0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/module.h>
0012 #include <linux/slab.h>
0013 #include <linux/string.h>
0014 #include <linux/fb.h>
0015 #include <linux/vt_kern.h>
0016 #include <linux/console.h>
0017 #include <asm/types.h>
0018 #include "fbcon.h"
0019 #include "fbcon_rotate.h"
0020
0021
0022
0023
0024
0025 static void ccw_update_attr(u8 *dst, u8 *src, int attribute,
0026 struct vc_data *vc)
0027 {
0028 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2;
0029 int width = (vc->vc_font.height + 7) >> 3;
0030 int mod = vc->vc_font.height % 8;
0031 u8 c, msk = ~(0xff << offset), msk1 = 0;
0032
0033 if (mod)
0034 msk <<= (8 - mod);
0035
0036 if (offset > mod)
0037 msk1 |= 0x01;
0038
0039 for (i = 0; i < vc->vc_font.width; i++) {
0040 for (j = 0; j < width; j++) {
0041 c = *src;
0042
0043 if (attribute & FBCON_ATTRIBUTE_UNDERLINE) {
0044 if (j == width - 1)
0045 c |= msk;
0046
0047 if (msk1 && j == width - 2)
0048 c |= msk1;
0049 }
0050
0051 if (attribute & FBCON_ATTRIBUTE_BOLD && i)
0052 *(dst - width) |= c;
0053
0054 if (attribute & FBCON_ATTRIBUTE_REVERSE)
0055 c = ~c;
0056 src++;
0057 *dst++ = c;
0058 }
0059 }
0060 }
0061
0062
0063 static void ccw_bmove(struct vc_data *vc, struct fb_info *info, int sy,
0064 int sx, int dy, int dx, int height, int width)
0065 {
0066 struct fbcon_ops *ops = info->fbcon_par;
0067 struct fb_copyarea area;
0068 u32 vyres = GETVYRES(ops->p, info);
0069
0070 area.sx = sy * vc->vc_font.height;
0071 area.sy = vyres - ((sx + width) * vc->vc_font.width);
0072 area.dx = dy * vc->vc_font.height;
0073 area.dy = vyres - ((dx + width) * vc->vc_font.width);
0074 area.width = height * vc->vc_font.height;
0075 area.height = width * vc->vc_font.width;
0076
0077 info->fbops->fb_copyarea(info, &area);
0078 }
0079
0080 static void ccw_clear(struct vc_data *vc, struct fb_info *info, int sy,
0081 int sx, int height, int width)
0082 {
0083 struct fbcon_ops *ops = info->fbcon_par;
0084 struct fb_fillrect region;
0085 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
0086 u32 vyres = GETVYRES(ops->p, info);
0087
0088 region.color = attr_bgcol_ec(bgshift,vc,info);
0089 region.dx = sy * vc->vc_font.height;
0090 region.dy = vyres - ((sx + width) * vc->vc_font.width);
0091 region.height = width * vc->vc_font.width;
0092 region.width = height * vc->vc_font.height;
0093 region.rop = ROP_COPY;
0094
0095 info->fbops->fb_fillrect(info, ®ion);
0096 }
0097
0098 static inline void ccw_putcs_aligned(struct vc_data *vc, struct fb_info *info,
0099 const u16 *s, u32 attr, u32 cnt,
0100 u32 d_pitch, u32 s_pitch, u32 cellsize,
0101 struct fb_image *image, u8 *buf, u8 *dst)
0102 {
0103 struct fbcon_ops *ops = info->fbcon_par;
0104 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
0105 u32 idx = (vc->vc_font.height + 7) >> 3;
0106 u8 *src;
0107
0108 while (cnt--) {
0109 src = ops->fontbuffer + (scr_readw(s--) & charmask)*cellsize;
0110
0111 if (attr) {
0112 ccw_update_attr(buf, src, attr, vc);
0113 src = buf;
0114 }
0115
0116 if (likely(idx == 1))
0117 __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
0118 vc->vc_font.width);
0119 else
0120 fb_pad_aligned_buffer(dst, d_pitch, src, idx,
0121 vc->vc_font.width);
0122
0123 dst += d_pitch * vc->vc_font.width;
0124 }
0125
0126 info->fbops->fb_imageblit(info, image);
0127 }
0128
0129 static void ccw_putcs(struct vc_data *vc, struct fb_info *info,
0130 const unsigned short *s, int count, int yy, int xx,
0131 int fg, int bg)
0132 {
0133 struct fb_image image;
0134 struct fbcon_ops *ops = info->fbcon_par;
0135 u32 width = (vc->vc_font.height + 7)/8;
0136 u32 cellsize = width * vc->vc_font.width;
0137 u32 maxcnt = info->pixmap.size/cellsize;
0138 u32 scan_align = info->pixmap.scan_align - 1;
0139 u32 buf_align = info->pixmap.buf_align - 1;
0140 u32 cnt, pitch, size;
0141 u32 attribute = get_attribute(info, scr_readw(s));
0142 u8 *dst, *buf = NULL;
0143 u32 vyres = GETVYRES(ops->p, info);
0144
0145 if (!ops->fontbuffer)
0146 return;
0147
0148 image.fg_color = fg;
0149 image.bg_color = bg;
0150 image.dx = yy * vc->vc_font.height;
0151 image.dy = vyres - ((xx + count) * vc->vc_font.width);
0152 image.width = vc->vc_font.height;
0153 image.depth = 1;
0154
0155 if (attribute) {
0156 buf = kmalloc(cellsize, GFP_KERNEL);
0157 if (!buf)
0158 return;
0159 }
0160
0161 s += count - 1;
0162
0163 while (count) {
0164 if (count > maxcnt)
0165 cnt = maxcnt;
0166 else
0167 cnt = count;
0168
0169 image.height = vc->vc_font.width * cnt;
0170 pitch = ((image.width + 7) >> 3) + scan_align;
0171 pitch &= ~scan_align;
0172 size = pitch * image.height + buf_align;
0173 size &= ~buf_align;
0174 dst = fb_get_buffer_offset(info, &info->pixmap, size);
0175 image.data = dst;
0176 ccw_putcs_aligned(vc, info, s, attribute, cnt, pitch,
0177 width, cellsize, &image, buf, dst);
0178 image.dy += image.height;
0179 count -= cnt;
0180 s -= cnt;
0181 }
0182
0183
0184
0185
0186 if (unlikely(buf))
0187 kfree(buf);
0188
0189 }
0190
0191 static void ccw_clear_margins(struct vc_data *vc, struct fb_info *info,
0192 int color, int bottom_only)
0193 {
0194 unsigned int cw = vc->vc_font.width;
0195 unsigned int ch = vc->vc_font.height;
0196 unsigned int rw = info->var.yres - (vc->vc_cols*cw);
0197 unsigned int bh = info->var.xres - (vc->vc_rows*ch);
0198 unsigned int bs = vc->vc_rows*ch;
0199 struct fb_fillrect region;
0200
0201 region.color = color;
0202 region.rop = ROP_COPY;
0203
0204 if ((int) rw > 0 && !bottom_only) {
0205 region.dx = 0;
0206 region.dy = info->var.yoffset;
0207 region.height = rw;
0208 region.width = info->var.xres_virtual;
0209 info->fbops->fb_fillrect(info, ®ion);
0210 }
0211
0212 if ((int) bh > 0) {
0213 region.dx = info->var.xoffset + bs;
0214 region.dy = 0;
0215 region.height = info->var.yres_virtual;
0216 region.width = bh;
0217 info->fbops->fb_fillrect(info, ®ion);
0218 }
0219 }
0220
0221 static void ccw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
0222 int fg, int bg)
0223 {
0224 struct fb_cursor cursor;
0225 struct fbcon_ops *ops = info->fbcon_par;
0226 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
0227 int w = (vc->vc_font.height + 7) >> 3, c;
0228 int y = real_y(ops->p, vc->state.y);
0229 int attribute, use_sw = vc->vc_cursor_type & CUR_SW;
0230 int err = 1, dx, dy;
0231 char *src;
0232 u32 vyres = GETVYRES(ops->p, info);
0233
0234 if (!ops->fontbuffer)
0235 return;
0236
0237 cursor.set = 0;
0238
0239 c = scr_readw((u16 *) vc->vc_pos);
0240 attribute = get_attribute(info, c);
0241 src = ops->fontbuffer + ((c & charmask) * (w * vc->vc_font.width));
0242
0243 if (ops->cursor_state.image.data != src ||
0244 ops->cursor_reset) {
0245 ops->cursor_state.image.data = src;
0246 cursor.set |= FB_CUR_SETIMAGE;
0247 }
0248
0249 if (attribute) {
0250 u8 *dst;
0251
0252 dst = kmalloc_array(w, vc->vc_font.width, GFP_ATOMIC);
0253 if (!dst)
0254 return;
0255 kfree(ops->cursor_data);
0256 ops->cursor_data = dst;
0257 ccw_update_attr(dst, src, attribute, vc);
0258 src = dst;
0259 }
0260
0261 if (ops->cursor_state.image.fg_color != fg ||
0262 ops->cursor_state.image.bg_color != bg ||
0263 ops->cursor_reset) {
0264 ops->cursor_state.image.fg_color = fg;
0265 ops->cursor_state.image.bg_color = bg;
0266 cursor.set |= FB_CUR_SETCMAP;
0267 }
0268
0269 if (ops->cursor_state.image.height != vc->vc_font.width ||
0270 ops->cursor_state.image.width != vc->vc_font.height ||
0271 ops->cursor_reset) {
0272 ops->cursor_state.image.height = vc->vc_font.width;
0273 ops->cursor_state.image.width = vc->vc_font.height;
0274 cursor.set |= FB_CUR_SETSIZE;
0275 }
0276
0277 dx = y * vc->vc_font.height;
0278 dy = vyres - ((vc->state.x + 1) * vc->vc_font.width);
0279
0280 if (ops->cursor_state.image.dx != dx ||
0281 ops->cursor_state.image.dy != dy ||
0282 ops->cursor_reset) {
0283 ops->cursor_state.image.dx = dx;
0284 ops->cursor_state.image.dy = dy;
0285 cursor.set |= FB_CUR_SETPOS;
0286 }
0287
0288 if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
0289 ops->cursor_reset) {
0290 ops->cursor_state.hot.x = cursor.hot.y = 0;
0291 cursor.set |= FB_CUR_SETHOT;
0292 }
0293
0294 if (cursor.set & FB_CUR_SETSIZE ||
0295 vc->vc_cursor_type != ops->p->cursor_shape ||
0296 ops->cursor_state.mask == NULL ||
0297 ops->cursor_reset) {
0298 char *tmp, *mask = kmalloc_array(w, vc->vc_font.width,
0299 GFP_ATOMIC);
0300 int cur_height, size, i = 0;
0301 int width = (vc->vc_font.width + 7)/8;
0302
0303 if (!mask)
0304 return;
0305
0306 tmp = kmalloc_array(width, vc->vc_font.height, GFP_ATOMIC);
0307
0308 if (!tmp) {
0309 kfree(mask);
0310 return;
0311 }
0312
0313 kfree(ops->cursor_state.mask);
0314 ops->cursor_state.mask = mask;
0315
0316 ops->p->cursor_shape = vc->vc_cursor_type;
0317 cursor.set |= FB_CUR_SETSHAPE;
0318
0319 switch (CUR_SIZE(ops->p->cursor_shape)) {
0320 case CUR_NONE:
0321 cur_height = 0;
0322 break;
0323 case CUR_UNDERLINE:
0324 cur_height = (vc->vc_font.height < 10) ? 1 : 2;
0325 break;
0326 case CUR_LOWER_THIRD:
0327 cur_height = vc->vc_font.height/3;
0328 break;
0329 case CUR_LOWER_HALF:
0330 cur_height = vc->vc_font.height >> 1;
0331 break;
0332 case CUR_TWO_THIRDS:
0333 cur_height = (vc->vc_font.height << 1)/3;
0334 break;
0335 case CUR_BLOCK:
0336 default:
0337 cur_height = vc->vc_font.height;
0338 break;
0339 }
0340
0341 size = (vc->vc_font.height - cur_height) * width;
0342 while (size--)
0343 tmp[i++] = 0;
0344 size = cur_height * width;
0345 while (size--)
0346 tmp[i++] = 0xff;
0347 memset(mask, 0, w * vc->vc_font.width);
0348 rotate_ccw(tmp, mask, vc->vc_font.width, vc->vc_font.height);
0349 kfree(tmp);
0350 }
0351
0352 switch (mode) {
0353 case CM_ERASE:
0354 ops->cursor_state.enable = 0;
0355 break;
0356 case CM_DRAW:
0357 case CM_MOVE:
0358 default:
0359 ops->cursor_state.enable = (use_sw) ? 0 : 1;
0360 break;
0361 }
0362
0363 cursor.image.data = src;
0364 cursor.image.fg_color = ops->cursor_state.image.fg_color;
0365 cursor.image.bg_color = ops->cursor_state.image.bg_color;
0366 cursor.image.dx = ops->cursor_state.image.dx;
0367 cursor.image.dy = ops->cursor_state.image.dy;
0368 cursor.image.height = ops->cursor_state.image.height;
0369 cursor.image.width = ops->cursor_state.image.width;
0370 cursor.hot.x = ops->cursor_state.hot.x;
0371 cursor.hot.y = ops->cursor_state.hot.y;
0372 cursor.mask = ops->cursor_state.mask;
0373 cursor.enable = ops->cursor_state.enable;
0374 cursor.image.depth = 1;
0375 cursor.rop = ROP_XOR;
0376
0377 if (info->fbops->fb_cursor)
0378 err = info->fbops->fb_cursor(info, &cursor);
0379
0380 if (err)
0381 soft_cursor(info, &cursor);
0382
0383 ops->cursor_reset = 0;
0384 }
0385
0386 static int ccw_update_start(struct fb_info *info)
0387 {
0388 struct fbcon_ops *ops = info->fbcon_par;
0389 u32 yoffset;
0390 u32 vyres = GETVYRES(ops->p, info);
0391 int err;
0392
0393 yoffset = (vyres - info->var.yres) - ops->var.xoffset;
0394 ops->var.xoffset = ops->var.yoffset;
0395 ops->var.yoffset = yoffset;
0396 err = fb_pan_display(info, &ops->var);
0397 ops->var.xoffset = info->var.xoffset;
0398 ops->var.yoffset = info->var.yoffset;
0399 ops->var.vmode = info->var.vmode;
0400 return err;
0401 }
0402
0403 void fbcon_rotate_ccw(struct fbcon_ops *ops)
0404 {
0405 ops->bmove = ccw_bmove;
0406 ops->clear = ccw_clear;
0407 ops->putcs = ccw_putcs;
0408 ops->clear_margins = ccw_clear_margins;
0409 ops->cursor = ccw_cursor;
0410 ops->update_start = ccw_update_start;
0411 }