Hi folks,

Today I was doing some cleanups to our kernel message/debug console code
and I noticed we have only one driver in the tree that does some really
spooky things with its console device, namely the Xen console driver. I
did some cleanups and basically fixed the following:

- It now uses the CONSOLE_DRIVER() way to declare a driver, instead of
  using CONS_DRIVER() (which has some arguments which are no-ops
  nowadays), which means we can remove CONS_DRIVER() entirely.

- It doesn't use cn_checkc anymore. The driver had a cn_getc routine,
  but it was never being called, because it was overlapped by cn_checkc.
  cn_checkc is deprecated in favour of cn_getc, so I removed cn_getc and
  renamed cn_checkc to cn_getc.

- It doesn't runtime patch the functions inside struct consdev anymore.
  I'm planning on changing the consdev code to disallow drivers to patch
  their own functions, because the structure containing them may be
  shared between multiple console devices.

Because I don't have a system with Xen, I was only capable of
compile-testing the driver. Are there any (8.0-)users here who can test
the attached patch for me? Thanks!

-- 
 Ed Schouten <e...@80386.nl>
 WWW: http://80386.nl/
--- sys/dev/xen/console/console.c
+++ sys/dev/xen/console/console.c
@@ -45,17 +45,15 @@
 static void xcons_force_flush(void);
 static void xencons_priv_interrupt(void *);
 
-static cn_probe_t       xccnprobe;
-static cn_init_t        xccninit;
-static cn_getc_t        xccngetc;
-static cn_putc_t        xccnputc;
-static cn_putc_t        xccnputc_dom0;
-static cn_checkc_t      xccncheckc;
+static cn_probe_t       xc_cnprobe;
+static cn_init_t        xc_cninit;
+static cn_term_t        xc_cnterm;
+static cn_getc_t        xc_cngetc;
+static cn_putc_t        xc_cnputc;
 
 #define XC_POLLTIME 	(hz/10)
 
-CONS_DRIVER(xc, xccnprobe, xccninit, NULL, xccngetc, 
-	    xccncheckc, xccnputc, NULL);
+CONSOLE_DRIVER(xc);
 
 static int xen_console_up;
 static boolean_t xc_start_needed;
@@ -105,7 +103,7 @@
 };
 
 static void
-xccnprobe(struct consdev *cp)
+xc_cnprobe(struct consdev *cp)
 {
 	cp->cn_pri = CN_REMOTE;
 	sprintf(cp->cn_name, "%s0", driver_name);
@@ -113,37 +111,19 @@
 
 
 static void
-xccninit(struct consdev *cp)
+xc_cninit(struct consdev *cp)
 { 
 	CN_LOCK_INIT(cn_mtx,"XCONS LOCK");
 
 }
-int
-xccngetc(struct consdev *dev)
-{
-	int c;
-	if (xc_mute)
-	    	return 0;
-	do {
-		if ((c = xccncheckc(dev)) == -1) {
-#ifdef KDB
-			if (!kdb_active)
-#endif
-				/*
-				 * Polling without sleeping in Xen
-				 * doesn't work well.  Sleeping gives
-				 * other things like clock a chance to
-				 * run
-				 */
-				tsleep(&cn_mtx, PWAIT | PCATCH,
-				    "console sleep", XC_POLLTIME);
-		}
-	} while(c == -1);
-	return c;
+
+static void
+xc_cnterm(struct consdev *cp)
+{ 
 }
 
-int
-xccncheckc(struct consdev *dev)
+static int
+xc_cngetc(struct consdev *dev)
 {
 	int ret = (xc_mute ? 0 : -1);
 
@@ -162,17 +142,27 @@
 }
 
 static void
-xccnputc(struct consdev *dev, int c)
+xc_cnputc_domu(struct consdev *dev, int c)
 {
 	xcons_putc(c);
 }
 
 static void
-xccnputc_dom0(struct consdev *dev, int c)
+xc_cnputc_dom0(struct consdev *dev, int c)
 {
 	HYPERVISOR_console_io(CONSOLEIO_write, 1, (char *)&c);
 }
 
+static void
+xc_cnputc(struct consdev *dev, int c)
+{
+
+	if (xen_start_info->flags & SIF_INITDOMAIN)
+		xc_cnputc_dom0(dev, c);
+	else
+		xc_cnputc_domu(dev, c);
+}
+
 extern int db_active;
 static boolean_t
 xcons_putc(int c)
@@ -226,10 +216,6 @@
 {
 	int error;
 
-	if (xen_start_info->flags & SIF_INITDOMAIN) {
-		xc_consdev.cn_putc = xccnputc_dom0;
-	} 
-
 	xccons = tty_alloc(&xc_ttydevsw, NULL);
 	tty_makedev(xccons, NULL, "xc%r", 0);
 
@@ -388,7 +374,7 @@
 	tp = (struct tty *)v;
 
 	tty_lock(tp);
-	while ((c = xccncheckc(NULL)) != -1)
+	while ((c = xc_cngetc(NULL)) != -1)
 		ttydisc_rint(tp, c, 0);
 
 	if (xc_start_needed) {

Attachment: pgpSduarhJMqE.pgp
Description: PGP signature

Reply via email to