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/platform_device.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 platform devices - User Level meta-driver"
26 /* probing devices from the linux platform bus */
28 static struct resource
*get_platform_resource(struct vfio_platform_device
*vdev
,
31 struct platform_device
*dev
= (struct platform_device
*) vdev
->opaque
;
34 for (i
= 0; i
< dev
->num_resources
; i
++) {
35 struct resource
*r
= &dev
->resource
[i
];
37 if (resource_type(r
) & (IORESOURCE_MEM
|IORESOURCE_IO
)) {
47 static int get_platform_irq(struct vfio_platform_device
*vdev
, int i
)
49 struct platform_device
*pdev
= (struct platform_device
*) vdev
->opaque
;
51 return platform_get_irq(pdev
, i
);
54 static int vfio_platform_probe(struct platform_device
*pdev
)
56 struct vfio_platform_device
*vdev
;
59 vdev
= kzalloc(sizeof(*vdev
), GFP_KERNEL
);
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
;
69 ret
= vfio_platform_probe_common(vdev
, &pdev
->dev
);
76 static int vfio_platform_remove(struct platform_device
*pdev
)
78 struct vfio_platform_device
*vdev
;
80 vdev
= vfio_platform_remove_common(&pdev
->dev
);
89 static struct platform_driver vfio_platform_driver
= {
90 .probe
= vfio_platform_probe
,
91 .remove
= vfio_platform_remove
,
93 .name
= "vfio-platform",
98 module_platform_driver(vfio_platform_driver
);
100 MODULE_VERSION(DRIVER_VERSION
);
101 MODULE_LICENSE("GPL v2");
102 MODULE_AUTHOR(DRIVER_AUTHOR
);
103 MODULE_DESCRIPTION(DRIVER_DESC
);