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 38 #ifndef _SISUSB_H_ 39 #define _SISUSB_H_ 40 41 #ifdef CONFIG_COMPAT 42 #define SISUSB_NEW_CONFIG_COMPAT 43 #endif 44 45 #include <linux/mutex.h> 46 47 /* For older kernels, support for text consoles is by default 48 * off. To enable text console support, change the following: 49 */ 50 /* #define CONFIG_USB_SISUSBVGA_CON */ 51 52 /* Version Information */ 53 54 #define SISUSB_VERSION 0 55 #define SISUSB_REVISION 0 56 #define SISUSB_PATCHLEVEL 8 57 58 /* Include console and mode switching code? */ 59 60 #ifdef CONFIG_USB_SISUSBVGA_CON 61 #define INCL_SISUSB_CON 1 62 #endif 63 64 #include <linux/console.h> 65 #include <linux/vt_kern.h> 66 #include "sisusb_struct.h" 67 68 /* USB related */ 69 70 #define SISUSB_MINOR 133 /* official */ 71 72 /* Size of the sisusb input/output buffers */ 73 #define SISUSB_IBUF_SIZE 0x01000 74 #define SISUSB_OBUF_SIZE 0x10000 /* fixed */ 75 76 #define NUMOBUFS 8 /* max number of output buffers/output URBs */ 77 78 /* About endianness: 79 * 80 * 1) I/O ports, PCI config registers. The read/write() 81 * calls emulate inX/outX. Hence, the data is 82 * expected/delivered in machine endiannes by this 83 * driver. 84 * 2) Video memory. The data is copied 1:1. There is 85 * no swapping. Ever. This means for userland that 86 * the data has to be prepared properly. (Hint: 87 * think graphics data format, command queue, 88 * hardware cursor.) 89 * 3) MMIO. Data is copied 1:1. MMIO must be swapped 90 * properly by userland. 91 * 92 */ 93 94 #ifdef __BIG_ENDIAN 95 #define SISUSB_CORRECT_ENDIANNESS_PACKET(p) \ 96 do { \ 97 p->header = cpu_to_le16(p->header); \ 98 p->address = cpu_to_le32(p->address); \ 99 p->data = cpu_to_le32(p->data); \ 100 } while(0) 101 #else 102 #define SISUSB_CORRECT_ENDIANNESS_PACKET(p) 103 #endif 104 105 struct sisusb_usb_data; 106 107 struct sisusb_urb_context { /* urb->context for outbound bulk URBs */ 108 struct sisusb_usb_data *sisusb; 109 int urbindex; 110 int *actual_length; 111 }; 112 113 struct sisusb_usb_data { 114 struct usb_device *sisusb_dev; 115 struct usb_interface *interface; 116 struct kref kref; 117 wait_queue_head_t wait_q; /* for syncind and timeouts */ 118 struct mutex lock; /* general race avoidance */ 119 unsigned int ifnum; /* interface number of the USB device */ 120 int minor; /* minor (for logging clarity) */ 121 int isopen; /* !=0 if open */ 122 int present; /* !=0 if device is present on the bus */ 123 int ready; /* !=0 if device is ready for userland */ 124 int numobufs; /* number of obufs = number of out urbs */ 125 char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */ 126 int obufsize, ibufsize; 127 struct urb *sisurbout[NUMOBUFS]; 128 struct urb *sisurbin; 129 unsigned char urbstatus[NUMOBUFS]; 130 unsigned char completein; 131 struct sisusb_urb_context urbout_context[NUMOBUFS]; 132 unsigned long flagb0; 133 unsigned long vrambase; /* framebuffer base */ 134 unsigned int vramsize; /* framebuffer size (bytes) */ 135 unsigned long mmiobase; 136 unsigned int mmiosize; 137 unsigned long ioportbase; 138 unsigned char devinit; /* device initialized? */ 139 unsigned char gfxinit; /* graphics core initialized? */ 140 unsigned short chipid, chipvendor; 141 unsigned short chiprevision; 142 #ifdef INCL_SISUSB_CON 143 struct SiS_Private *SiS_Pr; 144 unsigned long scrbuf; 145 unsigned int scrbuf_size; 146 int haveconsole, con_first, con_last; 147 int havethisconsole[MAX_NR_CONSOLES]; 148 int textmodedestroyed; 149 unsigned int sisusb_num_columns; /* real number, not vt's idea */ 150 int cur_start_addr, con_rolled_over; 151 int sisusb_cursor_loc, bad_cursor_pos; 152 int sisusb_cursor_size_from; 153 int sisusb_cursor_size_to; 154 int current_font_height, current_font_512; 155 int font_backup_size, font_backup_height, font_backup_512; 156 char *font_backup; 157 int font_slot; 158 struct vc_data *sisusb_display_fg; 159 int is_gfx; 160 int con_blanked; 161 #endif 162 }; 163 164 #define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref) 165 166 /* USB transport related */ 167 168 /* urbstatus */ 169 #define SU_URB_BUSY 1 170 #define SU_URB_ALLOC 2 171 172 /* Endpoints */ 173 174 #define SISUSB_EP_GFX_IN 0x0e /* gfx std packet out(0e)/in(8e) */ 175 #define SISUSB_EP_GFX_OUT 0x0e 176 177 #define SISUSB_EP_GFX_BULK_OUT 0x01 /* gfx mem bulk out/in */ 178 #define SISUSB_EP_GFX_BULK_IN 0x02 /* ? 2 is "OUT" ? */ 179 180 #define SISUSB_EP_GFX_LBULK_OUT 0x03 /* gfx large mem bulk out */ 181 182 #define SISUSB_EP_UNKNOWN_04 0x04 /* ? 4 is "OUT" ? - unused */ 183 184 #define SISUSB_EP_BRIDGE_IN 0x0d /* Net2280 out(0d)/in(8d) */ 185 #define SISUSB_EP_BRIDGE_OUT 0x0d 186 187 #define SISUSB_TYPE_MEM 0 188 #define SISUSB_TYPE_IO 1 189 190 struct sisusb_packet { 191 unsigned short header; 192 u32 address; 193 u32 data; 194 } __attribute__ ((__packed__)); 195 196 #define CLEARPACKET(packet) memset(packet, 0, 10) 197 198 /* PCI bridge related */ 199 200 #define SISUSB_PCI_MEMBASE 0xd0000000 201 #define SISUSB_PCI_MMIOBASE 0xe4000000 202 #define SISUSB_PCI_IOPORTBASE 0x0000d000 203 204 #define SISUSB_PCI_PSEUDO_MEMBASE 0x10000000 205 #define SISUSB_PCI_PSEUDO_MMIOBASE 0x20000000 206 #define SISUSB_PCI_PSEUDO_IOPORTBASE 0x0000d000 207 #define SISUSB_PCI_PSEUDO_PCIBASE 0x00010000 208 209 #define SISUSB_PCI_MMIOSIZE (128*1024) 210 #define SISUSB_PCI_PCONFSIZE 0x5c 211 212 /* graphics core related */ 213 214 #define AROFFSET 0x40 215 #define ARROFFSET 0x41 216 #define GROFFSET 0x4e 217 #define SROFFSET 0x44 218 #define CROFFSET 0x54 219 #define MISCROFFSET 0x4c 220 #define MISCWOFFSET 0x42 221 #define INPUTSTATOFFSET 0x5A 222 #define PART1OFFSET 0x04 223 #define PART2OFFSET 0x10 224 #define PART3OFFSET 0x12 225 #define PART4OFFSET 0x14 226 #define PART5OFFSET 0x16 227 #define CAPTUREOFFSET 0x00 228 #define VIDEOOFFSET 0x02 229 #define COLREGOFFSET 0x48 230 #define PELMASKOFFSET 0x46 231 #define VGAENABLE 0x43 232 233 #define SISAR SISUSB_PCI_IOPORTBASE + AROFFSET 234 #define SISARR SISUSB_PCI_IOPORTBASE + ARROFFSET 235 #define SISGR SISUSB_PCI_IOPORTBASE + GROFFSET 236 #define SISSR SISUSB_PCI_IOPORTBASE + SROFFSET 237 #define SISCR SISUSB_PCI_IOPORTBASE + CROFFSET 238 #define SISMISCR SISUSB_PCI_IOPORTBASE + MISCROFFSET 239 #define SISMISCW SISUSB_PCI_IOPORTBASE + MISCWOFFSET 240 #define SISINPSTAT SISUSB_PCI_IOPORTBASE + INPUTSTATOFFSET 241 #define SISPART1 SISUSB_PCI_IOPORTBASE + PART1OFFSET 242 #define SISPART2 SISUSB_PCI_IOPORTBASE + PART2OFFSET 243 #define SISPART3 SISUSB_PCI_IOPORTBASE + PART3OFFSET 244 #define SISPART4 SISUSB_PCI_IOPORTBASE + PART4OFFSET 245 #define SISPART5 SISUSB_PCI_IOPORTBASE + PART5OFFSET 246 #define SISCAP SISUSB_PCI_IOPORTBASE + CAPTUREOFFSET 247 #define SISVID SISUSB_PCI_IOPORTBASE + VIDEOOFFSET 248 #define SISCOLIDXR SISUSB_PCI_IOPORTBASE + COLREGOFFSET - 1 249 #define SISCOLIDX SISUSB_PCI_IOPORTBASE + COLREGOFFSET 250 #define SISCOLDATA SISUSB_PCI_IOPORTBASE + COLREGOFFSET + 1 251 #define SISCOL2IDX SISPART5 252 #define SISCOL2DATA SISPART5 + 1 253 #define SISPEL SISUSB_PCI_IOPORTBASE + PELMASKOFFSET 254 #define SISVGAEN SISUSB_PCI_IOPORTBASE + VGAENABLE 255 #define SISDACA SISCOLIDX 256 #define SISDACD SISCOLDATA 257 258 /* ioctl related */ 259 260 /* Structure argument for SISUSB_GET_INFO ioctl */ 261 struct sisusb_info { 262 __u32 sisusb_id; /* for identifying sisusb */ 263 #define SISUSB_ID 0x53495355 /* Identify myself with 'SISU' */ 264 __u8 sisusb_version; 265 __u8 sisusb_revision; 266 __u8 sisusb_patchlevel; 267 __u8 sisusb_gfxinit; /* graphics core initialized? */ 268 269 __u32 sisusb_vrambase; 270 __u32 sisusb_mmiobase; 271 __u32 sisusb_iobase; 272 __u32 sisusb_pcibase; 273 274 __u32 sisusb_vramsize; /* framebuffer size in bytes */ 275 276 __u32 sisusb_minor; 277 278 __u32 sisusb_fbdevactive; /* != 0 if framebuffer device active */ 279 280 __u32 sisusb_conactive; /* != 0 if console driver active */ 281 282 __u8 sisusb_reserved[28]; /* for future use */ 283 }; 284 285 struct sisusb_command { 286 __u8 operation; /* see below */ 287 __u8 data0; /* operation dependent */ 288 __u8 data1; /* operation dependent */ 289 __u8 data2; /* operation dependent */ 290 __u32 data3; /* operation dependent */ 291 __u32 data4; /* for future use */ 292 }; 293 294 #define SUCMD_GET 0x01 /* for all: data0 = index, data3 = port */ 295 #define SUCMD_SET 0x02 /* data1 = value */ 296 #define SUCMD_SETOR 0x03 /* data1 = or */ 297 #define SUCMD_SETAND 0x04 /* data1 = and */ 298 #define SUCMD_SETANDOR 0x05 /* data1 = and, data2 = or */ 299 #define SUCMD_SETMASK 0x06 /* data1 = data, data2 = mask */ 300 301 #define SUCMD_CLRSCR 0x07 /* data0:1:2 = length, data3 = address */ 302 303 #define SUCMD_HANDLETEXTMODE 0x08 /* Reset/destroy text mode */ 304 305 #define SUCMD_SETMODE 0x09 /* Set a display mode (data3 = SiS mode) */ 306 #define SUCMD_SETVESAMODE 0x0a /* Set a display mode (data3 = VESA mode) */ 307 308 #define SISUSB_COMMAND _IOWR(0xF3,0x3D,struct sisusb_command) 309 #define SISUSB_GET_CONFIG_SIZE _IOR(0xF3,0x3E,__u32) 310 #define SISUSB_GET_CONFIG _IOR(0xF3,0x3F,struct sisusb_info) 311 312 #endif /* SISUSB_H */ 313