xref: /openbsd/sys/arch/hppa/gsc/hil_gsc.c (revision 78d5ff0e)
1*78d5ff0eSmpi /*	$OpenBSD: hil_gsc.c,v 1.6 2022/03/13 08:04:38 mpi Exp $	*/
2e03ba6a3Smiod /*
3e03ba6a3Smiod  * Copyright (c) 2003, Miodrag Vallat.
4e03ba6a3Smiod  * All rights reserved.
5e03ba6a3Smiod  *
6e03ba6a3Smiod  * Redistribution and use in source and binary forms, with or without
7e03ba6a3Smiod  * modification, are permitted provided that the following conditions
8e03ba6a3Smiod  * are met:
9e03ba6a3Smiod  * 1. Redistributions of source code must retain the above copyright
10e03ba6a3Smiod  *    notice, this list of conditions and the following disclaimer.
11e03ba6a3Smiod  * 2. Redistributions in binary form must reproduce the above copyright
12e03ba6a3Smiod  *    notice, this list of conditions and the following disclaimer in the
13e03ba6a3Smiod  *    documentation and/or other materials provided with the distribution.
14e03ba6a3Smiod  *
15e03ba6a3Smiod  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16e03ba6a3Smiod  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17e03ba6a3Smiod  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18e03ba6a3Smiod  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19e03ba6a3Smiod  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20e03ba6a3Smiod  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21e03ba6a3Smiod  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22e03ba6a3Smiod  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23e03ba6a3Smiod  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24e03ba6a3Smiod  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25e03ba6a3Smiod  * POSSIBILITY OF SUCH DAMAGE.
26e03ba6a3Smiod  *
27e03ba6a3Smiod  */
28e03ba6a3Smiod 
29e03ba6a3Smiod #include <sys/param.h>
30e03ba6a3Smiod #include <sys/systm.h>
31e03ba6a3Smiod #include <sys/device.h>
32e03ba6a3Smiod 
33e03ba6a3Smiod #include <machine/cpu.h>
34e03ba6a3Smiod #include <machine/intr.h>
35e03ba6a3Smiod #include <machine/iomod.h>
36e03ba6a3Smiod #include <machine/autoconf.h>
37e03ba6a3Smiod #include <machine/bus.h>
38e03ba6a3Smiod 
39e03ba6a3Smiod #include <hppa/dev/cpudevs.h>
40e03ba6a3Smiod #include <hppa/gsc/gscbusvar.h>
41e03ba6a3Smiod 
42e03ba6a3Smiod #include <machine/hil_machdep.h>
43e03ba6a3Smiod 
44e03ba6a3Smiod #include <dev/hil/hilvar.h>
45e03ba6a3Smiod 
46e03ba6a3Smiod int	hil_gsc_match(struct device *, void *, void *);
47e03ba6a3Smiod void	hil_gsc_attach(struct device *, struct device *, void *);
48e03ba6a3Smiod 
492be62f22Smiod struct hil_gsc_softc {
502be62f22Smiod 	struct hil_softc sc_hs;
512be62f22Smiod 	int		 sc_hil_console;
522be62f22Smiod };
532be62f22Smiod 
54*78d5ff0eSmpi const struct cfattach hil_gsc_ca = {
552be62f22Smiod 	sizeof(struct hil_gsc_softc), hil_gsc_match, hil_gsc_attach
56e03ba6a3Smiod };
57e03ba6a3Smiod 
58e03ba6a3Smiod int
hil_gsc_match(struct device * parent,void * match,void * aux)59e03ba6a3Smiod hil_gsc_match(struct device *parent, void *match, void *aux)
60e03ba6a3Smiod {
61e03ba6a3Smiod 	struct gsc_attach_args *ga = aux;
62e03ba6a3Smiod 
63e03ba6a3Smiod 	if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
64e03ba6a3Smiod 	    ga->ga_type.iodc_sv_model != HPPA_FIO_HIL)
65e03ba6a3Smiod 		return (0);
66e03ba6a3Smiod 
67e03ba6a3Smiod 	return (1);
68e03ba6a3Smiod }
69e03ba6a3Smiod 
70e03ba6a3Smiod void
hil_gsc_attach(struct device * parent,struct device * self,void * aux)71e03ba6a3Smiod hil_gsc_attach(struct device *parent, struct device *self, void *aux)
72e03ba6a3Smiod {
732be62f22Smiod 	struct hil_gsc_softc *gsc = (void *)self;
742be62f22Smiod 	struct hil_softc *sc = &gsc->sc_hs;
75e03ba6a3Smiod 	struct gsc_attach_args *ga = aux;
76e03ba6a3Smiod 
77e03ba6a3Smiod 	sc->sc_bst = ga->ga_iot;
78e03ba6a3Smiod 	if (bus_space_map(ga->ga_iot, ga->ga_hpa,
79e03ba6a3Smiod 	    HILMAPSIZE, 0, &sc->sc_bsh)) {
80e03ba6a3Smiod 		printf(": couldn't map hil controller\n");
81e03ba6a3Smiod 		return;
82e03ba6a3Smiod 	}
83e03ba6a3Smiod 
842be62f22Smiod 	gsc->sc_hil_console = ga->ga_dp.dp_mod == PAGE0->mem_kbd.pz_dp.dp_mod &&
85f307151fSmiod 	    bcmp(ga->ga_dp.dp_bc, PAGE0->mem_kbd.pz_dp.dp_bc, 6) == 0;
86f307151fSmiod 
872be62f22Smiod 	hil_attach(sc, &gsc->sc_hil_console);
88e03ba6a3Smiod 
897c4844bbSmickey 	gsc_intr_establish((struct gsc_softc *)parent, ga->ga_irq, IPL_TTY,
907c4844bbSmickey 	    hil_intr, sc, sc->sc_dev.dv_xname);
91e03ba6a3Smiod 
92e03ba6a3Smiod 	startuphook_establish(hil_attach_deferred, sc);
93e03ba6a3Smiod }
94