#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: zs_any.c,v 1.18 2008/04/28 20:23:37 martin Exp $");
#include "opt_kgdb.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/tty.h>
#include <sys/time.h>
#include <sys/syslog.h>
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/z8530var.h>
#ifdef KGDB
#include <uvm/uvm_extern.h>
#include <machine/idprom.h>
#include <machine/pmap.h>
#include <sun2/dev/cons.h>
#endif
#include <sun2/sun2/machdep.h>
#include <dev/ic/z8530reg.h>
#include <dev/sun/kbd_reg.h>
static int zs_any_match(device_t, cfdata_t, void *);
static void zs_any_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(zs_obio, sizeof(struct zsc_softc),
zs_any_match, zs_any_attach, NULL, NULL);
CFATTACH_DECL_NEW(zs_obmem, sizeof(struct zsc_softc),
zs_any_match, zs_any_attach, NULL, NULL);
CFATTACH_DECL_NEW(zs_mbmem, sizeof(struct zsc_softc),
zs_any_match, zs_any_attach, NULL, NULL);
static int
zs_any_match(device_t parent, cfdata_t cf, void *aux)
{
struct mainbus_attach_args *ma = aux;
bus_space_handle_t bh;
int matched;
if (bus_space_map(ma->ma_bustag, ma->ma_paddr, sizeof(struct zsdevice),
0, &bh))
return (0);
matched = (bus_space_peek_1(ma->ma_bustag, bh, 0, NULL) == 0);
bus_space_unmap(ma->ma_bustag, bh, sizeof(struct zsdevice));
if (!matched)
return (0);
if (ma->ma_pri == -1)
ma->ma_pri = ZSHARD_PRI;
return (1);
}
static void
zs_any_attach(device_t parent, device_t self, void *aux)
{
struct zsc_softc *zsc = device_private(self);
struct mainbus_attach_args *ma = aux;
bus_space_handle_t bh;
zsc->zsc_dev = self;
zsc->zsc_bustag = ma->ma_bustag;
zsc->zsc_dmatag = ma->ma_dmatag;
zsc->zsc_promunit = device_unit(self);
zsc->zsc_node = 0;
if (bus_space_map(ma->ma_bustag, ma->ma_paddr, sizeof(struct zsdevice),
BUS_SPACE_MAP_LINEAR, &bh)) {
aprint_normal("\n");
panic("%s: can't map", __func__);
}
zs_attach(zsc, (void *)bh, ma->ma_pri);
}
int
zs_console_flags(int promunit, int node, int channel)
{
int cookie, flags = 0;
if (promunit == 0)
cookie = PROMDEV_TTYA + channel;
else if (promunit == 1 && channel == 0)
cookie = PROMDEV_KBD;
else
cookie = -1;
if (cookie == prom_stdin() &&
(cookie != PROMDEV_KBD || prom_kbdid() >= KB_SUN2))
flags |= ZS_HWFLAG_CONSOLE_INPUT;
if (cookie != PROMDEV_KBD && cookie == prom_stdout())
flags |= ZS_HWFLAG_CONSOLE_OUTPUT;
return (flags);
}
#ifdef KGDB
void *
zs_find_prom(int unit)
{
bus_addr_t zs0_phys;
vaddr_t va;
if (unit != 0)
return (NULL);
zs0_phys = (cpu_machine_id == ID_SUN2_120 ? 0x002000 : 0x7f2000);
if (find_prom_map(zs0_phys, PMAP_OBIO, sizeof(struct zsdevice), &va))
return (NULL);
return (void *)va;
}
#endif