Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: fcode-rom.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: @(#)fcode-rom.fth 1.7 06/10/18 | |
43 | purpose: PCI bus package | |
44 | copyright: Copyright 1994 FirmWorks All Rights Reserved | |
45 | copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. | |
46 | copyright: Use is subject to license terms. | |
47 | ||
48 | headerless | |
49 | \ If the expansion ROM mapped at "virt" contains an FCode program, | |
50 | \ copy it into RAM and return its address | |
51 | ||
52 | : le-w@ ( adr -- n ) dup c@ swap 1+ c@ bwjoin ; | |
53 | : be-l@ ( adr -- n ) | |
54 | dup 3 + c@ swap dup 2 + c@ swap dup 1 + c@ swap c@ bljoin | |
55 | ; | |
56 | ||
57 | : fcode-image? ( PCI-struct-adr -- flag ) | |
58 | dup " PCIR" comp if drop false exit then | |
59 | ||
60 | \ Check if the Vendor ID matches | |
61 | dup 4 + le-w@ 0 parent-w@ <> if | |
62 | drop false exit | |
63 | then | |
64 | ||
65 | \ Check if the device ID matches | |
66 | dup h# 06 + le-w@ h# 02 parent-w@ <> if | |
67 | drop false exit | |
68 | then | |
69 | ||
70 | h# 14 + c@ 1 = | |
71 | ; | |
72 | ||
73 | [ifdef] fcode-checksum | |
74 | \ This code can be enabled to perform a checksum test on | |
75 | \ the Plugin card FCode PROM. Checksum test is performed | |
76 | \ before the FCode is evaluated to make sure that the FCode | |
77 | \ driver in FCode PROM is not corrupted. Checksum calculation | |
78 | \ algorithm and related stuff is defined in PCI Specification | |
79 | \ document. | |
80 | : fcode-sum-ok? ( adr len -- ok? ) | |
81 | over 4 + l@ < if ( h-adr ) \ h-adr: header address | |
82 | drop false exit ( false ) \ length error | |
83 | then ( h-adr ) | |
84 | ||
85 | dup 2+ w@ swap ( exp-sum h-adr ) | |
86 | dup 8 + ( exp-sum h-adr b-adr ) \ b-adr: body-address | |
87 | swap 4 + l@ 8 - ( exp-sum b-adr b-len ) \ b-len: body-length | |
88 | bounds 0 -rot do ( exp-sum 0 ) | |
89 | i c@ + ( exp-sum csum ) | |
90 | loop | |
91 | lwsplit + lwsplit + h# ffff and ( exp-sum sum ) | |
92 | 2dup <> if ( exp-sum sum ) | |
93 | cmn-warn[ | |
94 | " FCode checksum error; expected: %x result: %x" ( ) | |
95 | ]cmn-end | |
96 | false ( false ) | |
97 | else ( exp-sum sum ) | |
98 | 2drop true ( true ) | |
99 | then | |
100 | ; | |
101 | [then] | |
102 | ||
103 | : release-rom-resource ( phys.hi release? -- ) | |
104 | if ( phys.hi ) | |
105 | \ Zero the ROM Base Address Register | |
106 | \ and release associated resources | |
107 | 0 over parent-l! ( -- ) | |
108 | release-bar-resources ( -- ) | |
109 | else ( phys.hi ) | |
110 | \ disable ROMBAR address decode | |
111 | dup parent-l@ 1 invert and ( phys.hi reg' ) | |
112 | swap parent-l! ( -- ) | |
113 | then ( -- ) | |
114 | ; | |
115 | ||
116 | headers | |
117 | 0 value rom-base | |
118 | ||
119 | : locate-fcode ( rom-image-adr -- false | adr len true ) | |
120 | dup to rom-base | |
121 | begin | |
122 | dup le-w@ h# aa55 <> if | |
123 | drop false exit | |
124 | then ( rom-image-adr ) | |
125 | ||
126 | dup h# 18 + le-w@ over + ( rom-image-adr PCI-struct-adr ) | |
127 | dup fcode-image? if ( rom-image-adr PCI-struct-adr ) | |
128 | drop dup rom-base - ( rom-image-adr offset ) | |
129 | encode-int " fcode-rom-offset" property | |
130 | dup 2 + le-w@ + ( FCode-image-adr ) | |
131 | dup >r 4 + be-l@ ( FCode-len ) | |
132 | dup alloc-mem ( FCode-len adr ) | |
133 | swap 2dup r> -rot cmove ( adr len ) | |
134 | [ifdef] fcode-checksum | |
135 | 2dup fcode-sum-ok? 0= if ( adr len ) | |
136 | 2drop false exit ( false ) | |
137 | then | |
138 | [then] | |
139 | true exit | |
140 | then | |
141 | dup h# 15 + c@ h# 80 and 0= ( rom-image-adr PCI-struct-adr ) | |
142 | while \ More images ( rom-image-adr PCI-struct-adr ) | |
143 | h# 10 + le-w@ 9 lshift + ( rom-image-adr' ) | |
144 | repeat ( rom-image-adr' ) | |
145 | 2drop false | |
146 | ; | |
147 | ||
148 | defer skip-fcode-prom? ( -- flag ) ' false to skip-fcode-prom? | |
149 | : umin ( n1 n2 -- min ) 2dup u> if swap then drop ; | |
150 | : find-fcode? ( -- false | adr len true ) | |
151 | ||
152 | skip-fcode-prom? if false exit then | |
153 | ||
154 | expansion-rom get-bar# >bar-struct >r ( -- ) | |
155 | r@ >bar.implemented? @ 0= if ( -- ) | |
156 | r> drop false exit ( -- ) | |
157 | then ( -- ) | |
158 | ||
159 | \ The >bar.size element is bumped to 64 bit size | |
160 | \ to take care of 64 bit pci address. We need to | |
161 | \ xlsplit to get back the lower 32 bit value. The | |
162 | \ upper 32 bit is zero here since we are talking about | |
163 | \ ROM bar size. | |
164 | 0 0 r@ >bar.phys.hi @ r> >bar.size x@ ( 0 0 phys.hi size ) | |
165 | xlsplit drop h# 2.0000 umin dup >r ( 0 0 phys.hi size' ) | |
166 | " map-in" $call-parent ( va ) ( r: size ) | |
167 | r> ( va len ) | |
168 | ||
169 | \ Turn on address decode enable in Expansion ROM Base Address Register | |
170 | expansion-rom >r ( va len ) ( r: offset ) | |
171 | r@ parent-l@ 1 or r@ parent-l! ( va len ) ( r: offset ) | |
172 | ||
173 | \ Turn on memory enable | |
174 | 4 parent-w@ 2 or 4 parent-w! ( va len ) ( r: offset ) | |
175 | ||
176 | >r dup >r locate-fcode ( false | adr len true ) | |
177 | ||
178 | r> r> " map-out" $call-parent ( false | adr len true ) | |
179 | ||
180 | r> false release-rom-resource ( false | adr len true ) | |
181 | ; | |
182 | ||
183 | ||
184 | \ After a function has been located and a device node has been created | |
185 | \ for it, fill in the device node with properties and methods. | |
186 | ||
187 | headerless | |
188 | ||
189 | : driver-name ( -- str len ) | |
190 | sub-vendev-id-value nip if \ Subsystem Ven ID is non-zero | |
191 | vdss-id-value \ Use pciVVVV,DDDD.SSSS.ssss | |
192 | else | |
193 | vendev-id-value \ Use pciVVVV,DDDD | |
194 | then | |
195 | ; | |
196 | ||
197 | : no-builtin-fcode? ( -- flag ) | |
198 | builtin-drivers find-package if ( phandle ) | |
199 | >r ( -- ) | |
200 | driver-name r@ find-method if ( acf ) | |
201 | true true ( acf true true ) | |
202 | else ( -- ) | |
203 | class-property-value r@ find-method if ( acf ) | |
204 | false true ( acf false true ) | |
205 | else ( -- ) | |
206 | false ( false ) | |
207 | then ( acf name? true | false ) | |
208 | then ( acf name? true | false ) | |
209 | r> drop ( acf name? true | false ) | |
210 | if ( acf name? ) | |
211 | drop ( acf ) | |
212 | catch 0= if false exit then ( false ) | |
213 | then ( -- ) | |
214 | then | |
215 | true | |
216 | ; |