Apps: fixed 3 programs for using a long path in parameters
[kolibrios.git] / drivers / pci.inc
blobadc58778d96a0e7465b63fae77ed68a05a69ed19
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
2 ;;                                                                 ;;\r
3 ;; Copyright (C) KolibriOS team 2004-2018. All rights reserved.    ;;\r
4 ;; Distributed under terms of the GNU General Public License       ;;\r
5 ;;                                                                 ;;\r
6 ;;          GNU GENERAL PUBLIC LICENSE                             ;;\r
7 ;;             Version 2, June 1991                                ;;\r
8 ;;                                                                 ;;\r
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
11 struct  PCI_header\r
13         vendor_id       dw ?    ; 0x00\r
14         device_id       dw ?    ; 0x02\r
15         command         dw ?    ; 0x04\r
16         status          dw ?    ; 0x06\r
17         revision_id     db ?    ; 0x08\r
18         prog_if         db ?    ; 0x09\r
19         subclass        db ?    ; 0x0A\r
20         class_code      db ?    ; 0x0B\r
21         cache_line_size db ?    ; 0x0C\r
22         latency_timer   db ?    ; 0x0D\r
23         header_type     db ?    ; 0x0E\r
24         bist            db ?    ; 0x0F\r
26 ends\r
28 struct  PCI_header00    PCI_header\r
30         base_addr_0     dd ?    ; 0x10\r
31         base_addr_1     dd ?    ; 0x14\r
32         base_addr_2     dd ?    ; 0x18\r
33         base_addr_3     dd ?    ; 0x1C\r
34         base_addr_4     dd ?    ; 0x20\r
35         base_addr_5     dd ?    ; 0x24\r
36         cardbus_cis_ptr dd ?    ; 0x28\r
37         subsys_vendor   dw ?    ; 0x2C\r
38         subsys_id       dw ?    ; 0x2E\r
39         exp_rom_addr    dd ?    ; 0x30\r
40         cap_ptr         db ?    ; 0x34\r
41                         rb 7    ; reserved\r
42         interrupt_line  db ?    ; 0x3C\r
43         interrupt_pin   db ?    ; 0x3D\r
44         min_grant       db ?    ; 0x3E\r
45         max_latency     db ?    ; 0x3F\r
47 ends\r
49 struct  PCI_header01    PCI_header\r
51         base_addr_0     dd ?    ; 0x10\r
52         base_addr_1     dd ?    ; 0x14\r
53         prim_bus_nr     db ?    ; 0x18\r
54         sec_bus_nr      db ?    ; 0x19\r
55         sub_bus_nr      db ?    ; 0x1A\r
56         sec_lat_tmr     db ?    ; 0x1B\r
57         io_base         db ?    ; 0x1C\r
58         io_limit        db ?    ; 0x1D\r
59         sec_status      dw ?    ; 0x1E\r
60         mem_base        dw ?    ; 0x20\r
61         mem_limit       dw ?    ; 0x22\r
62         pref_mem_base   dw ?    ; 0x24\r
63         pref_mem_limit  dw ?    ; 0x26\r
64         pref_base_up    dd ?    ; 0x28\r
65         pref_limit_up   dd ?    ; 0x2C\r
66         io_base_up      dw ?    ; 0x30\r
67         io_limit_up     dw ?    ; 0x32\r
68         cap_ptr         db ?    ; 0x34\r
69                         rb 3    ; reserved\r
70         exp_rom_addr    dd ?    ; 0x38\r
71         interrupt_line  db ?    ; 0x3C\r
72         interrupt_pin   db ?    ; 0x3E\r
73         bridge_ctrl     dw ?    ; 0x3F\r
75 ends\r
77 struct  PCI_header02    PCI_header\r
79         base_addr       dd ?    ; 0x10\r
80         cap_list_offs   db ?    ; 0x14\r
81                         rb 1    ; reserved\r
82         sec_stat        dw ?    ; 0x16\r
83         pci_bus_nr      db ?    ; 0x18\r
84         cardbus_bus_nr  db ?    ; 0x19\r
85         sub_bus_nr      db ?    ; 0x1A\r
86         cardbus_lat_tmr db ?    ; 0x1B\r
87         mbar_0          dd ?    ; 0x1C\r
88         mlimit_0        dd ?    ; 0x20\r
89         mbar_1          dd ?    ; 0x24\r
90         mlimit_1        dd ?    ; 0x28\r
91         iobar_0         dd ?    ; 0x2C\r
92         iolimit_0       dd ?    ; 0x30\r
93         iobar_1         dd ?    ; 0x34\r
94         iolimit_1       dd ?    ; 0x38\r
95         interrupt_line  db ?    ; 0x3C\r
96         interrupt_pin   db ?    ; 0x3D\r
97         bridge_ctrl     dw ?    ; 0x3E\r
98         subs_did        dw ?    ; 0x40\r
99         subs_vid        dw ?    ; 0x42\r
100         legacy_bar      dd ?    ; 0x44\r
102 ends\r
104 ; Base address bits\r
105         PCI_BASE_ADDRESS_SPACE_IO               = 0x01\r
106         PCI_BASE_ADDRESS_IO_MASK                = 0xFFFFFFFC\r
107         PCI_BASE_ADDRESS_MEM_MASK               = 0xFFFFFFF0\r
108         PCI_BASE_ADDRESS_MEM_TYPE_MASK          = 0x00000006\r
109         PCI_BASE_ADDRESS_MEM_TYPE_32            = 0x0\r
110         PCI_BASE_ADDRESS_MEM_TYPE_RESERVED      = 0x02\r
111         PCI_BASE_ADDRESS_MEM_TYPE_64            = 0x4\r
114 ; command bits\r
115         PCI_CMD_PIO                     = 0x01          ; bit0: io space control\r
116         PCI_CMD_MMIO                    = 0x02          ; bit1: memory space control\r
117         PCI_CMD_MASTER                  = 0x04          ; bit2: device acts as a PCI master\r
118         PCI_CMD_INTX_DISABLE            = 0x400         ; INTx emulation disable\r
120 ; status bits\r
121         PCI_STATUS_CAPA                 = 0x10          ; bit4: new capabilities available\r
124 if used PCI_find_io\r
125 proc PCI_find_io stdcall bus, dev\r
127         push    esi\r
128         xor     eax, eax\r
129         mov     esi, PCI_header00.base_addr_0\r
130   .check:\r
131         invoke  PciRead32, [bus], [dev], esi\r
132         test    eax, PCI_BASE_ADDRESS_IO_MASK\r
133         jz      .inc\r
134         test    eax, PCI_BASE_ADDRESS_SPACE_IO\r
135         jz      .inc\r
136         and     eax, PCI_BASE_ADDRESS_IO_MASK\r
137         pop     esi\r
138         ret\r
140   .inc:\r
141         add     esi, 4\r
142         cmp     esi, PCI_header00.base_addr_5\r
143         jbe     .check\r
144         pop     esi\r
145         xor     eax, eax\r
146         ret\r
148 endp\r
149 end if\r
152 if used PCI_find_mmio\r
153 proc PCI_find_mmio stdcall bus, dev\r
155         push    esi ebx\r
156         mov     esi, PCI_header00.base_addr_0\r
157   .check:\r
158         invoke  PciRead32, [bus], [dev], esi\r
159         DEBUGF  1, "BAR: 0x%x\n", eax\r
160         mov     ebx, eax\r
161         test    eax, PCI_BASE_ADDRESS_SPACE_IO  ; MMIO address?\r
162         jnz     .next\r
163         and     ebx, PCI_BASE_ADDRESS_MEM_TYPE_MASK\r
164         cmp     bl, PCI_BASE_ADDRESS_MEM_TYPE_64\r
165         je      .is64\r
166         cmp     bl, PCI_BASE_ADDRESS_MEM_TYPE_32\r
167         jne     .next\r
168         ; Ok, we have a 32-bit BAR.\r
169         and     eax, PCI_BASE_ADDRESS_MEM_MASK\r
170         pop     ebx esi\r
171         DEBUGF  1, "32-bit MMIO address found: 0x%x\n", eax\r
172         ret\r
174   .is64:\r
175         ; Ok, we have a 64-bit BAR, check if the upper 32-bits are 0, then we can use it..\r
176         push    eax\r
177         add     esi, 4\r
178         cmp     esi, PCI_header00.base_addr_5\r
179         ja      .fail\r
180         invoke  PciRead32, [bus], [dev], esi\r
181         test    eax, eax\r
182         pop     eax\r
183         jnz     .next\r
184         and     eax, PCI_BASE_ADDRESS_MEM_MASK\r
185         pop     ebx esi\r
186         DEBUGF  1, "64-bit MMIO address found: 0x00000000%x\n", eax\r
187         ret\r
189   .next:\r
190         add     esi, 4\r
191         cmp     esi, PCI_header00.base_addr_5\r
192         jbe     .check\r
193   .fail:\r
194         xor     eax, eax\r
195         pop     ebx esi\r
196         DEBUGF  1, "No usable MMIO addresses found!\n"\r
197         ret\r
199 endp\r
200 end if