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 "qemu/units.h" 27 #include "system/kvm.h" 28 #include "system/hvf.h" 29 #include "system/qtest.h" 30 #include "system/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" 38 39 void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp) 40 { 41 /* 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. 55 */ 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; 61 62 /* 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. 67 */ 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; 75 } 76 } else { 77 vq_supported = cpu->sve_vq.supported; 78 } 79 80 /* 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. 84 */ 85 if (vq_map != 0) { 86 max_vq = 32 - clz32(vq_map); 87 vq_mask = MAKE_64BIT_MASK(0, max_vq); 88 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; 96 } 97 98 if (kvm_enabled()) { 99 /* 100 * For KVM we have to automatically enable all supported uninitialized 101 * lengths, even when the smaller lengths are not all powers-of-two. 102 */ 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; 107 } 108 } else if (cpu->sve_max_vq == 0) { 109 /* 110 * No explicit bits enabled, and no implicit bits from sve-max-vq. 111 */ 112 if (!cpu_isar_feature(aa64_sve, cpu)) { 113 /* 114 * SVE is disabled and so are all vector lengths. Good. 115 * Disable all SVE extensions as well. 116 */ 117 cpu->isar.id_aa64zfr0 = 0; 118 return; 119 } 120 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; 127 } 128 vq = ctz32(tmp) + 1; 129 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; 133 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; 142 } 143 144 max_vq = 32 - clz32(vq_map); 145 vq_mask = MAKE_64BIT_MASK(0, max_vq); 146 } 147 148 /* 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. 152 */ 153 if (cpu->sve_max_vq != 0) { 154 max_vq = cpu->sve_max_vq; 155 vq_mask = MAKE_64BIT_MASK(0, max_vq); 156 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; 163 } 164 165 /* Set all bits not explicitly set within sve-max-vq. */ 166 vq_map |= ~vq_init & vq_mask; 167 } 168 169 /* 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. 173 */ 174 assert(max_vq != 0); 175 assert(vq_mask != 0); 176 vq_map &= vq_mask; 177 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"); 198 } 199 } 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; 220 } 221 } 222 } 223 } 224 225 /* 226 * Now that we validated all our vector lengths, the only question 227 * left to answer is if we even want SVE at all. 228 */ 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; 235 } 236 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; 240 } 241 242 /* 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. 246 */ 247 static void cpu_arm_get_vq(Object *obj, Visitor *v, const char *name, 248 void *opaque, Error **errp) 249 { 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; 255 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); 263 } 264 visit_type_bool(v, name, &value, errp); 265 } 266 267 static void cpu_arm_set_vq(Object *obj, Visitor *v, const char *name, 268 void *opaque, Error **errp) 269 { 270 ARMVQMap *vq_map = opaque; 271 uint32_t vq = atoi(&name[3]) / 128; 272 bool value; 273 274 if (!visit_type_bool(v, name, &value, errp)) { 275 return; 276 } 277 278 vq_map->map = deposit32(vq_map->map, vq - 1, 1, value); 279 vq_map->init |= 1 << (vq - 1); 280 } 281 282 static bool cpu_arm_get_sve(Object *obj, Error **errp) 283 { 284 ARMCPU *cpu = ARM_CPU(obj); 285 return cpu_isar_feature(aa64_sve, cpu); 286 } 287 288 static void cpu_arm_set_sve(Object *obj, bool value, Error **errp) 289 { 290 ARMCPU *cpu = ARM_CPU(obj); 291 uint64_t t; 292 293 if (value && kvm_enabled() && !kvm_arm_sve_supported()) { 294 error_setg(errp, "'sve' feature not supported by KVM on this host"); 295 return; 296 } 297 298 t = cpu->isar.id_aa64pfr0; 299 t = FIELD_DP64(t, ID_AA64PFR0, SVE, value); 300 cpu->isar.id_aa64pfr0 = t; 301 } 302 303 void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp) 304 { 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; 309 310 if (vq_map == 0) { 311 if (!cpu_isar_feature(aa64_sme, cpu)) { 312 cpu->isar.id_aa64smfr0 = 0; 313 return; 314 } 315 316 /* TODO: KVM will require limitations via SMCR_EL2. */ 317 vq_map = vq_supported & ~vq_init; 318 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; 326 } 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; 335 } 336 /* TODO: KVM will require limitations via SMCR_EL2. */ 337 } 338 339 cpu->sme_vq.map = vq_map; 340 } 341 342 static bool cpu_arm_get_sme(Object *obj, Error **errp) 343 { 344 ARMCPU *cpu = ARM_CPU(obj); 345 return cpu_isar_feature(aa64_sme, cpu); 346 } 347 348 static void cpu_arm_set_sme(Object *obj, bool value, Error **errp) 349 { 350 ARMCPU *cpu = ARM_CPU(obj); 351 uint64_t t; 352 353 t = cpu->isar.id_aa64pfr1; 354 t = FIELD_DP64(t, ID_AA64PFR1, SME, value); 355 cpu->isar.id_aa64pfr1 = t; 356 } 357 358 static bool cpu_arm_get_sme_fa64(Object *obj, Error **errp) 359 { 360 ARMCPU *cpu = ARM_CPU(obj); 361 return cpu_isar_feature(aa64_sme, cpu) && 362 cpu_isar_feature(aa64_sme_fa64, cpu); 363 } 364 365 static void cpu_arm_set_sme_fa64(Object *obj, bool value, Error **errp) 366 { 367 ARMCPU *cpu = ARM_CPU(obj); 368 uint64_t t; 369 370 t = cpu->isar.id_aa64smfr0; 371 t = FIELD_DP64(t, ID_AA64SMFR0, FA64, value); 372 cpu->isar.id_aa64smfr0 = t; 373 } 374 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) 380 { 381 uint32_t *ptr_default_vq = opaque; 382 int32_t default_len, default_vq, remainder; 383 384 if (!visit_type_int32(v, name, &default_len, errp)) { 385 return; 386 } 387 388 /* Undocumented, but the kernel allows -1 to indicate "maximum". */ 389 if (default_len == -1) { 390 *ptr_default_vq = ARM_MAX_VQ; 391 return; 392 } 393 394 default_vq = default_len / 16; 395 remainder = default_len % 16; 396 397 /* 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. 400 */ 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"); 405 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); 414 } 415 return; 416 } 417 418 *ptr_default_vq = default_vq; 419 } 420 421 static void cpu_arm_get_default_vec_len(Object *obj, Visitor *v, 422 const char *name, void *opaque, 423 Error **errp) 424 { 425 uint32_t *ptr_default_vq = opaque; 426 int32_t value = *ptr_default_vq * 16; 427 428 visit_type_int32(v, name, &value, errp); 429 } 430 #endif 431 432 void aarch64_add_sve_properties(Object *obj) 433 { 434 ARMCPU *cpu = ARM_CPU(obj); 435 uint32_t vq; 436 437 object_property_add_bool(obj, "sve", cpu_arm_get_sve, cpu_arm_set_sve); 438 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); 444 } 445 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 453 } 454 455 void aarch64_add_sme_properties(Object *obj) 456 { 457 ARMCPU *cpu = ARM_CPU(obj); 458 uint32_t vq; 459 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); 463 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); 469 } 470 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 478 } 479 480 void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp) 481 { 482 ARMPauthFeature features = cpu_isar_feature(pauth_feature, cpu); 483 uint64_t isar1, isar2; 484 485 /* 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. 490 * 491 * Begin by disabling all fields. 492 */ 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); 498 499 isar2 = cpu->isar.id_aa64isar2; 500 isar2 = FIELD_DP64(isar2, ID_AA64ISAR2, APA3, 0); 501 isar2 = FIELD_DP64(isar2, ID_AA64ISAR2, GPA3, 0); 502 503 if (kvm_enabled() || hvf_enabled()) { 504 /* 505 * Exit early if PAuth is enabled and fall through to disable it. 506 * The algorithm selection properties are not present. 507 */ 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()); 512 } 513 return; 514 } 515 } else { 516 /* Pauth properties are only present when the model supports it. */ 517 if (features == 0) { 518 assert(!cpu->prop_pauth); 519 return; 520 } 521 522 if (cpu->prop_pauth) { 523 if ((cpu->prop_pauth_impdef && cpu->prop_pauth_qarma3) || 524 (cpu->prop_pauth_impdef && cpu->prop_pauth_qarma5) || 525 (cpu->prop_pauth_qarma3 && cpu->prop_pauth_qarma5)) { 526 error_setg(errp, 527 "cannot enable pauth-impdef, pauth-qarma3 and " 528 "pauth-qarma5 at the same time"); 529 return; 530 } 531 532 if (cpu->prop_pauth_impdef) { 533 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, API, features); 534 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPI, 1); 535 } else if (cpu->prop_pauth_qarma3) { 536 isar2 = FIELD_DP64(isar2, ID_AA64ISAR2, APA3, features); 537 isar2 = FIELD_DP64(isar2, ID_AA64ISAR2, GPA3, 1); 538 } else { /* default is pauth-qarma5 */ 539 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, APA, features); 540 isar1 = FIELD_DP64(isar1, ID_AA64ISAR1, GPA, 1); 541 } 542 } else if (cpu->prop_pauth_impdef || 543 cpu->prop_pauth_qarma3 || 544 cpu->prop_pauth_qarma5) { 545 error_setg(errp, "cannot enable pauth-impdef, pauth-qarma3 or " 546 "pauth-qarma5 without pauth"); 547 error_append_hint(errp, "Add pauth=on to the CPU property list.\n"); 548 } 549 } 550 551 cpu->isar.id_aa64isar1 = isar1; 552 cpu->isar.id_aa64isar2 = isar2; 553 } 554 555 static const Property arm_cpu_pauth_property = 556 DEFINE_PROP_BOOL("pauth", ARMCPU, prop_pauth, true); 557 static const Property arm_cpu_pauth_impdef_property = 558 DEFINE_PROP_BOOL("pauth-impdef", ARMCPU, prop_pauth_impdef, false); 559 static const Property arm_cpu_pauth_qarma3_property = 560 DEFINE_PROP_BOOL("pauth-qarma3", ARMCPU, prop_pauth_qarma3, false); 561 static Property arm_cpu_pauth_qarma5_property = 562 DEFINE_PROP_BOOL("pauth-qarma5", ARMCPU, prop_pauth_qarma5, false); 563 564 void aarch64_add_pauth_properties(Object *obj) 565 { 566 ARMCPU *cpu = ARM_CPU(obj); 567 568 /* Default to PAUTH on, with the architected algorithm on TCG. */ 569 qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_property); 570 if (kvm_enabled() || hvf_enabled()) { 571 /* 572 * Mirror PAuth support from the probed sysregs back into the 573 * property for KVM or hvf. Is it just a bit backward? Yes it is! 574 * Note that prop_pauth is true whether the host CPU supports the 575 * architected QARMA5 algorithm or the IMPDEF one. We don't 576 * provide the separate pauth-impdef property for KVM or hvf, 577 * only for TCG. 578 */ 579 cpu->prop_pauth = cpu_isar_feature(aa64_pauth, cpu); 580 } else { 581 qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_impdef_property); 582 qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_qarma3_property); 583 qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_qarma5_property); 584 } 585 } 586 587 void arm_cpu_lpa2_finalize(ARMCPU *cpu, Error **errp) 588 { 589 uint64_t t; 590 591 /* 592 * We only install the property for tcg -cpu max; this is the 593 * only situation in which the cpu field can be true. 594 */ 595 if (!cpu->prop_lpa2) { 596 return; 597 } 598 599 t = cpu->isar.id_aa64mmfr0; 600 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16, 2); /* 16k pages w/ LPA2 */ 601 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4, 1); /* 4k pages w/ LPA2 */ 602 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16_2, 3); /* 16k stage2 w/ LPA2 */ 603 t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4_2, 3); /* 4k stage2 w/ LPA2 */ 604 cpu->isar.id_aa64mmfr0 = t; 605 } 606 607 static void aarch64_a57_initfn(Object *obj) 608 { 609 ARMCPU *cpu = ARM_CPU(obj); 610 611 cpu->dtb_compatible = "arm,cortex-a57"; 612 set_feature(&cpu->env, ARM_FEATURE_V8); 613 set_feature(&cpu->env, ARM_FEATURE_NEON); 614 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); 615 set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); 616 set_feature(&cpu->env, ARM_FEATURE_AARCH64); 617 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); 618 set_feature(&cpu->env, ARM_FEATURE_EL2); 619 set_feature(&cpu->env, ARM_FEATURE_EL3); 620 set_feature(&cpu->env, ARM_FEATURE_PMU); 621 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A57; 622 cpu->midr = 0x411fd070; 623 cpu->revidr = 0x00000000; 624 cpu->reset_fpsid = 0x41034070; 625 cpu->isar.mvfr0 = 0x10110222; 626 cpu->isar.mvfr1 = 0x12111111; 627 cpu->isar.mvfr2 = 0x00000043; 628 cpu->ctr = 0x8444c004; 629 cpu->reset_sctlr = 0x00c50838; 630 cpu->isar.id_pfr0 = 0x00000131; 631 cpu->isar.id_pfr1 = 0x00011011; 632 cpu->isar.id_dfr0 = 0x03010066; 633 cpu->id_afr0 = 0x00000000; 634 cpu->isar.id_mmfr0 = 0x10101105; 635 cpu->isar.id_mmfr1 = 0x40000000; 636 cpu->isar.id_mmfr2 = 0x01260000; 637 cpu->isar.id_mmfr3 = 0x02102211; 638 cpu->isar.id_isar0 = 0x02101110; 639 cpu->isar.id_isar1 = 0x13112111; 640 cpu->isar.id_isar2 = 0x21232042; 641 cpu->isar.id_isar3 = 0x01112131; 642 cpu->isar.id_isar4 = 0x00011142; 643 cpu->isar.id_isar5 = 0x00011121; 644 cpu->isar.id_isar6 = 0; 645 cpu->isar.id_aa64pfr0 = 0x00002222; 646 cpu->isar.id_aa64dfr0 = 0x10305106; 647 cpu->isar.id_aa64isar0 = 0x00011120; 648 cpu->isar.id_aa64mmfr0 = 0x00001124; 649 cpu->isar.dbgdidr = 0x3516d000; 650 cpu->isar.dbgdevid = 0x01110f13; 651 cpu->isar.dbgdevid1 = 0x2; 652 cpu->isar.reset_pmcr_el0 = 0x41013000; 653 cpu->clidr = 0x0a200023; 654 /* 32KB L1 dcache */ 655 cpu->ccsidr[0] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 4, 64, 32 * KiB, 7); 656 /* 48KB L1 icache */ 657 cpu->ccsidr[1] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 3, 64, 48 * KiB, 2); 658 /* 2048KB L2 cache */ 659 cpu->ccsidr[2] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 16, 64, 2 * MiB, 7); 660 cpu->dcz_blocksize = 4; /* 64 bytes */ 661 cpu->gic_num_lrs = 4; 662 cpu->gic_vpribits = 5; 663 cpu->gic_vprebits = 5; 664 cpu->gic_pribits = 5; 665 define_cortex_a72_a57_a53_cp_reginfo(cpu); 666 } 667 668 static void aarch64_a53_initfn(Object *obj) 669 { 670 ARMCPU *cpu = ARM_CPU(obj); 671 672 cpu->dtb_compatible = "arm,cortex-a53"; 673 set_feature(&cpu->env, ARM_FEATURE_V8); 674 set_feature(&cpu->env, ARM_FEATURE_NEON); 675 set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); 676 set_feature(&cpu->env, ARM_FEATURE_BACKCOMPAT_CNTFRQ); 677 set_feature(&cpu->env, ARM_FEATURE_AARCH64); 678 set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); 679 set_feature(&cpu->env, ARM_FEATURE_EL2); 680 set_feature(&cpu->env, ARM_FEATURE_EL3); 681 set_feature(&cpu->env, ARM_FEATURE_PMU); 682 cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A53; 683 cpu->midr = 0x410fd034; 684 cpu->revidr = 0x00000100; 685 cpu->reset_fpsid = 0x41034070; 686 cpu->isar.mvfr0 = 0x10110222; 687 cpu->isar.mvfr1 = 0x12111111; 688 cpu->isar.mvfr2 = 0x00000043; 689 cpu->ctr = 0x84448004; /* L1Ip = VIPT */ 690 cpu->reset_sctlr = 0x00c50838; 691 cpu->isar.id_pfr0 = 0x00000131; 692 cpu->isar.id_pfr1 = 0x00011011; 693 cpu->isar.id_dfr0 = 0x03010066; 694 cpu->id_afr0 = 0x00000000; 695 cpu->isar.id_mmfr0 = 0x10101105; 696 cpu->isar.id_mmfr1 = 0x40000000; 697 cpu->isar.id_mmfr2 = 0x01260000; 698 cpu->isar.id_mmfr3 = 0x02102211; 699 cpu->isar.id_isar0 = 0x02101110; 700 cpu->isar.id_isar1 = 0x13112111; 701 cpu->isar.id_isar2 = 0x21232042; 702 cpu->isar.id_isar3 = 0x01112131; 703 cpu->isar.id_isar4 = 0x00011142; 704 cpu->isar.id_isar5 = 0x00011121; 705 cpu->isar.id_isar6 = 0; 706 cpu->isar.id_aa64pfr0 = 0x00002222; 707 cpu->isar.id_aa64dfr0 = 0x10305106; 708 cpu->isar.id_aa64isar0 = 0x00011120; 709 cpu->isar.id_aa64mmfr0 = 0x00001122; /* 40 bit physical addr */ 710 cpu->isar.dbgdidr = 0x3516d000; 711 cpu->isar.dbgdevid = 0x00110f13; 712 cpu->isar.dbgdevid1 = 0x1; 713 cpu->isar.reset_pmcr_el0 = 0x41033000; 714 cpu->clidr = 0x0a200023; 715 /* 32KB L1 dcache */ 716 cpu->ccsidr[0] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 4, 64, 32 * KiB, 7); 717 /* 32KB L1 icache */ 718 cpu->ccsidr[1] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 1, 64, 32 * KiB, 2); 719 /* 1024KB L2 cache */ 720 cpu->ccsidr[2] = make_ccsidr(CCSIDR_FORMAT_LEGACY, 16, 64, 1 * MiB, 7); 721 cpu->dcz_blocksize = 4; /* 64 bytes */ 722 cpu->gic_num_lrs = 4; 723 cpu->gic_vpribits = 5; 724 cpu->gic_vprebits = 5; 725 cpu->gic_pribits = 5; 726 define_cortex_a72_a57_a53_cp_reginfo(cpu); 727 } 728 729 static void aarch64_host_initfn(Object *obj) 730 { 731 #if defined(CONFIG_KVM) 732 ARMCPU *cpu = ARM_CPU(obj); 733 kvm_arm_set_cpu_features_from_host(cpu); 734 if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { 735 aarch64_add_sve_properties(obj); 736 aarch64_add_pauth_properties(obj); 737 } 738 #elif defined(CONFIG_HVF) 739 ARMCPU *cpu = ARM_CPU(obj); 740 hvf_arm_set_cpu_features_from_host(cpu); 741 aarch64_add_pauth_properties(obj); 742 #else 743 g_assert_not_reached(); 744 #endif 745 } 746 747 static void aarch64_max_initfn(Object *obj) 748 { 749 if (kvm_enabled() || hvf_enabled()) { 750 /* With KVM or HVF, '-cpu max' is identical to '-cpu host' */ 751 aarch64_host_initfn(obj); 752 return; 753 } 754 755 if (tcg_enabled() || qtest_enabled()) { 756 aarch64_a57_initfn(obj); 757 } 758 759 /* '-cpu max' for TCG: we currently do this as "A57 with extra things" */ 760 if (tcg_enabled()) { 761 aarch64_max_tcg_initfn(obj); 762 } 763 } 764 765 static const ARMCPUInfo aarch64_cpus[] = { 766 { .name = "cortex-a57", .initfn = aarch64_a57_initfn }, 767 { .name = "cortex-a53", .initfn = aarch64_a53_initfn }, 768 { .name = "max", .initfn = aarch64_max_initfn }, 769 #if defined(CONFIG_KVM) || defined(CONFIG_HVF) 770 { .name = "host", .initfn = aarch64_host_initfn }, 771 #endif 772 }; 773 774 static bool aarch64_cpu_get_aarch64(Object *obj, Error **errp) 775 { 776 ARMCPU *cpu = ARM_CPU(obj); 777 778 return arm_feature(&cpu->env, ARM_FEATURE_AARCH64); 779 } 780 781 static void aarch64_cpu_set_aarch64(Object *obj, bool value, Error **errp) 782 { 783 ARMCPU *cpu = ARM_CPU(obj); 784 785 /* At this time, this property is only allowed if KVM is enabled. This 786 * restriction allows us to avoid fixing up functionality that assumes a 787 * uniform execution state like do_interrupt. 788 */ 789 if (value == false) { 790 if (!kvm_enabled() || !kvm_arm_aarch32_supported()) { 791 error_setg(errp, "'aarch64' feature cannot be disabled " 792 "unless KVM is enabled and 32-bit EL1 " 793 "is supported"); 794 return; 795 } 796 unset_feature(&cpu->env, ARM_FEATURE_AARCH64); 797 } else { 798 set_feature(&cpu->env, ARM_FEATURE_AARCH64); 799 } 800 } 801 802 static void aarch64_cpu_finalizefn(Object *obj) 803 { 804 } 805 806 static const gchar *aarch64_gdb_arch_name(CPUState *cs) 807 { 808 return "aarch64"; 809 } 810 811 static void aarch64_cpu_class_init(ObjectClass *oc, void *data) 812 { 813 CPUClass *cc = CPU_CLASS(oc); 814 815 cc->gdb_read_register = aarch64_cpu_gdb_read_register; 816 cc->gdb_write_register = aarch64_cpu_gdb_write_register; 817 cc->gdb_core_xml_file = "aarch64-core.xml"; 818 cc->gdb_arch_name = aarch64_gdb_arch_name; 819 820 object_class_property_add_bool(oc, "aarch64", aarch64_cpu_get_aarch64, 821 aarch64_cpu_set_aarch64); 822 object_class_property_set_description(oc, "aarch64", 823 "Set on/off to enable/disable aarch64 " 824 "execution state "); 825 } 826 827 static void aarch64_cpu_instance_init(Object *obj) 828 { 829 ARMCPUClass *acc = ARM_CPU_GET_CLASS(obj); 830 831 acc->info->initfn(obj); 832 arm_cpu_post_init(obj); 833 } 834 835 static void cpu_register_class_init(ObjectClass *oc, void *data) 836 { 837 ARMCPUClass *acc = ARM_CPU_CLASS(oc); 838 839 acc->info = data; 840 } 841 842 void aarch64_cpu_register(const ARMCPUInfo *info) 843 { 844 TypeInfo type_info = { 845 .parent = TYPE_AARCH64_CPU, 846 .instance_init = aarch64_cpu_instance_init, 847 .class_init = info->class_init ?: cpu_register_class_init, 848 .class_data = (void *)info, 849 }; 850 851 type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name); 852 type_register_static(&type_info); 853 g_free((void *)type_info.name); 854 } 855 856 static const TypeInfo aarch64_cpu_type_info = { 857 .name = TYPE_AARCH64_CPU, 858 .parent = TYPE_ARM_CPU, 859 .instance_finalize = aarch64_cpu_finalizefn, 860 .abstract = true, 861 .class_init = aarch64_cpu_class_init, 862 }; 863 864 static void aarch64_cpu_register_types(void) 865 { 866 size_t i; 867 868 type_register_static(&aarch64_cpu_type_info); 869 870 for (i = 0; i < ARRAY_SIZE(aarch64_cpus); ++i) { 871 aarch64_cpu_register(&aarch64_cpus[i]); 872 } 873 } 874 875 type_init(aarch64_cpu_register_types) 876