matroxfb_accel.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /*
  2. *
  3. * Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200 and G400
  4. *
  5. * (c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>
  6. *
  7. * Version: 1.65 2002/08/14
  8. *
  9. * MTRR stuff: 1998 Tom Rini <trini@kernel.crashing.org>
  10. *
  11. * Contributors: "menion?" <menion@mindless.com>
  12. * Betatesting, fixes, ideas
  13. *
  14. * "Kurt Garloff" <garloff@suse.de>
  15. * Betatesting, fixes, ideas, videomodes, videomodes timmings
  16. *
  17. * "Tom Rini" <trini@kernel.crashing.org>
  18. * MTRR stuff, PPC cleanups, betatesting, fixes, ideas
  19. *
  20. * "Bibek Sahu" <scorpio@dodds.net>
  21. * Access device through readb|w|l and write b|w|l
  22. * Extensive debugging stuff
  23. *
  24. * "Daniel Haun" <haund@usa.net>
  25. * Testing, hardware cursor fixes
  26. *
  27. * "Scott Wood" <sawst46+@pitt.edu>
  28. * Fixes
  29. *
  30. * "Gerd Knorr" <kraxel@goldbach.isdn.cs.tu-berlin.de>
  31. * Betatesting
  32. *
  33. * "Kelly French" <targon@hazmat.com>
  34. * "Fernando Herrera" <fherrera@eurielec.etsit.upm.es>
  35. * Betatesting, bug reporting
  36. *
  37. * "Pablo Bianucci" <pbian@pccp.com.ar>
  38. * Fixes, ideas, betatesting
  39. *
  40. * "Inaky Perez Gonzalez" <inaky@peloncho.fis.ucm.es>
  41. * Fixes, enhandcements, ideas, betatesting
  42. *
  43. * "Ryuichi Oikawa" <roikawa@rr.iiij4u.or.jp>
  44. * PPC betatesting, PPC support, backward compatibility
  45. *
  46. * "Paul Womar" <Paul@pwomar.demon.co.uk>
  47. * "Owen Waller" <O.Waller@ee.qub.ac.uk>
  48. * PPC betatesting
  49. *
  50. * "Thomas Pornin" <pornin@bolet.ens.fr>
  51. * Alpha betatesting
  52. *
  53. * "Pieter van Leuven" <pvl@iae.nl>
  54. * "Ulf Jaenicke-Roessler" <ujr@physik.phy.tu-dresden.de>
  55. * G100 testing
  56. *
  57. * "H. Peter Arvin" <hpa@transmeta.com>
  58. * Ideas
  59. *
  60. * "Cort Dougan" <cort@cs.nmt.edu>
  61. * CHRP fixes and PReP cleanup
  62. *
  63. * "Mark Vojkovich" <mvojkovi@ucsd.edu>
  64. * G400 support
  65. *
  66. * (following author is not in any relation with this code, but his code
  67. * is included in this driver)
  68. *
  69. * Based on framebuffer driver for VBE 2.0 compliant graphic boards
  70. * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
  71. *
  72. * (following author is not in any relation with this code, but his ideas
  73. * were used when writing this driver)
  74. *
  75. * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk>
  76. *
  77. */
  78. #include "matroxfb_accel.h"
  79. #include "matroxfb_DAC1064.h"
  80. #include "matroxfb_Ti3026.h"
  81. #include "matroxfb_misc.h"
  82. #define curr_ydstorg(x) ACCESS_FBINFO2(x, curr.ydstorg.pixels)
  83. #define mga_ydstlen(y,l) mga_outl(M_YDSTLEN | M_EXEC, ((y) << 16) | (l))
  84. static inline void matrox_cfb4_pal(u_int32_t* pal) {
  85. unsigned int i;
  86. for (i = 0; i < 16; i++) {
  87. pal[i] = i * 0x11111111U;
  88. }
  89. }
  90. static inline void matrox_cfb8_pal(u_int32_t* pal) {
  91. unsigned int i;
  92. for (i = 0; i < 16; i++) {
  93. pal[i] = i * 0x01010101U;
  94. }
  95. }
  96. static void matroxfb_copyarea(struct fb_info* info, const struct fb_copyarea* area);
  97. static void matroxfb_fillrect(struct fb_info* info, const struct fb_fillrect* rect);
  98. static void matroxfb_imageblit(struct fb_info* info, const struct fb_image* image);
  99. static void matroxfb_cfb4_fillrect(struct fb_info* info, const struct fb_fillrect* rect);
  100. static void matroxfb_cfb4_copyarea(struct fb_info* info, const struct fb_copyarea* area);
  101. void matrox_cfbX_init(WPMINFO2) {
  102. u_int32_t maccess;
  103. u_int32_t mpitch;
  104. u_int32_t mopmode;
  105. int accel;
  106. DBG(__func__)
  107. mpitch = ACCESS_FBINFO(fbcon).var.xres_virtual;
  108. ACCESS_FBINFO(fbops).fb_copyarea = cfb_copyarea;
  109. ACCESS_FBINFO(fbops).fb_fillrect = cfb_fillrect;
  110. ACCESS_FBINFO(fbops).fb_imageblit = cfb_imageblit;
  111. ACCESS_FBINFO(fbops).fb_cursor = NULL;
  112. accel = (ACCESS_FBINFO(fbcon).var.accel_flags & FB_ACCELF_TEXT) == FB_ACCELF_TEXT;
  113. switch (ACCESS_FBINFO(fbcon).var.bits_per_pixel) {
  114. case 4: maccess = 0x00000000; /* accelerate as 8bpp video */
  115. mpitch = (mpitch >> 1) | 0x8000; /* disable linearization */
  116. mopmode = M_OPMODE_4BPP;
  117. matrox_cfb4_pal(ACCESS_FBINFO(cmap));
  118. if (accel && !(mpitch & 1)) {
  119. ACCESS_FBINFO(fbops).fb_copyarea = matroxfb_cfb4_copyarea;
  120. ACCESS_FBINFO(fbops).fb_fillrect = matroxfb_cfb4_fillrect;
  121. }
  122. break;
  123. case 8: maccess = 0x00000000;
  124. mopmode = M_OPMODE_8BPP;
  125. matrox_cfb8_pal(ACCESS_FBINFO(cmap));
  126. if (accel) {
  127. ACCESS_FBINFO(fbops).fb_copyarea = matroxfb_copyarea;
  128. ACCESS_FBINFO(fbops).fb_fillrect = matroxfb_fillrect;
  129. ACCESS_FBINFO(fbops).fb_imageblit = matroxfb_imageblit;
  130. }
  131. break;
  132. case 16: if (ACCESS_FBINFO(fbcon).var.green.length == 5)
  133. maccess = 0xC0000001;
  134. else
  135. maccess = 0x40000001;
  136. mopmode = M_OPMODE_16BPP;
  137. if (accel) {
  138. ACCESS_FBINFO(fbops).fb_copyarea = matroxfb_copyarea;
  139. ACCESS_FBINFO(fbops).fb_fillrect = matroxfb_fillrect;
  140. ACCESS_FBINFO(fbops).fb_imageblit = matroxfb_imageblit;
  141. }
  142. break;
  143. case 24: maccess = 0x00000003;
  144. mopmode = M_OPMODE_24BPP;
  145. if (accel) {
  146. ACCESS_FBINFO(fbops).fb_copyarea = matroxfb_copyarea;
  147. ACCESS_FBINFO(fbops).fb_fillrect = matroxfb_fillrect;
  148. ACCESS_FBINFO(fbops).fb_imageblit = matroxfb_imageblit;
  149. }
  150. break;
  151. case 32: maccess = 0x00000002;
  152. mopmode = M_OPMODE_32BPP;
  153. if (accel) {
  154. ACCESS_FBINFO(fbops).fb_copyarea = matroxfb_copyarea;
  155. ACCESS_FBINFO(fbops).fb_fillrect = matroxfb_fillrect;
  156. ACCESS_FBINFO(fbops).fb_imageblit = matroxfb_imageblit;
  157. }
  158. break;
  159. default: maccess = 0x00000000;
  160. mopmode = 0x00000000;
  161. break; /* turn off acceleration!!! */
  162. }
  163. mga_fifo(8);
  164. mga_outl(M_PITCH, mpitch);
  165. mga_outl(M_YDSTORG, curr_ydstorg(MINFO));
  166. if (ACCESS_FBINFO(capable.plnwt))
  167. mga_outl(M_PLNWT, -1);
  168. if (ACCESS_FBINFO(capable.srcorg)) {
  169. mga_outl(M_SRCORG, 0);
  170. mga_outl(M_DSTORG, 0);
  171. }
  172. mga_outl(M_OPMODE, mopmode);
  173. mga_outl(M_CXBNDRY, 0xFFFF0000);
  174. mga_outl(M_YTOP, 0);
  175. mga_outl(M_YBOT, 0x01FFFFFF);
  176. mga_outl(M_MACCESS, maccess);
  177. ACCESS_FBINFO(accel.m_dwg_rect) = M_DWG_TRAP | M_DWG_SOLID | M_DWG_ARZERO | M_DWG_SGNZERO | M_DWG_SHIFTZERO;
  178. if (isMilleniumII(MINFO)) ACCESS_FBINFO(accel.m_dwg_rect) |= M_DWG_TRANSC;
  179. ACCESS_FBINFO(accel.m_opmode) = mopmode;
  180. }
  181. EXPORT_SYMBOL(matrox_cfbX_init);
  182. static void matrox_accel_bmove(WPMINFO int vxres, int sy, int sx, int dy, int dx, int height, int width) {
  183. int start, end;
  184. CRITFLAGS
  185. DBG(__func__)
  186. CRITBEGIN
  187. if ((dy < sy) || ((dy == sy) && (dx <= sx))) {
  188. mga_fifo(2);
  189. mga_outl(M_DWGCTL, M_DWG_BITBLT | M_DWG_SHIFTZERO | M_DWG_SGNZERO |
  190. M_DWG_BFCOL | M_DWG_REPLACE);
  191. mga_outl(M_AR5, vxres);
  192. width--;
  193. start = sy*vxres+sx+curr_ydstorg(MINFO);
  194. end = start+width;
  195. } else {
  196. mga_fifo(3);
  197. mga_outl(M_DWGCTL, M_DWG_BITBLT | M_DWG_SHIFTZERO | M_DWG_BFCOL | M_DWG_REPLACE);
  198. mga_outl(M_SGN, 5);
  199. mga_outl(M_AR5, -vxres);
  200. width--;
  201. end = (sy+height-1)*vxres+sx+curr_ydstorg(MINFO);
  202. start = end+width;
  203. dy += height-1;
  204. }
  205. mga_fifo(4);
  206. mga_outl(M_AR0, end);
  207. mga_outl(M_AR3, start);
  208. mga_outl(M_FXBNDRY, ((dx+width)<<16) | dx);
  209. mga_ydstlen(dy, height);
  210. WaitTillIdle();
  211. CRITEND
  212. }
  213. static void matrox_accel_bmove_lin(WPMINFO int vxres, int sy, int sx, int dy, int dx, int height, int width) {
  214. int start, end;
  215. CRITFLAGS
  216. DBG(__func__)
  217. CRITBEGIN
  218. if ((dy < sy) || ((dy == sy) && (dx <= sx))) {
  219. mga_fifo(2);
  220. mga_outl(M_DWGCTL, M_DWG_BITBLT | M_DWG_SHIFTZERO | M_DWG_SGNZERO |
  221. M_DWG_BFCOL | M_DWG_REPLACE);
  222. mga_outl(M_AR5, vxres);
  223. width--;
  224. start = sy*vxres+sx+curr_ydstorg(MINFO);
  225. end = start+width;
  226. } else {
  227. mga_fifo(3);
  228. mga_outl(M_DWGCTL, M_DWG_BITBLT | M_DWG_SHIFTZERO | M_DWG_BFCOL | M_DWG_REPLACE);
  229. mga_outl(M_SGN, 5);
  230. mga_outl(M_AR5, -vxres);
  231. width--;
  232. end = (sy+height-1)*vxres+sx+curr_ydstorg(MINFO);
  233. start = end+width;
  234. dy += height-1;
  235. }
  236. mga_fifo(5);
  237. mga_outl(M_AR0, end);
  238. mga_outl(M_AR3, start);
  239. mga_outl(M_FXBNDRY, ((dx+width)<<16) | dx);
  240. mga_outl(M_YDST, dy*vxres >> 5);
  241. mga_outl(M_LEN | M_EXEC, height);
  242. WaitTillIdle();
  243. CRITEND
  244. }
  245. static void matroxfb_cfb4_copyarea(struct fb_info* info, const struct fb_copyarea* area) {
  246. MINFO_FROM_INFO(info);
  247. if ((area->sx | area->dx | area->width) & 1)
  248. cfb_copyarea(info, area);
  249. else
  250. matrox_accel_bmove_lin(PMINFO ACCESS_FBINFO(fbcon.var.xres_virtual) >> 1, area->sy, area->sx >> 1, area->dy, area->dx >> 1, area->height, area->width >> 1);
  251. }
  252. static void matroxfb_copyarea(struct fb_info* info, const struct fb_copyarea* area) {
  253. MINFO_FROM_INFO(info);
  254. matrox_accel_bmove(PMINFO ACCESS_FBINFO(fbcon.var.xres_virtual), area->sy, area->sx, area->dy, area->dx, area->height, area->width);
  255. }
  256. static void matroxfb_accel_clear(WPMINFO u_int32_t color, int sy, int sx, int height,
  257. int width) {
  258. CRITFLAGS
  259. DBG(__func__)
  260. CRITBEGIN
  261. mga_fifo(5);
  262. mga_outl(M_DWGCTL, ACCESS_FBINFO(accel.m_dwg_rect) | M_DWG_REPLACE);
  263. mga_outl(M_FCOL, color);
  264. mga_outl(M_FXBNDRY, ((sx + width) << 16) | sx);
  265. mga_ydstlen(sy, height);
  266. WaitTillIdle();
  267. CRITEND
  268. }
  269. static void matroxfb_fillrect(struct fb_info* info, const struct fb_fillrect* rect) {
  270. MINFO_FROM_INFO(info);
  271. switch (rect->rop) {
  272. case ROP_COPY:
  273. matroxfb_accel_clear(PMINFO ((u_int32_t*)info->pseudo_palette)[rect->color], rect->dy, rect->dx, rect->height, rect->width);
  274. break;
  275. }
  276. }
  277. static void matroxfb_cfb4_clear(WPMINFO u_int32_t bgx, int sy, int sx, int height, int width) {
  278. int whattodo;
  279. CRITFLAGS
  280. DBG(__func__)
  281. CRITBEGIN
  282. whattodo = 0;
  283. if (sx & 1) {
  284. sx ++;
  285. if (!width) return;
  286. width --;
  287. whattodo = 1;
  288. }
  289. if (width & 1) {
  290. whattodo |= 2;
  291. }
  292. width >>= 1;
  293. sx >>= 1;
  294. if (width) {
  295. mga_fifo(5);
  296. mga_outl(M_DWGCTL, ACCESS_FBINFO(accel.m_dwg_rect) | M_DWG_REPLACE2);
  297. mga_outl(M_FCOL, bgx);
  298. mga_outl(M_FXBNDRY, ((sx + width) << 16) | sx);
  299. mga_outl(M_YDST, sy * ACCESS_FBINFO(fbcon).var.xres_virtual >> 6);
  300. mga_outl(M_LEN | M_EXEC, height);
  301. WaitTillIdle();
  302. }
  303. if (whattodo) {
  304. u_int32_t step = ACCESS_FBINFO(fbcon).var.xres_virtual >> 1;
  305. vaddr_t vbase = ACCESS_FBINFO(video.vbase);
  306. if (whattodo & 1) {
  307. unsigned int uaddr = sy * step + sx - 1;
  308. u_int32_t loop;
  309. u_int8_t bgx2 = bgx & 0xF0;
  310. for (loop = height; loop > 0; loop --) {
  311. mga_writeb(vbase, uaddr, (mga_readb(vbase, uaddr) & 0x0F) | bgx2);
  312. uaddr += step;
  313. }
  314. }
  315. if (whattodo & 2) {
  316. unsigned int uaddr = sy * step + sx + width;
  317. u_int32_t loop;
  318. u_int8_t bgx2 = bgx & 0x0F;
  319. for (loop = height; loop > 0; loop --) {
  320. mga_writeb(vbase, uaddr, (mga_readb(vbase, uaddr) & 0xF0) | bgx2);
  321. uaddr += step;
  322. }
  323. }
  324. }
  325. CRITEND
  326. }
  327. static void matroxfb_cfb4_fillrect(struct fb_info* info, const struct fb_fillrect* rect) {
  328. MINFO_FROM_INFO(info);
  329. switch (rect->rop) {
  330. case ROP_COPY:
  331. matroxfb_cfb4_clear(PMINFO ((u_int32_t*)info->pseudo_palette)[rect->color], rect->dy, rect->dx, rect->height, rect->width);
  332. break;
  333. }
  334. }
  335. static void matroxfb_1bpp_imageblit(WPMINFO u_int32_t fgx, u_int32_t bgx,
  336. const u_int8_t* chardata, int width, int height, int yy, int xx) {
  337. u_int32_t step;
  338. u_int32_t ydstlen;
  339. u_int32_t xlen;
  340. u_int32_t ar0;
  341. u_int32_t charcell;
  342. u_int32_t fxbndry;
  343. vaddr_t mmio;
  344. int easy;
  345. CRITFLAGS
  346. DBG_HEAVY(__func__);
  347. step = (width + 7) >> 3;
  348. charcell = height * step;
  349. xlen = (charcell + 3) & ~3;
  350. ydstlen = (yy << 16) | height;
  351. if (width == step << 3) {
  352. ar0 = height * width - 1;
  353. easy = 1;
  354. } else {
  355. ar0 = width - 1;
  356. easy = 0;
  357. }
  358. CRITBEGIN
  359. mga_fifo(3);
  360. if (easy)
  361. mga_outl(M_DWGCTL, M_DWG_ILOAD | M_DWG_SGNZERO | M_DWG_SHIFTZERO | M_DWG_BMONOWF | M_DWG_LINEAR | M_DWG_REPLACE);
  362. else
  363. mga_outl(M_DWGCTL, M_DWG_ILOAD | M_DWG_SGNZERO | M_DWG_SHIFTZERO | M_DWG_BMONOWF | M_DWG_REPLACE);
  364. mga_outl(M_FCOL, fgx);
  365. mga_outl(M_BCOL, bgx);
  366. fxbndry = ((xx + width - 1) << 16) | xx;
  367. mmio = ACCESS_FBINFO(mmio.vbase);
  368. mga_fifo(6);
  369. mga_writel(mmio, M_FXBNDRY, fxbndry);
  370. mga_writel(mmio, M_AR0, ar0);
  371. mga_writel(mmio, M_AR3, 0);
  372. if (easy) {
  373. mga_writel(mmio, M_YDSTLEN | M_EXEC, ydstlen);
  374. mga_memcpy_toio(mmio, chardata, xlen);
  375. } else {
  376. mga_writel(mmio, M_AR5, 0);
  377. mga_writel(mmio, M_YDSTLEN | M_EXEC, ydstlen);
  378. if ((step & 3) == 0) {
  379. /* Great. Source has 32bit aligned lines, so we can feed them
  380. directly to the accelerator. */
  381. mga_memcpy_toio(mmio, chardata, charcell);
  382. } else if (step == 1) {
  383. /* Special case for 1..8bit widths */
  384. while (height--) {
  385. #if defined(__BIG_ENDIAN)
  386. fb_writel((*chardata) << 24, mmio.vaddr);
  387. #else
  388. fb_writel(*chardata, mmio.vaddr);
  389. #endif
  390. chardata++;
  391. }
  392. } else if (step == 2) {
  393. /* Special case for 9..15bit widths */
  394. while (height--) {
  395. #if defined(__BIG_ENDIAN)
  396. fb_writel((*(u_int16_t*)chardata) << 16, mmio.vaddr);
  397. #else
  398. fb_writel(*(u_int16_t*)chardata, mmio.vaddr);
  399. #endif
  400. chardata += 2;
  401. }
  402. } else {
  403. /* Tell... well, why bother... */
  404. while (height--) {
  405. size_t i;
  406. for (i = 0; i < step; i += 4) {
  407. /* Hope that there are at least three readable bytes beyond the end of bitmap */
  408. fb_writel(get_unaligned((u_int32_t*)(chardata + i)),mmio.vaddr);
  409. }
  410. chardata += step;
  411. }
  412. }
  413. }
  414. WaitTillIdle();
  415. CRITEND
  416. }
  417. static void matroxfb_imageblit(struct fb_info* info, const struct fb_image* image) {
  418. MINFO_FROM_INFO(info);
  419. DBG_HEAVY(__func__);
  420. if (image->depth == 1) {
  421. u_int32_t fgx, bgx;
  422. fgx = ((u_int32_t*)info->pseudo_palette)[image->fg_color];
  423. bgx = ((u_int32_t*)info->pseudo_palette)[image->bg_color];
  424. matroxfb_1bpp_imageblit(PMINFO fgx, bgx, image->data, image->width, image->height, image->dy, image->dx);
  425. } else {
  426. /* Danger! image->depth is useless: logo painting code always
  427. passes framebuffer color depth here, although logo data are
  428. always 8bpp and info->pseudo_palette is changed to contain
  429. logo palette to be used (but only for true/direct-color... sic...).
  430. So do it completely in software... */
  431. cfb_imageblit(info, image);
  432. }
  433. }
  434. MODULE_LICENSE("GPL");