sti_sgc.c revision 1.1 1 /* $NetBSD: sti_sgc.c,v 1.1 2013/01/11 12:03:03 tsutsui Exp $ */
2 /* $OpenBSD: sti_sgc.c,v 1.14 2007/05/26 00:36:03 krw Exp $ */
3
4 /*
5 * Copyright (c) 2005, Miodrag Vallat
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 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.1 2013/01/11 12:03:03 tsutsui Exp $");
31
32 #include <sys/param.h>
33 #include <sys/device.h>
34 #include <sys/bus.h>
35
36 #include <uvm/uvm_extern.h>
37
38 #include <dev/wscons/wsdisplayvar.h>
39
40 #include <dev/ic/stireg.h>
41 #include <dev/ic/stivar.h>
42
43 #include <hp300/dev/sgcvar.h>
44
45 static int sticonslot;
46
47 static int sti_sgc_match(device_t, struct cfdata *, void *);
48 static void sti_sgc_attach(device_t, device_t, void *);
49
50 static int sti_sgc_probe(bus_space_tag_t, int);
51 static void sti_sgc_end_attach(device_t);
52
53 CFATTACH_DECL_NEW(sti_sgc, sizeof(struct sti_softc),
54 sti_sgc_match, sti_sgc_attach, NULL, NULL);
55
56 static int
57 sti_sgc_match(device_t parent, struct cfdata *cf, void *aux)
58 {
59 struct sgc_attach_args *saa = aux;
60
61 /*
62 * If we already probed it successfully as a console device, go ahead,
63 * since we will not be able to bus_space_map() again.
64 */
65 if (saa->saa_slot == sticonslot)
66 return 1;
67
68 return sti_sgc_probe(saa->saa_iot, saa->saa_slot);
69 }
70
71 static void
72 sti_sgc_attach(device_t parent, device_t self, void *aux)
73 {
74 struct sti_softc *sc = device_private(self);
75 struct sgc_attach_args *saa = aux;
76 bus_space_tag_t iot = saa->saa_iot;
77 bus_space_handle_t ioh, romh;
78 bus_addr_t pa = (bus_addr_t)sgc_slottopa(saa->saa_slot);
79 u_int romend;
80 int i;
81
82 /* XXX: temporalily map before obtain romend. */
83 #define STI_ROMSIZE_SAFE (sizeof(struct sti_dd) * 4)
84 if (bus_space_map(iot, pa, STI_ROMSIZE_SAFE, 0, &ioh)) {
85 aprint_error(": can't map ROM");
86 return;
87 }
88 romend = sti_rom_size(iot, ioh);
89 bus_space_unmap(iot, ioh, STI_ROMSIZE_SAFE);
90
91 sc->sc_dev = self;
92 sc->sc_enable_rom = NULL;
93 sc->sc_disable_rom = NULL;
94
95 if (bus_space_map(iot, pa, romend, 0, &romh)) {
96 aprint_error(": can't map ROM(2)");
97 return;
98 }
99 sc->bases[0] = romh;
100 for (i = 0; i < STI_REGION_MAX; i++)
101 sc->bases[i] = pa;
102 if (saa->saa_slot == sticonslot)
103 sc->sc_flags |= STI_CONSOLE;
104 if (sti_attach_common(sc, iot, iot, romh, STI_CODEBASE_ALT) == 0)
105 config_interrupts(self, sti_sgc_end_attach);
106 }
107
108 static int
109 sti_sgc_probe(bus_space_tag_t iot, int slot)
110 {
111 bus_space_handle_t ioh;
112 bus_addr_t pa = (bus_addr_t)sgc_slottopa(slot);
113 int devtype;
114
115 if (bus_space_map(iot, pa, PAGE_SIZE, 0, &ioh))
116 return 0;
117 devtype = bus_space_read_1(iot, ioh, 3);
118 bus_space_unmap(iot, ioh, PAGE_SIZE);
119
120 /*
121 * This might not be reliable enough. On the other hand, non-STI
122 * SGC cards will apparently not initialize in an hp300, to the
123 * point of not even answering bus probes (checked with an
124 * Harmony/FDDI SGC card).
125 */
126 if (devtype != STI_DEVTYPE1 &&
127 devtype != STI_DEVTYPE4)
128 return 0;
129 return 1;
130 }
131
132 static void
133 sti_sgc_end_attach(device_t self)
134 {
135 struct sti_softc *sc = device_private(self);
136
137 sti_end_attach(sc);
138 }
139