]> git.proxmox.com Git - mirror_qemu.git/blame - target-s390x/cpu_models.c
s390x/cpumodel: register defined CPU models as subclasses
[mirror_qemu.git] / target-s390x / cpu_models.c
CommitLineData
41868f84
DH
1/*
2 * CPU models for s390x
3 *
4 * Copyright 2016 IBM Corp.
5 *
6 * Author(s): David Hildenbrand <dahi@linux.vnet.ibm.com>
7 *
8 * This work is licensed under the terms of the GNU GPL, version 2 or (at
9 * your option) any later version. See the COPYING file in the top-level
10 * directory.
11 */
12
13#include "qemu/osdep.h"
14#include "cpu.h"
6c064de1 15#include "gen-features.h"
41868f84
DH
16#include "qapi/error.h"
17#ifndef CONFIG_USER_ONLY
18#include "sysemu/arch_init.h"
19#endif
20
6c064de1
DH
21#define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
22 { \
23 .name = _name, \
24 .type = _type, \
25 .gen = _gen, \
26 .ec_ga = _ec_ga, \
27 .mha_pow = _mha_pow, \
28 .hmfai = _hmfai, \
29 .desc = _desc, \
30 .base_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _BASE }, \
31 .default_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _DEFAULT }, \
32 .full_init = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _FULL }, \
33 }
34
35/*
36 * CPU definiton list in order of release. For now, base features of a
37 * following release are always a subset of base features of the previous
38 * release. Same is correct for the other feature sets.
39 * A BC release always follows the corresponding EC release.
40 */
41static S390CPUDef s390_cpu_defs[] = {
42 CPUDEF_INIT(0x2064, 7, 1, 38, 0x00000000U, "z900", "IBM zSeries 900 GA1"),
43 CPUDEF_INIT(0x2064, 7, 2, 38, 0x00000000U, "z900.2", "IBM zSeries 900 GA2"),
44 CPUDEF_INIT(0x2064, 7, 3, 38, 0x00000000U, "z900.3", "IBM zSeries 900 GA3"),
45 CPUDEF_INIT(0x2066, 7, 3, 38, 0x00000000U, "z800", "IBM zSeries 800 GA1"),
46 CPUDEF_INIT(0x2084, 8, 1, 38, 0x00000000U, "z990", "IBM zSeries 990 GA1"),
47 CPUDEF_INIT(0x2084, 8, 2, 38, 0x00000000U, "z990.2", "IBM zSeries 990 GA2"),
48 CPUDEF_INIT(0x2084, 8, 3, 38, 0x00000000U, "z990.3", "IBM zSeries 990 GA3"),
49 CPUDEF_INIT(0x2086, 8, 3, 38, 0x00000000U, "z890", "IBM zSeries 880 GA1"),
50 CPUDEF_INIT(0x2084, 8, 4, 38, 0x00000000U, "z990.4", "IBM zSeries 990 GA4"),
51 CPUDEF_INIT(0x2086, 8, 4, 38, 0x00000000U, "z890.2", "IBM zSeries 880 GA2"),
52 CPUDEF_INIT(0x2084, 8, 5, 38, 0x00000000U, "z990.5", "IBM zSeries 990 GA5"),
53 CPUDEF_INIT(0x2086, 8, 5, 38, 0x00000000U, "z890.3", "IBM zSeries 880 GA3"),
54 CPUDEF_INIT(0x2094, 9, 1, 40, 0x00000000U, "z9EC", "IBM System z9 EC GA1"),
55 CPUDEF_INIT(0x2094, 9, 2, 40, 0x00000000U, "z9EC.2", "IBM System z9 EC GA2"),
56 CPUDEF_INIT(0x2096, 9, 2, 40, 0x00000000U, "z9BC", "IBM System z9 BC GA1"),
57 CPUDEF_INIT(0x2094, 9, 3, 40, 0x00000000U, "z9EC.3", "IBM System z9 EC GA3"),
58 CPUDEF_INIT(0x2096, 9, 3, 40, 0x00000000U, "z9BC.2", "IBM System z9 BC GA2"),
59 CPUDEF_INIT(0x2097, 10, 1, 43, 0x00000000U, "z10EC", "IBM System z10 EC GA1"),
60 CPUDEF_INIT(0x2097, 10, 2, 43, 0x00000000U, "z10EC.2", "IBM System z10 EC GA2"),
61 CPUDEF_INIT(0x2098, 10, 2, 43, 0x00000000U, "z10BC", "IBM System z10 BC GA1"),
62 CPUDEF_INIT(0x2097, 10, 3, 43, 0x00000000U, "z10EC.3", "IBM System z10 EC GA3"),
63 CPUDEF_INIT(0x2098, 10, 3, 43, 0x00000000U, "z10BC.2", "IBM System z10 BC GA2"),
64 CPUDEF_INIT(0x2817, 11, 1, 44, 0x08000000U, "z196", "IBM zEnterprise 196 GA1"),
65 CPUDEF_INIT(0x2817, 11, 2, 44, 0x08000000U, "z196.2", "IBM zEnterprise 196 GA2"),
66 CPUDEF_INIT(0x2818, 11, 2, 44, 0x08000000U, "z114", "IBM zEnterprise 114 GA1"),
67 CPUDEF_INIT(0x2827, 12, 1, 44, 0x08000000U, "zEC12", "IBM zEnterprise EC12 GA1"),
68 CPUDEF_INIT(0x2827, 12, 2, 44, 0x08000000U, "zEC12.2", "IBM zEnterprise EC12 GA2"),
69 CPUDEF_INIT(0x2828, 12, 2, 44, 0x08000000U, "zBC12", "IBM zEnterprise BC12 GA1"),
70 CPUDEF_INIT(0x2964, 13, 1, 47, 0x08000000U, "z13", "IBM z13 GA1"),
71 CPUDEF_INIT(0x2964, 13, 2, 47, 0x08000000U, "z13.2", "IBM z13 GA2"),
72 CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
73};
74
41868f84
DH
75struct S390PrintCpuListInfo {
76 FILE *f;
77 fprintf_function print;
78};
79
80static void print_cpu_model_list(ObjectClass *klass, void *opaque)
81{
82 struct S390PrintCpuListInfo *info = opaque;
83 S390CPUClass *scc = S390_CPU_CLASS(klass);
84 char *name = g_strdup(object_class_get_name(klass));
85 const char *details = "";
86
87 if (scc->is_static) {
88 details = "(static, migration-safe)";
89 } else if (scc->is_migration_safe) {
90 details = "(migration-safe)";
91 }
92
93 /* strip off the -s390-cpu */
94 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
95 (*info->print)(info->f, "s390 %-15s %-35s %s\n", name, scc->desc,
96 details);
97 g_free(name);
98}
99
100void s390_cpu_list(FILE *f, fprintf_function print)
101{
102 struct S390PrintCpuListInfo info = {
103 .f = f,
104 .print = print,
105 };
106
107 object_class_foreach(print_cpu_model_list, TYPE_S390_CPU, false, &info);
108}
109
110#ifndef CONFIG_USER_ONLY
111static void create_cpu_model_list(ObjectClass *klass, void *opaque)
112{
113 CpuDefinitionInfoList **cpu_list = opaque;
114 CpuDefinitionInfoList *entry;
115 CpuDefinitionInfo *info;
116 char *name = g_strdup(object_class_get_name(klass));
117 S390CPUClass *scc = S390_CPU_CLASS(klass);
118
119 /* strip off the -s390-cpu */
120 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
121 info = g_malloc0(sizeof(*info));
122 info->name = name;
123 info->has_migration_safe = true;
124 info->migration_safe = scc->is_migration_safe;
125 info->q_static = scc->is_static;
126
127
128 entry = g_malloc0(sizeof(*entry));
129 entry->value = info;
130 entry->next = *cpu_list;
131 *cpu_list = entry;
132}
133
134CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
135{
136 CpuDefinitionInfoList *list = NULL;
137
138 object_class_foreach(create_cpu_model_list, TYPE_S390_CPU, false, &list);
139
140 return list;
141}
142#endif
143
144void s390_realize_cpu_model(CPUState *cs, Error **errp)
145{
146 S390CPUClass *xcc = S390_CPU_GET_CLASS(cs);
147
148 if (xcc->kvm_required && !kvm_enabled()) {
149 error_setg(errp, "CPU definition requires KVM");
150 return;
151 }
152}
153
6c064de1
DH
154static void s390_cpu_model_initfn(Object *obj)
155{
156}
157
41868f84
DH
158#ifdef CONFIG_KVM
159static void s390_host_cpu_model_initfn(Object *obj)
160{
161}
162#endif
163
164static void s390_qemu_cpu_model_initfn(Object *obj)
165{
166}
167
168static void s390_cpu_model_finalize(Object *obj)
169{
170}
171
6efadc90
DH
172static bool get_is_migration_safe(Object *obj, Error **errp)
173{
174 return S390_CPU_GET_CLASS(obj)->is_migration_safe;
175}
176
177static bool get_is_static(Object *obj, Error **errp)
178{
179 return S390_CPU_GET_CLASS(obj)->is_static;
180}
181
182static char *get_description(Object *obj, Error **errp)
183{
184 return g_strdup(S390_CPU_GET_CLASS(obj)->desc);
185}
186
187void s390_cpu_model_class_register_props(ObjectClass *oc)
188{
189 object_class_property_add_bool(oc, "migration-safe", get_is_migration_safe,
190 NULL, NULL);
191 object_class_property_add_bool(oc, "static", get_is_static,
192 NULL, NULL);
193 object_class_property_add_str(oc, "description", get_description, NULL,
194 NULL);
195}
196
41868f84
DH
197#ifdef CONFIG_KVM
198static void s390_host_cpu_model_class_init(ObjectClass *oc, void *data)
199{
200 S390CPUClass *xcc = S390_CPU_CLASS(oc);
201
202 xcc->kvm_required = true;
203 xcc->desc = "KVM only: All recognized features";
204}
205#endif
206
6c064de1
DH
207static void s390_base_cpu_model_class_init(ObjectClass *oc, void *data)
208{
209 S390CPUClass *xcc = S390_CPU_CLASS(oc);
210
211 /* all base models are migration safe */
212 xcc->cpu_def = (const S390CPUDef *) data;
213 xcc->is_migration_safe = true;
214 xcc->is_static = true;
215 xcc->desc = xcc->cpu_def->desc;
216}
217
218static void s390_cpu_model_class_init(ObjectClass *oc, void *data)
219{
220 S390CPUClass *xcc = S390_CPU_CLASS(oc);
221
222 /* model that can change between QEMU versions */
223 xcc->cpu_def = (const S390CPUDef *) data;
224 xcc->is_migration_safe = true;
225 xcc->desc = xcc->cpu_def->desc;
226}
227
41868f84
DH
228static void s390_qemu_cpu_model_class_init(ObjectClass *oc, void *data)
229{
230 S390CPUClass *xcc = S390_CPU_CLASS(oc);
231
232 xcc->is_migration_safe = true;
233 xcc->desc = g_strdup_printf("QEMU Virtual CPU version %s",
234 qemu_hw_version());
235}
236
237#define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
238#define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX)
239
240/* Generate type name for a cpu model. Caller has to free the string. */
241static char *s390_cpu_type_name(const char *model_name)
242{
243 return g_strdup_printf(S390_CPU_TYPE_NAME("%s"), model_name);
244}
245
6c064de1
DH
246/* Generate type name for a base cpu model. Caller has to free the string. */
247static char *s390_base_cpu_type_name(const char *model_name)
248{
249 return g_strdup_printf(S390_CPU_TYPE_NAME("%s-base"), model_name);
250}
251
41868f84
DH
252ObjectClass *s390_cpu_class_by_name(const char *name)
253{
254 char *typename = s390_cpu_type_name(name);
255 ObjectClass *oc;
256
257 oc = object_class_by_name(typename);
258 g_free(typename);
259 return oc;
260}
261
262static const TypeInfo qemu_s390_cpu_type_info = {
263 .name = S390_CPU_TYPE_NAME("qemu"),
264 .parent = TYPE_S390_CPU,
265 .instance_init = s390_qemu_cpu_model_initfn,
266 .instance_finalize = s390_cpu_model_finalize,
267 .class_init = s390_qemu_cpu_model_class_init,
268};
269
270#ifdef CONFIG_KVM
271static const TypeInfo host_s390_cpu_type_info = {
272 .name = S390_CPU_TYPE_NAME("host"),
273 .parent = TYPE_S390_CPU,
274 .instance_init = s390_host_cpu_model_initfn,
275 .instance_finalize = s390_cpu_model_finalize,
276 .class_init = s390_host_cpu_model_class_init,
277};
278#endif
279
280static void register_types(void)
281{
6c064de1
DH
282 int i;
283
284 /* init all bitmaps from gnerated data initially */
285 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
286 s390_init_feat_bitmap(s390_cpu_defs[i].base_init,
287 s390_cpu_defs[i].base_feat);
288 s390_init_feat_bitmap(s390_cpu_defs[i].default_init,
289 s390_cpu_defs[i].default_feat);
290 s390_init_feat_bitmap(s390_cpu_defs[i].full_init,
291 s390_cpu_defs[i].full_feat);
292 }
293
294 for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
295 char *base_name = s390_base_cpu_type_name(s390_cpu_defs[i].name);
296 TypeInfo ti_base = {
297 .name = base_name,
298 .parent = TYPE_S390_CPU,
299 .instance_init = s390_cpu_model_initfn,
300 .instance_finalize = s390_cpu_model_finalize,
301 .class_init = s390_base_cpu_model_class_init,
302 .class_data = (void *) &s390_cpu_defs[i],
303 };
304 char *name = s390_cpu_type_name(s390_cpu_defs[i].name);
305 TypeInfo ti = {
306 .name = name,
307 .parent = TYPE_S390_CPU,
308 .instance_init = s390_cpu_model_initfn,
309 .instance_finalize = s390_cpu_model_finalize,
310 .class_init = s390_cpu_model_class_init,
311 .class_data = (void *) &s390_cpu_defs[i],
312 };
313
314 type_register_static(&ti_base);
315 type_register_static(&ti);
316 g_free(base_name);
317 g_free(name);
318 }
319
41868f84
DH
320 type_register_static(&qemu_s390_cpu_type_info);
321#ifdef CONFIG_KVM
322 type_register_static(&host_s390_cpu_type_info);
323#endif
324}
325
326type_init(register_types)