1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/fb.h>
21#include <linux/ioport.h>
22#include <linux/types.h>
23#include <asm/io.h>
24
25#include "sis.h"
26#include "sis_accel.h"
27
28static const u8 sisALUConv[] =
29{
30 0x00,
31 0x88,
32 0x44,
33 0xCC,
34 0x22,
35 0xAA,
36 0x66,
37 0xEE,
38 0x11,
39 0x99,
40 0x55,
41 0xDD,
42 0x33,
43 0xBB,
44 0x77,
45 0xFF,
46};
47
48static const u8 sisPatALUConv[] =
49{
50 0x00,
51 0xA0,
52 0x50,
53 0xF0,
54 0x0A,
55 0xAA,
56 0x5A,
57 0xFA,
58 0x05,
59 0xA5,
60 0x55,
61 0xF5,
62 0x0F,
63 0xAF,
64 0x5F,
65 0xFF,
66};
67
68static const int myrops[] = {
69 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
70};
71
72
73#ifdef CONFIG_FB_SIS_300
74static void
75SiS300Sync(struct sis_video_info *ivideo)
76{
77 SiS300Idle
78}
79
80static void
81SiS300SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int xdir, int ydir,
82 int rop, int trans_color)
83{
84 SiS300SetupDSTColorDepth(ivideo->DstColor);
85 SiS300SetupSRCPitch(ivideo->video_linelength)
86 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
87
88 if(trans_color != -1) {
89 SiS300SetupROP(0x0A)
90 SiS300SetupSRCTrans(trans_color)
91 SiS300SetupCMDFlag(TRANSPARENT_BITBLT)
92 } else {
93 SiS300SetupROP(sisALUConv[rop])
94 }
95 if(xdir > 0) {
96 SiS300SetupCMDFlag(X_INC)
97 }
98 if(ydir > 0) {
99 SiS300SetupCMDFlag(Y_INC)
100 }
101}
102
103static void
104SiS300SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x,
105 int src_y, int dst_x, int dst_y, int width, int height)
106{
107 u32 srcbase = 0, dstbase = 0;
108
109 if(src_y >= 2048) {
110 srcbase = ivideo->video_linelength * src_y;
111 src_y = 0;
112 }
113 if(dst_y >= 2048) {
114 dstbase = ivideo->video_linelength * dst_y;
115 dst_y = 0;
116 }
117
118 SiS300SetupSRCBase(srcbase);
119 SiS300SetupDSTBase(dstbase);
120
121 if(!(ivideo->CommandReg & X_INC)) {
122 src_x += width-1;
123 dst_x += width-1;
124 }
125 if(!(ivideo->CommandReg & Y_INC)) {
126 src_y += height-1;
127 dst_y += height-1;
128 }
129 SiS300SetupRect(width, height)
130 SiS300SetupSRCXY(src_x, src_y)
131 SiS300SetupDSTXY(dst_x, dst_y)
132 SiS300DoCMD
133}
134
135static void
136SiS300SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
137{
138 SiS300SetupPATFG(color)
139 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
140 SiS300SetupDSTColorDepth(ivideo->DstColor);
141 SiS300SetupROP(sisPatALUConv[rop])
142 SiS300SetupCMDFlag(PATFG)
143}
144
145static void
146SiS300SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
147{
148 u32 dstbase = 0;
149
150 if(y >= 2048) {
151 dstbase = ivideo->video_linelength * y;
152 y = 0;
153 }
154 SiS300SetupDSTBase(dstbase)
155 SiS300SetupDSTXY(x,y)
156 SiS300SetupRect(w,h)
157 SiS300SetupCMDFlag(X_INC | Y_INC | BITBLT)
158 SiS300DoCMD
159}
160#endif
161
162
163
164#ifdef CONFIG_FB_SIS_315
165static void
166SiS310Sync(struct sis_video_info *ivideo)
167{
168 SiS310Idle
169}
170
171static void
172SiS310SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int rop, int trans_color)
173{
174 SiS310SetupDSTColorDepth(ivideo->DstColor);
175 SiS310SetupSRCPitch(ivideo->video_linelength)
176 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
177 if(trans_color != -1) {
178 SiS310SetupROP(0x0A)
179 SiS310SetupSRCTrans(trans_color)
180 SiS310SetupCMDFlag(TRANSPARENT_BITBLT)
181 } else {
182 SiS310SetupROP(sisALUConv[rop])
183
184
185 }
186 SiS310SetupCMDFlag(ivideo->SiS310_AccelDepth)
187
188}
189
190static void
191SiS310SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x, int src_y,
192 int dst_x, int dst_y, int width, int height)
193{
194 u32 srcbase = 0, dstbase = 0;
195 int mymin = min(src_y, dst_y);
196 int mymax = max(src_y, dst_y);
197
198
199
200
201
202
203
204
205
206
207
208 if((mymax - mymin) < height) {
209 if((src_y >= 2048) || (dst_y >= 2048)) {
210 srcbase = ivideo->video_linelength * mymin;
211 dstbase = ivideo->video_linelength * mymin;
212 src_y -= mymin;
213 dst_y -= mymin;
214 }
215 } else {
216 if(src_y >= 2048) {
217 srcbase = ivideo->video_linelength * src_y;
218 src_y = 0;
219 }
220 if(dst_y >= 2048) {
221 dstbase = ivideo->video_linelength * dst_y;
222 dst_y = 0;
223 }
224 }
225
226 srcbase += ivideo->video_offset;
227 dstbase += ivideo->video_offset;
228
229 SiS310SetupSRCBase(srcbase);
230 SiS310SetupDSTBase(dstbase);
231 SiS310SetupRect(width, height)
232 SiS310SetupSRCXY(src_x, src_y)
233 SiS310SetupDSTXY(dst_x, dst_y)
234 SiS310DoCMD
235}
236
237static void
238SiS310SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
239{
240 SiS310SetupPATFG(color)
241 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
242 SiS310SetupDSTColorDepth(ivideo->DstColor);
243 SiS310SetupROP(sisPatALUConv[rop])
244 SiS310SetupCMDFlag(PATFG | ivideo->SiS310_AccelDepth)
245}
246
247static void
248SiS310SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
249{
250 u32 dstbase = 0;
251
252 if(y >= 2048) {
253 dstbase = ivideo->video_linelength * y;
254 y = 0;
255 }
256 dstbase += ivideo->video_offset;
257 SiS310SetupDSTBase(dstbase)
258 SiS310SetupDSTXY(x,y)
259 SiS310SetupRect(w,h)
260 SiS310SetupCMDFlag(BITBLT)
261 SiS310DoCMD
262}
263#endif
264
265
266
267
268
269int sisfb_initaccel(struct sis_video_info *ivideo)
270{
271#ifdef SISFB_USE_SPINLOCKS
272 spin_lock_init(&ivideo->lockaccel);
273#endif
274 return 0;
275}
276
277void sisfb_syncaccel(struct sis_video_info *ivideo)
278{
279 if(ivideo->sisvga_engine == SIS_300_VGA) {
280#ifdef CONFIG_FB_SIS_300
281 SiS300Sync(ivideo);
282#endif
283 } else {
284#ifdef CONFIG_FB_SIS_315
285 SiS310Sync(ivideo);
286#endif
287 }
288}
289
290int fbcon_sis_sync(struct fb_info *info)
291{
292 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
293 CRITFLAGS
294
295 if((!ivideo->accel) || (!ivideo->engineok))
296 return 0;
297
298 CRITBEGIN
299 sisfb_syncaccel(ivideo);
300 CRITEND
301
302 return 0;
303}
304
305void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
306{
307 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
308 u32 col = 0;
309 u32 vxres = info->var.xres_virtual;
310 u32 vyres = info->var.yres_virtual;
311 int width, height;
312 CRITFLAGS
313
314 if(info->state != FBINFO_STATE_RUNNING)
315 return;
316
317 if((!ivideo->accel) || (!ivideo->engineok)) {
318 cfb_fillrect(info, rect);
319 return;
320 }
321
322 if(!rect->width || !rect->height || rect->dx >= vxres || rect->dy >= vyres)
323 return;
324
325
326 width = ((rect->dx + rect->width) > vxres) ? (vxres - rect->dx) : rect->width;
327 height = ((rect->dy + rect->height) > vyres) ? (vyres - rect->dy) : rect->height;
328
329 switch(info->var.bits_per_pixel) {
330 case 8: col = rect->color;
331 break;
332 case 16:
333 case 32: col = ((u32 *)(info->pseudo_palette))[rect->color];
334 break;
335 }
336
337 if(ivideo->sisvga_engine == SIS_300_VGA) {
338#ifdef CONFIG_FB_SIS_300
339 CRITBEGIN
340 SiS300SetupForSolidFill(ivideo, col, myrops[rect->rop]);
341 SiS300SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
342 CRITEND
343#endif
344 } else {
345#ifdef CONFIG_FB_SIS_315
346 CRITBEGIN
347 SiS310SetupForSolidFill(ivideo, col, myrops[rect->rop]);
348 SiS310SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
349 CRITEND
350#endif
351 }
352
353 sisfb_syncaccel(ivideo);
354}
355
356void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area)
357{
358 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
359 u32 vxres = info->var.xres_virtual;
360 u32 vyres = info->var.yres_virtual;
361 int width = area->width;
362 int height = area->height;
363 CRITFLAGS
364
365 if(info->state != FBINFO_STATE_RUNNING)
366 return;
367
368 if((!ivideo->accel) || (!ivideo->engineok)) {
369 cfb_copyarea(info, area);
370 return;
371 }
372
373 if(!width || !height ||
374 area->sx >= vxres || area->sy >= vyres ||
375 area->dx >= vxres || area->dy >= vyres)
376 return;
377
378
379 if((area->sx + width) > vxres) width = vxres - area->sx;
380 if((area->dx + width) > vxres) width = vxres - area->dx;
381 if((area->sy + height) > vyres) height = vyres - area->sy;
382 if((area->dy + height) > vyres) height = vyres - area->dy;
383
384 if(ivideo->sisvga_engine == SIS_300_VGA) {
385#ifdef CONFIG_FB_SIS_300
386 int xdir, ydir;
387
388 if(area->sx < area->dx) xdir = 0;
389 else xdir = 1;
390 if(area->sy < area->dy) ydir = 0;
391 else ydir = 1;
392
393 CRITBEGIN
394 SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
395 SiS300SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
396 area->dx, area->dy, width, height);
397 CRITEND
398#endif
399 } else {
400#ifdef CONFIG_FB_SIS_315
401 CRITBEGIN
402 SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
403 SiS310SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
404 area->dx, area->dy, width, height);
405 CRITEND
406#endif
407 }
408
409 sisfb_syncaccel(ivideo);
410}
411