1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2013 - Virtual Open Systems
4 * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
7 #ifndef VFIO_PLATFORM_PRIVATE_H
8 #define VFIO_PLATFORM_PRIVATE_H
10 #include <linux/types.h>
11 #include <linux/interrupt.h>
13 #define VFIO_PLATFORM_OFFSET_SHIFT 40
14 #define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1)
16 #define VFIO_PLATFORM_OFFSET_TO_INDEX(off) \
17 (off >> VFIO_PLATFORM_OFFSET_SHIFT)
19 #define VFIO_PLATFORM_INDEX_TO_OFFSET(index) \
20 ((u64)(index) << VFIO_PLATFORM_OFFSET_SHIFT)
22 struct vfio_platform_irq
{
27 struct eventfd_ctx
*trigger
;
30 struct virqfd
*unmask
;
34 struct vfio_platform_region
{
39 #define VFIO_PLATFORM_REGION_TYPE_MMIO 1
40 #define VFIO_PLATFORM_REGION_TYPE_PIO 2
44 struct vfio_platform_device
{
45 struct vfio_platform_region
*regions
;
47 struct vfio_platform_irq
*irqs
;
51 struct module
*parent_module
;
54 struct module
*reset_module
;
55 struct device
*device
;
58 * These fields should be filled by the bus specific binder
63 /* callbacks to discover device resources */
65 (*get_resource
)(struct vfio_platform_device
*vdev
, int i
);
66 int (*get_irq
)(struct vfio_platform_device
*vdev
, int i
);
67 int (*of_reset
)(struct vfio_platform_device
*vdev
);
72 typedef int (*vfio_platform_reset_fn_t
)(struct vfio_platform_device
*vdev
);
74 struct vfio_platform_reset_node
{
75 struct list_head link
;
78 vfio_platform_reset_fn_t of_reset
;
81 extern int vfio_platform_probe_common(struct vfio_platform_device
*vdev
,
83 extern struct vfio_platform_device
*vfio_platform_remove_common
86 extern int vfio_platform_irq_init(struct vfio_platform_device
*vdev
);
87 extern void vfio_platform_irq_cleanup(struct vfio_platform_device
*vdev
);
89 extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device
*vdev
,
90 uint32_t flags
, unsigned index
,
91 unsigned start
, unsigned count
,
94 extern void __vfio_platform_register_reset(struct vfio_platform_reset_node
*n
);
95 extern void vfio_platform_unregister_reset(const char *compat
,
96 vfio_platform_reset_fn_t fn
);
97 #define vfio_platform_register_reset(__compat, __reset) \
98 static struct vfio_platform_reset_node __reset ## _node = { \
99 .owner = THIS_MODULE, \
100 .compat = __compat, \
101 .of_reset = __reset, \
103 __vfio_platform_register_reset(&__reset ## _node)
105 #define module_vfio_reset_handler(compat, reset) \
106 MODULE_ALIAS("vfio-reset:" compat); \
107 static int __init reset ## _module_init(void) \
109 vfio_platform_register_reset(compat, reset); \
112 static void __exit reset ## _module_exit(void) \
114 vfio_platform_unregister_reset(compat, reset); \
116 module_init(reset ## _module_init); \
117 module_exit(reset ## _module_exit)
119 #endif /* VFIO_PLATFORM_PRIVATE_H */