pci.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2008,2009 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_CPU_PCI_H
  19. #define GRUB_CPU_PCI_H 1
  20. #include <grub/types.h>
  21. #include <grub/i386/io.h>
  22. #define GRUB_MACHINE_PCI_IO_BASE 0
  23. #define GRUB_PCI_ADDR_REG 0xcf8
  24. #define GRUB_PCI_DATA_REG 0xcfc
  25. #define GRUB_PCI_NUM_BUS 256
  26. #define GRUB_PCI_NUM_DEVICES 32
  27. static inline grub_uint32_t
  28. grub_pci_read (grub_pci_address_t addr)
  29. {
  30. grub_outl (addr, GRUB_PCI_ADDR_REG);
  31. return grub_inl (GRUB_PCI_DATA_REG);
  32. }
  33. static inline grub_uint16_t
  34. grub_pci_read_word (grub_pci_address_t addr)
  35. {
  36. grub_outl (addr & ~3, GRUB_PCI_ADDR_REG);
  37. return grub_inw (GRUB_PCI_DATA_REG + (addr & 3));
  38. }
  39. static inline grub_uint8_t
  40. grub_pci_read_byte (grub_pci_address_t addr)
  41. {
  42. grub_outl (addr & ~3, GRUB_PCI_ADDR_REG);
  43. return grub_inb (GRUB_PCI_DATA_REG + (addr & 3));
  44. }
  45. static inline void
  46. grub_pci_write (grub_pci_address_t addr, grub_uint32_t data)
  47. {
  48. grub_outl (addr, GRUB_PCI_ADDR_REG);
  49. grub_outl (data, GRUB_PCI_DATA_REG);
  50. }
  51. static inline void
  52. grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data)
  53. {
  54. grub_outl (addr & ~3, GRUB_PCI_ADDR_REG);
  55. grub_outw (data, GRUB_PCI_DATA_REG + (addr & 3));
  56. }
  57. static inline void
  58. grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
  59. {
  60. grub_outl (addr & ~3, GRUB_PCI_ADDR_REG);
  61. grub_outb (data, GRUB_PCI_DATA_REG + (addr & 3));
  62. }
  63. #ifndef GRUB_MACHINE_IEEE1275
  64. static inline volatile void *
  65. grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)),
  66. grub_addr_t base,
  67. grub_size_t size __attribute__ ((unused)))
  68. {
  69. return (volatile void *) base;
  70. }
  71. static inline void
  72. grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)),
  73. volatile void *mem __attribute__ ((unused)),
  74. grub_size_t size __attribute__ ((unused)))
  75. {
  76. }
  77. #else
  78. volatile void *
  79. grub_pci_device_map_range (grub_pci_device_t dev,
  80. grub_addr_t base,
  81. grub_size_t size);
  82. void
  83. grub_pci_device_unmap_range (grub_pci_device_t dev,
  84. volatile void *mem,
  85. grub_size_t size);
  86. #endif
  87. #endif /* GRUB_CPU_PCI_H */