10 #define TEMU_BUS_PCI_H 
   15 #include "temu-c/Bus/PCIDefines.h" 
   16 #include "temu-c/Memory/Memory.h" 
   17 #include "temu-c/Support/Logging.h" 
   18 #include "temu-c/Support/Objsys.h" 
   34 } temu_PCIDeviceVTable;
 
   36 #define TEMU_PCI_CONFIG_BYTES 256
 
   37 #define TEMU_PCIE_CONFIG_BYTES 4096
 
   38 #define TEMU_PCI_CONFIG_WORDS 64
 
   39 #define TEMU_PCIE_CONFIG_WORDS 1024
 
   48   void (*
mapPciIo)(temu_Object *Obj, 
unsigned Device, 
unsigned Bar,
 
   49                    uint64_t Addr, uint64_t Len);
 
   51   void (*
mapPciMem)(temu_Object *Obj, 
unsigned Device, 
unsigned Bar,
 
   52                     uint64_t Addr, uint64_t Len);
 
   55 TEMU_IFACE_REFERENCE_TYPE(temu_PCIBus)
 
   56 #define TEMU_PCI_BUS_IFACE_TYPE "temu::PCIBusIface" 
   63 } temu_PCIBridgeIface;
 
   64 TEMU_IFACE_REFERENCE_TYPE(temu_PCIBridge)
 
   65 #define TEMU_PCI_BRIDGE_IFACE_TYPE "temu::PCIBridgeIface" 
   70   temu_PCIConfig (*getPciConfig)(temu_Object *);
 
   73   uint32_t (*readConfig)(temu_Object *Obj, uint32_t offset);
 
   74   uint64_t (*getPciBarSize)(temu_Object *, 
unsigned bar);
 
   75   uint64_t (*getPciExpansionROMSize)(temu_Object *);
 
   78 } temu_PCIDeviceIface;
 
   79 TEMU_IFACE_REFERENCE_TYPE(temu_PCIDevice)
 
   80 #define TEMU_PCI_DEVICE_IFACE_TYPE "temu::PCIDeviceIface" 
   93 TEMU_API uint32_t temu_pciGetConfig(temu_PCIConfig config, uint32_t offset,
 
  101 temu_pciDeviceRegister(temu_Class *C)
 
  161 temu_pciSetDeviceId(temu_PCIConfig C, uint16_t Val)
 
  163   temu_pciSetConfig(C, TEMU_PCI_CONFIG_DEVICE_ID_OFFSET,
 
  164                     TEMU_PCI_CONFIG_DEVICE_ID_SIZE, Val);
 
  168 temu_pciSetVendorId(temu_PCIConfig C, uint16_t Val)
 
  170   temu_pciSetConfig(C, TEMU_PCI_CONFIG_VENDOR_ID_OFFSET,
 
  171                     TEMU_PCI_CONFIG_VENDOR_ID_SIZE, Val);
 
  175 temu_pciSetStatus(temu_PCIConfig C, uint16_t Val)
 
  177   temu_pciSetConfig(C, TEMU_PCI_CONFIG_STATUS_OFFSET,
 
  178                     TEMU_PCI_CONFIG_STATUS_SIZE, Val);
 
  182 temu_pciSetClassCode(temu_PCIConfig C, uint32_t Val)
 
  184   temu_pciSetConfig(C, TEMU_PCI_CONFIG_CLASS_CODE_OFFSET,
 
  185                     TEMU_PCI_CONFIG_CLASS_CODE_SIZE, Val);
 
  189 temu_pciSetRevId(temu_PCIConfig C, uint8_t Val)
 
  191   temu_pciSetConfig(C, TEMU_PCI_CONFIG_REVISION_ID_OFFSET,
 
  192                     TEMU_PCI_CONFIG_REVISION_ID_SIZE, Val);
 
  196 temu_pciSetBist(temu_PCIConfig C, uint8_t Val)
 
  198   temu_pciSetConfig(C, TEMU_PCI_CONFIG_BIST_OFFSET, TEMU_PCI_CONFIG_BIST_SIZE,
 
  203 temu_pciSetHeaderType(temu_PCIConfig C, uint8_t Val)
 
  205   temu_pciSetConfig(C, TEMU_PCI_CONFIG_HEADER_TYPE_OFFSET,
 
  206                     TEMU_PCI_CONFIG_HEADER_TYPE_SIZE, Val);
 
  210 temu_pciSetLatencyTimer(temu_PCIConfig C, uint8_t Val)
 
  212   temu_pciSetConfig(C, TEMU_PCI_CONFIG_LATENCY_TIMER_OFFSET,
 
  213                     TEMU_PCI_CONFIG_LATENCY_TIMER_SIZE, Val);
 
  217 temu_pciSetCacheLineSize(temu_PCIConfig C, uint8_t Val)
 
  219   temu_pciSetConfig(C, TEMU_PCI_CONFIG_CACHELINE_SIZE_OFFSET,
 
  220                     TEMU_PCI_CONFIG_CACHELINE_SIZE_SIZE, Val);
 
  224 temu_pciSetInterruptPin(temu_PCIConfig C, uint8_t Val)
 
  227   temu_pciSetConfig(C, TEMU_PCI_TYPE_00_INTERRUPT_PIN_OFFSET,
 
  228                     TEMU_PCI_TYPE_00_INTERRUPT_PIN_SIZE, Val);
 
  232 temu_pciSetSubsystemId(temu_PCIConfig C, uint16_t Val)
 
  234   assert(temu_pciGetConfig(C, TEMU_PCI_CONFIG_HEADER_TYPE_OFFSET,
 
  235                            TEMU_PCI_CONFIG_HEADER_TYPE_SIZE) == 0);
 
  236   temu_pciSetConfig(C, TEMU_PCI_TYPE_00_SUBSYSTEM_ID_OFFSET,
 
  237                     TEMU_PCI_TYPE_00_SUBSYSTEM_ID_SIZE, Val);
 
  241 temu_pciSetSubsystemVendorId(temu_PCIConfig C, uint16_t Val)
 
  243   assert(temu_pciGetConfig(C, TEMU_PCI_CONFIG_HEADER_TYPE_OFFSET,
 
  244                            TEMU_PCI_CONFIG_HEADER_TYPE_SIZE) == 0);
 
  245   temu_pciSetConfig(C, TEMU_PCI_TYPE_00_SUBSYSTEM_VENDOR_ID_OFFSET,
 
  246                     TEMU_PCI_TYPE_00_SUBSYSTEM_VENDOR_ID_SIZE, Val);