pci.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_PCI_H
  19. #define GRUB_PCI_H 1
  20. #ifndef ASM_FILE
  21. #include <grub/types.h>
  22. #include <grub/symbol.h>
  23. #endif
  24. #define GRUB_PCI_ADDR_SPACE_MASK 0x01
  25. #define GRUB_PCI_ADDR_SPACE_MEMORY 0x00
  26. #define GRUB_PCI_ADDR_SPACE_IO 0x01
  27. #define GRUB_PCI_ADDR_MEM_TYPE_MASK 0x06
  28. #define GRUB_PCI_ADDR_MEM_TYPE_32 0x00 /* 32 bit address */
  29. #define GRUB_PCI_ADDR_MEM_TYPE_1M 0x02 /* Below 1M [obsolete] */
  30. #define GRUB_PCI_ADDR_MEM_TYPE_64 0x04 /* 64 bit address */
  31. #define GRUB_PCI_ADDR_MEM_PREFETCH 0x08 /* prefetchable */
  32. #define GRUB_PCI_ADDR_MEM_MASK ~0xf
  33. #define GRUB_PCI_ADDR_IO_MASK ~0x03
  34. #define GRUB_PCI_REG_PCI_ID 0x00
  35. #define GRUB_PCI_REG_VENDOR 0x00
  36. #define GRUB_PCI_REG_DEVICE 0x02
  37. #define GRUB_PCI_REG_COMMAND 0x04
  38. #define GRUB_PCI_REG_STATUS 0x06
  39. #define GRUB_PCI_REG_REVISION 0x08
  40. #define GRUB_PCI_REG_CLASS 0x08
  41. #define GRUB_PCI_REG_CACHELINE 0x0c
  42. #define GRUB_PCI_REG_LAT_TIMER 0x0d
  43. #define GRUB_PCI_REG_HEADER_TYPE 0x0e
  44. #define GRUB_PCI_REG_BIST 0x0f
  45. #define GRUB_PCI_REG_ADDRESSES 0x10
  46. /* Beware that 64-bit address takes 2 registers. */
  47. #define GRUB_PCI_REG_ADDRESS_REG0 0x10
  48. #define GRUB_PCI_REG_ADDRESS_REG1 0x14
  49. #define GRUB_PCI_REG_ADDRESS_REG2 0x18
  50. #define GRUB_PCI_REG_ADDRESS_REG3 0x1c
  51. #define GRUB_PCI_REG_ADDRESS_REG4 0x20
  52. #define GRUB_PCI_REG_ADDRESS_REG5 0x24
  53. #define GRUB_PCI_REG_CIS_POINTER 0x28
  54. #define GRUB_PCI_REG_SUBVENDOR 0x2c
  55. #define GRUB_PCI_REG_SUBSYSTEM 0x2e
  56. #define GRUB_PCI_REG_ROM_ADDRESS 0x30
  57. #define GRUB_PCI_REG_CAP_POINTER 0x34
  58. #define GRUB_PCI_REG_IRQ_LINE 0x3c
  59. #define GRUB_PCI_REG_IRQ_PIN 0x3d
  60. #define GRUB_PCI_REG_MIN_GNT 0x3e
  61. #define GRUB_PCI_REG_MAX_LAT 0x3f
  62. #define GRUB_PCI_COMMAND_IO_ENABLED 0x0001
  63. #define GRUB_PCI_COMMAND_MEM_ENABLED 0x0002
  64. #define GRUB_PCI_COMMAND_BUS_MASTER 0x0004
  65. #define GRUB_PCI_COMMAND_PARITY_ERROR 0x0040
  66. #define GRUB_PCI_COMMAND_SERR_ENABLE 0x0100
  67. #define GRUB_PCI_STATUS_CAPABILITIES 0x0010
  68. #define GRUB_PCI_STATUS_66MHZ_CAPABLE 0x0020
  69. #define GRUB_PCI_STATUS_FAST_B2B_CAPABLE 0x0080
  70. #define GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT 9
  71. #define GRUB_PCI_STATUS_DEVSEL_TIMING_MASK 0x0600
  72. #define GRUB_PCI_CLASS_DISPLAY_VGA 0x0300
  73. #define GRUB_PCI_CLASS_SERIAL_USB 0x0c03
  74. #define GRUB_PCI_CLASS_COMMUNICATION_SERIAL 0x0700
  75. #define GRUB_PCI_CLASS_COMMUNICATION_MODEM 0x0703
  76. #define GRUB_PCI_SERIAL_16550_COMPATIBLE 0x02
  77. #ifndef ASM_FILE
  78. enum
  79. {
  80. GRUB_PCI_CLASS_NETWORK = 0x02
  81. };
  82. enum
  83. {
  84. GRUB_PCI_CAP_POWER_MANAGEMENT = 0x01
  85. };
  86. enum
  87. {
  88. GRUB_PCI_VENDOR_BROADCOM = 0x14e4
  89. };
  90. typedef grub_uint32_t grub_pci_id_t;
  91. #ifdef GRUB_MACHINE_EMU
  92. #include <grub/pciutils.h>
  93. #else
  94. typedef grub_uint32_t grub_pci_address_t;
  95. struct grub_pci_device
  96. {
  97. int bus;
  98. int device;
  99. int function;
  100. };
  101. typedef struct grub_pci_device grub_pci_device_t;
  102. static inline int
  103. grub_pci_get_bus (grub_pci_device_t dev)
  104. {
  105. return dev.bus;
  106. }
  107. static inline int
  108. grub_pci_get_device (grub_pci_device_t dev)
  109. {
  110. return dev.device;
  111. }
  112. static inline int
  113. grub_pci_get_function (grub_pci_device_t dev)
  114. {
  115. return dev.function;
  116. }
  117. #include <grub/cpu/pci.h>
  118. #endif
  119. typedef int (*grub_pci_iteratefunc_t)
  120. (grub_pci_device_t dev, grub_pci_id_t pciid, void *data);
  121. grub_pci_address_t EXPORT_FUNC(grub_pci_make_address) (grub_pci_device_t dev,
  122. int reg);
  123. void EXPORT_FUNC(grub_pci_iterate) (grub_pci_iteratefunc_t hook,
  124. void *hook_data);
  125. #include <grub/dma.h>
  126. grub_uint8_t
  127. EXPORT_FUNC (grub_pci_find_capability) (grub_pci_device_t dev, grub_uint8_t cap);
  128. #endif
  129. #endif /* GRUB_PCI_H */