blob: 85ffe5d9d1abd94e851a456301c4253935767c6e [file] [log] [blame]
Antonios Motakisde49fc02015-03-16 14:08:42 -06001/*
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
Antonios Motakise8909e62015-03-16 14:08:46 -060021#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
Antonios Motakis682704c2015-03-16 14:08:48 -060030struct vfio_platform_irq {
31 u32 flags;
32 u32 count;
Antonios Motakis9a363212015-03-16 14:08:49 -060033 int hwirq;
Antonios Motakis57f972e2015-03-16 14:08:50 -060034 char *name;
35 struct eventfd_ctx *trigger;
Antonios Motakis06211b42015-03-16 14:08:50 -060036 bool masked;
37 spinlock_t lock;
Antonios Motakisa7fa7c72015-03-16 14:08:55 -060038 struct virqfd *unmask;
39 struct virqfd *mask;
Antonios Motakis682704c2015-03-16 14:08:48 -060040};
41
Antonios Motakise8909e62015-03-16 14:08:46 -060042struct 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
Antonios Motakis6e3f2642015-03-16 14:08:47 -060049 void __iomem *ioaddr;
Antonios Motakise8909e62015-03-16 14:08:46 -060050};
51
Antonios Motakisde49fc02015-03-16 14:08:42 -060052struct vfio_platform_device {
Antonios Motakise8909e62015-03-16 14:08:46 -060053 struct vfio_platform_region *regions;
54 u32 num_regions;
Antonios Motakis682704c2015-03-16 14:08:48 -060055 struct vfio_platform_irq *irqs;
56 u32 num_irqs;
Antonios Motakise8909e62015-03-16 14:08:46 -060057 int refcnt;
Antonios Motakis9a363212015-03-16 14:08:49 -060058 struct mutex igate;
Eric Auger32a2d712015-11-03 18:12:12 +000059 struct module *parent_module;
Eric Auger0628c4d2015-11-03 18:12:16 +000060 const char *compat;
Sinan Kayaa12a9362016-07-19 09:01:44 -040061 const char *acpihid;
Eric Augere9e05062015-11-03 18:12:17 +000062 struct module *reset_module;
Eric Auger705e60b2015-11-03 18:12:18 +000063 struct device *device;
Antonios Motakise8909e62015-03-16 14:08:46 -060064
Antonios Motakisde49fc02015-03-16 14:08:42 -060065 /*
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);
Sinan Kaya7aef80c2016-07-19 09:01:41 -040075 int (*of_reset)(struct vfio_platform_device *vdev);
Sinan Kayab5add542016-07-19 09:01:47 -040076
77 bool reset_required;
Antonios Motakisde49fc02015-03-16 14:08:42 -060078};
79
Eric Augere0864972015-11-03 18:12:13 +000080typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
81
82struct vfio_platform_reset_node {
83 struct list_head link;
84 char *compat;
85 struct module *owner;
Sinan Kaya7aef80c2016-07-19 09:01:41 -040086 vfio_platform_reset_fn_t of_reset;
Eric Augere0864972015-11-03 18:12:13 +000087};
88
Antonios Motakisde49fc02015-03-16 14:08:42 -060089extern int vfio_platform_probe_common(struct vfio_platform_device *vdev,
90 struct device *dev);
91extern struct vfio_platform_device *vfio_platform_remove_common
92 (struct device *dev);
93
Antonios Motakis682704c2015-03-16 14:08:48 -060094extern int vfio_platform_irq_init(struct vfio_platform_device *vdev);
95extern void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
96
Antonios Motakis9a363212015-03-16 14:08:49 -060097extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
98 uint32_t flags, unsigned index,
99 unsigned start, unsigned count,
100 void *data);
101
Eric Augere0864972015-11-03 18:12:13 +0000102extern void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
103extern void vfio_platform_unregister_reset(const char *compat,
104 vfio_platform_reset_fn_t fn);
105#define vfio_platform_register_reset(__compat, __reset) \
106static struct vfio_platform_reset_node __reset ## _node = { \
107 .owner = THIS_MODULE, \
108 .compat = __compat, \
Sinan Kaya7aef80c2016-07-19 09:01:41 -0400109 .of_reset = __reset, \
Eric Augere0864972015-11-03 18:12:13 +0000110}; \
111__vfio_platform_register_reset(&__reset ## _node)
112
Eric Auger58864652015-11-03 18:12:14 +0000113#define module_vfio_reset_handler(compat, reset) \
114MODULE_ALIAS("vfio-reset:" compat); \
115static int __init reset ## _module_init(void) \
116{ \
117 vfio_platform_register_reset(compat, reset); \
118 return 0; \
119}; \
120static void __exit reset ## _module_exit(void) \
121{ \
122 vfio_platform_unregister_reset(compat, reset); \
123}; \
124module_init(reset ## _module_init); \
125module_exit(reset ## _module_exit)
126
Antonios Motakisde49fc02015-03-16 14:08:42 -0600127#endif /* VFIO_PLATFORM_PRIVATE_H */