hb.c revision 1.1 1 /* $NetBSD: hb.c,v 1.1 1999/12/09 14:53:04 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
35 #include <news68k/news68k/isr.h>
36 #include <news68k/dev/hbvar.h>
37
38 static int hb_match __P((struct device *, struct cfdata *, void *));
39 static void hb_attach __P((struct device *, struct device *, void *));
40 static int hb_search __P((struct device *, struct cfdata *, void *));
41 static int hb_print __P((void *, const char *));
42
43 struct cfattach hb_ca = {
44 sizeof(struct device), hb_match, hb_attach
45 };
46
47 extern struct cfdriver hb_cd;
48
49 static int
50 hb_match(parent, cf, aux)
51 struct device *parent;
52 struct cfdata *cf;
53 void *aux;
54 {
55 char *ma_name = aux;
56
57 if (strcmp(ma_name, hb_cd.cd_name) != 0)
58 return 0;
59
60 return 1;
61 }
62
63 static void
64 hb_attach(parent, self, aux)
65 struct device *parent;
66 struct device *self;
67 void *aux;
68 {
69 struct hb_attach_args ha;
70
71 printf("\n");
72 bzero(&ha, sizeof(ha));
73
74 config_search(hb_search, self, &ha);
75 }
76
77 static int
78 hb_search(parent, cf, aux)
79 struct device *parent;
80 struct cfdata *cf;
81 void *aux;
82 {
83 struct hb_attach_args *ha = aux;
84
85 ha->ha_name = cf->cf_driver->cd_name;
86 ha->ha_address = cf->cf_addr;
87 ha->ha_ipl = cf->cf_ipl;
88 ha->ha_vect = cf->cf_vect;
89
90 if ((*cf->cf_attach->ca_match)(parent, cf, ha) > 0)
91 config_attach(parent, cf, ha, hb_print);
92
93 return 0;
94 }
95
96 /*
97 * Print out the confargs. The (parent) name is non-NULL
98 * when there was no match found by config_found().
99 */
100 static int
101 hb_print(args, name)
102 void *args;
103 const char *name;
104 {
105 struct hb_attach_args *ha = args;
106
107 #if 0
108 if (ha->ha_addr > 0)
109 #endif
110 printf (" addr 0x%08lx", ha->ha_address);
111 if (ha->ha_ipl > 0)
112 printf (" ipl %d", ha->ha_ipl);
113 if (ha->ha_vect > 0) {
114 printf (" vect %d", ha->ha_vect);
115 }
116
117 return (QUIET);
118 }
119
120 /*
121 * hb_intr_establish: establish hb interrupt
122 */
123 void
124 hb_intr_establish(hbvect, hand, ipl, arg)
125 int hbvect;
126 int (*hand) __P((void *)), ipl;
127 void *arg;
128 {
129
130 if ((ipl < 1) || (ipl > 7)) {
131 printf("hb: illegal interrupt level: %d\n", ipl);
132 panic("hb_intr_establish");
133 }
134
135 if ((hbvect < 0) || (hbvect > 255)) {
136 printf("pcc: illegal vector offset: 0x%x\n", hbvect);
137 panic("pccintr_establish");
138 }
139
140 isrlink_vectored(hand, arg, ipl, hbvect);
141 }
142
143 void
144 hb_intr_disestablish(hbvect)
145 int hbvect;
146 {
147
148 if ((hbvect < 0) || (hbvect > 255)) {
149 printf("hb: illegal vector offset: 0x%x\n", hbvect);
150 panic("hb_intr_disestablish");
151 }
152
153 isrunlink_vectored(hbvect);
154 }
155