pci.h 897 B

12345678910111213141516171819202122232425262728293031323334353637
  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 unsigned int pci_cfg_read32(unsigned int bus, unsigned int dev,
  25. unsigned int func, unsigned int reg)
  26. {
  27. port_outl(0xCF8, 0x80000000 | (bus << 16) | (dev << 11) |
  28. (func << 8) | (reg & 0xFC));
  29. return port_inl(0xCFC);
  30. }
  31. #endif