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