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
);
255 static inline void load_front(int offset
, struct fb_info
*info
)
257 struct i810fb_par
*par
= (struct i810fb_par
*) info
->par
;
259 if (begin_iring(info
, 8 + IRING_PAD
)) return;
261 PUT_RING(PARSER
| FLUSH
);
266 if (begin_iring(info
, 8 + IRING_PAD
)) return;
268 PUT_RING(PARSER
| FRONT_BUFFER
| ((par
->pitch
>> 3) << 8));
269 PUT_RING((par
->fb
.offset
<< 12) + offset
);
275 * i810fb_iring_enable - enables/disables the ringbuffer
276 * @mode: enable or disable
277 * @par: pointer to i810fb_par structure
280 * Enables or disables the ringbuffer, effectively enabling or
281 * disabling the instruction/acceleration engine.
283 static inline void i810fb_iring_enable(struct i810fb_par
*par
, u32 mode
)
286 u8 __iomem
*mmio
= par
->mmio_start_virtual
;
288 tmp
= i810_readl(IRING
+ 12, mmio
);
294 i810_writel(IRING
+ 12, mmio
, tmp
);
297 void i810fb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
299 struct i810fb_par
*par
= (struct i810fb_par
*) info
->par
;
300 u32 dx
, dy
, width
, height
, dest
, rop
= 0, color
= 0;
302 if (!info
->var
.accel_flags
|| par
->dev_flags
& LOCKUP
||
304 return cfb_fillrect(info
, rect
);
309 color
= ((u32
*) (info
->pseudo_palette
))[rect
->color
];
311 rop
= i810fb_rop
[rect
->rop
];
313 dx
= rect
->dx
* par
->depth
;
314 width
= rect
->width
* par
->depth
;
316 height
= rect
->height
;
318 dest
= info
->fix
.smem_start
+ (dy
* info
->fix
.line_length
) + dx
;
319 color_blit(width
, height
, info
->fix
.line_length
, dest
, rop
, color
,
320 par
->blit_bpp
, info
);
323 void i810fb_copyarea(struct fb_info
*info
, const struct fb_copyarea
*region
)
325 struct i810fb_par
*par
= (struct i810fb_par
*) info
->par
;
326 u32 sx
, sy
, dx
, dy
, pitch
, width
, height
, src
, dest
, xdir
;
328 if (!info
->var
.accel_flags
|| par
->dev_flags
& LOCKUP
||
330 return cfb_copyarea(info
, region
);
332 dx
= region
->dx
* par
->depth
;
333 sx
= region
->sx
* par
->depth
;
334 width
= region
->width
* par
->depth
;
337 height
= region
->height
;
348 pitch
= info
->fix
.line_length
;
351 pitch
= (-(info
->fix
.line_length
)) & 0xFFFF;
355 src
= info
->fix
.smem_start
+ (sy
* info
->fix
.line_length
) + sx
;
356 dest
= info
->fix
.smem_start
+ (dy
* info
->fix
.line_length
) + dx
;
358 source_copy_blit(width
, height
, pitch
, xdir
, src
, dest
,
359 PAT_COPY_ROP
, par
->blit_bpp
, info
);
362 void i810fb_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
364 struct i810fb_par
*par
= (struct i810fb_par
*) info
->par
;
365 u32 fg
= 0, bg
= 0, size
, dst
;
367 if (!info
->var
.accel_flags
|| par
->dev_flags
& LOCKUP
||
368 par
->depth
== 4 || image
->depth
!= 1)
369 return cfb_imageblit(info
, image
);
371 switch (info
->var
.bits_per_pixel
) {
373 fg
= image
->fg_color
;
374 bg
= image
->bg_color
;
378 fg
= ((u32
*)(info
->pseudo_palette
))[image
->fg_color
];
379 bg
= ((u32
*)(info
->pseudo_palette
))[image
->bg_color
];
383 dst
= info
->fix
.smem_start
+ (image
->dy
* info
->fix
.line_length
) +
384 (image
->dx
* par
->depth
);
386 size
= (image
->width
+7)/8 + 1;
388 size
*= image
->height
;
391 mono_src_copy_imm_blit(image
->width
* par
->depth
,
392 image
->height
, info
->fix
.line_length
,
393 size
/4, par
->blit_bpp
,
394 PAT_COPY_ROP
, dst
, (u32
*) image
->data
,
398 int i810fb_sync(struct fb_info
*info
)
400 struct i810fb_par
*par
= (struct i810fb_par
*) info
->par
;
402 if (!info
->var
.accel_flags
|| par
->dev_flags
& LOCKUP
)
405 return wait_for_engine_idle(info
);
408 void i810fb_load_front(u32 offset
, struct fb_info
*info
)
410 struct i810fb_par
*par
= (struct i810fb_par
*) info
->par
;
411 u8 __iomem
*mmio
= par
->mmio_start_virtual
;
413 if (!info
->var
.accel_flags
|| par
->dev_flags
& LOCKUP
)
414 i810_writel(DPLYBASE
, mmio
, par
->fb
.physical
+ offset
);
416 load_front(offset
, info
);
420 * i810fb_init_ringbuffer - initialize the ringbuffer
421 * @par: pointer to i810fb_par structure
424 * Initializes the ringbuffer by telling the device the
425 * size and location of the ringbuffer. It also sets
426 * the head and tail pointers = 0
428 void i810fb_init_ringbuffer(struct fb_info
*info
)
430 struct i810fb_par
*par
= (struct i810fb_par
*) info
->par
;
432 u8 __iomem
*mmio
= par
->mmio_start_virtual
;
434 wait_for_engine_idle(info
);
435 i810fb_iring_enable(par
, OFF
);
436 i810_writel(IRING
, mmio
, 0);
437 i810_writel(IRING
+ 4, mmio
, 0);
440 tmp2
= i810_readl(IRING
+ 8, mmio
) & ~RBUFFER_START_MASK
;
441 tmp1
= par
->iring
.physical
;
442 i810_writel(IRING
+ 8, mmio
, tmp2
| tmp1
);
444 tmp1
= i810_readl(IRING
+ 12, mmio
);
445 tmp1
&= ~RBUFFER_SIZE_MASK
;
446 tmp2
= (par
->iring
.size
- I810_PAGESIZE
) & RBUFFER_SIZE_MASK
;
447 i810_writel(IRING
+ 12, mmio
, tmp1
| tmp2
);
448 i810fb_iring_enable(par
, ON
);