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