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.
9 #include "hw/cpu/core.h"
10 #include "qapi/visitor.h"
11 #include "qapi/error.h"
12 #include "sysemu/cpus.h"
14 static void core_prop_get_core_id(Object
*obj
, Visitor
*v
, const char *name
,
15 void *opaque
, Error
**errp
)
17 CPUCore
*core
= CPU_CORE(obj
);
18 int64_t value
= core
->core_id
;
20 visit_type_int(v
, name
, &value
, errp
);
23 static void core_prop_set_core_id(Object
*obj
, Visitor
*v
, const char *name
,
24 void *opaque
, Error
**errp
)
26 CPUCore
*core
= CPU_CORE(obj
);
27 Error
*local_err
= NULL
;
30 visit_type_int(v
, name
, &value
, &local_err
);
32 error_propagate(errp
, local_err
);
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
);
57 Error
*local_err
= NULL
;
60 visit_type_int(v
, name
, &value
, &local_err
);
62 error_propagate(errp
, local_err
);
66 core
->nr_threads
= value
;
69 static void cpu_core_instance_init(Object
*obj
)
71 CPUCore
*core
= CPU_CORE(obj
);
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
;
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
);
87 static const TypeInfo cpu_core_type_info
= {
88 .name
= TYPE_CPU_CORE
,
89 .parent
= TYPE_DEVICE
,
91 .class_init
= cpu_core_class_init
,
92 .instance_size
= sizeof(CPUCore
),
93 .instance_init
= cpu_core_instance_init
,
96 static void cpu_core_register_types(void)
98 type_register_static(&cpu_core_type_info
);
101 type_init(cpu_core_register_types
)