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" 171f5d6b2aSDaniel Henrique Barboza #include "hw/pci-host/pnv_phb.h" 189ae1329eSCédric Le Goater 199ae1329eSCédric Le Goater typedef struct PnvPHB3 PnvPHB3; 202c4d3a50SCédric Le Goater typedef struct PnvChip PnvChip; 219ae1329eSCédric Le Goater 229ae1329eSCédric Le Goater /* 239ae1329eSCédric Le Goater * PHB3 XICS Source for MSIs 249ae1329eSCédric Le Goater */ 259ae1329eSCédric Le Goater #define TYPE_PHB3_MSI "phb3-msi" 26db1015e9SEduardo Habkost typedef struct Phb3MsiState Phb3MsiState; 278110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(Phb3MsiState, PHB3_MSI, 288110fa1dSEduardo Habkost TYPE_PHB3_MSI) 299ae1329eSCédric Le Goater 309ae1329eSCédric Le Goater #define PHB3_MAX_MSI 2048 319ae1329eSCédric Le Goater 32db1015e9SEduardo Habkost struct Phb3MsiState { 339ae1329eSCédric Le Goater ICSState ics; 349ae1329eSCédric Le Goater qemu_irq *qirqs; 359ae1329eSCédric Le Goater 369ae1329eSCédric Le Goater PnvPHB3 *phb; 379ae1329eSCédric Le Goater uint64_t rba[PHB3_MAX_MSI / 64]; 389ae1329eSCédric Le Goater uint32_t rba_sum; 39db1015e9SEduardo Habkost }; 409ae1329eSCédric Le Goater 419ae1329eSCédric Le Goater void pnv_phb3_msi_update_config(Phb3MsiState *msis, uint32_t base, 429ae1329eSCédric Le Goater uint32_t count); 439ae1329eSCédric Le Goater void pnv_phb3_msi_send(Phb3MsiState *msis, uint64_t addr, uint16_t data, 449ae1329eSCédric Le Goater int32_t dev_pe); 459ae1329eSCédric Le Goater void pnv_phb3_msi_ffi(Phb3MsiState *msis, uint64_t val); 469ae1329eSCédric Le Goater void pnv_phb3_msi_pic_print_info(Phb3MsiState *msis, Monitor *mon); 479ae1329eSCédric Le Goater 489ae1329eSCédric Le Goater 499ae1329eSCédric Le Goater /* 509ae1329eSCédric Le Goater * We have one such address space wrapper per possible device under 519ae1329eSCédric Le Goater * the PHB since they need to be assigned statically at qemu device 529ae1329eSCédric Le Goater * creation time. The relationship to a PE is done later dynamically. 539ae1329eSCédric Le Goater * This means we can potentially create a lot of these guys. Q35 549ae1329eSCédric Le Goater * stores them as some kind of radix tree but we never really need to 559ae1329eSCédric Le Goater * do fast lookups so instead we simply keep a QLIST of them for now, 569ae1329eSCédric Le Goater * we can add the radix if needed later on. 579ae1329eSCédric Le Goater * 589ae1329eSCédric Le Goater * We do cache the PE number to speed things up a bit though. 599ae1329eSCédric Le Goater */ 609ae1329eSCédric Le Goater typedef struct PnvPhb3DMASpace { 619ae1329eSCédric Le Goater PCIBus *bus; 629ae1329eSCédric Le Goater uint8_t devfn; 639ae1329eSCédric Le Goater int pe_num; /* Cached PE number */ 649ae1329eSCédric Le Goater #define PHB_INVALID_PE (-1) 659ae1329eSCédric Le Goater PnvPHB3 *phb; 669ae1329eSCédric Le Goater AddressSpace dma_as; 679ae1329eSCédric Le Goater IOMMUMemoryRegion dma_mr; 689ae1329eSCédric Le Goater MemoryRegion msi32_mr; 699ae1329eSCédric Le Goater MemoryRegion msi64_mr; 709ae1329eSCédric Le Goater QLIST_ENTRY(PnvPhb3DMASpace) list; 719ae1329eSCédric Le Goater } PnvPhb3DMASpace; 729ae1329eSCédric Le Goater 739ae1329eSCédric Le Goater /* 749ae1329eSCédric Le Goater * PHB3 Power Bus Common Queue 759ae1329eSCédric Le Goater */ 769ae1329eSCédric Le Goater #define TYPE_PNV_PBCQ "pnv-pbcq" 778063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(PnvPBCQState, PNV_PBCQ) 789ae1329eSCédric Le Goater 79db1015e9SEduardo Habkost struct PnvPBCQState { 809ae1329eSCédric Le Goater DeviceState parent; 819ae1329eSCédric Le Goater 829ae1329eSCédric Le Goater uint32_t nest_xbase; 839ae1329eSCédric Le Goater uint32_t spci_xbase; 849ae1329eSCédric Le Goater uint32_t pci_xbase; 859ae1329eSCédric Le Goater #define PBCQ_NEST_REGS_COUNT 0x46 869ae1329eSCédric Le Goater #define PBCQ_PCI_REGS_COUNT 0x15 879ae1329eSCédric Le Goater #define PBCQ_SPCI_REGS_COUNT 0x5 889ae1329eSCédric Le Goater 899ae1329eSCédric Le Goater uint64_t nest_regs[PBCQ_NEST_REGS_COUNT]; 909ae1329eSCédric Le Goater uint64_t spci_regs[PBCQ_SPCI_REGS_COUNT]; 919ae1329eSCédric Le Goater uint64_t pci_regs[PBCQ_PCI_REGS_COUNT]; 929ae1329eSCédric Le Goater MemoryRegion mmbar0; 939ae1329eSCédric Le Goater MemoryRegion mmbar1; 949ae1329eSCédric Le Goater MemoryRegion phbbar; 959ae1329eSCédric Le Goater uint64_t mmio0_base; 969ae1329eSCédric Le Goater uint64_t mmio0_size; 979ae1329eSCédric Le Goater uint64_t mmio1_base; 989ae1329eSCédric Le Goater uint64_t mmio1_size; 999ae1329eSCédric Le Goater PnvPHB3 *phb; 1009ae1329eSCédric Le Goater 1019ae1329eSCédric Le Goater MemoryRegion xscom_nest_regs; 1029ae1329eSCédric Le Goater MemoryRegion xscom_pci_regs; 1039ae1329eSCédric Le Goater MemoryRegion xscom_spci_regs; 104db1015e9SEduardo Habkost }; 1059ae1329eSCédric Le Goater 1069ae1329eSCédric Le Goater /* 107*8ec1e4f1SDaniel Henrique Barboza * PHB3 PCIe Root Bus 1089ae1329eSCédric Le Goater */ 10941cb8d31SDaniel Henrique Barboza #define TYPE_PNV_PHB3_ROOT_BUS "pnv-phb3-root" 110*8ec1e4f1SDaniel Henrique Barboza struct PnvPHB3RootBus { 111*8ec1e4f1SDaniel Henrique Barboza PCIBus parent; 112*8ec1e4f1SDaniel Henrique Barboza 113*8ec1e4f1SDaniel Henrique Barboza uint32_t chip_id; 114*8ec1e4f1SDaniel Henrique Barboza uint32_t phb_id; 115*8ec1e4f1SDaniel Henrique Barboza }; 116*8ec1e4f1SDaniel Henrique Barboza OBJECT_DECLARE_SIMPLE_TYPE(PnvPHB3RootBus, PNV_PHB3_ROOT_BUS) 1179ae1329eSCédric Le Goater 1189ae1329eSCédric Le Goater /* 1199ae1329eSCédric Le Goater * PHB3 PCIe Host Bridge for PowerNV machines (POWER8) 1209ae1329eSCédric Le Goater */ 1219ae1329eSCédric Le Goater #define TYPE_PNV_PHB3 "pnv-phb3" 1228063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(PnvPHB3, PNV_PHB3) 1239ae1329eSCédric Le Goater 1249ae1329eSCédric Le Goater #define PNV_PHB3_NUM_M64 16 1259ae1329eSCédric Le Goater #define PNV_PHB3_NUM_REGS (0x1000 >> 3) 1269ae1329eSCédric Le Goater #define PNV_PHB3_NUM_LSI 8 1279ae1329eSCédric Le Goater #define PNV_PHB3_NUM_PE 256 1289ae1329eSCédric Le Goater 1299ae1329eSCédric Le Goater #define PCI_MMIO_TOTAL_SIZE (0x1ull << 60) 1309ae1329eSCédric Le Goater 1319ae1329eSCédric Le Goater struct PnvPHB3 { 1321f5d6b2aSDaniel Henrique Barboza DeviceState parent; 1331f5d6b2aSDaniel Henrique Barboza 1341f5d6b2aSDaniel Henrique Barboza PnvPHB *phb_base; 1359ae1329eSCédric Le Goater 1369ae1329eSCédric Le Goater uint32_t chip_id; 1379ae1329eSCédric Le Goater uint32_t phb_id; 1389ae1329eSCédric Le Goater char bus_path[8]; 1399ae1329eSCédric Le Goater 1409ae1329eSCédric Le Goater uint64_t regs[PNV_PHB3_NUM_REGS]; 1419ae1329eSCédric Le Goater MemoryRegion mr_regs; 1429ae1329eSCédric Le Goater 1439ae1329eSCédric Le Goater MemoryRegion mr_m32; 1449ae1329eSCédric Le Goater MemoryRegion mr_m64[PNV_PHB3_NUM_M64]; 1459ae1329eSCédric Le Goater MemoryRegion pci_mmio; 1469ae1329eSCédric Le Goater MemoryRegion pci_io; 1479ae1329eSCédric Le Goater 1489ae1329eSCédric Le Goater uint64_t ioda_LIST[8]; 1499ae1329eSCédric Le Goater uint64_t ioda_LXIVT[8]; 1509ae1329eSCédric Le Goater uint64_t ioda_TVT[512]; 1519ae1329eSCédric Le Goater uint64_t ioda_M64BT[16]; 1529ae1329eSCédric Le Goater uint64_t ioda_MDT[256]; 1539ae1329eSCédric Le Goater uint64_t ioda_PEEV[4]; 1549ae1329eSCédric Le Goater 1559ae1329eSCédric Le Goater uint32_t total_irq; 1569ae1329eSCédric Le Goater ICSState lsis; 1579ae1329eSCédric Le Goater qemu_irq *qirqs; 1589ae1329eSCédric Le Goater Phb3MsiState msis; 1599ae1329eSCédric Le Goater 1609ae1329eSCédric Le Goater PnvPBCQState pbcq; 1619ae1329eSCédric Le Goater 1629ae1329eSCédric Le Goater QLIST_HEAD(, PnvPhb3DMASpace) dma_spaces; 1632c4d3a50SCédric Le Goater 1642c4d3a50SCédric Le Goater PnvChip *chip; 1659ae1329eSCédric Le Goater }; 1669ae1329eSCédric Le Goater 1679ae1329eSCédric Le Goater uint64_t pnv_phb3_reg_read(void *opaque, hwaddr off, unsigned size); 1689ae1329eSCédric Le Goater void pnv_phb3_reg_write(void *opaque, hwaddr off, uint64_t val, unsigned size); 1699ae1329eSCédric Le Goater void pnv_phb3_update_regions(PnvPHB3 *phb); 1709ae1329eSCédric Le Goater void pnv_phb3_remap_irqs(PnvPHB3 *phb); 17191bcee71SDaniel Henrique Barboza void pnv_phb3_bus_init(DeviceState *dev, PnvPHB3 *phb); 1729ae1329eSCédric Le Goater 1739ae1329eSCédric Le Goater #endif /* PCI_HOST_PNV_PHB3_H */ 174