uio_driver.h 4.1 KB
Newer Older
H
Hans J. Koch 已提交
1 2 3 4 5
/*
 * include/linux/uio_driver.h
 *
 * Copyright(C) 2005, Benedikt Spranger <b.spranger@linutronix.de>
 * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
6
 * Copyright(C) 2006, Hans J. Koch <hjk@hansjkoch.de>
H
Hans J. Koch 已提交
7 8 9 10 11 12 13 14 15 16
 * Copyright(C) 2006, Greg Kroah-Hartman <greg@kroah.com>
 *
 * Userspace IO driver.
 *
 * Licensed under the GPLv2 only.
 */

#ifndef _UIO_DRIVER_H_
#define _UIO_DRIVER_H_

17
#include <linux/device.h>
H
Hans J. Koch 已提交
18 19 20
#include <linux/fs.h>
#include <linux/interrupt.h>

21
struct module;
G
Greg Kroah-Hartman 已提交
22 23
struct uio_map;

H
Hans J. Koch 已提交
24 25
/**
 * struct uio_mem - description of a UIO memory region
26
 * @name:		name of the memory region for identification
27 28 29 30 31 32 33
 * @addr:               address of the device's memory rounded to page
 * 			size (phys_addr is used since addr can be
 * 			logical, virtual, or physical & phys_addr_t
 * 			should always be large enough to handle any of
 * 			the address types)
 * @offs:               offset of device memory within the page
 * @size:		size of IO (multiple of page size)
H
Hans J. Koch 已提交
34 35
 * @memtype:		type of memory addr points to
 * @internal_addr:	ioremap-ped version of addr, for driver internal use
G
Greg Kroah-Hartman 已提交
36
 * @map:		for use by the UIO core only.
H
Hans J. Koch 已提交
37 38
 */
struct uio_mem {
39
	const char		*name;
40
	phys_addr_t		addr;
41
	unsigned long		offs;
42
	resource_size_t		size;
H
Hans J. Koch 已提交
43 44
	int			memtype;
	void __iomem		*internal_addr;
G
Greg Kroah-Hartman 已提交
45
	struct uio_map		*map;
H
Hans J. Koch 已提交
46 47
};

48
#define MAX_UIO_MAPS	5
H
Hans J. Koch 已提交
49

50 51 52 53
struct uio_portio;

/**
 * struct uio_port - description of a UIO port region
54
 * @name:		name of the port region for identification
55 56 57 58 59 60
 * @start:		start of port region
 * @size:		size of port region
 * @porttype:		type of port (see UIO_PORT_* below)
 * @portio:		for use by the UIO core only.
 */
struct uio_port {
61
	const char		*name;
62 63 64 65 66 67 68 69
	unsigned long		start;
	unsigned long		size;
	int			porttype;
	struct uio_portio	*portio;
};

#define MAX_UIO_PORT_REGIONS	5

70 71
struct uio_device {
        struct module           *owner;
72
	struct device		dev;
73 74 75 76 77
        int                     minor;
        atomic_t                event;
        struct fasync_struct    *async_queue;
        wait_queue_head_t       wait;
        struct uio_info         *info;
78
	spinlock_t		info_lock;
79 80 81
        struct kobject          *map_dir;
        struct kobject          *portio_dir;
};
H
Hans J. Koch 已提交
82 83 84 85 86 87 88

/**
 * struct uio_info - UIO device capabilities
 * @uio_dev:		the UIO device this info belongs to
 * @name:		device name
 * @version:		device driver version
 * @mem:		list of mappable memory regions, size==0 for end of list
89
 * @port:		list of port regions, size==0 for end of list
H
Hans J. Koch 已提交
90 91 92 93 94 95 96
 * @irq:		interrupt number or UIO_IRQ_CUSTOM
 * @irq_flags:		flags for request_irq()
 * @priv:		optional private data
 * @handler:		the device's irq handler
 * @mmap:		mmap operation for this uio device
 * @open:		open operation for this uio device
 * @release:		release operation for this uio device
97
 * @irqcontrol:		disable/enable irqs when 0/1 is written to /dev/uioX
H
Hans J. Koch 已提交
98 99 100
 */
struct uio_info {
	struct uio_device	*uio_dev;
101 102
	const char		*name;
	const char		*version;
H
Hans J. Koch 已提交
103
	struct uio_mem		mem[MAX_UIO_MAPS];
104
	struct uio_port		port[MAX_UIO_PORT_REGIONS];
H
Hans J. Koch 已提交
105 106 107 108 109 110 111
	long			irq;
	unsigned long		irq_flags;
	void			*priv;
	irqreturn_t (*handler)(int irq, struct uio_info *dev_info);
	int (*mmap)(struct uio_info *info, struct vm_area_struct *vma);
	int (*open)(struct uio_info *info, struct inode *inode);
	int (*release)(struct uio_info *info, struct inode *inode);
112
	int (*irqcontrol)(struct uio_info *info, s32 irq_on);
H
Hans J. Koch 已提交
113 114 115 116 117 118
};

extern int __must_check
	__uio_register_device(struct module *owner,
			      struct device *parent,
			      struct uio_info *info);
119 120 121 122 123

/* use a define to avoid include chaining to get THIS_MODULE */
#define uio_register_device(parent, info) \
	__uio_register_device(THIS_MODULE, parent, info)

H
Hans J. Koch 已提交
124 125 126
extern void uio_unregister_device(struct uio_info *info);
extern void uio_event_notify(struct uio_info *info);

127
/* defines for uio_info->irq */
H
Hans J. Koch 已提交
128
#define UIO_IRQ_CUSTOM	-1
E
Eric W. Biederman 已提交
129
#define UIO_IRQ_NONE	0
H
Hans J. Koch 已提交
130

131
/* defines for uio_mem->memtype */
H
Hans J. Koch 已提交
132 133 134 135 136
#define UIO_MEM_NONE	0
#define UIO_MEM_PHYS	1
#define UIO_MEM_LOGICAL	2
#define UIO_MEM_VIRTUAL 3

137 138 139 140 141 142
/* defines for uio_port->porttype */
#define UIO_PORT_NONE	0
#define UIO_PORT_X86	1
#define UIO_PORT_GPIO	2
#define UIO_PORT_OTHER	3

H
Hans J. Koch 已提交
143
#endif /* _LINUX_UIO_DRIVER_H_ */