]>
Commit | Line | Data |
---|---|---|
1 | #include <io.h> | |
2 | #include <stdint.h> | |
3 | #include <pci.h> | |
4 | ||
5 | static void __pci_config(int bus, int slot, int fn, int addr) | |
6 | { | |
7 | outl(0xCF8, 0x80000000ULL | (bus << 16) | (slot << 11) | (fn << 8) | (addr & ~3)); | |
8 | } | |
9 | ||
10 | void pci_write32(int bus, int slot, int fn, int addr, uint32_t data) | |
11 | { | |
12 | __pci_config(bus, slot, fn, addr); | |
13 | outl(0xCFC, data); | |
14 | } | |
15 | ||
16 | void pci_write16(int bus, int slot, int fn, int addr, uint16_t data) | |
17 | { | |
18 | __pci_config(bus, slot, fn, addr); | |
19 | outw(0xCFC, data); | |
20 | } | |
21 | ||
22 | void pci_write8(int bus, int slot, int fn, int addr, uint8_t data) | |
23 | { | |
24 | __pci_config(bus, slot, fn, addr); | |
25 | outb(0xCFC, data); | |
26 | } | |
27 | ||
28 | uint32_t pci_read32(int bus, int slot, int fn, int addr) | |
29 | { | |
30 | __pci_config(bus, slot, fn, addr); | |
31 | return inl(0xCFC); | |
32 | } | |
33 | ||
34 | uint16_t pci_read16(int bus, int slot, int fn, int addr) | |
35 | { | |
36 | __pci_config(bus, slot, fn, addr); | |
37 | return inw(0xCFC + (addr & 2)); | |
38 | } | |
39 | ||
40 | uint8_t pci_read8(int bus, int slot, int fn, int addr) | |
41 | { | |
42 | __pci_config(bus, slot, fn, addr); | |
43 | return inb(0xCFC + (addr & 3)); | |
44 | } |