pciDriver.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #ifndef PCIDRIVER_H_
  2. #define PCIDRIVER_H_
  3. /**
  4. * This is a full rewrite of the pciDriver.
  5. * New default is to support kernel 2.6, using kernel 2.6 APIs.
  6. *
  7. * This header defines the interface to the outside world.
  8. *
  9. * $Revision: 1.6 $
  10. * $Date: 2008-01-24 14:21:36 $
  11. *
  12. */
  13. /*
  14. * Change History:
  15. *
  16. * $Log: not supported by cvs2svn $
  17. * Revision 1.5 2008-01-11 10:15:14 marcus
  18. * Removed unused interrupt code.
  19. * Added intSource to the wait interrupt call.
  20. *
  21. * Revision 1.4 2006/11/17 18:44:42 marcus
  22. * Type of SG list can now be selected at runtime. Added type to sglist.
  23. *
  24. * Revision 1.3 2006/11/17 16:23:02 marcus
  25. * Added slot number to the PCI info IOctl.
  26. *
  27. * Revision 1.2 2006/11/13 12:29:09 marcus
  28. * Added a IOctl call, to confiure the interrupt response. (testing pending).
  29. * Basic interrupts are now supported.
  30. *
  31. * Revision 1.1 2006/10/10 14:46:52 marcus
  32. * Initial commit of the new pciDriver for kernel 2.6
  33. *
  34. * Revision 1.7 2006/10/06 15:18:06 marcus
  35. * Updated PCI info and PCI cmd
  36. *
  37. * Revision 1.6 2006/09/25 16:51:07 marcus
  38. * Added PCI config IOctls, and implemented basic mmap functions.
  39. *
  40. * Revision 1.5 2006/09/18 17:13:12 marcus
  41. * backup commit.
  42. *
  43. * Revision 1.4 2006/09/15 15:44:41 marcus
  44. * backup commit.
  45. *
  46. * Revision 1.3 2006/08/15 11:40:02 marcus
  47. * backup commit.
  48. *
  49. * Revision 1.2 2006/08/12 18:28:42 marcus
  50. * Sync with the laptop
  51. *
  52. * Revision 1.1 2006/08/11 15:30:46 marcus
  53. * Sync with the laptop
  54. *
  55. */
  56. #include <linux/ioctl.h>
  57. #include "../pcilib_types.h"
  58. /* Identifies the PCI-E Xilinx ML605 */
  59. #define PCIE_XILINX_VENDOR_ID 0x10ee
  60. #define PCIE_ML605_DEVICE_ID 0x6024
  61. /* Identifies the PCI-E IPE Camera */
  62. #define PCIE_IPECAMERA_DEVICE_ID 0x6081
  63. #define PCIE_KAPTURE_DEVICE_ID 0x6028
  64. //#define PCIE_IPECAMERA_DEVICE_ID 0x6018
  65. /* Possible values for ioctl commands */
  66. /* PCI mmap areas */
  67. #define PCIDRIVER_BAR0 0
  68. #define PCIDRIVER_BAR1 1
  69. #define PCIDRIVER_BAR2 2
  70. #define PCIDRIVER_BAR3 3
  71. #define PCIDRIVER_BAR4 4
  72. #define PCIDRIVER_BAR5 5
  73. /* mmap mode of the device */
  74. #define PCIDRIVER_MMAP_PCI 0
  75. #define PCIDRIVER_MMAP_KMEM 1
  76. /* Direction of a DMA operation */
  77. #define PCIDRIVER_DMA_BIDIRECTIONAL 0
  78. #define PCIDRIVER_DMA_TODEVICE PCILIB_KMEM_SYNC_TODEVICE
  79. #define PCIDRIVER_DMA_FROMDEVICE PCILIB_KMEM_SYNC_FROMDEVICE
  80. /* Possible sizes in a PCI command */
  81. #define PCIDRIVER_PCI_CFG_SZ_BYTE 1
  82. #define PCIDRIVER_PCI_CFG_SZ_WORD 2
  83. #define PCIDRIVER_PCI_CFG_SZ_DWORD 3
  84. /* Possible types of SG lists */
  85. #define PCIDRIVER_SG_NONMERGED 0
  86. #define PCIDRIVER_SG_MERGED 1
  87. /* Maximum number of interrupt sources */
  88. #define PCIDRIVER_INT_MAXSOURCES 16
  89. #define KMEM_FLAG_REUSE 1 /**< Try to reuse existing buffer with the same use & item */
  90. #define KMEM_FLAG_EXCLUSIVE 2 /**< Allow only a single application accessing a specified use & item */
  91. #define KMEM_FLAG_PERSISTENT 4 /**< Sets persistent mode */
  92. #define KMEM_FLAG_HW 8 /**< The buffer may be accessed by hardware, the hardware access will not occur any more if passed to _free function */
  93. #define KMEM_FLAG_FORCE 16 /**< Force memory cleanup even if references are present */
  94. #define KMEM_FLAG_MASS 32 /**< Apply to all buffers of selected use */
  95. #define KMEM_FLAG_TRY 64 /**< Do not allocate buffers, try to reuse and fail if not possible */
  96. #define KMEM_FLAG_REUSED 1 /**< Indicates if buffer with specified use & item was already allocated and reused */
  97. #define KMEM_FLAG_REUSED_PERSISTENT 4 /**< Indicates that reused buffer was persistent before the call */
  98. #define KMEM_FLAG_REUSED_HW 8 /**< Indicates that reused buffer had a HW reference before the call */
  99. /* Types */
  100. typedef struct {
  101. unsigned long type;
  102. unsigned long pa;
  103. unsigned long size;
  104. unsigned long align;
  105. unsigned long use;
  106. unsigned long item;
  107. int flags;
  108. int handle_id;
  109. } kmem_handle_t;
  110. typedef struct {
  111. unsigned long addr;
  112. unsigned long size;
  113. } umem_sgentry_t;
  114. typedef struct {
  115. int handle_id;
  116. int type;
  117. int nents;
  118. umem_sgentry_t *sg;
  119. } umem_sglist_t;
  120. typedef struct {
  121. unsigned long vma;
  122. unsigned long size;
  123. int handle_id;
  124. int dir;
  125. } umem_handle_t;
  126. typedef struct {
  127. kmem_handle_t handle;
  128. int dir;
  129. } kmem_sync_t;
  130. typedef struct {
  131. unsigned long count;
  132. unsigned long timeout; // microseconds
  133. unsigned int source;
  134. } interrupt_wait_t;
  135. typedef struct {
  136. int size;
  137. int addr;
  138. union {
  139. unsigned char byte;
  140. unsigned short word;
  141. unsigned int dword; /* not strict C, but if not can have problems */
  142. } val;
  143. } pci_cfg_cmd;
  144. typedef struct {
  145. unsigned short vendor_id;
  146. unsigned short device_id;
  147. unsigned short bus;
  148. unsigned short slot;
  149. unsigned short func;
  150. unsigned short devfn;
  151. unsigned char interrupt_pin;
  152. unsigned char interrupt_line;
  153. unsigned int irq;
  154. unsigned long bar_start[6];
  155. unsigned long bar_length[6];
  156. unsigned long bar_flags[6];
  157. } pcilib_board_info_t;
  158. /* ioctl interface */
  159. /* See documentation for a detailed usage explanation */
  160. /*
  161. * one of the problems of ioctl, is that requires a type definition.
  162. * This type is only 8-bits wide, and half-documented in
  163. * <linux-src>/Documentation/ioctl-number.txt.
  164. * previous SHL -> 'S' definition, conflicts with several devices,
  165. * so I changed it to be pci -> 'p', in the range 0xA0-AF
  166. */
  167. #define PCIDRIVER_IOC_MAGIC 'p'
  168. #define PCIDRIVER_IOC_BASE 0xA0
  169. #define PCIDRIVER_IOC_MMAP_MODE _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 0 )
  170. #define PCIDRIVER_IOC_MMAP_AREA _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 1 )
  171. #define PCIDRIVER_IOC_KMEM_ALLOC _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 2, kmem_handle_t * )
  172. #define PCIDRIVER_IOC_KMEM_FREE _IOW ( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 3, kmem_handle_t * )
  173. #define PCIDRIVER_IOC_KMEM_SYNC _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 4, kmem_sync_t * )
  174. #define PCIDRIVER_IOC_UMEM_SGMAP _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 5, umem_handle_t * )
  175. #define PCIDRIVER_IOC_UMEM_SGUNMAP _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 6, umem_handle_t * )
  176. #define PCIDRIVER_IOC_UMEM_SGGET _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 7, umem_sglist_t * )
  177. #define PCIDRIVER_IOC_UMEM_SYNC _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 8, umem_handle_t * )
  178. #define PCIDRIVER_IOC_WAITI _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 9 )
  179. /* And now, the methods to access the PCI configuration area */
  180. #define PCIDRIVER_IOC_PCI_CFG_RD _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 10, pci_cfg_cmd * )
  181. #define PCIDRIVER_IOC_PCI_CFG_WR _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 11, pci_cfg_cmd * )
  182. #define PCIDRIVER_IOC_PCI_INFO _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 12, pcilib_board_info_t * )
  183. /* Clear interrupt queues */
  184. #define PCIDRIVER_IOC_CLEAR_IOQ _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 13 )
  185. #endif