hw/elf_ops: Fix a typo
[qemu/ar7.git] / hw / cpu / core.c
blob92d3b2fbad62cc3dd7656f148bfdbbc685275275
1 /*
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.
8 */
10 #include "qemu/osdep.h"
11 #include "hw/cpu/core.h"
12 #include "qapi/visitor.h"
13 #include "qemu/module.h"
14 #include "qapi/error.h"
15 #include "sysemu/cpus.h"
16 #include "hw/boards.h"
18 static void core_prop_get_core_id(Object *obj, Visitor *v, const char *name,
19 void *opaque, Error **errp)
21 CPUCore *core = CPU_CORE(obj);
22 int64_t value = core->core_id;
24 visit_type_int(v, name, &value, errp);
27 static void core_prop_set_core_id(Object *obj, Visitor *v, const char *name,
28 void *opaque, Error **errp)
30 CPUCore *core = CPU_CORE(obj);
31 int64_t value;
33 if (!visit_type_int(v, name, &value, errp)) {
34 return;
37 if (value < 0) {
38 error_setg(errp, "Invalid core id %"PRId64, value);
39 return;
42 core->core_id = value;
45 static void core_prop_get_nr_threads(Object *obj, Visitor *v, const char *name,
46 void *opaque, Error **errp)
48 CPUCore *core = CPU_CORE(obj);
49 int64_t value = core->nr_threads;
51 visit_type_int(v, name, &value, errp);
54 static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
55 void *opaque, Error **errp)
57 CPUCore *core = CPU_CORE(obj);
58 int64_t value;
60 if (!visit_type_int(v, name, &value, errp)) {
61 return;
64 core->nr_threads = value;
67 static void cpu_core_instance_init(Object *obj)
69 MachineState *ms = MACHINE(qdev_get_machine());
70 CPUCore *core = CPU_CORE(obj);
72 core->nr_threads = ms->smp.threads;
75 static void cpu_core_class_init(ObjectClass *oc, void *data)
77 DeviceClass *dc = DEVICE_CLASS(oc);
79 set_bit(DEVICE_CATEGORY_CPU, dc->categories);
80 object_class_property_add(oc, "core-id", "int", core_prop_get_core_id,
81 core_prop_set_core_id, NULL, NULL);
82 object_class_property_add(oc, "nr-threads", "int", core_prop_get_nr_threads,
83 core_prop_set_nr_threads, NULL, NULL);
86 static const TypeInfo cpu_core_type_info = {
87 .name = TYPE_CPU_CORE,
88 .parent = TYPE_DEVICE,
89 .abstract = true,
90 .class_init = cpu_core_class_init,
91 .instance_size = sizeof(CPUCore),
92 .instance_init = cpu_core_instance_init,
95 static void cpu_core_register_types(void)
97 type_register_static(&cpu_core_type_info);
100 type_init(cpu_core_register_types)