pci.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #define PCI_VENDOR_ID 0x00 // 2
  3. #define PCI_DEVICE_ID 0x02 // 2
  4. #define PCI_COMMAND 0x04 // 2
  5. #define PCI_STATUS 0x06 // 2
  6. #define PCI_REVISION_ID 0x08 // 1
  7. #define PCI_PROG_IF 0x09 // 1
  8. #define PCI_SUBCLASS 0x0a // 1
  9. #define PCI_CLASS 0x0b // 1
  10. #define PCI_CACHE_LINE_SIZE 0x0c // 1
  11. #define PCI_LATENCY_TIMER 0x0d // 1
  12. #define PCI_HEADER_TYPE 0x0e // 1
  13. #define PCI_BIST 0x0f // 1
  14. #define PCI_BAR0 0x10 // 4
  15. #define PCI_BAR1 0x14 // 4
  16. #define PCI_BAR2 0x18 // 4
  17. #define PCI_BAR3 0x1C // 4
  18. #define PCI_BAR4 0x20 // 4
  19. #define PCI_BAR5 0x24 // 4
  20. #define PCI_INTERRUPT_LINE 0x3C // 1
  21. #define PCI_SECONDARY_BUS 0x19 // 1
  22. #define PCI_HEADER_TYPE_DEVICE 0
  23. #define PCI_HEADER_TYPE_BRIDGE 1
  24. #define PCI_HEADER_TYPE_CARDBUS 2
  25. #define PCI_TYPE_BRIDGE 0x0604
  26. #define PCI_TYPE_SATA 0x0106
  27. #define PCI_ADDRESS_PORT 0xCF8
  28. #define PCI_VALUE_PORT 0xCFC
  29. #define PCI_NONE 0xFFFF
  30. typedef void (*pci_func_t)(uint32_t device, uint16_t vendor_id, uint16_t device_id, void * extra);
  31. static inline int pci_extract_bus(uint32_t device) {
  32. return (uint8_t)((device >> 16));
  33. }
  34. static inline int pci_extract_slot(uint32_t device) {
  35. return (uint8_t)((device >> 8));
  36. }
  37. static inline int pci_extract_func(uint32_t device) {
  38. return (uint8_t)(device);
  39. }
  40. static inline uint32_t pci_get_addr(uint32_t device, int field) {
  41. return 0x80000000 | (pci_extract_bus(device) << 16) | (pci_extract_slot(device) << 11) | (pci_extract_func(device) << 8) | ((field) & 0xFC);
  42. }
  43. static inline uint32_t pci_box_device(int bus, int slot, int func) {
  44. return (uint32_t)((bus << 16) | (slot << 8) | func);
  45. }
  46. uint32_t pci_read_field(uint32_t device, int field, int size);
  47. void pci_write_field(uint32_t device, int field, int size, uint32_t value);
  48. uint16_t pci_find_type(uint32_t dev);
  49. const char * pci_vendor_lookup(unsigned short vendor_id);
  50. const char * pci_device_lookup(unsigned short vendor_id, unsigned short device_id);
  51. void pci_scan_hit(pci_func_t f, uint32_t dev, void * extra);
  52. void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, void * extra);
  53. void pci_scan_slot(pci_func_t f, int type, int bus, int slot, void * extra);
  54. void pci_scan_bus(pci_func_t f, int type, int bus, void * extra);
  55. void pci_scan(pci_func_t f, int type, void * extra);
  56. void pci_remap(void);
  57. int pci_get_interrupt(uint32_t device);