hb.c revision 1.11 1 1.11 tsutsui /* $NetBSD: hb.c,v 1.11 2003/05/09 13:36:40 tsutsui 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.11 tsutsui #include <newsmips/dev/hbvar.h>
10 1.11 tsutsui
11 1.1 tsubai static int hb_match __P((struct device *, struct cfdata *, void *));
12 1.1 tsubai static void hb_attach __P((struct device *, struct device *, void *));
13 1.2 tsubai static int hb_search __P((struct device *, struct cfdata *, void *));
14 1.1 tsubai static int hb_print __P((void *, const char *));
15 1.1 tsubai
16 1.9 thorpej CFATTACH_DECL(hb, sizeof(struct device),
17 1.9 thorpej hb_match, hb_attach, NULL, NULL);
18 1.1 tsubai
19 1.1 tsubai extern struct cfdriver hb_cd;
20 1.1 tsubai
21 1.4 tsubai struct intrhand {
22 1.4 tsubai int (*func) __P((void *));
23 1.4 tsubai void *arg;
24 1.4 tsubai };
25 1.4 tsubai
26 1.4 tsubai #define NHBINTR 4
27 1.4 tsubai struct intrhand hb_intrhand[6][NHBINTR];
28 1.4 tsubai
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.11 tsutsui struct hb_attach_args ha;
50 1.1 tsubai
51 1.1 tsubai printf("\n");
52 1.11 tsutsui memset(&ha, 0, sizeof(ha));
53 1.11 tsutsui config_search(hb_search, self, &ha);
54 1.1 tsubai }
55 1.1 tsubai
56 1.2 tsubai static int
57 1.2 tsubai hb_search(parent, cf, aux)
58 1.2 tsubai struct device *parent;
59 1.2 tsubai struct cfdata *cf;
60 1.2 tsubai void *aux;
61 1.2 tsubai {
62 1.11 tsutsui struct hb_attach_args *ha = aux;
63 1.2 tsubai
64 1.11 tsutsui ha->ha_name = cf->cf_name;
65 1.11 tsutsui ha->ha_addr = cf->cf_addr;
66 1.11 tsutsui ha->ha_level = cf->cf_level;
67 1.2 tsubai
68 1.11 tsutsui if (config_match(parent, cf, ha) > 0)
69 1.11 tsutsui config_attach(parent, cf, ha, hb_print);
70 1.2 tsubai
71 1.2 tsubai return 0;
72 1.2 tsubai }
73 1.2 tsubai
74 1.1 tsubai /*
75 1.1 tsubai * Print out the confargs. The (parent) name is non-NULL
76 1.1 tsubai * when there was no match found by config_found().
77 1.1 tsubai */
78 1.1 tsubai static int
79 1.1 tsubai hb_print(args, name)
80 1.1 tsubai void *args;
81 1.1 tsubai const char *name;
82 1.1 tsubai {
83 1.11 tsutsui struct hb_attach_args *ha = args;
84 1.1 tsubai
85 1.1 tsubai /* Be quiet about empty HB locations. */
86 1.1 tsubai if (name)
87 1.3 tsubai return QUIET;
88 1.1 tsubai
89 1.11 tsutsui if (ha->ha_addr != -1)
90 1.11 tsutsui aprint_normal(" addr 0x%x", ha->ha_addr);
91 1.1 tsubai
92 1.3 tsubai return UNCONF;
93 1.4 tsubai }
94 1.4 tsubai
95 1.4 tsubai void *
96 1.4 tsubai hb_intr_establish(irq, level, func, arg)
97 1.4 tsubai int irq, level;
98 1.4 tsubai int (*func) __P((void *));
99 1.4 tsubai void *arg;
100 1.4 tsubai {
101 1.4 tsubai struct intrhand *ih = hb_intrhand[irq];
102 1.4 tsubai int i;
103 1.4 tsubai
104 1.4 tsubai for (i = NHBINTR; i > 0; i--) {
105 1.4 tsubai if (ih->func == NULL)
106 1.4 tsubai goto found;
107 1.4 tsubai ih++;
108 1.4 tsubai }
109 1.4 tsubai panic("hb_intr_establish: no room");
110 1.4 tsubai
111 1.4 tsubai found:
112 1.4 tsubai ih->func = func;
113 1.4 tsubai ih->arg = arg;
114 1.4 tsubai
115 1.4 tsubai #ifdef HB_DEBUG
116 1.4 tsubai for (irq = 0; irq <= 2; irq++) {
117 1.4 tsubai for (i = 0; i < NHBINTR; i++) {
118 1.4 tsubai printf("%p(%p) ",
119 1.4 tsubai hb_intrhand[irq][i].func,
120 1.4 tsubai hb_intrhand[irq][i].arg);
121 1.4 tsubai }
122 1.4 tsubai printf("\n");
123 1.4 tsubai }
124 1.4 tsubai #endif
125 1.4 tsubai
126 1.4 tsubai return ih;
127 1.4 tsubai }
128 1.4 tsubai
129 1.4 tsubai void
130 1.4 tsubai hb_intr_dispatch(irq)
131 1.4 tsubai int irq;
132 1.4 tsubai {
133 1.4 tsubai struct intrhand *ih;
134 1.4 tsubai int i;
135 1.4 tsubai
136 1.4 tsubai ih = hb_intrhand[irq];
137 1.4 tsubai for (i = NHBINTR; i > 0; i--) {
138 1.4 tsubai if (ih->func)
139 1.4 tsubai (*ih->func)(ih->arg);
140 1.4 tsubai ih++;
141 1.4 tsubai }
142 1.1 tsubai }
143