From: Antonios Motakis <a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
To: kvmarm-FPEHb7Xf0XXUo1n7N8X6UoWGPAHP3yOg@public.gmane.org,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Cc: "open list:VFIO DRIVER"
<kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
eric.auger-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
marc.zyngier-5wv7dgnIgG8@public.gmane.org,
will.deacon-5wv7dgnIgG8@public.gmane.org,
open list <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Antonios Motakis
<a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>,
tech-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org,
christoffer.dall-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org
Subject: [PATCH v10 01/20] vfio/platform: initial skeleton of VFIO support for platform devices
Date: Thu, 27 Nov 2014 18:32:41 +0100 [thread overview]
Message-ID: <1417109580-10505-2-git-send-email-a.motakis@virtualopensystems.com> (raw)
In-Reply-To: <1417109580-10505-1-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
This patch forms the common skeleton code for platform devices support
with VFIO. This will include the core functionality of VFIO_PLATFORM,
however binding to the device and discovering the device resources will
be done with the help of a separate file where any Linux platform bus
specific code will reside.
This will allow us to implement support for also discovering AMBA devices
and their resources, but still reuse a large part of the VFIO_PLATFORM
implementation.
Signed-off-by: Antonios Motakis <a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
---
drivers/vfio/platform/vfio_platform_common.c | 121 ++++++++++++++++++++++++++
drivers/vfio/platform/vfio_platform_private.h | 36 ++++++++
2 files changed, 157 insertions(+)
create mode 100644 drivers/vfio/platform/vfio_platform_common.c
create mode 100644 drivers/vfio/platform/vfio_platform_private.h
diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
new file mode 100644
index 0000000..34d023b
--- /dev/null
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2013 - Virtual Open Systems
+ * Author: Antonios Motakis <a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/device.h>
+#include <linux/iommu.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <linux/vfio.h>
+
+#include "vfio_platform_private.h"
+
+static void vfio_platform_release(void *device_data)
+{
+ module_put(THIS_MODULE);
+}
+
+static int vfio_platform_open(void *device_data)
+{
+ if (!try_module_get(THIS_MODULE))
+ return -ENODEV;
+
+ return 0;
+}
+
+static long vfio_platform_ioctl(void *device_data,
+ unsigned int cmd, unsigned long arg)
+{
+ if (cmd == VFIO_DEVICE_GET_INFO)
+ return -EINVAL;
+
+ else if (cmd == VFIO_DEVICE_GET_REGION_INFO)
+ return -EINVAL;
+
+ else if (cmd == VFIO_DEVICE_GET_IRQ_INFO)
+ return -EINVAL;
+
+ else if (cmd == VFIO_DEVICE_SET_IRQS)
+ return -EINVAL;
+
+ else if (cmd == VFIO_DEVICE_RESET)
+ return -EINVAL;
+
+ return -ENOTTY;
+}
+
+static ssize_t vfio_platform_read(void *device_data, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ return -EINVAL;
+}
+
+static ssize_t vfio_platform_write(void *device_data, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ return -EINVAL;
+}
+
+static int vfio_platform_mmap(void *device_data, struct vm_area_struct *vma)
+{
+ return -EINVAL;
+}
+
+static const struct vfio_device_ops vfio_platform_ops = {
+ .name = "vfio-platform",
+ .open = vfio_platform_open,
+ .release = vfio_platform_release,
+ .ioctl = vfio_platform_ioctl,
+ .read = vfio_platform_read,
+ .write = vfio_platform_write,
+ .mmap = vfio_platform_mmap,
+};
+
+int vfio_platform_probe_common(struct vfio_platform_device *vdev,
+ struct device *dev)
+{
+ struct iommu_group *group;
+ int ret;
+
+ if (!vdev)
+ return -EINVAL;
+
+ group = iommu_group_get(dev);
+ if (!group) {
+ pr_err("VFIO: No IOMMU group for device %s\n", vdev->name);
+ return -EINVAL;
+ }
+
+ ret = vfio_add_group_dev(dev, &vfio_platform_ops, vdev);
+ if (ret) {
+ iommu_group_put(group);
+ return ret;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(vfio_platform_probe_common);
+
+struct vfio_platform_device *vfio_platform_remove_common(struct device *dev)
+{
+ struct vfio_platform_device *vdev;
+
+ vdev = vfio_del_group_dev(dev);
+ if (vdev)
+ iommu_group_put(dev->iommu_group);
+
+ return vdev;
+}
+EXPORT_SYMBOL_GPL(vfio_platform_remove_common);
diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
new file mode 100644
index 0000000..062b92d
--- /dev/null
+++ b/drivers/vfio/platform/vfio_platform_private.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 - Virtual Open Systems
+ * Author: Antonios Motakis <a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef VFIO_PLATFORM_PRIVATE_H
+#define VFIO_PLATFORM_PRIVATE_H
+
+struct vfio_platform_device {
+ /*
+ * These fields should be filled by the bus specific binder
+ */
+ void *opaque;
+ const char *name;
+ uint32_t flags;
+ /* callbacks to discover device resources */
+ struct resource*
+ (*get_resource)(struct vfio_platform_device *vdev, int i);
+ int (*get_irq)(struct vfio_platform_device *vdev, int i);
+};
+
+extern int vfio_platform_probe_common(struct vfio_platform_device *vdev,
+ struct device *dev);
+extern struct vfio_platform_device *vfio_platform_remove_common
+ (struct device *dev);
+
+#endif /* VFIO_PLATFORM_PRIVATE_H */
--
2.1.3
next prev parent reply other threads:[~2014-11-27 17:32 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-27 17:32 [PATCH v10 00/20] VFIO support for platform and ARM AMBA devices Antonios Motakis
[not found] ` <1417109580-10505-1-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
2014-11-27 17:32 ` Antonios Motakis [this message]
2014-11-27 17:32 ` [PATCH v10 02/20] vfio: platform: probe to devices on the platform bus Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 03/20] vfio: platform: add the VFIO PLATFORM module to Kconfig Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 04/20] vfio: amba: VFIO support for AMBA devices Antonios Motakis
[not found] ` <1417109580-10505-5-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
2014-12-09 14:18 ` Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 05/20] vfio: amba: add the VFIO for AMBA devices module to Kconfig Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 06/20] vfio/platform: return info for bound device Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 07/20] vfio/platform: return info for device memory mapped IO regions Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 08/20] vfio/platform: read and write support for the device fd Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 09/20] vfio/platform: support MMAP of MMIO regions Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 10/20] vfio/platform: return IRQ info Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 11/20] vfio/platform: initial interrupts support code Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 12/20] vfio/platform: trigger an interrupt via eventfd Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 13/20] vfio/platform: support for level sensitive interrupts Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 14/20] vfio: add a vfio_ prefix to virqfd_enable and virqfd_disable and export Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 15/20] vfio: virqfd: rename vfio_pci_virqfd_init and vfio_pci_virqfd_exit Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 16/20] vfio: add local lock for virqfd instead of depending on VFIO PCI Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 17/20] vfio: pass an opaque pointer on virqfd initialization Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 18/20] vfio: move eventfd support code for VFIO_PCI to a separate file Antonios Motakis
2014-11-27 17:32 ` [PATCH v10 19/20] vfio: initialize the virqfd workqueue in VFIO generic code Antonios Motakis
2014-11-27 17:33 ` [PATCH v10 20/20] vfio/platform: implement IRQ masking/unmasking via an eventfd Antonios Motakis
2014-11-28 18:05 ` [PATCH v10 00/20] VFIO support for platform and ARM AMBA devices Eric Auger
[not found] ` <5478B963.5050707-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2014-12-01 12:45 ` Antonios Motakis
[not found] ` <CAG8rG2wAt-wa26wBPA+2stb+Xn=B52thd8osRHWQm9WeQZbO1Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-01 14:29 ` Eric Auger
2014-12-07 19:12 ` Alex Williamson
[not found] ` <1417979565.1095.22.camel-xdHQ/5r00wBBDLzU/O5InQ@public.gmane.org>
2014-12-09 14:24 ` Antonios Motakis
[not found] ` <CAG8rG2wB9KtjYGEL91TDS9AiKFHjPHJKjqyRPJj7wqKP6c+Knw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-09 15:08 ` Alex Williamson
[not found] ` <1418137697.1095.126.camel-xdHQ/5r00wBBDLzU/O5InQ@public.gmane.org>
2014-12-10 14:00 ` Antonios Motakis
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=1417109580-10505-2-git-send-email-a.motakis@virtualopensystems.com \
--to=a.motakis-lrhrjnjw1ufhk3s98ze1ajgjjy/sre9j@public.gmane.org \
--cc=alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=christoffer.dall-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=eric.auger-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=kvmarm-FPEHb7Xf0XXUo1n7N8X6UoWGPAHP3yOg@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=marc.zyngier-5wv7dgnIgG8@public.gmane.org \
--cc=tech-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org \
--cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
/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