@@ -559,3 +559,47 @@ bool machine_validate_cpu_topology(MachineState *ms, Error **errp)
return true;
}
+
+Object *cpu_slot_get_free_parent(CPUTopoState *child, Error **errp)
+{
+ MachineState *ms = MACHINE(qdev_get_machine());
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
+ CPUTopoLevel level = CPU_TOPO_LEVEL(child);
+ CPUSlot *slot = ms->topo;
+
+ if (!slot) {
+ return NULL;
+ }
+
+ /*
+ * For CPUs and cores that support hotplug, the behavior is to specify
+ * some topology sub ids. This requires special handling.
+ */
+ if (level == mc->smp_props.possible_cpus_qom_granu) {
+ CPUTopoClass *child_tc = CPU_TOPO_GET_CLASS(child);
+
+ if (child_tc->search_parent_pre_plug) {
+ return child_tc->search_parent_pre_plug(child,
+ CPU_TOPO(slot), errp);
+ }
+ }
+
+ /*
+ * For other topology devices, just collect them into CPU slot.
+ * The realize() of CPUTopoClass will check no "parent" option case.
+ */
+ return OBJECT(slot);
+}
+
+char *cpu_slot_name_future_child(CPUTopoState *child)
+{
+ MachineState *ms = MACHINE(qdev_get_machine());
+ CPUTopoLevel level = CPU_TOPO_LEVEL(child);
+ CPUSlot *slot = ms->topo;
+
+ if (!slot) {
+ return NULL;
+ }
+
+ return get_topo_global_name(&slot->stat, level);
+}
@@ -20,8 +20,10 @@
#include "qemu/osdep.h"
+#include "hw/core/cpu-slot.h"
#include "hw/core/cpu-topo.h"
#include "hw/qdev-properties.h"
+#include "monitor/user-child.h"
#include "qapi/error.h"
const char *cpu_topo_level_to_string(CPUTopoLevel level)
@@ -272,10 +274,38 @@ static void cpu_topo_unrealize(DeviceState *dev)
}
}
+/*
+ * Prefer to insert topology device into topology tree where the CPU
+ * slot is the root.
+ */
+static Object *cpu_topo_get_parent(UserChild *uc, Error **errp)
+{
+ return cpu_slot_get_free_parent(CPU_TOPO(uc), errp);
+}
+
+static char *cpu_topo_get_child_name(UserChild *uc, Object *parent)
+{
+ return cpu_slot_name_future_child(CPU_TOPO(uc));
+}
+
+/* Only check type. Other topology details with be checked at realize(). */
+static bool cpu_topo_check_user_parent(UserChild *uc, Object *parent)
+{
+ CPUTopoState *topo;
+
+ topo = (CPUTopoState *)object_dynamic_cast(parent, TYPE_CPU_TOPO);
+ if (!topo) {
+ return false;
+ }
+
+ return true;
+}
+
static void cpu_topo_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
CPUTopoClass *tc = CPU_TOPO_CLASS(oc);
+ UserChildClass *ucc = USER_CHILD_CLASS(oc);
/* All topology devices belong to CPU property. */
set_bit(DEVICE_CATEGORY_CPU, dc->categories);
@@ -290,6 +320,10 @@ static void cpu_topo_class_init(ObjectClass *oc, void *data)
dc->hotpluggable = false;
tc->level = CPU_TOPO_UNKNOWN;
+
+ ucc->get_parent = cpu_topo_get_parent;
+ ucc->get_child_name = cpu_topo_get_child_name;
+ ucc->check_parent = cpu_topo_check_user_parent;
}
static void cpu_topo_instance_init(Object *obj)
@@ -310,6 +344,10 @@ static const TypeInfo cpu_topo_type_info = {
.class_init = cpu_topo_class_init,
.instance_size = sizeof(CPUTopoState),
.instance_init = cpu_topo_instance_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_USER_CHILD },
+ { }
+ }
};
static void cpu_topo_register_types(void)
@@ -102,4 +102,7 @@ void machine_plug_cpu_slot(MachineState *ms);
void machine_create_smp_topo_tree(MachineState *ms, Error **errp);
bool machine_validate_cpu_topology(MachineState *ms, Error **errp);
+Object *cpu_slot_get_free_parent(CPUTopoState *child, Error **errp);
+char *cpu_slot_name_future_child(CPUTopoState *child);
+
#endif /* CPU_SLOT_H */
@@ -48,6 +48,8 @@ OBJECT_DECLARE_TYPE(CPUTopoState, CPUTopoClass, CPU_TOPO)
* new child (including direct child and non-direct child) is added.
* @check_topo_child: Method to check the support for new child (including
* direct child and non-direct child) to be added.
+ * @search_parent_pre_plug: Method to search proper topology parent of @child
+ * from @root.
*/
struct CPUTopoClass {
/*< private >*/
@@ -59,6 +61,8 @@ struct CPUTopoClass {
bool is_realize);
void (*check_topo_child)(CPUTopoState *parent, CPUTopoState *child,
Error **errp);
+ Object *(*search_parent_pre_plug)(CPUTopoState *child, CPUTopoState *root,
+ Error **errp);
};
/**