mb862xxfb_accel.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * drivers/mb862xx/mb862xxfb_accel.c
  4. *
  5. * Fujitsu Carmine/Coral-P(A)/Lime framebuffer driver acceleration support
  6. *
  7. * (C) 2007 Alexander Shishkin <virtuoso@slind.org>
  8. * (C) 2009 Valentin Sitdikov <v.sitdikov@gmail.com>
  9. * (C) 2009 Siemens AG
  10. */
  11. #include <linux/fb.h>
  12. #include <linux/delay.h>
  13. #include <linux/init.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/module.h>
  16. #include <linux/pci.h>
  17. #include <linux/slab.h>
  18. #include "mb862xxfb.h"
  19. #include "mb862xx_reg.h"
  20. #include "mb862xxfb_accel.h"
  21. static void mb862xxfb_write_fifo(u32 count, u32 *data, struct fb_info *info)
  22. {
  23. struct mb862xxfb_par *par = info->par;
  24. static u32 free;
  25. u32 total = 0;
  26. while (total < count) {
  27. if (free) {
  28. outreg(geo, GDC_GEO_REG_INPUT_FIFO, data[total]);
  29. total++;
  30. free--;
  31. } else {
  32. free = (u32) inreg(draw, GDC_REG_FIFO_COUNT);
  33. }
  34. }
  35. }
  36. static void mb86290fb_copyarea(struct fb_info *info,
  37. const struct fb_copyarea *area)
  38. {
  39. __u32 cmd[6];
  40. cmd[0] = (GDC_TYPE_SETREGISTER << 24) | (1 << 16) | GDC_REG_MODE_BITMAP;
  41. /* Set raster operation */
  42. cmd[1] = (2 << 7) | (GDC_ROP_COPY << 9);
  43. cmd[2] = GDC_TYPE_BLTCOPYP << 24;
  44. if (area->sx >= area->dx && area->sy >= area->dy)
  45. cmd[2] |= GDC_CMD_BLTCOPY_TOP_LEFT << 16;
  46. else if (area->sx >= area->dx && area->sy <= area->dy)
  47. cmd[2] |= GDC_CMD_BLTCOPY_BOTTOM_LEFT << 16;
  48. else if (area->sx <= area->dx && area->sy >= area->dy)
  49. cmd[2] |= GDC_CMD_BLTCOPY_TOP_RIGHT << 16;
  50. else
  51. cmd[2] |= GDC_CMD_BLTCOPY_BOTTOM_RIGHT << 16;
  52. cmd[3] = (area->sy << 16) | area->sx;
  53. cmd[4] = (area->dy << 16) | area->dx;
  54. cmd[5] = (area->height << 16) | area->width;
  55. mb862xxfb_write_fifo(6, cmd, info);
  56. }
  57. /*
  58. * Fill in the cmd array /GDC FIFO commands/ to draw a 1bit image.
  59. * Make sure cmd has enough room!
  60. */
  61. static void mb86290fb_imageblit1(u32 *cmd, u16 step, u16 dx, u16 dy,
  62. u16 width, u16 height, u32 fgcolor,
  63. u32 bgcolor, const struct fb_image *image,
  64. struct fb_info *info)
  65. {
  66. int i;
  67. unsigned const char *line;
  68. u16 bytes;
  69. /* set colors and raster operation regs */
  70. cmd[0] = (GDC_TYPE_SETREGISTER << 24) | (1 << 16) | GDC_REG_MODE_BITMAP;
  71. /* Set raster operation */
  72. cmd[1] = (2 << 7) | (GDC_ROP_COPY << 9);
  73. cmd[2] =
  74. (GDC_TYPE_SETCOLORREGISTER << 24) | (GDC_CMD_BODY_FORE_COLOR << 16);
  75. cmd[3] = fgcolor;
  76. cmd[4] =
  77. (GDC_TYPE_SETCOLORREGISTER << 24) | (GDC_CMD_BODY_BACK_COLOR << 16);
  78. cmd[5] = bgcolor;
  79. i = 0;
  80. line = image->data;
  81. bytes = (image->width + 7) >> 3;
  82. /* and the image */
  83. cmd[6] = (GDC_TYPE_DRAWBITMAPP << 24) |
  84. (GDC_CMD_BITMAP << 16) | (2 + (step * height));
  85. cmd[7] = (dy << 16) | dx;
  86. cmd[8] = (height << 16) | width;
  87. while (i < height) {
  88. memcpy(&cmd[9 + i * step], line, step << 2);
  89. #ifdef __LITTLE_ENDIAN
  90. {
  91. int k = 0;
  92. for (k = 0; k < step; k++)
  93. cmd[9 + i * step + k] =
  94. cpu_to_be32(cmd[9 + i * step + k]);
  95. }
  96. #endif
  97. line += bytes;
  98. i++;
  99. }
  100. }
  101. /*
  102. * Fill in the cmd array /GDC FIFO commands/ to draw a 8bit image.
  103. * Make sure cmd has enough room!
  104. */
  105. static void mb86290fb_imageblit8(u32 *cmd, u16 step, u16 dx, u16 dy,
  106. u16 width, u16 height, u32 fgcolor,
  107. u32 bgcolor, const struct fb_image *image,
  108. struct fb_info *info)
  109. {
  110. int i, j;
  111. unsigned const char *line, *ptr;
  112. u16 bytes;
  113. cmd[0] = (GDC_TYPE_DRAWBITMAPP << 24) |
  114. (GDC_CMD_BLT_DRAW << 16) | (2 + (height * step));
  115. cmd[1] = (dy << 16) | dx;
  116. cmd[2] = (height << 16) | width;
  117. i = 0;
  118. line = image->data;
  119. bytes = image->width;
  120. while (i < height) {
  121. ptr = line;
  122. for (j = 0; j < step; j++) {
  123. cmd[3 + i * step + j] =
  124. (((u32 *) (info->pseudo_palette))[*ptr]) & 0xffff;
  125. ptr++;
  126. cmd[3 + i * step + j] |=
  127. ((((u32 *) (info->
  128. pseudo_palette))[*ptr]) & 0xffff) << 16;
  129. ptr++;
  130. }
  131. line += bytes;
  132. i++;
  133. }
  134. }
  135. /*
  136. * Fill in the cmd array /GDC FIFO commands/ to draw a 16bit image.
  137. * Make sure cmd has enough room!
  138. */
  139. static void mb86290fb_imageblit16(u32 *cmd, u16 step, u16 dx, u16 dy,
  140. u16 width, u16 height, u32 fgcolor,
  141. u32 bgcolor, const struct fb_image *image,
  142. struct fb_info *info)
  143. {
  144. int i;
  145. unsigned const char *line;
  146. u16 bytes;
  147. i = 0;
  148. line = image->data;
  149. bytes = image->width << 1;
  150. cmd[0] = (GDC_TYPE_DRAWBITMAPP << 24) |
  151. (GDC_CMD_BLT_DRAW << 16) | (2 + step * height);
  152. cmd[1] = (dy << 16) | dx;
  153. cmd[2] = (height << 16) | width;
  154. while (i < height) {
  155. memcpy(&cmd[3 + i * step], line, step);
  156. line += bytes;
  157. i++;
  158. }
  159. }
  160. static void mb86290fb_imageblit(struct fb_info *info,
  161. const struct fb_image *image)
  162. {
  163. u32 *cmd = NULL;
  164. void (*cmdfn) (u32 *, u16, u16, u16, u16, u16, u32, u32,
  165. const struct fb_image *, struct fb_info *) = NULL;
  166. u32 cmdlen;
  167. u32 fgcolor = 0, bgcolor = 0;
  168. u16 step;
  169. u16 width = image->width, height = image->height;
  170. u16 dx = image->dx, dy = image->dy;
  171. int x2, y2, vxres, vyres;
  172. x2 = image->dx + image->width;
  173. y2 = image->dy + image->height;
  174. vxres = info->var.xres_virtual;
  175. vyres = info->var.yres_virtual;
  176. x2 = min(x2, vxres);
  177. y2 = min(y2, vyres);
  178. width = x2 - dx;
  179. height = y2 - dy;
  180. switch (image->depth) {
  181. case 1:
  182. step = (width + 31) >> 5;
  183. cmdlen = 9 + height * step;
  184. cmdfn = mb86290fb_imageblit1;
  185. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  186. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  187. fgcolor =
  188. ((u32 *) (info->pseudo_palette))[image->fg_color];
  189. bgcolor =
  190. ((u32 *) (info->pseudo_palette))[image->bg_color];
  191. } else {
  192. fgcolor = image->fg_color;
  193. bgcolor = image->bg_color;
  194. }
  195. break;
  196. case 8:
  197. step = (width + 1) >> 1;
  198. cmdlen = 3 + height * step;
  199. cmdfn = mb86290fb_imageblit8;
  200. break;
  201. case 16:
  202. step = (width + 1) >> 1;
  203. cmdlen = 3 + height * step;
  204. cmdfn = mb86290fb_imageblit16;
  205. break;
  206. default:
  207. cfb_imageblit(info, image);
  208. return;
  209. }
  210. cmd = kmalloc_array(cmdlen, 4, GFP_DMA);
  211. if (!cmd)
  212. return cfb_imageblit(info, image);
  213. cmdfn(cmd, step, dx, dy, width, height, fgcolor, bgcolor, image, info);
  214. mb862xxfb_write_fifo(cmdlen, cmd, info);
  215. kfree(cmd);
  216. }
  217. static void mb86290fb_fillrect(struct fb_info *info,
  218. const struct fb_fillrect *rect)
  219. {
  220. u32 x2, y2, vxres, vyres, height, width, fg;
  221. u32 cmd[7];
  222. vxres = info->var.xres_virtual;
  223. vyres = info->var.yres_virtual;
  224. if (!rect->width || !rect->height || rect->dx > vxres
  225. || rect->dy > vyres)
  226. return;
  227. /* We could use hardware clipping but on many cards you get around
  228. * hardware clipping by writing to framebuffer directly. */
  229. x2 = rect->dx + rect->width;
  230. y2 = rect->dy + rect->height;
  231. x2 = min(x2, vxres);
  232. y2 = min(y2, vyres);
  233. width = x2 - rect->dx;
  234. height = y2 - rect->dy;
  235. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  236. info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  237. fg = ((u32 *) (info->pseudo_palette))[rect->color];
  238. else
  239. fg = rect->color;
  240. switch (rect->rop) {
  241. case ROP_XOR:
  242. /* Set raster operation */
  243. cmd[1] = (2 << 7) | (GDC_ROP_XOR << 9);
  244. break;
  245. case ROP_COPY:
  246. /* Set raster operation */
  247. cmd[1] = (2 << 7) | (GDC_ROP_COPY << 9);
  248. break;
  249. }
  250. cmd[0] = (GDC_TYPE_SETREGISTER << 24) | (1 << 16) | GDC_REG_MODE_BITMAP;
  251. /* cmd[1] set earlier */
  252. cmd[2] =
  253. (GDC_TYPE_SETCOLORREGISTER << 24) | (GDC_CMD_BODY_FORE_COLOR << 16);
  254. cmd[3] = fg;
  255. cmd[4] = (GDC_TYPE_DRAWRECTP << 24) | (GDC_CMD_BLT_FILL << 16);
  256. cmd[5] = (rect->dy << 16) | (rect->dx);
  257. cmd[6] = (height << 16) | width;
  258. mb862xxfb_write_fifo(7, cmd, info);
  259. }
  260. void mb862xxfb_init_accel(struct fb_info *info, struct fb_ops *fbops, int xres)
  261. {
  262. struct mb862xxfb_par *par = info->par;
  263. if (info->var.bits_per_pixel == 32) {
  264. fbops->fb_fillrect = cfb_fillrect;
  265. fbops->fb_copyarea = cfb_copyarea;
  266. fbops->fb_imageblit = cfb_imageblit;
  267. } else {
  268. outreg(disp, GC_L0EM, 3);
  269. fbops->fb_fillrect = mb86290fb_fillrect;
  270. fbops->fb_copyarea = mb86290fb_copyarea;
  271. fbops->fb_imageblit = mb86290fb_imageblit;
  272. }
  273. outreg(draw, GDC_REG_DRAW_BASE, 0);
  274. outreg(draw, GDC_REG_MODE_MISC, 0x8000);
  275. outreg(draw, GDC_REG_X_RESOLUTION, xres);
  276. info->flags |=
  277. FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
  278. FBINFO_HWACCEL_IMAGEBLIT;
  279. info->fix.accel = 0xff; /*FIXME: add right define */
  280. }
  281. MODULE_LICENSE("GPL v2");