sisusb.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * sisusb - usb kernel driver for Net2280/SiS315 based USB2VGA dongles
  3. *
  4. * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
  5. *
  6. * If distributed as part of the Linux kernel, this code is licensed under the
  7. * terms of the GPL v2.
  8. *
  9. * Otherwise, the following license terms apply:
  10. *
  11. * * Redistribution and use in source and binary forms, with or without
  12. * * modification, are permitted provided that the following conditions
  13. * * are met:
  14. * * 1) Redistributions of source code must retain the above copyright
  15. * * notice, this list of conditions and the following disclaimer.
  16. * * 2) Redistributions in binary form must reproduce the above copyright
  17. * * notice, this list of conditions and the following disclaimer in the
  18. * * documentation and/or other materials provided with the distribution.
  19. * * 3) The name of the author may not be used to endorse or promote products
  20. * * derived from this software without specific prior written permission.
  21. * *
  22. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
  23. * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  24. * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  34. *
  35. */
  36. #ifndef _SISUSB_H_
  37. #define _SISUSB_H_
  38. #ifdef CONFIG_COMPAT
  39. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10)
  40. #include <linux/ioctl32.h>
  41. #define SISUSB_OLD_CONFIG_COMPAT
  42. #else
  43. #define SISUSB_NEW_CONFIG_COMPAT
  44. #endif
  45. #endif
  46. /* Version Information */
  47. #define SISUSB_VERSION 0
  48. #define SISUSB_REVISION 0
  49. #define SISUSB_PATCHLEVEL 7
  50. /* USB related */
  51. #define SISUSB_MINOR 133 /* FIXME */
  52. /* Size of the sisusb input/output buffers */
  53. #define SISUSB_IBUF_SIZE 0x01000
  54. #define SISUSB_OBUF_SIZE 0x10000 /* fixed */
  55. #define NUMOBUFS 8 /* max number of output buffers/output URBs */
  56. /* About endianness:
  57. *
  58. * 1) I/O ports, PCI config registers. The read/write()
  59. * calls emulate inX/outX. Hence, the data is
  60. * expected/delivered in machine endiannes by this
  61. * driver.
  62. * 2) Video memory. The data is copied 1:1. There is
  63. * no swapping. Ever. This means for userland that
  64. * the data has to be prepared properly. (Hint:
  65. * think graphics data format, command queue,
  66. * hardware cursor.)
  67. * 3) MMIO. Data is copied 1:1. MMIO must be swapped
  68. * properly by userland.
  69. *
  70. */
  71. #ifdef __BIG_ENDIAN
  72. #define SISUSB_CORRECT_ENDIANNESS_PACKET(p) \
  73. do { \
  74. p->header = cpu_to_le16(p->header); \
  75. p->address = cpu_to_le32(p->address); \
  76. p->data = cpu_to_le32(p->data); \
  77. } while(0)
  78. #else
  79. #define SISUSB_CORRECT_ENDIANNESS_PACKET(p)
  80. #endif
  81. struct sisusb_usb_data;
  82. struct sisusb_urb_context { /* urb->context for outbound bulk URBs */
  83. struct sisusb_usb_data *sisusb;
  84. int urbindex;
  85. int *actual_length;
  86. };
  87. struct sisusb_usb_data {
  88. struct usb_device *sisusb_dev;
  89. struct usb_interface *interface;
  90. struct kref kref;
  91. wait_queue_head_t wait_q; /* for syncind and timeouts */
  92. struct semaphore lock; /* general race avoidance */
  93. unsigned int ifnum; /* interface number of the USB device */
  94. int minor; /* minor (for logging clarity) */
  95. int isopen; /* !=0 if open */
  96. int present; /* !=0 if device is present on the bus */
  97. int ready; /* !=0 if device is ready for userland */
  98. #ifdef SISUSB_OLD_CONFIG_COMPAT
  99. int ioctl32registered;
  100. #endif
  101. int numobufs; /* number of obufs = number of out urbs */
  102. char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */
  103. int obufsize, ibufsize;
  104. dma_addr_t transfer_dma_out[NUMOBUFS];
  105. dma_addr_t transfer_dma_in;
  106. struct urb *sisurbout[NUMOBUFS];
  107. struct urb *sisurbin;
  108. unsigned char urbstatus[NUMOBUFS];
  109. unsigned char completein;
  110. struct sisusb_urb_context urbout_context[NUMOBUFS];
  111. unsigned long flagb0;
  112. unsigned long vrambase; /* framebuffer base */
  113. unsigned int vramsize; /* framebuffer size (bytes) */
  114. unsigned long mmiobase;
  115. unsigned int mmiosize;
  116. unsigned long ioportbase;
  117. unsigned char devinit; /* device initialized? */
  118. unsigned char gfxinit; /* graphics core initialized? */
  119. unsigned short chipid, chipvendor;
  120. unsigned short chiprevision;
  121. };
  122. #define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref)
  123. /* USB transport related */
  124. /* urbstatus */
  125. #define SU_URB_BUSY 1
  126. #define SU_URB_ALLOC 2
  127. /* Endpoints */
  128. #define SISUSB_EP_GFX_IN 0x0e /* gfx std packet out(0e)/in(8e) */
  129. #define SISUSB_EP_GFX_OUT 0x0e
  130. #define SISUSB_EP_GFX_BULK_OUT 0x01 /* gfx mem bulk out/in */
  131. #define SISUSB_EP_GFX_BULK_IN 0x02 /* ? 2 is "OUT" ? */
  132. #define SISUSB_EP_GFX_LBULK_OUT 0x03 /* gfx large mem bulk out */
  133. #define SISUSB_EP_UNKNOWN_04 0x04 /* ? 4 is "OUT" ? - unused */
  134. #define SISUSB_EP_BRIDGE_IN 0x0d /* Net2280 out(0d)/in(8d) */
  135. #define SISUSB_EP_BRIDGE_OUT 0x0d
  136. #define SISUSB_TYPE_MEM 0
  137. #define SISUSB_TYPE_IO 1
  138. struct sisusb_packet {
  139. unsigned short header;
  140. u32 address;
  141. u32 data;
  142. } __attribute__((__packed__));
  143. #define CLEARPACKET(packet) memset(packet, 0, 10)
  144. /* PCI bridge related */
  145. #define SISUSB_PCI_MEMBASE 0xd0000000
  146. #define SISUSB_PCI_MMIOBASE 0xe4000000
  147. #define SISUSB_PCI_IOPORTBASE 0x0000d000
  148. #define SISUSB_PCI_PSEUDO_MEMBASE 0x10000000
  149. #define SISUSB_PCI_PSEUDO_MMIOBASE 0x20000000
  150. #define SISUSB_PCI_PSEUDO_IOPORTBASE 0x0000d000
  151. #define SISUSB_PCI_PSEUDO_PCIBASE 0x00010000
  152. #define SISUSB_PCI_MMIOSIZE (128*1024)
  153. #define SISUSB_PCI_PCONFSIZE 0x5c
  154. /* graphics core related */
  155. #define AROFFSET 0x40
  156. #define ARROFFSET 0x41
  157. #define GROFFSET 0x4e
  158. #define SROFFSET 0x44
  159. #define CROFFSET 0x54
  160. #define MISCROFFSET 0x4c
  161. #define MISCWOFFSET 0x42
  162. #define INPUTSTATOFFSET 0x5A
  163. #define PART1OFFSET 0x04
  164. #define PART2OFFSET 0x10
  165. #define PART3OFFSET 0x12
  166. #define PART4OFFSET 0x14
  167. #define PART5OFFSET 0x16
  168. #define CAPTUREOFFSET 0x00
  169. #define VIDEOOFFSET 0x02
  170. #define COLREGOFFSET 0x48
  171. #define PELMASKOFFSET 0x46
  172. #define VGAENABLE 0x43
  173. #define SISAR SISUSB_PCI_IOPORTBASE + AROFFSET
  174. #define SISARR SISUSB_PCI_IOPORTBASE + ARROFFSET
  175. #define SISGR SISUSB_PCI_IOPORTBASE + GROFFSET
  176. #define SISSR SISUSB_PCI_IOPORTBASE + SROFFSET
  177. #define SISCR SISUSB_PCI_IOPORTBASE + CROFFSET
  178. #define SISMISCR SISUSB_PCI_IOPORTBASE + MISCROFFSET
  179. #define SISMISCW SISUSB_PCI_IOPORTBASE + MISCWOFFSET
  180. #define SISINPSTAT SISUSB_PCI_IOPORTBASE + INPUTSTATOFFSET
  181. #define SISPART1 SISUSB_PCI_IOPORTBASE + PART1OFFSET
  182. #define SISPART2 SISUSB_PCI_IOPORTBASE + PART2OFFSET
  183. #define SISPART3 SISUSB_PCI_IOPORTBASE + PART3OFFSET
  184. #define SISPART4 SISUSB_PCI_IOPORTBASE + PART4OFFSET
  185. #define SISPART5 SISUSB_PCI_IOPORTBASE + PART5OFFSET
  186. #define SISCAP SISUSB_PCI_IOPORTBASE + CAPTUREOFFSET
  187. #define SISVID SISUSB_PCI_IOPORTBASE + VIDEOOFFSET
  188. #define SISCOLIDXR SISUSB_PCI_IOPORTBASE + COLREGOFFSET - 1
  189. #define SISCOLIDX SISUSB_PCI_IOPORTBASE + COLREGOFFSET
  190. #define SISCOLDATA SISUSB_PCI_IOPORTBASE + COLREGOFFSET + 1
  191. #define SISCOL2IDX SISPART5
  192. #define SISCOL2DATA SISPART5 + 1
  193. #define SISPEL SISUSB_PCI_IOPORTBASE + PELMASKOFFSET
  194. #define SISVGAEN SISUSB_PCI_IOPORTBASE + VGAENABLE
  195. #define SISDACA SISCOLIDX
  196. #define SISDACD SISCOLDATA
  197. /* ioctl related */
  198. /* Structure argument for SISUSB_GET_INFO ioctl */
  199. struct sisusb_info {
  200. __u32 sisusb_id; /* for identifying sisusb */
  201. #define SISUSB_ID 0x53495355 /* Identify myself with 'SISU' */
  202. __u8 sisusb_version;
  203. __u8 sisusb_revision;
  204. __u8 sisusb_patchlevel;
  205. __u8 sisusb_gfxinit; /* graphics core initialized? */
  206. __u32 sisusb_vrambase;
  207. __u32 sisusb_mmiobase;
  208. __u32 sisusb_iobase;
  209. __u32 sisusb_pcibase;
  210. __u32 sisusb_vramsize; /* framebuffer size in bytes */
  211. __u32 sisusb_minor;
  212. __u32 sisusb_fbdevactive; /* != 0 if framebuffer device active */
  213. __u8 sisusb_reserved[32]; /* for future use */
  214. };
  215. struct sisusb_command {
  216. __u8 operation; /* see below */
  217. __u8 data0; /* operation dependent */
  218. __u8 data1; /* operation dependent */
  219. __u8 data2; /* operation dependent */
  220. __u32 data3; /* operation dependent */
  221. __u32 data4; /* for future use */
  222. };
  223. #define SUCMD_GET 0x01 /* for all: data0 = index, data3 = port */
  224. #define SUCMD_SET 0x02 /* data1 = value */
  225. #define SUCMD_SETOR 0x03 /* data1 = or */
  226. #define SUCMD_SETAND 0x04 /* data1 = and */
  227. #define SUCMD_SETANDOR 0x05 /* data1 = and, data2 = or */
  228. #define SUCMD_SETMASK 0x06 /* data1 = data, data2 = mask */
  229. #define SUCMD_CLRSCR 0x07 /* data0:1:2 = length, data3 = address */
  230. #define SISUSB_COMMAND _IOWR(0xF3,0x3D,struct sisusb_command)
  231. #define SISUSB_GET_CONFIG_SIZE _IOR(0xF3,0x3E,__u32)
  232. #define SISUSB_GET_CONFIG _IOR(0xF3,0x3F,struct sisusb_info)
  233. #endif /* SISUSB_H */