xref: /openbmc/linux/include/linux/uio_driver.h (revision 9f38abef)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * include/linux/uio_driver.h
4  *
5  * Copyright(C) 2005, Benedikt Spranger <b.spranger@linutronix.de>
6  * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
7  * Copyright(C) 2006, Hans J. Koch <hjk@hansjkoch.de>
8  * Copyright(C) 2006, Greg Kroah-Hartman <greg@kroah.com>
9  *
10  * Userspace IO driver.
11  */
12 
13 #ifndef _UIO_DRIVER_H_
14 #define _UIO_DRIVER_H_
15 
16 #include <linux/device.h>
17 #include <linux/fs.h>
18 #include <linux/interrupt.h>
19 
20 struct module;
21 struct uio_map;
22 
23 /**
24  * struct uio_mem - description of a UIO memory region
25  * @name:		name of the memory region for identification
26  * @addr:               address of the device's memory rounded to page
27  *			size (phys_addr is used since addr can be
28  *			logical, virtual, or physical & phys_addr_t
29  *			should always be large enough to handle any of
30  *			the address types)
31  * @offs:               offset of device memory within the page
32  * @size:		size of IO (multiple of page size)
33  * @memtype:		type of memory addr points to
34  * @internal_addr:	ioremap-ped version of addr, for driver internal use
35  * @map:		for use by the UIO core only.
36  */
37 struct uio_mem {
38 	const char		*name;
39 	phys_addr_t		addr;
40 	unsigned long		offs;
41 	resource_size_t		size;
42 	int			memtype;
43 	void __iomem		*internal_addr;
44 	struct uio_map		*map;
45 };
46 
47 #define MAX_UIO_MAPS	5
48 
49 struct uio_portio;
50 
51 /**
52  * struct uio_port - description of a UIO port region
53  * @name:		name of the port region for identification
54  * @start:		start of port region
55  * @size:		size of port region
56  * @porttype:		type of port (see UIO_PORT_* below)
57  * @portio:		for use by the UIO core only.
58  */
59 struct uio_port {
60 	const char		*name;
61 	unsigned long		start;
62 	unsigned long		size;
63 	int			porttype;
64 	struct uio_portio	*portio;
65 };
66 
67 #define MAX_UIO_PORT_REGIONS	5
68 
69 struct uio_device {
70 	struct module           *owner;
71 	struct device		dev;
72 	int                     minor;
73 	atomic_t                event;
74 	struct fasync_struct    *async_queue;
75 	wait_queue_head_t       wait;
76 	struct uio_info         *info;
77 	struct mutex		info_lock;
78 	struct kobject          *map_dir;
79 	struct kobject          *portio_dir;
80 };
81 
82 /**
83  * struct uio_info - UIO device capabilities
84  * @uio_dev:		the UIO device this info belongs to
85  * @name:		device name
86  * @version:		device driver version
87  * @mem:		list of mappable memory regions, size==0 for end of list
88  * @port:		list of port regions, size==0 for end of list
89  * @irq:		interrupt number or UIO_IRQ_CUSTOM
90  * @irq_flags:		flags for request_irq()
91  * @priv:		optional private data
92  * @handler:		the device's irq handler
93  * @mmap:		mmap operation for this uio device
94  * @open:		open operation for this uio device
95  * @release:		release operation for this uio device
96  * @irqcontrol:		disable/enable irqs when 0/1 is written to /dev/uioX
97  */
98 struct uio_info {
99 	struct uio_device	*uio_dev;
100 	const char		*name;
101 	const char		*version;
102 	struct uio_mem		mem[MAX_UIO_MAPS];
103 	struct uio_port		port[MAX_UIO_PORT_REGIONS];
104 	long			irq;
105 	unsigned long		irq_flags;
106 	void			*priv;
107 	irqreturn_t (*handler)(int irq, struct uio_info *dev_info);
108 	int (*mmap)(struct uio_info *info, struct vm_area_struct *vma);
109 	int (*open)(struct uio_info *info, struct inode *inode);
110 	int (*release)(struct uio_info *info, struct inode *inode);
111 	int (*irqcontrol)(struct uio_info *info, s32 irq_on);
112 };
113 
114 extern int __must_check
115 	__uio_register_device(struct module *owner,
116 			      struct device *parent,
117 			      struct uio_info *info);
118 
119 /* use a define to avoid include chaining to get THIS_MODULE */
120 
121 /**
122  * uio_register_device - register a new userspace IO device
123  * @parent:	parent device
124  * @info:	UIO device capabilities
125  *
126  * returns zero on success or a negative error code.
127  */
128 #define uio_register_device(parent, info) \
129 	__uio_register_device(THIS_MODULE, parent, info)
130 
131 extern void uio_unregister_device(struct uio_info *info);
132 extern void uio_event_notify(struct uio_info *info);
133 
134 extern int __must_check
135 	__devm_uio_register_device(struct module *owner,
136 				   struct device *parent,
137 				   struct uio_info *info);
138 
139 /* use a define to avoid include chaining to get THIS_MODULE */
140 
141 /**
142  * devm_uio_register_device - Resource managed uio_register_device()
143  * @parent:	parent device
144  * @info:	UIO device capabilities
145  *
146  * returns zero on success or a negative error code.
147  */
148 #define devm_uio_register_device(parent, info) \
149 	__devm_uio_register_device(THIS_MODULE, parent, info)
150 
151 /* defines for uio_info->irq */
152 #define UIO_IRQ_CUSTOM	-1
153 #define UIO_IRQ_NONE	0
154 
155 /* defines for uio_mem->memtype */
156 #define UIO_MEM_NONE	0
157 #define UIO_MEM_PHYS	1
158 #define UIO_MEM_LOGICAL	2
159 #define UIO_MEM_VIRTUAL 3
160 #define UIO_MEM_IOVA	4
161 
162 /* defines for uio_port->porttype */
163 #define UIO_PORT_NONE	0
164 #define UIO_PORT_X86	1
165 #define UIO_PORT_GPIO	2
166 #define UIO_PORT_OTHER	3
167 
168 #endif /* _LINUX_UIO_DRIVER_H_ */
169