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 uninitialized 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 ARMPauthFeature features = cpu_isar_feature(pauth_feature, cpu); 477 uint64_t isar1; 478 479 /* 480 * These properties enable or disable Pauth as a whole, or change 481 * the pauth algorithm, but do not change the set of features that 482 * are present. We have saved a copy of those features above and 483 * will now place it into the field that chooses the algorithm. 484 * 485 * Begin by disabling all fields. 486 */ 487 isar1 = cpu->isar.id_aa64isar1; 488 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, APA, 0); 489 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPA, 0); 490 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, API, 0); 491 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPI, 0); 492 493 if (kvm_enabled() || hvf_enabled()) { 494 /* 495 * Exit early if PAuth is enabled and fall through to disable it. 496 * The algorithm selection properties are not present. 497 */ 498 if (cpu->prop_pauth) { 499 if (features == 0) { 500 error_setg(errp, "'pauth' feature not supported by " 501 "%s on this host", current_accel_name()); 502 } 503 return; 504 } 505 } else { 506 /* Pauth properties are only present when the model supports it. */ 507 if (features == 0) { 508 assert(!cpu->prop_pauth); 509 return; 510 } 511 512 if (cpu->prop_pauth) { 513 if (cpu->prop_pauth_impdef) { 514 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, API, features); 515 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPI, 1); 516 } else { 517 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, APA, features); 518 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPA, 1); 519 } 520 } else if (cpu->prop_pauth_impdef) { 521 error_setg(errp, "cannot enable pauth-impdef without pauth"); 522 error_append_hint(errp, "Add pauth=on to the CPU property list.\n"); 523 } 524 } 525 526 cpu->isar.id_aa64isar1 = isar1; 527 } 528 529 static Property arm_cpu_pauth_property = 530 DEFINE_PROP_BOOL("pauth", ARMCPU, prop_pauth, true); 531 static Property arm_cpu_pauth_impdef_property = 532 DEFINE_PROP_BOOL("pauth-impdef", ARMCPU, prop_pauth_impdef, false); 533 534 void aarch64_add_pauth_properties(Object *obj) 535 { 536 ARMCPU *cpu = ARM_CPU(obj); 537 538 /* Default to PAUTH on, with the architected algorithm on TCG. */ 539 qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_property); 540 if (kvm_enabled() || hvf_enabled()) { 541 /* 542 * Mirror PAuth support from the probed sysregs back into the 543 * property for KVM or hvf. Is it just a bit backward? Yes it is! 544 * Note that prop_pauth is true whether the host CPU supports the 545 * architected QARMA5 algorithm or the IMPDEF one. We don't 546 * provide the separate pauth-impdef property for KVM or hvf, 547 * only for TCG. 548 */ 549 cpu->prop_pauth = cpu_isar_feature(aa64_pauth, cpu); 550 } else { 551 qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_impdef_property); 552 } 553 } 554 555 void arm_cpu_lpa2_finalize(ARMCPU *cpu, Error **errp) 556 { 557 uint64_t t; 558 559 /* 560 * We only install the property for tcg -cpu max; this is the 561 * only situation in which the cpu field can be true. 562 */ 563 if (!cpu->prop_lpa2) { 564 return; 565 } 566 567 t = cpu->isar.id_aa64mmfr0; 568 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16, 2); /* 16k pages w/ LPA2 */ 569 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4, 1); /* 4k pages w/ LPA2 */ 570 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16_2, 3); /* 16k stage2 w/ LPA2 */ 571 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4_2, 3); /* 4k stage2 w/ LPA2 */ 572 cpu->isar.id_aa64mmfr0 = t; 573 } 574 575 static void aarch64_a57_initfn(Object *obj) 576 { 577 ARMCPU *cpu = ARM_CPU(obj); 578 579 cpu->dtb_compatible = "arm,cortex-a57"; 580 set_feature(&cpu->env, ARM_FEATURE_V8); 581 set_feature(&cpu->env, ARM_FEATURE_NEON); 582 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); 583 set_feature(&cpu->env, ARM_FEATURE_AARCH64); 584 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); 585 set_feature(&cpu->env, ARM_FEATURE_EL2); 586 set_feature(&cpu->env, ARM_FEATURE_EL3); 587 set_feature(&cpu->env, ARM_FEATURE_PMU); 588 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A57; 589 cpu->midr = 0x411fd070; 590 cpu->revidr = 0x00000000; 591 cpu->reset_fpsid = 0x41034070; 592 cpu->isar.mvfr0 = 0x10110222; 593 cpu->isar.mvfr1 = 0x12111111; 594 cpu->isar.mvfr2 = 0x00000043; 595 cpu->ctr = 0x8444c004; 596 cpu->reset_sctlr = 0x00c50838; 597 cpu->isar.id_pfr0 = 0x00000131; 598 cpu->isar.id_pfr1 = 0x00011011; 599 cpu->isar.id_dfr0 = 0x03010066; 600 cpu->id_afr0 = 0x00000000; 601 cpu->isar.id_mmfr0 = 0x10101105; 602 cpu->isar.id_mmfr1 = 0x40000000; 603 cpu->isar.id_mmfr2 = 0x01260000; 604 cpu->isar.id_mmfr3 = 0x02102211; 605 cpu->isar.id_isar0 = 0x02101110; 606 cpu->isar.id_isar1 = 0x13112111; 607 cpu->isar.id_isar2 = 0x21232042; 608 cpu->isar.id_isar3 = 0x01112131; 609 cpu->isar.id_isar4 = 0x00011142; 610 cpu->isar.id_isar5 = 0x00011121; 611 cpu->isar.id_isar6 = 0; 612 cpu->isar.id_aa64pfr0 = 0x00002222; 613 cpu->isar.id_aa64dfr0 = 0x10305106; 614 cpu->isar.id_aa64isar0 = 0x00011120; 615 cpu->isar.id_aa64mmfr0 = 0x00001124; 616 cpu->isar.dbgdidr = 0x3516d000; 617 cpu->isar.dbgdevid = 0x01110f13; 618 cpu->isar.dbgdevid1 = 0x2; 619 cpu->isar.reset_pmcr_el0 = 0x41013000; 620 cpu->clidr = 0x0a200023; 621 cpu->ccsidr[0] = 0x701fe00a; /* 32KB L1 dcache */ 622 cpu->ccsidr[1] = 0x201fe012; /* 48KB L1 icache */ 623 cpu->ccsidr[2] = 0x70ffe07a; /* 2048KB L2 cache */ 624 cpu->dcz_blocksize = 4; /* 64 bytes */ 625 cpu->gic_num_lrs = 4; 626 cpu->gic_vpribits = 5; 627 cpu->gic_vprebits = 5; 628 cpu->gic_pribits = 5; 629 define_cortex_a72_a57_a53_cp_reginfo(cpu); 630 } 631 632 static void aarch64_a53_initfn(Object *obj) 633 { 634 ARMCPU *cpu = ARM_CPU(obj); 635 636 cpu->dtb_compatible = "arm,cortex-a53"; 637 set_feature(&cpu->env, ARM_FEATURE_V8); 638 set_feature(&cpu->env, ARM_FEATURE_NEON); 639 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); 640 set_feature(&cpu->env, ARM_FEATURE_AARCH64); 641 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); 642 set_feature(&cpu->env, ARM_FEATURE_EL2); 643 set_feature(&cpu->env, ARM_FEATURE_EL3); 644 set_feature(&cpu->env, ARM_FEATURE_PMU); 645 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A53; 646 cpu->midr = 0x410fd034; 647 cpu->revidr = 0x00000000; 648 cpu->reset_fpsid = 0x41034070; 649 cpu->isar.mvfr0 = 0x10110222; 650 cpu->isar.mvfr1 = 0x12111111; 651 cpu->isar.mvfr2 = 0x00000043; 652 cpu->ctr = 0x84448004; /* L1Ip = VIPT */ 653 cpu->reset_sctlr = 0x00c50838; 654 cpu->isar.id_pfr0 = 0x00000131; 655 cpu->isar.id_pfr1 = 0x00011011; 656 cpu->isar.id_dfr0 = 0x03010066; 657 cpu->id_afr0 = 0x00000000; 658 cpu->isar.id_mmfr0 = 0x10101105; 659 cpu->isar.id_mmfr1 = 0x40000000; 660 cpu->isar.id_mmfr2 = 0x01260000; 661 cpu->isar.id_mmfr3 = 0x02102211; 662 cpu->isar.id_isar0 = 0x02101110; 663 cpu->isar.id_isar1 = 0x13112111; 664 cpu->isar.id_isar2 = 0x21232042; 665 cpu->isar.id_isar3 = 0x01112131; 666 cpu->isar.id_isar4 = 0x00011142; 667 cpu->isar.id_isar5 = 0x00011121; 668 cpu->isar.id_isar6 = 0; 669 cpu->isar.id_aa64pfr0 = 0x00002222; 670 cpu->isar.id_aa64dfr0 = 0x10305106; 671 cpu->isar.id_aa64isar0 = 0x00011120; 672 cpu->isar.id_aa64mmfr0 = 0x00001122; /* 40 bit physical addr */ 673 cpu->isar.dbgdidr = 0x3516d000; 674 cpu->isar.dbgdevid = 0x00110f13; 675 cpu->isar.dbgdevid1 = 0x1; 676 cpu->isar.reset_pmcr_el0 = 0x41033000; 677 cpu->clidr = 0x0a200023; 678 cpu->ccsidr[0] = 0x700fe01a; /* 32KB L1 dcache */ 679 cpu->ccsidr[1] = 0x201fe00a; /* 32KB L1 icache */ 680 cpu->ccsidr[2] = 0x707fe07a; /* 1024KB L2 cache */ 681 cpu->dcz_blocksize = 4; /* 64 bytes */ 682 cpu->gic_num_lrs = 4; 683 cpu->gic_vpribits = 5; 684 cpu->gic_vprebits = 5; 685 cpu->gic_pribits = 5; 686 define_cortex_a72_a57_a53_cp_reginfo(cpu); 687 } 688 689 static void aarch64_host_initfn(Object *obj) 690 { 691 #if defined(CONFIG_KVM) 692 ARMCPU *cpu = ARM_CPU(obj); 693 kvm_arm_set_cpu_features_from_host(cpu); 694 if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { 695 aarch64_add_sve_properties(obj); 696 aarch64_add_pauth_properties(obj); 697 } 698 #elif defined(CONFIG_HVF) 699 ARMCPU *cpu = ARM_CPU(obj); 700 hvf_arm_set_cpu_features_from_host(cpu); 701 aarch64_add_pauth_properties(obj); 702 #else 703 g_assert_not_reached(); 704 #endif 705 } 706 707 static void aarch64_max_initfn(Object *obj) 708 { 709 if (kvm_enabled() || hvf_enabled()) { 710 /* With KVM or HVF, '-cpu max' is identical to '-cpu host' */ 711 aarch64_host_initfn(obj); 712 return; 713 } 714 715 if (tcg_enabled() || qtest_enabled()) { 716 aarch64_a57_initfn(obj); 717 } 718 719 /* '-cpu max' for TCG: we currently do this as "A57 with extra things" */ 720 if (tcg_enabled()) { 721 aarch64_max_tcg_initfn(obj); 722 } 723 } 724 725 static const ARMCPUInfo aarch64_cpus[] = { 726 { .name = "cortex-a57", .initfn = aarch64_a57_initfn }, 727 { .name = "cortex-a53", .initfn = aarch64_a53_initfn }, 728 { .name = "max", .initfn = aarch64_max_initfn }, 729 #if defined(CONFIG_KVM) || defined(CONFIG_HVF) 730 { .name = "host", .initfn = aarch64_host_initfn }, 731 #endif 732 }; 733 734 static bool aarch64_cpu_get_aarch64(Object *obj, Error **errp) 735 { 736 ARMCPU *cpu = ARM_CPU(obj); 737 738 return arm_feature(&cpu->env, ARM_FEATURE_AARCH64); 739 } 740 741 static void aarch64_cpu_set_aarch64(Object *obj, bool value, Error **errp) 742 { 743 ARMCPU *cpu = ARM_CPU(obj); 744 745 /* At this time, this property is only allowed if KVM is enabled. This 746 * restriction allows us to avoid fixing up functionality that assumes a 747 * uniform execution state like do_interrupt. 748 */ 749 if (value == false) { 750 if (!kvm_enabled() || !kvm_arm_aarch32_supported()) { 751 error_setg(errp, "'aarch64' feature cannot be disabled " 752 "unless KVM is enabled and 32-bit EL1 " 753 "is supported"); 754 return; 755 } 756 unset_feature(&cpu->env, ARM_FEATURE_AARCH64); 757 } else { 758 set_feature(&cpu->env, ARM_FEATURE_AARCH64); 759 } 760 } 761 762 static void aarch64_cpu_finalizefn(Object *obj) 763 { 764 } 765 766 static gchar *aarch64_gdb_arch_name(CPUState *cs) 767 { 768 return g_strdup("aarch64"); 769 } 770 771 static void aarch64_cpu_class_init(ObjectClass *oc, void *data) 772 { 773 CPUClass *cc = CPU_CLASS(oc); 774 775 cc->gdb_read_register = aarch64_cpu_gdb_read_register; 776 cc->gdb_write_register = aarch64_cpu_gdb_write_register; 777 cc->gdb_num_core_regs = 34; 778 cc->gdb_core_xml_file = "aarch64-core.xml"; 779 cc->gdb_arch_name = aarch64_gdb_arch_name; 780 781 object_class_property_add_bool(oc, "aarch64", aarch64_cpu_get_aarch64, 782 aarch64_cpu_set_aarch64); 783 object_class_property_set_description(oc, "aarch64", 784 "Set on/off to enable/disable aarch64 " 785 "execution state "); 786 } 787 788 static void aarch64_cpu_instance_init(Object *obj) 789 { 790 ARMCPUClass *acc = ARM_CPU_GET_CLASS(obj); 791 792 acc->info->initfn(obj); 793 arm_cpu_post_init(obj); 794 } 795 796 static void cpu_register_class_init(ObjectClass *oc, void *data) 797 { 798 ARMCPUClass *acc = ARM_CPU_CLASS(oc); 799 800 acc->info = data; 801 } 802 803 void aarch64_cpu_register(const ARMCPUInfo *info) 804 { 805 TypeInfo type_info = { 806 .parent = TYPE_AARCH64_CPU, 807 .instance_size = sizeof(ARMCPU), 808 .instance_init = aarch64_cpu_instance_init, 809 .class_size = sizeof(ARMCPUClass), 810 .class_init = info->class_init ?: cpu_register_class_init, 811 .class_data = (void *)info, 812 }; 813 814 type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name); 815 type_register(&type_info); 816 g_free((void *)type_info.name); 817 } 818 819 static const TypeInfo aarch64_cpu_type_info = { 820 .name = TYPE_AARCH64_CPU, 821 .parent = TYPE_ARM_CPU, 822 .instance_size = sizeof(ARMCPU), 823 .instance_finalize = aarch64_cpu_finalizefn, 824 .abstract = true, 825 .class_size = sizeof(AArch64CPUClass), 826 .class_init = aarch64_cpu_class_init, 827 }; 828 829 static void aarch64_cpu_register_types(void) 830 { 831 size_t i; 832 833 type_register_static(&aarch64_cpu_type_info); 834 835 for (i = 0; i < ARRAY_SIZE(aarch64_cpus); ++i) { 836 aarch64_cpu_register(&aarch64_cpus[i]); 837 } 838 } 839 840 type_init(aarch64_cpu_register_types) 841