tcx.c revision 1.21 1 1.21 christos /* $NetBSD: tcx.c,v 1.21 2007/03/04 06:02:41 christos Exp $ */
2 1.1 pk
3 1.1 pk /*
4 1.1 pk * Copyright (c) 1996,1998 The NetBSD Foundation, Inc.
5 1.1 pk * All rights reserved.
6 1.1 pk *
7 1.1 pk * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pk * by Paul Kranenburg.
9 1.1 pk *
10 1.1 pk * Redistribution and use in source and binary forms, with or without
11 1.1 pk * modification, are permitted provided that the following conditions
12 1.1 pk * are met:
13 1.1 pk * 1. Redistributions of source code must retain the above copyright
14 1.1 pk * notice, this list of conditions and the following disclaimer.
15 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pk * notice, this list of conditions and the following disclaimer in the
17 1.1 pk * documentation and/or other materials provided with the distribution.
18 1.1 pk * 3. All advertising materials mentioning features or use of this software
19 1.1 pk * must display the following acknowledgement:
20 1.1 pk * This product includes software developed by the NetBSD
21 1.1 pk * Foundation, Inc. and its contributors.
22 1.1 pk * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 pk * contributors may be used to endorse or promote products derived
24 1.1 pk * from this software without specific prior written permission.
25 1.1 pk *
26 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
37 1.1 pk */
38 1.1 pk
39 1.1 pk /*
40 1.1 pk * color display (TCX) driver.
41 1.1 pk *
42 1.1 pk * Does not handle interrupts, even though they can occur.
43 1.1 pk *
44 1.1 pk * XXX should defer colormap updates to vertical retrace interrupts
45 1.1 pk */
46 1.4 lukem
47 1.4 lukem #include <sys/cdefs.h>
48 1.21 christos __KERNEL_RCSID(0, "$NetBSD: tcx.c,v 1.21 2007/03/04 06:02:41 christos Exp $");
49 1.7 darrenr
50 1.7 darrenr /*
51 1.7 darrenr * define for cg8 emulation on S24 (24-bit version of tcx) for the SS5;
52 1.7 darrenr * it is bypassed on the 8-bit version (onboard framebuffer for SS4)
53 1.7 darrenr */
54 1.7 darrenr #undef TCX_CG8
55 1.1 pk
56 1.1 pk #include <sys/param.h>
57 1.1 pk #include <sys/systm.h>
58 1.1 pk #include <sys/buf.h>
59 1.1 pk #include <sys/device.h>
60 1.1 pk #include <sys/ioctl.h>
61 1.1 pk #include <sys/malloc.h>
62 1.1 pk #include <sys/mman.h>
63 1.1 pk #include <sys/tty.h>
64 1.1 pk #include <sys/conf.h>
65 1.1 pk
66 1.1 pk #ifdef DEBUG
67 1.1 pk #include <sys/proc.h>
68 1.1 pk #include <sys/syslog.h>
69 1.1 pk #endif
70 1.1 pk
71 1.1 pk #include <machine/bus.h>
72 1.1 pk #include <machine/autoconf.h>
73 1.1 pk
74 1.1 pk #include <dev/sun/fbio.h>
75 1.1 pk #include <dev/sun/fbvar.h>
76 1.1 pk #include <dev/sun/btreg.h>
77 1.1 pk #include <dev/sun/btvar.h>
78 1.2 pk
79 1.2 pk #include <dev/sbus/sbusvar.h>
80 1.2 pk #include <dev/sbus/tcxreg.h>
81 1.1 pk
82 1.1 pk /* per-display variables */
83 1.1 pk struct tcx_softc {
84 1.1 pk struct device sc_dev; /* base device */
85 1.1 pk struct sbusdev sc_sd; /* sbus device */
86 1.1 pk struct fbdevice sc_fb; /* frame buffer device */
87 1.1 pk bus_space_tag_t sc_bustag;
88 1.8 thorpej struct openprom_addr sc_physadr[TCX_NREG];/* phys addr of h/w */
89 1.1 pk
90 1.1 pk volatile struct bt_regs *sc_bt; /* Brooktree registers */
91 1.1 pk volatile struct tcx_thc *sc_thc;/* THC registers */
92 1.7 darrenr #ifdef TCX_CG8
93 1.7 darrenr volatile ulong *sc_cplane; /* framebuffer with control planes */
94 1.7 darrenr #endif
95 1.7 darrenr short sc_8bit; /* true if 8-bit hardware */
96 1.1 pk short sc_blanked; /* true if blanked */
97 1.1 pk union bt_cmap sc_cmap; /* Brooktree color map */
98 1.1 pk };
99 1.1 pk
100 1.7 darrenr /*
101 1.7 darrenr * The S24 provides the framebuffer RAM mapped in three ways:
102 1.7 darrenr * 26 bits per pixel, in 32-bit words; the low-order 24 bits are
103 1.7 darrenr * blue, green, and red values, and the other two bits select the
104 1.7 darrenr * display modes, per pixel);
105 1.7 darrenr * 24 bits per pixel, in 32-bit words; the high-order byte reads as
106 1.7 darrenr * zero, and is ignored on writes (so the mode bits cannot be altered);
107 1.7 darrenr * 8 bits per pixel, unpadded; writes to this space do not modify the
108 1.7 darrenr * other 18 bits.
109 1.7 darrenr */
110 1.7 darrenr #define TCX_CTL_8_MAPPED 0x00000000 /* 8 bits, uses color map */
111 1.7 darrenr #define TCX_CTL_24_MAPPED 0x01000000 /* 24 bits, uses color map */
112 1.7 darrenr #define TCX_CTL_24_LEVEL 0x03000000 /* 24 bits, ignores color map */
113 1.7 darrenr #define TCX_CTL_PIXELMASK 0x00FFFFFF /* mask for index/level */
114 1.7 darrenr
115 1.1 pk /* autoconfiguration driver */
116 1.17 perry static void tcxattach(struct device *, struct device *, void *);
117 1.17 perry static int tcxmatch(struct device *, struct cfdata *, void *);
118 1.17 perry static void tcx_unblank(struct device *);
119 1.1 pk
120 1.11 thorpej CFATTACH_DECL(tcx, sizeof(struct tcx_softc),
121 1.12 thorpej tcxmatch, tcxattach, NULL, NULL);
122 1.1 pk
123 1.1 pk extern struct cfdriver tcx_cd;
124 1.1 pk
125 1.9 gehenna dev_type_open(tcxopen);
126 1.9 gehenna dev_type_close(tcxclose);
127 1.9 gehenna dev_type_ioctl(tcxioctl);
128 1.9 gehenna dev_type_mmap(tcxmmap);
129 1.9 gehenna
130 1.9 gehenna const struct cdevsw tcx_cdevsw = {
131 1.9 gehenna tcxopen, tcxclose, noread, nowrite, tcxioctl,
132 1.13 jdolecek nostop, notty, nopoll, tcxmmap, nokqfilter,
133 1.9 gehenna };
134 1.9 gehenna
135 1.1 pk /* frame buffer generic driver */
136 1.1 pk static struct fbdriver tcx_fbdriver = {
137 1.13 jdolecek tcx_unblank, tcxopen, tcxclose, tcxioctl, nopoll, tcxmmap,
138 1.13 jdolecek nokqfilter
139 1.1 pk };
140 1.1 pk
141 1.17 perry static void tcx_reset(struct tcx_softc *);
142 1.17 perry static void tcx_loadcmap(struct tcx_softc *, int, int);
143 1.1 pk
144 1.1 pk #define OBPNAME "SUNW,tcx"
145 1.7 darrenr
146 1.7 darrenr #ifdef TCX_CG8
147 1.7 darrenr /*
148 1.7 darrenr * For CG8 emulation, we map the 32-bit-deep framebuffer at an offset of
149 1.7 darrenr * 256K; the cg8 space begins with a mono overlay plane and an overlay
150 1.7 darrenr * enable plane (128K bytes each, 1 bit per pixel), immediately followed
151 1.7 darrenr * by the color planes, 32 bits per pixel. We also map just the 32-bit
152 1.7 darrenr * framebuffer at 0x04000000 (TCX_USER_RAM_COMPAT), for compatibility
153 1.7 darrenr * with the cg8 driver.
154 1.7 darrenr */
155 1.7 darrenr #define TCX_CG8OVERLAY (256 * 1024)
156 1.7 darrenr #define TCX_SIZE_DFB32 (1152 * 900 * 4) /* max size of the framebuffer */
157 1.7 darrenr #endif
158 1.7 darrenr
159 1.1 pk /*
160 1.1 pk * Match a tcx.
161 1.1 pk */
162 1.1 pk int
163 1.1 pk tcxmatch(parent, cf, aux)
164 1.1 pk struct device *parent;
165 1.1 pk struct cfdata *cf;
166 1.1 pk void *aux;
167 1.1 pk {
168 1.1 pk struct sbus_attach_args *sa = aux;
169 1.1 pk
170 1.1 pk return (strcmp(sa->sa_name, OBPNAME) == 0);
171 1.1 pk }
172 1.1 pk
173 1.1 pk /*
174 1.1 pk * Attach a display.
175 1.1 pk */
176 1.1 pk void
177 1.1 pk tcxattach(parent, self, args)
178 1.1 pk struct device *parent, *self;
179 1.1 pk void *args;
180 1.1 pk {
181 1.1 pk struct tcx_softc *sc = (struct tcx_softc *)self;
182 1.1 pk struct sbus_attach_args *sa = args;
183 1.1 pk int node, ramsize;
184 1.1 pk volatile struct bt_regs *bt;
185 1.1 pk struct fbdevice *fb = &sc->sc_fb;
186 1.1 pk bus_space_handle_t bh;
187 1.1 pk int isconsole;
188 1.1 pk
189 1.1 pk sc->sc_bustag = sa->sa_bustag;
190 1.1 pk node = sa->sa_node;
191 1.1 pk
192 1.1 pk fb->fb_driver = &tcx_fbdriver;
193 1.1 pk fb->fb_device = &sc->sc_dev;
194 1.1 pk /* Mask out invalid flags from the user. */
195 1.19 thorpej fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags & FB_USERMASK;
196 1.7 darrenr /*
197 1.7 darrenr * The onboard framebuffer on the SS4 supports only 8-bit mode;
198 1.7 darrenr * it can be distinguished from the S24 card for the SS5 by the
199 1.7 darrenr * presence of the "tcx-8-bit" attribute on the SS4 version.
200 1.7 darrenr */
201 1.7 darrenr sc->sc_8bit = node_has_property(node, "tcx-8-bit");
202 1.7 darrenr #ifdef TCX_CG8
203 1.7 darrenr if (sc->sc_8bit) {
204 1.7 darrenr #endif
205 1.7 darrenr /*
206 1.7 darrenr * cg8 emulation is either not compiled in or not supported
207 1.7 darrenr * on this hardware. Report values for the 8-bit framebuffer
208 1.7 darrenr * so cg3 emulation works. (If this hardware supports
209 1.7 darrenr * 24-bit mode, the 24-bit framebuffer will also be available)
210 1.7 darrenr */
211 1.7 darrenr fb->fb_type.fb_depth = 8;
212 1.7 darrenr fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
213 1.7 darrenr
214 1.7 darrenr ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
215 1.7 darrenr #ifdef TCX_CG8
216 1.7 darrenr } else {
217 1.7 darrenr /*
218 1.7 darrenr * for cg8 emulation, unconditionally report the depth as
219 1.7 darrenr * 32 bits, but use the height and width reported by the
220 1.7 darrenr * boot prom. cg8 users want to see the full size of
221 1.7 darrenr * overlay planes plus color planes included in the
222 1.7 darrenr * reported framebuffer size.
223 1.7 darrenr */
224 1.7 darrenr fb->fb_type.fb_depth = 32;
225 1.7 darrenr fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
226 1.7 darrenr fb->fb_linebytes =
227 1.7 darrenr (fb->fb_type.fb_width * fb->fb_type.fb_depth) / 8;
228 1.7 darrenr ramsize = TCX_CG8OVERLAY +
229 1.7 darrenr (fb->fb_type.fb_height * fb->fb_linebytes);
230 1.7 darrenr }
231 1.7 darrenr #endif
232 1.1 pk fb->fb_type.fb_cmsize = 256;
233 1.1 pk fb->fb_type.fb_size = ramsize;
234 1.1 pk printf(": %s, %d x %d", OBPNAME,
235 1.1 pk fb->fb_type.fb_width,
236 1.1 pk fb->fb_type.fb_height);
237 1.7 darrenr #ifdef TCX_CG8
238 1.7 darrenr /*
239 1.7 darrenr * if cg8 emulation is enabled, say so; but if hardware can't
240 1.7 darrenr * emulate cg8, explain that instead
241 1.7 darrenr */
242 1.7 darrenr printf( (sc->sc_8bit)?
243 1.7 darrenr " (8-bit only)" :
244 1.7 darrenr " (emulating cg8)");
245 1.7 darrenr #endif
246 1.1 pk
247 1.1 pk /*
248 1.1 pk * XXX - should be set to FBTYPE_TCX.
249 1.1 pk * XXX For CG3 emulation to work in current (96/6) X11 servers,
250 1.1 pk * XXX `fbtype' must point to an "unregocnised" entry.
251 1.1 pk */
252 1.7 darrenr #ifdef TCX_CG8
253 1.7 darrenr if (sc->sc_8bit) {
254 1.7 darrenr fb->fb_type.fb_type = FBTYPE_RESERVED3;
255 1.7 darrenr } else {
256 1.7 darrenr fb->fb_type.fb_type = FBTYPE_MEMCOLOR;
257 1.7 darrenr }
258 1.7 darrenr #else
259 1.1 pk fb->fb_type.fb_type = FBTYPE_RESERVED3;
260 1.7 darrenr #endif
261 1.1 pk
262 1.1 pk
263 1.1 pk if (sa->sa_nreg != TCX_NREG) {
264 1.1 pk printf("%s: only %d register sets\n",
265 1.1 pk self->dv_xname, sa->sa_nreg);
266 1.1 pk return;
267 1.1 pk }
268 1.1 pk bcopy(sa->sa_reg, sc->sc_physadr,
269 1.8 thorpej sa->sa_nreg * sizeof(struct openprom_addr));
270 1.1 pk
271 1.1 pk /* XXX - fix THC and TEC offsets */
272 1.8 thorpej sc->sc_physadr[TCX_REG_TEC].oa_base += 0x1000;
273 1.8 thorpej sc->sc_physadr[TCX_REG_THC].oa_base += 0x1000;
274 1.1 pk
275 1.1 pk /* Map the register banks we care about */
276 1.1 pk if (sbus_bus_map(sa->sa_bustag,
277 1.8 thorpej sc->sc_physadr[TCX_REG_THC].oa_space,
278 1.8 thorpej sc->sc_physadr[TCX_REG_THC].oa_base,
279 1.1 pk sizeof (struct tcx_thc),
280 1.5 pk BUS_SPACE_MAP_LINEAR, &bh) != 0) {
281 1.1 pk printf("tcxattach: cannot map thc registers\n");
282 1.1 pk return;
283 1.1 pk }
284 1.6 eeh sc->sc_thc = (volatile struct tcx_thc *)
285 1.6 eeh bus_space_vaddr(sa->sa_bustag, bh);
286 1.1 pk
287 1.1 pk if (sbus_bus_map(sa->sa_bustag,
288 1.8 thorpej sc->sc_physadr[TCX_REG_CMAP].oa_space,
289 1.8 thorpej sc->sc_physadr[TCX_REG_CMAP].oa_base,
290 1.1 pk sizeof (struct bt_regs),
291 1.5 pk BUS_SPACE_MAP_LINEAR, &bh) != 0) {
292 1.1 pk printf("tcxattach: cannot map bt registers\n");
293 1.1 pk return;
294 1.1 pk }
295 1.6 eeh sc->sc_bt = bt = (volatile struct bt_regs *)
296 1.6 eeh bus_space_vaddr(sa->sa_bustag, bh);
297 1.1 pk
298 1.7 darrenr #ifdef TCX_CG8
299 1.7 darrenr if (!sc->sc_8bit) {
300 1.7 darrenr if (sbus_bus_map(sa->sa_bustag,
301 1.16 pk sc->sc_physadr[TCX_REG_RDFB32].oa_space,
302 1.16 pk sc->sc_physadr[TCX_REG_RDFB32].oa_base,
303 1.7 darrenr TCX_SIZE_DFB32,
304 1.7 darrenr BUS_SPACE_MAP_LINEAR,
305 1.16 pk &bh) != 0) {
306 1.7 darrenr printf("tcxattach: cannot map control planes\n");
307 1.7 darrenr return;
308 1.7 darrenr }
309 1.7 darrenr sc->sc_cplane = (volatile ulong *)bh;
310 1.7 darrenr }
311 1.7 darrenr #endif
312 1.7 darrenr
313 1.1 pk isconsole = fb_is_console(node);
314 1.1 pk
315 1.1 pk printf(", id %d, rev %d, sense %d",
316 1.1 pk (sc->sc_thc->thc_config & THC_CFG_FBID) >> THC_CFG_FBID_SHIFT,
317 1.1 pk (sc->sc_thc->thc_config & THC_CFG_REV) >> THC_CFG_REV_SHIFT,
318 1.1 pk (sc->sc_thc->thc_config & THC_CFG_SENSE) >> THC_CFG_SENSE_SHIFT
319 1.1 pk );
320 1.1 pk
321 1.1 pk /* reset cursor & frame buffer controls */
322 1.1 pk tcx_reset(sc);
323 1.1 pk
324 1.1 pk /* Initialize the default color map. */
325 1.1 pk bt_initcmap(&sc->sc_cmap, 256);
326 1.1 pk tcx_loadcmap(sc, 0, 256);
327 1.1 pk
328 1.1 pk /* enable video */
329 1.1 pk sc->sc_thc->thc_hcmisc |= THC_MISC_VIDEN;
330 1.1 pk
331 1.1 pk if (isconsole) {
332 1.1 pk printf(" (console)\n");
333 1.1 pk } else
334 1.1 pk printf("\n");
335 1.1 pk
336 1.1 pk sbus_establish(&sc->sc_sd, &sc->sc_dev);
337 1.1 pk fb_attach(&sc->sc_fb, isconsole);
338 1.1 pk }
339 1.1 pk
340 1.7 darrenr #ifdef TCX_CG8
341 1.7 darrenr /*
342 1.7 darrenr * keep track of the number of opens, so we can switch to 24-bit mode
343 1.7 darrenr * when the device is first opened, and return to 8-bit mode on the
344 1.7 darrenr * last close. (stolen from cgfourteen driver...) There can only be
345 1.7 darrenr * one TCX per system, so we only need one flag.
346 1.7 darrenr */
347 1.7 darrenr static int tcx_opens = 0;
348 1.7 darrenr #endif
349 1.7 darrenr
350 1.1 pk int
351 1.18 christos tcxopen(dev, flags, mode, l)
352 1.1 pk dev_t dev;
353 1.1 pk int flags, mode;
354 1.18 christos struct lwp *l;
355 1.1 pk {
356 1.1 pk int unit = minor(dev);
357 1.7 darrenr #ifdef TCX_CG8
358 1.7 darrenr struct tcx_softc *sc;
359 1.7 darrenr int i, s, oldopens;
360 1.7 darrenr volatile ulong *cptr;
361 1.7 darrenr struct fbdevice *fb;
362 1.7 darrenr #endif
363 1.1 pk
364 1.1 pk if (unit >= tcx_cd.cd_ndevs || tcx_cd.cd_devs[unit] == NULL)
365 1.1 pk return (ENXIO);
366 1.7 darrenr #ifdef TCX_CG8
367 1.7 darrenr sc = tcx_cd.cd_devs[unit];
368 1.7 darrenr if (!sc->sc_8bit) {
369 1.7 darrenr s = splhigh();
370 1.7 darrenr oldopens = tcx_opens++;
371 1.7 darrenr splx(s);
372 1.7 darrenr if (oldopens == 0) {
373 1.7 darrenr /*
374 1.7 darrenr * rewrite the control planes to select 24-bit mode
375 1.7 darrenr * and clear the screen
376 1.7 darrenr */
377 1.7 darrenr fb = &sc->sc_fb;
378 1.7 darrenr i = fb->fb_type.fb_height * fb->fb_type.fb_width;
379 1.7 darrenr cptr = sc->sc_cplane;
380 1.7 darrenr while (--i >= 0)
381 1.7 darrenr *cptr++ = TCX_CTL_24_LEVEL;
382 1.7 darrenr }
383 1.7 darrenr }
384 1.7 darrenr #endif
385 1.1 pk return (0);
386 1.1 pk }
387 1.1 pk
388 1.1 pk int
389 1.18 christos tcxclose(dev, flags, mode, l)
390 1.1 pk dev_t dev;
391 1.1 pk int flags, mode;
392 1.18 christos struct lwp *l;
393 1.1 pk {
394 1.1 pk struct tcx_softc *sc = tcx_cd.cd_devs[minor(dev)];
395 1.7 darrenr #ifdef TCX_CG8
396 1.7 darrenr int i, s, opens;
397 1.7 darrenr volatile ulong *cptr;
398 1.7 darrenr struct fbdevice *fb;
399 1.7 darrenr #endif
400 1.1 pk
401 1.1 pk tcx_reset(sc);
402 1.7 darrenr #ifdef TCX_CG8
403 1.7 darrenr if (!sc->sc_8bit) {
404 1.7 darrenr s = splhigh();
405 1.7 darrenr opens = --tcx_opens;
406 1.7 darrenr if (tcx_opens <= 0)
407 1.7 darrenr opens = tcx_opens = 0;
408 1.7 darrenr splx(s);
409 1.7 darrenr if (opens == 0) {
410 1.7 darrenr /*
411 1.7 darrenr * rewrite the control planes to select 8-bit mode,
412 1.7 darrenr * preserving the contents of the screen.
413 1.7 darrenr * (or we could just bzero the whole thing...)
414 1.7 darrenr */
415 1.7 darrenr fb = &sc->sc_fb;
416 1.7 darrenr i = fb->fb_type.fb_height * fb->fb_type.fb_width;
417 1.7 darrenr cptr = sc->sc_cplane;
418 1.7 darrenr while (--i >= 0)
419 1.7 darrenr *cptr++ &= TCX_CTL_PIXELMASK;
420 1.7 darrenr }
421 1.7 darrenr }
422 1.7 darrenr #endif
423 1.1 pk return (0);
424 1.1 pk }
425 1.1 pk
426 1.1 pk int
427 1.18 christos tcxioctl(dev, cmd, data, flags, l)
428 1.1 pk dev_t dev;
429 1.1 pk u_long cmd;
430 1.21 christos void *data;
431 1.1 pk int flags;
432 1.18 christos struct lwp *l;
433 1.1 pk {
434 1.1 pk struct tcx_softc *sc = tcx_cd.cd_devs[minor(dev)];
435 1.1 pk int error;
436 1.1 pk
437 1.1 pk switch (cmd) {
438 1.1 pk
439 1.1 pk case FBIOGTYPE:
440 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
441 1.1 pk break;
442 1.1 pk
443 1.1 pk case FBIOGATTR:
444 1.1 pk #define fba ((struct fbgattr *)data)
445 1.1 pk fba->real_type = sc->sc_fb.fb_type.fb_type;
446 1.1 pk fba->owner = 0; /* XXX ??? */
447 1.1 pk fba->fbtype = sc->sc_fb.fb_type;
448 1.1 pk fba->sattr.flags = 0;
449 1.1 pk fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
450 1.1 pk fba->sattr.dev_specific[0] = -1;
451 1.1 pk fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
452 1.1 pk fba->emu_types[1] = FBTYPE_SUN3COLOR;
453 1.1 pk fba->emu_types[2] = -1;
454 1.1 pk #undef fba
455 1.1 pk break;
456 1.1 pk
457 1.1 pk case FBIOGETCMAP:
458 1.1 pk #define p ((struct fbcmap *)data)
459 1.1 pk return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
460 1.1 pk
461 1.1 pk case FBIOPUTCMAP:
462 1.1 pk /* copy to software map */
463 1.7 darrenr #ifdef TCX_CG8
464 1.7 darrenr if (!sc->sc_8bit) {
465 1.7 darrenr /*
466 1.7 darrenr * cg8 has extra bits in high-order byte of the index
467 1.7 darrenr * that bt_putcmap doesn't recognize
468 1.7 darrenr */
469 1.7 darrenr p->index &= 0xffffff;
470 1.7 darrenr }
471 1.7 darrenr #endif
472 1.1 pk error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
473 1.1 pk if (error)
474 1.1 pk return (error);
475 1.1 pk /* now blast them into the chip */
476 1.1 pk /* XXX should use retrace interrupt */
477 1.1 pk tcx_loadcmap(sc, p->index, p->count);
478 1.1 pk #undef p
479 1.1 pk break;
480 1.1 pk
481 1.1 pk case FBIOGVIDEO:
482 1.1 pk *(int *)data = sc->sc_blanked;
483 1.1 pk break;
484 1.1 pk
485 1.1 pk case FBIOSVIDEO:
486 1.1 pk if (*(int *)data)
487 1.1 pk tcx_unblank(&sc->sc_dev);
488 1.1 pk else if (!sc->sc_blanked) {
489 1.1 pk sc->sc_blanked = 1;
490 1.1 pk sc->sc_thc->thc_hcmisc &= ~THC_MISC_VIDEN;
491 1.1 pk /* Put monitor in `power-saving mode' */
492 1.1 pk sc->sc_thc->thc_hcmisc |= THC_MISC_VSYNC_DISABLE;
493 1.1 pk sc->sc_thc->thc_hcmisc |= THC_MISC_HSYNC_DISABLE;
494 1.1 pk }
495 1.1 pk break;
496 1.1 pk
497 1.1 pk default:
498 1.1 pk #ifdef DEBUG
499 1.1 pk log(LOG_NOTICE, "tcxioctl(0x%lx) (%s[%d])\n", cmd,
500 1.20 jdc l->l_proc->p_comm, l->l_proc->p_pid);
501 1.1 pk #endif
502 1.1 pk return (ENOTTY);
503 1.1 pk }
504 1.1 pk return (0);
505 1.1 pk }
506 1.1 pk
507 1.1 pk /*
508 1.1 pk * Clean up hardware state (e.g., after bootup or after X crashes).
509 1.1 pk */
510 1.1 pk static void
511 1.1 pk tcx_reset(sc)
512 1.1 pk struct tcx_softc *sc;
513 1.1 pk {
514 1.1 pk volatile struct bt_regs *bt;
515 1.1 pk
516 1.1 pk /* Enable cursor in Brooktree DAC. */
517 1.1 pk bt = sc->sc_bt;
518 1.1 pk bt->bt_addr = 0x06 << 24;
519 1.1 pk bt->bt_ctrl |= 0x03 << 24;
520 1.1 pk }
521 1.1 pk
522 1.1 pk /*
523 1.1 pk * Load a subset of the current (new) colormap into the color DAC.
524 1.1 pk */
525 1.1 pk static void
526 1.1 pk tcx_loadcmap(sc, start, ncolors)
527 1.1 pk struct tcx_softc *sc;
528 1.1 pk int start, ncolors;
529 1.1 pk {
530 1.1 pk volatile struct bt_regs *bt;
531 1.1 pk u_int *ip, i;
532 1.1 pk int count;
533 1.1 pk
534 1.1 pk ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)]; /* start/4 * 3 */
535 1.1 pk count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
536 1.1 pk bt = sc->sc_bt;
537 1.1 pk bt->bt_addr = BT_D4M4(start) << 24;
538 1.1 pk while (--count >= 0) {
539 1.1 pk i = *ip++;
540 1.1 pk /* hardware that makes one want to pound boards with hammers */
541 1.1 pk bt->bt_cmap = i;
542 1.1 pk bt->bt_cmap = i << 8;
543 1.1 pk bt->bt_cmap = i << 16;
544 1.1 pk bt->bt_cmap = i << 24;
545 1.1 pk }
546 1.1 pk }
547 1.1 pk
548 1.1 pk static void
549 1.1 pk tcx_unblank(dev)
550 1.1 pk struct device *dev;
551 1.1 pk {
552 1.1 pk struct tcx_softc *sc = (struct tcx_softc *)dev;
553 1.1 pk
554 1.1 pk if (sc->sc_blanked) {
555 1.1 pk sc->sc_blanked = 0;
556 1.1 pk sc->sc_thc->thc_hcmisc &= ~THC_MISC_VSYNC_DISABLE;
557 1.1 pk sc->sc_thc->thc_hcmisc &= ~THC_MISC_HSYNC_DISABLE;
558 1.1 pk sc->sc_thc->thc_hcmisc |= THC_MISC_VIDEN;
559 1.1 pk }
560 1.1 pk }
561 1.1 pk
562 1.1 pk /*
563 1.1 pk * Base addresses at which users can mmap() the various pieces of a tcx.
564 1.1 pk */
565 1.1 pk #define TCX_USER_RAM 0x00000000
566 1.1 pk #define TCX_USER_RAM24 0x01000000
567 1.1 pk #define TCX_USER_RAM_COMPAT 0x04000000 /* cg3 emulation */
568 1.1 pk #define TCX_USER_STIP 0x10000000
569 1.1 pk #define TCX_USER_BLIT 0x20000000
570 1.1 pk #define TCX_USER_RDFB32 0x28000000
571 1.1 pk #define TCX_USER_RSTIP 0x30000000
572 1.1 pk #define TCX_USER_RBLIT 0x38000000
573 1.1 pk #define TCX_USER_TEC 0x70001000
574 1.1 pk #define TCX_USER_BTREGS 0x70002000
575 1.1 pk #define TCX_USER_THC 0x70004000
576 1.1 pk #define TCX_USER_DHC 0x70008000
577 1.1 pk #define TCX_USER_ALT 0x7000a000
578 1.1 pk #define TCX_USER_UART 0x7000c000
579 1.1 pk #define TCX_USER_VRT 0x7000e000
580 1.1 pk #define TCX_USER_ROM 0x70010000
581 1.1 pk
582 1.1 pk struct mmo {
583 1.1 pk u_int mo_uaddr; /* user (virtual) address */
584 1.1 pk u_int mo_size; /* size, or 0 for video ram size */
585 1.1 pk u_int mo_bank; /* register bank number */
586 1.1 pk };
587 1.1 pk
588 1.1 pk /*
589 1.1 pk * Return the address that would map the given device at the given
590 1.1 pk * offset, allowing for the given protection, or return -1 for error.
591 1.1 pk *
592 1.1 pk * XXX needs testing against `demanding' applications (e.g., aviator)
593 1.1 pk */
594 1.1 pk paddr_t
595 1.1 pk tcxmmap(dev, off, prot)
596 1.1 pk dev_t dev;
597 1.1 pk off_t off;
598 1.1 pk int prot;
599 1.1 pk {
600 1.1 pk struct tcx_softc *sc = tcx_cd.cd_devs[minor(dev)];
601 1.8 thorpej struct openprom_addr *rr = sc->sc_physadr;
602 1.7 darrenr struct mmo *mo, *mo_end;
603 1.1 pk u_int u, sz;
604 1.1 pk static struct mmo mmo[] = {
605 1.1 pk { TCX_USER_RAM, 0, TCX_REG_DFB8 },
606 1.1 pk { TCX_USER_RAM24, 0, TCX_REG_DFB24 },
607 1.1 pk { TCX_USER_RAM_COMPAT, 0, TCX_REG_DFB8 },
608 1.1 pk
609 1.1 pk { TCX_USER_STIP, 1, TCX_REG_STIP },
610 1.1 pk { TCX_USER_BLIT, 1, TCX_REG_BLIT },
611 1.7 darrenr { TCX_USER_RDFB32, 0, TCX_REG_RDFB32 },
612 1.1 pk { TCX_USER_RSTIP, 1, TCX_REG_RSTIP },
613 1.1 pk { TCX_USER_RBLIT, 1, TCX_REG_RBLIT },
614 1.1 pk { TCX_USER_TEC, 1, TCX_REG_TEC },
615 1.1 pk { TCX_USER_BTREGS, 8192 /* XXX */, TCX_REG_CMAP },
616 1.1 pk { TCX_USER_THC, sizeof(struct tcx_thc), TCX_REG_THC },
617 1.1 pk { TCX_USER_DHC, 1, TCX_REG_DHC },
618 1.1 pk { TCX_USER_ALT, 1, TCX_REG_ALT },
619 1.1 pk { TCX_USER_ROM, 65536, TCX_REG_ROM },
620 1.1 pk };
621 1.1 pk #define NMMO (sizeof mmo / sizeof *mmo)
622 1.7 darrenr #ifdef TCX_CG8
623 1.7 darrenr /*
624 1.7 darrenr * alternate mapping for CG8 emulation:
625 1.7 darrenr * map part of the 8-bit-deep framebuffer into the cg8 overlay
626 1.7 darrenr * space, just so there's something there, and map the 32-bit-deep
627 1.7 darrenr * framebuffer where cg8 users expect to find it.
628 1.7 darrenr */
629 1.7 darrenr static struct mmo mmo_cg8[] = {
630 1.7 darrenr { TCX_USER_RAM, TCX_CG8OVERLAY, TCX_REG_DFB8 },
631 1.7 darrenr { TCX_CG8OVERLAY, TCX_SIZE_DFB32, TCX_REG_DFB24 },
632 1.7 darrenr { TCX_USER_RAM_COMPAT, TCX_SIZE_DFB32, TCX_REG_DFB24 }
633 1.7 darrenr };
634 1.7 darrenr #define NMMO_CG8 (sizeof mmo_cg8 / sizeof *mmo_cg8)
635 1.7 darrenr #endif
636 1.1 pk
637 1.1 pk if (off & PGOFSET)
638 1.1 pk panic("tcxmmap");
639 1.1 pk
640 1.1 pk /*
641 1.1 pk * Entries with size 0 map video RAM (i.e., the size in fb data).
642 1.7 darrenr * Entries that map 32-bit deep regions are adjusted for their
643 1.7 darrenr * depth (fb_size gives the size of the 8-bit-deep region).
644 1.1 pk *
645 1.1 pk * Since we work in pages, the fact that the map offset table's
646 1.1 pk * sizes are sometimes bizarre (e.g., 1) is effectively ignored:
647 1.1 pk * one byte is as good as one page.
648 1.1 pk */
649 1.7 darrenr #ifdef TCX_CG8
650 1.7 darrenr if (sc->sc_8bit) {
651 1.7 darrenr mo = mmo;
652 1.7 darrenr mo_end = &mmo[NMMO];
653 1.7 darrenr } else {
654 1.7 darrenr mo = mmo_cg8;
655 1.7 darrenr mo_end = &mmo_cg8[NMMO_CG8];
656 1.7 darrenr }
657 1.7 darrenr #else
658 1.7 darrenr mo = mmo;
659 1.7 darrenr mo_end = &mmo[NMMO];
660 1.7 darrenr #endif
661 1.7 darrenr for (; mo < mo_end; mo++) {
662 1.1 pk if ((u_int)off < mo->mo_uaddr)
663 1.1 pk continue;
664 1.1 pk u = off - mo->mo_uaddr;
665 1.7 darrenr sz = mo->mo_size;
666 1.7 darrenr if (sz == 0) {
667 1.7 darrenr sz = sc->sc_fb.fb_type.fb_size;
668 1.7 darrenr /*
669 1.7 darrenr * check for the 32-bit-deep regions and adjust
670 1.7 darrenr * accordingly
671 1.7 darrenr */
672 1.7 darrenr if (mo->mo_uaddr == TCX_USER_RAM24 ||
673 1.7 darrenr mo->mo_uaddr == TCX_USER_RDFB32) {
674 1.7 darrenr if (sc->sc_8bit) {
675 1.7 darrenr /*
676 1.7 darrenr * not present on 8-bit hardware
677 1.7 darrenr */
678 1.7 darrenr continue;
679 1.7 darrenr }
680 1.7 darrenr sz *= 4;
681 1.7 darrenr }
682 1.7 darrenr }
683 1.1 pk if (u < sz) {
684 1.3 eeh return (bus_space_mmap(sc->sc_bustag,
685 1.8 thorpej BUS_ADDR(rr[mo->mo_bank].oa_space,
686 1.8 thorpej rr[mo->mo_bank].oa_base),
687 1.3 eeh u,
688 1.3 eeh prot,
689 1.3 eeh BUS_SPACE_MAP_LINEAR));
690 1.1 pk }
691 1.1 pk }
692 1.3 eeh return (-1);
693 1.1 pk }
694