diff options
author | Antonios Motakis <a.motakis@virtualopensystems.com> | 2015-03-16 16:08:42 -0400 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2015-03-16 16:08:42 -0400 |
commit | de49fc0d99e6a8af8be4f56869bdea12976d3551 (patch) | |
tree | 9d8a3063bf89f317187c5bda3ed768e37be35ce6 | |
parent | 06e5801b8cb3fc057d88cb4dc03c0b64b2744cda (diff) |
vfio/platform: initial skeleton of VFIO support for platform devices
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@virtualopensystems.com>
[Baptiste Reynal: added includes in vfio_platform_private.h]
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_common.c | 121 | ||||
-rw-r--r-- | drivers/vfio/platform/vfio_platform_private.h | 39 |
2 files changed, 160 insertions, 0 deletions
diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c new file mode 100644 index 000000000000..34d023bdda16 --- /dev/null +++ b/drivers/vfio/platform/vfio_platform_common.c | |||
@@ -0,0 +1,121 @@ | |||
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/device.h> | ||
16 | #include <linux/iommu.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/mutex.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/types.h> | ||
21 | #include <linux/vfio.h> | ||
22 | |||
23 | #include "vfio_platform_private.h" | ||
24 | |||
25 | static void vfio_platform_release(void *device_data) | ||
26 | { | ||
27 | module_put(THIS_MODULE); | ||
28 | } | ||
29 | |||
30 | static int vfio_platform_open(void *device_data) | ||
31 | { | ||
32 | if (!try_module_get(THIS_MODULE)) | ||
33 | return -ENODEV; | ||
34 | |||
35 | return 0; | ||
36 | } | ||
37 | |||
38 | static long vfio_platform_ioctl(void *device_data, | ||
39 | unsigned int cmd, unsigned long arg) | ||
40 | { | ||
41 | if (cmd == VFIO_DEVICE_GET_INFO) | ||
42 | return -EINVAL; | ||
43 | |||
44 | else if (cmd == VFIO_DEVICE_GET_REGION_INFO) | ||
45 | return -EINVAL; | ||
46 | |||
47 | else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) | ||
48 | return -EINVAL; | ||
49 | |||
50 | else if (cmd == VFIO_DEVICE_SET_IRQS) | ||
51 | return -EINVAL; | ||
52 | |||
53 | else if (cmd == VFIO_DEVICE_RESET) | ||
54 | return -EINVAL; | ||
55 | |||
56 | return -ENOTTY; | ||
57 | } | ||
58 | |||
59 | static ssize_t vfio_platform_read(void *device_data, char __user *buf, | ||
60 | size_t count, loff_t *ppos) | ||
61 | { | ||
62 | return -EINVAL; | ||
63 | } | ||
64 | |||
65 | static ssize_t vfio_platform_write(void *device_data, const char __user *buf, | ||
66 | size_t count, loff_t *ppos) | ||
67 | { | ||
68 | return -EINVAL; | ||
69 | } | ||
70 | |||
71 | static int vfio_platform_mmap(void *device_data, struct vm_area_struct *vma) | ||
72 | { | ||
73 | return -EINVAL; | ||
74 | } | ||
75 | |||
76 | static const struct vfio_device_ops vfio_platform_ops = { | ||
77 | .name = "vfio-platform", | ||
78 | .open = vfio_platform_open, | ||
79 | .release = vfio_platform_release, | ||
80 | .ioctl = vfio_platform_ioctl, | ||
81 | .read = vfio_platform_read, | ||
82 | .write = vfio_platform_write, | ||
83 | .mmap = vfio_platform_mmap, | ||
84 | }; | ||
85 | |||
86 | int vfio_platform_probe_common(struct vfio_platform_device *vdev, | ||
87 | struct device *dev) | ||
88 | { | ||
89 | struct iommu_group *group; | ||
90 | int ret; | ||
91 | |||
92 | if (!vdev) | ||
93 | return -EINVAL; | ||
94 | |||
95 | group = iommu_group_get(dev); | ||
96 | if (!group) { | ||
97 | pr_err("VFIO: No IOMMU group for device %s\n", vdev->name); | ||
98 | return -EINVAL; | ||
99 | } | ||
100 | |||
101 | ret = vfio_add_group_dev(dev, &vfio_platform_ops, vdev); | ||
102 | if (ret) { | ||
103 | iommu_group_put(group); | ||
104 | return ret; | ||
105 | } | ||
106 | |||
107 | return 0; | ||
108 | } | ||
109 | EXPORT_SYMBOL_GPL(vfio_platform_probe_common); | ||
110 | |||
111 | struct vfio_platform_device *vfio_platform_remove_common(struct device *dev) | ||
112 | { | ||
113 | struct vfio_platform_device *vdev; | ||
114 | |||
115 | vdev = vfio_del_group_dev(dev); | ||
116 | if (vdev) | ||
117 | iommu_group_put(dev->iommu_group); | ||
118 | |||
119 | return vdev; | ||
120 | } | ||
121 | 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 000000000000..c04698872440 --- /dev/null +++ b/drivers/vfio/platform/vfio_platform_private.h | |||
@@ -0,0 +1,39 @@ | |||
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 | #ifndef VFIO_PLATFORM_PRIVATE_H | ||
16 | #define VFIO_PLATFORM_PRIVATE_H | ||
17 | |||
18 | #include <linux/types.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | |||
21 | struct vfio_platform_device { | ||
22 | /* | ||
23 | * These fields should be filled by the bus specific binder | ||
24 | */ | ||
25 | void *opaque; | ||
26 | const char *name; | ||
27 | uint32_t flags; | ||
28 | /* callbacks to discover device resources */ | ||
29 | struct resource* | ||
30 | (*get_resource)(struct vfio_platform_device *vdev, int i); | ||
31 | int (*get_irq)(struct vfio_platform_device *vdev, int i); | ||
32 | }; | ||
33 | |||
34 | extern int vfio_platform_probe_common(struct vfio_platform_device *vdev, | ||
35 | struct device *dev); | ||
36 | extern struct vfio_platform_device *vfio_platform_remove_common | ||
37 | (struct device *dev); | ||
38 | |||
39 | #endif /* VFIO_PLATFORM_PRIVATE_H */ | ||