Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
0002 /*
0003  * sisusb - usb kernel driver for Net2280/SiS315 based USB2VGA dongles
0004  *
0005  * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
0006  *
0007  * If distributed as part of the Linux kernel, this code is licensed under the
0008  * terms of the GPL v2.
0009  *
0010  * Otherwise, the following license terms apply:
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1) Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2) Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  * 3) The name of the author may not be used to endorse or promote products
0021  *    derived from this software without specific prior written permission.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
0024  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0025  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0026  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0028  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0032  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0033  *
0034  * Author:  Thomas Winischhofer <thomas@winischhofer.net>
0035  *
0036  */
0037 
0038 #ifndef _SISUSB_H_
0039 #define _SISUSB_H_
0040 
0041 #include <linux/mutex.h>
0042 
0043 /* Version Information */
0044 
0045 #define SISUSB_VERSION      0
0046 #define SISUSB_REVISION     0
0047 #define SISUSB_PATCHLEVEL   8
0048 
0049 /* Include console and mode switching code? */
0050 
0051 #include <linux/console.h>
0052 #include <linux/vt_kern.h>
0053 #include "sisusb_struct.h"
0054 
0055 /* USB related */
0056 
0057 #define SISUSB_MINOR        133 /* official */
0058 
0059 /* Size of the sisusb input/output buffers */
0060 #define SISUSB_IBUF_SIZE  0x01000
0061 #define SISUSB_OBUF_SIZE  0x10000   /* fixed */
0062 
0063 #define NUMOBUFS 8      /* max number of output buffers/output URBs */
0064 
0065 /* About endianness:
0066  *
0067  * 1) I/O ports, PCI config registers. The read/write()
0068  *    calls emulate inX/outX. Hence, the data is
0069  *    expected/delivered in machine endiannes by this
0070  *    driver.
0071  * 2) Video memory. The data is copied 1:1. There is
0072  *    no swapping. Ever. This means for userland that
0073  *    the data has to be prepared properly. (Hint:
0074  *    think graphics data format, command queue,
0075  *    hardware cursor.)
0076  * 3) MMIO. Data is copied 1:1. MMIO must be swapped
0077  *    properly by userland.
0078  *
0079  */
0080 
0081 #ifdef __BIG_ENDIAN
0082 #define SISUSB_CORRECT_ENDIANNESS_PACKET(p)     \
0083     do {                        \
0084         p->header  = cpu_to_le16(p->header);    \
0085         p->address = cpu_to_le32(p->address);   \
0086         p->data    = cpu_to_le32(p->data);  \
0087     } while(0)
0088 #else
0089 #define SISUSB_CORRECT_ENDIANNESS_PACKET(p)
0090 #endif
0091 
0092 struct sisusb_usb_data;
0093 
0094 struct sisusb_urb_context { /* urb->context for outbound bulk URBs */
0095     struct sisusb_usb_data *sisusb;
0096     int urbindex;
0097     int *actual_length;
0098 };
0099 
0100 struct sisusb_usb_data {
0101     struct usb_device *sisusb_dev;
0102     struct usb_interface *interface;
0103     struct kref kref;
0104     wait_queue_head_t wait_q;   /* for syncind and timeouts */
0105     struct mutex lock;  /* general race avoidance */
0106     unsigned int ifnum; /* interface number of the USB device */
0107     int minor;      /* minor (for logging clarity) */
0108     int isopen;     /* !=0 if open */
0109     int present;        /* !=0 if device is present on the bus */
0110     int ready;      /* !=0 if device is ready for userland */
0111     int numobufs;       /* number of obufs = number of out urbs */
0112     char *obuf[NUMOBUFS], *ibuf;    /* transfer buffers */
0113     int obufsize, ibufsize;
0114     struct urb *sisurbout[NUMOBUFS];
0115     struct urb *sisurbin;
0116     unsigned char urbstatus[NUMOBUFS];
0117     unsigned char completein;
0118     struct sisusb_urb_context urbout_context[NUMOBUFS];
0119     unsigned long flagb0;
0120     unsigned long vrambase; /* framebuffer base */
0121     unsigned int vramsize;  /* framebuffer size (bytes) */
0122     unsigned long mmiobase;
0123     unsigned int mmiosize;
0124     unsigned long ioportbase;
0125     unsigned char devinit;  /* device initialized? */
0126     unsigned char gfxinit;  /* graphics core initialized? */
0127     unsigned short chipid, chipvendor;
0128     unsigned short chiprevision;
0129 #ifdef CONFIG_USB_SISUSBVGA_CON
0130     struct SiS_Private *SiS_Pr;
0131     unsigned long scrbuf;
0132     unsigned int scrbuf_size;
0133     int haveconsole, con_first, con_last;
0134     int havethisconsole[MAX_NR_CONSOLES];
0135     int textmodedestroyed;
0136     unsigned int sisusb_num_columns;    /* real number, not vt's idea */
0137     int cur_start_addr, con_rolled_over;
0138     int sisusb_cursor_loc, bad_cursor_pos;
0139     int sisusb_cursor_size_from;
0140     int sisusb_cursor_size_to;
0141     int current_font_height, current_font_512;
0142     int font_backup_size, font_backup_height, font_backup_512;
0143     char *font_backup;
0144     int font_slot;
0145     struct vc_data *sisusb_display_fg;
0146     int is_gfx;
0147     int con_blanked;
0148 #endif
0149 };
0150 
0151 #define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref)
0152 
0153 /* USB transport related */
0154 
0155 /* urbstatus */
0156 #define SU_URB_BUSY   1
0157 #define SU_URB_ALLOC  2
0158 
0159 /* Endpoints */
0160 
0161 #define SISUSB_EP_GFX_IN    0x0e    /* gfx std packet out(0e)/in(8e) */
0162 #define SISUSB_EP_GFX_OUT   0x0e
0163 
0164 #define SISUSB_EP_GFX_BULK_OUT  0x01    /* gfx mem bulk out/in */
0165 #define SISUSB_EP_GFX_BULK_IN   0x02    /* ? 2 is "OUT" ? */
0166 
0167 #define SISUSB_EP_GFX_LBULK_OUT 0x03    /* gfx large mem bulk out */
0168 
0169 #define SISUSB_EP_UNKNOWN_04    0x04    /* ? 4 is "OUT" ? - unused */
0170 
0171 #define SISUSB_EP_BRIDGE_IN 0x0d    /* Net2280 out(0d)/in(8d) */
0172 #define SISUSB_EP_BRIDGE_OUT    0x0d
0173 
0174 #define SISUSB_TYPE_MEM     0
0175 #define SISUSB_TYPE_IO      1
0176 
0177 struct sisusb_packet {
0178     unsigned short header;
0179     u32 address;
0180     u32 data;
0181 } __attribute__ ((__packed__));
0182 
0183 #define CLEARPACKET(packet) memset(packet, 0, 10)
0184 
0185 /* PCI bridge related */
0186 
0187 #define SISUSB_PCI_MEMBASE  0xd0000000
0188 #define SISUSB_PCI_MMIOBASE 0xe4000000
0189 #define SISUSB_PCI_IOPORTBASE   0x0000d000
0190 
0191 #define SISUSB_PCI_PSEUDO_MEMBASE   0x10000000
0192 #define SISUSB_PCI_PSEUDO_MMIOBASE  0x20000000
0193 #define SISUSB_PCI_PSEUDO_IOPORTBASE    0x0000d000
0194 #define SISUSB_PCI_PSEUDO_PCIBASE   0x00010000
0195 
0196 #define SISUSB_PCI_MMIOSIZE (128*1024)
0197 #define SISUSB_PCI_PCONFSIZE    0x5c
0198 
0199 /* graphics core related */
0200 
0201 #define AROFFSET    0x40
0202 #define ARROFFSET   0x41
0203 #define GROFFSET    0x4e
0204 #define SROFFSET    0x44
0205 #define CROFFSET    0x54
0206 #define MISCROFFSET 0x4c
0207 #define MISCWOFFSET 0x42
0208 #define INPUTSTATOFFSET 0x5A
0209 #define PART1OFFSET 0x04
0210 #define PART2OFFSET 0x10
0211 #define PART3OFFSET 0x12
0212 #define PART4OFFSET 0x14
0213 #define PART5OFFSET 0x16
0214 #define CAPTUREOFFSET   0x00
0215 #define VIDEOOFFSET 0x02
0216 #define COLREGOFFSET    0x48
0217 #define PELMASKOFFSET   0x46
0218 #define VGAENABLE   0x43
0219 
0220 #define SISAR       SISUSB_PCI_IOPORTBASE + AROFFSET
0221 #define SISARR      SISUSB_PCI_IOPORTBASE + ARROFFSET
0222 #define SISGR       SISUSB_PCI_IOPORTBASE + GROFFSET
0223 #define SISSR       SISUSB_PCI_IOPORTBASE + SROFFSET
0224 #define SISCR       SISUSB_PCI_IOPORTBASE + CROFFSET
0225 #define SISMISCR    SISUSB_PCI_IOPORTBASE + MISCROFFSET
0226 #define SISMISCW    SISUSB_PCI_IOPORTBASE + MISCWOFFSET
0227 #define SISINPSTAT  SISUSB_PCI_IOPORTBASE + INPUTSTATOFFSET
0228 #define SISPART1    SISUSB_PCI_IOPORTBASE + PART1OFFSET
0229 #define SISPART2    SISUSB_PCI_IOPORTBASE + PART2OFFSET
0230 #define SISPART3    SISUSB_PCI_IOPORTBASE + PART3OFFSET
0231 #define SISPART4    SISUSB_PCI_IOPORTBASE + PART4OFFSET
0232 #define SISPART5    SISUSB_PCI_IOPORTBASE + PART5OFFSET
0233 #define SISCAP      SISUSB_PCI_IOPORTBASE + CAPTUREOFFSET
0234 #define SISVID      SISUSB_PCI_IOPORTBASE + VIDEOOFFSET
0235 #define SISCOLIDXR  SISUSB_PCI_IOPORTBASE + COLREGOFFSET - 1
0236 #define SISCOLIDX   SISUSB_PCI_IOPORTBASE + COLREGOFFSET
0237 #define SISCOLDATA  SISUSB_PCI_IOPORTBASE + COLREGOFFSET + 1
0238 #define SISCOL2IDX  SISPART5
0239 #define SISCOL2DATA SISPART5 + 1
0240 #define SISPEL      SISUSB_PCI_IOPORTBASE + PELMASKOFFSET
0241 #define SISVGAEN    SISUSB_PCI_IOPORTBASE + VGAENABLE
0242 #define SISDACA     SISCOLIDX
0243 #define SISDACD     SISCOLDATA
0244 
0245 /* ioctl related */
0246 
0247 /* Structure argument for SISUSB_GET_INFO ioctl  */
0248 struct sisusb_info {
0249     __u32 sisusb_id;    /* for identifying sisusb */
0250 #define SISUSB_ID  0x53495355   /* Identify myself with 'SISU' */
0251     __u8 sisusb_version;
0252     __u8 sisusb_revision;
0253     __u8 sisusb_patchlevel;
0254     __u8 sisusb_gfxinit;    /* graphics core initialized? */
0255 
0256     __u32 sisusb_vrambase;
0257     __u32 sisusb_mmiobase;
0258     __u32 sisusb_iobase;
0259     __u32 sisusb_pcibase;
0260 
0261     __u32 sisusb_vramsize;  /* framebuffer size in bytes */
0262 
0263     __u32 sisusb_minor;
0264 
0265     __u32 sisusb_fbdevactive;   /* != 0 if framebuffer device active */
0266 
0267     __u32 sisusb_conactive; /* != 0 if console driver active */
0268 
0269     __u8 sisusb_reserved[28];   /* for future use */
0270 };
0271 
0272 struct sisusb_command {
0273     __u8 operation;     /* see below */
0274     __u8 data0;     /* operation dependent */
0275     __u8 data1;     /* operation dependent */
0276     __u8 data2;     /* operation dependent */
0277     __u32 data3;        /* operation dependent */
0278     __u32 data4;        /* for future use */
0279 };
0280 
0281 #define SUCMD_GET   0x01    /* for all: data0 = index, data3 = port */
0282 #define SUCMD_SET   0x02    /* data1 = value */
0283 #define SUCMD_SETOR 0x03    /* data1 = or */
0284 #define SUCMD_SETAND    0x04    /* data1 = and */
0285 #define SUCMD_SETANDOR  0x05    /* data1 = and, data2 = or */
0286 #define SUCMD_SETMASK   0x06    /* data1 = data, data2 = mask */
0287 
0288 #define SUCMD_CLRSCR    0x07    /* data0:1:2 = length, data3 = address */
0289 
0290 #define SUCMD_HANDLETEXTMODE 0x08   /* Reset/destroy text mode */
0291 
0292 #define SUCMD_SETMODE   0x09    /* Set a display mode (data3 = SiS mode) */
0293 #define SUCMD_SETVESAMODE 0x0a  /* Set a display mode (data3 = VESA mode) */
0294 
0295 #define SISUSB_COMMAND      _IOWR(0xF3,0x3D,struct sisusb_command)
0296 #define SISUSB_GET_CONFIG_SIZE  _IOR(0xF3,0x3E,__u32)
0297 #define SISUSB_GET_CONFIG   _IOR(0xF3,0x3F,struct sisusb_info)
0298 
0299 #endif /* SISUSB_H */