xref: /qemu/include/hw/ppc/pnv.h (revision eb859a27e1ebeeeaff096a0c041d9f75c9f7a722)
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;
7454f59d78SCédric Le Goater     PnvPsi       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);
105*eb859a27SCédric Le Goater     void (*dt_populate)(PnvChip *chip, void *fdt);
106e997040eSCédric Le Goater } PnvChipClass;
107e997040eSCédric Le Goater 
1087fd544d8SIgor Mammedov #define PNV_CHIP_TYPE_SUFFIX "-" TYPE_PNV_CHIP
1097fd544d8SIgor Mammedov #define PNV_CHIP_TYPE_NAME(cpu_model) cpu_model PNV_CHIP_TYPE_SUFFIX
1107fd544d8SIgor Mammedov 
1117fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8E PNV_CHIP_TYPE_NAME("power8e_v2.1")
112e997040eSCédric Le Goater #define PNV_CHIP_POWER8E(obj) \
113e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8E)
114e997040eSCédric Le Goater 
1157fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8 PNV_CHIP_TYPE_NAME("power8_v2.0")
116e997040eSCédric Le Goater #define PNV_CHIP_POWER8(obj) \
117e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8)
118e997040eSCédric Le Goater 
1197fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8NVL PNV_CHIP_TYPE_NAME("power8nvl_v1.0")
120e997040eSCédric Le Goater #define PNV_CHIP_POWER8NVL(obj) \
121e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8NVL)
122e997040eSCédric Le Goater 
1237fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER9 PNV_CHIP_TYPE_NAME("power9_v2.0")
124e997040eSCédric Le Goater #define PNV_CHIP_POWER9(obj) \
125e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER9)
126e997040eSCédric Le Goater 
127e997040eSCédric Le Goater /*
1285509db4aSCédric Le Goater  * This generates a HW chip id depending on an index, as found on a
1295509db4aSCédric Le Goater  * two socket system with dual chip modules :
130e997040eSCédric Le Goater  *
131e997040eSCédric Le Goater  *    0x0, 0x1, 0x10, 0x11
132e997040eSCédric Le Goater  *
133e997040eSCédric Le Goater  * 4 chips should be the maximum
1345509db4aSCédric Le Goater  *
1355509db4aSCédric Le Goater  * TODO: use a machine property to define the chip ids
136e997040eSCédric Le Goater  */
137e997040eSCédric Le Goater #define PNV_CHIP_HWID(i) ((((i) & 0x3e) << 3) | ((i) & 0x1))
1389e933f4aSBenjamin Herrenschmidt 
1395509db4aSCédric Le Goater /*
1405509db4aSCédric Le Goater  * Converts back a HW chip id to an index. This is useful to calculate
1415509db4aSCédric Le Goater  * the MMIO addresses of some controllers which depend on the chip id.
1425509db4aSCédric Le Goater  */
1435509db4aSCédric Le Goater #define PNV_CHIP_INDEX(chip)                                    \
1445509db4aSCédric Le Goater     (((chip)->chip_id >> 2) * 2 + ((chip)->chip_id & 0x3))
1455509db4aSCédric Le Goater 
146b168a138SCédric Le Goater #define TYPE_PNV_MACHINE       MACHINE_TYPE_NAME("powernv")
147b168a138SCédric Le Goater #define PNV_MACHINE(obj) \
148b168a138SCédric Le Goater     OBJECT_CHECK(PnvMachineState, (obj), TYPE_PNV_MACHINE)
1499e933f4aSBenjamin Herrenschmidt 
1509e933f4aSBenjamin Herrenschmidt typedef struct PnvMachineState {
1519e933f4aSBenjamin Herrenschmidt     /*< private >*/
1529e933f4aSBenjamin Herrenschmidt     MachineState parent_obj;
1539e933f4aSBenjamin Herrenschmidt 
1549e933f4aSBenjamin Herrenschmidt     uint32_t     initrd_base;
1559e933f4aSBenjamin Herrenschmidt     long         initrd_size;
156e997040eSCédric Le Goater 
157e997040eSCédric Le Goater     uint32_t     num_chips;
158e997040eSCédric Le Goater     PnvChip      **chips;
1593495b6b6SCédric Le Goater 
1603495b6b6SCédric Le Goater     ISABus       *isa_bus;
16154f59d78SCédric Le Goater     uint32_t     cpld_irqstate;
162aeaef83dSCédric Le Goater 
163aeaef83dSCédric Le Goater     IPMIBmc      *bmc;
164bce0b691SCédric Le Goater     Notifier     powerdown_notifier;
1659e933f4aSBenjamin Herrenschmidt } PnvMachineState;
1669e933f4aSBenjamin Herrenschmidt 
167b3b066e9SCédric Le Goater static inline bool pnv_chip_is_power9(const PnvChip *chip)
168b3b066e9SCédric Le Goater {
169b3b066e9SCédric Le Goater     return PNV_CHIP_GET_CLASS(chip)->chip_type == PNV_CHIP_POWER9;
170b3b066e9SCédric Le Goater }
171b3b066e9SCédric Le Goater 
172b3b066e9SCédric Le Goater static inline bool pnv_is_power9(PnvMachineState *pnv)
173b3b066e9SCédric Le Goater {
174b3b066e9SCédric Le Goater     return pnv_chip_is_power9(pnv->chips[0]);
175b3b066e9SCédric Le Goater }
176b3b066e9SCédric Le Goater 
1779e933f4aSBenjamin Herrenschmidt #define PNV_FDT_ADDR          0x01000000
178d2fd9612SCédric Le Goater #define PNV_TIMEBASE_FREQ     512000000ULL
1799e933f4aSBenjamin Herrenschmidt 
180967b7523SCédric Le Goater /*
181aeaef83dSCédric Le Goater  * BMC helpers
182aeaef83dSCédric Le Goater  */
183b168a138SCédric Le Goater void pnv_dt_bmc_sensors(IPMIBmc *bmc, void *fdt);
184bce0b691SCédric Le Goater void pnv_bmc_powerdown(IPMIBmc *bmc);
185aeaef83dSCédric Le Goater 
186aeaef83dSCédric Le Goater /*
187967b7523SCédric Le Goater  * POWER8 MMIO base addresses
188967b7523SCédric Le Goater  */
189967b7523SCédric Le Goater #define PNV_XSCOM_SIZE        0x800000000ull
190967b7523SCédric Le Goater #define PNV_XSCOM_BASE(chip)                                            \
191967b7523SCédric Le Goater     (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE)
192967b7523SCédric Le Goater 
193bf5615e7SCédric Le Goater /*
194bf5615e7SCédric Le Goater  * XSCOM 0x20109CA defines the ICP BAR:
195bf5615e7SCédric Le Goater  *
196bf5615e7SCédric Le Goater  * 0:29   : bits 14 to 43 of address to define 1 MB region.
197bf5615e7SCédric Le Goater  * 30     : 1 to enable ICP to receive loads/stores against its BAR region
198bf5615e7SCédric Le Goater  * 31:63  : Constant 0
199bf5615e7SCédric Le Goater  *
200bf5615e7SCédric Le Goater  * Usually defined as :
201bf5615e7SCédric Le Goater  *
202bf5615e7SCédric Le Goater  *      0xffffe00200000000 -> 0x0003ffff80000000
203bf5615e7SCédric Le Goater  *      0xffffe00600000000 -> 0x0003ffff80100000
204bf5615e7SCédric Le Goater  *      0xffffe02200000000 -> 0x0003ffff80800000
205bf5615e7SCédric Le Goater  *      0xffffe02600000000 -> 0x0003ffff80900000
206bf5615e7SCédric Le Goater  */
207bf5615e7SCédric Le Goater #define PNV_ICP_SIZE         0x0000000000100000ull
208bf5615e7SCédric Le Goater #define PNV_ICP_BASE(chip)                                              \
209bf5615e7SCédric Le Goater     (0x0003ffff80000000ull + (uint64_t) PNV_CHIP_INDEX(chip) * PNV_ICP_SIZE)
210bf5615e7SCédric Le Goater 
21154f59d78SCédric Le Goater 
21254f59d78SCédric Le Goater #define PNV_PSIHB_SIZE       0x0000000000100000ull
21354f59d78SCédric Le Goater #define PNV_PSIHB_BASE(chip) \
21454f59d78SCédric Le Goater     (0x0003fffe80000000ull + (uint64_t)PNV_CHIP_INDEX(chip) * PNV_PSIHB_SIZE)
21554f59d78SCédric Le Goater 
21654f59d78SCédric Le Goater #define PNV_PSIHB_FSP_SIZE   0x0000000100000000ull
21754f59d78SCédric Le Goater #define PNV_PSIHB_FSP_BASE(chip) \
21854f59d78SCédric Le Goater     (0x0003ffe000000000ull + (uint64_t)PNV_CHIP_INDEX(chip) * \
21954f59d78SCédric Le Goater      PNV_PSIHB_FSP_SIZE)
22054f59d78SCédric Le Goater 
2212dfa91a2SCédric Le Goater /*
2222dfa91a2SCédric Le Goater  * POWER9 MMIO base addresses
2232dfa91a2SCédric Le Goater  */
2242dfa91a2SCédric Le Goater #define PNV9_CHIP_BASE(chip, base)   \
2252dfa91a2SCédric Le Goater     ((base) + ((uint64_t) (chip)->chip_id << 42))
2262dfa91a2SCédric Le Goater 
2272dfa91a2SCédric Le Goater #define PNV9_XIVE_VC_SIZE            0x0000008000000000ull
2282dfa91a2SCédric Le Goater #define PNV9_XIVE_VC_BASE(chip)      PNV9_CHIP_BASE(chip, 0x0006010000000000ull)
2292dfa91a2SCédric Le Goater 
2302dfa91a2SCédric Le Goater #define PNV9_XIVE_PC_SIZE            0x0000001000000000ull
2312dfa91a2SCédric Le Goater #define PNV9_XIVE_PC_BASE(chip)      PNV9_CHIP_BASE(chip, 0x0006018000000000ull)
2322dfa91a2SCédric Le Goater 
2332dfa91a2SCédric Le Goater #define PNV9_XIVE_IC_SIZE            0x0000000000080000ull
2342dfa91a2SCédric Le Goater #define PNV9_XIVE_IC_BASE(chip)      PNV9_CHIP_BASE(chip, 0x0006030203100000ull)
2352dfa91a2SCédric Le Goater 
2362dfa91a2SCédric Le Goater #define PNV9_XIVE_TM_SIZE            0x0000000000040000ull
2372dfa91a2SCédric Le Goater #define PNV9_XIVE_TM_BASE(chip)      PNV9_CHIP_BASE(chip, 0x0006030203180000ull)
2382dfa91a2SCédric Le Goater 
2392dfa91a2SCédric Le Goater 
2409e933f4aSBenjamin Herrenschmidt #endif /* _PPC_PNV_H */
241