pcie.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * pcie.h
  3. *
  4. * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
  5. * VA Linux Systems Japan K.K.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef QEMU_PCIE_H
  21. #define QEMU_PCIE_H
  22. #include "hw.h"
  23. #include "pci_regs.h"
  24. #include "pcie_regs.h"
  25. #include "pcie_aer.h"
  26. typedef enum {
  27. /* for attention and power indicator */
  28. PCI_EXP_HP_IND_RESERVED = PCI_EXP_SLTCTL_IND_RESERVED,
  29. PCI_EXP_HP_IND_ON = PCI_EXP_SLTCTL_IND_ON,
  30. PCI_EXP_HP_IND_BLINK = PCI_EXP_SLTCTL_IND_BLINK,
  31. PCI_EXP_HP_IND_OFF = PCI_EXP_SLTCTL_IND_OFF,
  32. } PCIExpressIndicator;
  33. typedef enum {
  34. /* these bits must match the bits in Slot Control/Status registers.
  35. * PCI_EXP_HP_EV_xxx = PCI_EXP_SLTCTL_xxxE = PCI_EXP_SLTSTA_xxx
  36. *
  37. * Not all the bits of slot control register match with the ones of
  38. * slot status. Not some bits of slot status register is used to
  39. * show status, not to report event occurrence.
  40. * So such bits must be masked out when checking the software
  41. * notification condition.
  42. */
  43. PCI_EXP_HP_EV_ABP = PCI_EXP_SLTCTL_ABPE,
  44. /* attention button pressed */
  45. PCI_EXP_HP_EV_PDC = PCI_EXP_SLTCTL_PDCE,
  46. /* presence detect changed */
  47. PCI_EXP_HP_EV_CCI = PCI_EXP_SLTCTL_CCIE,
  48. /* command completed */
  49. PCI_EXP_HP_EV_SUPPORTED = PCI_EXP_HP_EV_ABP |
  50. PCI_EXP_HP_EV_PDC |
  51. PCI_EXP_HP_EV_CCI,
  52. /* supported event mask */
  53. /* events not listed aren't supported */
  54. } PCIExpressHotPlugEvent;
  55. struct PCIExpressDevice {
  56. /* Offset of express capability in config space */
  57. uint8_t exp_cap;
  58. /* SLOT */
  59. unsigned int hpev_intx; /* INTx for hot plug event (0-3:INT[A-D]#)
  60. * default is 0 = INTA#
  61. * If the chip wants to use other interrupt
  62. * line, initialize this member with the
  63. * desired number.
  64. * If the chip dynamically changes this member,
  65. * also initialize it when loaded as
  66. * appropreately.
  67. */
  68. bool hpev_notified; /* Logical AND of conditions for hot plug event.
  69. Following 6.7.3.4:
  70. Software Notification of Hot-Plug Events, an interrupt
  71. is sent whenever the logical and of these conditions
  72. transitions from false to true. */
  73. /* AER */
  74. uint16_t aer_cap;
  75. PCIEAERLog aer_log;
  76. unsigned int aer_intx; /* INTx for error reporting
  77. * default is 0 = INTA#
  78. * If the chip wants to use other interrupt
  79. * line, initialize this member with the
  80. * desired number.
  81. * If the chip dynamically changes this member,
  82. * also initialize it when loaded as
  83. * appropreately.
  84. */
  85. };
  86. /* PCI express capability helper functions */
  87. int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, uint8_t port);
  88. void pcie_cap_exit(PCIDevice *dev);
  89. uint8_t pcie_cap_get_type(const PCIDevice *dev);
  90. void pcie_cap_flags_set_vector(PCIDevice *dev, uint8_t vector);
  91. uint8_t pcie_cap_flags_get_vector(PCIDevice *dev);
  92. void pcie_cap_deverr_init(PCIDevice *dev);
  93. void pcie_cap_deverr_reset(PCIDevice *dev);
  94. void pcie_cap_slot_init(PCIDevice *dev, uint16_t slot);
  95. void pcie_cap_slot_reset(PCIDevice *dev);
  96. void pcie_cap_slot_write_config(PCIDevice *dev,
  97. uint32_t addr, uint32_t val, int len);
  98. int pcie_cap_slot_post_load(void *opaque, int version_id);
  99. void pcie_cap_slot_push_attention_button(PCIDevice *dev);
  100. void pcie_cap_root_init(PCIDevice *dev);
  101. void pcie_cap_root_reset(PCIDevice *dev);
  102. void pcie_cap_flr_init(PCIDevice *dev);
  103. void pcie_cap_flr_write_config(PCIDevice *dev,
  104. uint32_t addr, uint32_t val, int len);
  105. void pcie_cap_ari_init(PCIDevice *dev);
  106. void pcie_cap_ari_reset(PCIDevice *dev);
  107. bool pcie_cap_is_ari_enabled(const PCIDevice *dev);
  108. /* PCI express extended capability helper functions */
  109. uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id);
  110. void pcie_add_capability(PCIDevice *dev,
  111. uint16_t cap_id, uint8_t cap_ver,
  112. uint16_t offset, uint16_t size);
  113. void pcie_ari_init(PCIDevice *dev, uint16_t offset, uint16_t nextfn);
  114. #endif /* QEMU_PCIE_H */