sti_machdep.c revision 1.3 1 1.3 tsutsui /* $NetBSD: sti_machdep.c,v 1.3 2025/05/19 17:34:03 tsutsui 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 /*-
30 1.1 tsutsui * Copyright (c) 2020, 2025 Izumi Tsutsui. All rights reserved.
31 1.1 tsutsui *
32 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
33 1.1 tsutsui * modification, are permitted provided that the following conditions
34 1.1 tsutsui * are met:
35 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
36 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
37 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
38 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
39 1.1 tsutsui * documentation and/or other materials provided with the distribution.
40 1.1 tsutsui *
41 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
42 1.1 tsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 1.1 tsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 1.1 tsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
45 1.1 tsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 1.1 tsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 1.1 tsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 1.1 tsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 1.1 tsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
50 1.1 tsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 1.1 tsutsui */
52 1.1 tsutsui
53 1.1 tsutsui #include <sys/cdefs.h>
54 1.3 tsutsui __KERNEL_RCSID(0, "$NetBSD: sti_machdep.c,v 1.3 2025/05/19 17:34:03 tsutsui Exp $");
55 1.1 tsutsui
56 1.1 tsutsui #include <sys/param.h>
57 1.1 tsutsui #include <sys/device.h>
58 1.1 tsutsui #include <sys/bus.h>
59 1.1 tsutsui
60 1.1 tsutsui #include <dev/wscons/wsconsio.h>
61 1.1 tsutsui
62 1.1 tsutsui #include <hp300/dev/sti_machdep.h>
63 1.1 tsutsui
64 1.1 tsutsui /*
65 1.1 tsutsui * 425e EVRX specific hardware
66 1.1 tsutsui */
67 1.1 tsutsui /*
68 1.1 tsutsui * EVRX RAMDAC (Bt458) is found at offset 0x060000 from SGC bus PA and
69 1.1 tsutsui * offset 0x040000 length 0x1c0000 is mapped in MI sti via ROM region 2
70 1.1 tsutsui */
71 1.1 tsutsui #define STI_EVRX_REGNO2OFFSET 0x020000
72 1.1 tsutsui #define STI_EVRX_FBOFFSET 0x200000
73 1.1 tsutsui
74 1.1 tsutsui #define EVRX_BT458_ADDR (STI_EVRX_REGNO2OFFSET + 0x200 + 2)
75 1.1 tsutsui #define EVRX_BT458_CMAP (STI_EVRX_REGNO2OFFSET + 0x204 + 2)
76 1.1 tsutsui #define EVRX_BT458_CTRL (STI_EVRX_REGNO2OFFSET + 0x208 + 2)
77 1.1 tsutsui #define EVRX_BT458_OMAP (STI_EVRX_REGNO2OFFSET + 0x20C + 2)
78 1.1 tsutsui
79 1.1 tsutsui /* from HP-UX /usr/lib/libddevrx.a */
80 1.1 tsutsui #define EVRX_MAGIC00 (STI_EVRX_REGNO2OFFSET + 0x600)
81 1.1 tsutsui #define EVRX_MAGIC04 (STI_EVRX_REGNO2OFFSET + 0x604)
82 1.1 tsutsui #define EVRX_MAGIC08 (STI_EVRX_REGNO2OFFSET + 0x608)
83 1.1 tsutsui #define EVRX_MAGIC0C (STI_EVRX_REGNO2OFFSET + 0x60c)
84 1.1 tsutsui #define EVRX_MAGIC10 (STI_EVRX_REGNO2OFFSET + 0x610)
85 1.1 tsutsui #define EVRX_MAGIC10_BSY 0x00010000
86 1.1 tsutsui #define EVRX_MAGIC18 (STI_EVRX_REGNO2OFFSET + 0x618)
87 1.1 tsutsui #define EVRX_MAGIC1C (STI_EVRX_REGNO2OFFSET + 0x61c)
88 1.1 tsutsui
89 1.1 tsutsui /*
90 1.1 tsutsui * HP A1659A CRX specific hardware
91 1.1 tsutsui */
92 1.1 tsutsui #define STI_CRX_FBOFFSET 0x01000000
93 1.1 tsutsui
94 1.1 tsutsui /* 425e EVRX/CRX specific access functions */
95 1.1 tsutsui static int sti_evrx_putcmap(struct sti_screen *, u_int, u_int);
96 1.1 tsutsui static void sti_evrx_resetramdac(struct sti_screen *);
97 1.1 tsutsui static void sti_evrx_resetcmap(struct sti_screen *);
98 1.1 tsutsui static void sti_evrx_setupfb(struct sti_screen *);
99 1.1 tsutsui static paddr_t sti_m68k_mmap(void *, void *, off_t, int);
100 1.1 tsutsui
101 1.1 tsutsui static struct bus_space_tag sticn_tag;
102 1.1 tsutsui static struct sti_rom sticn_rom;
103 1.1 tsutsui static struct sti_screen sticn_scr;
104 1.1 tsutsui static bus_addr_t sticn_bases[STI_REGION_MAX];
105 1.1 tsutsui
106 1.1 tsutsui static const struct wsdisplay_accessops sti_m68k_accessops = {
107 1.1 tsutsui sti_ioctl,
108 1.1 tsutsui sti_m68k_mmap,
109 1.1 tsutsui sti_alloc_screen,
110 1.1 tsutsui sti_free_screen,
111 1.1 tsutsui sti_show_screen,
112 1.1 tsutsui sti_load_font
113 1.1 tsutsui };
114 1.1 tsutsui
115 1.1 tsutsui void
116 1.1 tsutsui sti_machdep_attach_console(struct sti_machdep_softc *sc)
117 1.1 tsutsui {
118 1.1 tsutsui struct sti_softc *ssc = &sc->sc_sti;
119 1.1 tsutsui
120 1.1 tsutsui ssc->sc_flags |= STI_CONSOLE | STI_ATTACHED;
121 1.1 tsutsui ssc->sc_rom = &sticn_rom;
122 1.1 tsutsui ssc->sc_rom->rom_softc = ssc;
123 1.1 tsutsui ssc->sc_scr = &sticn_scr;
124 1.1 tsutsui ssc->sc_scr->scr_rom = ssc->sc_rom;
125 1.1 tsutsui memcpy(ssc->bases, sticn_bases, sizeof(ssc->bases));
126 1.1 tsutsui
127 1.1 tsutsui sti_describe(ssc);
128 1.1 tsutsui }
129 1.1 tsutsui
130 1.1 tsutsui void
131 1.1 tsutsui sti_machdep_attach(struct sti_machdep_softc *sc)
132 1.1 tsutsui {
133 1.1 tsutsui struct sti_softc *ssc = &sc->sc_sti;
134 1.1 tsutsui struct sti_screen *scr;
135 1.1 tsutsui paddr_t base = sc->sc_base;
136 1.1 tsutsui struct wsemuldisplaydev_attach_args waa;
137 1.1 tsutsui struct sti_dd *rom_dd;
138 1.1 tsutsui uint32_t grid0;
139 1.1 tsutsui
140 1.1 tsutsui /* Identify the board model by dd_grid */
141 1.1 tsutsui rom_dd = &ssc->sc_rom->rom_dd;
142 1.1 tsutsui grid0 = rom_dd->dd_grid[0];
143 1.1 tsutsui scr = ssc->sc_scr;
144 1.1 tsutsui
145 1.1 tsutsui switch (grid0) {
146 1.1 tsutsui case STI_DD_EVRX:
147 1.1 tsutsui /*
148 1.1 tsutsui * 425e on-board EVRX framebuffer.
149 1.1 tsutsui * bitmap memory can be accessed at offset +0x200000.
150 1.1 tsutsui */
151 1.1 tsutsui sc->sc_bitmap = base + STI_EVRX_FBOFFSET;
152 1.1 tsutsui
153 1.1 tsutsui aprint_normal_dev(ssc->sc_dev, "Enable mmap support\n");
154 1.1 tsutsui
155 1.1 tsutsui /*
156 1.1 tsutsui * initialize Bt458 RAMDAC and preserve initial color map
157 1.1 tsutsui */
158 1.1 tsutsui sti_evrx_resetramdac(scr);
159 1.1 tsutsui sti_evrx_resetcmap(scr);
160 1.1 tsutsui
161 1.1 tsutsui scr->setupfb = sti_evrx_setupfb;
162 1.1 tsutsui scr->putcmap = sti_evrx_putcmap;
163 1.1 tsutsui
164 1.1 tsutsui scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
165 1.1 tsutsui waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
166 1.1 tsutsui waa.scrdata = &scr->scr_screenlist;
167 1.1 tsutsui waa.accessops = &sti_m68k_accessops;
168 1.1 tsutsui waa.accesscookie = scr;
169 1.1 tsutsui
170 1.1 tsutsui config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint,
171 1.1 tsutsui CFARGS_NONE);
172 1.1 tsutsui break;
173 1.1 tsutsui
174 1.1 tsutsui case STI_DD_CRX:
175 1.1 tsutsui /*
176 1.1 tsutsui * HP A1659A CRX on some 425t variants.
177 1.1 tsutsui * bitmap memory can be accessed at offset +0x1000000.
178 1.1 tsutsui */
179 1.1 tsutsui sc->sc_bitmap = base + STI_CRX_FBOFFSET;
180 1.1 tsutsui
181 1.1 tsutsui aprint_normal_dev(ssc->sc_dev, "Enable mmap support\n");
182 1.1 tsutsui
183 1.1 tsutsui scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
184 1.1 tsutsui waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
185 1.1 tsutsui waa.scrdata = &scr->scr_screenlist;
186 1.1 tsutsui waa.accessops = &sti_m68k_accessops;
187 1.1 tsutsui waa.accesscookie = scr;
188 1.1 tsutsui
189 1.1 tsutsui config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint,
190 1.1 tsutsui CFARGS_NONE);
191 1.1 tsutsui break;
192 1.1 tsutsui default:
193 1.1 tsutsui /*
194 1.1 tsutsui * Unsupported variants.
195 1.1 tsutsui * Use default common sti(4) attachment (no bitmap support).
196 1.1 tsutsui */
197 1.1 tsutsui sti_end_attach(ssc);
198 1.1 tsutsui break;
199 1.1 tsutsui }
200 1.1 tsutsui }
201 1.1 tsutsui
202 1.1 tsutsui static int
203 1.1 tsutsui sti_evrx_putcmap(struct sti_screen *scr, u_int index, u_int count)
204 1.1 tsutsui {
205 1.1 tsutsui struct sti_rom *rom = scr->scr_rom;
206 1.1 tsutsui bus_space_tag_t bst = rom->memt;
207 1.1 tsutsui bus_space_handle_t bsh = rom->regh[2];
208 1.1 tsutsui int i;
209 1.1 tsutsui
210 1.1 tsutsui /* magic setup from HP-UX */
211 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
212 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
213 1.1 tsutsui for (i = index; i < index + count; i++) {
214 1.1 tsutsui /* this is what HP-UX woodDownloadCmap() does */
215 1.1 tsutsui while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
216 1.1 tsutsui EVRX_MAGIC10_BSY) != 0)
217 1.1 tsutsui continue;
218 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
219 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_rcmap[i]);
220 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_gcmap[i]);
221 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC10, scr->scr_bcmap[i]);
222 1.1 tsutsui }
223 1.1 tsutsui return 0;
224 1.1 tsutsui }
225 1.1 tsutsui
226 1.1 tsutsui static void
227 1.1 tsutsui sti_evrx_resetramdac(struct sti_screen *scr)
228 1.1 tsutsui {
229 1.1 tsutsui struct sti_rom *rom = scr->scr_rom;
230 1.1 tsutsui bus_space_tag_t bst = rom->memt;
231 1.1 tsutsui bus_space_handle_t bsh = rom->regh[2];
232 1.1 tsutsui #if 0
233 1.1 tsutsui int i;
234 1.1 tsutsui #endif
235 1.1 tsutsui
236 1.1 tsutsui /*
237 1.1 tsutsui * Initialize the Bt458. When we write to control registers,
238 1.1 tsutsui * the address is not incremented automatically. So we specify
239 1.1 tsutsui * it ourselves for each control register.
240 1.1 tsutsui */
241 1.1 tsutsui
242 1.1 tsutsui /* all planes will be read */
243 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x04);
244 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0xff);
245 1.1 tsutsui
246 1.1 tsutsui /* all planes have non-blink */
247 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x05);
248 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
249 1.1 tsutsui
250 1.1 tsutsui /* palette enabled, ovly plane disabled */
251 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x06);
252 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x40);
253 1.1 tsutsui
254 1.1 tsutsui /* no test mode */
255 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x07);
256 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
257 1.1 tsutsui
258 1.1 tsutsui /* magic initialization from HP-UX woodInitializeHardware() */
259 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
260 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC04, 0x00000001);
261 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
262 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC0C, 0x00000001);
263 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC18, 0xFFFFFFFF);
264 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC1C, 0x00000000);
265 1.1 tsutsui
266 1.1 tsutsui #if 0
267 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x00);
268 1.1 tsutsui for (i = 0; i < 4; i++) {
269 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
270 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
271 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
272 1.1 tsutsui }
273 1.1 tsutsui #endif
274 1.1 tsutsui }
275 1.1 tsutsui
276 1.1 tsutsui static void
277 1.1 tsutsui sti_evrx_resetcmap(struct sti_screen *scr)
278 1.1 tsutsui {
279 1.1 tsutsui struct sti_rom *rom = scr->scr_rom;
280 1.1 tsutsui bus_space_tag_t bst = rom->memt;
281 1.1 tsutsui bus_space_handle_t bsh = rom->regh[2];
282 1.1 tsutsui int i;
283 1.1 tsutsui
284 1.1 tsutsui /* magic setup from HP-UX */
285 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
286 1.1 tsutsui bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
287 1.1 tsutsui
288 1.1 tsutsui /* preserve palette values initialized by STI firmware */
289 1.1 tsutsui for (i = 0; i < STI_NCMAP; i++) {
290 1.1 tsutsui /* this is what HP-UX woodUploadCmap() does */
291 1.1 tsutsui while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
292 1.1 tsutsui EVRX_MAGIC10_BSY) != 0)
293 1.1 tsutsui continue;
294 1.1 tsutsui bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
295 1.1 tsutsui scr->scr_rcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
296 1.1 tsutsui scr->scr_gcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
297 1.1 tsutsui scr->scr_bcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
298 1.1 tsutsui }
299 1.1 tsutsui }
300 1.1 tsutsui
301 1.1 tsutsui static void
302 1.1 tsutsui sti_evrx_setupfb(struct sti_screen *scr)
303 1.1 tsutsui {
304 1.1 tsutsui
305 1.1 tsutsui sti_init(scr, 0);
306 1.1 tsutsui sti_evrx_resetramdac(scr);
307 1.1 tsutsui }
308 1.1 tsutsui
309 1.1 tsutsui static paddr_t
310 1.1 tsutsui sti_m68k_mmap(void *v, void *vs, off_t offset, int prot)
311 1.1 tsutsui {
312 1.1 tsutsui struct sti_screen *scr = (struct sti_screen *)v;
313 1.1 tsutsui struct sti_rom *rom = scr->scr_rom;
314 1.1 tsutsui struct sti_softc *ssc = rom->rom_softc;
315 1.1 tsutsui struct sti_machdep_softc *sc = device_private(ssc->sc_dev);
316 1.1 tsutsui paddr_t cookie = -1;
317 1.1 tsutsui
318 1.1 tsutsui if ((offset & PAGE_MASK) != 0)
319 1.1 tsutsui return -1;
320 1.1 tsutsui
321 1.1 tsutsui switch (scr->scr_wsmode) {
322 1.1 tsutsui case WSDISPLAYIO_MODE_MAPPED:
323 1.1 tsutsui /* not implemented yet; what should be shown? */
324 1.1 tsutsui break;
325 1.1 tsutsui case WSDISPLAYIO_MODE_DUMBFB:
326 1.1 tsutsui if (offset >= 0 && offset < (scr->fbwidth * scr->fbheight))
327 1.1 tsutsui cookie = m68k_btop(sc->sc_bitmap + offset);
328 1.1 tsutsui break;
329 1.1 tsutsui default:
330 1.1 tsutsui break;
331 1.1 tsutsui }
332 1.1 tsutsui
333 1.1 tsutsui return cookie;
334 1.1 tsutsui }
335 1.1 tsutsui
336 1.1 tsutsui void
337 1.1 tsutsui sti_machdep_cnattach(bus_space_tag_t bst, paddr_t base)
338 1.1 tsutsui {
339 1.1 tsutsui int i;
340 1.1 tsutsui
341 1.1 tsutsui sticn_tag = *bst;
342 1.1 tsutsui
343 1.1 tsutsui /* sticn_bases[0] will be fixed in sti_cnattach() */
344 1.1 tsutsui for (i = 0; i < STI_REGION_MAX; i++)
345 1.1 tsutsui sticn_bases[i] = (bus_addr_t)base;
346 1.1 tsutsui
347 1.1 tsutsui sti_cnattach(&sticn_rom, &sticn_scr, &sticn_tag, sticn_bases,
348 1.1 tsutsui STI_CODEBASE_ALT);
349 1.1 tsutsui }
350