Rev 431 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 431 | Rev 593 | ||
---|---|---|---|
1 | $Revision: 431 $ |
- | |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3 | ;; ;; |
2 | ;; ;; |
4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
6 | ;; ;; |
5 | ;; ;; |
7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | 7 | ||
- | 8 | $Revision: 593 $ |
|
- | 9 | ||
8 | 10 | ||
9 | ;*************************************************************************** |
11 | ;*************************************************************************** |
10 | ; |
12 | ; |
11 | ; PCI CODE FOLLOWS |
13 | ; PCI CODE FOLLOWS |
12 | ; |
14 | ; |
13 | ; the following functions provide access to the PCI interface. |
15 | ; the following functions provide access to the PCI interface. |
14 | ; These functions are used by scan_bus, and also some ethernet drivers |
16 | ; These functions are used by scan_bus, and also some ethernet drivers |
15 | ; |
17 | ; |
16 | ;*************************************************************************** |
18 | ;*************************************************************************** |
17 | 19 | ||
18 | ; PCI Bus defines |
20 | ; PCI Bus defines |
19 | PCI_HEADER_TYPE equ 0x0e ;8 bit |
21 | PCI_HEADER_TYPE equ 0x0e ;8 bit |
20 | PCI_BASE_ADDRESS_0 equ 0x10 ;32 bit |
22 | PCI_BASE_ADDRESS_0 equ 0x10 ;32 bit |
21 | PCI_BASE_ADDRESS_5 equ 0x24 ;32 bits |
23 | PCI_BASE_ADDRESS_5 equ 0x24 ;32 bits |
22 | PCI_BASE_ADDRESS_SPACE_IO equ 0x01 |
24 | PCI_BASE_ADDRESS_SPACE_IO equ 0x01 |
23 | PCI_VENDOR_ID equ 0x00 ;16 bit |
25 | PCI_VENDOR_ID equ 0x00 ;16 bit |
24 | PCI_BASE_ADDRESS_IO_MASK equ 0xFFFFFFFC |
26 | PCI_BASE_ADDRESS_IO_MASK equ 0xFFFFFFFC |
25 | 27 | ||
26 | ;*************************************************************************** |
28 | ;*************************************************************************** |
27 | ; Function |
29 | ; Function |
28 | ; config_cmd |
30 | ; config_cmd |
29 | ; |
31 | ; |
30 | ; Description |
32 | ; Description |
31 | ; creates a command dword for use with the PCI bus |
33 | ; creates a command dword for use with the PCI bus |
32 | ; bus # in ebx |
34 | ; bus # in ebx |
33 | ; devfn in ecx |
35 | ; devfn in ecx |
34 | ; where in edx |
36 | ; where in edx |
35 | ; |
37 | ; |
36 | ; command dword returned in eax |
38 | ; command dword returned in eax |
37 | ; Only eax destroyed |
39 | ; Only eax destroyed |
38 | ;*************************************************************************** |
40 | ;*************************************************************************** |
39 | config_cmd: |
41 | config_cmd: |
40 | push ecx |
42 | push ecx |
41 | mov eax, ebx |
43 | mov eax, ebx |
42 | shl eax, 16 |
44 | shl eax, 16 |
43 | or eax, 0x80000000 |
45 | or eax, 0x80000000 |
44 | shl ecx, 8 |
46 | shl ecx, 8 |
45 | or eax, ecx |
47 | or eax, ecx |
46 | pop ecx |
48 | pop ecx |
47 | or eax, edx |
49 | or eax, edx |
48 | and eax, 0xFFFFFFFC |
50 | and eax, 0xFFFFFFFC |
49 | ret |
51 | ret |
50 | 52 | ||
51 | ;*************************************************************************** |
53 | ;*************************************************************************** |
52 | ; Function |
54 | ; Function |
53 | ; pcibios_read_config_byte |
55 | ; pcibios_read_config_byte |
54 | ; |
56 | ; |
55 | ; Description |
57 | ; Description |
56 | ; reads a byte from the PCI config space |
58 | ; reads a byte from the PCI config space |
57 | ; bus # in ebx |
59 | ; bus # in ebx |
58 | ; devfn in ecx |
60 | ; devfn in ecx |
59 | ; where in edx ( ls 16 bits significant ) |
61 | ; where in edx ( ls 16 bits significant ) |
60 | ; |
62 | ; |
61 | ; byte returned in al ( rest of eax zero ) |
63 | ; byte returned in al ( rest of eax zero ) |
62 | ; Only eax/edx destroyed |
64 | ; Only eax/edx destroyed |
63 | ;*************************************************************************** |
65 | ;*************************************************************************** |
64 | pcibios_read_config_byte: |
66 | pcibios_read_config_byte: |
65 | call config_cmd |
67 | call config_cmd |
66 | push dx |
68 | push dx |
67 | mov dx, 0xCF8 |
69 | mov dx, 0xCF8 |
68 | out dx, eax |
70 | out dx, eax |
69 | pop dx |
71 | pop dx |
70 | 72 | ||
71 | xor eax, eax |
73 | xor eax, eax |
72 | and dx, 0x03 |
74 | and dx, 0x03 |
73 | add dx, 0xCFC |
75 | add dx, 0xCFC |
74 | ; and dx, 0xFFC |
76 | ; and dx, 0xFFC |
75 | in al, dx |
77 | in al, dx |
76 | ret |
78 | ret |
77 | 79 | ||
78 | ;*************************************************************************** |
80 | ;*************************************************************************** |
79 | ; Function |
81 | ; Function |
80 | ; pcibios_read_config_word |
82 | ; pcibios_read_config_word |
81 | ; |
83 | ; |
82 | ; Description |
84 | ; Description |
83 | ; reads a word from the PCI config space |
85 | ; reads a word from the PCI config space |
84 | ; bus # in ebx |
86 | ; bus # in ebx |
85 | ; devfn in ecx |
87 | ; devfn in ecx |
86 | ; where in edx ( ls 16 bits significant ) |
88 | ; where in edx ( ls 16 bits significant ) |
87 | ; |
89 | ; |
88 | ; word returned in ax ( rest of eax zero ) |
90 | ; word returned in ax ( rest of eax zero ) |
89 | ; Only eax/edx destroyed |
91 | ; Only eax/edx destroyed |
90 | ;*************************************************************************** |
92 | ;*************************************************************************** |
91 | pcibios_read_config_word: |
93 | pcibios_read_config_word: |
92 | call config_cmd |
94 | call config_cmd |
93 | push dx |
95 | push dx |
94 | mov dx, 0xCF8 |
96 | mov dx, 0xCF8 |
95 | out dx, eax |
97 | out dx, eax |
96 | pop dx |
98 | pop dx |
97 | 99 | ||
98 | xor eax, eax |
100 | xor eax, eax |
99 | and dx, 0x02 |
101 | and dx, 0x02 |
100 | add dx, 0xCFC |
102 | add dx, 0xCFC |
101 | ; and dx, 0xFFC |
103 | ; and dx, 0xFFC |
102 | in ax, dx |
104 | in ax, dx |
103 | ret |
105 | ret |
104 | 106 | ||
105 | ;*************************************************************************** |
107 | ;*************************************************************************** |
106 | ; Function |
108 | ; Function |
107 | ; pcibios_read_config_dword |
109 | ; pcibios_read_config_dword |
108 | ; |
110 | ; |
109 | ; Description |
111 | ; Description |
110 | ; reads a dword from the PCI config space |
112 | ; reads a dword from the PCI config space |
111 | ; bus # in ebx |
113 | ; bus # in ebx |
112 | ; devfn in ecx |
114 | ; devfn in ecx |
113 | ; where in edx ( ls 16 bits significant ) |
115 | ; where in edx ( ls 16 bits significant ) |
114 | ; |
116 | ; |
115 | ; dword returned in eax |
117 | ; dword returned in eax |
116 | ; Only eax/edx destroyed |
118 | ; Only eax/edx destroyed |
117 | ;*************************************************************************** |
119 | ;*************************************************************************** |
118 | pcibios_read_config_dword: |
120 | pcibios_read_config_dword: |
119 | push edx |
121 | push edx |
120 | call config_cmd |
122 | call config_cmd |
121 | push dx |
123 | push dx |
122 | mov dx, 0xCF8 |
124 | mov dx, 0xCF8 |
123 | out dx, eax |
125 | out dx, eax |
124 | pop dx |
126 | pop dx |
125 | xor eax, eax |
127 | xor eax, eax |
126 | mov dx, 0xCFC |
128 | mov dx, 0xCFC |
127 | in eax, dx |
129 | in eax, dx |
128 | pop edx |
130 | pop edx |
129 | ret |
131 | ret |
130 | 132 | ||
131 | ;*************************************************************************** |
133 | ;*************************************************************************** |
132 | ; Function |
134 | ; Function |
133 | ; pcibios_write_config_byte |
135 | ; pcibios_write_config_byte |
134 | ; |
136 | ; |
135 | ; Description |
137 | ; Description |
136 | ; write a byte in al to the PCI config space |
138 | ; write a byte in al to the PCI config space |
137 | ; bus # in ebx |
139 | ; bus # in ebx |
138 | ; devfn in ecx |
140 | ; devfn in ecx |
139 | ; where in edx ( ls 16 bits significant ) |
141 | ; where in edx ( ls 16 bits significant ) |
140 | ; |
142 | ; |
141 | ; Only eax/edx destroyed |
143 | ; Only eax/edx destroyed |
142 | ;*************************************************************************** |
144 | ;*************************************************************************** |
143 | pcibios_write_config_byte: |
145 | pcibios_write_config_byte: |
144 | push ax |
146 | push ax |
145 | call config_cmd |
147 | call config_cmd |
146 | push dx |
148 | push dx |
147 | mov dx, 0xCF8 |
149 | mov dx, 0xCF8 |
148 | out dx, eax |
150 | out dx, eax |
149 | pop dx |
151 | pop dx |
150 | pop ax |
152 | pop ax |
151 | 153 | ||
152 | and dx, 0x03 |
154 | and dx, 0x03 |
153 | add dx, 0xCFC |
155 | add dx, 0xCFC |
154 | out dx, al |
156 | out dx, al |
155 | ret |
157 | ret |
156 | 158 | ||
157 | ;*************************************************************************** |
159 | ;*************************************************************************** |
158 | ; Function |
160 | ; Function |
159 | ; pcibios_write_config_word |
161 | ; pcibios_write_config_word |
160 | ; |
162 | ; |
161 | ; Description |
163 | ; Description |
162 | ; write a word in ax to the PCI config space |
164 | ; write a word in ax to the PCI config space |
163 | ; bus # in ebx |
165 | ; bus # in ebx |
164 | ; devfn in ecx |
166 | ; devfn in ecx |
165 | ; where in edx ( ls 16 bits significant ) |
167 | ; where in edx ( ls 16 bits significant ) |
166 | ; |
168 | ; |
167 | ; Only eax/edx destroyed |
169 | ; Only eax/edx destroyed |
168 | ;*************************************************************************** |
170 | ;*************************************************************************** |
169 | pcibios_write_config_word: |
171 | pcibios_write_config_word: |
170 | push ax |
172 | push ax |
171 | call config_cmd |
173 | call config_cmd |
172 | push dx |
174 | push dx |
173 | mov dx, 0xCF8 |
175 | mov dx, 0xCF8 |
174 | out dx, eax |
176 | out dx, eax |
175 | pop dx |
177 | pop dx |
176 | pop ax |
178 | pop ax |
177 | 179 | ||
178 | and dx, 0x02 |
180 | and dx, 0x02 |
179 | add dx, 0xCFC |
181 | add dx, 0xCFC |
180 | out dx, ax |
182 | out dx, ax |
181 | ret |
183 | ret |
182 | 184 | ||
183 | ;*************************************************************************** |
185 | ;*************************************************************************** |
184 | ; Function |
186 | ; Function |
185 | ; delay_us |
187 | ; delay_us |
186 | ; |
188 | ; |
187 | ; Description |
189 | ; Description |
188 | ; delays for 30 to 60 us |
190 | ; delays for 30 to 60 us |
189 | ; |
191 | ; |
190 | ; I would prefer this routine to be able to delay for |
192 | ; I would prefer this routine to be able to delay for |
191 | ; a selectable number of microseconds, but this works for now. |
193 | ; a selectable number of microseconds, but this works for now. |
192 | ; |
194 | ; |
193 | ; If you know a better way to do 2us delay, pleae tell me! |
195 | ; If you know a better way to do 2us delay, pleae tell me! |
194 | ;*************************************************************************** |
196 | ;*************************************************************************** |
195 | delay_us: |
197 | delay_us: |
196 | push eax |
198 | push eax |
197 | push ecx |
199 | push ecx |
198 | 200 | ||
199 | mov ecx,2 |
201 | mov ecx,2 |
200 | 202 | ||
201 | in al,0x61 |
203 | in al,0x61 |
202 | and al,0x10 |
204 | and al,0x10 |
203 | mov ah,al |
205 | mov ah,al |
204 | cld |
206 | cld |
205 | 207 | ||
206 | dcnt1: |
208 | dcnt1: |
207 | in al,0x61 |
209 | in al,0x61 |
208 | and al,0x10 |
210 | and al,0x10 |
209 | cmp al,ah |
211 | cmp al,ah |
210 | jz dcnt1 |
212 | jz dcnt1 |
211 | 213 | ||
212 | mov ah,al |
214 | mov ah,al |
213 | loop dcnt1 |
215 | loop dcnt1 |
214 | 216 | ||
215 | pop ecx |
217 | pop ecx |
216 | pop eax |
218 | pop eax |
217 | 219 | ||
218 | ret |
220 | ret |
219 | 221 | ||
220 | ;*************************************************************************** |
222 | ;*************************************************************************** |
221 | ; Function |
223 | ; Function |
222 | ; scan_bus |
224 | ; scan_bus |
223 | ; |
225 | ; |
224 | ; Description |
226 | ; Description |
225 | ; Scans the PCI bus for a supported device |
227 | ; Scans the PCI bus for a supported device |
226 | ; If a supported device is found, the drvr_ variables are initialised |
228 | ; If a supported device is found, the drvr_ variables are initialised |
227 | ; to that drivers functions ( as defined in the PCICards table) |
229 | ; to that drivers functions ( as defined in the PCICards table) |
228 | ; |
230 | ; |
229 | ; io_addr holds card I/O space. 32 bit, but only LS 16 bits valid |
231 | ; io_addr holds card I/O space. 32 bit, but only LS 16 bits valid |
230 | ; pci_data holds the PCI vendor + device code |
232 | ; pci_data holds the PCI vendor + device code |
231 | ; pci_dev holds PCI bus dev # |
233 | ; pci_dev holds PCI bus dev # |
232 | ; pci_bus holds PCI bus # |
234 | ; pci_bus holds PCI bus # |
233 | ; |
235 | ; |
234 | ; io_addr will be zero if no card found |
236 | ; io_addr will be zero if no card found |
235 | ; |
237 | ; |
236 | ;*************************************************************************** |
238 | ;*************************************************************************** |
237 | scan_bus: |
239 | scan_bus: |
238 | xor eax, eax |
240 | xor eax, eax |
239 | mov [hdrtype], al |
241 | mov [hdrtype], al |
240 | mov [pci_data], eax |
242 | mov [pci_data], eax |
241 | 243 | ||
242 | xor ebx, ebx ; ebx = bus# 0 .. 255 |
244 | xor ebx, ebx ; ebx = bus# 0 .. 255 |
243 | 245 | ||
244 | sb_bus_loop: |
246 | sb_bus_loop: |
245 | xor ecx, ecx ; ecx = devfn# 0 .. 254 ( not 255? ) |
247 | xor ecx, ecx ; ecx = devfn# 0 .. 254 ( not 255? ) |
246 | 248 | ||
247 | sb_devf_loop: |
249 | sb_devf_loop: |
248 | mov eax, ecx |
250 | mov eax, ecx |
249 | and eax, 0x07 |
251 | and eax, 0x07 |
250 | 252 | ||
251 | cmp eax, 0 |
253 | cmp eax, 0 |
252 | jne sb_001 |
254 | jne sb_001 |
253 | 255 | ||
254 | mov edx, PCI_HEADER_TYPE |
256 | mov edx, PCI_HEADER_TYPE |
255 | call pcibios_read_config_byte |
257 | call pcibios_read_config_byte |
256 | mov [hdrtype], al |
258 | mov [hdrtype], al |
257 | jmp sb_002 |
259 | jmp sb_002 |
258 | 260 | ||
259 | sb_001: |
261 | sb_001: |
260 | mov al, [hdrtype] |
262 | mov al, [hdrtype] |
261 | and al, 0x80 |
263 | and al, 0x80 |
262 | cmp al, 0x80 |
264 | cmp al, 0x80 |
263 | jne sb_inc_devf |
265 | jne sb_inc_devf |
264 | 266 | ||
265 | sb_002: |
267 | sb_002: |
266 | mov edx, PCI_VENDOR_ID |
268 | mov edx, PCI_VENDOR_ID |
267 | call pcibios_read_config_dword |
269 | call pcibios_read_config_dword |
268 | mov [vendor_device], eax |
270 | mov [vendor_device], eax |
269 | cmp eax, 0xffffffff |
271 | cmp eax, 0xffffffff |
270 | je sb_empty |
272 | je sb_empty |
271 | cmp eax, 0 |
273 | cmp eax, 0 |
272 | jne sb_check_vendor |
274 | jne sb_check_vendor |
273 | 275 | ||
274 | sb_empty: |
276 | sb_empty: |
275 | mov [hdrtype], byte 0 |
277 | mov [hdrtype], byte 0 |
276 | jmp sb_inc_devf |
278 | jmp sb_inc_devf |
277 | 279 | ||
278 | sb_check_vendor: |
280 | sb_check_vendor: |
279 | ; iterate though PCICards until end or match found |
281 | ; iterate though PCICards until end or match found |
280 | mov esi, PCICards |
282 | mov esi, PCICards |
281 | 283 | ||
282 | sb_check: |
284 | sb_check: |
283 | cmp [esi], dword 0 |
285 | cmp [esi], dword 0 |
284 | je sb_inc_devf ; Quit if at last entry |
286 | je sb_inc_devf ; Quit if at last entry |
285 | cmp eax, [esi] |
287 | cmp eax, [esi] |
286 | je sb_got_card |
288 | je sb_got_card |
287 | add esi, PCICARDS_ENTRY_SIZE |
289 | add esi, PCICARDS_ENTRY_SIZE |
288 | jmp sb_check |
290 | jmp sb_check |
289 | 291 | ||
290 | sb_got_card: |
292 | sb_got_card: |
291 | ; indicate that we have found the card |
293 | ; indicate that we have found the card |
292 | mov [pci_data], eax |
294 | mov [pci_data], eax |
293 | mov [pci_dev], ecx |
295 | mov [pci_dev], ecx |
294 | mov [pci_bus], ebx |
296 | mov [pci_bus], ebx |
295 | 297 | ||
296 | ; Define the driver functions |
298 | ; Define the driver functions |
297 | push eax |
299 | push eax |
298 | mov eax, [esi+4] |
300 | mov eax, [esi+4] |
299 | mov [drvr_probe], eax |
301 | mov [drvr_probe], eax |
300 | mov eax, [esi+8] |
302 | mov eax, [esi+8] |
301 | mov [drvr_reset], eax |
303 | mov [drvr_reset], eax |
302 | mov eax, [esi+12] |
304 | mov eax, [esi+12] |
303 | mov [drvr_poll], eax |
305 | mov [drvr_poll], eax |
304 | mov eax, [esi+16] |
306 | mov eax, [esi+16] |
305 | mov [drvr_transmit], eax |
307 | mov [drvr_transmit], eax |
306 | mov eax, [esi+20] |
308 | mov eax, [esi+20] |
307 | mov [drvr_cable], eax |
309 | mov [drvr_cable], eax |
308 | pop eax |
310 | pop eax |
309 | 311 | ||
310 | mov edx, PCI_BASE_ADDRESS_0 |
312 | mov edx, PCI_BASE_ADDRESS_0 |
311 | 313 | ||
312 | sb_reg_check: |
314 | sb_reg_check: |
313 | call pcibios_read_config_dword |
315 | call pcibios_read_config_dword |
314 | mov [io_addr], eax |
316 | mov [io_addr], eax |
315 | and eax, PCI_BASE_ADDRESS_IO_MASK |
317 | and eax, PCI_BASE_ADDRESS_IO_MASK |
316 | cmp eax, 0 |
318 | cmp eax, 0 |
317 | je sb_inc_reg |
319 | je sb_inc_reg |
318 | mov eax, [io_addr] |
320 | mov eax, [io_addr] |
319 | and eax, PCI_BASE_ADDRESS_SPACE_IO |
321 | and eax, PCI_BASE_ADDRESS_SPACE_IO |
320 | cmp eax, 0 |
322 | cmp eax, 0 |
321 | je sb_inc_reg |
323 | je sb_inc_reg |
322 | 324 | ||
323 | mov eax, [io_addr] |
325 | mov eax, [io_addr] |
324 | and eax, PCI_BASE_ADDRESS_IO_MASK |
326 | and eax, PCI_BASE_ADDRESS_IO_MASK |
325 | mov [io_addr], eax |
327 | mov [io_addr], eax |
326 | 328 | ||
327 | sb_exit1: |
329 | sb_exit1: |
328 | ret |
330 | ret |
329 | 331 | ||
330 | sb_inc_reg: |
332 | sb_inc_reg: |
331 | add edx, 4 |
333 | add edx, 4 |
332 | cmp edx, PCI_BASE_ADDRESS_5 |
334 | cmp edx, PCI_BASE_ADDRESS_5 |
333 | jbe sb_reg_check |
335 | jbe sb_reg_check |
334 | 336 | ||
335 | sb_inc_devf: |
337 | sb_inc_devf: |
336 | inc ecx |
338 | inc ecx |
337 | cmp ecx, 255 |
339 | cmp ecx, 255 |
338 | jb sb_devf_loop |
340 | jb sb_devf_loop |
339 | inc ebx |
341 | inc ebx |
340 | cmp ebx, 256 |
342 | cmp ebx, 256 |
341 | jb sb_bus_loop |
343 | jb sb_bus_loop |
342 | 344 | ||
343 | ; We get here if we didn't find our card |
345 | ; We get here if we didn't find our card |
344 | ; set io_addr to 0 as an indication |
346 | ; set io_addr to 0 as an indication |
345 | xor eax, eax |
347 | xor eax, eax |
346 | mov [io_addr], eax |
348 | mov [io_addr], eax |
347 | 349 | ||
348 | sb_exit2: |
350 | sb_exit2: |
349 | ret |
351 | ret |