3 * ATI Mach64 Hardware Acceleration
6 #include <linux/sched.h>
7 #include <linux/delay.h>
9 #include <video/mach64.h>
13 * Generic Mach64 routines
16 void aty_reset_engine(const struct atyfb_par *par)
19 aty_st_le32(GEN_TEST_CNTL,
20 aty_ld_le32(GEN_TEST_CNTL, par) & ~GUI_ENGINE_ENABLE,
23 aty_st_le32(GEN_TEST_CNTL,
24 aty_ld_le32(GEN_TEST_CNTL, par) | GUI_ENGINE_ENABLE,
26 /* ensure engine is not locked up by clearing any FIFO or */
30 par) | BUS_HOST_ERR_ACK | BUS_FIFO_ERR_ACK,
34 static void reset_GTC_3D_engine(const struct atyfb_par *par)
36 aty_st_le32(SCALE_3D_CNTL, 0xc0, par);
37 mdelay(GTC_3D_RESET_DELAY);
38 aty_st_le32(SETUP_CNTL, 0x00, par);
39 mdelay(GTC_3D_RESET_DELAY);
40 aty_st_le32(SCALE_3D_CNTL, 0x00, par);
41 mdelay(GTC_3D_RESET_DELAY);
44 void aty_init_engine(struct atyfb_par *par, struct fb_info *info)
48 /* determine modal information from global mode structure */
49 pitch_value = info->var.xres_virtual;
51 if (info->var.bits_per_pixel == 24) {
52 /* In 24 bpp, the engine is in 8 bpp - this requires that all */
53 /* horizontal coordinates and widths must be adjusted */
54 pitch_value = pitch_value * 3;
57 /* On GTC (RagePro), we need to reset the 3D engine before */
58 if (M64_HAS(RESET_3D))
59 reset_GTC_3D_engine(par);
61 /* Reset engine, enable, and clear any engine errors */
62 aty_reset_engine(par);
63 /* Ensure that vga page pointers are set to zero - the upper */
64 /* page pointers are set to 1 to handle overflows in the */
66 aty_st_le32(MEM_VGA_WP_SEL, 0x00010000, par);
67 aty_st_le32(MEM_VGA_RP_SEL, 0x00010000, par);
69 /* ---- Setup standard engine context ---- */
71 /* All GUI registers here are FIFOed - therefore, wait for */
72 /* the appropriate number of empty FIFO entries */
73 wait_for_fifo(14, par);
75 /* enable all registers to be loaded for context loads */
76 aty_st_le32(CONTEXT_MASK, 0xFFFFFFFF, par);
78 /* set destination pitch to modal pitch, set offset to zero */
79 aty_st_le32(DST_OFF_PITCH, (pitch_value / 8) << 22, par);
81 /* zero these registers (set them to a known state) */
82 aty_st_le32(DST_Y_X, 0, par);
83 aty_st_le32(DST_HEIGHT, 0, par);
84 aty_st_le32(DST_BRES_ERR, 0, par);
85 aty_st_le32(DST_BRES_INC, 0, par);
86 aty_st_le32(DST_BRES_DEC, 0, par);
88 /* set destination drawing attributes */
89 aty_st_le32(DST_CNTL, DST_LAST_PEL | DST_Y_TOP_TO_BOTTOM |
90 DST_X_LEFT_TO_RIGHT, par);
92 /* set source pitch to modal pitch, set offset to zero */
93 aty_st_le32(SRC_OFF_PITCH, (pitch_value / 8) << 22, par);
95 /* set these registers to a known state */
96 aty_st_le32(SRC_Y_X, 0, par);
97 aty_st_le32(SRC_HEIGHT1_WIDTH1, 1, par);
98 aty_st_le32(SRC_Y_X_START, 0, par);
99 aty_st_le32(SRC_HEIGHT2_WIDTH2, 1, par);
101 /* set source pixel retrieving attributes */
102 aty_st_le32(SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT, par);
104 /* set host attributes */
105 wait_for_fifo(13, par);
106 aty_st_le32(HOST_CNTL, 0, par);
108 /* set pattern attributes */
109 aty_st_le32(PAT_REG0, 0, par);
110 aty_st_le32(PAT_REG1, 0, par);
111 aty_st_le32(PAT_CNTL, 0, par);
113 /* set scissors to modal size */
114 aty_st_le32(SC_LEFT, 0, par);
115 aty_st_le32(SC_TOP, 0, par);
116 aty_st_le32(SC_BOTTOM, par->crtc.vyres - 1, par);
117 aty_st_le32(SC_RIGHT, pitch_value - 1, par);
119 /* set background color to minimum value (usually BLACK) */
120 aty_st_le32(DP_BKGD_CLR, 0, par);
122 /* set foreground color to maximum value (usually WHITE) */
123 aty_st_le32(DP_FRGD_CLR, 0xFFFFFFFF, par);
125 /* set write mask to effect all pixel bits */
126 aty_st_le32(DP_WRITE_MASK, 0xFFFFFFFF, par);
128 /* set foreground mix to overpaint and background mix to */
130 aty_st_le32(DP_MIX, FRGD_MIX_S | BKGD_MIX_D, par);
132 /* set primary source pixel channel to foreground color */
134 aty_st_le32(DP_SRC, FRGD_SRC_FRGD_CLR, par);
136 /* set compare functionality to false (no-effect on */
138 wait_for_fifo(3, par);
139 aty_st_le32(CLR_CMP_CLR, 0, par);
140 aty_st_le32(CLR_CMP_MASK, 0xFFFFFFFF, par);
141 aty_st_le32(CLR_CMP_CNTL, 0, par);
143 /* set pixel depth */
144 wait_for_fifo(2, par);
145 aty_st_le32(DP_PIX_WIDTH, par->crtc.dp_pix_width, par);
146 aty_st_le32(DP_CHAIN_MASK, par->crtc.dp_chain_mask, par);
148 wait_for_fifo(5, par);
149 aty_st_le32(SCALE_3D_CNTL, 0, par);
150 aty_st_le32(Z_CNTL, 0, par);
151 aty_st_le32(CRTC_INT_CNTL, aty_ld_le32(CRTC_INT_CNTL, par) & ~0x20,
153 aty_st_le32(GUI_TRAJ_CNTL, 0x100023, par);
155 /* insure engine is idle before leaving */
160 * Accelerated functions
163 static inline void draw_rect(s16 x, s16 y, u16 width, u16 height,
164 struct atyfb_par *par)
166 /* perform rectangle fill */
167 wait_for_fifo(2, par);
168 aty_st_le32(DST_Y_X, (x << 16) | y, par);
169 aty_st_le32(DST_HEIGHT_WIDTH, (width << 16) | height, par);
170 par->blitter_may_be_busy = 1;
173 void atyfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
175 struct atyfb_par *par = (struct atyfb_par *) info->par;
176 u32 dy = area->dy, sy = area->sy, direction = DST_LAST_PEL;
177 u32 sx = area->sx, dx = area->dx, width = area->width;
180 if (!area->width || !area->height)
182 if (!par->accel_flags) {
183 if (par->blitter_may_be_busy)
185 cfb_copyarea(info, area);
189 pitch_value = info->var.xres_virtual;
190 if (info->var.bits_per_pixel == 24) {
191 /* In 24 bpp, the engine is in 8 bpp - this requires that all */
192 /* horizontal coordinates and widths must be adjusted */
199 if (area->sy < area->dy) {
200 dy += area->height - 1;
201 sy += area->height - 1;
203 direction |= DST_Y_TOP_TO_BOTTOM;
209 direction |= DST_X_LEFT_TO_RIGHT;
211 wait_for_fifo(4, par);
212 aty_st_le32(DP_SRC, FRGD_SRC_BLIT, par);
213 aty_st_le32(SRC_Y_X, (sx << 16) | sy, par);
214 aty_st_le32(SRC_HEIGHT1_WIDTH1, (width << 16) | area->height, par);
215 aty_st_le32(DST_CNTL, direction, par);
216 draw_rect(dx, dy, width, area->height, par);
219 void atyfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
221 struct atyfb_par *par = (struct atyfb_par *) info->par;
222 u32 color = rect->color, dx = rect->dx, width = rect->width;
224 if (!rect->width || !rect->height)
226 if (!par->accel_flags) {
227 if (par->blitter_may_be_busy)
229 cfb_fillrect(info, rect);
233 color |= (rect->color << 8);
234 color |= (rect->color << 16);
236 if (info->var.bits_per_pixel == 24) {
237 /* In 24 bpp, the engine is in 8 bpp - this requires that all */
238 /* horizontal coordinates and widths must be adjusted */
243 wait_for_fifo(3, par);
244 aty_st_le32(DP_FRGD_CLR, color, par);
246 BKGD_SRC_BKGD_CLR | FRGD_SRC_FRGD_CLR | MONO_SRC_ONE,
248 aty_st_le32(DST_CNTL,
249 DST_LAST_PEL | DST_Y_TOP_TO_BOTTOM |
250 DST_X_LEFT_TO_RIGHT, par);
251 draw_rect(dx, rect->dy, width, rect->height, par);
254 void atyfb_imageblit(struct fb_info *info, const struct fb_image *image)
256 struct atyfb_par *par = (struct atyfb_par *) info->par;
258 if (par->blitter_may_be_busy)
260 cfb_imageblit(info, image);