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/ppc/xics.h" 14db1015e9SEduardo Habkost #include "qom/object.h" 151f5d6b2aSDaniel Henrique Barboza #include "hw/pci-host/pnv_phb.h" 169ae1329eSCédric Le Goater 179ae1329eSCédric Le Goater typedef struct PnvPHB3 PnvPHB3; 189ae1329eSCédric Le Goater 199ae1329eSCédric Le Goater /* 209ae1329eSCédric Le Goater * PHB3 XICS Source for MSIs 219ae1329eSCédric Le Goater */ 229ae1329eSCédric Le Goater #define TYPE_PHB3_MSI "phb3-msi" 23db1015e9SEduardo Habkost typedef struct Phb3MsiState Phb3MsiState; 248110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(Phb3MsiState, PHB3_MSI, 258110fa1dSEduardo Habkost TYPE_PHB3_MSI) 269ae1329eSCédric Le Goater 279ae1329eSCédric Le Goater #define PHB3_MAX_MSI 2048 289ae1329eSCédric Le Goater 29db1015e9SEduardo 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; 36db1015e9SEduardo 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); 43*dafec001SPhilippe Mathieu-Daudé void pnv_phb3_msi_pic_print_info(Phb3MsiState *msis, GString *buf); 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" 748063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(PnvPBCQState, PNV_PBCQ) 759ae1329eSCédric Le Goater 76db1015e9SEduardo Habkost struct PnvPBCQState { 779ae1329eSCédric Le Goater DeviceState parent; 789ae1329eSCédric Le Goater 799ae1329eSCédric Le Goater uint32_t nest_xbase; 809ae1329eSCédric Le Goater uint32_t spci_xbase; 819ae1329eSCédric Le Goater uint32_t pci_xbase; 829ae1329eSCédric Le Goater #define PBCQ_NEST_REGS_COUNT 0x46 839ae1329eSCédric Le Goater #define PBCQ_PCI_REGS_COUNT 0x15 849ae1329eSCédric Le Goater #define PBCQ_SPCI_REGS_COUNT 0x5 859ae1329eSCédric Le Goater 869ae1329eSCédric Le Goater uint64_t nest_regs[PBCQ_NEST_REGS_COUNT]; 879ae1329eSCédric Le Goater uint64_t spci_regs[PBCQ_SPCI_REGS_COUNT]; 889ae1329eSCédric Le Goater uint64_t pci_regs[PBCQ_PCI_REGS_COUNT]; 899ae1329eSCédric Le Goater MemoryRegion mmbar0; 909ae1329eSCédric Le Goater MemoryRegion mmbar1; 919ae1329eSCédric Le Goater MemoryRegion phbbar; 929ae1329eSCédric Le Goater uint64_t mmio0_base; 939ae1329eSCédric Le Goater uint64_t mmio0_size; 949ae1329eSCédric Le Goater uint64_t mmio1_base; 959ae1329eSCédric Le Goater uint64_t mmio1_size; 969ae1329eSCédric Le Goater PnvPHB3 *phb; 979ae1329eSCédric Le Goater 989ae1329eSCédric Le Goater MemoryRegion xscom_nest_regs; 999ae1329eSCédric Le Goater MemoryRegion xscom_pci_regs; 1009ae1329eSCédric Le Goater MemoryRegion xscom_spci_regs; 101db1015e9SEduardo Habkost }; 1029ae1329eSCédric Le Goater 1039ae1329eSCédric Le Goater /* 1048ec1e4f1SDaniel Henrique Barboza * PHB3 PCIe Root Bus 1059ae1329eSCédric Le Goater */ 10641cb8d31SDaniel Henrique Barboza #define TYPE_PNV_PHB3_ROOT_BUS "pnv-phb3-root" 1078ec1e4f1SDaniel Henrique Barboza struct PnvPHB3RootBus { 1088ec1e4f1SDaniel Henrique Barboza PCIBus parent; 1098ec1e4f1SDaniel Henrique Barboza 1108ec1e4f1SDaniel Henrique Barboza uint32_t chip_id; 1118ec1e4f1SDaniel Henrique Barboza uint32_t phb_id; 1128ec1e4f1SDaniel Henrique Barboza }; 1138ec1e4f1SDaniel Henrique Barboza OBJECT_DECLARE_SIMPLE_TYPE(PnvPHB3RootBus, PNV_PHB3_ROOT_BUS) 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" 1198063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(PnvPHB3, 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 { 1291f5d6b2aSDaniel Henrique Barboza DeviceState parent; 1301f5d6b2aSDaniel Henrique Barboza 1311f5d6b2aSDaniel Henrique Barboza PnvPHB *phb_base; 1329ae1329eSCédric Le Goater 1339ae1329eSCédric Le Goater uint32_t chip_id; 1349ae1329eSCédric Le Goater uint32_t phb_id; 1359ae1329eSCédric Le Goater char bus_path[8]; 1369ae1329eSCédric Le Goater 1379ae1329eSCédric Le Goater uint64_t regs[PNV_PHB3_NUM_REGS]; 1389ae1329eSCédric Le Goater MemoryRegion mr_regs; 1399ae1329eSCédric Le Goater 1409ae1329eSCédric Le Goater MemoryRegion mr_m32; 1419ae1329eSCédric Le Goater MemoryRegion mr_m64[PNV_PHB3_NUM_M64]; 1429ae1329eSCédric Le Goater MemoryRegion pci_mmio; 1439ae1329eSCédric Le Goater MemoryRegion pci_io; 1449ae1329eSCédric Le Goater 1459ae1329eSCédric Le Goater uint64_t ioda_LIST[8]; 1469ae1329eSCédric Le Goater uint64_t ioda_LXIVT[8]; 1479ae1329eSCédric Le Goater uint64_t ioda_TVT[512]; 1489ae1329eSCédric Le Goater uint64_t ioda_M64BT[16]; 1499ae1329eSCédric Le Goater uint64_t ioda_MDT[256]; 1509ae1329eSCédric Le Goater uint64_t ioda_PEEV[4]; 1519ae1329eSCédric Le Goater 1529ae1329eSCédric Le Goater uint32_t total_irq; 1539ae1329eSCédric Le Goater ICSState lsis; 1549ae1329eSCédric Le Goater qemu_irq *qirqs; 1559ae1329eSCédric Le Goater Phb3MsiState msis; 1569ae1329eSCédric Le Goater 1579ae1329eSCédric Le Goater PnvPBCQState pbcq; 1589ae1329eSCédric Le Goater 1599ae1329eSCédric Le Goater QLIST_HEAD(, PnvPhb3DMASpace) dma_spaces; 1602c4d3a50SCédric Le Goater 1612c4d3a50SCédric Le Goater PnvChip *chip; 1629ae1329eSCédric Le Goater }; 1639ae1329eSCédric Le Goater 1649ae1329eSCédric Le Goater uint64_t pnv_phb3_reg_read(void *opaque, hwaddr off, unsigned size); 1659ae1329eSCédric Le Goater void pnv_phb3_reg_write(void *opaque, hwaddr off, uint64_t val, unsigned size); 1669ae1329eSCédric Le Goater void pnv_phb3_update_regions(PnvPHB3 *phb); 1679ae1329eSCédric Le Goater void pnv_phb3_remap_irqs(PnvPHB3 *phb); 16891bcee71SDaniel Henrique Barboza void pnv_phb3_bus_init(DeviceState *dev, PnvPHB3 *phb); 1699ae1329eSCédric Le Goater 1709ae1329eSCédric Le Goater #endif /* PCI_HOST_PNV_PHB3_H */ 171