? diff.fontfix Index: config/cf/linux.cf =================================================================== RCS file: /home/eich/cvs/xc/config/cf/linux.cf,v retrieving revision 1.1.1.60 diff -u -p -r1.1.1.60 linux.cf --- config/cf/linux.cf 25 Nov 2004 16:50:09 -0000 1.1.1.60 +++ config/cf/linux.cf 14 Jan 2005 18:28:24 -0000 @@ -324,6 +324,15 @@ InstallNamedTargetNoClobber(install,file # endif #endif +/* + * Let the OS restore console fonts instead of the generic VGA + * layer. This exists for Linux only at the moment so put it + * here. + */ +#ifndef DoOSFontRestore +# define DoOSFontRestore YES +#endif + /* The DRM module requires kernel services that appeared in late 2.1.x kernels and are known to be present in 2.2.x kernels. */ #ifndef BuildXF86DRI Index: programs/Xserver/hw/xfree86/os-support/linux/Imakefile =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile,v retrieving revision 1.1.1.16 diff -u -p -r1.1.1.16 Imakefile --- programs/Xserver/hw/xfree86/os-support/linux/Imakefile 15 Sep 2004 09:37:12 -0000 1.1.1.16 +++ programs/Xserver/hw/xfree86/os-support/linux/Imakefile 14 Jan 2005 18:28:41 -0000 @@ -47,15 +47,21 @@ PLATFORM_OBJ=ia64Pci.o lnx_ia64.o PLATFORM_DEFINES=-DOS_PROBE_PCI_CHIPSET=lnxProbePciChipset #endif +#if DoOSFontRestore +FONTSRC=lnx_font.c +FONTOBJ=lnx_font.o +FONT_DEFINES=-DDO_OS_FONTRESTORE +#endif + SRCS = lnx_init.c lnx_video.c lnx_io.c libc_wrapper.c bios_mmap.c \ VTsw_usl.c std_kbdEv.c posix_tty.c $(MOUSESRC) \ lnx_pci.c vidmem.c lnx_apm.c $(JOYSTICK_SRC) $(DRI_SRC) $(RES_SRCS) \ - $(PLATFORM_SRC) lnx_kmod.c lnx_agp.c $(KBDSRC) /*wcHelper.c*/ + $(PLATFORM_SRC) lnx_kmod.c lnx_agp.c $(FONTSRC) $(KBDSRC) /*wcHelper.c*/ OBJS = lnx_init.o lnx_video.o lnx_io.o libc_wrapper.o bios_mmap.o \ VTsw_usl.o std_kbdEv.o posix_tty.o $(MOUSEOBJ) \ lnx_pci.o vidmem.o lnx_apm.o $(JOYSTICK_OBJ) $(DRI_OBJ) $(RES_OBJS) \ - $(PLATFORM_OBJ) lnx_kmod.o lnx_agp.o $(KBDOBJ) /*wcHelper.o*/ + $(PLATFORM_OBJ) lnx_kmod.o lnx_agp.o $(FONTOBJ) $(KBDOBJ) /*wcHelper.o*/ INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \ -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(XF86OSSRC)/shared \ @@ -63,10 +69,14 @@ INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC RESDEFINES = -DUSESTDRES -DEFINES = $(MTRRDEFINES) $(RESDEFINES) $(PLATFORM_DEFINES) -DHAVE_SYSV_IPC +DEFINES = $(MTRRDEFINES) $(RESDEFINES) $(PLATFORM_DEFINES) $(FONT_DEFINES) -DHAVE_SYSV_IPC #if defined(AlphaArchitecture) SpecialObjectRule(lnx_ev56.o, lnx_ev56.c, -mcpu=ev56) +#endif + +#if DoOSFontRestore +SpecialObjectRule(VTsw_usl.o, VTsw_usl.c, -DOSHEADER=\"lnx.h\" -DOSSWITCHAWAY="lnx_switchaway()") #endif SubdirLibraryRule($(OBJS)) Index: programs/Xserver/hw/xfree86/os-support/linux/lnx.h =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx.h,v retrieving revision 1.1.1.3 diff -u -p -r1.1.1.3 lnx.h --- programs/Xserver/hw/xfree86/os-support/linux/lnx.h 30 Apr 2003 14:15:22 -0000 1.1.1.3 +++ programs/Xserver/hw/xfree86/os-support/linux/lnx.h 14 Jan 2005 18:28:41 -0000 @@ -39,6 +39,13 @@ extern long (*_iobase)(unsigned, int, in # endif # endif /* __alpha__ */ +# if defined(DO_OS_FONTRESTORE) +Bool lnx_savefont(void); +Bool lnx_restorefont(void); +Bool lnx_switchaway(void); +void lnx_freefontdata(void); +# endif + #define LNX_H_ #endif Index: programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c =================================================================== RCS file: programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c diff -N programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c 14 Jan 2005 18:28:41 -0000 @@ -0,0 +1,258 @@ +/* + * Copyright 2004, Egbert Eich + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * EGBERT EICH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON- + * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Egbert Eich shall not + * be used in advertising or otherwise to promote the sale, use or other deal- + *ings in this Software without prior written authorization from Egbert Eich. + * + */ +#include "X.h" +#include "Xmd.h" + +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "lnx.h" + +#include +#include +#include + +struct { + int width; + int height; + int charcount; + unsigned char *data; +} lnxfont = { 0, 0, 0, NULL }; + + +static Bool +getfont(int *width, int *height, + int *charcount, unsigned char *data) +{ + struct console_font_op op; + struct consolefontdesc ds; + int result; + + op.op = KD_FONT_OP_GET; + op.width = *width; + op.height = *height; + op.charcount = *charcount; + op.data = data; + op.flags = 0; + + SYSCALL(result = ioctl(xf86Info.consoleFd, KDFONTOP, &op)); +#ifdef DEBUG + ErrorF("Console font read: h: %i count: %i\n",op.height,op.charcount); +#endif + + if (!result) { + + *width = op.width; + *height = op.height; + *charcount = op.charcount; + + return TRUE; + } + + if (errno != ENOSYS && errno != EINVAL) + return FALSE; + + /* GIO_FONTX fallback */ + ds.charcount = *charcount; + ds.charheight = *height; + ds.chardata = (char *)data; + *width = 8; + + SYSCALL(result = ioctl(xf86Info.consoleFd, GIO_FONTX, &ds)); + + if (!result) { + + *charcount = ds.charcount; + *height = ds.charheight; + + return TRUE; + } + + if (errno != ENOSYS && errno != EINVAL) + return FALSE; + + /* GIO_FONT fallback */ + if (*charcount < 256) + return FALSE; + + SYSCALL(result = ioctl(xf86Info.consoleFd, GIO_FONT, data)); + + if (!result) { + *height = 0; + *charcount = 512; + return TRUE; + } + + return FALSE; + +} + +Bool +lnx_savefont(void) +{ + unsigned char *fontdata; + int size; + int fd; + int width = 32, height = 32, charcount = 2048; + +#ifdef DEBUG + ErrorF("SAVE font\n"); +#endif + /* if we are in fbdev mode we don't bother saving fonts */ + if ((fd = open ("/dev/fb0",O_RDWR)) != -1) { + close (fd); + return TRUE; + } + + if (!getfont(&width, &height, &charcount, NULL)) { + xf86Msg(X_WARNING, + "lnx_savefont: cannot obtain font info\n"); + goto error; + } else if (charcount == 2048) { + xf86Msg(X_WARNING, "lnx_savefont: " + "kernel bug: kernel doesn't report font info\n"); + return FALSE; + } + + size = (width + 7)/8 * 32 * charcount; + fontdata = (unsigned char *)xnfalloc(size); + if (!fontdata) { + xf86Msg(X_WARNING, + "lnx_savefont: cannot allocate memory to save font\n"); + goto error; + } + + if (!getfont(&width, &height, &charcount, fontdata)) { + xf86Msg(X_WARNING,"lnx_savefont: cannot read font data\n"); + goto error; + } + lnxfont.width = width; + lnxfont.height = height; + lnxfont.charcount = charcount; + lnxfont.data = fontdata; + + return TRUE; + + error: + return FALSE; +} + +static Bool +setfont(int width, int height, + int charcount, unsigned char *data) +{ + struct console_font_op op; + struct consolefontdesc ds; + int result; + + op.op = KD_FONT_OP_SET; + op.flags = 0; + op.charcount = charcount; + op.width = width; + op.height = height; + op.data = data; + + SYSCALL(result = ioctl(xf86Info.consoleFd, KDFONTOP, &op)); + + if (!result) + return TRUE; + + if (errno != ENOSYS && errno != EINVAL) + return FALSE; + + /* PIO_FONTX fallback */ + if (width != 8) + return FALSE; + + ds.charcount = charcount; + ds.chardata = (char *)data; + ds.charheight = height; + SYSCALL(result = ioctl(xf86Info.consoleFd, PIO_FONTX, &ds)); + + if (!result) + return TRUE; + + if (errno != ENOSYS && errno != EINVAL) + return FALSE; + + /* PIO_FONT fallback */ + SYSCALL(result = ioctl(xf86Info.consoleFd, PIO_FONT, data)); + + if (!result) + return TRUE; + + return FALSE; +} + +Bool +lnx_restorefont(void) +{ + if (lnxfont.data == NULL) + return FALSE; +#ifdef DEBUG + ErrorF("RESTORE font\n"); +#endif +#if 0 + /* must wack the height to make the kernel reprogram the VGA registers */ + if (!setfont(lnxfont.width, lnxfont.height + 1, lnxfont.charcount, + lnxfont.data)) { + xf86Msg(X_WARNING,"lnx_fontretore: cannot write font data\n"); + return FALSE; + } +#endif + if (!setfont(lnxfont.width, lnxfont.height, lnxfont.charcount, + lnxfont.data)) { + xf86Msg(X_WARNING,"lnx_restorefont: cannot write font data\n"); + return FALSE; + } + + return TRUE; +} + +Bool +lnx_switchaway(void) +{ + Bool ret; + + /* temporarily switch to text mode */ + ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); + ret = lnx_restorefont(); + ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS); + return ret; +} + +void +lnx_freefontdata(void) +{ + if (lnxfont.data == NULL) + return; + + xfree(lnxfont.data); + lnxfont.data = NULL; + lnxfont.width = lnxfont.height = lnxfont.charcount = 0; +} Index: programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v retrieving revision 1.1.1.5 diff -u -p -r1.1.1.5 lnx_init.c --- programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c 6 Jul 2004 15:12:49 -0000 1.1.1.5 +++ programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c 14 Jan 2005 18:28:41 -0000 @@ -213,6 +213,9 @@ xf86OpenConsole(void) { xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); } +#if defined(DO_OS_FONTRESTORE) + lnx_savefont(); +#endif SYSCALL(result = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT)); if (result < 0) { @@ -270,17 +273,25 @@ void xf86CloseConsole() { struct vt_mode VT; +#if defined(DO_OS_FONTRESTORE) + struct vt_stat vts; + int vtno = -1; + if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) == 0) + vtno = vts.v_active; +#endif #if 0 ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno); ioctl(xf86Info.consoleFd, VT_WAITACTIVE, 0); #endif ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode ... */ + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) { VT.mode = VT_AUTO; ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */ } + /* * Perform a switch back to the active VT when we were started */ @@ -289,6 +300,11 @@ xf86CloseConsole() ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT); activeVT = -1; } +#if defined(DO_OS_FONTRESTORE) + if (xf86Info.vtno == vtno) + lnx_restorefont(); + lnx_freefontdata(); +#endif close(xf86Info.consoleFd); /* make the vt-manager happy */ restoreVtPerms(); /* restore the permissions */ Index: programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c,v retrieving revision 1.1.1.8 diff -u -p -r1.1.1.8 lnx_kbd.c --- programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c 6 Jul 2004 15:12:49 -0000 1.1.1.8 +++ programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c 14 Jan 2005 18:28:41 -0000 @@ -21,6 +21,9 @@ #include "xf86Xinput.h" #include "xf86OSKbd.h" #include "atKeynames.h" +#if defined(DO_OS_FONTRESTORE) +#include "lnx.h" +#endif #include "lnx_kbd.h" #define KBC_TIMEOUT 250 /* Timeout in ms for sending to keyboard controller */ Index: programs/Xserver/hw/xfree86/os-support/shared/VTsw_usl.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/os-support/shared/VTsw_usl.c,v retrieving revision 1.1.1.3 diff -u -p -r1.1.1.3 VTsw_usl.c --- programs/Xserver/hw/xfree86/os-support/shared/VTsw_usl.c 30 Apr 2003 14:15:24 -0000 1.1.1.3 +++ programs/Xserver/hw/xfree86/os-support/shared/VTsw_usl.c 14 Jan 2005 18:28:41 -0000 @@ -29,6 +29,10 @@ #include "xf86Priv.h" #include "xf86_OSlib.h" +#ifdef OSHEADER +# include OSHEADER +#endif + /* * Handle the VT-switching interface for OSs that use USL-style ioctl()s * (the sysv, sco, and linux subdirs). @@ -62,6 +66,9 @@ xf86VTSwitchAway() } else { +#ifdef OSSWITCHAWAY + OSSWITCHAWAY; +#endif return(TRUE); } } Index: programs/Xserver/hw/xfree86/vgahw/Imakefile =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/vgahw/Imakefile,v retrieving revision 1.1.1.3 diff -u -p -r1.1.1.3 Imakefile --- programs/Xserver/hw/xfree86/vgahw/Imakefile 22 Nov 2002 10:03:33 -0000 1.1.1.3 +++ programs/Xserver/hw/xfree86/vgahw/Imakefile 14 Jan 2005 18:28:41 -0000 @@ -15,6 +15,10 @@ MODSRC = vgaHWmodule.c MODOBJ = vgaHWmodule.o #endif +#if DoOSFontRestore +FONT_DEFINES = -DSAVE_FONT1=0 -DSAVE_FONT2=0 -DSAVE_TEXT=0 +#endif + SRCS = vgaHW.c /*vgaCmap.c*/ $(MODSRC) OBJS = vgaHW.o /*vgaCmap.o*/ $(MODOBJ) @@ -27,7 +31,7 @@ OBJS = vgaHW.o /*vgaCmap.o*/ $(MODOBJ) LINTLIBS = ../../../dix/llib-ldix.ln ../../../os/llib-los.ln \ ../../mfb/llib-lmfb.ln ../../mi/llib-lmi.ln - DEFINES = + DEFINES = $(FONT_DEFINES) ModuleObjectRule() Index: programs/Xserver/hw/xfree86/vgahw/vgaHW.c =================================================================== RCS file: /home/eich/cvs/xc/programs/Xserver/hw/xfree86/vgahw/vgaHW.c,v retrieving revision 1.1.1.27 diff -u -p -r1.1.1.27 vgaHW.c --- programs/Xserver/hw/xfree86/vgahw/vgaHW.c 3 Aug 2004 10:10:31 -0000 1.1.1.27 +++ programs/Xserver/hw/xfree86/vgahw/vgaHW.c 14 Jan 2005 18:28:41 -0000 @@ -25,7 +25,7 @@ #include "xf86cmap.h" #ifndef SAVE_FONT1 -#define SAVE_FONT1 +#define SAVE_FONT1 1 #endif /* @@ -36,10 +36,10 @@ #define NEED_SAVED_CMAP #endif #ifndef SAVE_TEXT -#define SAVE_TEXT +#define SAVE_TEXT 1 #endif #ifndef SAVE_FONT2 -#define SAVE_FONT2 +#define SAVE_FONT2 1 #endif /* bytes per plane to save for text */ @@ -51,11 +51,11 @@ #if 0 /* Override all of these for now */ #undef SAVE_FONT1 -#define SAVE_FONT1 +#define SAVE_FONT1 1 #undef SAVE_FONT2 -#define SAVE_FONT2 +#define SAVE_FONT2 1 #undef SAVE_TEST -#define SAVE_TEST +#define SAVE_TEST 1 #undef FONT_AMOUNT #define FONT_AMOUNT 65536 #undef TEXT_AMOUNT @@ -720,13 +720,12 @@ vgaHWSeqReset(vgaHWPtr hwp, Bool start) void vgaHWRestoreFonts(ScrnInfoPtr scrninfp, vgaRegPtr restore) { +#if SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 vgaHWPtr hwp = VGAHWPTR(scrninfp); int savedIOBase; unsigned char miscOut, attr10, gr1, gr3, gr4, gr5, gr6, gr8, seq2, seq4; Bool doMap = FALSE; -#if defined(SAVE_TEXT) || defined(SAVE_FONT1) || defined(SAVE_FONT2) - /* If nothing to do, return now */ if (!hwp->FontInfo1 && !hwp->FontInfo2 && !hwp->TextInfo) return; @@ -782,7 +781,7 @@ vgaHWRestoreFonts(ScrnInfoPtr scrninfp, hwp->writeGr(hwp, 0x01, 0x00); /* all planes come from CPU */ } -#ifdef SAVE_FONT1 +#if SAVE_FONT1 if (hwp->FontInfo1) { hwp->writeSeq(hwp, 0x02, 0x04); /* write to plane 2 */ hwp->writeGr(hwp, 0x04, 0x02); /* read plane 2 */ @@ -790,7 +789,7 @@ vgaHWRestoreFonts(ScrnInfoPtr scrninfp, } #endif -#ifdef SAVE_FONT2 +#if SAVE_FONT2 if (hwp->FontInfo2) { hwp->writeSeq(hwp, 0x02, 0x08); /* write to plane 3 */ hwp->writeGr(hwp, 0x04, 0x03); /* read plane 3 */ @@ -798,7 +797,7 @@ vgaHWRestoreFonts(ScrnInfoPtr scrninfp, } #endif -#ifdef SAVE_TEXT +#if SAVE_TEXT if (hwp->TextInfo) { hwp->writeSeq(hwp, 0x02, 0x01); /* write to plane 0 */ hwp->writeGr(hwp, 0x04, 0x00); /* read plane 0 */ @@ -828,7 +827,7 @@ vgaHWRestoreFonts(ScrnInfoPtr scrninfp, if (doMap) vgaHWUnmapMem(scrninfp); -#endif /* defined(SAVE_TEXT) || defined(SAVE_FONT1) || defined(SAVE_FONT2) */ +#endif /* SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 */ } @@ -906,13 +905,12 @@ vgaHWRestore(ScrnInfoPtr scrninfp, vgaRe void vgaHWSaveFonts(ScrnInfoPtr scrninfp, vgaRegPtr save) { +#if SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 vgaHWPtr hwp = VGAHWPTR(scrninfp); int savedIOBase; unsigned char miscOut, attr10, gr4, gr5, gr6, seq2, seq4; Bool doMap = FALSE; -#if defined(SAVE_TEXT) || defined(SAVE_FONT1) || defined(SAVE_FONT2) - if (hwp->Base == NULL) { doMap = TRUE; if (!vgaHWMapMem(scrninfp)) { @@ -961,21 +959,21 @@ vgaHWSaveFonts(ScrnInfoPtr scrninfp, vga hwp->writeGr(hwp, 0x05, 0x00); /* write mode 0, read mode 0 */ hwp->writeGr(hwp, 0x06, 0x05); /* set graphics */ -#ifdef SAVE_FONT1 +#if SAVE_FONT1 if (hwp->FontInfo1 || (hwp->FontInfo1 = xalloc(FONT_AMOUNT))) { hwp->writeSeq(hwp, 0x02, 0x04); /* write to plane 2 */ hwp->writeGr(hwp, 0x04, 0x02); /* read plane 2 */ slowbcopy_frombus(hwp->Base, hwp->FontInfo1, FONT_AMOUNT); } #endif /* SAVE_FONT1 */ -#ifdef SAVE_FONT2 +#if SAVE_FONT2 if (hwp->FontInfo2 || (hwp->FontInfo2 = xalloc(FONT_AMOUNT))) { hwp->writeSeq(hwp, 0x02, 0x08); /* write to plane 3 */ hwp->writeGr(hwp, 0x04, 0x03); /* read plane 3 */ slowbcopy_frombus(hwp->Base, hwp->FontInfo2, FONT_AMOUNT); } #endif /* SAVE_FONT2 */ -#ifdef SAVE_TEXT +#if SAVE_TEXT if (hwp->TextInfo || (hwp->TextInfo = xalloc(2 * TEXT_AMOUNT))) { hwp->writeSeq(hwp, 0x02, 0x01); /* write to plane 0 */ hwp->writeGr(hwp, 0x04, 0x00); /* read plane 0 */ @@ -1002,7 +1000,7 @@ vgaHWSaveFonts(ScrnInfoPtr scrninfp, vga if (doMap) vgaHWUnmapMem(scrninfp); -#endif /* defined(SAVE_TEXT) || defined(SAVE_FONT1) || defined(SAVE_FONT2) */ +#endif /* SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 */ } void