1 /* $NetBSD: hil_gsc.c,v 1.1 2014/02/24 07:23:43 skrll Exp $ */
2 /* $OpenBSD: hil_gsc.c,v 1.5 2005/12/22 07:09:52 miod Exp $ */
3 /*
4 * Copyright (c) 2003, Miodrag Vallat.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/device.h>
33 #include <sys/cpu.h>
34 #include <sys/bus.h>
35
36 #include <machine/intr.h>
37 #include <machine/iomod.h>
38 #include <machine/autoconf.h>
39
40 #include <hppa/dev/cpudevs.h>
41 #include <hppa/gsc/gscbusvar.h>
42 #include <hppa/hppa/machdep.h>
43
44 #include <machine/hil_machdep.h>
45
46 #include <dev/hil/hilvar.h>
47
48 static int hil_gsc_match(device_t, cfdata_t, void *);
49 static void hil_gsc_attach(device_t, device_t, void *);
50
51 struct hil_gsc_softc {
52 struct hil_softc sc_hs;
53 int sc_hil_console;
54 void *sc_ih;
55 };
56
57 CFATTACH_DECL_NEW(hil_gsc, sizeof(struct hil_gsc_softc),
58 hil_gsc_match, hil_gsc_attach, NULL, NULL);
59
60 int
hil_gsc_match(device_t parent,cfdata_t cf,void * aux)61 hil_gsc_match(device_t parent, cfdata_t cf, void *aux)
62 {
63 struct gsc_attach_args *ga = aux;
64
65 if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
66 ga->ga_type.iodc_sv_model != HPPA_FIO_HIL)
67 return 0;
68
69 return 1;
70 }
71
72 void
hil_gsc_attach(device_t parent,device_t self,void * aux)73 hil_gsc_attach(device_t parent, device_t self, void *aux)
74 {
75 struct hil_gsc_softc *gsc = device_private(self);
76 struct hil_softc *sc = &gsc->sc_hs;
77 struct gsc_attach_args *ga = aux;
78 int pagezero_cookie;
79
80 sc->sc_dev = self;
81 sc->sc_bst = ga->ga_iot;
82 if (bus_space_map(ga->ga_iot, ga->ga_hpa,
83 HILMAPSIZE, 0, &sc->sc_bsh)) {
84 aprint_error(": couldn't map hil controller\n");
85 return;
86 }
87
88 pagezero_cookie = hppa_pagezero_map();
89 gsc->sc_hil_console = ga->ga_dp.dp_mod == PAGE0->mem_kbd.pz_dp.dp_mod &&
90 memcmp(ga->ga_dp.dp_bc, PAGE0->mem_kbd.pz_dp.dp_bc, 6) == 0;
91 hppa_pagezero_unmap(pagezero_cookie);
92
93 hil_attach(sc, &gsc->sc_hil_console);
94
95 gsc->sc_ih = hppa_intr_establish(IPL_TTY, hil_intr, sc,
96 ga->ga_ir, ga->ga_irq);
97
98 config_interrupts(self, hil_attach_deferred);
99 }
100