pciDriver.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 0x04a0
  61. /* Identifies the PCI-E IPE Camera */
  62. #define PCIE_IPECAMERA_DEVICE_ID 0x6081
  63. //#define PCIE_IPECAMERA_DEVICE_ID 0x6018
  64. /* Possible values for ioctl commands */
  65. /* PCI mmap areas */
  66. #define PCIDRIVER_BAR0 0
  67. #define PCIDRIVER_BAR1 1
  68. #define PCIDRIVER_BAR2 2
  69. #define PCIDRIVER_BAR3 3
  70. #define PCIDRIVER_BAR4 4
  71. #define PCIDRIVER_BAR5 5
  72. /* mmap mode of the device */
  73. #define PCIDRIVER_MMAP_PCI 0
  74. #define PCIDRIVER_MMAP_KMEM 1
  75. /* Direction of a DMA operation */
  76. #define PCIDRIVER_DMA_BIDIRECTIONAL 0
  77. #define PCIDRIVER_DMA_TODEVICE PCILIB_KMEM_SYNC_TODEVICE
  78. #define PCIDRIVER_DMA_FROMDEVICE PCILIB_KMEM_SYNC_FROMDEVICE
  79. /* Possible sizes in a PCI command */
  80. #define PCIDRIVER_PCI_CFG_SZ_BYTE 1
  81. #define PCIDRIVER_PCI_CFG_SZ_WORD 2
  82. #define PCIDRIVER_PCI_CFG_SZ_DWORD 3
  83. /* Possible types of SG lists */
  84. #define PCIDRIVER_SG_NONMERGED 0
  85. #define PCIDRIVER_SG_MERGED 1
  86. /* Maximum number of interrupt sources */
  87. #define PCIDRIVER_INT_MAXSOURCES 16
  88. #define KMEM_FLAG_REUSE 1 /**< Try to reuse existing buffer with the same use & item */
  89. #define KMEM_FLAG_EXCLUSIVE 2 /**< Allow only a single application accessing a specified use & item */
  90. #define KMEM_FLAG_PERSISTENT 4 /**< Sets persistent mode */
  91. #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 */
  92. #define KMEM_FLAG_FORCE 16 /**< Force memory cleanup even if references are present */
  93. #define KMEM_FLAG_MASS 32 /**< Apply to all buffers of selected use */
  94. #define KMEM_FLAG_TRY 64 /**< Do not allocate buffers, try to reuse and fail if not possible */
  95. #define KMEM_FLAG_REUSED 1 /**< Indicates if buffer with specified use & item was already allocated and reused */
  96. #define KMEM_FLAG_REUSED_PERSISTENT 4 /**< Indicates that reused buffer was persistent before the call */
  97. #define KMEM_FLAG_REUSED_HW 8 /**< Indicates that reused buffer had a HW reference before the call */
  98. /* Types */
  99. typedef struct {
  100. unsigned long type;
  101. unsigned long pa;
  102. unsigned long size;
  103. unsigned long align;
  104. unsigned long use;
  105. unsigned long item;
  106. int flags;
  107. int handle_id;
  108. } kmem_handle_t;
  109. typedef struct {
  110. unsigned long addr;
  111. unsigned long size;
  112. } umem_sgentry_t;
  113. typedef struct {
  114. int handle_id;
  115. int type;
  116. int nents;
  117. umem_sgentry_t *sg;
  118. } umem_sglist_t;
  119. typedef struct {
  120. unsigned long vma;
  121. unsigned long size;
  122. int handle_id;
  123. int dir;
  124. } umem_handle_t;
  125. typedef struct {
  126. kmem_handle_t handle;
  127. int dir;
  128. } kmem_sync_t;
  129. typedef struct {
  130. unsigned long count;
  131. unsigned long timeout; // microseconds
  132. unsigned int source;
  133. } interrupt_wait_t;
  134. typedef struct {
  135. int size;
  136. int addr;
  137. union {
  138. unsigned char byte;
  139. unsigned short word;
  140. unsigned int dword; /* not strict C, but if not can have problems */
  141. } val;
  142. } pci_cfg_cmd;
  143. typedef struct {
  144. unsigned short vendor_id;
  145. unsigned short device_id;
  146. unsigned short bus;
  147. unsigned short slot;
  148. unsigned short devfn;
  149. unsigned char interrupt_pin;
  150. unsigned char interrupt_line;
  151. unsigned int irq;
  152. unsigned long bar_start[6];
  153. unsigned long bar_length[6];
  154. unsigned long bar_flags[6];
  155. } pcilib_board_info_t;
  156. /* ioctl interface */
  157. /* See documentation for a detailed usage explanation */
  158. /*
  159. * one of the problems of ioctl, is that requires a type definition.
  160. * This type is only 8-bits wide, and half-documented in
  161. * <linux-src>/Documentation/ioctl-number.txt.
  162. * previous SHL -> 'S' definition, conflicts with several devices,
  163. * so I changed it to be pci -> 'p', in the range 0xA0-AF
  164. */
  165. #define PCIDRIVER_IOC_MAGIC 'p'
  166. #define PCIDRIVER_IOC_BASE 0xA0
  167. #define PCIDRIVER_IOC_MMAP_MODE _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 0 )
  168. #define PCIDRIVER_IOC_MMAP_AREA _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 1 )
  169. #define PCIDRIVER_IOC_KMEM_ALLOC _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 2, kmem_handle_t * )
  170. #define PCIDRIVER_IOC_KMEM_FREE _IOW ( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 3, kmem_handle_t * )
  171. #define PCIDRIVER_IOC_KMEM_SYNC _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 4, kmem_sync_t * )
  172. #define PCIDRIVER_IOC_UMEM_SGMAP _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 5, umem_handle_t * )
  173. #define PCIDRIVER_IOC_UMEM_SGUNMAP _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 6, umem_handle_t * )
  174. #define PCIDRIVER_IOC_UMEM_SGGET _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 7, umem_sglist_t * )
  175. #define PCIDRIVER_IOC_UMEM_SYNC _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 8, umem_handle_t * )
  176. #define PCIDRIVER_IOC_WAITI _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 9 )
  177. /* And now, the methods to access the PCI configuration area */
  178. #define PCIDRIVER_IOC_PCI_CFG_RD _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 10, pci_cfg_cmd * )
  179. #define PCIDRIVER_IOC_PCI_CFG_WR _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 11, pci_cfg_cmd * )
  180. #define PCIDRIVER_IOC_PCI_INFO _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 12, pcilib_board_info_t * )
  181. /* Clear interrupt queues */
  182. #define PCIDRIVER_IOC_CLEAR_IOQ _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 13 )
  183. #endif