2002-01-04 20:11:55 +03:00
|
|
|
/* $NetBSD: pckbc_pnpbios.c,v 1.4 2002/01/04 17:11:55 ws Exp $ */
|
2000-04-22 10:41:34 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PNPBIOS attachment for the PC Keyboard Controller driver.
|
|
|
|
*
|
|
|
|
* This is a little wonky. The keyboard controller actually
|
|
|
|
* has 2 PNPBIOS nodes: one for the controller and the keyboard
|
|
|
|
* interrupt, and one for the aux port (mouse) interrupt.
|
|
|
|
*
|
|
|
|
* For this reason, we actually attach *two* instances of this
|
|
|
|
* driver. After both of them have been found, then we attach
|
|
|
|
* sub-devices.
|
|
|
|
*/
|
|
|
|
|
2001-11-15 10:03:28 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-01-04 20:11:55 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: pckbc_pnpbios.c,v 1.4 2002/01/04 17:11:55 ws Exp $");
|
2001-11-15 10:03:28 +03:00
|
|
|
|
2000-04-22 10:41:34 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
|
|
|
|
#include <dev/ic/i8042reg.h>
|
|
|
|
#include <dev/ic/pckbcvar.h>
|
|
|
|
|
|
|
|
#include <i386/pnpbios/pnpbiosvar.h>
|
|
|
|
|
|
|
|
int pckbc_pnpbios_match(struct device *, struct cfdata *, void *);
|
|
|
|
void pckbc_pnpbios_attach(struct device *, struct device *, void *);
|
|
|
|
|
|
|
|
struct pckbc_pnpbios_softc {
|
|
|
|
struct pckbc_softc sc_pckbc;
|
|
|
|
|
|
|
|
int sc_irq;
|
|
|
|
int sc_ist;
|
|
|
|
pckbc_slot_t sc_slot;
|
|
|
|
};
|
|
|
|
|
2002-01-04 20:11:55 +03:00
|
|
|
/* Save first port: */
|
|
|
|
static struct pckbc_pnpbios_softc *first;
|
|
|
|
|
2000-04-22 10:41:34 +04:00
|
|
|
extern struct cfdriver pckbc_cd;
|
|
|
|
|
|
|
|
struct cfattach pckbc_pnpbios_ca = {
|
|
|
|
sizeof(struct pckbc_pnpbios_softc), pckbc_pnpbios_match,
|
|
|
|
pckbc_pnpbios_attach,
|
|
|
|
};
|
|
|
|
|
|
|
|
void pckbc_pnpbios_intr_establish(struct pckbc_softc *, pckbc_slot_t);
|
|
|
|
|
|
|
|
int
|
|
|
|
pckbc_pnpbios_match(struct device *parent,
|
|
|
|
struct cfdata *match,
|
|
|
|
void *aux)
|
|
|
|
{
|
|
|
|
struct pnpbiosdev_attach_args *aa = aux;
|
|
|
|
|
2001-03-31 13:20:40 +04:00
|
|
|
if (strcmp(aa->idstr, "PNP0303") == 0 ||
|
|
|
|
strcmp(aa->idstr, "PNP0320") == 0) /* Japanese 106 */
|
|
|
|
return (1); /* plus more? */
|
2000-04-22 10:41:34 +04:00
|
|
|
if (strcmp(aa->idstr, "PNP0F13") == 0)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pckbc_pnpbios_attach(struct device *parent,
|
|
|
|
struct device *self,
|
|
|
|
void *aux)
|
|
|
|
{
|
2002-01-04 20:11:55 +03:00
|
|
|
struct pckbc_pnpbios_softc *psc = (void *) self;
|
2000-04-22 10:41:34 +04:00
|
|
|
struct pckbc_softc *sc = &psc->sc_pckbc;
|
|
|
|
struct pckbc_internal *t;
|
|
|
|
struct pnpbiosdev_attach_args *aa = aux;
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh_d, ioh_c;
|
|
|
|
pckbc_slot_t peer;
|
2002-01-04 20:11:55 +03:00
|
|
|
int iobase;
|
2000-04-22 10:41:34 +04:00
|
|
|
|
2001-03-31 13:20:40 +04:00
|
|
|
if (strncmp(aa->idstr, "PNP03", 5) == 0) {
|
2000-04-22 10:41:34 +04:00
|
|
|
psc->sc_slot = PCKBC_KBD_SLOT;
|
|
|
|
peer = PCKBC_AUX_SLOT;
|
|
|
|
} else if (strcmp(aa->idstr, "PNP0F13") == 0) {
|
|
|
|
psc->sc_slot = PCKBC_AUX_SLOT;
|
|
|
|
peer = PCKBC_KBD_SLOT;
|
|
|
|
} else {
|
|
|
|
printf(": unknown port!\n");
|
|
|
|
panic("pckbc_pnpbios_attach: impossible");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(": %s port\n", pckbc_slot_names[psc->sc_slot]);
|
|
|
|
|
|
|
|
if (pnpbios_getirqnum(aa->pbt, aa->resc, 0, &psc->sc_irq,
|
|
|
|
&psc->sc_ist) != 0) {
|
|
|
|
printf("%s: unable to get IRQ number or type\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-04 20:11:55 +03:00
|
|
|
if (!first)
|
|
|
|
first = psc;
|
|
|
|
|
|
|
|
if (!first->sc_pckbc.id) {
|
2000-04-22 10:41:34 +04:00
|
|
|
|
2002-01-04 20:11:55 +03:00
|
|
|
if (pnpbios_getiobase(aa->pbt, aa->resc, 0, &iot, &iobase))
|
|
|
|
return;
|
2000-04-22 10:41:34 +04:00
|
|
|
|
|
|
|
if (pckbc_is_console(iot, iobase)) {
|
|
|
|
t = &pckbc_consdata;
|
|
|
|
ioh_d = t->t_ioh_d;
|
|
|
|
ioh_c = t->t_ioh_c;
|
|
|
|
pckbc_console_attached = 1;
|
|
|
|
/* t->t_cmdbyte was initialized by cnattach */
|
|
|
|
} else {
|
|
|
|
if (pnpbios_io_map(aa->pbt, aa->resc, 0,
|
|
|
|
&iot, &ioh_d) ||
|
|
|
|
pnpbios_io_map(aa->pbt, aa->resc, 1,
|
|
|
|
&iot, &ioh_c))
|
|
|
|
panic("pckbc_pnpbios_attach: couldn't map");
|
|
|
|
|
|
|
|
t = malloc(sizeof(struct pckbc_internal),
|
|
|
|
M_DEVBUF, M_WAITOK);
|
|
|
|
memset(t, 0, sizeof(*t));
|
|
|
|
t->t_iot = iot;
|
|
|
|
t->t_ioh_d = ioh_d;
|
|
|
|
t->t_ioh_c = ioh_c;
|
|
|
|
t->t_addr = iobase;
|
|
|
|
t->t_cmdbyte = KC8_CPU; /* Enable ports */
|
|
|
|
callout_init(&t->t_cleanup);
|
|
|
|
}
|
|
|
|
|
2002-01-04 20:11:55 +03:00
|
|
|
t->t_sc = &first->sc_pckbc;
|
|
|
|
first->sc_pckbc.id = t;
|
2000-04-22 10:41:34 +04:00
|
|
|
|
2002-01-04 20:11:55 +03:00
|
|
|
first->sc_pckbc.intr_establish = pckbc_pnpbios_intr_establish;
|
|
|
|
config_defer(&first->sc_pckbc.sc_dv,
|
|
|
|
(void(*)(struct device *))pckbc_attach);
|
2000-04-22 10:41:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pckbc_pnpbios_intr_establish(struct pckbc_softc *sc,
|
|
|
|
pckbc_slot_t slot)
|
|
|
|
{
|
2002-01-04 20:11:55 +03:00
|
|
|
struct pckbc_pnpbios_softc *psc;
|
|
|
|
void *rv = NULL;
|
2000-04-22 10:41:34 +04:00
|
|
|
int irq, ist;
|
2002-01-04 20:11:55 +03:00
|
|
|
int i;
|
2000-04-22 10:41:34 +04:00
|
|
|
|
|
|
|
/*
|
2002-01-04 20:11:55 +03:00
|
|
|
* Note we're always called with sc == first.
|
2000-04-22 10:41:34 +04:00
|
|
|
*/
|
2002-01-04 20:11:55 +03:00
|
|
|
for (i = 0; i < pckbc_cd.cd_ndevs; i++) {
|
|
|
|
psc = pckbc_cd.cd_devs[i];
|
|
|
|
if (psc && psc->sc_slot == slot) {
|
|
|
|
irq = psc->sc_irq;
|
|
|
|
ist = psc->sc_ist;
|
|
|
|
break;
|
|
|
|
}
|
2000-04-22 10:41:34 +04:00
|
|
|
}
|
2002-01-04 20:11:55 +03:00
|
|
|
if (i < pckbc_cd.cd_ndevs)
|
|
|
|
rv = isa_intr_establish(0/*XXX*/, irq, ist, IPL_TTY, pckbcintr, sc);
|
2000-04-22 10:41:34 +04:00
|
|
|
if (rv == NULL) {
|
|
|
|
printf("%s: unable to establish interrupt for %s slot\n",
|
|
|
|
sc->sc_dv.dv_xname, pckbc_slot_names[slot]);
|
|
|
|
} else {
|
|
|
|
printf("%s: using irq %d for %s slot\n", sc->sc_dv.dv_xname,
|
|
|
|
irq, pckbc_slot_names[slot]);
|
|
|
|
}
|
|
|
|
}
|