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>
12 #include <linux/vfio.h>
14 #define VFIO_PLATFORM_OFFSET_SHIFT 40
15 #define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1)
17 #define VFIO_PLATFORM_OFFSET_TO_INDEX(off) \
18 (off >> VFIO_PLATFORM_OFFSET_SHIFT)
20 #define VFIO_PLATFORM_INDEX_TO_OFFSET(index) \
21 ((u64)(index) << VFIO_PLATFORM_OFFSET_SHIFT)
23 struct vfio_platform_irq {
28 struct eventfd_ctx *trigger;
31 struct virqfd *unmask;
35 struct vfio_platform_region {
40 #define VFIO_PLATFORM_REGION_TYPE_MMIO 1
41 #define VFIO_PLATFORM_REGION_TYPE_PIO 2
45 struct vfio_platform_device {
46 struct vfio_device vdev;
47 struct vfio_platform_region *regions;
49 struct vfio_platform_irq *irqs;
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 int vfio_platform_probe_common(struct vfio_platform_device *vdev,
83 void vfio_platform_remove_common(struct vfio_platform_device *vdev);
85 int vfio_platform_irq_init(struct vfio_platform_device *vdev);
86 void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
88 int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
89 uint32_t flags, unsigned index,
90 unsigned start, unsigned count, void *data);
92 void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
93 void vfio_platform_unregister_reset(const char *compat,
94 vfio_platform_reset_fn_t fn);
95 #define vfio_platform_register_reset(__compat, __reset) \
96 static struct vfio_platform_reset_node __reset ## _node = { \
97 .owner = THIS_MODULE, \
99 .of_reset = __reset, \
101 __vfio_platform_register_reset(&__reset ## _node)
103 #define module_vfio_reset_handler(compat, reset) \
104 MODULE_ALIAS("vfio-reset:" compat); \
105 static int __init reset ## _module_init(void) \
107 vfio_platform_register_reset(compat, reset); \
110 static void __exit reset ## _module_exit(void) \
112 vfio_platform_unregister_reset(compat, reset); \
114 module_init(reset ## _module_init); \
115 module_exit(reset ## _module_exit)
117 #endif /* VFIO_PLATFORM_PRIVATE_H */