[PATCH 1/3: FBDEV: VGA State Save/Restore module
Hi,
Attached is a patch against linux-2.5.50 + James Simmons fbdev.diff to save and restore the VGA state. This includes character maps (plane 0-3), the colormap, and the video mode. This can be used in fb_open() and fb_release() to go back to VGA text/graphics mode.
Usage:
struct fb_vgastate state;
/* To save VGA state */
state.flags = VGA_SAVE_MODE | VGA_SAVE_CMAP | VGA_SAVE_FONTS; fb_save_vga(&state);
/* To restore VGA state */fb_restore_vga(&state);
Limitations:
1. Restoring the VGA state from high-resolution graphics mode may result in a corrupt display which can be corrected by switching consoles. May need a screen redraw at this point. Restoring from VGA graphics mode to text mode and vice versa is okay.
2. Assumes some things about the hardware which is not universally
correct: VGA memory base is at 0xA0000, memory size is 64KB, the hardware palette is readable, etc.
Any comments welcome.
Tony
PS: Please reverse the early patch I submitted if it was applied -- vgastate.diff
drivers/video/Makefile +1 -1
@@ -6,7 +6,7 @@ # This list comes from 'grep -l EXPORT_SYMBOL *.[hc]'. export-objs := fbmem.o fbcmap.o fbmon.o modedb.o softcursor.o cfbfillrect.o \ - cfbcopyarea.o cfbimgblt.o cyber2000fb.o + cfbcopyarea.o cfbimgblt.o cyber2000fb.o vgastate.o # Each configuration option enables a list of files.
drivers/video/vgastate.c +438 -0
438 lines not on this page · raw message
include/linux/fb.h +31 -0
@@ -321,6 +321,37 @@struct fb_image image;/* Cursor image */ }; +/* VGA State Save and Restore */ +#define VGA_SAVE_FONT0 1/* save/restore plane 2 fonts */ +#define VGA_SAVE_FONT1 2/* save/restore plane 3 fonts */ +#define VGA_SAVE_TEXT 4/* save/restore plane 0/1 fonts */ +#define VGA_SAVE_FONTS 7/* save/restore all fonts */ +#define VGA_SAVE_MODE 8/* save/restore video mode */ +#define VGA_SAVE_CMAP 16/* save/restore color map/DAC */ + +struct fb_vgastate { +caddr_t vgabase;/* mmio base, if supported */ +__u32 flags;/* what state/s to save (see VGA_SAVE_*) */ +__u32 depth;/* current fb depth, not important */ +__u32 num_attr;/* number of att registers, 0 for default */ +__u32 num_crtc;/* number of crt registers, 0 for default */ +__u32 num_gfx;/* number of gfx registers, 0 for default */ +__u32 num_seq;/* number of seq registers, 0 for default */ +caddr_t fbbase;/* -- DO NOT ALTER STARTING HERE -- */ +__u8 *vga_font0; +__u8 *vga_font1; +__u8 *vga_text; +__u8 *vga_cmap; +__u8 *attr; +__u8 *crtc; +__u8 *gfx; +__u8 *seq; +__u8 misc; +}; + +extern int fb_save_vga (struct fb_vgastate *state); +extern int fb_restore_vga (struct fb_vgastate *state); +#ifdef __KERNEL__#include <linux/fs.h>
Quoted 7 lines
Limitations:
1. Restoring the VGA state from high-resolution graphics mode may result in a corrupt display which can be corrected by switching consoles. May need a screen redraw at this point. Restoring from VGA graphics mode to text mode and vice versa is okay.
Quoted 5 lines
2. Assumes some things about the hardware which is not universally
correct: VGA memory base is at0xA0000, memory size is 64KB, the hardware palette is readable, etc.Any comments welcome.
One thing I like to suggest. I like to move the vga code in fb.h to vga.h. Alot of fbdev devices don't have a VGA core.
Quoted 7 lines · James Simmons
Quoted 7 lines
Limitations:
1. Restoring the VGA state from high-resolution graphics mode may result in a corrupt display which can be corrected by switching consoles. May need a screen redraw at this point. Restoring from VGA graphics mode to text mode and vice versa is okay.
Quoted 10 lines
Quoted 5 lines
2. Assumes some things about the hardware which is not universally
correct: VGA memory base is at0xA0000, memory size is 64KB, the hardware palette is readable, etc.Any comments welcome.
One thing I like to suggest. I like to move the vga code in
fb.htovga.h. Alot of fbdev devices don't have a VGA core.
Only the structure definition of fb_vgastate is in fb.h. For drivers without a vga core, they'll just won't link to it and it won't be compiled. Plus, vga.h is not a common header (not located in include/asm or include/linux) and it contains a lot of declarations and definitions which are irrelevant to most drivers or are already duplicated. This will be messier, I think.
Maybe we can just enclose it in a macro, something like:
#ifdef FBDEV_HAS_VGACORE
...
#endif
Tony
Quoted 6 lines
Quoted 5 lines
One thing I like to suggest. I like to move the vga code in
fb.htovga.h. Alot of fbdev devices don't have a VGA core.
Quoted 6 lines
Only the structure definition of
fb_vgastateis infb.h. For drivers without a vga core, they'll just won't link to it and it won't be compiled. Plus,vga.his not a common header (not located ininclude/asmorinclude/linux) and it contains a lot of declarations and definitions which are irrelevant to most drivers or are already duplicated. This will be messier, I think.
I like to move vga.h to include/video. And yes I like to clean it up. The reason is I like to implement the function in vga.h and some in vgastate into vgacon.c. It would be nice if vgacon could support different hardware states per VC instead of changing every virtual console for everything. The other dream is I like to see vgacon become firmware independent.
Quoted 5 lines
Maybe we can just enclose it in a macro, something like:
#ifdef
FBDEV_HAS_VGACORE
...
#endif
Yuck :-(
Quoted 8 lines · James Simmons
Quoted 7 lines
Only the structure definition of
fb_vgastateis infb.h. For drivers without a vga core, they'll just won't link to it and it won't be compiled. Plus,vga.his not a common header (not located ininclude/asmorinclude/linux) and it contains a lot of declarations and definitions which are irrelevant to most drivers or are already duplicated. This will be messier, I think.
Quoted 6 lines
I like to move
vga.htoinclude/video. And yes I like to clean it up. The reason is I like to implement the function invga.hand some in vgastate intovgacon.c. It would be nice if vgacon could support different hardware states per VC instead of changing every virtual console for everything. The other dream is I like to see vgacon become firmware independent.
OK.
Tony