radeon_accel.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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(DST_Y_X, (region->dy << 16) | region->dx);
  51. OUTREG(DST_WIDTH_HEIGHT, (region->width << 16) | region->height);
  52. }
  53. void radeonfb_fillrect(struct fb_info *info, const struct fb_fillrect *region)
  54. {
  55. struct radeonfb_info *rinfo = info->par;
  56. struct fb_fillrect modded;
  57. int vxres, vyres;
  58. if (info->state != FBINFO_STATE_RUNNING)
  59. return;
  60. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  61. cfb_fillrect(info, region);
  62. return;
  63. }
  64. radeon_fixup_offset(rinfo);
  65. vxres = info->var.xres_virtual;
  66. vyres = info->var.yres_virtual;
  67. memcpy(&modded, region, sizeof(struct fb_fillrect));
  68. if(!modded.width || !modded.height ||
  69. modded.dx >= vxres || modded.dy >= vyres)
  70. return;
  71. if(modded.dx + modded.width > vxres) modded.width = vxres - modded.dx;
  72. if(modded.dy + modded.height > vyres) modded.height = vyres - modded.dy;
  73. radeonfb_prim_fillrect(rinfo, &modded);
  74. }
  75. static void radeonfb_prim_copyarea(struct radeonfb_info *rinfo,
  76. const struct fb_copyarea *area)
  77. {
  78. int xdir, ydir;
  79. u32 sx, sy, dx, dy, w, h;
  80. w = area->width; h = area->height;
  81. dx = area->dx; dy = area->dy;
  82. sx = area->sx; sy = area->sy;
  83. xdir = sx - dx;
  84. ydir = sy - dy;
  85. if ( xdir < 0 ) { sx += w-1; dx += w-1; }
  86. if ( ydir < 0 ) { sy += h-1; dy += h-1; }
  87. radeon_fifo_wait(3);
  88. OUTREG(DP_GUI_MASTER_CNTL,
  89. rinfo->dp_gui_master_cntl /* i.e. GMC_DST_32BPP */
  90. | GMC_BRUSH_NONE
  91. | GMC_SRC_DSTCOLOR
  92. | ROP3_S
  93. | DP_SRC_SOURCE_MEMORY );
  94. OUTREG(DP_WRITE_MSK, 0xffffffff);
  95. OUTREG(DP_CNTL, (xdir>=0 ? DST_X_LEFT_TO_RIGHT : 0)
  96. | (ydir>=0 ? DST_Y_TOP_TO_BOTTOM : 0));
  97. radeon_fifo_wait(3);
  98. OUTREG(SRC_Y_X, (sy << 16) | sx);
  99. OUTREG(DST_Y_X, (dy << 16) | dx);
  100. OUTREG(DST_HEIGHT_WIDTH, (h << 16) | w);
  101. }
  102. void radeonfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  103. {
  104. struct radeonfb_info *rinfo = info->par;
  105. struct fb_copyarea modded;
  106. u32 vxres, vyres;
  107. modded.sx = area->sx;
  108. modded.sy = area->sy;
  109. modded.dx = area->dx;
  110. modded.dy = area->dy;
  111. modded.width = area->width;
  112. modded.height = area->height;
  113. if (info->state != FBINFO_STATE_RUNNING)
  114. return;
  115. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  116. cfb_copyarea(info, area);
  117. return;
  118. }
  119. radeon_fixup_offset(rinfo);
  120. vxres = info->var.xres_virtual;
  121. vyres = info->var.yres_virtual;
  122. if(!modded.width || !modded.height ||
  123. modded.sx >= vxres || modded.sy >= vyres ||
  124. modded.dx >= vxres || modded.dy >= vyres)
  125. return;
  126. if(modded.sx + modded.width > vxres) modded.width = vxres - modded.sx;
  127. if(modded.dx + modded.width > vxres) modded.width = vxres - modded.dx;
  128. if(modded.sy + modded.height > vyres) modded.height = vyres - modded.sy;
  129. if(modded.dy + modded.height > vyres) modded.height = vyres - modded.dy;
  130. radeonfb_prim_copyarea(rinfo, &modded);
  131. }
  132. void radeonfb_imageblit(struct fb_info *info, const struct fb_image *image)
  133. {
  134. struct radeonfb_info *rinfo = info->par;
  135. if (info->state != FBINFO_STATE_RUNNING)
  136. return;
  137. radeon_engine_idle();
  138. cfb_imageblit(info, image);
  139. }
  140. int radeonfb_sync(struct fb_info *info)
  141. {
  142. struct radeonfb_info *rinfo = info->par;
  143. if (info->state != FBINFO_STATE_RUNNING)
  144. return 0;
  145. radeon_engine_idle();
  146. return 0;
  147. }
  148. void radeonfb_engine_reset(struct radeonfb_info *rinfo)
  149. {
  150. u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
  151. u32 host_path_cntl;
  152. radeon_engine_flush (rinfo);
  153. clock_cntl_index = INREG(CLOCK_CNTL_INDEX);
  154. mclk_cntl = INPLL(MCLK_CNTL);
  155. OUTPLL(MCLK_CNTL, (mclk_cntl |
  156. FORCEON_MCLKA |
  157. FORCEON_MCLKB |
  158. FORCEON_YCLKA |
  159. FORCEON_YCLKB |
  160. FORCEON_MC |
  161. FORCEON_AIC));
  162. host_path_cntl = INREG(HOST_PATH_CNTL);
  163. rbbm_soft_reset = INREG(RBBM_SOFT_RESET);
  164. if (rinfo->family == CHIP_FAMILY_R300 ||
  165. rinfo->family == CHIP_FAMILY_R350 ||
  166. rinfo->family == CHIP_FAMILY_RV350) {
  167. u32 tmp;
  168. OUTREG(RBBM_SOFT_RESET, (rbbm_soft_reset |
  169. SOFT_RESET_CP |
  170. SOFT_RESET_HI |
  171. SOFT_RESET_E2));
  172. INREG(RBBM_SOFT_RESET);
  173. OUTREG(RBBM_SOFT_RESET, 0);
  174. tmp = INREG(RB2D_DSTCACHE_MODE);
  175. OUTREG(RB2D_DSTCACHE_MODE, tmp | (1 << 17)); /* FIXME */
  176. } else {
  177. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset |
  178. SOFT_RESET_CP |
  179. SOFT_RESET_HI |
  180. SOFT_RESET_SE |
  181. SOFT_RESET_RE |
  182. SOFT_RESET_PP |
  183. SOFT_RESET_E2 |
  184. SOFT_RESET_RB);
  185. INREG(RBBM_SOFT_RESET);
  186. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset & (u32)
  187. ~(SOFT_RESET_CP |
  188. SOFT_RESET_HI |
  189. SOFT_RESET_SE |
  190. SOFT_RESET_RE |
  191. SOFT_RESET_PP |
  192. SOFT_RESET_E2 |
  193. SOFT_RESET_RB));
  194. INREG(RBBM_SOFT_RESET);
  195. }
  196. OUTREG(HOST_PATH_CNTL, host_path_cntl | HDP_SOFT_RESET);
  197. INREG(HOST_PATH_CNTL);
  198. OUTREG(HOST_PATH_CNTL, host_path_cntl);
  199. if (rinfo->family != CHIP_FAMILY_R300 ||
  200. rinfo->family != CHIP_FAMILY_R350 ||
  201. rinfo->family != CHIP_FAMILY_RV350)
  202. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset);
  203. OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index);
  204. OUTPLL(MCLK_CNTL, mclk_cntl);
  205. }
  206. void radeonfb_engine_init (struct radeonfb_info *rinfo)
  207. {
  208. unsigned long temp;
  209. /* disable 3D engine */
  210. OUTREG(RB3D_CNTL, 0);
  211. radeonfb_engine_reset(rinfo);
  212. radeon_fifo_wait (1);
  213. if ((rinfo->family != CHIP_FAMILY_R300) &&
  214. (rinfo->family != CHIP_FAMILY_R350) &&
  215. (rinfo->family != CHIP_FAMILY_RV350))
  216. OUTREG(RB2D_DSTCACHE_MODE, 0);
  217. radeon_fifo_wait (3);
  218. /* We re-read MC_FB_LOCATION from card as it can have been
  219. * modified by XFree drivers (ouch !)
  220. */
  221. rinfo->fb_local_base = INREG(MC_FB_LOCATION) << 16;
  222. OUTREG(DEFAULT_PITCH_OFFSET, (rinfo->pitch << 0x16) |
  223. (rinfo->fb_local_base >> 10));
  224. OUTREG(DST_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
  225. OUTREG(SRC_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
  226. radeon_fifo_wait (1);
  227. #if defined(__BIG_ENDIAN)
  228. OUTREGP(DP_DATATYPE, HOST_BIG_ENDIAN_EN, ~HOST_BIG_ENDIAN_EN);
  229. #else
  230. OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN);
  231. #endif
  232. radeon_fifo_wait (2);
  233. OUTREG(DEFAULT_SC_TOP_LEFT, 0);
  234. OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX |
  235. DEFAULT_SC_BOTTOM_MAX));
  236. temp = radeon_get_dstbpp(rinfo->depth);
  237. rinfo->dp_gui_master_cntl = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS);
  238. radeon_fifo_wait (1);
  239. OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl |
  240. GMC_BRUSH_SOLID_COLOR |
  241. GMC_SRC_DATATYPE_COLOR));
  242. radeon_fifo_wait (7);
  243. /* clear line drawing regs */
  244. OUTREG(DST_LINE_START, 0);
  245. OUTREG(DST_LINE_END, 0);
  246. /* set brush color regs */
  247. OUTREG(DP_BRUSH_FRGD_CLR, 0xffffffff);
  248. OUTREG(DP_BRUSH_BKGD_CLR, 0x00000000);
  249. /* set source color regs */
  250. OUTREG(DP_SRC_FRGD_CLR, 0xffffffff);
  251. OUTREG(DP_SRC_BKGD_CLR, 0x00000000);
  252. /* default write mask */
  253. OUTREG(DP_WRITE_MSK, 0xffffffff);
  254. radeon_engine_idle ();
  255. }