pciutils.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_PCIUTILS_H
  19. #define GRUB_PCIUTILS_H 1
  20. #include <pciaccess.h>
  21. typedef struct pci_device *grub_pci_device_t;
  22. static inline int
  23. grub_pci_get_bus (grub_pci_device_t dev)
  24. {
  25. return dev->bus;
  26. }
  27. static inline int
  28. grub_pci_get_device (grub_pci_device_t dev)
  29. {
  30. return dev->dev;
  31. }
  32. static inline int
  33. grub_pci_get_function (grub_pci_device_t dev)
  34. {
  35. return dev->func;
  36. }
  37. struct grub_pci_address
  38. {
  39. grub_pci_device_t dev;
  40. int pos;
  41. };
  42. typedef struct grub_pci_address grub_pci_address_t;
  43. static inline grub_uint32_t
  44. grub_pci_read (grub_pci_address_t addr)
  45. {
  46. grub_uint32_t ret;
  47. pci_device_cfg_read_u32 (addr.dev, &ret, addr.pos);
  48. return ret;
  49. }
  50. static inline grub_uint16_t
  51. grub_pci_read_word (grub_pci_address_t addr)
  52. {
  53. grub_uint16_t ret;
  54. pci_device_cfg_read_u16 (addr.dev, &ret, addr.pos);
  55. return ret;
  56. }
  57. static inline grub_uint8_t
  58. grub_pci_read_byte (grub_pci_address_t addr)
  59. {
  60. grub_uint8_t ret;
  61. pci_device_cfg_read_u8 (addr.dev, &ret, addr.pos);
  62. return ret;
  63. }
  64. static inline void
  65. grub_pci_write (grub_pci_address_t addr, grub_uint32_t data)
  66. {
  67. pci_device_cfg_write_u32 (addr.dev, data, addr.pos);
  68. }
  69. static inline void
  70. grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data)
  71. {
  72. pci_device_cfg_write_u16 (addr.dev, data, addr.pos);
  73. }
  74. static inline void
  75. grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
  76. {
  77. pci_device_cfg_write_u8 (addr.dev, data, addr.pos);
  78. }
  79. void *
  80. grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base,
  81. grub_size_t size);
  82. void
  83. grub_pci_device_unmap_range (grub_pci_device_t dev, void *mem,
  84. grub_size_t size);
  85. #endif /* GRUB_PCIUTILS_H */