Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * include/linux/uio_driver.h
0004  *
0005  * Copyright(C) 2005, Benedikt Spranger <b.spranger@linutronix.de>
0006  * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
0007  * Copyright(C) 2006, Hans J. Koch <hjk@hansjkoch.de>
0008  * Copyright(C) 2006, Greg Kroah-Hartman <greg@kroah.com>
0009  *
0010  * Userspace IO driver.
0011  */
0012 
0013 #ifndef _UIO_DRIVER_H_
0014 #define _UIO_DRIVER_H_
0015 
0016 #include <linux/device.h>
0017 #include <linux/fs.h>
0018 #include <linux/interrupt.h>
0019 
0020 struct module;
0021 struct uio_map;
0022 
0023 /**
0024  * struct uio_mem - description of a UIO memory region
0025  * @name:       name of the memory region for identification
0026  * @addr:               address of the device's memory rounded to page
0027  *          size (phys_addr is used since addr can be
0028  *          logical, virtual, or physical & phys_addr_t
0029  *          should always be large enough to handle any of
0030  *          the address types)
0031  * @offs:               offset of device memory within the page
0032  * @size:       size of IO (multiple of page size)
0033  * @memtype:        type of memory addr points to
0034  * @internal_addr:  ioremap-ped version of addr, for driver internal use
0035  * @map:        for use by the UIO core only.
0036  */
0037 struct uio_mem {
0038     const char      *name;
0039     phys_addr_t     addr;
0040     unsigned long       offs;
0041     resource_size_t     size;
0042     int         memtype;
0043     void __iomem        *internal_addr;
0044     struct uio_map      *map;
0045 };
0046 
0047 #define MAX_UIO_MAPS    5
0048 
0049 struct uio_portio;
0050 
0051 /**
0052  * struct uio_port - description of a UIO port region
0053  * @name:       name of the port region for identification
0054  * @start:      start of port region
0055  * @size:       size of port region
0056  * @porttype:       type of port (see UIO_PORT_* below)
0057  * @portio:     for use by the UIO core only.
0058  */
0059 struct uio_port {
0060     const char      *name;
0061     unsigned long       start;
0062     unsigned long       size;
0063     int         porttype;
0064     struct uio_portio   *portio;
0065 };
0066 
0067 #define MAX_UIO_PORT_REGIONS    5
0068 
0069 struct uio_device {
0070     struct module           *owner;
0071     struct device       dev;
0072     int                     minor;
0073     atomic_t                event;
0074     struct fasync_struct    *async_queue;
0075     wait_queue_head_t       wait;
0076     struct uio_info         *info;
0077     struct mutex        info_lock;
0078     struct kobject          *map_dir;
0079     struct kobject          *portio_dir;
0080 };
0081 
0082 /**
0083  * struct uio_info - UIO device capabilities
0084  * @uio_dev:        the UIO device this info belongs to
0085  * @name:       device name
0086  * @version:        device driver version
0087  * @mem:        list of mappable memory regions, size==0 for end of list
0088  * @port:       list of port regions, size==0 for end of list
0089  * @irq:        interrupt number or UIO_IRQ_CUSTOM
0090  * @irq_flags:      flags for request_irq()
0091  * @priv:       optional private data
0092  * @handler:        the device's irq handler
0093  * @mmap:       mmap operation for this uio device
0094  * @open:       open operation for this uio device
0095  * @release:        release operation for this uio device
0096  * @irqcontrol:     disable/enable irqs when 0/1 is written to /dev/uioX
0097  */
0098 struct uio_info {
0099     struct uio_device   *uio_dev;
0100     const char      *name;
0101     const char      *version;
0102     struct uio_mem      mem[MAX_UIO_MAPS];
0103     struct uio_port     port[MAX_UIO_PORT_REGIONS];
0104     long            irq;
0105     unsigned long       irq_flags;
0106     void            *priv;
0107     irqreturn_t (*handler)(int irq, struct uio_info *dev_info);
0108     int (*mmap)(struct uio_info *info, struct vm_area_struct *vma);
0109     int (*open)(struct uio_info *info, struct inode *inode);
0110     int (*release)(struct uio_info *info, struct inode *inode);
0111     int (*irqcontrol)(struct uio_info *info, s32 irq_on);
0112 };
0113 
0114 extern int __must_check
0115     __uio_register_device(struct module *owner,
0116                   struct device *parent,
0117                   struct uio_info *info);
0118 
0119 /* use a define to avoid include chaining to get THIS_MODULE */
0120 
0121 /**
0122  * uio_register_device - register a new userspace IO device
0123  * @parent: parent device
0124  * @info:   UIO device capabilities
0125  *
0126  * returns zero on success or a negative error code.
0127  */
0128 #define uio_register_device(parent, info) \
0129     __uio_register_device(THIS_MODULE, parent, info)
0130 
0131 extern void uio_unregister_device(struct uio_info *info);
0132 extern void uio_event_notify(struct uio_info *info);
0133 
0134 extern int __must_check
0135     __devm_uio_register_device(struct module *owner,
0136                    struct device *parent,
0137                    struct uio_info *info);
0138 
0139 /* use a define to avoid include chaining to get THIS_MODULE */
0140 
0141 /**
0142  * devm_uio_register_device - Resource managed uio_register_device()
0143  * @parent: parent device
0144  * @info:   UIO device capabilities
0145  *
0146  * returns zero on success or a negative error code.
0147  */
0148 #define devm_uio_register_device(parent, info) \
0149     __devm_uio_register_device(THIS_MODULE, parent, info)
0150 
0151 /* defines for uio_info->irq */
0152 #define UIO_IRQ_CUSTOM  -1
0153 #define UIO_IRQ_NONE    0
0154 
0155 /* defines for uio_mem->memtype */
0156 #define UIO_MEM_NONE    0
0157 #define UIO_MEM_PHYS    1
0158 #define UIO_MEM_LOGICAL 2
0159 #define UIO_MEM_VIRTUAL 3
0160 #define UIO_MEM_IOVA    4
0161 
0162 /* defines for uio_port->porttype */
0163 #define UIO_PORT_NONE   0
0164 #define UIO_PORT_X86    1
0165 #define UIO_PORT_GPIO   2
0166 #define UIO_PORT_OTHER  3
0167 
0168 #endif /* _LINUX_UIO_DRIVER_H_ */