Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / pci-bridge / hotplugalloc.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: hotplugalloc.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: @(#)hotplugalloc.fth 1.3 06/10/20
43purpose: PCI bridge probe code
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47hex
48headerless
49
50\ This file implements hotplug enabled resource allocation
51\ routines. Please refer fwarc case 2006/198 for details.
52
53fload ${BP}/dev/pci/hotplugdetect.fth
54
55\ Aggregrate Resource set aside for hotplug
56h# 800.0000 value hotplug-iosize \ 128 MB of io space
57h# 4000.0000 value hotplug-memsize \ 1 GB of Mem32 space
58h# 8000.0000 value hotplug-mem64size \ 2 GB of Mem64 space
59d# 224 value hotplug-busrange \ 224 extra busses
60
61false value preallocation-scheme?
620 value hotplug-memlimit
630 value hotplug-mem64limit
640 value hotplug-iolimit
650 value hotplug-buslimit
66false value my-slot?
670 value 1st-level-cnt
680 value 2nd-level-cnt
69
70: umin ( n1 n2 -- min ) 2dup u> if swap then drop ;
71
72\ These are 64 bit arithmetic operation needed to support
73\ pci 64 bit memory address handling on the data stack.
74: x> ( x1 x2 -- gt? )
75 xlsplit rot xlsplit rot 2dup > if ( x1.lo x2.lo x1.hi x2.hi )
76 2drop 2drop true
77 else
78 < if ( x2.lo x1.lo )
79 2drop false
80 else
81 swap u> ( flag )
82 then
83 then
84;
85
86: xmin ( x1 x2 -- umin ) 2dup x> if swap then drop ;
87
88: make-power-of-2 ( n -- n' )
89 d# 32 0 do ( n )
90 1 i lshift ( n p2 )
91 2dup u<= if ( n p2 )
92 nip leave ( p2 )
93 else ( n p2 )
94 drop ( n )
95 then ( n )
96 loop ( p2 )
97;
98
99\ Those platforms which implement the latest hotplug
100\ allocation scheme, will run a pci bus preprober in
101\ the host bridge driver to gather information about
102\ 1st level slots (host platform slots) and 2nd level
103\ slots (expansion box slots) and publish the following
104\ properties,
105\ "level1-hotplug-slot-count"
106\ "level2-hotplug-slot-count"
107\
108\ These properties are later consumed by the pci-pci
109\ bridge driver to calculate hotplug resource.
110: slot-count-inherited-property? ( -- true | false )
111 \ Get 1st level slot count property
112 " level1-hotplug-slot-count" get-inherited-property 0= if ( prop-addr len )
113 decode-int to 1st-level-cnt 2drop ( )
114 \ Since the first level slot count property is there,
115 \ we assume the 2nd level slot count property will be there.
116 " level2-hotplug-slot-count" get-inherited-property drop ( prop-addr len )
117 decode-int to 2nd-level-cnt 2drop ( )
118 true ( true )
119 else
120 false ( false )
121 then
122;
123
124\ Let us determine if this nexus node has 1st level slots
125\ (platform onboard slots) or 2nd level slots (expansion box slots).
126\ That will give us the divisor to be used when scaling down the
127\ hotplug allocation values for my slots. Note that the 1st level
128\ slots get higher hotplug resource as compared to the 2nd level
129\ slots. The divisor is found on this policy,
130\
131\ if I have 1st-level slots then,
132\ divisor = 1st-slot-cnt
133\ if I have 2nd-level slots then,
134\ divisor = 1st-slot-cnt * 2nd-slot-cnt
135\
136: init-hotplug-params ( -- )
137 \ Does any of my parent have slot-implemented?
138 " slot-implemented?" get-inherited-property 0= if ( addr len )
139 \ If so, then my slots are 2nd level slots.
140 \ So divisor = 1st-slot-cnt * 2nd-slot-cnt.
141 2drop 1st-level-cnt 2nd-level-cnt * ( divisor )
142 else
143 \ My slots are 1st level slots.
144 \ So divisor = 1st-slot-cnt.
145 1st-level-cnt ( divisor )
146 then
147 ?dup if ( divisor )
148 hotplug-busrange over / to hotplug-busrange ( divisor )
149 make-power-of-2 ( divisor' )
150 hotplug-iosize over / to hotplug-iosize ( divisor' )
151 hotplug-memsize over / to hotplug-memsize ( divisor' )
152 hotplug-mem64size swap / to hotplug-mem64size ( )
153[ifdef] HOTPLUG-DEBUG?
154 cr ." Hotplug range for this bridge : " " pwd" eval
155 ." hotplug-memsize : " hotplug-memsize u.
156 cr ." hotplug-mem64size : " hotplug-mem64size u.
157 cr ." hotplug-iosize : " hotplug-iosize u.
158 cr ." hotplug-busrange : " hotplug-busrange u.
159[then]
160 then ( )
161;
162
163\ Hotplug enabled claim-pci-resource .
164: hp-claim-pci-resource ( -- mem-lo mem64-lo io-lo dma-lo mem-hi mem64-hi io-hi dma-hi bus# )
165 \ Does this bridge implement hotplug slots ?
166 hotplug-capability? if ( )
167 true is my-slot? ( )
168 init-hotplug-params ( )
169 hotplug-capable-prop ( )
170 \ Now let us allocate resource for the bridge
171 0 allocate-bridge-resources ( . . . . . . bus# )
172 \ Since this is hotplug capable, set the upper range for this
173 \ bridge's hotplug resource window.
174 dup hotplug-busrange + is hotplug-buslimit
175 ( mem-lo mem64-lo io-lo dma-lo mem-hi mem64-hi io-hi dma-hi bus# )
176 8 pick hotplug-memsize + 5 pick umin is hotplug-memlimit
177 ( mem-lo mem64-lo io-lo dma-lo mem-hi mem64-hi io-hi dma-hi bus# )
178 7 pick hotplug-mem64size + 4 pick xmin is hotplug-mem64limit
179 ( mem-lo mem64-lo io-lo dma-lo mem-hi mem64-hi io-hi dma-hi bus# )
180 6 pick hotplug-iosize + 3 pick umin is hotplug-iolimit
181 ( mem-lo mem64-lo io-lo dma-lo mem-hi mem64-hi io-hi dma-hi bus# )
182 else
183 \ The bridge does not have hotplug slots.
184 \ let us see if it just implements standard pci slots without
185 \ hotplug capability. This information is needed to determine
186 \ if the slots downstream to me in the hierarchy are 1st level
187 \ or 2nd level.
188 slot-implemented? is my-slot? ( )
189 \ Now let us allocate resource for the bridge
190 0 allocate-bridge-resources ( . . . . . . bus# )
191 then
192 \ Publish my "slot-implemented?" property
193 my-slot? if 0 0 " slot-implemented?" property then
194;
195
196\ This routine while releasing the unused bridge resources back to
197\ the parent node, will retain some portion of it for later hotplug
198\ operation. This is what we term as "hotplug preallocation". So as
199\ a outcome of this routine, the upper ranges of the bridge resources
200\ will be left at the following minimum water mark,
201\
202\ hotplug-buslimit = Total bus numbers left to the bridge.
203\ hotplug-memlimit = Upper range of mem32 space
204\ hotplug-mem64limit = Upper range of mem64 space
205\ hotplug-iolimit = Upper range of IO space
206\
207: hp-retain-pci-resource ( -- )
208 \ Params for allocate-bus# are ( n m-aln m-sz m64-aln m64-sz io-aln io-sz )
209 hotplug-buslimit \ Total minimum bus range
210 h# 10.0000 hotplug-memlimit \ mem32 alignment and size
211 h# 10.0000 hotplug-mem64limit \ mem64 alignment and size
212 h# 1000 hotplug-iolimit \ io alignment and size
213 allocate-bus# ( mem-lo mem64-lo io-lo dma-lo mem-hi mem64-hi io-hi dma-hi bus# )
214
215 \ Subordinate Bus Number register:
216 h# 1a my-b! ( mem-lo mem64-lo io-lo dma-lo mem-hi mem64-hi io-hi dma-hi )
217 drop set-limits ( mem-lo mem64-lo io-lo dma-lo )
218 3drop drop
219;
220
221\ Reduce the subordinate bus# to the maximum bus number of any
222\ of our children, and the memory and IO forwarding limits to
223\ the limits of the address space actually allocated. ...
224: (hp-free-unused-pci-resource) ( -- )
225 -1 allocate-bridge-resources ( mem-lo mem64-lo io-lo dma-lo mem-hi mem64-hi io-hi dma-hi bus# )
226 h# 1a my-b! ( mem-lo mem64-lo io-lo dma-lo mem-hi mem64-hi io-hi dma-hi )
227 drop set-limits ( mem-lo mem64-lo io-lo dma-lo )
228 3drop drop
229;