xref: /qemu/include/hw/ppc/pnv.h (revision 8fa1f4ef3828e71bfec1de2934c99e35c25709b6)
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"
28e997040eSCédric Le Goater 
29b168a138SCédric Le Goater #define TYPE_PNV_CHIP "pnv-chip"
30e997040eSCédric Le Goater #define PNV_CHIP(obj) OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP)
31e997040eSCédric Le Goater #define PNV_CHIP_CLASS(klass) \
32e997040eSCédric Le Goater      OBJECT_CLASS_CHECK(PnvChipClass, (klass), TYPE_PNV_CHIP)
33e997040eSCédric Le Goater #define PNV_CHIP_GET_CLASS(obj) \
34e997040eSCédric Le Goater      OBJECT_GET_CLASS(PnvChipClass, (obj), TYPE_PNV_CHIP)
35e997040eSCédric Le Goater 
36e997040eSCédric Le Goater typedef enum PnvChipType {
37e997040eSCédric Le Goater     PNV_CHIP_POWER8E,     /* AKA Murano (default) */
38e997040eSCédric Le Goater     PNV_CHIP_POWER8,      /* AKA Venice */
39e997040eSCédric Le Goater     PNV_CHIP_POWER8NVL,   /* AKA Naples */
40e997040eSCédric Le Goater     PNV_CHIP_POWER9,      /* AKA Nimbus */
41e997040eSCédric Le Goater } PnvChipType;
42e997040eSCédric Le Goater 
43e997040eSCédric Le Goater typedef struct PnvChip {
44e997040eSCédric Le Goater     /*< private >*/
45e997040eSCédric Le Goater     SysBusDevice parent_obj;
46e997040eSCédric Le Goater 
47e997040eSCédric Le Goater     /*< public >*/
48e997040eSCédric Le Goater     uint32_t     chip_id;
49e997040eSCédric Le Goater     uint64_t     ram_start;
50e997040eSCédric Le Goater     uint64_t     ram_size;
51397a79e7SCédric Le Goater 
52397a79e7SCédric Le Goater     uint32_t     nr_cores;
53397a79e7SCédric Le Goater     uint64_t     cores_mask;
54d2fd9612SCédric Le Goater     void         *cores;
55967b7523SCédric Le Goater 
56967b7523SCédric Le Goater     hwaddr       xscom_base;
57967b7523SCédric Le Goater     MemoryRegion xscom_mmio;
58967b7523SCédric Le Goater     MemoryRegion xscom;
59967b7523SCédric Le Goater     AddressSpace xscom_as;
6077864267SCédric Le Goater } PnvChip;
6177864267SCédric Le Goater 
6277864267SCédric Le Goater #define TYPE_PNV8_CHIP "pnv8-chip"
6377864267SCédric Le Goater #define PNV8_CHIP(obj) OBJECT_CHECK(Pnv8Chip, (obj), TYPE_PNV8_CHIP)
6477864267SCédric Le Goater 
6577864267SCédric Le Goater typedef struct Pnv8Chip {
6677864267SCédric Le Goater     /*< private >*/
6777864267SCédric Le Goater     PnvChip      parent_obj;
6877864267SCédric Le Goater 
6977864267SCédric Le Goater     /*< public >*/
70bf5615e7SCédric Le Goater     MemoryRegion icp_mmio;
71a3980bf5SBenjamin Herrenschmidt 
72a3980bf5SBenjamin Herrenschmidt     PnvLpcController lpc;
7354f59d78SCédric Le Goater     PnvPsi       psi;
740722d05aSBenjamin Herrenschmidt     PnvOCC       occ;
7577864267SCédric Le Goater } Pnv8Chip;
7677864267SCédric Le Goater 
7777864267SCédric Le Goater #define TYPE_PNV9_CHIP "pnv9-chip"
7877864267SCédric Le Goater #define PNV9_CHIP(obj) OBJECT_CHECK(Pnv9Chip, (obj), TYPE_PNV9_CHIP)
7977864267SCédric Le Goater 
8077864267SCédric Le Goater typedef struct Pnv9Chip {
8177864267SCédric Le Goater     /*< private >*/
8277864267SCédric Le Goater     PnvChip      parent_obj;
8377864267SCédric Le Goater 
8477864267SCédric Le Goater     /*< public >*/
8577864267SCédric Le Goater } Pnv9Chip;
86e997040eSCédric Le Goater 
87e997040eSCédric Le Goater typedef struct PnvChipClass {
88e997040eSCédric Le Goater     /*< private >*/
89e997040eSCédric Le Goater     SysBusDeviceClass parent_class;
90e997040eSCédric Le Goater 
91e997040eSCédric Le Goater     /*< public >*/
92e997040eSCédric Le Goater     PnvChipType  chip_type;
93e997040eSCédric Le Goater     uint64_t     chip_cfam_id;
94397a79e7SCédric Le Goater     uint64_t     cores_mask;
95631adaffSCédric Le Goater 
96967b7523SCédric Le Goater     hwaddr       xscom_base;
97967b7523SCédric Le Goater 
9877864267SCédric Le Goater     DeviceRealize parent_realize;
9977864267SCédric Le Goater 
100631adaffSCédric Le Goater     uint32_t (*core_pir)(PnvChip *chip, uint32_t core_id);
101*8fa1f4efSCédric Le Goater     void (*intc_create)(PnvChip *chip, PowerPCCPU *cpu, Error **errp);
10204026890SCédric Le Goater     ISABus *(*isa_create)(PnvChip *chip, Error **errp);
103e997040eSCédric Le Goater } PnvChipClass;
104e997040eSCédric Le Goater 
1057fd544d8SIgor Mammedov #define PNV_CHIP_TYPE_SUFFIX "-" TYPE_PNV_CHIP
1067fd544d8SIgor Mammedov #define PNV_CHIP_TYPE_NAME(cpu_model) cpu_model PNV_CHIP_TYPE_SUFFIX
1077fd544d8SIgor Mammedov 
1087fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8E PNV_CHIP_TYPE_NAME("power8e_v2.1")
109e997040eSCédric Le Goater #define PNV_CHIP_POWER8E(obj) \
110e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8E)
111e997040eSCédric Le Goater 
1127fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8 PNV_CHIP_TYPE_NAME("power8_v2.0")
113e997040eSCédric Le Goater #define PNV_CHIP_POWER8(obj) \
114e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8)
115e997040eSCédric Le Goater 
1167fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER8NVL PNV_CHIP_TYPE_NAME("power8nvl_v1.0")
117e997040eSCédric Le Goater #define PNV_CHIP_POWER8NVL(obj) \
118e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER8NVL)
119e997040eSCédric Le Goater 
1207fd544d8SIgor Mammedov #define TYPE_PNV_CHIP_POWER9 PNV_CHIP_TYPE_NAME("power9_v2.0")
121e997040eSCédric Le Goater #define PNV_CHIP_POWER9(obj) \
122e997040eSCédric Le Goater     OBJECT_CHECK(PnvChip, (obj), TYPE_PNV_CHIP_POWER9)
123e997040eSCédric Le Goater 
124e997040eSCédric Le Goater /*
1255509db4aSCédric Le Goater  * This generates a HW chip id depending on an index, as found on a
1265509db4aSCédric Le Goater  * two socket system with dual chip modules :
127e997040eSCédric Le Goater  *
128e997040eSCédric Le Goater  *    0x0, 0x1, 0x10, 0x11
129e997040eSCédric Le Goater  *
130e997040eSCédric Le Goater  * 4 chips should be the maximum
1315509db4aSCédric Le Goater  *
1325509db4aSCédric Le Goater  * TODO: use a machine property to define the chip ids
133e997040eSCédric Le Goater  */
134e997040eSCédric Le Goater #define PNV_CHIP_HWID(i) ((((i) & 0x3e) << 3) | ((i) & 0x1))
1359e933f4aSBenjamin Herrenschmidt 
1365509db4aSCédric Le Goater /*
1375509db4aSCédric Le Goater  * Converts back a HW chip id to an index. This is useful to calculate
1385509db4aSCédric Le Goater  * the MMIO addresses of some controllers which depend on the chip id.
1395509db4aSCédric Le Goater  */
1405509db4aSCédric Le Goater #define PNV_CHIP_INDEX(chip)                                    \
1415509db4aSCédric Le Goater     (((chip)->chip_id >> 2) * 2 + ((chip)->chip_id & 0x3))
1425509db4aSCédric Le Goater 
143b168a138SCédric Le Goater #define TYPE_PNV_MACHINE       MACHINE_TYPE_NAME("powernv")
144b168a138SCédric Le Goater #define PNV_MACHINE(obj) \
145b168a138SCédric Le Goater     OBJECT_CHECK(PnvMachineState, (obj), TYPE_PNV_MACHINE)
1469e933f4aSBenjamin Herrenschmidt 
1479e933f4aSBenjamin Herrenschmidt typedef struct PnvMachineState {
1489e933f4aSBenjamin Herrenschmidt     /*< private >*/
1499e933f4aSBenjamin Herrenschmidt     MachineState parent_obj;
1509e933f4aSBenjamin Herrenschmidt 
1519e933f4aSBenjamin Herrenschmidt     uint32_t     initrd_base;
1529e933f4aSBenjamin Herrenschmidt     long         initrd_size;
153e997040eSCédric Le Goater 
154e997040eSCédric Le Goater     uint32_t     num_chips;
155e997040eSCédric Le Goater     PnvChip      **chips;
1563495b6b6SCédric Le Goater 
1573495b6b6SCédric Le Goater     ISABus       *isa_bus;
15854f59d78SCédric Le Goater     uint32_t     cpld_irqstate;
159aeaef83dSCédric Le Goater 
160aeaef83dSCédric Le Goater     IPMIBmc      *bmc;
161bce0b691SCédric Le Goater     Notifier     powerdown_notifier;
1629e933f4aSBenjamin Herrenschmidt } PnvMachineState;
1639e933f4aSBenjamin Herrenschmidt 
164b3b066e9SCédric Le Goater static inline bool pnv_chip_is_power9(const PnvChip *chip)
165b3b066e9SCédric Le Goater {
166b3b066e9SCédric Le Goater     return PNV_CHIP_GET_CLASS(chip)->chip_type == PNV_CHIP_POWER9;
167b3b066e9SCédric Le Goater }
168b3b066e9SCédric Le Goater 
169b3b066e9SCédric Le Goater static inline bool pnv_is_power9(PnvMachineState *pnv)
170b3b066e9SCédric Le Goater {
171b3b066e9SCédric Le Goater     return pnv_chip_is_power9(pnv->chips[0]);
172b3b066e9SCédric Le Goater }
173b3b066e9SCédric Le Goater 
1749e933f4aSBenjamin Herrenschmidt #define PNV_FDT_ADDR          0x01000000
175d2fd9612SCédric Le Goater #define PNV_TIMEBASE_FREQ     512000000ULL
1769e933f4aSBenjamin Herrenschmidt 
177967b7523SCédric Le Goater /*
178aeaef83dSCédric Le Goater  * BMC helpers
179aeaef83dSCédric Le Goater  */
180b168a138SCédric Le Goater void pnv_dt_bmc_sensors(IPMIBmc *bmc, void *fdt);
181bce0b691SCédric Le Goater void pnv_bmc_powerdown(IPMIBmc *bmc);
182aeaef83dSCédric Le Goater 
183aeaef83dSCédric Le Goater /*
184967b7523SCédric Le Goater  * POWER8 MMIO base addresses
185967b7523SCédric Le Goater  */
186967b7523SCédric Le Goater #define PNV_XSCOM_SIZE        0x800000000ull
187967b7523SCédric Le Goater #define PNV_XSCOM_BASE(chip)                                            \
188967b7523SCédric Le Goater     (chip->xscom_base + ((uint64_t)(chip)->chip_id) * PNV_XSCOM_SIZE)
189967b7523SCédric Le Goater 
190bf5615e7SCédric Le Goater /*
191bf5615e7SCédric Le Goater  * XSCOM 0x20109CA defines the ICP BAR:
192bf5615e7SCédric Le Goater  *
193bf5615e7SCédric Le Goater  * 0:29   : bits 14 to 43 of address to define 1 MB region.
194bf5615e7SCédric Le Goater  * 30     : 1 to enable ICP to receive loads/stores against its BAR region
195bf5615e7SCédric Le Goater  * 31:63  : Constant 0
196bf5615e7SCédric Le Goater  *
197bf5615e7SCédric Le Goater  * Usually defined as :
198bf5615e7SCédric Le Goater  *
199bf5615e7SCédric Le Goater  *      0xffffe00200000000 -> 0x0003ffff80000000
200bf5615e7SCédric Le Goater  *      0xffffe00600000000 -> 0x0003ffff80100000
201bf5615e7SCédric Le Goater  *      0xffffe02200000000 -> 0x0003ffff80800000
202bf5615e7SCédric Le Goater  *      0xffffe02600000000 -> 0x0003ffff80900000
203bf5615e7SCédric Le Goater  */
204bf5615e7SCédric Le Goater #define PNV_ICP_SIZE         0x0000000000100000ull
205bf5615e7SCédric Le Goater #define PNV_ICP_BASE(chip)                                              \
206bf5615e7SCédric Le Goater     (0x0003ffff80000000ull + (uint64_t) PNV_CHIP_INDEX(chip) * PNV_ICP_SIZE)
207bf5615e7SCédric Le Goater 
20854f59d78SCédric Le Goater 
20954f59d78SCédric Le Goater #define PNV_PSIHB_SIZE       0x0000000000100000ull
21054f59d78SCédric Le Goater #define PNV_PSIHB_BASE(chip) \
21154f59d78SCédric Le Goater     (0x0003fffe80000000ull + (uint64_t)PNV_CHIP_INDEX(chip) * PNV_PSIHB_SIZE)
21254f59d78SCédric Le Goater 
21354f59d78SCédric Le Goater #define PNV_PSIHB_FSP_SIZE   0x0000000100000000ull
21454f59d78SCédric Le Goater #define PNV_PSIHB_FSP_BASE(chip) \
21554f59d78SCédric Le Goater     (0x0003ffe000000000ull + (uint64_t)PNV_CHIP_INDEX(chip) * \
21654f59d78SCédric Le Goater      PNV_PSIHB_FSP_SIZE)
21754f59d78SCédric Le Goater 
2189e933f4aSBenjamin Herrenschmidt #endif /* _PPC_PNV_H */
219