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 #include <linux/workqueue.h>
18
19 #include <asm/io.h>
20
21 /*
22 * This is the interface between the low-level console driver and the
23 * low-level frame buffer device
24 */
25
26 struct fbcon_display {
27 /* Filled in by the low-level console driver */
28 const u_char *fontdata;
29 int userfont; /* != 0 if fontdata kmalloc()ed */
30 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
31 u_short scrollmode; /* Scroll Method, use fb_scrollmode() */
32 #endif
33 short yscroll; /* Hardware scrolling */
34 int vrows; /* number of virtual rows */
35 int cursor_shape;
36 int con_rotate;
37 u32 xres_virtual;
38 u32 yres_virtual;
39 u32 height;
40 u32 width;
41 u32 bits_per_pixel;
42 u32 grayscale;
43 u32 nonstd;
44 u32 accel_flags;
45 u32 rotate;
46 struct fb_bitfield red;
47 struct fb_bitfield green;
48 struct fb_bitfield blue;
49 struct fb_bitfield transp;
50 const struct fb_videomode *mode;
51 };
52
53 struct fbcon_bitops {
54 void (*bmove)(struct vc_data *vc, struct fb_info *info, int sy,
55 int sx, int dy, int dx, int height, int width);
56 void (*clear)(struct vc_data *vc, struct fb_info *info, int sy,
57 int sx, int height, int width, int fb, int bg);
58 void (*putcs)(struct vc_data *vc, struct fb_info *info,
59 const unsigned short *s, int count, int yy, int xx,
60 int fg, int bg);
61 void (*clear_margins)(struct vc_data *vc, struct fb_info *info,
62 int color, int bottom_only);
63 void (*cursor)(struct vc_data *vc, struct fb_info *info,
64 bool enable, int fg, int bg);
65 int (*update_start)(struct fb_info *info);
66 int (*rotate_font)(struct fb_info *info, struct vc_data *vc);
67 };
68
69 struct fbcon_par {
70 struct fb_var_screeninfo var; /* copy of the current fb_var_screeninfo */
71 struct delayed_work cursor_work; /* Cursor timer */
72 struct fb_cursor cursor_state;
73 struct fbcon_display *p;
74 struct fb_info *info;
75 int currcon; /* Current VC. */
76 int cur_blink_jiffies;
77 int cursor_flash;
78 int cursor_reset;
79 int blank_state;
80 int graphics;
81 bool initialized;
82 int rotate;
83 int cur_rotate;
84 char *cursor_data;
85 u8 *fontbuffer;
86 u8 *fontdata;
87 u8 *cursor_src;
88 u32 cursor_size;
89 u32 fd_size;
90
91 const struct fbcon_bitops *bitops;
92 };
93
94 /*
95 * Attribute Decoding
96 */
97
98 /* Color */
99 #define attr_fgcol(fgshift,s) \
100 (((s) >> (fgshift)) & 0x0f)
101 #define attr_bgcol(bgshift,s) \
102 (((s) >> (bgshift)) & 0x0f)
103
104 /* Monochrome */
105 #define attr_bold(s) \
106 ((s) & 0x200)
107 #define attr_reverse(s) \
108 ((s) & 0x800)
109 #define attr_underline(s) \
110 ((s) & 0x400)
111 #define attr_blink(s) \
112 ((s) & 0x8000)
113
mono_col(const struct fb_info * info)114 static inline int mono_col(const struct fb_info *info)
115 {
116 __u32 max_len;
117 max_len = max(info->var.green.length, info->var.red.length);
118 max_len = max(info->var.blue.length, max_len);
119 return (~(0xfff << max_len)) & 0xff;
120 }
121
122 /*
123 * Scroll Method
124 */
125
126 /* There are several methods fbcon can use to move text around the screen:
127 *
128 * Operation Pan Wrap
129 *---------------------------------------------
130 * SCROLL_MOVE copyarea No No
131 * SCROLL_PAN_MOVE copyarea Yes No
132 * SCROLL_WRAP_MOVE copyarea No Yes
133 * SCROLL_REDRAW imageblit No No
134 * SCROLL_PAN_REDRAW imageblit Yes No
135 * SCROLL_WRAP_REDRAW imageblit No Yes
136 *
137 * (SCROLL_WRAP_REDRAW is not implemented yet)
138 *
139 * In general, fbcon will choose the best scrolling
140 * method based on the rule below:
141 *
142 * Pan/Wrap > accel imageblit > accel copyarea >
143 * soft imageblit > (soft copyarea)
144 *
145 * Exception to the rule: Pan + accel copyarea is
146 * preferred over Pan + accel imageblit.
147 *
148 * The above is typical for PCI/AGP cards. Unless
149 * overridden, fbcon will never use soft copyarea.
150 *
151 * If you need to override the above rule, set the
152 * appropriate flags in fb_info->flags. For example,
153 * to prefer copyarea over imageblit, set
154 * FBINFO_READS_FAST.
155 *
156 * Other notes:
157 * + use the hardware engine to move the text
158 * (hw-accelerated copyarea() and fillrect())
159 * + use hardware-supported panning on a large virtual screen
160 * + amifb can not only pan, but also wrap the display by N lines
161 * (i.e. visible line i = physical line (i+N) % yres).
162 * + read what's already rendered on the screen and
163 * write it in a different place (this is cfb_copyarea())
164 * + re-render the text to the screen
165 *
166 * Whether to use wrapping or panning can only be figured out at
167 * runtime (when we know whether our font height is a multiple
168 * of the pan/wrap step)
169 *
170 */
171
172 #define SCROLL_MOVE 0x001
173 #define SCROLL_PAN_MOVE 0x002
174 #define SCROLL_WRAP_MOVE 0x003
175 #define SCROLL_REDRAW 0x004
176 #define SCROLL_PAN_REDRAW 0x005
177
fb_scrollmode(struct fbcon_display * fb)178 static inline u_short fb_scrollmode(struct fbcon_display *fb)
179 {
180 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
181 return fb->scrollmode;
182 #else
183 /* hardcoded to SCROLL_REDRAW if acceleration was disabled. */
184 return SCROLL_REDRAW;
185 #endif
186 }
187
188
189 #ifdef CONFIG_FB_TILEBLITTING
190 extern void fbcon_set_tileops(struct vc_data *vc, struct fb_info *info);
191 #endif
192 extern void fbcon_set_bitops_ur(struct fbcon_par *par);
193 extern int soft_cursor(struct fb_info *info, struct fb_cursor *cursor);
194
195 #define FBCON_ATTRIBUTE_UNDERLINE 1
196 #define FBCON_ATTRIBUTE_REVERSE 2
197 #define FBCON_ATTRIBUTE_BOLD 4
198
real_y(struct fbcon_display * p,int ypos)199 static inline int real_y(struct fbcon_display *p, int ypos)
200 {
201 int rows = p->vrows;
202
203 ypos += p->yscroll;
204 return ypos < rows ? ypos : ypos - rows;
205 }
206
207
get_attribute(struct fb_info * info,u16 c)208 static inline int get_attribute(struct fb_info *info, u16 c)
209 {
210 int attribute = 0;
211
212 if (fb_get_color_depth(&info->var, &info->fix) == 1) {
213 if (attr_underline(c))
214 attribute |= FBCON_ATTRIBUTE_UNDERLINE;
215 if (attr_reverse(c))
216 attribute |= FBCON_ATTRIBUTE_REVERSE;
217 if (attr_bold(c))
218 attribute |= FBCON_ATTRIBUTE_BOLD;
219 }
220
221 return attribute;
222 }
223
224 #define FBCON_SWAP(i,r,v) ({ \
225 typeof(r) _r = (r); \
226 typeof(v) _v = (v); \
227 (void) (&_r == &_v); \
228 (i == FB_ROTATE_UR || i == FB_ROTATE_UD) ? _r : _v; })
229
230 #endif /* _VIDEO_FBCON_H */
231