aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonios Motakis <a.motakis@virtualopensystems.com>2015-03-16 16:08:43 -0400
committerAlex Williamson <alex.williamson@redhat.com>2015-03-16 16:08:43 -0400
commit9df85aaa43297cb12dc85155695dd1bfdf94f91d (patch)
treeb7a17a5d63ae1d3b6f6412e8251f066421050fb6
parentde49fc0d99e6a8af8be4f56869bdea12976d3551 (diff)
vfio: platform: probe to devices on the platform bus
Driver to bind to Linux platform devices, and callbacks to discover their resources to be used by the main VFIO PLATFORM code. Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com> Signed-off-by: Baptiste Reynal <b.reynal@virtualopensystems.com> Reviewed-by: Eric Auger <eric.auger@linaro.org> Tested-by: Eric Auger <eric.auger@linaro.org> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
-rw-r--r--drivers/vfio/platform/vfio_platform.c103
-rw-r--r--include/uapi/linux/vfio.h1
2 files changed, 104 insertions, 0 deletions
diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
new file mode 100644
index 000000000000..cef645c83996
--- /dev/null
+++ b/drivers/vfio/platform/vfio_platform.c
@@ -0,0 +1,103 @@
1/*
2 * Copyright (C) 2013 - Virtual Open Systems
3 * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/module.h>
16#include <linux/slab.h>
17#include <linux/vfio.h>
18#include <linux/platform_device.h>
19
20#include "vfio_platform_private.h"
21
22#define DRIVER_VERSION "0.10"
23#define DRIVER_AUTHOR "Antonios Motakis <a.motakis@virtualopensystems.com>"
24#define DRIVER_DESC "VFIO for platform devices - User Level meta-driver"
25
26/* probing devices from the linux platform bus */
27
28static struct resource *get_platform_resource(struct vfio_platform_device *vdev,
29 int num)
30{
31 struct platform_device *dev = (struct platform_device *) vdev->opaque;
32 int i;
33
34 for (i = 0; i < dev->num_resources; i++) {
35 struct resource *r = &dev->resource[i];
36
37 if (resource_type(r) & (IORESOURCE_MEM|IORESOURCE_IO)) {
38 if (!num)
39 return r;
40
41 num--;
42 }
43 }
44 return NULL;
45}
46
47static int get_platform_irq(struct vfio_platform_device *vdev, int i)
48{
49 struct platform_device *pdev = (struct platform_device *) vdev->opaque;
50
51 return platform_get_irq(pdev, i);
52}
53
54static int vfio_platform_probe(struct platform_device *pdev)
55{
56 struct vfio_platform_device *vdev;
57 int ret;
58
59 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
60 if (!vdev)
61 return -ENOMEM;
62
63 vdev->opaque = (void *) pdev;
64 vdev->name = pdev->name;
65 vdev->flags = VFIO_DEVICE_FLAGS_PLATFORM;
66 vdev->get_resource = get_platform_resource;
67 vdev->get_irq = get_platform_irq;
68
69 ret = vfio_platform_probe_common(vdev, &pdev->dev);
70 if (ret)
71 kfree(vdev);
72
73 return ret;
74}
75
76static int vfio_platform_remove(struct platform_device *pdev)
77{
78 struct vfio_platform_device *vdev;
79
80 vdev = vfio_platform_remove_common(&pdev->dev);
81 if (vdev) {
82 kfree(vdev);
83 return 0;
84 }
85
86 return -EINVAL;
87}
88
89static struct platform_driver vfio_platform_driver = {
90 .probe = vfio_platform_probe,
91 .remove = vfio_platform_remove,
92 .driver = {
93 .name = "vfio-platform",
94 .owner = THIS_MODULE,
95 },
96};
97
98module_platform_driver(vfio_platform_driver);
99
100MODULE_VERSION(DRIVER_VERSION);
101MODULE_LICENSE("GPL v2");
102MODULE_AUTHOR(DRIVER_AUTHOR);
103MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index 82889c30f4f5..ea9514b6bb5c 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -160,6 +160,7 @@ struct vfio_device_info {
160 __u32 flags; 160 __u32 flags;
161#define VFIO_DEVICE_FLAGS_RESET (1 << 0) /* Device supports reset */ 161#define VFIO_DEVICE_FLAGS_RESET (1 << 0) /* Device supports reset */
162#define VFIO_DEVICE_FLAGS_PCI (1 << 1) /* vfio-pci device */ 162#define VFIO_DEVICE_FLAGS_PCI (1 << 1) /* vfio-pci device */
163#define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2) /* vfio-platform device */
163 __u32 num_regions; /* Max region index + 1 */ 164 __u32 num_regions; /* Max region index + 1 */
164 __u32 num_irqs; /* Max IRQ index + 1 */ 165 __u32 num_irqs; /* Max IRQ index + 1 */
165}; 166};