1999-01-23 16:53:30 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 as
|
|
|
|
* the first lines of this file unmodified.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:34:37 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-01-23 16:53:30 +00:00
|
|
|
#include "opt_kbd.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:27:19 +00:00
|
|
|
#include <sys/module.h>
|
1999-01-23 16:53:30 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/malloc.h>
|
2000-03-19 03:25:13 +00:00
|
|
|
#include <machine/bus_pio.h>
|
1999-05-22 15:47:34 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
1999-01-23 16:53:30 +00:00
|
|
|
|
|
|
|
#include <dev/kbd/atkbdcreg.h>
|
|
|
|
|
|
|
|
#include <isa/isareg.h>
|
|
|
|
#include <isa/isavar.h>
|
|
|
|
|
2000-12-08 20:09:00 +00:00
|
|
|
static MALLOC_DEFINE(M_ATKBDDEV, "atkbddev", "AT Keyboard device");
|
1999-01-23 16:53:30 +00:00
|
|
|
|
|
|
|
/* children */
|
|
|
|
typedef struct atkbdc_device {
|
2001-09-06 12:09:26 +00:00
|
|
|
struct resource_list resources;
|
|
|
|
int rid;
|
2000-03-19 04:37:18 +00:00
|
|
|
u_int32_t vendorid;
|
|
|
|
u_int32_t serial;
|
|
|
|
u_int32_t logicalid;
|
|
|
|
u_int32_t compatid;
|
1999-01-23 16:53:30 +00:00
|
|
|
} atkbdc_device_t;
|
|
|
|
|
|
|
|
/* kbdc */
|
2003-04-30 12:57:40 +00:00
|
|
|
static devclass_t atkbdc_devclass;
|
1999-01-23 16:53:30 +00:00
|
|
|
|
|
|
|
static int atkbdc_probe(device_t dev);
|
|
|
|
static int atkbdc_attach(device_t dev);
|
2001-09-06 12:09:26 +00:00
|
|
|
static device_t atkbdc_add_child(device_t bus, int order, char *name,
|
|
|
|
int unit);
|
1999-07-29 01:03:04 +00:00
|
|
|
static int atkbdc_print_child(device_t bus, device_t dev);
|
1999-01-23 16:53:30 +00:00
|
|
|
static int atkbdc_read_ivar(device_t bus, device_t dev, int index,
|
2000-04-30 10:01:56 +00:00
|
|
|
uintptr_t *val);
|
1999-01-23 16:53:30 +00:00
|
|
|
static int atkbdc_write_ivar(device_t bus, device_t dev, int index,
|
2000-04-30 10:01:56 +00:00
|
|
|
uintptr_t val);
|
2001-09-06 12:09:26 +00:00
|
|
|
static struct resource_list
|
|
|
|
*atkbdc_get_resource_list (device_t bus, device_t dev);
|
|
|
|
static struct resource
|
|
|
|
*atkbdc_alloc_resource(device_t bus, device_t dev, int type,
|
|
|
|
int *rid, u_long start, u_long end,
|
|
|
|
u_long count, u_int flags);
|
|
|
|
static int atkbdc_release_resource(device_t bus, device_t dev, int type,
|
|
|
|
int rid, struct resource *res);
|
1999-01-23 16:53:30 +00:00
|
|
|
|
|
|
|
static device_method_t atkbdc_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, atkbdc_probe),
|
|
|
|
DEVMETHOD(device_attach, atkbdc_attach),
|
1999-05-18 11:33:14 +00:00
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
1999-01-23 16:53:30 +00:00
|
|
|
|
2001-09-06 12:09:26 +00:00
|
|
|
DEVMETHOD(bus_add_child, atkbdc_add_child),
|
1999-01-23 16:53:30 +00:00
|
|
|
DEVMETHOD(bus_print_child, atkbdc_print_child),
|
|
|
|
DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
|
|
|
|
DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
|
2001-09-06 12:09:26 +00:00
|
|
|
DEVMETHOD(bus_get_resource_list,atkbdc_get_resource_list),
|
|
|
|
DEVMETHOD(bus_alloc_resource, atkbdc_alloc_resource),
|
|
|
|
DEVMETHOD(bus_release_resource, atkbdc_release_resource),
|
1999-01-23 16:53:30 +00:00
|
|
|
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
|
|
|
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
2001-09-06 12:09:26 +00:00
|
|
|
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
|
|
|
|
DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
|
|
|
|
DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
|
1999-01-23 16:53:30 +00:00
|
|
|
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
|
|
|
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t atkbdc_driver = {
|
|
|
|
ATKBDC_DRIVER_NAME,
|
|
|
|
atkbdc_methods,
|
|
|
|
sizeof(atkbdc_softc_t *),
|
|
|
|
};
|
|
|
|
|
2000-03-19 03:25:13 +00:00
|
|
|
static struct isa_pnp_id atkbdc_ids[] = {
|
|
|
|
{ 0x0303d041, "Keyboard controller (i8042)" }, /* PNP0303 */
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
1999-01-23 16:53:30 +00:00
|
|
|
static int
|
|
|
|
atkbdc_probe(device_t dev)
|
|
|
|
{
|
2000-03-19 03:25:13 +00:00
|
|
|
struct resource *port0;
|
|
|
|
struct resource *port1;
|
2001-09-06 12:09:26 +00:00
|
|
|
u_long start;
|
|
|
|
u_long count;
|
2000-03-19 03:25:13 +00:00
|
|
|
int error;
|
|
|
|
int rid;
|
1999-01-23 16:53:30 +00:00
|
|
|
|
2000-03-19 03:25:13 +00:00
|
|
|
/* check PnP IDs */
|
|
|
|
if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
device_set_desc(dev, "Keyboard controller (i8042)");
|
1999-05-30 11:12:30 +00:00
|
|
|
|
2001-09-06 12:09:26 +00:00
|
|
|
/*
|
|
|
|
* Adjust I/O port resources.
|
|
|
|
* The AT keyboard controller uses two ports (a command/data port
|
|
|
|
* 0x60 and a status port 0x64), which may be given to us in
|
|
|
|
* one resource (0x60 through 0x64) or as two separate resources
|
|
|
|
* (0x60 and 0x64). Furthermore, /boot/device.hints may contain
|
|
|
|
* just one port, 0x60. We shall adjust resource settings
|
|
|
|
* so that these two ports are available as two separate resources.
|
|
|
|
*/
|
|
|
|
device_quiet(dev);
|
1999-05-22 15:47:34 +00:00
|
|
|
rid = 0;
|
2001-09-06 12:09:26 +00:00
|
|
|
if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
|
|
|
|
return ENXIO;
|
|
|
|
if (count > 1) /* adjust the count */
|
|
|
|
bus_set_resource(dev, SYS_RES_IOPORT, rid, start, 1);
|
2004-03-17 17:50:55 +00:00
|
|
|
port0 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
|
2000-03-19 03:25:13 +00:00
|
|
|
if (port0 == NULL)
|
|
|
|
return ENXIO;
|
|
|
|
rid = 1;
|
2001-09-06 12:09:26 +00:00
|
|
|
if (bus_get_resource(dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0)
|
|
|
|
bus_set_resource(dev, SYS_RES_IOPORT, 1,
|
|
|
|
start + KBD_STATUS_PORT, 1);
|
2004-03-17 17:50:55 +00:00
|
|
|
port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
|
2000-03-19 03:25:13 +00:00
|
|
|
if (port1 == NULL) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
|
1999-05-22 15:47:34 +00:00
|
|
|
return ENXIO;
|
2000-03-19 03:25:13 +00:00
|
|
|
}
|
2001-09-06 12:09:26 +00:00
|
|
|
device_verbose(dev);
|
2000-03-19 03:25:13 +00:00
|
|
|
|
|
|
|
error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
|
2001-09-06 12:09:26 +00:00
|
|
|
if (error == 0)
|
|
|
|
bus_generic_probe(dev);
|
2000-03-19 03:25:13 +00:00
|
|
|
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
|
|
|
|
|
1999-01-23 16:53:30 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
atkbdc_attach(device_t dev)
|
|
|
|
{
|
|
|
|
atkbdc_softc_t *sc;
|
2001-09-06 12:09:26 +00:00
|
|
|
int unit;
|
1999-05-18 11:33:14 +00:00
|
|
|
int error;
|
1999-06-29 17:35:09 +00:00
|
|
|
int rid;
|
1999-01-23 16:53:30 +00:00
|
|
|
|
1999-05-18 11:33:14 +00:00
|
|
|
unit = device_get_unit(dev);
|
1999-01-23 16:53:30 +00:00
|
|
|
sc = *(atkbdc_softc_t **)device_get_softc(dev);
|
1999-05-18 11:33:14 +00:00
|
|
|
if (sc == NULL) {
|
|
|
|
/*
|
|
|
|
* We have to maintain two copies of the kbdc_softc struct,
|
|
|
|
* as the low-level console needs to have access to the
|
|
|
|
* keyboard controller before kbdc is probed and attached.
|
|
|
|
* kbdc_soft[] contains the default entry for that purpose.
|
|
|
|
* See atkbdc.c. XXX
|
|
|
|
*/
|
|
|
|
sc = atkbdc_get_softc(unit);
|
|
|
|
if (sc == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
1999-06-29 17:35:09 +00:00
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->port0 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
|
|
|
|
RF_ACTIVE);
|
2000-03-19 03:25:13 +00:00
|
|
|
if (sc->port0 == NULL)
|
1999-06-29 17:35:09 +00:00
|
|
|
return ENXIO;
|
2000-03-19 03:25:13 +00:00
|
|
|
rid = 1;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
|
|
|
|
RF_ACTIVE);
|
2000-03-19 03:25:13 +00:00
|
|
|
if (sc->port1 == NULL) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1);
|
|
|
|
if (error) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1);
|
1999-05-18 11:33:14 +00:00
|
|
|
return error;
|
2000-03-19 03:25:13 +00:00
|
|
|
}
|
1999-05-18 11:33:14 +00:00
|
|
|
*(atkbdc_softc_t **)device_get_softc(dev) = sc;
|
1999-01-23 16:53:30 +00:00
|
|
|
|
2001-09-06 12:09:26 +00:00
|
|
|
bus_generic_attach(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static device_t
|
|
|
|
atkbdc_add_child(device_t bus, int order, char *name, int unit)
|
|
|
|
{
|
|
|
|
atkbdc_device_t *ivar;
|
|
|
|
device_t child;
|
|
|
|
int t;
|
|
|
|
|
|
|
|
ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV,
|
|
|
|
M_NOWAIT | M_ZERO);
|
|
|
|
if (!ivar)
|
|
|
|
return NULL;
|
|
|
|
|
2001-09-25 16:59:28 +00:00
|
|
|
child = device_add_child_ordered(bus, order, name, unit);
|
2001-09-06 12:09:26 +00:00
|
|
|
if (child == NULL) {
|
|
|
|
free(ivar, M_ATKBDDEV);
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
resource_list_init(&ivar->resources);
|
|
|
|
ivar->rid = order;
|
1999-01-23 16:53:30 +00:00
|
|
|
|
|
|
|
/*
|
2001-09-06 12:09:26 +00:00
|
|
|
* If the device is not created by the PnP BIOS or ACPI,
|
|
|
|
* refer to device hints for IRQ.
|
1999-01-23 16:53:30 +00:00
|
|
|
*/
|
2001-09-06 12:09:26 +00:00
|
|
|
if (ISA_PNP_PROBE(device_get_parent(bus), bus, atkbdc_ids) != 0) {
|
|
|
|
if (resource_int_value(name, unit, "irq", &t) != 0)
|
|
|
|
t = -1;
|
|
|
|
} else {
|
|
|
|
t = bus_get_resource_start(bus, SYS_RES_IRQ, ivar->rid);
|
|
|
|
}
|
|
|
|
if (t > 0)
|
|
|
|
resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid,
|
|
|
|
t, t, 1);
|
1999-01-23 16:53:30 +00:00
|
|
|
|
2003-07-02 16:09:02 +00:00
|
|
|
if (resource_disabled(name, unit))
|
2001-09-06 12:09:26 +00:00
|
|
|
device_disable(child);
|
1999-01-23 16:53:30 +00:00
|
|
|
|
2001-09-06 12:09:26 +00:00
|
|
|
device_set_ivars(child, ivar);
|
|
|
|
|
|
|
|
return child;
|
1999-01-23 16:53:30 +00:00
|
|
|
}
|
|
|
|
|
1999-07-29 01:03:04 +00:00
|
|
|
static int
|
1999-01-23 16:53:30 +00:00
|
|
|
atkbdc_print_child(device_t bus, device_t dev)
|
|
|
|
{
|
|
|
|
atkbdc_device_t *kbdcdev;
|
2001-09-06 12:09:26 +00:00
|
|
|
u_long irq;
|
|
|
|
int flags;
|
1999-07-29 01:03:04 +00:00
|
|
|
int retval = 0;
|
1999-01-23 16:53:30 +00:00
|
|
|
|
|
|
|
kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
|
|
|
|
|
1999-07-29 01:03:04 +00:00
|
|
|
retval += bus_print_child_header(bus, dev);
|
2001-09-06 12:09:26 +00:00
|
|
|
flags = device_get_flags(dev);
|
|
|
|
if (flags != 0)
|
|
|
|
retval += printf(" flags 0x%x", flags);
|
|
|
|
irq = bus_get_resource_start(dev, SYS_RES_IRQ, kbdcdev->rid);
|
|
|
|
if (irq != 0)
|
|
|
|
retval += printf(" irq %ld", irq);
|
1999-07-29 01:03:04 +00:00
|
|
|
retval += bus_print_child_footer(bus, dev);
|
1999-01-23 16:53:30 +00:00
|
|
|
|
1999-07-29 01:03:04 +00:00
|
|
|
return (retval);
|
1999-01-23 16:53:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-30 10:01:56 +00:00
|
|
|
atkbdc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
|
1999-01-23 16:53:30 +00:00
|
|
|
{
|
|
|
|
atkbdc_device_t *ivar;
|
|
|
|
|
|
|
|
ivar = (atkbdc_device_t *)device_get_ivars(dev);
|
|
|
|
switch (index) {
|
2000-03-19 04:37:18 +00:00
|
|
|
case KBDC_IVAR_VENDORID:
|
|
|
|
*val = (u_long)ivar->vendorid;
|
|
|
|
break;
|
|
|
|
case KBDC_IVAR_SERIAL:
|
|
|
|
*val = (u_long)ivar->serial;
|
|
|
|
break;
|
|
|
|
case KBDC_IVAR_LOGICALID:
|
|
|
|
*val = (u_long)ivar->logicalid;
|
|
|
|
break;
|
|
|
|
case KBDC_IVAR_COMPATID:
|
|
|
|
*val = (u_long)ivar->compatid;
|
|
|
|
break;
|
1999-01-23 16:53:30 +00:00
|
|
|
default:
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-30 10:01:56 +00:00
|
|
|
atkbdc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
|
1999-01-23 16:53:30 +00:00
|
|
|
{
|
|
|
|
atkbdc_device_t *ivar;
|
|
|
|
|
|
|
|
ivar = (atkbdc_device_t *)device_get_ivars(dev);
|
|
|
|
switch (index) {
|
2000-03-19 04:37:18 +00:00
|
|
|
case KBDC_IVAR_VENDORID:
|
|
|
|
ivar->vendorid = (u_int32_t)val;
|
|
|
|
break;
|
|
|
|
case KBDC_IVAR_SERIAL:
|
|
|
|
ivar->serial = (u_int32_t)val;
|
|
|
|
break;
|
|
|
|
case KBDC_IVAR_LOGICALID:
|
|
|
|
ivar->logicalid = (u_int32_t)val;
|
|
|
|
break;
|
|
|
|
case KBDC_IVAR_COMPATID:
|
|
|
|
ivar->compatid = (u_int32_t)val;
|
|
|
|
break;
|
1999-01-23 16:53:30 +00:00
|
|
|
default:
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-06 12:09:26 +00:00
|
|
|
static struct resource_list
|
|
|
|
*atkbdc_get_resource_list (device_t bus, device_t dev)
|
|
|
|
{
|
|
|
|
atkbdc_device_t *ivar;
|
|
|
|
|
|
|
|
ivar = (atkbdc_device_t *)device_get_ivars(dev);
|
|
|
|
return &ivar->resources;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct resource
|
|
|
|
*atkbdc_alloc_resource(device_t bus, device_t dev, int type, int *rid,
|
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
|
|
|
{
|
|
|
|
atkbdc_device_t *ivar;
|
|
|
|
|
|
|
|
ivar = (atkbdc_device_t *)device_get_ivars(dev);
|
|
|
|
return resource_list_alloc(&ivar->resources, bus, dev, type, rid,
|
|
|
|
start, end, count, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
atkbdc_release_resource(device_t bus, device_t dev, int type, int rid,
|
|
|
|
struct resource *res)
|
|
|
|
{
|
|
|
|
atkbdc_device_t *ivar;
|
|
|
|
|
|
|
|
ivar = (atkbdc_device_t *)device_get_ivars(dev);
|
|
|
|
return resource_list_release(&ivar->resources, bus, dev, type, rid,
|
|
|
|
res);
|
|
|
|
}
|
|
|
|
|
1999-01-23 16:53:30 +00:00
|
|
|
DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
|
2001-08-30 09:17:03 +00:00
|
|
|
DRIVER_MODULE(atkbdc, acpi, atkbdc_driver, atkbdc_devclass, 0, 0);
|