1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "qemu/osdep.h"
22#include "hw/cpu/cluster.h"
23#include "hw/qdev-properties.h"
24#include "hw/core/cpu.h"
25#include "qapi/error.h"
26#include "qemu/module.h"
27#include "qemu/cutils.h"
28
29static Property cpu_cluster_properties[] = {
30 DEFINE_PROP_UINT32("cluster-id", CPUClusterState, cluster_id, 0),
31 DEFINE_PROP_END_OF_LIST()
32};
33
34typedef struct CallbackData {
35 CPUClusterState *cluster;
36 int cpu_count;
37} CallbackData;
38
39static int add_cpu_to_cluster(Object *obj, void *opaque)
40{
41 CallbackData *cbdata = opaque;
42 CPUState *cpu = (CPUState *)object_dynamic_cast(obj, TYPE_CPU);
43
44 if (cpu) {
45 cpu->cluster_index = cbdata->cluster->cluster_id;
46 cbdata->cpu_count++;
47 }
48 return 0;
49}
50
51static void cpu_cluster_realize(DeviceState *dev, Error **errp)
52{
53
54 CPUClusterState *cluster = CPU_CLUSTER(dev);
55 Object *cluster_obj = OBJECT(dev);
56 CallbackData cbdata = {
57 .cluster = cluster,
58 .cpu_count = 0,
59 };
60
61 if (cluster->cluster_id >= MAX_CLUSTERS) {
62 error_setg(errp, "cluster-id must be less than %d", MAX_CLUSTERS);
63 return;
64 }
65
66 object_child_foreach_recursive(cluster_obj, add_cpu_to_cluster, &cbdata);
67
68
69
70
71
72
73
74 assert(cbdata.cpu_count > 0);
75}
76
77static void cpu_cluster_class_init(ObjectClass *klass, void *data)
78{
79 DeviceClass *dc = DEVICE_CLASS(klass);
80
81 device_class_set_props(dc, cpu_cluster_properties);
82 dc->realize = cpu_cluster_realize;
83
84
85 dc->user_creatable = false;
86}
87
88static const TypeInfo cpu_cluster_type_info = {
89 .name = TYPE_CPU_CLUSTER,
90 .parent = TYPE_DEVICE,
91 .instance_size = sizeof(CPUClusterState),
92 .class_init = cpu_cluster_class_init,
93};
94
95static void cpu_cluster_register_types(void)
96{
97 type_register_static(&cpu_cluster_type_info);
98}
99
100type_init(cpu_cluster_register_types)
101