ppc/pnv: Introduce PnvMachineClass and PnvMachineClass::compat

The pnv_dt_create() function generates different contents for the
"compatible" property of the root node in the DT, depending on the
CPU type. This is open coded with multiple ifs using pnv_is_powerXX()
helpers.

It seems cleaner to achieve with QOM. Introduce a base class for the
powernv machine and a compat attribute that each child class can use
to provide the value for the "compatible" property.

Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <157623839085.360005.4046508784077843216.stgit@bahia.lan>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
[dwg: Folded in small fix Greg spotted after posting]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Greg Kurz 2019-12-13 12:59:50 +01:00 committed by David Gibson
parent 248e4e924e
commit d76f2da7a5
2 changed files with 31 additions and 14 deletions

View File

@ -484,9 +484,7 @@ static void pnv_dt_power_mgt(void *fdt)
static void *pnv_dt_create(MachineState *machine) static void *pnv_dt_create(MachineState *machine)
{ {
const char plat_compat8[] = "qemu,powernv8\0qemu,powernv\0ibm,powernv"; PnvMachineClass *pmc = PNV_MACHINE_GET_CLASS(machine);
const char plat_compat9[] = "qemu,powernv9\0ibm,powernv";
const char plat_compat10[] = "qemu,powernv10\0ibm,powernv";
PnvMachineState *pnv = PNV_MACHINE(machine); PnvMachineState *pnv = PNV_MACHINE(machine);
void *fdt; void *fdt;
char *buf; char *buf;
@ -504,17 +502,7 @@ static void *pnv_dt_create(MachineState *machine)
_FDT((fdt_setprop_cell(fdt, 0, "#size-cells", 0x2))); _FDT((fdt_setprop_cell(fdt, 0, "#size-cells", 0x2)));
_FDT((fdt_setprop_string(fdt, 0, "model", _FDT((fdt_setprop_string(fdt, 0, "model",
"IBM PowerNV (emulated by qemu)"))); "IBM PowerNV (emulated by qemu)")));
if (pnv_is_power10(pnv)) { _FDT((fdt_setprop(fdt, 0, "compatible", pmc->compat, pmc->compat_size)));
_FDT((fdt_setprop(fdt, 0, "compatible", plat_compat10,
sizeof(plat_compat10))));
} else if (pnv_is_power9(pnv)) {
_FDT((fdt_setprop(fdt, 0, "compatible", plat_compat9,
sizeof(plat_compat9))));
} else {
_FDT((fdt_setprop(fdt, 0, "compatible", plat_compat8,
sizeof(plat_compat8))));
}
buf = qemu_uuid_unparse_strdup(&qemu_uuid); buf = qemu_uuid_unparse_strdup(&qemu_uuid);
_FDT((fdt_setprop_string(fdt, 0, "vm,uuid", buf))); _FDT((fdt_setprop_string(fdt, 0, "vm,uuid", buf)));
@ -1692,6 +1680,8 @@ static void pnv_machine_power8_class_init(ObjectClass *oc, void *data)
{ {
MachineClass *mc = MACHINE_CLASS(oc); MachineClass *mc = MACHINE_CLASS(oc);
XICSFabricClass *xic = XICS_FABRIC_CLASS(oc); XICSFabricClass *xic = XICS_FABRIC_CLASS(oc);
PnvMachineClass *pmc = PNV_MACHINE_CLASS(oc);
static const char compat[] = "qemu,powernv8\0qemu,powernv\0ibm,powernv";
mc->desc = "IBM PowerNV (Non-Virtualized) POWER8"; mc->desc = "IBM PowerNV (Non-Virtualized) POWER8";
mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0"); mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0");
@ -1699,26 +1689,39 @@ static void pnv_machine_power8_class_init(ObjectClass *oc, void *data)
xic->icp_get = pnv_icp_get; xic->icp_get = pnv_icp_get;
xic->ics_get = pnv_ics_get; xic->ics_get = pnv_ics_get;
xic->ics_resend = pnv_ics_resend; xic->ics_resend = pnv_ics_resend;
pmc->compat = compat;
pmc->compat_size = sizeof(compat);
} }
static void pnv_machine_power9_class_init(ObjectClass *oc, void *data) static void pnv_machine_power9_class_init(ObjectClass *oc, void *data)
{ {
MachineClass *mc = MACHINE_CLASS(oc); MachineClass *mc = MACHINE_CLASS(oc);
XiveFabricClass *xfc = XIVE_FABRIC_CLASS(oc); XiveFabricClass *xfc = XIVE_FABRIC_CLASS(oc);
PnvMachineClass *pmc = PNV_MACHINE_CLASS(oc);
static const char compat[] = "qemu,powernv9\0ibm,powernv";
mc->desc = "IBM PowerNV (Non-Virtualized) POWER9"; mc->desc = "IBM PowerNV (Non-Virtualized) POWER9";
mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power9_v2.0"); mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power9_v2.0");
xfc->match_nvt = pnv_match_nvt; xfc->match_nvt = pnv_match_nvt;
mc->alias = "powernv"; mc->alias = "powernv";
pmc->compat = compat;
pmc->compat_size = sizeof(compat);
} }
static void pnv_machine_power10_class_init(ObjectClass *oc, void *data) static void pnv_machine_power10_class_init(ObjectClass *oc, void *data)
{ {
MachineClass *mc = MACHINE_CLASS(oc); MachineClass *mc = MACHINE_CLASS(oc);
PnvMachineClass *pmc = PNV_MACHINE_CLASS(oc);
static const char compat[] = "qemu,powernv10\0ibm,powernv";
mc->desc = "IBM PowerNV (Non-Virtualized) POWER10"; mc->desc = "IBM PowerNV (Non-Virtualized) POWER10";
mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power10_v1.0"); mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power10_v1.0");
pmc->compat = compat;
pmc->compat_size = sizeof(compat);
} }
static void pnv_machine_class_init(ObjectClass *oc, void *data) static void pnv_machine_class_init(ObjectClass *oc, void *data)
@ -1796,6 +1799,7 @@ static const TypeInfo types[] = {
.instance_size = sizeof(PnvMachineState), .instance_size = sizeof(PnvMachineState),
.instance_init = pnv_machine_instance_init, .instance_init = pnv_machine_instance_init,
.class_init = pnv_machine_class_init, .class_init = pnv_machine_class_init,
.class_size = sizeof(PnvMachineClass),
.interfaces = (InterfaceInfo[]) { .interfaces = (InterfaceInfo[]) {
{ TYPE_INTERRUPT_STATS_PROVIDER }, { TYPE_INTERRUPT_STATS_PROVIDER },
{ }, { },

View File

@ -185,6 +185,19 @@ PowerPCCPU *pnv_chip_find_cpu(PnvChip *chip, uint32_t pir);
#define TYPE_PNV_MACHINE MACHINE_TYPE_NAME("powernv") #define TYPE_PNV_MACHINE MACHINE_TYPE_NAME("powernv")
#define PNV_MACHINE(obj) \ #define PNV_MACHINE(obj) \
OBJECT_CHECK(PnvMachineState, (obj), TYPE_PNV_MACHINE) OBJECT_CHECK(PnvMachineState, (obj), TYPE_PNV_MACHINE)
#define PNV_MACHINE_GET_CLASS(obj) \
OBJECT_GET_CLASS(PnvMachineClass, obj, TYPE_PNV_MACHINE)
#define PNV_MACHINE_CLASS(klass) \
OBJECT_CLASS_CHECK(PnvMachineClass, klass, TYPE_PNV_MACHINE)
typedef struct PnvMachineClass {
/*< private >*/
MachineClass parent_class;
/*< public >*/
const char *compat;
int compat_size;
} PnvMachineClass;
typedef struct PnvMachineState { typedef struct PnvMachineState {
/*< private >*/ /*< private >*/