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.

efi_pci_api.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef _IPXE_EFI_PCI_API_H
  2. #define _IPXE_EFI_PCI_API_H
  3. /** @file
  4. *
  5. * iPXE PCI I/O API for EFI
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #ifdef PCIAPI_EFI
  10. #define PCIAPI_PREFIX_efi
  11. #else
  12. #define PCIAPI_PREFIX_efi __efi_
  13. #endif
  14. /* EFI PCI width codes defined by EFI spec */
  15. #define EFIPCI_WIDTH_BYTE 0
  16. #define EFIPCI_WIDTH_WORD 1
  17. #define EFIPCI_WIDTH_DWORD 2
  18. #define EFIPCI_LOCATION( _offset, _width ) \
  19. ( (_offset) | ( (_width) << 16 ) )
  20. #define EFIPCI_OFFSET( _location ) ( (_location) & 0xffff )
  21. #define EFIPCI_WIDTH( _location ) ( (_location) >> 16 )
  22. struct pci_device;
  23. extern int efipci_read ( struct pci_device *pci, unsigned long location,
  24. void *value );
  25. extern int efipci_write ( struct pci_device *pci, unsigned long location,
  26. unsigned long value );
  27. /**
  28. * Determine number of PCI buses within system
  29. *
  30. * @ret num_bus Number of buses
  31. */
  32. static inline __always_inline int
  33. PCIAPI_INLINE ( efi, pci_num_bus ) ( void ) {
  34. /* EFI does not want us to scan the PCI bus ourselves */
  35. return 0;
  36. }
  37. /**
  38. * Read byte from PCI configuration space via EFI
  39. *
  40. * @v pci PCI device
  41. * @v where Location within PCI configuration space
  42. * @v value Value read
  43. * @ret rc Return status code
  44. */
  45. static inline __always_inline int
  46. PCIAPI_INLINE ( efi, pci_read_config_byte ) ( struct pci_device *pci,
  47. unsigned int where,
  48. uint8_t *value ) {
  49. *value = 0xff;
  50. return efipci_read ( pci,
  51. EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
  52. value );
  53. }
  54. /**
  55. * Read word from PCI configuration space via EFI
  56. *
  57. * @v pci PCI device
  58. * @v where Location within PCI configuration space
  59. * @v value Value read
  60. * @ret rc Return status code
  61. */
  62. static inline __always_inline int
  63. PCIAPI_INLINE ( efi, pci_read_config_word ) ( struct pci_device *pci,
  64. unsigned int where,
  65. uint16_t *value ) {
  66. *value = 0xffff;
  67. return efipci_read ( pci,
  68. EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
  69. value );
  70. }
  71. /**
  72. * Read dword from PCI configuration space via EFI
  73. *
  74. * @v pci PCI device
  75. * @v where Location within PCI configuration space
  76. * @v value Value read
  77. * @ret rc Return status code
  78. */
  79. static inline __always_inline int
  80. PCIAPI_INLINE ( efi, pci_read_config_dword ) ( struct pci_device *pci,
  81. unsigned int where,
  82. uint32_t *value ) {
  83. *value = 0xffffffffUL;
  84. return efipci_read ( pci,
  85. EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
  86. value );
  87. }
  88. /**
  89. * Write byte to PCI configuration space via EFI
  90. *
  91. * @v pci PCI device
  92. * @v where Location within PCI configuration space
  93. * @v value Value to be written
  94. * @ret rc Return status code
  95. */
  96. static inline __always_inline int
  97. PCIAPI_INLINE ( efi, pci_write_config_byte ) ( struct pci_device *pci,
  98. unsigned int where,
  99. uint8_t value ) {
  100. return efipci_write ( pci,
  101. EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
  102. value );
  103. }
  104. /**
  105. * Write word to PCI configuration space via EFI
  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 ( efi, pci_write_config_word ) ( struct pci_device *pci,
  114. unsigned int where,
  115. uint16_t value ) {
  116. return efipci_write ( pci,
  117. EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
  118. value );
  119. }
  120. /**
  121. * Write dword to PCI configuration space via EFI
  122. *
  123. * @v pci PCI device
  124. * @v where Location within PCI configuration space
  125. * @v value Value to be written
  126. * @ret rc Return status code
  127. */
  128. static inline __always_inline int
  129. PCIAPI_INLINE ( efi, pci_write_config_dword ) ( struct pci_device *pci,
  130. unsigned int where,
  131. uint32_t value ) {
  132. return efipci_write ( pci,
  133. EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
  134. value );
  135. }
  136. #endif /* _IPXE_EFI_PCI_API_H */