Rev 1487 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1463 | art_zh | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) 2010 KolibriOS team. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; ;; |
||
7 | ;; PCIe.INC ;; |
||
8 | ;; ;; |
||
9 | ;; Extended PCI express services ;; |
||
10 | ;; ;; |
||
11 | ;; Author: ;; |
||
12 | ;; art_zh |
||
13 | ;; ;; |
||
14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
15 | |||
16 | $Revision: 1463 $ |
||
17 | |||
18 | ;*************************************************************************** |
||
19 | ; Function |
||
20 | ; pci_ext_config: |
||
21 | ; |
||
22 | ; Description |
||
23 | ; PCIe extended (memory-mapped) config space detection |
||
24 | ; |
||
25 | ; WARNINGs: |
||
26 | ; 1) Very Experimental! |
||
27 | ; 2) direct HT-detection (no ACPI or BIOS service used) |
||
28 | ; 3) Only AMD/HT processors currently supported |
||
29 | ; |
||
30 | ;*************************************************************************** |
||
31 | |||
32 | PCIe_CONFIG_SPACE equ 0xF0000000 ; to be moved to const.inc |
||
33 | mmio_pcie_cfg_addr dd 0x0 ; not defined by default |
||
34 | mmio_pcie_cfg_lim dd 0x0 ; each bus needs 1Mb |
||
35 | |||
36 | |||
37 | align 4 |
||
38 | |||
39 | pci_ext_config: |
||
40 | |||
41 | push ebx |
||
42 | mov bx, 0xC184 ; dev = 24, fn = 01, reg = 84h |
||
43 | |||
44 | .check_HT_mmio: |
||
45 | mov cx, bx |
||
46 | mov ax, 0x0002 ; bus = 0, 1dword to read |
||
47 | call pci_read_reg |
||
48 | mov bx, cx |
||
49 | sub bl, 4 |
||
50 | and al, 0x80 ; check the NP bit |
||
51 | jz .not_pcie_cfg |
||
52 | shl eax, 8 ; bus:[27..20], dev:[19:15] |
||
53 | or eax, 0x00007FFC ; fun:[14..12], reg:[11:2] |
||
54 | mov [mmio_pcie_cfg_lim], eax |
||
55 | mov cl, bl |
||
56 | mov ax, 0x0002 ; bus = 0, 1dword to read |
||
57 | call pci_read_reg |
||
58 | mov bx, cx |
||
59 | test al, 0x03 ; MMIO Base RW enabled? |
||
60 | jz .not_pcie_cfg |
||
61 | test al, 0x0C ; MMIO Base locked? |
||
62 | jnz .not_pcie_cfg |
||
63 | xor al, al |
||
64 | shl eax, 8 |
||
65 | ; test eax, 0x000F0000 ; MMIO Base must be bus0-aligned |
||
66 | ; jnz .not_pcie_cfg |
||
67 | mov [mmio_pcie_cfg_addr], eax |
||
68 | add eax, 0x000FFFFC |
||
69 | sub eax,[mmio_pcie_cfg_lim] ; MMIO must cover at least one bus |
||
70 | ja .not_pcie_cfg |
||
71 | |||
72 | ; -- it looks like a true PCIe config space; |
||
73 | mov eax,[mmio_pcie_cfg_addr] ; physical address |
||
74 | or eax, (PG_SHARED + PG_LARGE + PG_USER) |
||
75 | mov ebx, PCIe_CONFIG_SPACE ; linear address |
||
76 | mov ecx, ebx |
||
77 | shr ebx, 20 |
||
78 | add ebx, sys_pgdir ; PgDir entry @ |
||
79 | @@: |
||
80 | mov dword[ebx], eax ; map 4 buses |
||
81 | invlpg [ecx] |
||
82 | cmp bl, 4 |
||
83 | jz .pcie_cfg_mapped ; fix it later |
||
84 | add bl, 4 ; next PgDir entry |
||
85 | add eax, 0x400000 ; eax += 4M |
||
86 | add ecx, 0x400000 |
||
87 | jmp @b |
||
88 | |||
89 | .pcie_cfg_mapped: |
||
90 | |||
91 | ; -- glad to have the extended PCIe config field found |
||
92 | mov esi, boot_pcie_ok |
||
93 | pop ebx |
||
94 | call boot_log |
||
95 | ret ; <<<<<<<<<<< OK >>>>>>>>>>> |
||
96 | |||
97 | .not_pcie_cfg: |
||
98 | |||
99 | xor eax, eax |
||
100 | mov [mmio_pcie_cfg_addr], eax |
||
101 | mov [mmio_pcie_cfg_lim], eax |
||
102 | add bl, 12 |
||
103 | cmp bl, 0xC0 ; MMIO regs lay below this offset |
||
104 | jb .check_HT_mmio |
||
105 | mov esi, boot_pcie_fail |
||
106 | pop ebx |
||
107 | call boot_log |
||
108 | ret ; <<<<<<<<< FAILURE >>>>>>>>>><><<><<<><<<<><<<<<><<<<<<><<<<<<<><<<<<<<<>><><<><<<><<<<><<<<<><<<<<<><<<<<<<><<<<<<<<><<<<<<<<<><<<<<<<<<<> |
||
109 |