pci-bridge-emul.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PCI_BRIDGE_EMUL_H__
  3. #define __PCI_BRIDGE_EMUL_H__
  4. #include <linux/kernel.h>
  5. /* PCI configuration space of a PCI-to-PCI bridge. */
  6. struct pci_bridge_emul_conf {
  7. u16 vendor;
  8. u16 device;
  9. u16 command;
  10. u16 status;
  11. u32 class_revision;
  12. u8 cache_line_size;
  13. u8 latency_timer;
  14. u8 header_type;
  15. u8 bist;
  16. u32 bar[2];
  17. u8 primary_bus;
  18. u8 secondary_bus;
  19. u8 subordinate_bus;
  20. u8 secondary_latency_timer;
  21. u8 iobase;
  22. u8 iolimit;
  23. u16 secondary_status;
  24. u16 membase;
  25. u16 memlimit;
  26. u16 pref_mem_base;
  27. u16 pref_mem_limit;
  28. u32 prefbaseupper;
  29. u32 preflimitupper;
  30. u16 iobaseupper;
  31. u16 iolimitupper;
  32. u8 capabilities_pointer;
  33. u8 reserve[3];
  34. u32 romaddr;
  35. u8 intline;
  36. u8 intpin;
  37. u16 bridgectrl;
  38. };
  39. /* PCI configuration space of the PCIe capabilities */
  40. struct pci_bridge_emul_pcie_conf {
  41. u8 cap_id;
  42. u8 next;
  43. u16 cap;
  44. u32 devcap;
  45. u16 devctl;
  46. u16 devsta;
  47. u32 lnkcap;
  48. u16 lnkctl;
  49. u16 lnksta;
  50. u32 slotcap;
  51. u16 slotctl;
  52. u16 slotsta;
  53. u16 rootctl;
  54. u16 rsvd;
  55. u32 rootsta;
  56. u32 devcap2;
  57. u16 devctl2;
  58. u16 devsta2;
  59. u32 lnkcap2;
  60. u16 lnkctl2;
  61. u16 lnksta2;
  62. u32 slotcap2;
  63. u16 slotctl2;
  64. u16 slotsta2;
  65. };
  66. struct pci_bridge_emul;
  67. typedef enum { PCI_BRIDGE_EMUL_HANDLED,
  68. PCI_BRIDGE_EMUL_NOT_HANDLED } pci_bridge_emul_read_status_t;
  69. struct pci_bridge_emul_ops {
  70. /*
  71. * Called when reading from the regular PCI bridge
  72. * configuration space. Return PCI_BRIDGE_EMUL_HANDLED when the
  73. * operation has handled the read operation and filled in the
  74. * *value, or PCI_BRIDGE_EMUL_NOT_HANDLED when the read should
  75. * be emulated by the common code by reading from the
  76. * in-memory copy of the configuration space.
  77. */
  78. pci_bridge_emul_read_status_t (*read_base)(struct pci_bridge_emul *bridge,
  79. int reg, u32 *value);
  80. /*
  81. * Same as ->read_base(), except it is for reading from the
  82. * PCIe capability configuration space.
  83. */
  84. pci_bridge_emul_read_status_t (*read_pcie)(struct pci_bridge_emul *bridge,
  85. int reg, u32 *value);
  86. /*
  87. * Called when writing to the regular PCI bridge configuration
  88. * space. old is the current value, new is the new value being
  89. * written, and mask indicates which parts of the value are
  90. * being changed.
  91. */
  92. void (*write_base)(struct pci_bridge_emul *bridge, int reg,
  93. u32 old, u32 new, u32 mask);
  94. /*
  95. * Same as ->write_base(), except it is for writing from the
  96. * PCIe capability configuration space.
  97. */
  98. void (*write_pcie)(struct pci_bridge_emul *bridge, int reg,
  99. u32 old, u32 new, u32 mask);
  100. };
  101. struct pci_bridge_emul {
  102. struct pci_bridge_emul_conf conf;
  103. struct pci_bridge_emul_pcie_conf pcie_conf;
  104. struct pci_bridge_emul_ops *ops;
  105. void *data;
  106. bool has_pcie;
  107. };
  108. void pci_bridge_emul_init(struct pci_bridge_emul *bridge);
  109. int pci_bridge_emul_conf_read(struct pci_bridge_emul *bridge, int where,
  110. int size, u32 *value);
  111. int pci_bridge_emul_conf_write(struct pci_bridge_emul *bridge, int where,
  112. int size, u32 value);
  113. #endif /* __PCI_BRIDGE_EMUL_H__ */