From: Yan Zhao <yan.y.zhao@intel.com>
To: alex.williamson@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
cohuck@redhat.com, zhenyuw@linux.intel.com, zhi.a.wang@intel.com,
kevin.tian@intel.com, shaopeng.he@intel.com, yi.l.liu@intel.com,
Yan Zhao <yan.y.zhao@intel.com>
Subject: [RFC PATCH v3 7/9] samples/vfio-pci: add a sample vendor module of vfio-pci for IGD devices
Date: Tue, 11 Feb 2020 05:14:47 -0500 [thread overview]
Message-ID: <20200211101447.21137-1-yan.y.zhao@intel.com> (raw)
In-Reply-To: <20200211095727.20426-1-yan.y.zhao@intel.com>
This sample driver does nothing but calls default device ops of vfio-pci
to pass through IGD devices.
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
---
samples/Kconfig | 6 ++
samples/Makefile | 1 +
samples/vfio-pci/Makefile | 2 +
samples/vfio-pci/igd_pt.c | 148 ++++++++++++++++++++++++++++++++++++++
4 files changed, 157 insertions(+)
create mode 100644 samples/vfio-pci/Makefile
create mode 100644 samples/vfio-pci/igd_pt.c
diff --git a/samples/Kconfig b/samples/Kconfig
index c8dacb4dda80..84d6a91567af 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -169,4 +169,10 @@ config SAMPLE_VFS
as mount API and statx(). Note that this is restricted to the x86
arch whilst it accesses system calls that aren't yet in all arches.
+config SAMPLE_VFIO_PCI_IGD_PT
+ tristate "Build VFIO sample vendor driver to pass through IGD devices -- loadable modules only"
+ depends on VFIO_PCI && m
+ help
+ Build a sample driver to pass through IGD devices as a vendor driver
+ of VFIO PCI.
endif # SAMPLES
diff --git a/samples/Makefile b/samples/Makefile
index 7d6e4ca28d69..db56daf3a11c 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -19,4 +19,5 @@ obj-$(CONFIG_SAMPLE_TRACE_EVENTS) += trace_events/
obj-$(CONFIG_SAMPLE_TRACE_PRINTK) += trace_printk/
obj-$(CONFIG_VIDEO_PCI_SKELETON) += v4l/
obj-y += vfio-mdev/
+obj-y += vfio-pci/
subdir-$(CONFIG_SAMPLE_VFS) += vfs
diff --git a/samples/vfio-pci/Makefile b/samples/vfio-pci/Makefile
new file mode 100644
index 000000000000..7125f0a325c2
--- /dev/null
+++ b/samples/vfio-pci/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_SAMPLE_VFIO_PCI_IGD_PT) += igd_pt.o
diff --git a/samples/vfio-pci/igd_pt.c b/samples/vfio-pci/igd_pt.c
new file mode 100644
index 000000000000..45acbd1ad2fb
--- /dev/null
+++ b/samples/vfio-pci/igd_pt.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Pass through IGD devices as a vendor driver of vfio-pci device driver
+ * Copyright(c) 2019 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/vfio.h>
+#include <linux/sysfs.h>
+#include <linux/file.h>
+#include <linux/pci.h>
+#include <linux/eventfd.h>
+
+#define VERSION_STRING "0.1"
+#define DRIVER_AUTHOR "Intel Corporation"
+
+/*
+ * below are pciids of IGD devices supported in this driver
+ */
+static const struct pci_device_id pciidlist[] = {
+ {0x8086, 0x5927, ~0, ~0, 0x30000, 0xff0000, 0},
+ {0x8086, 0x591d, ~0, ~0, 0x30000, 0xff0000, 0},
+ {0x8086, 0x193b, ~0, ~0, 0x30000, 0xff0000, 0},
+};
+
+struct igd_pt_device {
+ __u32 vendor;
+ __u32 device;
+
+};
+
+void *igd_pt_probe(struct pci_dev *pdev)
+{
+ int supported_dev_cnt =
+ sizeof(pciidlist)/sizeof(struct pci_device_id);
+ int i;
+ struct igd_pt_device *igd_device;
+
+ for (i = 0; i < supported_dev_cnt; i++) {
+ if (pciidlist[i].vendor == pdev->vendor &&
+ pciidlist[i].device == pdev->device)
+ goto support;
+ }
+
+ return ERR_PTR(-ENODEV);
+
+support:
+
+ igd_device = kzalloc(sizeof(*igd_device), GFP_KERNEL);
+
+ if (!igd_device)
+ return ERR_PTR(-ENOMEM);
+
+ igd_device->vendor = pdev->vendor;
+ igd_device->device = pdev->device;
+
+ return igd_device;
+}
+
+static void igd_pt_remove(void *vendor_data)
+{
+ struct igd_pt_device *igd_device =
+ (struct igd_pt_device *)vendor_data;
+
+ kfree(igd_device);
+}
+
+static int igd_pt_open(void *device_data)
+{
+ struct vfio_pci_device *vdev = device_data;
+
+ return vfio_pci_open(vdev);
+}
+
+void igd_pt_release(void *device_data)
+{
+ struct vfio_pci_device *vdev = device_data;
+
+ vfio_pci_release(vdev);
+}
+
+static long igd_pt_ioctl(void *device_data,
+ unsigned int cmd, unsigned long arg)
+{
+ struct vfio_pci_device *vdev = device_data;
+
+ return vfio_pci_ioctl(vdev, cmd, arg);
+}
+
+static ssize_t igd_pt_read(void *device_data, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct vfio_pci_device *vdev = device_data;
+
+ return vfio_pci_read(vdev, buf, count, ppos);
+}
+
+static ssize_t igd_pt_write(void *device_data, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct vfio_pci_device *vdev = device_data;
+
+ return vfio_pci_write(vdev, buf, count, ppos);
+}
+
+static int igd_pt_mmap(void *device_data, struct vm_area_struct *vma)
+{
+ struct vfio_pci_device *vdev = device_data;
+
+ return vfio_pci_mmap(vdev, vma);
+}
+
+static void igd_pt_request(void *device_data, unsigned int count)
+{
+ struct vfio_pci_device *vdev = device_data;
+
+ vfio_pci_request(vdev, count);
+}
+
+static struct vfio_device_ops igd_pt_device_ops_node = {
+ .name = "IGD dt",
+ .open = igd_pt_open,
+ .release = igd_pt_release,
+ .ioctl = igd_pt_ioctl,
+ .read = igd_pt_read,
+ .write = igd_pt_write,
+ .mmap = igd_pt_mmap,
+ .request = igd_pt_request,
+};
+
+#define igd_pt_device_ops (&igd_pt_device_ops_node)
+
+module_vfio_pci_register_vendor_handler("IGD dt", igd_pt_probe,
+ igd_pt_remove, igd_pt_device_ops);
+
+MODULE_ALIAS("vfio-pci:8086-591d");
+MODULE_ALIAS("vfio-pci:8086-5927");
+MODULE_LICENSE("GPL v2");
+MODULE_INFO(supported, "Sample driver as vendor driver of vfio-pci to pass through IGD");
+MODULE_VERSION(VERSION_STRING);
+MODULE_AUTHOR(DRIVER_AUTHOR);
--
2.17.1
next prev parent reply other threads:[~2020-02-11 10:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-11 9:57 [RFC PATCH v3 0/9] Introduce vendor ops in vfio-pci Yan Zhao
2020-02-11 10:10 ` [RFC PATCH v3 1/9] vfio/pci: export vfio_pci_device public and add vfio_pci_device_private Yan Zhao
2020-02-20 21:00 ` Alex Williamson
2020-02-21 6:19 ` Yan Zhao
2020-02-11 10:11 ` [RFC PATCH v3 2/9] vfio/pci: export functions in vfio_pci_ops Yan Zhao
2020-02-11 10:11 ` [RFC PATCH v3 3/9] vfio/pci: register/unregister vfio_pci_vendor_driver_ops Yan Zhao
2020-02-11 10:12 ` [RFC PATCH v3 4/9] vfio/pci: macros to generate module_init and module_exit for vendor modules Yan Zhao
2020-02-11 10:13 ` [RFC PATCH v3 5/9] vfio/pci: let vfio_pci know how many vendor regions are registered Yan Zhao
2020-02-11 10:14 ` [RFC PATCH v3 6/9] vfio/pci: export vfio_pci_setup_barmap Yan Zhao
2020-02-20 21:00 ` Alex Williamson
2020-02-21 6:20 ` Yan Zhao
2020-02-11 10:14 ` Yan Zhao [this message]
2020-02-11 10:15 ` [RFC PATCH v3 8/9] vfio: header for vfio live migration region Yan Zhao
2020-02-11 10:15 ` [RFC PATCH v3 9/9] i40e/vf_migration: vfio-pci vendor driver for VF live migration Yan Zhao
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=20200211101447.21137-1-yan.y.zhao@intel.com \
--to=yan.y.zhao@intel.com \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shaopeng.he@intel.com \
--cc=yi.l.liu@intel.com \
--cc=zhenyuw@linux.intel.com \
--cc=zhi.a.wang@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