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