hb.c revision 1.3 1 /* $NetBSD: hb.c,v 1.3 2000/02/08 16:17:31 tsutsui Exp $ */
2
3 /*-
4 * Copyright (C) 1999 Izumi Tsutsui. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/device.h>
32
33 #include <machine/autoconf.h>
34 #include <machine/cpu.h>
35
36 #include <news68k/news68k/isr.h>
37 #include <news68k/dev/hbvar.h>
38
39 static int hb_match __P((struct device *, struct cfdata *, void *));
40 static void hb_attach __P((struct device *, struct device *, void *));
41 static int hb_search __P((struct device *, struct cfdata *, void *));
42 static int hb_print __P((void *, const char *));
43
44 struct cfattach hb_ca = {
45 sizeof(struct device), hb_match, hb_attach
46 };
47
48 extern struct cfdriver hb_cd;
49
50 static int
51 hb_match(parent, cf, aux)
52 struct device *parent;
53 struct cfdata *cf;
54 void *aux;
55 {
56 struct mainbus_attach_args *ma = aux;
57
58 if (strcmp(ma->ma_name, hb_cd.cd_name) != 0)
59 return 0;
60
61 if (ma->ma_systype != -1 && ma->ma_systype != systype)
62 return 0;
63
64 return 1;
65 }
66
67 static void
68 hb_attach(parent, self, aux)
69 struct device *parent;
70 struct device *self;
71 void *aux;
72 {
73 struct hb_attach_args ha;
74
75 printf("\n");
76 bzero(&ha, sizeof(ha));
77
78 config_search(hb_search, self, &ha);
79 }
80
81 static int
82 hb_search(parent, cf, aux)
83 struct device *parent;
84 struct cfdata *cf;
85 void *aux;
86 {
87 struct hb_attach_args *ha = aux;
88
89 ha->ha_name = cf->cf_driver->cd_name;
90 ha->ha_address = cf->cf_addr;
91 ha->ha_ipl = cf->cf_ipl;
92 ha->ha_vect = cf->cf_vect;
93
94 if ((*cf->cf_attach->ca_match)(parent, cf, ha) > 0)
95 config_attach(parent, cf, ha, hb_print);
96
97 return 0;
98 }
99
100 /*
101 * Print out the confargs. The (parent) name is non-NULL
102 * when there was no match found by config_found().
103 */
104 static int
105 hb_print(args, name)
106 void *args;
107 const char *name;
108 {
109 struct hb_attach_args *ha = args;
110
111 #if 0
112 if (ha->ha_addr > 0)
113 #endif
114 printf (" addr 0x%08lx", ha->ha_address);
115 if (ha->ha_ipl > 0)
116 printf (" ipl %d", ha->ha_ipl);
117 if (ha->ha_vect > 0) {
118 printf (" vect %d", ha->ha_vect);
119 }
120
121 return (QUIET);
122 }
123
124 /*
125 * hb_intr_establish: establish hb interrupt
126 */
127 void
128 hb_intr_establish(hbvect, hand, ipl, arg)
129 int hbvect;
130 int (*hand) __P((void *)), ipl;
131 void *arg;
132 {
133
134 if ((ipl < 1) || (ipl > 7)) {
135 printf("hb: illegal interrupt level: %d\n", ipl);
136 panic("hb_intr_establish");
137 }
138
139 if ((hbvect < 0) || (hbvect > 255)) {
140 printf("hb: illegal vector offset: 0x%x\n", hbvect);
141 panic("hb_intr_establish");
142 }
143
144 isrlink_vectored(hand, arg, ipl, hbvect);
145 }
146
147 void
148 hb_intr_disestablish(hbvect)
149 int hbvect;
150 {
151
152 if ((hbvect < 0) || (hbvect > 255)) {
153 printf("hb: illegal vector offset: 0x%x\n", hbvect);
154 panic("hb_intr_disestablish");
155 }
156
157 isrunlink_vectored(hbvect);
158 }
159