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 if (value < 0) { 37 error_setg(errp, "Invalid core id %"PRId64, value); 38 return; 39 } 40 41 core->core_id = value; 42 } 43 44 static void core_prop_get_nr_threads(Object *obj, Visitor *v, const char *name, 45 void *opaque, Error **errp) 46 { 47 CPUCore *core = CPU_CORE(obj); 48 int64_t value = core->nr_threads; 49 50 visit_type_int(v, name, &value, errp); 51 } 52 53 static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name, 54 void *opaque, Error **errp) 55 { 56 CPUCore *core = CPU_CORE(obj); 57 Error *local_err = NULL; 58 int64_t value; 59 60 visit_type_int(v, name, &value, &local_err); 61 if (local_err) { 62 error_propagate(errp, local_err); 63 return; 64 } 65 66 core->nr_threads = value; 67 } 68 69 static void cpu_core_instance_init(Object *obj) 70 { 71 CPUCore *core = CPU_CORE(obj); 72 73 object_property_add(obj, "core-id", "int", core_prop_get_core_id, 74 core_prop_set_core_id, NULL, NULL, NULL); 75 object_property_add(obj, "nr-threads", "int", core_prop_get_nr_threads, 76 core_prop_set_nr_threads, NULL, NULL, NULL); 77 core->nr_threads = smp_threads; 78 } 79 80 static void cpu_core_class_init(ObjectClass *oc, void *data) 81 { 82 DeviceClass *dc = DEVICE_CLASS(oc); 83 84 set_bit(DEVICE_CATEGORY_CPU, dc->categories); 85 } 86 87 static const TypeInfo cpu_core_type_info = { 88 .name = TYPE_CPU_CORE, 89 .parent = TYPE_DEVICE, 90 .abstract = true, 91 .class_init = cpu_core_class_init, 92 .instance_size = sizeof(CPUCore), 93 .instance_init = cpu_core_instance_init, 94 }; 95 96 static void cpu_core_register_types(void) 97 { 98 type_register_static(&cpu_core_type_info); 99 } 100 101 type_init(cpu_core_register_types) 102