Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / target / arm / cpu64.c
blob458d1cee01200826b7436410338d8738c44463ec
1 /*
2 * QEMU AArch64 CPU
4 * Copyright (c) 2013 Linaro Ltd
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.
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.
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>
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 "qemu/units.h"
27 #include "sysemu/kvm.h"
28 #include "sysemu/hvf.h"
29 #include "sysemu/qtest.h"
30 #include "sysemu/tcg.h"
31 #include "kvm_arm.h"
32 #include "hvf_arm.h"
33 #include "qapi/visitor.h"
34 #include "hw/qdev-properties.h"
35 #include "internals.h"
36 #include "cpu-features.h"
37 #include "cpregs.h"
39 void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp)
42 * If any vector lengths are explicitly enabled with sve<N> properties,
43 * then all other lengths are implicitly disabled. If sve-max-vq is
44 * specified then it is the same as explicitly enabling all lengths
45 * up to and including the specified maximum, which means all larger
46 * lengths will be implicitly disabled. If no sve<N> properties
47 * are enabled and sve-max-vq is not specified, then all lengths not
48 * explicitly disabled will be enabled. Additionally, all power-of-two
49 * vector lengths less than the maximum enabled length will be
50 * automatically enabled and all vector lengths larger than the largest
51 * disabled power-of-two vector length will be automatically disabled.
52 * Errors are generated if the user provided input that interferes with
53 * any of the above. Finally, if SVE is not disabled, then at least one
54 * vector length must be enabled.
56 uint32_t vq_map = cpu->sve_vq.map;
57 uint32_t vq_init = cpu->sve_vq.init;
58 uint32_t vq_supported;
59 uint32_t vq_mask = 0;
60 uint32_t tmp, vq, max_vq = 0;
63 * CPU models specify a set of supported vector lengths which are
64 * enabled by default. Attempting to enable any vector length not set
65 * in the supported bitmap results in an error. When KVM is enabled we
66 * fetch the supported bitmap from the host.
68 if (kvm_enabled()) {
69 if (kvm_arm_sve_supported()) {
70 cpu->sve_vq.supported = kvm_arm_sve_get_vls(cpu);
71 vq_supported = cpu->sve_vq.supported;
72 } else {
73 assert(!cpu_isar_feature(aa64_sve, cpu));
74 vq_supported = 0;
76 } else {
77 vq_supported = cpu->sve_vq.supported;
81 * Process explicit sve<N> properties.
82 * From the properties, sve_vq_map<N> implies sve_vq_init<N>.
83 * Check first for any sve<N> enabled.
85 if (vq_map != 0) {
86 max_vq = 32 - clz32(vq_map);
87 vq_mask = MAKE_64BIT_MASK(0, max_vq);
89 if (cpu->sve_max_vq && max_vq > cpu->sve_max_vq) {
90 error_setg(errp, "cannot enable sve%d", max_vq * 128);
91 error_append_hint(errp, "sve%d is larger than the maximum vector "
92 "length, sve-max-vq=%d (%d bits)\n",
93 max_vq * 128, cpu->sve_max_vq,
94 cpu->sve_max_vq * 128);
95 return;
98 if (kvm_enabled()) {
100 * For KVM we have to automatically enable all supported uninitialized
101 * lengths, even when the smaller lengths are not all powers-of-two.
103 vq_map |= vq_supported & ~vq_init & vq_mask;
104 } else {
105 /* Propagate enabled bits down through required powers-of-two. */
106 vq_map |= SVE_VQ_POW2_MAP & ~vq_init & vq_mask;
108 } else if (cpu->sve_max_vq == 0) {
110 * No explicit bits enabled, and no implicit bits from sve-max-vq.
112 if (!cpu_isar_feature(aa64_sve, cpu)) {
114 * SVE is disabled and so are all vector lengths. Good.
115 * Disable all SVE extensions as well.
117 cpu->isar.id_aa64zfr0 = 0;
118 return;
121 if (kvm_enabled()) {
122 /* Disabling a supported length disables all larger lengths. */
123 tmp = vq_init & vq_supported;
124 } else {
125 /* Disabling a power-of-two disables all larger lengths. */
126 tmp = vq_init & SVE_VQ_POW2_MAP;
128 vq = ctz32(tmp) + 1;
130 max_vq = vq <= ARM_MAX_VQ ? vq - 1 : ARM_MAX_VQ;
131 vq_mask = max_vq > 0 ? MAKE_64BIT_MASK(0, max_vq) : 0;
132 vq_map = vq_supported & ~vq_init & vq_mask;
134 if (vq_map == 0) {
135 error_setg(errp, "cannot disable sve%d", vq * 128);
136 error_append_hint(errp, "Disabling sve%d results in all "
137 "vector lengths being disabled.\n",
138 vq * 128);
139 error_append_hint(errp, "With SVE enabled, at least one "
140 "vector length must be enabled.\n");
141 return;
144 max_vq = 32 - clz32(vq_map);
145 vq_mask = MAKE_64BIT_MASK(0, max_vq);
149 * Process the sve-max-vq property.
150 * Note that we know from the above that no bit above
151 * sve-max-vq is currently set.
153 if (cpu->sve_max_vq != 0) {
154 max_vq = cpu->sve_max_vq;
155 vq_mask = MAKE_64BIT_MASK(0, max_vq);
157 if (vq_init & ~vq_map & (1 << (max_vq - 1))) {
158 error_setg(errp, "cannot disable sve%d", max_vq * 128);
159 error_append_hint(errp, "The maximum vector length must be "
160 "enabled, sve-max-vq=%d (%d bits)\n",
161 max_vq, max_vq * 128);
162 return;
165 /* Set all bits not explicitly set within sve-max-vq. */
166 vq_map |= ~vq_init & vq_mask;
170 * We should know what max-vq is now. Also, as we're done
171 * manipulating sve-vq-map, we ensure any bits above max-vq
172 * are clear, just in case anybody looks.
174 assert(max_vq != 0);
175 assert(vq_mask != 0);
176 vq_map &= vq_mask;
178 /* Ensure the set of lengths matches what is supported. */
179 tmp = vq_map ^ (vq_supported & vq_mask);
180 if (tmp) {
181 vq = 32 - clz32(tmp);
182 if (vq_map & (1 << (vq - 1))) {
183 if (cpu->sve_max_vq) {
184 error_setg(errp, "cannot set sve-max-vq=%d", cpu->sve_max_vq);
185 error_append_hint(errp, "This CPU does not support "
186 "the vector length %d-bits.\n", vq * 128);
187 error_append_hint(errp, "It may not be possible to use "
188 "sve-max-vq with this CPU. Try "
189 "using only sve<N> properties.\n");
190 } else {
191 error_setg(errp, "cannot enable sve%d", vq * 128);
192 if (vq_supported) {
193 error_append_hint(errp, "This CPU does not support "
194 "the vector length %d-bits.\n", vq * 128);
195 } else {
196 error_append_hint(errp, "SVE not supported by KVM "
197 "on this host\n");
200 return;
201 } else {
202 if (kvm_enabled()) {
203 error_setg(errp, "cannot disable sve%d", vq * 128);
204 error_append_hint(errp, "The KVM host requires all "
205 "supported vector lengths smaller "
206 "than %d bits to also be enabled.\n",
207 max_vq * 128);
208 return;
209 } else {
210 /* Ensure all required powers-of-two are enabled. */
211 tmp = SVE_VQ_POW2_MAP & vq_mask & ~vq_map;
212 if (tmp) {
213 vq = 32 - clz32(tmp);
214 error_setg(errp, "cannot disable sve%d", vq * 128);
215 error_append_hint(errp, "sve%d is required as it "
216 "is a power-of-two length smaller "
217 "than the maximum, sve%d\n",
218 vq * 128, max_vq * 128);
219 return;
226 * Now that we validated all our vector lengths, the only question
227 * left to answer is if we even want SVE at all.
229 if (!cpu_isar_feature(aa64_sve, cpu)) {
230 error_setg(errp, "cannot enable sve%d", max_vq * 128);
231 error_append_hint(errp, "SVE must be enabled to enable vector "
232 "lengths.\n");
233 error_append_hint(errp, "Add sve=on to the CPU property list.\n");
234 return;
237 /* From now on sve_max_vq is the actual maximum supported length. */
238 cpu->sve_max_vq = max_vq;
239 cpu->sve_vq.map = vq_map;
243 * Note that cpu_arm_{get,set}_vq cannot use the simpler
244 * object_property_add_bool interface because they make use of the
245 * contents of "name" to determine which bit on which to operate.
247 static void cpu_arm_get_vq(Object *obj, Visitor *v, const char *name,
248 void *opaque, Error **errp)
250 ARMCPU *cpu = ARM_CPU(obj);
251 ARMVQMap *vq_map = opaque;
252 uint32_t vq = atoi(&name[3]) / 128;
253 bool sve = vq_map == &cpu->sve_vq;
254 bool value;
256 /* All vector lengths are disabled when feature is off. */
257 if (sve
258 ? !cpu_isar_feature(aa64_sve, cpu)
259 : !cpu_isar_feature(aa64_sme, cpu)) {
260 value = false;
261 } else {
262 value = extract32(vq_map->map, vq - 1, 1);
264 visit_type_bool(v, name, &value, errp);
267 static void cpu_arm_set_vq(Object *obj, Visitor *v, const char *name,
268 void *opaque, Error **errp)
270 ARMVQMap *vq_map = opaque;
271 uint32_t vq = atoi(&name[3]) / 128;
272 bool value;
274 if (!visit_type_bool(v, name, &value, errp)) {
275 return;
278 vq_map->map = deposit32(vq_map->map, vq - 1, 1, value);
279 vq_map->init |= 1 << (vq - 1);
282 static bool cpu_arm_get_sve(Object *obj, Error **errp)
284 ARMCPU *cpu = ARM_CPU(obj);
285 return cpu_isar_feature(aa64_sve, cpu);
288 static void cpu_arm_set_sve(Object *obj, bool value, Error **errp)
290 ARMCPU *cpu = ARM_CPU(obj);
291 uint64_t t;
293 if (value && kvm_enabled() && !kvm_arm_sve_supported()) {
294 error_setg(errp, "'sve' feature not supported by KVM on this host");
295 return;
298 t = cpu->isar.id_aa64pfr0;
299 t = FIELD_DP64(t, ID_AA64PFR0, SVE, value);
300 cpu->isar.id_aa64pfr0 = t;
303 void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp)
305 uint32_t vq_map = cpu->sme_vq.map;
306 uint32_t vq_init = cpu->sme_vq.init;
307 uint32_t vq_supported = cpu->sme_vq.supported;
308 uint32_t vq;
310 if (vq_map == 0) {
311 if (!cpu_isar_feature(aa64_sme, cpu)) {
312 cpu->isar.id_aa64smfr0 = 0;
313 return;
316 /* TODO: KVM will require limitations via SMCR_EL2. */
317 vq_map = vq_supported & ~vq_init;
319 if (vq_map == 0) {
320 vq = ctz32(vq_supported) + 1;
321 error_setg(errp, "cannot disable sme%d", vq * 128);
322 error_append_hint(errp, "All SME vector lengths are disabled.\n");
323 error_append_hint(errp, "With SME enabled, at least one "
324 "vector length must be enabled.\n");
325 return;
327 } else {
328 if (!cpu_isar_feature(aa64_sme, cpu)) {
329 vq = 32 - clz32(vq_map);
330 error_setg(errp, "cannot enable sme%d", vq * 128);
331 error_append_hint(errp, "SME must be enabled to enable "
332 "vector lengths.\n");
333 error_append_hint(errp, "Add sme=on to the CPU property list.\n");
334 return;
336 /* TODO: KVM will require limitations via SMCR_EL2. */
339 cpu->sme_vq.map = vq_map;
342 static bool cpu_arm_get_sme(Object *obj, Error **errp)
344 ARMCPU *cpu = ARM_CPU(obj);
345 return cpu_isar_feature(aa64_sme, cpu);
348 static void cpu_arm_set_sme(Object *obj, bool value, Error **errp)
350 ARMCPU *cpu = ARM_CPU(obj);
351 uint64_t t;
353 t = cpu->isar.id_aa64pfr1;
354 t = FIELD_DP64(t, ID_AA64PFR1, SME, value);
355 cpu->isar.id_aa64pfr1 = t;
358 static bool cpu_arm_get_sme_fa64(Object *obj, Error **errp)
360 ARMCPU *cpu = ARM_CPU(obj);
361 return cpu_isar_feature(aa64_sme, cpu) &&
362 cpu_isar_feature(aa64_sme_fa64, cpu);
365 static void cpu_arm_set_sme_fa64(Object *obj, bool value, Error **errp)
367 ARMCPU *cpu = ARM_CPU(obj);
368 uint64_t t;
370 t = cpu->isar.id_aa64smfr0;
371 t = FIELD_DP64(t, ID_AA64SMFR0, FA64, value);
372 cpu->isar.id_aa64smfr0 = t;
375 #ifdef CONFIG_USER_ONLY
376 /* Mirror linux /proc/sys/abi/{sve,sme}_default_vector_length. */
377 static void cpu_arm_set_default_vec_len(Object *obj, Visitor *v,
378 const char *name, void *opaque,
379 Error **errp)
381 uint32_t *ptr_default_vq = opaque;
382 int32_t default_len, default_vq, remainder;
384 if (!visit_type_int32(v, name, &default_len, errp)) {
385 return;
388 /* Undocumented, but the kernel allows -1 to indicate "maximum". */
389 if (default_len == -1) {
390 *ptr_default_vq = ARM_MAX_VQ;
391 return;
394 default_vq = default_len / 16;
395 remainder = default_len % 16;
398 * Note that the 512 max comes from include/uapi/asm/sve_context.h
399 * and is the maximum architectural width of ZCR_ELx.LEN.
401 if (remainder || default_vq < 1 || default_vq > 512) {
402 ARMCPU *cpu = ARM_CPU(obj);
403 const char *which =
404 (ptr_default_vq == &cpu->sve_default_vq ? "sve" : "sme");
406 error_setg(errp, "cannot set %s-default-vector-length", which);
407 if (remainder) {
408 error_append_hint(errp, "Vector length not a multiple of 16\n");
409 } else if (default_vq < 1) {
410 error_append_hint(errp, "Vector length smaller than 16\n");
411 } else {
412 error_append_hint(errp, "Vector length larger than %d\n",
413 512 * 16);
415 return;
418 *ptr_default_vq = default_vq;
421 static void cpu_arm_get_default_vec_len(Object *obj, Visitor *v,
422 const char *name, void *opaque,
423 Error **errp)
425 uint32_t *ptr_default_vq = opaque;
426 int32_t value = *ptr_default_vq * 16;
428 visit_type_int32(v, name, &value, errp);
430 #endif
432 void aarch64_add_sve_properties(Object *obj)
434 ARMCPU *cpu = ARM_CPU(obj);
435 uint32_t vq;
437 object_property_add_bool(obj, "sve", cpu_arm_get_sve, cpu_arm_set_sve);
439 for (vq = 1; vq <= ARM_MAX_VQ; ++vq) {
440 char name[8];
441 snprintf(name, sizeof(name), "sve%d", vq * 128);
442 object_property_add(obj, name, "bool", cpu_arm_get_vq,
443 cpu_arm_set_vq, NULL, &cpu->sve_vq);
446 #ifdef CONFIG_USER_ONLY
447 /* Mirror linux /proc/sys/abi/sve_default_vector_length. */
448 object_property_add(obj, "sve-default-vector-length", "int32",
449 cpu_arm_get_default_vec_len,
450 cpu_arm_set_default_vec_len, NULL,
451 &cpu->sve_default_vq);
452 #endif
455 void aarch64_add_sme_properties(Object *obj)
457 ARMCPU *cpu = ARM_CPU(obj);
458 uint32_t vq;
460 object_property_add_bool(obj, "sme", cpu_arm_get_sme, cpu_arm_set_sme);
461 object_property_add_bool(obj, "sme_fa64", cpu_arm_get_sme_fa64,
462 cpu_arm_set_sme_fa64);
464 for (vq = 1; vq <= ARM_MAX_VQ; vq <<= 1) {
465 char name[8];
466 snprintf(name, sizeof(name), "sme%d", vq * 128);
467 object_property_add(obj, name, "bool", cpu_arm_get_vq,
468 cpu_arm_set_vq, NULL, &cpu->sme_vq);
471 #ifdef CONFIG_USER_ONLY
472 /* Mirror linux /proc/sys/abi/sme_default_vector_length. */
473 object_property_add(obj, "sme-default-vector-length", "int32",
474 cpu_arm_get_default_vec_len,
475 cpu_arm_set_default_vec_len, NULL,
476 &cpu->sme_default_vq);
477 #endif
480 void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp)
482 ARMPauthFeature features = cpu_isar_feature(pauth_feature, cpu);
483 uint64_t isar1, isar2;
486 * These properties enable or disable Pauth as a whole, or change
487 * the pauth algorithm, but do not change the set of features that
488 * are present. We have saved a copy of those features above and
489 * will now place it into the field that chooses the algorithm.
491 * Begin by disabling all fields.
493 isar1 = cpu->isar.id_aa64isar1;
494 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, APA, 0);
495 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPA, 0);
496 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, API, 0);
497 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPI, 0);
499 isar2 = cpu->isar.id_aa64isar2;
500 isar2 = FIELD_DP64(isar2, ID_AA64ISAR2, APA3, 0);
501 isar2 = FIELD_DP64(isar2, ID_AA64ISAR2, GPA3, 0);
503 if (kvm_enabled() || hvf_enabled()) {
505 * Exit early if PAuth is enabled and fall through to disable it.
506 * The algorithm selection properties are not present.
508 if (cpu->prop_pauth) {
509 if (features == 0) {
510 error_setg(errp, "'pauth' feature not supported by "
511 "%s on this host", current_accel_name());
513 return;
515 } else {
516 /* Pauth properties are only present when the model supports it. */
517 if (features == 0) {
518 assert(!cpu->prop_pauth);
519 return;
522 if (cpu->prop_pauth) {
523 if (cpu->prop_pauth_impdef && cpu->prop_pauth_qarma3) {
524 error_setg(errp,
525 "cannot enable both pauth-impdef and pauth-qarma3");
526 return;
529 if (cpu->prop_pauth_impdef) {
530 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, API, features);
531 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPI, 1);
532 } else if (cpu->prop_pauth_qarma3) {
533 isar2 = FIELD_DP64(isar2, ID_AA64ISAR2, APA3, features);
534 isar2 = FIELD_DP64(isar2, ID_AA64ISAR2, GPA3, 1);
535 } else {
536 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, APA, features);
537 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPA, 1);
539 } else if (cpu->prop_pauth_impdef || cpu->prop_pauth_qarma3) {
540 error_setg(errp, "cannot enable pauth-impdef or "
541 "pauth-qarma3 without pauth");
542 error_append_hint(errp, "Add pauth=on to the CPU property list.\n");
546 cpu->isar.id_aa64isar1 = isar1;
547 cpu->isar.id_aa64isar2 = isar2;
550 static Property arm_cpu_pauth_property =
551 DEFINE_PROP_BOOL("pauth", ARMCPU, prop_pauth, true);
552 static Property arm_cpu_pauth_impdef_property =
553 DEFINE_PROP_BOOL("pauth-impdef", ARMCPU, prop_pauth_impdef, false);
554 static Property arm_cpu_pauth_qarma3_property =
555 DEFINE_PROP_BOOL("pauth-qarma3", ARMCPU, prop_pauth_qarma3, false);
557 void aarch64_add_pauth_properties(Object *obj)
559 ARMCPU *cpu = ARM_CPU(obj);
561 /* Default to PAUTH on, with the architected algorithm on TCG. */
562 qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_property);
563 if (kvm_enabled() || hvf_enabled()) {
565 * Mirror PAuth support from the probed sysregs back into the
566 * property for KVM or hvf. Is it just a bit backward? Yes it is!
567 * Note that prop_pauth is true whether the host CPU supports the
568 * architected QARMA5 algorithm or the IMPDEF one. We don't
569 * provide the separate pauth-impdef property for KVM or hvf,
570 * only for TCG.
572 cpu->prop_pauth = cpu_isar_feature(aa64_pauth, cpu);
573 } else {
574 qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_impdef_property);
575 qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_qarma3_property);
579 void arm_cpu_lpa2_finalize(ARMCPU *cpu, Error **errp)
581 uint64_t t;
584 * We only install the property for tcg -cpu max; this is the
585 * only situation in which the cpu field can be true.
587 if (!cpu->prop_lpa2) {
588 return;
591 t = cpu->isar.id_aa64mmfr0;
592 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16, 2); /* 16k pages w/ LPA2 */
593 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4, 1); /* 4k pages w/ LPA2 */
594 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16_2, 3); /* 16k stage2 w/ LPA2 */
595 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4_2, 3); /* 4k stage2 w/ LPA2 */
596 cpu->isar.id_aa64mmfr0 = t;
599 static void aarch64_a57_initfn(Object *obj)
601 ARMCPU *cpu = ARM_CPU(obj);
603 cpu->dtb_compatible = "arm,cortex-a57";
604 set_feature(&cpu->env, ARM_FEATURE_V8);
605 set_feature(&cpu->env, ARM_FEATURE_NEON);
606 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
607 set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ);
608 set_feature(&cpu->env, ARM_FEATURE_AARCH64);
609 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
610 set_feature(&cpu->env, ARM_FEATURE_EL2);
611 set_feature(&cpu->env, ARM_FEATURE_EL3);
612 set_feature(&cpu->env, ARM_FEATURE_PMU);
613 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A57;
614 cpu->midr = 0x411fd070;
615 cpu->revidr = 0x00000000;
616 cpu->reset_fpsid = 0x41034070;
617 cpu->isar.mvfr0 = 0x10110222;
618 cpu->isar.mvfr1 = 0x12111111;
619 cpu->isar.mvfr2 = 0x00000043;
620 cpu->ctr = 0x8444c004;
621 cpu->reset_sctlr = 0x00c50838;
622 cpu->isar.id_pfr0 = 0x00000131;
623 cpu->isar.id_pfr1 = 0x00011011;
624 cpu->isar.id_dfr0 = 0x03010066;
625 cpu->id_afr0 = 0x00000000;
626 cpu->isar.id_mmfr0 = 0x10101105;
627 cpu->isar.id_mmfr1 = 0x40000000;
628 cpu->isar.id_mmfr2 = 0x01260000;
629 cpu->isar.id_mmfr3 = 0x02102211;
630 cpu->isar.id_isar0 = 0x02101110;
631 cpu->isar.id_isar1 = 0x13112111;
632 cpu->isar.id_isar2 = 0x21232042;
633 cpu->isar.id_isar3 = 0x01112131;
634 cpu->isar.id_isar4 = 0x00011142;
635 cpu->isar.id_isar5 = 0x00011121;
636 cpu->isar.id_isar6 = 0;
637 cpu->isar.id_aa64pfr0 = 0x00002222;
638 cpu->isar.id_aa64dfr0 = 0x10305106;
639 cpu->isar.id_aa64isar0 = 0x00011120;
640 cpu->isar.id_aa64mmfr0 = 0x00001124;
641 cpu->isar.dbgdidr = 0x3516d000;
642 cpu->isar.dbgdevid = 0x01110f13;
643 cpu->isar.dbgdevid1 = 0x2;
644 cpu->isar.reset_pmcr_el0 = 0x41013000;
645 cpu->clidr = 0x0a200023;
646 /* 32KB L1 dcache */
647 cpu->ccsidr[0] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 4, 64, 32 * KiB, 7);
648 /* 48KB L1 icache */
649 cpu->ccsidr[1] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 3, 64, 48 * KiB, 2);
650 /* 2048KB L2 cache */
651 cpu->ccsidr[2] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 16, 64, 2 * MiB, 7);
652 cpu->dcz_blocksize = 4; /* 64 bytes */
653 cpu->gic_num_lrs = 4;
654 cpu->gic_vpribits = 5;
655 cpu->gic_vprebits = 5;
656 cpu->gic_pribits = 5;
657 define_cortex_a72_a57_a53_cp_reginfo(cpu);
660 static void aarch64_a53_initfn(Object *obj)
662 ARMCPU *cpu = ARM_CPU(obj);
664 cpu->dtb_compatible = "arm,cortex-a53";
665 set_feature(&cpu->env, ARM_FEATURE_V8);
666 set_feature(&cpu->env, ARM_FEATURE_NEON);
667 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
668 set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ);
669 set_feature(&cpu->env, ARM_FEATURE_AARCH64);
670 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
671 set_feature(&cpu->env, ARM_FEATURE_EL2);
672 set_feature(&cpu->env, ARM_FEATURE_EL3);
673 set_feature(&cpu->env, ARM_FEATURE_PMU);
674 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A53;
675 cpu->midr = 0x410fd034;
676 cpu->revidr = 0x00000100;
677 cpu->reset_fpsid = 0x41034070;
678 cpu->isar.mvfr0 = 0x10110222;
679 cpu->isar.mvfr1 = 0x12111111;
680 cpu->isar.mvfr2 = 0x00000043;
681 cpu->ctr = 0x84448004; /* L1Ip = VIPT */
682 cpu->reset_sctlr = 0x00c50838;
683 cpu->isar.id_pfr0 = 0x00000131;
684 cpu->isar.id_pfr1 = 0x00011011;
685 cpu->isar.id_dfr0 = 0x03010066;
686 cpu->id_afr0 = 0x00000000;
687 cpu->isar.id_mmfr0 = 0x10101105;
688 cpu->isar.id_mmfr1 = 0x40000000;
689 cpu->isar.id_mmfr2 = 0x01260000;
690 cpu->isar.id_mmfr3 = 0x02102211;
691 cpu->isar.id_isar0 = 0x02101110;
692 cpu->isar.id_isar1 = 0x13112111;
693 cpu->isar.id_isar2 = 0x21232042;
694 cpu->isar.id_isar3 = 0x01112131;
695 cpu->isar.id_isar4 = 0x00011142;
696 cpu->isar.id_isar5 = 0x00011121;
697 cpu->isar.id_isar6 = 0;
698 cpu->isar.id_aa64pfr0 = 0x00002222;
699 cpu->isar.id_aa64dfr0 = 0x10305106;
700 cpu->isar.id_aa64isar0 = 0x00011120;
701 cpu->isar.id_aa64mmfr0 = 0x00001122; /* 40 bit physical addr */
702 cpu->isar.dbgdidr = 0x3516d000;
703 cpu->isar.dbgdevid = 0x00110f13;
704 cpu->isar.dbgdevid1 = 0x1;
705 cpu->isar.reset_pmcr_el0 = 0x41033000;
706 cpu->clidr = 0x0a200023;
707 /* 32KB L1 dcache */
708 cpu->ccsidr[0] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 4, 64, 32 * KiB, 7);
709 /* 32KB L1 icache */
710 cpu->ccsidr[1] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 1, 64, 32 * KiB, 2);
711 /* 1024KB L2 cache */
712 cpu->ccsidr[2] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 16, 64, 1 * MiB, 7);
713 cpu->dcz_blocksize = 4; /* 64 bytes */
714 cpu->gic_num_lrs = 4;
715 cpu->gic_vpribits = 5;
716 cpu->gic_vprebits = 5;
717 cpu->gic_pribits = 5;
718 define_cortex_a72_a57_a53_cp_reginfo(cpu);
721 static void aarch64_host_initfn(Object *obj)
723 #if defined(CONFIG_KVM)
724 ARMCPU *cpu = ARM_CPU(obj);
725 kvm_arm_set_cpu_features_from_host(cpu);
726 if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
727 aarch64_add_sve_properties(obj);
728 aarch64_add_pauth_properties(obj);
730 #elif defined(CONFIG_HVF)
731 ARMCPU *cpu = ARM_CPU(obj);
732 hvf_arm_set_cpu_features_from_host(cpu);
733 aarch64_add_pauth_properties(obj);
734 #else
735 g_assert_not_reached();
736 #endif
739 static void aarch64_max_initfn(Object *obj)
741 if (kvm_enabled() || hvf_enabled()) {
742 /* With KVM or HVF, '-cpu max' is identical to '-cpu host' */
743 aarch64_host_initfn(obj);
744 return;
747 if (tcg_enabled() || qtest_enabled()) {
748 aarch64_a57_initfn(obj);
751 /* '-cpu max' for TCG: we currently do this as "A57 with extra things" */
752 if (tcg_enabled()) {
753 aarch64_max_tcg_initfn(obj);
757 static const ARMCPUInfo aarch64_cpus[] = {
758 { .name = "cortex-a57", .initfn = aarch64_a57_initfn },
759 { .name = "cortex-a53", .initfn = aarch64_a53_initfn },
760 { .name = "max", .initfn = aarch64_max_initfn },
761 #if defined(CONFIG_KVM) || defined(CONFIG_HVF)
762 { .name = "host", .initfn = aarch64_host_initfn },
763 #endif
766 static bool aarch64_cpu_get_aarch64(Object *obj, Error **errp)
768 ARMCPU *cpu = ARM_CPU(obj);
770 return arm_feature(&cpu->env, ARM_FEATURE_AARCH64);
773 static void aarch64_cpu_set_aarch64(Object *obj, bool value, Error **errp)
775 ARMCPU *cpu = ARM_CPU(obj);
777 /* At this time, this property is only allowed if KVM is enabled. This
778 * restriction allows us to avoid fixing up functionality that assumes a
779 * uniform execution state like do_interrupt.
781 if (value == false) {
782 if (!kvm_enabled() || !kvm_arm_aarch32_supported()) {
783 error_setg(errp, "'aarch64' feature cannot be disabled "
784 "unless KVM is enabled and 32-bit EL1 "
785 "is supported");
786 return;
788 unset_feature(&cpu->env, ARM_FEATURE_AARCH64);
789 } else {
790 set_feature(&cpu->env, ARM_FEATURE_AARCH64);
794 static void aarch64_cpu_finalizefn(Object *obj)
798 static const gchar *aarch64_gdb_arch_name(CPUState *cs)
800 return "aarch64";
803 static void aarch64_cpu_class_init(ObjectClass *oc, void *data)
805 CPUClass *cc = CPU_CLASS(oc);
807 cc->gdb_read_register = aarch64_cpu_gdb_read_register;
808 cc->gdb_write_register = aarch64_cpu_gdb_write_register;
809 cc->gdb_core_xml_file = "aarch64-core.xml";
810 cc->gdb_arch_name = aarch64_gdb_arch_name;
812 object_class_property_add_bool(oc, "aarch64", aarch64_cpu_get_aarch64,
813 aarch64_cpu_set_aarch64);
814 object_class_property_set_description(oc, "aarch64",
815 "Set on/off to enable/disable aarch64 "
816 "execution state ");
819 static void aarch64_cpu_instance_init(Object *obj)
821 ARMCPUClass *acc = ARM_CPU_GET_CLASS(obj);
823 acc->info->initfn(obj);
824 arm_cpu_post_init(obj);
827 static void cpu_register_class_init(ObjectClass *oc, void *data)
829 ARMCPUClass *acc = ARM_CPU_CLASS(oc);
831 acc->info = data;
834 void aarch64_cpu_register(const ARMCPUInfo *info)
836 TypeInfo type_info = {
837 .parent = TYPE_AARCH64_CPU,
838 .instance_init = aarch64_cpu_instance_init,
839 .class_init = info->class_init ?: cpu_register_class_init,
840 .class_data = (void *)info,
843 type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
844 type_register(&type_info);
845 g_free((void *)type_info.name);
848 static const TypeInfo aarch64_cpu_type_info = {
849 .name = TYPE_AARCH64_CPU,
850 .parent = TYPE_ARM_CPU,
851 .instance_finalize = aarch64_cpu_finalizefn,
852 .abstract = true,
853 .class_init = aarch64_cpu_class_init,
856 static void aarch64_cpu_register_types(void)
858 size_t i;
860 type_register_static(&aarch64_cpu_type_info);
862 for (i = 0; i < ARRAY_SIZE(aarch64_cpus); ++i) {
863 aarch64_cpu_register(&aarch64_cpus[i]);
867 type_init(aarch64_cpu_register_types)