xref: /netbsd-src/sys/arch/hp300/dev/hil_intio.c (revision 594f789a5c7bef0390e4223293d2f6fcada88e9b)
1*594f789aSthorpej /*	$NetBSD: hil_intio.c,v 1.5 2024/01/16 05:48:28 thorpej Exp $	*/
2b04b7da8Stsutsui /*	$OpenBSD: hil_intio.c,v 1.8 2007/01/06 20:10:57 miod Exp $	*/
3b04b7da8Stsutsui 
4b04b7da8Stsutsui /*
5b04b7da8Stsutsui  * Copyright (c) 2005, Miodrag Vallat.
6b04b7da8Stsutsui  * All rights reserved.
7b04b7da8Stsutsui  *
8b04b7da8Stsutsui  * Redistribution and use in source and binary forms, with or without
9b04b7da8Stsutsui  * modification, are permitted provided that the following conditions
10b04b7da8Stsutsui  * are met:
11b04b7da8Stsutsui  * 1. Redistributions of source code must retain the above copyright
12b04b7da8Stsutsui  *    notice, this list of conditions and the following disclaimer.
13b04b7da8Stsutsui  * 2. Redistributions in binary form must reproduce the above copyright
14b04b7da8Stsutsui  *    notice, this list of conditions and the following disclaimer in the
15b04b7da8Stsutsui  *    documentation and/or other materials provided with the distribution.
16b04b7da8Stsutsui  *
17b04b7da8Stsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18b04b7da8Stsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19b04b7da8Stsutsui  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20b04b7da8Stsutsui  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21b04b7da8Stsutsui  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22b04b7da8Stsutsui  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23b04b7da8Stsutsui  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24b04b7da8Stsutsui  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25b04b7da8Stsutsui  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26b04b7da8Stsutsui  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27b04b7da8Stsutsui  * POSSIBILITY OF SUCH DAMAGE.
28b04b7da8Stsutsui  *
29b04b7da8Stsutsui  */
30b04b7da8Stsutsui 
31806e09adStsutsui #include "wsdisplay.h"
32806e09adStsutsui 
33b04b7da8Stsutsui #include <sys/param.h>
34b04b7da8Stsutsui #include <sys/systm.h>
35b04b7da8Stsutsui #include <sys/device.h>
36b04b7da8Stsutsui #include <sys/conf.h>
37b04b7da8Stsutsui #include <sys/bus.h>
38b04b7da8Stsutsui #include <sys/cpu.h>
39b04b7da8Stsutsui 
40b04b7da8Stsutsui #include <machine/intr.h>
41b04b7da8Stsutsui 
42b04b7da8Stsutsui #include <dev/cons.h>
43806e09adStsutsui #if NWSDISPLAY > 0
44806e09adStsutsui #include <dev/wscons/wsdisplayvar.h>
45806e09adStsutsui #endif
46b04b7da8Stsutsui 
47b04b7da8Stsutsui #include <hp300/dev/intiovar.h>
48b04b7da8Stsutsui 
49b04b7da8Stsutsui #include <machine/hil_machdep.h>
50b04b7da8Stsutsui #include <dev/hil/hilvar.h>
51b04b7da8Stsutsui 
525248c692Stsutsui static int	hil_intio_match(device_t, cfdata_t, void *);
535248c692Stsutsui static void	hil_intio_attach(device_t, device_t, void *);
54b04b7da8Stsutsui 
55b04b7da8Stsutsui CFATTACH_DECL_NEW(hil_intio, sizeof(struct hil_softc),
56b04b7da8Stsutsui     hil_intio_match, hil_intio_attach, NULL, NULL);
57b04b7da8Stsutsui 
58b04b7da8Stsutsui int
hil_intio_match(device_t parent,cfdata_t cf,void * aux)59b04b7da8Stsutsui hil_intio_match(device_t parent, cfdata_t cf, void *aux)
60b04b7da8Stsutsui {
61b04b7da8Stsutsui 	struct intio_attach_args *ia = aux;
62b04b7da8Stsutsui 	static int hil_matched = 0;
63b04b7da8Stsutsui 
64b04b7da8Stsutsui 	if (strcmp("hil", ia->ia_modname) != 0)
65b04b7da8Stsutsui 		return 0;
66b04b7da8Stsutsui 
67b04b7da8Stsutsui 	/* Allow only one instance. */
68b04b7da8Stsutsui 	if (hil_matched != 0)
695248c692Stsutsui 		return 0;
70b04b7da8Stsutsui 
71b04b7da8Stsutsui 	if (badaddr((void *)ia->ia_addr))	/* should not happen! */
725248c692Stsutsui 		return 0;
73b04b7da8Stsutsui 
745248c692Stsutsui 	return 1;
75b04b7da8Stsutsui }
76b04b7da8Stsutsui 
77b04b7da8Stsutsui int hil_is_console = -1;	/* undecided */
78b04b7da8Stsutsui 
79b04b7da8Stsutsui void
hil_intio_attach(device_t parent,device_t self,void * aux)80b04b7da8Stsutsui hil_intio_attach(device_t parent, device_t self, void *aux)
81b04b7da8Stsutsui {
82b04b7da8Stsutsui 	struct hil_softc *sc = device_private(self);
83b04b7da8Stsutsui 	struct intio_attach_args *ia = aux;
84b04b7da8Stsutsui 
85b04b7da8Stsutsui 	sc->sc_dev = self;
86b04b7da8Stsutsui 	sc->sc_bst = ia->ia_bst;
87b04b7da8Stsutsui 	if (bus_space_map(sc->sc_bst, ia->ia_iobase,
88b04b7da8Stsutsui 	    HILMAPSIZE, 0, &sc->sc_bsh) != 0) {
895248c692Stsutsui 		aprint_error(": couldn't map hil controller\n");
90b04b7da8Stsutsui 		return;
91b04b7da8Stsutsui 	}
92b04b7da8Stsutsui 
93b04b7da8Stsutsui 	/*
94b04b7da8Stsutsui 	 * Check that the configured console device is a wsdisplay.
95b04b7da8Stsutsui 	 */
96806e09adStsutsui #if NWSDISPLAY > 0
97806e09adStsutsui 	if (cn_tab->cn_putc != wsdisplay_cnputc)
98806e09adStsutsui #endif
99806e09adStsutsui 	{
100a7b6e616Stsutsui 		hil_is_console = 0;
101806e09adStsutsui 	}
102b04b7da8Stsutsui 
103b04b7da8Stsutsui 	hil_attach(sc, &hil_is_console);
104*594f789aSthorpej 	intr_establish(hil_intr, sc, ia->ia_ipl, ISRPRI_TTY);
105b04b7da8Stsutsui 
106b04b7da8Stsutsui 	config_interrupts(self, hil_attach_deferred);
107b04b7da8Stsutsui }
108