radeon_accel.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #include "radeonfb.h"
  2. /* the accelerated functions here are patterned after the
  3. * "ACCEL_MMIO" ifdef branches in XFree86
  4. * --dte
  5. */
  6. static void radeon_fixup_offset(struct radeonfb_info *rinfo)
  7. {
  8. u32 local_base;
  9. /* *** Ugly workaround *** */
  10. /*
  11. * On some platforms, the video memory is mapped at 0 in radeon chip space
  12. * (like PPCs) by the firmware. X will always move it up so that it's seen
  13. * by the chip to be at the same address as the PCI BAR.
  14. * That means that when switching back from X, there is a mismatch between
  15. * the offsets programmed into the engine. This means that potentially,
  16. * accel operations done before radeonfb has a chance to re-init the engine
  17. * will have incorrect offsets, and potentially trash system memory !
  18. *
  19. * The correct fix is for fbcon to never call any accel op before the engine
  20. * has properly been re-initialized (by a call to set_var), but this is a
  21. * complex fix. This workaround in the meantime, called before every accel
  22. * operation, makes sure the offsets are in sync.
  23. */
  24. radeon_fifo_wait (1);
  25. local_base = INREG(MC_FB_LOCATION) << 16;
  26. if (local_base == rinfo->fb_local_base)
  27. return;
  28. rinfo->fb_local_base = local_base;
  29. radeon_fifo_wait (3);
  30. OUTREG(DEFAULT_PITCH_OFFSET, (rinfo->pitch << 0x16) |
  31. (rinfo->fb_local_base >> 10));
  32. OUTREG(DST_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
  33. OUTREG(SRC_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
  34. }
  35. static void radeonfb_prim_fillrect(struct radeonfb_info *rinfo,
  36. const struct fb_fillrect *region)
  37. {
  38. radeon_fifo_wait(4);
  39. OUTREG(DP_GUI_MASTER_CNTL,
  40. rinfo->dp_gui_master_cntl /* contains, like GMC_DST_32BPP */
  41. | GMC_BRUSH_SOLID_COLOR
  42. | ROP3_P);
  43. if (radeon_get_dstbpp(rinfo->depth) != DST_8BPP)
  44. OUTREG(DP_BRUSH_FRGD_CLR, rinfo->pseudo_palette[region->color]);
  45. else
  46. OUTREG(DP_BRUSH_FRGD_CLR, region->color);
  47. OUTREG(DP_WRITE_MSK, 0xffffffff);
  48. OUTREG(DP_CNTL, (DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM));
  49. radeon_fifo_wait(2);
  50. OUTREG(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL);
  51. OUTREG(WAIT_UNTIL, (WAIT_2D_IDLECLEAN | WAIT_DMA_GUI_IDLE));
  52. radeon_fifo_wait(2);
  53. OUTREG(DST_Y_X, (region->dy << 16) | region->dx);
  54. OUTREG(DST_WIDTH_HEIGHT, (region->width << 16) | region->height);
  55. }
  56. void radeonfb_fillrect(struct fb_info *info, const struct fb_fillrect *region)
  57. {
  58. struct radeonfb_info *rinfo = info->par;
  59. struct fb_fillrect modded;
  60. int vxres, vyres;
  61. if (info->state != FBINFO_STATE_RUNNING)
  62. return;
  63. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  64. cfb_fillrect(info, region);
  65. return;
  66. }
  67. radeon_fixup_offset(rinfo);
  68. vxres = info->var.xres_virtual;
  69. vyres = info->var.yres_virtual;
  70. memcpy(&modded, region, sizeof(struct fb_fillrect));
  71. if(!modded.width || !modded.height ||
  72. modded.dx >= vxres || modded.dy >= vyres)
  73. return;
  74. if(modded.dx + modded.width > vxres) modded.width = vxres - modded.dx;
  75. if(modded.dy + modded.height > vyres) modded.height = vyres - modded.dy;
  76. radeonfb_prim_fillrect(rinfo, &modded);
  77. }
  78. static void radeonfb_prim_copyarea(struct radeonfb_info *rinfo,
  79. const struct fb_copyarea *area)
  80. {
  81. int xdir, ydir;
  82. u32 sx, sy, dx, dy, w, h;
  83. w = area->width; h = area->height;
  84. dx = area->dx; dy = area->dy;
  85. sx = area->sx; sy = area->sy;
  86. xdir = sx - dx;
  87. ydir = sy - dy;
  88. if ( xdir < 0 ) { sx += w-1; dx += w-1; }
  89. if ( ydir < 0 ) { sy += h-1; dy += h-1; }
  90. radeon_fifo_wait(3);
  91. OUTREG(DP_GUI_MASTER_CNTL,
  92. rinfo->dp_gui_master_cntl /* i.e. GMC_DST_32BPP */
  93. | GMC_BRUSH_NONE
  94. | GMC_SRC_DSTCOLOR
  95. | ROP3_S
  96. | DP_SRC_SOURCE_MEMORY );
  97. OUTREG(DP_WRITE_MSK, 0xffffffff);
  98. OUTREG(DP_CNTL, (xdir>=0 ? DST_X_LEFT_TO_RIGHT : 0)
  99. | (ydir>=0 ? DST_Y_TOP_TO_BOTTOM : 0));
  100. radeon_fifo_wait(2);
  101. OUTREG(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL);
  102. OUTREG(WAIT_UNTIL, (WAIT_2D_IDLECLEAN | WAIT_DMA_GUI_IDLE));
  103. radeon_fifo_wait(3);
  104. OUTREG(SRC_Y_X, (sy << 16) | sx);
  105. OUTREG(DST_Y_X, (dy << 16) | dx);
  106. OUTREG(DST_HEIGHT_WIDTH, (h << 16) | w);
  107. }
  108. void radeonfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  109. {
  110. struct radeonfb_info *rinfo = info->par;
  111. struct fb_copyarea modded;
  112. u32 vxres, vyres;
  113. modded.sx = area->sx;
  114. modded.sy = area->sy;
  115. modded.dx = area->dx;
  116. modded.dy = area->dy;
  117. modded.width = area->width;
  118. modded.height = area->height;
  119. if (info->state != FBINFO_STATE_RUNNING)
  120. return;
  121. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  122. cfb_copyarea(info, area);
  123. return;
  124. }
  125. radeon_fixup_offset(rinfo);
  126. vxres = info->var.xres_virtual;
  127. vyres = info->var.yres_virtual;
  128. if(!modded.width || !modded.height ||
  129. modded.sx >= vxres || modded.sy >= vyres ||
  130. modded.dx >= vxres || modded.dy >= vyres)
  131. return;
  132. if(modded.sx + modded.width > vxres) modded.width = vxres - modded.sx;
  133. if(modded.dx + modded.width > vxres) modded.width = vxres - modded.dx;
  134. if(modded.sy + modded.height > vyres) modded.height = vyres - modded.sy;
  135. if(modded.dy + modded.height > vyres) modded.height = vyres - modded.dy;
  136. radeonfb_prim_copyarea(rinfo, &modded);
  137. }
  138. void radeonfb_imageblit(struct fb_info *info, const struct fb_image *image)
  139. {
  140. struct radeonfb_info *rinfo = info->par;
  141. if (info->state != FBINFO_STATE_RUNNING)
  142. return;
  143. radeon_engine_idle();
  144. cfb_imageblit(info, image);
  145. }
  146. int radeonfb_sync(struct fb_info *info)
  147. {
  148. struct radeonfb_info *rinfo = info->par;
  149. if (info->state != FBINFO_STATE_RUNNING)
  150. return 0;
  151. radeon_engine_idle();
  152. return 0;
  153. }
  154. void radeonfb_engine_reset(struct radeonfb_info *rinfo)
  155. {
  156. u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
  157. u32 host_path_cntl;
  158. radeon_engine_flush (rinfo);
  159. clock_cntl_index = INREG(CLOCK_CNTL_INDEX);
  160. mclk_cntl = INPLL(MCLK_CNTL);
  161. OUTPLL(MCLK_CNTL, (mclk_cntl |
  162. FORCEON_MCLKA |
  163. FORCEON_MCLKB |
  164. FORCEON_YCLKA |
  165. FORCEON_YCLKB |
  166. FORCEON_MC |
  167. FORCEON_AIC));
  168. host_path_cntl = INREG(HOST_PATH_CNTL);
  169. rbbm_soft_reset = INREG(RBBM_SOFT_RESET);
  170. if (IS_R300_VARIANT(rinfo)) {
  171. u32 tmp;
  172. OUTREG(RBBM_SOFT_RESET, (rbbm_soft_reset |
  173. SOFT_RESET_CP |
  174. SOFT_RESET_HI |
  175. SOFT_RESET_E2));
  176. INREG(RBBM_SOFT_RESET);
  177. OUTREG(RBBM_SOFT_RESET, 0);
  178. tmp = INREG(RB2D_DSTCACHE_MODE);
  179. OUTREG(RB2D_DSTCACHE_MODE, tmp | (1 << 17)); /* FIXME */
  180. } else {
  181. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset |
  182. SOFT_RESET_CP |
  183. SOFT_RESET_HI |
  184. SOFT_RESET_SE |
  185. SOFT_RESET_RE |
  186. SOFT_RESET_PP |
  187. SOFT_RESET_E2 |
  188. SOFT_RESET_RB);
  189. INREG(RBBM_SOFT_RESET);
  190. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset & (u32)
  191. ~(SOFT_RESET_CP |
  192. SOFT_RESET_HI |
  193. SOFT_RESET_SE |
  194. SOFT_RESET_RE |
  195. SOFT_RESET_PP |
  196. SOFT_RESET_E2 |
  197. SOFT_RESET_RB));
  198. INREG(RBBM_SOFT_RESET);
  199. }
  200. OUTREG(HOST_PATH_CNTL, host_path_cntl | HDP_SOFT_RESET);
  201. INREG(HOST_PATH_CNTL);
  202. OUTREG(HOST_PATH_CNTL, host_path_cntl);
  203. if (!IS_R300_VARIANT(rinfo))
  204. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset);
  205. OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index);
  206. OUTPLL(MCLK_CNTL, mclk_cntl);
  207. }
  208. void radeonfb_engine_init (struct radeonfb_info *rinfo)
  209. {
  210. unsigned long temp;
  211. /* disable 3D engine */
  212. OUTREG(RB3D_CNTL, 0);
  213. radeonfb_engine_reset(rinfo);
  214. radeon_fifo_wait (1);
  215. if (IS_R300_VARIANT(rinfo)) {
  216. OUTREG(RB2D_DSTCACHE_MODE, INREG(RB2D_DSTCACHE_MODE) |
  217. RB2D_DC_AUTOFLUSH_ENABLE |
  218. RB2D_DC_DC_DISABLE_IGNORE_PE);
  219. } else {
  220. /* This needs to be double checked with ATI. Latest X driver
  221. * completely "forgets" to set this register on < r3xx, and
  222. * we used to just write 0 there... I'll keep the 0 and update
  223. * that when we have sorted things out on X side.
  224. */
  225. OUTREG(RB2D_DSTCACHE_MODE, 0);
  226. }
  227. radeon_fifo_wait (3);
  228. /* We re-read MC_FB_LOCATION from card as it can have been
  229. * modified by XFree drivers (ouch !)
  230. */
  231. rinfo->fb_local_base = INREG(MC_FB_LOCATION) << 16;
  232. OUTREG(DEFAULT_PITCH_OFFSET, (rinfo->pitch << 0x16) |
  233. (rinfo->fb_local_base >> 10));
  234. OUTREG(DST_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
  235. OUTREG(SRC_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
  236. radeon_fifo_wait (1);
  237. #if defined(__BIG_ENDIAN)
  238. OUTREGP(DP_DATATYPE, HOST_BIG_ENDIAN_EN, ~HOST_BIG_ENDIAN_EN);
  239. #else
  240. OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN);
  241. #endif
  242. radeon_fifo_wait (2);
  243. OUTREG(DEFAULT_SC_TOP_LEFT, 0);
  244. OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX |
  245. DEFAULT_SC_BOTTOM_MAX));
  246. temp = radeon_get_dstbpp(rinfo->depth);
  247. rinfo->dp_gui_master_cntl = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS);
  248. radeon_fifo_wait (1);
  249. OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl |
  250. GMC_BRUSH_SOLID_COLOR |
  251. GMC_SRC_DATATYPE_COLOR));
  252. radeon_fifo_wait (7);
  253. /* clear line drawing regs */
  254. OUTREG(DST_LINE_START, 0);
  255. OUTREG(DST_LINE_END, 0);
  256. /* set brush color regs */
  257. OUTREG(DP_BRUSH_FRGD_CLR, 0xffffffff);
  258. OUTREG(DP_BRUSH_BKGD_CLR, 0x00000000);
  259. /* set source color regs */
  260. OUTREG(DP_SRC_FRGD_CLR, 0xffffffff);
  261. OUTREG(DP_SRC_BKGD_CLR, 0x00000000);
  262. /* default write mask */
  263. OUTREG(DP_WRITE_MSK, 0xffffffff);
  264. radeon_engine_idle ();
  265. }