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