1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
/*
* linux/drivers/video/fbgen.c -- Generic routines for frame buffer devices
*
* Created 3 Jan 1998 by Geert Uytterhoeven
*
* 2001 - Documented with DocBook
* - Brad Douglas <brad@neruo.com>
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*/
#include <linux/module.h>
#include <linux/string.h>
#include <linux/tty.h>
#include <linux/fb.h>
#include <linux/slab.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <video/fbcon.h>
static int currcon = 0;
/* ---- `Generic' versions of the frame buffer device operations ----------- */
/**
* fbgen_get_fix - get fixed part of display
* @fix: fb_fix_screeninfo structure
* @con: virtual console number
* @info: frame buffer info structure
*
* Get the fixed information part of the display and place it
* into @fix for virtual console @con on device @info.
*
* Returns negative errno on error, or zero on success.
*
*/
int fbgen_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
{
struct fb_info_gen *info2 = (struct fb_info_gen *)info;
struct fbgen_hwswitch *fbhw = info2->fbhw;
char par[info2->parsize];
if (con == -1)
fbhw->get_par(&par, info2);
else {
int err;
if ((err = fbhw->decode_var(&fb_display[con].var, &par, info2)))
return err;
}
memset(fix, 0, sizeof(struct fb_fix_screeninfo));
return fbhw->encode_fix(fix, &par, info2);
}
/**
* fbgen_get_var - get user defined part of display
* @var: fb_var_screeninfo structure
* @con: virtual console number
* @info: frame buffer info structure
*
* Get the user defined part of the display and place it into @var
* for virtual console @con on device @info.
*
* Returns negative errno on error, or zero for success.
*
*/
int fbgen_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
{
struct fb_info_gen *info2 = (struct fb_info_gen *)info;
struct fbgen_hwswitch *fbhw = info2->fbhw;
char par[info2->parsize];
if (con == -1) {
fbhw->get_par(&par, info2);
fbhw->encode_var(var, &par, info2);
} else
*var = fb_display[con].var;
return 0;
}
/**
* fbgen_set_var - set the user defined part of display
* @var: fb_var_screeninfo user defined part of the display
* @con: virtual console number
* @info: frame buffer info structure
*
* Set the user defined part of the display as dictated by @var
* for virtual console @con on device @info.
*
* Returns negative errno on error, or zero for success.
*
*/
int fbgen_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
{
struct fb_info_gen *info2 = (struct fb_info_gen *)info;
int err;
int oldxres, oldyres, oldbpp, oldxres_virtual, oldyres_virtual, oldyoffset;
if ((err = fbgen_do_set_var(var, con == currcon, info2)))
return err;
if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
oldxres = fb_display[con].var.xres;
oldyres = fb_display[con].var.yres;
oldxres_virtual = fb_display[con].var.xres_virtual;
oldyres_virtual = fb_display[con].var.yres_virtual;
oldbpp = fb_display[con].var.bits_per_pixel;
oldyoffset = fb_display[con].var.yoffset;
fb_display[con].var = *var;
if (oldxres != var->xres || oldyres != var->yres ||
oldxres_virtual != var->xres_virtual ||
oldyres_virtual != var->yres_virtual ||
oldbpp != var->bits_per_pixel ||
oldyoffset != var->yoffset) {
fbgen_set_disp(con, info2);
if (info->changevar)
(*info->changevar)(con);
if ((err = fb_alloc_cmap(&fb_display[con].cmap, 0, 0)))
return err;
fbgen_install_cmap(con, info2);
}
}
var->activate = 0;
return 0;
}
/**
* fbgen_get_cmap - get the colormap
* @cmap: frame buffer colormap structure
* @kspc: boolean, 0 copy local, 1 put_user() function
* @con: virtual console number
* @info: frame buffer info structure
*
* Gets the colormap for virtual console @con and places it into
* @cmap for device @info.
*
* Returns negative errno on error, or zero for success.
*
*/
int fbgen_get_cmap(struct fb_cmap *cmap, int kspc, int con,
struct fb_info *info)
{
struct fb_info_gen *info2 = (struct fb_info_gen *)info;
struct fbgen_hwswitch *fbhw = info2->fbhw;
if (con == currcon) /* current console ? */
return fb_get_cmap(cmap, kspc, fbhw->getcolreg, info);
else
if (fb_display[con].cmap.len) /* non default colormap ? */
fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
else {
int size = fb_display[con].var.bits_per_pixel == 16 ? 64 : 256;
fb_copy_cmap(fb_default_cmap(size), cmap, kspc ? 0 : 2);
}
return 0;
}
/**
* fbgen_set_cmap - set the colormap
* @cmap: frame buffer colormap structure
* @kspc: boolean, 0 copy local, 1 get_user() function
* @con: virtual console number
* @info: frame buffer info structure
*
* Sets the colormap @cmap for virtual console @con on
* device @info.
*
* Returns negative errno on error, or zero for success.
*
*/
int fbgen_set_cmap(struct fb_cmap *cmap, int kspc, int con,
struct fb_info *info)
{
struct fb_info_gen *info2 = (struct fb_info_gen *)info;
struct fbgen_hwswitch *fbhw = info2->fbhw;
int err;
if (!fb_display[con].cmap.len) { /* no colormap allocated ? */
int size = fb_display[con].var.bits_per_pixel == 16 ? 64 : 256;
if ((err = fb_alloc_cmap(&fb_display[con].cmap, size, 0)))
return err;
}
if (con == currcon) /* current console ? */
return fb_set_cmap(cmap, kspc, fbhw->setcolreg, info);
else
fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1);
return 0;
}
/**
* fbgen_pan_display - pan or wrap the display
* @var: frame buffer user defined part of display
* @con: virtual console number
* @info: frame buffer info structure
*
* Pan or wrap virtual console @con for device @info.
*
* This call looks only at xoffset, yoffset and the
* FB_VMODE_YWRAP flag in @var.
*
* Returns negative errno on error, or zero for success.
*
*/
int fbgen_pan_display(struct fb_var_screeninfo *var, int con,
struct fb_info *info)
{
struct fb_info_gen *info2 = (struct fb_info_gen *)info;
struct fbgen_hwswitch *fbhw = info2->fbhw;
int xoffset = var->xoffset;
int yoffset = var->yoffset;
int err;
if (xoffset < 0 ||
xoffset+fb_display[con].var.xres > fb_display[con].var.xres_virtual ||
yoffset < 0 ||
yoffset+fb_display[con].var.yres > fb_display[con].var.yres_virtual)
return -EINVAL;
if (con == currcon) {
if (fbhw->pan_display) {
if ((err = fbhw->pan_display(var, info2)))
return err;
} else
return -EINVAL;
}
fb_display[con].var.xoffset = var->xoffset;
fb_display[con].var.yoffset = var->yoffset;
if (var->vmode & FB_VMODE_YWRAP)
fb_display[con].var.vmode |= FB_VMODE_YWRAP;
else
fb_display[con].var.vmode &= ~FB_VMODE_YWRAP;
return 0;
}
/* ---- Helper functions --------------------------------------------------- */
/**
* fbgen_do_set_var - change the video mode
* @var: frame buffer user defined part of display
* @isactive: boolean, 0 inactive, 1 active
* @info: generic frame buffer info structure
*
* Change the video mode settings for device @info. If @isactive
* is non-zero, the changes will be activated immediately.
*
* Return negative errno on error, or zero for success.
*
*/
int fbgen_do_set_var(struct fb_var_screeninfo *var, int isactive,
struct fb_info_gen *info)
{
struct fbgen_hwswitch *fbhw = info->fbhw;
int err, activate;
char par[info->parsize];
if ((err = fbhw->decode_var(var, &par, info)))
return err;
activate = var->activate;
if (((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) && isactive)
fbhw->set_par(&par, info);
fbhw->encode_var(var, &par, info);
var->activate = activate;
return 0;
}
/**
* fbgen_set_disp - set generic display
* @con: virtual console number
* @info: generic frame buffer info structure
*
* Sets a display on virtual console @con for device @info.
*
*/
void fbgen_set_disp(int con, struct fb_info_gen *info)
{
struct fbgen_hwswitch *fbhw = info->fbhw;
struct fb_fix_screeninfo fix;
char par[info->parsize];
struct display *display;
if (con >= 0)
display = &fb_display[con];
else
display = info->info.disp; /* used during initialization */
if (con == -1)
fbhw->get_par(&par, info);
else
fbhw->decode_var(&fb_display[con].var, &par, info);
memset(&fix, 0, sizeof(struct fb_fix_screeninfo));
fbhw->encode_fix(&fix, &par, info);
display->visual = fix.visual;
display->type = fix.type;
display->type_aux = fix.type_aux;
display->ypanstep = fix.ypanstep;
display->ywrapstep = fix.ywrapstep;
display->line_length = fix.line_length;
if (info->fbhw->blank || fix.visual == FB_VISUAL_PSEUDOCOLOR ||
fix.visual == FB_VISUAL_DIRECTCOLOR)
display->can_soft_blank = 1;
else
display->can_soft_blank = 0;
fbhw->set_disp(&par, display, info);
#if 0 /* FIXME: generic inverse is not supported yet */
display->inverse = (fix.visual == FB_VISUAL_MONO01 ? !inverse : inverse);
#else
display->inverse = fix.visual == FB_VISUAL_MONO01;
#endif
}
/**
* fbgen_install_cmap - install the current colormap
* @con: virtual console number
* @info: generic frame buffer info structure
*
* Installs the current colormap for virtual console @con on
* device @info.
*
*/
void fbgen_install_cmap(int con, struct fb_info_gen *info)
{
struct fbgen_hwswitch *fbhw = info->fbhw;
if (con != currcon)
return;
if (fb_display[con].cmap.len)
fb_set_cmap(&fb_display[con].cmap, 1, fbhw->setcolreg, &info->info);
else {
int size = fb_display[con].var.bits_per_pixel == 16 ? 64 : 256;
fb_set_cmap(fb_default_cmap(size), 1, fbhw->setcolreg, &info->info);
}
}
/**
* fbgen_update_var - update user defined part of display
* @con: virtual console number
* @info: frame buffer info structure
*
* Updates the user defined part of the display ('var'
* structure) on virtual console @con for device @info.
* This function is called by fbcon.c.
*
* Returns negative errno on error, or zero for success.
*
*/
int fbgen_update_var(int con, struct fb_info *info)
{
struct fb_info_gen *info2 = (struct fb_info_gen *)info;
struct fbgen_hwswitch *fbhw = info2->fbhw;
int err;
if (fbhw->pan_display) {
if ((err = fbhw->pan_display(&fb_display[con].var, info2)))
return err;
}
return 0;
}
/**
* fbgen_switch - switch to a different virtual console.
* @con: virtual console number
* @info: frame buffer info structure
*
* Switch to virtuall console @con on device @info.
*
* Returns zero.
*
*/
int fbgen_switch(int con, struct fb_info *info)
{
struct fb_info_gen *info2 = (struct fb_info_gen *)info;
struct fbgen_hwswitch *fbhw = info2->fbhw;
/* Do we have to save the colormap ? */
if (fb_display[currcon].cmap.len)
fb_get_cmap(&fb_display[currcon].cmap, 1, fbhw->getcolreg,
&info2->info);
fbgen_do_set_var(&fb_display[con].var, 1, info2);
currcon = con;
/* Install new colormap */
fbgen_install_cmap(con, info2);
return 0;
}
/**
* fbgen_blank - blank the screen
* @blank: boolean, 0 unblank, 1 blank
* @info: frame buffer info structure
*
* Blank the screen on device @info.
*
*/
void fbgen_blank(int blank, struct fb_info *info)
{
struct fb_info_gen *info2 = (struct fb_info_gen *)info;
struct fbgen_hwswitch *fbhw = info2->fbhw;
u16 black[16];
struct fb_cmap cmap;
if (fbhw->blank && !fbhw->blank(blank, info2))
return;
if (blank) {
memset(black, 0, 16*sizeof(u16));
cmap.red = black;
cmap.green = black;
cmap.blue = black;
cmap.transp = NULL;
cmap.start = 0;
cmap.len = 16;
fb_set_cmap(&cmap, 1, fbhw->setcolreg, info);
} else
fbgen_install_cmap(currcon, info2);
}
|