@@ -27,6 +27,7 @@ static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
CPUCore *core = CPU_CORE(obj);
+ CPUTopoState *topo = CPU_TOPO(obj);
int64_t value;
if (!visit_type_int(v, name, &value, errp)) {
@@ -34,6 +35,7 @@ static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
}
core->nr_threads = value;
+ topo->max_children = core->nr_threads;
}
static void core_prop_set_plugged_threads(Object *obj, Visitor *v,
@@ -53,6 +55,7 @@ static void core_prop_set_plugged_threads(Object *obj, Visitor *v,
static void cpu_core_instance_init(Object *obj)
{
CPUCore *core = CPU_CORE(obj);
+ CPUTopoState *topo = CPU_TOPO(obj);
/*
* Only '-device something-cpu-core,help' can get us there before
@@ -64,11 +67,14 @@ static void cpu_core_instance_init(Object *obj)
}
core->plugged_threads = -1;
+ /* Core's child can only be the thread. */
+ topo->child_level = CPU_TOPO_THREAD;
}
static void cpu_core_realize(DeviceState *dev, Error **errp)
{
CPUCore *core = CPU_CORE(dev);
+ CPUCoreClass *cc = CPU_CORE_GET_CLASS(core);
if (core->plugged_threads > core->nr_threads) {
error_setg(errp, "Plugged threads (plugged-threads: %d) must "
@@ -78,25 +84,32 @@ static void cpu_core_realize(DeviceState *dev, Error **errp)
} else if (core->plugged_threads == -1) {
core->plugged_threads = core->nr_threads;
}
+
+ cc->parent_realize(dev, errp);
}
static void cpu_core_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
+ CPUTopoClass *tc = CPU_TOPO_CLASS(oc);
+ CPUCoreClass *cc = CPU_CORE_CLASS(oc);
- set_bit(DEVICE_CATEGORY_CPU, dc->categories);
+ set_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories);
object_class_property_add(oc, "nr-threads", "int", core_prop_get_nr_threads,
core_prop_set_nr_threads, NULL, NULL);
object_class_property_add(oc, "plugged-threads", "int", NULL,
core_prop_set_plugged_threads, NULL, NULL);
- dc->realize = cpu_core_realize;
+ device_class_set_parent_realize(dc, cpu_core_realize, &cc->parent_realize);
+
+ tc->level = CPU_TOPO_CORE;
}
static const TypeInfo cpu_core_type_info = {
.name = TYPE_CPU_CORE,
- .parent = TYPE_DEVICE,
+ .parent = TYPE_CPU_TOPO,
.abstract = true,
.class_init = cpu_core_class_init,
+ .class_size = sizeof(CPUCoreClass),
.instance_size = sizeof(CPUCore),
.instance_init = cpu_core_instance_init,
};
@@ -334,6 +334,7 @@ static void pnv_core_unrealize(DeviceState *dev)
{
PnvCore *pc = PNV_CORE(dev);
CPUCore *cc = CPU_CORE(dev);
+ PnvCoreClass *pcc = PNV_CORE_GET_CLASS(pc);
int i;
qemu_unregister_reset(pnv_core_reset, pc);
@@ -342,6 +343,8 @@ static void pnv_core_unrealize(DeviceState *dev)
pnv_core_cpu_unrealize(pc, pc->threads[i]);
}
g_free(pc->threads);
+
+ pcc->parent_unrealize(dev);
}
static Property pnv_core_properties[] = {
@@ -380,11 +383,12 @@ static void pnv_core_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc);
PnvCoreClass *pcc = PNV_CORE_CLASS(oc);
- dc->unrealize = pnv_core_unrealize;
device_class_set_props(dc, pnv_core_properties);
dc->user_creatable = false;
device_class_set_parent_realize(dc, pnv_core_realize,
&pcc->parent_realize);
+ device_class_set_parent_unrealize(dc, pnv_core_unrealize,
+ &pcc->parent_unrealize);
}
#define DEFINE_PNV_CORE_TYPE(family, cpu_model) \
@@ -72,6 +72,11 @@ static void powerpc_core_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc);
PowerPCCoreClass *ppc_class = POWERPC_CORE_CLASS(oc);
+ /*
+ * PPC cores support hotplug and must be created after
+ * qemu_init_board().
+ */
+ clear_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories);
object_class_property_add(oc, "core-id", "int",
powerpc_core_prop_get_core_id,
powerpc_core_prop_set_core_id,
@@ -235,6 +235,7 @@ static void spapr_delete_vcpu(PowerPCCPU *cpu)
static void spapr_cpu_core_unrealize(DeviceState *dev)
{
SpaprCpuCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
+ SpaprCpuCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(sc);
CPUCore *cc = CPU_CORE(dev);
int i;
@@ -254,6 +255,8 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)
}
g_free(sc->threads);
qemu_unregister_reset(spapr_cpu_core_reset_handler, sc);
+
+ scc->parent_unrealize(dev);
}
static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
@@ -366,12 +369,14 @@ static void spapr_cpu_core_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc);
SpaprCpuCoreClass *scc = SPAPR_CPU_CORE_CLASS(oc);
- dc->unrealize = spapr_cpu_core_unrealize;
dc->reset = spapr_cpu_core_reset;
device_class_set_props(dc, spapr_cpu_core_properties);
+ dc->hotpluggable = true;
scc->cpu_type = data;
device_class_set_parent_realize(dc, spapr_cpu_core_realize,
&scc->parent_realize);
+ device_class_set_parent_unrealize(dc, spapr_cpu_core_unrealize,
+ &scc->parent_unrealize);
}
#define DEFINE_SPAPR_CPU_CORE_TYPE(cpu_model) \
@@ -10,15 +10,24 @@
#define HW_CPU_CORE_H
#include "hw/qdev-core.h"
+#include "hw/core/cpu-topo.h"
#include "qom/object.h"
#define TYPE_CPU_CORE "cpu-core"
-OBJECT_DECLARE_SIMPLE_TYPE(CPUCore, CPU_CORE)
+OBJECT_DECLARE_TYPE(CPUCore, CPUCoreClass, CPU_CORE)
+
+struct CPUCoreClass {
+ /*< private >*/
+ CPUTopoClass parent_class;
+
+ /*< public >*/
+ DeviceRealize parent_realize;
+};
struct CPUCore {
/*< private >*/
- DeviceState parent_obj;
+ CPUTopoState parent_obj;
/*< public >*/
int core_id;
@@ -51,6 +51,7 @@ struct PnvCoreClass {
uint64_t xscom_size;
DeviceRealize parent_realize;
+ DeviceUnrealize parent_unrealize;
};
#define PNV_CORE_TYPE_SUFFIX "-" TYPE_PNV_CORE
@@ -39,6 +39,7 @@ struct SpaprCpuCoreClass {
const char *cpu_type;
DeviceRealize parent_realize;
+ DeviceUnrealize parent_unrealize;
};
const char *spapr_get_cpu_core_type(const char *cpu_type);