dmaengine: imx-sdma: Let the core do the device node validation
[linux/fpc-iii.git] / drivers / vfio / platform / vfio_amba.c
blob62dfbfeaabfc59c3adcfbc9565e672f81bf21176
1 /*
2 * Copyright (C) 2013 - Virtual Open Systems
3 * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
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.
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.
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/vfio.h>
18 #include <linux/amba/bus.h>
20 #include "vfio_platform_private.h"
22 #define DRIVER_VERSION "0.10"
23 #define DRIVER_AUTHOR "Antonios Motakis <a.motakis@virtualopensystems.com>"
24 #define DRIVER_DESC "VFIO for AMBA devices - User Level meta-driver"
26 /* probing devices from the AMBA bus */
28 static struct resource *get_amba_resource(struct vfio_platform_device *vdev,
29 int i)
31 struct amba_device *adev = (struct amba_device *) vdev->opaque;
33 if (i == 0)
34 return &adev->res;
36 return NULL;
39 static int get_amba_irq(struct vfio_platform_device *vdev, int i)
41 struct amba_device *adev = (struct amba_device *) vdev->opaque;
42 int ret = 0;
44 if (i < AMBA_NR_IRQS)
45 ret = adev->irq[i];
47 /* zero is an unset IRQ for AMBA devices */
48 return ret ? ret : -ENXIO;
51 static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id)
53 struct vfio_platform_device *vdev;
54 int ret;
56 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
57 if (!vdev)
58 return -ENOMEM;
60 vdev->name = kasprintf(GFP_KERNEL, "vfio-amba-%08x", adev->periphid);
61 if (!vdev->name) {
62 kfree(vdev);
63 return -ENOMEM;
66 vdev->opaque = (void *) adev;
67 vdev->flags = VFIO_DEVICE_FLAGS_AMBA;
68 vdev->get_resource = get_amba_resource;
69 vdev->get_irq = get_amba_irq;
70 vdev->parent_module = THIS_MODULE;
71 vdev->reset_required = false;
73 ret = vfio_platform_probe_common(vdev, &adev->dev);
74 if (ret) {
75 kfree(vdev->name);
76 kfree(vdev);
79 return ret;
82 static int vfio_amba_remove(struct amba_device *adev)
84 struct vfio_platform_device *vdev;
86 vdev = vfio_platform_remove_common(&adev->dev);
87 if (vdev) {
88 kfree(vdev->name);
89 kfree(vdev);
90 return 0;
93 return -EINVAL;
96 static const struct amba_id pl330_ids[] = {
97 { 0, 0 },
100 MODULE_DEVICE_TABLE(amba, pl330_ids);
102 static struct amba_driver vfio_amba_driver = {
103 .probe = vfio_amba_probe,
104 .remove = vfio_amba_remove,
105 .id_table = pl330_ids,
106 .drv = {
107 .name = "vfio-amba",
108 .owner = THIS_MODULE,
112 module_amba_driver(vfio_amba_driver);
114 MODULE_VERSION(DRIVER_VERSION);
115 MODULE_LICENSE("GPL v2");
116 MODULE_AUTHOR(DRIVER_AUTHOR);
117 MODULE_DESCRIPTION(DRIVER_DESC);