fbcon_cw.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /*
  2. * linux/drivers/video/console/fbcon_ud.c -- Software Rotation - 90 degrees
  3. *
  4. * Copyright (C) 2005 Antonino Daplas <adaplas @pol.net>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive for
  8. * more details.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/slab.h>
  12. #include <linux/string.h>
  13. #include <linux/fb.h>
  14. #include <linux/vt_kern.h>
  15. #include <linux/console.h>
  16. #include <asm/types.h>
  17. #include "fbcon.h"
  18. #include "fbcon_rotate.h"
  19. /*
  20. * Rotation 90 degrees
  21. */
  22. static void cw_update_attr(u8 *dst, u8 *src, int attribute,
  23. struct vc_data *vc)
  24. {
  25. int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2;
  26. int width = (vc->vc_font.height + 7) >> 3;
  27. u8 c, t = 0, msk = ~(0xff >> offset);
  28. for (i = 0; i < vc->vc_font.width; i++) {
  29. for (j = 0; j < width; j++) {
  30. c = *src;
  31. if (attribute & FBCON_ATTRIBUTE_UNDERLINE && !j)
  32. c |= msk;
  33. if (attribute & FBCON_ATTRIBUTE_BOLD && i)
  34. c |= *(src-width);
  35. if (attribute & FBCON_ATTRIBUTE_REVERSE)
  36. c = ~c;
  37. src++;
  38. *dst++ = c;
  39. t = c;
  40. }
  41. }
  42. }
  43. static void cw_bmove(struct vc_data *vc, struct fb_info *info, int sy,
  44. int sx, int dy, int dx, int height, int width)
  45. {
  46. struct fbcon_ops *ops = info->fbcon_par;
  47. struct fb_copyarea area;
  48. u32 vxres = GETVXRES(ops->p->scrollmode, info);
  49. area.sx = vxres - ((sy + height) * vc->vc_font.height);
  50. area.sy = sx * vc->vc_font.width;
  51. area.dx = vxres - ((dy + height) * vc->vc_font.height);
  52. area.dy = dx * vc->vc_font.width;
  53. area.width = height * vc->vc_font.height;
  54. area.height = width * vc->vc_font.width;
  55. info->fbops->fb_copyarea(info, &area);
  56. }
  57. static void cw_clear(struct vc_data *vc, struct fb_info *info, int sy,
  58. int sx, int height, int width)
  59. {
  60. struct fbcon_ops *ops = info->fbcon_par;
  61. struct fb_fillrect region;
  62. int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
  63. u32 vxres = GETVXRES(ops->p->scrollmode, info);
  64. region.color = attr_bgcol_ec(bgshift,vc,info);
  65. region.dx = vxres - ((sy + height) * vc->vc_font.height);
  66. region.dy = sx * vc->vc_font.width;
  67. region.height = width * vc->vc_font.width;
  68. region.width = height * vc->vc_font.height;
  69. region.rop = ROP_COPY;
  70. info->fbops->fb_fillrect(info, &region);
  71. }
  72. static inline void cw_putcs_aligned(struct vc_data *vc, struct fb_info *info,
  73. const u16 *s, u32 attr, u32 cnt,
  74. u32 d_pitch, u32 s_pitch, u32 cellsize,
  75. struct fb_image *image, u8 *buf, u8 *dst)
  76. {
  77. struct fbcon_ops *ops = info->fbcon_par;
  78. u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  79. u32 idx = (vc->vc_font.height + 7) >> 3;
  80. u8 *src;
  81. while (cnt--) {
  82. src = ops->fontbuffer + (scr_readw(s++) & charmask)*cellsize;
  83. if (attr) {
  84. cw_update_attr(buf, src, attr, vc);
  85. src = buf;
  86. }
  87. if (likely(idx == 1))
  88. __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
  89. vc->vc_font.width);
  90. else
  91. fb_pad_aligned_buffer(dst, d_pitch, src, idx,
  92. vc->vc_font.width);
  93. dst += d_pitch * vc->vc_font.width;
  94. }
  95. info->fbops->fb_imageblit(info, image);
  96. }
  97. static void cw_putcs(struct vc_data *vc, struct fb_info *info,
  98. const unsigned short *s, int count, int yy, int xx,
  99. int fg, int bg)
  100. {
  101. struct fb_image image;
  102. struct fbcon_ops *ops = info->fbcon_par;
  103. u32 width = (vc->vc_font.height + 7)/8;
  104. u32 cellsize = width * vc->vc_font.width;
  105. u32 maxcnt = info->pixmap.size/cellsize;
  106. u32 scan_align = info->pixmap.scan_align - 1;
  107. u32 buf_align = info->pixmap.buf_align - 1;
  108. u32 cnt, pitch, size;
  109. u32 attribute = get_attribute(info, scr_readw(s));
  110. u8 *dst, *buf = NULL;
  111. u32 vxres = GETVXRES(ops->p->scrollmode, info);
  112. if (!ops->fontbuffer)
  113. return;
  114. image.fg_color = fg;
  115. image.bg_color = bg;
  116. image.dx = vxres - ((yy + 1) * vc->vc_font.height);
  117. image.dy = xx * vc->vc_font.width;
  118. image.width = vc->vc_font.height;
  119. image.depth = 1;
  120. if (attribute) {
  121. buf = kmalloc(cellsize, GFP_KERNEL);
  122. if (!buf)
  123. return;
  124. }
  125. while (count) {
  126. if (count > maxcnt)
  127. cnt = maxcnt;
  128. else
  129. cnt = count;
  130. image.height = vc->vc_font.width * cnt;
  131. pitch = ((image.width + 7) >> 3) + scan_align;
  132. pitch &= ~scan_align;
  133. size = pitch * image.height + buf_align;
  134. size &= ~buf_align;
  135. dst = fb_get_buffer_offset(info, &info->pixmap, size);
  136. image.data = dst;
  137. cw_putcs_aligned(vc, info, s, attribute, cnt, pitch,
  138. width, cellsize, &image, buf, dst);
  139. image.dy += image.height;
  140. count -= cnt;
  141. s += cnt;
  142. }
  143. /* buf is always NULL except when in monochrome mode, so in this case
  144. it's a gain to check buf against NULL even though kfree() handles
  145. NULL pointers just fine */
  146. if (unlikely(buf))
  147. kfree(buf);
  148. }
  149. static void cw_clear_margins(struct vc_data *vc, struct fb_info *info,
  150. int bottom_only)
  151. {
  152. unsigned int cw = vc->vc_font.width;
  153. unsigned int ch = vc->vc_font.height;
  154. unsigned int rw = info->var.yres - (vc->vc_cols*cw);
  155. unsigned int bh = info->var.xres - (vc->vc_rows*ch);
  156. unsigned int rs = info->var.yres - rw;
  157. struct fb_fillrect region;
  158. int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
  159. region.color = attr_bgcol_ec(bgshift,vc,info);
  160. region.rop = ROP_COPY;
  161. if (rw && !bottom_only) {
  162. region.dx = 0;
  163. region.dy = info->var.yoffset + rs;
  164. region.height = rw;
  165. region.width = info->var.xres_virtual;
  166. info->fbops->fb_fillrect(info, &region);
  167. }
  168. if (bh) {
  169. region.dx = info->var.xoffset;
  170. region.dy = info->var.yoffset;
  171. region.height = info->var.yres;
  172. region.width = bh;
  173. info->fbops->fb_fillrect(info, &region);
  174. }
  175. }
  176. static void cw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
  177. int softback_lines, int fg, int bg)
  178. {
  179. struct fb_cursor cursor;
  180. struct fbcon_ops *ops = info->fbcon_par;
  181. unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  182. int w = (vc->vc_font.height + 7) >> 3, c;
  183. int y = real_y(ops->p, vc->vc_y);
  184. int attribute, use_sw = (vc->vc_cursor_type & 0x10);
  185. int err = 1, dx, dy;
  186. char *src;
  187. u32 vxres = GETVXRES(ops->p->scrollmode, info);
  188. if (!ops->fontbuffer)
  189. return;
  190. cursor.set = 0;
  191. if (softback_lines) {
  192. if (y + softback_lines >= vc->vc_rows) {
  193. mode = CM_ERASE;
  194. ops->cursor_flash = 0;
  195. return;
  196. } else
  197. y += softback_lines;
  198. }
  199. c = scr_readw((u16 *) vc->vc_pos);
  200. attribute = get_attribute(info, c);
  201. src = ops->fontbuffer + ((c & charmask) * (w * vc->vc_font.width));
  202. if (ops->cursor_state.image.data != src ||
  203. ops->cursor_reset) {
  204. ops->cursor_state.image.data = src;
  205. cursor.set |= FB_CUR_SETIMAGE;
  206. }
  207. if (attribute) {
  208. u8 *dst;
  209. dst = kmalloc(w * vc->vc_font.width, GFP_ATOMIC);
  210. if (!dst)
  211. return;
  212. kfree(ops->cursor_data);
  213. ops->cursor_data = dst;
  214. cw_update_attr(dst, src, attribute, vc);
  215. src = dst;
  216. }
  217. if (ops->cursor_state.image.fg_color != fg ||
  218. ops->cursor_state.image.bg_color != bg ||
  219. ops->cursor_reset) {
  220. ops->cursor_state.image.fg_color = fg;
  221. ops->cursor_state.image.bg_color = bg;
  222. cursor.set |= FB_CUR_SETCMAP;
  223. }
  224. if (ops->cursor_state.image.height != vc->vc_font.width ||
  225. ops->cursor_state.image.width != vc->vc_font.height ||
  226. ops->cursor_reset) {
  227. ops->cursor_state.image.height = vc->vc_font.width;
  228. ops->cursor_state.image.width = vc->vc_font.height;
  229. cursor.set |= FB_CUR_SETSIZE;
  230. }
  231. dx = vxres - ((y * vc->vc_font.height) + vc->vc_font.height);
  232. dy = vc->vc_x * vc->vc_font.width;
  233. if (ops->cursor_state.image.dx != dx ||
  234. ops->cursor_state.image.dy != dy ||
  235. ops->cursor_reset) {
  236. ops->cursor_state.image.dx = dx;
  237. ops->cursor_state.image.dy = dy;
  238. cursor.set |= FB_CUR_SETPOS;
  239. }
  240. if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
  241. ops->cursor_reset) {
  242. ops->cursor_state.hot.x = cursor.hot.y = 0;
  243. cursor.set |= FB_CUR_SETHOT;
  244. }
  245. if (cursor.set & FB_CUR_SETSIZE ||
  246. vc->vc_cursor_type != ops->p->cursor_shape ||
  247. ops->cursor_state.mask == NULL ||
  248. ops->cursor_reset) {
  249. char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC);
  250. int cur_height, size, i = 0;
  251. int width = (vc->vc_font.width + 7)/8;
  252. if (!mask)
  253. return;
  254. tmp = kmalloc(width * vc->vc_font.height, GFP_ATOMIC);
  255. if (!tmp) {
  256. kfree(mask);
  257. return;
  258. }
  259. kfree(ops->cursor_state.mask);
  260. ops->cursor_state.mask = mask;
  261. ops->p->cursor_shape = vc->vc_cursor_type;
  262. cursor.set |= FB_CUR_SETSHAPE;
  263. switch (ops->p->cursor_shape & CUR_HWMASK) {
  264. case CUR_NONE:
  265. cur_height = 0;
  266. break;
  267. case CUR_UNDERLINE:
  268. cur_height = (vc->vc_font.height < 10) ? 1 : 2;
  269. break;
  270. case CUR_LOWER_THIRD:
  271. cur_height = vc->vc_font.height/3;
  272. break;
  273. case CUR_LOWER_HALF:
  274. cur_height = vc->vc_font.height >> 1;
  275. break;
  276. case CUR_TWO_THIRDS:
  277. cur_height = (vc->vc_font.height << 1)/3;
  278. break;
  279. case CUR_BLOCK:
  280. default:
  281. cur_height = vc->vc_font.height;
  282. break;
  283. }
  284. size = (vc->vc_font.height - cur_height) * width;
  285. while (size--)
  286. tmp[i++] = 0;
  287. size = cur_height * width;
  288. while (size--)
  289. tmp[i++] = 0xff;
  290. memset(mask, 0, w * vc->vc_font.width);
  291. rotate_cw(tmp, mask, vc->vc_font.width, vc->vc_font.height);
  292. kfree(tmp);
  293. }
  294. switch (mode) {
  295. case CM_ERASE:
  296. ops->cursor_state.enable = 0;
  297. break;
  298. case CM_DRAW:
  299. case CM_MOVE:
  300. default:
  301. ops->cursor_state.enable = (use_sw) ? 0 : 1;
  302. break;
  303. }
  304. cursor.image.data = src;
  305. cursor.image.fg_color = ops->cursor_state.image.fg_color;
  306. cursor.image.bg_color = ops->cursor_state.image.bg_color;
  307. cursor.image.dx = ops->cursor_state.image.dx;
  308. cursor.image.dy = ops->cursor_state.image.dy;
  309. cursor.image.height = ops->cursor_state.image.height;
  310. cursor.image.width = ops->cursor_state.image.width;
  311. cursor.hot.x = ops->cursor_state.hot.x;
  312. cursor.hot.y = ops->cursor_state.hot.y;
  313. cursor.mask = ops->cursor_state.mask;
  314. cursor.enable = ops->cursor_state.enable;
  315. cursor.image.depth = 1;
  316. cursor.rop = ROP_XOR;
  317. if (info->fbops->fb_cursor)
  318. err = info->fbops->fb_cursor(info, &cursor);
  319. if (err)
  320. soft_cursor(info, &cursor);
  321. ops->cursor_reset = 0;
  322. }
  323. static int cw_update_start(struct fb_info *info)
  324. {
  325. struct fbcon_ops *ops = info->fbcon_par;
  326. u32 vxres = GETVXRES(ops->p->scrollmode, info);
  327. u32 xoffset;
  328. int err;
  329. xoffset = vxres - (info->var.xres + ops->var.yoffset);
  330. ops->var.yoffset = ops->var.xoffset;
  331. ops->var.xoffset = xoffset;
  332. err = fb_pan_display(info, &ops->var);
  333. ops->var.xoffset = info->var.xoffset;
  334. ops->var.yoffset = info->var.yoffset;
  335. ops->var.vmode = info->var.vmode;
  336. return err;
  337. }
  338. void fbcon_rotate_cw(struct fbcon_ops *ops)
  339. {
  340. ops->bmove = cw_bmove;
  341. ops->clear = cw_clear;
  342. ops->putcs = cw_putcs;
  343. ops->clear_margins = cw_clear_margins;
  344. ops->cursor = cw_cursor;
  345. ops->update_start = cw_update_start;
  346. }
  347. EXPORT_SYMBOL(fbcon_rotate_cw);
  348. MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
  349. MODULE_DESCRIPTION("Console Rotation (90 degrees) Support");
  350. MODULE_LICENSE("GPL");