pciDriver.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. /* Possible values for ioctl commands */
  58. /* PCI mmap areas */
  59. #define PCIDRIVER_BAR0 0
  60. #define PCIDRIVER_BAR1 1
  61. #define PCIDRIVER_BAR2 2
  62. #define PCIDRIVER_BAR3 3
  63. #define PCIDRIVER_BAR4 4
  64. #define PCIDRIVER_BAR5 5
  65. /* mmap mode of the device */
  66. #define PCIDRIVER_MMAP_PCI 0
  67. #define PCIDRIVER_MMAP_KMEM 1
  68. /* Direction of a DMA operation */
  69. #define PCIDRIVER_DMA_BIDIRECTIONAL 0
  70. #define PCIDRIVER_DMA_TODEVICE 1
  71. #define PCIDRIVER_DMA_FROMDEVICE 2
  72. /* Possible sizes in a PCI command */
  73. #define PCIDRIVER_PCI_CFG_SZ_BYTE 1
  74. #define PCIDRIVER_PCI_CFG_SZ_WORD 2
  75. #define PCIDRIVER_PCI_CFG_SZ_DWORD 3
  76. /* Possible types of SG lists */
  77. #define PCIDRIVER_SG_NONMERGED 0
  78. #define PCIDRIVER_SG_MERGED 1
  79. /* Maximum number of interrupt sources */
  80. #define PCIDRIVER_INT_MAXSOURCES 16
  81. /* Types */
  82. typedef struct {
  83. unsigned long pa;
  84. unsigned long size;
  85. int handle_id;
  86. } kmem_handle_t;
  87. typedef struct {
  88. unsigned long addr;
  89. unsigned long size;
  90. } umem_sgentry_t;
  91. typedef struct {
  92. int handle_id;
  93. int type;
  94. int nents;
  95. umem_sgentry_t *sg;
  96. } umem_sglist_t;
  97. typedef struct {
  98. unsigned long vma;
  99. unsigned long size;
  100. int handle_id;
  101. int dir;
  102. } umem_handle_t;
  103. typedef struct {
  104. kmem_handle_t handle;
  105. int dir;
  106. } kmem_sync_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. typedef struct {
  117. unsigned short vendor_id;
  118. unsigned short device_id;
  119. unsigned short bus;
  120. unsigned short slot;
  121. unsigned short devfn;
  122. unsigned char interrupt_pin;
  123. unsigned char interrupt_line;
  124. unsigned int irq;
  125. unsigned long bar_start[6];
  126. unsigned long bar_length[6];
  127. } pci_board_info;
  128. /* ioctl interface */
  129. /* See documentation for a detailed usage explanation */
  130. /*
  131. * one of the problems of ioctl, is that requires a type definition.
  132. * This type is only 8-bits wide, and half-documented in
  133. * <linux-src>/Documentation/ioctl-number.txt.
  134. * previous SHL -> 'S' definition, conflicts with several devices,
  135. * so I changed it to be pci -> 'p', in the range 0xA0-AF
  136. */
  137. #define PCIDRIVER_IOC_MAGIC 'p'
  138. #define PCIDRIVER_IOC_BASE 0xA0
  139. #define PCIDRIVER_IOC_MMAP_MODE _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 0 )
  140. #define PCIDRIVER_IOC_MMAP_AREA _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 1 )
  141. #define PCIDRIVER_IOC_KMEM_ALLOC _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 2, kmem_handle_t * )
  142. #define PCIDRIVER_IOC_KMEM_FREE _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 3, kmem_handle_t * )
  143. #define PCIDRIVER_IOC_KMEM_SYNC _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 4, kmem_sync_t * )
  144. #define PCIDRIVER_IOC_UMEM_SGMAP _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 5, umem_handle_t * )
  145. #define PCIDRIVER_IOC_UMEM_SGUNMAP _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 6, umem_handle_t * )
  146. #define PCIDRIVER_IOC_UMEM_SGGET _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 7, umem_sglist_t * )
  147. #define PCIDRIVER_IOC_UMEM_SYNC _IOW( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 8, umem_handle_t * )
  148. #define PCIDRIVER_IOC_WAITI _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 9 )
  149. /* And now, the methods to access the PCI configuration area */
  150. #define PCIDRIVER_IOC_PCI_CFG_RD _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 10, pci_cfg_cmd * )
  151. #define PCIDRIVER_IOC_PCI_CFG_WR _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 11, pci_cfg_cmd * )
  152. #define PCIDRIVER_IOC_PCI_INFO _IOWR( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 12, pci_board_info * )
  153. /* Clear interrupt queues */
  154. #define PCIDRIVER_IOC_CLEAR_IOQ _IO( PCIDRIVER_IOC_MAGIC, PCIDRIVER_IOC_BASE + 13 )
  155. #endif