| 1 | /* |
| 2 | * QEMU Hypervisor.framework (HVF) support -- ARM specifics |
| 3 | * |
| 4 | * Copyright (c) 2021 Alexander Graf |
| 5 | * |
| 6 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 7 | * See the COPYING file in the top-level directory. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #ifndef QEMU_HVF_ARM_H |
| 12 | #define QEMU_HVF_ARM_H |
| 13 | |
| 14 | #include "system/hvf.h" |
| 15 | #include "target/arm/cpu-qom.h" |
| 16 | |
| 17 | /** |
| 18 | * hvf_arm_init_debug() - initialize guest debug capabilities |
| 19 | * |
| 20 | * Should be called only once before using guest debug capabilities. |
| 21 | */ |
| 22 | void hvf_arm_init_debug(void); |
| 23 | |
| 24 | void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu); |
| 25 | |
| 26 | /* |
| 27 | * We need access to types from macOS SDK >=15.2, so expose stubs if the |
| 28 | * headers are not available until we raise our minimum macOS version. |
| 29 | */ |
| 30 | #ifdef __MAC_OS_X_VERSION_MAX_ALLOWED |
| 31 | #if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 150200) && defined(__aarch64__) |
| 32 | #include "system/hvf_int.h" |
| 33 | |
| 34 | static inline bool hvf_arm_sme2_supported(void) |
| 35 | { |
| 36 | if (__builtin_available(macOS 15.2, *)) { |
| 37 | size_t svl_bytes; |
| 38 | hv_return_t result = hv_sme_config_get_max_svl_bytes(&svl_bytes); |
| 39 | /* Nested virt not supported together with SME right now. */ |
| 40 | if (hvf_nested_virt_enabled()) { |
| 41 | return false; |
| 42 | } |
| 43 | if (result == HV_UNSUPPORTED) { |
| 44 | return false; |
| 45 | } |
| 46 | assert_hvf_ok(result); |
| 47 | return svl_bytes > 0; |
| 48 | } else { |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | static inline uint32_t hvf_arm_sme2_get_svl(void) |
| 54 | { |
| 55 | if (__builtin_available(macOS 15.2, *)) { |
| 56 | size_t svl_bytes; |
| 57 | hv_return_t result = hv_sme_config_get_max_svl_bytes(&svl_bytes); |
| 58 | assert_hvf_ok(result); |
| 59 | return svl_bytes; |
| 60 | } else { |
| 61 | abort(); |
| 62 | } |
| 63 | } |
| 64 | #else /* (__MAC_OS_X_VERSION_MAX_ALLOWED >= 150200) */ |
| 65 | #include "hvf/hvf_sme_stubs.h" |
| 66 | #endif /* (__MAC_OS_X_VERSION_MAX_ALLOWED >= 150200) */ |
| 67 | #else /* ifdef __MAC_OS_X_VERSION_MAX_ALLOWED */ |
| 68 | #include "hvf/hvf_sme_stubs.h" |
| 69 | #endif /* ifdef __MAC_OS_X_VERSION_MAX_ALLOWED */ |
| 70 | |
| 71 | #endif |