From owner-freebsd-hackers@FreeBSD.ORG Sat Aug 22 19:12:08 2009 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 99C7A106564A; Sat, 22 Aug 2009 19:12:08 +0000 (UTC) (envelope-from ed@hoeg.nl) Received: from palm.hoeg.nl (mx0.hoeg.nl [IPv6:2001:7b8:613:100::211]) by mx1.freebsd.org (Postfix) with ESMTP id 29DB98FC16; Sat, 22 Aug 2009 19:12:08 +0000 (UTC) Received: by palm.hoeg.nl (Postfix, from userid 1000) id 615811CD18; Sat, 22 Aug 2009 21:12:07 +0200 (CEST) Date: Sat, 22 Aug 2009 21:12:07 +0200 From: Ed Schouten To: freebsd-hackers@FreeBSD.org Message-ID: <20090822191207.GP1292@hoeg.nl> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="xzSe+wpn+kb4oFkG" Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Cc: kmacy@FreeBSD.org Subject: CFT: Patch for the Xen console driver X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Aug 2009 19:12:08 -0000 --xzSe+wpn+kb4oFkG Content-Type: multipart/mixed; boundary="mio/lN7rX3OFvPvp" Content-Disposition: inline --mio/lN7rX3OFvPvp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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! --=20 Ed Schouten WWW: http://80386.nl/ --mio/lN7rX3OFvPvp Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="xencons.diff" Content-Transfer-Encoding: quoted-printable --- 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 *); =20 -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; =20 #define XC_POLLTIME (hz/10) =20 -CONS_DRIVER(xc, xccnprobe, xccninit, NULL, xccngetc,=20 - xccncheckc, xccnputc, NULL); +CONSOLE_DRIVER(xc); =20 static int xen_console_up; static boolean_t xc_start_needed; @@ -105,7 +103,7 @@ }; =20 static void -xccnprobe(struct consdev *cp) +xc_cnprobe(struct consdev *cp) { cp->cn_pri =3D CN_REMOTE; sprintf(cp->cn_name, "%s0", driver_name); @@ -113,37 +111,19 @@ =20 =20 static void -xccninit(struct consdev *cp) +xc_cninit(struct consdev *cp) {=20 CN_LOCK_INIT(cn_mtx,"XCONS LOCK"); =20 } -int -xccngetc(struct consdev *dev) -{ - int c; - if (xc_mute) - return 0; - do { - if ((c =3D xccncheckc(dev)) =3D=3D -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 =3D=3D -1); - return c; + +static void +xc_cnterm(struct consdev *cp) +{=20 } =20 -int -xccncheckc(struct consdev *dev) +static int +xc_cngetc(struct consdev *dev) { int ret =3D (xc_mute ? 0 : -1); =20 @@ -162,17 +142,27 @@ } =20 static void -xccnputc(struct consdev *dev, int c) +xc_cnputc_domu(struct consdev *dev, int c) { xcons_putc(c); } =20 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); } =20 +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; =20 - if (xen_start_info->flags & SIF_INITDOMAIN) { - xc_consdev.cn_putc =3D xccnputc_dom0; - }=20 - xccons =3D tty_alloc(&xc_ttydevsw, NULL); tty_makedev(xccons, NULL, "xc%r", 0); =20 @@ -388,7 +374,7 @@ tp =3D (struct tty *)v; =20 tty_lock(tp); - while ((c =3D xccncheckc(NULL)) !=3D -1) + while ((c =3D xc_cngetc(NULL)) !=3D -1) ttydisc_rint(tp, c, 0); =20 if (xc_start_needed) { --mio/lN7rX3OFvPvp-- --xzSe+wpn+kb4oFkG Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkqQQwcACgkQ52SDGA2eCwVCRwCeJN1fuv6S3qqiYFQwvI1MpWRI 3z4AnioibEcAKOYq7x9lFoNqbDtk5nhB =3Yi7 -----END PGP SIGNATURE----- --xzSe+wpn+kb4oFkG--