#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/rman.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <machine/bus.h>
#include <arm64/coresight/coresight.h>
#include <arm64/coresight/coresight_funnel.h>
#include "coresight_if.h"
#define FUNNEL_DEBUG
#undef FUNNEL_DEBUG
#ifdef FUNNEL_DEBUG
#define dprintf(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define dprintf(fmt, ...)
#endif
static struct resource_spec funnel_spec[] = {
{ SYS_RES_MEMORY, 0, RF_ACTIVE },
{ -1, 0 }
};
static int
funnel_init(device_t dev)
{
struct funnel_softc *sc;
sc = device_get_softc(dev);
if (sc->hwtype == HWTYPE_STATIC_FUNNEL)
return (0);
bus_write_4(sc->res, CORESIGHT_LAR, CORESIGHT_UNLOCK);
dprintf("Device ID: %x\n", bus_read_4(sc->res, FUNNEL_DEVICEID));
return (0);
}
static int
funnel_enable(device_t dev, struct endpoint *endp,
struct coresight_event *event)
{
struct funnel_softc *sc;
uint32_t reg;
sc = device_get_softc(dev);
if (sc->hwtype == HWTYPE_STATIC_FUNNEL)
return (0);
reg = bus_read_4(sc->res, FUNNEL_FUNCTL);
reg &= ~(FUNCTL_HOLDTIME_MASK);
reg |= (7 << FUNCTL_HOLDTIME_SHIFT);
reg |= (1 << endp->reg);
bus_write_4(sc->res, FUNNEL_FUNCTL, reg);
return (0);
}
static void
funnel_disable(device_t dev, struct endpoint *endp,
struct coresight_event *event)
{
struct funnel_softc *sc;
uint32_t reg;
sc = device_get_softc(dev);
if (sc->hwtype == HWTYPE_STATIC_FUNNEL)
return;
reg = bus_read_4(sc->res, FUNNEL_FUNCTL);
reg &= ~(1 << endp->reg);
bus_write_4(sc->res, FUNNEL_FUNCTL, reg);
}
int
funnel_attach(device_t dev)
{
struct coresight_desc desc;
struct funnel_softc *sc;
sc = device_get_softc(dev);
if (sc->hwtype == HWTYPE_FUNNEL &&
bus_alloc_resources(dev, funnel_spec, &sc->res) != 0) {
device_printf(dev, "cannot allocate resources for device\n");
return (ENXIO);
}
desc.pdata = sc->pdata;
desc.dev = dev;
desc.dev_type = CORESIGHT_FUNNEL;
coresight_register(&desc);
return (0);
}
static device_method_t funnel_methods[] = {
DEVMETHOD(coresight_init, funnel_init),
DEVMETHOD(coresight_enable, funnel_enable),
DEVMETHOD(coresight_disable, funnel_disable),
DEVMETHOD_END
};
DEFINE_CLASS_0(funnel, funnel_driver, funnel_methods,
sizeof(struct funnel_softc));