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