xref: /openbmc/qemu/hw/cpu/core.c (revision 0c0c1fd9)
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 "hw/cpu/core.h"
10 #include "qapi/visitor.h"
11 #include "qapi/error.h"
12 #include "sysemu/cpus.h"
13 
14 static void core_prop_get_core_id(Object *obj, Visitor *v, const char *name,
15                                   void *opaque, Error **errp)
16 {
17     CPUCore *core = CPU_CORE(obj);
18     int64_t value = core->core_id;
19 
20     visit_type_int(v, name, &value, errp);
21 }
22 
23 static void core_prop_set_core_id(Object *obj, Visitor *v, const char *name,
24                                   void *opaque, Error **errp)
25 {
26     CPUCore *core = CPU_CORE(obj);
27     Error *local_err = NULL;
28     int64_t value;
29 
30     visit_type_int(v, name, &value, &local_err);
31     if (local_err) {
32         error_propagate(errp, local_err);
33         return;
34     }
35 
36     core->core_id = value;
37 }
38 
39 static void core_prop_get_nr_threads(Object *obj, Visitor *v, const char *name,
40                                      void *opaque, Error **errp)
41 {
42     CPUCore *core = CPU_CORE(obj);
43     int64_t value = core->nr_threads;
44 
45     visit_type_int(v, name, &value, errp);
46 }
47 
48 static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
49                                      void *opaque, Error **errp)
50 {
51     CPUCore *core = CPU_CORE(obj);
52     Error *local_err = NULL;
53     int64_t value;
54 
55     visit_type_int(v, name, &value, &local_err);
56     if (local_err) {
57         error_propagate(errp, local_err);
58         return;
59     }
60 
61     core->nr_threads = value;
62 }
63 
64 static void cpu_core_instance_init(Object *obj)
65 {
66     CPUCore *core = CPU_CORE(obj);
67 
68     object_property_add(obj, "core-id", "int", core_prop_get_core_id,
69                         core_prop_set_core_id, NULL, NULL, NULL);
70     object_property_add(obj, "nr-threads", "int", core_prop_get_nr_threads,
71                         core_prop_set_nr_threads, NULL, NULL, NULL);
72     core->nr_threads = smp_threads;
73 }
74 
75 static const TypeInfo cpu_core_type_info = {
76     .name = TYPE_CPU_CORE,
77     .parent = TYPE_DEVICE,
78     .abstract = true,
79     .instance_size = sizeof(CPUCore),
80     .instance_init = cpu_core_instance_init,
81 };
82 
83 static void cpu_core_register_types(void)
84 {
85     type_register_static(&cpu_core_type_info);
86 }
87 
88 type_init(cpu_core_register_types)
89