pci.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* PCI configuration space and low-level port I/O helpers. */
  2. #ifndef PCI_H
  3. #define PCI_H
  4. static inline void port_outb(unsigned short port, unsigned char v)
  5. {
  6. __asm__ volatile ("outb %0, %1" : : "a"(v), "Nd"(port));
  7. }
  8. static inline unsigned char port_inb(unsigned short port)
  9. {
  10. unsigned char v;
  11. __asm__ volatile ("inb %1, %0" : "=a"(v) : "Nd"(port));
  12. return v;
  13. }
  14. static inline void port_outl(unsigned short port, unsigned int v)
  15. {
  16. __asm__ volatile ("outl %0, %1" : : "a"(v), "Nd"(port));
  17. }
  18. static inline unsigned int port_inl(unsigned short port)
  19. {
  20. unsigned int v;
  21. __asm__ volatile ("inl %1, %0" : "=a"(v) : "Nd"(port));
  22. return v;
  23. }
  24. static inline void port_outw(unsigned short port, unsigned short v)
  25. {
  26. __asm__ volatile ("outw %0, %1" : : "a"(v), "Nd"(port));
  27. }
  28. static inline unsigned short port_inw(unsigned short port)
  29. {
  30. unsigned short v;
  31. __asm__ volatile ("inw %1, %0" : "=a"(v) : "Nd"(port));
  32. return v;
  33. }
  34. static inline unsigned int pci_cfg_read32(unsigned int bus, unsigned int dev,
  35. unsigned int func, unsigned int reg)
  36. {
  37. port_outl(0xCF8, 0x80000000 | (bus << 16) | (dev << 11) |
  38. (func << 8) | (reg & 0xFC));
  39. return port_inl(0xCFC);
  40. }
  41. static inline void pci_cfg_write32(unsigned int bus, unsigned int dev,
  42. unsigned int func, unsigned int reg,
  43. unsigned int val)
  44. {
  45. port_outl(0xCF8, 0x80000000 | (bus << 16) | (dev << 11) |
  46. (func << 8) | (reg & 0xFC));
  47. port_outl(0xCFC, val);
  48. }
  49. static inline void pci_cfg_write16(unsigned int bus, unsigned int dev,
  50. unsigned int func, unsigned int reg,
  51. unsigned short val)
  52. {
  53. port_outl(0xCF8, 0x80000000 | (bus << 16) | (dev << 11) |
  54. (func << 8) | (reg & 0xFC));
  55. port_outw((unsigned short)(0xCFC + (reg & 2)), val);
  56. }
  57. static inline void pci_cfg_write8(unsigned int bus, unsigned int dev,
  58. unsigned int func, unsigned int reg,
  59. unsigned char val)
  60. {
  61. port_outl(0xCF8, 0x80000000 | (bus << 16) | (dev << 11) |
  62. (func << 8) | (reg & 0xFC));
  63. port_outb((unsigned short)(0xCFC + (reg & 3)), val);
  64. }
  65. #endif