xref: /netbsd-src/sys/arch/news68k/dev/hb.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: hb.c,v 1.19 2008/05/14 13:29:28 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  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __KERNEL_RCSID(0, "$NetBSD: hb.c,v 1.19 2008/05/14 13:29:28 tsutsui Exp $");
29 
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/device.h>
33 
34 #include <machine/autoconf.h>
35 #include <machine/bus.h>
36 #include <machine/cpu.h>
37 
38 #include <news68k/news68k/isr.h>
39 #include <news68k/dev/hbvar.h>
40 
41 #include "ioconf.h"
42 
43 static int  hb_match(device_t, cfdata_t, void *);
44 static void hb_attach(device_t, device_t, void *);
45 static int  hb_search(device_t, cfdata_t, const int *, void *);
46 static int  hb_print(void *, const char *);
47 
48 CFATTACH_DECL_NEW(hb, 0,
49     hb_match, hb_attach, NULL, NULL);
50 
51 static int
52 hb_match(device_t parent, cfdata_t cf, void *aux)
53 {
54 	struct mainbus_attach_args *ma = aux;
55 
56 	if (strcmp(ma->ma_name, hb_cd.cd_name) != 0)
57 		return 0;
58 
59 	if (ma->ma_systype != -1 && ma->ma_systype != systype)
60 		return 0;
61 
62 	return 1;
63 }
64 
65 static void
66 hb_attach(device_t parent, device_t self, void *aux)
67 {
68 	struct hb_attach_args ha;
69 
70 	aprint_normal("\n");
71 	memset(&ha, 0, sizeof(ha));
72 
73 	config_search_ia(hb_search, self, "hb", &ha);
74 }
75 
76 static int
77 hb_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
78 {
79 	struct hb_attach_args *ha = aux;
80 
81 	ha->ha_name = cf->cf_name;
82 	ha->ha_address = cf->cf_addr;
83 	ha->ha_ipl = cf->cf_ipl;
84 	ha->ha_vect = cf->cf_vect;
85 
86 	/* XXX news68k Hyper-bus is not a real bus... */
87 	ha->ha_bust = ISIIOPA(ha->ha_address) ?
88 	    NEWS68K_BUS_SPACE_INTIO : NEWS68K_BUS_SPACE_EIO;
89 
90 	if (config_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(void *args, const char *name)
102 {
103 	struct hb_attach_args *ha = args;
104 
105 #if 0
106 	if (ha->ha_addr > 0)
107 #endif
108 		aprint_normal(" addr 0x%08lx", ha->ha_address);
109 	if (ha->ha_ipl > 0)
110 		aprint_normal(" ipl %d", ha->ha_ipl);
111 	if (ha->ha_vect > 0) {
112 		aprint_normal(" vect %d", ha->ha_vect);
113 	}
114 
115 	return QUIET;
116 }
117 
118 /*
119  * hb_intr_establish: establish hb interrupt
120  */
121 void
122 hb_intr_establish(int hbvect, int (*hand)(void *), int ipl, void *arg)
123 {
124 
125 	if ((ipl < 1) || (ipl > 7)) {
126 		printf("hb: illegal interrupt level: %d\n", ipl);
127 		panic("hb_intr_establish");
128 	}
129 
130 	if ((hbvect < 0) || (hbvect > 255)) {
131 		printf("hb: illegal vector offset: 0x%x\n", hbvect);
132 		panic("hb_intr_establish");
133 	}
134 
135 	isrlink_vectored(hand, arg, ipl, hbvect);
136 }
137 
138 void
139 hb_intr_disestablish(int hbvect)
140 {
141 
142 	if ((hbvect < 0) || (hbvect > 255)) {
143 		printf("hb: illegal vector offset: 0x%x\n", hbvect);
144 		panic("hb_intr_disestablish");
145 	}
146 
147 	isrunlink_vectored(hbvect);
148 }
149