fbcon_ccw.c 11 KB

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