sisusb.h 9.8 KB

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