#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: obmem.c,v 1.21 2021/08/07 16:19:06 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <uvm/uvm_extern.h>
#include <machine/autoconf.h>
#include <machine/pmap.h>
#include <sun2/sun2/control.h>
#include <sun2/sun2/machdep.h>
static int obmem_match(device_t, cfdata_t, void *);
static void obmem_attach(device_t, device_t, void *);
struct obmem_softc {
device_t sc_dev;
bus_space_tag_t sc_bustag;
bus_dma_tag_t sc_dmatag;
};
CFATTACH_DECL_NEW(obmem, sizeof(struct obmem_softc),
obmem_match, obmem_attach, NULL, NULL);
static int obmem_attached;
static paddr_t obmem_bus_mmap(bus_space_tag_t, bus_type_t, bus_addr_t,
off_t, int, int);
static int _obmem_bus_map(bus_space_tag_t, bus_type_t, bus_addr_t,
bus_size_t, int, vaddr_t, bus_space_handle_t *);
static struct sun68k_bus_space_tag obmem_space_tag = {
NULL,
NULL,
_obmem_bus_map,
NULL,
NULL,
NULL,
obmem_bus_mmap,
NULL,
NULL,
NULL
};
static int
obmem_match(device_t parent, cfdata_t cf, void *aux)
{
struct mainbus_attach_args *ma = aux;
if (obmem_attached)
return 0;
return ma->ma_name == NULL || strcmp(cf->cf_name, ma->ma_name) == 0;
}
static void
obmem_attach(device_t parent, device_t self, void *aux)
{
struct mainbus_attach_args *ma = aux;
struct obmem_softc *sc = device_private(self);
struct obmem_attach_args obma;
const char *const *cpp;
static const char *const special[] = {
NULL
};
obmem_attached = 1;
sc->sc_dev = self;
aprint_normal("\n");
sc->sc_bustag = ma->ma_bustag;
sc->sc_dmatag = ma->ma_dmatag;
obmem_space_tag.cookie = sc;
obmem_space_tag.parent = sc->sc_bustag;
obma = *ma;
obma.obma_bustag = &obmem_space_tag;
obma.obma_paddr = LOCATOR_REQUIRED;
obma.obma_pri = LOCATOR_OPTIONAL;
for (cpp = special; *cpp != NULL; cpp++) {
obma.obma_name = *cpp;
config_search(self, &obma,
CFARGS(.search = sun68k_bus_search));
}
obma.obma_name = NULL;
config_search(self, &obma,
CFARGS(.search = sun68k_bus_search));
}
int
_obmem_bus_map(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr,
bus_size_t size, int flags, vaddr_t vaddr, bus_space_handle_t *hp)
{
struct obmem_softc *sc = t->cookie;
return bus_space_map2(sc->sc_bustag, PMAP_OBMEM, paddr,
size, flags, vaddr, hp);
}
paddr_t
obmem_bus_mmap(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr, off_t off,
int prot, int flags)
{
struct obmem_softc *sc = t->cookie;
return bus_space_mmap2(sc->sc_bustag, PMAP_OBMEM, paddr, off,
prot, flags);
}