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