0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/types.h>
0013 #include <linux/acpi.h>
0014 #include <linux/export.h>
0015 #include <linux/errno.h>
0016 #include <linux/version.h>
0017 #include <linux/cpuhotplug.h>
0018 #include <asm/mshyperv.h>
0019
0020 static bool hyperv_initialized;
0021
0022 static int __init hyperv_init(void)
0023 {
0024 struct hv_get_vp_registers_output result;
0025 u32 a, b, c, d;
0026 u64 guest_id;
0027 int ret;
0028
0029
0030
0031
0032
0033
0034 if (acpi_disabled)
0035 return 0;
0036
0037 if (strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8))
0038 return 0;
0039
0040
0041 guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
0042 hv_set_vpreg(HV_REGISTER_GUEST_OSID, guest_id);
0043
0044
0045 hv_get_vpreg_128(HV_REGISTER_FEATURES, &result);
0046 ms_hyperv.features = result.as32.a;
0047 ms_hyperv.priv_high = result.as32.b;
0048 ms_hyperv.misc_features = result.as32.c;
0049
0050 hv_get_vpreg_128(HV_REGISTER_ENLIGHTENMENTS, &result);
0051 ms_hyperv.hints = result.as32.a;
0052
0053 pr_info("Hyper-V: privilege flags low 0x%x, high 0x%x, hints 0x%x, misc 0x%x\n",
0054 ms_hyperv.features, ms_hyperv.priv_high, ms_hyperv.hints,
0055 ms_hyperv.misc_features);
0056
0057
0058 hv_get_vpreg_128(HV_REGISTER_HYPERVISOR_VERSION, &result);
0059 a = result.as32.a;
0060 b = result.as32.b;
0061 c = result.as32.c;
0062 d = result.as32.d;
0063 pr_info("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n",
0064 b >> 16, b & 0xFFFF, a, d & 0xFFFFFF, c, d >> 24);
0065
0066 ret = hv_common_init();
0067 if (ret)
0068 return ret;
0069
0070 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "arm64/hyperv_init:online",
0071 hv_common_cpu_init, hv_common_cpu_die);
0072 if (ret < 0) {
0073 hv_common_free();
0074 return ret;
0075 }
0076
0077 hyperv_initialized = true;
0078 return 0;
0079 }
0080
0081 early_initcall(hyperv_init);
0082
0083 bool hv_is_hyperv_initialized(void)
0084 {
0085 return hyperv_initialized;
0086 }
0087 EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized);