cgsix.c revision 1.27 1 1.27 macallan /* $NetBSD: cgsix.c,v 1.27 2005/06/28 20:55:21 macallan Exp $ */
2 1.1 pk
3 1.1 pk /*-
4 1.1 pk * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 pk * All rights reserved.
6 1.1 pk *
7 1.1 pk * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pk * by Paul Kranenburg.
9 1.1 pk *
10 1.1 pk * Redistribution and use in source and binary forms, with or without
11 1.1 pk * modification, are permitted provided that the following conditions
12 1.1 pk * are met:
13 1.1 pk * 1. Redistributions of source code must retain the above copyright
14 1.1 pk * notice, this list of conditions and the following disclaimer.
15 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pk * notice, this list of conditions and the following disclaimer in the
17 1.1 pk * documentation and/or other materials provided with the distribution.
18 1.1 pk * 3. All advertising materials mentioning features or use of this software
19 1.1 pk * must display the following acknowledgement:
20 1.1 pk * This product includes software developed by the NetBSD
21 1.1 pk * Foundation, Inc. and its contributors.
22 1.1 pk * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 pk * contributors may be used to endorse or promote products derived
24 1.1 pk * from this software without specific prior written permission.
25 1.1 pk *
26 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
37 1.1 pk */
38 1.1 pk
39 1.1 pk /*
40 1.1 pk * Copyright (c) 1993
41 1.1 pk * The Regents of the University of California. All rights reserved.
42 1.1 pk *
43 1.1 pk * This software was developed by the Computer Systems Engineering group
44 1.1 pk * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
45 1.1 pk * contributed to Berkeley.
46 1.1 pk *
47 1.1 pk * All advertising materials mentioning features or use of this software
48 1.1 pk * must display the following acknowledgement:
49 1.1 pk * This product includes software developed by the University of
50 1.1 pk * California, Lawrence Berkeley Laboratory.
51 1.1 pk *
52 1.1 pk * Redistribution and use in source and binary forms, with or without
53 1.1 pk * modification, are permitted provided that the following conditions
54 1.1 pk * are met:
55 1.1 pk * 1. Redistributions of source code must retain the above copyright
56 1.1 pk * notice, this list of conditions and the following disclaimer.
57 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
58 1.1 pk * notice, this list of conditions and the following disclaimer in the
59 1.1 pk * documentation and/or other materials provided with the distribution.
60 1.13 agc * 3. Neither the name of the University nor the names of its contributors
61 1.1 pk * may be used to endorse or promote products derived from this software
62 1.1 pk * without specific prior written permission.
63 1.1 pk *
64 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 1.1 pk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 1.1 pk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 1.1 pk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 1.1 pk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 1.1 pk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 1.1 pk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 1.1 pk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 1.1 pk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 1.1 pk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 1.1 pk * SUCH DAMAGE.
75 1.1 pk *
76 1.1 pk * @(#)cgsix.c 8.4 (Berkeley) 1/21/94
77 1.1 pk */
78 1.1 pk
79 1.1 pk /*
80 1.1 pk * color display (cgsix) driver.
81 1.1 pk *
82 1.1 pk * Does not handle interrupts, even though they can occur.
83 1.1 pk *
84 1.1 pk * XXX should defer colormap updates to vertical retrace interrupts
85 1.1 pk */
86 1.7 lukem
87 1.7 lukem #include <sys/cdefs.h>
88 1.27 macallan __KERNEL_RCSID(0, "$NetBSD: cgsix.c,v 1.27 2005/06/28 20:55:21 macallan Exp $");
89 1.1 pk
90 1.1 pk #include <sys/param.h>
91 1.1 pk #include <sys/systm.h>
92 1.1 pk #include <sys/buf.h>
93 1.1 pk #include <sys/device.h>
94 1.1 pk #include <sys/ioctl.h>
95 1.1 pk #include <sys/malloc.h>
96 1.1 pk #include <sys/mman.h>
97 1.1 pk #include <sys/tty.h>
98 1.1 pk #include <sys/conf.h>
99 1.1 pk
100 1.1 pk #ifdef DEBUG
101 1.1 pk #include <sys/proc.h>
102 1.1 pk #include <sys/syslog.h>
103 1.1 pk #endif
104 1.1 pk
105 1.1 pk #include <uvm/uvm_extern.h>
106 1.1 pk
107 1.1 pk #include <machine/bus.h>
108 1.1 pk
109 1.1 pk #include <dev/sun/fbio.h>
110 1.1 pk #include <dev/sun/fbvar.h>
111 1.1 pk
112 1.1 pk #include <dev/sun/btreg.h>
113 1.1 pk #include <dev/sun/btvar.h>
114 1.1 pk #include <dev/sun/pfourreg.h>
115 1.1 pk
116 1.18 martin #include <dev/wscons/wsconsio.h>
117 1.18 martin #include <dev/wsfont/wsfont.h>
118 1.1 pk #include <dev/rasops/rasops.h>
119 1.18 martin
120 1.18 martin #include "opt_wsemul.h"
121 1.20 martin #include "rasops_glue.h"
122 1.1 pk
123 1.23 macallan #include <dev/sun/cgsixreg.h>
124 1.23 macallan #include <dev/sun/cgsixvar.h>
125 1.23 macallan
126 1.1 pk static void cg6_unblank(struct device *);
127 1.1 pk
128 1.8 gehenna extern struct cfdriver cgsix_cd;
129 1.1 pk
130 1.8 gehenna dev_type_open(cgsixopen);
131 1.8 gehenna dev_type_close(cgsixclose);
132 1.8 gehenna dev_type_ioctl(cgsixioctl);
133 1.8 gehenna dev_type_mmap(cgsixmmap);
134 1.8 gehenna
135 1.8 gehenna const struct cdevsw cgsix_cdevsw = {
136 1.8 gehenna cgsixopen, cgsixclose, noread, nowrite, cgsixioctl,
137 1.9 jdolecek nostop, notty, nopoll, cgsixmmap, nokqfilter,
138 1.8 gehenna };
139 1.1 pk
140 1.1 pk /* frame buffer generic driver */
141 1.1 pk static struct fbdriver cg6_fbdriver = {
142 1.9 jdolecek cg6_unblank, cgsixopen, cgsixclose, cgsixioctl, nopoll, cgsixmmap,
143 1.9 jdolecek nokqfilter
144 1.1 pk };
145 1.1 pk
146 1.1 pk static void cg6_reset (struct cgsix_softc *);
147 1.1 pk static void cg6_loadcmap (struct cgsix_softc *, int, int);
148 1.1 pk static void cg6_loadomap (struct cgsix_softc *);
149 1.1 pk static void cg6_setcursor (struct cgsix_softc *);/* set position */
150 1.1 pk static void cg6_loadcursor (struct cgsix_softc *);/* set shape */
151 1.1 pk
152 1.23 macallan #if NWSDISPLAY > 0
153 1.23 macallan static void cg6_setup_palette(struct cgsix_softc *);
154 1.23 macallan
155 1.18 martin struct wsscreen_descr cgsix_defaultscreen = {
156 1.18 martin "std",
157 1.18 martin 0, 0, /* will be filled in -- XXX shouldn't, it's global */
158 1.23 macallan NULL, /* textops */
159 1.23 macallan 8, 16, /* font width/height */
160 1.23 macallan WSSCREEN_WSCOLORS /* capabilities */
161 1.18 martin };
162 1.18 martin
163 1.23 macallan static int cgsix_ioctl(void *, u_long, caddr_t, int, struct proc *);
164 1.23 macallan static paddr_t cgsix_mmap(void *, off_t, int);
165 1.23 macallan void cgsix_init_screen(struct cgsix_softc *, struct cg6_screen *,
166 1.23 macallan int, long *);
167 1.23 macallan
168 1.23 macallan static int cgsix_alloc_screen(void *, const struct wsscreen_descr *,
169 1.22 martin void **, int *, int *, long *);
170 1.23 macallan static void cgsix_free_screen(void *, void *);
171 1.23 macallan static int cgsix_show_screen(void *, void *, int,
172 1.22 martin void (*) (void *, int, int), void *);
173 1.23 macallan void cgsix_switch_screen(struct cgsix_softc *);
174 1.23 macallan void cgsix_restore_screen(struct cg6_screen *, const struct wsscreen_descr *, u_int16_t *);
175 1.23 macallan void cgsix_clearscreen(struct cgsix_softc *);
176 1.23 macallan void cgsix_setup_mono(struct cgsix_softc *, int, int, int, int, uint32_t,
177 1.23 macallan uint32_t);
178 1.23 macallan void cgsix_feed_line(struct cgsix_softc *, int, uint8_t *);
179 1.23 macallan void cgsix_rectfill(struct cgsix_softc *, int, int, int, int, uint32_t);
180 1.23 macallan
181 1.23 macallan int cgsix_putcmap(struct cgsix_softc *, struct wsdisplay_cmap *);
182 1.23 macallan int cgsix_getcmap(struct cgsix_softc *, struct wsdisplay_cmap *);
183 1.23 macallan void cgsix_putchar(void *, int, int, u_int, long);
184 1.23 macallan void cgsix_cursor(void *, int, int, int);
185 1.23 macallan
186 1.18 martin
187 1.18 martin struct wsdisplay_accessops cgsix_accessops = {
188 1.18 martin cgsix_ioctl,
189 1.18 martin cgsix_mmap,
190 1.18 martin cgsix_alloc_screen,
191 1.18 martin cgsix_free_screen,
192 1.18 martin cgsix_show_screen,
193 1.18 martin NULL, /* load_font */
194 1.18 martin NULL, /* pollc */
195 1.18 martin NULL, /* getwschar */
196 1.18 martin NULL, /* putwschar */
197 1.18 martin NULL /* scroll */
198 1.18 martin };
199 1.18 martin
200 1.18 martin const struct wsscreen_descr *_cgsix_scrlist[] = {
201 1.18 martin &cgsix_defaultscreen
202 1.18 martin };
203 1.18 martin
204 1.18 martin struct wsscreen_list cgsix_screenlist = {
205 1.18 martin sizeof(_cgsix_scrlist) / sizeof(struct wsscreen_descr *),
206 1.18 martin _cgsix_scrlist
207 1.18 martin };
208 1.18 martin
209 1.23 macallan
210 1.23 macallan extern const u_char rasops_cmap[768];
211 1.23 macallan
212 1.23 macallan #endif /* NWSDISPLAY > 0 */
213 1.23 macallan
214 1.23 macallan #if (NWSDISPLAY > 0) || defined(RASTERCONSOLE)
215 1.23 macallan void cg6_invert(struct cgsix_softc *, int, int, int, int);
216 1.23 macallan
217 1.23 macallan /* need this for both cases because ri_hw points to it */
218 1.23 macallan static struct cg6_screen cg6_console_screen;
219 1.23 macallan #endif
220 1.23 macallan
221 1.1 pk #ifdef RASTERCONSOLE
222 1.1 pk int cgsix_use_rasterconsole = 1;
223 1.18 martin #endif
224 1.1 pk
225 1.1 pk /*
226 1.1 pk * cg6 accelerated console routines.
227 1.1 pk *
228 1.1 pk * Note that buried in this code in several places is the assumption
229 1.1 pk * that pixels are exactly one byte wide. Since this is cg6-specific
230 1.1 pk * code, this seems safe. This assumption resides in things like the
231 1.1 pk * use of ri_emuwidth without messing around with ri_pelbytes, or the
232 1.1 pk * assumption that ri_font->fontwidth is the right thing to multiply
233 1.1 pk * character-cell counts by to get byte counts.
234 1.1 pk */
235 1.1 pk
236 1.1 pk /*
237 1.1 pk * Magic values for blitter
238 1.1 pk */
239 1.1 pk
240 1.5 tsutsui /* Values for the mode register */
241 1.5 tsutsui #define CG6_MODE ( \
242 1.5 tsutsui 0x00200000 /* GX_BLIT_SRC */ \
243 1.5 tsutsui | 0x00020000 /* GX_MODE_COLOR8 */ \
244 1.5 tsutsui | 0x00008000 /* GX_DRAW_RENDER */ \
245 1.5 tsutsui | 0x00002000 /* GX_BWRITE0_ENABLE */ \
246 1.5 tsutsui | 0x00001000 /* GX_BWRITE1_DISABLE */ \
247 1.5 tsutsui | 0x00000200 /* GX_BREAD_0 */ \
248 1.5 tsutsui | 0x00000080 /* GX_BDISP_0 */ \
249 1.5 tsutsui )
250 1.5 tsutsui #define CG6_MODE_MASK ( \
251 1.5 tsutsui 0x00300000 /* GX_BLIT_ALL */ \
252 1.5 tsutsui | 0x00060000 /* GX_MODE_ALL */ \
253 1.5 tsutsui | 0x00018000 /* GX_DRAW_ALL */ \
254 1.5 tsutsui | 0x00006000 /* GX_BWRITE0_ALL */ \
255 1.5 tsutsui | 0x00001800 /* GX_BWRITE1_ALL */ \
256 1.5 tsutsui | 0x00000600 /* GX_BREAD_ALL */ \
257 1.5 tsutsui | 0x00000180 /* GX_BDISP_ALL */ \
258 1.5 tsutsui )
259 1.5 tsutsui
260 1.1 pk /* Value for the alu register for screen-to-screen copies */
261 1.1 pk #define CG6_ALU_COPY ( \
262 1.1 pk 0x80000000 /* GX_PLANE_ONES (ignore planemask register) */ \
263 1.1 pk | 0x20000000 /* GX_PIXEL_ONES (ignore pixelmask register) */ \
264 1.1 pk | 0x00800000 /* GX_ATTR_SUPP (function unknown) */ \
265 1.1 pk | 0x00000000 /* GX_RAST_BOOL (function unknown) */ \
266 1.1 pk | 0x00000000 /* GX_PLOT_PLOT (function unknown) */ \
267 1.1 pk | 0x08000000 /* GX_PATTERN_ONES (ignore pattern) */ \
268 1.1 pk | 0x01000000 /* GX_POLYG_OVERLAP (unsure - handle overlap?) */ \
269 1.1 pk | 0x0000cccc /* ALU = src */ \
270 1.1 pk )
271 1.1 pk
272 1.1 pk /* Value for the alu register for region fills */
273 1.1 pk #define CG6_ALU_FILL ( \
274 1.1 pk 0x80000000 /* GX_PLANE_ONES (ignore planemask register) */ \
275 1.1 pk | 0x20000000 /* GX_PIXEL_ONES (ignore pixelmask register) */ \
276 1.1 pk | 0x00800000 /* GX_ATTR_SUPP (function unknown) */ \
277 1.1 pk | 0x00000000 /* GX_RAST_BOOL (function unknown) */ \
278 1.1 pk | 0x00000000 /* GX_PLOT_PLOT (function unknown) */ \
279 1.1 pk | 0x08000000 /* GX_PATTERN_ONES (ignore pattern) */ \
280 1.1 pk | 0x01000000 /* GX_POLYG_OVERLAP (unsure - handle overlap?) */ \
281 1.1 pk | 0x0000ff00 /* ALU = fg color */ \
282 1.1 pk )
283 1.1 pk
284 1.1 pk /* Value for the alu register for toggling an area */
285 1.1 pk #define CG6_ALU_FLIP ( \
286 1.1 pk 0x80000000 /* GX_PLANE_ONES (ignore planemask register) */ \
287 1.1 pk | 0x20000000 /* GX_PIXEL_ONES (ignore pixelmask register) */ \
288 1.1 pk | 0x00800000 /* GX_ATTR_SUPP (function unknown) */ \
289 1.1 pk | 0x00000000 /* GX_RAST_BOOL (function unknown) */ \
290 1.1 pk | 0x00000000 /* GX_PLOT_PLOT (function unknown) */ \
291 1.1 pk | 0x08000000 /* GX_PATTERN_ONES (ignore pattern) */ \
292 1.1 pk | 0x01000000 /* GX_POLYG_OVERLAP (unsure - handle overlap?) */ \
293 1.1 pk | 0x00005555 /* ALU = ~dst */ \
294 1.1 pk )
295 1.1 pk
296 1.1 pk /*
297 1.1 pk * Wait for a blit to finish.
298 1.1 pk * 0x8000000 bit: function unknown; 0x20000000 bit: GX_BLT_INPROGRESS
299 1.1 pk */
300 1.1 pk #define CG6_BLIT_WAIT(fbc) do { \
301 1.1 pk while (((fbc)->fbc_blit & 0xa0000000) == 0xa0000000) \
302 1.1 pk /*EMPTY*/; \
303 1.1 pk } while (0)
304 1.1 pk
305 1.1 pk /*
306 1.1 pk * Wait for a drawing operation to finish, or at least get queued.
307 1.1 pk * 0x8000000 bit: function unknown; 0x20000000 bit: GX_FULL
308 1.1 pk */
309 1.1 pk #define CG6_DRAW_WAIT(fbc) do { \
310 1.1 pk while (((fbc)->fbc_draw & 0xa0000000) == 0xa0000000) \
311 1.1 pk /*EMPTY*/; \
312 1.1 pk } while (0)
313 1.1 pk
314 1.1 pk /*
315 1.1 pk * Wait for the whole engine to go idle. This may not matter in our case;
316 1.1 pk * I'm not sure whether blits are actually queued or not. It more likely
317 1.1 pk * is intended for lines and such that do get queued.
318 1.1 pk * 0x10000000 bit: GX_INPROGRESS
319 1.1 pk */
320 1.1 pk #define CG6_DRAIN(fbc) do { \
321 1.1 pk while ((fbc)->fbc_s & 0x10000000) \
322 1.1 pk /*EMPTY*/; \
323 1.1 pk } while (0)
324 1.1 pk
325 1.23 macallan #if (NWSDISPLAY > 0) || defined(RASTERCONSOLE)
326 1.5 tsutsui static void cg6_ras_init(struct cgsix_softc *);
327 1.5 tsutsui static void cg6_ras_copyrows(void *, int, int, int);
328 1.5 tsutsui static void cg6_ras_copycols(void *, int, int, int, int);
329 1.5 tsutsui static void cg6_ras_erasecols(void *, int, int, int, long int);
330 1.5 tsutsui static void cg6_ras_eraserows(void *, int, int, long int);
331 1.24 macallan #if defined(RASTERCONSOLE) && defined(CG6_BLIT_CURSOR)
332 1.5 tsutsui static void cg6_ras_do_cursor(struct rasops_info *);
333 1.23 macallan #endif
334 1.5 tsutsui static void
335 1.5 tsutsui cg6_ras_init(struct cgsix_softc *sc)
336 1.5 tsutsui {
337 1.5 tsutsui volatile struct cg6_fbc *fbc = sc->sc_fbc;
338 1.5 tsutsui
339 1.5 tsutsui CG6_DRAIN(fbc);
340 1.5 tsutsui fbc->fbc_mode &= ~CG6_MODE_MASK;
341 1.5 tsutsui fbc->fbc_mode |= CG6_MODE;
342 1.5 tsutsui }
343 1.5 tsutsui
344 1.1 pk static void
345 1.1 pk cg6_ras_copyrows(void *cookie, int src, int dst, int n)
346 1.1 pk {
347 1.23 macallan struct rasops_info *ri=cookie;
348 1.23 macallan struct cg6_screen *scr=ri->ri_hw;
349 1.23 macallan struct cgsix_softc *sc=scr->sc;
350 1.23 macallan
351 1.23 macallan #if NWSDISPLAY > 0
352 1.23 macallan int from, to, len;
353 1.23 macallan
354 1.23 macallan from = ri->ri_cols * src;
355 1.23 macallan to = ri->ri_cols * dst;
356 1.23 macallan len = ri->ri_cols * n;
357 1.23 macallan
358 1.23 macallan memmove(&scr->attrs[to], &scr->attrs[from], len * sizeof(long));
359 1.23 macallan memmove(&scr->chars[to], &scr->chars[from], len * sizeof(uint16_t));
360 1.23 macallan
361 1.23 macallan if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
362 1.23 macallan #endif
363 1.23 macallan volatile struct cg6_fbc *fbc = sc->sc_fbc;
364 1.1 pk
365 1.23 macallan if (dst == src)
366 1.23 macallan return;
367 1.23 macallan if (src < 0) {
368 1.23 macallan n += src;
369 1.23 macallan src = 0;
370 1.23 macallan }
371 1.23 macallan if (src+n > ri->ri_rows)
372 1.23 macallan n = ri->ri_rows - src;
373 1.23 macallan if (dst < 0) {
374 1.23 macallan n += dst;
375 1.23 macallan dst = 0;
376 1.23 macallan }
377 1.23 macallan if (dst+n > ri->ri_rows)
378 1.23 macallan n = ri->ri_rows - dst;
379 1.23 macallan if (n <= 0)
380 1.23 macallan return;
381 1.23 macallan n *= ri->ri_font->fontheight;
382 1.23 macallan src *= ri->ri_font->fontheight;
383 1.23 macallan dst *= ri->ri_font->fontheight;
384 1.23 macallan fbc->fbc_clip = 0;
385 1.23 macallan fbc->fbc_s = 0;
386 1.23 macallan fbc->fbc_offx = 0;
387 1.23 macallan fbc->fbc_offy = 0;
388 1.23 macallan fbc->fbc_clipminx = 0;
389 1.23 macallan fbc->fbc_clipminy = 0;
390 1.23 macallan fbc->fbc_clipmaxx = ri->ri_width - 1;
391 1.23 macallan fbc->fbc_clipmaxy = ri->ri_height - 1;
392 1.23 macallan fbc->fbc_alu = CG6_ALU_COPY;
393 1.23 macallan fbc->fbc_x0 = ri->ri_xorigin;
394 1.23 macallan fbc->fbc_y0 = ri->ri_yorigin + src;
395 1.23 macallan fbc->fbc_x1 = ri->ri_xorigin + ri->ri_emuwidth - 1;
396 1.23 macallan fbc->fbc_y1 = ri->ri_yorigin + src + n - 1;
397 1.23 macallan fbc->fbc_x2 = ri->ri_xorigin;
398 1.23 macallan fbc->fbc_y2 = ri->ri_yorigin + dst;
399 1.23 macallan fbc->fbc_x3 = ri->ri_xorigin + ri->ri_emuwidth - 1;
400 1.23 macallan fbc->fbc_y3 = ri->ri_yorigin + dst + n - 1;
401 1.23 macallan CG6_BLIT_WAIT(fbc);
402 1.23 macallan CG6_DRAIN(fbc);
403 1.23 macallan #if NWSDISPLAY > 0
404 1.23 macallan }
405 1.23 macallan #endif
406 1.1 pk }
407 1.1 pk
408 1.1 pk static void
409 1.1 pk cg6_ras_copycols(void *cookie, int row, int src, int dst, int n)
410 1.1 pk {
411 1.23 macallan struct rasops_info *ri=cookie;
412 1.23 macallan struct cg6_screen *scr=ri->ri_hw;
413 1.23 macallan struct cgsix_softc *sc=scr->sc;
414 1.23 macallan
415 1.23 macallan #if NWSDISPLAY > 0
416 1.23 macallan int from, to;
417 1.23 macallan
418 1.23 macallan from = src + row * ri->ri_cols;
419 1.23 macallan to = dst + row * ri->ri_cols;
420 1.23 macallan
421 1.23 macallan memmove(&scr->attrs[to], &scr->attrs[from], n * sizeof(long));
422 1.23 macallan memmove(&scr->chars[to], &scr->chars[from], n * sizeof(uint16_t));
423 1.23 macallan
424 1.23 macallan if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
425 1.23 macallan #endif
426 1.23 macallan volatile struct cg6_fbc *fbc = sc->sc_fbc;
427 1.1 pk
428 1.23 macallan if (dst == src)
429 1.23 macallan return;
430 1.23 macallan if ((row < 0) || (row >= ri->ri_rows))
431 1.23 macallan return;
432 1.23 macallan if (src < 0) {
433 1.23 macallan n += src;
434 1.23 macallan src = 0;
435 1.23 macallan }
436 1.23 macallan if (src+n > ri->ri_cols)
437 1.23 macallan n = ri->ri_cols - src;
438 1.23 macallan if (dst < 0) {
439 1.23 macallan n += dst;
440 1.23 macallan dst = 0;
441 1.23 macallan }
442 1.23 macallan if (dst+n > ri->ri_cols)
443 1.23 macallan n = ri->ri_cols - dst;
444 1.23 macallan if (n <= 0)
445 1.23 macallan return;
446 1.23 macallan n *= ri->ri_font->fontwidth;
447 1.23 macallan src *= ri->ri_font->fontwidth;
448 1.23 macallan dst *= ri->ri_font->fontwidth;
449 1.23 macallan row *= ri->ri_font->fontheight;
450 1.23 macallan fbc->fbc_clip = 0;
451 1.23 macallan fbc->fbc_s = 0;
452 1.23 macallan fbc->fbc_offx = 0;
453 1.23 macallan fbc->fbc_offy = 0;
454 1.23 macallan fbc->fbc_clipminx = 0;
455 1.23 macallan fbc->fbc_clipminy = 0;
456 1.23 macallan fbc->fbc_clipmaxx = ri->ri_width - 1;
457 1.23 macallan fbc->fbc_clipmaxy = ri->ri_height - 1;
458 1.23 macallan fbc->fbc_alu = CG6_ALU_COPY;
459 1.23 macallan fbc->fbc_x0 = ri->ri_xorigin + src;
460 1.23 macallan fbc->fbc_y0 = ri->ri_yorigin + row;
461 1.23 macallan fbc->fbc_x1 = ri->ri_xorigin + src + n - 1;
462 1.23 macallan fbc->fbc_y1 = ri->ri_yorigin + row +
463 1.23 macallan ri->ri_font->fontheight - 1;
464 1.23 macallan fbc->fbc_x2 = ri->ri_xorigin + dst;
465 1.23 macallan fbc->fbc_y2 = ri->ri_yorigin + row;
466 1.23 macallan fbc->fbc_x3 = ri->ri_xorigin + dst + n - 1;
467 1.23 macallan fbc->fbc_y3 = ri->ri_yorigin + row +
468 1.23 macallan ri->ri_font->fontheight - 1;
469 1.23 macallan CG6_BLIT_WAIT(fbc);
470 1.23 macallan CG6_DRAIN(fbc);
471 1.23 macallan #if NWSDISPLAY > 0
472 1.23 macallan }
473 1.23 macallan #endif
474 1.1 pk }
475 1.1 pk
476 1.1 pk static void
477 1.1 pk cg6_ras_erasecols(void *cookie, int row, int col, int n, long int attr)
478 1.1 pk {
479 1.23 macallan struct rasops_info *ri=cookie;
480 1.23 macallan struct cg6_screen *scr=ri->ri_hw;
481 1.23 macallan struct cgsix_softc *sc=scr->sc;
482 1.23 macallan
483 1.23 macallan #if NWSDISPLAY > 0
484 1.23 macallan int start, end, i;
485 1.23 macallan
486 1.23 macallan start = col + row * ri->ri_cols;
487 1.23 macallan end = start + n;
488 1.23 macallan
489 1.23 macallan for (i = start; i < end; i++) {
490 1.23 macallan scr->attrs[i] = attr;
491 1.23 macallan scr->chars[i] = 0x20;
492 1.23 macallan }
493 1.23 macallan if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
494 1.23 macallan #endif
495 1.23 macallan volatile struct cg6_fbc *fbc = sc->sc_fbc;
496 1.1 pk
497 1.23 macallan if ((row < 0) || (row >= ri->ri_rows))
498 1.23 macallan return;
499 1.23 macallan if (col < 0) {
500 1.23 macallan n += col;
501 1.23 macallan col = 0;
502 1.23 macallan }
503 1.23 macallan if (col+n > ri->ri_cols)
504 1.23 macallan n = ri->ri_cols - col;
505 1.23 macallan if (n <= 0)
506 1.23 macallan return;
507 1.23 macallan n *= ri->ri_font->fontwidth;
508 1.23 macallan col *= ri->ri_font->fontwidth;
509 1.23 macallan row *= ri->ri_font->fontheight;
510 1.23 macallan fbc->fbc_clip = 0;
511 1.23 macallan fbc->fbc_s = 0;
512 1.23 macallan fbc->fbc_offx = 0;
513 1.23 macallan fbc->fbc_offy = 0;
514 1.23 macallan fbc->fbc_clipminx = 0;
515 1.23 macallan fbc->fbc_clipminy = 0;
516 1.23 macallan fbc->fbc_clipmaxx = ri->ri_width - 1;
517 1.23 macallan fbc->fbc_clipmaxy = ri->ri_height - 1;
518 1.23 macallan fbc->fbc_alu = CG6_ALU_FILL;
519 1.23 macallan fbc->fbc_fg = ri->ri_devcmap[(attr >> 16) & 0xff];
520 1.23 macallan fbc->fbc_arecty = ri->ri_yorigin + row;
521 1.23 macallan fbc->fbc_arectx = ri->ri_xorigin + col;
522 1.23 macallan fbc->fbc_arecty = ri->ri_yorigin + row +
523 1.23 macallan ri->ri_font->fontheight - 1;
524 1.23 macallan fbc->fbc_arectx = ri->ri_xorigin + col + n - 1;
525 1.23 macallan CG6_DRAW_WAIT(fbc);
526 1.23 macallan CG6_DRAIN(fbc);
527 1.23 macallan #if NWSDISPLAY > 0
528 1.23 macallan }
529 1.23 macallan #endif
530 1.1 pk }
531 1.1 pk
532 1.1 pk static void
533 1.1 pk cg6_ras_eraserows(void *cookie, int row, int n, long int attr)
534 1.1 pk {
535 1.23 macallan struct rasops_info *ri=cookie;
536 1.23 macallan struct cg6_screen *scr=ri->ri_hw;
537 1.23 macallan struct cgsix_softc *sc=scr->sc;
538 1.23 macallan
539 1.23 macallan #if NWSDISPLAY > 0
540 1.23 macallan int start, end, i;
541 1.23 macallan
542 1.23 macallan start = ri->ri_cols*row;
543 1.23 macallan end = ri->ri_cols * (row + n);
544 1.23 macallan
545 1.23 macallan for (i = start; i < end; i++) {
546 1.23 macallan scr->attrs[i] = attr;
547 1.23 macallan scr->chars[i] = 0x20;
548 1.23 macallan }
549 1.23 macallan
550 1.23 macallan if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
551 1.23 macallan #endif
552 1.23 macallan volatile struct cg6_fbc *fbc = sc->sc_fbc;
553 1.1 pk
554 1.23 macallan if (row < 0) {
555 1.23 macallan n += row;
556 1.23 macallan row = 0;
557 1.23 macallan }
558 1.23 macallan if (row+n > ri->ri_rows)
559 1.23 macallan n = ri->ri_rows - row;
560 1.23 macallan if (n <= 0)
561 1.23 macallan return;
562 1.23 macallan fbc->fbc_clip = 0;
563 1.23 macallan fbc->fbc_s = 0;
564 1.23 macallan fbc->fbc_offx = 0;
565 1.23 macallan fbc->fbc_offy = 0;
566 1.23 macallan fbc->fbc_clipminx = 0;
567 1.23 macallan fbc->fbc_clipminy = 0;
568 1.23 macallan fbc->fbc_clipmaxx = ri->ri_width - 1;
569 1.23 macallan fbc->fbc_clipmaxy = ri->ri_height - 1;
570 1.23 macallan fbc->fbc_alu = CG6_ALU_FILL;
571 1.23 macallan fbc->fbc_fg = ri->ri_devcmap[(attr >> 16) & 0xff];
572 1.23 macallan if ((n == ri->ri_rows) && (ri->ri_flg & RI_FULLCLEAR)) {
573 1.23 macallan fbc->fbc_arecty = 0;
574 1.23 macallan fbc->fbc_arectx = 0;
575 1.23 macallan fbc->fbc_arecty = ri->ri_height - 1;
576 1.23 macallan fbc->fbc_arectx = ri->ri_width - 1;
577 1.23 macallan } else {
578 1.23 macallan row *= ri->ri_font->fontheight;
579 1.23 macallan fbc->fbc_arecty = ri->ri_yorigin + row;
580 1.23 macallan fbc->fbc_arectx = ri->ri_xorigin;
581 1.23 macallan fbc->fbc_arecty = ri->ri_yorigin + row +
582 1.23 macallan (n * ri->ri_font->fontheight) - 1;
583 1.23 macallan fbc->fbc_arectx = ri->ri_xorigin + ri->ri_emuwidth - 1;
584 1.23 macallan }
585 1.23 macallan CG6_DRAW_WAIT(fbc);
586 1.23 macallan CG6_DRAIN(fbc);
587 1.23 macallan #if NWSDISPLAY > 0
588 1.1 pk }
589 1.23 macallan #endif
590 1.1 pk }
591 1.1 pk
592 1.24 macallan #if defined(RASTERCONSOLE) && defined(CG6_BLIT_CURSOR)
593 1.1 pk /*
594 1.1 pk * Really want something more like fg^bg here, but that would be more
595 1.1 pk * or less impossible to migrate to colors. So we hope there's
596 1.1 pk * something not too inappropriate in the colormap...besides, it's what
597 1.1 pk * the non-accelerated code did. :-)
598 1.1 pk */
599 1.1 pk static void
600 1.1 pk cg6_ras_do_cursor(struct rasops_info *ri)
601 1.1 pk {
602 1.24 macallan struct cg6_screen *scr = ri->ri_hw;
603 1.24 macallan struct cgsix_softc *sc = scr->sc;
604 1.23 macallan int row, col;
605 1.23 macallan
606 1.1 pk row = ri->ri_crow * ri->ri_font->fontheight;
607 1.1 pk col = ri->ri_ccol * ri->ri_font->fontwidth;
608 1.24 macallan cg6_invert(sc, ri->ri_xorigin + col,ri->ri_yorigin +
609 1.24 macallan row, ri->ri_font->fontwidth, ri->ri_font->fontheight);
610 1.1 pk }
611 1.23 macallan #endif /* RASTERCONSOLE */
612 1.23 macallan
613 1.23 macallan #endif /* (NWSDISPLAY > 0) || defined(RASTERCONSOLE) */
614 1.1 pk
615 1.1 pk void
616 1.25 tsutsui cg6attach(struct cgsix_softc *sc, const char *name, int isconsole)
617 1.1 pk {
618 1.1 pk struct fbdevice *fb = &sc->sc_fb;
619 1.23 macallan #if NWSDISPLAY > 0
620 1.18 martin struct wsemuldisplaydev_attach_args aa;
621 1.23 macallan struct rasops_info *ri = &cg6_console_screen.ri;
622 1.18 martin unsigned long defattr;
623 1.20 martin #endif
624 1.1 pk
625 1.1 pk fb->fb_driver = &cg6_fbdriver;
626 1.1 pk
627 1.1 pk /* Don't have to map the pfour register on the cgsix. */
628 1.1 pk fb->fb_pfour = NULL;
629 1.1 pk
630 1.1 pk fb->fb_type.fb_cmsize = 256;
631 1.23 macallan fb->fb_type.fb_size = sc->sc_ramsize;
632 1.23 macallan /*fb->fb_type.fb_height * fb->fb_linebytes;*/
633 1.1 pk printf(": %s, %d x %d", name,
634 1.1 pk fb->fb_type.fb_width, fb->fb_type.fb_height);
635 1.18 martin if(sc->sc_fhc) {
636 1.23 macallan sc->sc_fhcrev = (*sc->sc_fhc >> FHC_REV_SHIFT) &
637 1.1 pk (FHC_REV_MASK >> FHC_REV_SHIFT);
638 1.18 martin } else
639 1.18 martin sc->sc_fhcrev=-1;
640 1.1 pk printf(", rev %d", sc->sc_fhcrev);
641 1.1 pk
642 1.1 pk /* reset cursor & frame buffer controls */
643 1.1 pk cg6_reset(sc);
644 1.1 pk
645 1.1 pk /* enable video */
646 1.1 pk sc->sc_thc->thc_misc |= THC_MISC_VIDEN;
647 1.1 pk
648 1.1 pk if (isconsole) {
649 1.1 pk printf(" (console)");
650 1.19 perry
651 1.23 macallan /* this is the old console attachment stuff - sparc still needs it */
652 1.1 pk #ifdef RASTERCONSOLE
653 1.1 pk if (cgsix_use_rasterconsole) {
654 1.1 pk fbrcons_init(&sc->sc_fb);
655 1.23 macallan /*
656 1.23 macallan * we don't use the screen struct but keep it here to
657 1.23 macallan * avoid ugliness in the cg6_ras_* functions
658 1.23 macallan */
659 1.23 macallan cg6_console_screen.sc = sc;
660 1.23 macallan sc->sc_fb.fb_rinfo.ri_hw = &cg6_console_screen;
661 1.1 pk sc->sc_fb.fb_rinfo.ri_ops.copyrows = cg6_ras_copyrows;
662 1.1 pk sc->sc_fb.fb_rinfo.ri_ops.copycols = cg6_ras_copycols;
663 1.1 pk sc->sc_fb.fb_rinfo.ri_ops.erasecols = cg6_ras_erasecols;
664 1.1 pk sc->sc_fb.fb_rinfo.ri_ops.eraserows = cg6_ras_eraserows;
665 1.24 macallan #ifdef CG6_BLIT_CURSOR
666 1.1 pk sc->sc_fb.fb_rinfo.ri_do_cursor = cg6_ras_do_cursor;
667 1.24 macallan #endif
668 1.5 tsutsui cg6_ras_init(sc);
669 1.1 pk }
670 1.1 pk #endif
671 1.1 pk }
672 1.26 thorpej printf("\n");
673 1.1 pk
674 1.18 martin fb_attach(&sc->sc_fb, isconsole);
675 1.23 macallan sc->sc_width = fb->fb_type.fb_width;
676 1.23 macallan sc->sc_stride = fb->fb_type.fb_width;
677 1.23 macallan sc->sc_height = fb->fb_type.fb_height;
678 1.19 perry
679 1.24 macallan printf("%s: framebuffer size: %d MB\n", sc->sc_dev.dv_xname,
680 1.24 macallan sc->sc_ramsize >> 20);
681 1.24 macallan
682 1.20 martin #if NWSDISPLAY
683 1.20 martin /* setup rasops and so on for wsdisplay */
684 1.18 martin wsfont_init();
685 1.18 martin cg6_ras_init(sc);
686 1.23 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
687 1.23 macallan sc->sc_bg = WS_DEFAULT_BG;
688 1.23 macallan
689 1.23 macallan LIST_INIT(&sc->screens);
690 1.23 macallan sc->active = NULL;
691 1.23 macallan sc->currenttype = &cgsix_defaultscreen;
692 1.27 macallan callout_init(&sc->switch_callout);
693 1.23 macallan
694 1.27 macallan if(isconsole) {
695 1.27 macallan /* we mess with cg6_console_screen only once */
696 1.27 macallan cgsix_init_screen(sc, &cg6_console_screen, 1, &defattr);
697 1.27 macallan cgsix_defaultscreen.textops = &ri->ri_ops;
698 1.27 macallan cgsix_defaultscreen.capabilities = ri->ri_caps;
699 1.27 macallan cgsix_defaultscreen.nrows = ri->ri_rows;
700 1.27 macallan cgsix_defaultscreen.ncols = ri->ri_cols;
701 1.27 macallan cg6_console_screen.active = 1;
702 1.27 macallan sc->active = &cg6_console_screen;
703 1.27 macallan wsdisplay_cnattach(&cgsix_defaultscreen, ri, 0, 0, defattr);
704 1.27 macallan } else {
705 1.27 macallan /*
706 1.27 macallan * we're not the console so we just clear the screen and don't
707 1.27 macallan * set up any sort of text display
708 1.27 macallan */
709 1.27 macallan if (cgsix_defaultscreen.textops == NULL) {
710 1.27 macallan /*
711 1.27 macallan * ugly, but...
712 1.27 macallan * we want the console settings to win, so we only
713 1.27 macallan * touch anything when we find an untouched screen
714 1.27 macallan * definition. In this case we fill it from fb to
715 1.27 macallan * avoid problems in case no cgsix is the console
716 1.27 macallan */
717 1.27 macallan ri = &sc->sc_fb.fb_rinfo;
718 1.27 macallan cgsix_defaultscreen.textops = &ri->ri_ops;
719 1.27 macallan cgsix_defaultscreen.capabilities = ri->ri_caps;
720 1.27 macallan cgsix_defaultscreen.nrows = ri->ri_rows;
721 1.27 macallan cgsix_defaultscreen.ncols = ri->ri_cols;
722 1.27 macallan }
723 1.27 macallan sc->active = NULL;
724 1.27 macallan cgsix_clearscreen(sc);
725 1.27 macallan }
726 1.23 macallan
727 1.23 macallan cg6_setup_palette(sc);
728 1.27 macallan
729 1.27 macallan aa.scrdata = &cgsix_screenlist;
730 1.18 martin aa.console = isconsole;
731 1.18 martin aa.accessops = &cgsix_accessops;
732 1.18 martin aa.accesscookie = sc;
733 1.18 martin config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
734 1.23 macallan #else
735 1.23 macallan bt_initcmap(&sc->sc_cmap, 256);
736 1.23 macallan cg6_loadcmap(sc, 0, 256);
737 1.23 macallan
738 1.20 martin #endif
739 1.18 martin
740 1.1 pk }
741 1.1 pk
742 1.1 pk
743 1.1 pk int
744 1.22 martin cgsixopen(dev_t dev, int flags, int mode, struct proc *p)
745 1.1 pk {
746 1.1 pk int unit = minor(dev);
747 1.1 pk
748 1.1 pk if (unit >= cgsix_cd.cd_ndevs || cgsix_cd.cd_devs[unit] == NULL)
749 1.22 martin return ENXIO;
750 1.22 martin return 0;
751 1.1 pk }
752 1.1 pk
753 1.1 pk int
754 1.22 martin cgsixclose(dev_t dev, int flags, int mode, struct proc *p)
755 1.1 pk {
756 1.1 pk struct cgsix_softc *sc = cgsix_cd.cd_devs[minor(dev)];
757 1.1 pk
758 1.1 pk cg6_reset(sc);
759 1.1 pk
760 1.23 macallan #if NWSDISPLAY > 0
761 1.23 macallan cg6_setup_palette(sc);
762 1.23 macallan #else
763 1.1 pk /* (re-)initialize the default color map */
764 1.1 pk bt_initcmap(&sc->sc_cmap, 256);
765 1.23 macallan
766 1.1 pk cg6_loadcmap(sc, 0, 256);
767 1.23 macallan #endif
768 1.1 pk
769 1.22 martin return 0;
770 1.1 pk }
771 1.1 pk
772 1.1 pk int
773 1.22 martin cgsixioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
774 1.1 pk {
775 1.1 pk struct cgsix_softc *sc = cgsix_cd.cd_devs[minor(dev)];
776 1.16 chs union cursor_cmap tcm;
777 1.16 chs uint32_t image[32], mask[32];
778 1.1 pk u_int count;
779 1.1 pk int v, error;
780 1.1 pk
781 1.18 martin #ifdef CGSIX_DEBUG
782 1.18 martin printf("cgsixioctl(%ld)\n",cmd);
783 1.18 martin #endif
784 1.18 martin
785 1.1 pk switch (cmd) {
786 1.1 pk
787 1.1 pk case FBIOGTYPE:
788 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
789 1.1 pk break;
790 1.1 pk
791 1.1 pk case FBIOGATTR:
792 1.1 pk #define fba ((struct fbgattr *)data)
793 1.1 pk fba->real_type = sc->sc_fb.fb_type.fb_type;
794 1.1 pk fba->owner = 0; /* XXX ??? */
795 1.1 pk fba->fbtype = sc->sc_fb.fb_type;
796 1.1 pk fba->sattr.flags = 0;
797 1.1 pk fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
798 1.1 pk fba->sattr.dev_specific[0] = -1;
799 1.1 pk fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
800 1.1 pk fba->emu_types[1] = -1;
801 1.1 pk #undef fba
802 1.1 pk break;
803 1.1 pk
804 1.1 pk case FBIOGETCMAP:
805 1.1 pk #define p ((struct fbcmap *)data)
806 1.1 pk return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
807 1.1 pk
808 1.1 pk case FBIOPUTCMAP:
809 1.1 pk /* copy to software map */
810 1.1 pk error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
811 1.1 pk if (error)
812 1.22 martin return error;
813 1.1 pk /* now blast them into the chip */
814 1.1 pk /* XXX should use retrace interrupt */
815 1.1 pk cg6_loadcmap(sc, p->index, p->count);
816 1.1 pk #undef p
817 1.1 pk break;
818 1.1 pk
819 1.1 pk case FBIOGVIDEO:
820 1.1 pk *(int *)data = sc->sc_blanked;
821 1.1 pk break;
822 1.1 pk
823 1.1 pk case FBIOSVIDEO:
824 1.1 pk if (*(int *)data)
825 1.1 pk cg6_unblank(&sc->sc_dev);
826 1.1 pk else if (!sc->sc_blanked) {
827 1.1 pk sc->sc_blanked = 1;
828 1.1 pk sc->sc_thc->thc_misc &= ~THC_MISC_VIDEN;
829 1.1 pk }
830 1.1 pk break;
831 1.1 pk
832 1.1 pk /* these are for both FBIOSCURSOR and FBIOGCURSOR */
833 1.1 pk #define p ((struct fbcursor *)data)
834 1.1 pk #define cc (&sc->sc_cursor)
835 1.1 pk
836 1.1 pk case FBIOGCURSOR:
837 1.1 pk /* do not quite want everything here... */
838 1.1 pk p->set = FB_CUR_SETALL; /* close enough, anyway */
839 1.1 pk p->enable = cc->cc_enable;
840 1.1 pk p->pos = cc->cc_pos;
841 1.1 pk p->hot = cc->cc_hot;
842 1.1 pk p->size = cc->cc_size;
843 1.1 pk
844 1.1 pk /* begin ugh ... can we lose some of this crap?? */
845 1.1 pk if (p->image != NULL) {
846 1.1 pk count = cc->cc_size.y * 32 / NBBY;
847 1.16 chs error = copyout(cc->cc_bits[1], p->image, count);
848 1.1 pk if (error)
849 1.22 martin return error;
850 1.16 chs error = copyout(cc->cc_bits[0], p->mask, count);
851 1.1 pk if (error)
852 1.22 martin return error;
853 1.1 pk }
854 1.1 pk if (p->cmap.red != NULL) {
855 1.1 pk error = bt_getcmap(&p->cmap,
856 1.1 pk (union bt_cmap *)&cc->cc_color, 2, 1);
857 1.1 pk if (error)
858 1.22 martin return error;
859 1.1 pk } else {
860 1.1 pk p->cmap.index = 0;
861 1.1 pk p->cmap.count = 2;
862 1.1 pk }
863 1.1 pk /* end ugh */
864 1.1 pk break;
865 1.1 pk
866 1.1 pk case FBIOSCURSOR:
867 1.1 pk /*
868 1.1 pk * For setcmap and setshape, verify parameters, so that
869 1.1 pk * we do not get halfway through an update and then crap
870 1.1 pk * out with the software state screwed up.
871 1.1 pk */
872 1.1 pk v = p->set;
873 1.1 pk if (v & FB_CUR_SETCMAP) {
874 1.1 pk /*
875 1.1 pk * This use of a temporary copy of the cursor
876 1.1 pk * colormap is not terribly efficient, but these
877 1.1 pk * copies are small (8 bytes)...
878 1.1 pk */
879 1.1 pk tcm = cc->cc_color;
880 1.23 macallan error = bt_putcmap(&p->cmap, (union bt_cmap *)&tcm, 2,
881 1.23 macallan 1);
882 1.1 pk if (error)
883 1.22 martin return error;
884 1.1 pk }
885 1.1 pk if (v & FB_CUR_SETSHAPE) {
886 1.1 pk if ((u_int)p->size.x > 32 || (u_int)p->size.y > 32)
887 1.22 martin return EINVAL;
888 1.1 pk count = p->size.y * 32 / NBBY;
889 1.16 chs error = copyin(p->image, image, count);
890 1.16 chs if (error)
891 1.16 chs return error;
892 1.16 chs error = copyin(p->mask, mask, count);
893 1.16 chs if (error)
894 1.16 chs return error;
895 1.1 pk }
896 1.1 pk
897 1.1 pk /* parameters are OK; do it */
898 1.1 pk if (v & (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT)) {
899 1.1 pk if (v & FB_CUR_SETCUR)
900 1.1 pk cc->cc_enable = p->enable;
901 1.1 pk if (v & FB_CUR_SETPOS)
902 1.1 pk cc->cc_pos = p->pos;
903 1.1 pk if (v & FB_CUR_SETHOT)
904 1.1 pk cc->cc_hot = p->hot;
905 1.1 pk cg6_setcursor(sc);
906 1.1 pk }
907 1.1 pk if (v & FB_CUR_SETCMAP) {
908 1.1 pk cc->cc_color = tcm;
909 1.1 pk cg6_loadomap(sc); /* XXX defer to vertical retrace */
910 1.1 pk }
911 1.1 pk if (v & FB_CUR_SETSHAPE) {
912 1.1 pk cc->cc_size = p->size;
913 1.1 pk count = p->size.y * 32 / NBBY;
914 1.16 chs memset(cc->cc_bits, 0, sizeof cc->cc_bits);
915 1.16 chs memcpy(cc->cc_bits[1], image, count);
916 1.16 chs memcpy(cc->cc_bits[0], mask, count);
917 1.1 pk cg6_loadcursor(sc);
918 1.1 pk }
919 1.1 pk break;
920 1.1 pk
921 1.1 pk #undef p
922 1.1 pk #undef cc
923 1.1 pk
924 1.1 pk case FBIOGCURPOS:
925 1.1 pk *(struct fbcurpos *)data = sc->sc_cursor.cc_pos;
926 1.1 pk break;
927 1.1 pk
928 1.1 pk case FBIOSCURPOS:
929 1.1 pk sc->sc_cursor.cc_pos = *(struct fbcurpos *)data;
930 1.1 pk cg6_setcursor(sc);
931 1.1 pk break;
932 1.1 pk
933 1.1 pk case FBIOGCURMAX:
934 1.1 pk /* max cursor size is 32x32 */
935 1.1 pk ((struct fbcurpos *)data)->x = 32;
936 1.1 pk ((struct fbcurpos *)data)->y = 32;
937 1.1 pk break;
938 1.1 pk
939 1.1 pk default:
940 1.1 pk #ifdef DEBUG
941 1.1 pk log(LOG_NOTICE, "cgsixioctl(0x%lx) (%s[%d])\n", cmd,
942 1.1 pk p->p_comm, p->p_pid);
943 1.1 pk #endif
944 1.22 martin return ENOTTY;
945 1.1 pk }
946 1.22 martin return 0;
947 1.1 pk }
948 1.1 pk
949 1.1 pk /*
950 1.1 pk * Clean up hardware state (e.g., after bootup or after X crashes).
951 1.1 pk */
952 1.1 pk static void
953 1.22 martin cg6_reset(struct cgsix_softc *sc)
954 1.1 pk {
955 1.1 pk volatile struct cg6_tec_xxx *tec;
956 1.1 pk int fhc;
957 1.1 pk volatile struct bt_regs *bt;
958 1.1 pk
959 1.1 pk /* hide the cursor, just in case */
960 1.1 pk sc->sc_thc->thc_cursxy = (THC_CURSOFF << 16) | THC_CURSOFF;
961 1.1 pk
962 1.1 pk /* turn off frobs in transform engine (makes X11 work) */
963 1.1 pk tec = sc->sc_tec;
964 1.1 pk tec->tec_mv = 0;
965 1.1 pk tec->tec_clip = 0;
966 1.1 pk tec->tec_vdc = 0;
967 1.1 pk
968 1.1 pk /* take care of hardware bugs in old revisions */
969 1.1 pk if (sc->sc_fhcrev < 5) {
970 1.1 pk /*
971 1.17 wiz * Keep current resolution; set CPU to 68020, set test
972 1.1 pk * window (size 1Kx1K), and for rev 1, disable dest cache.
973 1.1 pk */
974 1.1 pk fhc = (*sc->sc_fhc & FHC_RES_MASK) | FHC_CPU_68020 |
975 1.1 pk FHC_TEST |
976 1.1 pk (11 << FHC_TESTX_SHIFT) | (11 << FHC_TESTY_SHIFT);
977 1.1 pk if (sc->sc_fhcrev < 2)
978 1.1 pk fhc |= FHC_DST_DISABLE;
979 1.1 pk *sc->sc_fhc = fhc;
980 1.1 pk }
981 1.1 pk
982 1.1 pk /* Enable cursor in Brooktree DAC. */
983 1.1 pk bt = sc->sc_bt;
984 1.1 pk bt->bt_addr = 0x06 << 24;
985 1.1 pk bt->bt_ctrl |= 0x03 << 24;
986 1.1 pk }
987 1.1 pk
988 1.1 pk static void
989 1.22 martin cg6_setcursor(struct cgsix_softc *sc)
990 1.1 pk {
991 1.1 pk
992 1.1 pk /* we need to subtract the hot-spot value here */
993 1.1 pk #define COORD(f) (sc->sc_cursor.cc_pos.f - sc->sc_cursor.cc_hot.f)
994 1.1 pk sc->sc_thc->thc_cursxy = sc->sc_cursor.cc_enable ?
995 1.1 pk ((COORD(x) << 16) | (COORD(y) & 0xffff)) :
996 1.1 pk (THC_CURSOFF << 16) | THC_CURSOFF;
997 1.1 pk #undef COORD
998 1.1 pk }
999 1.1 pk
1000 1.1 pk static void
1001 1.22 martin cg6_loadcursor(struct cgsix_softc *sc)
1002 1.1 pk {
1003 1.1 pk volatile struct cg6_thc *thc;
1004 1.1 pk u_int edgemask, m;
1005 1.1 pk int i;
1006 1.1 pk
1007 1.1 pk /*
1008 1.1 pk * Keep the top size.x bits. Here we *throw out* the top
1009 1.1 pk * size.x bits from an all-one-bits word, introducing zeros in
1010 1.1 pk * the top size.x bits, then invert all the bits to get what
1011 1.1 pk * we really wanted as our mask. But this fails if size.x is
1012 1.1 pk * 32---a sparc uses only the low 5 bits of the shift count---
1013 1.1 pk * so we have to special case that.
1014 1.1 pk */
1015 1.1 pk edgemask = ~0;
1016 1.1 pk if (sc->sc_cursor.cc_size.x < 32)
1017 1.1 pk edgemask = ~(edgemask >> sc->sc_cursor.cc_size.x);
1018 1.1 pk thc = sc->sc_thc;
1019 1.1 pk for (i = 0; i < 32; i++) {
1020 1.1 pk m = sc->sc_cursor.cc_bits[0][i] & edgemask;
1021 1.1 pk thc->thc_cursmask[i] = m;
1022 1.1 pk thc->thc_cursbits[i] = m & sc->sc_cursor.cc_bits[1][i];
1023 1.1 pk }
1024 1.1 pk }
1025 1.1 pk
1026 1.1 pk /*
1027 1.1 pk * Load a subset of the current (new) colormap into the color DAC.
1028 1.1 pk */
1029 1.1 pk static void
1030 1.22 martin cg6_loadcmap(struct cgsix_softc *sc, int start, int ncolors)
1031 1.1 pk {
1032 1.1 pk volatile struct bt_regs *bt;
1033 1.1 pk u_int *ip, i;
1034 1.1 pk int count;
1035 1.1 pk
1036 1.1 pk ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)]; /* start/4 * 3 */
1037 1.1 pk count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
1038 1.1 pk bt = sc->sc_bt;
1039 1.1 pk bt->bt_addr = BT_D4M4(start) << 24;
1040 1.1 pk while (--count >= 0) {
1041 1.1 pk i = *ip++;
1042 1.1 pk /* hardware that makes one want to pound boards with hammers */
1043 1.1 pk bt->bt_cmap = i;
1044 1.1 pk bt->bt_cmap = i << 8;
1045 1.1 pk bt->bt_cmap = i << 16;
1046 1.1 pk bt->bt_cmap = i << 24;
1047 1.1 pk }
1048 1.1 pk }
1049 1.1 pk
1050 1.1 pk /*
1051 1.1 pk * Load the cursor (overlay `foreground' and `background') colors.
1052 1.1 pk */
1053 1.1 pk static void
1054 1.22 martin cg6_loadomap(struct cgsix_softc *sc)
1055 1.1 pk {
1056 1.1 pk volatile struct bt_regs *bt;
1057 1.1 pk u_int i;
1058 1.1 pk
1059 1.1 pk bt = sc->sc_bt;
1060 1.1 pk bt->bt_addr = 0x01 << 24; /* set background color */
1061 1.1 pk i = sc->sc_cursor.cc_color.cm_chip[0];
1062 1.1 pk bt->bt_omap = i; /* R */
1063 1.1 pk bt->bt_omap = i << 8; /* G */
1064 1.1 pk bt->bt_omap = i << 16; /* B */
1065 1.1 pk
1066 1.1 pk bt->bt_addr = 0x03 << 24; /* set foreground color */
1067 1.1 pk bt->bt_omap = i << 24; /* R */
1068 1.1 pk i = sc->sc_cursor.cc_color.cm_chip[1];
1069 1.1 pk bt->bt_omap = i; /* G */
1070 1.1 pk bt->bt_omap = i << 8; /* B */
1071 1.1 pk }
1072 1.1 pk
1073 1.1 pk static void
1074 1.22 martin cg6_unblank(struct device *dev)
1075 1.1 pk {
1076 1.1 pk struct cgsix_softc *sc = (struct cgsix_softc *)dev;
1077 1.1 pk
1078 1.1 pk if (sc->sc_blanked) {
1079 1.1 pk sc->sc_blanked = 0;
1080 1.1 pk sc->sc_thc->thc_misc |= THC_MISC_VIDEN;
1081 1.1 pk }
1082 1.1 pk }
1083 1.1 pk
1084 1.1 pk /* XXX the following should be moved to a "user interface" header */
1085 1.1 pk /*
1086 1.1 pk * Base addresses at which users can mmap() the various pieces of a cg6.
1087 1.1 pk * Note that although the Brooktree color registers do not occupy 8K,
1088 1.1 pk * the X server dies if we do not allow it to map 8K there (it just maps
1089 1.1 pk * from 0x70000000 forwards, as a contiguous chunk).
1090 1.1 pk */
1091 1.1 pk #define CG6_USER_FBC 0x70000000
1092 1.1 pk #define CG6_USER_TEC 0x70001000
1093 1.1 pk #define CG6_USER_BTREGS 0x70002000
1094 1.1 pk #define CG6_USER_FHC 0x70004000
1095 1.1 pk #define CG6_USER_THC 0x70005000
1096 1.1 pk #define CG6_USER_ROM 0x70006000
1097 1.1 pk #define CG6_USER_RAM 0x70016000
1098 1.1 pk #define CG6_USER_DHC 0x80000000
1099 1.1 pk
1100 1.1 pk struct mmo {
1101 1.2 eeh u_long mo_uaddr; /* user (virtual) address */
1102 1.2 eeh u_long mo_size; /* size, or 0 for video ram size */
1103 1.2 eeh u_long mo_physoff; /* offset from sc_physadr */
1104 1.1 pk };
1105 1.1 pk
1106 1.1 pk /*
1107 1.1 pk * Return the address that would map the given device at the given
1108 1.1 pk * offset, allowing for the given protection, or return -1 for error.
1109 1.1 pk *
1110 1.1 pk * XXX needs testing against `demanding' applications (e.g., aviator)
1111 1.1 pk */
1112 1.1 pk paddr_t
1113 1.22 martin cgsixmmap(dev_t dev, off_t off, int prot)
1114 1.1 pk {
1115 1.1 pk struct cgsix_softc *sc = cgsix_cd.cd_devs[minor(dev)];
1116 1.1 pk struct mmo *mo;
1117 1.1 pk u_int u, sz;
1118 1.1 pk static struct mmo mmo[] = {
1119 1.1 pk { CG6_USER_RAM, 0, CGSIX_RAM_OFFSET },
1120 1.1 pk
1121 1.1 pk /* do not actually know how big most of these are! */
1122 1.1 pk { CG6_USER_FBC, 1, CGSIX_FBC_OFFSET },
1123 1.1 pk { CG6_USER_TEC, 1, CGSIX_TEC_OFFSET },
1124 1.1 pk { CG6_USER_BTREGS, 8192 /* XXX */, CGSIX_BT_OFFSET },
1125 1.1 pk { CG6_USER_FHC, 1, CGSIX_FHC_OFFSET },
1126 1.1 pk { CG6_USER_THC, sizeof(struct cg6_thc), CGSIX_THC_OFFSET },
1127 1.1 pk { CG6_USER_ROM, 65536, CGSIX_ROM_OFFSET },
1128 1.1 pk { CG6_USER_DHC, 1, CGSIX_DHC_OFFSET },
1129 1.1 pk };
1130 1.1 pk #define NMMO (sizeof mmo / sizeof *mmo)
1131 1.1 pk
1132 1.1 pk if (off & PGOFSET)
1133 1.1 pk panic("cgsixmmap");
1134 1.1 pk
1135 1.1 pk /*
1136 1.1 pk * Entries with size 0 map video RAM (i.e., the size in fb data).
1137 1.1 pk *
1138 1.1 pk * Since we work in pages, the fact that the map offset table's
1139 1.1 pk * sizes are sometimes bizarre (e.g., 1) is effectively ignored:
1140 1.1 pk * one byte is as good as one page.
1141 1.1 pk */
1142 1.1 pk for (mo = mmo; mo < &mmo[NMMO]; mo++) {
1143 1.2 eeh if ((u_long)off < mo->mo_uaddr)
1144 1.1 pk continue;
1145 1.1 pk u = off - mo->mo_uaddr;
1146 1.23 macallan sz = mo->mo_size ? mo->mo_size :
1147 1.23 macallan sc->sc_ramsize/*sc_fb.fb_type.fb_size*/;
1148 1.1 pk if (u < sz) {
1149 1.6 eeh return (bus_space_mmap(sc->sc_bustag,
1150 1.6 eeh sc->sc_paddr, u+mo->mo_physoff,
1151 1.6 eeh prot, BUS_SPACE_MAP_LINEAR));
1152 1.1 pk }
1153 1.1 pk }
1154 1.1 pk
1155 1.1 pk #ifdef DEBUG
1156 1.1 pk {
1157 1.10 thorpej struct proc *p = curlwp->l_proc; /* XXX */
1158 1.4 chs log(LOG_NOTICE, "cgsixmmap(0x%llx) (%s[%d])\n",
1159 1.4 chs (long long)off, p->p_comm, p->p_pid);
1160 1.1 pk }
1161 1.1 pk #endif
1162 1.22 martin return -1; /* not a user-map offset */
1163 1.1 pk }
1164 1.18 martin
1165 1.23 macallan #if NWSDISPLAY > 0
1166 1.18 martin
1167 1.23 macallan static void
1168 1.23 macallan cg6_setup_palette(struct cgsix_softc *sc)
1169 1.18 martin {
1170 1.23 macallan int i, j;
1171 1.23 macallan
1172 1.23 macallan j = 0;
1173 1.23 macallan for (i = 0; i < 256; i++) {
1174 1.23 macallan sc->sc_cmap.cm_map[i][0] = rasops_cmap[j];
1175 1.23 macallan j++;
1176 1.23 macallan sc->sc_cmap.cm_map[i][1] = rasops_cmap[j];
1177 1.23 macallan j++;
1178 1.23 macallan sc->sc_cmap.cm_map[i][2] = rasops_cmap[j];
1179 1.23 macallan j++;
1180 1.23 macallan }
1181 1.23 macallan cg6_loadcmap(sc, 0, 256);
1182 1.18 martin }
1183 1.18 martin
1184 1.18 martin int
1185 1.18 martin cgsix_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
1186 1.18 martin {
1187 1.18 martin /* we'll probably need to add more stuff here */
1188 1.18 martin struct cgsix_softc *sc = v;
1189 1.18 martin struct wsdisplay_fbinfo *wdf;
1190 1.18 martin struct rasops_info *ri = &sc->sc_fb.fb_rinfo;
1191 1.23 macallan struct cg6_screen *ms = sc->active;
1192 1.18 martin #ifdef CGSIX_DEBUG
1193 1.18 martin printf("cgsix_ioctl(%ld)\n",cmd);
1194 1.18 martin #endif
1195 1.18 martin switch (cmd) {
1196 1.18 martin case WSDISPLAYIO_GTYPE:
1197 1.18 martin *(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
1198 1.18 martin return 0;
1199 1.18 martin case WSDISPLAYIO_GINFO:
1200 1.18 martin wdf = (void *)data;
1201 1.18 martin wdf->height = ri->ri_height;
1202 1.18 martin wdf->width = ri->ri_width;
1203 1.18 martin wdf->depth = ri->ri_depth;
1204 1.18 martin wdf->cmsize = 256;
1205 1.18 martin return 0;
1206 1.19 perry
1207 1.18 martin case WSDISPLAYIO_GETCMAP:
1208 1.22 martin return cgsix_getcmap(sc,
1209 1.22 martin (struct wsdisplay_cmap *)data);
1210 1.18 martin case WSDISPLAYIO_PUTCMAP:
1211 1.22 martin return cgsix_putcmap(sc,
1212 1.22 martin (struct wsdisplay_cmap *)data);
1213 1.19 perry
1214 1.18 martin case WSDISPLAYIO_SMODE:
1215 1.18 martin {
1216 1.23 macallan int new_mode = *(int*)data;
1217 1.23 macallan if (new_mode != sc->sc_mode)
1218 1.18 martin {
1219 1.23 macallan sc->sc_mode = new_mode;
1220 1.23 macallan if(new_mode == WSDISPLAYIO_MODE_EMUL)
1221 1.18 martin {
1222 1.23 macallan cg6_reset(sc);
1223 1.23 macallan cg6_ras_init(sc);
1224 1.23 macallan /* restore the screen content */
1225 1.23 macallan cgsix_restore_screen(ms,
1226 1.23 macallan ms->type, ms->chars);
1227 1.23 macallan /*
1228 1.23 macallan * because X likes to bork up
1229 1.23 macallan * our colour map
1230 1.22 martin */
1231 1.23 macallan cg6_setup_palette(sc); /* and draw the cursor */
1232 1.23 macallan cgsix_cursor(ms, ms->cursoron,
1233 1.23 macallan ms->cursorrow,
1234 1.23 macallan ms->cursorcol);
1235 1.18 martin }
1236 1.18 martin }
1237 1.18 martin }
1238 1.18 martin }
1239 1.18 martin return EPASSTHROUGH;
1240 1.18 martin }
1241 1.18 martin
1242 1.18 martin paddr_t
1243 1.18 martin cgsix_mmap(void *v, off_t offset, int prot)
1244 1.18 martin {
1245 1.18 martin struct cgsix_softc *sc = v;
1246 1.23 macallan if(offset<sc->sc_ramsize) {
1247 1.23 macallan return bus_space_mmap(sc->sc_bustag, sc->sc_paddr,
1248 1.23 macallan CGSIX_RAM_OFFSET+offset, prot, BUS_SPACE_MAP_LINEAR);
1249 1.18 martin }
1250 1.18 martin /* I'm not at all sure this is the right thing to do */
1251 1.23 macallan return cgsixmmap(0, offset, prot); /* assume minor dev 0 for now */
1252 1.18 martin }
1253 1.18 martin
1254 1.19 perry int
1255 1.18 martin cgsix_putcmap(struct cgsix_softc *sc, struct wsdisplay_cmap *cm)
1256 1.18 martin {
1257 1.18 martin u_int index = cm->index;
1258 1.18 martin u_int count = cm->count;
1259 1.18 martin int error,i;
1260 1.18 martin if (index >= 256 || count > 256 || index + count > 256)
1261 1.18 martin return EINVAL;
1262 1.18 martin
1263 1.23 macallan for (i = 0; i < count; i++)
1264 1.18 martin {
1265 1.22 martin error = copyin(&cm->red[i],
1266 1.23 macallan &sc->sc_cmap.cm_map[index + i][0], 1);
1267 1.18 martin if (error)
1268 1.18 martin return error;
1269 1.22 martin error = copyin(&cm->green[i],
1270 1.23 macallan &sc->sc_cmap.cm_map[index + i][1],
1271 1.22 martin 1);
1272 1.18 martin if (error)
1273 1.18 martin return error;
1274 1.22 martin error = copyin(&cm->blue[i],
1275 1.23 macallan &sc->sc_cmap.cm_map[index + i][2], 1);
1276 1.18 martin if (error)
1277 1.18 martin return error;
1278 1.18 martin }
1279 1.23 macallan cg6_loadcmap(sc, index, count);
1280 1.19 perry
1281 1.18 martin return 0;
1282 1.18 martin }
1283 1.18 martin
1284 1.22 martin int
1285 1.22 martin cgsix_getcmap(struct cgsix_softc *sc, struct wsdisplay_cmap *cm)
1286 1.18 martin {
1287 1.18 martin u_int index = cm->index;
1288 1.18 martin u_int count = cm->count;
1289 1.18 martin int error,i;
1290 1.18 martin
1291 1.18 martin if (index >= 256 || count > 256 || index + count > 256)
1292 1.18 martin return EINVAL;
1293 1.18 martin
1294 1.23 macallan for (i = 0; i < count; i++)
1295 1.18 martin {
1296 1.23 macallan error = copyout(&sc->sc_cmap.cm_map[index + i][0],
1297 1.23 macallan &cm->red[i], 1);
1298 1.18 martin if (error)
1299 1.18 martin return error;
1300 1.23 macallan error = copyout(&sc->sc_cmap.cm_map[index + i][1],
1301 1.23 macallan &cm->green[i], 1);
1302 1.18 martin if (error)
1303 1.18 martin return error;
1304 1.23 macallan error = copyout(&sc->sc_cmap.cm_map[index + i][2],
1305 1.23 macallan &cm->blue[i], 1);
1306 1.18 martin if (error)
1307 1.18 martin return error;
1308 1.18 martin }
1309 1.19 perry
1310 1.18 martin return 0;
1311 1.18 martin }
1312 1.23 macallan
1313 1.23 macallan void
1314 1.23 macallan cgsix_init_screen(struct cgsix_softc *sc, struct cg6_screen *scr,
1315 1.23 macallan int existing, long *defattr)
1316 1.23 macallan {
1317 1.23 macallan struct rasops_info *ri = &scr->ri;
1318 1.23 macallan int cnt;
1319 1.23 macallan scr->sc = sc;
1320 1.23 macallan /*scr->type = type;*/
1321 1.23 macallan scr->cursorcol = 0;
1322 1.23 macallan scr->cursorrow = 0;
1323 1.23 macallan scr->cursordrawn = 0;
1324 1.23 macallan
1325 1.23 macallan ri->ri_depth = 8;
1326 1.23 macallan ri->ri_width = sc->sc_width;
1327 1.23 macallan ri->ri_height = sc->sc_height;
1328 1.23 macallan ri->ri_stride = sc->sc_stride;
1329 1.23 macallan ri->ri_flg = RI_CENTER;
1330 1.23 macallan
1331 1.23 macallan ri->ri_bits = sc->sc_fb.fb_pixels;
1332 1.23 macallan
1333 1.23 macallan rasops_init(ri, sc->sc_height/8, sc->sc_width/8);
1334 1.23 macallan ri->ri_caps=WSSCREEN_WSCOLORS;
1335 1.23 macallan rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
1336 1.23 macallan sc->sc_width / ri->ri_font->fontwidth);
1337 1.23 macallan ri->ri_ops.allocattr(ri, 0, 0, 0, defattr);
1338 1.23 macallan
1339 1.23 macallan cnt = ri->ri_rows * ri->ri_cols;
1340 1.23 macallan /*
1341 1.23 macallan * we allocate both chars and attributes in one chunk, attributes first
1342 1.23 macallan * because they have the (potentially) bigger alignment
1343 1.23 macallan */
1344 1.23 macallan scr->attrs = (long *)malloc(cnt * (sizeof(long) + sizeof(uint16_t)),
1345 1.23 macallan M_DEVBUF, M_WAITOK);
1346 1.23 macallan scr->chars = (uint16_t *)&scr->attrs[cnt];
1347 1.23 macallan
1348 1.23 macallan /* enable acceleration */
1349 1.23 macallan ri->ri_hw = scr;
1350 1.23 macallan ri->ri_ops.copyrows = cg6_ras_copyrows;
1351 1.23 macallan ri->ri_ops.copycols = cg6_ras_copycols;
1352 1.23 macallan ri->ri_ops.eraserows = cg6_ras_eraserows;
1353 1.23 macallan ri->ri_ops.erasecols = cg6_ras_erasecols;
1354 1.23 macallan ri->ri_ops.cursor = cgsix_cursor;
1355 1.23 macallan ri->ri_ops.putchar = cgsix_putchar;
1356 1.23 macallan if (existing) {
1357 1.23 macallan scr->active = 1;
1358 1.23 macallan } else {
1359 1.23 macallan scr->active = 0;
1360 1.23 macallan }
1361 1.23 macallan
1362 1.23 macallan cg6_ras_eraserows(&scr->ri, 0, ri->ri_rows, *defattr);
1363 1.23 macallan
1364 1.23 macallan LIST_INSERT_HEAD(&sc->screens, scr, next);
1365 1.23 macallan }
1366 1.23 macallan
1367 1.23 macallan int
1368 1.23 macallan cgsix_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
1369 1.23 macallan int *curxp, int *curyp, long *defattrp)
1370 1.23 macallan {
1371 1.23 macallan struct cgsix_softc *sc = v;
1372 1.23 macallan struct cg6_screen *scr;
1373 1.23 macallan
1374 1.23 macallan scr = malloc(sizeof(struct cg6_screen), M_DEVBUF, M_WAITOK|M_ZERO);
1375 1.23 macallan cgsix_init_screen(sc, scr, 0, defattrp);
1376 1.23 macallan
1377 1.23 macallan if (sc->active == NULL) {
1378 1.23 macallan scr->active = 1;
1379 1.23 macallan sc->active = scr;
1380 1.23 macallan sc->currenttype = type;
1381 1.23 macallan }
1382 1.23 macallan
1383 1.23 macallan *cookiep = scr;
1384 1.23 macallan *curxp = scr->cursorcol;
1385 1.23 macallan *curyp = scr->cursorrow;
1386 1.23 macallan return 0;
1387 1.23 macallan }
1388 1.23 macallan
1389 1.23 macallan void
1390 1.23 macallan cgsix_free_screen(void *v, void *cookie)
1391 1.23 macallan {
1392 1.23 macallan struct cgsix_softc *sc = v;
1393 1.23 macallan struct cg6_screen *scr = cookie;
1394 1.23 macallan
1395 1.23 macallan LIST_REMOVE(scr, next);
1396 1.23 macallan if (scr != &cg6_console_screen) {
1397 1.23 macallan free(scr->attrs, M_DEVBUF);
1398 1.23 macallan free(scr, M_DEVBUF);
1399 1.23 macallan } else
1400 1.23 macallan panic("cgsix_free_screen: console");
1401 1.23 macallan
1402 1.23 macallan if (sc->active == scr)
1403 1.23 macallan sc->active = 0;
1404 1.23 macallan }
1405 1.23 macallan
1406 1.23 macallan int
1407 1.23 macallan cgsix_show_screen(void *v, void *cookie, int waitok,
1408 1.23 macallan void (*cb)(void *, int, int), void *cbarg)
1409 1.23 macallan {
1410 1.23 macallan struct cgsix_softc *sc = v;
1411 1.23 macallan struct cg6_screen *scr, *oldscr;
1412 1.23 macallan
1413 1.23 macallan scr = cookie;
1414 1.23 macallan oldscr = sc->active;
1415 1.23 macallan if (scr == oldscr)
1416 1.23 macallan return 0;
1417 1.23 macallan
1418 1.23 macallan sc->wanted = scr;
1419 1.23 macallan sc->switchcb = cb;
1420 1.23 macallan sc->switchcbarg = cbarg;
1421 1.23 macallan if (cb) {
1422 1.23 macallan callout_reset(&sc->switch_callout, 0,
1423 1.23 macallan (void(*)(void *))cgsix_switch_screen, sc);
1424 1.23 macallan return EAGAIN;
1425 1.23 macallan }
1426 1.23 macallan
1427 1.23 macallan cgsix_switch_screen(sc);
1428 1.23 macallan return 0;
1429 1.23 macallan }
1430 1.23 macallan
1431 1.23 macallan void
1432 1.23 macallan cgsix_switch_screen(struct cgsix_softc *sc)
1433 1.23 macallan {
1434 1.23 macallan struct cg6_screen *scr, *oldscr;
1435 1.23 macallan
1436 1.23 macallan scr = sc->wanted;
1437 1.23 macallan if (!scr) {
1438 1.23 macallan printf("cgsix_switch_screen: disappeared\n");
1439 1.23 macallan (*sc->switchcb)(sc->switchcbarg, EIO, 0);
1440 1.23 macallan return;
1441 1.23 macallan }
1442 1.23 macallan oldscr = sc->active; /* can be NULL! */
1443 1.23 macallan #ifdef DIAGNOSTIC
1444 1.23 macallan if (oldscr) {
1445 1.23 macallan if (!oldscr->active)
1446 1.23 macallan panic("cgsix_switch_screen: not active");
1447 1.23 macallan }
1448 1.23 macallan #endif
1449 1.23 macallan if (scr == oldscr)
1450 1.23 macallan return;
1451 1.23 macallan
1452 1.23 macallan #ifdef DIAGNOSTIC
1453 1.23 macallan if (scr->active)
1454 1.23 macallan panic("cgsix_switch_screen: active");
1455 1.23 macallan #endif
1456 1.23 macallan
1457 1.23 macallan if (oldscr)
1458 1.23 macallan oldscr->active = 0;
1459 1.23 macallan #ifdef notyet
1460 1.23 macallan if (sc->currenttype != type) {
1461 1.23 macallan cgsix_set_screentype(sc, type);
1462 1.23 macallan sc->currenttype = type;
1463 1.23 macallan }
1464 1.23 macallan #endif
1465 1.23 macallan
1466 1.23 macallan /* Clear the entire screen. */
1467 1.23 macallan
1468 1.23 macallan scr->active = 1;
1469 1.23 macallan cgsix_restore_screen(scr, &cgsix_defaultscreen, scr->chars);
1470 1.23 macallan
1471 1.23 macallan sc->active = scr;
1472 1.23 macallan
1473 1.23 macallan scr->ri.ri_ops.cursor(scr, scr->cursoron, scr->cursorrow,
1474 1.23 macallan scr->cursorcol);
1475 1.23 macallan
1476 1.23 macallan sc->wanted = 0;
1477 1.23 macallan if (sc->switchcb)
1478 1.23 macallan (*sc->switchcb)(sc->switchcbarg, 0, 0);
1479 1.23 macallan }
1480 1.23 macallan
1481 1.23 macallan void
1482 1.23 macallan cgsix_restore_screen(struct cg6_screen *scr,
1483 1.23 macallan const struct wsscreen_descr *type, u_int16_t *mem)
1484 1.23 macallan {
1485 1.23 macallan int i, j, offset = 0;
1486 1.23 macallan uint16_t *charptr = scr->chars;
1487 1.23 macallan long *attrptr = scr->attrs;
1488 1.23 macallan
1489 1.23 macallan cgsix_clearscreen(scr->sc);
1490 1.23 macallan for (i = 0; i < scr->ri.ri_rows; i++) {
1491 1.23 macallan for (j = 0; j < scr->ri.ri_cols; j++) {
1492 1.23 macallan cgsix_putchar(scr, i, j, charptr[offset],
1493 1.23 macallan attrptr[offset]);
1494 1.23 macallan offset++;
1495 1.23 macallan }
1496 1.23 macallan }
1497 1.23 macallan scr->cursordrawn = 0;
1498 1.23 macallan }
1499 1.23 macallan
1500 1.23 macallan void
1501 1.23 macallan cgsix_rectfill(struct cgsix_softc *sc, int xs, int ys, int wi, int he,
1502 1.23 macallan uint32_t col)
1503 1.23 macallan {
1504 1.23 macallan volatile struct cg6_fbc *fbc = sc->sc_fbc;
1505 1.23 macallan
1506 1.23 macallan CG6_DRAIN(fbc);
1507 1.23 macallan fbc->fbc_clip = 0;
1508 1.23 macallan fbc->fbc_s = 0;
1509 1.23 macallan fbc->fbc_offx = 0;
1510 1.23 macallan fbc->fbc_offy = 0;
1511 1.23 macallan fbc->fbc_clipminx = 0;
1512 1.23 macallan fbc->fbc_clipminy = 0;
1513 1.23 macallan fbc->fbc_clipmaxx = sc->sc_width - 1;
1514 1.23 macallan fbc->fbc_clipmaxy = sc->sc_height - 1;
1515 1.23 macallan fbc->fbc_alu = CG6_ALU_FILL;
1516 1.23 macallan fbc->fbc_fg = col;
1517 1.23 macallan fbc->fbc_arecty = ys;
1518 1.23 macallan fbc->fbc_arectx = xs;
1519 1.23 macallan fbc->fbc_arecty = ys + he - 1;
1520 1.23 macallan fbc->fbc_arectx = xs + wi - 1;
1521 1.23 macallan CG6_DRAW_WAIT(fbc);
1522 1.23 macallan }
1523 1.23 macallan
1524 1.23 macallan void
1525 1.23 macallan cgsix_setup_mono(struct cgsix_softc *sc, int x, int y, int wi, int he,
1526 1.23 macallan uint32_t fg, uint32_t bg)
1527 1.23 macallan {
1528 1.23 macallan volatile struct cg6_fbc *fbc=sc->sc_fbc;
1529 1.23 macallan CG6_DRAIN(fbc);
1530 1.23 macallan fbc->fbc_x0 = x;
1531 1.23 macallan fbc->fbc_x1 =x + wi - 1;
1532 1.23 macallan fbc->fbc_y0 = y;
1533 1.23 macallan fbc->fbc_incx = 0;
1534 1.23 macallan fbc->fbc_incy = 1;
1535 1.23 macallan fbc->fbc_fg = fg;
1536 1.23 macallan fbc->fbc_bg = bg;
1537 1.23 macallan fbc->fbc_mode = 0x00140000; /* nosrc, color1 */
1538 1.23 macallan fbc->fbc_alu = 0x0800fc30; /* colour expansion, solid bg */
1539 1.23 macallan sc->sc_mono_width = wi;
1540 1.23 macallan /* now feed the data into the chip */
1541 1.23 macallan }
1542 1.23 macallan
1543 1.23 macallan void
1544 1.23 macallan cgsix_feed_line(struct cgsix_softc *sc, int count, uint8_t *data)
1545 1.23 macallan {
1546 1.23 macallan int i;
1547 1.23 macallan uint32_t latch, res = 0, shift;
1548 1.23 macallan volatile struct cg6_fbc *fbc = sc->sc_fbc;
1549 1.23 macallan
1550 1.23 macallan if (sc->sc_mono_width > 32) {
1551 1.23 macallan /* ARGH! */
1552 1.23 macallan } else
1553 1.23 macallan {
1554 1.23 macallan shift = 24;
1555 1.23 macallan for (i = 0; i < count; i++) {
1556 1.23 macallan latch = data[i];
1557 1.23 macallan res |= latch << shift;
1558 1.23 macallan shift -= 8;
1559 1.23 macallan }
1560 1.23 macallan fbc->fbc_font = res;
1561 1.23 macallan }
1562 1.23 macallan }
1563 1.23 macallan
1564 1.23 macallan void
1565 1.23 macallan cgsix_putchar(void *cookie, int row, int col, u_int c, long attr)
1566 1.23 macallan {
1567 1.23 macallan struct rasops_info *ri=cookie;
1568 1.23 macallan struct cg6_screen *scr=ri->ri_hw;
1569 1.23 macallan struct cgsix_softc *sc=scr->sc;
1570 1.23 macallan int pos;
1571 1.23 macallan
1572 1.23 macallan if ((row >= 0) && (row < ri->ri_rows) && (col >= 0) &&
1573 1.23 macallan (col < ri->ri_cols)) {
1574 1.23 macallan pos = col + row * ri->ri_cols;
1575 1.23 macallan scr->attrs[pos] = attr;
1576 1.23 macallan scr->chars[pos] = c;
1577 1.23 macallan
1578 1.23 macallan if ((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1579 1.23 macallan /*cgsix_sync(sc);*/
1580 1.23 macallan int fg, bg, uc, i;
1581 1.23 macallan uint8_t *data;
1582 1.23 macallan int x, y, wi, he;
1583 1.23 macallan volatile struct cg6_fbc *fbc = sc->sc_fbc;
1584 1.23 macallan
1585 1.23 macallan wi = ri->ri_font->fontwidth;
1586 1.23 macallan he = ri->ri_font->fontheight;
1587 1.23 macallan
1588 1.23 macallan if (!CHAR_IN_FONT(c, ri->ri_font))
1589 1.23 macallan return;
1590 1.23 macallan bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xff];
1591 1.23 macallan fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xff];
1592 1.23 macallan x = ri->ri_xorigin + col * wi;
1593 1.23 macallan y = ri->ri_yorigin + row * he;
1594 1.23 macallan if (c == 0x20) {
1595 1.23 macallan cgsix_rectfill(sc, x, y, wi, he, bg);
1596 1.23 macallan } else {
1597 1.23 macallan uc = c-ri->ri_font->firstchar;
1598 1.23 macallan data = (uint8_t *)ri->ri_font->data + uc *
1599 1.23 macallan ri->ri_fontscale;
1600 1.23 macallan
1601 1.23 macallan cgsix_setup_mono(sc, x, y, wi, 1, fg, bg);
1602 1.23 macallan for (i = 0; i < he; i++) {
1603 1.23 macallan cgsix_feed_line(sc, ri->ri_font->stride,
1604 1.23 macallan data);
1605 1.23 macallan data += ri->ri_font->stride;
1606 1.23 macallan }
1607 1.23 macallan /* put the chip back to normal */
1608 1.23 macallan fbc->fbc_incy = 0;
1609 1.23 macallan /* nosrc, color8 */
1610 1.23 macallan fbc->fbc_mode = 0x00120000;
1611 1.23 macallan fbc->fbc_mode &= ~CG6_MODE_MASK;
1612 1.23 macallan fbc->fbc_mode |= CG6_MODE;
1613 1.23 macallan }
1614 1.23 macallan }
1615 1.23 macallan }
1616 1.23 macallan }
1617 1.23 macallan
1618 1.23 macallan void
1619 1.23 macallan cgsix_cursor(void *cookie, int on, int row, int col)
1620 1.23 macallan {
1621 1.23 macallan struct rasops_info *ri=cookie;
1622 1.23 macallan struct cg6_screen *scr=ri->ri_hw;
1623 1.23 macallan struct cgsix_softc *sc=scr->sc;
1624 1.23 macallan int x, y, wi, he;
1625 1.23 macallan
1626 1.23 macallan wi = ri->ri_font->fontwidth;
1627 1.23 macallan he = ri->ri_font->fontheight;
1628 1.23 macallan
1629 1.23 macallan if((scr->active) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
1630 1.23 macallan x = scr->cursorcol * wi + ri->ri_xorigin;
1631 1.23 macallan y = scr->cursorrow * he + ri->ri_yorigin;
1632 1.23 macallan if(scr->cursordrawn) {
1633 1.23 macallan cg6_invert(sc, x, y, wi, he);
1634 1.23 macallan scr->cursordrawn = 0;
1635 1.23 macallan }
1636 1.23 macallan scr->cursorrow = row;
1637 1.23 macallan scr->cursorcol = col;
1638 1.23 macallan if((scr->cursoron = on) != 0)
1639 1.23 macallan {
1640 1.23 macallan x = scr->cursorcol * wi + ri->ri_xorigin;
1641 1.23 macallan y = scr->cursorrow * he + ri->ri_yorigin;
1642 1.23 macallan cg6_invert(sc, x, y, wi, he);
1643 1.23 macallan scr->cursordrawn = 1;
1644 1.23 macallan }
1645 1.23 macallan } else {
1646 1.23 macallan scr->cursoron = on;
1647 1.23 macallan scr->cursorrow = row;
1648 1.23 macallan scr->cursorcol = col;
1649 1.23 macallan scr->cursordrawn = 0;
1650 1.23 macallan }
1651 1.23 macallan }
1652 1.23 macallan
1653 1.23 macallan void
1654 1.23 macallan cgsix_clearscreen(struct cgsix_softc *sc)
1655 1.23 macallan {
1656 1.23 macallan struct rasops_info *ri=&cg6_console_screen.ri;
1657 1.23 macallan
1658 1.23 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
1659 1.23 macallan volatile struct cg6_fbc *fbc = sc->sc_fbc;
1660 1.23 macallan
1661 1.23 macallan CG6_DRAIN(fbc);
1662 1.23 macallan fbc->fbc_clip = 0;
1663 1.23 macallan fbc->fbc_s = 0;
1664 1.23 macallan fbc->fbc_offx = 0;
1665 1.23 macallan fbc->fbc_offy = 0;
1666 1.23 macallan fbc->fbc_clipminx = 0;
1667 1.23 macallan fbc->fbc_clipminy = 0;
1668 1.23 macallan fbc->fbc_clipmaxx = ri->ri_width - 1;
1669 1.23 macallan fbc->fbc_clipmaxy = ri->ri_height - 1;
1670 1.23 macallan fbc->fbc_alu = CG6_ALU_FILL;
1671 1.23 macallan fbc->fbc_fg = ri->ri_devcmap[sc->sc_bg];
1672 1.23 macallan fbc->fbc_arectx = 0;
1673 1.23 macallan fbc->fbc_arecty = 0;
1674 1.23 macallan fbc->fbc_arectx = ri->ri_width - 1;
1675 1.23 macallan fbc->fbc_arecty = ri->ri_height - 1;
1676 1.23 macallan CG6_DRAW_WAIT(fbc);
1677 1.23 macallan }
1678 1.23 macallan }
1679 1.23 macallan
1680 1.23 macallan #endif /* NWSDISPLAY > 0 */
1681 1.23 macallan
1682 1.23 macallan #if (NWSDISPLAY > 0) || defined(RASTERCONSOLE)
1683 1.23 macallan void
1684 1.23 macallan cg6_invert(struct cgsix_softc *sc, int x, int y, int wi, int he)
1685 1.23 macallan {
1686 1.23 macallan volatile struct cg6_fbc *fbc = sc->sc_fbc;
1687 1.23 macallan struct rasops_info *ri = &cg6_console_screen.ri;
1688 1.23 macallan
1689 1.23 macallan CG6_DRAIN(fbc);
1690 1.23 macallan fbc->fbc_clip = 0;
1691 1.23 macallan fbc->fbc_s = 0;
1692 1.23 macallan fbc->fbc_offx = 0;
1693 1.23 macallan fbc->fbc_offy = 0;
1694 1.23 macallan fbc->fbc_clipminx = 0;
1695 1.23 macallan fbc->fbc_clipminy = 0;
1696 1.23 macallan fbc->fbc_clipmaxx = ri->ri_width - 1;
1697 1.23 macallan fbc->fbc_clipmaxy = ri->ri_height - 1;
1698 1.23 macallan fbc->fbc_alu = CG6_ALU_FLIP;
1699 1.23 macallan fbc->fbc_arecty = y;
1700 1.23 macallan fbc->fbc_arectx = x;
1701 1.24 macallan fbc->fbc_arecty = y + he - 1;
1702 1.24 macallan fbc->fbc_arectx = x + wi - 1;
1703 1.23 macallan CG6_DRAW_WAIT(fbc);
1704 1.23 macallan }
1705 1.23 macallan
1706 1.23 macallan #endif
1707