Subversion Repositories Kolibri OS

Rev

Rev 8224 | Details | Compare with Previous | Last modification | View Log | RSS feed

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