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 #ifndef VFIO_PLATFORM_PRIVATE_H
16 #define VFIO_PLATFORM_PRIVATE_H
18 #include <linux/types.h>
19 #include <linux/interrupt.h>
21 #define VFIO_PLATFORM_OFFSET_SHIFT 40
22 #define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1)
24 #define VFIO_PLATFORM_OFFSET_TO_INDEX(off) \
25 (off >> VFIO_PLATFORM_OFFSET_SHIFT)
27 #define VFIO_PLATFORM_INDEX_TO_OFFSET(index) \
28 ((u64)(index) << VFIO_PLATFORM_OFFSET_SHIFT)
30 struct vfio_platform_irq {
35 struct eventfd_ctx *trigger;
38 struct virqfd *unmask;
42 struct vfio_platform_region {
47 #define VFIO_PLATFORM_REGION_TYPE_MMIO 1
48 #define VFIO_PLATFORM_REGION_TYPE_PIO 2
52 struct vfio_platform_device {
53 struct vfio_platform_region *regions;
55 struct vfio_platform_irq *irqs;
59 struct module *parent_module;
62 struct module *reset_module;
63 struct device *device;
66 * These fields should be filled by the bus specific binder
71 /* callbacks to discover device resources */
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);
80 typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
82 struct vfio_platform_reset_node {
83 struct list_head link;
86 vfio_platform_reset_fn_t of_reset;
89 extern int vfio_platform_probe_common(struct vfio_platform_device *vdev,
91 extern struct vfio_platform_device *vfio_platform_remove_common
94 extern int vfio_platform_irq_init(struct vfio_platform_device *vdev);
95 extern void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
97 extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
98 uint32_t flags, unsigned index,
99 unsigned start, unsigned count,
102 extern void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
103 extern void vfio_platform_unregister_reset(const char *compat,
104 vfio_platform_reset_fn_t fn);
105 #define vfio_platform_register_reset(__compat, __reset) \
106 static struct vfio_platform_reset_node __reset ## _node = { \
107 .owner = THIS_MODULE, \
108 .compat = __compat, \
109 .of_reset = __reset, \
111 __vfio_platform_register_reset(&__reset ## _node)
113 #define module_vfio_reset_handler(compat, reset) \
114 MODULE_ALIAS("vfio-reset:" compat); \
115 static int __init reset ## _module_init(void) \
117 vfio_platform_register_reset(compat, reset); \
120 static void __exit reset ## _module_exit(void) \
122 vfio_platform_unregister_reset(compat, reset); \
124 module_init(reset ## _module_init); \
125 module_exit(reset ## _module_exit)
127 #endif /* VFIO_PLATFORM_PRIVATE_H */