1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PCI_BRIDGE_EMUL_H__
3 #define __PCI_BRIDGE_EMUL_H__
5 #include <linux/kernel.h>
7 /* PCI configuration space of a PCI-to-PCI bridge. */
8 struct pci_bridge_emul_conf {
13 __le32 class_revision;
22 u8 secondary_latency_timer;
25 __le16 secondary_status;
29 __le16 pref_mem_limit;
31 __le32 preflimitupper;
34 u8 capabilities_pointer;
42 /* PCI configuration space of the PCIe capabilities */
43 struct pci_bridge_emul_pcie_conf {
70 struct pci_bridge_emul;
72 typedef enum { PCI_BRIDGE_EMUL_HANDLED,
73 PCI_BRIDGE_EMUL_NOT_HANDLED } pci_bridge_emul_read_status_t;
75 struct pci_bridge_emul_ops {
77 * Called when reading from the regular PCI bridge
78 * configuration space. Return PCI_BRIDGE_EMUL_HANDLED when the
79 * operation has handled the read operation and filled in the
80 * *value, or PCI_BRIDGE_EMUL_NOT_HANDLED when the read should
81 * be emulated by the common code by reading from the
82 * in-memory copy of the configuration space.
84 pci_bridge_emul_read_status_t (*read_base)(struct pci_bridge_emul *bridge,
88 * Same as ->read_base(), except it is for reading from the
89 * PCIe capability configuration space.
91 pci_bridge_emul_read_status_t (*read_pcie)(struct pci_bridge_emul *bridge,
95 * Same as ->read_base(), except it is for reading from the
96 * PCIe extended capability configuration space.
98 pci_bridge_emul_read_status_t (*read_ext)(struct pci_bridge_emul *bridge,
102 * Called when writing to the regular PCI bridge configuration
103 * space. old is the current value, new is the new value being
104 * written, and mask indicates which parts of the value are
107 void (*write_base)(struct pci_bridge_emul *bridge, int reg,
108 u32 old, u32 new, u32 mask);
111 * Same as ->write_base(), except it is for writing from the
112 * PCIe capability configuration space.
114 void (*write_pcie)(struct pci_bridge_emul *bridge, int reg,
115 u32 old, u32 new, u32 mask);
118 * Same as ->write_base(), except it is for writing from the
119 * PCIe extended capability configuration space.
121 void (*write_ext)(struct pci_bridge_emul *bridge, int reg,
122 u32 old, u32 new, u32 mask);
125 struct pci_bridge_reg_behavior;
127 struct pci_bridge_emul {
128 struct pci_bridge_emul_conf conf;
129 struct pci_bridge_emul_pcie_conf pcie_conf;
130 const struct pci_bridge_emul_ops *ops;
131 struct pci_bridge_reg_behavior *pci_regs_behavior;
132 struct pci_bridge_reg_behavior *pcie_cap_regs_behavior;
137 u16 subsystem_vendor_id;
143 * PCI bridge does not support forwarding of prefetchable memory
144 * requests between primary and secondary buses.
146 PCI_BRIDGE_EMUL_NO_PREFMEM_FORWARD = BIT(0),
149 * PCI bridge does not support forwarding of IO requests between
150 * primary and secondary buses.
152 PCI_BRIDGE_EMUL_NO_IO_FORWARD = BIT(1),
155 int pci_bridge_emul_init(struct pci_bridge_emul *bridge,
157 void pci_bridge_emul_cleanup(struct pci_bridge_emul *bridge);
159 int pci_bridge_emul_conf_read(struct pci_bridge_emul *bridge, int where,
160 int size, u32 *value);
161 int pci_bridge_emul_conf_write(struct pci_bridge_emul *bridge, int where,
162 int size, u32 value);
164 #endif /* __PCI_BRIDGE_EMUL_H__ */