cgfourteen.c revision 1.21.4.7 1 1.21.4.7 nathanw /* $NetBSD: cgfourteen.c,v 1.21.4.7 2002/10/18 02:39:51 nathanw Exp $ */
2 1.21.4.2 nathanw
3 1.21.4.2 nathanw /*
4 1.21.4.2 nathanw * Copyright (c) 1996
5 1.21.4.2 nathanw * The President and Fellows of Harvard College. All rights reserved.
6 1.21.4.2 nathanw * Copyright (c) 1992, 1993
7 1.21.4.2 nathanw * The Regents of the University of California. All rights reserved.
8 1.21.4.2 nathanw *
9 1.21.4.2 nathanw * This software was developed by the Computer Systems Engineering group
10 1.21.4.2 nathanw * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
11 1.21.4.2 nathanw * contributed to Berkeley.
12 1.21.4.2 nathanw *
13 1.21.4.2 nathanw * All advertising materials mentioning features or use of this software
14 1.21.4.2 nathanw * must display the following acknowledgement:
15 1.21.4.2 nathanw * This product includes software developed by Harvard University.
16 1.21.4.2 nathanw * This product includes software developed by the University of
17 1.21.4.2 nathanw * California, Lawrence Berkeley Laboratory.
18 1.21.4.2 nathanw *
19 1.21.4.2 nathanw * Redistribution and use in source and binary forms, with or without
20 1.21.4.2 nathanw * modification, are permitted provided that the following conditions
21 1.21.4.2 nathanw * are met:
22 1.21.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
23 1.21.4.2 nathanw * notice, this list of conditions and the following disclaimer.
24 1.21.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
25 1.21.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
26 1.21.4.2 nathanw * documentation and/or other materials provided with the distribution.
27 1.21.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
28 1.21.4.2 nathanw * must display the following acknowledgement:
29 1.21.4.2 nathanw * This product includes software developed by the University of
30 1.21.4.2 nathanw * California, Berkeley and its contributors.
31 1.21.4.2 nathanw * This product includes software developed by Harvard University and
32 1.21.4.2 nathanw * its contributors.
33 1.21.4.2 nathanw * 4. Neither the name of the University nor the names of its contributors
34 1.21.4.2 nathanw * may be used to endorse or promote products derived from this software
35 1.21.4.2 nathanw * without specific prior written permission.
36 1.21.4.2 nathanw *
37 1.21.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
38 1.21.4.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 1.21.4.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 1.21.4.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
41 1.21.4.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42 1.21.4.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43 1.21.4.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 1.21.4.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45 1.21.4.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46 1.21.4.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 1.21.4.2 nathanw * SUCH DAMAGE.
48 1.21.4.2 nathanw *
49 1.21.4.2 nathanw * Based on:
50 1.21.4.2 nathanw * NetBSD: cgthree.c,v 1.28 1996/05/31 09:59:22 pk Exp
51 1.21.4.2 nathanw * NetBSD: cgsix.c,v 1.25 1996/04/01 17:30:00 christos Exp
52 1.21.4.2 nathanw */
53 1.21.4.2 nathanw
54 1.21.4.2 nathanw /*
55 1.21.4.2 nathanw * Driver for Campus-II on-board mbus-based video (cgfourteen).
56 1.21.4.2 nathanw * Provides minimum emulation of a Sun cgthree 8-bit framebuffer to
57 1.21.4.2 nathanw * allow X to run.
58 1.21.4.2 nathanw *
59 1.21.4.2 nathanw * Does not handle interrupts, even though they can occur.
60 1.21.4.2 nathanw *
61 1.21.4.2 nathanw * XXX should defer colormap updates to vertical retrace interrupts
62 1.21.4.2 nathanw */
63 1.21.4.2 nathanw
64 1.21.4.2 nathanw /*
65 1.21.4.2 nathanw * The following is for debugging only; it opens up a security hole
66 1.21.4.2 nathanw * enabled by allowing any user to map the control registers for the
67 1.21.4.2 nathanw * cg14 into their space.
68 1.21.4.2 nathanw */
69 1.21.4.2 nathanw #undef CG14_MAP_REGS
70 1.21.4.2 nathanw
71 1.21.4.2 nathanw /*
72 1.21.4.2 nathanw * The following enables 24-bit operation: when opened, the framebuffer
73 1.21.4.2 nathanw * will switch to 24-bit mode (actually 32-bit mode), and provide a
74 1.21.4.2 nathanw * simple cg8 emulation.
75 1.21.4.2 nathanw *
76 1.21.4.2 nathanw * XXX Note that the code enabled by this define is currently untested/broken.
77 1.21.4.2 nathanw */
78 1.21.4.2 nathanw #undef CG14_CG8
79 1.21.4.2 nathanw
80 1.21.4.2 nathanw #include <sys/param.h>
81 1.21.4.2 nathanw #include <sys/systm.h>
82 1.21.4.2 nathanw #include <sys/buf.h>
83 1.21.4.2 nathanw #include <sys/device.h>
84 1.21.4.2 nathanw #include <sys/ioctl.h>
85 1.21.4.2 nathanw #include <sys/malloc.h>
86 1.21.4.2 nathanw #include <sys/mman.h>
87 1.21.4.2 nathanw #include <sys/tty.h>
88 1.21.4.2 nathanw #include <sys/conf.h>
89 1.21.4.2 nathanw
90 1.21.4.2 nathanw #include <uvm/uvm_extern.h>
91 1.21.4.2 nathanw
92 1.21.4.2 nathanw #include <machine/bus.h>
93 1.21.4.2 nathanw #include <machine/autoconf.h>
94 1.21.4.2 nathanw
95 1.21.4.2 nathanw #include <dev/sbus/sbusvar.h>
96 1.21.4.2 nathanw
97 1.21.4.2 nathanw #include <dev/sun/fbio.h>
98 1.21.4.2 nathanw #include <dev/sun/fbvar.h>
99 1.21.4.2 nathanw
100 1.21.4.2 nathanw #include <sparc/dev/cgfourteenreg.h>
101 1.21.4.2 nathanw #include <sparc/dev/cgfourteenvar.h>
102 1.21.4.2 nathanw
103 1.21.4.2 nathanw /* autoconfiguration driver */
104 1.21.4.2 nathanw static void cgfourteenattach(struct device *, struct device *, void *);
105 1.21.4.2 nathanw static int cgfourteenmatch(struct device *, struct cfdata *, void *);
106 1.21.4.2 nathanw static void cgfourteenunblank(struct device *);
107 1.21.4.2 nathanw
108 1.21.4.7 nathanw CFATTACH_DECL(cgfourteen, sizeof(struct cgfourteen_softc),
109 1.21.4.7 nathanw cgfourteenmatch, cgfourteenattach, NULL, NULL);
110 1.21.4.2 nathanw
111 1.21.4.2 nathanw extern struct cfdriver cgfourteen_cd;
112 1.21.4.2 nathanw
113 1.21.4.6 nathanw dev_type_open(cgfourteenopen);
114 1.21.4.6 nathanw dev_type_close(cgfourteenclose);
115 1.21.4.6 nathanw dev_type_ioctl(cgfourteenioctl);
116 1.21.4.6 nathanw dev_type_mmap(cgfourteenmmap);
117 1.21.4.6 nathanw
118 1.21.4.6 nathanw const struct cdevsw cgfourteen_cdevsw = {
119 1.21.4.6 nathanw cgfourteenopen, cgfourteenclose, noread, nowrite, cgfourteenioctl,
120 1.21.4.6 nathanw nostop, notty, nopoll, cgfourteenmmap,
121 1.21.4.6 nathanw };
122 1.21.4.6 nathanw
123 1.21.4.2 nathanw /* frame buffer generic driver */
124 1.21.4.2 nathanw static struct fbdriver cgfourteenfbdriver = {
125 1.21.4.2 nathanw cgfourteenunblank, cgfourteenopen, cgfourteenclose, cgfourteenioctl,
126 1.21.4.6 nathanw nopoll, cgfourteenmmap
127 1.21.4.2 nathanw };
128 1.21.4.2 nathanw
129 1.21.4.2 nathanw static void cg14_set_video __P((struct cgfourteen_softc *, int));
130 1.21.4.2 nathanw static int cg14_get_video __P((struct cgfourteen_softc *));
131 1.21.4.2 nathanw static int cg14_get_cmap __P((struct fbcmap *, union cg14cmap *, int));
132 1.21.4.2 nathanw static int cg14_put_cmap __P((struct fbcmap *, union cg14cmap *, int));
133 1.21.4.2 nathanw static void cg14_load_hwcmap __P((struct cgfourteen_softc *, int, int));
134 1.21.4.2 nathanw static void cg14_init __P((struct cgfourteen_softc *));
135 1.21.4.2 nathanw static void cg14_reset __P((struct cgfourteen_softc *));
136 1.21.4.2 nathanw static void cg14_loadomap __P((struct cgfourteen_softc *));/* cursor overlay */
137 1.21.4.2 nathanw static void cg14_setcursor __P((struct cgfourteen_softc *));/* set position */
138 1.21.4.2 nathanw static void cg14_loadcursor __P((struct cgfourteen_softc *));/* set shape */
139 1.21.4.2 nathanw
140 1.21.4.2 nathanw /*
141 1.21.4.3 nathanw * We map the display memory with an offset of 256K when emulating the cg3 or
142 1.21.4.3 nathanw * cg8; the cg3 uses this offset for compatibility with the cg4, and both the
143 1.21.4.3 nathanw * cg4 and cg8 have a mono overlay plane and an overlay enable plane in the
144 1.21.4.3 nathanw * first 256K. Mapping at an offset of 0x04000000 causes only the color
145 1.21.4.3 nathanw * frame buffer to be mapped, without the overlay planes.
146 1.21.4.3 nathanw */
147 1.21.4.3 nathanw #define START (128*1024 + 128*1024)
148 1.21.4.3 nathanw #define NOOVERLAY (0x04000000)
149 1.21.4.3 nathanw
150 1.21.4.3 nathanw /*
151 1.21.4.2 nathanw * Match a cgfourteen.
152 1.21.4.2 nathanw */
153 1.21.4.2 nathanw int
154 1.21.4.2 nathanw cgfourteenmatch(parent, cf, aux)
155 1.21.4.2 nathanw struct device *parent;
156 1.21.4.2 nathanw struct cfdata *cf;
157 1.21.4.2 nathanw void *aux;
158 1.21.4.2 nathanw {
159 1.21.4.2 nathanw union obio_attach_args *uoba = aux;
160 1.21.4.2 nathanw struct sbus_attach_args *sa = &uoba->uoba_sbus;
161 1.21.4.2 nathanw
162 1.21.4.2 nathanw /*
163 1.21.4.2 nathanw * The cgfourteen is a local-bus video adaptor, accessed directly
164 1.21.4.2 nathanw * via the processor, and not through device space or an external
165 1.21.4.2 nathanw * bus. Thus we look _only_ at the obio bus.
166 1.21.4.2 nathanw * Additionally, these things exist only on the Sun4m.
167 1.21.4.2 nathanw */
168 1.21.4.2 nathanw
169 1.21.4.2 nathanw if (uoba->uoba_isobio4 != 0 || !CPU_ISSUN4M)
170 1.21.4.2 nathanw return (0);
171 1.21.4.2 nathanw
172 1.21.4.2 nathanw /* Check driver name */
173 1.21.4.7 nathanw return (strcmp(cf->cf_name, sa->sa_name) == 0);
174 1.21.4.2 nathanw }
175 1.21.4.2 nathanw
176 1.21.4.2 nathanw /*
177 1.21.4.2 nathanw * Attach a display. We need to notice if it is the console, too.
178 1.21.4.2 nathanw */
179 1.21.4.2 nathanw void
180 1.21.4.2 nathanw cgfourteenattach(parent, self, aux)
181 1.21.4.2 nathanw struct device *parent, *self;
182 1.21.4.2 nathanw void *aux;
183 1.21.4.2 nathanw {
184 1.21.4.2 nathanw union obio_attach_args *uoba = aux;
185 1.21.4.2 nathanw struct sbus_attach_args *sa = &uoba->uoba_sbus;
186 1.21.4.2 nathanw struct cgfourteen_softc *sc = (struct cgfourteen_softc *)self;
187 1.21.4.2 nathanw struct fbdevice *fb = &sc->sc_fb;
188 1.21.4.2 nathanw bus_space_handle_t bh;
189 1.21.4.2 nathanw int node, ramsize;
190 1.21.4.2 nathanw u_int32_t *lut;
191 1.21.4.2 nathanw int i, isconsole;
192 1.21.4.2 nathanw
193 1.21.4.2 nathanw node = sa->sa_node;
194 1.21.4.2 nathanw
195 1.21.4.2 nathanw /* Remember cookies for cgfourteenmmap() */
196 1.21.4.2 nathanw sc->sc_bustag = sa->sa_bustag;
197 1.21.4.2 nathanw
198 1.21.4.2 nathanw fb->fb_driver = &cgfourteenfbdriver;
199 1.21.4.2 nathanw fb->fb_device = &sc->sc_dev;
200 1.21.4.2 nathanw /* Mask out invalid flags from the user. */
201 1.21.4.2 nathanw fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
202 1.21.4.2 nathanw
203 1.21.4.2 nathanw /*
204 1.21.4.2 nathanw * We're emulating a cg3/8, so represent ourselves as one
205 1.21.4.2 nathanw */
206 1.21.4.2 nathanw #ifdef CG14_CG8
207 1.21.4.2 nathanw fb->fb_type.fb_type = FBTYPE_MEMCOLOR;
208 1.21.4.2 nathanw fb->fb_type.fb_depth = 32;
209 1.21.4.2 nathanw #else
210 1.21.4.2 nathanw fb->fb_type.fb_type = FBTYPE_SUN3COLOR;
211 1.21.4.2 nathanw fb->fb_type.fb_depth = 8;
212 1.21.4.2 nathanw #endif
213 1.21.4.2 nathanw fb_setsize_obp(fb, sc->sc_fb.fb_type.fb_depth, 1152, 900, node);
214 1.21.4.3 nathanw #ifdef CG14_CG8
215 1.21.4.3 nathanw /*
216 1.21.4.3 nathanw * fb_setsize_obp set fb->fb_linebytes based on the current
217 1.21.4.3 nathanw * depth reported by obp, but that defaults to 8 bits (as
218 1.21.4.3 nathanw * reported by getpropint(). Update the value to reflect
219 1.21.4.3 nathanw * the depth that will be used after open.
220 1.21.4.3 nathanw * The display memory size returned by the cg8 driver includes
221 1.21.4.3 nathanw * the space used by the overlay planes, but the size returned
222 1.21.4.3 nathanw * by the cg3 driver does not; emulate the other drivers.
223 1.21.4.3 nathanw */
224 1.21.4.3 nathanw fb->fb_linebytes = (fb->fb_type.fb_width * fb->fb_type.fb_depth) / 8;
225 1.21.4.3 nathanw ramsize = roundup(START + (fb->fb_type.fb_height * fb->fb_linebytes),
226 1.21.4.3 nathanw NBPG);
227 1.21.4.3 nathanw #else
228 1.21.4.2 nathanw ramsize = roundup(fb->fb_type.fb_height * fb->fb_linebytes, NBPG);
229 1.21.4.3 nathanw #endif
230 1.21.4.2 nathanw fb->fb_type.fb_cmsize = CG14_CLUT_SIZE;
231 1.21.4.2 nathanw fb->fb_type.fb_size = ramsize;
232 1.21.4.2 nathanw
233 1.21.4.2 nathanw if (sa->sa_nreg < 2) {
234 1.21.4.2 nathanw printf("%s: only %d register sets\n",
235 1.21.4.2 nathanw self->dv_xname, sa->sa_nreg);
236 1.21.4.2 nathanw return;
237 1.21.4.2 nathanw }
238 1.21.4.2 nathanw bcopy(sa->sa_reg, sc->sc_physadr,
239 1.21.4.5 nathanw sa->sa_nreg * sizeof(struct openprom_addr));
240 1.21.4.2 nathanw
241 1.21.4.2 nathanw /*
242 1.21.4.2 nathanw * Now map in the 8 useful pages of registers
243 1.21.4.2 nathanw */
244 1.21.4.2 nathanw if (sa->sa_size < 0x10000) {
245 1.21.4.2 nathanw #ifdef DIAGNOSTIC
246 1.21.4.2 nathanw printf("warning: can't find all cgfourteen registers...\n");
247 1.21.4.2 nathanw #endif
248 1.21.4.2 nathanw sa->sa_size = 0x10000;
249 1.21.4.2 nathanw }
250 1.21.4.2 nathanw if (sbus_bus_map(sa->sa_bustag,
251 1.21.4.2 nathanw sa->sa_slot, sa->sa_offset, sa->sa_size,
252 1.21.4.2 nathanw BUS_SPACE_MAP_LINEAR, &bh) != 0) {
253 1.21.4.2 nathanw printf("%s: cannot map control registers\n", self->dv_xname);
254 1.21.4.2 nathanw return;
255 1.21.4.2 nathanw }
256 1.21.4.2 nathanw
257 1.21.4.2 nathanw sc->sc_ctl = (struct cg14ctl *) (bh);
258 1.21.4.2 nathanw sc->sc_hwc = (struct cg14curs *) (bh + CG14_OFFSET_CURS);
259 1.21.4.2 nathanw sc->sc_dac = (struct cg14dac *) (bh + CG14_OFFSET_DAC);
260 1.21.4.2 nathanw sc->sc_xlut = (struct cg14xlut *) (bh + CG14_OFFSET_XLUT);
261 1.21.4.2 nathanw sc->sc_clut1 = (struct cg14clut *) (bh + CG14_OFFSET_CLUT1);
262 1.21.4.2 nathanw sc->sc_clut2 = (struct cg14clut *) (bh + CG14_OFFSET_CLUT2);
263 1.21.4.2 nathanw sc->sc_clut3 = (struct cg14clut *) (bh + CG14_OFFSET_CLUT3);
264 1.21.4.2 nathanw sc->sc_clutincr = (u_int *) (bh + CG14_OFFSET_CLUTINCR);
265 1.21.4.2 nathanw
266 1.21.4.2 nathanw /*
267 1.21.4.2 nathanw * Let the user know that we're here
268 1.21.4.2 nathanw */
269 1.21.4.2 nathanw #ifdef CG14_CG8
270 1.21.4.2 nathanw printf(": cgeight emulated at %dx%dx24bpp",
271 1.21.4.2 nathanw fb->fb_type.fb_width, fb->fb_type.fb_height);
272 1.21.4.2 nathanw #else
273 1.21.4.2 nathanw printf(": cgthree emulated at %dx%dx8bpp",
274 1.21.4.2 nathanw fb->fb_type.fb_width, fb->fb_type.fb_height);
275 1.21.4.2 nathanw #endif
276 1.21.4.2 nathanw /*
277 1.21.4.2 nathanw * Enable the video, but don't change the pixel depth.
278 1.21.4.2 nathanw */
279 1.21.4.2 nathanw cg14_set_video(sc, 1);
280 1.21.4.2 nathanw
281 1.21.4.2 nathanw /*
282 1.21.4.2 nathanw * Grab the initial colormap
283 1.21.4.2 nathanw */
284 1.21.4.2 nathanw lut = (u_int32_t *) sc->sc_clut1->clut_lut;
285 1.21.4.2 nathanw for (i = 0; i < CG14_CLUT_SIZE; i++)
286 1.21.4.2 nathanw sc->sc_cmap.cm_chip[i] = lut[i];
287 1.21.4.2 nathanw
288 1.21.4.2 nathanw /* See if we're the console */
289 1.21.4.2 nathanw isconsole = fb_is_console(node);
290 1.21.4.2 nathanw
291 1.21.4.2 nathanw if (isconsole) {
292 1.21.4.2 nathanw printf(" (console)\n");
293 1.21.4.2 nathanw #ifdef notdef
294 1.21.4.2 nathanw /*
295 1.21.4.2 nathanw * We don't use the raster console since the cg14 is
296 1.21.4.2 nathanw * fast enough already.
297 1.21.4.2 nathanw */
298 1.21.4.2 nathanw #ifdef RASTERCONSOLE
299 1.21.4.2 nathanw fbrcons_init(fb);
300 1.21.4.2 nathanw #endif
301 1.21.4.2 nathanw #endif /* notdef */
302 1.21.4.2 nathanw } else
303 1.21.4.2 nathanw printf("\n");
304 1.21.4.2 nathanw
305 1.21.4.2 nathanw /* Attach to /dev/fb */
306 1.21.4.2 nathanw fb_attach(&sc->sc_fb, isconsole);
307 1.21.4.2 nathanw }
308 1.21.4.2 nathanw
309 1.21.4.2 nathanw /*
310 1.21.4.2 nathanw * Keep track of the number of opens made. In the 24-bit driver, we need to
311 1.21.4.2 nathanw * switch to 24-bit mode on the first open, and switch back to 8-bit on
312 1.21.4.2 nathanw * the last close. This kind of nonsense is needed to give screenblank
313 1.21.4.2 nathanw * a fighting chance of working.
314 1.21.4.2 nathanw */
315 1.21.4.2 nathanw static int cg14_opens = 0;
316 1.21.4.2 nathanw
317 1.21.4.2 nathanw int
318 1.21.4.2 nathanw cgfourteenopen(dev, flags, mode, p)
319 1.21.4.2 nathanw dev_t dev;
320 1.21.4.2 nathanw int flags, mode;
321 1.21.4.2 nathanw struct proc *p;
322 1.21.4.2 nathanw {
323 1.21.4.2 nathanw struct cgfourteen_softc *sc = cgfourteen_cd.cd_devs[minor(dev)];
324 1.21.4.2 nathanw int unit = minor(dev);
325 1.21.4.2 nathanw int s, oldopens;
326 1.21.4.2 nathanw
327 1.21.4.2 nathanw if (unit >= cgfourteen_cd.cd_ndevs ||
328 1.21.4.2 nathanw cgfourteen_cd.cd_devs[unit] == NULL)
329 1.21.4.2 nathanw return (ENXIO);
330 1.21.4.2 nathanw
331 1.21.4.2 nathanw s = splhigh();
332 1.21.4.2 nathanw oldopens = cg14_opens++;
333 1.21.4.2 nathanw splx(s);
334 1.21.4.2 nathanw
335 1.21.4.2 nathanw /* Setup the cg14 as we want it, and save the original PROM state */
336 1.21.4.2 nathanw if (oldopens == 0) /* first open only, to make screenblank work */
337 1.21.4.2 nathanw cg14_init(sc);
338 1.21.4.2 nathanw
339 1.21.4.2 nathanw return (0);
340 1.21.4.2 nathanw }
341 1.21.4.2 nathanw
342 1.21.4.2 nathanw int
343 1.21.4.2 nathanw cgfourteenclose(dev, flags, mode, p)
344 1.21.4.2 nathanw dev_t dev;
345 1.21.4.2 nathanw int flags, mode;
346 1.21.4.2 nathanw struct proc *p;
347 1.21.4.2 nathanw {
348 1.21.4.2 nathanw struct cgfourteen_softc *sc = cgfourteen_cd.cd_devs[minor(dev)];
349 1.21.4.2 nathanw int s, opens;
350 1.21.4.2 nathanw
351 1.21.4.2 nathanw s = splhigh();
352 1.21.4.2 nathanw opens = --cg14_opens;
353 1.21.4.2 nathanw if (cg14_opens < 0)
354 1.21.4.2 nathanw opens = cg14_opens = 0;
355 1.21.4.2 nathanw splx(s);
356 1.21.4.2 nathanw
357 1.21.4.2 nathanw /*
358 1.21.4.2 nathanw * Restore video state to make the PROM happy, on last close.
359 1.21.4.2 nathanw */
360 1.21.4.2 nathanw if (opens == 0)
361 1.21.4.2 nathanw cg14_reset(sc);
362 1.21.4.2 nathanw
363 1.21.4.2 nathanw return (0);
364 1.21.4.2 nathanw }
365 1.21.4.2 nathanw
366 1.21.4.2 nathanw int
367 1.21.4.2 nathanw cgfourteenioctl(dev, cmd, data, flags, p)
368 1.21.4.2 nathanw dev_t dev;
369 1.21.4.2 nathanw u_long cmd;
370 1.21.4.2 nathanw caddr_t data;
371 1.21.4.2 nathanw int flags;
372 1.21.4.2 nathanw struct proc *p;
373 1.21.4.2 nathanw {
374 1.21.4.2 nathanw struct cgfourteen_softc *sc = cgfourteen_cd.cd_devs[minor(dev)];
375 1.21.4.2 nathanw struct fbgattr *fba;
376 1.21.4.2 nathanw union cg14cursor_cmap tcm;
377 1.21.4.2 nathanw int v, error;
378 1.21.4.2 nathanw u_int count;
379 1.21.4.2 nathanw
380 1.21.4.2 nathanw switch (cmd) {
381 1.21.4.2 nathanw
382 1.21.4.2 nathanw case FBIOGTYPE:
383 1.21.4.2 nathanw *(struct fbtype *)data = sc->sc_fb.fb_type;
384 1.21.4.2 nathanw break;
385 1.21.4.2 nathanw
386 1.21.4.2 nathanw case FBIOGATTR:
387 1.21.4.2 nathanw fba = (struct fbgattr *)data;
388 1.21.4.2 nathanw fba->real_type = FBTYPE_MDICOLOR;
389 1.21.4.2 nathanw fba->owner = 0; /* XXX ??? */
390 1.21.4.2 nathanw fba->fbtype = sc->sc_fb.fb_type;
391 1.21.4.2 nathanw fba->sattr.flags = 0;
392 1.21.4.2 nathanw fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
393 1.21.4.2 nathanw fba->sattr.dev_specific[0] = -1;
394 1.21.4.2 nathanw fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
395 1.21.4.2 nathanw fba->emu_types[1] = -1;
396 1.21.4.2 nathanw break;
397 1.21.4.2 nathanw
398 1.21.4.2 nathanw case FBIOGETCMAP:
399 1.21.4.2 nathanw return (cg14_get_cmap((struct fbcmap *)data, &sc->sc_cmap,
400 1.21.4.2 nathanw CG14_CLUT_SIZE));
401 1.21.4.2 nathanw
402 1.21.4.2 nathanw case FBIOPUTCMAP:
403 1.21.4.2 nathanw /* copy to software map */
404 1.21.4.2 nathanw #define p ((struct fbcmap *)data)
405 1.21.4.2 nathanw #ifdef CG14_CG8
406 1.21.4.2 nathanw p->index &= 0xffffff;
407 1.21.4.2 nathanw #endif
408 1.21.4.2 nathanw error = cg14_put_cmap(p, &sc->sc_cmap, CG14_CLUT_SIZE);
409 1.21.4.2 nathanw if (error)
410 1.21.4.2 nathanw return (error);
411 1.21.4.2 nathanw /* now blast them into the chip */
412 1.21.4.2 nathanw /* XXX should use retrace interrupt */
413 1.21.4.2 nathanw cg14_load_hwcmap(sc, p->index, p->count);
414 1.21.4.2 nathanw #undef p
415 1.21.4.2 nathanw break;
416 1.21.4.2 nathanw
417 1.21.4.2 nathanw case FBIOGVIDEO:
418 1.21.4.2 nathanw *(int *)data = cg14_get_video(sc);
419 1.21.4.2 nathanw break;
420 1.21.4.2 nathanw
421 1.21.4.2 nathanw case FBIOSVIDEO:
422 1.21.4.2 nathanw cg14_set_video(sc, *(int *)data);
423 1.21.4.2 nathanw break;
424 1.21.4.2 nathanw
425 1.21.4.2 nathanw /* these are for both FBIOSCURSOR and FBIOGCURSOR */
426 1.21.4.2 nathanw #define p ((struct fbcursor *)data)
427 1.21.4.2 nathanw #define cc (&sc->sc_cursor)
428 1.21.4.2 nathanw case FBIOGCURSOR:
429 1.21.4.2 nathanw /* do not quite want everything here... */
430 1.21.4.2 nathanw p->set = FB_CUR_SETALL; /* close enough, anyway */
431 1.21.4.2 nathanw p->enable = cc->cc_enable;
432 1.21.4.2 nathanw p->pos = cc->cc_pos;
433 1.21.4.2 nathanw p->hot = cc->cc_hot;
434 1.21.4.2 nathanw p->size = cc->cc_size;
435 1.21.4.2 nathanw
436 1.21.4.2 nathanw /* begin ugh ... can we lose some of this crap?? */
437 1.21.4.2 nathanw if (p->image != NULL) {
438 1.21.4.2 nathanw count = cc->cc_size.y * 32 / NBBY;
439 1.21.4.2 nathanw error = copyout((caddr_t)cc->cc_cplane,
440 1.21.4.2 nathanw (caddr_t)p->image, count);
441 1.21.4.2 nathanw if (error)
442 1.21.4.2 nathanw return (error);
443 1.21.4.2 nathanw error = copyout((caddr_t)cc->cc_eplane,
444 1.21.4.2 nathanw (caddr_t)p->mask, count);
445 1.21.4.2 nathanw if (error)
446 1.21.4.2 nathanw return (error);
447 1.21.4.2 nathanw }
448 1.21.4.2 nathanw if (p->cmap.red != NULL) {
449 1.21.4.2 nathanw error = cg14_get_cmap(&p->cmap,
450 1.21.4.2 nathanw (union cg14cmap *)&cc->cc_color, 2);
451 1.21.4.2 nathanw if (error)
452 1.21.4.2 nathanw return (error);
453 1.21.4.2 nathanw } else {
454 1.21.4.2 nathanw p->cmap.index = 0;
455 1.21.4.2 nathanw p->cmap.count = 2;
456 1.21.4.2 nathanw }
457 1.21.4.2 nathanw /* end ugh */
458 1.21.4.2 nathanw break;
459 1.21.4.2 nathanw
460 1.21.4.2 nathanw case FBIOSCURSOR:
461 1.21.4.2 nathanw /*
462 1.21.4.2 nathanw * For setcmap and setshape, verify parameters, so that
463 1.21.4.2 nathanw * we do not get halfway through an update and then crap
464 1.21.4.2 nathanw * out with the software state screwed up.
465 1.21.4.2 nathanw */
466 1.21.4.2 nathanw v = p->set;
467 1.21.4.2 nathanw if (v & FB_CUR_SETCMAP) {
468 1.21.4.2 nathanw /*
469 1.21.4.2 nathanw * This use of a temporary copy of the cursor
470 1.21.4.2 nathanw * colormap is not terribly efficient, but these
471 1.21.4.2 nathanw * copies are small (8 bytes)...
472 1.21.4.2 nathanw */
473 1.21.4.2 nathanw tcm = cc->cc_color;
474 1.21.4.2 nathanw error = cg14_put_cmap(&p->cmap, (union cg14cmap *)&tcm,
475 1.21.4.2 nathanw 2);
476 1.21.4.2 nathanw if (error)
477 1.21.4.2 nathanw return (error);
478 1.21.4.2 nathanw }
479 1.21.4.2 nathanw if (v & FB_CUR_SETSHAPE) {
480 1.21.4.2 nathanw if ((u_int)p->size.x > 32 || (u_int)p->size.y > 32)
481 1.21.4.2 nathanw return (EINVAL);
482 1.21.4.2 nathanw count = p->size.y * 32 / NBBY;
483 1.21.4.2 nathanw if (!uvm_useracc(p->image, count, B_READ) ||
484 1.21.4.2 nathanw !uvm_useracc(p->mask, count, B_READ))
485 1.21.4.2 nathanw return (EFAULT);
486 1.21.4.2 nathanw }
487 1.21.4.2 nathanw
488 1.21.4.2 nathanw /* parameters are OK; do it */
489 1.21.4.2 nathanw if (v & (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT)) {
490 1.21.4.2 nathanw if (v & FB_CUR_SETCUR)
491 1.21.4.2 nathanw cc->cc_enable = p->enable;
492 1.21.4.2 nathanw if (v & FB_CUR_SETPOS)
493 1.21.4.2 nathanw cc->cc_pos = p->pos;
494 1.21.4.2 nathanw if (v & FB_CUR_SETHOT)
495 1.21.4.2 nathanw cc->cc_hot = p->hot;
496 1.21.4.2 nathanw cg14_setcursor(sc);
497 1.21.4.2 nathanw }
498 1.21.4.2 nathanw if (v & FB_CUR_SETCMAP) {
499 1.21.4.2 nathanw cc->cc_color = tcm;
500 1.21.4.2 nathanw cg14_loadomap(sc); /* XXX defer to vertical retrace */
501 1.21.4.2 nathanw }
502 1.21.4.2 nathanw if (v & FB_CUR_SETSHAPE) {
503 1.21.4.2 nathanw cc->cc_size = p->size;
504 1.21.4.2 nathanw count = p->size.y * 32 / NBBY;
505 1.21.4.2 nathanw bzero((caddr_t)cc->cc_eplane, sizeof cc->cc_eplane);
506 1.21.4.2 nathanw bzero((caddr_t)cc->cc_cplane, sizeof cc->cc_cplane);
507 1.21.4.2 nathanw bcopy(p->mask, (caddr_t)cc->cc_eplane, count);
508 1.21.4.2 nathanw bcopy(p->image, (caddr_t)cc->cc_cplane, count);
509 1.21.4.2 nathanw cg14_loadcursor(sc);
510 1.21.4.2 nathanw }
511 1.21.4.2 nathanw break;
512 1.21.4.2 nathanw
513 1.21.4.2 nathanw #undef cc
514 1.21.4.2 nathanw #undef p
515 1.21.4.2 nathanw case FBIOGCURPOS:
516 1.21.4.2 nathanw *(struct fbcurpos *)data = sc->sc_cursor.cc_pos;
517 1.21.4.2 nathanw break;
518 1.21.4.2 nathanw
519 1.21.4.2 nathanw case FBIOSCURPOS:
520 1.21.4.2 nathanw sc->sc_cursor.cc_pos = *(struct fbcurpos *)data;
521 1.21.4.2 nathanw cg14_setcursor(sc);
522 1.21.4.2 nathanw break;
523 1.21.4.2 nathanw
524 1.21.4.2 nathanw case FBIOGCURMAX:
525 1.21.4.2 nathanw /* max cursor size is 32x32 */
526 1.21.4.2 nathanw ((struct fbcurpos *)data)->x = 32;
527 1.21.4.2 nathanw ((struct fbcurpos *)data)->y = 32;
528 1.21.4.2 nathanw break;
529 1.21.4.2 nathanw
530 1.21.4.2 nathanw default:
531 1.21.4.2 nathanw return (ENOTTY);
532 1.21.4.2 nathanw }
533 1.21.4.2 nathanw return (0);
534 1.21.4.2 nathanw }
535 1.21.4.2 nathanw
536 1.21.4.2 nathanw /*
537 1.21.4.2 nathanw * Undo the effect of an FBIOSVIDEO that turns the video off.
538 1.21.4.2 nathanw */
539 1.21.4.2 nathanw static void
540 1.21.4.2 nathanw cgfourteenunblank(dev)
541 1.21.4.2 nathanw struct device *dev;
542 1.21.4.2 nathanw {
543 1.21.4.2 nathanw
544 1.21.4.2 nathanw cg14_set_video((struct cgfourteen_softc *)dev, 1);
545 1.21.4.2 nathanw }
546 1.21.4.2 nathanw
547 1.21.4.2 nathanw /*
548 1.21.4.2 nathanw * Return the address that would map the given device at the given
549 1.21.4.2 nathanw * offset, allowing for the given protection, or return -1 for error.
550 1.21.4.2 nathanw *
551 1.21.4.2 nathanw * The cg14 frame buffer can be mapped in either 8-bit or 32-bit mode
552 1.21.4.2 nathanw * starting at the address stored in the PROM. In 8-bit mode, the X
553 1.21.4.2 nathanw * channel is not present, and can be ignored. In 32-bit mode, mapping
554 1.21.4.2 nathanw * at 0K delivers a 32-bpp buffer where the upper 8 bits select the X
555 1.21.4.2 nathanw * channel information. We hardwire the Xlut to all zeroes to insure
556 1.21.4.2 nathanw * that, regardless of this value, direct 24-bit color access will be
557 1.21.4.2 nathanw * used.
558 1.21.4.2 nathanw *
559 1.21.4.2 nathanw * Alternatively, mapping the frame buffer at an offset of 16M seems to
560 1.21.4.2 nathanw * tell the chip to ignore the X channel. XXX where does it get the X value
561 1.21.4.2 nathanw * to use?
562 1.21.4.2 nathanw */
563 1.21.4.2 nathanw paddr_t
564 1.21.4.2 nathanw cgfourteenmmap(dev, off, prot)
565 1.21.4.2 nathanw dev_t dev;
566 1.21.4.2 nathanw off_t off;
567 1.21.4.2 nathanw int prot;
568 1.21.4.2 nathanw {
569 1.21.4.2 nathanw struct cgfourteen_softc *sc = cgfourteen_cd.cd_devs[minor(dev)];
570 1.21.4.2 nathanw
571 1.21.4.2 nathanw if (off & PGOFSET)
572 1.21.4.2 nathanw panic("cgfourteenmmap");
573 1.21.4.2 nathanw
574 1.21.4.2 nathanw if (off < 0)
575 1.21.4.2 nathanw return (-1);
576 1.21.4.2 nathanw
577 1.21.4.2 nathanw #if defined(DEBUG) && defined(CG14_MAP_REGS) /* XXX: security hole */
578 1.21.4.2 nathanw /*
579 1.21.4.2 nathanw * Map the control registers into user space. Should only be
580 1.21.4.2 nathanw * used for debugging!
581 1.21.4.2 nathanw */
582 1.21.4.2 nathanw if ((u_int)off >= 0x10000000 && (u_int)off < 0x10000000 + 16*4096) {
583 1.21.4.2 nathanw off -= 0x10000000;
584 1.21.4.2 nathanw if (bus_space_mmap(sc->sc_bustag,
585 1.21.4.2 nathanw BUS_ADDR(sc->sc_physadr[CG14_CTL_IDX].sbr_slot,
586 1.21.4.2 nathanw sc->sc_physadr[CG14_CTL_IDX].sbr_offset),
587 1.21.4.2 nathanw off, prot, BUS_SPACE_MAP_LINEAR));
588 1.21.4.2 nathanw }
589 1.21.4.2 nathanw #endif
590 1.21.4.2 nathanw
591 1.21.4.2 nathanw if ((u_int)off >= NOOVERLAY)
592 1.21.4.2 nathanw off -= NOOVERLAY;
593 1.21.4.3 nathanw else if ((u_int)off >= START)
594 1.21.4.3 nathanw off -= START;
595 1.21.4.2 nathanw else
596 1.21.4.2 nathanw off = 0;
597 1.21.4.2 nathanw
598 1.21.4.3 nathanw /*
599 1.21.4.3 nathanw * fb_size includes the overlay space only for the CG8.
600 1.21.4.3 nathanw */
601 1.21.4.3 nathanw #ifdef CG14_CG8
602 1.21.4.3 nathanw if (off >= sc->sc_fb.fb_type.fb_size - START)
603 1.21.4.3 nathanw #else
604 1.21.4.3 nathanw if (off >= sc->sc_fb.fb_type.fb_size)
605 1.21.4.3 nathanw #endif
606 1.21.4.3 nathanw {
607 1.21.4.2 nathanw #ifdef DEBUG
608 1.21.4.2 nathanw printf("\nmmap request out of bounds: request 0x%x, "
609 1.21.4.2 nathanw "bound 0x%x\n", (unsigned) off,
610 1.21.4.2 nathanw (unsigned)sc->sc_fb.fb_type.fb_size);
611 1.21.4.2 nathanw #endif
612 1.21.4.2 nathanw return (-1);
613 1.21.4.2 nathanw }
614 1.21.4.2 nathanw
615 1.21.4.2 nathanw return (bus_space_mmap(sc->sc_bustag,
616 1.21.4.5 nathanw BUS_ADDR(sc->sc_physadr[CG14_PXL_IDX].oa_space,
617 1.21.4.5 nathanw sc->sc_physadr[CG14_PXL_IDX].oa_base),
618 1.21.4.2 nathanw off, prot, BUS_SPACE_MAP_LINEAR));
619 1.21.4.2 nathanw }
620 1.21.4.2 nathanw
621 1.21.4.2 nathanw /*
622 1.21.4.2 nathanw * Miscellaneous helper functions
623 1.21.4.2 nathanw */
624 1.21.4.2 nathanw
625 1.21.4.2 nathanw /* Initialize the framebuffer, storing away useful state for later reset */
626 1.21.4.2 nathanw static void
627 1.21.4.2 nathanw cg14_init(sc)
628 1.21.4.2 nathanw struct cgfourteen_softc *sc;
629 1.21.4.2 nathanw {
630 1.21.4.2 nathanw u_int32_t *clut;
631 1.21.4.2 nathanw u_int8_t *xlut;
632 1.21.4.2 nathanw int i;
633 1.21.4.2 nathanw
634 1.21.4.2 nathanw /*
635 1.21.4.2 nathanw * We stash away the following to restore on close:
636 1.21.4.2 nathanw *
637 1.21.4.2 nathanw * color look-up table 1 (sc->sc_saveclut)
638 1.21.4.2 nathanw * x look-up table (sc->sc_savexlut)
639 1.21.4.2 nathanw * control register (sc->sc_savectl)
640 1.21.4.2 nathanw * cursor control register (sc->sc_savehwc)
641 1.21.4.2 nathanw */
642 1.21.4.2 nathanw sc->sc_savectl = sc->sc_ctl->ctl_mctl;
643 1.21.4.2 nathanw sc->sc_savehwc = sc->sc_hwc->curs_ctl;
644 1.21.4.2 nathanw
645 1.21.4.2 nathanw clut = (u_int32_t *) sc->sc_clut1->clut_lut;
646 1.21.4.2 nathanw xlut = (u_int8_t *) sc->sc_xlut->xlut_lut;
647 1.21.4.2 nathanw for (i = 0; i < CG14_CLUT_SIZE; i++) {
648 1.21.4.2 nathanw sc->sc_saveclut.cm_chip[i] = clut[i];
649 1.21.4.2 nathanw sc->sc_savexlut[i] = xlut[i];
650 1.21.4.2 nathanw }
651 1.21.4.2 nathanw
652 1.21.4.2 nathanw #ifdef CG14_CG8
653 1.21.4.2 nathanw /*
654 1.21.4.2 nathanw * Enable the video, and put in 24 bit mode.
655 1.21.4.2 nathanw */
656 1.21.4.2 nathanw sc->sc_ctl->ctl_mctl = CG14_MCTL_ENABLEVID | CG14_MCTL_PIXMODE_32 |
657 1.21.4.2 nathanw CG14_MCTL_POWERCTL;
658 1.21.4.2 nathanw
659 1.21.4.2 nathanw /*
660 1.21.4.2 nathanw * Zero the xlut to enable direct-color mode
661 1.21.4.2 nathanw */
662 1.21.4.2 nathanw bzero(sc->sc_xlut, CG14_CLUT_SIZE);
663 1.21.4.2 nathanw #else
664 1.21.4.2 nathanw /*
665 1.21.4.2 nathanw * Enable the video and put it in 8 bit mode
666 1.21.4.2 nathanw */
667 1.21.4.2 nathanw sc->sc_ctl->ctl_mctl = CG14_MCTL_ENABLEVID | CG14_MCTL_PIXMODE_8 |
668 1.21.4.2 nathanw CG14_MCTL_POWERCTL;
669 1.21.4.2 nathanw #endif
670 1.21.4.2 nathanw }
671 1.21.4.2 nathanw
672 1.21.4.2 nathanw static void
673 1.21.4.2 nathanw cg14_reset(sc) /* Restore the state saved on cg14_init */
674 1.21.4.2 nathanw struct cgfourteen_softc *sc;
675 1.21.4.2 nathanw {
676 1.21.4.2 nathanw u_int32_t *clut;
677 1.21.4.2 nathanw u_int8_t *xlut;
678 1.21.4.2 nathanw int i;
679 1.21.4.2 nathanw
680 1.21.4.2 nathanw /*
681 1.21.4.2 nathanw * We restore the following, saved in cg14_init:
682 1.21.4.2 nathanw *
683 1.21.4.2 nathanw * color look-up table 1 (sc->sc_saveclut)
684 1.21.4.2 nathanw * x look-up table (sc->sc_savexlut)
685 1.21.4.2 nathanw * control register (sc->sc_savectl)
686 1.21.4.2 nathanw * cursor control register (sc->sc_savehwc)
687 1.21.4.2 nathanw *
688 1.21.4.2 nathanw * Note that we don't touch the video enable bits in the
689 1.21.4.2 nathanw * control register; otherwise, screenblank wouldn't work.
690 1.21.4.2 nathanw */
691 1.21.4.2 nathanw sc->sc_ctl->ctl_mctl = (sc->sc_ctl->ctl_mctl & (CG14_MCTL_ENABLEVID |
692 1.21.4.2 nathanw CG14_MCTL_POWERCTL)) |
693 1.21.4.2 nathanw (sc->sc_savectl & ~(CG14_MCTL_ENABLEVID |
694 1.21.4.2 nathanw CG14_MCTL_POWERCTL));
695 1.21.4.2 nathanw sc->sc_hwc->curs_ctl = sc->sc_savehwc;
696 1.21.4.2 nathanw
697 1.21.4.2 nathanw clut = (u_int32_t *) sc->sc_clut1->clut_lut;
698 1.21.4.2 nathanw xlut = (u_int8_t *) sc->sc_xlut->xlut_lut;
699 1.21.4.2 nathanw for (i = 0; i < CG14_CLUT_SIZE; i++) {
700 1.21.4.2 nathanw clut[i] = sc->sc_saveclut.cm_chip[i];
701 1.21.4.2 nathanw xlut[i] = sc->sc_savexlut[i];
702 1.21.4.2 nathanw }
703 1.21.4.2 nathanw }
704 1.21.4.2 nathanw
705 1.21.4.2 nathanw /* Enable/disable video display; power down monitor if DPMS-capable */
706 1.21.4.2 nathanw static void
707 1.21.4.2 nathanw cg14_set_video(sc, enable)
708 1.21.4.2 nathanw struct cgfourteen_softc *sc;
709 1.21.4.2 nathanw int enable;
710 1.21.4.2 nathanw {
711 1.21.4.2 nathanw /*
712 1.21.4.2 nathanw * We can only use DPMS to power down the display if the chip revision
713 1.21.4.2 nathanw * is greater than 0.
714 1.21.4.2 nathanw */
715 1.21.4.2 nathanw if (enable) {
716 1.21.4.2 nathanw if ((sc->sc_ctl->ctl_rsr & CG14_RSR_REVMASK) > 0)
717 1.21.4.2 nathanw sc->sc_ctl->ctl_mctl |= (CG14_MCTL_ENABLEVID |
718 1.21.4.2 nathanw CG14_MCTL_POWERCTL);
719 1.21.4.2 nathanw else
720 1.21.4.2 nathanw sc->sc_ctl->ctl_mctl |= CG14_MCTL_ENABLEVID;
721 1.21.4.2 nathanw } else {
722 1.21.4.2 nathanw if ((sc->sc_ctl->ctl_rsr & CG14_RSR_REVMASK) > 0)
723 1.21.4.2 nathanw sc->sc_ctl->ctl_mctl &= ~(CG14_MCTL_ENABLEVID |
724 1.21.4.2 nathanw CG14_MCTL_POWERCTL);
725 1.21.4.2 nathanw else
726 1.21.4.2 nathanw sc->sc_ctl->ctl_mctl &= ~CG14_MCTL_ENABLEVID;
727 1.21.4.2 nathanw }
728 1.21.4.2 nathanw }
729 1.21.4.2 nathanw
730 1.21.4.2 nathanw /* Get status of video display */
731 1.21.4.2 nathanw static int
732 1.21.4.2 nathanw cg14_get_video(sc)
733 1.21.4.2 nathanw struct cgfourteen_softc *sc;
734 1.21.4.2 nathanw {
735 1.21.4.2 nathanw return ((sc->sc_ctl->ctl_mctl & CG14_MCTL_ENABLEVID) != 0);
736 1.21.4.2 nathanw }
737 1.21.4.2 nathanw
738 1.21.4.2 nathanw /* Read the software shadow colormap */
739 1.21.4.2 nathanw static int
740 1.21.4.2 nathanw cg14_get_cmap(p, cm, cmsize)
741 1.21.4.2 nathanw struct fbcmap *p;
742 1.21.4.2 nathanw union cg14cmap *cm;
743 1.21.4.2 nathanw int cmsize;
744 1.21.4.2 nathanw {
745 1.21.4.4 nathanw u_int i, start, count;
746 1.21.4.4 nathanw u_char *cp;
747 1.21.4.2 nathanw
748 1.21.4.4 nathanw start = p->index;
749 1.21.4.4 nathanw count = p->count;
750 1.21.4.4 nathanw if (start >= cmsize || count > cmsize - start)
751 1.21.4.2 nathanw #ifdef DEBUG
752 1.21.4.2 nathanw {
753 1.21.4.2 nathanw printf("putcmaperror: start %d cmsize %d count %d\n",
754 1.21.4.2 nathanw start,cmsize,count);
755 1.21.4.2 nathanw #endif
756 1.21.4.4 nathanw return (EINVAL);
757 1.21.4.2 nathanw #ifdef DEBUG
758 1.21.4.2 nathanw }
759 1.21.4.2 nathanw #endif
760 1.21.4.2 nathanw
761 1.21.4.4 nathanw if (!uvm_useracc(p->red, count, B_WRITE) ||
762 1.21.4.4 nathanw !uvm_useracc(p->green, count, B_WRITE) ||
763 1.21.4.4 nathanw !uvm_useracc(p->blue, count, B_WRITE))
764 1.21.4.4 nathanw return (EFAULT);
765 1.21.4.4 nathanw for (cp = &cm->cm_map[start][0], i = 0; i < count; cp += 4, i++) {
766 1.21.4.4 nathanw p->red[i] = cp[3];
767 1.21.4.4 nathanw p->green[i] = cp[2];
768 1.21.4.4 nathanw p->blue[i] = cp[1];
769 1.21.4.4 nathanw }
770 1.21.4.4 nathanw return (0);
771 1.21.4.2 nathanw }
772 1.21.4.2 nathanw
773 1.21.4.2 nathanw /* Write the software shadow colormap */
774 1.21.4.2 nathanw static int
775 1.21.4.2 nathanw cg14_put_cmap(p, cm, cmsize)
776 1.21.4.4 nathanw struct fbcmap *p;
777 1.21.4.4 nathanw union cg14cmap *cm;
778 1.21.4.4 nathanw int cmsize;
779 1.21.4.4 nathanw {
780 1.21.4.4 nathanw u_int i, start, count;
781 1.21.4.4 nathanw u_char *cp;
782 1.21.4.4 nathanw
783 1.21.4.4 nathanw start = p->index;
784 1.21.4.4 nathanw count = p->count;
785 1.21.4.4 nathanw if (start >= cmsize || count > cmsize - start)
786 1.21.4.2 nathanw #ifdef DEBUG
787 1.21.4.2 nathanw {
788 1.21.4.2 nathanw printf("putcmaperror: start %d cmsize %d count %d\n",
789 1.21.4.2 nathanw start,cmsize,count);
790 1.21.4.2 nathanw #endif
791 1.21.4.4 nathanw return (EINVAL);
792 1.21.4.2 nathanw #ifdef DEBUG
793 1.21.4.2 nathanw }
794 1.21.4.2 nathanw #endif
795 1.21.4.2 nathanw
796 1.21.4.4 nathanw if (!uvm_useracc(p->red, count, B_READ) ||
797 1.21.4.4 nathanw !uvm_useracc(p->green, count, B_READ) ||
798 1.21.4.4 nathanw !uvm_useracc(p->blue, count, B_READ))
799 1.21.4.4 nathanw return (EFAULT);
800 1.21.4.4 nathanw for (cp = &cm->cm_map[start][0], i = 0; i < count; cp += 4, i++) {
801 1.21.4.4 nathanw cp[3] = p->red[i];
802 1.21.4.4 nathanw cp[2] = p->green[i];
803 1.21.4.4 nathanw cp[1] = p->blue[i];
804 1.21.4.2 nathanw cp[0] = 0; /* no alpha channel */
805 1.21.4.4 nathanw }
806 1.21.4.4 nathanw return (0);
807 1.21.4.2 nathanw }
808 1.21.4.2 nathanw
809 1.21.4.2 nathanw static void
810 1.21.4.2 nathanw cg14_load_hwcmap(sc, start, ncolors)
811 1.21.4.2 nathanw struct cgfourteen_softc *sc;
812 1.21.4.2 nathanw int start, ncolors;
813 1.21.4.2 nathanw {
814 1.21.4.2 nathanw /* XXX switch to auto-increment, and on retrace intr */
815 1.21.4.2 nathanw
816 1.21.4.2 nathanw /* Setup pointers to source and dest */
817 1.21.4.2 nathanw u_int32_t *colp = &sc->sc_cmap.cm_chip[start];
818 1.21.4.2 nathanw volatile u_int32_t *lutp = &sc->sc_clut1->clut_lut[start];
819 1.21.4.2 nathanw
820 1.21.4.2 nathanw /* Copy by words */
821 1.21.4.2 nathanw while (--ncolors >= 0)
822 1.21.4.2 nathanw *lutp++ = *colp++;
823 1.21.4.2 nathanw }
824 1.21.4.2 nathanw
825 1.21.4.2 nathanw /*
826 1.21.4.2 nathanw * Load the cursor (overlay `foreground' and `background') colors.
827 1.21.4.2 nathanw */
828 1.21.4.2 nathanw static void
829 1.21.4.2 nathanw cg14_setcursor(sc)
830 1.21.4.2 nathanw struct cgfourteen_softc *sc;
831 1.21.4.2 nathanw {
832 1.21.4.2 nathanw /* we need to subtract the hot-spot value here */
833 1.21.4.2 nathanw #define COORD(f) (sc->sc_cursor.cc_pos.f - sc->sc_cursor.cc_hot.f)
834 1.21.4.2 nathanw
835 1.21.4.2 nathanw sc->sc_hwc->curs_ctl = (sc->sc_cursor.cc_enable ? CG14_CURS_ENABLE : 0);
836 1.21.4.2 nathanw sc->sc_hwc->curs_x = COORD(x);
837 1.21.4.2 nathanw sc->sc_hwc->curs_y = COORD(y);
838 1.21.4.2 nathanw
839 1.21.4.2 nathanw #undef COORD
840 1.21.4.2 nathanw }
841 1.21.4.2 nathanw
842 1.21.4.2 nathanw static void
843 1.21.4.2 nathanw cg14_loadcursor(sc)
844 1.21.4.2 nathanw struct cgfourteen_softc *sc;
845 1.21.4.2 nathanw {
846 1.21.4.2 nathanw volatile struct cg14curs *hwc;
847 1.21.4.2 nathanw u_int edgemask, m;
848 1.21.4.2 nathanw int i;
849 1.21.4.2 nathanw
850 1.21.4.2 nathanw /*
851 1.21.4.2 nathanw * Keep the top size.x bits. Here we *throw out* the top
852 1.21.4.2 nathanw * size.x bits from an all-one-bits word, introducing zeros in
853 1.21.4.2 nathanw * the top size.x bits, then invert all the bits to get what
854 1.21.4.2 nathanw * we really wanted as our mask. But this fails if size.x is
855 1.21.4.2 nathanw * 32---a sparc uses only the low 5 bits of the shift count---
856 1.21.4.2 nathanw * so we have to special case that.
857 1.21.4.2 nathanw */
858 1.21.4.2 nathanw edgemask = ~0;
859 1.21.4.2 nathanw if (sc->sc_cursor.cc_size.x < 32)
860 1.21.4.2 nathanw edgemask = ~(edgemask >> sc->sc_cursor.cc_size.x);
861 1.21.4.2 nathanw hwc = sc->sc_hwc;
862 1.21.4.2 nathanw for (i = 0; i < 32; i++) {
863 1.21.4.2 nathanw m = sc->sc_cursor.cc_eplane[i] & edgemask;
864 1.21.4.2 nathanw hwc->curs_plane0[i] = m;
865 1.21.4.2 nathanw hwc->curs_plane1[i] = m & sc->sc_cursor.cc_cplane[i];
866 1.21.4.2 nathanw }
867 1.21.4.2 nathanw }
868 1.21.4.2 nathanw
869 1.21.4.2 nathanw static void
870 1.21.4.2 nathanw cg14_loadomap(sc)
871 1.21.4.2 nathanw struct cgfourteen_softc *sc;
872 1.21.4.2 nathanw {
873 1.21.4.2 nathanw /* set background color */
874 1.21.4.2 nathanw sc->sc_hwc->curs_color1 = sc->sc_cursor.cc_color.cm_chip[0];
875 1.21.4.2 nathanw /* set foreground color */
876 1.21.4.2 nathanw sc->sc_hwc->curs_color2 = sc->sc_cursor.cc_color.cm_chip[1];
877 1.21.4.2 nathanw }
878