cgtwo.c revision 1.35.6.4 1 1.35.6.4 nathanw /* $NetBSD: cgtwo.c,v 1.35.6.4 2002/10/18 02:39: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/cgtworeg.h>
74 1.35.6.2 nathanw
75 1.35.6.2 nathanw
76 1.35.6.2 nathanw /* per-display variables */
77 1.35.6.2 nathanw struct cgtwo_softc {
78 1.35.6.2 nathanw struct device sc_dev; /* base device */
79 1.35.6.2 nathanw struct fbdevice sc_fb; /* frame buffer device */
80 1.35.6.2 nathanw vme_addr_t sc_paddr;
81 1.35.6.2 nathanw vme_chipset_tag_t sc_ct;
82 1.35.6.2 nathanw bus_space_tag_t sc_bt;
83 1.35.6.2 nathanw volatile struct cg2statusreg *sc_reg; /* CG2 control registers */
84 1.35.6.2 nathanw volatile u_short *sc_cmap;
85 1.35.6.2 nathanw #define sc_redmap(sc) ((sc)->sc_cmap)
86 1.35.6.2 nathanw #define sc_greenmap(sc) ((sc)->sc_cmap + CG2_CMSIZE)
87 1.35.6.2 nathanw #define sc_bluemap(sc) ((sc)->sc_cmap + 2 * CG2_CMSIZE)
88 1.35.6.2 nathanw };
89 1.35.6.2 nathanw
90 1.35.6.2 nathanw /* autoconfiguration driver */
91 1.35.6.2 nathanw static void cgtwoattach __P((struct device *, struct device *, void *));
92 1.35.6.2 nathanw static int cgtwomatch __P((struct device *, struct cfdata *, void *));
93 1.35.6.2 nathanw static void cgtwounblank __P((struct device *));
94 1.35.6.2 nathanw int cgtwogetcmap __P((struct cgtwo_softc *, struct fbcmap *));
95 1.35.6.2 nathanw int cgtwoputcmap __P((struct cgtwo_softc *, struct fbcmap *));
96 1.35.6.2 nathanw
97 1.35.6.4 nathanw CFATTACH_DECL(cgtwo, sizeof(struct cgtwo_softc),
98 1.35.6.4 nathanw cgtwomatch, cgtwoattach, NULL, NULL);
99 1.35.6.2 nathanw
100 1.35.6.2 nathanw extern struct cfdriver cgtwo_cd;
101 1.35.6.2 nathanw
102 1.35.6.3 nathanw dev_type_open(cgtwoopen);
103 1.35.6.3 nathanw dev_type_ioctl(cgtwoioctl);
104 1.35.6.3 nathanw dev_type_mmap(cgtwommap);
105 1.35.6.3 nathanw
106 1.35.6.3 nathanw const struct cdevsw cgtwo_cdevsw = {
107 1.35.6.3 nathanw cgtwoopen, nullclose, noread, nowrite, cgtwoioctl,
108 1.35.6.3 nathanw nostop, notty, nopoll, cgtwommap,
109 1.35.6.3 nathanw };
110 1.35.6.3 nathanw
111 1.35.6.2 nathanw /* frame buffer generic driver */
112 1.35.6.2 nathanw static struct fbdriver cgtwofbdriver = {
113 1.35.6.3 nathanw cgtwounblank, cgtwoopen, nullclose, cgtwoioctl, nopoll, cgtwommap
114 1.35.6.2 nathanw };
115 1.35.6.2 nathanw
116 1.35.6.2 nathanw /*
117 1.35.6.2 nathanw * Match a cgtwo.
118 1.35.6.2 nathanw */
119 1.35.6.2 nathanw int
120 1.35.6.2 nathanw cgtwomatch(parent, cf, aux)
121 1.35.6.2 nathanw struct device *parent;
122 1.35.6.2 nathanw struct cfdata *cf;
123 1.35.6.2 nathanw void *aux;
124 1.35.6.2 nathanw {
125 1.35.6.2 nathanw struct vme_attach_args *va = aux;
126 1.35.6.2 nathanw vme_chipset_tag_t ct = va->va_vct;
127 1.35.6.2 nathanw vme_am_t mod;
128 1.35.6.2 nathanw
129 1.35.6.2 nathanw /*
130 1.35.6.2 nathanw * Mask out invalid flags from the user.
131 1.35.6.2 nathanw */
132 1.35.6.2 nathanw cf->cf_flags &= FB_USERMASK;
133 1.35.6.2 nathanw
134 1.35.6.2 nathanw mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
135 1.35.6.2 nathanw if (vme_probe(ct, va->r[0].offset + CG2_CTLREG_OFF, 2, mod, VME_D16,
136 1.35.6.2 nathanw 0, 0)) {
137 1.35.6.2 nathanw return (0);
138 1.35.6.2 nathanw }
139 1.35.6.2 nathanw
140 1.35.6.2 nathanw return (1);
141 1.35.6.2 nathanw }
142 1.35.6.2 nathanw
143 1.35.6.2 nathanw /*
144 1.35.6.2 nathanw * Attach a display. We need to notice if it is the console, too.
145 1.35.6.2 nathanw */
146 1.35.6.2 nathanw void
147 1.35.6.2 nathanw cgtwoattach(parent, self, aux)
148 1.35.6.2 nathanw struct device *parent, *self;
149 1.35.6.2 nathanw void *aux;
150 1.35.6.2 nathanw {
151 1.35.6.2 nathanw struct vme_attach_args *va = aux;
152 1.35.6.2 nathanw vme_chipset_tag_t ct = va->va_vct;
153 1.35.6.2 nathanw bus_space_tag_t bt;
154 1.35.6.2 nathanw bus_space_handle_t bh;
155 1.35.6.2 nathanw vme_am_t mod;
156 1.35.6.2 nathanw vme_mapresc_t resc;
157 1.35.6.2 nathanw struct cgtwo_softc *sc = (struct cgtwo_softc *)self;
158 1.35.6.2 nathanw struct fbdevice *fb = &sc->sc_fb;
159 1.35.6.2 nathanw struct eeprom *eep = (struct eeprom *)eeprom_va;
160 1.35.6.2 nathanw int isconsole = 0;
161 1.35.6.2 nathanw char *nam = NULL;
162 1.35.6.2 nathanw
163 1.35.6.2 nathanw sc->sc_ct = ct;
164 1.35.6.2 nathanw fb->fb_driver = &cgtwofbdriver;
165 1.35.6.2 nathanw fb->fb_device = &sc->sc_dev;
166 1.35.6.2 nathanw fb->fb_type.fb_type = FBTYPE_SUN2COLOR;
167 1.35.6.2 nathanw fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
168 1.35.6.2 nathanw
169 1.35.6.2 nathanw fb->fb_type.fb_depth = 8;
170 1.35.6.2 nathanw fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
171 1.35.6.2 nathanw
172 1.35.6.2 nathanw fb->fb_type.fb_cmsize = 256;
173 1.35.6.2 nathanw fb->fb_type.fb_size = roundup(CG2_MAPPED_SIZE, NBPG);
174 1.35.6.2 nathanw printf(": %s, %d x %d", nam,
175 1.35.6.2 nathanw fb->fb_type.fb_width, fb->fb_type.fb_height);
176 1.35.6.2 nathanw
177 1.35.6.2 nathanw /*
178 1.35.6.2 nathanw * When the ROM has mapped in a cgtwo display, the address
179 1.35.6.2 nathanw * maps only the video RAM, so in any case we have to map the
180 1.35.6.2 nathanw * registers ourselves. We only need the video RAM if we are
181 1.35.6.2 nathanw * going to print characters via rconsole.
182 1.35.6.2 nathanw */
183 1.35.6.2 nathanw sc->sc_paddr = va->r[0].offset;
184 1.35.6.2 nathanw mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
185 1.35.6.2 nathanw
186 1.35.6.2 nathanw if (vme_space_map(ct, sc->sc_paddr + CG2_ROPMEM_OFF +
187 1.35.6.2 nathanw offsetof(struct cg2fb, status.reg),
188 1.35.6.2 nathanw sizeof(struct cg2statusreg), mod, VME_D16, 0,
189 1.35.6.2 nathanw &bt, &bh, &resc) != 0)
190 1.35.6.2 nathanw panic("cgtwo: vme_map status");
191 1.35.6.2 nathanw sc->sc_bt = bt;
192 1.35.6.2 nathanw sc->sc_reg = (volatile struct cg2statusreg *)bh; /* XXX */
193 1.35.6.2 nathanw
194 1.35.6.2 nathanw if (vme_space_map(ct, sc->sc_paddr + CG2_ROPMEM_OFF +
195 1.35.6.2 nathanw offsetof(struct cg2fb, redmap[0]),
196 1.35.6.2 nathanw 3 * CG2_CMSIZE, mod, VME_D16, 0,
197 1.35.6.2 nathanw &bt, &bh, &resc) != 0)
198 1.35.6.2 nathanw panic("cgtwo: vme_map cmap");
199 1.35.6.2 nathanw sc->sc_cmap = (volatile u_short *)bh; /* XXX */
200 1.35.6.2 nathanw
201 1.35.6.2 nathanw /*
202 1.35.6.2 nathanw * Assume this is the console if there's no eeprom info
203 1.35.6.2 nathanw * to be found.
204 1.35.6.2 nathanw */
205 1.35.6.2 nathanw if (eep == NULL || eep->eeConsole == EE_CONS_COLOR)
206 1.35.6.2 nathanw isconsole = fb_is_console(0);
207 1.35.6.2 nathanw else
208 1.35.6.2 nathanw isconsole = 0;
209 1.35.6.2 nathanw
210 1.35.6.2 nathanw if (isconsole) {
211 1.35.6.2 nathanw if (vme_space_map(ct, sc->sc_paddr + CG2_PIXMAP_OFF,
212 1.35.6.2 nathanw CG2_PIXMAP_SIZE, mod, VME_D16, 0,
213 1.35.6.2 nathanw &bt, &bh, &resc) != 0)
214 1.35.6.2 nathanw panic("cgtwo: vme_map pixels");
215 1.35.6.2 nathanw
216 1.35.6.2 nathanw fb->fb_pixels = (caddr_t)bh; /* XXX */
217 1.35.6.2 nathanw printf(" (console)\n");
218 1.35.6.2 nathanw #ifdef RASTERCONSOLE
219 1.35.6.2 nathanw fbrcons_init(fb);
220 1.35.6.2 nathanw #endif
221 1.35.6.2 nathanw } else
222 1.35.6.2 nathanw printf("\n");
223 1.35.6.2 nathanw
224 1.35.6.2 nathanw fb_attach(fb, isconsole);
225 1.35.6.2 nathanw }
226 1.35.6.2 nathanw
227 1.35.6.2 nathanw int
228 1.35.6.2 nathanw cgtwoopen(dev, flags, mode, p)
229 1.35.6.2 nathanw dev_t dev;
230 1.35.6.2 nathanw int flags, mode;
231 1.35.6.2 nathanw struct proc *p;
232 1.35.6.2 nathanw {
233 1.35.6.2 nathanw int unit = minor(dev);
234 1.35.6.2 nathanw
235 1.35.6.2 nathanw if (unit >= cgtwo_cd.cd_ndevs || cgtwo_cd.cd_devs[unit] == NULL)
236 1.35.6.2 nathanw return (ENXIO);
237 1.35.6.2 nathanw return (0);
238 1.35.6.2 nathanw }
239 1.35.6.2 nathanw
240 1.35.6.2 nathanw int
241 1.35.6.2 nathanw cgtwoioctl(dev, cmd, data, flags, p)
242 1.35.6.2 nathanw dev_t dev;
243 1.35.6.2 nathanw u_long cmd;
244 1.35.6.2 nathanw register caddr_t data;
245 1.35.6.2 nathanw int flags;
246 1.35.6.2 nathanw struct proc *p;
247 1.35.6.2 nathanw {
248 1.35.6.2 nathanw register struct cgtwo_softc *sc = cgtwo_cd.cd_devs[minor(dev)];
249 1.35.6.2 nathanw register struct fbgattr *fba;
250 1.35.6.2 nathanw
251 1.35.6.2 nathanw switch (cmd) {
252 1.35.6.2 nathanw
253 1.35.6.2 nathanw case FBIOGTYPE:
254 1.35.6.2 nathanw *(struct fbtype *)data = sc->sc_fb.fb_type;
255 1.35.6.2 nathanw break;
256 1.35.6.2 nathanw
257 1.35.6.2 nathanw case FBIOGATTR:
258 1.35.6.2 nathanw fba = (struct fbgattr *)data;
259 1.35.6.2 nathanw fba->real_type = sc->sc_fb.fb_type.fb_type;
260 1.35.6.2 nathanw fba->owner = 0; /* XXX ??? */
261 1.35.6.2 nathanw fba->fbtype = sc->sc_fb.fb_type;
262 1.35.6.2 nathanw fba->sattr.flags = 0;
263 1.35.6.2 nathanw fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
264 1.35.6.2 nathanw fba->sattr.dev_specific[0] = -1;
265 1.35.6.2 nathanw fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
266 1.35.6.2 nathanw fba->emu_types[1] = -1;
267 1.35.6.2 nathanw break;
268 1.35.6.2 nathanw
269 1.35.6.2 nathanw case FBIOGETCMAP:
270 1.35.6.2 nathanw return cgtwogetcmap(sc, (struct fbcmap *) data);
271 1.35.6.2 nathanw
272 1.35.6.2 nathanw case FBIOPUTCMAP:
273 1.35.6.2 nathanw return cgtwoputcmap(sc, (struct fbcmap *) data);
274 1.35.6.2 nathanw
275 1.35.6.2 nathanw case FBIOGVIDEO:
276 1.35.6.2 nathanw *(int *)data = sc->sc_reg->video_enab;
277 1.35.6.2 nathanw break;
278 1.35.6.2 nathanw
279 1.35.6.2 nathanw case FBIOSVIDEO:
280 1.35.6.2 nathanw sc->sc_reg->video_enab = (*(int*)data) & 1;
281 1.35.6.2 nathanw break;
282 1.35.6.2 nathanw
283 1.35.6.2 nathanw default:
284 1.35.6.2 nathanw return (ENOTTY);
285 1.35.6.2 nathanw }
286 1.35.6.2 nathanw return (0);
287 1.35.6.2 nathanw }
288 1.35.6.2 nathanw
289 1.35.6.2 nathanw /*
290 1.35.6.2 nathanw * Undo the effect of an FBIOSVIDEO that turns the video off.
291 1.35.6.2 nathanw */
292 1.35.6.2 nathanw static void
293 1.35.6.2 nathanw cgtwounblank(dev)
294 1.35.6.2 nathanw struct device *dev;
295 1.35.6.2 nathanw {
296 1.35.6.2 nathanw struct cgtwo_softc *sc = (struct cgtwo_softc *)dev;
297 1.35.6.2 nathanw sc->sc_reg->video_enab = 1;
298 1.35.6.2 nathanw }
299 1.35.6.2 nathanw
300 1.35.6.2 nathanw /*
301 1.35.6.2 nathanw */
302 1.35.6.2 nathanw int
303 1.35.6.2 nathanw cgtwogetcmap(sc, cmap)
304 1.35.6.2 nathanw register struct cgtwo_softc *sc;
305 1.35.6.2 nathanw register struct fbcmap *cmap;
306 1.35.6.2 nathanw {
307 1.35.6.2 nathanw u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
308 1.35.6.2 nathanw int error, start, count, ecount;
309 1.35.6.2 nathanw register u_int i;
310 1.35.6.2 nathanw register volatile u_short *p;
311 1.35.6.2 nathanw
312 1.35.6.2 nathanw start = cmap->index;
313 1.35.6.2 nathanw count = cmap->count;
314 1.35.6.2 nathanw ecount = start + count;
315 1.35.6.2 nathanw if (start >= CG2_CMSIZE || count > CG2_CMSIZE - start)
316 1.35.6.2 nathanw return (EINVAL);
317 1.35.6.2 nathanw
318 1.35.6.2 nathanw /* XXX - Wait for retrace? */
319 1.35.6.2 nathanw
320 1.35.6.2 nathanw /* Copy hardware to local arrays. */
321 1.35.6.2 nathanw p = &sc_redmap(sc)[start];
322 1.35.6.2 nathanw for (i = start; i < ecount; i++)
323 1.35.6.2 nathanw red[i] = *p++;
324 1.35.6.2 nathanw p = &sc_greenmap(sc)[start];
325 1.35.6.2 nathanw for (i = start; i < ecount; i++)
326 1.35.6.2 nathanw green[i] = *p++;
327 1.35.6.2 nathanw p = &sc_bluemap(sc)[start];
328 1.35.6.2 nathanw for (i = start; i < ecount; i++)
329 1.35.6.2 nathanw blue[i] = *p++;
330 1.35.6.2 nathanw
331 1.35.6.2 nathanw /* Copy local arrays to user space. */
332 1.35.6.2 nathanw if ((error = copyout(red + start, cmap->red, count)) != 0)
333 1.35.6.2 nathanw return (error);
334 1.35.6.2 nathanw if ((error = copyout(green + start, cmap->green, count)) != 0)
335 1.35.6.2 nathanw return (error);
336 1.35.6.2 nathanw if ((error = copyout(blue + start, cmap->blue, count)) != 0)
337 1.35.6.2 nathanw return (error);
338 1.35.6.2 nathanw
339 1.35.6.2 nathanw return (0);
340 1.35.6.2 nathanw }
341 1.35.6.2 nathanw
342 1.35.6.2 nathanw /*
343 1.35.6.2 nathanw */
344 1.35.6.2 nathanw int
345 1.35.6.2 nathanw cgtwoputcmap(sc, cmap)
346 1.35.6.2 nathanw register struct cgtwo_softc *sc;
347 1.35.6.2 nathanw register struct fbcmap *cmap;
348 1.35.6.2 nathanw {
349 1.35.6.2 nathanw u_char red[CG2_CMSIZE], green[CG2_CMSIZE], blue[CG2_CMSIZE];
350 1.35.6.2 nathanw int error;
351 1.35.6.2 nathanw u_int start, count, ecount;
352 1.35.6.2 nathanw register u_int i;
353 1.35.6.2 nathanw register volatile u_short *p;
354 1.35.6.2 nathanw
355 1.35.6.2 nathanw start = cmap->index;
356 1.35.6.2 nathanw count = cmap->count;
357 1.35.6.2 nathanw ecount = start + count;
358 1.35.6.2 nathanw if (start >= CG2_CMSIZE || count > CG2_CMSIZE - start)
359 1.35.6.2 nathanw return (EINVAL);
360 1.35.6.2 nathanw
361 1.35.6.2 nathanw /* Copy from user space to local arrays. */
362 1.35.6.2 nathanw if ((error = copyin(cmap->red, red + start, count)) != 0)
363 1.35.6.2 nathanw return (error);
364 1.35.6.2 nathanw if ((error = copyin(cmap->green, green + start, count)) != 0)
365 1.35.6.2 nathanw return (error);
366 1.35.6.2 nathanw if ((error = copyin(cmap->blue, blue + start, count)) != 0)
367 1.35.6.2 nathanw return (error);
368 1.35.6.2 nathanw
369 1.35.6.2 nathanw /* XXX - Wait for retrace? */
370 1.35.6.2 nathanw
371 1.35.6.2 nathanw /* Copy from local arrays to hardware. */
372 1.35.6.2 nathanw p = &sc_redmap(sc)[start];
373 1.35.6.2 nathanw for (i = start; i < ecount; i++)
374 1.35.6.2 nathanw *p++ = red[i];
375 1.35.6.2 nathanw p = &sc_greenmap(sc)[start];
376 1.35.6.2 nathanw for (i = start; i < ecount; i++)
377 1.35.6.2 nathanw *p++ = green[i];
378 1.35.6.2 nathanw p = &sc_bluemap(sc)[start];
379 1.35.6.2 nathanw for (i = start; i < ecount; i++)
380 1.35.6.2 nathanw *p++ = blue[i];
381 1.35.6.2 nathanw
382 1.35.6.2 nathanw return (0);
383 1.35.6.2 nathanw }
384 1.35.6.2 nathanw
385 1.35.6.2 nathanw /*
386 1.35.6.2 nathanw * Return the address that would map the given device at the given
387 1.35.6.2 nathanw * offset, allowing for the given protection, or return -1 for error.
388 1.35.6.2 nathanw */
389 1.35.6.2 nathanw paddr_t
390 1.35.6.2 nathanw cgtwommap(dev, off, prot)
391 1.35.6.2 nathanw dev_t dev;
392 1.35.6.2 nathanw off_t off;
393 1.35.6.2 nathanw int prot;
394 1.35.6.2 nathanw {
395 1.35.6.2 nathanw register struct cgtwo_softc *sc = cgtwo_cd.cd_devs[minor(dev)];
396 1.35.6.2 nathanw vme_am_t mod;
397 1.35.6.2 nathanw bus_space_handle_t bh;
398 1.35.6.2 nathanw extern int sparc_vme_mmap_cookie __P((vme_addr_t, vme_am_t,
399 1.35.6.2 nathanw bus_space_handle_t *));
400 1.35.6.2 nathanw
401 1.35.6.2 nathanw if (off & PGOFSET)
402 1.35.6.2 nathanw panic("cgtwommap");
403 1.35.6.2 nathanw
404 1.35.6.2 nathanw if (off >= sc->sc_fb.fb_type.fb_size)
405 1.35.6.2 nathanw return (-1);
406 1.35.6.2 nathanw
407 1.35.6.2 nathanw /* Apparently, the pixels are in 32-bit data space */
408 1.35.6.2 nathanw mod = 0x3d; /* VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA */
409 1.35.6.2 nathanw
410 1.35.6.2 nathanw if (sparc_vme_mmap_cookie(sc->sc_paddr + off, mod, &bh) != 0)
411 1.35.6.2 nathanw panic("cgtwommap");
412 1.35.6.2 nathanw
413 1.35.6.2 nathanw return ((paddr_t)bh);
414 1.35.6.2 nathanw }
415