i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / video / i810 / i810_accel.c
blob7672d2ea9b357309e5c4f0ffd96ca1eeaf69b63d
1 /*-*- linux-c -*-
2 * linux/drivers/video/i810_accel.c -- Hardware Acceleration
4 * Copyright (C) 2001 Antonino Daplas<adaplas@pol.net>
5 * All Rights Reserved
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
11 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/fb.h>
15 #include "i810_regs.h"
16 #include "i810.h"
17 #include "i810_main.h"
19 static u32 i810fb_rop[] = {
20 COLOR_COPY_ROP, /* ROP_COPY */
21 XOR_ROP /* ROP_XOR */
24 /* Macros */
25 #define PUT_RING(n) { \
26 i810_writel(par->cur_tail, par->iring.virtual, n); \
27 par->cur_tail += 4; \
28 par->cur_tail &= RING_SIZE_MASK; \
31 extern void flush_cache(void);
33 /************************************************************/
35 /* BLT Engine Routines */
36 static inline void i810_report_error(u8 __iomem *mmio)
38 printk("IIR : 0x%04x\n"
39 "EIR : 0x%04x\n"
40 "PGTBL_ER: 0x%04x\n"
41 "IPEIR : 0x%04x\n"
42 "IPEHR : 0x%04x\n",
43 i810_readw(IIR, mmio),
44 i810_readb(EIR, mmio),
45 i810_readl(PGTBL_ER, mmio),
46 i810_readl(IPEIR, mmio),
47 i810_readl(IPEHR, mmio));
50 /**
51 * wait_for_space - check ring buffer free space
52 * @space: amount of ringbuffer space needed in bytes
53 * @par: pointer to i810fb_par structure
55 * DESCRIPTION:
56 * The function waits until a free space from the ringbuffer
57 * is available
58 */
59 static inline int wait_for_space(struct fb_info *info, u32 space)
61 struct i810fb_par *par = info->par;
62 u32 head, count = WAIT_COUNT, tail;
63 u8 __iomem *mmio = par->mmio_start_virtual;
65 tail = par->cur_tail;
66 while (count--) {
67 head = i810_readl(IRING + 4, mmio) & RBUFFER_HEAD_MASK;
68 if ((tail == head) ||
69 (tail > head &&
70 (par->iring.size - tail + head) >= space) ||
71 (tail < head && (head - tail) >= space)) {
72 return 0;
75 printk("ringbuffer lockup!!!\n");
76 i810_report_error(mmio);
77 par->dev_flags |= LOCKUP;
78 info->pixmap.scan_align = 1;
79 return 1;
82 /**
83 * wait_for_engine_idle - waits for all hardware engines to finish
84 * @par: pointer to i810fb_par structure
86 * DESCRIPTION:
87 * This waits for lring(0), iring(1), and batch(3), etc to finish and
88 * waits until ringbuffer is empty.
90 static inline int wait_for_engine_idle(struct fb_info *info)
92 struct i810fb_par *par = info->par;
93 u8 __iomem *mmio = par->mmio_start_virtual;
94 int count = WAIT_COUNT;
96 if (wait_for_space(info, par->iring.size)) /* flush */
97 return 1;
99 while((i810_readw(INSTDONE, mmio) & 0x7B) != 0x7B && --count);
100 if (count) return 0;
102 printk("accel engine lockup!!!\n");
103 printk("INSTDONE: 0x%04x\n", i810_readl(INSTDONE, mmio));
104 i810_report_error(mmio);
105 par->dev_flags |= LOCKUP;
106 info->pixmap.scan_align = 1;
107 return 1;
110 /* begin_iring - prepares the ringbuffer
111 * @space: length of sequence in dwords
112 * @par: pointer to i810fb_par structure
114 * DESCRIPTION:
115 * Checks/waits for sufficient space in ringbuffer of size
116 * space. Returns the tail of the buffer
118 static inline u32 begin_iring(struct fb_info *info, u32 space)
120 struct i810fb_par *par = info->par;
122 if (par->dev_flags & ALWAYS_SYNC)
123 wait_for_engine_idle(info);
124 return wait_for_space(info, space);
128 * end_iring - advances the buffer
129 * @par: pointer to i810fb_par structure
131 * DESCRIPTION:
132 * This advances the tail of the ringbuffer, effectively
133 * beginning the execution of the graphics instruction sequence.
135 static inline void end_iring(struct i810fb_par *par)
137 u8 __iomem *mmio = par->mmio_start_virtual;
139 i810_writel(IRING, mmio, par->cur_tail);
143 * source_copy_blit - BLIT transfer operation
144 * @dwidth: width of rectangular graphics data
145 * @dheight: height of rectangular graphics data
146 * @dpitch: bytes per line of destination buffer
147 * @xdir: direction of copy (left to right or right to left)
148 * @src: address of first pixel to read from
149 * @dest: address of first pixel to write to
150 * @from: source address
151 * @where: destination address
152 * @rop: raster operation
153 * @blit_bpp: pixel format which can be different from the
154 * framebuffer's pixelformat
155 * @par: pointer to i810fb_par structure
157 * DESCRIPTION:
158 * This is a BLIT operation typically used when doing
159 * a 'Copy and Paste'
161 static inline void source_copy_blit(int dwidth, int dheight, int dpitch,
162 int xdir, int src, int dest, int rop,
163 int blit_bpp, struct fb_info *info)
165 struct i810fb_par *par = info->par;
167 if (begin_iring(info, 24 + IRING_PAD)) return;
169 PUT_RING(BLIT | SOURCE_COPY_BLIT | 4);
170 PUT_RING(xdir | rop << 16 | dpitch | DYN_COLOR_EN | blit_bpp);
171 PUT_RING(dheight << 16 | dwidth);
172 PUT_RING(dest);
173 PUT_RING(dpitch);
174 PUT_RING(src);
176 end_iring(par);
180 * color_blit - solid color BLIT operation
181 * @width: width of destination
182 * @height: height of destination
183 * @pitch: pixels per line of the buffer
184 * @dest: address of first pixel to write to
185 * @where: destination
186 * @rop: raster operation
187 * @what: color to transfer
188 * @blit_bpp: pixel format which can be different from the
189 * framebuffer's pixelformat
190 * @par: pointer to i810fb_par structure
192 * DESCRIPTION:
193 * A BLIT operation which can be used for color fill/rectangular fill
195 static inline void color_blit(int width, int height, int pitch, int dest,
196 int rop, int what, int blit_bpp,
197 struct fb_info *info)
199 struct i810fb_par *par = info->par;
201 if (begin_iring(info, 24 + IRING_PAD)) return;
203 PUT_RING(BLIT | COLOR_BLT | 3);
204 PUT_RING(rop << 16 | pitch | SOLIDPATTERN | DYN_COLOR_EN | blit_bpp);
205 PUT_RING(height << 16 | width);
206 PUT_RING(dest);
207 PUT_RING(what);
208 PUT_RING(NOP);
210 end_iring(par);
214 * mono_src_copy_imm_blit - color expand from system memory to framebuffer
215 * @dwidth: width of destination
216 * @dheight: height of destination
217 * @dpitch: pixels per line of the buffer
218 * @dsize: size of bitmap in double words
219 * @dest: address of first byte of pixel;
220 * @rop: raster operation
221 * @blit_bpp: pixelformat to use which can be different from the
222 * framebuffer's pixelformat
223 * @src: address of image data
224 * @bg: backgound color
225 * @fg: forground color
226 * @par: pointer to i810fb_par structure
228 * DESCRIPTION:
229 * A color expand operation where the source data is placed in the
230 * ringbuffer itself. Useful for drawing text.
232 * REQUIREMENT:
233 * The end of a scanline must be padded to the next word.
235 static inline void mono_src_copy_imm_blit(int dwidth, int dheight, int dpitch,
236 int dsize, int blit_bpp, int rop,
237 int dest, const u32 *src, int bg,
238 int fg, struct fb_info *info)
240 struct i810fb_par *par = info->par;
242 if (begin_iring(info, 24 + (dsize << 2) + IRING_PAD)) return;
244 PUT_RING(BLIT | MONO_SOURCE_COPY_IMMEDIATE | (4 + dsize));
245 PUT_RING(DYN_COLOR_EN | blit_bpp | rop << 16 | dpitch);
246 PUT_RING(dheight << 16 | dwidth);
247 PUT_RING(dest);
248 PUT_RING(bg);
249 PUT_RING(fg);
250 while (dsize--)
251 PUT_RING(*src++);
253 end_iring(par);
256 static inline void load_front(int offset, struct fb_info *info)
258 struct i810fb_par *par = info->par;
260 if (begin_iring(info, 8 + IRING_PAD)) return;
262 PUT_RING(PARSER | FLUSH);
263 PUT_RING(NOP);
265 end_iring(par);
267 if (begin_iring(info, 8 + IRING_PAD)) return;
269 PUT_RING(PARSER | FRONT_BUFFER | ((par->pitch >> 3) << 8));
270 PUT_RING((par->fb.offset << 12) + offset);
272 end_iring(par);
276 * i810fb_iring_enable - enables/disables the ringbuffer
277 * @mode: enable or disable
278 * @par: pointer to i810fb_par structure
280 * DESCRIPTION:
281 * Enables or disables the ringbuffer, effectively enabling or
282 * disabling the instruction/acceleration engine.
284 static inline void i810fb_iring_enable(struct i810fb_par *par, u32 mode)
286 u32 tmp;
287 u8 __iomem *mmio = par->mmio_start_virtual;
289 tmp = i810_readl(IRING + 12, mmio);
290 if (mode == OFF)
291 tmp &= ~1;
292 else
293 tmp |= 1;
294 flush_cache();
295 i810_writel(IRING + 12, mmio, tmp);
298 void i810fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
300 struct i810fb_par *par = info->par;
301 u32 dx, dy, width, height, dest, rop = 0, color = 0;
303 if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
304 par->depth == 4) {
305 cfb_fillrect(info, rect);
306 return;
309 if (par->depth == 1)
310 color = rect->color;
311 else
312 color = ((u32 *) (info->pseudo_palette))[rect->color];
314 rop = i810fb_rop[rect->rop];
316 dx = rect->dx * par->depth;
317 width = rect->width * par->depth;
318 dy = rect->dy;
319 height = rect->height;
321 dest = info->fix.smem_start + (dy * info->fix.line_length) + dx;
322 color_blit(width, height, info->fix.line_length, dest, rop, color,
323 par->blit_bpp, info);
326 void i810fb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
328 struct i810fb_par *par = info->par;
329 u32 sx, sy, dx, dy, pitch, width, height, src, dest, xdir;
331 if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
332 par->depth == 4) {
333 cfb_copyarea(info, region);
334 return;
337 dx = region->dx * par->depth;
338 sx = region->sx * par->depth;
339 width = region->width * par->depth;
340 sy = region->sy;
341 dy = region->dy;
342 height = region->height;
344 if (dx <= sx) {
345 xdir = INCREMENT;
347 else {
348 xdir = DECREMENT;
349 sx += width - 1;
350 dx += width - 1;
352 if (dy <= sy) {
353 pitch = info->fix.line_length;
355 else {
356 pitch = (-(info->fix.line_length)) & 0xFFFF;
357 sy += height - 1;
358 dy += height - 1;
360 src = info->fix.smem_start + (sy * info->fix.line_length) + sx;
361 dest = info->fix.smem_start + (dy * info->fix.line_length) + dx;
363 source_copy_blit(width, height, pitch, xdir, src, dest,
364 PAT_COPY_ROP, par->blit_bpp, info);
367 void i810fb_imageblit(struct fb_info *info, const struct fb_image *image)
369 struct i810fb_par *par = info->par;
370 u32 fg = 0, bg = 0, size, dst;
372 if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
373 par->depth == 4 || image->depth != 1) {
374 cfb_imageblit(info, image);
375 return;
378 switch (info->var.bits_per_pixel) {
379 case 8:
380 fg = image->fg_color;
381 bg = image->bg_color;
382 break;
383 case 16:
384 case 24:
385 fg = ((u32 *)(info->pseudo_palette))[image->fg_color];
386 bg = ((u32 *)(info->pseudo_palette))[image->bg_color];
387 break;
390 dst = info->fix.smem_start + (image->dy * info->fix.line_length) +
391 (image->dx * par->depth);
393 size = (image->width+7)/8 + 1;
394 size &= ~1;
395 size *= image->height;
396 size += 7;
397 size &= ~7;
398 mono_src_copy_imm_blit(image->width * par->depth,
399 image->height, info->fix.line_length,
400 size/4, par->blit_bpp,
401 PAT_COPY_ROP, dst, (u32 *) image->data,
402 bg, fg, info);
405 int i810fb_sync(struct fb_info *info)
407 struct i810fb_par *par = info->par;
409 if (!info->var.accel_flags || par->dev_flags & LOCKUP)
410 return 0;
412 return wait_for_engine_idle(info);
415 void i810fb_load_front(u32 offset, struct fb_info *info)
417 struct i810fb_par *par = info->par;
418 u8 __iomem *mmio = par->mmio_start_virtual;
420 if (!info->var.accel_flags || par->dev_flags & LOCKUP)
421 i810_writel(DPLYBASE, mmio, par->fb.physical + offset);
422 else
423 load_front(offset, info);
427 * i810fb_init_ringbuffer - initialize the ringbuffer
428 * @par: pointer to i810fb_par structure
430 * DESCRIPTION:
431 * Initializes the ringbuffer by telling the device the
432 * size and location of the ringbuffer. It also sets
433 * the head and tail pointers = 0
435 void i810fb_init_ringbuffer(struct fb_info *info)
437 struct i810fb_par *par = info->par;
438 u32 tmp1, tmp2;
439 u8 __iomem *mmio = par->mmio_start_virtual;
441 wait_for_engine_idle(info);
442 i810fb_iring_enable(par, OFF);
443 i810_writel(IRING, mmio, 0);
444 i810_writel(IRING + 4, mmio, 0);
445 par->cur_tail = 0;
447 tmp2 = i810_readl(IRING + 8, mmio) & ~RBUFFER_START_MASK;
448 tmp1 = par->iring.physical;
449 i810_writel(IRING + 8, mmio, tmp2 | tmp1);
451 tmp1 = i810_readl(IRING + 12, mmio);
452 tmp1 &= ~RBUFFER_SIZE_MASK;
453 tmp2 = (par->iring.size - I810_PAGESIZE) & RBUFFER_SIZE_MASK;
454 i810_writel(IRING + 12, mmio, tmp1 | tmp2);
455 i810fb_iring_enable(par, ON);