Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / pci / map.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: map.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: @(#)map.fth 1.18 07/06/22
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All rights reserved.
45copyright: Use is subject to license terms.
46
47\
48\ probe-state is a flag that notifies the map words to relocate a BAR if
49\ the requested size is greater than the currently allocated size.
50\ if probe-state? is true then the contents of the BAR storage array is also
51\ valid and we make use of that fact.
52\
53
54: is-enabled? ( phys.hi -- flag ) h# ff invert and 4 + self-w@ 7 and 0<> ;
55: expansion-rom? ( phys.hi -- flag )
56 h# ff and dup h# 30 = swap h# 38 = or
57;
58
59: probe-state-relocate ( p.lo p.mid p.hi len -- p.lo p.hi len )
60 2swap drop -rot ( p.lo p.hi len )
61 over expansion-rom? if exit then ( p.lo p.hi len )
62 over is-enabled? ( p.lo p.hi len flag )
63 probe-state? 0= or if exit then ( p.lo p.hi len )
64 over get-bar# >bar-struct ( p.lo p.hi len barstr )
65 dup >bar.implemented? @ if ( p.lo p.hi len barstr )
66 \ the element >bar.size is bumped to 64 bit
67 \ to take care of 64 bit pci address.
68 dup >r >bar.size x@ ( p.lo p.hi len size )
69 over x< if ( p.lo p.hi len )
70 over release-bar-resources ( p.lo p.hi len )
71 dup r@ >bar.size x! ( p.lo p.hi len )
72 over reassign-bar-resources ( p.lo p.hi len )
73 then ( p.lo p.hi len )
74 r> drop ( p.lo p.hi len )
75 else ( p.lo p.hi len barstr )
76 drop
77 then
78;
79
80: (pci-map-cfg) ( p.low p.mid p.hi len -- vaddr )
81 2swap 2drop ( p.hi len )
82 bus-map-cfg ( vadr )
83;
84
85: (pci-map-io) ( p.low p.mid p.hi len -- vaddr )
86 probe-state-relocate >r ( p.lo p.hi )
87 tuck self-l@ 3 invert and + 0 rot r> ( p.lo p.mid p.hi len )
88 bus-map-io ( vaddr )
89;
90
91: (pci-map-mem) ( p.low p.mid p.hi len incr -- vaddr )
92 >r probe-state-relocate >r ( p.lo p.hi )
93 tuck self-l@ h# f invert and + swap r> ( p.lo p.hi len )
94 r@ if ( p.lo p.hi len )
95 over r> + self-l@ -rot ( p.lo p.mid p.hi len )
96 else ( p.lo p.hi len )
97 r> drop 2>r 0 2r> ( p.lo p.mid p.hi len )
98 then ( p.lo p.hi len )
99 bus-map-mem ( vaddr )
100;
101
102: map-bar64-in-mem32 ( p.low p.mid p.hi len -- vaddr )
103 4 (pci-map-mem) ( vaddr )
104;
105
106defer (pci-map-mem64) ' map-bar64-in-mem32 is (pci-map-mem64)
107
108: $map-type ( n -- str-len )
109 case
110 01 of " I/O" endof
111 02 of " 32 bit memory" endof
112 03 of " 64 bit memory" endof
113 h# 43 of " 64 bit prefetchable memory" endof
114 \ Default
115 " unknown address space" rot
116 endcase
117;
118
119: .whine ( ss ss' -- ss' )
120 diagnostic-mode? if ( ss ss' )
121 cmn-warn[
122 swap $map-type 2 pick $map-type ( ss' str-len str-len' )
123 " FCODE map-in doesn't match decoded register type; Requested: %s, Decoded: %s"
124 ]cmn-end ( ss' )
125 else ( ss ss' )
126 nip ( ss' )
127 then ( ss' )
128;
129
130: verify-pci-map-in ( p.hi -- ss )
131 dup self-l@ 0= if ( p.hi )
132 \ BAR is not implemented
133 \ Just accept it
134 cfg>ss# exit
135 then
136
137 dup cfg>ss# dup if ( p.hi ss )
138 over get-bar# 5 <= if ( p.hi ss )
139 \ A memory/IO bar
140 swap self-l@ ( ss pa )
141 dup 1 and if ( ss pa )
142 \ IO bar..
143 1 7 ( ss pa type mask )
144 else ( ss pa )
145 \ Memory bar, convert
146 dup 1 >> 3 and case ( ss pa )
147 0 of h# 02 endof
148 1 of h# 82 endof
149 2 of ( ss pa )
150 \ check if prefetchable
151 dup 8 and if ( ss pa )
152 h# 43 ( ss pa type )
153 else
154 h# 03 ( ss pa type )
155 then
156 endof
157 3 of cmn-error[ " BAR has reserved bits set" ]cmn-end abort endof
158 endcase ( ss pa type )
159 h# f ( ss pa type mask )
160 then ( ss pa type mask )
161 else ( p.hi ss )
162 \ ROMBARs are always memory mapped.
163 swap self-l@ h# 02 h# f ( ss pa type mask )
164 then ( ss pa type mask )
165 rot and if ( ss type )
166 \ Note that for mem32 bar the lower 4-bits are zero
167 \ and hence this code does not get executed. This oversight
168 \ has been there for many years and changing that behaviour
169 \ now might introduce regression in some of the vendor fcodes.
170 2dup swap h# 7f and ( ss type type ss' )
171 <> if .whine exit then ( type )
172 then ( ss type )
173 then ( ss type )
174 nip ( type )
175;
176
177: pci-map-in ( p.low p.mid p.hi len -- vaddr )
178 over verify-pci-map-in
179 h# 7f and case
180 0 of (pci-map-cfg) endof
181 1 of (pci-map-io) endof
182 2 of 0 (pci-map-mem) endof
183 3 of 4 (pci-map-mem) endof
184 h# 43 of (pci-map-mem64) endof
185 endcase
186;