Rev 1505 | Rev 1508 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1505 | Rev 1507 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | ;; ;; |
6 | ;; ;; |
7 | ;; PCI32.INC ;; |
7 | ;; PCI32.INC ;; |
8 | ;; ;; |
8 | ;; ;; |
9 | ;; 32 bit PCI driver code ;; |
9 | ;; 32 bit PCI driver code ;; |
10 | ;; ;; |
10 | ;; ;; |
- | 11 | ;; Version 0.4 February 2nd, 2010 ;; |
|
11 | ;; Version 0.3 April 9, 2007 ;; |
12 | ;; Version 0.3 April 9, 2007 ;; |
12 | ;; Version 0.2 December 21st, 2002 ;; |
13 | ;; Version 0.2 December 21st, 2002 ;; |
13 | ;; ;; |
14 | ;; ;; |
14 | ;; Author: Victor Prodan, victorprodan@yahoo.com ;; |
15 | ;; Author: Victor Prodan, victorprodan@yahoo.com ;; |
15 | ;; Mihailov Ilia, ghost.nsk@gmail.com ;; |
16 | ;; Mihailov Ilia, ghost.nsk@gmail.com ;; |
- | 17 | ;; Artem Jerdev, kolibri@jerdev.co.uk ;; |
|
16 | ;; Credits: ;; |
18 | ;; Credits: ;; |
17 | ;; Ralf Brown ;; |
19 | ;; Ralf Brown ;; |
18 | ;; Mike Hibbett, mikeh@oceanfree.net ;; |
20 | ;; Mike Hibbett, mikeh@oceanfree.net ;; |
19 | ;; ;; |
21 | ;; ;; |
20 | ;; See file COPYING for details ;; |
22 | ;; See file COPYING for details ;; |
21 | ;; ;; |
23 | ;; ;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 23... | Line 25... | ||
23 | 25 | ||
Line 24... | Line 26... | ||
24 | $Revision: 1462 $ |
26 | $Revision: 1507 $ |
25 | 27 | ||
26 | ;*************************************************************************** |
28 | ;*************************************************************************** |
27 | ; Function |
29 | ; Function |
28 | ; pci_api: |
30 | ; pci_api: |
29 | ; |
31 | ; |
30 | ; Description |
32 | ; Description |
31 | ; entry point for system PCI calls |
33 | ; entry point for system PCI calls |
Line 32... | Line 34... | ||
32 | ;*************************************************************************** |
34 | ;*************************************************************************** |
Line 33... | Line 35... | ||
33 | ;mmio_pci_addr equ 0x400 ; set actual PCI address here to activate user-MMIO |
35 | mmio_pci_addr dw 0x400 ; default PCI device bdf-address |
Line 74... | Line 76... | ||
74 | cmp al,9 |
76 | cmp al,9 |
75 | jz pci_write_reg ;word |
77 | jz pci_write_reg ;word |
76 | cmp al,10 |
78 | cmp al,10 |
77 | jz pci_write_reg ;dword |
79 | jz pci_write_reg ;dword |
Line 78... | Line -... | ||
78 | - | ||
79 | if defined mmio_pci_addr |
80 | |
80 | cmp al,11 ; user-level MMIO functions |
81 | cmp al,11 ; user-level MMIO functions |
81 | jz pci_mmio_init |
82 | jz pci_mmio_init |
82 | cmp al,12 |
83 | cmp al,12 |
83 | jz pci_mmio_map |
84 | jz pci_mmio_map |
84 | cmp al,13 |
85 | cmp al,13 |
85 | jz pci_mmio_unmap |
86 | jz pci_mmio_unmap |
Line 86... | Line 87... | ||
86 | end if |
87 | |
Line 87... | Line 88... | ||
87 | 88 | ||
Line 382... | Line 383... | ||
382 | ; Function |
383 | ; Function |
383 | ; pci_mmio_init |
384 | ; pci_mmio_init |
384 | ; |
385 | ; |
385 | ; Description |
386 | ; Description |
386 | ; IN: bx = device's PCI bus address (bbbbbbbbdddddfff) |
387 | ; IN: bx = device's PCI bus address (bbbbbbbbdddddfff) |
387 | ; Returns eax = user heap space available (bytes) |
388 | ; Returns eax = phys. address of user-accessible DMA block |
388 | ; Error codes |
389 | ; Error codes |
389 | ; eax = -1 : PCI user access blocked, |
390 | ; eax = -1 : PCI user access blocked, |
390 | ; eax = -2 : device not registered for uMMIO service |
391 | ; eax = -2 : device not registered for uMMIO service |
391 | ; eax = -3 : user heap initialization failure |
392 | ; eax = -3 : user heap initialization failure |
392 | ;*************************************************************************** |
393 | ;*************************************************************************** |
393 | pci_mmio_init: |
394 | pci_mmio_init: |
394 | cmp bx, mmio_pci_addr |
395 | cmp bx, [mmio_pci_addr] |
395 | jz @f |
396 | jz @f |
396 | mov eax,-2 |
397 | mov eax,-2 |
397 | ret |
398 | ret |
398 | @@: |
399 | @@: |
399 | call init_heap ; (if not initialized yet) |
400 | call init_heap ; (if not initialized yet) |
400 | or eax,eax |
401 | or eax,eax |
401 | jz @f |
402 | jz @f |
- | 403 | mov eax, [UserDMAaddr] |
|
402 | ret |
404 | ret |
403 | @@: |
405 | @@: |
404 | mov eax,-3 |
406 | mov eax,-3 |
405 | ret |
407 | ret |
Line 410... | Line 412... | ||
410 | ; pci_mmio_map |
412 | ; pci_mmio_map |
411 | ; |
413 | ; |
412 | ; Description |
414 | ; Description |
413 | ; maps a block of PCI memory to user-accessible linear address |
415 | ; maps a block of PCI memory to user-accessible linear address |
414 | ; |
416 | ; |
415 | ; WARNING! This VERY EXPERIMENTAL service is for one chosen PCI device only! |
- | |
416 | ; The target device address should be set in kernel var mmio_pci_addr |
- | |
417 | ; |
417 | ; |
418 | ; IN: ah = BAR#; |
418 | ; IN: ah = BAR#; or |
- | 419 | ; IN: ah = 0xDA for DMA-mapping requests; |
|
419 | ; IN: ebx = block size (bytes); |
420 | ; IN: ebx = block size (bytes); |
420 | ; IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages); |
421 | ; IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages); |
421 | ; |
422 | ; |
422 | ; Returns eax = MMIO block's linear address in the userspace (if no error) |
423 | ; Returns eax = MMIO block's linear address in the userspace (if no error) |
423 | ; |
424 | ; |
Line 430... | Line 431... | ||
430 | ; eax = -5 : dynamic userspace allocation problem |
431 | ; eax = -5 : dynamic userspace allocation problem |
431 | ;*************************************************************************** |
432 | ;*************************************************************************** |
Line 432... | Line 433... | ||
432 | 433 | ||
433 | pci_mmio_map: |
434 | pci_mmio_map: |
- | 435 | and edx,0x0ffff |
|
- | 436 | cmp ah, 0xDA |
|
434 | and edx,0x0ffff |
437 | jz .dma_map |
435 | cmp ah,6 |
438 | cmp ah,6 |
436 | jc .bar_0_5 |
439 | jc .bar_0_5 |
437 | jz .bar_rom |
440 | jz .bar_rom |
438 | mov eax,-2 |
441 | mov eax,-2 |
- | 442 | ret |
|
- | 443 | ||
- | 444 | .dma_map: |
|
- | 445 | push ecx |
|
- | 446 | mov ecx,ebx |
|
- | 447 | mov eax,[UserDMAaddr] |
|
- | 448 | jmp .allocate_block |
|
439 | ret |
449 | |
440 | .bar_rom: |
450 | .bar_rom: |
441 | mov ah, 8 ; bar6 = Expansion ROM base address |
451 | mov ah, 8 ; bar6 = Expansion ROM base address |
442 | .bar_0_5: |
452 | .bar_0_5: |
443 | push ecx |
453 | push ecx |
Line 446... | Line 456... | ||
446 | push ebx |
456 | push ebx |
447 | mov bl, ah ; bl = BAR# (0..5), however bl=8 for BAR6 |
457 | mov bl, ah ; bl = BAR# (0..5), however bl=8 for BAR6 |
448 | shl bl, 1 |
458 | shl bl, 1 |
449 | shl bl, 1 |
459 | shl bl, 1 |
450 | add bl, 0x10 ; now bl = BAR offset in PCI config. space |
460 | add bl, 0x10 ; now bl = BAR offset in PCI config. space |
451 | mov ax, mmio_pci_addr |
461 | mov ax, [mmio_pci_addr] |
452 | mov bh, al ; bh = dddddfff |
462 | mov bh, al ; bh = dddddfff |
453 | mov al, 2 ; al : DW to read |
463 | mov al, 2 ; al : DW to read |
454 | call pci_read_reg |
464 | call pci_read_reg |
455 | or eax, eax |
465 | or eax, eax |
456 | jnz @f |
466 | jnz @f |
Line 463... | Line 473... | ||
463 | jmp mmio_ret_fail |
473 | jmp mmio_ret_fail |
464 | @@: |
474 | @@: |
465 | pop ecx ; ecx = block size, bytes (expanded to whole page) |
475 | pop ecx ; ecx = block size, bytes (expanded to whole page) |
466 | mov ebx, ecx ; user_alloc destroys eax, ecx, edx, but saves ebx |
476 | mov ebx, ecx ; user_alloc destroys eax, ecx, edx, but saves ebx |
467 | and eax, 0xFFFFFFF0 |
477 | and eax, 0xFFFFFFF0 |
- | 478 | ||
- | 479 | .allocate_block: |
|
468 | push eax ; store MMIO physical address + keep 2DWords in the stack |
480 | push eax ; store MMIO physical address + keep the stack 2x4b deep |
469 | stdcall user_alloc, ecx |
481 | stdcall user_alloc, ecx |
470 | or eax, eax |
482 | or eax, eax |
471 | jnz mmio_map_over |
483 | jnz mmio_map_over |
472 | mov eax,-5 ; problem with page allocation |
484 | mov eax,-5 ; problem with page allocation |
Line 482... | Line 494... | ||
482 | mov ebx, eax ; ebx = linear address |
494 | mov ebx, eax ; ebx = linear address |
483 | pop eax ; eax = MMIO start |
495 | pop eax ; eax = MMIO start |
484 | pop edx ; edx = MMIO shift (pages) |
496 | pop edx ; edx = MMIO shift (pages) |
485 | shl edx, 12 ; edx = MMIO shift (bytes) |
497 | shl edx, 12 ; edx = MMIO shift (bytes) |
486 | add eax, edx ; eax = uMMIO physical address |
498 | add eax, edx ; eax = uMMIO physical address |
487 | or eax, PG_SHARED |
- | |
488 | or eax, PG_UW |
- | |
489 | or eax, PG_NOCACHE |
499 | or eax, (PG_SHARED+PG_UW+PG_NOCACHE) |
490 | mov edi, ebx |
500 | mov edi, ebx |
491 | call commit_pages |
501 | call commit_pages |
492 | mov eax, edi |
502 | mov eax, edi |
493 | ret |
503 | ret |