hb.c revision 1.4 1 1.4 tsubai /* $NetBSD: hb.c,v 1.4 1999/12/17 03:06:14 tsubai 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.4 tsubai struct intrhand {
21 1.4 tsubai int (*func) __P((void *));
22 1.4 tsubai void *arg;
23 1.4 tsubai };
24 1.4 tsubai
25 1.4 tsubai #define NHBINTR 4
26 1.4 tsubai struct intrhand hb_intrhand[6][NHBINTR];
27 1.4 tsubai
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.4 tsubai }
91 1.4 tsubai
92 1.4 tsubai void *
93 1.4 tsubai hb_intr_establish(irq, level, func, arg)
94 1.4 tsubai int irq, level;
95 1.4 tsubai int (*func) __P((void *));
96 1.4 tsubai void *arg;
97 1.4 tsubai {
98 1.4 tsubai struct intrhand *ih = hb_intrhand[irq];
99 1.4 tsubai int i;
100 1.4 tsubai
101 1.4 tsubai for (i = NHBINTR; i > 0; i--) {
102 1.4 tsubai if (ih->func == NULL)
103 1.4 tsubai goto found;
104 1.4 tsubai ih++;
105 1.4 tsubai }
106 1.4 tsubai panic("hb_intr_establish: no room");
107 1.4 tsubai
108 1.4 tsubai found:
109 1.4 tsubai ih->func = func;
110 1.4 tsubai ih->arg = arg;
111 1.4 tsubai
112 1.4 tsubai #ifdef HB_DEBUG
113 1.4 tsubai for (irq = 0; irq <= 2; irq++) {
114 1.4 tsubai for (i = 0; i < NHBINTR; i++) {
115 1.4 tsubai printf("%p(%p) ",
116 1.4 tsubai hb_intrhand[irq][i].func,
117 1.4 tsubai hb_intrhand[irq][i].arg);
118 1.4 tsubai }
119 1.4 tsubai printf("\n");
120 1.4 tsubai }
121 1.4 tsubai #endif
122 1.4 tsubai
123 1.4 tsubai return ih;
124 1.4 tsubai }
125 1.4 tsubai
126 1.4 tsubai void
127 1.4 tsubai hb_intr_dispatch(irq)
128 1.4 tsubai int irq;
129 1.4 tsubai {
130 1.4 tsubai struct intrhand *ih;
131 1.4 tsubai int i;
132 1.4 tsubai
133 1.4 tsubai ih = hb_intrhand[irq];
134 1.4 tsubai for (i = NHBINTR; i > 0; i--) {
135 1.4 tsubai if (ih->func)
136 1.4 tsubai (*ih->func)(ih->arg);
137 1.4 tsubai ih++;
138 1.4 tsubai }
139 1.1 tsubai }
140