blob: c0bee15d7aade070ce3161d2406a25038f914c46 [file] [log] [blame]
David Hildenbrand6c064de2016-09-05 10:52:22 +02001/*
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#ifndef TARGET_S390X_CPU_MODELS_H
14#define TARGET_S390X_CPU_MODELS_H
15
16#include "cpu_features.h"
17#include "qom/cpu.h"
18
19/* static CPU definition */
20typedef struct S390CPUDef {
21 const char *name; /* name exposed to the user */
22 const char *desc; /* description exposed to the user */
23 uint8_t gen; /* hw generation identification */
24 uint16_t type; /* cpu type identification */
25 uint8_t ec_ga; /* EC GA version (on which also the BC is based) */
26 uint8_t mha_pow; /* Maximum Host Adress Power, mha = 2^pow-1 */
27 uint32_t hmfai; /* hypervisor-managed facilities */
28 /* base/min features, must never be changed between QEMU versions */
29 S390FeatBitmap base_feat;
30 /* used to init base_feat from generated data */
31 S390FeatInit base_init;
32 /* deafault features, QEMU version specific */
33 S390FeatBitmap default_feat;
34 /* used to init default_feat from generated data */
35 S390FeatInit default_init;
36 /* max allowed features, QEMU version specific */
37 S390FeatBitmap full_feat;
38 /* used to init full_feat from generated data */
39 S390FeatInit full_init;
40} S390CPUDef;
41
David Hildenbrandad5afd02016-09-05 10:52:23 +020042/* CPU model based on a CPU definition */
43typedef struct S390CPUModel {
44 const S390CPUDef *def;
45 S390FeatBitmap features;
46 /* values copied from the "host" model, can change during migration */
47 uint16_t lowest_ibc; /* lowest IBC that the hardware supports */
48 uint32_t cpu_id; /* CPU id */
David Hildenbrand64bc98f2017-05-31 21:34:33 +020049 uint8_t cpu_id_format; /* CPU id format bit */
David Hildenbrandad5afd02016-09-05 10:52:23 +020050 uint8_t cpu_ver; /* CPU version, usually "ff" for kvm */
51} S390CPUModel;
52
David Hildenbrand3b84c252016-09-05 10:52:35 +020053/*
54 * CPU ID
55 *
56 * bits 0-7: Zeroes (ff for kvm)
57 * bits 8-31: CPU ID (serial number)
David Hildenbrand64bc98f2017-05-31 21:34:33 +020058 * bits 32-47: Machine type
59 * bit 48: CPU ID format
60 * bits 49-63: Zeroes
David Hildenbrand3b84c252016-09-05 10:52:35 +020061 */
62#define cpuid_type(x) (((x) >> 16) & 0xffff)
63#define cpuid_id(x) (((x) >> 32) & 0xffffff)
64#define cpuid_ver(x) (((x) >> 56) & 0xff)
David Hildenbrand64bc98f2017-05-31 21:34:33 +020065#define cpuid_format(x) (((x) >> 15) & 0x1)
David Hildenbrand3b84c252016-09-05 10:52:35 +020066
67#define lowest_ibc(x) (((uint32_t)(x) >> 16) & 0xfff)
68#define unblocked_ibc(x) ((uint32_t)(x) & 0xfff)
69#define has_ibc(x) (lowest_ibc(x) != 0)
70
David Hildenbrand059be522016-09-05 10:52:30 +020071#define S390_GEN_Z10 0xa
David Hildenbrand3b84c252016-09-05 10:52:35 +020072#define ibc_gen(x) (x == 0 ? 0 : ((x >> 4) + S390_GEN_Z10))
73#define ibc_ec_ga(x) (x & 0xf)
David Hildenbrand059be522016-09-05 10:52:30 +020074
Jason J. Hernec9ad8a72017-04-10 09:39:00 -040075void s390_cpudef_featoff(uint8_t gen, uint8_t ec_ga, S390Feat feat);
76void s390_cpudef_featoff_greater(uint8_t gen, uint8_t ec_ga, S390Feat feat);
David Hildenbranda3669302016-09-05 10:52:32 +020077uint32_t s390_get_hmfai(void);
David Hildenbrand3fad3252016-09-05 10:52:31 +020078uint8_t s390_get_mha_pow(void);
David Hildenbrand059be522016-09-05 10:52:30 +020079uint32_t s390_get_ibc_val(void);
80static inline uint16_t s390_ibc_from_cpu_model(const S390CPUModel *model)
81{
82 uint16_t ibc = 0;
83
84 if (model->def->gen >= S390_GEN_Z10) {
85 ibc = ((model->def->gen - S390_GEN_Z10) << 4) + model->def->ec_ga;
86 }
87 return ibc;
88}
David Hildenbrand4dd42002016-09-05 10:52:29 +020089void s390_get_feat_block(S390FeatType type, uint8_t *data);
David Hildenbrand7c72ac42016-09-05 10:52:25 +020090bool s390_has_feat(S390Feat feat);
David Hildenbrand3b84c252016-09-05 10:52:35 +020091uint8_t s390_get_gen_for_cpu_type(uint16_t type);
92static inline bool s390_known_cpu_type(uint16_t type)
93{
94 return s390_get_gen_for_cpu_type(type) != 0;
95}
96static inline uint64_t s390_cpuid_from_cpu_model(const S390CPUModel *model)
97{
98 return ((uint64_t)model->cpu_ver << 56) |
99 ((uint64_t)model->cpu_id << 32) |
David Hildenbrand64bc98f2017-05-31 21:34:33 +0200100 ((uint64_t)model->def->type << 16) |
101 (model->def->gen == 7 ? 0 : (uint64_t)model->cpu_id_format << 15);
David Hildenbrand3b84c252016-09-05 10:52:35 +0200102}
103S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
104 S390FeatBitmap features);
105
106#ifdef CONFIG_KVM
107bool kvm_s390_cpu_models_supported(void);
108void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp);
109void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp);
110#else
111static inline void kvm_s390_get_host_cpu_model(S390CPUModel *model,
112 Error **errp)
113{
114}
115static inline void kvm_s390_apply_cpu_model(const S390CPUModel *model,
116 Error **errp)
117{
118}
119static inline bool kvm_s390_cpu_models_supported(void)
120{
121 return false;
122}
123#endif
David Hildenbrand7c72ac42016-09-05 10:52:25 +0200124
David Hildenbrand6c064de2016-09-05 10:52:22 +0200125#endif /* TARGET_S390X_CPU_MODELS_H */