19ae1329eSCédric Le Goater /* 29ae1329eSCédric Le Goater * QEMU PowerPC PowerNV (POWER8) PHB3 model 39ae1329eSCédric Le Goater * 49ae1329eSCédric Le Goater * Copyright (c) 2014-2020, IBM Corporation. 59ae1329eSCédric Le Goater * 69ae1329eSCédric Le Goater * This code is licensed under the GPL version 2 or later. See the 79ae1329eSCédric Le Goater * COPYING file in the top-level directory. 89ae1329eSCédric Le Goater */ 99ae1329eSCédric Le Goater 109ae1329eSCédric Le Goater #ifndef PCI_HOST_PNV_PHB3_H 119ae1329eSCédric Le Goater #define PCI_HOST_PNV_PHB3_H 129ae1329eSCédric Le Goater 139ae1329eSCédric Le Goater #include "hw/pci/pcie_host.h" 149ae1329eSCédric Le Goater #include "hw/pci/pcie_port.h" 159ae1329eSCédric Le Goater #include "hw/ppc/xics.h" 16*db1015e9SEduardo Habkost #include "qom/object.h" 179ae1329eSCédric Le Goater 189ae1329eSCédric Le Goater typedef struct PnvPHB3 PnvPHB3; 199ae1329eSCédric Le Goater 209ae1329eSCédric Le Goater /* 219ae1329eSCédric Le Goater * PHB3 XICS Source for MSIs 229ae1329eSCédric Le Goater */ 239ae1329eSCédric Le Goater #define TYPE_PHB3_MSI "phb3-msi" 24*db1015e9SEduardo Habkost typedef struct Phb3MsiState Phb3MsiState; 259ae1329eSCédric Le Goater #define PHB3_MSI(obj) OBJECT_CHECK(Phb3MsiState, (obj), TYPE_PHB3_MSI) 269ae1329eSCédric Le Goater 279ae1329eSCédric Le Goater #define PHB3_MAX_MSI 2048 289ae1329eSCédric Le Goater 29*db1015e9SEduardo Habkost struct Phb3MsiState { 309ae1329eSCédric Le Goater ICSState ics; 319ae1329eSCédric Le Goater qemu_irq *qirqs; 329ae1329eSCédric Le Goater 339ae1329eSCédric Le Goater PnvPHB3 *phb; 349ae1329eSCédric Le Goater uint64_t rba[PHB3_MAX_MSI / 64]; 359ae1329eSCédric Le Goater uint32_t rba_sum; 36*db1015e9SEduardo Habkost }; 379ae1329eSCédric Le Goater 389ae1329eSCédric Le Goater void pnv_phb3_msi_update_config(Phb3MsiState *msis, uint32_t base, 399ae1329eSCédric Le Goater uint32_t count); 409ae1329eSCédric Le Goater void pnv_phb3_msi_send(Phb3MsiState *msis, uint64_t addr, uint16_t data, 419ae1329eSCédric Le Goater int32_t dev_pe); 429ae1329eSCédric Le Goater void pnv_phb3_msi_ffi(Phb3MsiState *msis, uint64_t val); 439ae1329eSCédric Le Goater void pnv_phb3_msi_pic_print_info(Phb3MsiState *msis, Monitor *mon); 449ae1329eSCédric Le Goater 459ae1329eSCédric Le Goater 469ae1329eSCédric Le Goater /* 479ae1329eSCédric Le Goater * We have one such address space wrapper per possible device under 489ae1329eSCédric Le Goater * the PHB since they need to be assigned statically at qemu device 499ae1329eSCédric Le Goater * creation time. The relationship to a PE is done later dynamically. 509ae1329eSCédric Le Goater * This means we can potentially create a lot of these guys. Q35 519ae1329eSCédric Le Goater * stores them as some kind of radix tree but we never really need to 529ae1329eSCédric Le Goater * do fast lookups so instead we simply keep a QLIST of them for now, 539ae1329eSCédric Le Goater * we can add the radix if needed later on. 549ae1329eSCédric Le Goater * 559ae1329eSCédric Le Goater * We do cache the PE number to speed things up a bit though. 569ae1329eSCédric Le Goater */ 579ae1329eSCédric Le Goater typedef struct PnvPhb3DMASpace { 589ae1329eSCédric Le Goater PCIBus *bus; 599ae1329eSCédric Le Goater uint8_t devfn; 609ae1329eSCédric Le Goater int pe_num; /* Cached PE number */ 619ae1329eSCédric Le Goater #define PHB_INVALID_PE (-1) 629ae1329eSCédric Le Goater PnvPHB3 *phb; 639ae1329eSCédric Le Goater AddressSpace dma_as; 649ae1329eSCédric Le Goater IOMMUMemoryRegion dma_mr; 659ae1329eSCédric Le Goater MemoryRegion msi32_mr; 669ae1329eSCédric Le Goater MemoryRegion msi64_mr; 679ae1329eSCédric Le Goater QLIST_ENTRY(PnvPhb3DMASpace) list; 689ae1329eSCédric Le Goater } PnvPhb3DMASpace; 699ae1329eSCédric Le Goater 709ae1329eSCédric Le Goater /* 719ae1329eSCédric Le Goater * PHB3 Power Bus Common Queue 729ae1329eSCédric Le Goater */ 739ae1329eSCédric Le Goater #define TYPE_PNV_PBCQ "pnv-pbcq" 74*db1015e9SEduardo Habkost typedef struct PnvPBCQState PnvPBCQState; 759ae1329eSCédric Le Goater #define PNV_PBCQ(obj) OBJECT_CHECK(PnvPBCQState, (obj), TYPE_PNV_PBCQ) 769ae1329eSCédric Le Goater 77*db1015e9SEduardo Habkost struct PnvPBCQState { 789ae1329eSCédric Le Goater DeviceState parent; 799ae1329eSCédric Le Goater 809ae1329eSCédric Le Goater uint32_t nest_xbase; 819ae1329eSCédric Le Goater uint32_t spci_xbase; 829ae1329eSCédric Le Goater uint32_t pci_xbase; 839ae1329eSCédric Le Goater #define PBCQ_NEST_REGS_COUNT 0x46 849ae1329eSCédric Le Goater #define PBCQ_PCI_REGS_COUNT 0x15 859ae1329eSCédric Le Goater #define PBCQ_SPCI_REGS_COUNT 0x5 869ae1329eSCédric Le Goater 879ae1329eSCédric Le Goater uint64_t nest_regs[PBCQ_NEST_REGS_COUNT]; 889ae1329eSCédric Le Goater uint64_t spci_regs[PBCQ_SPCI_REGS_COUNT]; 899ae1329eSCédric Le Goater uint64_t pci_regs[PBCQ_PCI_REGS_COUNT]; 909ae1329eSCédric Le Goater MemoryRegion mmbar0; 919ae1329eSCédric Le Goater MemoryRegion mmbar1; 929ae1329eSCédric Le Goater MemoryRegion phbbar; 939ae1329eSCédric Le Goater uint64_t mmio0_base; 949ae1329eSCédric Le Goater uint64_t mmio0_size; 959ae1329eSCédric Le Goater uint64_t mmio1_base; 969ae1329eSCédric Le Goater uint64_t mmio1_size; 979ae1329eSCédric Le Goater PnvPHB3 *phb; 989ae1329eSCédric Le Goater 999ae1329eSCédric Le Goater MemoryRegion xscom_nest_regs; 1009ae1329eSCédric Le Goater MemoryRegion xscom_pci_regs; 1019ae1329eSCédric Le Goater MemoryRegion xscom_spci_regs; 102*db1015e9SEduardo Habkost }; 1039ae1329eSCédric Le Goater 1049ae1329eSCédric Le Goater /* 1059ae1329eSCédric Le Goater * PHB3 PCIe Root port 1069ae1329eSCédric Le Goater */ 1079ae1329eSCédric Le Goater #define TYPE_PNV_PHB3_ROOT_BUS "pnv-phb3-root-bus" 1089ae1329eSCédric Le Goater 1099ae1329eSCédric Le Goater #define TYPE_PNV_PHB3_ROOT_PORT "pnv-phb3-root-port" 1109ae1329eSCédric Le Goater 1119ae1329eSCédric Le Goater typedef struct PnvPHB3RootPort { 1129ae1329eSCédric Le Goater PCIESlot parent_obj; 1139ae1329eSCédric Le Goater } PnvPHB3RootPort; 1149ae1329eSCédric Le Goater 1159ae1329eSCédric Le Goater /* 1169ae1329eSCédric Le Goater * PHB3 PCIe Host Bridge for PowerNV machines (POWER8) 1179ae1329eSCédric Le Goater */ 1189ae1329eSCédric Le Goater #define TYPE_PNV_PHB3 "pnv-phb3" 1199ae1329eSCédric Le Goater #define PNV_PHB3(obj) OBJECT_CHECK(PnvPHB3, (obj), TYPE_PNV_PHB3) 1209ae1329eSCédric Le Goater 1219ae1329eSCédric Le Goater #define PNV_PHB3_NUM_M64 16 1229ae1329eSCédric Le Goater #define PNV_PHB3_NUM_REGS (0x1000 >> 3) 1239ae1329eSCédric Le Goater #define PNV_PHB3_NUM_LSI 8 1249ae1329eSCédric Le Goater #define PNV_PHB3_NUM_PE 256 1259ae1329eSCédric Le Goater 1269ae1329eSCédric Le Goater #define PCI_MMIO_TOTAL_SIZE (0x1ull << 60) 1279ae1329eSCédric Le Goater 1289ae1329eSCédric Le Goater struct PnvPHB3 { 1299ae1329eSCédric Le Goater PCIExpressHost parent_obj; 1309ae1329eSCédric Le Goater 1319ae1329eSCédric Le Goater uint32_t chip_id; 1329ae1329eSCédric Le Goater uint32_t phb_id; 1339ae1329eSCédric Le Goater char bus_path[8]; 1349ae1329eSCédric Le Goater 1359ae1329eSCédric Le Goater uint64_t regs[PNV_PHB3_NUM_REGS]; 1369ae1329eSCédric Le Goater MemoryRegion mr_regs; 1379ae1329eSCédric Le Goater 1389ae1329eSCédric Le Goater MemoryRegion mr_m32; 1399ae1329eSCédric Le Goater MemoryRegion mr_m64[PNV_PHB3_NUM_M64]; 1409ae1329eSCédric Le Goater MemoryRegion pci_mmio; 1419ae1329eSCédric Le Goater MemoryRegion pci_io; 1429ae1329eSCédric Le Goater 1439ae1329eSCédric Le Goater uint64_t ioda_LIST[8]; 1449ae1329eSCédric Le Goater uint64_t ioda_LXIVT[8]; 1459ae1329eSCédric Le Goater uint64_t ioda_TVT[512]; 1469ae1329eSCédric Le Goater uint64_t ioda_M64BT[16]; 1479ae1329eSCédric Le Goater uint64_t ioda_MDT[256]; 1489ae1329eSCédric Le Goater uint64_t ioda_PEEV[4]; 1499ae1329eSCédric Le Goater 1509ae1329eSCédric Le Goater uint32_t total_irq; 1519ae1329eSCédric Le Goater ICSState lsis; 1529ae1329eSCédric Le Goater qemu_irq *qirqs; 1539ae1329eSCédric Le Goater Phb3MsiState msis; 1549ae1329eSCédric Le Goater 1559ae1329eSCédric Le Goater PnvPBCQState pbcq; 1569ae1329eSCédric Le Goater 1579ae1329eSCédric Le Goater PnvPHB3RootPort root; 1589ae1329eSCédric Le Goater 1599ae1329eSCédric Le Goater QLIST_HEAD(, PnvPhb3DMASpace) dma_spaces; 1609ae1329eSCédric Le Goater }; 1619ae1329eSCédric Le Goater 1629ae1329eSCédric Le Goater uint64_t pnv_phb3_reg_read(void *opaque, hwaddr off, unsigned size); 1639ae1329eSCédric Le Goater void pnv_phb3_reg_write(void *opaque, hwaddr off, uint64_t val, unsigned size); 1649ae1329eSCédric Le Goater void pnv_phb3_update_regions(PnvPHB3 *phb); 1659ae1329eSCédric Le Goater void pnv_phb3_remap_irqs(PnvPHB3 *phb); 1669ae1329eSCédric Le Goater 1679ae1329eSCédric Le Goater #endif /* PCI_HOST_PNV_PHB3_H */ 168