cgeight.c revision 1.22 1 1.22 simonb /* $NetBSD: cgeight.c,v 1.22 2000/06/26 04:56:03 simonb Exp $ */
2 1.14 thorpej
3 1.14 thorpej /*-
4 1.14 thorpej * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5 1.14 thorpej * All rights reserved.
6 1.14 thorpej *
7 1.14 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.14 thorpej * by Jason R. Thorpe.
9 1.14 thorpej *
10 1.14 thorpej * Redistribution and use in source and binary forms, with or without
11 1.14 thorpej * modification, are permitted provided that the following conditions
12 1.14 thorpej * are met:
13 1.14 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.14 thorpej * notice, this list of conditions and the following disclaimer.
15 1.14 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.14 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.14 thorpej * documentation and/or other materials provided with the distribution.
18 1.14 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.14 thorpej * must display the following acknowledgement:
20 1.14 thorpej * This product includes software developed by the NetBSD
21 1.14 thorpej * Foundation, Inc. and its contributors.
22 1.14 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.14 thorpej * contributors may be used to endorse or promote products derived
24 1.14 thorpej * from this software without specific prior written permission.
25 1.14 thorpej *
26 1.14 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.14 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.14 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.14 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.14 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.14 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.14 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.14 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.14 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.14 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.14 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.14 thorpej */
38 1.1 thorpej
39 1.1 thorpej /*
40 1.1 thorpej * Copyright (c) 1995 Theo de Raadt
41 1.1 thorpej * Copyright (c) 1992, 1993
42 1.1 thorpej * The Regents of the University of California. All rights reserved.
43 1.1 thorpej *
44 1.1 thorpej * This software was developed by the Computer Systems Engineering group
45 1.1 thorpej * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
46 1.1 thorpej * contributed to Berkeley.
47 1.1 thorpej *
48 1.1 thorpej * All advertising materials mentioning features or use of this software
49 1.1 thorpej * must display the following acknowledgement:
50 1.1 thorpej * This product includes software developed by the University of
51 1.1 thorpej * California, Lawrence Berkeley Laboratory.
52 1.1 thorpej *
53 1.1 thorpej * Redistribution and use in source and binary forms, with or without
54 1.1 thorpej * modification, are permitted provided that the following conditions
55 1.1 thorpej * are met:
56 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
57 1.1 thorpej * notice, this list of conditions and the following disclaimer.
58 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
59 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
60 1.1 thorpej * documentation and/or other materials provided with the distribution.
61 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
62 1.1 thorpej * must display the following acknowledgement:
63 1.1 thorpej * This product includes software developed by the University of
64 1.1 thorpej * California, Berkeley and its contributors.
65 1.1 thorpej * 4. Neither the name of the University nor the names of its contributors
66 1.1 thorpej * may be used to endorse or promote products derived from this software
67 1.1 thorpej * without specific prior written permission.
68 1.1 thorpej *
69 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
70 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
71 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
72 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
73 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
74 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
75 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
76 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
77 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
78 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
79 1.1 thorpej * SUCH DAMAGE.
80 1.1 thorpej *
81 1.1 thorpej * from @(#)cgthree.c 8.2 (Berkeley) 10/30/93
82 1.1 thorpej */
83 1.1 thorpej
84 1.1 thorpej /*
85 1.1 thorpej * color display (cgeight) driver.
86 1.1 thorpej *
87 1.1 thorpej * Does not handle interrupts, even though they can occur.
88 1.1 thorpej *
89 1.1 thorpej * XXX should defer colormap updates to vertical retrace interrupts
90 1.1 thorpej */
91 1.1 thorpej
92 1.1 thorpej #include <sys/param.h>
93 1.4 christos #include <sys/systm.h>
94 1.1 thorpej #include <sys/buf.h>
95 1.1 thorpej #include <sys/device.h>
96 1.1 thorpej #include <sys/ioctl.h>
97 1.1 thorpej #include <sys/malloc.h>
98 1.1 thorpej #include <sys/mman.h>
99 1.1 thorpej #include <sys/tty.h>
100 1.7 christos #include <sys/conf.h>
101 1.1 thorpej
102 1.1 thorpej #include <vm/vm.h>
103 1.1 thorpej
104 1.1 thorpej #include <machine/fbio.h>
105 1.1 thorpej #include <machine/autoconf.h>
106 1.1 thorpej #include <machine/pmap.h>
107 1.1 thorpej #include <machine/fbvar.h>
108 1.1 thorpej #include <machine/eeprom.h>
109 1.7 christos #include <machine/conf.h>
110 1.1 thorpej
111 1.1 thorpej #include <sparc/dev/btreg.h>
112 1.1 thorpej #include <sparc/dev/btvar.h>
113 1.1 thorpej #include <sparc/dev/pfourreg.h>
114 1.1 thorpej
115 1.1 thorpej /* per-display variables */
116 1.1 thorpej struct cgeight_softc {
117 1.16 pk struct device sc_dev; /* base device */
118 1.16 pk struct fbdevice sc_fb; /* frame buffer device */
119 1.16 pk bus_space_tag_t sc_bustag;
120 1.16 pk bus_type_t sc_btype; /* phys address description */
121 1.16 pk bus_addr_t sc_paddr; /* for device mmap() */
122 1.16 pk
123 1.1 thorpej volatile struct fbcontrol *sc_fbc; /* Brooktree registers */
124 1.16 pk union bt_cmap sc_cmap; /* Brooktree color map */
125 1.1 thorpej };
126 1.1 thorpej
127 1.1 thorpej /* autoconfiguration driver */
128 1.1 thorpej static void cgeightattach(struct device *, struct device *, void *);
129 1.12 pk static int cgeightmatch(struct device *, struct cfdata *, void *);
130 1.6 pk #if defined(SUN4)
131 1.1 thorpej static void cgeightunblank __P((struct device *));
132 1.6 pk #endif
133 1.1 thorpej
134 1.16 pk static int cg8_pfour_probe __P((void *, void *));
135 1.16 pk
136 1.9 thorpej /* cdevsw prototypes */
137 1.9 thorpej cdev_decl(cgeight);
138 1.9 thorpej
139 1.5 thorpej struct cfattach cgeight_ca = {
140 1.5 thorpej sizeof(struct cgeight_softc), cgeightmatch, cgeightattach
141 1.5 thorpej };
142 1.5 thorpej
143 1.15 thorpej extern struct cfdriver cgeight_cd;
144 1.1 thorpej
145 1.6 pk #if defined(SUN4)
146 1.1 thorpej /* frame buffer generic driver */
147 1.1 thorpej static struct fbdriver cgeightfbdriver = {
148 1.9 thorpej cgeightunblank, cgeightopen, cgeightclose, cgeightioctl,
149 1.9 thorpej cgeightpoll, cgeightmmap
150 1.1 thorpej };
151 1.1 thorpej
152 1.1 thorpej static void cgeightloadcmap __P((struct cgeight_softc *, int, int));
153 1.1 thorpej static int cgeight_get_video __P((struct cgeight_softc *));
154 1.1 thorpej static void cgeight_set_video __P((struct cgeight_softc *, int));
155 1.6 pk #endif
156 1.1 thorpej
157 1.1 thorpej /*
158 1.1 thorpej * Match a cgeight.
159 1.1 thorpej */
160 1.1 thorpej int
161 1.12 pk cgeightmatch(parent, cf, aux)
162 1.1 thorpej struct device *parent;
163 1.12 pk struct cfdata *cf;
164 1.12 pk void *aux;
165 1.1 thorpej {
166 1.16 pk union obio_attach_args *uoba = aux;
167 1.16 pk struct obio4_attach_args *oba;
168 1.1 thorpej
169 1.16 pk if (uoba->uoba_isobio4 == 0)
170 1.1 thorpej return (0);
171 1.1 thorpej
172 1.16 pk oba = &uoba->uoba_oba4;
173 1.17 pk return (bus_space_probe(oba->oba_bustag, 0, oba->oba_paddr,
174 1.17 pk 4, /* probe size */
175 1.17 pk 0, /* offset */
176 1.17 pk 0, /* flags */
177 1.17 pk cg8_pfour_probe, NULL));
178 1.16 pk }
179 1.1 thorpej
180 1.16 pk int
181 1.16 pk cg8_pfour_probe(vaddr, arg)
182 1.16 pk void *vaddr;
183 1.16 pk void *arg;
184 1.16 pk {
185 1.1 thorpej
186 1.16 pk return (fb_pfour_id(vaddr) == PFOUR_ID_COLOR24);
187 1.1 thorpej }
188 1.1 thorpej
189 1.1 thorpej /*
190 1.1 thorpej * Attach a display. We need to notice if it is the console, too.
191 1.1 thorpej */
192 1.1 thorpej void
193 1.16 pk cgeightattach(parent, self, aux)
194 1.1 thorpej struct device *parent, *self;
195 1.16 pk void *aux;
196 1.1 thorpej {
197 1.6 pk #if defined(SUN4)
198 1.16 pk union obio_attach_args *uoba = aux;
199 1.16 pk struct obio4_attach_args *oba = &uoba->uoba_oba4;
200 1.16 pk struct cgeight_softc *sc = (struct cgeight_softc *)self;
201 1.4 christos struct fbdevice *fb = &sc->sc_fb;
202 1.16 pk bus_space_handle_t bh;
203 1.16 pk volatile struct bt_regs *bt;
204 1.16 pk int ramsize, i, isconsole;
205 1.16 pk
206 1.16 pk sc->sc_bustag = oba->oba_bustag;
207 1.16 pk sc->sc_btype = (bus_type_t)0;
208 1.16 pk sc->sc_paddr = (bus_addr_t)oba->oba_paddr;
209 1.16 pk
210 1.16 pk /* Map the pfour register. */
211 1.16 pk if (obio_bus_map(oba->oba_bustag, oba->oba_paddr,
212 1.16 pk 0,
213 1.16 pk sizeof(u_int32_t),
214 1.16 pk BUS_SPACE_MAP_LINEAR,
215 1.16 pk 0, &bh) != 0) {
216 1.16 pk printf("%s: cannot map pfour register\n", self->dv_xname);
217 1.16 pk return;
218 1.16 pk }
219 1.16 pk fb->fb_pfour = (volatile u_int32_t *)bh;
220 1.1 thorpej
221 1.1 thorpej fb->fb_driver = &cgeightfbdriver;
222 1.1 thorpej fb->fb_device = &sc->sc_dev;
223 1.1 thorpej fb->fb_type.fb_type = FBTYPE_MEMCOLOR;
224 1.16 pk fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
225 1.16 pk fb->fb_flags |= FB_PFOUR;
226 1.1 thorpej
227 1.1 thorpej ramsize = PFOUR_COLOR_OFF_END - PFOUR_COLOR_OFF_OVERLAY;
228 1.1 thorpej
229 1.1 thorpej fb->fb_type.fb_depth = 24;
230 1.16 pk fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
231 1.1 thorpej
232 1.1 thorpej sc->sc_fb.fb_type.fb_cmsize = 256;
233 1.1 thorpej sc->sc_fb.fb_type.fb_size = ramsize;
234 1.16 pk printf(": cgeight/p4, %d x %d",
235 1.16 pk fb->fb_type.fb_width,
236 1.16 pk fb->fb_type.fb_height);
237 1.1 thorpej
238 1.1 thorpej isconsole = 0;
239 1.1 thorpej
240 1.16 pk if (CPU_ISSUN4) {
241 1.1 thorpej struct eeprom *eep = (struct eeprom *)eeprom_va;
242 1.1 thorpej
243 1.1 thorpej /*
244 1.1 thorpej * Assume this is the console if there's no eeprom info
245 1.1 thorpej * to be found.
246 1.1 thorpej */
247 1.1 thorpej if (eep == NULL || eep->eeConsole == EE_CONS_P4OPT)
248 1.20 pk isconsole = fb_is_console(0);
249 1.1 thorpej }
250 1.1 thorpej
251 1.1 thorpej #if 0
252 1.1 thorpej /*
253 1.1 thorpej * We don't do any of the console handling here. Instead,
254 1.1 thorpej * we let the bwtwo driver pick up the overlay plane and
255 1.1 thorpej * use it instead. Rconsole should have better performance
256 1.1 thorpej * with the 1-bit depth.
257 1.1 thorpej * -- Jason R. Thorpe <thorpej (at) NetBSD.ORG>
258 1.1 thorpej */
259 1.1 thorpej
260 1.1 thorpej /*
261 1.1 thorpej * When the ROM has mapped in a cgfour display, the address
262 1.1 thorpej * maps only the video RAM, so in any case we have to map the
263 1.1 thorpej * registers ourselves. We only need the video RAM if we are
264 1.1 thorpej * going to print characters via rconsole.
265 1.1 thorpej */
266 1.1 thorpej
267 1.1 thorpej if (isconsole) {
268 1.1 thorpej /* XXX this is kind of a waste */
269 1.1 thorpej fb->fb_pixels = mapiodev(ca->ca_ra.ra_reg,
270 1.13 pk PFOUR_COLOR_OFF_OVERLAY, ramsize);
271 1.1 thorpej }
272 1.1 thorpej #endif
273 1.1 thorpej
274 1.1 thorpej /* Map the Brooktree. */
275 1.16 pk if (obio_bus_map(oba->oba_bustag, oba->oba_paddr,
276 1.16 pk PFOUR_COLOR_OFF_CMAP,
277 1.16 pk sizeof(struct fbcontrol),
278 1.16 pk BUS_SPACE_MAP_LINEAR,
279 1.16 pk 0, &bh) != 0) {
280 1.16 pk printf("%s: cannot map control registers\n", self->dv_xname);
281 1.16 pk return;
282 1.16 pk }
283 1.16 pk sc->sc_fbc = (volatile struct fbcontrol *)bh;
284 1.1 thorpej
285 1.1 thorpej #if 0 /* XXX thorpej ??? */
286 1.1 thorpej /* tell the enable plane to look at the mono image */
287 1.1 thorpej memset(ca->ca_ra.ra_vaddr, 0xff,
288 1.1 thorpej sc->sc_fb.fb_type.fb_width * sc->sc_fb.fb_type.fb_height / 8);
289 1.1 thorpej #endif
290 1.1 thorpej
291 1.1 thorpej /* grab initial (current) color map */
292 1.1 thorpej bt = &sc->sc_fbc->fbc_dac;
293 1.1 thorpej bt->bt_addr = 0;
294 1.1 thorpej for (i = 0; i < 256 * 3 / 4; i++)
295 1.1 thorpej sc->sc_cmap.cm_chip[i] = bt->bt_cmap;
296 1.1 thorpej
297 1.1 thorpej BT_INIT(bt, 0);
298 1.1 thorpej
299 1.1 thorpej #if 0 /* see above */
300 1.1 thorpej if (isconsole) {
301 1.11 christos printf(" (console)\n");
302 1.1 thorpej #if defined(RASTERCONSOLE) && 0 /* XXX been told it doesn't work well. */
303 1.1 thorpej fbrcons_init(fb);
304 1.1 thorpej #endif
305 1.1 thorpej } else
306 1.1 thorpej #endif /* 0 */
307 1.11 christos printf("\n");
308 1.1 thorpej
309 1.1 thorpej /*
310 1.1 thorpej * Even though we're not using rconsole, we'd still like
311 1.1 thorpej * to notice if we're the console framebuffer.
312 1.1 thorpej */
313 1.1 thorpej fb_attach(&sc->sc_fb, isconsole);
314 1.6 pk #endif
315 1.1 thorpej }
316 1.1 thorpej
317 1.1 thorpej int
318 1.1 thorpej cgeightopen(dev, flags, mode, p)
319 1.1 thorpej dev_t dev;
320 1.1 thorpej int flags, mode;
321 1.1 thorpej struct proc *p;
322 1.1 thorpej {
323 1.1 thorpej int unit = minor(dev);
324 1.1 thorpej
325 1.5 thorpej if (unit >= cgeight_cd.cd_ndevs || cgeight_cd.cd_devs[unit] == NULL)
326 1.1 thorpej return (ENXIO);
327 1.1 thorpej return (0);
328 1.1 thorpej }
329 1.1 thorpej
330 1.1 thorpej int
331 1.1 thorpej cgeightclose(dev, flags, mode, p)
332 1.1 thorpej dev_t dev;
333 1.1 thorpej int flags, mode;
334 1.1 thorpej struct proc *p;
335 1.1 thorpej {
336 1.1 thorpej
337 1.1 thorpej return (0);
338 1.1 thorpej }
339 1.1 thorpej
340 1.1 thorpej int
341 1.1 thorpej cgeightioctl(dev, cmd, data, flags, p)
342 1.1 thorpej dev_t dev;
343 1.1 thorpej u_long cmd;
344 1.18 pk caddr_t data;
345 1.1 thorpej int flags;
346 1.1 thorpej struct proc *p;
347 1.1 thorpej {
348 1.6 pk #if defined(SUN4)
349 1.18 pk struct cgeight_softc *sc = cgeight_cd.cd_devs[minor(dev)];
350 1.18 pk struct fbgattr *fba;
351 1.1 thorpej int error;
352 1.1 thorpej
353 1.1 thorpej switch (cmd) {
354 1.1 thorpej
355 1.1 thorpej case FBIOGTYPE:
356 1.1 thorpej *(struct fbtype *)data = sc->sc_fb.fb_type;
357 1.1 thorpej break;
358 1.1 thorpej
359 1.1 thorpej case FBIOGATTR:
360 1.1 thorpej fba = (struct fbgattr *)data;
361 1.1 thorpej fba->real_type = sc->sc_fb.fb_type.fb_type;
362 1.1 thorpej fba->owner = 0; /* XXX ??? */
363 1.1 thorpej fba->fbtype = sc->sc_fb.fb_type;
364 1.1 thorpej fba->sattr.flags = 0;
365 1.1 thorpej fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
366 1.1 thorpej fba->sattr.dev_specific[0] = -1;
367 1.1 thorpej fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
368 1.1 thorpej fba->emu_types[1] = -1;
369 1.1 thorpej break;
370 1.1 thorpej
371 1.1 thorpej case FBIOGETCMAP:
372 1.21 pk #define p ((struct fbcmap *)data)
373 1.21 pk return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
374 1.1 thorpej
375 1.1 thorpej case FBIOPUTCMAP:
376 1.1 thorpej /* copy to software map */
377 1.21 pk error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
378 1.1 thorpej if (error)
379 1.1 thorpej return (error);
380 1.1 thorpej /* now blast them into the chip */
381 1.1 thorpej /* XXX should use retrace interrupt */
382 1.1 thorpej cgeightloadcmap(sc, p->index, p->count);
383 1.1 thorpej #undef p
384 1.1 thorpej break;
385 1.1 thorpej
386 1.1 thorpej case FBIOGVIDEO:
387 1.1 thorpej *(int *)data = cgeight_get_video(sc);
388 1.1 thorpej break;
389 1.1 thorpej
390 1.1 thorpej case FBIOSVIDEO:
391 1.1 thorpej cgeight_set_video(sc, *(int *)data);
392 1.1 thorpej break;
393 1.1 thorpej
394 1.1 thorpej default:
395 1.1 thorpej return (ENOTTY);
396 1.1 thorpej }
397 1.6 pk #endif
398 1.1 thorpej return (0);
399 1.9 thorpej }
400 1.9 thorpej
401 1.9 thorpej int
402 1.9 thorpej cgeightpoll(dev, events, p)
403 1.9 thorpej dev_t dev;
404 1.9 thorpej int events;
405 1.9 thorpej struct proc *p;
406 1.9 thorpej {
407 1.9 thorpej
408 1.9 thorpej return (seltrue(dev, events, p));
409 1.1 thorpej }
410 1.1 thorpej
411 1.1 thorpej /*
412 1.1 thorpej * Return the address that would map the given device at the given
413 1.1 thorpej * offset, allowing for the given protection, or return -1 for error.
414 1.1 thorpej *
415 1.1 thorpej * The cg8 maps it's overlay plane at 0 for 128K, followed by the
416 1.1 thorpej * enable plane for 128K, followed by the colour for as long as it
417 1.1 thorpej * goes. Starting at 8MB, it maps the ramdac for NBPG, then the p4
418 1.1 thorpej * register for NBPG, then the bootrom for 0x40000.
419 1.1 thorpej */
420 1.22 simonb paddr_t
421 1.1 thorpej cgeightmmap(dev, off, prot)
422 1.1 thorpej dev_t dev;
423 1.22 simonb off_t off;
424 1.22 simonb int prot;
425 1.1 thorpej {
426 1.18 pk struct cgeight_softc *sc = cgeight_cd.cd_devs[minor(dev)];
427 1.18 pk bus_space_handle_t bh;
428 1.22 simonb off_t poff;
429 1.1 thorpej
430 1.1 thorpej #define START_ENABLE (128*1024)
431 1.1 thorpej #define START_COLOR ((128*1024) + (128*1024))
432 1.1 thorpej #define COLOR_SIZE (sc->sc_fb.fb_type.fb_width * \
433 1.1 thorpej sc->sc_fb.fb_type.fb_height * 3)
434 1.1 thorpej #define END_COLOR (START_COLOR + COLOR_SIZE)
435 1.1 thorpej #define START_SPECIAL 0x800000
436 1.1 thorpej #define PROMSIZE 0x40000
437 1.1 thorpej #define NOOVERLAY (0x04000000)
438 1.1 thorpej
439 1.1 thorpej if (off & PGOFSET)
440 1.1 thorpej panic("cgeightmap");
441 1.1 thorpej
442 1.19 mrg if (off < 0)
443 1.19 mrg return (-1);
444 1.19 mrg else if ((u_int)off >= NOOVERLAY) {
445 1.8 thorpej off -= NOOVERLAY;
446 1.1 thorpej
447 1.1 thorpej /*
448 1.1 thorpej * X11 maps a huge chunk of the frame buffer; far more than
449 1.1 thorpej * there really is. We compensate by double-mapping the
450 1.1 thorpej * first page for as many other pages as it wants
451 1.1 thorpej */
452 1.19 mrg while ((u_int)off >= COLOR_SIZE)
453 1.1 thorpej off -= COLOR_SIZE; /* XXX thorpej ??? */
454 1.1 thorpej
455 1.1 thorpej poff = off + PFOUR_COLOR_OFF_COLOR;
456 1.1 thorpej } else if ((u_int)off < START_ENABLE) {
457 1.1 thorpej /*
458 1.1 thorpej * in overlay plane
459 1.1 thorpej */
460 1.1 thorpej poff = PFOUR_COLOR_OFF_OVERLAY + off;
461 1.1 thorpej } else if ((u_int)off < START_COLOR) {
462 1.1 thorpej /*
463 1.1 thorpej * in enable plane
464 1.1 thorpej */
465 1.1 thorpej poff = (off - START_ENABLE) + PFOUR_COLOR_OFF_ENABLE;
466 1.8 thorpej } else if ((u_int)off < sc->sc_fb.fb_type.fb_size) {
467 1.1 thorpej /*
468 1.1 thorpej * in colour plane
469 1.6 pk */
470 1.1 thorpej poff = (off - START_COLOR) + PFOUR_COLOR_OFF_COLOR;
471 1.1 thorpej } else if ((u_int)off < START_SPECIAL) {
472 1.1 thorpej /*
473 1.1 thorpej * hole
474 1.1 thorpej */
475 1.1 thorpej poff = 0; /* XXX */
476 1.1 thorpej } else if ((u_int)off == START_SPECIAL) {
477 1.1 thorpej /*
478 1.1 thorpej * colour map (Brooktree)
479 1.1 thorpej */
480 1.1 thorpej poff = PFOUR_COLOR_OFF_CMAP;
481 1.1 thorpej } else if ((u_int)off == START_SPECIAL + NBPG) {
482 1.1 thorpej /*
483 1.1 thorpej * p4 register
484 1.1 thorpej */
485 1.1 thorpej poff = 0;
486 1.1 thorpej } else if ((u_int)off > (START_SPECIAL + (NBPG * 2)) &&
487 1.1 thorpej (u_int) off < (START_SPECIAL + (NBPG * 2) + PROMSIZE)) {
488 1.1 thorpej /*
489 1.1 thorpej * rom
490 1.1 thorpej */
491 1.1 thorpej poff = 0x8000 + (off - (START_SPECIAL + (NBPG * 2)));
492 1.1 thorpej } else
493 1.1 thorpej return (-1);
494 1.16 pk
495 1.18 pk if (bus_space_mmap(sc->sc_bustag,
496 1.18 pk sc->sc_btype,
497 1.18 pk sc->sc_paddr + poff,
498 1.18 pk BUS_SPACE_MAP_LINEAR, &bh))
499 1.18 pk return (-1);
500 1.18 pk
501 1.22 simonb return ((paddr_t)bh);
502 1.1 thorpej }
503 1.1 thorpej
504 1.6 pk #if defined(SUN4)
505 1.6 pk /*
506 1.6 pk * Undo the effect of an FBIOSVIDEO that turns the video off.
507 1.6 pk */
508 1.6 pk static void
509 1.6 pk cgeightunblank(dev)
510 1.6 pk struct device *dev;
511 1.6 pk {
512 1.6 pk
513 1.6 pk cgeight_set_video((struct cgeight_softc *)dev, 1);
514 1.6 pk }
515 1.6 pk
516 1.1 thorpej static int
517 1.1 thorpej cgeight_get_video(sc)
518 1.1 thorpej struct cgeight_softc *sc;
519 1.1 thorpej {
520 1.1 thorpej
521 1.1 thorpej return (fb_pfour_get_video(&sc->sc_fb));
522 1.1 thorpej }
523 1.1 thorpej
524 1.1 thorpej static void
525 1.1 thorpej cgeight_set_video(sc, enable)
526 1.1 thorpej struct cgeight_softc *sc;
527 1.1 thorpej int enable;
528 1.1 thorpej {
529 1.1 thorpej
530 1.1 thorpej fb_pfour_set_video(&sc->sc_fb, enable);
531 1.1 thorpej }
532 1.6 pk
533 1.6 pk /*
534 1.6 pk * Load a subset of the current (new) colormap into the Brooktree DAC.
535 1.6 pk */
536 1.6 pk static void
537 1.6 pk cgeightloadcmap(sc, start, ncolors)
538 1.6 pk register struct cgeight_softc *sc;
539 1.6 pk register int start, ncolors;
540 1.6 pk {
541 1.18 pk volatile struct bt_regs *bt;
542 1.18 pk u_int *ip;
543 1.18 pk int count;
544 1.6 pk
545 1.6 pk ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)]; /* start/4 * 3 */
546 1.6 pk count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
547 1.6 pk bt = &sc->sc_fbc->fbc_dac;
548 1.6 pk bt->bt_addr = BT_D4M4(start);
549 1.6 pk while (--count >= 0)
550 1.6 pk bt->bt_cmap = *ip++;
551 1.6 pk }
552 1.6 pk #endif
553