xref: /openbmc/qemu/hw/cpu/core.c (revision ac89de40)
1 /*
2  * CPU core abstract device
3  *
4  * Copyright (C) 2016 Bharata B Rao <bharata@linux.vnet.ibm.com>
5  *
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  */
9 #include "qemu/osdep.h"
10 #include "hw/cpu/core.h"
11 #include "qapi/visitor.h"
12 #include "qapi/error.h"
13 #include "sysemu/cpus.h"
14 
15 static void core_prop_get_core_id(Object *obj, Visitor *v, const char *name,
16                                   void *opaque, Error **errp)
17 {
18     CPUCore *core = CPU_CORE(obj);
19     int64_t value = core->core_id;
20 
21     visit_type_int(v, name, &value, errp);
22 }
23 
24 static void core_prop_set_core_id(Object *obj, Visitor *v, const char *name,
25                                   void *opaque, Error **errp)
26 {
27     CPUCore *core = CPU_CORE(obj);
28     Error *local_err = NULL;
29     int64_t value;
30 
31     visit_type_int(v, name, &value, &local_err);
32     if (local_err) {
33         error_propagate(errp, local_err);
34         return;
35     }
36 
37     if (value < 0) {
38         error_setg(errp, "Invalid core id %"PRId64, value);
39         return;
40     }
41 
42     core->core_id = value;
43 }
44 
45 static void core_prop_get_nr_threads(Object *obj, Visitor *v, const char *name,
46                                      void *opaque, Error **errp)
47 {
48     CPUCore *core = CPU_CORE(obj);
49     int64_t value = core->nr_threads;
50 
51     visit_type_int(v, name, &value, errp);
52 }
53 
54 static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
55                                      void *opaque, Error **errp)
56 {
57     CPUCore *core = CPU_CORE(obj);
58     Error *local_err = NULL;
59     int64_t value;
60 
61     visit_type_int(v, name, &value, &local_err);
62     if (local_err) {
63         error_propagate(errp, local_err);
64         return;
65     }
66 
67     core->nr_threads = value;
68 }
69 
70 static void cpu_core_instance_init(Object *obj)
71 {
72     CPUCore *core = CPU_CORE(obj);
73 
74     object_property_add(obj, "core-id", "int", core_prop_get_core_id,
75                         core_prop_set_core_id, NULL, NULL, NULL);
76     object_property_add(obj, "nr-threads", "int", core_prop_get_nr_threads,
77                         core_prop_set_nr_threads, NULL, NULL, NULL);
78     core->nr_threads = smp_threads;
79 }
80 
81 static void cpu_core_class_init(ObjectClass *oc, void *data)
82 {
83     DeviceClass *dc = DEVICE_CLASS(oc);
84 
85     set_bit(DEVICE_CATEGORY_CPU, dc->categories);
86 }
87 
88 static const TypeInfo cpu_core_type_info = {
89     .name = TYPE_CPU_CORE,
90     .parent = TYPE_DEVICE,
91     .abstract = true,
92     .class_init = cpu_core_class_init,
93     .instance_size = sizeof(CPUCore),
94     .instance_init = cpu_core_instance_init,
95 };
96 
97 static void cpu_core_register_types(void)
98 {
99     type_register_static(&cpu_core_type_info);
100 }
101 
102 type_init(cpu_core_register_types)
103