Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / pci / device-props.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: device-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 ============================================
42id: @(#)device-props.fth 1.11 06/07/28
43purpose: PCI bus package
44copyright: Copyright 1994 FirmWorks All Rights Reserved
45copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
46copyright: Use is subject to license terms.
47
48\ All the code in this file executes as a child of a PCI device
49\ and so my-space is valid and config-X $call-parent (parent-X)
50\ accesses must be used.
51
52: vid,did ( -- ven-id dev-id ) 0 parent-l@ lwsplit ;
53
54: svid,ssid ( -- subven-id subsys-id ) subsystem-base parent-l@ lwsplit ;
55
56: rev-id ( -- n ) 8 parent-w@ ;
57
58: class-code ( -- n ) 8 parent-l@ 8 rshift ;
59
60h# ffff constant invalid-std-cap
61
62\ Traverse capability list looking for PCI-Express capabilities
63: pcie-capability-regs ( -- pointer | 0 )
64 h# 34 parent-b@ ( pointer )
65 begin dup while ( pointer )
66 dup parent-w@ dup invalid-std-cap <> if ( pointer w-value )
67 wbsplit swap h# 10 = if ( pointer next )
68 drop exit ( pointer )
69 else
70 nip ( next )
71 then
72 else
73 cmn-warn[ " Standard Capability Config access failed" ]cmn-end
74 abort
75 then
76 repeat
77;
78
79\ Create properties reflecting standard configuration header information
80
81: int16-property ( phys.hi name$ -- ) 2>r parent-w@ 2r> integer-property ;
82: int8-property ( phys.hi name$ -- ) 2>r parent-b@ 2r> integer-property ;
83
84: ?int16-property ( phys.hi name$ -- )
85 2>r parent-w@ ?dup if 2r> integer-property else 2r> 2drop then
86;
87
88\ Create properties common to PCI and PCIE.
89: make-basic-function-properties ( -- )
90 0 " vendor-id" int16-property
91 2 " device-id" int16-property
92 8 " revision-id" int8-property
93
94 header-type 1 <> if \ Not a PCI-PCI bridge
95 subsystem-base ( offset )
96 dup " subsystem-vendor-id" ?int16-property
97 2+ " subsystem-id" ?int16-property
98 then
99
100 class-code " class-code" integer-property
101
102 h# 10 h# 0c tuck parent-b! " cache-line-size" int8-property
103
104 h# 3d parent-b@ ?dup if ( intr )
105 dup " interrupts" integer-property ( intr )
106 my-space swap " assign-int-line" $call-parent ( line#,true | false )
107 if h# 3c parent-b! then ( )
108 then ( )
109;
110
111: make-pci-specific-properties ( -- )
112 header-type 1 <> if
113 card-bus? if
114 \ cardbus requires that we set the PRIMARY bus number.
115 my-space cfg>bus# h# 18 parent-b!
116 else
117 h# 3e " min-grant" int8-property
118 h# 3f " max-latency" int8-property
119 then
120 then
121
122 \ Per Solaris/OBP agreement (see psypci.c, simba.c), set cache line size
123 \ and latency timer. By setting them this early, we get full PCI speed
124 \ during boot, solving bugid 4346844. See also bugids 1234181 and 1235094.
125 \
126 \ If variations on either value are needed, they can be changed via nvramrc
127 \ script, and the Solaris PCI nexi will respect the changed properties.
128 \
129 \ Cache line size is set above in make-basic-function-properties
130
131 h# 40 h# 0d tuck parent-b! " latency-timer" int8-property
132
133 6 parent-w@ ( int )
134 dup 9 rshift 3 and " devsel-speed" integer-property
135 dup 7 rshift 1 and if " fast-back-to-back" boolean-property then
136 dup 6 rshift 1 and if " udf-supported" boolean-property then
137 5 rshift 1 and if " 66mhz-capable" boolean-property then
138;
139
140[ifndef] RELEASE
141: create-port-type-property ( -- ) \ XXX DEBUG ONLY XXX
142 pcie-capability-regs 2 + parent-w@ 4 >> h# f and
143 case
144 0 of " PCIE-Endpoint" endof
145 1 of " Legacy-PCIE-Endpoint" endof
146 4 of " Root-Port" endof
147 5 of " Upstream-Port" endof
148 6 of " Downstream-Port" endof
149 7 of " PCIE-PCI/PCIX-Bridge" endof
150 8 of " PCI/PCIX-PCIE-Bridge" endof
151 ( default ) " Other" rot
152 endcase
153 encode-string " port-type" property
154;
155[then]
156
157: make-pcie-specific-properties ( -- )
158[ifndef] RELEASE
159 create-port-type-property \ XXX DEBUG ONLY XXX
160[then]
161;
162
163: pci-make-function-properties ( -- )
164 make-basic-function-properties
165 pci-express? 0= if
166 make-pci-specific-properties
167 else
168 make-pcie-specific-properties
169 then
170;
171
172fload ${BP}/dev/pci/generic-names.fth
173fload ${BP}/dev/pci/compatible-prop.fth
174
175\ If a generic name cannot be found, create a name of the form pciVVVV,DDDD
176\ unless subdevice subvendor IDS exist in which case use them instead.
177\
178: name-property-value ( -- adr len )
179 pci-express? if
180 vid,did
181 else
182 svid,ssid 2dup or 0= if 2drop vid,did then
183 then
184 ascii-vendev-id
185;
186
187: make-name-property ( -- )
188 class-code unknown-class? if name-property-value then
189 encode-string " name" property
190;
191
192: class-property-value ( -- adr len )
193 push-hex class-code <# u# u# u# u# u# u# " class" $hold u#> pop-base
194;
195
196\ Create standard properties for functions with no fcode drivers
197: make-std-fcode-properties ( -- )
198 make-name-property
199 make-compatible-property
200 make-reg-property
201;