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