Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: probe.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: @(#)probe.fth 1.6 06/02/16 | |
43 | purpose: | |
44 | copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | \ In order to use this file you need to: | |
48 | \ | |
49 | \ Define | |
50 | \ a nexus specific address to string converter and set the defer | |
51 | \ make-probe-device$ to point to it. | |
52 | \ The stack diagram is: | |
53 | \ | |
54 | \ my-bus-encoder ( pa.lo pa.hi -- str,len ) | |
55 | \ | |
56 | \ You should use the name of your nexus and typically your encode | |
57 | \ method to make strings of the form: | |
58 | \ | |
59 | \ foo-pa,hi,pa-lo | |
60 | \ | |
61 | \ These strings correspond to the names of the methods that load | |
62 | \ the built-in drivers. | |
63 | \ | |
64 | \ You may also need to modify: my-interrupt-parent | |
65 | \ if interrupts from your children do not go to your parent. | |
66 | \ If this is true and your children generate interrupts in | |
67 | \ different parent nodes then this code will need to change. | |
68 | \ | |
69 | \ | |
70 | \ External interfaces for you to use: | |
71 | \ | |
72 | \ build-probed-nodes ( -- ) | |
73 | \ This will probe the nodes and create location and interrupt | |
74 | \ map properties appropriately. | |
75 | \ | |
76 | \ probe-table! ( my-space my-address acf intr ino location,len -- ) | |
77 | \ Call this routine to append nodes to the probe list that | |
78 | \ will be used by the build-probed-nodes method. | |
79 | \ | |
80 | \ my-space,my-address are obvious and will form | |
81 | \ the reg entry in your node | |
82 | \ acf This is a probe rooutine. | |
83 | \ -1 means dont probe just create, | |
84 | \ otherwise it must point to a | |
85 | \ routine with a stack diagram that | |
86 | \ must be: | |
87 | \ my-probe ( lo,hi -- probe? ) | |
88 | \ lo,hi and my-space,my-address that | |
89 | \ you defined on the probe-table! | |
90 | \ line. | |
91 | \ If this acf executes then the state | |
92 | \ returned is cached to improve | |
93 | \ performance. | |
94 | \ intr, ino a mapping for a device generated | |
95 | \ intr and an INO in the node pointed | |
96 | \ to by my-interrupt-parent. | |
97 | \ 0,0 means no interrupts and no | |
98 | \ entry will be created in | |
99 | \ interrupt-map. | |
100 | \ locn,len a string to use as the location | |
101 | \ property if this node exists. | |
102 | \ Null string (0,0) means there is no | |
103 | \ location property for this node. | |
104 | \ | |
105 | ||
106 | headerless | |
107 | 0 value num-addrcells | |
108 | 0 value builtin-phandle | |
109 | ||
110 | : no-loc$ ( -- adr, len ) 0 0 ; \ used in most nexuses | |
111 | ||
112 | : builtin-drivers ( -- str$ ) " /packages/SUNW,builtin-drivers" ; | |
113 | ||
114 | my-parent ihandle>phandle instance value my-interrupt-parent | |
115 | instance defer make-probe-device$ | |
116 | h# 20 instance buffer: probed-device$ | |
117 | h# 1000 alloc-mem dup instance value device-probe-list | |
118 | ( table ) instance value device-probe-ptr | |
119 | ||
120 | struct | |
121 | 4 field >probe-acf | |
122 | 4 field >probe-address | |
123 | 4 field >probe-location | |
124 | 2 field >probe-space | |
125 | 1 field >probe-ino | |
126 | 1 field >probe-intr | |
127 | constant /probe-entry | |
128 | ||
129 | : probe-table! ( my-space my-address acf intr ino location,len -- ) | |
130 | device-probe-ptr >r | |
131 | ?dup if ( space addr acf intr ino loc,len) | |
132 | dup 2 + alloc-mem pack ( space addr acf intr ino va ) | |
133 | else ( space addr acf intr ino loc ) | |
134 | drop 0 ( space addr acf intr ino 0 ) | |
135 | then ( space addr acf intr ino va ) | |
136 | r@ >probe-location l! ( space addr acf intr ino ) | |
137 | r@ >probe-ino c! ( space addr acf intr ) | |
138 | r@ >probe-intr c! ( space addr acf ) | |
139 | r@ >probe-acf l! ( space addr ) | |
140 | r@ >probe-address l! ( space ) | |
141 | r@ >probe-space w! ( ) | |
142 | r> /probe-entry + is device-probe-ptr | |
143 | ; | |
144 | ||
145 | : asr-probe ( ptr acf -- ptr acf build-it? ) \ hook for asr | |
146 | true | |
147 | ; | |
148 | ||
149 | : (parse-table) ( table acf -- ) | |
150 | begin ( ptr acf ) | |
151 | over device-probe-ptr < while ( ptr acf ) | |
152 | asr-probe if | |
153 | 2dup execute ( ptr acf ) | |
154 | then | |
155 | swap /probe-entry + swap ( ptr' acf ) | |
156 | repeat 2drop ( -- ) | |
157 | ; | |
158 | ||
159 | : build-probed-node ( ptr -- ) | |
160 | builtin-phandle >r >r ( ) | |
161 | r@ >probe-address l@ r@ >probe-space w@ ( lo hi ) | |
162 | r@ >probe-acf l@ dup case ( lo hi acf acf ) | |
163 | -1 of endof ( lo hi true ) | |
164 | 0 of endof ( lo hi false ) | |
165 | ( default ) | |
166 | drop >r 2dup r> ( lo hi lo hi acf ) | |
167 | catch if ( lo hi xx yy ) | |
168 | 2drop false ( lo hi false ) | |
169 | then ( lo hi probe? ) | |
170 | 0 ( lo hi probe? 0 ) | |
171 | endcase ( lo hi probe? ) | |
172 | dup r@ >probe-acf l! ( lo hi probe? ) | |
173 | r> r> ( lo hi probe? ptr phandle ) | |
174 | rot 0= if ( lo hi ptr phandle ) | |
175 | 2drop 2drop exit ( ) | |
176 | then ( lo hi ptr phandle ) | |
177 | 2over make-probe-device$ ( lo hi ptr phandle probe$ ) | |
178 | rot find-method if ( lo hi ptr acf ) | |
179 | 2swap num-addrcells 1 = if nip then ( ptr acf hi ) | |
180 | " encode-unit" my-self $call-method ( ptr acf reg$ ) | |
181 | 0 0 2swap ( ptr acf 0 0 reg$ ) | |
182 | new-device ( ptr acf 0 0 reg$ ) | |
183 | set-args ( ptr acf ) | |
184 | catch 0= if ( ptr ) | |
185 | dup >probe-location l@ ?dup if ( ptr va ) | |
186 | count encode-string ( ptr xdr,len ) | |
187 | " sunw,location" property ( ptr ) | |
188 | then ( ptr ) | |
189 | then ( ptr ) | |
190 | drop ( ) | |
191 | finish-device ( ) | |
192 | else ( lo hi ptr ) | |
193 | 3drop ( ) | |
194 | then ( ) | |
195 | ; | |
196 | ||
197 | : en+ encode-int encode+ ; | |
198 | ||
199 | : build-prober-intrmap ( xdr,len ptr acf ptr -- ) | |
200 | >probe-intr c@ if ( xdr,len ptr acf ) | |
201 | over >r 2swap ( ptr acf xdr,len ) | |
202 | r@ >probe-space w@ en+ ( ptr acf xdr,len ) | |
203 | num-addrcells 2 = if ( ptr acf xdr,len ) | |
204 | r@ >probe-address l@ en+ ( ptr acf xdr,len ) | |
205 | then ( ptr acf xdr,len ) | |
206 | r@ >probe-intr c@ en+ ( ptr acf xdr,len ) | |
207 | my-interrupt-parent en+ ( ptr acf xdr,len ) | |
208 | r> >probe-ino c@ en+ ( ptr acf xdr,len ) | |
209 | 2swap ( xdr,len ptr acf ) | |
210 | then ( xdr,len ptr acf ) | |
211 | ; | |
212 | ||
213 | : locn-strings ( ptr -- ) | |
214 | >probe-location l@ ?dup if ( va ) | |
215 | dup c@ 2 + free-mem ( ) | |
216 | then ( ) | |
217 | ; | |
218 | ||
219 | : build-probed-nodes ( -- ) | |
220 | builtin-drivers find-package 0= if | |
221 | exit | |
222 | then is builtin-phandle | |
223 | " #address-cells" get-my-property 0= if | |
224 | decode-int nip nip | |
225 | else | |
226 | [ifndef] RELEASE | |
227 | cmn-error[ " Missing #address-cells property" ]cmn-end | |
228 | [then] | |
229 | 2 | |
230 | then is num-addrcells | |
231 | diagnostic-mode? if cmn-msg[ then | |
232 | ||
233 | 0 0 encode-bytes | |
234 | device-probe-list ['] build-prober-intrmap (parse-table) | |
235 | ?dup if " interrupt-map" property else drop then | |
236 | device-probe-list ['] build-probed-node (parse-table) | |
237 | device-probe-list ['] locn-strings (parse-table) | |
238 | device-probe-list h# 1000 free-mem | |
239 | ||
240 | diagnostic-mode? if " " ]cmn-end then | |
241 | ; |