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" 16db1015e9SEduardo Habkost #include "qom/object.h" 179ae1329eSCédric Le Goater 189ae1329eSCédric Le Goater typedef struct PnvPHB3 PnvPHB3; 192c4d3a50SCédric Le Goater typedef struct PnvChip PnvChip; 209ae1329eSCédric Le Goater 219ae1329eSCédric Le Goater /* 229ae1329eSCédric Le Goater * PHB3 XICS Source for MSIs 239ae1329eSCédric Le Goater */ 249ae1329eSCédric Le Goater #define TYPE_PHB3_MSI "phb3-msi" 25db1015e9SEduardo Habkost typedef struct Phb3MsiState Phb3MsiState; 268110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(Phb3MsiState, PHB3_MSI, 278110fa1dSEduardo Habkost TYPE_PHB3_MSI) 289ae1329eSCédric Le Goater 299ae1329eSCédric Le Goater #define PHB3_MAX_MSI 2048 309ae1329eSCédric Le Goater 31db1015e9SEduardo Habkost struct Phb3MsiState { 329ae1329eSCédric Le Goater ICSState ics; 339ae1329eSCédric Le Goater qemu_irq *qirqs; 349ae1329eSCédric Le Goater 359ae1329eSCédric Le Goater PnvPHB3 *phb; 369ae1329eSCédric Le Goater uint64_t rba[PHB3_MAX_MSI / 64]; 379ae1329eSCédric Le Goater uint32_t rba_sum; 38db1015e9SEduardo Habkost }; 399ae1329eSCédric Le Goater 409ae1329eSCédric Le Goater void pnv_phb3_msi_update_config(Phb3MsiState *msis, uint32_t base, 419ae1329eSCédric Le Goater uint32_t count); 429ae1329eSCédric Le Goater void pnv_phb3_msi_send(Phb3MsiState *msis, uint64_t addr, uint16_t data, 439ae1329eSCédric Le Goater int32_t dev_pe); 449ae1329eSCédric Le Goater void pnv_phb3_msi_ffi(Phb3MsiState *msis, uint64_t val); 459ae1329eSCédric Le Goater void pnv_phb3_msi_pic_print_info(Phb3MsiState *msis, Monitor *mon); 469ae1329eSCédric Le Goater 479ae1329eSCédric Le Goater 489ae1329eSCédric Le Goater /* 499ae1329eSCédric Le Goater * We have one such address space wrapper per possible device under 509ae1329eSCédric Le Goater * the PHB since they need to be assigned statically at qemu device 519ae1329eSCédric Le Goater * creation time. The relationship to a PE is done later dynamically. 529ae1329eSCédric Le Goater * This means we can potentially create a lot of these guys. Q35 539ae1329eSCédric Le Goater * stores them as some kind of radix tree but we never really need to 549ae1329eSCédric Le Goater * do fast lookups so instead we simply keep a QLIST of them for now, 559ae1329eSCédric Le Goater * we can add the radix if needed later on. 569ae1329eSCédric Le Goater * 579ae1329eSCédric Le Goater * We do cache the PE number to speed things up a bit though. 589ae1329eSCédric Le Goater */ 599ae1329eSCédric Le Goater typedef struct PnvPhb3DMASpace { 609ae1329eSCédric Le Goater PCIBus *bus; 619ae1329eSCédric Le Goater uint8_t devfn; 629ae1329eSCédric Le Goater int pe_num; /* Cached PE number */ 639ae1329eSCédric Le Goater #define PHB_INVALID_PE (-1) 649ae1329eSCédric Le Goater PnvPHB3 *phb; 659ae1329eSCédric Le Goater AddressSpace dma_as; 669ae1329eSCédric Le Goater IOMMUMemoryRegion dma_mr; 679ae1329eSCédric Le Goater MemoryRegion msi32_mr; 689ae1329eSCédric Le Goater MemoryRegion msi64_mr; 699ae1329eSCédric Le Goater QLIST_ENTRY(PnvPhb3DMASpace) list; 709ae1329eSCédric Le Goater } PnvPhb3DMASpace; 719ae1329eSCédric Le Goater 729ae1329eSCédric Le Goater /* 739ae1329eSCédric Le Goater * PHB3 Power Bus Common Queue 749ae1329eSCédric Le Goater */ 759ae1329eSCédric Le Goater #define TYPE_PNV_PBCQ "pnv-pbcq" 768063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(PnvPBCQState, PNV_PBCQ) 779ae1329eSCédric Le Goater 78db1015e9SEduardo Habkost struct PnvPBCQState { 799ae1329eSCédric Le Goater DeviceState parent; 809ae1329eSCédric Le Goater 819ae1329eSCédric Le Goater uint32_t nest_xbase; 829ae1329eSCédric Le Goater uint32_t spci_xbase; 839ae1329eSCédric Le Goater uint32_t pci_xbase; 849ae1329eSCédric Le Goater #define PBCQ_NEST_REGS_COUNT 0x46 859ae1329eSCédric Le Goater #define PBCQ_PCI_REGS_COUNT 0x15 869ae1329eSCédric Le Goater #define PBCQ_SPCI_REGS_COUNT 0x5 879ae1329eSCédric Le Goater 889ae1329eSCédric Le Goater uint64_t nest_regs[PBCQ_NEST_REGS_COUNT]; 899ae1329eSCédric Le Goater uint64_t spci_regs[PBCQ_SPCI_REGS_COUNT]; 909ae1329eSCédric Le Goater uint64_t pci_regs[PBCQ_PCI_REGS_COUNT]; 919ae1329eSCédric Le Goater MemoryRegion mmbar0; 929ae1329eSCédric Le Goater MemoryRegion mmbar1; 939ae1329eSCédric Le Goater MemoryRegion phbbar; 949ae1329eSCédric Le Goater uint64_t mmio0_base; 959ae1329eSCédric Le Goater uint64_t mmio0_size; 969ae1329eSCédric Le Goater uint64_t mmio1_base; 979ae1329eSCédric Le Goater uint64_t mmio1_size; 989ae1329eSCédric Le Goater PnvPHB3 *phb; 999ae1329eSCédric Le Goater 1009ae1329eSCédric Le Goater MemoryRegion xscom_nest_regs; 1019ae1329eSCédric Le Goater MemoryRegion xscom_pci_regs; 1029ae1329eSCédric Le Goater MemoryRegion xscom_spci_regs; 103db1015e9SEduardo Habkost }; 1049ae1329eSCédric Le Goater 1059ae1329eSCédric Le Goater /* 1069ae1329eSCédric Le Goater * PHB3 PCIe Root port 1079ae1329eSCédric Le Goater */ 108*41cb8d31SDaniel Henrique Barboza #define TYPE_PNV_PHB3_ROOT_BUS "pnv-phb3-root" 1099ae1329eSCédric Le Goater 1109ae1329eSCédric Le Goater #define TYPE_PNV_PHB3_ROOT_PORT "pnv-phb3-root-port" 1119ae1329eSCédric Le Goater 1129ae1329eSCédric Le Goater typedef struct PnvPHB3RootPort { 1139ae1329eSCédric Le Goater PCIESlot parent_obj; 1149ae1329eSCédric Le Goater } PnvPHB3RootPort; 1159ae1329eSCédric Le Goater 1169ae1329eSCédric Le Goater /* 1179ae1329eSCédric Le Goater * PHB3 PCIe Host Bridge for PowerNV machines (POWER8) 1189ae1329eSCédric Le Goater */ 1199ae1329eSCédric Le Goater #define TYPE_PNV_PHB3 "pnv-phb3" 1208063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(PnvPHB3, PNV_PHB3) 1219ae1329eSCédric Le Goater 1229ae1329eSCédric Le Goater #define PNV_PHB3_NUM_M64 16 1239ae1329eSCédric Le Goater #define PNV_PHB3_NUM_REGS (0x1000 >> 3) 1249ae1329eSCédric Le Goater #define PNV_PHB3_NUM_LSI 8 1259ae1329eSCédric Le Goater #define PNV_PHB3_NUM_PE 256 1269ae1329eSCédric Le Goater 1279ae1329eSCédric Le Goater #define PCI_MMIO_TOTAL_SIZE (0x1ull << 60) 1289ae1329eSCédric Le Goater 1299ae1329eSCédric Le Goater struct PnvPHB3 { 1309ae1329eSCédric Le Goater PCIExpressHost parent_obj; 1319ae1329eSCédric Le Goater 1329ae1329eSCédric Le Goater uint32_t chip_id; 1339ae1329eSCédric Le Goater uint32_t phb_id; 1349ae1329eSCédric Le Goater char bus_path[8]; 1359ae1329eSCédric Le Goater 1369ae1329eSCédric Le Goater uint64_t regs[PNV_PHB3_NUM_REGS]; 1379ae1329eSCédric Le Goater MemoryRegion mr_regs; 1389ae1329eSCédric Le Goater 1399ae1329eSCédric Le Goater MemoryRegion mr_m32; 1409ae1329eSCédric Le Goater MemoryRegion mr_m64[PNV_PHB3_NUM_M64]; 1419ae1329eSCédric Le Goater MemoryRegion pci_mmio; 1429ae1329eSCédric Le Goater MemoryRegion pci_io; 1439ae1329eSCédric Le Goater 1449ae1329eSCédric Le Goater uint64_t ioda_LIST[8]; 1459ae1329eSCédric Le Goater uint64_t ioda_LXIVT[8]; 1469ae1329eSCédric Le Goater uint64_t ioda_TVT[512]; 1479ae1329eSCédric Le Goater uint64_t ioda_M64BT[16]; 1489ae1329eSCédric Le Goater uint64_t ioda_MDT[256]; 1499ae1329eSCédric Le Goater uint64_t ioda_PEEV[4]; 1509ae1329eSCédric Le Goater 1519ae1329eSCédric Le Goater uint32_t total_irq; 1529ae1329eSCédric Le Goater ICSState lsis; 1539ae1329eSCédric Le Goater qemu_irq *qirqs; 1549ae1329eSCédric Le Goater Phb3MsiState msis; 1559ae1329eSCédric Le Goater 1569ae1329eSCédric Le Goater PnvPBCQState pbcq; 1579ae1329eSCédric Le Goater 1589ae1329eSCédric Le Goater QLIST_HEAD(, PnvPhb3DMASpace) dma_spaces; 1592c4d3a50SCédric Le Goater 1602c4d3a50SCédric Le Goater PnvChip *chip; 1619ae1329eSCédric Le Goater }; 1629ae1329eSCédric Le Goater 1639ae1329eSCédric Le Goater uint64_t pnv_phb3_reg_read(void *opaque, hwaddr off, unsigned size); 1649ae1329eSCédric Le Goater void pnv_phb3_reg_write(void *opaque, hwaddr off, uint64_t val, unsigned size); 1659ae1329eSCédric Le Goater void pnv_phb3_update_regions(PnvPHB3 *phb); 1669ae1329eSCédric Le Goater void pnv_phb3_remap_irqs(PnvPHB3 *phb); 1679ae1329eSCédric Le Goater 1689ae1329eSCédric Le Goater #endif /* PCI_HOST_PNV_PHB3_H */ 169