driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
From: yakui.zhao@intel.com (Zhao Yakui)
Subject: [RFC PATCH 06/15] drivers/acrn: add the support of querying ACRN api version
Date: Fri, 16 Aug 2019 10:25:47 +0800	[thread overview]
Message-ID: <1565922356-4488-7-git-send-email-yakui.zhao@intel.com> (raw)
In-Reply-To: <1565922356-4488-1-git-send-email-yakui.zhao@intel.com>

In order to assure that the ACRN module can work with the required ACRN
hypervisor, it needs to check whether the required version is consistent
with the queried version from ACRN ypervisor. If it is inconsistent, it
won't coninue the initialization of ACRN_HSM module.
Similarly the user-space module also needs to check the driver version.

Co-developed-by: Jason Chen CJ <jason.cj.chen at intel.com>
Signed-off-by: Jason Chen CJ <jason.cj.chen at intel.com>
Co-developed-by: Liu Shuo <shuo.a.liu at intel.com>
Signed-off-by: Liu Shuo <shuo.a.liu at intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao at intel.com>
---
 drivers/staging/acrn/acrn_dev.c           | 47 +++++++++++++++++++++++++++++++
 include/uapi/linux/acrn/acrn_ioctl_defs.h | 32 +++++++++++++++++++++
 2 files changed, 79 insertions(+)
 create mode 100644 include/uapi/linux/acrn/acrn_ioctl_defs.h

diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c
index 55a7612..57cd2bb 100644
--- a/drivers/staging/acrn/acrn_dev.c
+++ b/drivers/staging/acrn/acrn_dev.c
@@ -18,13 +18,22 @@
 #include <linux/kdev_t.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/io.h>
 #include <linux/module.h>
+#include <linux/uaccess.h>
+#include <linux/slab.h>
 #include <asm/acrn.h>
 #include <asm/hypervisor.h>
+#include <linux/acrn/acrn_ioctl_defs.h>
+
+#include "acrn_hypercall.h"
 
 #define  DEVICE_NAME "acrn_hsm"
 #define  CLASS_NAME  "acrn"
 
+#define ACRN_API_VERSION_MAJOR	1
+#define ACRN_API_VERSION_MINOR	0
+
 static int	acrn_hsm_inited;
 static int	major;
 static struct class	*acrn_class;
@@ -44,6 +53,19 @@ long acrn_dev_ioctl(struct file *filep,
 {
 	long ret = 0;
 
+	if (ioctl_num == IC_GET_API_VERSION) {
+		struct api_version api_version;
+
+		api_version.major_version = ACRN_API_VERSION_MAJOR;
+		api_version.minor_version = ACRN_API_VERSION_MINOR;
+
+		if (copy_to_user((void *)ioctl_param, &api_version,
+				 sizeof(api_version)))
+			return -EFAULT;
+
+		return 0;
+	}
+
 	return ret;
 }
 
@@ -59,9 +81,12 @@ static const struct file_operations fops = {
 };
 
 #define EAX_PRIVILEGE_VM	BIT(0)
+#define SUPPORT_HV_API_VERSION_MAJOR	1
+#define SUPPORT_HV_API_VERSION_MINOR	0
 
 static int __init acrn_init(void)
 {
+	struct api_version *api_version;
 	acrn_hsm_inited = 0;
 	if (x86_hyper_type != X86_HYPER_ACRN)
 		return -ENODEV;
@@ -69,6 +94,28 @@ static int __init acrn_init(void)
 	if (!(cpuid_eax(0x40000001) & EAX_PRIVILEGE_VM))
 		return -EPERM;
 
+	api_version = kmalloc(sizeof(*api_version), GFP_KERNEL);
+	if (!api_version)
+		return -ENOMEM;
+
+	if (hcall_get_api_version(virt_to_phys(api_version)) < 0) {
+		pr_err("acrn: failed to get api version from Hypervisor !\n");
+		kfree(api_version);
+		return -EINVAL;
+	}
+
+	if (api_version->major_version >= SUPPORT_HV_API_VERSION_MAJOR &&
+	    api_version->minor_version >= SUPPORT_HV_API_VERSION_MINOR) {
+		pr_info("acrn: hv api version %d.%d\n",
+			api_version->major_version, api_version->minor_version);
+		kfree(api_version);
+	} else {
+		pr_err("acrn: not support hv api version %d.%d!\n",
+		       api_version->major_version, api_version->minor_version);
+		kfree(api_version);
+		return -EINVAL;
+	}
+
 	/* Try to dynamically allocate a major number for the device */
 	major = register_chrdev(0, DEVICE_NAME, &fops);
 	if (major < 0) {
diff --git a/include/uapi/linux/acrn/acrn_ioctl_defs.h b/include/uapi/linux/acrn/acrn_ioctl_defs.h
new file mode 100644
index 0000000..8dbf69a
--- /dev/null
+++ b/include/uapi/linux/acrn/acrn_ioctl_defs.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
+/**
+ * @file acrn_ioctl_defs.h
+ *
+ * ACRN definition for ioctl to user space
+ */
+
+#ifndef __ACRN_IOCTL_DEFS_H__
+#define __ACRN_IOCTL_DEFS_H__
+
+/**
+ * struct api_version - data structure to track ACRN_SRV API version
+ *
+ * @major_version: major version of ACRN_SRV API
+ * @minor_version: minor version of ACRN_SRV API
+ */
+struct api_version {
+	uint32_t major_version;
+	uint32_t minor_version;
+};
+
+/*
+ * Common IOCTL ID definition for DM
+ */
+#define _IC_ID(x, y) (((x) << 24) | (y))
+#define IC_ID 0x43UL
+
+/* General */
+#define IC_ID_GEN_BASE                  0x0UL
+#define IC_GET_API_VERSION             _IC_ID(IC_ID, IC_ID_GEN_BASE + 0x00)
+
+#endif /* __ACRN_IOCTL_DEFS_H__ */
-- 
2.7.4

  parent reply	other threads:[~2019-08-16  2:25 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16  2:25 [RFC PATCH 00/15] acrn: add the ACRN driver module Zhao Yakui
2019-08-16  2:25 ` [RFC PATCH 01/15] x86/acrn: Report X2APIC for ACRN guest Zhao Yakui
2019-08-16  2:25 ` [RFC PATCH 02/15] x86/acrn: Add two APIs to add/remove driver-specific upcall ISR handler Zhao Yakui
2019-08-16  2:25 ` [RFC PATCH 03/15] x86/acrn: Add hypercall for ACRN guest Zhao Yakui
2019-08-16  2:25 ` [RFC PATCH 04/15] drivers/acrn: add the basic framework of acrn char device driver Zhao Yakui
2019-08-16  7:05   ` Greg KH
2019-08-19  4:02     ` Zhao, Yakui
2019-08-19  5:26       ` Greg KH
2019-08-16 11:28   ` Dan Carpenter
2019-08-16  2:25 ` [RFC PATCH 05/15] drivers/acrn: add driver-specific hypercall for ACRN_HSM Zhao Yakui
2019-08-16  2:25 ` Zhao Yakui [this message]
2019-08-16  2:25 ` [RFC PATCH 07/15] drivers/acrn: add acrn vm/vcpu management for ACRN_HSM char device Zhao Yakui
2019-08-16  2:25 ` [RFC PATCH 08/15] drivers/acrn: add VM memory management for ACRN " Zhao Yakui
2019-08-16 12:58   ` Dan Carpenter
2019-08-19  5:32     ` Zhao, Yakui
2019-08-19  7:39       ` Dan Carpenter
2019-08-19  7:46         ` Borislav Petkov
2019-08-20  2:25         ` Zhao, Yakui
2019-08-16  2:25 ` [RFC PATCH 09/15] drivers/acrn: add passthrough device support Zhao Yakui
2019-08-16 13:05   ` Dan Carpenter
2019-09-02  0:18     ` Zhao, Yakui
2019-08-16  2:25 ` [RFC PATCH 10/15] drivers/acrn: add interrupt injection support Zhao Yakui
2019-08-16 13:12   ` Dan Carpenter
2019-08-19  4:59     ` Zhao, Yakui
2019-08-16  2:25 ` [RFC PATCH 11/15] drivers/acrn: add the support of handling emulated ioreq Zhao Yakui
2019-08-16 13:39   ` Dan Carpenter
2019-08-19  4:54     ` Zhao, Yakui
2019-08-16  2:25 ` [RFC PATCH 12/15] drivers/acrn: add driver-specific IRQ handle to dispatch IO_REQ request Zhao Yakui
2019-08-16  2:25 ` [RFC PATCH 13/15] drivers/acrn: add service to obtain Power data transition Zhao Yakui
2019-08-16  2:25 ` [RFC PATCH 14/15] drivers/acrn: add the support of irqfd and eventfd Zhao Yakui
2019-08-16  2:25 ` [RFC PATCH 15/15] drivers/acrn: add the support of offline SOS cpu Zhao Yakui
2019-08-19 10:34   ` Dan Carpenter
2019-08-20  2:23     ` Zhao, Yakui
2019-08-16  6:39 ` [RFC PATCH 00/15] acrn: add the ACRN driver module Borislav Petkov
2019-08-16  7:03   ` Greg KH
2019-08-19  2:39     ` Zhao, Yakui
2019-08-19  5:25       ` Greg KH
2019-08-19  1:44   ` Zhao, Yakui
2019-08-19  5:25     ` Greg KH
2019-08-19  5:39       ` Zhao, Yakui
2019-08-19  6:18     ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1565922356-4488-7-git-send-email-yakui.zhao@intel.com \
    --to=yakui.zhao@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).