Rev 2929 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2886 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
7 | ;; Version 2, June 1991 ;; |
||
8 | ;; ;; |
||
9 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
10 | |||
11 | |||
12 | ; PCI Bus defines |
||
13 | |||
14 | PCI_HEADER_TYPE = 0x0e ; 8 bit |
||
15 | PCI_BASE_ADDRESS_0 = 0x10 ; 32 bit |
||
2935 | hidnplayr | 16 | PCI_BASE_ADDRESS_1 = 0x14 ; 32 bits |
17 | PCI_BASE_ADDRESS_2 = 0x18 ; 32 bits |
||
18 | PCI_BASE_ADDRESS_3 = 0x1c ; 32 bits |
||
19 | PCI_BASE_ADDRESS_4 = 0x20 ; 32 bits |
||
2886 | hidnplayr | 20 | PCI_BASE_ADDRESS_5 = 0x24 ; 32 bits |
21 | PCI_BASE_ADDRESS_SPACE_IO = 0x01 |
||
22 | PCI_BASE_ADDRESS_IO_MASK = 0xFFFFFFFC |
||
2935 | hidnplayr | 23 | PCI_BASE_ADDRESS_MEM_MASK = 0xFFFFFFF0 |
2886 | hidnplayr | 24 | |
25 | ; PCI programming |
||
26 | |||
2935 | hidnplayr | 27 | PCI_VENDOR_ID = 0x00 ; 16 bit |
28 | PCI_DEVICE_ID = 0x02 ; 16 bits |
||
2886 | hidnplayr | 29 | PCI_REG_COMMAND = 0x4 ; command register |
30 | PCI_REG_STATUS = 0x6 ; status register |
||
2935 | hidnplayr | 31 | PCI_REVISION_ID = 0x08 ; 8 bits |
2886 | hidnplayr | 32 | PCI_REG_LATENCY = 0xd ; latency timer register |
33 | PCI_REG_CAP_PTR = 0x34 ; capabilities pointer |
||
2935 | hidnplayr | 34 | PCI_REG_IRQ = 0x3c |
2886 | hidnplayr | 35 | PCI_REG_CAPABILITY_ID = 0x0 ; capapility ID in pm register block |
36 | PCI_REG_PM_STATUS = 0x4 ; power management status register |
||
37 | PCI_REG_PM_CTRL = 0x4 ; power management control register |
||
38 | PCI_BIT_PIO = 1 ; bit0: io space control |
||
39 | PCI_BIT_MMIO = 2 ; bit1: memory space control |
||
40 | PCI_BIT_MASTER = 4 ; bit2: device acts as a PCI master |
||
41 | |||
42 | |||
43 | macro find_io bus, dev, io { |
||
44 | |||
45 | local .check, .inc, .got |
||
46 | |||
47 | xor eax, eax |
||
48 | mov esi, PCI_BASE_ADDRESS_0 |
||
49 | movzx ecx, bus |
||
50 | movzx edx, dev |
||
51 | .check: |
||
2929 | hidnplayr | 52 | push ecx edx |
2886 | hidnplayr | 53 | stdcall PciRead32, ecx ,edx ,esi |
2929 | hidnplayr | 54 | pop edx ecx |
2886 | hidnplayr | 55 | |
56 | test eax, PCI_BASE_ADDRESS_IO_MASK |
||
57 | jz .inc |
||
58 | |||
59 | test eax, PCI_BASE_ADDRESS_SPACE_IO |
||
60 | jz .inc |
||
61 | |||
62 | and eax, PCI_BASE_ADDRESS_IO_MASK |
||
63 | jmp .got |
||
64 | |||
65 | .inc: |
||
66 | add esi, 4 |
||
67 | cmp esi, PCI_BASE_ADDRESS_5 |
||
2922 | hidnplayr | 68 | jbe .check |
69 | xor eax, eax |
||
2886 | hidnplayr | 70 | |
71 | .got: |
||
2922 | hidnplayr | 72 | mov io, eax |
2886 | hidnplayr | 73 | |
74 | } |
||
75 | |||
76 | |||
2922 | hidnplayr | 77 | macro find_mmio32 bus, dev, io { |
2886 | hidnplayr | 78 | |
2922 | hidnplayr | 79 | local .check, .inc, .got |
2886 | hidnplayr | 80 | |
81 | mov esi, PCI_BASE_ADDRESS_0 |
||
82 | .check: |
||
2922 | hidnplayr | 83 | stdcall PciRead32, bus, dev, esi |
2886 | hidnplayr | 84 | |
2922 | hidnplayr | 85 | test eax, PCI_BASE_ADDRESS_SPACE_IO ; mmio address? |
86 | jnz .inc |
||
2886 | hidnplayr | 87 | |
2922 | hidnplayr | 88 | test eax, 100b ; 64 bit? |
89 | jnz .inc |
||
90 | and eax, not 1111b |
||
91 | jmp .got |
||
92 | |||
93 | .inc: |
||
2886 | hidnplayr | 94 | add esi, 4 |
95 | cmp esi, PCI_BASE_ADDRESS_5 |
||
2922 | hidnplayr | 96 | jbe .check |
97 | xor eax, eax |
||
2886 | hidnplayr | 98 | |
99 | .got: |
||
2922 | hidnplayr | 100 | mov io, eax |
2886 | hidnplayr | 101 | } |
102 | |||
103 | macro find_irq bus, dev, irq { |
||
104 | |||
105 | push eax edx ecx |
||
106 | movzx ecx, bus |
||
107 | movzx edx, dev |
||
2935 | hidnplayr | 108 | stdcall PciRead8, ecx, edx, PCI_REG_IRQ |
2886 | hidnplayr | 109 | mov irq, al |
110 | pop ecx edx eax |
||
111 | |||
112 | } |
||
113 | |||
114 | macro find_rev bus, dev, rev { |
||
115 | |||
116 | push eax edx ecx |
||
117 | movzx ecx, bus |
||
118 | movzx edx, dev |
||
119 | stdcall PciRead8, ecx ,edx ,0x8 |
||
120 | mov rev, al |
||
121 | pop ecx edx eax |
||
122 | |||
123 | } |
||
124 | |||
125 | macro make_bus_master bus, dev { |
||
126 | |||
127 | movzx ecx, bus |
||
128 | movzx edx, dev |
||
129 | stdcall PciRead32, ecx ,edx, PCI_REG_COMMAND |
||
2911 | hidnplayr | 130 | or al, PCI_BIT_MASTER |
2886 | hidnplayr | 131 | stdcall PciWrite32, ecx, edx, PCI_REG_COMMAND, eax |
132 | |||
2911 | hidnplayr | 133 | } |
2886 | hidnplayr | 134 | |
2911 | hidnplayr | 135 | macro adjust_latency bus, dev, min { |
136 | |||
137 | movzx ecx, bus |
||
138 | movzx edx, dev |
||
139 | stdcall PciRead8, ecx ,edx, PCI_REG_LATENCY |
||
140 | cmp al, min |
||
141 | ja @f |
||
142 | mov al, min |
||
143 | stdcall PciWrite8, ecx, edx, PCI_REG_LATENCY, eax |
||
144 | @@: |
||
145 | |||
146 | } |