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