#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: neptune.c,v 1.23 2021/08/07 16:19:07 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/frame.h>
#include <arch/x68k/dev/intiovar.h>
#include <arch/x68k/dev/neptunevar.h>
static int neptune_bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
int, bus_space_handle_t *);
static void neptune_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
static int neptune_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_size_t, bus_space_handle_t *);
static struct x68k_bus_space neptune_bus = {
#if 0
X68K_NEPUTUNE_BUS,
#endif
neptune_bus_space_map, neptune_bus_space_unmap,
neptune_bus_space_subregion,
x68k_bus_space_alloc, x68k_bus_space_free,
};
static int neptune_match(device_t, cfdata_t, void *);
static void neptune_attach(device_t, device_t, void *);
static int neptune_search(device_t, cfdata_t, const int *, void *);
static int neptune_print(void *, const char *);
CFATTACH_DECL_NEW(neptune, sizeof(struct neptune_softc),
neptune_match, neptune_attach, NULL, NULL);
static int
neptune_match(device_t parent, cfdata_t cf, void *aux)
{
struct intio_attach_args *ia = aux;
if (strcmp(ia->ia_name, "neptune") != 0)
return 0;
ia->ia_size = 0x400;
if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY))
return 0;
return (1);
}
static void
neptune_attach(device_t parent, device_t self, void *aux)
{
struct neptune_softc *sc = device_private(self);
struct intio_attach_args *ia = aux;
struct neptune_attach_args na;
int r __diagused;
cfdata_t cf;
ia->ia_size = 0x400;
r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
#ifdef DIAGNOSTIC
if (r)
panic("IO map for Neptune corruption??");
#endif
sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_WAITOK);
*sc->sc_bst = neptune_bus;
sc->sc_bst->x68k_bus_device = self;
sc->sc_addr = (vaddr_t)IIOV(ia->ia_addr);
na.na_bst = sc->sc_bst;
na.na_intr = ia->ia_intr;
cf = config_search(self, &na,
CFARGS(.submatch = neptune_search));
if (cf) {
aprint_normal(": Neptune-X ISA bridge\n");
config_attach(self, cf, &na, neptune_print, CFARGS_NONE);
} else {
aprint_normal(": no device found.\n");
intio_map_free_region(parent, ia);
}
}
static int
neptune_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
{
struct neptune_attach_args *na = aux;
na->na_addr = cf->neptune_cf_addr;
return config_match(parent, cf, na);
}
static int
neptune_print(void *aux, const char *name)
{
struct neptune_attach_args *na = aux;
aprint_normal(" addr 0x%06x", na->na_addr);
return (QUIET);
}
static int
neptune_bus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size,
int flags, bus_space_handle_t *bshp)
{
struct neptune_softc *sc = device_private(t->x68k_bus_device);
vaddr_t start = sc->sc_addr;
*bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2);
if (badaddr((void *)*bshp)) {
return 1;
}
*bshp |= 0x80000000;
return (0);
}
static void
neptune_bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
bus_size_t size)
{
return;
}
static int
neptune_bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
{
*nbshp = bsh + offset*2;
return (0);
}