mach64_accel.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:10k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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