1*1adf2470SChalapathi V /*
2*1adf2470SChalapathi V * QEMU PowerPC nest pervasive common chiplet model
3*1adf2470SChalapathi V *
4*1adf2470SChalapathi V * Copyright (c) 2023, IBM Corporation.
5*1adf2470SChalapathi V *
6*1adf2470SChalapathi V * SPDX-License-Identifier: GPL-2.0-or-later
7*1adf2470SChalapathi V */
8*1adf2470SChalapathi V
9*1adf2470SChalapathi V #include "qemu/osdep.h"
10*1adf2470SChalapathi V #include "qemu/log.h"
11*1adf2470SChalapathi V #include "hw/qdev-properties.h"
12*1adf2470SChalapathi V #include "hw/ppc/pnv.h"
13*1adf2470SChalapathi V #include "hw/ppc/pnv_xscom.h"
14*1adf2470SChalapathi V #include "hw/ppc/pnv_nest_pervasive.h"
15*1adf2470SChalapathi V
16*1adf2470SChalapathi V /*
17*1adf2470SChalapathi V * Status, configuration, and control units in POWER chips is provided
18*1adf2470SChalapathi V * by the pervasive subsystem, which connects registers to the SCOM bus,
19*1adf2470SChalapathi V * which can be programmed by processor cores, other units on the chip,
20*1adf2470SChalapathi V * BMCs, or other POWER chips.
21*1adf2470SChalapathi V *
22*1adf2470SChalapathi V * A POWER10 chip is divided into logical units called chiplets. Chiplets
23*1adf2470SChalapathi V * are broadly divided into "core chiplets" (with the processor cores) and
24*1adf2470SChalapathi V * "nest chiplets" (with everything else). Each chiplet has an attachment
25*1adf2470SChalapathi V * to the pervasive bus (PIB) and with chiplet-specific registers.
26*1adf2470SChalapathi V * All nest chiplets have a common basic set of registers.
27*1adf2470SChalapathi V *
28*1adf2470SChalapathi V * This model will provide the registers functionality for common registers of
29*1adf2470SChalapathi V * nest unit (PB Chiplet, PCI Chiplets, MC Chiplet, PAU Chiplets)
30*1adf2470SChalapathi V *
31*1adf2470SChalapathi V * Currently this model provide the read/write functionality of chiplet control
32*1adf2470SChalapathi V * scom registers.
33*1adf2470SChalapathi V */
34*1adf2470SChalapathi V
35*1adf2470SChalapathi V #define CPLT_CONF0 0x08
36*1adf2470SChalapathi V #define CPLT_CONF0_OR 0x18
37*1adf2470SChalapathi V #define CPLT_CONF0_CLEAR 0x28
38*1adf2470SChalapathi V #define CPLT_CONF1 0x09
39*1adf2470SChalapathi V #define CPLT_CONF1_OR 0x19
40*1adf2470SChalapathi V #define CPLT_CONF1_CLEAR 0x29
41*1adf2470SChalapathi V #define CPLT_STAT0 0x100
42*1adf2470SChalapathi V #define CPLT_MASK0 0x101
43*1adf2470SChalapathi V #define CPLT_PROTECT_MODE 0x3FE
44*1adf2470SChalapathi V #define CPLT_ATOMIC_CLOCK 0x3FF
45*1adf2470SChalapathi V
pnv_chiplet_ctrl_read(void * opaque,hwaddr addr,unsigned size)46*1adf2470SChalapathi V static uint64_t pnv_chiplet_ctrl_read(void *opaque, hwaddr addr, unsigned size)
47*1adf2470SChalapathi V {
48*1adf2470SChalapathi V PnvNestChipletPervasive *nest_pervasive = PNV_NEST_CHIPLET_PERVASIVE(
49*1adf2470SChalapathi V opaque);
50*1adf2470SChalapathi V uint32_t reg = addr >> 3;
51*1adf2470SChalapathi V uint64_t val = ~0ull;
52*1adf2470SChalapathi V
53*1adf2470SChalapathi V /* CPLT_CTRL0 to CPLT_CTRL5 */
54*1adf2470SChalapathi V for (int i = 0; i < PNV_CPLT_CTRL_SIZE; i++) {
55*1adf2470SChalapathi V if (reg == i) {
56*1adf2470SChalapathi V return nest_pervasive->control_regs.cplt_ctrl[i];
57*1adf2470SChalapathi V } else if ((reg == (i + 0x10)) || (reg == (i + 0x20))) {
58*1adf2470SChalapathi V qemu_log_mask(LOG_GUEST_ERROR, "%s: Write only register, ignoring "
59*1adf2470SChalapathi V "xscom read at 0x%" PRIx32 "\n",
60*1adf2470SChalapathi V __func__, reg);
61*1adf2470SChalapathi V return val;
62*1adf2470SChalapathi V }
63*1adf2470SChalapathi V }
64*1adf2470SChalapathi V
65*1adf2470SChalapathi V switch (reg) {
66*1adf2470SChalapathi V case CPLT_CONF0:
67*1adf2470SChalapathi V val = nest_pervasive->control_regs.cplt_cfg0;
68*1adf2470SChalapathi V break;
69*1adf2470SChalapathi V case CPLT_CONF0_OR:
70*1adf2470SChalapathi V case CPLT_CONF0_CLEAR:
71*1adf2470SChalapathi V qemu_log_mask(LOG_GUEST_ERROR, "%s: Write only register, ignoring "
72*1adf2470SChalapathi V "xscom read at 0x%" PRIx32 "\n",
73*1adf2470SChalapathi V __func__, reg);
74*1adf2470SChalapathi V break;
75*1adf2470SChalapathi V case CPLT_CONF1:
76*1adf2470SChalapathi V val = nest_pervasive->control_regs.cplt_cfg1;
77*1adf2470SChalapathi V break;
78*1adf2470SChalapathi V case CPLT_CONF1_OR:
79*1adf2470SChalapathi V case CPLT_CONF1_CLEAR:
80*1adf2470SChalapathi V qemu_log_mask(LOG_GUEST_ERROR, "%s: Write only register, ignoring "
81*1adf2470SChalapathi V "xscom read at 0x%" PRIx32 "\n",
82*1adf2470SChalapathi V __func__, reg);
83*1adf2470SChalapathi V break;
84*1adf2470SChalapathi V case CPLT_STAT0:
85*1adf2470SChalapathi V val = nest_pervasive->control_regs.cplt_stat0;
86*1adf2470SChalapathi V break;
87*1adf2470SChalapathi V case CPLT_MASK0:
88*1adf2470SChalapathi V val = nest_pervasive->control_regs.cplt_mask0;
89*1adf2470SChalapathi V break;
90*1adf2470SChalapathi V case CPLT_PROTECT_MODE:
91*1adf2470SChalapathi V val = nest_pervasive->control_regs.ctrl_protect_mode;
92*1adf2470SChalapathi V break;
93*1adf2470SChalapathi V case CPLT_ATOMIC_CLOCK:
94*1adf2470SChalapathi V val = nest_pervasive->control_regs.ctrl_atomic_lock;
95*1adf2470SChalapathi V break;
96*1adf2470SChalapathi V default:
97*1adf2470SChalapathi V qemu_log_mask(LOG_UNIMP, "%s: Chiplet_control_regs: Invalid xscom "
98*1adf2470SChalapathi V "read at 0x%" PRIx32 "\n", __func__, reg);
99*1adf2470SChalapathi V }
100*1adf2470SChalapathi V return val;
101*1adf2470SChalapathi V }
102*1adf2470SChalapathi V
pnv_chiplet_ctrl_write(void * opaque,hwaddr addr,uint64_t val,unsigned size)103*1adf2470SChalapathi V static void pnv_chiplet_ctrl_write(void *opaque, hwaddr addr,
104*1adf2470SChalapathi V uint64_t val, unsigned size)
105*1adf2470SChalapathi V {
106*1adf2470SChalapathi V PnvNestChipletPervasive *nest_pervasive = PNV_NEST_CHIPLET_PERVASIVE(
107*1adf2470SChalapathi V opaque);
108*1adf2470SChalapathi V uint32_t reg = addr >> 3;
109*1adf2470SChalapathi V
110*1adf2470SChalapathi V /* CPLT_CTRL0 to CPLT_CTRL5 */
111*1adf2470SChalapathi V for (int i = 0; i < PNV_CPLT_CTRL_SIZE; i++) {
112*1adf2470SChalapathi V if (reg == i) {
113*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_ctrl[i] = val;
114*1adf2470SChalapathi V return;
115*1adf2470SChalapathi V } else if (reg == (i + 0x10)) {
116*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_ctrl[i] |= val;
117*1adf2470SChalapathi V return;
118*1adf2470SChalapathi V } else if (reg == (i + 0x20)) {
119*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_ctrl[i] &= ~val;
120*1adf2470SChalapathi V return;
121*1adf2470SChalapathi V }
122*1adf2470SChalapathi V }
123*1adf2470SChalapathi V
124*1adf2470SChalapathi V switch (reg) {
125*1adf2470SChalapathi V case CPLT_CONF0:
126*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_cfg0 = val;
127*1adf2470SChalapathi V break;
128*1adf2470SChalapathi V case CPLT_CONF0_OR:
129*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_cfg0 |= val;
130*1adf2470SChalapathi V break;
131*1adf2470SChalapathi V case CPLT_CONF0_CLEAR:
132*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_cfg0 &= ~val;
133*1adf2470SChalapathi V break;
134*1adf2470SChalapathi V case CPLT_CONF1:
135*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_cfg1 = val;
136*1adf2470SChalapathi V break;
137*1adf2470SChalapathi V case CPLT_CONF1_OR:
138*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_cfg1 |= val;
139*1adf2470SChalapathi V break;
140*1adf2470SChalapathi V case CPLT_CONF1_CLEAR:
141*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_cfg1 &= ~val;
142*1adf2470SChalapathi V break;
143*1adf2470SChalapathi V case CPLT_STAT0:
144*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_stat0 = val;
145*1adf2470SChalapathi V break;
146*1adf2470SChalapathi V case CPLT_MASK0:
147*1adf2470SChalapathi V nest_pervasive->control_regs.cplt_mask0 = val;
148*1adf2470SChalapathi V break;
149*1adf2470SChalapathi V case CPLT_PROTECT_MODE:
150*1adf2470SChalapathi V nest_pervasive->control_regs.ctrl_protect_mode = val;
151*1adf2470SChalapathi V break;
152*1adf2470SChalapathi V case CPLT_ATOMIC_CLOCK:
153*1adf2470SChalapathi V nest_pervasive->control_regs.ctrl_atomic_lock = val;
154*1adf2470SChalapathi V break;
155*1adf2470SChalapathi V default:
156*1adf2470SChalapathi V qemu_log_mask(LOG_UNIMP, "%s: Chiplet_control_regs: Invalid xscom "
157*1adf2470SChalapathi V "write at 0x%" PRIx32 "\n",
158*1adf2470SChalapathi V __func__, reg);
159*1adf2470SChalapathi V }
160*1adf2470SChalapathi V }
161*1adf2470SChalapathi V
162*1adf2470SChalapathi V static const MemoryRegionOps pnv_nest_pervasive_control_xscom_ops = {
163*1adf2470SChalapathi V .read = pnv_chiplet_ctrl_read,
164*1adf2470SChalapathi V .write = pnv_chiplet_ctrl_write,
165*1adf2470SChalapathi V .valid.min_access_size = 8,
166*1adf2470SChalapathi V .valid.max_access_size = 8,
167*1adf2470SChalapathi V .impl.min_access_size = 8,
168*1adf2470SChalapathi V .impl.max_access_size = 8,
169*1adf2470SChalapathi V .endianness = DEVICE_BIG_ENDIAN,
170*1adf2470SChalapathi V };
171*1adf2470SChalapathi V
pnv_nest_pervasive_realize(DeviceState * dev,Error ** errp)172*1adf2470SChalapathi V static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp)
173*1adf2470SChalapathi V {
174*1adf2470SChalapathi V PnvNestChipletPervasive *nest_pervasive = PNV_NEST_CHIPLET_PERVASIVE(dev);
175*1adf2470SChalapathi V
176*1adf2470SChalapathi V /* Chiplet control scoms */
177*1adf2470SChalapathi V pnv_xscom_region_init(&nest_pervasive->xscom_ctrl_regs_mr,
178*1adf2470SChalapathi V OBJECT(nest_pervasive),
179*1adf2470SChalapathi V &pnv_nest_pervasive_control_xscom_ops,
180*1adf2470SChalapathi V nest_pervasive, "pervasive-control",
181*1adf2470SChalapathi V PNV10_XSCOM_CHIPLET_CTRL_REGS_SIZE);
182*1adf2470SChalapathi V }
183*1adf2470SChalapathi V
pnv_nest_pervasive_class_init(ObjectClass * klass,void * data)184*1adf2470SChalapathi V static void pnv_nest_pervasive_class_init(ObjectClass *klass, void *data)
185*1adf2470SChalapathi V {
186*1adf2470SChalapathi V DeviceClass *dc = DEVICE_CLASS(klass);
187*1adf2470SChalapathi V
188*1adf2470SChalapathi V dc->desc = "PowerNV nest pervasive chiplet";
189*1adf2470SChalapathi V dc->realize = pnv_nest_pervasive_realize;
190*1adf2470SChalapathi V }
191*1adf2470SChalapathi V
192*1adf2470SChalapathi V static const TypeInfo pnv_nest_pervasive_info = {
193*1adf2470SChalapathi V .name = TYPE_PNV_NEST_CHIPLET_PERVASIVE,
194*1adf2470SChalapathi V .parent = TYPE_DEVICE,
195*1adf2470SChalapathi V .instance_size = sizeof(PnvNestChipletPervasive),
196*1adf2470SChalapathi V .class_init = pnv_nest_pervasive_class_init,
197*1adf2470SChalapathi V .interfaces = (InterfaceInfo[]) {
198*1adf2470SChalapathi V { TYPE_PNV_XSCOM_INTERFACE },
199*1adf2470SChalapathi V { }
200*1adf2470SChalapathi V }
201*1adf2470SChalapathi V };
202*1adf2470SChalapathi V
pnv_nest_pervasive_register_types(void)203*1adf2470SChalapathi V static void pnv_nest_pervasive_register_types(void)
204*1adf2470SChalapathi V {
205*1adf2470SChalapathi V type_register_static(&pnv_nest_pervasive_info);
206*1adf2470SChalapathi V }
207*1adf2470SChalapathi V
208*1adf2470SChalapathi V type_init(pnv_nest_pervasive_register_types);
209