xref: /openbmc/qemu/target/arm/cpu64.c (revision d0bf492f)
1 /*
2  * QEMU AArch64 CPU
3  *
4  * Copyright (c) 2013 Linaro Ltd
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <http://www.gnu.org/licenses/gpl-2.0.html>
19  */
20 
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "cpu.h"
24 #include "cpregs.h"
25 #include "qemu/module.h"
26 #include "sysemu/kvm.h"
27 #include "sysemu/hvf.h"
28 #include "sysemu/qtest.h"
29 #include "sysemu/tcg.h"
30 #include "kvm_arm.h"
31 #include "hvf_arm.h"
32 #include "qapi/visitor.h"
33 #include "hw/qdev-properties.h"
34 #include "internals.h"
35 #include "cpregs.h"
36 
37 void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp)
38 {
39     /*
40      * If any vector lengths are explicitly enabled with sve<N> properties,
41      * then all other lengths are implicitly disabled.  If sve-max-vq is
42      * specified then it is the same as explicitly enabling all lengths
43      * up to and including the specified maximum, which means all larger
44      * lengths will be implicitly disabled.  If no sve<N> properties
45      * are enabled and sve-max-vq is not specified, then all lengths not
46      * explicitly disabled will be enabled.  Additionally, all power-of-two
47      * vector lengths less than the maximum enabled length will be
48      * automatically enabled and all vector lengths larger than the largest
49      * disabled power-of-two vector length will be automatically disabled.
50      * Errors are generated if the user provided input that interferes with
51      * any of the above.  Finally, if SVE is not disabled, then at least one
52      * vector length must be enabled.
53      */
54     uint32_t vq_map = cpu->sve_vq.map;
55     uint32_t vq_init = cpu->sve_vq.init;
56     uint32_t vq_supported;
57     uint32_t vq_mask = 0;
58     uint32_t tmp, vq, max_vq = 0;
59 
60     /*
61      * CPU models specify a set of supported vector lengths which are
62      * enabled by default.  Attempting to enable any vector length not set
63      * in the supported bitmap results in an error.  When KVM is enabled we
64      * fetch the supported bitmap from the host.
65      */
66     if (kvm_enabled()) {
67         if (kvm_arm_sve_supported()) {
68             cpu->sve_vq.supported = kvm_arm_sve_get_vls(CPU(cpu));
69             vq_supported = cpu->sve_vq.supported;
70         } else {
71             assert(!cpu_isar_feature(aa64_sve, cpu));
72             vq_supported = 0;
73         }
74     } else {
75         vq_supported = cpu->sve_vq.supported;
76     }
77 
78     /*
79      * Process explicit sve<N> properties.
80      * From the properties, sve_vq_map<N> implies sve_vq_init<N>.
81      * Check first for any sve<N> enabled.
82      */
83     if (vq_map != 0) {
84         max_vq = 32 - clz32(vq_map);
85         vq_mask = MAKE_64BIT_MASK(0, max_vq);
86 
87         if (cpu->sve_max_vq && max_vq > cpu->sve_max_vq) {
88             error_setg(errp, "cannot enable sve%d", max_vq * 128);
89             error_append_hint(errp, "sve%d is larger than the maximum vector "
90                               "length, sve-max-vq=%d (%d bits)\n",
91                               max_vq * 128, cpu->sve_max_vq,
92                               cpu->sve_max_vq * 128);
93             return;
94         }
95 
96         if (kvm_enabled()) {
97             /*
98              * For KVM we have to automatically enable all supported unitialized
99              * lengths, even when the smaller lengths are not all powers-of-two.
100              */
101             vq_map |= vq_supported & ~vq_init & vq_mask;
102         } else {
103             /* Propagate enabled bits down through required powers-of-two. */
104             vq_map |= SVE_VQ_POW2_MAP & ~vq_init & vq_mask;
105         }
106     } else if (cpu->sve_max_vq == 0) {
107         /*
108          * No explicit bits enabled, and no implicit bits from sve-max-vq.
109          */
110         if (!cpu_isar_feature(aa64_sve, cpu)) {
111             /* SVE is disabled and so are all vector lengths.  Good. */
112             return;
113         }
114 
115         if (kvm_enabled()) {
116             /* Disabling a supported length disables all larger lengths. */
117             tmp = vq_init & vq_supported;
118         } else {
119             /* Disabling a power-of-two disables all larger lengths. */
120             tmp = vq_init & SVE_VQ_POW2_MAP;
121         }
122         vq = ctz32(tmp) + 1;
123 
124         max_vq = vq <= ARM_MAX_VQ ? vq - 1 : ARM_MAX_VQ;
125         vq_mask = max_vq > 0 ? MAKE_64BIT_MASK(0, max_vq) : 0;
126         vq_map = vq_supported & ~vq_init & vq_mask;
127 
128         if (vq_map == 0) {
129             error_setg(errp, "cannot disable sve%d", vq * 128);
130             error_append_hint(errp, "Disabling sve%d results in all "
131                               "vector lengths being disabled.\n",
132                               vq * 128);
133             error_append_hint(errp, "With SVE enabled, at least one "
134                               "vector length must be enabled.\n");
135             return;
136         }
137 
138         max_vq = 32 - clz32(vq_map);
139         vq_mask = MAKE_64BIT_MASK(0, max_vq);
140     }
141 
142     /*
143      * Process the sve-max-vq property.
144      * Note that we know from the above that no bit above
145      * sve-max-vq is currently set.
146      */
147     if (cpu->sve_max_vq != 0) {
148         max_vq = cpu->sve_max_vq;
149         vq_mask = MAKE_64BIT_MASK(0, max_vq);
150 
151         if (vq_init & ~vq_map & (1 << (max_vq - 1))) {
152             error_setg(errp, "cannot disable sve%d", max_vq * 128);
153             error_append_hint(errp, "The maximum vector length must be "
154                               "enabled, sve-max-vq=%d (%d bits)\n",
155                               max_vq, max_vq * 128);
156             return;
157         }
158 
159         /* Set all bits not explicitly set within sve-max-vq. */
160         vq_map |= ~vq_init & vq_mask;
161     }
162 
163     /*
164      * We should know what max-vq is now.  Also, as we're done
165      * manipulating sve-vq-map, we ensure any bits above max-vq
166      * are clear, just in case anybody looks.
167      */
168     assert(max_vq != 0);
169     assert(vq_mask != 0);
170     vq_map &= vq_mask;
171 
172     /* Ensure the set of lengths matches what is supported. */
173     tmp = vq_map ^ (vq_supported & vq_mask);
174     if (tmp) {
175         vq = 32 - clz32(tmp);
176         if (vq_map & (1 << (vq - 1))) {
177             if (cpu->sve_max_vq) {
178                 error_setg(errp, "cannot set sve-max-vq=%d", cpu->sve_max_vq);
179                 error_append_hint(errp, "This CPU does not support "
180                                   "the vector length %d-bits.\n", vq * 128);
181                 error_append_hint(errp, "It may not be possible to use "
182                                   "sve-max-vq with this CPU. Try "
183                                   "using only sve<N> properties.\n");
184             } else {
185                 error_setg(errp, "cannot enable sve%d", vq * 128);
186                 if (vq_supported) {
187                     error_append_hint(errp, "This CPU does not support "
188                                       "the vector length %d-bits.\n", vq * 128);
189                 } else {
190                     error_append_hint(errp, "SVE not supported by KVM "
191                                       "on this host\n");
192                 }
193             }
194             return;
195         } else {
196             if (kvm_enabled()) {
197                 error_setg(errp, "cannot disable sve%d", vq * 128);
198                 error_append_hint(errp, "The KVM host requires all "
199                                   "supported vector lengths smaller "
200                                   "than %d bits to also be enabled.\n",
201                                   max_vq * 128);
202                 return;
203             } else {
204                 /* Ensure all required powers-of-two are enabled. */
205                 tmp = SVE_VQ_POW2_MAP & vq_mask & ~vq_map;
206                 if (tmp) {
207                     vq = 32 - clz32(tmp);
208                     error_setg(errp, "cannot disable sve%d", vq * 128);
209                     error_append_hint(errp, "sve%d is required as it "
210                                       "is a power-of-two length smaller "
211                                       "than the maximum, sve%d\n",
212                                       vq * 128, max_vq * 128);
213                     return;
214                 }
215             }
216         }
217     }
218 
219     /*
220      * Now that we validated all our vector lengths, the only question
221      * left to answer is if we even want SVE at all.
222      */
223     if (!cpu_isar_feature(aa64_sve, cpu)) {
224         error_setg(errp, "cannot enable sve%d", max_vq * 128);
225         error_append_hint(errp, "SVE must be enabled to enable vector "
226                           "lengths.\n");
227         error_append_hint(errp, "Add sve=on to the CPU property list.\n");
228         return;
229     }
230 
231     /* From now on sve_max_vq is the actual maximum supported length. */
232     cpu->sve_max_vq = max_vq;
233     cpu->sve_vq.map = vq_map;
234 }
235 
236 /*
237  * Note that cpu_arm_{get,set}_vq cannot use the simpler
238  * object_property_add_bool interface because they make use of the
239  * contents of "name" to determine which bit on which to operate.
240  */
241 static void cpu_arm_get_vq(Object *obj, Visitor *v, const char *name,
242                            void *opaque, Error **errp)
243 {
244     ARMCPU *cpu = ARM_CPU(obj);
245     ARMVQMap *vq_map = opaque;
246     uint32_t vq = atoi(&name[3]) / 128;
247     bool sve = vq_map == &cpu->sve_vq;
248     bool value;
249 
250     /* All vector lengths are disabled when feature is off. */
251     if (sve
252         ? !cpu_isar_feature(aa64_sve, cpu)
253         : !cpu_isar_feature(aa64_sme, cpu)) {
254         value = false;
255     } else {
256         value = extract32(vq_map->map, vq - 1, 1);
257     }
258     visit_type_bool(v, name, &value, errp);
259 }
260 
261 static void cpu_arm_set_vq(Object *obj, Visitor *v, const char *name,
262                            void *opaque, Error **errp)
263 {
264     ARMVQMap *vq_map = opaque;
265     uint32_t vq = atoi(&name[3]) / 128;
266     bool value;
267 
268     if (!visit_type_bool(v, name, &value, errp)) {
269         return;
270     }
271 
272     vq_map->map = deposit32(vq_map->map, vq - 1, 1, value);
273     vq_map->init |= 1 << (vq - 1);
274 }
275 
276 static bool cpu_arm_get_sve(Object *obj, Error **errp)
277 {
278     ARMCPU *cpu = ARM_CPU(obj);
279     return cpu_isar_feature(aa64_sve, cpu);
280 }
281 
282 static void cpu_arm_set_sve(Object *obj, bool value, Error **errp)
283 {
284     ARMCPU *cpu = ARM_CPU(obj);
285     uint64_t t;
286 
287     if (value && kvm_enabled() && !kvm_arm_sve_supported()) {
288         error_setg(errp, "'sve' feature not supported by KVM on this host");
289         return;
290     }
291 
292     t = cpu->isar.id_aa64pfr0;
293     t = FIELD_DP64(t, ID_AA64PFR0, SVE, value);
294     cpu->isar.id_aa64pfr0 = t;
295 }
296 
297 void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp)
298 {
299     uint32_t vq_map = cpu->sme_vq.map;
300     uint32_t vq_init = cpu->sme_vq.init;
301     uint32_t vq_supported = cpu->sme_vq.supported;
302     uint32_t vq;
303 
304     if (vq_map == 0) {
305         if (!cpu_isar_feature(aa64_sme, cpu)) {
306             cpu->isar.id_aa64smfr0 = 0;
307             return;
308         }
309 
310         /* TODO: KVM will require limitations via SMCR_EL2. */
311         vq_map = vq_supported & ~vq_init;
312 
313         if (vq_map == 0) {
314             vq = ctz32(vq_supported) + 1;
315             error_setg(errp, "cannot disable sme%d", vq * 128);
316             error_append_hint(errp, "All SME vector lengths are disabled.\n");
317             error_append_hint(errp, "With SME enabled, at least one "
318                               "vector length must be enabled.\n");
319             return;
320         }
321     } else {
322         if (!cpu_isar_feature(aa64_sme, cpu)) {
323             vq = 32 - clz32(vq_map);
324             error_setg(errp, "cannot enable sme%d", vq * 128);
325             error_append_hint(errp, "SME must be enabled to enable "
326                               "vector lengths.\n");
327             error_append_hint(errp, "Add sme=on to the CPU property list.\n");
328             return;
329         }
330         /* TODO: KVM will require limitations via SMCR_EL2. */
331     }
332 
333     cpu->sme_vq.map = vq_map;
334 }
335 
336 static bool cpu_arm_get_sme(Object *obj, Error **errp)
337 {
338     ARMCPU *cpu = ARM_CPU(obj);
339     return cpu_isar_feature(aa64_sme, cpu);
340 }
341 
342 static void cpu_arm_set_sme(Object *obj, bool value, Error **errp)
343 {
344     ARMCPU *cpu = ARM_CPU(obj);
345     uint64_t t;
346 
347     t = cpu->isar.id_aa64pfr1;
348     t = FIELD_DP64(t, ID_AA64PFR1, SME, value);
349     cpu->isar.id_aa64pfr1 = t;
350 }
351 
352 static bool cpu_arm_get_sme_fa64(Object *obj, Error **errp)
353 {
354     ARMCPU *cpu = ARM_CPU(obj);
355     return cpu_isar_feature(aa64_sme, cpu) &&
356            cpu_isar_feature(aa64_sme_fa64, cpu);
357 }
358 
359 static void cpu_arm_set_sme_fa64(Object *obj, bool value, Error **errp)
360 {
361     ARMCPU *cpu = ARM_CPU(obj);
362     uint64_t t;
363 
364     t = cpu->isar.id_aa64smfr0;
365     t = FIELD_DP64(t, ID_AA64SMFR0, FA64, value);
366     cpu->isar.id_aa64smfr0 = t;
367 }
368 
369 #ifdef CONFIG_USER_ONLY
370 /* Mirror linux /proc/sys/abi/{sve,sme}_default_vector_length. */
371 static void cpu_arm_set_default_vec_len(Object *obj, Visitor *v,
372                                         const char *name, void *opaque,
373                                         Error **errp)
374 {
375     uint32_t *ptr_default_vq = opaque;
376     int32_t default_len, default_vq, remainder;
377 
378     if (!visit_type_int32(v, name, &default_len, errp)) {
379         return;
380     }
381 
382     /* Undocumented, but the kernel allows -1 to indicate "maximum". */
383     if (default_len == -1) {
384         *ptr_default_vq = ARM_MAX_VQ;
385         return;
386     }
387 
388     default_vq = default_len / 16;
389     remainder = default_len % 16;
390 
391     /*
392      * Note that the 512 max comes from include/uapi/asm/sve_context.h
393      * and is the maximum architectural width of ZCR_ELx.LEN.
394      */
395     if (remainder || default_vq < 1 || default_vq > 512) {
396         ARMCPU *cpu = ARM_CPU(obj);
397         const char *which =
398             (ptr_default_vq == &cpu->sve_default_vq ? "sve" : "sme");
399 
400         error_setg(errp, "cannot set %s-default-vector-length", which);
401         if (remainder) {
402             error_append_hint(errp, "Vector length not a multiple of 16\n");
403         } else if (default_vq < 1) {
404             error_append_hint(errp, "Vector length smaller than 16\n");
405         } else {
406             error_append_hint(errp, "Vector length larger than %d\n",
407                               512 * 16);
408         }
409         return;
410     }
411 
412     *ptr_default_vq = default_vq;
413 }
414 
415 static void cpu_arm_get_default_vec_len(Object *obj, Visitor *v,
416                                         const char *name, void *opaque,
417                                         Error **errp)
418 {
419     uint32_t *ptr_default_vq = opaque;
420     int32_t value = *ptr_default_vq * 16;
421 
422     visit_type_int32(v, name, &value, errp);
423 }
424 #endif
425 
426 void aarch64_add_sve_properties(Object *obj)
427 {
428     ARMCPU *cpu = ARM_CPU(obj);
429     uint32_t vq;
430 
431     object_property_add_bool(obj, "sve", cpu_arm_get_sve, cpu_arm_set_sve);
432 
433     for (vq = 1; vq <= ARM_MAX_VQ; ++vq) {
434         char name[8];
435         sprintf(name, "sve%d", vq * 128);
436         object_property_add(obj, name, "bool", cpu_arm_get_vq,
437                             cpu_arm_set_vq, NULL, &cpu->sve_vq);
438     }
439 
440 #ifdef CONFIG_USER_ONLY
441     /* Mirror linux /proc/sys/abi/sve_default_vector_length. */
442     object_property_add(obj, "sve-default-vector-length", "int32",
443                         cpu_arm_get_default_vec_len,
444                         cpu_arm_set_default_vec_len, NULL,
445                         &cpu->sve_default_vq);
446 #endif
447 }
448 
449 void aarch64_add_sme_properties(Object *obj)
450 {
451     ARMCPU *cpu = ARM_CPU(obj);
452     uint32_t vq;
453 
454     object_property_add_bool(obj, "sme", cpu_arm_get_sme, cpu_arm_set_sme);
455     object_property_add_bool(obj, "sme_fa64", cpu_arm_get_sme_fa64,
456                              cpu_arm_set_sme_fa64);
457 
458     for (vq = 1; vq <= ARM_MAX_VQ; vq <<= 1) {
459         char name[8];
460         sprintf(name, "sme%d", vq * 128);
461         object_property_add(obj, name, "bool", cpu_arm_get_vq,
462                             cpu_arm_set_vq, NULL, &cpu->sme_vq);
463     }
464 
465 #ifdef CONFIG_USER_ONLY
466     /* Mirror linux /proc/sys/abi/sme_default_vector_length. */
467     object_property_add(obj, "sme-default-vector-length", "int32",
468                         cpu_arm_get_default_vec_len,
469                         cpu_arm_set_default_vec_len, NULL,
470                         &cpu->sme_default_vq);
471 #endif
472 }
473 
474 void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp)
475 {
476     int arch_val = 0, impdef_val = 0;
477     uint64_t t;
478 
479     /* Exit early if PAuth is enabled, and fall through to disable it */
480     if ((kvm_enabled() || hvf_enabled()) && cpu->prop_pauth) {
481         if (!cpu_isar_feature(aa64_pauth, cpu)) {
482             error_setg(errp, "'pauth' feature not supported by %s on this host",
483                        kvm_enabled() ? "KVM" : "hvf");
484         }
485 
486         return;
487     }
488 
489     /* TODO: Handle HaveEnhancedPAC, HaveEnhancedPAC2, HaveFPAC. */
490     if (cpu->prop_pauth) {
491         if (cpu->prop_pauth_impdef) {
492             impdef_val = 1;
493         } else {
494             arch_val = 1;
495         }
496     } else if (cpu->prop_pauth_impdef) {
497         error_setg(errp, "cannot enable pauth-impdef without pauth");
498         error_append_hint(errp, "Add pauth=on to the CPU property list.\n");
499     }
500 
501     t = cpu->isar.id_aa64isar1;
502     t = FIELD_DP64(t, ID_AA64ISAR1, APA, arch_val);
503     t = FIELD_DP64(t, ID_AA64ISAR1, GPA, arch_val);
504     t = FIELD_DP64(t, ID_AA64ISAR1, API, impdef_val);
505     t = FIELD_DP64(t, ID_AA64ISAR1, GPI, impdef_val);
506     cpu->isar.id_aa64isar1 = t;
507 }
508 
509 static Property arm_cpu_pauth_property =
510     DEFINE_PROP_BOOL("pauth", ARMCPU, prop_pauth, true);
511 static Property arm_cpu_pauth_impdef_property =
512     DEFINE_PROP_BOOL("pauth-impdef", ARMCPU, prop_pauth_impdef, false);
513 
514 void aarch64_add_pauth_properties(Object *obj)
515 {
516     ARMCPU *cpu = ARM_CPU(obj);
517 
518     /* Default to PAUTH on, with the architected algorithm on TCG. */
519     qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_property);
520     if (kvm_enabled() || hvf_enabled()) {
521         /*
522          * Mirror PAuth support from the probed sysregs back into the
523          * property for KVM or hvf. Is it just a bit backward? Yes it is!
524          * Note that prop_pauth is true whether the host CPU supports the
525          * architected QARMA5 algorithm or the IMPDEF one. We don't
526          * provide the separate pauth-impdef property for KVM or hvf,
527          * only for TCG.
528          */
529         cpu->prop_pauth = cpu_isar_feature(aa64_pauth, cpu);
530     } else {
531         qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_impdef_property);
532     }
533 }
534 
535 void arm_cpu_lpa2_finalize(ARMCPU *cpu, Error **errp)
536 {
537     uint64_t t;
538 
539     /*
540      * We only install the property for tcg -cpu max; this is the
541      * only situation in which the cpu field can be true.
542      */
543     if (!cpu->prop_lpa2) {
544         return;
545     }
546 
547     t = cpu->isar.id_aa64mmfr0;
548     t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16, 2);   /* 16k pages w/ LPA2 */
549     t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4, 1);    /*  4k pages w/ LPA2 */
550     t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16_2, 3); /* 16k stage2 w/ LPA2 */
551     t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4_2, 3);  /*  4k stage2 w/ LPA2 */
552     cpu->isar.id_aa64mmfr0 = t;
553 }
554 
555 static void aarch64_a57_initfn(Object *obj)
556 {
557     ARMCPU *cpu = ARM_CPU(obj);
558 
559     cpu->dtb_compatible = "arm,cortex-a57";
560     set_feature(&cpu->env, ARM_FEATURE_V8);
561     set_feature(&cpu->env, ARM_FEATURE_NEON);
562     set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
563     set_feature(&cpu->env, ARM_FEATURE_AARCH64);
564     set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
565     set_feature(&cpu->env, ARM_FEATURE_EL2);
566     set_feature(&cpu->env, ARM_FEATURE_EL3);
567     set_feature(&cpu->env, ARM_FEATURE_PMU);
568     cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A57;
569     cpu->midr = 0x411fd070;
570     cpu->revidr = 0x00000000;
571     cpu->reset_fpsid = 0x41034070;
572     cpu->isar.mvfr0 = 0x10110222;
573     cpu->isar.mvfr1 = 0x12111111;
574     cpu->isar.mvfr2 = 0x00000043;
575     cpu->ctr = 0x8444c004;
576     cpu->reset_sctlr = 0x00c50838;
577     cpu->isar.id_pfr0 = 0x00000131;
578     cpu->isar.id_pfr1 = 0x00011011;
579     cpu->isar.id_dfr0 = 0x03010066;
580     cpu->id_afr0 = 0x00000000;
581     cpu->isar.id_mmfr0 = 0x10101105;
582     cpu->isar.id_mmfr1 = 0x40000000;
583     cpu->isar.id_mmfr2 = 0x01260000;
584     cpu->isar.id_mmfr3 = 0x02102211;
585     cpu->isar.id_isar0 = 0x02101110;
586     cpu->isar.id_isar1 = 0x13112111;
587     cpu->isar.id_isar2 = 0x21232042;
588     cpu->isar.id_isar3 = 0x01112131;
589     cpu->isar.id_isar4 = 0x00011142;
590     cpu->isar.id_isar5 = 0x00011121;
591     cpu->isar.id_isar6 = 0;
592     cpu->isar.id_aa64pfr0 = 0x00002222;
593     cpu->isar.id_aa64dfr0 = 0x10305106;
594     cpu->isar.id_aa64isar0 = 0x00011120;
595     cpu->isar.id_aa64mmfr0 = 0x00001124;
596     cpu->isar.dbgdidr = 0x3516d000;
597     cpu->isar.dbgdevid = 0x01110f13;
598     cpu->isar.dbgdevid1 = 0x2;
599     cpu->isar.reset_pmcr_el0 = 0x41013000;
600     cpu->clidr = 0x0a200023;
601     cpu->ccsidr[0] = 0x701fe00a; /* 32KB L1 dcache */
602     cpu->ccsidr[1] = 0x201fe012; /* 48KB L1 icache */
603     cpu->ccsidr[2] = 0x70ffe07a; /* 2048KB L2 cache */
604     cpu->dcz_blocksize = 4; /* 64 bytes */
605     cpu->gic_num_lrs = 4;
606     cpu->gic_vpribits = 5;
607     cpu->gic_vprebits = 5;
608     cpu->gic_pribits = 5;
609     define_cortex_a72_a57_a53_cp_reginfo(cpu);
610 }
611 
612 static void aarch64_a53_initfn(Object *obj)
613 {
614     ARMCPU *cpu = ARM_CPU(obj);
615 
616     cpu->dtb_compatible = "arm,cortex-a53";
617     set_feature(&cpu->env, ARM_FEATURE_V8);
618     set_feature(&cpu->env, ARM_FEATURE_NEON);
619     set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
620     set_feature(&cpu->env, ARM_FEATURE_AARCH64);
621     set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
622     set_feature(&cpu->env, ARM_FEATURE_EL2);
623     set_feature(&cpu->env, ARM_FEATURE_EL3);
624     set_feature(&cpu->env, ARM_FEATURE_PMU);
625     cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A53;
626     cpu->midr = 0x410fd034;
627     cpu->revidr = 0x00000000;
628     cpu->reset_fpsid = 0x41034070;
629     cpu->isar.mvfr0 = 0x10110222;
630     cpu->isar.mvfr1 = 0x12111111;
631     cpu->isar.mvfr2 = 0x00000043;
632     cpu->ctr = 0x84448004; /* L1Ip = VIPT */
633     cpu->reset_sctlr = 0x00c50838;
634     cpu->isar.id_pfr0 = 0x00000131;
635     cpu->isar.id_pfr1 = 0x00011011;
636     cpu->isar.id_dfr0 = 0x03010066;
637     cpu->id_afr0 = 0x00000000;
638     cpu->isar.id_mmfr0 = 0x10101105;
639     cpu->isar.id_mmfr1 = 0x40000000;
640     cpu->isar.id_mmfr2 = 0x01260000;
641     cpu->isar.id_mmfr3 = 0x02102211;
642     cpu->isar.id_isar0 = 0x02101110;
643     cpu->isar.id_isar1 = 0x13112111;
644     cpu->isar.id_isar2 = 0x21232042;
645     cpu->isar.id_isar3 = 0x01112131;
646     cpu->isar.id_isar4 = 0x00011142;
647     cpu->isar.id_isar5 = 0x00011121;
648     cpu->isar.id_isar6 = 0;
649     cpu->isar.id_aa64pfr0 = 0x00002222;
650     cpu->isar.id_aa64dfr0 = 0x10305106;
651     cpu->isar.id_aa64isar0 = 0x00011120;
652     cpu->isar.id_aa64mmfr0 = 0x00001122; /* 40 bit physical addr */
653     cpu->isar.dbgdidr = 0x3516d000;
654     cpu->isar.dbgdevid = 0x00110f13;
655     cpu->isar.dbgdevid1 = 0x1;
656     cpu->isar.reset_pmcr_el0 = 0x41033000;
657     cpu->clidr = 0x0a200023;
658     cpu->ccsidr[0] = 0x700fe01a; /* 32KB L1 dcache */
659     cpu->ccsidr[1] = 0x201fe00a; /* 32KB L1 icache */
660     cpu->ccsidr[2] = 0x707fe07a; /* 1024KB L2 cache */
661     cpu->dcz_blocksize = 4; /* 64 bytes */
662     cpu->gic_num_lrs = 4;
663     cpu->gic_vpribits = 5;
664     cpu->gic_vprebits = 5;
665     cpu->gic_pribits = 5;
666     define_cortex_a72_a57_a53_cp_reginfo(cpu);
667 }
668 
669 static void aarch64_host_initfn(Object *obj)
670 {
671 #if defined(CONFIG_KVM)
672     ARMCPU *cpu = ARM_CPU(obj);
673     kvm_arm_set_cpu_features_from_host(cpu);
674     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
675         aarch64_add_sve_properties(obj);
676         aarch64_add_pauth_properties(obj);
677     }
678 #elif defined(CONFIG_HVF)
679     ARMCPU *cpu = ARM_CPU(obj);
680     hvf_arm_set_cpu_features_from_host(cpu);
681     aarch64_add_pauth_properties(obj);
682 #else
683     g_assert_not_reached();
684 #endif
685 }
686 
687 static void aarch64_max_initfn(Object *obj)
688 {
689     if (kvm_enabled() || hvf_enabled()) {
690         /* With KVM or HVF, '-cpu max' is identical to '-cpu host' */
691         aarch64_host_initfn(obj);
692         return;
693     }
694 
695     if (tcg_enabled() || qtest_enabled()) {
696         aarch64_a57_initfn(obj);
697     }
698 
699     /* '-cpu max' for TCG: we currently do this as "A57 with extra things" */
700     if (tcg_enabled()) {
701         aarch64_max_tcg_initfn(obj);
702     }
703 }
704 
705 static const ARMCPUInfo aarch64_cpus[] = {
706     { .name = "cortex-a57",         .initfn = aarch64_a57_initfn },
707     { .name = "cortex-a53",         .initfn = aarch64_a53_initfn },
708     { .name = "max",                .initfn = aarch64_max_initfn },
709 #if defined(CONFIG_KVM) || defined(CONFIG_HVF)
710     { .name = "host",               .initfn = aarch64_host_initfn },
711 #endif
712 };
713 
714 static bool aarch64_cpu_get_aarch64(Object *obj, Error **errp)
715 {
716     ARMCPU *cpu = ARM_CPU(obj);
717 
718     return arm_feature(&cpu->env, ARM_FEATURE_AARCH64);
719 }
720 
721 static void aarch64_cpu_set_aarch64(Object *obj, bool value, Error **errp)
722 {
723     ARMCPU *cpu = ARM_CPU(obj);
724 
725     /* At this time, this property is only allowed if KVM is enabled.  This
726      * restriction allows us to avoid fixing up functionality that assumes a
727      * uniform execution state like do_interrupt.
728      */
729     if (value == false) {
730         if (!kvm_enabled() || !kvm_arm_aarch32_supported()) {
731             error_setg(errp, "'aarch64' feature cannot be disabled "
732                              "unless KVM is enabled and 32-bit EL1 "
733                              "is supported");
734             return;
735         }
736         unset_feature(&cpu->env, ARM_FEATURE_AARCH64);
737     } else {
738         set_feature(&cpu->env, ARM_FEATURE_AARCH64);
739     }
740 }
741 
742 static void aarch64_cpu_finalizefn(Object *obj)
743 {
744 }
745 
746 static gchar *aarch64_gdb_arch_name(CPUState *cs)
747 {
748     return g_strdup("aarch64");
749 }
750 
751 static void aarch64_cpu_class_init(ObjectClass *oc, void *data)
752 {
753     CPUClass *cc = CPU_CLASS(oc);
754 
755     cc->gdb_read_register = aarch64_cpu_gdb_read_register;
756     cc->gdb_write_register = aarch64_cpu_gdb_write_register;
757     cc->gdb_num_core_regs = 34;
758     cc->gdb_core_xml_file = "aarch64-core.xml";
759     cc->gdb_arch_name = aarch64_gdb_arch_name;
760 
761     object_class_property_add_bool(oc, "aarch64", aarch64_cpu_get_aarch64,
762                                    aarch64_cpu_set_aarch64);
763     object_class_property_set_description(oc, "aarch64",
764                                           "Set on/off to enable/disable aarch64 "
765                                           "execution state ");
766 }
767 
768 static void aarch64_cpu_instance_init(Object *obj)
769 {
770     ARMCPUClass *acc = ARM_CPU_GET_CLASS(obj);
771 
772     acc->info->initfn(obj);
773     arm_cpu_post_init(obj);
774 }
775 
776 static void cpu_register_class_init(ObjectClass *oc, void *data)
777 {
778     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
779 
780     acc->info = data;
781 }
782 
783 void aarch64_cpu_register(const ARMCPUInfo *info)
784 {
785     TypeInfo type_info = {
786         .parent = TYPE_AARCH64_CPU,
787         .instance_size = sizeof(ARMCPU),
788         .instance_init = aarch64_cpu_instance_init,
789         .class_size = sizeof(ARMCPUClass),
790         .class_init = info->class_init ?: cpu_register_class_init,
791         .class_data = (void *)info,
792     };
793 
794     type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
795     type_register(&type_info);
796     g_free((void *)type_info.name);
797 }
798 
799 static const TypeInfo aarch64_cpu_type_info = {
800     .name = TYPE_AARCH64_CPU,
801     .parent = TYPE_ARM_CPU,
802     .instance_size = sizeof(ARMCPU),
803     .instance_finalize = aarch64_cpu_finalizefn,
804     .abstract = true,
805     .class_size = sizeof(AArch64CPUClass),
806     .class_init = aarch64_cpu_class_init,
807 };
808 
809 static void aarch64_cpu_register_types(void)
810 {
811     size_t i;
812 
813     type_register_static(&aarch64_cpu_type_info);
814 
815     for (i = 0; i < ARRAY_SIZE(aarch64_cpus); ++i) {
816         aarch64_cpu_register(&aarch64_cpus[i]);
817     }
818 }
819 
820 type_init(aarch64_cpu_register_types)
821