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.

pcidirect.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef _PCIDIRECT_H
  2. #define _PCIDIRECT_H
  3. #include <stdint.h>
  4. #include <gpxe/io.h>
  5. #ifdef PCIAPI_DIRECT
  6. #define PCIAPI_PREFIX_direct
  7. #else
  8. #define PCIAPI_PREFIX_direct __direct_
  9. #endif
  10. /** @file
  11. *
  12. * PCI configuration space access via Type 1 accesses
  13. *
  14. */
  15. #define PCIDIRECT_CONFIG_ADDRESS 0xcf8
  16. #define PCIDIRECT_CONFIG_DATA 0xcfc
  17. struct pci_device;
  18. extern void pcidirect_prepare ( struct pci_device *pci, int where );
  19. /**
  20. * Determine maximum PCI bus number within system
  21. *
  22. * @ret max_bus Maximum bus number
  23. */
  24. static inline __always_inline int
  25. PCIAPI_INLINE ( direct, pci_max_bus ) ( void ) {
  26. /* No way to work this out via Type 1 accesses */
  27. return 0xff;
  28. }
  29. /**
  30. * Read byte from PCI configuration space via Type 1 access
  31. *
  32. * @v pci PCI device
  33. * @v where Location within PCI configuration space
  34. * @v value Value read
  35. * @ret rc Return status code
  36. */
  37. static inline __always_inline int
  38. PCIAPI_INLINE ( direct, pci_read_config_byte ) ( struct pci_device *pci,
  39. unsigned int where,
  40. uint8_t *value ) {
  41. pcidirect_prepare ( pci, where );
  42. *value = inb ( PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
  43. return 0;
  44. }
  45. /**
  46. * Read word from PCI configuration space via Type 1 access
  47. *
  48. * @v pci PCI device
  49. * @v where Location within PCI configuration space
  50. * @v value Value read
  51. * @ret rc Return status code
  52. */
  53. static inline __always_inline int
  54. PCIAPI_INLINE ( direct, pci_read_config_word ) ( struct pci_device *pci,
  55. unsigned int where,
  56. uint16_t *value ) {
  57. pcidirect_prepare ( pci, where );
  58. *value = inw ( PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
  59. return 0;
  60. }
  61. /**
  62. * Read dword from PCI configuration space via Type 1 access
  63. *
  64. * @v pci PCI device
  65. * @v where Location within PCI configuration space
  66. * @v value Value read
  67. * @ret rc Return status code
  68. */
  69. static inline __always_inline int
  70. PCIAPI_INLINE ( direct, pci_read_config_dword ) ( struct pci_device *pci,
  71. unsigned int where,
  72. uint32_t *value ) {
  73. pcidirect_prepare ( pci, where );
  74. *value = inl ( PCIDIRECT_CONFIG_DATA );
  75. return 0;
  76. }
  77. /**
  78. * Write byte to PCI configuration space via Type 1 access
  79. *
  80. * @v pci PCI device
  81. * @v where Location within PCI configuration space
  82. * @v value Value to be written
  83. * @ret rc Return status code
  84. */
  85. static inline __always_inline int
  86. PCIAPI_INLINE ( direct, pci_write_config_byte ) ( struct pci_device *pci,
  87. unsigned int where,
  88. uint8_t value ) {
  89. pcidirect_prepare ( pci, where );
  90. outb ( value, PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
  91. return 0;
  92. }
  93. /**
  94. * Write word to PCI configuration space via Type 1 access
  95. *
  96. * @v pci PCI device
  97. * @v where Location within PCI configuration space
  98. * @v value Value to be written
  99. * @ret rc Return status code
  100. */
  101. static inline __always_inline int
  102. PCIAPI_INLINE ( direct, pci_write_config_word ) ( struct pci_device *pci,
  103. unsigned int where,
  104. uint16_t value ) {
  105. pcidirect_prepare ( pci, where );
  106. outw ( value, PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
  107. return 0;
  108. }
  109. /**
  110. * Write dword to PCI configuration space via Type 1 access
  111. *
  112. * @v pci PCI device
  113. * @v where Location within PCI configuration space
  114. * @v value Value to be written
  115. * @ret rc Return status code
  116. */
  117. static inline __always_inline int
  118. PCIAPI_INLINE ( direct, pci_write_config_dword ) ( struct pci_device *pci,
  119. unsigned int where,
  120. uint32_t value ) {
  121. pcidirect_prepare ( pci, where );
  122. outl ( value, PCIDIRECT_CONFIG_DATA );
  123. return 0;
  124. }
  125. #endif /* _PCIDIRECT_H */