pciDriver.h 7.2 KB

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