Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / usb2 / hcd / fcode.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: fcode.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 ============================================
42id: @(#)fcode.fth 1.1 07/01/22
43purpose: Load USB device fcode driver
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45\ See license at end of file
46
47hex
48headers
49
50false value probemsg? \ Optional probing messages
51
52\ Find FCode in Sun Microsystems PROM. See dropins.src for your platform.
53
54: find-fcode ( adr1 len1 -- true | false )
55 " SUNW,builtin-drivers" find-package drop \ Ignore return code
56 find-method if
57 h# 1.0000 dup alloc-mem swap 2dup 2>r rot ( addr 1.0000 xt )
58 execute 2r> rot if 2dup byte-load then free-mem true
59 else
60 false
61 then
62;
63
64\ >tmp$ copies the string to allocated memory. This is necessary because
65\ the loading of a hub driver may cause another driver to be loaded,
66\ thus re-entering load-fcodedriver . The string that class$ returns
67\ is in a static area that is overwritten on each call, so it must
68\ be copied to a dynamically-allocated place. It's tempting to
69\ apply >tmp$ only to class$, but then the "free-mem" would have
70\ to be omitted for strings from super$ and driver$
71
72: >tmp$ ( $1 -- $2 )
73 >r r@ alloc-mem ( name-adr adr r: len )
74 tuck r@ move ( adr r: len )
75 r> ( adr len )
76;
77
78\ $load-driver executes an FCode driver that is stored somewhere
79\ other than on the device itself. This should be defined outside
80\ the FCode driver...
81
82\ any-drop-ins? and do-drop-in are fcode driver loading methods in
83\ FirmWorks' OpenFirmware implementation.
84\ The following code may have to be changed for other OpenFirmware
85\ implementation, provided they have a special way of loading fcode
86\ driver from system ROM.
87
88\ If any-drop-ins? or do-drop-in is missing, eval will throw an error
89\ that will be caught in $load-driver.
90
91: did-drop-in? ( name$ -- flag )
92 2dup " any-drop-ins?" eval ( name$ flag )
93 0= if 2drop false exit then ( name$ )
94
95 probemsg? if ( name$ )
96 ." Matched dropin driver " 2dup type cr ( name$ )
97 then ( name$ )
98
99 " do-drop-in" eval true
100;
101
102: $load-driver ( name$ -- done? )
103 >tmp$ ( name$' )
104
105\ Replace firmworks-invoking code with SUN-invoking code
106\ 2dup ['] did-drop-in? catch if 2drop false then ( name$' done? )
107 2dup ['] find-fcode catch if ." Fatal error in find-fcode" cr false then
108 -rot free-mem ( done? )
109;
110
111\ Words to get my (as a child) properties
112
113: get-int-property ( name$ -- n )
114 get-my-property 0= if decode-int nip nip else 0 then
115;
116: get-class-properties ( -- class subclass protocol )
117 " class" get-int-property
118 " subclass" get-int-property
119 " protocol" get-int-property
120;
121: get-vendor-properties ( -- vendor product release )
122 " vendor-id" get-int-property
123 " device-id" get-int-property
124 " release" get-int-property
125;
126
127\ Some little pieces for easy formatting of USB name strings
128
129: $hold ( adr len -- )
130 dup if bounds swap 1- ?do i c@ hold -1 +loop else 2drop then
131;
132
133: usb#> ( n -- ) " usb" $hold 0 u#> ; \ Prepends: usb
134: #usb#> ( n -- ) u#s drop usb#> ; \ Prepends: usbN
135: #, ( n -- ) u#s drop ascii , hold ; \ Prepends: ,N
136: #. ( n -- ) u#s drop ascii . hold ; \ Prepends: .N
137
138: ?#, ( n level test-level -- ) \ Prepends: ,N if levels match
139 >= if #, else drop then
140;
141
142: device$ ( -- adr len )
143 get-vendor-properties drop ( vendor-id device-id )
144 push-hex
145 <# #, #usb#>
146 pop-base
147;
148
149\ Return a string of the form usb,classC[,S[,P]] depending on level
150\ Level: 0 -> C 1 -> C,S 2 -> C,S,P
151: class$ ( level -- name$ )
152 >r get-class-properties r> ( class subclass protocol level )
153 push-hex ( class subclass protocol level )
154 <# ( class subclass protocol level )
155 tuck ( class subclass level protocol level )
156 2 ?#, ( class subclass level )
157 1 ?#, ( class )
158 u#s " usb,class" $hold ( )
159 u#>
160 pop-base
161;
162
163: load-fcode-driver ( -- )
164 " compatible" get-my-property 0= if ( adr len )
165 begin
166 ?dup while ( adr len )
167 decode-string ( adr len adr' len' )
168 $load-driver if 2drop exit then
169 repeat drop
170 then
171;
172
173\ LICENSE_BEGIN
174\ Copyright (c) 2006 FirmWorks
175\
176\ Permission is hereby granted, free of charge, to any person obtaining
177\ a copy of this software and associated documentation files (the
178\ "Software"), to deal in the Software without restriction, including
179\ without limitation the rights to use, copy, modify, merge, publish,
180\ distribute, sublicense, and/or sell copies of the Software, and to
181\ permit persons to whom the Software is furnished to do so, subject to
182\ the following conditions:
183\
184\ The above copyright notice and this permission notice shall be
185\ included in all copies or substantial portions of the Software.
186\
187\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
188\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
189\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
190\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
191\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
192\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
193\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
194\
195\ LICENSE_END