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.2KB

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