hb.c revision 1.16 1 /* $NetBSD: hb.c,v 1.16 2005/08/26 13:19:36 drochner 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/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: hb.c,v 1.16 2005/08/26 13:19:36 drochner Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35
36 #include <machine/autoconf.h>
37 #include <machine/bus.h>
38 #include <machine/cpu.h>
39
40 #include <news68k/news68k/isr.h>
41 #include <news68k/dev/hbvar.h>
42
43 #include "ioconf.h"
44
45 static int hb_match(struct device *, struct cfdata *, void *);
46 static void hb_attach(struct device *, struct device *, void *);
47 static int hb_search(struct device *, struct cfdata *,
48 const int *, void *);
49 static int hb_print(void *, const char *);
50
51 CFATTACH_DECL(hb, sizeof(struct device),
52 hb_match, hb_attach, NULL, NULL);
53
54 static int
55 hb_match(struct device *parent, struct cfdata *cf, void *aux)
56 {
57 struct mainbus_attach_args *ma = aux;
58
59 if (strcmp(ma->ma_name, hb_cd.cd_name) != 0)
60 return 0;
61
62 if (ma->ma_systype != -1 && ma->ma_systype != systype)
63 return 0;
64
65 return 1;
66 }
67
68 static void
69 hb_attach(struct device *parent, struct device *self, void *aux)
70 {
71 struct hb_attach_args ha;
72
73 printf("\n");
74 memset(&ha, 0, sizeof(ha));
75
76 config_search_ia(hb_search, self, "hb", &ha);
77 }
78
79 static int
80 hb_search(struct device *parent, struct cfdata *cf,
81 const int *ldesc, void *aux)
82 {
83 struct hb_attach_args *ha = aux;
84
85 ha->ha_name = cf->cf_name;
86 ha->ha_address = cf->cf_addr;
87 ha->ha_ipl = cf->cf_ipl;
88 ha->ha_vect = cf->cf_vect;
89
90 /* XXX news68k Hyper-bus is not a real bus... */
91 ha->ha_bust = ISIIOPA(ha->ha_address) ?
92 NEWS68K_BUS_SPACE_INTIO : NEWS68K_BUS_SPACE_EIO;
93
94 if (config_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(void *args, const char *name)
106 {
107 struct hb_attach_args *ha = args;
108
109 #if 0
110 if (ha->ha_addr > 0)
111 #endif
112 aprint_normal (" addr 0x%08lx", ha->ha_address);
113 if (ha->ha_ipl > 0)
114 aprint_normal (" ipl %d", ha->ha_ipl);
115 if (ha->ha_vect > 0) {
116 aprint_normal (" vect %d", ha->ha_vect);
117 }
118
119 return QUIET;
120 }
121
122 /*
123 * hb_intr_establish: establish hb interrupt
124 */
125 void
126 hb_intr_establish(int hbvect, int (*hand)(void *), int ipl, void *arg)
127 {
128
129 if ((ipl < 1) || (ipl > 7)) {
130 printf("hb: illegal interrupt level: %d\n", ipl);
131 panic("hb_intr_establish");
132 }
133
134 if ((hbvect < 0) || (hbvect > 255)) {
135 printf("hb: illegal vector offset: 0x%x\n", hbvect);
136 panic("hb_intr_establish");
137 }
138
139 isrlink_vectored(hand, arg, ipl, hbvect);
140 }
141
142 void
143 hb_intr_disestablish(int hbvect)
144 {
145
146 if ((hbvect < 0) || (hbvect > 255)) {
147 printf("hb: illegal vector offset: 0x%x\n", hbvect);
148 panic("hb_intr_disestablish");
149 }
150
151 isrunlink_vectored(hbvect);
152 }
153