1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/config.h>
14#include <linux/module.h>
15#include <linux/string.h>
16#include <linux/fb.h>
17#include <linux/vt_kern.h>
18#include <linux/console.h>
19#include <asm/types.h>
20#include "fbcon.h"
21
22
23
24
25#define FBCON_ATTRIBUTE_UNDERLINE 1
26#define FBCON_ATTRIBUTE_REVERSE 2
27#define FBCON_ATTRIBUTE_BOLD 4
28
29static inline int real_y(struct display *p, int ypos)
30{
31 int rows = p->vrows;
32
33 ypos += p->yscroll;
34 return ypos < rows ? ypos : ypos - rows;
35}
36
37
38static inline int get_attribute(struct fb_info *info, u16 c)
39{
40 int attribute = 0;
41
42 if (fb_get_color_depth(info) == 1) {
43 if (attr_underline(c))
44 attribute |= FBCON_ATTRIBUTE_UNDERLINE;
45 if (attr_reverse(c))
46 attribute |= FBCON_ATTRIBUTE_REVERSE;
47 if (attr_bold(c))
48 attribute |= FBCON_ATTRIBUTE_BOLD;
49 }
50
51 return attribute;
52}
53
54static inline void update_attr(u8 *dst, u8 *src, int attribute,
55 struct vc_data *vc)
56{
57 int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
58 int width = (vc->vc_font.width + 7) >> 3;
59 unsigned int cellsize = vc->vc_font.height * width;
60 u8 c;
61
62 offset = cellsize - (offset * width);
63 for (i = 0; i < cellsize; i++) {
64 c = src[i];
65 if (attribute & FBCON_ATTRIBUTE_UNDERLINE && i >= offset)
66 c = 0xff;
67 if (attribute & FBCON_ATTRIBUTE_BOLD)
68 c |= c >> 1;
69 if (attribute & FBCON_ATTRIBUTE_REVERSE)
70 c = ~c;
71 dst[i] = c;
72 }
73}
74
75static void bit_bmove(struct vc_data *vc, struct fb_info *info, int sy,
76 int sx, int dy, int dx, int height, int width)
77{
78 struct fb_copyarea area;
79
80 area.sx = sx * vc->vc_font.width;
81 area.sy = sy * vc->vc_font.height;
82 area.dx = dx * vc->vc_font.width;
83 area.dy = dy * vc->vc_font.height;
84 area.height = height * vc->vc_font.height;
85 area.width = width * vc->vc_font.width;
86
87 info->fbops->fb_copyarea(info, &area);
88}
89
90static void bit_clear(struct vc_data *vc, struct fb_info *info, int sy,
91 int sx, int height, int width)
92{
93 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
94 struct fb_fillrect region;
95
96 region.color = attr_bgcol_ec(bgshift, vc);
97 region.dx = sx * vc->vc_font.width;
98 region.dy = sy * vc->vc_font.height;
99 region.width = width * vc->vc_font.width;
100 region.height = height * vc->vc_font.height;
101 region.rop = ROP_COPY;
102
103 info->fbops->fb_fillrect(info, ®ion);
104}
105
106static void bit_putcs(struct vc_data *vc, struct fb_info *info,
107 const unsigned short *s, int count, int yy, int xx,
108 int fg, int bg)
109{
110 void (*move_unaligned)(struct fb_info *info, struct fb_pixmap *buf,
111 u8 *dst, u32 d_pitch, u8 *src, u32 idx,
112 u32 height, u32 shift_high, u32 shift_low,
113 u32 mod);
114 void (*move_aligned)(struct fb_info *info, struct fb_pixmap *buf,
115 u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch,
116 u32 height);
117 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
118 unsigned int width = (vc->vc_font.width + 7) >> 3;
119 unsigned int cellsize = vc->vc_font.height * width;
120 unsigned int maxcnt = info->pixmap.size/cellsize;
121 unsigned int scan_align = info->pixmap.scan_align - 1;
122 unsigned int buf_align = info->pixmap.buf_align - 1;
123 unsigned int shift_low = 0, mod = vc->vc_font.width % 8;
124 unsigned int shift_high = 8, pitch, cnt, size, k;
125 unsigned int idx = vc->vc_font.width >> 3;
126 unsigned int attribute = get_attribute(info, scr_readw(s));
127 struct fb_image image;
128 u8 *src, *dst, *buf = NULL;
129
130 if (attribute) {
131 buf = kmalloc(cellsize, GFP_KERNEL);
132 if (!buf)
133 return;
134 }
135
136 image.fg_color = fg;
137 image.bg_color = bg;
138
139 image.dx = xx * vc->vc_font.width;
140 image.dy = yy * vc->vc_font.height;
141 image.height = vc->vc_font.height;
142 image.depth = 1;
143
144 if (info->pixmap.outbuf && info->pixmap.inbuf) {
145 move_aligned = fb_iomove_buf_aligned;
146 move_unaligned = fb_iomove_buf_unaligned;
147 } else {
148 move_aligned = fb_sysmove_buf_aligned;
149 move_unaligned = fb_sysmove_buf_unaligned;
150 }
151 while (count) {
152 if (count > maxcnt)
153 cnt = k = maxcnt;
154 else
155 cnt = k = count;
156
157 image.width = vc->vc_font.width * cnt;
158 pitch = ((image.width + 7) >> 3) + scan_align;
159 pitch &= ~scan_align;
160 size = pitch * image.height + buf_align;
161 size &= ~buf_align;
162 dst = fb_get_buffer_offset(info, &info->pixmap, size);
163 image.data = dst;
164 if (mod) {
165 while (k--) {
166 src = vc->vc_font.data + (scr_readw(s++)&
167 charmask)*cellsize;
168
169 if (attribute) {
170 update_attr(buf, src, attribute, vc);
171 src = buf;
172 }
173
174 move_unaligned(info, &info->pixmap, dst, pitch,
175 src, idx, image.height,
176 shift_high, shift_low, mod);
177 shift_low += mod;
178 dst += (shift_low >= 8) ? width : width - 1;
179 shift_low &= 7;
180 shift_high = 8 - shift_low;
181 }
182 } else {
183 while (k--) {
184 src = vc->vc_font.data + (scr_readw(s++)&
185 charmask)*cellsize;
186
187 if (attribute) {
188 update_attr(buf, src, attribute, vc);
189 src = buf;
190 }
191
192 move_aligned(info, &info->pixmap, dst, pitch,
193 src, idx, image.height);
194 dst += width;
195 }
196 }
197 info->fbops->fb_imageblit(info, &image);
198 image.dx += cnt * vc->vc_font.width;
199 count -= cnt;
200 }
201
202 if (buf)
203 kfree(buf);
204}
205
206static void bit_clear_margins(struct vc_data *vc, struct fb_info *info,
207 int bottom_only)
208{
209 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
210 unsigned int cw = vc->vc_font.width;
211 unsigned int ch = vc->vc_font.height;
212 unsigned int rw = info->var.xres - (vc->vc_cols*cw);
213 unsigned int bh = info->var.yres - (vc->vc_rows*ch);
214 unsigned int rs = info->var.xres - rw;
215 unsigned int bs = info->var.yres - bh;
216 struct fb_fillrect region;
217
218 region.color = attr_bgcol_ec(bgshift, vc);
219 region.rop = ROP_COPY;
220
221 if (rw && !bottom_only) {
222 region.dx = info->var.xoffset + rs;
223 region.dy = 0;
224 region.width = rw;
225 region.height = info->var.yres_virtual;
226 info->fbops->fb_fillrect(info, ®ion);
227 }
228
229 if (bh) {
230 region.dx = info->var.xoffset;
231 region.dy = info->var.yoffset + bs;
232 region.width = rs;
233 region.height = bh;
234 info->fbops->fb_fillrect(info, ®ion);
235 }
236}
237
238static void bit_cursor(struct vc_data *vc, struct fb_info *info,
239 struct display *p, int mode, int fg, int bg)
240{
241 struct fb_cursor cursor;
242 struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
243 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
244 int w = (vc->vc_font.width + 7) >> 3, c;
245 int y = real_y(p, vc->vc_y);
246 int attribute, use_sw = (vc->vc_cursor_type & 0x10);
247 char *src;
248
249 cursor.set = 0;
250
251 c = scr_readw((u16 *) vc->vc_pos);
252 attribute = get_attribute(info, c);
253 src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));
254
255 if (ops->cursor_state.image.data != src ||
256 ops->cursor_reset) {
257 ops->cursor_state.image.data = src;
258 cursor.set |= FB_CUR_SETIMAGE;
259 }
260
261 if (attribute) {
262 u8 *dst;
263
264 dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
265 if (!dst)
266 return;
267 if (ops->cursor_data)
268 kfree(ops->cursor_data);
269 ops->cursor_data = dst;
270 update_attr(dst, src, attribute, vc);
271 src = dst;
272 }
273
274 if (ops->cursor_state.image.fg_color != fg ||
275 ops->cursor_state.image.bg_color != bg ||
276 ops->cursor_reset) {
277 ops->cursor_state.image.fg_color = fg;
278 ops->cursor_state.image.bg_color = bg;
279 cursor.set |= FB_CUR_SETCMAP;
280 }
281
282 if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->vc_x)) ||
283 (ops->cursor_state.image.dy != (vc->vc_font.height * y)) ||
284 ops->cursor_reset) {
285 ops->cursor_state.image.dx = vc->vc_font.width * vc->vc_x;
286 ops->cursor_state.image.dy = vc->vc_font.height * y;
287 cursor.set |= FB_CUR_SETPOS;
288 }
289
290 if (ops->cursor_state.image.height != vc->vc_font.height ||
291 ops->cursor_state.image.width != vc->vc_font.width ||
292 ops->cursor_reset) {
293 ops->cursor_state.image.height = vc->vc_font.height;
294 ops->cursor_state.image.width = vc->vc_font.width;
295 cursor.set |= FB_CUR_SETSIZE;
296 }
297
298 if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
299 ops->cursor_reset) {
300 ops->cursor_state.hot.x = cursor.hot.y = 0;
301 cursor.set |= FB_CUR_SETHOT;
302 }
303
304 if (cursor.set & FB_CUR_SETSIZE ||
305 vc->vc_cursor_type != p->cursor_shape ||
306 ops->cursor_state.mask == NULL ||
307 ops->cursor_reset) {
308 char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
309 int cur_height, size, i = 0;
310 u8 msk = 0xff;
311
312 if (!mask)
313 return;
314
315 if (ops->cursor_state.mask)
316 kfree(ops->cursor_state.mask);
317 ops->cursor_state.mask = mask;
318
319 p->cursor_shape = vc->vc_cursor_type;
320 cursor.set |= FB_CUR_SETSHAPE;
321
322 switch (p->cursor_shape & CUR_HWMASK) {
323 case CUR_NONE:
324 cur_height = 0;
325 break;
326 case CUR_UNDERLINE:
327 cur_height = (vc->vc_font.height < 10) ? 1 : 2;
328 break;
329 case CUR_LOWER_THIRD:
330 cur_height = vc->vc_font.height/3;
331 break;
332 case CUR_LOWER_HALF:
333 cur_height = vc->vc_font.height >> 1;
334 break;
335 case CUR_TWO_THIRDS:
336 cur_height = (vc->vc_font.height << 1)/3;
337 break;
338 case CUR_BLOCK:
339 default:
340 cur_height = vc->vc_font.height;
341 break;
342 }
343 size = (vc->vc_font.height - cur_height) * w;
344 while (size--)
345 mask[i++] = ~msk;
346 size = cur_height * w;
347 while (size--)
348 mask[i++] = msk;
349 }
350
351 switch (mode) {
352 case CM_ERASE:
353 ops->cursor_state.enable = 0;
354 break;
355 case CM_DRAW:
356 case CM_MOVE:
357 default:
358 ops->cursor_state.enable = (use_sw) ? 0 : 1;
359 break;
360 }
361
362 cursor.image.data = src;
363 cursor.image.fg_color = ops->cursor_state.image.fg_color;
364 cursor.image.bg_color = ops->cursor_state.image.bg_color;
365 cursor.image.dx = ops->cursor_state.image.dx;
366 cursor.image.dy = ops->cursor_state.image.dy;
367 cursor.image.height = ops->cursor_state.image.height;
368 cursor.image.width = ops->cursor_state.image.width;
369 cursor.hot.x = ops->cursor_state.hot.x;
370 cursor.hot.y = ops->cursor_state.hot.y;
371 cursor.mask = ops->cursor_state.mask;
372 cursor.enable = ops->cursor_state.enable;
373 cursor.image.depth = 1;
374 cursor.rop = ROP_XOR;
375
376 info->fbops->fb_cursor(info, &cursor);
377
378 ops->cursor_reset = 0;
379}
380
381void fbcon_set_bitops(struct fbcon_ops *ops)
382{
383 ops->bmove = bit_bmove;
384 ops->clear = bit_clear;
385 ops->putcs = bit_putcs;
386 ops->clear_margins = bit_clear_margins;
387 ops->cursor = bit_cursor;
388}
389
390EXPORT_SYMBOL(fbcon_set_bitops);
391
392MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
393MODULE_DESCRIPTION("Bit Blitting Operation");
394MODULE_LICENSE("GPL");
395
396