xref: /qemu/include/hw/ppc/pnv.h (revision 2dfa91a2aa5a84aa0e7b68517e58793717d41b32)
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"
28*2dfa91a2SCé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 >*/
86*2dfa91a2SCé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);
105e997040eSCédric Le Goater } PnvChipClass;
106e997040eSCédric Le Goater 
1077fd544d8SIgor Mammedov #define PNV_CHIP_TYPE_SUFFIX "-" TYPE_PNV_CHIP
1087fd544d8SIgor Mammedov #define PNV_CHIP_TYPE_NAME(cpu_model) cpu_model PNV_CHIP_TYPE_SUFFIX
1097fd544d8SIgor Mammedov 
1107fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8E PNV_CHIP_TYPE_NAME("power8e_v2.1")
111e997040eSCédric Le Goater #define PNV_CHIP_POWER8E(obj) \
112e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8E)
113e997040eSCédric Le Goater 
1147fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8 PNV_CHIP_TYPE_NAME("power8_v2.0")
115e997040eSCédric Le Goater #define PNV_CHIP_POWER8(obj) \
116e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8)
117e997040eSCédric Le Goater 
1187fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8NVL PNV_CHIP_TYPE_NAME("power8nvl_v1.0")
119e997040eSCédric Le Goater #define PNV_CHIP_POWER8NVL(obj) \
120e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8NVL)
121e997040eSCédric Le Goater 
1227fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER9 PNV_CHIP_TYPE_NAME("power9_v2.0")
123e997040eSCédric Le Goater #define PNV_CHIP_POWER9(obj) \
124e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER9)
125e997040eSCédric Le Goater 
126e997040eSCédric Le Goater /*
1275509db4aSCédric Le Goater  * This generates a HW chip id depending on an index, as found on a
1285509db4aSCédric Le Goater  * two socket system with dual chip modules :
129e997040eSCédric Le Goater  *
130e997040eSCédric Le Goater  *    0x0, 0x1, 0x10, 0x11
131e997040eSCédric Le Goater  *
132e997040eSCédric Le Goater  * 4 chips should be the maximum
1335509db4aSCédric Le Goater  *
1345509db4aSCédric Le Goater  * TODO: use a machine property to define the chip ids
135e997040eSCédric Le Goater  */
136e997040eSCédric Le Goater #define PNV_CHIP_HWID(i) ((((i) & 0x3e) << 3) | ((i) & 0x1))
1379e933f4aSBenjamin Herrenschmidt 
1385509db4aSCédric Le Goater /*
1395509db4aSCédric Le Goater  * Converts back a HW chip id to an index. This is useful to calculate
1405509db4aSCédric Le Goater  * the MMIO addresses of some controllers which depend on the chip id.
1415509db4aSCédric Le Goater  */
1425509db4aSCédric Le Goater #define PNV_CHIP_INDEX(chip)                                    \
1435509db4aSCédric Le Goater     (((chip)->chip_id >> 2) * 2 + ((chip)->chip_id & 0x3))
1445509db4aSCédric Le Goater 
145b168a138SCédric Le Goater #define TYPE_PNV_MACHINE       MACHINE_TYPE_NAME("powernv")
146b168a138SCédric Le Goater #define PNV_MACHINE(obj) \
147b168a138SCédric Le Goater     OBJECT_CHECK(PnvMachineState, (obj), TYPE_PNV_MACHINE)
1489e933f4aSBenjamin Herrenschmidt 
1499e933f4aSBenjamin Herrenschmidt typedef struct PnvMachineState {
1509e933f4aSBenjamin Herrenschmidt     /*< private >*/
1519e933f4aSBenjamin Herrenschmidt     MachineState parent_obj;
1529e933f4aSBenjamin Herrenschmidt 
1539e933f4aSBenjamin Herrenschmidt     uint32_t     initrd_base;
1549e933f4aSBenjamin Herrenschmidt     long         initrd_size;
155e997040eSCédric Le Goater 
156e997040eSCédric Le Goater     uint32_t     num_chips;
157e997040eSCédric Le Goater     PnvChip      **chips;
1583495b6b6SCédric Le Goater 
1593495b6b6SCédric Le Goater     ISABus       *isa_bus;
16054f59d78SCédric Le Goater     uint32_t     cpld_irqstate;
161aeaef83dSCédric Le Goater 
162aeaef83dSCédric Le Goater     IPMIBmc      *bmc;
163bce0b691SCédric Le Goater     Notifier     powerdown_notifier;
1649e933f4aSBenjamin Herrenschmidt } PnvMachineState;
1659e933f4aSBenjamin Herrenschmidt 
166b3b066e9SCédric Le Goater static inline bool pnv_chip_is_power9(const PnvChip *chip)
167b3b066e9SCédric Le Goater {
168b3b066e9SCédric Le Goater     return PNV_CHIP_GET_CLASS(chip)->chip_type == PNV_CHIP_POWER9;
169b3b066e9SCédric Le Goater }
170b3b066e9SCédric Le Goater 
171b3b066e9SCédric Le Goater static inline bool pnv_is_power9(PnvMachineState *pnv)
172b3b066e9SCédric Le Goater {
173b3b066e9SCédric Le Goater     return pnv_chip_is_power9(pnv->chips[0]);
174b3b066e9SCédric Le Goater }
175b3b066e9SCédric Le Goater 
1769e933f4aSBenjamin Herrenschmidt #define PNV_FDT_ADDR          0x01000000
177d2fd9612SCédric Le Goater #define PNV_TIMEBASE_FREQ     512000000ULL
1789e933f4aSBenjamin Herrenschmidt 
179967b7523SCédric Le Goater /*
180aeaef83dSCédric Le Goater  * BMC helpers
181aeaef83dSCédric Le Goater  */
182b168a138SCédric Le Goater void pnv_dt_bmc_sensors(IPMIBmc *bmc, void *fdt);
183bce0b691SCédric Le Goater void pnv_bmc_powerdown(IPMIBmc *bmc);
184aeaef83dSCédric Le Goater 
185aeaef83dSCédric Le Goater /*
186967b7523SCédric Le Goater  * POWER8 MMIO base addresses
187967b7523SCédric Le Goater  */
188967b7523SCédric Le Goater #define PNV_XSCOM_SIZE        0x800000000ull
189967b7523SCédric Le Goater #define PNV_XSCOM_BASE(chip)                                            \
190967b7523SCédric Le Goater     (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE)
191967b7523SCédric Le Goater 
192bf5615e7SCédric Le Goater /*
193bf5615e7SCédric Le Goater  * XSCOM 0x20109CA defines the ICP BAR:
194bf5615e7SCédric Le Goater  *
195bf5615e7SCédric Le Goater  * 0:29   : bits 14 to 43 of address to define 1 MB region.
196bf5615e7SCédric Le Goater  * 30     : 1 to enable ICP to receive loads/stores against its BAR region
197bf5615e7SCédric Le Goater  * 31:63  : Constant 0
198bf5615e7SCédric Le Goater  *
199bf5615e7SCédric Le Goater  * Usually defined as :
200bf5615e7SCédric Le Goater  *
201bf5615e7SCédric Le Goater  *      0xffffe00200000000 -> 0x0003ffff80000000
202bf5615e7SCédric Le Goater  *      0xffffe00600000000 -> 0x0003ffff80100000
203bf5615e7SCédric Le Goater  *      0xffffe02200000000 -> 0x0003ffff80800000
204bf5615e7SCédric Le Goater  *      0xffffe02600000000 -> 0x0003ffff80900000
205bf5615e7SCédric Le Goater  */
206bf5615e7SCédric Le Goater #define PNV_ICP_SIZE         0x0000000000100000ull
207bf5615e7SCédric Le Goater #define PNV_ICP_BASE(chip)                                              \
208bf5615e7SCédric Le Goater     (0x0003ffff80000000ull + (uint64_t) PNV_CHIP_INDEX(chip) * PNV_ICP_SIZE)
209bf5615e7SCédric Le Goater 
21054f59d78SCédric Le Goater 
21154f59d78SCédric Le Goater #define PNV_PSIHB_SIZE       0x0000000000100000ull
21254f59d78SCédric Le Goater #define PNV_PSIHB_BASE(chip) \
21354f59d78SCédric Le Goater     (0x0003fffe80000000ull + (uint64_t)PNV_CHIP_INDEX(chip) * PNV_PSIHB_SIZE)
21454f59d78SCédric Le Goater 
21554f59d78SCédric Le Goater #define PNV_PSIHB_FSP_SIZE   0x0000000100000000ull
21654f59d78SCédric Le Goater #define PNV_PSIHB_FSP_BASE(chip) \
21754f59d78SCédric Le Goater     (0x0003ffe000000000ull + (uint64_t)PNV_CHIP_INDEX(chip) * \
21854f59d78SCédric Le Goater      PNV_PSIHB_FSP_SIZE)
21954f59d78SCédric Le Goater 
220*2dfa91a2SCédric Le Goater /*
221*2dfa91a2SCédric Le Goater  * POWER9 MMIO base addresses
222*2dfa91a2SCédric Le Goater  */
223*2dfa91a2SCédric Le Goater #define PNV9_CHIP_BASE(chip, base)   \
224*2dfa91a2SCédric Le Goater     ((base) + ((uint64_t) (chip)->chip_id << 42))
225*2dfa91a2SCédric Le Goater 
226*2dfa91a2SCédric Le Goater #define PNV9_XIVE_VC_SIZE            0x0000008000000000ull
227*2dfa91a2SCédric Le Goater #define PNV9_XIVE_VC_BASE(chip)      PNV9_CHIP_BASE(chip, 0x0006010000000000ull)
228*2dfa91a2SCédric Le Goater 
229*2dfa91a2SCédric Le Goater #define PNV9_XIVE_PC_SIZE            0x0000001000000000ull
230*2dfa91a2SCédric Le Goater #define PNV9_XIVE_PC_BASE(chip)      PNV9_CHIP_BASE(chip, 0x0006018000000000ull)
231*2dfa91a2SCédric Le Goater 
232*2dfa91a2SCédric Le Goater #define PNV9_XIVE_IC_SIZE            0x0000000000080000ull
233*2dfa91a2SCédric Le Goater #define PNV9_XIVE_IC_BASE(chip)      PNV9_CHIP_BASE(chip, 0x0006030203100000ull)
234*2dfa91a2SCédric Le Goater 
235*2dfa91a2SCédric Le Goater #define PNV9_XIVE_TM_SIZE            0x0000000000040000ull
236*2dfa91a2SCédric Le Goater #define PNV9_XIVE_TM_BASE(chip)      PNV9_CHIP_BASE(chip, 0x0006030203180000ull)
237*2dfa91a2SCédric Le Goater 
238*2dfa91a2SCédric Le Goater 
2399e933f4aSBenjamin Herrenschmidt #endif /* _PPC_PNV_H */
240