]> Git Repo - qemu.git/blame - hw/ppc/pnv_core.c
works with less than base ISA qemu-system-riscv32 -M virt -bios none -kernel output...
[qemu.git] / hw / ppc / pnv_core.c
CommitLineData
d2fd9612
CLG
1/*
2 * QEMU PowerPC PowerNV CPU Core model
3 *
4 * Copyright (c) 2016, IBM Corporation.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
f70c5966 8 * as published by the Free Software Foundation; either version 2.1 of
d2fd9612
CLG
9 * the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
0b8fa32f 19
d2fd9612 20#include "qemu/osdep.h"
71e8a915 21#include "sysemu/reset.h"
d2fd9612 22#include "qapi/error.h"
24ece072 23#include "qemu/log.h"
0b8fa32f 24#include "qemu/module.h"
fcf5ef2a 25#include "target/ppc/cpu.h"
d2fd9612
CLG
26#include "hw/ppc/ppc.h"
27#include "hw/ppc/pnv.h"
28#include "hw/ppc/pnv_core.h"
ec575aa0 29#include "hw/ppc/pnv_xscom.h"
960fbd29 30#include "hw/ppc/xics.h"
a27bd6c7 31#include "hw/qdev-properties.h"
bd4160bc 32#include "helper_regs.h"
d2fd9612 33
35bdb9de
IM
34static const char *pnv_core_cpu_typename(PnvCore *pc)
35{
36 const char *core_type = object_class_get_name(object_get_class(OBJECT(pc)));
37 int len = strlen(core_type) - strlen(PNV_CORE_TYPE_SUFFIX);
38 char *s = g_strdup_printf(POWERPC_CPU_TYPE_NAME("%.*s"), len, core_type);
39 const char *cpu_type = object_class_get_name(object_class_by_name(s));
40 g_free(s);
41 return cpu_type;
42}
43
59942f0e 44static void pnv_core_cpu_reset(PnvCore *pc, PowerPCCPU *cpu)
d2fd9612 45{
d2fd9612
CLG
46 CPUState *cs = CPU(cpu);
47 CPUPPCState *env = &cpu->env;
59942f0e 48 PnvChipClass *pcc = PNV_CHIP_GET_CLASS(pc->chip);
d2fd9612
CLG
49
50 cpu_reset(cs);
51
52 /*
53 * the skiboot firmware elects a primary thread to initialize the
54 * system and it can be any.
55 */
56 env->gpr[3] = PNV_FDT_ADDR;
57 env->nip = 0x10;
58 env->msr |= MSR_HVB; /* Hypervisor mode */
08c3f3a7 59 env->spr[SPR_HRMOR] = pc->hrmor;
bd4160bc 60 hreg_compute_hflags(env);
2fdedcbc 61 ppc_maybe_interrupt(env);
08c3f3a7 62
59942f0e 63 pcc->intc_reset(pc->chip, cpu);
d2fd9612
CLG
64}
65
24ece072
CLG
66/*
67 * These values are read by the PowerNV HW monitors under Linux
68 */
69#define PNV_XSCOM_EX_DTS_RESULT0 0x50000
70#define PNV_XSCOM_EX_DTS_RESULT1 0x50001
71
90ef386c
CLG
72static uint64_t pnv_core_power8_xscom_read(void *opaque, hwaddr addr,
73 unsigned int width)
24ece072
CLG
74{
75 uint32_t offset = addr >> 3;
76 uint64_t val = 0;
77
78 /* The result should be 38 C */
79 switch (offset) {
80 case PNV_XSCOM_EX_DTS_RESULT0:
81 val = 0x26f024f023f0000ull;
82 break;
83 case PNV_XSCOM_EX_DTS_RESULT1:
84 val = 0x24f000000000000ull;
85 break;
86 default:
c7e71a18 87 qemu_log_mask(LOG_UNIMP, "Warning: reading reg=0x%" HWADDR_PRIx "\n",
24ece072
CLG
88 addr);
89 }
90
91 return val;
92}
93
90ef386c
CLG
94static void pnv_core_power8_xscom_write(void *opaque, hwaddr addr, uint64_t val,
95 unsigned int width)
24ece072 96{
c7e71a18 97 qemu_log_mask(LOG_UNIMP, "Warning: writing to reg=0x%" HWADDR_PRIx "\n",
24ece072
CLG
98 addr);
99}
100
90ef386c
CLG
101static const MemoryRegionOps pnv_core_power8_xscom_ops = {
102 .read = pnv_core_power8_xscom_read,
103 .write = pnv_core_power8_xscom_write,
104 .valid.min_access_size = 8,
105 .valid.max_access_size = 8,
106 .impl.min_access_size = 8,
107 .impl.max_access_size = 8,
108 .endianness = DEVICE_BIG_ENDIAN,
109};
110
111
112/*
113 * POWER9 core controls
114 */
115#define PNV9_XSCOM_EC_PPM_SPECIAL_WKUP_HYP 0xf010d
116#define PNV9_XSCOM_EC_PPM_SPECIAL_WKUP_OTR 0xf010a
117
118static uint64_t pnv_core_power9_xscom_read(void *opaque, hwaddr addr,
119 unsigned int width)
120{
121 uint32_t offset = addr >> 3;
122 uint64_t val = 0;
123
124 /* The result should be 38 C */
125 switch (offset) {
126 case PNV_XSCOM_EX_DTS_RESULT0:
127 val = 0x26f024f023f0000ull;
128 break;
129 case PNV_XSCOM_EX_DTS_RESULT1:
130 val = 0x24f000000000000ull;
131 break;
132 case PNV9_XSCOM_EC_PPM_SPECIAL_WKUP_HYP:
133 case PNV9_XSCOM_EC_PPM_SPECIAL_WKUP_OTR:
134 val = 0x0;
135 break;
136 default:
137 qemu_log_mask(LOG_UNIMP, "Warning: reading reg=0x%" HWADDR_PRIx "\n",
138 addr);
139 }
140
141 return val;
142}
143
144static void pnv_core_power9_xscom_write(void *opaque, hwaddr addr, uint64_t val,
145 unsigned int width)
146{
147 uint32_t offset = addr >> 3;
148
149 switch (offset) {
150 case PNV9_XSCOM_EC_PPM_SPECIAL_WKUP_HYP:
151 case PNV9_XSCOM_EC_PPM_SPECIAL_WKUP_OTR:
152 break;
153 default:
154 qemu_log_mask(LOG_UNIMP, "Warning: writing to reg=0x%" HWADDR_PRIx "\n",
155 addr);
156 }
157}
158
159static const MemoryRegionOps pnv_core_power9_xscom_ops = {
160 .read = pnv_core_power9_xscom_read,
161 .write = pnv_core_power9_xscom_write,
24ece072
CLG
162 .valid.min_access_size = 8,
163 .valid.max_access_size = 8,
164 .impl.min_access_size = 8,
165 .impl.max_access_size = 8,
166 .endianness = DEVICE_BIG_ENDIAN,
167};
168
59942f0e 169static void pnv_core_cpu_realize(PnvCore *pc, PowerPCCPU *cpu, Error **errp)
d2fd9612 170{
3a247521
DG
171 CPUPPCState *env = &cpu->env;
172 int core_pir;
173 int thread_index = 0; /* TODO: TCG supports only one thread */
174 ppc_spr_t *pir = &env->spr_cb[SPR_PIR];
d2fd9612 175 Error *local_err = NULL;
59942f0e 176 PnvChipClass *pcc = PNV_CHIP_GET_CLASS(pc->chip);
960fbd29 177
668f62ec 178 if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
960fbd29
CLG
179 return;
180 }
d2fd9612 181
59942f0e 182 pcc->intc_create(pc->chip, cpu, &local_err);
d2fd9612
CLG
183 if (local_err) {
184 error_propagate(errp, local_err);
185 return;
186 }
187
59942f0e 188 core_pir = object_property_get_uint(OBJECT(pc), "pir", &error_abort);
3a247521
DG
189
190 /*
191 * The PIR of a thread is the core PIR + the thread index. We will
192 * need to find a way to get the thread index when TCG supports
193 * more than 1. We could use the object name ?
194 */
195 pir->default_value = core_pir + thread_index;
196
197 /* Set time-base frequency to 512 MHz */
198 cpu_ppc_tb_init(env, PNV_TIMEBASE_FREQ);
fa06541b
CLG
199}
200
201static void pnv_core_reset(void *dev)
202{
203 CPUCore *cc = CPU_CORE(dev);
204 PnvCore *pc = PNV_CORE(dev);
205 int i;
3a247521 206
fa06541b 207 for (i = 0; i < cc->nr_threads; i++) {
59942f0e 208 pnv_core_cpu_reset(pc, pc->threads[i]);
fa06541b 209 }
d2fd9612
CLG
210}
211
212static void pnv_core_realize(DeviceState *dev, Error **errp)
213{
214 PnvCore *pc = PNV_CORE(OBJECT(dev));
90ef386c 215 PnvCoreClass *pcc = PNV_CORE_GET_CLASS(pc);
d2fd9612 216 CPUCore *cc = CPU_CORE(OBJECT(dev));
35bdb9de 217 const char *typename = pnv_core_cpu_typename(pc);
d2fd9612
CLG
218 Error *local_err = NULL;
219 void *obj;
220 int i, j;
221 char name[32];
960fbd29 222
158e17a6 223 assert(pc->chip);
d2fd9612 224
08304a86 225 pc->threads = g_new(PowerPCCPU *, cc->nr_threads);
d2fd9612 226 for (i = 0; i < cc->nr_threads; i++) {
8907fc25
CLG
227 PowerPCCPU *cpu;
228
08304a86 229 obj = object_new(typename);
8907fc25 230 cpu = POWERPC_CPU(obj);
d2fd9612 231
08304a86 232 pc->threads[i] = POWERPC_CPU(obj);
d2fd9612
CLG
233
234 snprintf(name, sizeof(name), "thread[%d]", i);
d2623129 235 object_property_add_child(OBJECT(pc), name, obj);
8907fc25
CLG
236
237 cpu->machine_data = g_new0(PnvCPUState, 1);
238
d2fd9612
CLG
239 object_unref(obj);
240 }
241
242 for (j = 0; j < cc->nr_threads; j++) {
59942f0e 243 pnv_core_cpu_realize(pc, pc->threads[j], &local_err);
d2fd9612
CLG
244 if (local_err) {
245 goto err;
246 }
247 }
24ece072
CLG
248
249 snprintf(name, sizeof(name), "xscom-core.%d", cc->core_id);
2b548a42 250 /* TODO: check PNV_XSCOM_EX_SIZE for p10 */
90ef386c 251 pnv_xscom_region_init(&pc->xscom_regs, OBJECT(dev), pcc->xscom_ops,
c035851a 252 pc, name, PNV_XSCOM_EX_SIZE);
fa06541b
CLG
253
254 qemu_register_reset(pnv_core_reset, pc);
d2fd9612
CLG
255 return;
256
257err:
258 while (--i >= 0) {
08304a86 259 obj = OBJECT(pc->threads[i]);
d2fd9612
CLG
260 object_unparent(obj);
261 }
262 g_free(pc->threads);
263 error_propagate(errp, local_err);
264}
265
59942f0e 266static void pnv_core_cpu_unrealize(PnvCore *pc, PowerPCCPU *cpu)
5e22e292 267{
8907fc25 268 PnvCPUState *pnv_cpu = pnv_cpu_state(cpu);
59942f0e 269 PnvChipClass *pcc = PNV_CHIP_GET_CLASS(pc->chip);
8907fc25 270
59942f0e 271 pcc->intc_destroy(pc->chip, cpu);
5e22e292 272 cpu_remove_sync(CPU(cpu));
8907fc25
CLG
273 cpu->machine_data = NULL;
274 g_free(pnv_cpu);
5e22e292
DG
275 object_unparent(OBJECT(cpu));
276}
277
b69c3c21 278static void pnv_core_unrealize(DeviceState *dev)
5e22e292
DG
279{
280 PnvCore *pc = PNV_CORE(dev);
281 CPUCore *cc = CPU_CORE(dev);
282 int i;
283
fa06541b
CLG
284 qemu_unregister_reset(pnv_core_reset, pc);
285
5e22e292 286 for (i = 0; i < cc->nr_threads; i++) {
59942f0e 287 pnv_core_cpu_unrealize(pc, pc->threads[i]);
5e22e292
DG
288 }
289 g_free(pc->threads);
290}
291
d2fd9612
CLG
292static Property pnv_core_properties[] = {
293 DEFINE_PROP_UINT32("pir", PnvCore, pir, 0),
08c3f3a7 294 DEFINE_PROP_UINT64("hrmor", PnvCore, hrmor, 0),
158e17a6 295 DEFINE_PROP_LINK("chip", PnvCore, chip, TYPE_PNV_CHIP, PnvChip *),
d2fd9612
CLG
296 DEFINE_PROP_END_OF_LIST(),
297};
298
90ef386c
CLG
299static void pnv_core_power8_class_init(ObjectClass *oc, void *data)
300{
301 PnvCoreClass *pcc = PNV_CORE_CLASS(oc);
302
303 pcc->xscom_ops = &pnv_core_power8_xscom_ops;
304}
305
306static void pnv_core_power9_class_init(ObjectClass *oc, void *data)
307{
308 PnvCoreClass *pcc = PNV_CORE_CLASS(oc);
309
310 pcc->xscom_ops = &pnv_core_power9_xscom_ops;
311}
312
2b548a42
CLG
313static void pnv_core_power10_class_init(ObjectClass *oc, void *data)
314{
315 PnvCoreClass *pcc = PNV_CORE_CLASS(oc);
316
317 /* TODO: Use the P9 XSCOMs for now on P10 */
318 pcc->xscom_ops = &pnv_core_power9_xscom_ops;
319}
320
d2fd9612
CLG
321static void pnv_core_class_init(ObjectClass *oc, void *data)
322{
323 DeviceClass *dc = DEVICE_CLASS(oc);
d2fd9612
CLG
324
325 dc->realize = pnv_core_realize;
5e22e292 326 dc->unrealize = pnv_core_unrealize;
4f67d30b 327 device_class_set_props(dc, pnv_core_properties);
23a782eb 328 dc->user_creatable = false;
d2fd9612
CLG
329}
330
90ef386c 331#define DEFINE_PNV_CORE_TYPE(family, cpu_model) \
7383af1e
IM
332 { \
333 .parent = TYPE_PNV_CORE, \
334 .name = PNV_CORE_TYPE_NAME(cpu_model), \
90ef386c 335 .class_init = pnv_core_##family##_class_init, \
d2fd9612 336 }
d2fd9612 337
7383af1e
IM
338static const TypeInfo pnv_core_infos[] = {
339 {
340 .name = TYPE_PNV_CORE,
341 .parent = TYPE_CPU_CORE,
342 .instance_size = sizeof(PnvCore),
343 .class_size = sizeof(PnvCoreClass),
344 .class_init = pnv_core_class_init,
345 .abstract = true,
346 },
90ef386c
CLG
347 DEFINE_PNV_CORE_TYPE(power8, "power8e_v2.1"),
348 DEFINE_PNV_CORE_TYPE(power8, "power8_v2.0"),
349 DEFINE_PNV_CORE_TYPE(power8, "power8nvl_v1.0"),
350 DEFINE_PNV_CORE_TYPE(power9, "power9_v2.0"),
6bc8c046 351 DEFINE_PNV_CORE_TYPE(power10, "power10_v2.0"),
7383af1e 352};
d2fd9612 353
7383af1e 354DEFINE_TYPES(pnv_core_infos)
5dad902c
CLG
355
356/*
357 * POWER9 Quads
358 */
359
360#define P9X_EX_NCU_SPEC_BAR 0x11010
361
362static uint64_t pnv_quad_xscom_read(void *opaque, hwaddr addr,
363 unsigned int width)
364{
365 uint32_t offset = addr >> 3;
366 uint64_t val = -1;
367
368 switch (offset) {
369 case P9X_EX_NCU_SPEC_BAR:
370 case P9X_EX_NCU_SPEC_BAR + 0x400: /* Second EX */
371 val = 0;
372 break;
373 default:
374 qemu_log_mask(LOG_UNIMP, "%s: writing @0x%08x\n", __func__,
375 offset);
376 }
377
378 return val;
379}
380
381static void pnv_quad_xscom_write(void *opaque, hwaddr addr, uint64_t val,
382 unsigned int width)
383{
384 uint32_t offset = addr >> 3;
385
386 switch (offset) {
387 case P9X_EX_NCU_SPEC_BAR:
388 case P9X_EX_NCU_SPEC_BAR + 0x400: /* Second EX */
389 break;
390 default:
391 qemu_log_mask(LOG_UNIMP, "%s: writing @0x%08x\n", __func__,
392 offset);
393 }
394}
395
396static const MemoryRegionOps pnv_quad_xscom_ops = {
397 .read = pnv_quad_xscom_read,
398 .write = pnv_quad_xscom_write,
399 .valid.min_access_size = 8,
400 .valid.max_access_size = 8,
401 .impl.min_access_size = 8,
402 .impl.max_access_size = 8,
403 .endianness = DEVICE_BIG_ENDIAN,
404};
405
406static void pnv_quad_realize(DeviceState *dev, Error **errp)
407{
408 PnvQuad *eq = PNV_QUAD(dev);
409 char name[32];
410
92612f15 411 snprintf(name, sizeof(name), "xscom-quad.%d", eq->quad_id);
5dad902c
CLG
412 pnv_xscom_region_init(&eq->xscom_regs, OBJECT(dev), &pnv_quad_xscom_ops,
413 eq, name, PNV9_XSCOM_EQ_SIZE);
414}
415
416static Property pnv_quad_properties[] = {
92612f15 417 DEFINE_PROP_UINT32("quad-id", PnvQuad, quad_id, 0),
5dad902c
CLG
418 DEFINE_PROP_END_OF_LIST(),
419};
420
421static void pnv_quad_class_init(ObjectClass *oc, void *data)
422{
423 DeviceClass *dc = DEVICE_CLASS(oc);
424
425 dc->realize = pnv_quad_realize;
4f67d30b 426 device_class_set_props(dc, pnv_quad_properties);
23a782eb 427 dc->user_creatable = false;
5dad902c
CLG
428}
429
430static const TypeInfo pnv_quad_info = {
431 .name = TYPE_PNV_QUAD,
432 .parent = TYPE_DEVICE,
433 .instance_size = sizeof(PnvQuad),
434 .class_init = pnv_quad_class_init,
435};
436
437static void pnv_core_register_types(void)
438{
439 type_register_static(&pnv_quad_info);
440}
441
442type_init(pnv_core_register_types)
This page took 0.362048 seconds and 5 git commands to generate.