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