1
0

pci.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef ASM_PCI_H
  2. #define ASM_PCI_H
  3. /*
  4. * Copyright (C) 2013, Red Hat Inc, Michael S. Tsirkin <mst@redhat.com>
  5. *
  6. * This work is licensed under the terms of the GNU LGPL, version 2.
  7. */
  8. #include "libcflat.h"
  9. #include "pci.h"
  10. #include "x86/asm/io.h"
  11. #define PCI_CONF1_ADDRESS(dev, reg) ((0x1 << 31) | (dev << 8) | reg)
  12. static inline uint8_t pci_config_readb(pcidevaddr_t dev, uint8_t reg)
  13. {
  14. outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8);
  15. return inb(0xCFC);
  16. }
  17. static inline uint16_t pci_config_readw(pcidevaddr_t dev, uint8_t reg)
  18. {
  19. outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8);
  20. return inw(0xCFC);
  21. }
  22. static inline uint32_t pci_config_readl(pcidevaddr_t dev, uint8_t reg)
  23. {
  24. outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8);
  25. return inl(0xCFC);
  26. }
  27. static inline void pci_config_writeb(pcidevaddr_t dev, uint8_t reg,
  28. uint8_t val)
  29. {
  30. outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8);
  31. outb(val, 0xCFC);
  32. }
  33. static inline void pci_config_writew(pcidevaddr_t dev, uint8_t reg,
  34. uint16_t val)
  35. {
  36. outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8);
  37. outw(val, 0xCFC);
  38. }
  39. static inline void pci_config_writel(pcidevaddr_t dev, uint8_t reg,
  40. uint32_t val)
  41. {
  42. outl(PCI_CONF1_ADDRESS(dev, reg), 0xCF8);
  43. outl(val, 0xCFC);
  44. }
  45. static inline
  46. phys_addr_t pci_translate_addr(pcidevaddr_t dev __unused, uint64_t addr)
  47. {
  48. return addr;
  49. }
  50. #endif