gbox.c revision 1.4 1 1.4 tsutsui /* $NetBSD: gbox.c,v 1.4 2025/05/27 18:44:31 tsutsui Exp $ */
2 1.1 tsutsui /* $OpenBSD: gbox.c,v 1.15 2007/01/07 15:13:52 miod 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 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
30 1.1 tsutsui * All rights reserved.
31 1.1 tsutsui *
32 1.1 tsutsui * This code is derived from software contributed to The NetBSD Foundation
33 1.1 tsutsui * by Jason R. Thorpe.
34 1.1 tsutsui *
35 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
36 1.1 tsutsui * modification, are permitted provided that the following conditions
37 1.1 tsutsui * are met:
38 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
39 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
40 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
41 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
42 1.1 tsutsui * documentation and/or other materials provided with the distribution.
43 1.1 tsutsui *
44 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
45 1.1 tsutsui * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46 1.1 tsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 1.1 tsutsui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
48 1.1 tsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 1.1 tsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 1.1 tsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 1.1 tsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 1.1 tsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 1.1 tsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54 1.1 tsutsui * POSSIBILITY OF SUCH DAMAGE.
55 1.1 tsutsui */
56 1.1 tsutsui
57 1.1 tsutsui /*
58 1.1 tsutsui * Copyright (c) 1988 University of Utah.
59 1.1 tsutsui * Copyright (c) 1990, 1993
60 1.1 tsutsui * The Regents of the University of California. All rights reserved.
61 1.1 tsutsui *
62 1.1 tsutsui * This code is derived from software contributed to Berkeley by
63 1.1 tsutsui * the Systems Programming Group of the University of Utah Computer
64 1.1 tsutsui * Science Department.
65 1.1 tsutsui *
66 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
67 1.1 tsutsui * modification, are permitted provided that the following conditions
68 1.1 tsutsui * are met:
69 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
70 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
71 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
72 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
73 1.1 tsutsui * documentation and/or other materials provided with the distribution.
74 1.1 tsutsui * 3. Neither the name of the University nor the names of its contributors
75 1.1 tsutsui * may be used to endorse or promote products derived from this software
76 1.1 tsutsui * without specific prior written permission.
77 1.1 tsutsui *
78 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
79 1.1 tsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
80 1.1 tsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
81 1.1 tsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
82 1.1 tsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
83 1.1 tsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
84 1.1 tsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
85 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
86 1.1 tsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
87 1.1 tsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88 1.1 tsutsui * SUCH DAMAGE.
89 1.1 tsutsui *
90 1.1 tsutsui * from: Utah $Hdr: grf_gb.c 1.18 93/08/13$
91 1.1 tsutsui *
92 1.1 tsutsui * @(#)grf_gb.c 8.4 (Berkeley) 1/12/94
93 1.1 tsutsui */
94 1.1 tsutsui
95 1.1 tsutsui /*
96 1.1 tsutsui * Graphics routines for the Gatorbox.
97 1.1 tsutsui *
98 1.1 tsutsui * Note: In the context of this system, "gator" and "gatorbox" both refer to
99 1.1 tsutsui * HP 987x0 graphics systems. "Gator" is not used for high res mono.
100 1.1 tsutsui * (as in 9837 Gator systems)
101 1.1 tsutsui */
102 1.1 tsutsui
103 1.1 tsutsui #include <sys/param.h>
104 1.1 tsutsui #include <sys/systm.h>
105 1.1 tsutsui #include <sys/conf.h>
106 1.1 tsutsui #include <sys/device.h>
107 1.1 tsutsui #include <sys/proc.h>
108 1.1 tsutsui #include <sys/ioctl.h>
109 1.1 tsutsui #include <sys/bus.h>
110 1.1 tsutsui #include <sys/cpu.h>
111 1.1 tsutsui
112 1.1 tsutsui #include <machine/autoconf.h>
113 1.1 tsutsui
114 1.1 tsutsui #include <hp300/dev/dioreg.h>
115 1.1 tsutsui #include <hp300/dev/diovar.h>
116 1.1 tsutsui #include <hp300/dev/diodevs.h>
117 1.1 tsutsui #include <hp300/dev/intiovar.h>
118 1.1 tsutsui
119 1.1 tsutsui #include <dev/wscons/wsconsio.h>
120 1.1 tsutsui #include <dev/wscons/wsdisplayvar.h>
121 1.1 tsutsui #include <dev/rasops/rasops.h>
122 1.1 tsutsui
123 1.1 tsutsui #include <hp300/dev/diofbreg.h>
124 1.1 tsutsui #include <hp300/dev/diofbvar.h>
125 1.1 tsutsui #include <hp300/dev/gboxreg.h>
126 1.1 tsutsui
127 1.1 tsutsui struct gbox_softc {
128 1.1 tsutsui device_t sc_dev;
129 1.1 tsutsui struct diofb *sc_fb;
130 1.1 tsutsui struct diofb sc_fb_store;
131 1.1 tsutsui int sc_scode;
132 1.1 tsutsui };
133 1.1 tsutsui
134 1.2 tsutsui static int gbox_dio_match(device_t, cfdata_t, void *);
135 1.2 tsutsui static void gbox_dio_attach(device_t, device_t, void *);
136 1.2 tsutsui static int gbox_intio_match(device_t, cfdata_t, void *);
137 1.2 tsutsui static void gbox_intio_attach(device_t, device_t, void *);
138 1.1 tsutsui
139 1.1 tsutsui CFATTACH_DECL_NEW(gbox_dio, sizeof(struct gbox_softc),
140 1.1 tsutsui gbox_dio_match, gbox_dio_attach, NULL, NULL);
141 1.1 tsutsui
142 1.1 tsutsui CFATTACH_DECL_NEW(gbox_intio, sizeof(struct gbox_softc),
143 1.1 tsutsui gbox_intio_match, gbox_intio_attach, NULL, NULL);
144 1.1 tsutsui
145 1.2 tsutsui static int gbox_reset(struct diofb *, int, struct diofbreg *);
146 1.2 tsutsui static void gbox_restore(struct diofb *);
147 1.2 tsutsui static int gbox_setcmap(struct diofb *, struct wsdisplay_cmap *);
148 1.2 tsutsui static void gbox_setcolor(struct diofb *, u_int);
149 1.2 tsutsui static int gbox_windowmove(struct diofb *, uint16_t, uint16_t, uint16_t,
150 1.2 tsutsui uint16_t, uint16_t, uint16_t, int16_t, int16_t);
151 1.1 tsutsui
152 1.2 tsutsui static int gbox_ioctl(void *, void *, u_long, void *, int, struct lwp *);
153 1.1 tsutsui
154 1.2 tsutsui static struct wsdisplay_accessops gbox_accessops = {
155 1.4 tsutsui .ioctl = gbox_ioctl,
156 1.4 tsutsui .mmap = diofb_mmap,
157 1.4 tsutsui .alloc_screen = diofb_alloc_screen,
158 1.4 tsutsui .free_screen = diofb_free_screen,
159 1.4 tsutsui .show_screen = diofb_show_screen,
160 1.4 tsutsui .load_font = NULL,
161 1.1 tsutsui };
162 1.1 tsutsui
163 1.1 tsutsui /*
164 1.1 tsutsui * Attachment glue
165 1.1 tsutsui */
166 1.1 tsutsui int
167 1.1 tsutsui gbox_intio_match(device_t parent, cfdata_t cf, void *aux)
168 1.1 tsutsui {
169 1.1 tsutsui struct intio_attach_args *ia = aux;
170 1.1 tsutsui struct diofbreg *fbr;
171 1.1 tsutsui
172 1.1 tsutsui if (strcmp("fb", ia->ia_modname) != 0)
173 1.1 tsutsui return 0;
174 1.1 tsutsui
175 1.1 tsutsui fbr = (struct diofbreg *)ia->ia_addr;
176 1.1 tsutsui
177 1.1 tsutsui if (badaddr((void *)fbr))
178 1.2 tsutsui return 0;
179 1.1 tsutsui
180 1.1 tsutsui if (fbr->id == GRFHWID && fbr->fbid == GID_GATORBOX) {
181 1.2 tsutsui return 1;
182 1.1 tsutsui }
183 1.1 tsutsui
184 1.2 tsutsui return 0;
185 1.1 tsutsui }
186 1.1 tsutsui
187 1.1 tsutsui void
188 1.1 tsutsui gbox_intio_attach(device_t parent, device_t self, void *aux)
189 1.1 tsutsui {
190 1.1 tsutsui struct gbox_softc *sc = device_private(self);
191 1.1 tsutsui struct intio_attach_args *ia = aux;
192 1.1 tsutsui struct diofbreg *fbr;
193 1.1 tsutsui
194 1.1 tsutsui sc->sc_dev = self;
195 1.1 tsutsui fbr = (struct diofbreg *)ia->ia_addr;
196 1.1 tsutsui sc->sc_scode = CONSCODE_INTERNAL;
197 1.1 tsutsui
198 1.1 tsutsui if (sc->sc_scode == conscode) {
199 1.1 tsutsui sc->sc_fb = &diofb_cn;
200 1.1 tsutsui } else {
201 1.1 tsutsui sc->sc_fb = &sc->sc_fb_store;
202 1.1 tsutsui gbox_reset(sc->sc_fb, sc->sc_scode, fbr);
203 1.1 tsutsui }
204 1.1 tsutsui
205 1.1 tsutsui diofb_end_attach(self, &gbox_accessops, sc->sc_fb,
206 1.1 tsutsui sc->sc_scode == conscode, NULL);
207 1.1 tsutsui }
208 1.1 tsutsui
209 1.1 tsutsui int
210 1.1 tsutsui gbox_dio_match(device_t parent, cfdata_t cf, void *aux)
211 1.1 tsutsui {
212 1.1 tsutsui struct dio_attach_args *da = aux;
213 1.1 tsutsui
214 1.1 tsutsui /* We can not appear in DIO-II space */
215 1.1 tsutsui if (DIO_ISDIOII(da->da_scode))
216 1.2 tsutsui return 0;
217 1.1 tsutsui
218 1.1 tsutsui if (da->da_id == DIO_DEVICE_ID_FRAMEBUFFER &&
219 1.1 tsutsui da->da_secid == DIO_DEVICE_SECID_GATORBOX)
220 1.2 tsutsui return 1;
221 1.1 tsutsui
222 1.2 tsutsui return 0;
223 1.1 tsutsui }
224 1.1 tsutsui
225 1.1 tsutsui void
226 1.1 tsutsui gbox_dio_attach(device_t parent, device_t self, void *aux)
227 1.1 tsutsui {
228 1.1 tsutsui struct gbox_softc *sc = device_private(self);
229 1.1 tsutsui struct dio_attach_args *da = aux;
230 1.1 tsutsui bus_space_handle_t bsh;
231 1.1 tsutsui struct diofbreg * fbr;
232 1.1 tsutsui
233 1.1 tsutsui sc->sc_dev = self;
234 1.1 tsutsui sc->sc_scode = da->da_scode;
235 1.1 tsutsui if (sc->sc_scode == conscode) {
236 1.1 tsutsui fbr = (struct diofbreg *)conaddr; /* already mapped */
237 1.1 tsutsui sc->sc_fb = &diofb_cn;
238 1.1 tsutsui } else {
239 1.1 tsutsui sc->sc_fb = &sc->sc_fb_store;
240 1.1 tsutsui if (bus_space_map(da->da_bst, da->da_addr, da->da_size, 0,
241 1.1 tsutsui &bsh)) {
242 1.1 tsutsui aprint_error(": can't map framebuffer\n");
243 1.1 tsutsui return;
244 1.1 tsutsui }
245 1.1 tsutsui fbr = bus_space_vaddr(da->da_bst, bsh);
246 1.1 tsutsui if (gbox_reset(sc->sc_fb, sc->sc_scode, fbr) != 0) {
247 1.3 tsutsui aprint_error(": can't reset framebuffer\n");
248 1.1 tsutsui return;
249 1.1 tsutsui }
250 1.1 tsutsui }
251 1.1 tsutsui
252 1.1 tsutsui diofb_end_attach(self, &gbox_accessops, sc->sc_fb,
253 1.1 tsutsui sc->sc_scode == conscode, NULL);
254 1.1 tsutsui }
255 1.1 tsutsui
256 1.1 tsutsui /*
257 1.1 tsutsui * Initialize hardware and display routines.
258 1.1 tsutsui */
259 1.1 tsutsui
260 1.2 tsutsui const uint8_t crtc_init_data[] = {
261 1.1 tsutsui 0x29, 0x20, 0x23, 0x04, 0x30, 0x0b, 0x30,
262 1.1 tsutsui 0x30, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00
263 1.1 tsutsui };
264 1.1 tsutsui
265 1.1 tsutsui int
266 1.1 tsutsui gbox_reset(struct diofb *fb, int scode, struct diofbreg *fbr)
267 1.1 tsutsui {
268 1.1 tsutsui int rc;
269 1.1 tsutsui u_int i;
270 1.1 tsutsui
271 1.1 tsutsui /* XXX don't trust hardware, force defaults */
272 1.1 tsutsui fb->fbwidth = 1024;
273 1.1 tsutsui fb->fbheight = 1024;
274 1.1 tsutsui fb->dwidth = 1024;
275 1.1 tsutsui fb->dheight = 768;
276 1.1 tsutsui if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0)
277 1.2 tsutsui return rc;
278 1.1 tsutsui
279 1.1 tsutsui fb->bmv = gbox_windowmove;
280 1.1 tsutsui gbox_restore(fb);
281 1.1 tsutsui
282 1.1 tsutsui /*
283 1.1 tsutsui * Find out how many colors are available by determining
284 1.1 tsutsui * which planes are installed. That is, write all ones to
285 1.1 tsutsui * a frame buffer location, see how many ones are read back.
286 1.1 tsutsui */
287 1.1 tsutsui if (1 /* fb->planes == 0 */) {
288 1.2 tsutsui volatile uint8_t *fbp;
289 1.2 tsutsui uint8_t save;
290 1.1 tsutsui
291 1.2 tsutsui fbp = (uint8_t *)fb->fbkva;
292 1.1 tsutsui save = *fbp;
293 1.1 tsutsui *fbp = 0xff;
294 1.1 tsutsui fb->planemask = *fbp;
295 1.1 tsutsui *fbp = save;
296 1.1 tsutsui
297 1.1 tsutsui for (fb->planes = 1; fb->planemask >= (1 << fb->planes);
298 1.1 tsutsui fb->planes++);
299 1.1 tsutsui if (fb->planes > 8)
300 1.1 tsutsui fb->planes = 8;
301 1.1 tsutsui fb->planemask = (1 << fb->planes) - 1;
302 1.1 tsutsui }
303 1.1 tsutsui
304 1.1 tsutsui diofb_fbsetup(fb);
305 1.1 tsutsui for (i = 0; i <= fb->planemask; i++)
306 1.1 tsutsui gbox_setcolor(fb, i);
307 1.1 tsutsui
308 1.2 tsutsui return 0;
309 1.1 tsutsui }
310 1.1 tsutsui
311 1.1 tsutsui void
312 1.1 tsutsui gbox_restore(struct diofb *fb)
313 1.1 tsutsui {
314 1.1 tsutsui volatile struct gboxfb *gb = (struct gboxfb *)fb->regkva;
315 1.1 tsutsui u_int i;
316 1.1 tsutsui
317 1.1 tsutsui /*
318 1.1 tsutsui * The minimal info here is from the Gatorbox X driver.
319 1.1 tsutsui */
320 1.1 tsutsui gb->write_protect = 0x0;
321 1.1 tsutsui gb->regs.interrupt = 0x4;
322 1.1 tsutsui gb->rep_rule = RR_COPY;
323 1.1 tsutsui gb->blink1 = 0xff;
324 1.1 tsutsui gb->blink2 = 0xff;
325 1.1 tsutsui
326 1.1 tsutsui /*
327 1.1 tsutsui * Program the 6845.
328 1.1 tsutsui */
329 1.1 tsutsui for (i = 0; i < sizeof(crtc_init_data); i++) {
330 1.1 tsutsui gb->crtc_address = i;
331 1.1 tsutsui gb->crtc_data = crtc_init_data[i];
332 1.1 tsutsui }
333 1.1 tsutsui
334 1.1 tsutsui tile_mover_waitbusy(gb);
335 1.1 tsutsui
336 1.1 tsutsui /* Enable display */
337 1.1 tsutsui gb->regs.sec_interrupt = 0x01;
338 1.1 tsutsui }
339 1.1 tsutsui
340 1.1 tsutsui int
341 1.1 tsutsui gbox_ioctl(void *v, void *vs, u_long cmd, void *data, int flags, struct lwp *l)
342 1.1 tsutsui {
343 1.1 tsutsui struct diofb *fb = v;
344 1.1 tsutsui struct wsdisplay_fbinfo *wdf;
345 1.1 tsutsui u_int i;
346 1.1 tsutsui
347 1.1 tsutsui switch (cmd) {
348 1.1 tsutsui case WSDISPLAYIO_GTYPE:
349 1.1 tsutsui *(u_int *)data = WSDISPLAY_TYPE_GBOX;
350 1.1 tsutsui return 0;
351 1.1 tsutsui case WSDISPLAYIO_SMODE:
352 1.1 tsutsui fb->mapmode = *(u_int *)data;
353 1.1 tsutsui if (fb->mapmode == WSDISPLAYIO_MODE_EMUL) {
354 1.1 tsutsui gbox_restore(fb);
355 1.1 tsutsui for (i = 0; i <= fb->planemask; i++)
356 1.1 tsutsui gbox_setcolor(fb, i);
357 1.1 tsutsui }
358 1.1 tsutsui return 0;
359 1.1 tsutsui case WSDISPLAYIO_GINFO:
360 1.1 tsutsui wdf = (void *)data;
361 1.1 tsutsui wdf->width = fb->ri.ri_width;
362 1.1 tsutsui wdf->height = fb->ri.ri_height;
363 1.1 tsutsui wdf->depth = fb->ri.ri_depth;
364 1.1 tsutsui wdf->cmsize = 1 << fb->planes;
365 1.1 tsutsui return 0;
366 1.1 tsutsui case WSDISPLAYIO_LINEBYTES:
367 1.1 tsutsui *(u_int *)data = fb->ri.ri_stride;
368 1.1 tsutsui return 0;
369 1.1 tsutsui case WSDISPLAYIO_GETCMAP:
370 1.2 tsutsui return diofb_getcmap(fb, (struct wsdisplay_cmap *)data);
371 1.1 tsutsui case WSDISPLAYIO_PUTCMAP:
372 1.2 tsutsui return gbox_setcmap(fb, (struct wsdisplay_cmap *)data);
373 1.1 tsutsui case WSDISPLAYIO_GVIDEO:
374 1.1 tsutsui case WSDISPLAYIO_SVIDEO:
375 1.1 tsutsui return EPASSTHROUGH;
376 1.1 tsutsui }
377 1.1 tsutsui
378 1.1 tsutsui return EPASSTHROUGH;
379 1.1 tsutsui }
380 1.1 tsutsui
381 1.1 tsutsui void
382 1.1 tsutsui gbox_setcolor(struct diofb *fb, u_int index)
383 1.1 tsutsui {
384 1.1 tsutsui volatile struct gboxfb *gb = (struct gboxfb *)fb->regkva;
385 1.1 tsutsui
386 1.1 tsutsui gb->creg_select = index;
387 1.1 tsutsui gb->cmap_red = fb->cmap.r[index];
388 1.1 tsutsui gb->cmap_grn = fb->cmap.g[index];
389 1.1 tsutsui gb->cmap_blu = fb->cmap.b[index];
390 1.1 tsutsui gb->cmap_write = !!index;
391 1.1 tsutsui gbcm_waitbusy(gb);
392 1.1 tsutsui }
393 1.1 tsutsui
394 1.1 tsutsui int
395 1.1 tsutsui gbox_setcmap(struct diofb *fb, struct wsdisplay_cmap *cm)
396 1.1 tsutsui {
397 1.2 tsutsui uint8_t r[256], g[256], b[256];
398 1.1 tsutsui u_int index = cm->index, count = cm->count;
399 1.1 tsutsui u_int colcount = 1 << fb->planes;
400 1.1 tsutsui int error;
401 1.1 tsutsui
402 1.1 tsutsui if (index >= colcount || count > colcount - index)
403 1.2 tsutsui return EINVAL;
404 1.1 tsutsui
405 1.1 tsutsui if ((error = copyin(cm->red, r, count)) != 0)
406 1.2 tsutsui return error;
407 1.1 tsutsui if ((error = copyin(cm->green, g, count)) != 0)
408 1.2 tsutsui return error;
409 1.1 tsutsui if ((error = copyin(cm->blue, b, count)) != 0)
410 1.2 tsutsui return error;
411 1.1 tsutsui
412 1.1 tsutsui memcpy(fb->cmap.r + index, r, count);
413 1.1 tsutsui memcpy(fb->cmap.g + index, g, count);
414 1.1 tsutsui memcpy(fb->cmap.b + index, b, count);
415 1.1 tsutsui
416 1.1 tsutsui while (count-- != 0)
417 1.1 tsutsui gbox_setcolor(fb, index++);
418 1.1 tsutsui
419 1.2 tsutsui return 0;
420 1.1 tsutsui }
421 1.1 tsutsui
422 1.1 tsutsui int
423 1.2 tsutsui gbox_windowmove(struct diofb *fb, uint16_t sx, uint16_t sy,
424 1.2 tsutsui uint16_t dx, uint16_t dy, uint16_t cx, uint16_t cy, int16_t rop,
425 1.1 tsutsui int16_t planemask)
426 1.1 tsutsui {
427 1.1 tsutsui volatile struct gboxfb *gb = (struct gboxfb *)fb->regkva;
428 1.1 tsutsui int src, dest;
429 1.1 tsutsui
430 1.1 tsutsui if (planemask != 0xff)
431 1.2 tsutsui return EINVAL;
432 1.1 tsutsui
433 1.1 tsutsui src = (sy * 1024) + sx; /* upper left corner in pixels */
434 1.1 tsutsui dest = (dy * 1024) + dx;
435 1.1 tsutsui
436 1.1 tsutsui tile_mover_waitbusy(gb);
437 1.1 tsutsui
438 1.1 tsutsui gb->width = -(cx / 4);
439 1.1 tsutsui gb->height = -(cy / 4);
440 1.1 tsutsui if (src < dest)
441 1.1 tsutsui gb->rep_rule = MOVE_DOWN_RIGHT | rop;
442 1.1 tsutsui else {
443 1.1 tsutsui gb->rep_rule = MOVE_UP_LEFT | rop;
444 1.1 tsutsui /*
445 1.1 tsutsui * Adjust to top of lower right tile of the block.
446 1.1 tsutsui */
447 1.1 tsutsui src = src + ((cy - 4) * 1024) + (cx - 4);
448 1.1 tsutsui dest= dest + ((cy - 4) * 1024) + (cx - 4);
449 1.1 tsutsui }
450 1.2 tsutsui *(volatile uint8_t *)(fb->fbkva + dest) =
451 1.2 tsutsui *(volatile uint8_t *)(fb->fbkva + src);
452 1.1 tsutsui
453 1.1 tsutsui tile_mover_waitbusy(gb);
454 1.1 tsutsui
455 1.2 tsutsui return 0;
456 1.1 tsutsui }
457 1.1 tsutsui
458 1.1 tsutsui /*
459 1.1 tsutsui * Gatorbox console support
460 1.1 tsutsui */
461 1.1 tsutsui int
462 1.1 tsutsui gboxcnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
463 1.1 tsutsui {
464 1.1 tsutsui bus_space_handle_t bsh;
465 1.1 tsutsui void *va;
466 1.1 tsutsui struct diofbreg *fbr;
467 1.1 tsutsui struct diofb *fb = &diofb_cn;
468 1.1 tsutsui int size;
469 1.1 tsutsui
470 1.1 tsutsui if (bus_space_map(bst, addr, PAGE_SIZE, 0, &bsh))
471 1.1 tsutsui return 1;
472 1.1 tsutsui va = bus_space_vaddr(bst, bsh);
473 1.1 tsutsui fbr = va;
474 1.1 tsutsui
475 1.1 tsutsui if (badaddr(va) ||
476 1.1 tsutsui (fbr->id != GRFHWID) || (fbr->fbid != GID_GATORBOX)) {
477 1.1 tsutsui bus_space_unmap(bst, bsh, PAGE_SIZE);
478 1.1 tsutsui return 1;
479 1.1 tsutsui }
480 1.1 tsutsui
481 1.1 tsutsui size = DIO_SIZE(scode, va);
482 1.1 tsutsui
483 1.1 tsutsui bus_space_unmap(bst, bsh, PAGE_SIZE);
484 1.1 tsutsui if (bus_space_map(bst, addr, size, 0, &bsh))
485 1.1 tsutsui return 1;
486 1.1 tsutsui va = bus_space_vaddr(bst, bsh);
487 1.1 tsutsui
488 1.1 tsutsui /*
489 1.1 tsutsui * Initialize the framebuffer hardware.
490 1.1 tsutsui */
491 1.1 tsutsui conscode = scode;
492 1.1 tsutsui conaddr = va;
493 1.1 tsutsui gbox_reset(fb, conscode, (struct diofbreg *)conaddr);
494 1.1 tsutsui
495 1.1 tsutsui /*
496 1.1 tsutsui * Initialize the terminal emulator.
497 1.1 tsutsui */
498 1.1 tsutsui diofb_cnattach(fb);
499 1.1 tsutsui return 0;
500 1.1 tsutsui }
501