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