From 0d0cc4aa148213be2e4dfc7c1f87ef4dea146e3c Mon Sep 17 00:00:00 2001 From: thorpej Date: Thu, 13 May 1999 23:34:38 +0000 Subject: [PATCH] Rework the way ukbd attaches itself as the console (again). We now allow the code to pick the first USB keyboard instance as the console, ignoring which USB controller it's on. Should eventually allow detaching of the console keyboard. From Jason Thorpe --- sys/dev/pci/ohci_pci.c | 25 +---------------------- sys/dev/pci/uhci_pci.c | 25 +---------------------- sys/dev/usb/ukbd.c | 44 +++++++++++++++++++++++------------------ sys/dev/usb/ukbdvar.h | 45 ++++++++++++++++++++++++++++++++++++++++++ sys/dev/usb/usbdivar.h | 3 +-- 5 files changed, 73 insertions(+), 69 deletions(-) create mode 100644 sys/dev/usb/ukbdvar.h diff --git a/sys/dev/pci/ohci_pci.c b/sys/dev/pci/ohci_pci.c index 841f7c521972..155fac9f185a 100644 --- a/sys/dev/pci/ohci_pci.c +++ b/sys/dev/pci/ohci_pci.c @@ -1,4 +1,4 @@ -/* $NetBSD: ohci_pci.c,v 1.7 1999/05/06 19:12:22 thorpej Exp $ */ +/* $NetBSD: ohci_pci.c,v 1.8 1999/05/13 23:34:38 thorpej Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -70,13 +70,6 @@ struct cfattach ohci_pci_ca = { sizeof(struct ohci_softc), ohci_pci_match, ohci_pci_attach }; -struct { - pcitag_t tag; - int valid; -} ohci_pci_console_info; - -void ohci_pci_has_console __P((pcitag_t)); - int ohci_pci_match(parent, match, aux) struct device *parent; @@ -159,22 +152,6 @@ ohci_pci_attach(parent, self, aux) return; } - if (ohci_pci_console_info.valid && - memcmp(&ohci_pci_console_info.tag, &pa->pa_tag, - sizeof(pcitag_t)) == 0) - sc->sc_bus.has_console = 1; - else - sc->sc_bus.has_console = 0; - /* Attach usb device. */ config_found((void *)sc, &sc->sc_bus, usbctlprint); } - -void -ohci_pci_has_console(tag) - pcitag_t tag; -{ - - ohci_pci_console_info.tag = tag; - ohci_pci_console_info.valid = 1; -} diff --git a/sys/dev/pci/uhci_pci.c b/sys/dev/pci/uhci_pci.c index 44ca881ab316..05202283ab09 100644 --- a/sys/dev/pci/uhci_pci.c +++ b/sys/dev/pci/uhci_pci.c @@ -1,4 +1,4 @@ -/* $NetBSD: uhci_pci.c,v 1.5 1999/05/06 19:12:22 thorpej Exp $ */ +/* $NetBSD: uhci_pci.c,v 1.6 1999/05/13 23:34:38 thorpej Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -63,13 +63,6 @@ struct cfattach uhci_pci_ca = { sizeof(uhci_softc_t), uhci_pci_match, uhci_pci_attach }; -struct { - pcitag_t tag; - int valid; -} uhci_pci_console_info; - -void uhci_pci_has_console __P((pcitag_t)); - int uhci_pci_match(parent, match, aux) struct device *parent; @@ -165,22 +158,6 @@ uhci_pci_attach(parent, self, aux) return; } - if (uhci_pci_console_info.valid && - memcmp(&uhci_pci_console_info.tag, &pa->pa_tag, - sizeof(pcitag_t)) == 0) - sc->sc_bus.has_console = 1; - else - sc->sc_bus.has_console = 0; - /* Attach usb device. */ config_found((void *)sc, &sc->sc_bus, usbctlprint); } - -void -uhci_pci_has_console(tag) - pcitag_t tag; -{ - - uhci_pci_console_info.tag = tag; - uhci_pci_console_info.valid = 1; -} diff --git a/sys/dev/usb/ukbd.c b/sys/dev/usb/ukbd.c index ccaa9867b971..235c75293a9e 100644 --- a/sys/dev/usb/ukbd.c +++ b/sys/dev/usb/ukbd.c @@ -1,4 +1,4 @@ -/* $NetBSD: ukbd.c,v 1.30 1999/05/09 15:10:30 augustss Exp $ */ +/* $NetBSD: ukbd.c,v 1.31 1999/05/13 23:34:38 thorpej Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -68,6 +68,7 @@ #include #include #include +#include #if defined(__NetBSD__) #include @@ -213,6 +214,8 @@ struct ukbd_softc { #define UKBD_CHUNK 128 /* chunk size for read */ #define UKBD_BSIZE 1020 /* buffer size */ +int ukbd_is_console; + void ukbd_cngetc __P((void *, u_int *, int *)); void ukbd_cnpollc __P((void *, int)); @@ -231,16 +234,12 @@ void ukbd_set_leds __P((void *, int)); #if defined(__NetBSD__) int ukbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *)); -int ukbd_cnattach __P((void *v)); void ukbd_rawrepeat __P((void *v)); const struct wskbd_accessops ukbd_accessops = { ukbd_enable, ukbd_set_leds, ukbd_ioctl, -#if defined(CNATTACH) - ukbd_cnattach, -#endif }; extern const struct wscons_keydesc ukbd_keydesctab[]; @@ -334,18 +333,19 @@ USB_ATTACH(ukbd) /* * Remember if we're the console keyboard. * - * XXX This always picks the first keyboard on the bus, but - * what else can we really do? + * XXX This always picks the first keyboard on the + * first USB bus, but what else can we really do? */ - sc->sc_console_keyboard = uaa->device->bus->has_console; - if (sc->sc_console_keyboard) { + if ((sc->sc_console_keyboard = ukbd_is_console) != 0) { /* Don't let any other keyboard have it. */ - uaa->device->bus->has_console = 0; + ukbd_is_console = 0; } #if defined(__NetBSD__) - if (sc->sc_console_keyboard) - ukbd_cnattach(sc); + if (sc->sc_console_keyboard) { + DPRINTF(("ukbd_attach: console keyboard\n", sc)); + wskbd_cnattach(&ukbd_consops, sc, &ukbd_keymapdata); + } a.console = sc->sc_console_keyboard; @@ -412,9 +412,13 @@ ukbd_disco(p) if (sc->sc_console_keyboard) { /* * XXX Should probably disconnect our consops, - * XXX and set has_console in the bus handle back - * XXX to 1. + * XXX and either notify some other keyboard that + * XXX it can now be the console, or if there aren't + * XXX any more USB keyboards, set ukbd_is_console + * XXX back to 1 so that the next USB keyboard attached + * XXX to the system will get it. */ + panic("ukbd_disco: console keyboard"); } } @@ -709,13 +713,15 @@ ukbd_cnpollc(v, on) } int -ukbd_cnattach(v) - void *v; +ukbd_cnattach() { - struct ukbd_softc *sc = v; - DPRINTF(("ukbd_cnattach: sc=%p\n", sc)); - wskbd_cnattach(&ukbd_consops, sc, &ukbd_keymapdata); + /* + * XXX USB requires too many parts of the kernel to be running + * XXX in order to work, so we can't do much for the console + * XXX keyboard until autconfiguration has run its course. + */ + ukbd_is_console = 1; return (0); } diff --git a/sys/dev/usb/ukbdvar.h b/sys/dev/usb/ukbdvar.h new file mode 100644 index 000000000000..8adccc6a349e --- /dev/null +++ b/sys/dev/usb/ukbdvar.h @@ -0,0 +1,45 @@ +/* $NetBSD: ukbdvar.h,v 1.1 1999/05/13 23:34:38 thorpej Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DEV_USB_UKBDVAR_H_ +#define _DEV_USB_UKBDVAR_H_ + +int ukbd_cnattach __P((void)); + +#endif /* _DEV_USB_UKBDVAR_H_ */ diff --git a/sys/dev/usb/usbdivar.h b/sys/dev/usb/usbdivar.h index 67140487cf6b..ea8ec3baf700 100644 --- a/sys/dev/usb/usbdivar.h +++ b/sys/dev/usb/usbdivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: usbdivar.h,v 1.18 1999/05/06 19:12:23 thorpej Exp $ */ +/* $NetBSD: usbdivar.h,v 1.19 1999/05/13 23:34:38 thorpej Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -85,7 +85,6 @@ struct usbd_bus { usbd_status (*open_pipe)__P((struct usbd_pipe *pipe)); u_int32_t pipe_size; /* size of a pipe struct */ void (*do_poll)__P((struct usbd_bus *)); - int has_console; /* console input on this bus */ /* Filled by usb driver */ struct usbd_device *root_hub; usbd_device_handle devices[USB_MAX_DEVICES];