19e933f4aSBenjamin Herrenschmidt /* 29e933f4aSBenjamin Herrenschmidt * QEMU PowerPC PowerNV various definitions 39e933f4aSBenjamin Herrenschmidt * 49e933f4aSBenjamin Herrenschmidt * Copyright (c) 2014-2016 BenH, IBM Corporation. 59e933f4aSBenjamin Herrenschmidt * 69e933f4aSBenjamin Herrenschmidt * This library is free software; you can redistribute it and/or 79e933f4aSBenjamin Herrenschmidt * modify it under the terms of the GNU Lesser General Public 89e933f4aSBenjamin Herrenschmidt * License as published by the Free Software Foundation; either 99e933f4aSBenjamin Herrenschmidt * version 2 of the License, or (at your option) any later version. 109e933f4aSBenjamin Herrenschmidt * 119e933f4aSBenjamin Herrenschmidt * This library is distributed in the hope that it will be useful, 129e933f4aSBenjamin Herrenschmidt * but WITHOUT ANY WARRANTY; without even the implied warranty of 139e933f4aSBenjamin Herrenschmidt * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 149e933f4aSBenjamin Herrenschmidt * Lesser General Public License for more details. 159e933f4aSBenjamin Herrenschmidt * 169e933f4aSBenjamin Herrenschmidt * You should have received a copy of the GNU Lesser General Public 179e933f4aSBenjamin Herrenschmidt * License along with this library; if not, see <http://www.gnu.org/licenses/>. 189e933f4aSBenjamin Herrenschmidt */ 199e933f4aSBenjamin Herrenschmidt #ifndef _PPC_PNV_H 209e933f4aSBenjamin Herrenschmidt #define _PPC_PNV_H 219e933f4aSBenjamin Herrenschmidt 229e933f4aSBenjamin Herrenschmidt #include "hw/boards.h" 23e997040eSCédric Le Goater #include "hw/sysbus.h" 24eaf87a39SDavid Gibson #include "hw/ipmi/ipmi.h" 25a3980bf5SBenjamin Herrenschmidt #include "hw/ppc/pnv_lpc.h" 2654f59d78SCédric Le Goater #include "hw/ppc/pnv_psi.h" 270722d05aSBenjamin Herrenschmidt #include "hw/ppc/pnv_occ.h" 282dfa91a2SCédric Le Goater #include "hw/ppc/pnv_xive.h" 29e997040eSCédric Le Goater 30b168a138SCédric Le Goater #define TYPE_PNV_CHIP "pnv-chip" 31e997040eSCédric Le Goater #define PNV_CHIP(obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP) 32e997040eSCédric Le Goater #define PNV_CHIP_CLASS(klass) \ 33e997040eSCédric Le Goater OBJECT_CLASS_CHECK(PnvChipClass, (klass), TYPE_PNV_CHIP) 34e997040eSCédric Le Goater #define PNV_CHIP_GET_CLASS(obj) \ 35e997040eSCédric Le Goater OBJECT_GET_CLASS(PnvChipClass, (obj), TYPE_PNV_CHIP) 36e997040eSCédric Le Goater 37e997040eSCédric Le Goater typedef enum PnvChipType { 38e997040eSCédric Le Goater PNV_CHIP_POWER8E, /* AKA Murano (default) */ 39e997040eSCédric Le Goater PNV_CHIP_POWER8, /* AKA Venice */ 40e997040eSCédric Le Goater PNV_CHIP_POWER8NVL, /* AKA Naples */ 41e997040eSCédric Le Goater PNV_CHIP_POWER9, /* AKA Nimbus */ 42e997040eSCédric Le Goater } PnvChipType; 43e997040eSCédric Le Goater 44e997040eSCédric Le Goater typedef struct PnvChip { 45e997040eSCédric Le Goater /*< private >*/ 46e997040eSCédric Le Goater SysBusDevice parent_obj; 47e997040eSCédric Le Goater 48e997040eSCédric Le Goater /*< public >*/ 49e997040eSCédric Le Goater uint32_t chip_id; 50e997040eSCédric Le Goater uint64_t ram_start; 51e997040eSCédric Le Goater uint64_t ram_size; 52397a79e7SCédric Le Goater 53397a79e7SCédric Le Goater uint32_t nr_cores; 54397a79e7SCédric Le Goater uint64_t cores_mask; 55d2fd9612SCédric Le Goater void *cores; 56967b7523SCédric Le Goater 57967b7523SCédric Le Goater hwaddr xscom_base; 58967b7523SCédric Le Goater MemoryRegion xscom_mmio; 59967b7523SCédric Le Goater MemoryRegion xscom; 60967b7523SCédric Le Goater AddressSpace xscom_as; 6177864267SCédric Le Goater } PnvChip; 6277864267SCédric Le Goater 6377864267SCédric Le Goater #define TYPE_PNV8_CHIP "pnv8-chip" 6477864267SCédric Le Goater #define PNV8_CHIP(obj) OBJECT_CHECK(Pnv8Chip, (obj), TYPE_PNV8_CHIP) 6577864267SCédric Le Goater 6677864267SCédric Le Goater typedef struct Pnv8Chip { 6777864267SCédric Le Goater /*< private >*/ 6877864267SCédric Le Goater PnvChip parent_obj; 6977864267SCédric Le Goater 7077864267SCédric Le Goater /*< public >*/ 71bf5615e7SCédric Le Goater MemoryRegion icp_mmio; 72a3980bf5SBenjamin Herrenschmidt 73a3980bf5SBenjamin Herrenschmidt PnvLpcController lpc; 74*ae856055SCédric Le Goater Pnv8Psi psi; 750722d05aSBenjamin Herrenschmidt PnvOCC occ; 7677864267SCédric Le Goater } Pnv8Chip; 7777864267SCédric Le Goater 7877864267SCédric Le Goater #define TYPE_PNV9_CHIP "pnv9-chip" 7977864267SCédric Le Goater #define PNV9_CHIP(obj) OBJECT_CHECK(Pnv9Chip, (obj), TYPE_PNV9_CHIP) 8077864267SCédric Le Goater 8177864267SCédric Le Goater typedef struct Pnv9Chip { 8277864267SCédric Le Goater /*< private >*/ 8377864267SCédric Le Goater PnvChip parent_obj; 8477864267SCédric Le Goater 8577864267SCédric Le Goater /*< public >*/ 862dfa91a2SCédric Le Goater PnvXive xive; 8777864267SCédric Le Goater } Pnv9Chip; 88e997040eSCédric Le Goater 89e997040eSCédric Le Goater typedef struct PnvChipClass { 90e997040eSCédric Le Goater /*< private >*/ 91e997040eSCédric Le Goater SysBusDeviceClass parent_class; 92e997040eSCédric Le Goater 93e997040eSCédric Le Goater /*< public >*/ 94e997040eSCédric Le Goater PnvChipType chip_type; 95e997040eSCédric Le Goater uint64_t chip_cfam_id; 96397a79e7SCédric Le Goater uint64_t cores_mask; 97631adaffSCédric Le Goater 98967b7523SCédric Le Goater hwaddr xscom_base; 99967b7523SCédric Le Goater 10077864267SCédric Le Goater DeviceRealize parent_realize; 10177864267SCédric Le Goater 102631adaffSCédric Le Goater uint32_t (*core_pir)(PnvChip *chip, uint32_t core_id); 1038fa1f4efSCédric Le Goater void (*intc_create)(PnvChip *chip, PowerPCCPU *cpu, Error **errp); 10404026890SCédric Le Goater ISABus *(*isa_create)(PnvChip *chip, Error **errp); 105eb859a27SCédric Le Goater void (*dt_populate)(PnvChip *chip, void *fdt); 106d8e4aad5SCédric Le Goater void (*pic_print_info)(PnvChip *chip, Monitor *mon); 107e997040eSCédric Le Goater } PnvChipClass; 108e997040eSCédric Le Goater 1097fd544d8SIgor Mammedov #define PNV_CHIP_TYPE_SUFFIX "-" TYPE_PNV_CHIP 1107fd544d8SIgor Mammedov #define PNV_CHIP_TYPE_NAME(cpu_model) cpu_model PNV_CHIP_TYPE_SUFFIX 1117fd544d8SIgor Mammedov 1127fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8E PNV_CHIP_TYPE_NAME("power8e_v2.1") 113e997040eSCédric Le Goater #define PNV_CHIP_POWER8E(obj) \ 114e997040eSCédric Le Goater OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8E) 115e997040eSCédric Le Goater 1167fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8 PNV_CHIP_TYPE_NAME("power8_v2.0") 117e997040eSCédric Le Goater #define PNV_CHIP_POWER8(obj) \ 118e997040eSCédric Le Goater OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8) 119e997040eSCédric Le Goater 1207fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8NVL PNV_CHIP_TYPE_NAME("power8nvl_v1.0") 121e997040eSCédric Le Goater #define PNV_CHIP_POWER8NVL(obj) \ 122e997040eSCédric Le Goater OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8NVL) 123e997040eSCédric Le Goater 1247fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER9 PNV_CHIP_TYPE_NAME("power9_v2.0") 125e997040eSCédric Le Goater #define PNV_CHIP_POWER9(obj) \ 126e997040eSCédric Le Goater OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER9) 127e997040eSCédric Le Goater 128e997040eSCédric Le Goater /* 1295509db4aSCédric Le Goater * This generates a HW chip id depending on an index, as found on a 1305509db4aSCédric Le Goater * two socket system with dual chip modules : 131e997040eSCédric Le Goater * 132e997040eSCédric Le Goater * 0x0, 0x1, 0x10, 0x11 133e997040eSCédric Le Goater * 134e997040eSCédric Le Goater * 4 chips should be the maximum 1355509db4aSCédric Le Goater * 1365509db4aSCédric Le Goater * TODO: use a machine property to define the chip ids 137e997040eSCédric Le Goater */ 138e997040eSCédric Le Goater #define PNV_CHIP_HWID(i) ((((i) & 0x3e) << 3) | ((i) & 0x1)) 1399e933f4aSBenjamin Herrenschmidt 1405509db4aSCédric Le Goater /* 1415509db4aSCédric Le Goater * Converts back a HW chip id to an index. This is useful to calculate 1425509db4aSCédric Le Goater * the MMIO addresses of some controllers which depend on the chip id. 1435509db4aSCédric Le Goater */ 1445509db4aSCédric Le Goater #define PNV_CHIP_INDEX(chip) \ 1455509db4aSCédric Le Goater (((chip)->chip_id >> 2) * 2 + ((chip)->chip_id & 0x3)) 1465509db4aSCédric Le Goater 147b168a138SCédric Le Goater #define TYPE_PNV_MACHINE MACHINE_TYPE_NAME("powernv") 148b168a138SCédric Le Goater #define PNV_MACHINE(obj) \ 149b168a138SCédric Le Goater OBJECT_CHECK(PnvMachineState, (obj), TYPE_PNV_MACHINE) 1509e933f4aSBenjamin Herrenschmidt 1519e933f4aSBenjamin Herrenschmidt typedef struct PnvMachineState { 1529e933f4aSBenjamin Herrenschmidt /*< private >*/ 1539e933f4aSBenjamin Herrenschmidt MachineState parent_obj; 1549e933f4aSBenjamin Herrenschmidt 1559e933f4aSBenjamin Herrenschmidt uint32_t initrd_base; 1569e933f4aSBenjamin Herrenschmidt long initrd_size; 157e997040eSCédric Le Goater 158e997040eSCédric Le Goater uint32_t num_chips; 159e997040eSCédric Le Goater PnvChip **chips; 1603495b6b6SCédric Le Goater 1613495b6b6SCédric Le Goater ISABus *isa_bus; 16254f59d78SCédric Le Goater uint32_t cpld_irqstate; 163aeaef83dSCédric Le Goater 164aeaef83dSCédric Le Goater IPMIBmc *bmc; 165bce0b691SCédric Le Goater Notifier powerdown_notifier; 1669e933f4aSBenjamin Herrenschmidt } PnvMachineState; 1679e933f4aSBenjamin Herrenschmidt 168b3b066e9SCédric Le Goater static inline bool pnv_chip_is_power9(const PnvChip *chip) 169b3b066e9SCédric Le Goater { 170b3b066e9SCédric Le Goater return PNV_CHIP_GET_CLASS(chip)->chip_type == PNV_CHIP_POWER9; 171b3b066e9SCédric Le Goater } 172b3b066e9SCédric Le Goater 173b3b066e9SCédric Le Goater static inline bool pnv_is_power9(PnvMachineState *pnv) 174b3b066e9SCédric Le Goater { 175b3b066e9SCédric Le Goater return pnv_chip_is_power9(pnv->chips[0]); 176b3b066e9SCédric Le Goater } 177b3b066e9SCédric Le Goater 1789e933f4aSBenjamin Herrenschmidt #define PNV_FDT_ADDR 0x01000000 179d2fd9612SCédric Le Goater #define PNV_TIMEBASE_FREQ 512000000ULL 1809e933f4aSBenjamin Herrenschmidt 181967b7523SCédric Le Goater /* 182aeaef83dSCédric Le Goater * BMC helpers 183aeaef83dSCédric Le Goater */ 184b168a138SCédric Le Goater void pnv_dt_bmc_sensors(IPMIBmc *bmc, void *fdt); 185bce0b691SCédric Le Goater void pnv_bmc_powerdown(IPMIBmc *bmc); 186aeaef83dSCédric Le Goater 187aeaef83dSCédric Le Goater /* 188967b7523SCédric Le Goater * POWER8 MMIO base addresses 189967b7523SCédric Le Goater */ 190967b7523SCédric Le Goater #define PNV_XSCOM_SIZE 0x800000000ull 191967b7523SCédric Le Goater #define PNV_XSCOM_BASE(chip) \ 192967b7523SCédric Le Goater (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE) 193967b7523SCédric Le Goater 194bf5615e7SCédric Le Goater /* 195bf5615e7SCédric Le Goater * XSCOM 0x20109CA defines the ICP BAR: 196bf5615e7SCédric Le Goater * 197bf5615e7SCédric Le Goater * 0:29 : bits 14 to 43 of address to define 1 MB region. 198bf5615e7SCédric Le Goater * 30 : 1 to enable ICP to receive loads/stores against its BAR region 199bf5615e7SCédric Le Goater * 31:63 : Constant 0 200bf5615e7SCédric Le Goater * 201bf5615e7SCédric Le Goater * Usually defined as : 202bf5615e7SCédric Le Goater * 203bf5615e7SCédric Le Goater * 0xffffe00200000000 -> 0x0003ffff80000000 204bf5615e7SCédric Le Goater * 0xffffe00600000000 -> 0x0003ffff80100000 205bf5615e7SCédric Le Goater * 0xffffe02200000000 -> 0x0003ffff80800000 206bf5615e7SCédric Le Goater * 0xffffe02600000000 -> 0x0003ffff80900000 207bf5615e7SCédric Le Goater */ 208bf5615e7SCédric Le Goater #define PNV_ICP_SIZE 0x0000000000100000ull 209bf5615e7SCédric Le Goater #define PNV_ICP_BASE(chip) \ 210bf5615e7SCédric Le Goater (0x0003ffff80000000ull + (uint64_t) PNV_CHIP_INDEX(chip) * PNV_ICP_SIZE) 211bf5615e7SCédric Le Goater 21254f59d78SCédric Le Goater 21354f59d78SCédric Le Goater #define PNV_PSIHB_SIZE 0x0000000000100000ull 21454f59d78SCédric Le Goater #define PNV_PSIHB_BASE(chip) \ 21554f59d78SCédric Le Goater (0x0003fffe80000000ull + (uint64_t)PNV_CHIP_INDEX(chip) * PNV_PSIHB_SIZE) 21654f59d78SCédric Le Goater 21754f59d78SCédric Le Goater #define PNV_PSIHB_FSP_SIZE 0x0000000100000000ull 21854f59d78SCédric Le Goater #define PNV_PSIHB_FSP_BASE(chip) \ 21954f59d78SCédric Le Goater (0x0003ffe000000000ull + (uint64_t)PNV_CHIP_INDEX(chip) * \ 22054f59d78SCédric Le Goater PNV_PSIHB_FSP_SIZE) 22154f59d78SCédric Le Goater 2222dfa91a2SCédric Le Goater /* 2232dfa91a2SCédric Le Goater * POWER9 MMIO base addresses 2242dfa91a2SCédric Le Goater */ 2252dfa91a2SCédric Le Goater #define PNV9_CHIP_BASE(chip, base) \ 2262dfa91a2SCédric Le Goater ((base) + ((uint64_t) (chip)->chip_id << 42)) 2272dfa91a2SCédric Le Goater 2282dfa91a2SCédric Le Goater #define PNV9_XIVE_VC_SIZE 0x0000008000000000ull 2292dfa91a2SCédric Le Goater #define PNV9_XIVE_VC_BASE(chip) PNV9_CHIP_BASE(chip, 0x0006010000000000ull) 2302dfa91a2SCédric Le Goater 2312dfa91a2SCédric Le Goater #define PNV9_XIVE_PC_SIZE 0x0000001000000000ull 2322dfa91a2SCédric Le Goater #define PNV9_XIVE_PC_BASE(chip) PNV9_CHIP_BASE(chip, 0x0006018000000000ull) 2332dfa91a2SCédric Le Goater 2342dfa91a2SCédric Le Goater #define PNV9_XIVE_IC_SIZE 0x0000000000080000ull 2352dfa91a2SCédric Le Goater #define PNV9_XIVE_IC_BASE(chip) PNV9_CHIP_BASE(chip, 0x0006030203100000ull) 2362dfa91a2SCédric Le Goater 2372dfa91a2SCédric Le Goater #define PNV9_XIVE_TM_SIZE 0x0000000000040000ull 2382dfa91a2SCédric Le Goater #define PNV9_XIVE_TM_BASE(chip) PNV9_CHIP_BASE(chip, 0x0006030203180000ull) 2392dfa91a2SCédric Le Goater 2402dfa91a2SCédric Le Goater 2419e933f4aSBenjamin Herrenschmidt #endif /* _PPC_PNV_H */ 242