2 * linux/drivers/video/i810_accel.c -- Hardware Acceleration
4 * Copyright (C) 2001 Antonino Daplas<adaplas@pol.net>
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
11 #include <linux/kernel.h>
12 #include <linux/string.h>
15 #include "i810_regs.h"
18 static u32 i810fb_rop[] = {
19 COLOR_COPY_ROP, /* ROP_COPY */
24 #define PUT_RING(n) { \
25 i810_writel(par->cur_tail, par->iring.virtual, n); \
27 par->cur_tail &= RING_SIZE_MASK; \
30 extern void flush_cache(void);
32 /************************************************************/
34 /* BLT Engine Routines */
35 static inline void i810_report_error(u8 __iomem *mmio)
37 printk("IIR : 0x%04x\n"
42 i810_readw(IIR, mmio),
43 i810_readb(EIR, mmio),
44 i810_readl(PGTBL_ER, mmio),
45 i810_readl(IPEIR, mmio),
46 i810_readl(IPEHR, mmio));
50 * wait_for_space - check ring buffer free space
51 * @space: amount of ringbuffer space needed in bytes
52 * @par: pointer to i810fb_par structure
55 * The function waits until a free space from the ringbuffer
58 static inline int wait_for_space(struct fb_info *info, u32 space)
60 struct i810fb_par *par = (struct i810fb_par *) info->par;
61 u32 head, count = WAIT_COUNT, tail;
62 u8 __iomem *mmio = par->mmio_start_virtual;
66 head = i810_readl(IRING + 4, mmio) & RBUFFER_HEAD_MASK;
69 (par->iring.size - tail + head) >= space) ||
70 (tail < head && (head - tail) >= space)) {
74 printk("ringbuffer lockup!!!\n");
75 i810_report_error(mmio);
76 par->dev_flags |= LOCKUP;
77 info->pixmap.scan_align = 1;
82 * wait_for_engine_idle - waits for all hardware engines to finish
83 * @par: pointer to i810fb_par structure
86 * This waits for lring(0), iring(1), and batch(3), etc to finish and
87 * waits until ringbuffer is empty.
89 static inline int wait_for_engine_idle(struct fb_info *info)
91 struct i810fb_par *par = (struct i810fb_par *) info->par;
92 u8 __iomem *mmio = par->mmio_start_virtual;
93 int count = WAIT_COUNT;
95 if (wait_for_space(info, par->iring.size)) /* flush */
98 while((i810_readw(INSTDONE, mmio) & 0x7B) != 0x7B && --count);
101 printk("accel engine lockup!!!\n");
102 printk("INSTDONE: 0x%04x\n", i810_readl(INSTDONE, mmio));
103 i810_report_error(mmio);
104 par->dev_flags |= LOCKUP;
105 info->pixmap.scan_align = 1;
109 /* begin_iring - prepares the ringbuffer
110 * @space: length of sequence in dwords
111 * @par: pointer to i810fb_par structure
114 * Checks/waits for sufficent space in ringbuffer of size
115 * space. Returns the tail of the buffer
117 static inline u32 begin_iring(struct fb_info *info, u32 space)
119 struct i810fb_par *par = (struct i810fb_par *) info->par;
121 if (par->dev_flags & ALWAYS_SYNC)
122 wait_for_engine_idle(info);
123 return wait_for_space(info, space);
127 * end_iring - advances the buffer
128 * @par: pointer to i810fb_par structure
131 * This advances the tail of the ringbuffer, effectively
132 * beginning the execution of the graphics instruction sequence.
134 static inline void end_iring(struct i810fb_par *par)
136 u8 __iomem *mmio = par->mmio_start_virtual;
138 i810_writel(IRING, mmio, par->cur_tail);
142 * source_copy_blit - BLIT transfer operation
143 * @dwidth: width of rectangular graphics data
144 * @dheight: height of rectangular graphics data
145 * @dpitch: bytes per line of destination buffer
146 * @xdir: direction of copy (left to right or right to left)
147 * @src: address of first pixel to read from
148 * @dest: address of first pixel to write to
149 * @from: source address
150 * @where: destination address
151 * @rop: raster operation
152 * @blit_bpp: pixel format which can be different from the
153 * framebuffer's pixelformat
154 * @par: pointer to i810fb_par structure
157 * This is a BLIT operation typically used when doing
160 static inline void source_copy_blit(int dwidth, int dheight, int dpitch,
161 int xdir, int src, int dest, int rop,
162 int blit_bpp, struct fb_info *info)
164 struct i810fb_par *par = (struct i810fb_par *) info->par;
166 if (begin_iring(info, 24 + IRING_PAD)) return;
168 PUT_RING(BLIT | SOURCE_COPY_BLIT | 4);
169 PUT_RING(xdir | rop << 16 | dpitch | DYN_COLOR_EN | blit_bpp);
170 PUT_RING(dheight << 16 | dwidth);
179 * color_blit - solid color BLIT operation
180 * @width: width of destination
181 * @height: height of destination
182 * @pitch: pixels per line of the buffer
183 * @dest: address of first pixel to write to
184 * @where: destination
185 * @rop: raster operation
186 * @what: color to transfer
187 * @blit_bpp: pixel format which can be different from the
188 * framebuffer's pixelformat
189 * @par: pointer to i810fb_par structure
192 * A BLIT operation which can be used for color fill/rectangular fill
194 static inline void color_blit(int width, int height, int pitch, int dest,
195 int rop, int what, int blit_bpp,
196 struct fb_info *info)
198 struct i810fb_par *par = (struct i810fb_par *) info->par;
200 if (begin_iring(info, 24 + IRING_PAD)) return;
202 PUT_RING(BLIT | COLOR_BLT | 3);
203 PUT_RING(rop << 16 | pitch | SOLIDPATTERN | DYN_COLOR_EN | blit_bpp);
204 PUT_RING(height << 16 | width);
213 * mono_src_copy_imm_blit - color expand from system memory to framebuffer
214 * @dwidth: width of destination
215 * @dheight: height of destination
216 * @dpitch: pixels per line of the buffer
217 * @dsize: size of bitmap in double words
218 * @dest: address of first byte of pixel;
219 * @rop: raster operation
220 * @blit_bpp: pixelformat to use which can be different from the
221 * framebuffer's pixelformat
222 * @src: address of image data
223 * @bg: backgound color
224 * @fg: forground color
225 * @par: pointer to i810fb_par structure
228 * A color expand operation where the source data is placed in the
229 * ringbuffer itself. Useful for drawing text.
232 * The end of a scanline must be padded to the next word.
234 static inline void mono_src_copy_imm_blit(int dwidth, int dheight, int dpitch,
235 int dsize, int blit_bpp, int rop,
236 int dest, const u32 *src, int bg,
237 int fg, struct fb_info *info)
239 struct i810fb_par *par = (struct i810fb_par *) info->par;
241 if (begin_iring(info, 24 + (dsize << 2) + IRING_PAD)) return;
243 PUT_RING(BLIT | MONO_SOURCE_COPY_IMMEDIATE | (4 + dsize));
244 PUT_RING(DYN_COLOR_EN | blit_bpp | rop << 16 | dpitch);
245 PUT_RING(dheight << 16 | dwidth);
256 * mono_src_copy_blit - color expand from video memory to framebuffer
257 * @dwidth: width of destination
258 * @dheight: height of destination
259 * @dpitch: pixels per line of the buffer
260 * @qsize: size of bitmap in quad words
261 * @dest: address of first byte of pixel;
262 * @rop: raster operation
263 * @blit_bpp: pixelformat to use which can be different from the
264 * framebuffer's pixelformat
265 * @src: address of image data
266 * @bg: backgound color
267 * @fg: forground color
268 * @par: pointer to i810fb_par structure
271 * A color expand operation where the source data is in video memory.
272 * Useful for drawing text.
275 * The end of a scanline must be padded to the next word.
277 static inline void mono_src_copy_blit(int dwidth, int dheight, int dpitch,
278 int qsize, int blit_bpp, int rop,
279 int dest, int src, int bg,
280 int fg, struct fb_info *info)
282 struct i810fb_par *par = (struct i810fb_par *) info->par;
284 if (begin_iring(info, 32 + IRING_PAD)) return;
286 PUT_RING(BLIT | MONO_SOURCE_COPY_BLIT | 6);
287 PUT_RING(DYN_COLOR_EN | blit_bpp | rop << 16 | dpitch | 1 << 27);
288 PUT_RING(dheight << 16 | dwidth);
298 static inline void load_front(int offset, struct fb_info *info)
300 struct i810fb_par *par = (struct i810fb_par *) info->par;
302 if (begin_iring(info, 8 + IRING_PAD)) return;
304 PUT_RING(PARSER | FLUSH);
309 if (begin_iring(info, 8 + IRING_PAD)) return;
311 PUT_RING(PARSER | FRONT_BUFFER | ((par->pitch >> 3) << 8));
312 PUT_RING((par->fb.offset << 12) + offset);
318 * i810fb_iring_enable - enables/disables the ringbuffer
319 * @mode: enable or disable
320 * @par: pointer to i810fb_par structure
323 * Enables or disables the ringbuffer, effectively enabling or
324 * disabling the instruction/acceleration engine.
326 static inline void i810fb_iring_enable(struct i810fb_par *par, u32 mode)
329 u8 __iomem *mmio = par->mmio_start_virtual;
331 tmp = i810_readl(IRING + 12, mmio);
337 i810_writel(IRING + 12, mmio, tmp);
340 void i810fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
342 struct i810fb_par *par = (struct i810fb_par *) info->par;
343 u32 dx, dy, width, height, dest, rop = 0, color = 0;
345 if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
347 return cfb_fillrect(info, rect);
352 color = ((u32 *) (info->pseudo_palette))[rect->color];
354 rop = i810fb_rop[rect->rop];
356 dx = rect->dx * par->depth;
357 width = rect->width * par->depth;
359 height = rect->height;
361 dest = info->fix.smem_start + (dy * info->fix.line_length) + dx;
362 color_blit(width, height, info->fix.line_length, dest, rop, color,
363 par->blit_bpp, info);
366 void i810fb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
368 struct i810fb_par *par = (struct i810fb_par *) info->par;
369 u32 sx, sy, dx, dy, pitch, width, height, src, dest, xdir;
371 if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
373 return cfb_copyarea(info, region);
375 dx = region->dx * par->depth;
376 sx = region->sx * par->depth;
377 width = region->width * par->depth;
380 height = region->height;
391 pitch = info->fix.line_length;
394 pitch = (-(info->fix.line_length)) & 0xFFFF;
398 src = info->fix.smem_start + (sy * info->fix.line_length) + sx;
399 dest = info->fix.smem_start + (dy * info->fix.line_length) + dx;
401 source_copy_blit(width, height, pitch, xdir, src, dest,
402 PAT_COPY_ROP, par->blit_bpp, info);
405 void i810fb_imageblit(struct fb_info *info, const struct fb_image *image)
407 struct i810fb_par *par = (struct i810fb_par *) info->par;
408 u32 fg = 0, bg = 0, size, dst;
410 if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
411 par->depth == 4 || image->depth != 1)
412 return cfb_imageblit(info, image);
414 switch (info->var.bits_per_pixel) {
416 fg = image->fg_color;
417 bg = image->bg_color;
421 fg = ((u32 *)(info->pseudo_palette))[image->fg_color];
422 bg = ((u32 *)(info->pseudo_palette))[image->bg_color];
426 dst = info->fix.smem_start + (image->dy * info->fix.line_length) +
427 (image->dx * par->depth);
429 size = (image->width+7)/8 + 1;
431 size *= image->height;
434 mono_src_copy_imm_blit(image->width * par->depth,
435 image->height, info->fix.line_length,
436 size/4, par->blit_bpp,
437 PAT_COPY_ROP, dst, (u32 *) image->data,
441 int i810fb_sync(struct fb_info *info)
443 struct i810fb_par *par = (struct i810fb_par *) info->par;
445 if (!info->var.accel_flags || par->dev_flags & LOCKUP)
448 return wait_for_engine_idle(info);
451 void i810fb_load_front(u32 offset, struct fb_info *info)
453 struct i810fb_par *par = (struct i810fb_par *) info->par;
454 u8 __iomem *mmio = par->mmio_start_virtual;
456 if (!info->var.accel_flags || par->dev_flags & LOCKUP)
457 i810_writel(DPLYBASE, mmio, par->fb.physical + offset);
459 load_front(offset, info);
463 * i810fb_init_ringbuffer - initialize the ringbuffer
464 * @par: pointer to i810fb_par structure
467 * Initializes the ringbuffer by telling the device the
468 * size and location of the ringbuffer. It also sets
469 * the head and tail pointers = 0
471 void i810fb_init_ringbuffer(struct fb_info *info)
473 struct i810fb_par *par = (struct i810fb_par *) info->par;
475 u8 __iomem *mmio = par->mmio_start_virtual;
477 wait_for_engine_idle(info);
478 i810fb_iring_enable(par, OFF);
479 i810_writel(IRING, mmio, 0);
480 i810_writel(IRING + 4, mmio, 0);
483 tmp2 = i810_readl(IRING + 8, mmio) & ~RBUFFER_START_MASK;
484 tmp1 = par->iring.physical;
485 i810_writel(IRING + 8, mmio, tmp2 | tmp1);
487 tmp1 = i810_readl(IRING + 12, mmio);
488 tmp1 &= ~RBUFFER_SIZE_MASK;
489 tmp2 = (par->iring.size - I810_PAGESIZE) & RBUFFER_SIZE_MASK;
490 i810_writel(IRING + 12, mmio, tmp1 | tmp2);
491 i810fb_iring_enable(par, ON);