vfio: platform: add support for ACPI probe
[cascardo/linux.git] / drivers / vfio / platform / vfio_platform_private.h
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 #define VFIO_PLATFORM_OFFSET_SHIFT   40
22 #define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1)
23
24 #define VFIO_PLATFORM_OFFSET_TO_INDEX(off)      \
25         (off >> VFIO_PLATFORM_OFFSET_SHIFT)
26
27 #define VFIO_PLATFORM_INDEX_TO_OFFSET(index)    \
28         ((u64)(index) << VFIO_PLATFORM_OFFSET_SHIFT)
29
30 struct vfio_platform_irq {
31         u32                     flags;
32         u32                     count;
33         int                     hwirq;
34         char                    *name;
35         struct eventfd_ctx      *trigger;
36         bool                    masked;
37         spinlock_t              lock;
38         struct virqfd           *unmask;
39         struct virqfd           *mask;
40 };
41
42 struct vfio_platform_region {
43         u64                     addr;
44         resource_size_t         size;
45         u32                     flags;
46         u32                     type;
47 #define VFIO_PLATFORM_REGION_TYPE_MMIO  1
48 #define VFIO_PLATFORM_REGION_TYPE_PIO   2
49         void __iomem            *ioaddr;
50 };
51
52 struct vfio_platform_device {
53         struct vfio_platform_region     *regions;
54         u32                             num_regions;
55         struct vfio_platform_irq        *irqs;
56         u32                             num_irqs;
57         int                             refcnt;
58         struct mutex                    igate;
59         struct module                   *parent_module;
60         const char                      *compat;
61         const char                      *acpihid;
62         struct module                   *reset_module;
63         struct device                   *device;
64
65         /*
66          * These fields should be filled by the bus specific binder
67          */
68         void            *opaque;
69         const char      *name;
70         uint32_t        flags;
71         /* callbacks to discover device resources */
72         struct resource*
73                 (*get_resource)(struct vfio_platform_device *vdev, int i);
74         int     (*get_irq)(struct vfio_platform_device *vdev, int i);
75         int     (*of_reset)(struct vfio_platform_device *vdev);
76 };
77
78 typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
79
80 struct vfio_platform_reset_node {
81         struct list_head link;
82         char *compat;
83         struct module *owner;
84         vfio_platform_reset_fn_t of_reset;
85 };
86
87 extern int vfio_platform_probe_common(struct vfio_platform_device *vdev,
88                                       struct device *dev);
89 extern struct vfio_platform_device *vfio_platform_remove_common
90                                      (struct device *dev);
91
92 extern int vfio_platform_irq_init(struct vfio_platform_device *vdev);
93 extern void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
94
95 extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
96                                         uint32_t flags, unsigned index,
97                                         unsigned start, unsigned count,
98                                         void *data);
99
100 extern void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
101 extern void vfio_platform_unregister_reset(const char *compat,
102                                            vfio_platform_reset_fn_t fn);
103 #define vfio_platform_register_reset(__compat, __reset)         \
104 static struct vfio_platform_reset_node __reset ## _node = {     \
105         .owner = THIS_MODULE,                                   \
106         .compat = __compat,                                     \
107         .of_reset = __reset,                                    \
108 };                                                              \
109 __vfio_platform_register_reset(&__reset ## _node)
110
111 #define module_vfio_reset_handler(compat, reset)                \
112 MODULE_ALIAS("vfio-reset:" compat);                             \
113 static int __init reset ## _module_init(void)                   \
114 {                                                               \
115         vfio_platform_register_reset(compat, reset);            \
116         return 0;                                               \
117 };                                                              \
118 static void __exit reset ## _module_exit(void)                  \
119 {                                                               \
120         vfio_platform_unregister_reset(compat, reset);          \
121 };                                                              \
122 module_init(reset ## _module_init);                             \
123 module_exit(reset ## _module_exit)
124
125 #endif /* VFIO_PLATFORM_PRIVATE_H */