Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / video / console / fbcon.h
1 /*
2  *  linux/drivers/video/console/fbcon.h -- Low level frame buffer based console driver
3  *
4  *      Copyright (C) 1997 Geert Uytterhoeven
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
8  *  for more details.
9  */
10
11 #ifndef _VIDEO_FBCON_H
12 #define _VIDEO_FBCON_H
13
14 #include <linux/types.h>
15 #include <linux/vt_buffer.h>
16 #include <linux/vt_kern.h>
17
18 #include <asm/io.h>
19
20 #define FBCON_FLAGS_INIT         1
21 #define FBCON_FLAGS_CURSOR_TIMER 2
22
23    /*
24     *    This is the interface between the low-level console driver and the
25     *    low-level frame buffer device
26     */
27
28 #ifdef CONFIG_BOOTSPLASH
29 struct splash_img_data {
30         int ref_cnt;
31         int splash_color;       /* transparent color */
32         int splash_fg_color;    /* foreground color */
33         int splash_width;       /* width of image */
34         int splash_height;      /* height of image */
35         int splash_text_xo;     /* text area origin of origin */
36         int splash_text_yo;
37         int splash_text_wi;     /* text area size of jpeg*/
38         int splash_text_he;
39         int splash_boxcount;
40         int splash_sboxcount;
41         int splash_overpaintok; /* is it ok to overpaint boxes */
42         unsigned char *splash_boxes;
43         unsigned char *splash_jpeg;             /* jpeg */
44         unsigned char *splash_sboxes;
45         unsigned char *splash_silentjpeg;
46         unsigned char *splash_palette;          /* palette for 8-bit */
47 };
48
49 struct splash_pic_data {
50         int ref_cnt;
51         unsigned char *splash_pic;
52         int splash_pic_stride;
53         int splash_pic_size;
54 };
55
56 struct splash_data {
57         struct splash_data *next;
58         struct splash_img_data *imgd;
59         struct splash_pic_data *pic;
60         int splash_state;                       /* show splash? */
61         int splash_percent;
62         int splash_dosilent;                    /* show silent jpeg */
63
64         int splash_vc_text_wi;                  /* text area size used*/
65         int splash_vc_text_he;
66         int splash_boxes_xoff;
67         int splash_boxes_yoff;
68         int splash_sboxes_xoff;
69         int splash_sboxes_yoff;
70
71         bool color_set;
72         bool need_sync;
73 };
74 #endif
75
76 struct display {
77     /* Filled in by the low-level console driver */
78     const u_char *fontdata;
79     int userfont;                   /* != 0 if fontdata kmalloc()ed */
80     u_short scrollmode;             /* Scroll Method */
81     u_short inverse;                /* != 0 text black on white as default */
82     short yscroll;                  /* Hardware scrolling */
83     int vrows;                      /* number of virtual rows */
84     int cursor_shape;
85     int con_rotate;
86     u32 xres_virtual;
87     u32 yres_virtual;
88     u32 height;
89     u32 width;
90     u32 bits_per_pixel;
91     u32 grayscale;
92     u32 nonstd;
93     u32 accel_flags;
94     u32 rotate;
95     struct fb_bitfield red;
96     struct fb_bitfield green;
97     struct fb_bitfield blue;
98     struct fb_bitfield transp;
99     const struct fb_videomode *mode;
100 };
101
102 struct fbcon_ops {
103         void (*bmove)(struct vc_data *vc, struct fb_info *info, int sy,
104                       int sx, int dy, int dx, int height, int width);
105         void (*clear)(struct vc_data *vc, struct fb_info *info, int sy,
106                       int sx, int height, int width);
107         void (*putcs)(struct vc_data *vc, struct fb_info *info,
108                       const unsigned short *s, int count, int yy, int xx,
109                       int fg, int bg);
110         void (*clear_margins)(struct vc_data *vc, struct fb_info *info,
111                               int bottom_only);
112         void (*cursor)(struct vc_data *vc, struct fb_info *info, int mode,
113                        int softback_lines, int fg, int bg);
114         int  (*update_start)(struct fb_info *info);
115         int  (*rotate_font)(struct fb_info *info, struct vc_data *vc);
116         struct fb_var_screeninfo var;  /* copy of the current fb_var_screeninfo */
117         struct timer_list cursor_timer; /* Cursor timer */
118         struct fb_cursor cursor_state;
119         struct display *p;
120         int    currcon;                 /* Current VC. */
121         int    cursor_flash;
122         int    cursor_reset;
123         int    blank_state;
124         int    graphics;
125         int    save_graphics; /* for debug enter/leave */
126         int    flags;
127         int    rotate;
128         int    cur_rotate;
129         char  *cursor_data;
130         u8    *fontbuffer;
131         u8    *fontdata;
132         u8    *cursor_src;
133         u32    cursor_size;
134         u32    fd_size;
135 };
136     /*
137      *  Attribute Decoding
138      */
139
140 /* Color */
141 #define attr_fgcol(fgshift,s)    \
142         (((s) >> (fgshift)) & 0x0f)
143 #define attr_bgcol(bgshift,s)    \
144         (((s) >> (bgshift)) & 0x0f)
145
146 /* Monochrome */
147 #define attr_bold(s) \
148         ((s) & 0x200)
149 #define attr_reverse(s) \
150         ((s) & 0x800)
151 #define attr_underline(s) \
152         ((s) & 0x400)
153 #define attr_blink(s) \
154         ((s) & 0x8000)
155         
156
157 static inline int mono_col(const struct fb_info *info)
158 {
159         __u32 max_len;
160         max_len = max(info->var.green.length, info->var.red.length);
161         max_len = max(info->var.blue.length, max_len);
162         return (~(0xfff << max_len)) & 0xff;
163 }
164
165 static inline int attr_col_ec(int shift, struct vc_data *vc,
166                               struct fb_info *info, int is_fg)
167 {
168         int is_mono01;
169         int col;
170         int fg;
171         int bg;
172
173         if (!vc)
174                 return 0;
175
176         if (vc->vc_can_do_color)
177                 return is_fg ? attr_fgcol(shift,vc->vc_video_erase_char)
178                         : attr_bgcol(shift,vc->vc_video_erase_char);
179
180         if (!info)
181                 return 0;
182
183         col = mono_col(info);
184         is_mono01 = info->fix.visual == FB_VISUAL_MONO01;
185
186         if (attr_reverse(vc->vc_video_erase_char)) {
187                 fg = is_mono01 ? col : 0;
188                 bg = is_mono01 ? 0 : col;
189         }
190         else {
191                 fg = is_mono01 ? 0 : col;
192                 bg = is_mono01 ? col : 0;
193         }
194
195         return is_fg ? fg : bg;
196 }
197
198 #define attr_bgcol_ec(bgshift, vc, info) attr_col_ec(bgshift, vc, info, 0)
199 #define attr_fgcol_ec(fgshift, vc, info) attr_col_ec(fgshift, vc, info, 1)
200
201 /* Font */
202 #define REFCOUNT(fd)    (((int *)(fd))[-1])
203 #define FNTSIZE(fd)     (((int *)(fd))[-2])
204 #define FNTCHARCNT(fd)  (((int *)(fd))[-3])
205 #define FNTSUM(fd)      (((int *)(fd))[-4])
206 #define FONT_EXTRA_WORDS 4
207
208     /*
209      *  Scroll Method
210      */
211      
212 /* There are several methods fbcon can use to move text around the screen:
213  *
214  *                     Operation   Pan    Wrap
215  *---------------------------------------------
216  * SCROLL_MOVE         copyarea    No     No
217  * SCROLL_PAN_MOVE     copyarea    Yes    No
218  * SCROLL_WRAP_MOVE    copyarea    No     Yes
219  * SCROLL_REDRAW       imageblit   No     No
220  * SCROLL_PAN_REDRAW   imageblit   Yes    No
221  * SCROLL_WRAP_REDRAW  imageblit   No     Yes
222  *
223  * (SCROLL_WRAP_REDRAW is not implemented yet)
224  *
225  * In general, fbcon will choose the best scrolling
226  * method based on the rule below:
227  *
228  * Pan/Wrap > accel imageblit > accel copyarea >
229  * soft imageblit > (soft copyarea)
230  *
231  * Exception to the rule: Pan + accel copyarea is
232  * preferred over Pan + accel imageblit.
233  *
234  * The above is typical for PCI/AGP cards. Unless
235  * overridden, fbcon will never use soft copyarea.
236  *
237  * If you need to override the above rule, set the
238  * appropriate flags in fb_info->flags.  For example,
239  * to prefer copyarea over imageblit, set
240  * FBINFO_READS_FAST.
241  *
242  * Other notes:
243  * + use the hardware engine to move the text
244  *    (hw-accelerated copyarea() and fillrect())
245  * + use hardware-supported panning on a large virtual screen
246  * + amifb can not only pan, but also wrap the display by N lines
247  *    (i.e. visible line i = physical line (i+N) % yres).
248  * + read what's already rendered on the screen and
249  *     write it in a different place (this is cfb_copyarea())
250  * + re-render the text to the screen
251  *
252  * Whether to use wrapping or panning can only be figured out at
253  * runtime (when we know whether our font height is a multiple
254  * of the pan/wrap step)
255  *
256  */
257
258 #define SCROLL_MOVE        0x001
259 #define SCROLL_PAN_MOVE    0x002
260 #define SCROLL_WRAP_MOVE   0x003
261 #define SCROLL_REDRAW      0x004
262 #define SCROLL_PAN_REDRAW  0x005
263
264 #ifdef CONFIG_FB_TILEBLITTING
265 extern void fbcon_set_tileops(struct vc_data *vc, struct fb_info *info);
266 #endif
267 extern void fbcon_set_bitops(struct fbcon_ops *ops);
268 extern int  soft_cursor(struct fb_info *info, struct fb_cursor *cursor);
269
270 #define FBCON_ATTRIBUTE_UNDERLINE 1
271 #define FBCON_ATTRIBUTE_REVERSE   2
272 #define FBCON_ATTRIBUTE_BOLD      4
273
274 static inline int real_y(struct display *p, int ypos)
275 {
276         int rows = p->vrows;
277
278         ypos += p->yscroll;
279         return ypos < rows ? ypos : ypos - rows;
280 }
281
282
283 static inline int get_attribute(struct fb_info *info, u16 c)
284 {
285         int attribute = 0;
286
287         if (fb_get_color_depth(&info->var, &info->fix) == 1) {
288                 if (attr_underline(c))
289                         attribute |= FBCON_ATTRIBUTE_UNDERLINE;
290                 if (attr_reverse(c))
291                         attribute |= FBCON_ATTRIBUTE_REVERSE;
292                 if (attr_bold(c))
293                         attribute |= FBCON_ATTRIBUTE_BOLD;
294         }
295
296         return attribute;
297 }
298
299 #define FBCON_SWAP(i,r,v) ({ \
300         typeof(r) _r = (r);  \
301         typeof(v) _v = (v);  \
302         (void) (&_r == &_v); \
303         (i == FB_ROTATE_UR || i == FB_ROTATE_UD) ? _r : _v; })
304
305 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
306 extern void fbcon_set_rotate(struct fbcon_ops *ops);
307 #else
308 #define fbcon_set_rotate(x) do {} while(0)
309 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
310
311 #endif /* _VIDEO_FBCON_H */
312