File: /usr/src/linux/drivers/video/aty/mach64_accel.c

1     
2     /*
3      *  ATI Mach64 Hardware Acceleration
4      */
5     
6     #include <linux/delay.h>
7     #include <linux/fb.h>
8     
9     #include <video/fbcon.h>
10     #include <video/fbcon-cfb8.h>
11     #include <video/fbcon-cfb16.h>
12     #include <video/fbcon-cfb24.h>
13     #include <video/fbcon-cfb32.h>
14     
15     #include "mach64.h"
16     #include "atyfb.h"
17     
18         /*
19          *  Text console acceleration
20          */
21     
22     static void fbcon_aty_bmove(struct display *p, int sy, int sx, int dy, int dx,
23     			    int height, int width);
24     static void fbcon_aty_clear(struct vc_data *conp, struct display *p, int sy,
25     			    int sx, int height, int width);
26     
27     
28         /*
29          *  Generic Mach64 routines
30          */
31     
32     void aty_reset_engine(const struct fb_info_aty *info)
33     {
34         /* reset engine */
35         aty_st_le32(GEN_TEST_CNTL,
36     		aty_ld_le32(GEN_TEST_CNTL, info) & ~GUI_ENGINE_ENABLE, info);
37         /* enable engine */
38         aty_st_le32(GEN_TEST_CNTL,
39     		aty_ld_le32(GEN_TEST_CNTL, info) | GUI_ENGINE_ENABLE, info);
40         /* ensure engine is not locked up by clearing any FIFO or */
41         /* HOST errors */
42         aty_st_le32(BUS_CNTL, aty_ld_le32(BUS_CNTL, info) | BUS_HOST_ERR_ACK |
43     			  BUS_FIFO_ERR_ACK, info);
44     }
45     
46     static void reset_GTC_3D_engine(const struct fb_info_aty *info)
47     {
48     	aty_st_le32(SCALE_3D_CNTL, 0xc0, info);
49     	mdelay(GTC_3D_RESET_DELAY);
50     	aty_st_le32(SETUP_CNTL, 0x00, info);
51     	mdelay(GTC_3D_RESET_DELAY);
52     	aty_st_le32(SCALE_3D_CNTL, 0x00, info);
53     	mdelay(GTC_3D_RESET_DELAY);
54     }
55     
56     void aty_init_engine(const struct atyfb_par *par, struct fb_info_aty *info)
57     {
58         u32 pitch_value;
59     
60         /* determine modal information from global mode structure */
61         pitch_value = par->crtc.vxres;
62     
63         if (par->crtc.bpp == 24) {
64     	/* In 24 bpp, the engine is in 8 bpp - this requires that all */
65     	/* horizontal coordinates and widths must be adjusted */
66     	pitch_value = pitch_value * 3;
67         }
68     
69         /* On GTC (RagePro), we need to reset the 3D engine before */
70         if (M64_HAS(RESET_3D))
71         	reset_GTC_3D_engine(info);
72     
73         /* Reset engine, enable, and clear any engine errors */
74         aty_reset_engine(info);
75         /* Ensure that vga page pointers are set to zero - the upper */
76         /* page pointers are set to 1 to handle overflows in the */
77         /* lower page */
78         aty_st_le32(MEM_VGA_WP_SEL, 0x00010000, info);
79         aty_st_le32(MEM_VGA_RP_SEL, 0x00010000, info);
80     
81         /* ---- Setup standard engine context ---- */
82     
83         /* All GUI registers here are FIFOed - therefore, wait for */
84         /* the appropriate number of empty FIFO entries */
85         wait_for_fifo(14, info);
86     
87         /* enable all registers to be loaded for context loads */
88         aty_st_le32(CONTEXT_MASK, 0xFFFFFFFF, info);
89     
90         /* set destination pitch to modal pitch, set offset to zero */
91         aty_st_le32(DST_OFF_PITCH, (pitch_value / 8) << 22, info);
92     
93         /* zero these registers (set them to a known state) */
94         aty_st_le32(DST_Y_X, 0, info);
95         aty_st_le32(DST_HEIGHT, 0, info);
96         aty_st_le32(DST_BRES_ERR, 0, info);
97         aty_st_le32(DST_BRES_INC, 0, info);
98         aty_st_le32(DST_BRES_DEC, 0, info);
99     
100         /* set destination drawing attributes */
101         aty_st_le32(DST_CNTL, DST_LAST_PEL | DST_Y_TOP_TO_BOTTOM |
102     			  DST_X_LEFT_TO_RIGHT, info);
103     
104         /* set source pitch to modal pitch, set offset to zero */
105         aty_st_le32(SRC_OFF_PITCH, (pitch_value / 8) << 22, info);
106     
107         /* set these registers to a known state */
108         aty_st_le32(SRC_Y_X, 0, info);
109         aty_st_le32(SRC_HEIGHT1_WIDTH1, 1, info);
110         aty_st_le32(SRC_Y_X_START, 0, info);
111         aty_st_le32(SRC_HEIGHT2_WIDTH2, 1, info);
112     
113         /* set source pixel retrieving attributes */
114         aty_st_le32(SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT, info);
115     
116         /* set host attributes */
117         wait_for_fifo(13, info);
118         aty_st_le32(HOST_CNTL, 0, info);
119     
120         /* set pattern attributes */
121         aty_st_le32(PAT_REG0, 0, info);
122         aty_st_le32(PAT_REG1, 0, info);
123         aty_st_le32(PAT_CNTL, 0, info);
124     
125         /* set scissors to modal size */
126         aty_st_le32(SC_LEFT, 0, info);
127         aty_st_le32(SC_TOP, 0, info);
128         aty_st_le32(SC_BOTTOM, par->crtc.vyres-1, info);
129         aty_st_le32(SC_RIGHT, pitch_value-1, info);
130     
131         /* set background color to minimum value (usually BLACK) */
132         aty_st_le32(DP_BKGD_CLR, 0, info);
133     
134         /* set foreground color to maximum value (usually WHITE) */
135         aty_st_le32(DP_FRGD_CLR, 0xFFFFFFFF, info);
136     
137         /* set write mask to effect all pixel bits */
138         aty_st_le32(DP_WRITE_MASK, 0xFFFFFFFF, info);
139     
140         /* set foreground mix to overpaint and background mix to */
141         /* no-effect */
142         aty_st_le32(DP_MIX, FRGD_MIX_S | BKGD_MIX_D, info);
143     
144         /* set primary source pixel channel to foreground color */
145         /* register */
146         aty_st_le32(DP_SRC, FRGD_SRC_FRGD_CLR, info);
147     
148         /* set compare functionality to false (no-effect on */
149         /* destination) */
150         wait_for_fifo(3, info);
151         aty_st_le32(CLR_CMP_CLR, 0, info);
152         aty_st_le32(CLR_CMP_MASK, 0xFFFFFFFF, info);
153         aty_st_le32(CLR_CMP_CNTL, 0, info);
154     
155         /* set pixel depth */
156         wait_for_fifo(2, info);
157         aty_st_le32(DP_PIX_WIDTH, par->crtc.dp_pix_width, info);
158         aty_st_le32(DP_CHAIN_MASK, par->crtc.dp_chain_mask, info);
159     
160         wait_for_fifo(5, info);
161         aty_st_le32(SCALE_3D_CNTL, 0, info);
162         aty_st_le32(Z_CNTL, 0, info);
163         aty_st_le32(CRTC_INT_CNTL, aty_ld_le32(CRTC_INT_CNTL, info) & ~0x20, info);
164         aty_st_le32(GUI_TRAJ_CNTL, 0x100023, info);
165     
166         /* insure engine is idle before leaving */
167         wait_for_idle(info);
168     }
169     
170     
171         /*
172          *  Accelerated functions
173          */
174     
175     static inline void draw_rect(s16 x, s16 y, u16 width, u16 height,
176     			     struct fb_info_aty *info)
177     {
178         /* perform rectangle fill */
179         wait_for_fifo(2, info);
180         aty_st_le32(DST_Y_X, (x << 16) | y, info);
181         aty_st_le32(DST_HEIGHT_WIDTH, (width << 16) | height, info);
182         info->blitter_may_be_busy = 1;
183     }
184     
185     static inline void aty_rectcopy(int srcx, int srcy, int dstx, int dsty,
186     				u_int width, u_int height,
187     				struct fb_info_aty *info)
188     {
189         u32 direction = DST_LAST_PEL;
190         u32 pitch_value;
191     
192         if (!width || !height)
193     	return;
194     
195         pitch_value = info->current_par.crtc.vxres;
196         if (info->current_par.crtc.bpp == 24) {
197     	/* In 24 bpp, the engine is in 8 bpp - this requires that all */
198     	/* horizontal coordinates and widths must be adjusted */
199     	pitch_value *= 3;
200     	srcx *= 3;
201     	dstx *= 3;
202     	width *= 3;
203         }
204     
205         if (srcy < dsty) {
206     	dsty += height - 1;
207     	srcy += height - 1;
208         } else
209     	direction |= DST_Y_TOP_TO_BOTTOM;
210     
211         if (srcx < dstx) {
212     	dstx += width - 1;
213     	srcx += width - 1;
214         } else
215     	direction |= DST_X_LEFT_TO_RIGHT;
216     
217         wait_for_fifo(4, info);
218         aty_st_le32(DP_SRC, FRGD_SRC_BLIT, info);
219         aty_st_le32(SRC_Y_X, (srcx << 16) | srcy, info);
220         aty_st_le32(SRC_HEIGHT1_WIDTH1, (width << 16) | height, info);
221         aty_st_le32(DST_CNTL, direction, info);
222         draw_rect(dstx, dsty, width, height, info);
223     }
224     
225     void aty_rectfill(int dstx, int dsty, u_int width, u_int height, u_int color,
226     		  struct fb_info_aty *info)
227     {
228         if (!width || !height)
229     	return;
230     
231         if (info->current_par.crtc.bpp == 24) {
232     	/* In 24 bpp, the engine is in 8 bpp - this requires that all */
233     	/* horizontal coordinates and widths must be adjusted */
234     	dstx *= 3;
235     	width *= 3;
236         }
237     
238         wait_for_fifo(3, info);
239         aty_st_le32(DP_FRGD_CLR, color, info);
240         aty_st_le32(DP_SRC, BKGD_SRC_BKGD_CLR | FRGD_SRC_FRGD_CLR | MONO_SRC_ONE,
241     		info);
242         aty_st_le32(DST_CNTL, DST_LAST_PEL | DST_Y_TOP_TO_BOTTOM |
243     			  DST_X_LEFT_TO_RIGHT, info);
244         draw_rect(dstx, dsty, width, height, info);
245     }
246     
247     
248         /*
249          *  Text console acceleration
250          */
251     
252     static void fbcon_aty_bmove(struct display *p, int sy, int sx, int dy, int dx,
253     			    int height, int width)
254     {
255     #ifdef __sparc__
256         struct fb_info_aty *fb = (struct fb_info_aty *)(p->fb_info);
257     
258         if (fb->mmaped && (!fb->fb_info.display_fg
259     	|| fb->fb_info.display_fg->vc_num == fb->vtconsole))
260     	return;
261     #endif
262     
263         sx *= fontwidth(p);
264         sy *= fontheight(p);
265         dx *= fontwidth(p);
266         dy *= fontheight(p);
267         width *= fontwidth(p);
268         height *= fontheight(p);
269     
270         aty_rectcopy(sx, sy, dx, dy, width, height,
271     		 (struct fb_info_aty *)p->fb_info);
272     }
273     
274     static void fbcon_aty_clear(struct vc_data *conp, struct display *p, int sy,
275     			    int sx, int height, int width)
276     {
277         u32 bgx;
278     #ifdef __sparc__
279         struct fb_info_aty *fb = (struct fb_info_aty *)(p->fb_info);
280     
281         if (fb->mmaped && (!fb->fb_info.display_fg
282     	|| fb->fb_info.display_fg->vc_num == fb->vtconsole))
283     	return;
284     #endif
285     
286         bgx = attr_bgcol_ec(p, conp);
287         bgx |= (bgx << 8);
288         bgx |= (bgx << 16);
289     
290         sx *= fontwidth(p);
291         sy *= fontheight(p);
292         width *= fontwidth(p);
293         height *= fontheight(p);
294     
295         aty_rectfill(sx, sy, width, height, bgx,
296     		 (struct fb_info_aty *)p->fb_info);
297     }
298     
299     #ifdef __sparc__
300     #define check_access \
301         if (fb->mmaped && (!fb->fb_info.display_fg \
302     	|| fb->fb_info.display_fg->vc_num == fb->vtconsole)) \
303     	return;
304     #else
305     #define check_access do { } while (0)
306     #endif
307     
308     #define DEF_FBCON_ATY_OP(name, call, args...) \
309     static void name(struct vc_data *conp, struct display *p, args) \
310     { \
311         struct fb_info_aty *fb = (struct fb_info_aty *)(p->fb_info); \
312         check_access; \
313         if (fb->blitter_may_be_busy) \
314     	wait_for_idle((struct fb_info_aty *)p->fb_info); \
315         call; \
316     }
317     
318     #define DEF_FBCON_ATY(width) \
319         DEF_FBCON_ATY_OP(fbcon_aty##width##_putc, \
320     		     fbcon_cfb##width##_putc(conp, p, c, yy, xx), \
321     		     int c, int yy, int xx) \
322         DEF_FBCON_ATY_OP(fbcon_aty##width##_putcs, \
323     		     fbcon_cfb##width##_putcs(conp, p, s, count, yy, xx), \
324     		     const unsigned short *s, int count, int yy, int xx) \
325         DEF_FBCON_ATY_OP(fbcon_aty##width##_clear_margins, \
326     		     fbcon_cfb##width##_clear_margins(conp, p, bottom_only), \
327     		     int bottom_only) \
328      \
329     const struct display_switch fbcon_aty##width## = { \
330         setup:		fbcon_cfb##width##_setup, \
331         bmove:		fbcon_aty_bmove, \
332         clear:		fbcon_aty_clear, \
333         putc:		fbcon_aty##width##_putc, \
334         putcs:		fbcon_aty##width##_putcs, \
335         revc:		fbcon_cfb##width##_revc, \
336         clear_margins:	fbcon_aty##width##_clear_margins, \
337         fontwidthmask:	FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16) \
338     };
339     
340     #ifdef FBCON_HAS_CFB8
341     DEF_FBCON_ATY(8)
342     #endif
343     #ifdef FBCON_HAS_CFB16
344     DEF_FBCON_ATY(16)
345     #endif
346     #ifdef FBCON_HAS_CFB24
347     DEF_FBCON_ATY(24)
348     #endif
349     #ifdef FBCON_HAS_CFB32
350     DEF_FBCON_ATY(32)
351     #endif
352     
353