Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: md-iodevice-props.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)md-iodevice-props.fth 1.1 07/06/22 | |
43 | purpose: Apply local mac address properties using devaliases | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All rights reserved. | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headerless | |
48 | ||
49 | fload ${BP}/dev/pci/cfgio.fth | |
50 | ||
51 | d# 256 buffer: pci-string | |
52 | ||
53 | \ The root pci string's unit address is only the cfg-handle, so return | |
54 | \ " pci@<cfg-handle>" | |
55 | : make-root-pci-string ( cfg-handle -- $device-path ) | |
56 | $pci pci-string 0 $strcat ( cfg-handle $device-path ) | |
57 | rot (u.) 2swap $strcat ( $device-path' ) | |
58 | ; | |
59 | ||
60 | \ Concatinate the input device string with | |
61 | \ " pci@<device>,<function" | |
62 | : make-pci-string ( $device-path device function -- $device-path' ) | |
63 | 2swap $pci 2swap $strcat 2swap ( $device-path device function ) | |
64 | >r (u.) 2swap $strcat ( $device-path )( R: function ) | |
65 | r> ?dup if ( $device-path function| ) | |
66 | -rot " ," 2swap $strcat ( function $device-path ) | |
67 | rot (u.) 2swap $strcat ( $device-path ) | |
68 | then ( $device-path ) | |
69 | ; | |
70 | ||
71 | \ Compare str2 with str1, and update the flag accordingly | |
72 | : $compare ( flag str1,len1 str2,len2 -- flag str1,len1 ) | |
73 | 2over $= -rot 2swap or -rot ( flag str1,len1 ) | |
74 | ; | |
75 | ||
76 | \ Compare the 'device-type' property of the input node with the allowable | |
77 | \ pci bus types and return a flag. | |
78 | : pcibus? ( node -- flag ) | |
79 | " device-type" MD_PROP_STR md-find-prop dup if ( prop|0 ) | |
80 | md-decode-prop drop ( str,len ) | |
81 | 0 -rot ( flag str,len ) | |
82 | " pcie-switch-upstream" $compare ( flag str,len ) | |
83 | " pcie-switch-downstream" $compare ( flag str,len ) | |
84 | " pcie-pcix-bridge" $compare ( flag str,len ) | |
85 | " pcix-pcix-bridge" $compare ( flag str,len ) | |
86 | 2drop ( flag ) | |
87 | then ( flag ) | |
88 | ; | |
89 | ||
90 | \ Check to see if the input node is a network device | |
91 | : network-device? ( node -- flag ) | |
92 | " device-type" MD_PROP_STR md-find-prop dup if ( prop|0 ) | |
93 | md-decode-prop drop ( str,len ) | |
94 | " pci-network" $= ( flag ) | |
95 | then ( flag ) | |
96 | ; | |
97 | ||
98 | \ All interrupt-map nodes must have a parrent-interrupt property | |
99 | : interrupt-mapping? ( node -- flag ) | |
100 | " parent-interrupt" -1 md-find-prop 0<> ( flag ) | |
101 | ; | |
102 | ||
103 | \ All slot-name nodes must have a slot-name property | |
104 | : slot-name? ( node -- flag ) | |
105 | " slot-names" MD_PROP_STR md-find-prop 0<> ( flag ) | |
106 | ; | |
107 | ||
108 | \ Extract the device and function numbers from the MD node | |
109 | : get-md-dev-fcn ( node -- dev# fcn# ) | |
110 | dup " device-number" md-get-required-prop drop ( node dev# ) | |
111 | swap " function-number" md-get-required-prop drop ( dev# fcn# ) | |
112 | ; | |
113 | ||
114 | \ Input: | |
115 | \ phandle - Package handle of parent device tree node | |
116 | \ dev# - target child device number | |
117 | \ fcn# - target child function number | |
118 | \ Oputput: | |
119 | \ phandle' - Package handle of child device | |
120 | : find-child-device ( dev# fcn# phandle -- phandle' ) | |
121 | child dup if ( dev fcn phandle ) | |
122 | begin ( dev fcn phandle ) | |
123 | dup if ( dev fcn phandle ) | |
124 | dup " reg" rot get-package-property drop ( dev fcn phandle reg,len ) | |
125 | decode-int nip nip ( dev fcn phandle phys.hi ) | |
126 | 2over rot ( dev fcn phandle dev fcn phys.hi ) | |
127 | tuck cfg>fcn# = -rot cfg>dev# = and 0= ( dev fcn phandle flag ) | |
128 | else ( dev fcn phandle ) | |
129 | false ( dev fcn phandle flag ) | |
130 | then ( dev fcn phandle ) | |
131 | while ( dev fcn phandle ) | |
132 | peer ( dev fcn phandle ) | |
133 | repeat ( dev fcn phandle ) | |
134 | then ( dev fcn phandle ) | |
135 | nip nip ( phandle ) | |
136 | ; | |
137 | ||
138 | \ 'prop' is a property to create, 'name' is the name of the property, and | |
139 | \ 'phandle' is the device to create the property in. | |
140 | : set-device-property ( prop,len name,len phandle -- ) | |
141 | current-device >r ( prop,len name,len phandle )( R: phandle ) | |
142 | my-self >r ( prop,len name,len phandle )( R: phandle my-self ) | |
143 | 0 to my-self ( prop,len name,len phandle )( R: phandle my-self ) | |
144 | push-device property ( ) | |
145 | r> to my-self ( )( R: phandle ) | |
146 | r> push-device ( )( R: ) | |
147 | ; | |
148 | ||
149 | \ Integers in MD are stored in arrays of 64 bits, encode-int wants 32 bits. | |
150 | : encode-md-prop-data ( data,len -- prop,len ) | |
151 | 0 0 encode-bytes rot 0 ?do ( data prop,len ) | |
152 | 2 pick i + x@ encode-int encode+ ( data prop,len' ) | |
153 | /x +loop ( data prop,len' ) | |
154 | rot drop ( prop,len' ) | |
155 | ; | |
156 | ||
157 | \ Creates a property in the package pointed to by phandle if it exists in the | |
158 | \ MD node pointed to by node. | |
159 | : create-optional-property ( phandle node name,len -- ) | |
160 | 2dup >r >r ( phandle node name,len )( R: len name ) | |
161 | -1 md-find-prop ?dup if ( phandle prop| ) | |
162 | md-decode-prop case ( phandle [$data | val] ) | |
163 | MD_PROP_VAL of encode-int endof ( phandle prop,len ) | |
164 | MD_PROP_STR of encode-string endof ( phandle prop,len ) | |
165 | MD_PROP_DATA of encode-md-prop-data endof ( phandle prop,len ) | |
166 | cmn-error[ " Invalid MD property type" ]cmn-end | |
167 | endcase ( phandle prop,len ) | |
168 | rot r> r> rot ( prop,len name,len phandle )( R: ) | |
169 | set-device-property ( ) | |
170 | else ( phandle ) | |
171 | r> r> 3drop ( )( R: ) | |
172 | then ( ) | |
173 | ; | |
174 | ||
175 | \ These pci bus node properties are not required, but OpenBoot should create | |
176 | \ them if they are present in the MD. | |
177 | : create-optional-pci-properties ( phandle node -- ) | |
178 | 2dup " interrupts" create-optional-property ( phandle node -- ) | |
179 | 2dup " #interrupt-cells" create-optional-property ( phandle node -- ) | |
180 | 2dup " level2-hotplug-slot-count" create-optional-property ( phandle node -- ) | |
181 | 2dup " level1-hotplug-slot-count" create-optional-property ( phandle node -- ) | |
182 | " interrupt-map-mask" create-optional-property ( ) | |
183 | ; | |
184 | ||
185 | \ 'node' will point to an interrupt mapping node as specified by FWARC 2007/070. $path is the | |
186 | \ device tree path to create the interrupt mapping properties in. | |
187 | : create-interrupt-mapping ( $path node -- ) | |
188 | >r find-package if ( phandle| )( R: node ) | |
189 | \ If the node already has an interrupt-map property, extend it. | |
190 | \ Otherwise, start a new one. | |
191 | dup " interrupt-map" rot get-package-property if ( phandle [prop,len| ] ) | |
192 | 0 0 encode-bytes ( phandle prop,len ) | |
193 | else ( phandle prop,len ) | |
194 | encode-bytes ( phandle prop,len ) | |
195 | then ( phandle prop,len ) | |
196 | r@ " child-unit-address" md-get-required-prop drop ( phandle prop,len prop',len' ) | |
197 | encode-md-prop-data encode+ ( phandle prop,len ) | |
198 | r@ " child-interrupt" md-get-required-prop ( phandle prop,len [val type] | [buf len type] ) | |
199 | MD_PROP_VAL = if ( phandle prop,len [val | buf len ] ) | |
200 | encode-int ( phandle prop,len prop'',len ) | |
201 | else ( phandle prop,len buf len ) | |
202 | encode-md-prop-data ( phandle prop,len prop'',len ) | |
203 | then ( phandle prop,len prop'',len ) | |
204 | encode+ ( phandle prop,len ) | |
205 | r@ " parent-device-path" md-get-required-prop drop ( phandle prop,len path,len ) | |
206 | find-package if ( phandle prop,len pphandle| ) | |
207 | encode-int encode+ ( phandle prop,len ) | |
208 | else ( phandle prop,len ) | |
209 | cmn-error[ " Interrupt parent device missing" ]cmn-end | |
210 | then ( phandle prop,len ) | |
211 | r@ " parent-interrupt" md-get-required-prop ( phandle prop,len [val type] | [buf len type] ) | |
212 | MD_PROP_VAL = if ( phandle prop,len [val | buf len ] ) | |
213 | encode-int ( phandle prop,len prop'',len ) | |
214 | else ( phandle prop,len buf len ) | |
215 | encode-md-prop-data ( phandle prop,len prop'',len ) | |
216 | then ( phandle prop,len prop'',len ) | |
217 | encode+ ( phandle prop,len ) | |
218 | rot " interrupt-map" rot set-device-property ( ) | |
219 | then ( ) | |
220 | r> drop ( )( R: ) | |
221 | ; | |
222 | ||
223 | \ 'node' points to a slot-name MD node, and '$path' points to the device tree path | |
224 | \ to create the slot name property in. | |
225 | : create-slot-name ( $path node -- ) | |
226 | >r find-package if ( phandle| )( R: node ) | |
227 | r@ " slot-number" md-get-required-prop drop ( phandle slot-number ) | |
228 | encode-int ( phandle prop,len ) | |
229 | r@ " slot-names" md-get-required-prop drop ( phandle prop,len name,len ) | |
230 | encode-string encode+ ( phandle prop,len ) | |
231 | rot " slot-names" rot set-device-property ( ) | |
232 | then ( ) | |
233 | r> drop ( )( R: ) | |
234 | ; | |
235 | ||
236 | \ (apply-md-pci-props) is a recursive function that scans the IO devices in the MD and | |
237 | \ populates the OpenBoot device tree nodes with any necessary properties. | |
238 | defer (apply-md-pci-props) | |
239 | ||
240 | : ((apply-md-pci-props)) ( $device-path node -- $device-path ) | |
241 | >r r@ pcibus? if ( $device-path )( R: node ) | |
242 | 2dup ( $device-path $device-path ) | |
243 | r@ get-md-dev-fcn ( $device-path $device-path dev# fcn# ) | |
244 | make-pci-string ( $device-path $device-path' ) | |
245 | 2dup find-package if ( $device-path $device-path' phandle ) | |
246 | r@ create-optional-pci-properties ( $device-path $device-path ) | |
247 | ['] (apply-md-pci-props) ( $device-path $device-path' acf ) | |
248 | r@ md-applyto-fwds ( $device-path $device-path' ) | |
249 | then ( $device-path $device-path ) | |
250 | 2drop ( $device-path ) | |
251 | then ( $device-path ) | |
252 | r@ network-device? if ( $device-path ) | |
253 | 2dup find-package if ( $device-path phandle| ) | |
254 | r@ get-md-dev-fcn ( $device-path phandle dev fcn ) | |
255 | rot find-child-device ?dup 0= if ( $device-path phandle| ) | |
256 | r> drop exit ( $device-pah ) | |
257 | then ( $device-path phandle ) | |
258 | dup r@ " phy-type" create-optional-property ( $device-path phandle ) | |
259 | r@ " mac-addresses" MD_PROP_DATA md-find-prop ?dup if ( $device-path phandle prop| ) | |
260 | over >r md-decode-prop drop ( $device-path phandle prop,len ) | |
261 | 2dup encode-bytes " mac-addresses" ( $device-path phandle prop,len prop,len name,len ) | |
262 | r@ set-device-property ( $device-path phandle prop,len ) | |
263 | drop 6 encode-bytes " local-mac-address" ( $device-path phandle prop,len name,len ) | |
264 | r> set-device-property ( $device-path phandle ) | |
265 | then ( $device-path phandle ) | |
266 | drop ( $device-path ) | |
267 | then ( $device-path ) | |
268 | then ( $device-path ) | |
269 | r@ interrupt-mapping? if ( $device-path ) | |
270 | 2dup r@ create-interrupt-mapping ( $device-path ) | |
271 | then ( $device-path ) | |
272 | r@ slot-name? if ( $device-path ) | |
273 | 2dup r@ create-slot-name ( $device-path ) | |
274 | then ( $device-path ) | |
275 | r> drop ( $device-path )( R: ) | |
276 | ; | |
277 | ||
278 | ' ((apply-md-pci-props)) is (apply-md-pci-props) | |
279 | ||
280 | \ Traverse through the root nexus pci devices (the ones that have | |
281 | \ direct fwd links off of the phys_io node). These differ from normal pci | |
282 | \ device MD nodes since they are unique based on cfg-handle and not on | |
283 | \ device,function numbers. | |
284 | : apply-md-pci-props ( node -- ) | |
285 | dup " device-type" MD_PROP_STR md-find-prop ?dup if ( node prop| ) | |
286 | md-decode-prop drop ( node $dev-type ) | |
287 | " pciex" $= if ( node ) | |
288 | dup " cfg-handle" md-get-required-prop drop ( node cfg-handle ) | |
289 | make-root-pci-string ( node $device-path ) | |
290 | 2dup find-package if ( node $device-path phandle| ) | |
291 | 3 pick create-optional-pci-properties ( node $device-path ) | |
292 | rot ['] (apply-md-pci-props) swap md-applyto-fwds ( $device-path ) | |
293 | then ( node $device-path ) | |
294 | 2drop ( ) | |
295 | else ( node ) | |
296 | drop ( ) | |
297 | then ( ) | |
298 | else ( node ) | |
299 | drop ( ) | |
300 | then ( ) | |
301 | ; | |
302 | ||
303 | stand-init: Set MD device properties | |
304 | 0 " phys_io" md-find-node ?dup if ( node|false ) | |
305 | ['] apply-md-pci-props swap ( acf node ) | |
306 | md-applyto-fwds ( ) | |
307 | then ( ) | |
308 | ; |