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"
17 #include "i810_main.h"
19 static u32 i810fb_rop
[] = {
20 COLOR_COPY_ROP
, /* ROP_COPY */
25 #define PUT_RING(n) { \
26 i810_writel(par->cur_tail, par->iring.virtual, n); \
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"
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
));
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
56 * The function waits until a free space from the ringbuffer
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
;
67 head
= i810_readl(IRING
+ 4, mmio
) & RBUFFER_HEAD_MASK
;
70 (par
->iring
.size
- tail
+ head
) >= space
) ||
71 (tail
< head
&& (head
- tail
) >= space
)) {
75 printk("ringbuffer lockup!!!\n");
76 i810_report_error(mmio
);
77 par
->dev_flags
|= LOCKUP
;
78 info
->pixmap
.scan_align
= 1;
83 * wait_for_engine_idle - waits for all hardware engines to finish
84 * @par: pointer to i810fb_par structure
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 */
99 while((i810_readw(INSTDONE
, mmio
) & 0x7B) != 0x7B && --count
);
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;
110 /* begin_iring - prepares the ringbuffer
111 * @space: length of sequence in dwords
112 * @par: pointer to i810fb_par structure
115 * Checks/waits for sufficent 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
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
158 * This is a BLIT operation typically used when doing
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
);
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
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
);
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
229 * A color expand operation where the source data is placed in the
230 * ringbuffer itself. Useful for drawing text.
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
);
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
);
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
);
276 * i810fb_iring_enable - enables/disables the ringbuffer
277 * @mode: enable or disable
278 * @par: pointer to i810fb_par structure
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
)
287 u8 __iomem
*mmio
= par
->mmio_start_virtual
;
289 tmp
= i810_readl(IRING
+ 12, mmio
);
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
||
305 return cfb_fillrect(info
, rect
);
310 color
= ((u32
*) (info
->pseudo_palette
))[rect
->color
];
312 rop
= i810fb_rop
[rect
->rop
];
314 dx
= rect
->dx
* par
->depth
;
315 width
= rect
->width
* par
->depth
;
317 height
= rect
->height
;
319 dest
= info
->fix
.smem_start
+ (dy
* info
->fix
.line_length
) + dx
;
320 color_blit(width
, height
, info
->fix
.line_length
, dest
, rop
, color
,
321 par
->blit_bpp
, info
);
324 void i810fb_copyarea(struct fb_info
*info
, const struct fb_copyarea
*region
)
326 struct i810fb_par
*par
= info
->par
;
327 u32 sx
, sy
, dx
, dy
, pitch
, width
, height
, src
, dest
, xdir
;
329 if (!info
->var
.accel_flags
|| par
->dev_flags
& LOCKUP
||
331 return cfb_copyarea(info
, region
);
333 dx
= region
->dx
* par
->depth
;
334 sx
= region
->sx
* par
->depth
;
335 width
= region
->width
* par
->depth
;
338 height
= region
->height
;
349 pitch
= info
->fix
.line_length
;
352 pitch
= (-(info
->fix
.line_length
)) & 0xFFFF;
356 src
= info
->fix
.smem_start
+ (sy
* info
->fix
.line_length
) + sx
;
357 dest
= info
->fix
.smem_start
+ (dy
* info
->fix
.line_length
) + dx
;
359 source_copy_blit(width
, height
, pitch
, xdir
, src
, dest
,
360 PAT_COPY_ROP
, par
->blit_bpp
, info
);
363 void i810fb_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
365 struct i810fb_par
*par
= info
->par
;
366 u32 fg
= 0, bg
= 0, size
, dst
;
368 if (!info
->var
.accel_flags
|| par
->dev_flags
& LOCKUP
||
369 par
->depth
== 4 || image
->depth
!= 1)
370 return cfb_imageblit(info
, image
);
372 switch (info
->var
.bits_per_pixel
) {
374 fg
= image
->fg_color
;
375 bg
= image
->bg_color
;
379 fg
= ((u32
*)(info
->pseudo_palette
))[image
->fg_color
];
380 bg
= ((u32
*)(info
->pseudo_palette
))[image
->bg_color
];
384 dst
= info
->fix
.smem_start
+ (image
->dy
* info
->fix
.line_length
) +
385 (image
->dx
* par
->depth
);
387 size
= (image
->width
+7)/8 + 1;
389 size
*= image
->height
;
392 mono_src_copy_imm_blit(image
->width
* par
->depth
,
393 image
->height
, info
->fix
.line_length
,
394 size
/4, par
->blit_bpp
,
395 PAT_COPY_ROP
, dst
, (u32
*) image
->data
,
399 int i810fb_sync(struct fb_info
*info
)
401 struct i810fb_par
*par
= info
->par
;
403 if (!info
->var
.accel_flags
|| par
->dev_flags
& LOCKUP
)
406 return wait_for_engine_idle(info
);
409 void i810fb_load_front(u32 offset
, struct fb_info
*info
)
411 struct i810fb_par
*par
= info
->par
;
412 u8 __iomem
*mmio
= par
->mmio_start_virtual
;
414 if (!info
->var
.accel_flags
|| par
->dev_flags
& LOCKUP
)
415 i810_writel(DPLYBASE
, mmio
, par
->fb
.physical
+ offset
);
417 load_front(offset
, info
);
421 * i810fb_init_ringbuffer - initialize the ringbuffer
422 * @par: pointer to i810fb_par structure
425 * Initializes the ringbuffer by telling the device the
426 * size and location of the ringbuffer. It also sets
427 * the head and tail pointers = 0
429 void i810fb_init_ringbuffer(struct fb_info
*info
)
431 struct i810fb_par
*par
= info
->par
;
433 u8 __iomem
*mmio
= par
->mmio_start_virtual
;
435 wait_for_engine_idle(info
);
436 i810fb_iring_enable(par
, OFF
);
437 i810_writel(IRING
, mmio
, 0);
438 i810_writel(IRING
+ 4, mmio
, 0);
441 tmp2
= i810_readl(IRING
+ 8, mmio
) & ~RBUFFER_START_MASK
;
442 tmp1
= par
->iring
.physical
;
443 i810_writel(IRING
+ 8, mmio
, tmp2
| tmp1
);
445 tmp1
= i810_readl(IRING
+ 12, mmio
);
446 tmp1
&= ~RBUFFER_SIZE_MASK
;
447 tmp2
= (par
->iring
.size
- I810_PAGESIZE
) & RBUFFER_SIZE_MASK
;
448 i810_writel(IRING
+ 12, mmio
, tmp1
| tmp2
);
449 i810fb_iring_enable(par
, ON
);