xref: /openbmc/qemu/hw/ppc/pnv_n1_chiplet.c (revision 91e3bf2e925671eb37e3b71cf7fdeb6b7f30248c)
1*5706b006SChalapathi V /*
2*5706b006SChalapathi V  * QEMU PowerPC N1 chiplet model
3*5706b006SChalapathi V  *
4*5706b006SChalapathi V  * Copyright (c) 2023, IBM Corporation.
5*5706b006SChalapathi V  *
6*5706b006SChalapathi V  * SPDX-License-Identifier: GPL-2.0-or-later
7*5706b006SChalapathi V  */
8*5706b006SChalapathi V 
9*5706b006SChalapathi V #include "qemu/osdep.h"
10*5706b006SChalapathi V #include "qemu/log.h"
11*5706b006SChalapathi V #include "hw/qdev-properties.h"
12*5706b006SChalapathi V #include "hw/ppc/pnv.h"
13*5706b006SChalapathi V #include "hw/ppc/pnv_xscom.h"
14*5706b006SChalapathi V #include "hw/ppc/pnv_n1_chiplet.h"
15*5706b006SChalapathi V #include "hw/ppc/pnv_nest_pervasive.h"
16*5706b006SChalapathi V 
17*5706b006SChalapathi V /*
18*5706b006SChalapathi V  * The n1 chiplet contains chiplet control unit,
19*5706b006SChalapathi V  * PowerBus/RaceTrack/Bridge logic, nest Memory Management Unit(nMMU)
20*5706b006SChalapathi V  * and more.
21*5706b006SChalapathi V  *
22*5706b006SChalapathi V  * In this model Nest1 chiplet control registers are modelled via common
23*5706b006SChalapathi V  * nest pervasive model and few PowerBus racetrack registers are modelled.
24*5706b006SChalapathi V  */
25*5706b006SChalapathi V 
26*5706b006SChalapathi V #define PB_SCOM_EQ0_HP_MODE2_CURR      0xe
27*5706b006SChalapathi V #define PB_SCOM_ES3_MODE               0x8a
28*5706b006SChalapathi V 
pnv_n1_chiplet_pb_scom_eq_read(void * opaque,hwaddr addr,unsigned size)29*5706b006SChalapathi V static uint64_t pnv_n1_chiplet_pb_scom_eq_read(void *opaque, hwaddr addr,
30*5706b006SChalapathi V                                                   unsigned size)
31*5706b006SChalapathi V {
32*5706b006SChalapathi V     PnvN1Chiplet *n1_chiplet = PNV_N1_CHIPLET(opaque);
33*5706b006SChalapathi V     uint32_t reg = addr >> 3;
34*5706b006SChalapathi V     uint64_t val = ~0ull;
35*5706b006SChalapathi V 
36*5706b006SChalapathi V     switch (reg) {
37*5706b006SChalapathi V     case PB_SCOM_EQ0_HP_MODE2_CURR:
38*5706b006SChalapathi V         val = n1_chiplet->eq[0].hp_mode2_curr;
39*5706b006SChalapathi V         break;
40*5706b006SChalapathi V     default:
41*5706b006SChalapathi V         qemu_log_mask(LOG_UNIMP, "%s: Invalid xscom read at 0x%" PRIx32 "\n",
42*5706b006SChalapathi V                       __func__, reg);
43*5706b006SChalapathi V     }
44*5706b006SChalapathi V     return val;
45*5706b006SChalapathi V }
46*5706b006SChalapathi V 
pnv_n1_chiplet_pb_scom_eq_write(void * opaque,hwaddr addr,uint64_t val,unsigned size)47*5706b006SChalapathi V static void pnv_n1_chiplet_pb_scom_eq_write(void *opaque, hwaddr addr,
48*5706b006SChalapathi V                                                uint64_t val, unsigned size)
49*5706b006SChalapathi V {
50*5706b006SChalapathi V     PnvN1Chiplet *n1_chiplet = PNV_N1_CHIPLET(opaque);
51*5706b006SChalapathi V     uint32_t reg = addr >> 3;
52*5706b006SChalapathi V 
53*5706b006SChalapathi V     switch (reg) {
54*5706b006SChalapathi V     case PB_SCOM_EQ0_HP_MODE2_CURR:
55*5706b006SChalapathi V         n1_chiplet->eq[0].hp_mode2_curr = val;
56*5706b006SChalapathi V         break;
57*5706b006SChalapathi V     default:
58*5706b006SChalapathi V         qemu_log_mask(LOG_UNIMP, "%s: Invalid xscom write at 0x%" PRIx32 "\n",
59*5706b006SChalapathi V                       __func__, reg);
60*5706b006SChalapathi V     }
61*5706b006SChalapathi V }
62*5706b006SChalapathi V 
63*5706b006SChalapathi V static const MemoryRegionOps pnv_n1_chiplet_pb_scom_eq_ops = {
64*5706b006SChalapathi V     .read = pnv_n1_chiplet_pb_scom_eq_read,
65*5706b006SChalapathi V     .write = pnv_n1_chiplet_pb_scom_eq_write,
66*5706b006SChalapathi V     .valid.min_access_size = 8,
67*5706b006SChalapathi V     .valid.max_access_size = 8,
68*5706b006SChalapathi V     .impl.min_access_size = 8,
69*5706b006SChalapathi V     .impl.max_access_size = 8,
70*5706b006SChalapathi V     .endianness = DEVICE_BIG_ENDIAN,
71*5706b006SChalapathi V };
72*5706b006SChalapathi V 
pnv_n1_chiplet_pb_scom_es_read(void * opaque,hwaddr addr,unsigned size)73*5706b006SChalapathi V static uint64_t pnv_n1_chiplet_pb_scom_es_read(void *opaque, hwaddr addr,
74*5706b006SChalapathi V                                           unsigned size)
75*5706b006SChalapathi V {
76*5706b006SChalapathi V     PnvN1Chiplet *n1_chiplet = PNV_N1_CHIPLET(opaque);
77*5706b006SChalapathi V     uint32_t reg = addr >> 3;
78*5706b006SChalapathi V     uint64_t val = ~0ull;
79*5706b006SChalapathi V 
80*5706b006SChalapathi V     switch (reg) {
81*5706b006SChalapathi V     case PB_SCOM_ES3_MODE:
82*5706b006SChalapathi V         val = n1_chiplet->es[3].mode;
83*5706b006SChalapathi V         break;
84*5706b006SChalapathi V     default:
85*5706b006SChalapathi V         qemu_log_mask(LOG_UNIMP, "%s: Invalid xscom read at 0x%" PRIx32 "\n",
86*5706b006SChalapathi V                       __func__, reg);
87*5706b006SChalapathi V     }
88*5706b006SChalapathi V     return val;
89*5706b006SChalapathi V }
90*5706b006SChalapathi V 
pnv_n1_chiplet_pb_scom_es_write(void * opaque,hwaddr addr,uint64_t val,unsigned size)91*5706b006SChalapathi V static void pnv_n1_chiplet_pb_scom_es_write(void *opaque, hwaddr addr,
92*5706b006SChalapathi V                                                uint64_t val, unsigned size)
93*5706b006SChalapathi V {
94*5706b006SChalapathi V     PnvN1Chiplet *n1_chiplet = PNV_N1_CHIPLET(opaque);
95*5706b006SChalapathi V     uint32_t reg = addr >> 3;
96*5706b006SChalapathi V 
97*5706b006SChalapathi V     switch (reg) {
98*5706b006SChalapathi V     case PB_SCOM_ES3_MODE:
99*5706b006SChalapathi V         n1_chiplet->es[3].mode = val;
100*5706b006SChalapathi V         break;
101*5706b006SChalapathi V     default:
102*5706b006SChalapathi V         qemu_log_mask(LOG_UNIMP, "%s: Invalid xscom write at 0x%" PRIx32 "\n",
103*5706b006SChalapathi V                       __func__, reg);
104*5706b006SChalapathi V     }
105*5706b006SChalapathi V }
106*5706b006SChalapathi V 
107*5706b006SChalapathi V static const MemoryRegionOps pnv_n1_chiplet_pb_scom_es_ops = {
108*5706b006SChalapathi V     .read = pnv_n1_chiplet_pb_scom_es_read,
109*5706b006SChalapathi V     .write = pnv_n1_chiplet_pb_scom_es_write,
110*5706b006SChalapathi V     .valid.min_access_size = 8,
111*5706b006SChalapathi V     .valid.max_access_size = 8,
112*5706b006SChalapathi V     .impl.min_access_size = 8,
113*5706b006SChalapathi V     .impl.max_access_size = 8,
114*5706b006SChalapathi V     .endianness = DEVICE_BIG_ENDIAN,
115*5706b006SChalapathi V };
116*5706b006SChalapathi V 
pnv_n1_chiplet_realize(DeviceState * dev,Error ** errp)117*5706b006SChalapathi V static void pnv_n1_chiplet_realize(DeviceState *dev, Error **errp)
118*5706b006SChalapathi V {
119*5706b006SChalapathi V     PnvN1Chiplet *n1_chiplet = PNV_N1_CHIPLET(dev);
120*5706b006SChalapathi V 
121*5706b006SChalapathi V     /* Realize nest pervasive common chiplet model */
122*5706b006SChalapathi V     if (!qdev_realize(DEVICE(&n1_chiplet->nest_pervasive), NULL, errp)) {
123*5706b006SChalapathi V         return;
124*5706b006SChalapathi V     }
125*5706b006SChalapathi V 
126*5706b006SChalapathi V     /* Nest1 chiplet power bus EQ xscom region */
127*5706b006SChalapathi V     pnv_xscom_region_init(&n1_chiplet->xscom_pb_eq_mr, OBJECT(n1_chiplet),
128*5706b006SChalapathi V                           &pnv_n1_chiplet_pb_scom_eq_ops, n1_chiplet,
129*5706b006SChalapathi V                           "xscom-n1-chiplet-pb-scom-eq",
130*5706b006SChalapathi V                           PNV10_XSCOM_N1_PB_SCOM_EQ_SIZE);
131*5706b006SChalapathi V 
132*5706b006SChalapathi V     /* Nest1 chiplet power bus ES xscom region */
133*5706b006SChalapathi V     pnv_xscom_region_init(&n1_chiplet->xscom_pb_es_mr, OBJECT(n1_chiplet),
134*5706b006SChalapathi V                           &pnv_n1_chiplet_pb_scom_es_ops, n1_chiplet,
135*5706b006SChalapathi V                           "xscom-n1-chiplet-pb-scom-es",
136*5706b006SChalapathi V                           PNV10_XSCOM_N1_PB_SCOM_ES_SIZE);
137*5706b006SChalapathi V }
138*5706b006SChalapathi V 
pnv_n1_chiplet_class_init(ObjectClass * klass,void * data)139*5706b006SChalapathi V static void pnv_n1_chiplet_class_init(ObjectClass *klass, void *data)
140*5706b006SChalapathi V {
141*5706b006SChalapathi V     DeviceClass *dc = DEVICE_CLASS(klass);
142*5706b006SChalapathi V 
143*5706b006SChalapathi V     dc->desc = "PowerNV n1 chiplet";
144*5706b006SChalapathi V     dc->realize = pnv_n1_chiplet_realize;
145*5706b006SChalapathi V }
146*5706b006SChalapathi V 
pnv_n1_chiplet_instance_init(Object * obj)147*5706b006SChalapathi V static void pnv_n1_chiplet_instance_init(Object *obj)
148*5706b006SChalapathi V {
149*5706b006SChalapathi V     PnvN1Chiplet *n1_chiplet = PNV_N1_CHIPLET(obj);
150*5706b006SChalapathi V 
151*5706b006SChalapathi V     object_initialize_child(OBJECT(n1_chiplet), "nest-pervasive-common",
152*5706b006SChalapathi V                             &n1_chiplet->nest_pervasive,
153*5706b006SChalapathi V                             TYPE_PNV_NEST_CHIPLET_PERVASIVE);
154*5706b006SChalapathi V }
155*5706b006SChalapathi V 
156*5706b006SChalapathi V static const TypeInfo pnv_n1_chiplet_info = {
157*5706b006SChalapathi V     .name          = TYPE_PNV_N1_CHIPLET,
158*5706b006SChalapathi V     .parent        = TYPE_DEVICE,
159*5706b006SChalapathi V     .instance_init = pnv_n1_chiplet_instance_init,
160*5706b006SChalapathi V     .instance_size = sizeof(PnvN1Chiplet),
161*5706b006SChalapathi V     .class_init    = pnv_n1_chiplet_class_init,
162*5706b006SChalapathi V     .interfaces    = (InterfaceInfo[]) {
163*5706b006SChalapathi V         { TYPE_PNV_XSCOM_INTERFACE },
164*5706b006SChalapathi V         { }
165*5706b006SChalapathi V     }
166*5706b006SChalapathi V };
167*5706b006SChalapathi V 
pnv_n1_chiplet_register_types(void)168*5706b006SChalapathi V static void pnv_n1_chiplet_register_types(void)
169*5706b006SChalapathi V {
170*5706b006SChalapathi V     type_register_static(&pnv_n1_chiplet_info);
171*5706b006SChalapathi V }
172*5706b006SChalapathi V 
173*5706b006SChalapathi V type_init(pnv_n1_chiplet_register_types);
174