Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: pci.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: @(#)pci.fth 1.14 05/10/12 | |
43 | purpose: | |
44 | copyright: Copyright 2005 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headerless | |
48 | ||
49 | fload ${BP}/dev/pci/config-access.fth | |
50 | ||
51 | fload ${BP}/dev/pci/compatible.fth | |
52 | make-compatible-property | |
53 | ||
54 | external | |
55 | ||
56 | : map-in " map-in" $call-parent ; | |
57 | : map-out " map-out" $call-parent ; | |
58 | ||
59 | headerless | |
60 | ||
61 | \ Southbridge IDE controller's BARs are read only | |
62 | \ until the device is put into native mode | |
63 | [ifdef] M1575-workarounds | |
64 | 00 h# 43 my-b! \ unlock class code | |
65 | h# ff 09 my-b! \ switch to native mode | |
66 | [then] | |
67 | ||
68 | ||
69 | \ These two are just in case some PCI IDE card actually uses | |
70 | \ memory mapped regs rather than I/O | |
71 | 2 instance value reg-enable \ mem or I/O enable bit | |
72 | h# 0200.0000 instance value reg-type | |
73 | ||
74 | : bar>offset ( n -- offset ) h# 4 * h# 10 + ; | |
75 | ||
76 | : get-bar-n ( bar -- present? ) | |
77 | bar>offset ( offset ) | |
78 | my-l@ ( phys ) | |
79 | ?dup if ( phys ) | |
80 | 1 and if h# 1 else h# 2 then ( type ) | |
81 | is reg-enable true ( flag ) | |
82 | else ( -- ) | |
83 | false ( false ) | |
84 | then ( -- flag ) | |
85 | ; | |
86 | ||
87 | : bar>physhi ( bar -- phys-hi ) | |
88 | bar>offset ( offset ) | |
89 | reg-enable d# 24 << ( offset type ) | |
90 | my-space or or ( physhi ) | |
91 | ; | |
92 | ||
93 | : en+ ( xdr,len int -- xdr',len' ) encode-int encode+ ; | |
94 | : 0+ ( xdr,len 0 -- xdr',len' ) 0 en+ ; | |
95 | ||
96 | \ We need the PCI-prober to re-write the bars for ide so we | |
97 | \ make the reg property larger than the legacy BARs advertise. | |
98 | \ This causes reallocation. | |
99 | : reg+ ( xdr,len bar len -- xdr,len ) | |
100 | [ifdef] M1575-workarounds | |
101 | h# 20 + | |
102 | [then] | |
103 | >r bar>physhi en+ 0+ 0+ 0+ r> en+ | |
104 | ; | |
105 | ||
106 | : create-reg-property ( -- ) | |
107 | my-space encode-int 0+ 0+ 0+ 0+ ( xdr,len ) | |
108 | -1 is secondary? ( xdr,len ) | |
109 | 4 0 do ( xdr,len ) | |
110 | i get-bar-n if ( xdr,len ) | |
111 | i h# 8 reg+ ( xdr,len ) | |
112 | i 1+ dup get-bar-n drop h# 4 reg+ ( xdr,len ) | |
113 | secondary? 1+ is secondary? ( xdr,len ) | |
114 | then ( xdr,len ) | |
115 | 2 +loop ( xdr,len ) | |
116 | 9 my-b@ h# 80 and if | |
117 | secondary? if 4 else 2 then ( xdr,len DMA ) | |
118 | dup get-bar-n if ( xdr,len DMA ) | |
119 | h# 10 reg+ ( xdr,len ) | |
120 | else ( xdr,len ) | |
121 | drop ( xdr,len ) | |
122 | then ( xdr,len ) | |
123 | then ( xdr,len ) | |
124 | " reg" property ( -- ) | |
125 | ; | |
126 | ||
127 | create-reg-property | |
128 | ||
129 | : map-bar-n ( bar -- ) | |
130 | dup get-bar-n if ( bar ) | |
131 | dup bar>physhi my-address rot h# 8 map-in ( bar va ) | |
132 | else ( bar va ) | |
133 | 0 ( bar va ) | |
134 | then ( bar va ) | |
135 | reg-array rot na+ ! ( -- ) | |
136 | ; | |
137 | ||
138 | : enable-ide ( on|off -- ) | |
139 | 4 my-w@ reg-enable rot ( on? data bit ) | |
140 | if or else not and then ( data' ) | |
141 | 4 my-w! ( -- ) | |
142 | ; | |
143 | ||
144 | : map-regs ( -- ) | |
145 | reg-array @ if exit then | |
146 | 4 0 do i map-bar-n loop 1 enable-ide | |
147 | ; | |
148 | ||
149 | : ?unmap ( base index size -- ) | |
150 | -rot na+ dup >r @ 0 r> ! ( size va ) | |
151 | ?dup if ( size va ) | |
152 | swap map-out ( -- ) | |
153 | else ( size ) | |
154 | drop ( -- ) | |
155 | then ( -- ) | |
156 | ; | |
157 | ||
158 | : unmap-regs ( -- ) | |
159 | 4 0 do | |
160 | reg-array i 2dup ( base index base index ) | |
161 | h# 8 ?unmap ( base index ) | |
162 | 1+ h# 4 ?unmap ( -- ) | |
163 | 2 +loop | |
164 | reg-array @ if exit then | |
165 | 0 enable-ide | |
166 | ; | |
167 | ||
168 | : .cmd-irq ( -- flag? ) | |
169 | interface if h# 10 h# 57 else h# 4 h# 50 then | |
170 | my-b@ and | |
171 | ; | |
172 | ||
173 | : setup-device ( vendor device -- ) | |
174 | over h# 1095 = over h# 646 = and if | |
175 | \ Broken CMD controller requires devices on the secondary | |
176 | \ channel or it generates interrupts because the IRQ floats | |
177 | \ This interface is disabled via a jumper but the BARs aren't | |
178 | \ so we need to initialise them BUT not use them because they | |
179 | \ cause BUS errors. | |
180 | h# 51 my-b@ h# 8 and is secondary? | |
181 | h# 30 h# 71 my-b! \ Disable interrupts | |
182 | ['] .cmd-irq is ide-irq? | |
183 | then | |
184 | 2drop | |
185 | ; | |
186 | ||
187 | 0 my-l@ lwsplit setup-device |