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