patch-2.1.109 linux/drivers/video/vgacon.c

Next file: linux/drivers/video/vgafb.c
Previous file: linux/drivers/video/vfb.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.108/linux/drivers/video/vgacon.c linux/drivers/video/vgacon.c
@@ -3,6 +3,8 @@
  *
  *	Created 28 Sep 1997 by Geert Uytterhoeven
  *
+ *	Rewritten by Martin Mares <mj@ucw.cz>, July 1998
+ *
  *  This file is based on the old console.c, vga.c and vesa_blank.c drivers.
  *
  *	Copyright (C) 1991, 1992  Linus Torvalds
@@ -31,16 +33,13 @@
  *  more details.
  */
 
-
-
-
-/* KNOWN PROBLEMS/TO DO ===================================================== *
+/* KNOWN PROBLEMS/TO DO ========================================FIXME======== *
  *
  *	- monochrome attribute encoding (convert abscon <-> VGA style)
  *
- *	- speed up scrolling by changing the screen origin
+ *	- add support for VESA blanking
  *
- *	- add support for loadable fonts and VESA blanking
+ *	- Cursor shape fixes
  *
  * KNOWN PROBLEMS/TO DO ==================================================== */
 
@@ -61,8 +60,6 @@
 #include <linux/init.h>
 
 #include <asm/io.h>
-#include <asm/uaccess.h>
-#include <asm/linux_logo.h>
 
 
 #define BLANK 0x0020
@@ -70,116 +67,51 @@
 #define CAN_LOAD_EGA_FONTS	/* undefine if the user must not do this */
 #define CAN_LOAD_PALETTE	/* undefine if the user must not do this */
 
+#undef VGA_CAN_DO_64KB
+
 #define dac_reg	(0x3c8)
 #define dac_val	(0x3c9)
 
-#ifdef __powerpc__
-#define VGA_OFFSET _ISA_MEM_BASE;
-#else
-#define VGA_OFFSET 0x0
-#endif
-
-
 /*
  *  Interface used by the world
  */
 
-static unsigned long vgacon_startup(unsigned long kmem_start,
-				   const char **display_desc);
-static void vgacon_init(struct vc_data *conp);
-static void vgacon_deinit(struct vc_data *conp);
-static void vgacon_clear(struct vc_data *conp, int sy, int sx, int height,
-			 int width);
-static void vgacon_putc(struct vc_data *conp, int c, int ypos, int xpos);
-static void vgacon_putcs(struct vc_data *conp, const char *s, int count,
-			 int ypos, int xpos);
-static void vgacon_cursor(struct vc_data *conp, int mode);
-static void vgacon_scroll(struct vc_data *conp, int t, int b, int dir,
-			  int count);
-static void vgacon_bmove(struct vc_data *conp, int sy, int sx, int dy, int dx,
-		       int height, int width);
-static int vgacon_switch(struct vc_data *conp);
+static const char *vgacon_startup(void);
+static void vgacon_init(struct vc_data *c, int init);
+static void vgacon_cursor(struct vc_data *c, int mode);
+static int vgacon_switch(struct vc_data *c);
 static int vgacon_blank(int blank);
-static int vgacon_get_font(struct vc_data *conp, int *w, int *h, char *data);
-static int vgacon_set_font(struct vc_data *conp, int w, int h, char *data);
-static int vgacon_set_palette(struct vc_data *conp, unsigned char *table);
-static int vgacon_scrolldelta(struct vc_data *conp, int lines);
-
-
-/*
- *  Internal routines
- */
-
-static int vgacon_show_logo(void);
+static int vgacon_get_font(struct vc_data *c, int *w, int *h, char *data);
+static int vgacon_set_font(struct vc_data *c, int w, int h, char *data);
+static int vgacon_set_palette(struct vc_data *c, unsigned char *table);
+static int vgacon_scrolldelta(struct vc_data *c, int lines);
+static int vgacon_set_origin(struct vc_data *c);
+static void vgacon_save_screen(struct vc_data *c);
+static int vgacon_scroll(struct vc_data *c, int t, int b, int dir, int lines);
 
 
 /* Description of the hardware situation */
-static unsigned long   vga_video_mem_base;	/* Base of video memory */
-static unsigned long   vga_video_mem_term;	/* End of video memory */
+static unsigned long   vga_vram_base;		/* Base of video memory */
+static unsigned long   vga_vram_end;		/* End of video memory */
 static u16             vga_video_port_reg;	/* Video register select port */
 static u16             vga_video_port_val;	/* Video register value port */
-static unsigned long   vga_video_num_columns;	/* Number of text columns */
-static unsigned long   vga_video_num_lines;	/* Number of text lines */
-static unsigned long   vga_video_size_row;
-static unsigned long   vga_video_screen_size;
-
-static int vga_can_do_color = 0;
-static unsigned long vga_default_font_height;	/* Height of default screen font */
-
-static unsigned char vga_video_type;
-static unsigned char vga_has_wrapped;		/* all of videomem is data of fg_console */
-static unsigned char vga_hardscroll_enabled;
-static unsigned char vga_hardscroll_disabled_by_init = 0;
-
-
+static unsigned int    vga_video_num_columns;	/* Number of text columns */
+static unsigned int    vga_video_num_lines;	/* Number of text lines */
+static int	       vga_can_do_color = 0;	/* Do we support colors? */
+static unsigned int    vga_default_font_height;	/* Height of default screen font */
+static unsigned char   vga_video_type;		/* Card type */
+static unsigned char   vga_hardscroll_enabled;
+static unsigned char   vga_hardscroll_user_enable = 1;
+static unsigned char   vga_font_is_default = 1;
 
-    /*
-     *  VGA screen access
-     */ 
-
-static inline void vga_writew(u16 val, u16 * addr)
-{
-#ifdef __powerpc__
-	st_le16(addr, val);
-#else
-	writew(val, (unsigned long) addr);
-#endif /* !__powerpc__ */
-}
-
-static inline u16 vga_readw(u16 * addr)
-{
-#ifdef __powerpc__
-	return ld_le16(addr);
-#else
-	return readw((unsigned long) addr);
-#endif /* !__powerpc__ */	
-}
-
-static inline void vga_memsetw(void * s, u16 c, unsigned int count)
+void no_scroll(char *str, int *ints)
 {
-	u16 * addr = (u16 *) s;
-
-	while (count) {
-		count--;
-		vga_writew(c, addr++);
-	}
-}
-
-static inline void vga_memmovew(u16 *to, u16 *from, unsigned int count)
-{
-	if (to < from) {
-	    while (count) {
-		    count--;
-		    vga_writew(vga_readw(from++), to++);
-	    }
-	} else {
-	    from += count;
-	    to += count;
-	    while (count) {
-		    count--;
-		    vga_writew(vga_readw(--from), --to);
-	    }
-	}
+	/*
+	 * Disabling scrollback is required for the Braillex ib80-piezo
+	 * Braille reader made by F.H. Papenmeier (Germany).
+	 * Use the "no-scroll" bootflag.
+	 */
+	vga_hardscroll_user_enable = vga_hardscroll_enabled = 0;
 }
 
 
@@ -208,34 +140,32 @@
 }
 
 
-__initfunc(static unsigned long vgacon_startup(unsigned long kmem_start,
-					       const char **display_desc))
+__initfunc(static const char *vgacon_startup(void))
 {
+	const char *display_desc = NULL;
 	u16 saved;
 	u16 *p;
 
 	vga_video_num_lines = ORIG_VIDEO_LINES;
 	vga_video_num_columns = ORIG_VIDEO_COLS;
-	vga_video_size_row = 2 * ORIG_VIDEO_COLS;
-	vga_video_screen_size = vga_video_num_lines * vga_video_size_row;
 
 	if (ORIG_VIDEO_MODE == 7)	/* Is this a monochrome display? */
 	{
-		vga_video_mem_base = 0xb0000 + VGA_OFFSET;
+		vga_vram_base = 0xb0000;
 		vga_video_port_reg = 0x3b4;
 		vga_video_port_val = 0x3b5;
 		if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
 		{
 			vga_video_type = VIDEO_TYPE_EGAM;
-			vga_video_mem_term = 0xb8000 + VGA_OFFSET;
-			*display_desc = "EGA+";
+			vga_vram_end = 0xb8000;
+			display_desc = "EGA+";
 			request_region(0x3b0,16,"ega");
 		}
 		else
 		{
 			vga_video_type = VIDEO_TYPE_MDA;
-			vga_video_mem_term = 0xb2000 + VGA_OFFSET;
-			*display_desc = "*MDA";
+			vga_vram_end = 0xb2000;
+			display_desc = "*MDA";
 			request_region(0x3b0,12,"mda");
 			request_region(0x3bf, 1,"mda");
 		}
@@ -243,22 +173,22 @@
 	else				/* If not, it is color. */
 	{
 		vga_can_do_color = 1;
-		vga_video_mem_base = 0xb8000  + VGA_OFFSET;
-		vga_video_port_reg	= 0x3d4;
-		vga_video_port_val	= 0x3d5;
+		vga_vram_base = 0xb8000;
+		vga_video_port_reg = 0x3d4;
+		vga_video_port_val = 0x3d5;
 		if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
 		{
 			int i ;
 
-			vga_video_mem_term = 0xc0000 + VGA_OFFSET;
+			vga_vram_end = 0xc0000;
 
 			if (!ORIG_VIDEO_ISVGA) {
 				vga_video_type = VIDEO_TYPE_EGAC;
-				*display_desc = "EGA";
+				display_desc = "EGA";
 				request_region(0x3c0,32,"ega");
 			} else {
 				vga_video_type = VIDEO_TYPE_VGAC;
-				*display_desc = "VGA+";
+				display_desc = "VGA+";
 				request_region(0x3c0,32,"vga+");
 
 #ifdef VGA_CAN_DO_64KB
@@ -268,8 +198,8 @@
 				 * controllers (it seems like setting MM=01
 				 * and COE=1 isn't necessarily a good idea)
 				 */
-				vga_video_mem_base = 0xa0000  + VGA_OFFSET;
-				vga_video_mem_term = 0xb0000  + VGA_OFFSET;
+				vga_vram_base = 0xa0000;
+				vga_vram_end = 0xb0000;
 				outb_p (6, 0x3ce) ;
 				outb_p (6, 0x3cf) ;
 #endif
@@ -301,40 +231,36 @@
 		else
 		{
 			vga_video_type = VIDEO_TYPE_CGA;
-			vga_video_mem_term = 0xba000 + VGA_OFFSET;
-			*display_desc = "*CGA";
+			vga_vram_end = 0xba000;
+			display_desc = "*CGA";
 			request_region(0x3d4,2,"cga");
 		}
 	}
+	vga_vram_base = VGA_MAP_MEM(vga_vram_base);
+	vga_vram_end = VGA_MAP_MEM(vga_vram_end);
 
 	/*
 	 *	Find out if there is a graphics card present.
 	 *	Are there smarter methods around?
 	 */
-	p = (u16 *)vga_video_mem_base;
-	saved = vga_readw(p);
-	vga_writew(0xAA55, p);
-	if (vga_readw(p) != 0xAA55) {
-		vga_writew(saved, p);
-		return kmem_start;
-	}
-	vga_writew(0x55AA, p);
-	if (vga_readw(p) != 0x55AA) {
-		vga_writew(saved, p);
-		return kmem_start;
+	p = (u16 *)vga_vram_base;
+	saved = scr_readw(p);
+	scr_writew(0xAA55, p);
+	if (scr_readw(p) != 0xAA55) {
+		scr_writew(saved, p);
+		return NULL;
+	}
+	scr_writew(0x55AA, p);
+	if (scr_readw(p) != 0x55AA) {
+		scr_writew(saved, p);
+		return NULL;
 	}
-	vga_writew(saved, p);
+	scr_writew(saved, p);
 
-	vga_hardscroll_enabled = (vga_hardscroll_disabled_by_init ? 0 :
-	  (vga_video_type == VIDEO_TYPE_EGAC
+	if (vga_video_type == VIDEO_TYPE_EGAC
 	    || vga_video_type == VIDEO_TYPE_VGAC
-	    || vga_video_type == VIDEO_TYPE_EGAM));
-	vga_has_wrapped = 0;
-
-	if (vga_video_type == VIDEO_TYPE_VGAC
-	    || vga_video_type == VIDEO_TYPE_EGAC
-	    || vga_video_type == VIDEO_TYPE_EGAM)
-	{
+	    || vga_video_type == VIDEO_TYPE_EGAM) {
+		vga_hardscroll_enabled = vga_hardscroll_user_enable;
 		vga_default_font_height = ORIG_VIDEO_POINTS;
 		video_font_height = ORIG_VIDEO_POINTS;
 		/* This may be suboptimal but is a safe bet - go with it */
@@ -342,228 +268,407 @@
 			video_font_height * vga_video_num_lines;
 	}
 
-	if (!console_show_logo)
-	    console_show_logo = vgacon_show_logo;
-
-	return kmem_start;
-}
-
-
-static void vgacon_init(struct vc_data *conp)
-{
-    conp->vc_cols = vga_video_num_columns;
-    conp->vc_rows = vga_video_num_lines;
-    conp->vc_can_do_color = vga_can_do_color;
-}
-
-static void vgacon_deinit(struct vc_data *conp)
-{
+	return display_desc;
 }
 
 
-/* ====================================================================== */
-
-static void vgacon_clear(struct vc_data *conp, int sy, int sx, int height,
-			 int width)
+static void vgacon_init(struct vc_data *c, int init)
 {
-    int rows;
-    unsigned long dest;
-
-    if (console_blanked)
-	return;
-
-    dest = vga_video_mem_base + sy*vga_video_size_row + sx*2;
-    if (sx == 0 && width == vga_video_num_columns)      
-	vga_memsetw((void *)dest, conp->vc_video_erase_char, height * width);
-    else
-        for (rows = height; rows-- ; dest += vga_video_size_row)
-	    vga_memsetw((void *)dest, conp->vc_video_erase_char, width);
+	/* We cannot be loaded as a module, therefore init is always 1 */
+	c->vc_can_do_color = vga_can_do_color;
+	c->vc_cols = vga_video_num_columns;
+	c->vc_rows = vga_video_num_lines;
 }
 
 
-static void vgacon_putc(struct vc_data *conp, int c, int ypos, int xpos)
+static inline void vga_set_mem_top(struct vc_data *c)
 {
-    u16 *p;
-
-    if (console_blanked)
-	return;
-
-    p = (u16 *)(vga_video_mem_base+ypos*vga_video_size_row+xpos*2);
-    vga_writew(conp->vc_attr << 8 | c, p);
+	write_vga(12, (c->vc_visible_origin-vga_vram_base)/2);
 }
 
 
-static void vgacon_putcs(struct vc_data *conp, const char *s, int count,
-			 int ypos, int xpos)
-{
-    u16 *p;
-    u16 sattr;
-
-    if (console_blanked)
-	return;
-
-    p = (u16 *)(vga_video_mem_base+ypos*vga_video_size_row+xpos*2);
-    sattr = conp->vc_attr << 8;
-    while (count--)
-	vga_writew(sattr | ((int) (*s++) & 0xff), p++);
-}
-
-
-static void vgacon_cursor(struct vc_data *conp, int mode)
+static void vgacon_cursor(struct vc_data *c, int mode)
 {
+    if (c->vc_origin != c->vc_visible_origin)
+	vgacon_scrolldelta(c, 0);
     switch (mode) {
 	case CM_ERASE:
-	    write_vga(14, (vga_video_mem_term - vga_video_mem_base - 1)>>1);
+	    write_vga(14, (vga_vram_end - vga_vram_base - 1)/2);
 	    break;
 
 	case CM_MOVE:
 	case CM_DRAW:
-	    write_vga(14, conp->vc_y*vga_video_num_columns+conp->vc_x);
+	    write_vga(14, (c->vc_pos-vga_vram_base)/2);
 	    break;
     }
 }
 
 
-static void vgacon_scroll(struct vc_data *conp, int t, int b, int dir,
-			  int count)
+static int vgacon_switch(struct vc_data *c)
 {
-    if (console_blanked)
-	return;
+	/*
+	 * We need to save screen size here as it's the only way
+	 * we can spot the screen has been resized and we need to
+	 * set size of freshly allocated screens ourselves.
+	 */
+	vga_video_num_columns = c->vc_cols;
+	vga_video_num_lines = c->vc_rows;
+	scr_memcpyw_to((u16 *) c->vc_origin, (u16 *) c->vc_screenbuf, c->vc_screenbuf_size);
+	return 0;	/* Redrawing not needed */
+}
 
-    vgacon_cursor(conp, CM_ERASE);
 
-    switch (dir) {
-	case SM_UP:
-	    if (count > conp->vc_rows)	/* Maximum realistic size */
-		count = conp->vc_rows;
-	    vgacon_bmove(conp, t+count, 0, t, 0, b-t-count, conp->vc_cols);
-	    vgacon_clear(conp, b-count, 0, count, conp->vc_cols);
-	    break;
+static int vgacon_blank(int blank)
+{
+    /* FIXME: Implement! */
+    /* FIXME: Check if we really ignore everything when the console is blanked. */
+    if (blank) {
+	scr_memsetw((void *)vga_vram_base, BLANK, vc_cons[0].d->vc_screenbuf_size);
+	return 0;
+    } else {
+	/* Tell console.c that it has to restore the screen itself */
+	return 1;
+    }
+    return 0;
+}
 
-	case SM_DOWN:
-	    if (count > conp->vc_rows)	/* Maximum realistic size */
-		count = conp->vc_rows;
-	    /*
-	     *  Fixed bmove() should end Arno's frustration with copying?
-	     *  Confucius says:
-	     *	Man who copies in wrong direction, end up with trashed
-	     *	data
-	     */
-	    vgacon_bmove(conp, t, 0, t+count, 0, b-t-count, conp->vc_cols);
-	    vgacon_clear(conp, t, 0, count, conp->vc_cols);
-	    break;
 
-	case SM_LEFT:
-	    vgacon_bmove(conp, 0, t+count, 0, t, conp->vc_rows, b-t-count);
-	    vgacon_clear(conp, 0, b-count, conp->vc_rows, count);
-	    break;
+/*
+ * PIO_FONT support.
+ *
+ * The font loading code goes back to the codepage package by
+ * Joel Hoffman (joel@wam.umd.edu). (He reports that the original
+ * reference is: "From: p. 307 of _Programmer's Guide to PC & PS/2
+ * Video Systems_ by Richard Wilton. 1987.  Microsoft Press".)
+ *
+ * Change for certain monochrome monitors by Yury Shevchuck
+ * (sizif@botik.yaroslavl.su).
+ */
 
-	case SM_RIGHT:
-	    vgacon_bmove(conp, 0, t, 0, t+count, conp->vc_rows, b-t-count);
-	    vgacon_clear(conp, 0, t, conp->vc_rows, count);
-	    break;
-    }
-}
+#define colourmap 0xa0000
+/* Pauline Middelink <middelin@polyware.iaf.nl> reports that we
+   should use 0xA0000 for the bwmap as well.. */
+#define blackwmap 0xa0000
+#define cmapsz 8192
+#define attrib_port (0x3c0)
+#define seq_port_reg (0x3c4)
+#define seq_port_val (0x3c5)
+#define gr_port_reg (0x3ce)
+#define gr_port_val (0x3cf)
+
+static int
+vgacon_font_op(char *arg, int set)
+{
+#ifdef CAN_LOAD_EGA_FONTS
+	int ch512 = video_mode_512ch;
+	static int ch512enabled = 0;
+	int i;
+	char *charmap;
+	int beg;
+	unsigned short video_port_status = vga_video_port_reg + 6;
+	int font_select = 0x00;
+
+	if (vga_video_type == VIDEO_TYPE_EGAC || vga_video_type == VIDEO_TYPE_VGAC) {
+		charmap = (char *)VGA_MAP_MEM(colourmap);
+		beg = 0x0e;
+#ifdef VGA_CAN_DO_64KB
+		if (video_type == VIDEO_TYPE_VGAC)
+			beg = 0x06;
+#endif
+	} else if (vga_video_type == VIDEO_TYPE_EGAM) {
+		charmap = (char *)VGA_MAP_MEM(blackwmap);
+		beg = 0x0a;
+	} else
+		return -EINVAL;
+	
+#ifdef BROKEN_GRAPHICS_PROGRAMS
+	/*
+	 * All fonts are loaded in slot 0 (0:1 for 512 ch)
+	 */
 
+	if (!arg)
+		return -EINVAL;		/* Return to default font not supported */
 
-static void vgacon_bmove(struct vc_data *conp, int sy, int sx, int dy, int dx,
-			 int height, int width)
-{
-    unsigned long src, dst;
-    int rows;
+	vga_font_is_default = 0;
+	font_select = ch512 ? 0x04 : 0x00;
+#else	
+	/*
+	 * The default font is kept in slot 0 and is never touched.
+	 * A custom font is loaded in slot 2 (256 ch) or 2:3 (512 ch)
+	 */
+
+	if (set) {
+		vga_font_is_default = !arg;
+		if (!arg)
+			ch512 = 0;		/* Default font is always 256 */
+		font_select = arg ? (ch512 ? 0x0e : 0x0a) : 0x00;
+	}
 
-    if (console_blanked)
-	return;
+	if ( !vga_font_is_default )
+		charmap += 4*cmapsz;
+#endif
 
-    if (sx == 0 && dx == 0 && width == vga_video_num_columns) {
-	src = vga_video_mem_base + sy * vga_video_size_row;
-	dst = vga_video_mem_base + dy * vga_video_size_row;
-	vga_memmovew((u16 *)dst, (u16 *)src, height * width);
-    } else if (dy < sy || (dy == sy && dx < sx)) {
-	src = vga_video_mem_base + sy * vga_video_size_row + sx * 2;
-	dst = vga_video_mem_base + dy * vga_video_size_row + dx * 2;
-	for (rows = height; rows-- ;) {
-	    vga_memmovew((u16 *)dst, (u16 *)src, width);
-	    src += vga_video_size_row;
-	    dst += vga_video_size_row;
+	cli();
+	outb_p( 0x00, seq_port_reg );   /* First, the sequencer */
+	outb_p( 0x01, seq_port_val );   /* Synchronous reset */
+	outb_p( 0x02, seq_port_reg );
+	outb_p( 0x04, seq_port_val );   /* CPU writes only to map 2 */
+	outb_p( 0x04, seq_port_reg );
+	outb_p( 0x07, seq_port_val );   /* Sequential addressing */
+	outb_p( 0x00, seq_port_reg );
+	outb_p( 0x03, seq_port_val );   /* Clear synchronous reset */
+
+	outb_p( 0x04, gr_port_reg );    /* Now, the graphics controller */
+	outb_p( 0x02, gr_port_val );    /* select map 2 */
+	outb_p( 0x05, gr_port_reg );
+	outb_p( 0x00, gr_port_val );    /* disable odd-even addressing */
+	outb_p( 0x06, gr_port_reg );
+	outb_p( 0x00, gr_port_val );    /* map start at A000:0000 */
+	sti();
+	
+	if (arg) {
+		if (set)
+			for (i=0; i<cmapsz ; i++)
+				vga_writeb(arg[i], charmap + i);
+		else
+			for (i=0; i<cmapsz ; i++)
+				arg[i] = vga_readb(charmap + i);
+
+		/*
+		 * In 512-character mode, the character map is not contiguous if
+		 * we want to remain EGA compatible -- which we do
+		 */
+
+		if (ch512) {
+			charmap += 2*cmapsz;
+			arg += cmapsz;
+			if (set)
+				for (i=0; i<cmapsz ; i++)
+					vga_writeb(arg[i], charmap+i);
+			else
+				for (i=0; i<cmapsz ; i++)
+					arg[i] = vga_readb(charmap+i);
+		}
 	}
-    } else {
-	src = vga_video_mem_base + (sy+height-1) * vga_video_size_row + sx * 2;
-	dst = vga_video_mem_base + (dy+height-1) * vga_video_size_row + dx * 2;
-	for (rows = height; rows-- ;) {
-	    vga_memmovew((u16 *)dst, (u16 *)src, width);
-	    src -= vga_video_size_row;
-	    dst -= vga_video_size_row;
+	
+	cli();
+	outb_p( 0x00, seq_port_reg );   /* First, the sequencer */
+	outb_p( 0x01, seq_port_val );   /* Synchronous reset */
+	outb_p( 0x02, seq_port_reg );
+	outb_p( 0x03, seq_port_val );   /* CPU writes to maps 0 and 1 */
+	outb_p( 0x04, seq_port_reg );
+	outb_p( 0x03, seq_port_val );   /* odd-even addressing */
+	if (set) {
+		outb_p( 0x03, seq_port_reg ); /* Character Map Select */
+		outb_p( font_select, seq_port_val );
 	}
-    }
-}
+	outb_p( 0x00, seq_port_reg );
+	outb_p( 0x03, seq_port_val );   /* clear synchronous reset */
 
+	outb_p( 0x04, gr_port_reg );    /* Now, the graphics controller */
+	outb_p( 0x00, gr_port_val );    /* select map 0 for CPU */
+	outb_p( 0x05, gr_port_reg );
+	outb_p( 0x10, gr_port_val );    /* enable even-odd addressing */
+	outb_p( 0x06, gr_port_reg );
+	outb_p( beg, gr_port_val );     /* map starts at b800:0 or b000:0 */
+
+	/* if 512 char mode is already enabled don't re-enable it. */
+	if ((set)&&(ch512!=ch512enabled)) {	/* attribute controller */
+		ch512enabled=ch512;
+		/* 256-char: enable intensity bit
+		   512-char: disable intensity bit */
+		inb_p( video_port_status );	/* clear address flip-flop */
+		outb_p ( 0x12, attrib_port ); /* color plane enable register */
+		outb_p ( ch512 ? 0x07 : 0x0f, attrib_port );
+		/* Wilton (1987) mentions the following; I don't know what
+		   it means, but it works, and it appears necessary */
+		inb_p( video_port_status );
+		outb_p ( 0x20, attrib_port );
+	}
+	sti();
 
-static int vgacon_switch(struct vc_data *conp)
-{
-    return 0;
+	return 0;
+#else
+	return -EINVAL;
+#endif
 }
 
-
-static int vgacon_blank(int blank)
+/*
+ * Adjust the screen to fit a font of a certain height
+ */
+static int
+vgacon_adjust_height(unsigned fontheight)
 {
-    if (blank) {
-	vga_memsetw((void *)vga_video_mem_base, BLANK, vga_video_screen_size/2);
+	int rows, maxscan;
+	unsigned char ovr, vde, fsr, curs, cure;
+
+	if (fontheight > 32 || (vga_video_type != VIDEO_TYPE_VGAC &&
+	    vga_video_type != VIDEO_TYPE_EGAC && vga_video_type != VIDEO_TYPE_EGAM))
+		return -EINVAL;
+
+	if (fontheight == video_font_height)
+		return 0;
+
+	video_font_height = fontheight;
+
+	rows = video_scan_lines/fontheight;	/* Number of video rows we end up with */
+	maxscan = rows*fontheight - 1;		/* Scan lines to actually display-1 */
+
+	/* Reprogram the CRTC for the new font size
+	   Note: the attempt to read the overflow register will fail
+	   on an EGA, but using 0xff for the previous value appears to
+	   be OK for EGA text modes in the range 257-512 scan lines, so I
+	   guess we don't need to worry about it.
+
+	   The same applies for the spill bits in the font size and cursor
+	   registers; they are write-only on EGA, but it appears that they
+	   are all don't care bits on EGA, so I guess it doesn't matter. */
+
+	cli();
+	outb_p( 0x07, vga_video_port_reg );		/* CRTC overflow register */
+	ovr = inb_p(vga_video_port_val);
+	outb_p( 0x09, vga_video_port_reg );		/* Font size register */
+	fsr = inb_p(vga_video_port_val);
+	outb_p( 0x0a, vga_video_port_reg );		/* Cursor start */
+	curs = inb_p(vga_video_port_val);
+	outb_p( 0x0b, vga_video_port_reg );		/* Cursor end */
+	cure = inb_p(vga_video_port_val);
+	sti();
+
+	vde = maxscan & 0xff;			/* Vertical display end reg */
+	ovr = (ovr & 0xbd) +			/* Overflow register */
+	      ((maxscan & 0x100) >> 7) +
+	      ((maxscan & 0x200) >> 3);
+	fsr = (fsr & 0xe0) + (fontheight-1);    /*  Font size register */
+	curs = (curs & 0xc0) + fontheight - (fontheight < 10 ? 2 : 3);
+	cure = (cure & 0xe0) + fontheight - (fontheight < 10 ? 1 : 2);
+
+	cli();
+	outb_p( 0x07, vga_video_port_reg );		/* CRTC overflow register */
+	outb_p( ovr, vga_video_port_val );
+	outb_p( 0x09, vga_video_port_reg );		/* Font size */
+	outb_p( fsr, vga_video_port_val );
+	outb_p( 0x0a, vga_video_port_reg );		/* Cursor start */
+	outb_p( curs, vga_video_port_val );
+	outb_p( 0x0b, vga_video_port_reg );		/* Cursor end */
+	outb_p( cure, vga_video_port_val );
+	outb_p( 0x12, vga_video_port_reg );		/* Vertical display limit */
+	outb_p( vde, vga_video_port_val );
+	sti();
+
+	vc_resize_all(rows, 0);			/* Adjust console size */
 	return 0;
-    } else {
-	/* Tell console.c that it has to restore the screen itself */
-	return 1;
-    }
-    return 0;
 }
 
-
-static int vgacon_get_font(struct vc_data *conp, int *w, int *h, char *data)
+static int vgacon_get_font(struct vc_data *c, int *w, int *h, char *data)
 {
-    /* TODO */
-    return -ENOSYS;
+	*w = 8;
+	*h = video_font_height;
+	return vgacon_font_op(data, 0);
 }
 
-
-static int vgacon_set_font(struct vc_data *conp, int w, int h, char *data)
+static int vgacon_set_font(struct vc_data *c, int w, int h, char *data)
 {
-    /* TODO */
-    return -ENOSYS;
+	int rc;
+	if (w != 8 || h > 32)
+		return -EINVAL;
+	rc = vgacon_font_op(data, 1);
+	if (!rc)
+		rc = vgacon_adjust_height(h);
+	return rc;
 }
 
-static int vgacon_set_palette(struct vc_data *conp, unsigned char *table)
+static int vgacon_set_palette(struct vc_data *c, unsigned char *table)
 {
+#ifdef CAN_LOAD_PALETTE
 	int i, j ;
 
-	if (vga_video_type != VIDEO_TYPE_VGAC || console_blanked ||
-	    vt_cons[fg_console]->vc_mode == KD_GRAPHICS)
+	if (vga_video_type != VIDEO_TYPE_VGAC || console_blanked)
 		return -EINVAL;
 
 	for (i=j=0; i<16; i++) {
 		outb_p (table[i], dac_reg) ;
-		outb_p (vc_cons[fg_console].d->vc_palette[j++]>>2, dac_val) ;
-		outb_p (vc_cons[fg_console].d->vc_palette[j++]>>2, dac_val) ;
-		outb_p (vc_cons[fg_console].d->vc_palette[j++]>>2, dac_val) ;
+		outb_p (c->vc_palette[j++]>>2, dac_val) ;
+		outb_p (c->vc_palette[j++]>>2, dac_val) ;
+		outb_p (c->vc_palette[j++]>>2, dac_val) ;
 	}
 	return 0;
+#else
+	return -EINVAL;
+#endif
 }
 
-static int vgacon_scrolldelta(struct vc_data *conp, int lines)
+static int vgacon_scrolldelta(struct vc_data *c, int lines)
 {
-    /* TODO */
-    return -ENOSYS;
+	/* FIXME: Better scrollback strategy, maybe move it to generic code
+	 *	  and leave only vga_set_mem_top here.
+	 */
+	if (!lines)			/* Turn scrollback off */
+		c->vc_visible_origin = c->vc_origin;
+	else {
+		int p = c->vc_visible_origin - vga_vram_base;
+		p += lines * c->vc_size_row;
+		if (p < 0)
+			p = 0;
+		c->vc_visible_origin = p + vga_vram_base;
+		if (c->vc_visible_origin > c->vc_origin)
+			c->vc_visible_origin = c->vc_origin;
+	}
+	vga_set_mem_top(c);
+	return 1;
 }
 
-__initfunc(static int vgacon_show_logo( void ))
+static int vgacon_set_origin(struct vc_data *c)
 {
-    int height = 0;
-    char *p;
+	c->vc_origin = c->vc_visible_origin = vga_vram_base;
+	vga_set_mem_top(c);
+	return 1;
+}
 
-    printk(linux_serial_image);
-    for (p = linux_serial_image; *p; p++)
-	if (*p == '\n')
-	    height++;
-    return height;
+static void vgacon_save_screen(struct vc_data *c)
+{
+	static int vga_bootup_console = 0;
+
+	if (!vga_bootup_console) {
+		/* This is a gross hack, but here is the only place we can
+		 * set bootup console parameters without messing up generic
+		 * console initialization routines.
+		 */
+		vga_bootup_console = 1;
+		c->vc_x = ORIG_X;
+		c->vc_y = ORIG_Y;
+	}
+	scr_memcpyw_from((u16 *) c->vc_screenbuf, (u16 *) c->vc_origin, c->vc_screenbuf_size);
+}
+
+static int vgacon_scroll(struct vc_data *c, int t, int b, int dir, int lines)
+{
+	unsigned long oldo;
+	
+	if (t || b != c->vc_rows)
+		return 0;
+
+	if (c->vc_origin != c->vc_visible_origin)
+		vgacon_scrolldelta(c, 0);
+
+	/* FIXME: Handle scrolling down or by more lines? */
+	if (!vga_hardscroll_enabled || dir != SM_UP || lines != 1)
+		return 0;
+
+	oldo = c->vc_origin;
+	if (c->vc_scr_end + c->vc_size_row >= vga_vram_end) {
+		scr_memcpyw((u16 *)vga_vram_base,
+			    (u16 *)(oldo + c->vc_size_row),
+			    c->vc_screenbuf_size - c->vc_size_row);
+		c->vc_origin = vga_vram_base;
+	} else
+		c->vc_origin += c->vc_size_row;
+	c->vc_visible_origin = c->vc_origin;
+	c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
+	scr_memsetw((u16 *)(c->vc_scr_end - c->vc_size_row), c->vc_video_erase_char, c->vc_size_row);
+	vga_set_mem_top(c);
+	c->vc_pos = (c->vc_pos - oldo) + c->vc_origin;
+	return 1;
 }
 
 
@@ -572,9 +677,29 @@
  *  The console `switch' structure for the VGA based console
  */
 
+static int vgacon_dummy(struct vc_data *c)
+{
+	return 0;
+}
+
+#define DUMMY (void *) vgacon_dummy
+
 struct consw vga_con = {
-    vgacon_startup, vgacon_init, vgacon_deinit, vgacon_clear, vgacon_putc,
-    vgacon_putcs, vgacon_cursor, vgacon_scroll, vgacon_bmove, vgacon_switch,
-    vgacon_blank, vgacon_get_font, vgacon_set_font, vgacon_set_palette,
-    vgacon_scrolldelta
+	vgacon_startup,
+	vgacon_init,
+	DUMMY,				/* con_deinit */
+	DUMMY,				/* con_clear */
+	DUMMY,				/* con_putc */
+	DUMMY,				/* con_putcs */
+	vgacon_cursor,
+	vgacon_scroll,			/* con_scroll */
+	DUMMY,				/* con_bmove */
+	vgacon_switch,
+	vgacon_blank,
+	vgacon_get_font,
+	vgacon_set_font,
+	vgacon_set_palette,
+	vgacon_scrolldelta,
+	vgacon_set_origin,
+	vgacon_save_screen
 };

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov