uio_driver.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #ifndef _UIO_DRIVER_H_
  13. #define _UIO_DRIVER_H_
  14. #include <linux/device.h>
  15. #include <linux/fs.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/android_kabi.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. ANDROID_KABI_RESERVE(1);
  73. };
  74. /**
  75. * struct uio_info - UIO device capabilities
  76. * @uio_dev: the UIO device this info belongs to
  77. * @name: device name
  78. * @version: device driver version
  79. * @mem: list of mappable memory regions, size==0 for end of list
  80. * @port: list of port regions, size==0 for end of list
  81. * @irq: interrupt number or UIO_IRQ_CUSTOM
  82. * @irq_flags: flags for request_irq()
  83. * @priv: optional private data
  84. * @handler: the device's irq handler
  85. * @mmap: mmap operation for this uio device
  86. * @open: open operation for this uio device
  87. * @release: release operation for this uio device
  88. * @irqcontrol: disable/enable irqs when 0/1 is written to /dev/uioX
  89. */
  90. struct uio_info {
  91. struct uio_device *uio_dev;
  92. const char *name;
  93. const char *version;
  94. struct uio_mem mem[MAX_UIO_MAPS];
  95. struct uio_port port[MAX_UIO_PORT_REGIONS];
  96. long irq;
  97. unsigned long irq_flags;
  98. void *priv;
  99. irqreturn_t (*handler)(int irq, struct uio_info *dev_info);
  100. int (*mmap)(struct uio_info *info, struct vm_area_struct *vma);
  101. int (*open)(struct uio_info *info, struct inode *inode);
  102. int (*release)(struct uio_info *info, struct inode *inode);
  103. int (*irqcontrol)(struct uio_info *info, s32 irq_on);
  104. ANDROID_KABI_RESERVE(1);
  105. };
  106. extern int __must_check
  107. __uio_register_device(struct module *owner,
  108. struct device *parent,
  109. struct uio_info *info);
  110. /* use a define to avoid include chaining to get THIS_MODULE */
  111. #define uio_register_device(parent, info) \
  112. __uio_register_device(THIS_MODULE, parent, info)
  113. extern void uio_unregister_device(struct uio_info *info);
  114. extern void uio_event_notify(struct uio_info *info);
  115. extern int __must_check
  116. __devm_uio_register_device(struct module *owner,
  117. struct device *parent,
  118. struct uio_info *info);
  119. /* use a define to avoid include chaining to get THIS_MODULE */
  120. #define devm_uio_register_device(parent, info) \
  121. __devm_uio_register_device(THIS_MODULE, parent, info)
  122. /* defines for uio_info->irq */
  123. #define UIO_IRQ_CUSTOM -1
  124. #define UIO_IRQ_NONE 0
  125. /* defines for uio_mem->memtype */
  126. #define UIO_MEM_NONE 0
  127. #define UIO_MEM_PHYS 1
  128. #define UIO_MEM_LOGICAL 2
  129. #define UIO_MEM_VIRTUAL 3
  130. #define UIO_MEM_IOVA 4
  131. /* defines for uio_port->porttype */
  132. #define UIO_PORT_NONE 0
  133. #define UIO_PORT_X86 1
  134. #define UIO_PORT_GPIO 2
  135. #define UIO_PORT_OTHER 3
  136. #endif /* _LINUX_UIO_DRIVER_H_ */