2 * SiS 300/630/730/540/315/550/650/740 frame buffer driver
3 * for Linux kernels 2.4.x and 2.5.x
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the named License,
10 * or any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
21 * Based on the X driver's sis300_accel.h which is
22 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
23 * and sis310_accel.h which is
24 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
26 * Author: Thomas Winischhofer <thomas@winischhofer.net>:
27 * (see http://www.winischhofer.net/
28 * for more information and updates)
31 #ifndef _SISFB_ACCEL_H
32 #define _SISFB_ACCEL_H
34 /* Guard accelerator accesses with spin_lock_irqsave? Works well without. */
35 #undef SISFB_USE_SPINLOCKS
37 #ifdef SISFB_USE_SPINLOCKS
38 #include <linux/spinlock.h>
39 #define CRITBEGIN spin_lock_irqsave(&ivideo.lockaccel), critflags);
40 #define CRITEND spin_unlock_irqrestore(&ivideo.lockaccel), critflags);
41 #define CRITFLAGS unsigned long critflags;
48 /* Definitions for the SIS engine communication. */
50 #define PATREGSIZE 384 /* Pattern register size. 384 bytes @ 0x8300 */
51 #define BR(x) (0x8200 | (x) << 2)
52 #define PBR(x) (0x8300 | (x) << 2)
54 /* SiS300 engine commands */
55 #define BITBLT 0x00000000 /* Blit */
56 #define COLOREXP 0x00000001 /* Color expand */
57 #define ENCOLOREXP 0x00000002 /* Enhanced color expand */
58 #define MULTIPLE_SCANLINE 0x00000003 /* ? */
59 #define LINE 0x00000004 /* Draw line */
60 #define TRAPAZOID_FILL 0x00000005 /* Fill trapezoid */
61 #define TRANSPARENT_BITBLT 0x00000006 /* Transparent Blit */
63 /* Additional engine commands for 315 */
64 #define ALPHA_BLEND 0x00000007 /* Alpha blend ? */
65 #define A3D_FUNCTION 0x00000008 /* 3D command ? */
66 #define CLEAR_Z_BUFFER 0x00000009 /* ? */
67 #define GRADIENT_FILL 0x0000000A /* Gradient fill */
68 #define STRETCH_BITBLT 0x0000000B /* Stretched Blit */
71 #define SRCVIDEO 0x00000000 /* source is video RAM */
72 #define SRCSYSTEM 0x00000010 /* source is system memory */
73 #define SRCCPUBLITBUF SRCSYSTEM /* source is CPU-driven BitBuffer (for color expand) */
74 #define SRCAGP 0x00000020 /* source is AGP memory (?) */
77 #define PATFG 0x00000000 /* foreground color */
78 #define PATPATREG 0x00000040 /* pattern in pattern buffer (0x8300) */
79 #define PATMONO 0x00000080 /* mono pattern */
81 /* blitting direction (300 series only) */
82 #define X_INC 0x00010000
83 #define X_DEC 0x00000000
84 #define Y_INC 0x00020000
85 #define Y_DEC 0x00000000
88 #define NOCLIP 0x00000000
89 #define NOMERGECLIP 0x04000000
90 #define CLIPENABLE 0x00040000
91 #define CLIPWITHOUTMERGE 0x04040000
94 #define OPAQUE 0x00000000
95 #define TRANSPARENT 0x00100000
98 #define DSTAGP 0x02000000
99 #define DSTVIDEO 0x02000000
102 #define LINE_STYLE 0x00800000
103 #define NO_RESET_COUNTER 0x00400000
104 #define NO_LAST_PIXEL 0x00200000
106 /* Subfunctions for Color/Enhanced Color Expansion (315 only) */
107 #define COLOR_TO_MONO 0x00100000
108 #define AA_TEXT 0x00200000
110 /* Some general registers for 315 series */
111 #define SRC_ADDR 0x8200
112 #define SRC_PITCH 0x8204
113 #define AGP_BASE 0x8206 /* color-depth dependent value */
118 #define DST_ADDR 0x8210
119 #define DST_PITCH 0x8214
120 #define DST_HEIGHT 0x8216
121 #define RECT_WIDTH 0x8218
122 #define RECT_HEIGHT 0x821A
123 #define PAT_FGCOLOR 0x821C
124 #define PAT_BGCOLOR 0x8220
125 #define SRC_FGCOLOR 0x8224
126 #define SRC_BGCOLOR 0x8228
127 #define MONO_MASK 0x822C
128 #define LEFT_CLIP 0x8234
129 #define TOP_CLIP 0x8236
130 #define RIGHT_CLIP 0x8238
131 #define BOTTOM_CLIP 0x823A
132 #define COMMAND_READY 0x823C
133 #define FIRE_TRIGGER 0x8240
135 #define PATTERN_REG 0x8300 /* 384 bytes pattern buffer */
138 #define LINE_X0 SRC_Y
139 #define LINE_X1 DST_Y
140 #define LINE_Y0 SRC_X
141 #define LINE_Y1 DST_X
142 #define LINE_COUNT RECT_WIDTH
143 #define LINE_STYLE_PERIOD RECT_HEIGHT
144 #define LINE_STYLE_0 MONO_MASK
145 #define LINE_STYLE_1 0x8230
146 #define LINE_XN PATTERN_REG
147 #define LINE_YN PATTERN_REG+2
149 /* Transparent bitblit registers */
150 #define TRANS_DST_KEY_HIGH PAT_FGCOLOR
151 #define TRANS_DST_KEY_LOW PAT_BGCOLOR
152 #define TRANS_SRC_KEY_HIGH SRC_FGCOLOR
153 #define TRANS_SRC_KEY_LOW SRC_BGCOLOR
156 #define Q_BASE_ADDR 0x85C0 /* Base address of software queue (?) */
157 #define Q_WRITE_PTR 0x85C4 /* Current write pointer (?) */
158 #define Q_READ_PTR 0x85C8 /* Current read pointer (?) */
159 #define Q_STATUS 0x85CC /* queue status */
162 #define MMIO_IN8(base, offset) \
163 *(volatile u8 *)(((u8*)(base)) + (offset))
164 #define MMIO_IN16(base, offset) \
165 *(volatile u16 *)(void *)(((u8*)(base)) + (offset))
166 #define MMIO_IN32(base, offset) \
167 *(volatile u32 *)(void *)(((u8*)(base)) + (offset))
168 #define MMIO_OUT8(base, offset, val) \
169 *(volatile u8 *)(((u8*)(base)) + (offset)) = (val)
170 #define MMIO_OUT16(base, offset, val) \
171 *(volatile u16 *)(void *)(((u8*)(base)) + (offset)) = (val)
172 #define MMIO_OUT32(base, offset, val) \
173 *(volatile u32 *)(void *)(((u8*)(base)) + (offset)) = (val)
175 /* ------------- SiS 300 series -------------- */
177 /* Macros to do useful things with the SIS BitBLT engine */
181 bit 31 2D engine: 1 is idle,
182 bit 30 3D engine: 1 is idle,
183 bit 29 Command queue: 1 is empty
185 bits 28:24: Current CPU driven BitBlt buffer stage bit[4:0]
187 bits 15:0: Current command queue length
191 /* TW: BR(16)+2 = 0x8242 */
197 while( (MMIO_IN16(ivideo.mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){}; \
198 while( (MMIO_IN16(ivideo.mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){}; \
199 while( (MMIO_IN16(ivideo.mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){}; \
200 CmdQueLen=MMIO_IN16(ivideo.mmio_vbase, 0x8240); \
202 /* TW: (do three times, because 2D engine seems quite unsure about whether or not it's idle) */
204 #define SiS300SetupSRCBase(base) \
205 if (CmdQueLen <= 0) SiS300Idle;\
206 MMIO_OUT32(ivideo.mmio_vbase, BR(0), base);\
209 #define SiS300SetupSRCPitch(pitch) \
210 if (CmdQueLen <= 0) SiS300Idle;\
211 MMIO_OUT16(ivideo.mmio_vbase, BR(1), pitch);\
214 #define SiS300SetupSRCXY(x,y) \
215 if (CmdQueLen <= 0) SiS300Idle;\
216 MMIO_OUT32(ivideo.mmio_vbase, BR(2), (x)<<16 | (y) );\
219 #define SiS300SetupDSTBase(base) \
220 if (CmdQueLen <= 0) SiS300Idle;\
221 MMIO_OUT32(ivideo.mmio_vbase, BR(4), base);\
224 #define SiS300SetupDSTXY(x,y) \
225 if (CmdQueLen <= 0) SiS300Idle;\
226 MMIO_OUT32(ivideo.mmio_vbase, BR(3), (x)<<16 | (y) );\
229 #define SiS300SetupDSTRect(x,y) \
230 if (CmdQueLen <= 0) SiS300Idle;\
231 MMIO_OUT32(ivideo.mmio_vbase, BR(5), (y)<<16 | (x) );\
234 #define SiS300SetupDSTColorDepth(bpp) \
235 if (CmdQueLen <= 0) SiS300Idle;\
236 MMIO_OUT16(ivideo.mmio_vbase, BR(1)+2, bpp);\
239 #define SiS300SetupRect(w,h) \
240 if (CmdQueLen <= 0) SiS300Idle;\
241 MMIO_OUT32(ivideo.mmio_vbase, BR(6), (h)<<16 | (w) );\
244 #define SiS300SetupPATFG(color) \
245 if (CmdQueLen <= 0) SiS300Idle;\
246 MMIO_OUT32(ivideo.mmio_vbase, BR(7), color);\
249 #define SiS300SetupPATBG(color) \
250 if (CmdQueLen <= 0) SiS300Idle;\
251 MMIO_OUT32(ivideo.mmio_vbase, BR(8), color);\
254 #define SiS300SetupSRCFG(color) \
255 if (CmdQueLen <= 0) SiS300Idle;\
256 MMIO_OUT32(ivideo.mmio_vbase, BR(9), color);\
259 #define SiS300SetupSRCBG(color) \
260 if (CmdQueLen <= 0) SiS300Idle;\
261 MMIO_OUT32(ivideo.mmio_vbase, BR(10), color);\
264 /* 0x8224 src colorkey high */
265 /* 0x8228 src colorkey low */
266 /* 0x821c dest colorkey high */
267 /* 0x8220 dest colorkey low */
268 #define SiS300SetupSRCTrans(color) \
269 if (CmdQueLen <= 1) SiS300Idle;\
270 MMIO_OUT32(ivideo.mmio_vbase, 0x8224, color);\
271 MMIO_OUT32(ivideo.mmio_vbase, 0x8228, color);\
274 #define SiS300SetupDSTTrans(color) \
275 if (CmdQueLen <= 1) SiS300Idle;\
276 MMIO_OUT32(ivideo.mmio_vbase, 0x821C, color); \
277 MMIO_OUT32(ivideo.mmio_vbase, 0x8220, color); \
280 #define SiS300SetupMONOPAT(p0,p1) \
281 if (CmdQueLen <= 1) SiS300Idle;\
282 MMIO_OUT32(ivideo.mmio_vbase, BR(11), p0);\
283 MMIO_OUT32(ivideo.mmio_vbase, BR(12), p1);\
286 #define SiS300SetupClipLT(left,top) \
287 if (CmdQueLen <= 0) SiS300Idle;\
288 MMIO_OUT32(ivideo.mmio_vbase, BR(13), ((left) & 0xFFFF) | (top)<<16 );\
291 #define SiS300SetupClipRB(right,bottom) \
292 if (CmdQueLen <= 0) SiS300Idle;\
293 MMIO_OUT32(ivideo.mmio_vbase, BR(14), ((right) & 0xFFFF) | (bottom)<<16 );\
297 #define SiS300SetupROP(rop) \
298 ivideo.CommandReg = (rop) << 8;
300 #define SiS300SetupCMDFlag(flags) \
301 ivideo.CommandReg |= (flags);
303 #define SiS300DoCMD \
304 if (CmdQueLen <= 1) SiS300Idle;\
305 MMIO_OUT32(ivideo.mmio_vbase, BR(15), ivideo.CommandReg); \
306 MMIO_OUT32(ivideo.mmio_vbase, BR(16), 0);\
310 #define SiS300SetupX0Y0(x,y) \
311 if (CmdQueLen <= 0) SiS300Idle;\
312 MMIO_OUT32(ivideo.mmio_vbase, BR(2), (y)<<16 | (x) );\
315 #define SiS300SetupX1Y1(x,y) \
316 if (CmdQueLen <= 0) SiS300Idle;\
317 MMIO_OUT32(ivideo.mmio_vbase, BR(3), (y)<<16 | (x) );\
320 #define SiS300SetupLineCount(c) \
321 if (CmdQueLen <= 0) SiS300Idle;\
322 MMIO_OUT16(ivideo.mmio_vbase, BR(6), c);\
325 #define SiS300SetupStylePeriod(p) \
326 if (CmdQueLen <= 0) SiS300Idle;\
327 MMIO_OUT16(ivideo.mmio_vbase, BR(6)+2, p);\
330 #define SiS300SetupStyleLow(ls) \
331 if (CmdQueLen <= 0) SiS300Idle;\
332 MMIO_OUT32(ivideo.mmio_vbase, BR(11), ls);\
335 #define SiS300SetupStyleHigh(ls) \
336 if (CmdQueLen <= 0) SiS300Idle;\
337 MMIO_OUT32(ivideo.mmio_vbase, BR(12), ls);\
342 /* -------------- SiS 315 series --------------- */
345 bit 31 = 1: All engines idle and all queues empty
346 bit 30 = 1: Hardware Queue (=HW CQ, 2D queue, 3D queue) empty
347 bit 29 = 1: 2D engine is idle
348 bit 28 = 1: 3D engine is idle
349 bit 27 = 1: HW command queue empty
350 bit 26 = 1: 2D queue empty
351 bit 25 = 1: 3D queue empty
352 bit 24 = 1: SW command queue empty
353 bits 23:16: 2D counter 3
354 bits 15:8: 2D counter 2
355 bits 7:0: 2D counter 1
357 Where is the command queue length (current amount of commands the queue
358 can accept) on the 315 series?
361 /* TW: FIXME: CmdQueLen is... where....? */
362 /* We assume a length of 4 bytes per command; since 512K of
363 * of RAM are allocated, the number of commands is easily
364 * calculated (assuming that there is no 3D support yet)
365 * We calculate it very cautiously (128K only) and let the
366 * rest to the (never?)-to-come (?) 3D engine. (The 3D engine
367 * can use a similar technique, using the remaining 384K,
368 * hence a queue overflow is avoided)
369 * UPDATE: This technique causes a terrible system latency
370 * on integrated chipsets. Disable the queue handling for
375 while( (MMIO_IN16(ivideo.mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
376 while( (MMIO_IN16(ivideo.mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){}; \
378 /*CmdQueLen = ((128 * 1024) / 4) - 64; */ \
381 #define SiS310SetupSRCBase(base) \
382 if (CmdQueLen <= 0) SiS310Idle;\
383 MMIO_OUT32(ivideo.mmio_vbase, SRC_ADDR, base);\
386 #define SiS310SetupSRCPitch(pitch) \
387 if (CmdQueLen <= 0) SiS310Idle;\
388 MMIO_OUT16(ivideo.mmio_vbase, SRC_PITCH, pitch);\
391 #define SiS310SetupSRCXY(x,y) \
392 if (CmdQueLen <= 0) SiS310Idle;\
393 MMIO_OUT32(ivideo.mmio_vbase, SRC_Y, (x)<<16 | (y) );\
396 #define SiS310SetupDSTBase(base) \
397 if (CmdQueLen <= 0) SiS310Idle;\
398 MMIO_OUT32(ivideo.mmio_vbase, DST_ADDR, base);\
401 #define SiS310SetupDSTXY(x,y) \
402 if (CmdQueLen <= 0) SiS310Idle;\
403 MMIO_OUT32(ivideo.mmio_vbase, DST_Y, (x)<<16 | (y) );\
406 #define SiS310SetupDSTRect(x,y) \
407 if (CmdQueLen <= 0) SiS310Idle;\
408 MMIO_OUT32(ivideo.mmio_vbase, DST_PITCH, (y)<<16 | (x) );\
411 #define SiS310SetupDSTColorDepth(bpp) \
412 if (CmdQueLen <= 0) SiS310Idle;\
413 MMIO_OUT16(ivideo.mmio_vbase, AGP_BASE, bpp);\
416 #define SiS310SetupRect(w,h) \
417 if (CmdQueLen <= 0) SiS310Idle;\
418 MMIO_OUT32(ivideo.mmio_vbase, RECT_WIDTH, (h)<<16 | (w) );\
421 #define SiS310SetupPATFG(color) \
422 if (CmdQueLen <= 0) SiS310Idle;\
423 MMIO_OUT32(ivideo.mmio_vbase, PAT_FGCOLOR, color);\
426 #define SiS310SetupPATBG(color) \
427 if (CmdQueLen <= 0) SiS310Idle;\
428 MMIO_OUT32(ivideo.mmio_vbase, PAT_BGCOLOR, color);\
431 #define SiS310SetupSRCFG(color) \
432 if (CmdQueLen <= 0) SiS310Idle;\
433 MMIO_OUT32(ivideo.mmio_vbase, SRC_FGCOLOR, color);\
436 #define SiS310SetupSRCBG(color) \
437 if (CmdQueLen <= 0) SiS310Idle;\
438 MMIO_OUT32(ivideo.mmio_vbase, SRC_BGCOLOR, color);\
441 #define SiS310SetupSRCTrans(color) \
442 if (CmdQueLen <= 1) SiS310Idle;\
443 MMIO_OUT32(ivideo.mmio_vbase, TRANS_SRC_KEY_HIGH, color);\
444 MMIO_OUT32(ivideo.mmio_vbase, TRANS_SRC_KEY_LOW, color);\
447 #define SiS310SetupDSTTrans(color) \
448 if (CmdQueLen <= 1) SiS310Idle;\
449 MMIO_OUT32(ivideo.mmio_vbase, TRANS_DST_KEY_HIGH, color); \
450 MMIO_OUT32(ivideo.mmio_vbase, TRANS_DST_KEY_LOW, color); \
453 #define SiS310SetupMONOPAT(p0,p1) \
454 if (CmdQueLen <= 1) SiS310Idle;\
455 MMIO_OUT32(ivideo.mmio_vbase, MONO_MASK, p0);\
456 MMIO_OUT32(ivideo.mmio_vbase, MONO_MASK+4, p1);\
459 #define SiS310SetupClipLT(left,top) \
460 if (CmdQueLen <= 0) SiS310Idle;\
461 MMIO_OUT32(ivideo.mmio_vbase, LEFT_CLIP, ((left) & 0xFFFF) | (top)<<16 );\
464 #define SiS310SetupClipRB(right,bottom) \
465 if (CmdQueLen <= 0) SiS310Idle;\
466 MMIO_OUT32(ivideo.mmio_vbase, RIGHT_CLIP, ((right) & 0xFFFF) | (bottom)<<16 );\
469 #define SiS310SetupROP(rop) \
470 ivideo.CommandReg = (rop) << 8;
472 #define SiS310SetupCMDFlag(flags) \
473 ivideo.CommandReg |= (flags);
475 #define SiS310DoCMD \
476 if (CmdQueLen <= 1) SiS310Idle;\
477 MMIO_OUT32(ivideo.mmio_vbase, COMMAND_READY, ivideo.CommandReg); \
478 MMIO_OUT32(ivideo.mmio_vbase, FIRE_TRIGGER, 0); \
481 #define SiS310SetupX0Y0(x,y) \
482 if (CmdQueLen <= 0) SiS310Idle;\
483 MMIO_OUT32(ivideo.mmio_vbase, LINE_X0, (y)<<16 | (x) );\
486 #define SiS310SetupX1Y1(x,y) \
487 if (CmdQueLen <= 0) SiS310Idle;\
488 MMIO_OUT32(ivideo.mmio_vbase, LINE_X1, (y)<<16 | (x) );\
491 #define SiS310SetupLineCount(c) \
492 if (CmdQueLen <= 0) SiS310Idle;\
493 MMIO_OUT16(ivideo.mmio_vbase, LINE_COUNT, c);\
496 #define SiS310SetupStylePeriod(p) \
497 if (CmdQueLen <= 0) SiS310Idle;\
498 MMIO_OUT16(ivideo.mmio_vbase, LINE_STYLE_PERIOD, p);\
501 #define SiS310SetupStyleLow(ls) \
502 if (CmdQueLen <= 0) SiS310Idle;\
503 MMIO_OUT32(ivideo.mmio_vbase, LINE_STYLE_0, ls);\
506 #define SiS310SetupStyleHigh(ls) \
507 if (CmdQueLen <= 0) SiS310Idle;\
508 MMIO_OUT32(ivideo.mmio_vbase, LINE_STYLE_1, ls);\
511 int sisfb_initaccel(void);
512 void sisfb_syncaccel(void);
514 extern struct video_info ivideo;
516 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,33)
517 void fbcon_sis_bmove(struct display *p, int srcy, int srcx, int dsty,
518 int dstx, int height, int width);
519 void fbcon_sis_revc(struct display *p, int srcy, int srcx);
520 void fbcon_sis_clear8(struct vc_data *conp, struct display *p, int srcy,
521 int srcx, int height, int width);
522 void fbcon_sis_clear16(struct vc_data *conp, struct display *p, int srcy,
523 int srcx, int height, int width);
524 void fbcon_sis_clear32(struct vc_data *conp, struct display *p, int srcy,
525 int srcx, int height, int width);
527 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,34)
528 extern int sisfb_accel;
529 void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
530 void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area);