cgtwo.c revision 1.48 1 1.48 uwe /* $NetBSD: cgtwo.c,v 1.48 2003/08/24 17:32:00 uwe Exp $ */
2 1.1 pk
3 1.1 pk /*
4 1.1 pk * Copyright (c) 1992, 1993
5 1.1 pk * The Regents of the University of California. All rights reserved.
6 1.1 pk *
7 1.1 pk * This software was developed by the Computer Systems Engineering group
8 1.1 pk * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 pk * contributed to Berkeley.
10 1.1 pk *
11 1.1 pk * All advertising materials mentioning features or use of this software
12 1.1 pk * must display the following acknowledgement:
13 1.1 pk * This product includes software developed by the University of
14 1.1 pk * California, Lawrence Berkeley Laboratory.
15 1.1 pk *
16 1.1 pk * Redistribution and use in source and binary forms, with or without
17 1.1 pk * modification, are permitted provided that the following conditions
18 1.1 pk * are met:
19 1.1 pk * 1. Redistributions of source code must retain the above copyright
20 1.1 pk * notice, this list of conditions and the following disclaimer.
21 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 pk * notice, this list of conditions and the following disclaimer in the
23 1.1 pk * documentation and/or other materials provided with the distribution.
24 1.47 agc * 3. Neither the name of the University nor the names of its contributors
25 1.1 pk * may be used to endorse or promote products derived from this software
26 1.1 pk * without specific prior written permission.
27 1.1 pk *
28 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.1 pk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.1 pk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.1 pk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.1 pk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1 pk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1 pk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1 pk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.1 pk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.1 pk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.1 pk * SUCH DAMAGE.
39 1.1 pk *
40 1.1 pk * from: @(#)cgthree.c 8.2 (Berkeley) 10/30/93
41 1.1 pk */
42 1.1 pk
43 1.1 pk /*
44 1.1 pk * color display (cgtwo) driver.
45 1.1 pk *
46 1.1 pk * Does not handle interrupts, even though they can occur.
47 1.1 pk *
48 1.1 pk * XXX should defer colormap updates to vertical retrace interrupts
49 1.1 pk */
50 1.46 lukem
51 1.46 lukem #include <sys/cdefs.h>
52 1.48 uwe __KERNEL_RCSID(0, "$NetBSD: cgtwo.c,v 1.48 2003/08/24 17:32:00 uwe Exp $");
53 1.48 uwe
54 1.48 uwe #include "opt_rcons.h"
55 1.1 pk
56 1.1 pk #include <sys/param.h>
57 1.11 christos #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.14 christos #include <sys/conf.h>
65 1.1 pk
66 1.43 thorpej #include <uvm/uvm_extern.h>
67 1.43 thorpej
68 1.1 pk #include <machine/autoconf.h>
69 1.34 pk
70 1.34 pk #include <dev/sun/fbio.h>
71 1.34 pk #include <dev/sun/fbvar.h>
72 1.24 pk
73 1.24 pk #include <dev/vme/vmevar.h>
74 1.24 pk
75 1.2 pk #include <machine/eeprom.h>
76 1.3 pk #include <machine/cgtworeg.h>
77 1.1 pk
78 1.11 christos
79 1.1 pk /* per-display variables */
80 1.1 pk struct cgtwo_softc {
81 1.1 pk struct device sc_dev; /* base device */
82 1.1 pk struct fbdevice sc_fb; /* frame buffer device */
83 1.24 pk vme_addr_t sc_paddr;
84 1.24 pk vme_chipset_tag_t sc_ct;
85 1.24 pk bus_space_tag_t sc_bt;
86 1.3 pk volatile struct cg2statusreg *sc_reg; /* CG2 control registers */
87 1.3 pk volatile u_short *sc_cmap;
88 1.3 pk #define sc_redmap(sc) ((sc)->sc_cmap)
89 1.3 pk #define sc_greenmap(sc) ((sc)->sc_cmap + CG2_CMSIZE)
90 1.3 pk #define sc_bluemap(sc) ((sc)->sc_cmap + 2 * CG2_CMSIZE)
91 1.1 pk };
92 1.1 pk
93 1.1 pk /* autoconfiguration driver */
94 1.16 mrg static void cgtwoattach __P((struct device *, struct device *, void *));
95 1.20 pk static int cgtwomatch __P((struct device *, struct cfdata *, void *));
96 1.11 christos static void cgtwounblank __P((struct device *));
97 1.11 christos int cgtwogetcmap __P((struct cgtwo_softc *, struct fbcmap *));
98 1.11 christos int cgtwoputcmap __P((struct cgtwo_softc *, struct fbcmap *));
99 1.1 pk
100 1.39 thorpej CFATTACH_DECL(cgtwo, sizeof(struct cgtwo_softc),
101 1.40 thorpej cgtwomatch, cgtwoattach, NULL, NULL);
102 1.12 thorpej
103 1.23 thorpej extern struct cfdriver cgtwo_cd;
104 1.1 pk
105 1.37 gehenna dev_type_open(cgtwoopen);
106 1.37 gehenna dev_type_ioctl(cgtwoioctl);
107 1.37 gehenna dev_type_mmap(cgtwommap);
108 1.37 gehenna
109 1.37 gehenna const struct cdevsw cgtwo_cdevsw = {
110 1.37 gehenna cgtwoopen, nullclose, noread, nowrite, cgtwoioctl,
111 1.41 jdolecek nostop, notty, nopoll, cgtwommap, nokqfilter,
112 1.37 gehenna };
113 1.37 gehenna
114 1.1 pk /* frame buffer generic driver */
115 1.1 pk static struct fbdriver cgtwofbdriver = {
116 1.41 jdolecek cgtwounblank, cgtwoopen, nullclose, cgtwoioctl, nopoll, cgtwommap,
117 1.41 jdolecek nokqfilter
118 1.1 pk };
119 1.1 pk
120 1.1 pk /*
121 1.1 pk * Match a cgtwo.
122 1.1 pk */
123 1.1 pk int
124 1.20 pk cgtwomatch(parent, cf, aux)
125 1.1 pk struct device *parent;
126 1.20 pk struct cfdata *cf;
127 1.20 pk void *aux;
128 1.1 pk {
129 1.24 pk struct vme_attach_args *va = aux;
130 1.30 drochner vme_chipset_tag_t ct = va->va_vct;
131 1.30 drochner vme_am_t mod;
132 1.10 thorpej
133 1.10 thorpej /*
134 1.10 thorpej * Mask out invalid flags from the user.
135 1.10 thorpej */
136 1.10 thorpej cf->cf_flags &= FB_USERMASK;
137 1.2 pk
138 1.30 drochner mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
139 1.30 drochner if (vme_probe(ct, va->r[0].offset + CG2_CTLREG_OFF, 2, mod, VME_D16,
140 1.26 pk 0, 0)) {
141 1.30 drochner return (0);
142 1.24 pk }
143 1.1 pk
144 1.30 drochner return (1);
145 1.1 pk }
146 1.1 pk
147 1.1 pk /*
148 1.1 pk * Attach a display. We need to notice if it is the console, too.
149 1.1 pk */
150 1.1 pk void
151 1.24 pk cgtwoattach(parent, self, aux)
152 1.1 pk struct device *parent, *self;
153 1.24 pk void *aux;
154 1.1 pk {
155 1.24 pk struct vme_attach_args *va = aux;
156 1.30 drochner vme_chipset_tag_t ct = va->va_vct;
157 1.30 drochner bus_space_tag_t bt;
158 1.24 pk bus_space_handle_t bh;
159 1.30 drochner vme_am_t mod;
160 1.30 drochner vme_mapresc_t resc;
161 1.28 pk struct cgtwo_softc *sc = (struct cgtwo_softc *)self;
162 1.28 pk struct fbdevice *fb = &sc->sc_fb;
163 1.28 pk struct eeprom *eep = (struct eeprom *)eeprom_va;
164 1.11 christos int isconsole = 0;
165 1.1 pk
166 1.24 pk sc->sc_ct = ct;
167 1.28 pk fb->fb_driver = &cgtwofbdriver;
168 1.28 pk fb->fb_device = &sc->sc_dev;
169 1.28 pk fb->fb_type.fb_type = FBTYPE_SUN2COLOR;
170 1.28 pk fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
171 1.28 pk
172 1.28 pk fb->fb_type.fb_depth = 8;
173 1.28 pk fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
174 1.5 pk
175 1.28 pk fb->fb_type.fb_cmsize = 256;
176 1.43 thorpej fb->fb_type.fb_size = roundup(CG2_MAPPED_SIZE, PAGE_SIZE);
177 1.42 fredette printf(": cgtwo, %d x %d",
178 1.28 pk fb->fb_type.fb_width, fb->fb_type.fb_height);
179 1.1 pk
180 1.1 pk /*
181 1.1 pk * When the ROM has mapped in a cgtwo display, the address
182 1.1 pk * maps only the video RAM, so in any case we have to map the
183 1.1 pk * registers ourselves. We only need the video RAM if we are
184 1.1 pk * going to print characters via rconsole.
185 1.1 pk */
186 1.30 drochner sc->sc_paddr = va->r[0].offset;
187 1.30 drochner mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
188 1.24 pk
189 1.30 drochner if (vme_space_map(ct, sc->sc_paddr + CG2_ROPMEM_OFF +
190 1.24 pk offsetof(struct cg2fb, status.reg),
191 1.30 drochner sizeof(struct cg2statusreg), mod, VME_D16, 0,
192 1.30 drochner &bt, &bh, &resc) != 0)
193 1.24 pk panic("cgtwo: vme_map status");
194 1.30 drochner sc->sc_bt = bt;
195 1.30 drochner sc->sc_reg = (volatile struct cg2statusreg *)bh; /* XXX */
196 1.24 pk
197 1.30 drochner if (vme_space_map(ct, sc->sc_paddr + CG2_ROPMEM_OFF +
198 1.24 pk offsetof(struct cg2fb, redmap[0]),
199 1.30 drochner 3 * CG2_CMSIZE, mod, VME_D16, 0,
200 1.30 drochner &bt, &bh, &resc) != 0)
201 1.24 pk panic("cgtwo: vme_map cmap");
202 1.30 drochner sc->sc_cmap = (volatile u_short *)bh; /* XXX */
203 1.1 pk
204 1.28 pk /*
205 1.28 pk * Assume this is the console if there's no eeprom info
206 1.28 pk * to be found.
207 1.28 pk */
208 1.28 pk if (eep == NULL || eep->eeConsole == EE_CONS_COLOR)
209 1.31 pk isconsole = fb_is_console(0);
210 1.28 pk else
211 1.28 pk isconsole = 0;
212 1.28 pk
213 1.1 pk if (isconsole) {
214 1.30 drochner if (vme_space_map(ct, sc->sc_paddr + CG2_PIXMAP_OFF,
215 1.30 drochner CG2_PIXMAP_SIZE, mod, VME_D16, 0,
216 1.30 drochner &bt, &bh, &resc) != 0)
217 1.28 pk panic("cgtwo: vme_map pixels");
218 1.28 pk
219 1.30 drochner fb->fb_pixels = (caddr_t)bh; /* XXX */
220 1.19 christos printf(" (console)\n");
221 1.4 pk #ifdef RASTERCONSOLE
222 1.28 pk fbrcons_init(fb);
223 1.1 pk #endif
224 1.1 pk } else
225 1.19 christos printf("\n");
226 1.9 pk
227 1.28 pk fb_attach(fb, isconsole);
228 1.1 pk }
229 1.1 pk
230 1.1 pk int
231 1.45 fvdl cgtwoopen(dev, flags, mode, p)
232 1.1 pk dev_t dev;
233 1.1 pk int flags, mode;
234 1.45 fvdl struct proc *p;
235 1.1 pk {
236 1.1 pk int unit = minor(dev);
237 1.1 pk
238 1.12 thorpej if (unit >= cgtwo_cd.cd_ndevs || cgtwo_cd.cd_devs[unit] == NULL)
239 1.1 pk return (ENXIO);
240 1.1 pk return (0);
241 1.1 pk }
242 1.1 pk
243 1.1 pk int
244 1.45 fvdl cgtwoioctl(dev, cmd, data, flags, p)
245 1.1 pk dev_t dev;
246 1.1 pk u_long cmd;
247 1.1 pk register caddr_t data;
248 1.1 pk int flags;
249 1.45 fvdl struct proc *p;
250 1.1 pk {
251 1.12 thorpej register struct cgtwo_softc *sc = cgtwo_cd.cd_devs[minor(dev)];
252 1.1 pk register struct fbgattr *fba;
253 1.1 pk
254 1.1 pk switch (cmd) {
255 1.1 pk
256 1.1 pk case FBIOGTYPE:
257 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
258 1.1 pk break;
259 1.1 pk
260 1.1 pk case FBIOGATTR:
261 1.1 pk fba = (struct fbgattr *)data;
262 1.1 pk fba->real_type = sc->sc_fb.fb_type.fb_type;
263 1.1 pk fba->owner = 0; /* XXX ??? */
264 1.1 pk fba->fbtype = sc->sc_fb.fb_type;
265 1.1 pk fba->sattr.flags = 0;
266 1.1 pk fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
267 1.1 pk fba->sattr.dev_specific[0] = -1;
268 1.1 pk fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
269 1.1 pk fba->emu_types[1] = -1;
270 1.1 pk break;
271 1.1 pk
272 1.1 pk case FBIOGETCMAP:
273 1.11 christos return cgtwogetcmap(sc, (struct fbcmap *) data);
274 1.1 pk
275 1.1 pk case FBIOPUTCMAP:
276 1.11 christos return cgtwoputcmap(sc, (struct fbcmap *) data);
277 1.1 pk
278 1.1 pk case FBIOGVIDEO:
279 1.3 pk *(int *)data = sc->sc_reg->video_enab;
280 1.1 pk break;
281 1.1 pk
282 1.1 pk case FBIOSVIDEO:
283 1.3 pk sc->sc_reg->video_enab = (*(int*)data) & 1;
284 1.1 pk break;
285 1.1 pk
286 1.1 pk default:
287 1.1 pk return (ENOTTY);
288 1.1 pk }
289 1.1 pk return (0);
290 1.1 pk }
291 1.1 pk
292 1.1 pk /*
293 1.1 pk * Undo the effect of an FBIOSVIDEO that turns the video off.
294 1.1 pk */
295 1.1 pk static void
296 1.1 pk cgtwounblank(dev)
297 1.1 pk struct device *dev;
298 1.1 pk {
299 1.1 pk struct cgtwo_softc *sc = (struct cgtwo_softc *)dev;
300 1.3 pk sc->sc_reg->video_enab = 1;
301 1.1 pk }
302 1.1 pk
303 1.1 pk /*
304 1.1 pk */
305 1.1 pk int
306 1.1 pk cgtwogetcmap(sc, cmap)
307 1.1 pk register struct cgtwo_softc *sc;
308 1.1 pk register struct fbcmap *cmap;
309 1.1 pk {
310 1.1 pk u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
311 1.1 pk int error, start, count, ecount;
312 1.1 pk register u_int i;
313 1.3 pk register volatile u_short *p;
314 1.1 pk
315 1.1 pk start = cmap->index;
316 1.1 pk count = cmap->count;
317 1.1 pk ecount = start + count;
318 1.36 itojun if (start >= CG2_CMSIZE || count > CG2_CMSIZE - start)
319 1.1 pk return (EINVAL);
320 1.1 pk
321 1.1 pk /* XXX - Wait for retrace? */
322 1.1 pk
323 1.1 pk /* Copy hardware to local arrays. */
324 1.3 pk p = &sc_redmap(sc)[start];
325 1.1 pk for (i = start; i < ecount; i++)
326 1.1 pk red[i] = *p++;
327 1.3 pk p = &sc_greenmap(sc)[start];
328 1.1 pk for (i = start; i < ecount; i++)
329 1.1 pk green[i] = *p++;
330 1.3 pk p = &sc_bluemap(sc)[start];
331 1.1 pk for (i = start; i < ecount; i++)
332 1.1 pk blue[i] = *p++;
333 1.1 pk
334 1.1 pk /* Copy local arrays to user space. */
335 1.1 pk if ((error = copyout(red + start, cmap->red, count)) != 0)
336 1.1 pk return (error);
337 1.1 pk if ((error = copyout(green + start, cmap->green, count)) != 0)
338 1.1 pk return (error);
339 1.1 pk if ((error = copyout(blue + start, cmap->blue, count)) != 0)
340 1.1 pk return (error);
341 1.1 pk
342 1.1 pk return (0);
343 1.1 pk }
344 1.1 pk
345 1.1 pk /*
346 1.1 pk */
347 1.1 pk int
348 1.1 pk cgtwoputcmap(sc, cmap)
349 1.1 pk register struct cgtwo_softc *sc;
350 1.1 pk register struct fbcmap *cmap;
351 1.1 pk {
352 1.1 pk u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
353 1.35 jdolecek int error;
354 1.35 jdolecek u_int start, count, ecount;
355 1.1 pk register u_int i;
356 1.3 pk register volatile u_short *p;
357 1.1 pk
358 1.1 pk start = cmap->index;
359 1.1 pk count = cmap->count;
360 1.1 pk ecount = start + count;
361 1.36 itojun if (start >= CG2_CMSIZE || count > CG2_CMSIZE - start)
362 1.1 pk return (EINVAL);
363 1.1 pk
364 1.1 pk /* Copy from user space to local arrays. */
365 1.1 pk if ((error = copyin(cmap->red, red + start, count)) != 0)
366 1.1 pk return (error);
367 1.1 pk if ((error = copyin(cmap->green, green + start, count)) != 0)
368 1.1 pk return (error);
369 1.1 pk if ((error = copyin(cmap->blue, blue + start, count)) != 0)
370 1.1 pk return (error);
371 1.1 pk
372 1.1 pk /* XXX - Wait for retrace? */
373 1.1 pk
374 1.1 pk /* Copy from local arrays to hardware. */
375 1.3 pk p = &sc_redmap(sc)[start];
376 1.1 pk for (i = start; i < ecount; i++)
377 1.1 pk *p++ = red[i];
378 1.3 pk p = &sc_greenmap(sc)[start];
379 1.1 pk for (i = start; i < ecount; i++)
380 1.1 pk *p++ = green[i];
381 1.3 pk p = &sc_bluemap(sc)[start];
382 1.1 pk for (i = start; i < ecount; i++)
383 1.1 pk *p++ = blue[i];
384 1.1 pk
385 1.1 pk return (0);
386 1.1 pk }
387 1.1 pk
388 1.1 pk /*
389 1.1 pk * Return the address that would map the given device at the given
390 1.1 pk * offset, allowing for the given protection, or return -1 for error.
391 1.1 pk */
392 1.32 simonb paddr_t
393 1.1 pk cgtwommap(dev, off, prot)
394 1.1 pk dev_t dev;
395 1.32 simonb off_t off;
396 1.32 simonb int prot;
397 1.1 pk {
398 1.12 thorpej register struct cgtwo_softc *sc = cgtwo_cd.cd_devs[minor(dev)];
399 1.30 drochner vme_am_t mod;
400 1.29 pk bus_space_handle_t bh;
401 1.30 drochner extern int sparc_vme_mmap_cookie __P((vme_addr_t, vme_am_t,
402 1.30 drochner bus_space_handle_t *));
403 1.1 pk
404 1.1 pk if (off & PGOFSET)
405 1.1 pk panic("cgtwommap");
406 1.1 pk
407 1.32 simonb if (off >= sc->sc_fb.fb_type.fb_size)
408 1.1 pk return (-1);
409 1.1 pk
410 1.24 pk /* Apparently, the pixels are in 32-bit data space */
411 1.30 drochner mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
412 1.24 pk
413 1.30 drochner if (sparc_vme_mmap_cookie(sc->sc_paddr + off, mod, &bh) != 0)
414 1.24 pk panic("cgtwommap");
415 1.24 pk
416 1.32 simonb return ((paddr_t)bh);
417 1.1 pk }
418