1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#ifndef QEMU_PCI_BRIDGE_H
27#define QEMU_PCI_BRIDGE_H
28
29#include "hw/pci/pci_device.h"
30#include "hw/pci/pci_bus.h"
31#include "hw/cxl/cxl.h"
32#include "qom/object.h"
33
34typedef struct PCIBridgeWindows PCIBridgeWindows;
35
36
37
38
39
40
41struct PCIBridgeWindows {
42 MemoryRegion alias_pref_mem;
43 MemoryRegion alias_mem;
44 MemoryRegion alias_io;
45
46
47
48
49
50
51 MemoryRegion alias_vga[QEMU_PCI_VGA_NUM_REGIONS];
52};
53
54#define TYPE_PCI_BRIDGE "base-pci-bridge"
55OBJECT_DECLARE_SIMPLE_TYPE(PCIBridge, PCI_BRIDGE)
56#define IS_PCI_BRIDGE(dev) object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)
57
58struct PCIBridge {
59
60 PCIDevice parent_obj;
61
62
63
64 PCIBus sec_bus;
65
66
67
68
69
70
71
72
73 MemoryRegion address_space_mem;
74 MemoryRegion address_space_io;
75
76 PCIBridgeWindows windows;
77
78 pci_map_irq_fn map_irq;
79 const char *bus_name;
80};
81
82#define PCI_BRIDGE_DEV_PROP_CHASSIS_NR "chassis_nr"
83#define PCI_BRIDGE_DEV_PROP_MSI "msi"
84#define PCI_BRIDGE_DEV_PROP_SHPC "shpc"
85typedef struct CXLHost CXLHost;
86
87typedef struct PXBDev {
88
89 PCIDevice parent_obj;
90
91
92 uint8_t bus_nr;
93 uint16_t numa_node;
94 bool bypass_iommu;
95} PXBDev;
96
97typedef struct PXBPCIEDev {
98
99 PXBDev parent_obj;
100} PXBPCIEDev;
101
102#define TYPE_PXB_DEV "pxb"
103OBJECT_DECLARE_SIMPLE_TYPE(PXBDev, PXB_DEV)
104
105typedef struct PXBCXLDev {
106
107 PXBPCIEDev parent_obj;
108
109
110 bool hdm_for_passthrough;
111 CXLHost *cxl_host_bridge;
112} PXBCXLDev;
113
114#define TYPE_PXB_CXL_DEV "pxb-cxl"
115OBJECT_DECLARE_SIMPLE_TYPE(PXBCXLDev, PXB_CXL_DEV)
116
117int pci_bridge_ssvid_init(PCIDevice *dev, uint8_t offset,
118 uint16_t svid, uint16_t ssid,
119 Error **errp);
120
121PCIDevice *pci_bridge_get_device(PCIBus *bus);
122PCIBus *pci_bridge_get_sec_bus(PCIBridge *br);
123
124pcibus_t pci_bridge_get_base(const PCIDevice *bridge, uint8_t type);
125pcibus_t pci_bridge_get_limit(const PCIDevice *bridge, uint8_t type);
126
127void pci_bridge_update_mappings(PCIBridge *br);
128void pci_bridge_write_config(PCIDevice *d,
129 uint32_t address, uint32_t val, int len);
130void pci_bridge_disable_base_limit(PCIDevice *dev);
131void pci_bridge_reset(DeviceState *qdev);
132
133void pci_bridge_initfn(PCIDevice *pci_dev, const char *typename);
134void pci_bridge_exitfn(PCIDevice *pci_dev);
135
136void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
137 Error **errp);
138void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
139 Error **errp);
140void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
141 DeviceState *dev, Error **errp);
142
143
144
145
146
147
148void pci_bridge_map_irq(PCIBridge *br, const char* bus_name,
149 pci_map_irq_fn map_irq);
150
151
152#define PCI_BRIDGE_CTL_VGA_16BIT 0x10
153#define PCI_BRIDGE_CTL_DISCARD 0x100
154#define PCI_BRIDGE_CTL_SEC_DISCARD 0x200
155#define PCI_BRIDGE_CTL_DISCARD_STATUS 0x400
156#define PCI_BRIDGE_CTL_DISCARD_SERR 0x800
157
158typedef struct PCIBridgeQemuCap {
159 uint8_t id;
160 uint8_t next;
161 uint8_t len;
162 uint8_t type;
163
164
165 uint32_t bus_res;
166 uint64_t io;
167 uint32_t mem;
168
169
170 uint32_t mem_pref_32;
171 uint64_t mem_pref_64;
172} PCIBridgeQemuCap;
173
174#define REDHAT_PCI_CAP_TYPE_OFFSET 3
175#define REDHAT_PCI_CAP_RESOURCE_RESERVE 1
176
177
178
179
180
181typedef struct PCIResReserve {
182 uint32_t bus;
183 uint64_t io;
184 uint64_t mem_non_pref;
185 uint64_t mem_pref_32;
186 uint64_t mem_pref_64;
187} PCIResReserve;
188
189#define REDHAT_PCI_CAP_RES_RESERVE_BUS_RES 4
190#define REDHAT_PCI_CAP_RES_RESERVE_IO 8
191#define REDHAT_PCI_CAP_RES_RESERVE_MEM 16
192#define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_32 20
193#define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_64 24
194#define REDHAT_PCI_CAP_RES_RESERVE_CAP_SIZE 32
195
196int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,
197 PCIResReserve res_reserve, Error **errp);
198
199#endif
200