Rev 1629 | Rev 2288 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
586 | serge | 2 | ;; ;; |
1602 | art_zh | 3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
431 | serge | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; ;; |
||
586 | serge | 7 | ;; PCI32.INC ;; |
8 | ;; ;; |
||
9 | ;; 32 bit PCI driver code ;; |
||
10 | ;; ;; |
||
11 | ;; Version 0.3 April 9, 2007 ;; |
||
12 | ;; Version 0.2 December 21st, 2002 ;; |
||
13 | ;; ;; |
||
14 | ;; Author: Victor Prodan, victorprodan@yahoo.com ;; |
||
15 | ;; Mihailov Ilia, ghost.nsk@gmail.com ;; |
||
16 | ;; Credits: ;; |
||
17 | ;; Ralf Brown ;; |
||
18 | ;; Mike Hibbett, mikeh@oceanfree.net ;; |
||
19 | ;; ;; |
||
20 | ;; See file COPYING for details ;; |
||
21 | ;; ;; |
||
431 | serge | 22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ha | 23 | |
750 | victor | 24 | $Revision: 1949 $ |
1 | ha | 25 | |
26 | ;*************************************************************************** |
||
27 | ; Function |
||
28 | ; pci_api: |
||
29 | ; |
||
30 | ; Description |
||
31 | ; entry point for system PCI calls |
||
32 | ;*************************************************************************** |
||
1603 | art_zh | 33 | ;mmio_pci_addr equ 0x400 ; set actual PCI address here to activate user-MMIO |
1 | ha | 34 | |
1591 | lrz | 35 | iglobal |
36 | align 4 |
||
37 | f62call: |
||
1602 | art_zh | 38 | dd pci_fn_0 |
39 | dd pci_fn_1 |
||
40 | dd pci_fn_2 |
||
41 | dd pci_service_not_supported ;3 |
||
1591 | lrz | 42 | dd pci_read_reg ;4 byte |
1603 | art_zh | 43 | dd pci_read_reg ;5 word |
44 | dd pci_read_reg ;6 dword |
||
45 | dd pci_service_not_supported ;7 |
||
46 | dd pci_write_reg ;8 byte |
||
47 | dd pci_write_reg ;9 word |
||
48 | dd pci_write_reg ;10 dword |
||
1591 | lrz | 49 | if defined mmio_pci_addr |
50 | dd pci_mmio_init ;11 |
||
51 | dd pci_mmio_map ;12 |
||
52 | dd pci_mmio_unmap ;13 |
||
53 | end if |
||
1602 | art_zh | 54 | |
1591 | lrz | 55 | endg |
1370 | art_zh | 56 | |
1602 | art_zh | 57 | align 4 |
1591 | lrz | 58 | |
1 | ha | 59 | pci_api: |
60 | |||
1602 | art_zh | 61 | ;cross |
1614 | serge | 62 | mov eax,ebx |
1602 | art_zh | 63 | mov ebx,ecx |
64 | mov ecx,edx |
||
65 | |||
1614 | serge | 66 | cmp [pci_access_enabled],1 |
67 | jne pci_service_not_supported |
||
68 | |||
69 | movzx edx, al |
||
70 | |||
1591 | lrz | 71 | if defined mmio_pci_addr |
1614 | serge | 72 | cmp al, 13 |
1603 | art_zh | 73 | ja pci_service_not_supported |
1591 | lrz | 74 | else |
1614 | serge | 75 | cmp al, 10 |
1603 | art_zh | 76 | ja pci_service_not_supported |
1602 | art_zh | 77 | end if |
1603 | art_zh | 78 | |
79 | call dword [f62call+edx*4] |
||
80 | mov dword [esp+32],eax |
||
81 | ret |
||
1629 | serge | 82 | |
83 | |||
84 | align 4 |
||
85 | pci_api_drv: |
||
86 | |||
87 | cmp [pci_access_enabled],1 |
||
88 | jne .fail |
||
89 | |||
90 | cmp eax, 2 |
||
91 | ja .fail |
||
92 | |||
93 | jmp dword [f62call+eax*4] |
||
94 | |||
95 | .fail: |
||
96 | or eax,-1 |
||
97 | ret |
||
98 | |||
99 | |||
1602 | art_zh | 100 | ;; ============================================ |
1591 | lrz | 101 | |
1602 | art_zh | 102 | pci_fn_0: |
103 | ; PCI function 0: get pci version (AH.AL) |
||
104 | movzx eax,word [BOOT_VAR+0x9022] |
||
1348 | art_zh | 105 | ret |
1 | ha | 106 | |
1602 | art_zh | 107 | pci_fn_1: |
108 | ; PCI function 1: get last bus in AL |
||
109 | mov al,[BOOT_VAR+0x9021] |
||
1348 | art_zh | 110 | ret |
1 | ha | 111 | |
1602 | art_zh | 112 | pci_fn_2: |
113 | ; PCI function 2: get pci access mechanism |
||
114 | mov al,[BOOT_VAR+0x9020] |
||
1348 | art_zh | 115 | ret |
1 | ha | 116 | |
1602 | art_zh | 117 | pci_service_not_supported: |
118 | or eax,-1 |
||
1603 | art_zh | 119 | mov dword [esp+32],eax |
1348 | art_zh | 120 | ret |
1 | ha | 121 | |
122 | ;*************************************************************************** |
||
123 | ; Function |
||
124 | ; pci_make_config_cmd |
||
125 | ; |
||
126 | ; Description |
||
127 | ; creates a command dword for use with the PCI bus |
||
1602 | art_zh | 128 | ; bus # in ah |
129 | ; device+func in bh (dddddfff) |
||
130 | ; register in bl |
||
1 | ha | 131 | ; |
1602 | art_zh | 132 | ; command dword returned in eax ( 10000000 bbbbbbbb dddddfff rrrrrr00 ) |
1 | ha | 133 | ;*************************************************************************** |
134 | |||
135 | align 4 |
||
136 | |||
137 | pci_make_config_cmd: |
||
1602 | art_zh | 138 | shl eax,8 ; move bus to bits 16-23 |
139 | mov ax,bx ; combine all |
||
140 | and eax,0xffffff |
||
141 | or eax,0x80000000 |
||
1 | ha | 142 | ret |
143 | |||
144 | ;*************************************************************************** |
||
145 | ; Function |
||
146 | ; pci_read_reg: |
||
147 | ; |
||
148 | ; Description |
||
149 | ; read a register from the PCI config space into EAX/AX/AL |
||
1602 | art_zh | 150 | ; IN: ah=bus,device+func=bh,register address=bl |
151 | ; number of bytes to read (1,2,4) coded into AL, bits 0-1 |
||
586 | serge | 152 | ; (0 - byte, 1 - word, 2 - dword) |
1 | ha | 153 | ;*************************************************************************** |
154 | |||
155 | align 4 |
||
156 | |||
157 | pci_read_reg: |
||
1348 | art_zh | 158 | cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? |
159 | je pci_read_reg_2 |
||
1 | ha | 160 | |
1348 | art_zh | 161 | ; mechanism 1 |
1602 | art_zh | 162 | push esi ; save register size into ESI |
163 | mov esi,eax |
||
1348 | art_zh | 164 | and esi,3 |
1 | ha | 165 | |
1348 | art_zh | 166 | call pci_make_config_cmd |
1602 | art_zh | 167 | mov ebx,eax |
1348 | art_zh | 168 | ; get current state |
169 | mov dx,0xcf8 |
||
170 | in eax, dx |
||
171 | push eax |
||
172 | ; set up addressing to config data |
||
173 | mov eax,ebx |
||
174 | and al,0xfc ; make address dword-aligned |
||
175 | out dx,eax |
||
176 | ; get requested DWORD of config data |
||
177 | mov dl,0xfc |
||
178 | and bl,3 |
||
179 | or dl,bl ; add to port address first 2 bits of register address |
||
1 | ha | 180 | |
1602 | art_zh | 181 | or esi,esi |
182 | jz pci_read_byte1 |
||
183 | cmp esi,1 |
||
184 | jz pci_read_word1 |
||
185 | cmp esi,2 |
||
186 | jz pci_read_dword1 |
||
187 | jmp pci_fin_read1 |
||
1 | ha | 188 | |
1602 | art_zh | 189 | pci_read_byte1: |
1348 | art_zh | 190 | in al,dx |
1602 | art_zh | 191 | jmp pci_fin_read1 |
192 | pci_read_word1: |
||
1348 | art_zh | 193 | in ax,dx |
1602 | art_zh | 194 | jmp pci_fin_read1 |
195 | pci_read_dword1: |
||
1348 | art_zh | 196 | in eax,dx |
1602 | art_zh | 197 | jmp pci_fin_read1 |
198 | pci_fin_read1: |
||
1348 | art_zh | 199 | ; restore configuration control |
200 | xchg eax,[esp] |
||
201 | mov dx,0xcf8 |
||
202 | out dx,eax |
||
1 | ha | 203 | |
1348 | art_zh | 204 | pop eax |
1602 | art_zh | 205 | pop esi |
1348 | art_zh | 206 | ret |
1 | ha | 207 | pci_read_reg_2: |
208 | |||
1602 | art_zh | 209 | test bh,128 ;mech#2 only supports 16 devices per bus |
210 | jnz pci_read_reg_err |
||
1 | ha | 211 | |
1602 | art_zh | 212 | push esi ; save register size into ESI |
213 | mov esi,eax |
||
1348 | art_zh | 214 | and esi,3 |
1 | ha | 215 | |
1602 | art_zh | 216 | push eax |
1348 | art_zh | 217 | ;store current state of config space |
218 | mov dx,0xcf8 |
||
219 | in al,dx |
||
220 | mov ah,al |
||
221 | mov dl,0xfa |
||
222 | in al,dx |
||
1 | ha | 223 | |
1348 | art_zh | 224 | xchg eax,[esp] |
225 | ; out 0xcfa,bus |
||
226 | mov al,ah |
||
227 | out dx,al |
||
228 | ; out 0xcf8,0x80 |
||
229 | mov dl,0xf8 |
||
230 | mov al,0x80 |
||
231 | out dx,al |
||
232 | ; compute addr |
||
1602 | art_zh | 233 | shr bh,3 ; func is ignored in mechanism 2 |
234 | or bh,0xc0 |
||
235 | mov dx,bx |
||
1 | ha | 236 | |
1602 | art_zh | 237 | or esi,esi |
238 | jz pci_read_byte2 |
||
239 | cmp esi,1 |
||
240 | jz pci_read_word2 |
||
241 | cmp esi,2 |
||
242 | jz pci_read_dword2 |
||
243 | jmp pci_fin_read2 |
||
1 | ha | 244 | |
1602 | art_zh | 245 | pci_read_byte2: |
1348 | art_zh | 246 | in al,dx |
1602 | art_zh | 247 | jmp pci_fin_read2 |
248 | pci_read_word2: |
||
1348 | art_zh | 249 | in ax,dx |
1602 | art_zh | 250 | jmp pci_fin_read2 |
251 | pci_read_dword2: |
||
1348 | art_zh | 252 | in eax,dx |
1 | ha | 253 | ; jmp pci_fin_read2 |
1602 | art_zh | 254 | pci_fin_read2: |
1 | ha | 255 | |
1348 | art_zh | 256 | ; restore configuration space |
257 | xchg eax,[esp] |
||
258 | mov dx,0xcfa |
||
259 | out dx,al |
||
260 | mov dl,0xf8 |
||
261 | mov al,ah |
||
262 | out dx,al |
||
1 | ha | 263 | |
1348 | art_zh | 264 | pop eax |
1602 | art_zh | 265 | pop esi |
1348 | art_zh | 266 | ret |
1 | ha | 267 | |
1602 | art_zh | 268 | pci_read_reg_err: |
269 | xor eax,eax |
||
270 | dec eax |
||
271 | ret |
||
1 | ha | 272 | |
273 | |||
274 | ;*************************************************************************** |
||
275 | ; Function |
||
276 | ; pci_write_reg: |
||
277 | ; |
||
278 | ; Description |
||
279 | ; write a register from ECX/CX/CL into the PCI config space |
||
1602 | art_zh | 280 | ; IN: ah=bus,device+func=bh,register address (dword aligned)=bl, |
281 | ; value to write in ecx |
||
282 | ; number of bytes to write (1,2,4) coded into AL, bits 0-1 |
||
586 | serge | 283 | ; (0 - byte, 1 - word, 2 - dword) |
1 | ha | 284 | ;*************************************************************************** |
285 | |||
286 | align 4 |
||
287 | |||
288 | pci_write_reg: |
||
1348 | art_zh | 289 | cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? |
290 | je pci_write_reg_2 |
||
1 | ha | 291 | |
1348 | art_zh | 292 | ; mechanism 1 |
1602 | art_zh | 293 | push esi ; save register size into ESI |
294 | mov esi,eax |
||
295 | and esi,3 |
||
1 | ha | 296 | |
1348 | art_zh | 297 | call pci_make_config_cmd |
1602 | art_zh | 298 | mov ebx,eax |
1348 | art_zh | 299 | ; get current state into ecx |
300 | mov dx,0xcf8 |
||
301 | in eax, dx |
||
302 | push eax |
||
303 | ; set up addressing to config data |
||
304 | mov eax,ebx |
||
305 | and al,0xfc ; make address dword-aligned |
||
306 | out dx,eax |
||
307 | ; write DWORD of config data |
||
308 | mov dl,0xfc |
||
309 | and bl,3 |
||
310 | or dl,bl |
||
311 | mov eax,ecx |
||
1 | ha | 312 | |
1602 | art_zh | 313 | or esi,esi |
314 | jz pci_write_byte1 |
||
315 | cmp esi,1 |
||
316 | jz pci_write_word1 |
||
317 | cmp esi,2 |
||
318 | jz pci_write_dword1 |
||
319 | jmp pci_fin_write1 |
||
320 | |||
321 | pci_write_byte1: |
||
1348 | art_zh | 322 | out dx,al |
1602 | art_zh | 323 | jmp pci_fin_write1 |
324 | pci_write_word1: |
||
1348 | art_zh | 325 | out dx,ax |
1602 | art_zh | 326 | jmp pci_fin_write1 |
327 | pci_write_dword1: |
||
1348 | art_zh | 328 | out dx,eax |
1602 | art_zh | 329 | jmp pci_fin_write1 |
330 | pci_fin_write1: |
||
1 | ha | 331 | |
1348 | art_zh | 332 | ; restore configuration control |
333 | pop eax |
||
334 | mov dl,0xf8 |
||
335 | out dx,eax |
||
1 | ha | 336 | |
1348 | art_zh | 337 | xor eax,eax |
1602 | art_zh | 338 | pop esi |
339 | |||
1348 | art_zh | 340 | ret |
1 | ha | 341 | pci_write_reg_2: |
342 | |||
1602 | art_zh | 343 | test bh,128 ;mech#2 only supports 16 devices per bus |
344 | jnz pci_write_reg_err |
||
1 | ha | 345 | |
346 | |||
1602 | art_zh | 347 | push esi ; save register size into ESI |
1348 | art_zh | 348 | mov esi,eax |
1602 | art_zh | 349 | and esi,3 |
1 | ha | 350 | |
1348 | art_zh | 351 | push eax |
352 | ;store current state of config space |
||
353 | mov dx,0xcf8 |
||
354 | in al,dx |
||
355 | mov ah,al |
||
356 | mov dl,0xfa |
||
357 | in al,dx |
||
358 | xchg eax,[esp] |
||
359 | ; out 0xcfa,bus |
||
360 | mov al,ah |
||
361 | out dx,al |
||
362 | ; out 0xcf8,0x80 |
||
363 | mov dl,0xf8 |
||
364 | mov al,0x80 |
||
365 | out dx,al |
||
366 | ; compute addr |
||
367 | shr bh,3 ; func is ignored in mechanism 2 |
||
368 | or bh,0xc0 |
||
369 | mov dx,bx |
||
370 | ; write register |
||
371 | mov eax,ecx |
||
1 | ha | 372 | |
1602 | art_zh | 373 | or esi,esi |
374 | jz pci_write_byte2 |
||
375 | cmp esi,1 |
||
376 | jz pci_write_word2 |
||
377 | cmp esi,2 |
||
378 | jz pci_write_dword2 |
||
379 | jmp pci_fin_write2 |
||
380 | |||
381 | pci_write_byte2: |
||
1348 | art_zh | 382 | out dx,al |
1602 | art_zh | 383 | jmp pci_fin_write2 |
384 | pci_write_word2: |
||
1348 | art_zh | 385 | out dx,ax |
1602 | art_zh | 386 | jmp pci_fin_write2 |
387 | pci_write_dword2: |
||
1348 | art_zh | 388 | out dx,eax |
1602 | art_zh | 389 | jmp pci_fin_write2 |
390 | pci_fin_write2: |
||
1348 | art_zh | 391 | ; restore configuration space |
392 | pop eax |
||
393 | mov dx,0xcfa |
||
394 | out dx,al |
||
395 | mov dl,0xf8 |
||
396 | mov al,ah |
||
397 | out dx,al |
||
1 | ha | 398 | |
1348 | art_zh | 399 | xor eax,eax |
1602 | art_zh | 400 | pop esi |
1348 | art_zh | 401 | ret |
1 | ha | 402 | |
1602 | art_zh | 403 | pci_write_reg_err: |
404 | xor eax,eax |
||
405 | dec eax |
||
406 | ret |
||
586 | serge | 407 | |
1370 | art_zh | 408 | if defined mmio_pci_addr ; must be set above |
1348 | art_zh | 409 | ;*************************************************************************** |
410 | ; Function |
||
1603 | art_zh | 411 | ; pci_mmio_init |
1348 | art_zh | 412 | ; |
413 | ; Description |
||
1602 | art_zh | 414 | ; IN: bx = device's PCI bus address (bbbbbbbbdddddfff) |
1358 | art_zh | 415 | ; Returns eax = user heap space available (bytes) |
1348 | art_zh | 416 | ; Error codes |
417 | ; eax = -1 : PCI user access blocked, |
||
418 | ; eax = -2 : device not registered for uMMIO service |
||
419 | ; eax = -3 : user heap initialization failure |
||
420 | ;*************************************************************************** |
||
421 | pci_mmio_init: |
||
1603 | art_zh | 422 | cmp bx, mmio_pci_addr |
1348 | art_zh | 423 | jz @f |
424 | mov eax,-2 |
||
425 | ret |
||
426 | @@: |
||
427 | call init_heap ; (if not initialized yet) |
||
428 | or eax,eax |
||
429 | jz @f |
||
430 | ret |
||
431 | @@: |
||
432 | mov eax,-3 |
||
433 | ret |
||
434 | |||
435 | |||
436 | ;*************************************************************************** |
||
437 | ; Function |
||
1603 | art_zh | 438 | ; pci_mmio_map |
1348 | art_zh | 439 | ; |
440 | ; Description |
||
441 | ; maps a block of PCI memory to user-accessible linear address |
||
442 | ; |
||
443 | ; WARNING! This VERY EXPERIMENTAL service is for one chosen PCI device only! |
||
444 | ; The target device address should be set in kernel var mmio_pci_addr |
||
445 | ; |
||
1602 | art_zh | 446 | ; IN: ah = BAR#; |
447 | ; IN: ebx = block size (bytes); |
||
448 | ; IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages); |
||
1348 | art_zh | 449 | ; |
450 | ; Returns eax = MMIO block's linear address in the userspace (if no error) |
||
451 | ; |
||
452 | ; |
||
453 | ; Error codes |
||
454 | ; eax = -1 : user access to PCI blocked, |
||
455 | ; eax = -2 : an invalid BAR register referred |
||
456 | ; eax = -3 : no i/o space on that BAR |
||
457 | ; eax = -4 : a port i/o BAR register referred |
||
458 | ; eax = -5 : dynamic userspace allocation problem |
||
459 | ;*************************************************************************** |
||
460 | |||
461 | pci_mmio_map: |
||
462 | and edx,0x0ffff |
||
1602 | art_zh | 463 | cmp ah,6 |
1603 | art_zh | 464 | jc .bar_0_5 |
465 | jz .bar_rom |
||
1348 | art_zh | 466 | mov eax,-2 |
467 | ret |
||
1353 | art_zh | 468 | .bar_rom: |
469 | mov ah, 8 ; bar6 = Expansion ROM base address |
||
470 | .bar_0_5: |
||
1348 | art_zh | 471 | push ecx |
1602 | art_zh | 472 | add ebx, 4095 |
473 | and ebx,-4096 |
||
474 | push ebx |
||
475 | mov bl, ah ; bl = BAR# (0..5), however bl=8 for BAR6 |
||
476 | shl bl, 1 |
||
477 | shl bl, 1 |
||
478 | add bl, 0x10 ; now bl = BAR offset in PCI config. space |
||
1354 | diamond | 479 | mov ax, mmio_pci_addr |
1602 | art_zh | 480 | mov bh, al ; bh = dddddfff |
481 | mov al, 2 ; al : DW to read |
||
482 | call pci_read_reg |
||
1348 | art_zh | 483 | or eax, eax |
484 | jnz @f |
||
485 | mov eax,-3 ; empty I/O space |
||
486 | jmp mmio_ret_fail |
||
487 | @@: |
||
488 | test eax, 1 |
||
489 | jz @f |
||
490 | mov eax,-4 ; damned ports (not MMIO space) |
||
491 | jmp mmio_ret_fail |
||
492 | @@: |
||
1602 | art_zh | 493 | pop ecx ; ecx = block size, bytes (expanded to whole page) |
1348 | art_zh | 494 | mov ebx, ecx ; user_alloc destroys eax, ecx, edx, but saves ebx |
1602 | art_zh | 495 | and eax, 0xFFFFFFF0 |
1462 | art_zh | 496 | push eax ; store MMIO physical address + keep 2DWords in the stack |
1348 | art_zh | 497 | stdcall user_alloc, ecx |
1602 | art_zh | 498 | or eax, eax |
1348 | art_zh | 499 | jnz mmio_map_over |
500 | mov eax,-5 ; problem with page allocation |
||
501 | |||
502 | mmio_ret_fail: |
||
503 | pop ecx |
||
504 | pop edx |
||
505 | ret |
||
506 | |||
507 | mmio_map_over: |
||
508 | mov ecx, ebx ; ecx = size (bytes, expanded to whole page) |
||
509 | shr ecx, 12 ; ecx = number of pages |
||
510 | mov ebx, eax ; ebx = linear address |
||
1602 | art_zh | 511 | pop eax ; eax = MMIO start |
512 | pop edx ; edx = MMIO shift (pages) |
||
1348 | art_zh | 513 | shl edx, 12 ; edx = MMIO shift (bytes) |
514 | add eax, edx ; eax = uMMIO physical address |
||
1602 | art_zh | 515 | or eax, PG_SHARED |
516 | or eax, PG_UW |
||
517 | or eax, PG_NOCACHE |
||
1348 | art_zh | 518 | mov edi, ebx |
519 | call commit_pages |
||
520 | mov eax, edi |
||
521 | ret |
||
522 | |||
523 | ;*************************************************************************** |
||
524 | ; Function |
||
1603 | art_zh | 525 | ; pci_mmio_unmap_page |
1348 | art_zh | 526 | ; |
527 | ; Description |
||
528 | ; unmaps the linear space previously tied to a PCI memory block |
||
529 | ; |
||
530 | ; IN: ebx = linear address of space previously allocated by pci_mmio_map |
||
531 | ; returns eax = 1 if successfully unmapped |
||
532 | ; |
||
533 | ; Error codes |
||
534 | ; eax = -1 if no user PCI access allowed, |
||
535 | ; eax = 0 if unmapping failed |
||
536 | ;*************************************************************************** |
||
537 | |||
538 | pci_mmio_unmap: |
||
1602 | art_zh | 539 | stdcall user_free, ebx |
1348 | art_zh | 540 | ret |
541 | |||
1354 | diamond | 542 | end if |
1348 | art_zh | 543 | |
586 | serge | 544 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
1375 | Lrz | 545 | uglobal |
546 | align 4 |
||
586 | serge | 547 | ; VendID (2), DevID (2), Revision = 0 (1), Class Code (3), FNum (1), Bus (1) |
548 | pci_emu_dat: times 30*10 db 0 |
||
1375 | Lrz | 549 | endg |
586 | serge | 550 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
551 | align 4 |
||
552 | sys_pcibios: |
||
594 | diamond | 553 | cmp [pci_access_enabled], 1 |
1348 | art_zh | 554 | jne .unsupported_func |
555 | cmp [pci_bios_entry], 0 |
||
594 | diamond | 556 | jz .emulate_bios |
586 | serge | 557 | |
1348 | art_zh | 558 | push ds |
559 | mov ax, pci_data_sel |
||
560 | mov ds, ax |
||
561 | mov eax, ebp |
||
562 | mov ah, 0B1h |
||
563 | call pword [cs:pci_bios_entry] |
||
564 | pop ds |
||
586 | serge | 565 | |
566 | jmp .return |
||
567 | ;-=-=-=-=-=-=-=-= |
||
568 | .emulate_bios: |
||
569 | cmp ebp, 1 ; PCI_FUNCTION_ID |
||
570 | jnz .not_PCI_BIOS_PRESENT |
||
571 | mov edx, 'PCI ' |
||
1949 | clevermous | 572 | mov al, [BOOT_VAR + 0x9020] |
573 | mov bx, [BOOT_VAR + 0x9022] |
||
574 | mov cl, [BOOT_VAR + 0x9021] |
||
1348 | art_zh | 575 | xor ah, ah |
594 | diamond | 576 | jmp .return_abcd |
586 | serge | 577 | |
578 | .not_PCI_BIOS_PRESENT: |
||
579 | cmp ebp, 2 ; FIND_PCI_DEVICE |
||
580 | jne .not_FIND_PCI_DEVICE |
||
594 | diamond | 581 | mov ebx, pci_emu_dat |
582 | ..nxt: cmp [ebx], dx |
||
586 | serge | 583 | jne ..no |
594 | diamond | 584 | cmp [ebx + 2], cx |
586 | serge | 585 | jne ..no |
594 | diamond | 586 | dec si |
586 | serge | 587 | jns ..no |
594 | diamond | 588 | mov bx, [ebx + 4] |
1348 | art_zh | 589 | xor ah, ah |
594 | diamond | 590 | jmp .return_ab |
591 | ..no: cmp word[ebx], 0 |
||
586 | serge | 592 | je ..dev_not_found |
594 | diamond | 593 | add ebx, 10 |
586 | serge | 594 | jmp ..nxt |
595 | ..dev_not_found: |
||
596 | mov ah, 0x86 ; DEVICE_NOT_FOUND |
||
594 | diamond | 597 | jmp .return_a |
586 | serge | 598 | |
599 | .not_FIND_PCI_DEVICE: |
||
600 | cmp ebp, 3 ; FIND_PCI_CLASS_CODE |
||
601 | jne .not_FIND_PCI_CLASS_CODE |
||
602 | mov esi, pci_emu_dat |
||
594 | diamond | 603 | shl ecx, 8 |
1348 | art_zh | 604 | ..nxt2: cmp [esi], ecx |
586 | serge | 605 | jne ..no2 |
606 | mov bx, [esi] |
||
1348 | art_zh | 607 | xor ah, ah |
594 | diamond | 608 | jmp .return_ab |
586 | serge | 609 | ..no2: cmp dword[esi], 0 |
594 | diamond | 610 | je ..dev_not_found |
586 | serge | 611 | add esi, 10 |
612 | jmp ..nxt2 |
||
613 | |||
614 | .not_FIND_PCI_CLASS_CODE: |
||
615 | cmp ebp, 8 ; READ_CONFIG_* |
||
616 | jb .not_READ_CONFIG |
||
617 | cmp ebp, 0x0A |
||
618 | ja .not_READ_CONFIG |
||
1602 | art_zh | 619 | mov eax, ebp |
620 | mov ah, bh |
||
621 | mov edx, edi |
||
622 | mov bh, bl |
||
623 | mov bl, dl |
||
624 | call pci_read_reg |
||
625 | mov ecx, eax |
||
586 | serge | 626 | xor ah, ah ; SUCCESSFUL |
594 | diamond | 627 | jmp .return_abc |
586 | serge | 628 | .not_READ_CONFIG: |
629 | cmp ebp, 0x0B ; WRITE_CONFIG_* |
||
630 | jb .not_WRITE_CONFIG |
||
631 | cmp ebp, 0x0D |
||
632 | ja .not_WRITE_CONFIG |
||
1348 | art_zh | 633 | lea eax, [ebp+1] |
1602 | art_zh | 634 | mov ah, bh |
635 | mov edx, edi |
||
636 | mov bh, bl |
||
637 | mov bl, dl |
||
586 | serge | 638 | call pci_write_reg |
639 | xor ah, ah ; SUCCESSFUL |
||
594 | diamond | 640 | jmp .return_abc |
586 | serge | 641 | .not_WRITE_CONFIG: |
642 | .unsupported_func: |
||
643 | mov ah, 0x81 ; FUNC_NOT_SUPPORTED |
||
1375 | Lrz | 644 | .return:mov dword[esp + 4 ], edi |
645 | mov dword[esp + 8], esi |
||
594 | diamond | 646 | .return_abcd: |
1375 | Lrz | 647 | mov dword[esp + 24], edx |
594 | diamond | 648 | .return_abc: |
1375 | Lrz | 649 | mov dword[esp + 28], ecx |
594 | diamond | 650 | .return_ab: |
1375 | Lrz | 651 | mov dword[esp + 20], ebx |
594 | diamond | 652 | .return_a: |
1375 | Lrz | 653 | mov dword[esp + 32], eax |
586 | serge | 654 | ret |