1*c7fb772bSthorpej /* $NetBSD: hb.c,v 1.21 2021/08/07 16:19:00 thorpej Exp $ */
2a1099430Stsutsui
3a1099430Stsutsui /*-
4b87210faStsutsui * Copyright (c) 1999 Izumi Tsutsui. All rights reserved.
5a1099430Stsutsui *
6a1099430Stsutsui * Redistribution and use in source and binary forms, with or without
7a1099430Stsutsui * modification, are permitted provided that the following conditions
8a1099430Stsutsui * are met:
9a1099430Stsutsui * 1. Redistributions of source code must retain the above copyright
10a1099430Stsutsui * notice, this list of conditions and the following disclaimer.
11a1099430Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
12a1099430Stsutsui * notice, this list of conditions and the following disclaimer in the
13a1099430Stsutsui * documentation and/or other materials provided with the distribution.
14a1099430Stsutsui *
15a1099430Stsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16a1099430Stsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17a1099430Stsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18a1099430Stsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19a1099430Stsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20a1099430Stsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21a1099430Stsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22a1099430Stsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23b87210faStsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24b87210faStsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25a1099430Stsutsui */
26a1099430Stsutsui
27ed517291Slukem #include <sys/cdefs.h>
28*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: hb.c,v 1.21 2021/08/07 16:19:00 thorpej Exp $");
29ed517291Slukem
30a1099430Stsutsui #include <sys/param.h>
31a1099430Stsutsui #include <sys/systm.h>
32a1099430Stsutsui #include <sys/device.h>
33a1099430Stsutsui
34a1099430Stsutsui #include <machine/autoconf.h>
353f123214Stsutsui #include <machine/bus.h>
366968a454Stsutsui #include <machine/cpu.h>
37a1099430Stsutsui
38a1099430Stsutsui #include <news68k/news68k/isr.h>
39a1099430Stsutsui #include <news68k/dev/hbvar.h>
40a1099430Stsutsui
41378871cdStsutsui #include "ioconf.h"
42378871cdStsutsui
43820a544dStsutsui static int hb_match(device_t, cfdata_t, void *);
44820a544dStsutsui static void hb_attach(device_t, device_t, void *);
45820a544dStsutsui static int hb_search(device_t, cfdata_t, const int *, void *);
460687b33bStsutsui static int hb_print(void *, const char *);
47a1099430Stsutsui
48820a544dStsutsui CFATTACH_DECL_NEW(hb, 0,
49021b694dSthorpej hb_match, hb_attach, NULL, NULL);
50a1099430Stsutsui
51a1099430Stsutsui static int
hb_match(device_t parent,cfdata_t cf,void * aux)52820a544dStsutsui hb_match(device_t parent, cfdata_t cf, void *aux)
53a1099430Stsutsui {
546968a454Stsutsui struct mainbus_attach_args *ma = aux;
55a1099430Stsutsui
566968a454Stsutsui if (strcmp(ma->ma_name, hb_cd.cd_name) != 0)
576968a454Stsutsui return 0;
586968a454Stsutsui
596968a454Stsutsui if (ma->ma_systype != -1 && ma->ma_systype != systype)
60a1099430Stsutsui return 0;
61a1099430Stsutsui
62a1099430Stsutsui return 1;
63a1099430Stsutsui }
64a1099430Stsutsui
65a1099430Stsutsui static void
hb_attach(device_t parent,device_t self,void * aux)66820a544dStsutsui hb_attach(device_t parent, device_t self, void *aux)
67a1099430Stsutsui {
68a1099430Stsutsui struct hb_attach_args ha;
69a1099430Stsutsui
70820a544dStsutsui aprint_normal("\n");
71fe30b5a6Stsutsui memset(&ha, 0, sizeof(ha));
72a1099430Stsutsui
732685996bSthorpej config_search(self, &ha,
74*c7fb772bSthorpej CFARGS(.search = hb_search));
75a1099430Stsutsui }
76a1099430Stsutsui
77a1099430Stsutsui static int
hb_search(device_t parent,cfdata_t cf,const int * ldesc,void * aux)78820a544dStsutsui hb_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
79a1099430Stsutsui {
80a1099430Stsutsui struct hb_attach_args *ha = aux;
81a1099430Stsutsui
82d1ad2ac4Sthorpej ha->ha_name = cf->cf_name;
83a1099430Stsutsui ha->ha_address = cf->cf_addr;
84a1099430Stsutsui ha->ha_ipl = cf->cf_ipl;
85a1099430Stsutsui ha->ha_vect = cf->cf_vect;
86a1099430Stsutsui
873f123214Stsutsui /* XXX news68k Hyper-bus is not a real bus... */
883f123214Stsutsui ha->ha_bust = ISIIOPA(ha->ha_address) ?
893f123214Stsutsui NEWS68K_BUS_SPACE_INTIO : NEWS68K_BUS_SPACE_EIO;
903f123214Stsutsui
912685996bSthorpej if (config_probe(parent, cf, ha))
92*c7fb772bSthorpej config_attach(parent, cf, ha, hb_print, CFARGS_NONE);
93a1099430Stsutsui
94a1099430Stsutsui return 0;
95a1099430Stsutsui }
96a1099430Stsutsui
97a1099430Stsutsui /*
98a1099430Stsutsui * Print out the confargs. The (parent) name is non-NULL
99a1099430Stsutsui * when there was no match found by config_found().
100a1099430Stsutsui */
101a1099430Stsutsui static int
hb_print(void * args,const char * name)10252b46dcfStsutsui hb_print(void *args, const char *name)
103a1099430Stsutsui {
104a1099430Stsutsui struct hb_attach_args *ha = args;
105a1099430Stsutsui
106a1099430Stsutsui #if 0
107a1099430Stsutsui if (ha->ha_addr > 0)
108a1099430Stsutsui #endif
109dbb0f0ebSthorpej aprint_normal(" addr 0x%08lx", ha->ha_address);
110a1099430Stsutsui if (ha->ha_ipl > 0)
111dbb0f0ebSthorpej aprint_normal(" ipl %d", ha->ha_ipl);
112a1099430Stsutsui if (ha->ha_vect > 0) {
113dbb0f0ebSthorpej aprint_normal(" vect %d", ha->ha_vect);
114a1099430Stsutsui }
115a1099430Stsutsui
11652b46dcfStsutsui return QUIET;
117a1099430Stsutsui }
118a1099430Stsutsui
119a1099430Stsutsui /*
120a1099430Stsutsui * hb_intr_establish: establish hb interrupt
121a1099430Stsutsui */
122a1099430Stsutsui void
hb_intr_establish(int hbvect,int (* hand)(void *),int ipl,void * arg)12352b46dcfStsutsui hb_intr_establish(int hbvect, int (*hand)(void *), int ipl, void *arg)
124a1099430Stsutsui {
125a1099430Stsutsui
126a1099430Stsutsui if ((ipl < 1) || (ipl > 7)) {
127a1099430Stsutsui printf("hb: illegal interrupt level: %d\n", ipl);
128a1099430Stsutsui panic("hb_intr_establish");
129a1099430Stsutsui }
130a1099430Stsutsui
131a1099430Stsutsui if ((hbvect < 0) || (hbvect > 255)) {
132386f0ea7Stsutsui printf("hb: illegal vector offset: 0x%x\n", hbvect);
133386f0ea7Stsutsui panic("hb_intr_establish");
134a1099430Stsutsui }
135a1099430Stsutsui
136a1099430Stsutsui isrlink_vectored(hand, arg, ipl, hbvect);
137a1099430Stsutsui }
138a1099430Stsutsui
139a1099430Stsutsui void
hb_intr_disestablish(int hbvect)14052b46dcfStsutsui hb_intr_disestablish(int hbvect)
141a1099430Stsutsui {
142a1099430Stsutsui
143a1099430Stsutsui if ((hbvect < 0) || (hbvect > 255)) {
144a1099430Stsutsui printf("hb: illegal vector offset: 0x%x\n", hbvect);
145a1099430Stsutsui panic("hb_intr_disestablish");
146a1099430Stsutsui }
147a1099430Stsutsui
148a1099430Stsutsui isrunlink_vectored(hbvect);
149a1099430Stsutsui }
150