[v9,05/27] virt: gunyah: Identify hypervisor version
Commit Message
Export the version of Gunyah which is reported via the hyp_identify
hypercall. Increments of the major API version indicate possibly
backwards incompatible changes.
Export the hypervisor identity so that Gunyah drivers can act according
to the major API version.
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
---
drivers/virt/Makefile | 1 +
drivers/virt/gunyah/Makefile | 3 ++
drivers/virt/gunyah/gunyah.c | 54 ++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+)
create mode 100644 drivers/virt/gunyah/Makefile
create mode 100644 drivers/virt/gunyah/gunyah.c
@@ -12,3 +12,4 @@ obj-$(CONFIG_ACRN_HSM) += acrn/
obj-$(CONFIG_EFI_SECRET) += coco/efi_secret/
obj-$(CONFIG_SEV_GUEST) += coco/sev-guest/
obj-$(CONFIG_INTEL_TDX_GUEST) += coco/tdx-guest/
+obj-y += gunyah/
new file mode 100644
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_GUNYAH) += gunyah.o
new file mode 100644
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+#define pr_fmt(fmt) "gunyah: " fmt
+
+#include <linux/gunyah.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/printk.h>
+
+static struct gh_hypercall_hyp_identify_resp gunyah_api;
+
+u16 gh_api_version(void)
+{
+ return FIELD_GET(GH_API_INFO_API_VERSION_MASK, gunyah_api.api_info);
+}
+EXPORT_SYMBOL_GPL(gh_api_version);
+
+bool gh_api_has_feature(enum gh_api_feature feature)
+{
+ switch (feature) {
+ case GH_API_FEATURE_DOORBELL:
+ return !!(gunyah_api.flags[0] & GH_IDENTIFY_DOORBELL);
+ case GH_API_FEATURE_MSGQUEUE:
+ return !!(gunyah_api.flags[0] & GH_IDENTIFY_MSGQUEUE);
+ case GH_API_FEATURE_VCPU:
+ return !!(gunyah_api.flags[0] & GH_IDENTIFY_VCPU);
+ case GH_API_FEATURE_MEMEXTENT:
+ return !!(gunyah_api.flags[0] & GH_IDENTIFY_MEMEXTENT);
+ default:
+ return false;
+ }
+}
+EXPORT_SYMBOL_GPL(gh_api_has_feature);
+
+static int __init gunyah_init(void)
+{
+ if (!arch_is_gunyah_guest())
+ return -ENODEV;
+
+ gh_hypercall_hyp_identify(&gunyah_api);
+
+ pr_info("Running under Gunyah hypervisor %llx/v%u\n",
+ FIELD_GET(GH_API_INFO_VARIANT_MASK, gunyah_api.api_info),
+ gh_api_version());
+
+ return 0;
+}
+arch_initcall(gunyah_init);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Gunyah Hypervisor Driver");