Date: Mon, 8 Dec 1997 15:38:50 GMT
From: Roman Hodek <rnhodek@faui22c.informatik.uni-erlangen.de>
To: linux-m68k@lists.linux-m68k.org
Subject: L68K: Integration of Miquel's last sercons patches
Sender: owner-linux-m68k@phil.uni-sb.de


The patch below brings us in sync again with Miquel's PC version of
the sercons feature. The difference to what we had until now is mostly
that all functions in the struct console now receive the console * as
first argument. Also the struct console now has a new field 'cflag'
for storing the attributes for the console, which removes the need for
the global 'serial_console_cflag'.

Roman

------------------------------------------------------------------------------
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/Documentation/serial-console.txt linux-2.1.64/Documentation/serial-console.txt
--- linux-2.1.64.orig/Documentation/serial-console.txt	Mon Nov 17 12:23:35 1997
+++ linux-2.1.64/Documentation/serial-console.txt	Mon Dec  8 15:47:06 1997
@@ -83,4 +83,10 @@
    console=/dev/tty0), /dev/console is the same as /dev/tty0. In that
    case everything will still work.
 
-Miquel van Smoorenburg <miquels@cistron.nl>, 15-Jun-1997
+6. Thanks
+
+   Thanks to Geert Uytterhoeven <Geert.Uytterhoeven@cs.kuleuven.ac.be>
+   for porting the patches from 2.1.4x to 2.1.6x for taking care of
+   the integration of these patches into m68k, ppc and alpha.
+
+Miquel van Smoorenburg <miquels@cistron.nl>, 03-Dec-1997
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/arch/m68k/amiga/config.c linux-2.1.64/arch/m68k/amiga/config.c
--- linux-2.1.64.orig/arch/m68k/amiga/config.c	Mon Nov 17 12:23:35 1997
+++ linux-2.1.64/arch/m68k/amiga/config.c	Mon Dec  8 16:23:30 1997
@@ -83,7 +83,19 @@
 void amiga_serial_console_write(const char *s, unsigned int count);
 static void amiga_debug_init(void);
 
-static struct console amiga_console_driver;
+static struct console amiga_console_driver = {
+    "debug",			/* name */
+    NULL,			/* filled in by amiga_debug_init */
+    NULL,			/* read */
+    NULL,			/* device -- no device available for this */
+    NULL,			/* wait_key */
+    NULL,			/* unblank */
+    NULL,			/* setup */
+    0,				/* flags */
+    -1,				/* index */
+    0,				/* cflag */
+    NULL			/* next */
+};
 
 #ifdef CONFIG_MAGIC_SYSRQ
 static char amiga_sysrq_xlate[128] =
@@ -771,7 +783,8 @@
 
 static struct savekmsg *savekmsg = NULL;
 
-static void amiga_mem_console_write(const char *s, unsigned int count)
+static void amiga_mem_console_write(struct console *co, const char *s,
+				    unsigned int count)
 {
     if (savekmsg->size+count <= SAVEKMSG_MAXMEM-sizeof(struct savekmsg)) {
         memcpy(savekmsg->data+savekmsg->size, s, count);
@@ -795,7 +808,8 @@
 	;
 }
 
-void amiga_serial_console_write(const char *s, unsigned int count)
+void amiga_serial_console_write(struct console *co, const char *s,
+				unsigned int count)
 {
     while (count--) {
 	if (*s == '\n')
@@ -810,7 +824,7 @@
     amiga_serial_console_write(s, strlen(s));
 }
 
-int amiga_serial_console_wait_key(void)
+int amiga_serial_console_wait_key(struct console *co)
 {
     int ch;
 
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/arch/m68k/atari/config.c linux-2.1.64/arch/m68k/atari/config.c
--- linux-2.1.64.orig/arch/m68k/atari/config.c	Fri Nov 28 14:28:25 1997
+++ linux-2.1.64/arch/m68k/atari/config.c	Mon Dec  8 16:22:10 1997
@@ -90,7 +90,19 @@
 extern struct consw fb_con;
 static void atari_debug_init(void);
 
-static struct console atari_console_driver;
+static struct console atari_console_driver = {
+    "debug",			/* name */
+    NULL,			/* filled in by atari_debug_init */
+    NULL,			/* read */
+    NULL,			/* device -- no device available for this */
+    NULL,			/* wait_key */
+    NULL,			/* unblank */
+    NULL,			/* setup */
+    0,				/* flags */
+    -1,				/* index */
+    0,				/* cflag */
+    NULL			/* next */
+};
 
 /* Flag that Modem1 port is already initialized and used */
 int atari_MFP_init_done = 0;
@@ -990,7 +1002,8 @@
     mfp.usart_dta = c;
 }
 
-void atari_mfp_console_write (const char *str, unsigned int count)
+void atari_mfp_console_write (struct console *co, const char *str,
+			      unsigned int count)
 {
     while (count--) {
 	if (*str == '\n')
@@ -1008,7 +1021,8 @@
     scc.cha_b_data = c;
 }
 
-void atari_scc_console_write (const char *str, unsigned int count)
+void atari_scc_console_write (struct console *co, const char *str,
+			      unsigned int count)
 {
     while (count--) {
 	if (*str == '\n')
@@ -1024,7 +1038,8 @@
     acia.mid_data = c;
 }
 
-void atari_midi_console_write (const char *str, unsigned int count)
+void atari_midi_console_write (struct console *co, const char *str,
+			       unsigned int count)
 {
     while (count--) {
 	if (*str == '\n')
@@ -1053,7 +1068,8 @@
     return( 1 );
 }
 
-static void atari_par_console_write (const char *str, unsigned int count)
+static void atari_par_console_write (struct console *co, const char *str,
+				     unsigned int count)
 {
     static int printer_present = 1;
 
@@ -1074,14 +1090,14 @@
 }
 
 #ifdef CONFIG_SERIAL_CONSOLE
-int atari_mfp_console_wait_key(void)
+int atari_mfp_console_wait_key(struct console *co)
 {
     while( !(mfp.rcv_stat & 0x80) ) /* wait for rx buf filled */
 	barrier();
     return( mfp.usart_dta );
 }
 
-int atari_scc_console_wait_key(void)
+int atari_scc_console_wait_key(struct console *co)
 {
     do {
 	MFPDELAY();
@@ -1090,7 +1106,7 @@
     return( scc.cha_b_data );
 }
 
-int atari_midi_console_wait_key(void)
+int atari_midi_console_wait_key(struct console *co)
 {
     while( !(acia.mid_ctrl & ACIA_RDRF) ) /* wait for rx buf filled */
 	barrier();
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/arch/m68k/kernel/console.c linux-2.1.64/arch/m68k/kernel/console.c
--- linux-2.1.64.orig/arch/m68k/kernel/console.c	Mon Nov 17 12:23:36 1997
+++ linux-2.1.64/arch/m68k/kernel/console.c	Mon Dec  8 15:37:15 1997
@@ -2142,7 +2142,7 @@
 /* DPC: New version of console_print using putcs */
 
 #ifdef CONFIG_VT_CONSOLE
-void vt_console_print(const char * b, unsigned int count)
+void vt_console_print(struct console *co, const char * b, unsigned int count)
 {
    int currcons = fg_console;
    unsigned char c;
@@ -2227,7 +2227,7 @@
 	return MKDEV(TTY_MAJOR, c->index ? c->index : fg_console + 1);
 }
 
-extern int keyboard_wait_for_keypress(void);
+extern int keyboard_wait_for_keypress(struct console *);
 
 struct console vt_console_driver = {
 	"tty",
@@ -2238,6 +2238,7 @@
 	do_unblank_screen,
 	NULL,
 	CON_PRINTBUFFER,
+	-1,
 	0,
 	NULL
 };
@@ -2323,6 +2324,9 @@
  *
  * Reads the information preserved by setup.s to determine the current display
  * type and sets everything accordingly.
+ *
+ * FIXME: return early if we don't _have_ a video card installed.
+ *
  */
 __initfunc(unsigned long con_init(unsigned long kmem_start))
 {
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/drivers/char/keyboard.c linux-2.1.64/drivers/char/keyboard.c
--- linux-2.1.64.orig/drivers/char/keyboard.c	Tue Sep 23 16:04:12 1997
+++ linux-2.1.64/drivers/char/keyboard.c	Mon Dec  8 16:18:41 1997
@@ -63,10 +63,12 @@
 extern void scrollfront(int);
 
 struct wait_queue * keypress_wait = NULL;
+struct console;
 
-void keyboard_wait_for_keypress(void)
+int keyboard_wait_for_keypress(struct console *co)
 {
 	sleep_on(&keypress_wait);
+	return 0;
 }
 
 /*
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/drivers/char/m68kserial.c linux-2.1.64/drivers/char/m68kserial.c
--- linux-2.1.64.orig/drivers/char/m68kserial.c	Fri Nov 28 12:18:56 1997
+++ linux-2.1.64/drivers/char/m68kserial.c	Mon Dec  8 16:04:21 1997
@@ -140,7 +140,6 @@
 static struct termios *serial_termios_locked[NR_PORTS];
 #ifdef CONFIG_SERIAL_CONSOLE
 static struct console sercons;
-static int serial_console_cflag;
 #endif
 
 #ifndef MIN
@@ -1290,9 +1289,9 @@
 		info->sw->change_speed(info);
 	}
 #ifdef CONFIG_SERIAL_CONSOLE
-	if (serial_console_cflag && sercons.index == line) {
-		tty->termios->c_cflag = serial_console_cflag;
-		serial_console_cflag = 0;
+	if (sercons.cflag && sercons.index == line) {
+		tty->termios->c_cflag = sercons.cflag;
+		sercons.cflag = 0;
 		info->sw->change_speed(info);
 	}
 #endif
@@ -1654,23 +1653,27 @@
 	return MKDEV(TTY_MAJOR, 64 + c->index);
 }
 
-extern void amiga_serial_console_write(const char *s, unsigned int count);
-extern int amiga_serial_console_wait_key(void);
+extern void amiga_serial_console_write(struct console *co, const char *s,
+									   unsigned int count);
+extern int amiga_serial_console_wait_key(struct console *co);
 extern void amiga_init_serial_console(struct async_struct *info, int cflag);
-extern void atari_mfp_console_write (const char *str, unsigned int count);
-extern int atari_mfp_console_wait_key(void);
+extern void atari_mfp_console_write (struct console *co, const char *str,
+									 unsigned int count);
+extern int atari_mfp_console_wait_key(struct console *co);
 extern void atari_init_mfp_port( int cflag );
-extern void atari_scc_console_write (const char *str, unsigned int count);
-extern int atari_scc_console_wait_key(void);
+extern void atari_scc_console_write (struct console *co, const char *str,
+									 unsigned int count);
+extern int atari_scc_console_wait_key(struct console *co);
 extern void atari_init_scc_port( int cflag );
-extern void atari_midi_console_write (const char *str, unsigned int count);
-extern int atari_midi_console_wait_key(void);
+extern void atari_midi_console_write (struct console *co, const char *str,
+									  unsigned int count);
+extern int atari_midi_console_wait_key(struct console *co);
 extern void atari_init_midi_port( int cflag );
 
 /*
  *	Setup initial baud/bits/parity.
  */
-__initfunc(static void serial_console_setup(char *options))
+__initfunc(static void serial_console_setup(struct console *co, char *options))
 {
 	char *s;
 	int baud = 0, bits, parity;
@@ -1730,18 +1733,18 @@
 			cflag |= PARENB;
 			break;
 	}
-	serial_console_cflag = cflag;
+	co->cflag = cflag;
 	
 	/* Initialization of the port and filling in the missing fields of the
 	 * sercons struct must happen here, since register_console() already uses
 	 * write to print the log buffer. */
 	
 	/* Currently this supports the Amiga builtin port only */
-	if (MACH_IS_AMIGA && sercons.index == 0) {
-		sercons.write = amiga_serial_console_write;
-		sercons.wait_key = amiga_serial_console_wait_key;
+	if (MACH_IS_AMIGA && co->index == 0) {
+		co->write = amiga_serial_console_write;
+		co->wait_key = amiga_serial_console_wait_key;
 		/* no initialization yet */
-		/* amiga_init_serial_console(rs_table+sercons.index, */
+		/* amiga_init_serial_console(rs_table+co->index, */
 		/*			     serial_console_cflag); */
 	}
 	/* On Atari, Modem1 (ttyS0), Modem2 (ttyS1) and MIDI (ttyS5) are supported
@@ -1750,28 +1753,29 @@
 	 * Note2: On MIDI, 7812.5 bps is selected by 4800 on the command line, and
 	 * 500 kbps by 115200. All other rates give standard 31250bps. Mode 7N is
 	 * not possible and replaced by 7O2 ... */
-	else if (MACH_IS_ATARI && sercons.index == 0) {
-		sercons.write = atari_mfp_console_write;
-		sercons.wait_key = atari_mfp_console_wait_key;
+	else if (MACH_IS_ATARI && co->index == 0) {
+		co->write = atari_mfp_console_write;
+		co->wait_key = atari_mfp_console_wait_key;
 		atari_init_mfp_port( cflag );
 	}
-	else if (MACH_IS_ATARI && sercons.index == 1) {
-		sercons.write = atari_scc_console_write;
-		sercons.wait_key = atari_scc_console_wait_key;
+	else if (MACH_IS_ATARI && co->index == 1) {
+		co->write = atari_scc_console_write;
+		co->wait_key = atari_scc_console_wait_key;
 		atari_init_scc_port( cflag );
 	}
-	else if (MACH_IS_ATARI && sercons.index == 5) {
-		sercons.write = atari_midi_console_write;
-		sercons.wait_key = atari_midi_console_wait_key;
+	else if (MACH_IS_ATARI && co->index == 5) {
+		co->write = atari_midi_console_write;
+		co->wait_key = atari_midi_console_wait_key;
 		atari_init_midi_port( cflag );
 	}
 }
 
-static void dummy_console_write( const char *str, unsigned int count )
+static void dummy_console_write( struct console *co, const char *str,
+								 unsigned int count )
 {
 }
 
-static int dummy_wait_key(void)
+static int dummy_wait_key( struct console *co )
 {
 	return( '\r' );
 }
@@ -1785,6 +1789,7 @@
 	NULL,
 	serial_console_setup,
 	CON_PRINTBUFFER,
+	-1,
 	0,
 	NULL
 };
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/drivers/char/tty_io.c linux-2.1.64/drivers/char/tty_io.c
--- linux-2.1.64.orig/drivers/char/tty_io.c	Mon Nov 17 12:23:37 1997
+++ linux-2.1.64/drivers/char/tty_io.c	Mon Dec  8 15:47:04 1997
@@ -516,7 +516,7 @@
         struct console *c = console_drivers;
         while(c && !c->wait_key)
                 c = c->next;
-        if (c) c->wait_key();
+        if (c) c->wait_key(c);
 }
 
 void stop_tty(struct tty_struct *tty)
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/include/linux/console.h linux-2.1.64/include/linux/console.h
--- linux-2.1.64.orig/include/linux/console.h	Fri Nov 21 23:31:13 1997
+++ linux-2.1.64/include/linux/console.h	Mon Dec  8 15:49:00 1997
@@ -85,16 +85,17 @@
 
 struct console
 {
-	char name[8];		/* Name of the driver, eg tty, ttyS, ttyR   */
-	void (*write)(const char*, unsigned);	/* Write string - blocking. */
-	int (*read)(const char*, unsigned);	/* Read string - blocking.  */
-	kdev_t (*device)(struct console *);	/* Return maj/min device    */
-	int (*wait_key)(void);	/* Wait for keypress			    */
-        void (*unblank)(void);	/* To unblank the console in case of panic  */
-	void (*setup)(char *);	/* Initialize speed etc.		    */
-	short flags;		/* CON_XXX defined above.		    */
-	short index;		/* ttyS0, ttyS1, ..			    */
-	struct console *next;	/* Next. Only the first one used for input  */
+	char	name[8];
+	void	(*write)(struct console *, const char *, unsigned);
+	int	(*read)(struct console *, const char *, unsigned);
+	kdev_t	(*device)(struct console *);
+	int	(*wait_key)(struct console *);
+        void	(*unblank)(void);
+	void	(*setup)(struct console *, char *);
+	short	flags;
+	short	index;
+	int	cflag;
+	struct	 console *next;
 };
 
 extern void register_console(struct console *);
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/kernel/printk.c linux-2.1.64/kernel/printk.c
--- linux-2.1.64.orig/kernel/printk.c	Mon Nov 17 12:23:37 1997
+++ linux-2.1.64/kernel/printk.c	Mon Dec  8 16:15:47 1997
@@ -263,7 +263,7 @@
 			struct console *c = console_drivers;
 			while(c) {
 				if ((c->flags & CON_ENABLED) && c->write)
-					c->write(msg, p - msg + line_feed);
+					c->write(c, msg, p - msg + line_feed);
 				c = c->next;
 			}
 		}
@@ -282,7 +282,7 @@
 
 	while(c) {
 		if ((c->flags & CON_ENABLED) && c->write)
-			c->write(s, len);
+			c->write(c, s, len);
 		c = c->next;
 	}
 }
@@ -312,23 +312,32 @@
 	char	*q;
 
 	/*
-	 *	See if we want to use this console driver.
+	 *	See if we want to use this console driver. If we
+	 *	didn't select a console we take the first one
+	 *	that registers here.
 	 */
 	if (selected_console == 0) {
 		console->flags |= CON_ENABLED | CON_FIRST;
 		selected_console = 1;
 		if (console->setup)
-			console->setup(NULL);
+			console->setup(console, NULL);
 	}
+	/*
+	 *	See if this console matches one we selected on
+	 *	the command line.
+	 */
 	for(i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++) {
 		if (strcmp(console_cmdline[i].name, console->name) != 0)
 			continue;
+		if (console->index >= 0 &&
+		    console->index != console_cmdline[i].index)
+			continue;
 		console->flags |= CON_ENABLED;
 		console->index = console_cmdline[i].index;
 		if (i == 0)
 			console->flags |= CON_FIRST;
 		if (console->setup)
-			console->setup(console_cmdline[i].options);
+			console->setup(console, console_cmdline[i].options);
 		break;
 	}
 
@@ -362,7 +371,7 @@
 			len -= 3;
 		}
 		if (msg_level < console_loglevel)
-			console->write(q, len);
+			console->write(console, q, len);
 		if (buf[j-1] == '\n')
 			msg_level = -1;
 		j = 0;
