2 * CPU core abstract device
4 * Copyright (C) 2016 Bharata B Rao <bharata@linux.vnet.ibm.com>
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
10 #include "qemu/osdep.h"
12 #include "hw/boards.h"
13 #include "hw/cpu/core.h"
14 #include "qapi/error.h"
15 #include "qapi/visitor.h"
17 static void core_prop_get_core_id(Object
*obj
, Visitor
*v
, const char *name
,
18 void *opaque
, Error
**errp
)
20 CPUCore
*core
= CPU_CORE(obj
);
21 int64_t value
= core
->core_id
;
23 visit_type_int(v
, name
, &value
, errp
);
26 static void core_prop_set_core_id(Object
*obj
, Visitor
*v
, const char *name
,
27 void *opaque
, Error
**errp
)
29 CPUCore
*core
= CPU_CORE(obj
);
32 if (!visit_type_int(v
, name
, &value
, errp
)) {
37 error_setg(errp
, "Invalid core id %"PRId64
, value
);
41 core
->core_id
= value
;
44 static void core_prop_get_nr_threads(Object
*obj
, Visitor
*v
, const char *name
,
45 void *opaque
, Error
**errp
)
47 CPUCore
*core
= CPU_CORE(obj
);
48 int64_t value
= core
->nr_threads
;
50 visit_type_int(v
, name
, &value
, errp
);
53 static void core_prop_set_nr_threads(Object
*obj
, Visitor
*v
, const char *name
,
54 void *opaque
, Error
**errp
)
56 CPUCore
*core
= CPU_CORE(obj
);
59 if (!visit_type_int(v
, name
, &value
, errp
)) {
63 core
->nr_threads
= value
;
66 static void cpu_core_instance_init(Object
*obj
)
68 CPUCore
*core
= CPU_CORE(obj
);
71 * Only '-device something-cpu-core,help' can get us there before
72 * the machine has been created. We don't care to set nr_threads
73 * in this case since it isn't used afterwards.
75 if (current_machine
) {
76 core
->nr_threads
= current_machine
->smp
.threads
;
80 static void cpu_core_class_init(ObjectClass
*oc
, void *data
)
82 DeviceClass
*dc
= DEVICE_CLASS(oc
);
84 set_bit(DEVICE_CATEGORY_CPU
, dc
->categories
);
85 object_class_property_add(oc
, "core-id", "int", core_prop_get_core_id
,
86 core_prop_set_core_id
, NULL
, NULL
);
87 object_class_property_add(oc
, "nr-threads", "int", core_prop_get_nr_threads
,
88 core_prop_set_nr_threads
, NULL
, NULL
);
91 static const TypeInfo cpu_core_type_info
= {
92 .name
= TYPE_CPU_CORE
,
93 .parent
= TYPE_DEVICE
,
95 .class_init
= cpu_core_class_init
,
96 .instance_size
= sizeof(CPUCore
),
97 .instance_init
= cpu_core_instance_init
,
100 static void cpu_core_register_types(void)
102 type_register_static(&cpu_core_type_info
);
105 type_init(cpu_core_register_types
)