9 #ifndef TEMU_BUS_PCIe_H
10 #define TEMU_BUS_PCIe_H
15 #include "temu-c/Bus/PCI.h"
16 #include "temu-c/Bus/PCIDefines.h"
17 #include "temu-c/Memory/Memory.h"
18 #include "temu-c/Support/Logging.h"
19 #include "temu-c/Support/Objsys.h"
63 } temu_PCIeMessageTypes;
66 void (*
mapPciIo)(temu_Object *Obj,
unsigned Device,
unsigned Bar,
67 uint64_t Addr, uint64_t Len);
69 void (*
mapPciMem)(temu_Object *Obj,
unsigned Device,
unsigned Bar,
70 uint64_t Addr, uint64_t Len);
72 } temu_PCIExpressBusIface;
73 TEMU_IFACE_REFERENCE_TYPE(temu_PCIExpressBus)
74 #define TEMU_PCIe_BUS_IFACE_TYPE "temu::PCIExpressBusIface"
81 void (*
sendMessage)(
void *, temu_PCIeMessageTypes msgType, uint8_t *payload);
83 } temu_PCIExpressBridgeIface;
84 TEMU_IFACE_REFERENCE_TYPE(temu_PCIExpressBridge)
85 #define TEMU_PCIe_BRIDGE_IFACE_TYPE "temu::PCIExpressBridgeIface"
93 } temu_PCIExpressDevice;
111 static inline temu_PCIExpressBus *
112 temu_pciGetRootBus(temu_PCIExpressDevice *device)
116 while (bus->ParentDev != NULL) {
117 device = &bus->ParentDev->Super;
118 bus = device->PrimaryBus;
124 temu_pcieSetPrimaryBusId(temu_PCIExpressBridge *C, uint8_t Val)
129 temu_pcieSetSecondaryBusId(temu_PCIExpressBridge *C, uint8_t Val)
134 temu_pcieSetSubordinaryBusId(temu_PCIExpressBridge *C, uint8_t Val)
140 temu_pcieSetBusId(temu_PCIExpressBus *C, uint8_t Val)
145 temu_pcieSetDeviceId(temu_PCIConfig config, uint16_t Val)
147 temu_pciSetConfig(config, TEMU_PCI_CONFIG_DEVICE_ID_OFFSET,
148 TEMU_PCI_CONFIG_DEVICE_ID_SIZE, Val);
152 temu_pcieSetVendorId(temu_PCIConfig config, uint16_t Val)
154 temu_pciSetConfig(config, TEMU_PCI_CONFIG_VENDOR_ID_OFFSET,
155 TEMU_PCI_CONFIG_VENDOR_ID_SIZE, Val);
159 temu_pcieSetStatus(temu_PCIConfig config, uint16_t Val)
161 temu_pciSetConfig(config, TEMU_PCI_CONFIG_STATUS_OFFSET,
162 TEMU_PCI_CONFIG_STATUS_SIZE, Val);
164 static inline uint16_t
165 temu_pcieReadStatus(temu_PCIConfig config)
167 return temu_pciGetConfig(config, TEMU_PCI_CONFIG_STATUS_OFFSET,
168 TEMU_PCI_CONFIG_STATUS_SIZE);
172 temu_pcieSetClassCode(temu_PCIConfig config, uint32_t Val)
174 temu_pciSetConfig(config, TEMU_PCI_CONFIG_CLASS_CODE_OFFSET,
175 TEMU_PCI_CONFIG_CLASS_CODE_SIZE, Val);
179 temu_pcieSetRevId(temu_PCIConfig config, uint8_t Val)
181 temu_pciSetConfig(config, TEMU_PCI_CONFIG_REVISION_ID_OFFSET,
182 TEMU_PCI_CONFIG_REVISION_ID_SIZE, Val);
186 temu_pcieSetBist(temu_PCIConfig config, uint8_t Val)
188 temu_pciSetConfig(config, TEMU_PCI_CONFIG_BIST_OFFSET,
189 TEMU_PCI_CONFIG_BIST_SIZE, Val);
193 temu_pcieSetHeaderType(temu_PCIConfig config, uint8_t Val)
195 temu_pciSetConfig(config, TEMU_PCI_CONFIG_HEADER_TYPE_OFFSET,
196 TEMU_PCI_CONFIG_HEADER_TYPE_SIZE, Val);
200 temu_pcieSetLatencyTimer(temu_PCIConfig config, uint8_t Val)
202 temu_pciSetConfig(config, TEMU_PCI_CONFIG_LATENCY_TIMER_OFFSET,
203 TEMU_PCI_CONFIG_LATENCY_TIMER_SIZE, Val);
207 temu_pcieSetCacheLineSize(temu_PCIConfig config, uint8_t Val)
209 temu_pciSetConfig(config, TEMU_PCI_CONFIG_CACHELINE_SIZE_OFFSET,
210 TEMU_PCI_CONFIG_CACHELINE_SIZE_SIZE, Val);
214 temu_pcieSetInterruptPin0(temu_PCIConfig config, uint8_t Val)
217 temu_pciSetConfig(config, TEMU_PCI_TYPE_00_INTERRUPT_PIN_OFFSET,
218 TEMU_PCI_TYPE_00_INTERRUPT_PIN_SIZE, Val);
222 temu_pcieSetSubsystemId(temu_PCIConfig config, uint16_t Val)
224 assert(temu_pciGetConfig(config, TEMU_PCI_CONFIG_HEADER_TYPE_OFFSET,
225 TEMU_PCI_CONFIG_HEADER_TYPE_SIZE) == 0);
226 temu_pciSetConfig(config, TEMU_PCI_TYPE_00_SUBSYSTEM_ID_OFFSET,
227 TEMU_PCI_TYPE_00_SUBSYSTEM_ID_SIZE, Val);
231 temu_pcieSetSubsystemVendorId(temu_PCIConfig config, uint16_t Val)
233 assert(temu_pciGetConfig(config, TEMU_PCI_CONFIG_HEADER_TYPE_OFFSET,
234 TEMU_PCI_CONFIG_HEADER_TYPE_SIZE) == 0);
235 temu_pciSetConfig(config, TEMU_PCI_TYPE_00_SUBSYSTEM_VENDOR_ID_OFFSET,
236 TEMU_PCI_TYPE_00_SUBSYSTEM_VENDOR_ID_SIZE, Val);
239 temu_pcieSetPrimaryBusNumber(temu_PCIConfig config, uint8_t Val)
241 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_PRIMARY_BUS_NUMBER_OFFSET,
242 TEMU_PCI_TYPE_01_PRIMARY_BUS_NUMBER_SIZE, Val);
245 temu_pcieSetSecondaryBusNumber(temu_PCIConfig config, uint8_t Val)
247 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_SECONDARY_BUS_NUMBER_OFFSET,
248 TEMU_PCI_TYPE_01_SECONDARY_BUS_NUMBER_SIZE, Val);
251 temu_pcieSetSubordinateBusNumber(temu_PCIConfig config, uint8_t Val)
253 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_SUBORDINATE_BUS_NUMBER_OFFSET,
254 TEMU_PCI_TYPE_01_SUBORDINATE_BUS_NUMBER_SIZE, Val);
257 temu_pcieSetIOBase(temu_PCIConfig config, uint8_t Val)
259 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_IO_BASE_OFFSET,
260 TEMU_PCI_TYPE_01_IO_BASE_SIZE, Val);
263 temu_pcieSetIOLimit(temu_PCIConfig config, uint8_t Val)
265 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_IO_LIMIT_OFFSET,
266 TEMU_PCI_TYPE_01_IO_LIMIT_SIZE, Val);
269 temu_pcieSetSecondaryStatus(temu_PCIConfig config, uint16_t Val)
271 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_SECONDARY_STATUS_OFFSET,
272 TEMU_PCI_TYPE_01_SECONDARY_STATUS_SIZE, Val);
275 temu_pcieSetMemoryBase(temu_PCIConfig config, uint16_t Val)
277 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_MEMORY_BASE_OFFSET,
278 TEMU_PCI_TYPE_01_MEMORY_BASE_SIZE, Val);
281 temu_pcieSetMemoryLimit(temu_PCIConfig config, uint16_t Val)
283 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_MEMORY_LIMIT_OFFSET,
284 TEMU_PCI_TYPE_01_MEMORY_LIMIT_SIZE, Val);
287 temu_pcieSetPrefetchableMemoryBase(temu_PCIConfig config, uint16_t Val)
289 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_PREFETCHABLE_MEMORY_BASE_OFFSET,
290 TEMU_PCI_TYPE_01_PREFETCHABLE_MEMORY_BASE_SIZE, Val);
293 temu_pcieSetPrefetchableMemoryLimit(temu_PCIConfig config, uint16_t Val)
295 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_PREFETCHABLE_MEMORY_LIMIT_OFFSET,
296 TEMU_PCI_TYPE_01_PREFETCHABLE_MEMORY_LIMIT_SIZE, Val);
299 temu_pcieSetInterruptLine(temu_PCIConfig config, uint8_t Val)
301 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_INTERRUPT_LINE_OFFSET,
302 TEMU_PCI_TYPE_01_INTERRUPT_LINE_SIZE, Val);
305 temu_pcieSetInterruptPin1(temu_PCIConfig config, uint8_t Val)
307 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_INTERRUPT_PIN_OFFSET,
308 TEMU_PCI_TYPE_01_INTERRUPT_PIN_SIZE, Val);
311 temu_pcieSetBridgeControl(temu_PCIConfig config, uint16_t Val)
313 temu_pciSetConfig(config, TEMU_PCI_TYPE_01_BRIDGE_CONTROL_OFFSET,
314 TEMU_PCI_TYPE_01_BRIDGE_CONTROL_SIZE, Val);
317 static inline uint16_t
318 temu_pcieReadBridgeControl(temu_PCIConfig config)
320 return temu_pciGetConfig(config, TEMU_PCI_TYPE_01_BRIDGE_CONTROL_OFFSET,
321 TEMU_PCI_TYPE_01_BRIDGE_CONTROL_SIZE);