Home | History | Annotate | Line # | Download | only in dev
hb.c revision 1.3.2.1
      1  1.3.2.1  bouyer /*	$NetBSD: hb.c,v 1.3.2.1 2000/11/20 20:17:21 bouyer Exp $	*/
      2      1.1  tsubai 
      3      1.1  tsubai #include <sys/param.h>
      4      1.1  tsubai #include <sys/systm.h>
      5      1.1  tsubai #include <sys/device.h>
      6      1.1  tsubai 
      7      1.1  tsubai #include <machine/autoconf.h>
      8      1.1  tsubai 
      9      1.1  tsubai static int	hb_match __P((struct device *, struct cfdata *, void *));
     10      1.1  tsubai static void	hb_attach __P((struct device *, struct device *, void *));
     11      1.2  tsubai static int	hb_search __P((struct device *, struct cfdata *, void *));
     12      1.1  tsubai static int	hb_print __P((void *, const char *));
     13      1.1  tsubai 
     14      1.1  tsubai struct cfattach hb_ca = {
     15      1.1  tsubai 	sizeof(struct device), hb_match, hb_attach
     16      1.1  tsubai };
     17      1.1  tsubai 
     18      1.1  tsubai extern struct cfdriver hb_cd;
     19      1.1  tsubai 
     20  1.3.2.1  bouyer struct intrhand {
     21  1.3.2.1  bouyer 	int (*func) __P((void *));
     22  1.3.2.1  bouyer 	void *arg;
     23  1.3.2.1  bouyer };
     24  1.3.2.1  bouyer 
     25  1.3.2.1  bouyer #define NHBINTR	4
     26  1.3.2.1  bouyer struct intrhand hb_intrhand[6][NHBINTR];
     27  1.3.2.1  bouyer 
     28      1.1  tsubai static int
     29      1.1  tsubai hb_match(parent, cf, aux)
     30      1.1  tsubai 	struct device *parent;
     31      1.1  tsubai 	struct cfdata *cf;
     32      1.1  tsubai 	void *aux;
     33      1.1  tsubai {
     34      1.1  tsubai 	struct confargs *ca = aux;
     35      1.1  tsubai 
     36      1.1  tsubai 	if (strcmp(ca->ca_name, hb_cd.cd_name) != 0)
     37      1.1  tsubai 		return 0;
     38      1.1  tsubai 
     39      1.1  tsubai 	return 1;
     40      1.1  tsubai }
     41      1.1  tsubai 
     42      1.1  tsubai static void
     43      1.1  tsubai hb_attach(parent, self, aux)
     44      1.1  tsubai 	struct device *parent;
     45      1.1  tsubai 	struct device *self;
     46      1.1  tsubai 	void *aux;
     47      1.1  tsubai {
     48      1.3  tsubai 	struct confargs *ca = aux;
     49      1.1  tsubai 
     50      1.1  tsubai 	printf("\n");
     51      1.3  tsubai 	config_search(hb_search, self, ca);
     52      1.1  tsubai }
     53      1.1  tsubai 
     54      1.2  tsubai static int
     55      1.2  tsubai hb_search(parent, cf, aux)
     56      1.2  tsubai 	struct device *parent;
     57      1.2  tsubai 	struct cfdata *cf;
     58      1.2  tsubai 	void *aux;
     59      1.2  tsubai {
     60      1.2  tsubai 	struct confargs *ca = aux;
     61      1.2  tsubai 
     62      1.2  tsubai 	ca->ca_addr = cf->cf_addr;
     63      1.3  tsubai 	ca->ca_name = cf->cf_driver->cd_name;
     64      1.2  tsubai 
     65      1.3  tsubai 	if ((*cf->cf_attach->ca_match)(parent, cf, ca) > 0)
     66      1.2  tsubai 		config_attach(parent, cf, ca, hb_print);
     67      1.2  tsubai 
     68      1.2  tsubai 	return 0;
     69      1.2  tsubai }
     70      1.2  tsubai 
     71      1.1  tsubai /*
     72      1.1  tsubai  * Print out the confargs.  The (parent) name is non-NULL
     73      1.1  tsubai  * when there was no match found by config_found().
     74      1.1  tsubai  */
     75      1.1  tsubai static int
     76      1.1  tsubai hb_print(args, name)
     77      1.1  tsubai 	void *args;
     78      1.1  tsubai 	const char *name;
     79      1.1  tsubai {
     80      1.1  tsubai 	struct confargs *ca = args;
     81      1.1  tsubai 
     82      1.1  tsubai 	/* Be quiet about empty HB locations. */
     83      1.1  tsubai 	if (name)
     84      1.3  tsubai 		return QUIET;
     85      1.1  tsubai 
     86      1.1  tsubai 	if (ca->ca_addr != -1)
     87      1.1  tsubai 		printf(" addr 0x%x", ca->ca_addr);
     88      1.1  tsubai 
     89      1.3  tsubai 	return UNCONF;
     90  1.3.2.1  bouyer }
     91  1.3.2.1  bouyer 
     92  1.3.2.1  bouyer void *
     93  1.3.2.1  bouyer hb_intr_establish(irq, level, func, arg)
     94  1.3.2.1  bouyer 	int irq, level;
     95  1.3.2.1  bouyer 	int (*func) __P((void *));
     96  1.3.2.1  bouyer 	void *arg;
     97  1.3.2.1  bouyer {
     98  1.3.2.1  bouyer 	struct intrhand *ih = hb_intrhand[irq];
     99  1.3.2.1  bouyer 	int i;
    100  1.3.2.1  bouyer 
    101  1.3.2.1  bouyer 	for (i = NHBINTR; i > 0; i--) {
    102  1.3.2.1  bouyer 		if (ih->func == NULL)
    103  1.3.2.1  bouyer 			goto found;
    104  1.3.2.1  bouyer 		ih++;
    105  1.3.2.1  bouyer 	}
    106  1.3.2.1  bouyer 	panic("hb_intr_establish: no room");
    107  1.3.2.1  bouyer 
    108  1.3.2.1  bouyer found:
    109  1.3.2.1  bouyer 	ih->func = func;
    110  1.3.2.1  bouyer 	ih->arg = arg;
    111  1.3.2.1  bouyer 
    112  1.3.2.1  bouyer #ifdef HB_DEBUG
    113  1.3.2.1  bouyer 	for (irq = 0; irq <= 2; irq++) {
    114  1.3.2.1  bouyer 		for (i = 0; i < NHBINTR; i++) {
    115  1.3.2.1  bouyer 			printf("%p(%p) ",
    116  1.3.2.1  bouyer 			       hb_intrhand[irq][i].func,
    117  1.3.2.1  bouyer 			       hb_intrhand[irq][i].arg);
    118  1.3.2.1  bouyer 		}
    119  1.3.2.1  bouyer 		printf("\n");
    120  1.3.2.1  bouyer 	}
    121  1.3.2.1  bouyer #endif
    122  1.3.2.1  bouyer 
    123  1.3.2.1  bouyer 	return ih;
    124  1.3.2.1  bouyer }
    125  1.3.2.1  bouyer 
    126  1.3.2.1  bouyer void
    127  1.3.2.1  bouyer hb_intr_dispatch(irq)
    128  1.3.2.1  bouyer 	int irq;
    129  1.3.2.1  bouyer {
    130  1.3.2.1  bouyer 	struct intrhand *ih;
    131  1.3.2.1  bouyer 	int i;
    132  1.3.2.1  bouyer 
    133  1.3.2.1  bouyer 	ih = hb_intrhand[irq];
    134  1.3.2.1  bouyer 	for (i = NHBINTR; i > 0; i--) {
    135  1.3.2.1  bouyer 		if (ih->func)
    136  1.3.2.1  bouyer 			(*ih->func)(ih->arg);
    137  1.3.2.1  bouyer 		ih++;
    138  1.3.2.1  bouyer 	}
    139      1.1  tsubai }
    140