You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pcibios.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef _GPXE_PCIBIOS_H
  2. #define _GPXE_PCIBIOS_H
  3. #include <stdint.h>
  4. /** @file
  5. *
  6. * PCI configuration space access via PCI BIOS
  7. *
  8. */
  9. #ifdef PCIAPI_PCBIOS
  10. #define PCIAPI_PREFIX_pcbios
  11. #else
  12. #define PCIAPI_PREFIX_pcbios __pcbios_
  13. #endif
  14. struct pci_device;
  15. #define PCIBIOS_INSTALLATION_CHECK 0xb1010000
  16. #define PCIBIOS_READ_CONFIG_BYTE 0xb1080000
  17. #define PCIBIOS_READ_CONFIG_WORD 0xb1090000
  18. #define PCIBIOS_READ_CONFIG_DWORD 0xb10a0000
  19. #define PCIBIOS_WRITE_CONFIG_BYTE 0xb10b0000
  20. #define PCIBIOS_WRITE_CONFIG_WORD 0xb10c0000
  21. #define PCIBIOS_WRITE_CONFIG_DWORD 0xb10d0000
  22. extern int pcibios_read ( struct pci_device *pci, uint32_t command,
  23. uint32_t *value );
  24. extern int pcibios_write ( struct pci_device *pci, uint32_t command,
  25. uint32_t value );
  26. /**
  27. * Read byte from PCI configuration space via PCI BIOS
  28. *
  29. * @v pci PCI device
  30. * @v where Location within PCI configuration space
  31. * @v value Value read
  32. * @ret rc Return status code
  33. */
  34. static inline __always_inline int
  35. PCIAPI_INLINE ( pcbios, pci_read_config_byte ) ( struct pci_device *pci,
  36. unsigned int where,
  37. uint8_t *value ) {
  38. uint32_t tmp;
  39. int rc;
  40. rc = pcibios_read ( pci, PCIBIOS_READ_CONFIG_BYTE | where, &tmp );
  41. *value = tmp;
  42. return rc;
  43. }
  44. /**
  45. * Read word from PCI configuration space via PCI BIOS
  46. *
  47. * @v pci PCI device
  48. * @v where Location within PCI configuration space
  49. * @v value Value read
  50. * @ret rc Return status code
  51. */
  52. static inline __always_inline int
  53. PCIAPI_INLINE ( pcbios, pci_read_config_word ) ( struct pci_device *pci,
  54. unsigned int where,
  55. uint16_t *value ) {
  56. uint32_t tmp;
  57. int rc;
  58. rc = pcibios_read ( pci, PCIBIOS_READ_CONFIG_WORD | where, &tmp );
  59. *value = tmp;
  60. return rc;
  61. }
  62. /**
  63. * Read dword from PCI configuration space via PCI BIOS
  64. *
  65. * @v pci PCI device
  66. * @v where Location within PCI configuration space
  67. * @v value Value read
  68. * @ret rc Return status code
  69. */
  70. static inline __always_inline int
  71. PCIAPI_INLINE ( pcbios, pci_read_config_dword ) ( struct pci_device *pci,
  72. unsigned int where,
  73. uint32_t *value ) {
  74. return pcibios_read ( pci, PCIBIOS_READ_CONFIG_DWORD | where, value );
  75. }
  76. /**
  77. * Write byte to PCI configuration space via PCI BIOS
  78. *
  79. * @v pci PCI device
  80. * @v where Location within PCI configuration space
  81. * @v value Value to be written
  82. * @ret rc Return status code
  83. */
  84. static inline __always_inline int
  85. PCIAPI_INLINE ( pcbios, pci_write_config_byte ) ( struct pci_device *pci,
  86. unsigned int where,
  87. uint8_t value ) {
  88. return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_BYTE | where, value );
  89. }
  90. /**
  91. * Write word to PCI configuration space via PCI BIOS
  92. *
  93. * @v pci PCI device
  94. * @v where Location within PCI configuration space
  95. * @v value Value to be written
  96. * @ret rc Return status code
  97. */
  98. static inline __always_inline int
  99. PCIAPI_INLINE ( pcbios, pci_write_config_word ) ( struct pci_device *pci,
  100. unsigned int where,
  101. uint16_t value ) {
  102. return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_WORD | where, value );
  103. }
  104. /**
  105. * Write dword to PCI configuration space via PCI BIOS
  106. *
  107. * @v pci PCI device
  108. * @v where Location within PCI configuration space
  109. * @v value Value to be written
  110. * @ret rc Return status code
  111. */
  112. static inline __always_inline int
  113. PCIAPI_INLINE ( pcbios, pci_write_config_dword ) ( struct pci_device *pci,
  114. unsigned int where,
  115. uint32_t value ) {
  116. return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_DWORD | where, value);
  117. }
  118. #endif /* _GPXE_PCIBIOS_H */