14f9924c4SBenjamin Herrenschmidt /* 24f9924c4SBenjamin Herrenschmidt * QEMU PowerPC PowerNV (POWER9) PHB4 model 34f9924c4SBenjamin Herrenschmidt * 44f9924c4SBenjamin Herrenschmidt * Copyright (c) 2018-2020, IBM Corporation. 54f9924c4SBenjamin Herrenschmidt * 64f9924c4SBenjamin Herrenschmidt * This code is licensed under the GPL version 2 or later. See the 74f9924c4SBenjamin Herrenschmidt * COPYING file in the top-level directory. 84f9924c4SBenjamin Herrenschmidt */ 94f9924c4SBenjamin Herrenschmidt #include "qemu/osdep.h" 104f9924c4SBenjamin Herrenschmidt #include "qapi/error.h" 114f9924c4SBenjamin Herrenschmidt #include "qemu-common.h" 124f9924c4SBenjamin Herrenschmidt #include "qemu/log.h" 134f9924c4SBenjamin Herrenschmidt #include "target/ppc/cpu.h" 144f9924c4SBenjamin Herrenschmidt #include "hw/ppc/fdt.h" 154f9924c4SBenjamin Herrenschmidt #include "hw/pci-host/pnv_phb4_regs.h" 164f9924c4SBenjamin Herrenschmidt #include "hw/pci-host/pnv_phb4.h" 174f9924c4SBenjamin Herrenschmidt #include "hw/ppc/pnv_xscom.h" 184f9924c4SBenjamin Herrenschmidt #include "hw/pci/pci_bridge.h" 194f9924c4SBenjamin Herrenschmidt #include "hw/pci/pci_bus.h" 204f9924c4SBenjamin Herrenschmidt #include "hw/ppc/pnv.h" 214f9924c4SBenjamin Herrenschmidt #include "hw/qdev-properties.h" 224f9924c4SBenjamin Herrenschmidt 234f9924c4SBenjamin Herrenschmidt #include <libfdt.h> 244f9924c4SBenjamin Herrenschmidt 254f9924c4SBenjamin Herrenschmidt #define phb_pec_error(pec, fmt, ...) \ 264f9924c4SBenjamin Herrenschmidt qemu_log_mask(LOG_GUEST_ERROR, "phb4_pec[%d:%d]: " fmt "\n", \ 274f9924c4SBenjamin Herrenschmidt (pec)->chip_id, (pec)->index, ## __VA_ARGS__) 284f9924c4SBenjamin Herrenschmidt 294f9924c4SBenjamin Herrenschmidt 304f9924c4SBenjamin Herrenschmidt static uint64_t pnv_pec_nest_xscom_read(void *opaque, hwaddr addr, 314f9924c4SBenjamin Herrenschmidt unsigned size) 324f9924c4SBenjamin Herrenschmidt { 334f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = PNV_PHB4_PEC(opaque); 344f9924c4SBenjamin Herrenschmidt uint32_t reg = addr >> 3; 354f9924c4SBenjamin Herrenschmidt 364f9924c4SBenjamin Herrenschmidt /* TODO: add list of allowed registers and error out if not */ 374f9924c4SBenjamin Herrenschmidt return pec->nest_regs[reg]; 384f9924c4SBenjamin Herrenschmidt } 394f9924c4SBenjamin Herrenschmidt 404f9924c4SBenjamin Herrenschmidt static void pnv_pec_nest_xscom_write(void *opaque, hwaddr addr, 414f9924c4SBenjamin Herrenschmidt uint64_t val, unsigned size) 424f9924c4SBenjamin Herrenschmidt { 434f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = PNV_PHB4_PEC(opaque); 444f9924c4SBenjamin Herrenschmidt uint32_t reg = addr >> 3; 454f9924c4SBenjamin Herrenschmidt 464f9924c4SBenjamin Herrenschmidt switch (reg) { 474f9924c4SBenjamin Herrenschmidt case PEC_NEST_PBCQ_HW_CONFIG: 484f9924c4SBenjamin Herrenschmidt case PEC_NEST_DROP_PRIO_CTRL: 494f9924c4SBenjamin Herrenschmidt case PEC_NEST_PBCQ_ERR_INJECT: 504f9924c4SBenjamin Herrenschmidt case PEC_NEST_PCI_NEST_CLK_TRACE_CTL: 514f9924c4SBenjamin Herrenschmidt case PEC_NEST_PBCQ_PMON_CTRL: 524f9924c4SBenjamin Herrenschmidt case PEC_NEST_PBCQ_PBUS_ADDR_EXT: 534f9924c4SBenjamin Herrenschmidt case PEC_NEST_PBCQ_PRED_VEC_TIMEOUT: 544f9924c4SBenjamin Herrenschmidt case PEC_NEST_CAPP_CTRL: 554f9924c4SBenjamin Herrenschmidt case PEC_NEST_PBCQ_READ_STK_OVR: 564f9924c4SBenjamin Herrenschmidt case PEC_NEST_PBCQ_WRITE_STK_OVR: 574f9924c4SBenjamin Herrenschmidt case PEC_NEST_PBCQ_STORE_STK_OVR: 584f9924c4SBenjamin Herrenschmidt case PEC_NEST_PBCQ_RETRY_BKOFF_CTRL: 594f9924c4SBenjamin Herrenschmidt pec->nest_regs[reg] = val; 604f9924c4SBenjamin Herrenschmidt break; 614f9924c4SBenjamin Herrenschmidt default: 624f9924c4SBenjamin Herrenschmidt phb_pec_error(pec, "%s @0x%"HWADDR_PRIx"=%"PRIx64"\n", __func__, 634f9924c4SBenjamin Herrenschmidt addr, val); 644f9924c4SBenjamin Herrenschmidt } 654f9924c4SBenjamin Herrenschmidt } 664f9924c4SBenjamin Herrenschmidt 674f9924c4SBenjamin Herrenschmidt static const MemoryRegionOps pnv_pec_nest_xscom_ops = { 684f9924c4SBenjamin Herrenschmidt .read = pnv_pec_nest_xscom_read, 694f9924c4SBenjamin Herrenschmidt .write = pnv_pec_nest_xscom_write, 704f9924c4SBenjamin Herrenschmidt .valid.min_access_size = 8, 714f9924c4SBenjamin Herrenschmidt .valid.max_access_size = 8, 724f9924c4SBenjamin Herrenschmidt .impl.min_access_size = 8, 734f9924c4SBenjamin Herrenschmidt .impl.max_access_size = 8, 744f9924c4SBenjamin Herrenschmidt .endianness = DEVICE_BIG_ENDIAN, 754f9924c4SBenjamin Herrenschmidt }; 764f9924c4SBenjamin Herrenschmidt 774f9924c4SBenjamin Herrenschmidt static uint64_t pnv_pec_pci_xscom_read(void *opaque, hwaddr addr, 784f9924c4SBenjamin Herrenschmidt unsigned size) 794f9924c4SBenjamin Herrenschmidt { 804f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = PNV_PHB4_PEC(opaque); 814f9924c4SBenjamin Herrenschmidt uint32_t reg = addr >> 3; 824f9924c4SBenjamin Herrenschmidt 834f9924c4SBenjamin Herrenschmidt /* TODO: add list of allowed registers and error out if not */ 844f9924c4SBenjamin Herrenschmidt return pec->pci_regs[reg]; 854f9924c4SBenjamin Herrenschmidt } 864f9924c4SBenjamin Herrenschmidt 874f9924c4SBenjamin Herrenschmidt static void pnv_pec_pci_xscom_write(void *opaque, hwaddr addr, 884f9924c4SBenjamin Herrenschmidt uint64_t val, unsigned size) 894f9924c4SBenjamin Herrenschmidt { 904f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = PNV_PHB4_PEC(opaque); 914f9924c4SBenjamin Herrenschmidt uint32_t reg = addr >> 3; 924f9924c4SBenjamin Herrenschmidt 934f9924c4SBenjamin Herrenschmidt switch (reg) { 944f9924c4SBenjamin Herrenschmidt case PEC_PCI_PBAIB_HW_CONFIG: 954f9924c4SBenjamin Herrenschmidt case PEC_PCI_PBAIB_READ_STK_OVR: 964f9924c4SBenjamin Herrenschmidt pec->pci_regs[reg] = val; 974f9924c4SBenjamin Herrenschmidt break; 984f9924c4SBenjamin Herrenschmidt default: 994f9924c4SBenjamin Herrenschmidt phb_pec_error(pec, "%s @0x%"HWADDR_PRIx"=%"PRIx64"\n", __func__, 1004f9924c4SBenjamin Herrenschmidt addr, val); 1014f9924c4SBenjamin Herrenschmidt } 1024f9924c4SBenjamin Herrenschmidt } 1034f9924c4SBenjamin Herrenschmidt 1044f9924c4SBenjamin Herrenschmidt static const MemoryRegionOps pnv_pec_pci_xscom_ops = { 1054f9924c4SBenjamin Herrenschmidt .read = pnv_pec_pci_xscom_read, 1064f9924c4SBenjamin Herrenschmidt .write = pnv_pec_pci_xscom_write, 1074f9924c4SBenjamin Herrenschmidt .valid.min_access_size = 8, 1084f9924c4SBenjamin Herrenschmidt .valid.max_access_size = 8, 1094f9924c4SBenjamin Herrenschmidt .impl.min_access_size = 8, 1104f9924c4SBenjamin Herrenschmidt .impl.max_access_size = 8, 1114f9924c4SBenjamin Herrenschmidt .endianness = DEVICE_BIG_ENDIAN, 1124f9924c4SBenjamin Herrenschmidt }; 1134f9924c4SBenjamin Herrenschmidt 1144f9924c4SBenjamin Herrenschmidt static uint64_t pnv_pec_stk_nest_xscom_read(void *opaque, hwaddr addr, 1154f9924c4SBenjamin Herrenschmidt unsigned size) 1164f9924c4SBenjamin Herrenschmidt { 1174f9924c4SBenjamin Herrenschmidt PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(opaque); 1184f9924c4SBenjamin Herrenschmidt uint32_t reg = addr >> 3; 1194f9924c4SBenjamin Herrenschmidt 1204f9924c4SBenjamin Herrenschmidt /* TODO: add list of allowed registers and error out if not */ 1214f9924c4SBenjamin Herrenschmidt return stack->nest_regs[reg]; 1224f9924c4SBenjamin Herrenschmidt } 1234f9924c4SBenjamin Herrenschmidt 1244f9924c4SBenjamin Herrenschmidt static void pnv_pec_stk_update_map(PnvPhb4PecStack *stack) 1254f9924c4SBenjamin Herrenschmidt { 1264f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = stack->pec; 1274f9924c4SBenjamin Herrenschmidt MemoryRegion *sysmem = pec->system_memory; 1284f9924c4SBenjamin Herrenschmidt uint64_t bar_en = stack->nest_regs[PEC_NEST_STK_BAR_EN]; 1294f9924c4SBenjamin Herrenschmidt uint64_t bar, mask, size; 1304f9924c4SBenjamin Herrenschmidt char name[64]; 1314f9924c4SBenjamin Herrenschmidt 1324f9924c4SBenjamin Herrenschmidt /* 1334f9924c4SBenjamin Herrenschmidt * NOTE: This will really not work well if those are remapped 1344f9924c4SBenjamin Herrenschmidt * after the PHB has created its sub regions. We could do better 1354f9924c4SBenjamin Herrenschmidt * if we had a way to resize regions but we don't really care 1364f9924c4SBenjamin Herrenschmidt * that much in practice as the stuff below really only happens 1374f9924c4SBenjamin Herrenschmidt * once early during boot 1384f9924c4SBenjamin Herrenschmidt */ 1394f9924c4SBenjamin Herrenschmidt 1404f9924c4SBenjamin Herrenschmidt /* Handle unmaps */ 1414f9924c4SBenjamin Herrenschmidt if (memory_region_is_mapped(&stack->mmbar0) && 1424f9924c4SBenjamin Herrenschmidt !(bar_en & PEC_NEST_STK_BAR_EN_MMIO0)) { 1434f9924c4SBenjamin Herrenschmidt memory_region_del_subregion(sysmem, &stack->mmbar0); 1444f9924c4SBenjamin Herrenschmidt } 1454f9924c4SBenjamin Herrenschmidt if (memory_region_is_mapped(&stack->mmbar1) && 1464f9924c4SBenjamin Herrenschmidt !(bar_en & PEC_NEST_STK_BAR_EN_MMIO1)) { 1474f9924c4SBenjamin Herrenschmidt memory_region_del_subregion(sysmem, &stack->mmbar1); 1484f9924c4SBenjamin Herrenschmidt } 1494f9924c4SBenjamin Herrenschmidt if (memory_region_is_mapped(&stack->phbbar) && 1504f9924c4SBenjamin Herrenschmidt !(bar_en & PEC_NEST_STK_BAR_EN_PHB)) { 1514f9924c4SBenjamin Herrenschmidt memory_region_del_subregion(sysmem, &stack->phbbar); 1524f9924c4SBenjamin Herrenschmidt } 1534f9924c4SBenjamin Herrenschmidt if (memory_region_is_mapped(&stack->intbar) && 1544f9924c4SBenjamin Herrenschmidt !(bar_en & PEC_NEST_STK_BAR_EN_INT)) { 1554f9924c4SBenjamin Herrenschmidt memory_region_del_subregion(sysmem, &stack->intbar); 1564f9924c4SBenjamin Herrenschmidt } 1574f9924c4SBenjamin Herrenschmidt 1584f9924c4SBenjamin Herrenschmidt /* Update PHB */ 1594f9924c4SBenjamin Herrenschmidt pnv_phb4_update_regions(stack); 1604f9924c4SBenjamin Herrenschmidt 1614f9924c4SBenjamin Herrenschmidt /* Handle maps */ 1624f9924c4SBenjamin Herrenschmidt if (!memory_region_is_mapped(&stack->mmbar0) && 1634f9924c4SBenjamin Herrenschmidt (bar_en & PEC_NEST_STK_BAR_EN_MMIO0)) { 1644f9924c4SBenjamin Herrenschmidt bar = stack->nest_regs[PEC_NEST_STK_MMIO_BAR0] >> 8; 1654f9924c4SBenjamin Herrenschmidt mask = stack->nest_regs[PEC_NEST_STK_MMIO_BAR0_MASK]; 1664f9924c4SBenjamin Herrenschmidt size = ((~mask) >> 8) + 1; 1674f9924c4SBenjamin Herrenschmidt snprintf(name, sizeof(name), "pec-%d.%d-stack-%d-mmio0", 1684f9924c4SBenjamin Herrenschmidt pec->chip_id, pec->index, stack->stack_no); 1694f9924c4SBenjamin Herrenschmidt memory_region_init(&stack->mmbar0, OBJECT(stack), name, size); 1704f9924c4SBenjamin Herrenschmidt memory_region_add_subregion(sysmem, bar, &stack->mmbar0); 1714f9924c4SBenjamin Herrenschmidt stack->mmio0_base = bar; 1724f9924c4SBenjamin Herrenschmidt stack->mmio0_size = size; 1734f9924c4SBenjamin Herrenschmidt } 1744f9924c4SBenjamin Herrenschmidt if (!memory_region_is_mapped(&stack->mmbar1) && 1754f9924c4SBenjamin Herrenschmidt (bar_en & PEC_NEST_STK_BAR_EN_MMIO1)) { 1764f9924c4SBenjamin Herrenschmidt bar = stack->nest_regs[PEC_NEST_STK_MMIO_BAR1] >> 8; 1774f9924c4SBenjamin Herrenschmidt mask = stack->nest_regs[PEC_NEST_STK_MMIO_BAR1_MASK]; 1784f9924c4SBenjamin Herrenschmidt size = ((~mask) >> 8) + 1; 1794f9924c4SBenjamin Herrenschmidt snprintf(name, sizeof(name), "pec-%d.%d-stack-%d-mmio1", 1804f9924c4SBenjamin Herrenschmidt pec->chip_id, pec->index, stack->stack_no); 1814f9924c4SBenjamin Herrenschmidt memory_region_init(&stack->mmbar1, OBJECT(stack), name, size); 1824f9924c4SBenjamin Herrenschmidt memory_region_add_subregion(sysmem, bar, &stack->mmbar1); 1834f9924c4SBenjamin Herrenschmidt stack->mmio1_base = bar; 1844f9924c4SBenjamin Herrenschmidt stack->mmio1_size = size; 1854f9924c4SBenjamin Herrenschmidt } 1864f9924c4SBenjamin Herrenschmidt if (!memory_region_is_mapped(&stack->phbbar) && 1874f9924c4SBenjamin Herrenschmidt (bar_en & PEC_NEST_STK_BAR_EN_PHB)) { 1884f9924c4SBenjamin Herrenschmidt bar = stack->nest_regs[PEC_NEST_STK_PHB_REGS_BAR] >> 8; 1894f9924c4SBenjamin Herrenschmidt size = PNV_PHB4_NUM_REGS << 3; 1904f9924c4SBenjamin Herrenschmidt snprintf(name, sizeof(name), "pec-%d.%d-stack-%d-phb", 1914f9924c4SBenjamin Herrenschmidt pec->chip_id, pec->index, stack->stack_no); 1924f9924c4SBenjamin Herrenschmidt memory_region_init(&stack->phbbar, OBJECT(stack), name, size); 1934f9924c4SBenjamin Herrenschmidt memory_region_add_subregion(sysmem, bar, &stack->phbbar); 1944f9924c4SBenjamin Herrenschmidt } 1954f9924c4SBenjamin Herrenschmidt if (!memory_region_is_mapped(&stack->intbar) && 1964f9924c4SBenjamin Herrenschmidt (bar_en & PEC_NEST_STK_BAR_EN_INT)) { 1974f9924c4SBenjamin Herrenschmidt bar = stack->nest_regs[PEC_NEST_STK_INT_BAR] >> 8; 1984f9924c4SBenjamin Herrenschmidt size = PNV_PHB4_MAX_INTs << 16; 1994f9924c4SBenjamin Herrenschmidt snprintf(name, sizeof(name), "pec-%d.%d-stack-%d-int", 2004f9924c4SBenjamin Herrenschmidt stack->pec->chip_id, stack->pec->index, stack->stack_no); 2014f9924c4SBenjamin Herrenschmidt memory_region_init(&stack->intbar, OBJECT(stack), name, size); 2024f9924c4SBenjamin Herrenschmidt memory_region_add_subregion(sysmem, bar, &stack->intbar); 2034f9924c4SBenjamin Herrenschmidt } 2044f9924c4SBenjamin Herrenschmidt 2054f9924c4SBenjamin Herrenschmidt /* Update PHB */ 2064f9924c4SBenjamin Herrenschmidt pnv_phb4_update_regions(stack); 2074f9924c4SBenjamin Herrenschmidt } 2084f9924c4SBenjamin Herrenschmidt 2094f9924c4SBenjamin Herrenschmidt static void pnv_pec_stk_nest_xscom_write(void *opaque, hwaddr addr, 2104f9924c4SBenjamin Herrenschmidt uint64_t val, unsigned size) 2114f9924c4SBenjamin Herrenschmidt { 2124f9924c4SBenjamin Herrenschmidt PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(opaque); 2134f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = stack->pec; 2144f9924c4SBenjamin Herrenschmidt uint32_t reg = addr >> 3; 2154f9924c4SBenjamin Herrenschmidt 2164f9924c4SBenjamin Herrenschmidt switch (reg) { 2174f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PCI_NEST_FIR: 2184f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_NEST_STK_PCI_NEST_FIR] = val; 2194f9924c4SBenjamin Herrenschmidt break; 2204f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PCI_NEST_FIR_CLR: 2214f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_NEST_STK_PCI_NEST_FIR] &= val; 2224f9924c4SBenjamin Herrenschmidt break; 2234f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PCI_NEST_FIR_SET: 2244f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_NEST_STK_PCI_NEST_FIR] |= val; 2254f9924c4SBenjamin Herrenschmidt break; 2264f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PCI_NEST_FIR_MSK: 2274f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_NEST_STK_PCI_NEST_FIR_MSK] = val; 2284f9924c4SBenjamin Herrenschmidt break; 2294f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PCI_NEST_FIR_MSKC: 2304f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_NEST_STK_PCI_NEST_FIR_MSK] &= val; 2314f9924c4SBenjamin Herrenschmidt break; 2324f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PCI_NEST_FIR_MSKS: 2334f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_NEST_STK_PCI_NEST_FIR_MSK] |= val; 2344f9924c4SBenjamin Herrenschmidt break; 2354f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PCI_NEST_FIR_ACT0: 2364f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PCI_NEST_FIR_ACT1: 2374f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val; 2384f9924c4SBenjamin Herrenschmidt break; 2394f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PCI_NEST_FIR_WOF: 2404f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = 0; 2414f9924c4SBenjamin Herrenschmidt break; 2424f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_ERR_REPORT_0: 2434f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_ERR_REPORT_1: 2444f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PBCQ_GNRL_STATUS: 2454f9924c4SBenjamin Herrenschmidt /* Flag error ? */ 2464f9924c4SBenjamin Herrenschmidt break; 2474f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PBCQ_MODE: 2484f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val & 0xff00000000000000ull; 2494f9924c4SBenjamin Herrenschmidt break; 2504f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_MMIO_BAR0: 2514f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_MMIO_BAR0_MASK: 2524f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_MMIO_BAR1: 2534f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_MMIO_BAR1_MASK: 2544f9924c4SBenjamin Herrenschmidt if (stack->nest_regs[PEC_NEST_STK_BAR_EN] & 2554f9924c4SBenjamin Herrenschmidt (PEC_NEST_STK_BAR_EN_MMIO0 | 2564f9924c4SBenjamin Herrenschmidt PEC_NEST_STK_BAR_EN_MMIO1)) { 2574f9924c4SBenjamin Herrenschmidt phb_pec_error(pec, "Changing enabled BAR unsupported\n"); 2584f9924c4SBenjamin Herrenschmidt } 2594f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val & 0xffffffffff000000ull; 2604f9924c4SBenjamin Herrenschmidt break; 2614f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PHB_REGS_BAR: 2624f9924c4SBenjamin Herrenschmidt if (stack->nest_regs[PEC_NEST_STK_BAR_EN] & PEC_NEST_STK_BAR_EN_PHB) { 2634f9924c4SBenjamin Herrenschmidt phb_pec_error(pec, "Changing enabled BAR unsupported\n"); 2644f9924c4SBenjamin Herrenschmidt } 2654f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val & 0xffffffffffc00000ull; 2664f9924c4SBenjamin Herrenschmidt break; 2674f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_INT_BAR: 2684f9924c4SBenjamin Herrenschmidt if (stack->nest_regs[PEC_NEST_STK_BAR_EN] & PEC_NEST_STK_BAR_EN_INT) { 2694f9924c4SBenjamin Herrenschmidt phb_pec_error(pec, "Changing enabled BAR unsupported\n"); 2704f9924c4SBenjamin Herrenschmidt } 2714f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val & 0xfffffff000000000ull; 2724f9924c4SBenjamin Herrenschmidt break; 2734f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_BAR_EN: 2744f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val & 0xf000000000000000ull; 2754f9924c4SBenjamin Herrenschmidt pnv_pec_stk_update_map(stack); 2764f9924c4SBenjamin Herrenschmidt break; 2774f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_DATA_FRZ_TYPE: 2784f9924c4SBenjamin Herrenschmidt case PEC_NEST_STK_PBCQ_TUN_BAR: 2794f9924c4SBenjamin Herrenschmidt /* Not used for now */ 2804f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val; 2814f9924c4SBenjamin Herrenschmidt break; 2824f9924c4SBenjamin Herrenschmidt default: 2834f9924c4SBenjamin Herrenschmidt qemu_log_mask(LOG_UNIMP, "phb4_pec: nest_xscom_write 0x%"HWADDR_PRIx 2844f9924c4SBenjamin Herrenschmidt "=%"PRIx64"\n", addr, val); 2854f9924c4SBenjamin Herrenschmidt } 2864f9924c4SBenjamin Herrenschmidt } 2874f9924c4SBenjamin Herrenschmidt 2884f9924c4SBenjamin Herrenschmidt static const MemoryRegionOps pnv_pec_stk_nest_xscom_ops = { 2894f9924c4SBenjamin Herrenschmidt .read = pnv_pec_stk_nest_xscom_read, 2904f9924c4SBenjamin Herrenschmidt .write = pnv_pec_stk_nest_xscom_write, 2914f9924c4SBenjamin Herrenschmidt .valid.min_access_size = 8, 2924f9924c4SBenjamin Herrenschmidt .valid.max_access_size = 8, 2934f9924c4SBenjamin Herrenschmidt .impl.min_access_size = 8, 2944f9924c4SBenjamin Herrenschmidt .impl.max_access_size = 8, 2954f9924c4SBenjamin Herrenschmidt .endianness = DEVICE_BIG_ENDIAN, 2964f9924c4SBenjamin Herrenschmidt }; 2974f9924c4SBenjamin Herrenschmidt 2984f9924c4SBenjamin Herrenschmidt static uint64_t pnv_pec_stk_pci_xscom_read(void *opaque, hwaddr addr, 2994f9924c4SBenjamin Herrenschmidt unsigned size) 3004f9924c4SBenjamin Herrenschmidt { 3014f9924c4SBenjamin Herrenschmidt PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(opaque); 3024f9924c4SBenjamin Herrenschmidt uint32_t reg = addr >> 3; 3034f9924c4SBenjamin Herrenschmidt 3044f9924c4SBenjamin Herrenschmidt /* TODO: add list of allowed registers and error out if not */ 3054f9924c4SBenjamin Herrenschmidt return stack->pci_regs[reg]; 3064f9924c4SBenjamin Herrenschmidt } 3074f9924c4SBenjamin Herrenschmidt 3084f9924c4SBenjamin Herrenschmidt static void pnv_pec_stk_pci_xscom_write(void *opaque, hwaddr addr, 3094f9924c4SBenjamin Herrenschmidt uint64_t val, unsigned size) 3104f9924c4SBenjamin Herrenschmidt { 3114f9924c4SBenjamin Herrenschmidt PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(opaque); 3124f9924c4SBenjamin Herrenschmidt uint32_t reg = addr >> 3; 3134f9924c4SBenjamin Herrenschmidt 3144f9924c4SBenjamin Herrenschmidt switch (reg) { 3154f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PCI_FIR: 3164f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val; 3174f9924c4SBenjamin Herrenschmidt break; 3184f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PCI_FIR_CLR: 3194f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_PCI_STK_PCI_FIR] &= val; 3204f9924c4SBenjamin Herrenschmidt break; 3214f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PCI_FIR_SET: 3224f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_PCI_STK_PCI_FIR] |= val; 3234f9924c4SBenjamin Herrenschmidt break; 3244f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PCI_FIR_MSK: 3254f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val; 3264f9924c4SBenjamin Herrenschmidt break; 3274f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PCI_FIR_MSKC: 3284f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_PCI_STK_PCI_FIR_MSK] &= val; 3294f9924c4SBenjamin Herrenschmidt break; 3304f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PCI_FIR_MSKS: 3314f9924c4SBenjamin Herrenschmidt stack->nest_regs[PEC_PCI_STK_PCI_FIR_MSK] |= val; 3324f9924c4SBenjamin Herrenschmidt break; 3334f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PCI_FIR_ACT0: 3344f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PCI_FIR_ACT1: 3354f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val; 3364f9924c4SBenjamin Herrenschmidt break; 3374f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PCI_FIR_WOF: 3384f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = 0; 3394f9924c4SBenjamin Herrenschmidt break; 3404f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_ETU_RESET: 3414f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val & 0x8000000000000000ull; 3424f9924c4SBenjamin Herrenschmidt /* TODO: Implement reset */ 3434f9924c4SBenjamin Herrenschmidt break; 3444f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PBAIB_ERR_REPORT: 3454f9924c4SBenjamin Herrenschmidt break; 3464f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PBAIB_TX_CMD_CRED: 3474f9924c4SBenjamin Herrenschmidt case PEC_PCI_STK_PBAIB_TX_DAT_CRED: 3484f9924c4SBenjamin Herrenschmidt stack->nest_regs[reg] = val; 3494f9924c4SBenjamin Herrenschmidt break; 3504f9924c4SBenjamin Herrenschmidt default: 3514f9924c4SBenjamin Herrenschmidt qemu_log_mask(LOG_UNIMP, "phb4_pec_stk: pci_xscom_write 0x%"HWADDR_PRIx 3524f9924c4SBenjamin Herrenschmidt "=%"PRIx64"\n", addr, val); 3534f9924c4SBenjamin Herrenschmidt } 3544f9924c4SBenjamin Herrenschmidt } 3554f9924c4SBenjamin Herrenschmidt 3564f9924c4SBenjamin Herrenschmidt static const MemoryRegionOps pnv_pec_stk_pci_xscom_ops = { 3574f9924c4SBenjamin Herrenschmidt .read = pnv_pec_stk_pci_xscom_read, 3584f9924c4SBenjamin Herrenschmidt .write = pnv_pec_stk_pci_xscom_write, 3594f9924c4SBenjamin Herrenschmidt .valid.min_access_size = 8, 3604f9924c4SBenjamin Herrenschmidt .valid.max_access_size = 8, 3614f9924c4SBenjamin Herrenschmidt .impl.min_access_size = 8, 3624f9924c4SBenjamin Herrenschmidt .impl.max_access_size = 8, 3634f9924c4SBenjamin Herrenschmidt .endianness = DEVICE_BIG_ENDIAN, 3644f9924c4SBenjamin Herrenschmidt }; 3654f9924c4SBenjamin Herrenschmidt 3664f9924c4SBenjamin Herrenschmidt static void pnv_pec_instance_init(Object *obj) 3674f9924c4SBenjamin Herrenschmidt { 3684f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = PNV_PHB4_PEC(obj); 3694f9924c4SBenjamin Herrenschmidt int i; 3704f9924c4SBenjamin Herrenschmidt 3714f9924c4SBenjamin Herrenschmidt for (i = 0; i < PHB4_PEC_MAX_STACKS; i++) { 3724f9924c4SBenjamin Herrenschmidt object_initialize_child(obj, "stack[*]", &pec->stacks[i], 3739fc7fc4dSMarkus Armbruster TYPE_PNV_PHB4_PEC_STACK); 3744f9924c4SBenjamin Herrenschmidt } 3754f9924c4SBenjamin Herrenschmidt } 3764f9924c4SBenjamin Herrenschmidt 3774f9924c4SBenjamin Herrenschmidt static void pnv_pec_realize(DeviceState *dev, Error **errp) 3784f9924c4SBenjamin Herrenschmidt { 3794f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = PNV_PHB4_PEC(dev); 3804f9924c4SBenjamin Herrenschmidt char name[64]; 3814f9924c4SBenjamin Herrenschmidt int i; 3824f9924c4SBenjamin Herrenschmidt 3834f9924c4SBenjamin Herrenschmidt assert(pec->system_memory); 3844f9924c4SBenjamin Herrenschmidt 3854f9924c4SBenjamin Herrenschmidt /* Create stacks */ 3864f9924c4SBenjamin Herrenschmidt for (i = 0; i < pec->num_stacks; i++) { 3874f9924c4SBenjamin Herrenschmidt PnvPhb4PecStack *stack = &pec->stacks[i]; 3884f9924c4SBenjamin Herrenschmidt Object *stk_obj = OBJECT(stack); 3894f9924c4SBenjamin Herrenschmidt 3905325cc34SMarkus Armbruster object_property_set_int(stk_obj, "stack-no", i, &error_abort); 3915325cc34SMarkus Armbruster object_property_set_link(stk_obj, "pec", OBJECT(pec), &error_abort); 392668f62ecSMarkus Armbruster if (!qdev_realize(DEVICE(stk_obj), NULL, errp)) { 3934f9924c4SBenjamin Herrenschmidt return; 3944f9924c4SBenjamin Herrenschmidt } 3954f9924c4SBenjamin Herrenschmidt } 396efa05595SMarkus Armbruster for (; i < PHB4_PEC_MAX_STACKS; i++) { 397efa05595SMarkus Armbruster object_unparent(OBJECT(&pec->stacks[i])); 398efa05595SMarkus Armbruster } 3994f9924c4SBenjamin Herrenschmidt 4004f9924c4SBenjamin Herrenschmidt /* Initialize the XSCOM regions for the PEC registers */ 4014f9924c4SBenjamin Herrenschmidt snprintf(name, sizeof(name), "xscom-pec-%d.%d-nest", pec->chip_id, 4024f9924c4SBenjamin Herrenschmidt pec->index); 4034f9924c4SBenjamin Herrenschmidt pnv_xscom_region_init(&pec->nest_regs_mr, OBJECT(dev), 4044f9924c4SBenjamin Herrenschmidt &pnv_pec_nest_xscom_ops, pec, name, 4054f9924c4SBenjamin Herrenschmidt PHB4_PEC_NEST_REGS_COUNT); 4064f9924c4SBenjamin Herrenschmidt 4074f9924c4SBenjamin Herrenschmidt snprintf(name, sizeof(name), "xscom-pec-%d.%d-pci", pec->chip_id, 4084f9924c4SBenjamin Herrenschmidt pec->index); 4094f9924c4SBenjamin Herrenschmidt pnv_xscom_region_init(&pec->pci_regs_mr, OBJECT(dev), 4104f9924c4SBenjamin Herrenschmidt &pnv_pec_pci_xscom_ops, pec, name, 4114f9924c4SBenjamin Herrenschmidt PHB4_PEC_PCI_REGS_COUNT); 4124f9924c4SBenjamin Herrenschmidt } 4134f9924c4SBenjamin Herrenschmidt 4144f9924c4SBenjamin Herrenschmidt static int pnv_pec_dt_xscom(PnvXScomInterface *dev, void *fdt, 4154f9924c4SBenjamin Herrenschmidt int xscom_offset) 4164f9924c4SBenjamin Herrenschmidt { 4174f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = PNV_PHB4_PEC(dev); 4184f9924c4SBenjamin Herrenschmidt PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(dev); 4194f9924c4SBenjamin Herrenschmidt uint32_t nbase = pecc->xscom_nest_base(pec); 4204f9924c4SBenjamin Herrenschmidt uint32_t pbase = pecc->xscom_pci_base(pec); 4214f9924c4SBenjamin Herrenschmidt int offset, i; 4224f9924c4SBenjamin Herrenschmidt char *name; 4234f9924c4SBenjamin Herrenschmidt uint32_t reg[] = { 4244f9924c4SBenjamin Herrenschmidt cpu_to_be32(nbase), 4254f9924c4SBenjamin Herrenschmidt cpu_to_be32(pecc->xscom_nest_size), 4264f9924c4SBenjamin Herrenschmidt cpu_to_be32(pbase), 4274f9924c4SBenjamin Herrenschmidt cpu_to_be32(pecc->xscom_pci_size), 4284f9924c4SBenjamin Herrenschmidt }; 4294f9924c4SBenjamin Herrenschmidt 4304f9924c4SBenjamin Herrenschmidt name = g_strdup_printf("pbcq@%x", nbase); 4314f9924c4SBenjamin Herrenschmidt offset = fdt_add_subnode(fdt, xscom_offset, name); 4324f9924c4SBenjamin Herrenschmidt _FDT(offset); 4334f9924c4SBenjamin Herrenschmidt g_free(name); 4344f9924c4SBenjamin Herrenschmidt 4354f9924c4SBenjamin Herrenschmidt _FDT((fdt_setprop(fdt, offset, "reg", reg, sizeof(reg)))); 4364f9924c4SBenjamin Herrenschmidt 4374f9924c4SBenjamin Herrenschmidt _FDT((fdt_setprop_cell(fdt, offset, "ibm,pec-index", pec->index))); 4384f9924c4SBenjamin Herrenschmidt _FDT((fdt_setprop_cell(fdt, offset, "#address-cells", 1))); 4394f9924c4SBenjamin Herrenschmidt _FDT((fdt_setprop_cell(fdt, offset, "#size-cells", 0))); 4404f9924c4SBenjamin Herrenschmidt _FDT((fdt_setprop(fdt, offset, "compatible", pecc->compat, 4414f9924c4SBenjamin Herrenschmidt pecc->compat_size))); 4424f9924c4SBenjamin Herrenschmidt 4434f9924c4SBenjamin Herrenschmidt for (i = 0; i < pec->num_stacks; i++) { 4444f9924c4SBenjamin Herrenschmidt PnvPhb4PecStack *stack = &pec->stacks[i]; 4454f9924c4SBenjamin Herrenschmidt PnvPHB4 *phb = &stack->phb; 4464f9924c4SBenjamin Herrenschmidt int stk_offset; 4474f9924c4SBenjamin Herrenschmidt 4484f9924c4SBenjamin Herrenschmidt name = g_strdup_printf("stack@%x", i); 4494f9924c4SBenjamin Herrenschmidt stk_offset = fdt_add_subnode(fdt, offset, name); 4504f9924c4SBenjamin Herrenschmidt _FDT(stk_offset); 4514f9924c4SBenjamin Herrenschmidt g_free(name); 4524f9924c4SBenjamin Herrenschmidt _FDT((fdt_setprop(fdt, stk_offset, "compatible", pecc->stk_compat, 4534f9924c4SBenjamin Herrenschmidt pecc->stk_compat_size))); 4544f9924c4SBenjamin Herrenschmidt _FDT((fdt_setprop_cell(fdt, stk_offset, "reg", i))); 4554f9924c4SBenjamin Herrenschmidt _FDT((fdt_setprop_cell(fdt, stk_offset, "ibm,phb-index", phb->phb_id))); 4564f9924c4SBenjamin Herrenschmidt } 4574f9924c4SBenjamin Herrenschmidt 4584f9924c4SBenjamin Herrenschmidt return 0; 4594f9924c4SBenjamin Herrenschmidt } 4604f9924c4SBenjamin Herrenschmidt 4614f9924c4SBenjamin Herrenschmidt static Property pnv_pec_properties[] = { 4624f9924c4SBenjamin Herrenschmidt DEFINE_PROP_UINT32("index", PnvPhb4PecState, index, 0), 4634f9924c4SBenjamin Herrenschmidt DEFINE_PROP_UINT32("num-stacks", PnvPhb4PecState, num_stacks, 0), 4644f9924c4SBenjamin Herrenschmidt DEFINE_PROP_UINT32("chip-id", PnvPhb4PecState, chip_id, 0), 4654f9924c4SBenjamin Herrenschmidt DEFINE_PROP_LINK("system-memory", PnvPhb4PecState, system_memory, 4664f9924c4SBenjamin Herrenschmidt TYPE_MEMORY_REGION, MemoryRegion *), 4674f9924c4SBenjamin Herrenschmidt DEFINE_PROP_END_OF_LIST(), 4684f9924c4SBenjamin Herrenschmidt }; 4694f9924c4SBenjamin Herrenschmidt 4704f9924c4SBenjamin Herrenschmidt static uint32_t pnv_pec_xscom_pci_base(PnvPhb4PecState *pec) 4714f9924c4SBenjamin Herrenschmidt { 4724f9924c4SBenjamin Herrenschmidt return PNV9_XSCOM_PEC_PCI_BASE + 0x1000000 * pec->index; 4734f9924c4SBenjamin Herrenschmidt } 4744f9924c4SBenjamin Herrenschmidt 4754f9924c4SBenjamin Herrenschmidt static uint32_t pnv_pec_xscom_nest_base(PnvPhb4PecState *pec) 4764f9924c4SBenjamin Herrenschmidt { 4774f9924c4SBenjamin Herrenschmidt return PNV9_XSCOM_PEC_NEST_BASE + 0x400 * pec->index; 4784f9924c4SBenjamin Herrenschmidt } 4794f9924c4SBenjamin Herrenschmidt 4804f9924c4SBenjamin Herrenschmidt static void pnv_pec_class_init(ObjectClass *klass, void *data) 4814f9924c4SBenjamin Herrenschmidt { 4824f9924c4SBenjamin Herrenschmidt DeviceClass *dc = DEVICE_CLASS(klass); 4834f9924c4SBenjamin Herrenschmidt PnvXScomInterfaceClass *xdc = PNV_XSCOM_INTERFACE_CLASS(klass); 4844f9924c4SBenjamin Herrenschmidt PnvPhb4PecClass *pecc = PNV_PHB4_PEC_CLASS(klass); 4854f9924c4SBenjamin Herrenschmidt static const char compat[] = "ibm,power9-pbcq"; 4864f9924c4SBenjamin Herrenschmidt static const char stk_compat[] = "ibm,power9-phb-stack"; 4874f9924c4SBenjamin Herrenschmidt 4884f9924c4SBenjamin Herrenschmidt xdc->dt_xscom = pnv_pec_dt_xscom; 4894f9924c4SBenjamin Herrenschmidt 4904f9924c4SBenjamin Herrenschmidt dc->realize = pnv_pec_realize; 4914f9924c4SBenjamin Herrenschmidt device_class_set_props(dc, pnv_pec_properties); 49223a782ebSCédric Le Goater dc->user_creatable = false; 4934f9924c4SBenjamin Herrenschmidt 4944f9924c4SBenjamin Herrenschmidt pecc->xscom_nest_base = pnv_pec_xscom_nest_base; 4954f9924c4SBenjamin Herrenschmidt pecc->xscom_pci_base = pnv_pec_xscom_pci_base; 4964f9924c4SBenjamin Herrenschmidt pecc->xscom_nest_size = PNV9_XSCOM_PEC_NEST_SIZE; 4974f9924c4SBenjamin Herrenschmidt pecc->xscom_pci_size = PNV9_XSCOM_PEC_PCI_SIZE; 4984f9924c4SBenjamin Herrenschmidt pecc->compat = compat; 4994f9924c4SBenjamin Herrenschmidt pecc->compat_size = sizeof(compat); 5004f9924c4SBenjamin Herrenschmidt pecc->stk_compat = stk_compat; 5014f9924c4SBenjamin Herrenschmidt pecc->stk_compat_size = sizeof(stk_compat); 502*12060cbdSCédric Le Goater pecc->version = PNV_PHB4_VERSION; 503*12060cbdSCédric Le Goater pecc->device_id = PNV_PHB4_DEVICE_ID; 5044f9924c4SBenjamin Herrenschmidt } 5054f9924c4SBenjamin Herrenschmidt 5064f9924c4SBenjamin Herrenschmidt static const TypeInfo pnv_pec_type_info = { 5074f9924c4SBenjamin Herrenschmidt .name = TYPE_PNV_PHB4_PEC, 5084f9924c4SBenjamin Herrenschmidt .parent = TYPE_DEVICE, 5094f9924c4SBenjamin Herrenschmidt .instance_size = sizeof(PnvPhb4PecState), 5104f9924c4SBenjamin Herrenschmidt .instance_init = pnv_pec_instance_init, 5114f9924c4SBenjamin Herrenschmidt .class_init = pnv_pec_class_init, 5124f9924c4SBenjamin Herrenschmidt .class_size = sizeof(PnvPhb4PecClass), 5134f9924c4SBenjamin Herrenschmidt .interfaces = (InterfaceInfo[]) { 5144f9924c4SBenjamin Herrenschmidt { TYPE_PNV_XSCOM_INTERFACE }, 5154f9924c4SBenjamin Herrenschmidt { } 5164f9924c4SBenjamin Herrenschmidt } 5174f9924c4SBenjamin Herrenschmidt }; 5184f9924c4SBenjamin Herrenschmidt 5194f9924c4SBenjamin Herrenschmidt static void pnv_pec_stk_instance_init(Object *obj) 5204f9924c4SBenjamin Herrenschmidt { 5214f9924c4SBenjamin Herrenschmidt PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(obj); 5224f9924c4SBenjamin Herrenschmidt 5239fc7fc4dSMarkus Armbruster object_initialize_child(obj, "phb", &stack->phb, TYPE_PNV_PHB4); 5244f9924c4SBenjamin Herrenschmidt } 5254f9924c4SBenjamin Herrenschmidt 5264f9924c4SBenjamin Herrenschmidt static void pnv_pec_stk_realize(DeviceState *dev, Error **errp) 5274f9924c4SBenjamin Herrenschmidt { 5284f9924c4SBenjamin Herrenschmidt PnvPhb4PecStack *stack = PNV_PHB4_PEC_STACK(dev); 5294f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *pec = stack->pec; 5304f9924c4SBenjamin Herrenschmidt char name[64]; 5314f9924c4SBenjamin Herrenschmidt 5324f9924c4SBenjamin Herrenschmidt assert(pec); 5334f9924c4SBenjamin Herrenschmidt 5344f9924c4SBenjamin Herrenschmidt /* Initialize the XSCOM regions for the stack registers */ 5354f9924c4SBenjamin Herrenschmidt snprintf(name, sizeof(name), "xscom-pec-%d.%d-nest-stack-%d", 5364f9924c4SBenjamin Herrenschmidt pec->chip_id, pec->index, stack->stack_no); 5374f9924c4SBenjamin Herrenschmidt pnv_xscom_region_init(&stack->nest_regs_mr, OBJECT(stack), 5384f9924c4SBenjamin Herrenschmidt &pnv_pec_stk_nest_xscom_ops, stack, name, 5394f9924c4SBenjamin Herrenschmidt PHB4_PEC_NEST_STK_REGS_COUNT); 5404f9924c4SBenjamin Herrenschmidt 5414f9924c4SBenjamin Herrenschmidt snprintf(name, sizeof(name), "xscom-pec-%d.%d-pci-stack-%d", 5424f9924c4SBenjamin Herrenschmidt pec->chip_id, pec->index, stack->stack_no); 5434f9924c4SBenjamin Herrenschmidt pnv_xscom_region_init(&stack->pci_regs_mr, OBJECT(stack), 5444f9924c4SBenjamin Herrenschmidt &pnv_pec_stk_pci_xscom_ops, stack, name, 5454f9924c4SBenjamin Herrenschmidt PHB4_PEC_PCI_STK_REGS_COUNT); 5464f9924c4SBenjamin Herrenschmidt 5474f9924c4SBenjamin Herrenschmidt /* PHB pass-through */ 5484f9924c4SBenjamin Herrenschmidt snprintf(name, sizeof(name), "xscom-pec-%d.%d-pci-stack-%d-phb", 5494f9924c4SBenjamin Herrenschmidt pec->chip_id, pec->index, stack->stack_no); 5504f9924c4SBenjamin Herrenschmidt pnv_xscom_region_init(&stack->phb_regs_mr, OBJECT(&stack->phb), 5514f9924c4SBenjamin Herrenschmidt &pnv_phb4_xscom_ops, &stack->phb, name, 0x40); 5524f9924c4SBenjamin Herrenschmidt 5534f9924c4SBenjamin Herrenschmidt /* 5544f9924c4SBenjamin Herrenschmidt * Let the machine/chip realize the PHB object to customize more 5554f9924c4SBenjamin Herrenschmidt * easily some fields 5564f9924c4SBenjamin Herrenschmidt */ 5574f9924c4SBenjamin Herrenschmidt } 5584f9924c4SBenjamin Herrenschmidt 5594f9924c4SBenjamin Herrenschmidt static Property pnv_pec_stk_properties[] = { 5604f9924c4SBenjamin Herrenschmidt DEFINE_PROP_UINT32("stack-no", PnvPhb4PecStack, stack_no, 0), 5614f9924c4SBenjamin Herrenschmidt DEFINE_PROP_LINK("pec", PnvPhb4PecStack, pec, TYPE_PNV_PHB4_PEC, 5624f9924c4SBenjamin Herrenschmidt PnvPhb4PecState *), 5634f9924c4SBenjamin Herrenschmidt DEFINE_PROP_END_OF_LIST(), 5644f9924c4SBenjamin Herrenschmidt }; 5654f9924c4SBenjamin Herrenschmidt 5664f9924c4SBenjamin Herrenschmidt static void pnv_pec_stk_class_init(ObjectClass *klass, void *data) 5674f9924c4SBenjamin Herrenschmidt { 5684f9924c4SBenjamin Herrenschmidt DeviceClass *dc = DEVICE_CLASS(klass); 5694f9924c4SBenjamin Herrenschmidt 5704f9924c4SBenjamin Herrenschmidt device_class_set_props(dc, pnv_pec_stk_properties); 5714f9924c4SBenjamin Herrenschmidt dc->realize = pnv_pec_stk_realize; 57223a782ebSCédric Le Goater dc->user_creatable = false; 5734f9924c4SBenjamin Herrenschmidt 5744f9924c4SBenjamin Herrenschmidt /* TODO: reset regs ? */ 5754f9924c4SBenjamin Herrenschmidt } 5764f9924c4SBenjamin Herrenschmidt 5774f9924c4SBenjamin Herrenschmidt static const TypeInfo pnv_pec_stk_type_info = { 5784f9924c4SBenjamin Herrenschmidt .name = TYPE_PNV_PHB4_PEC_STACK, 5794f9924c4SBenjamin Herrenschmidt .parent = TYPE_DEVICE, 5804f9924c4SBenjamin Herrenschmidt .instance_size = sizeof(PnvPhb4PecStack), 5814f9924c4SBenjamin Herrenschmidt .instance_init = pnv_pec_stk_instance_init, 5824f9924c4SBenjamin Herrenschmidt .class_init = pnv_pec_stk_class_init, 5834f9924c4SBenjamin Herrenschmidt .interfaces = (InterfaceInfo[]) { 5844f9924c4SBenjamin Herrenschmidt { TYPE_PNV_XSCOM_INTERFACE }, 5854f9924c4SBenjamin Herrenschmidt { } 5864f9924c4SBenjamin Herrenschmidt } 5874f9924c4SBenjamin Herrenschmidt }; 5884f9924c4SBenjamin Herrenschmidt 5894f9924c4SBenjamin Herrenschmidt static void pnv_pec_register_types(void) 5904f9924c4SBenjamin Herrenschmidt { 5914f9924c4SBenjamin Herrenschmidt type_register_static(&pnv_pec_type_info); 5924f9924c4SBenjamin Herrenschmidt type_register_static(&pnv_pec_stk_type_info); 5934f9924c4SBenjamin Herrenschmidt } 5944f9924c4SBenjamin Herrenschmidt 5954f9924c4SBenjamin Herrenschmidt type_init(pnv_pec_register_types); 596