sti_sgc.c revision 1.7 1 1.7 andvar /* $NetBSD: sti_sgc.c,v 1.7 2022/07/03 11:30:48 andvar Exp $ */
2 1.1 tsutsui /* $OpenBSD: sti_sgc.c,v 1.14 2007/05/26 00:36:03 krw Exp $ */
3 1.1 tsutsui
4 1.1 tsutsui /*
5 1.1 tsutsui * Copyright (c) 2005, Miodrag Vallat
6 1.1 tsutsui *
7 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
8 1.1 tsutsui * modification, are permitted provided that the following conditions
9 1.1 tsutsui * are met:
10 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
11 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
12 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
14 1.1 tsutsui * documentation and/or other materials provided with the distribution.
15 1.1 tsutsui *
16 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 tsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.1 tsutsui * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 1.1 tsutsui * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 1.1 tsutsui * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.1 tsutsui * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.1 tsutsui * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 1.1 tsutsui * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 1.1 tsutsui * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 tsutsui * POSSIBILITY OF SUCH DAMAGE.
27 1.1 tsutsui *
28 1.1 tsutsui */
29 1.1 tsutsui #include <sys/cdefs.h>
30 1.7 andvar __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.7 2022/07/03 11:30:48 andvar Exp $");
31 1.1 tsutsui
32 1.1 tsutsui #include <sys/param.h>
33 1.1 tsutsui #include <sys/device.h>
34 1.1 tsutsui #include <sys/bus.h>
35 1.1 tsutsui
36 1.1 tsutsui #include <uvm/uvm_extern.h>
37 1.1 tsutsui
38 1.3 tsutsui #include <dev/wscons/wsconsio.h>
39 1.1 tsutsui #include <dev/wscons/wsdisplayvar.h>
40 1.1 tsutsui
41 1.1 tsutsui #include <dev/ic/stireg.h>
42 1.1 tsutsui #include <dev/ic/stivar.h>
43 1.1 tsutsui
44 1.1 tsutsui #include <hp300/dev/sgcvar.h>
45 1.2 tsutsui #include <hp300/dev/sti_sgcvar.h>
46 1.2 tsutsui #include <machine/autoconf.h>
47 1.1 tsutsui
48 1.3 tsutsui struct sti_sgc_softc {
49 1.3 tsutsui struct sti_softc sc_sti;
50 1.3 tsutsui
51 1.3 tsutsui paddr_t sc_bitmap;
52 1.3 tsutsui };
53 1.3 tsutsui
54 1.3 tsutsui /*
55 1.3 tsutsui * 425e EVRX specific hardware
56 1.3 tsutsui */
57 1.4 tsutsui /*
58 1.4 tsutsui * EVRX RAMDAC (Bt458) is found at offset 0x060000 from SGC bus PA and
59 1.4 tsutsui * offset 0x040000 length 0x1c0000 is mapped in MI sti via ROM region 2
60 1.4 tsutsui */
61 1.4 tsutsui #define STI_EVRX_REGNO2OFFSET 0x020000
62 1.3 tsutsui #define STI_EVRX_FBOFFSET 0x200000
63 1.3 tsutsui
64 1.4 tsutsui #define EVRX_BT458_ADDR (STI_EVRX_REGNO2OFFSET + 0x200 + 2)
65 1.4 tsutsui #define EVRX_BT458_CMAP (STI_EVRX_REGNO2OFFSET + 0x204 + 2)
66 1.4 tsutsui #define EVRX_BT458_CTRL (STI_EVRX_REGNO2OFFSET + 0x208 + 2)
67 1.4 tsutsui #define EVRX_BT458_OMAP (STI_EVRX_REGNO2OFFSET + 0x20C + 2)
68 1.3 tsutsui
69 1.3 tsutsui /* from HP-UX /usr/lib/libddevrx.a */
70 1.4 tsutsui #define EVRX_MAGIC00 (STI_EVRX_REGNO2OFFSET + 0x600)
71 1.4 tsutsui #define EVRX_MAGIC04 (STI_EVRX_REGNO2OFFSET + 0x604)
72 1.4 tsutsui #define EVRX_MAGIC08 (STI_EVRX_REGNO2OFFSET + 0x608)
73 1.4 tsutsui #define EVRX_MAGIC0C (STI_EVRX_REGNO2OFFSET + 0x60c)
74 1.4 tsutsui #define EVRX_MAGIC10 (STI_EVRX_REGNO2OFFSET + 0x610)
75 1.3 tsutsui #define EVRX_MAGIC10_BSY 0x00010000
76 1.4 tsutsui #define EVRX_MAGIC18 (STI_EVRX_REGNO2OFFSET + 0x618)
77 1.4 tsutsui #define EVRX_MAGIC1C (STI_EVRX_REGNO2OFFSET + 0x61c)
78 1.4 tsutsui
79 1.4 tsutsui /*
80 1.4 tsutsui * HP A1659A CRX specific hardware
81 1.4 tsutsui */
82 1.4 tsutsui #define STI_CRX_FBOFFSET 0x01000000
83 1.3 tsutsui
84 1.2 tsutsui static int sticonslot = -1;
85 1.4 tsutsui static struct bus_space_tag sticn_tag;
86 1.2 tsutsui static struct sti_rom sticn_rom;
87 1.2 tsutsui static struct sti_screen sticn_scr;
88 1.2 tsutsui static bus_addr_t sticn_bases[STI_REGION_MAX];
89 1.1 tsutsui
90 1.1 tsutsui static int sti_sgc_match(device_t, struct cfdata *, void *);
91 1.1 tsutsui static void sti_sgc_attach(device_t, device_t, void *);
92 1.1 tsutsui
93 1.1 tsutsui static int sti_sgc_probe(bus_space_tag_t, int);
94 1.1 tsutsui
95 1.3 tsutsui CFATTACH_DECL_NEW(sti_sgc, sizeof(struct sti_sgc_softc),
96 1.1 tsutsui sti_sgc_match, sti_sgc_attach, NULL, NULL);
97 1.1 tsutsui
98 1.4 tsutsui /* 425e EVRX/CRX specific access functions */
99 1.4 tsutsui static int sti_evrx_putcmap(struct sti_screen *, u_int, u_int);
100 1.4 tsutsui static void sti_evrx_resetramdac(struct sti_screen *);
101 1.4 tsutsui static void sti_evrx_resetcmap(struct sti_screen *);
102 1.4 tsutsui static void sti_evrx_setupfb(struct sti_screen *);
103 1.4 tsutsui static paddr_t sti_m68k_mmap(void *, void *, off_t, int);
104 1.4 tsutsui
105 1.4 tsutsui static const struct wsdisplay_accessops sti_m68k_accessops = {
106 1.4 tsutsui sti_ioctl,
107 1.4 tsutsui sti_m68k_mmap,
108 1.3 tsutsui sti_alloc_screen,
109 1.3 tsutsui sti_free_screen,
110 1.3 tsutsui sti_show_screen,
111 1.3 tsutsui sti_load_font
112 1.3 tsutsui };
113 1.3 tsutsui
114 1.1 tsutsui static int
115 1.1 tsutsui sti_sgc_match(device_t parent, struct cfdata *cf, void *aux)
116 1.1 tsutsui {
117 1.1 tsutsui struct sgc_attach_args *saa = aux;
118 1.1 tsutsui
119 1.1 tsutsui /*
120 1.1 tsutsui * If we already probed it successfully as a console device, go ahead,
121 1.1 tsutsui * since we will not be able to bus_space_map() again.
122 1.1 tsutsui */
123 1.1 tsutsui if (saa->saa_slot == sticonslot)
124 1.1 tsutsui return 1;
125 1.1 tsutsui
126 1.1 tsutsui return sti_sgc_probe(saa->saa_iot, saa->saa_slot);
127 1.1 tsutsui }
128 1.1 tsutsui
129 1.1 tsutsui static void
130 1.1 tsutsui sti_sgc_attach(device_t parent, device_t self, void *aux)
131 1.1 tsutsui {
132 1.3 tsutsui struct sti_sgc_softc *sc = device_private(self);
133 1.3 tsutsui struct sti_softc *ssc = &sc->sc_sti;
134 1.1 tsutsui struct sgc_attach_args *saa = aux;
135 1.3 tsutsui struct sti_screen *scr;
136 1.4 tsutsui bus_space_tag_t bst;
137 1.2 tsutsui bus_space_handle_t romh;
138 1.2 tsutsui bus_addr_t base;
139 1.3 tsutsui struct wsemuldisplaydev_attach_args waa;
140 1.1 tsutsui u_int romend;
141 1.3 tsutsui struct sti_dd *rom_dd;
142 1.3 tsutsui uint32_t grid0;
143 1.1 tsutsui int i;
144 1.1 tsutsui
145 1.3 tsutsui ssc->sc_dev = self;
146 1.4 tsutsui bst = saa->saa_iot;
147 1.3 tsutsui base = (bus_addr_t)sgc_slottopa(saa->saa_slot);
148 1.2 tsutsui
149 1.2 tsutsui if (saa->saa_slot == sticonslot) {
150 1.3 tsutsui ssc->sc_flags |= STI_CONSOLE | STI_ATTACHED;
151 1.3 tsutsui ssc->sc_rom = &sticn_rom;
152 1.3 tsutsui ssc->sc_rom->rom_softc = ssc;
153 1.3 tsutsui ssc->sc_scr = &sticn_scr;
154 1.3 tsutsui ssc->sc_scr->scr_rom = ssc->sc_rom;
155 1.3 tsutsui memcpy(ssc->bases, sticn_bases, sizeof(ssc->bases));
156 1.2 tsutsui
157 1.3 tsutsui sti_describe(ssc);
158 1.2 tsutsui } else {
159 1.4 tsutsui if (bus_space_map(bst, base, PAGE_SIZE, 0, &romh)) {
160 1.2 tsutsui aprint_error(": can't map ROM");
161 1.2 tsutsui return;
162 1.2 tsutsui }
163 1.2 tsutsui /*
164 1.2 tsutsui * Compute real PROM size
165 1.2 tsutsui */
166 1.4 tsutsui romend = sti_rom_size(bst, romh);
167 1.2 tsutsui
168 1.4 tsutsui bus_space_unmap(bst, romh, PAGE_SIZE);
169 1.2 tsutsui
170 1.4 tsutsui if (bus_space_map(bst, base, romend, 0, &romh)) {
171 1.2 tsutsui aprint_error(": can't map frame buffer");
172 1.2 tsutsui return;
173 1.2 tsutsui }
174 1.2 tsutsui
175 1.3 tsutsui ssc->bases[0] = romh;
176 1.2 tsutsui for (i = 0; i < STI_REGION_MAX; i++)
177 1.3 tsutsui ssc->bases[i] = base;
178 1.2 tsutsui
179 1.4 tsutsui if (sti_attach_common(ssc, bst, bst, romh,
180 1.2 tsutsui STI_CODEBASE_ALT) != 0)
181 1.2 tsutsui return;
182 1.1 tsutsui }
183 1.1 tsutsui
184 1.3 tsutsui /* Identify the board model by dd_grid */
185 1.3 tsutsui rom_dd = &ssc->sc_rom->rom_dd;
186 1.3 tsutsui grid0 = rom_dd->dd_grid[0];
187 1.3 tsutsui scr = ssc->sc_scr;
188 1.3 tsutsui
189 1.3 tsutsui switch (grid0) {
190 1.3 tsutsui case STI_DD_EVRX:
191 1.3 tsutsui /*
192 1.3 tsutsui * 425e on-board EVRX framebuffer.
193 1.3 tsutsui * bitmap memory can be accessed at offset +0x200000.
194 1.3 tsutsui */
195 1.3 tsutsui sc->sc_bitmap = base + STI_EVRX_FBOFFSET;
196 1.3 tsutsui
197 1.3 tsutsui aprint_normal_dev(self, "Enable mmap support\n");
198 1.3 tsutsui
199 1.3 tsutsui /*
200 1.3 tsutsui * initialize Bt458 RAMDAC and preserve initial color map
201 1.3 tsutsui */
202 1.4 tsutsui sti_evrx_resetramdac(scr);
203 1.4 tsutsui sti_evrx_resetcmap(scr);
204 1.4 tsutsui
205 1.4 tsutsui scr->setupfb = sti_evrx_setupfb;
206 1.4 tsutsui scr->putcmap = sti_evrx_putcmap;
207 1.3 tsutsui
208 1.3 tsutsui scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
209 1.3 tsutsui waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
210 1.3 tsutsui waa.scrdata = &scr->scr_screenlist;
211 1.4 tsutsui waa.accessops = &sti_m68k_accessops;
212 1.3 tsutsui waa.accesscookie = scr;
213 1.3 tsutsui
214 1.5 thorpej config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint,
215 1.6 thorpej CFARGS_NONE);
216 1.3 tsutsui break;
217 1.1 tsutsui
218 1.3 tsutsui case STI_DD_CRX:
219 1.3 tsutsui /*
220 1.3 tsutsui * HP A1659A CRX on some 425t variants.
221 1.4 tsutsui * bitmap memory can be accessed at offset +0x1000000.
222 1.3 tsutsui */
223 1.4 tsutsui sc->sc_bitmap = base + STI_CRX_FBOFFSET;
224 1.4 tsutsui
225 1.4 tsutsui aprint_normal_dev(self, "Enable mmap support\n");
226 1.4 tsutsui
227 1.4 tsutsui scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
228 1.4 tsutsui waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
229 1.4 tsutsui waa.scrdata = &scr->scr_screenlist;
230 1.4 tsutsui waa.accessops = &sti_m68k_accessops;
231 1.4 tsutsui waa.accesscookie = scr;
232 1.4 tsutsui
233 1.5 thorpej config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint,
234 1.6 thorpej CFARGS_NONE);
235 1.4 tsutsui break;
236 1.3 tsutsui default:
237 1.3 tsutsui /*
238 1.3 tsutsui * Unsupported variants.
239 1.3 tsutsui * Use default common sti(4) attachment (no bitmap support).
240 1.3 tsutsui */
241 1.3 tsutsui sti_end_attach(ssc);
242 1.3 tsutsui break;
243 1.3 tsutsui }
244 1.1 tsutsui }
245 1.1 tsutsui
246 1.1 tsutsui static int
247 1.1 tsutsui sti_sgc_probe(bus_space_tag_t iot, int slot)
248 1.1 tsutsui {
249 1.1 tsutsui bus_space_handle_t ioh;
250 1.1 tsutsui int devtype;
251 1.1 tsutsui
252 1.2 tsutsui if (bus_space_map(iot, (bus_addr_t)sgc_slottopa(slot),
253 1.2 tsutsui PAGE_SIZE, 0, &ioh))
254 1.1 tsutsui return 0;
255 1.2 tsutsui
256 1.1 tsutsui devtype = bus_space_read_1(iot, ioh, 3);
257 1.2 tsutsui
258 1.1 tsutsui bus_space_unmap(iot, ioh, PAGE_SIZE);
259 1.1 tsutsui
260 1.1 tsutsui /*
261 1.1 tsutsui * This might not be reliable enough. On the other hand, non-STI
262 1.7 andvar * SGC cards will apparently not initialize in the hp300, to the
263 1.1 tsutsui * point of not even answering bus probes (checked with an
264 1.1 tsutsui * Harmony/FDDI SGC card).
265 1.1 tsutsui */
266 1.2 tsutsui if (devtype != STI_DEVTYPE1 && devtype != STI_DEVTYPE4)
267 1.1 tsutsui return 0;
268 1.2 tsutsui
269 1.1 tsutsui return 1;
270 1.1 tsutsui }
271 1.1 tsutsui
272 1.3 tsutsui static int
273 1.4 tsutsui sti_evrx_putcmap(struct sti_screen *scr, u_int index, u_int count)
274 1.3 tsutsui {
275 1.4 tsutsui struct sti_rom *rom = scr->scr_rom;
276 1.4 tsutsui bus_space_tag_t bst = rom->memt;
277 1.4 tsutsui bus_space_handle_t bsh = rom->regh[2];
278 1.4 tsutsui int i;
279 1.3 tsutsui
280 1.3 tsutsui /* magic setup from HP-UX */
281 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
282 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
283 1.3 tsutsui for (i = index; i < index + count; i++) {
284 1.3 tsutsui /* this is what HP-UX woodDownloadCmap() does */
285 1.3 tsutsui while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
286 1.3 tsutsui EVRX_MAGIC10_BSY) != 0)
287 1.3 tsutsui continue;
288 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
289 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_rcmap[i]);
290 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_gcmap[i]);
291 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC10, scr->scr_bcmap[i]);
292 1.3 tsutsui }
293 1.3 tsutsui return 0;
294 1.3 tsutsui }
295 1.3 tsutsui
296 1.3 tsutsui static void
297 1.4 tsutsui sti_evrx_resetramdac(struct sti_screen *scr)
298 1.3 tsutsui {
299 1.4 tsutsui struct sti_rom *rom = scr->scr_rom;
300 1.4 tsutsui bus_space_tag_t bst = rom->memt;
301 1.4 tsutsui bus_space_handle_t bsh = rom->regh[2];
302 1.3 tsutsui #if 0
303 1.3 tsutsui int i;
304 1.3 tsutsui #endif
305 1.3 tsutsui
306 1.3 tsutsui /*
307 1.3 tsutsui * Initialize the Bt458. When we write to control registers,
308 1.3 tsutsui * the address is not incremented automatically. So we specify
309 1.3 tsutsui * it ourselves for each control register.
310 1.3 tsutsui */
311 1.3 tsutsui
312 1.3 tsutsui /* all planes will be read */
313 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x04);
314 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0xff);
315 1.3 tsutsui
316 1.3 tsutsui /* all planes have non-blink */
317 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x05);
318 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
319 1.3 tsutsui
320 1.7 andvar /* palette enabled, ovly plane disabled */
321 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x06);
322 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x40);
323 1.3 tsutsui
324 1.3 tsutsui /* no test mode */
325 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x07);
326 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
327 1.3 tsutsui
328 1.3 tsutsui /* magic initialization from HP-UX woodInitializeHardware() */
329 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
330 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC04, 0x00000001);
331 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
332 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC0C, 0x00000001);
333 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC18, 0xFFFFFFFF);
334 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC1C, 0x00000000);
335 1.3 tsutsui
336 1.3 tsutsui #if 0
337 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x00);
338 1.3 tsutsui for (i = 0; i < 4; i++) {
339 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
340 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
341 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
342 1.3 tsutsui }
343 1.3 tsutsui #endif
344 1.3 tsutsui }
345 1.3 tsutsui
346 1.3 tsutsui static void
347 1.4 tsutsui sti_evrx_resetcmap(struct sti_screen *scr)
348 1.3 tsutsui {
349 1.4 tsutsui struct sti_rom *rom = scr->scr_rom;
350 1.4 tsutsui bus_space_tag_t bst = rom->memt;
351 1.4 tsutsui bus_space_handle_t bsh = rom->regh[2];
352 1.3 tsutsui int i;
353 1.3 tsutsui
354 1.3 tsutsui /* magic setup from HP-UX */
355 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
356 1.3 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
357 1.3 tsutsui
358 1.3 tsutsui /* preserve palette values initialized by STI firmware */
359 1.3 tsutsui for (i = 0; i < STI_NCMAP; i++) {
360 1.3 tsutsui /* this is what HP-UX woodUploadCmap() does */
361 1.3 tsutsui while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
362 1.3 tsutsui EVRX_MAGIC10_BSY) != 0)
363 1.3 tsutsui continue;
364 1.3 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
365 1.3 tsutsui scr->scr_rcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
366 1.3 tsutsui scr->scr_gcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
367 1.3 tsutsui scr->scr_bcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
368 1.3 tsutsui }
369 1.3 tsutsui }
370 1.3 tsutsui
371 1.4 tsutsui static void
372 1.4 tsutsui sti_evrx_setupfb(struct sti_screen *scr)
373 1.3 tsutsui {
374 1.3 tsutsui
375 1.4 tsutsui sti_init(scr, 0);
376 1.4 tsutsui sti_evrx_resetramdac(scr);
377 1.3 tsutsui }
378 1.3 tsutsui
379 1.3 tsutsui static paddr_t
380 1.4 tsutsui sti_m68k_mmap(void *v, void *vs, off_t offset, int prot)
381 1.3 tsutsui {
382 1.3 tsutsui struct sti_screen *scr = (struct sti_screen *)v;
383 1.3 tsutsui struct sti_rom *rom = scr->scr_rom;
384 1.3 tsutsui struct sti_softc *ssc = rom->rom_softc;
385 1.3 tsutsui struct sti_sgc_softc *sc = device_private(ssc->sc_dev);
386 1.3 tsutsui paddr_t cookie = -1;
387 1.3 tsutsui
388 1.3 tsutsui if ((offset & PAGE_MASK) != 0)
389 1.3 tsutsui return -1;
390 1.3 tsutsui
391 1.3 tsutsui switch (scr->scr_wsmode) {
392 1.3 tsutsui case WSDISPLAYIO_MODE_MAPPED:
393 1.3 tsutsui /* not implemented yet; what should be shown? */
394 1.3 tsutsui break;
395 1.3 tsutsui case WSDISPLAYIO_MODE_DUMBFB:
396 1.3 tsutsui if (offset >= 0 && offset < (scr->fbwidth * scr->fbheight))
397 1.3 tsutsui cookie = m68k_btop(sc->sc_bitmap + offset);
398 1.3 tsutsui break;
399 1.3 tsutsui default:
400 1.3 tsutsui break;
401 1.3 tsutsui }
402 1.3 tsutsui
403 1.3 tsutsui return cookie;
404 1.3 tsutsui }
405 1.3 tsutsui
406 1.2 tsutsui int
407 1.2 tsutsui sti_sgc_cnprobe(bus_space_tag_t bst, bus_addr_t addr, int slot)
408 1.2 tsutsui {
409 1.2 tsutsui void *va;
410 1.2 tsutsui bus_space_handle_t romh;
411 1.2 tsutsui int devtype, rv = 0;
412 1.2 tsutsui
413 1.2 tsutsui if (bus_space_map(bst, addr, PAGE_SIZE, 0, &romh))
414 1.2 tsutsui return 0;
415 1.2 tsutsui
416 1.2 tsutsui va = bus_space_vaddr(bst, romh);
417 1.2 tsutsui if (badaddr(va))
418 1.2 tsutsui goto out;
419 1.2 tsutsui
420 1.2 tsutsui devtype = bus_space_read_1(bst, romh, 3);
421 1.2 tsutsui if (devtype == STI_DEVTYPE1 || devtype == STI_DEVTYPE4)
422 1.2 tsutsui rv = 1;
423 1.2 tsutsui
424 1.2 tsutsui out:
425 1.2 tsutsui bus_space_unmap(bst, romh, PAGE_SIZE);
426 1.2 tsutsui return rv;
427 1.2 tsutsui }
428 1.2 tsutsui
429 1.2 tsutsui void
430 1.2 tsutsui sti_sgc_cnattach(bus_space_tag_t bst, bus_addr_t addr, int slot)
431 1.1 tsutsui {
432 1.2 tsutsui int i;
433 1.2 tsutsui
434 1.4 tsutsui sticn_tag = *bst;
435 1.4 tsutsui
436 1.2 tsutsui /* sticn_bases[0] will be fixed in sti_cnattach() */
437 1.2 tsutsui for (i = 0; i < STI_REGION_MAX; i++)
438 1.2 tsutsui sticn_bases[i] = addr;
439 1.2 tsutsui
440 1.4 tsutsui sti_cnattach(&sticn_rom, &sticn_scr, &sticn_tag, sticn_bases,
441 1.2 tsutsui STI_CODEBASE_ALT);
442 1.1 tsutsui
443 1.2 tsutsui sticonslot = slot;
444 1.1 tsutsui }
445