@@ -20,6 +20,7 @@
#include "qemu/osdep.h"
+#include "hw/boards.h"
#include "hw/core/cpu-slot.h"
#include "qapi/error.h"
@@ -165,3 +166,33 @@ static void cpu_slot_register_types(void)
}
type_init(cpu_slot_register_types)
+
+void machine_plug_cpu_slot(MachineState *ms)
+{
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+ ms->topo = CPU_SLOT(qdev_new(TYPE_CPU_SLOT));
+
+ object_property_add_child(container_get(OBJECT(ms), "/peripheral"),
+ "cpu-slot", OBJECT(ms->topo));
+ DEVICE(ms->topo)->id = g_strdup_printf("%s", "cpu-slot");
+
+ qdev_realize_and_unref(DEVICE(ms->topo), NULL, &error_abort);
+ ms->topo->ms = ms;
+
+ if (!mc->smp_props.clusters_supported) {
+ clear_bit(CPU_TOPO_CLUSTER, ms->topo->supported_levels);
+ }
+
+ if (!mc->smp_props.dies_supported) {
+ clear_bit(CPU_TOPO_DIE, ms->topo->supported_levels);
+ }
+
+ if (!mc->smp_props.books_supported) {
+ clear_bit(CPU_TOPO_BOOK, ms->topo->supported_levels);
+ }
+
+ if (!mc->smp_props.drawers_supported) {
+ clear_bit(CPU_TOPO_DRAWER, ms->topo->supported_levels);
+ }
+}
@@ -10,6 +10,7 @@
#include "qemu/module.h"
#include "qom/object.h"
#include "hw/core/cpu.h"
+#include "hw/core/cpu-slot.h"
#define TYPE_MACHINE_SUFFIX "-machine"
@@ -398,6 +399,7 @@ struct MachineState {
AccelState *accelerator;
CPUArchIdList *possible_cpus;
CpuTopology smp;
+ CPUSlot *topo;
struct NVDIMMState *nvdimms_state;
struct NumaState *numa_state;
};
@@ -78,6 +78,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT)
* when necessary.
* @stat: Statistical topology information for topology tree.
* @supported_levels: Supported topology levels for topology tree.
+ * @ms: Machine in which this cpu-slot is plugged.
*/
struct CPUSlot {
/*< private >*/
@@ -87,6 +88,12 @@ struct CPUSlot {
QTAILQ_HEAD(, CPUCore) cores;
CPUTopoStat stat;
DECLARE_BITMAP(supported_levels, USER_AVAIL_LEVEL_NUM);
+ MachineState *ms;
};
+#define MACHINE_CORE_FOREACH(ms, core) \
+ QTAILQ_FOREACH((core), &(ms)->topo->cores, node)
+
+void machine_plug_cpu_slot(MachineState *ms);
+
#endif /* CPU_SLOT_H */
@@ -2128,6 +2128,8 @@ static void qemu_create_machine(QDict *qdict)
false, &error_abort);
qobject_unref(default_opts);
}
+
+ machine_plug_cpu_slot(current_machine);
}
static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)