ioctl.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef _PCIDRIVER_IOCTL_H_
  2. #define _PCIDRIVER_IOCTL_H_
  3. #include <linux/ioctl.h>
  4. #define PCIDRIVER_INTERFACE_VERSION 2 /**< Driver API version, only the pcilib with the same driver interface version is allowed */
  5. /* Possible values for ioctl commands */
  6. /* PCI mmap areas */
  7. #define PCIDRIVER_BAR0 0
  8. #define PCIDRIVER_BAR1 1
  9. #define PCIDRIVER_BAR2 2
  10. #define PCIDRIVER_BAR3 3
  11. #define PCIDRIVER_BAR4 4
  12. #define PCIDRIVER_BAR5 5
  13. /* mmap mode of the device */
  14. #define PCIDRIVER_MMAP_PCI 0
  15. #define PCIDRIVER_MMAP_KMEM 1
  16. #define PCIDRIVER_MMAP_AREA 2
  17. /* Direction of a DMA operation */
  18. #define PCIDRIVER_DMA_BIDIRECTIONAL 0
  19. #define PCIDRIVER_DMA_TODEVICE 1 // PCILIB_KMEM_SYNC_TODEVICE
  20. #define PCIDRIVER_DMA_FROMDEVICE 2 // PCILIB_KMEM_SYNC_FROMDEVICE
  21. /* Possible sizes in a PCI command */
  22. #define PCIDRIVER_PCI_CFG_SZ_BYTE 1
  23. #define PCIDRIVER_PCI_CFG_SZ_WORD 2
  24. #define PCIDRIVER_PCI_CFG_SZ_DWORD 3
  25. /* Possible types of SG lists */
  26. #define PCIDRIVER_SG_NONMERGED 0
  27. #define PCIDRIVER_SG_MERGED 1
  28. #define KMEM_REF_HW 0x80000000 /**< Special reference to indicate hardware access */
  29. #define KMEM_REF_COUNT 0x0FFFFFFF /**< Mask of reference counter (mmap/munmap), couting in mmaped memory pages */
  30. #define KMEM_MODE_REUSABLE 0x80000000 /**< Indicates reusable buffer */
  31. #define KMEM_MODE_EXCLUSIVE 0x40000000 /**< Only a single process is allowed to mmap the buffer */
  32. #define KMEM_MODE_PERSISTENT 0x20000000 /**< Persistent mode instructs kmem_free to preserve buffer in memory */
  33. #define KMEM_MODE_COUNT 0x0FFFFFFF /**< Mask of reuse counter (alloc/free) */
  34. #define KMEM_FLAG_REUSE PCILIB_KMEM_FLAG_REUSE /**< Try to reuse existing buffer with the same use & item */
  35. #define KMEM_FLAG_EXCLUSIVE PCILIB_KMEM_FLAG_EXCLUSIVE /**< Allow only a single application accessing a specified use & item */
  36. #define KMEM_FLAG_PERSISTENT PCILIB_KMEM_FLAG_PERSISTENT /**< Sets persistent mode */
  37. #define KMEM_FLAG_HW PCILIB_KMEM_FLAG_HARDWARE /**< The buffer may be accessed by hardware, the hardware access will not occur any more if passed to _free function */
  38. #define KMEM_FLAG_FORCE PCILIB_KMEM_FLAG_FORCE /**< Force memory cleanup even if references are present */
  39. #define KMEM_FLAG_MASS PCILIB_KMEM_FLAG_MASS /**< Apply to all buffers of selected use */
  40. #define KMEM_FLAG_TRY PCILIB_KMEM_FLAG_TRY /**< Do not allocate buffers, try to reuse and fail if not possible */
  41. #define KMEM_FLAG_REUSED PCILIB_KMEM_FLAG_REUSE /**< Indicates if buffer with specified use & item was already allocated and reused */
  42. #define KMEM_FLAG_REUSED_PERSISTENT PCILIB_KMEM_FLAG_PERSISTENT /**< Indicates that reused buffer was persistent before the call */
  43. #define KMEM_FLAG_REUSED_HW PCILIB_KMEM_FLAG_HARDWARE /**< Indicates that reused buffer had a HW reference before the call */
  44. /* Types */
  45. typedef struct {
  46. unsigned long version; /**< pcilib version */
  47. unsigned long interface; /**< driver interface version */
  48. unsigned long ioctls; /**< number of supporterd ioctls */
  49. unsigned long reserved[5]; /**< reserved for the future use */
  50. } pcilib_driver_version_t;
  51. typedef struct {
  52. int iommu; /**< Specifies if IOMMU is enabled or disabled */
  53. int mps; /**< PCIe maximum payload size */
  54. int readrq; /**< PCIe read request size */
  55. unsigned long dma_mask; /**< DMA mask */
  56. } pcilib_device_state_t;
  57. typedef struct {
  58. unsigned short vendor_id;
  59. unsigned short device_id;
  60. unsigned short bus;
  61. unsigned short slot;
  62. unsigned short func;
  63. unsigned short devfn;
  64. unsigned char interrupt_pin;
  65. unsigned char interrupt_line;
  66. unsigned int irq;
  67. unsigned long bar_start[6];
  68. unsigned long bar_length[6];
  69. unsigned long bar_flags[6];
  70. } pcilib_board_info_t;
  71. typedef struct {
  72. unsigned long type;
  73. unsigned long pa;
  74. unsigned long ba;
  75. unsigned long size;
  76. unsigned long align;
  77. unsigned long use;
  78. unsigned long item;
  79. int flags;
  80. int handle_id;
  81. } kmem_handle_t;
  82. typedef struct {
  83. unsigned long addr;
  84. unsigned long size;
  85. } umem_sgentry_t;
  86. typedef struct {
  87. int handle_id;
  88. int type;
  89. int nents;
  90. umem_sgentry_t *sg;
  91. } umem_sglist_t;
  92. typedef struct {
  93. unsigned long vma;
  94. unsigned long size;
  95. int handle_id;
  96. int dir;
  97. } umem_handle_t;
  98. typedef struct {
  99. kmem_handle_t handle;
  100. int dir;
  101. } kmem_sync_t;
  102. typedef struct {
  103. unsigned long count;
  104. unsigned long timeout; // microseconds
  105. unsigned int source;
  106. } interrupt_wait_t;
  107. typedef struct {
  108. int size;
  109. int addr;
  110. union {
  111. unsigned char byte;
  112. unsigned short word;
  113. unsigned int dword; /* not strict C, but if not can have problems */
  114. } val;
  115. } pci_cfg_cmd;
  116. /* ioctl interface */
  117. /* See documentation for a detailed usage explanation */
  118. /*
  119. * one of the problems of ioctl, is that requires a type definition.
  120. * This type is only 8-bits wide, and half-documented in
  121. * <linux-src>/Documentation/ioctl-number.txt.
  122. * previous SHL -> 'S' definition, conflicts with several devices,
  123. * so I changed it to be pci -> 'p', in the range 0xA0-BF
  124. */
  125. #define PCIDRIVER_IOC_MAGIC 'p'
  126. #define PCIDRIVER_IOC_BASE 0xA0
  127. #define PCIDRIVER_IOC_MMAP_MODE _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 0 )
  128. #define PCIDRIVER_IOC_MMAP_AREA _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 1 )
  129. #define PCIDRIVER_IOC_KMEM_ALLOC _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 2, kmem_handle_t * )
  130. #define PCIDRIVER_IOC_KMEM_FREE _IOW ( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 3, kmem_handle_t * )
  131. #define PCIDRIVER_IOC_KMEM_SYNC _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 4, kmem_sync_t * )
  132. #define PCIDRIVER_IOC_UMEM_SGMAP _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 5, umem_handle_t * )
  133. #define PCIDRIVER_IOC_UMEM_SGUNMAP _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 6, umem_handle_t * )
  134. #define PCIDRIVER_IOC_UMEM_SGGET _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 7, umem_sglist_t * )
  135. #define PCIDRIVER_IOC_UMEM_SYNC _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 8, umem_handle_t * )
  136. #define PCIDRIVER_IOC_WAITI _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 9 )
  137. /* And now, the methods to access the PCI configuration area */
  138. #define PCIDRIVER_IOC_PCI_CFG_RD _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 10, pci_cfg_cmd * )
  139. #define PCIDRIVER_IOC_PCI_CFG_WR _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 11, pci_cfg_cmd * )
  140. #define PCIDRIVER_IOC_PCI_INFO _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 12, pcilib_board_info_t * )
  141. /* Clear interrupt queues */
  142. #define PCIDRIVER_IOC_CLEAR_IOQ _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 13 )
  143. #define PCIDRIVER_IOC_VERSION _IOR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 14, pcilib_driver_version_t * )
  144. #define PCIDRIVER_IOC_DEVICE_STATE _IOR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 15, pcilib_device_state_t * )
  145. #define PCIDRIVER_IOC_DMA_MASK _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 16)
  146. #define PCIDRIVER_IOC_MPS _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 17)
  147. #define PCIDRIVER_IOC_MAX 17
  148. #endif /* _PCIDRIVER_IOCTL_H */