NetBSD/sys/arch/newsmips/dev/hb.c

156 lines
2.9 KiB
C
Raw Normal View History

/* $NetBSD: hb.c,v 1.12 2003/05/10 09:46:25 tsutsui Exp $ */
1998-02-18 16:48:03 +03:00
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
1998-02-18 16:48:03 +03:00
#include <machine/autoconf.h>
#include <machine/intr.h>
1998-02-18 16:48:03 +03:00
#include <newsmips/dev/hbvar.h>
1998-02-18 16:48:03 +03:00
static int hb_match __P((struct device *, struct cfdata *, void *));
static void hb_attach __P((struct device *, struct device *, void *));
static int hb_search __P((struct device *, struct cfdata *, void *));
1998-02-18 16:48:03 +03:00
static int hb_print __P((void *, const char *));
2002-10-02 08:27:51 +04:00
CFATTACH_DECL(hb, sizeof(struct device),
hb_match, hb_attach, NULL, NULL);
1998-02-18 16:48:03 +03:00
extern struct cfdriver hb_cd;
#define NLEVEL 4
static struct newsmips_intr hbintr_tab[NLEVEL];
1999-12-17 06:06:13 +03:00
1998-02-18 16:48:03 +03:00
static int
hb_match(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct confargs *ca = aux;
if (strcmp(ca->ca_name, hb_cd.cd_name) != 0)
return 0;
return 1;
}
static void
hb_attach(parent, self, aux)
struct device *parent;
struct device *self;
void *aux;
{
struct hb_attach_args ha;
struct newsmips_intr *ip;
int i;
1998-02-18 16:48:03 +03:00
printf("\n");
memset(&ha, 0, sizeof(ha));
for (i = 0; i < NLEVEL; i++) {
ip = &hbintr_tab[i];
LIST_INIT(&ip->intr_q);
}
config_search(hb_search, self, &ha);
1998-02-18 16:48:03 +03:00
}
static int
hb_search(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct hb_attach_args *ha = aux;
ha->ha_name = cf->cf_name;
ha->ha_addr = cf->cf_addr;
ha->ha_level = cf->cf_level;
if (config_match(parent, cf, ha) > 0)
config_attach(parent, cf, ha, hb_print);
return 0;
}
1998-02-18 16:48:03 +03:00
/*
* Print out the confargs. The (parent) name is non-NULL
* when there was no match found by config_found().
*/
static int
hb_print(args, name)
void *args;
const char *name;
{
struct hb_attach_args *ha = args;
1998-02-18 16:48:03 +03:00
/* Be quiet about empty HB locations. */
if (name)
1999-07-11 16:44:04 +04:00
return QUIET;
1998-02-18 16:48:03 +03:00
if (ha->ha_addr != -1)
aprint_normal(" addr 0x%x", ha->ha_addr);
1998-02-18 16:48:03 +03:00
1999-07-11 16:44:04 +04:00
return UNCONF;
1998-02-18 16:48:03 +03:00
}
1999-12-17 06:06:13 +03:00
void *
hb_intr_establish(level, mask, priority, func, arg)
int level, mask, priority;
1999-12-17 06:06:13 +03:00
int (*func) __P((void *));
void *arg;
{
struct newsmips_intr *ip;
struct newsmips_intrhand *ih, *curih;
1999-12-17 06:06:13 +03:00
ip = &hbintr_tab[level];
ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
if (ih == NULL)
panic("hb_intr_establish: malloc failed");
ih->ih_func = func;
ih->ih_arg = arg;
ih->ih_level = level;
ih->ih_mask = mask;
ih->ih_priority = priority;
if (LIST_EMPTY(&ip->intr_q)) {
LIST_INSERT_HEAD(&ip->intr_q, ih, ih_q);
goto done;
1999-12-17 06:06:13 +03:00
}
for (curih = LIST_FIRST(&ip->intr_q);
LIST_NEXT(curih, ih_q) != NULL;
curih = LIST_NEXT(curih, ih_q)) {
if (ih->ih_priority > curih->ih_priority) {
LIST_INSERT_BEFORE(curih, ih, ih_q);
goto done;
1999-12-17 06:06:13 +03:00
}
}
LIST_INSERT_AFTER(curih, ih, ih_q);
done:
1999-12-17 06:06:13 +03:00
return ih;
}
void
hb_intr_dispatch(level, stat)
int level;
int stat;
1999-12-17 06:06:13 +03:00
{
struct newsmips_intr *ip;
struct newsmips_intrhand *ih;
ip = &hbintr_tab[level];
1999-12-17 06:06:13 +03:00
LIST_FOREACH(ih, &ip->intr_q, ih_q) {
if (ih->ih_mask & stat)
(*ih->ih_func)(ih->ih_arg);
1999-12-17 06:06:13 +03:00
}
}