#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lebuffer.c,v 1.41 2022/09/25 18:03:04 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/errno.h>
#include <sys/device.h>
#include <sys/bus.h>
#include <machine/autoconf.h>
#include <sys/cpu.h>
#include <dev/sbus/sbusvar.h>
#include <dev/sbus/lebuffervar.h>
int lebufprint(void *, const char *);
int lebufmatch(device_t, cfdata_t, void *);
void lebufattach(device_t, device_t, void *);
CFATTACH_DECL_NEW(lebuffer, sizeof(struct lebuf_softc),
lebufmatch, lebufattach, NULL, NULL);
int
lebufprint(void *aux, const char *busname)
{
sbus_print(aux, busname);
return (UNCONF);
}
int
lebufmatch(device_t parent, cfdata_t cf, void *aux)
{
struct sbus_attach_args *sa = aux;
return (strcmp(cf->cf_name, sa->sa_name) == 0);
}
void
lebufattach(device_t parent, device_t self, void *aux)
{
struct sbus_attach_args *sa = aux;
struct lebuf_softc *sc = device_private(self);
struct sbus_softc *sbsc = device_private(parent);
int node;
int sbusburst;
bus_space_tag_t bt = sa->sa_bustag;
bus_dma_tag_t dt = sa->sa_dmatag;
bus_space_handle_t bh;
sc->sc_dev = self;
if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset, sa->sa_size,
BUS_SPACE_MAP_LINEAR, &bh) != 0) {
aprint_error(": cannot map registers\n");
return;
}
sc->sc_buffer = bus_space_vaddr(bt, bh);
sc->sc_bufsiz = sa->sa_size;
node = sc->sc_node = sa->sa_node;
sbusburst = sbsc->sc_burst;
if (sbusburst == 0)
sbusburst = SBUS_BURST_32 - 1;
sc->sc_burst = prom_getpropint(node, "burst-sizes", -1);
if (sc->sc_burst == -1)
sc->sc_burst = sbusburst;
sc->sc_burst &= sbusburst;
printf(": %dK memory\n", sc->sc_bufsiz / 1024);
devhandle_t selfh = device_handle(self);
for (node = firstchild(node); node; node = nextsibling(node)) {
struct sbus_attach_args sax;
sbus_setup_attach_args(sbsc,
bt, dt, node, &sax);
(void)config_found(self, (void *)&sax, lebufprint,
CFARGS(.devhandle = prom_node_to_devhandle(selfh, node)));
sbus_destroy_attach_args(&sax);
}
}