uio_driver.h 4.1 KB

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