refactor: one more step towards arch-agnostic design
[lunaix-os.git] / lunaix-os / arch / i386 / includes / sys / pci_hba.h
1 #ifndef __LUNAIX_PCI_HBA_H
2 #define __LUNAIX_PCI_HBA_H
3
4 #include <hal/pci.h>
5 #include <lunaix/types.h>
6
7 #include "port_io.h"
8
9 #define PCI_CONFIG_ADDR 0xcf8
10 #define PCI_CONFIG_DATA 0xcfc
11
12 static inline pci_reg_t
13 pci_read_cspace(ptr_t base, int offset)
14 {
15     port_wrdword(PCI_CONFIG_ADDR, base | (offset & ~0x3));
16     return port_rddword(PCI_CONFIG_DATA);
17 }
18
19 static inline void
20 pci_write_cspace(ptr_t base, int offset, pci_reg_t data)
21 {
22     port_wrdword(PCI_CONFIG_ADDR, base | (offset & ~0x3));
23     port_wrdword(PCI_CONFIG_DATA, data);
24 }
25
26 /**
27  * @brief 配置并启用设备MSI支持。
28  * 参阅:PCI LB Spec. (Rev 3) Section 6.8 & 6.8.1
29  * 以及:Intel Manual, Vol 3, Section 10.11
30  *
31  * @param device PCI device
32  * @param vector interrupt vector.
33  */
34 void
35 pci_setup_msi(struct pci_device* device, int vector);
36
37 #endif /* __LUNAIX_PCI_HBA_H */