radeon_accel.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 (rinfo->family == CHIP_FAMILY_R300 ||
  171. rinfo->family == CHIP_FAMILY_R350 ||
  172. rinfo->family == CHIP_FAMILY_RV350) {
  173. u32 tmp;
  174. OUTREG(RBBM_SOFT_RESET, (rbbm_soft_reset |
  175. SOFT_RESET_CP |
  176. SOFT_RESET_HI |
  177. SOFT_RESET_E2));
  178. INREG(RBBM_SOFT_RESET);
  179. OUTREG(RBBM_SOFT_RESET, 0);
  180. tmp = INREG(RB2D_DSTCACHE_MODE);
  181. OUTREG(RB2D_DSTCACHE_MODE, tmp | (1 << 17)); /* FIXME */
  182. } else {
  183. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset |
  184. SOFT_RESET_CP |
  185. SOFT_RESET_HI |
  186. SOFT_RESET_SE |
  187. SOFT_RESET_RE |
  188. SOFT_RESET_PP |
  189. SOFT_RESET_E2 |
  190. SOFT_RESET_RB);
  191. INREG(RBBM_SOFT_RESET);
  192. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset & (u32)
  193. ~(SOFT_RESET_CP |
  194. SOFT_RESET_HI |
  195. SOFT_RESET_SE |
  196. SOFT_RESET_RE |
  197. SOFT_RESET_PP |
  198. SOFT_RESET_E2 |
  199. SOFT_RESET_RB));
  200. INREG(RBBM_SOFT_RESET);
  201. }
  202. OUTREG(HOST_PATH_CNTL, host_path_cntl | HDP_SOFT_RESET);
  203. INREG(HOST_PATH_CNTL);
  204. OUTREG(HOST_PATH_CNTL, host_path_cntl);
  205. if (rinfo->family != CHIP_FAMILY_R300 &&
  206. rinfo->family != CHIP_FAMILY_R350 &&
  207. rinfo->family != CHIP_FAMILY_RV350)
  208. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset);
  209. OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index);
  210. OUTPLL(MCLK_CNTL, mclk_cntl);
  211. }
  212. void radeonfb_engine_init (struct radeonfb_info *rinfo)
  213. {
  214. unsigned long temp;
  215. /* disable 3D engine */
  216. OUTREG(RB3D_CNTL, 0);
  217. radeonfb_engine_reset(rinfo);
  218. radeon_fifo_wait (1);
  219. if ((rinfo->family != CHIP_FAMILY_R300) &&
  220. (rinfo->family != CHIP_FAMILY_R350) &&
  221. (rinfo->family != CHIP_FAMILY_RV350))
  222. OUTREG(RB2D_DSTCACHE_MODE, 0);
  223. radeon_fifo_wait (3);
  224. /* We re-read MC_FB_LOCATION from card as it can have been
  225. * modified by XFree drivers (ouch !)
  226. */
  227. rinfo->fb_local_base = INREG(MC_FB_LOCATION) << 16;
  228. OUTREG(DEFAULT_PITCH_OFFSET, (rinfo->pitch << 0x16) |
  229. (rinfo->fb_local_base >> 10));
  230. OUTREG(DST_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
  231. OUTREG(SRC_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
  232. radeon_fifo_wait (1);
  233. #if defined(__BIG_ENDIAN)
  234. OUTREGP(DP_DATATYPE, HOST_BIG_ENDIAN_EN, ~HOST_BIG_ENDIAN_EN);
  235. #else
  236. OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN);
  237. #endif
  238. radeon_fifo_wait (2);
  239. OUTREG(DEFAULT_SC_TOP_LEFT, 0);
  240. OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX |
  241. DEFAULT_SC_BOTTOM_MAX));
  242. temp = radeon_get_dstbpp(rinfo->depth);
  243. rinfo->dp_gui_master_cntl = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS);
  244. radeon_fifo_wait (1);
  245. OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl |
  246. GMC_BRUSH_SOLID_COLOR |
  247. GMC_SRC_DATATYPE_COLOR));
  248. radeon_fifo_wait (7);
  249. /* clear line drawing regs */
  250. OUTREG(DST_LINE_START, 0);
  251. OUTREG(DST_LINE_END, 0);
  252. /* set brush color regs */
  253. OUTREG(DP_BRUSH_FRGD_CLR, 0xffffffff);
  254. OUTREG(DP_BRUSH_BKGD_CLR, 0x00000000);
  255. /* set source color regs */
  256. OUTREG(DP_SRC_FRGD_CLR, 0xffffffff);
  257. OUTREG(DP_SRC_BKGD_CLR, 0x00000000);
  258. /* default write mask */
  259. OUTREG(DP_WRITE_MSK, 0xffffffff);
  260. radeon_engine_idle ();
  261. }