tcx.c revision 1.48 1 1.48 martin /* $NetBSD: tcx.c,v 1.48 2014/05/13 05:30:38 martin Exp $ */
2 1.1 pk
3 1.1 pk /*
4 1.36 macallan * Copyright (c) 1996, 1998, 2009 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.33 macallan * by Paul Kranenburg and Michael Lorenz.
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 *
19 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
30 1.1 pk */
31 1.1 pk
32 1.1 pk /*
33 1.1 pk * color display (TCX) driver.
34 1.1 pk *
35 1.1 pk * Does not handle interrupts, even though they can occur.
36 1.1 pk *
37 1.1 pk * XXX should defer colormap updates to vertical retrace interrupts
38 1.1 pk */
39 1.4 lukem
40 1.4 lukem #include <sys/cdefs.h>
41 1.48 martin __KERNEL_RCSID(0, "$NetBSD: tcx.c,v 1.48 2014/05/13 05:30:38 martin Exp $");
42 1.7 darrenr
43 1.7 darrenr /*
44 1.7 darrenr * define for cg8 emulation on S24 (24-bit version of tcx) for the SS5;
45 1.7 darrenr * it is bypassed on the 8-bit version (onboard framebuffer for SS4)
46 1.7 darrenr */
47 1.7 darrenr #undef TCX_CG8
48 1.1 pk
49 1.1 pk #include <sys/param.h>
50 1.1 pk #include <sys/systm.h>
51 1.1 pk #include <sys/buf.h>
52 1.1 pk #include <sys/device.h>
53 1.1 pk #include <sys/ioctl.h>
54 1.1 pk #include <sys/malloc.h>
55 1.1 pk #include <sys/mman.h>
56 1.1 pk #include <sys/tty.h>
57 1.1 pk #include <sys/conf.h>
58 1.1 pk
59 1.1 pk #ifdef DEBUG
60 1.1 pk #include <sys/proc.h>
61 1.1 pk #include <sys/syslog.h>
62 1.1 pk #endif
63 1.1 pk
64 1.22 ad #include <sys/bus.h>
65 1.1 pk #include <machine/autoconf.h>
66 1.1 pk
67 1.1 pk #include <dev/sun/fbio.h>
68 1.1 pk #include <dev/sun/fbvar.h>
69 1.1 pk #include <dev/sun/btreg.h>
70 1.1 pk #include <dev/sun/btvar.h>
71 1.2 pk
72 1.2 pk #include <dev/sbus/sbusvar.h>
73 1.2 pk #include <dev/sbus/tcxreg.h>
74 1.1 pk
75 1.32 macallan #include <dev/wscons/wsdisplayvar.h>
76 1.32 macallan #include <dev/wscons/wsconsio.h>
77 1.32 macallan #include <dev/wsfont/wsfont.h>
78 1.32 macallan #include <dev/rasops/rasops.h>
79 1.32 macallan
80 1.32 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
81 1.32 macallan
82 1.32 macallan #include "opt_wsemul.h"
83 1.32 macallan
84 1.42 tsutsui #include "ioconf.h"
85 1.42 tsutsui
86 1.1 pk /* per-display variables */
87 1.1 pk struct tcx_softc {
88 1.33 macallan device_t sc_dev; /* base device */
89 1.1 pk struct fbdevice sc_fb; /* frame buffer device */
90 1.1 pk bus_space_tag_t sc_bustag;
91 1.34 macallan struct openprom_addr sc_physaddr[TCX_NREG];/* phys addr of h/w */
92 1.1 pk
93 1.32 macallan bus_space_handle_t sc_bt; /* Brooktree registers */
94 1.32 macallan bus_space_handle_t sc_thc; /* THC registers */
95 1.32 macallan uint8_t *sc_fbaddr; /* framebuffer */
96 1.32 macallan uint64_t *sc_rblit; /* blitspace */
97 1.32 macallan uint64_t *sc_rstip; /* stipple space */
98 1.32 macallan
99 1.7 darrenr short sc_8bit; /* true if 8-bit hardware */
100 1.1 pk short sc_blanked; /* true if blanked */
101 1.32 macallan u_char sc_cmap_red[256];
102 1.32 macallan u_char sc_cmap_green[256];
103 1.32 macallan u_char sc_cmap_blue[256];
104 1.32 macallan int sc_mode, sc_bg;
105 1.37 macallan int sc_cursor_x, sc_cursor_y;
106 1.37 macallan int sc_hotspot_x, sc_hotspot_y;
107 1.32 macallan struct vcons_data vd;
108 1.32 macallan };
109 1.32 macallan
110 1.32 macallan static struct vcons_screen tcx_console_screen;
111 1.32 macallan
112 1.32 macallan extern const u_char rasops_cmap[768];
113 1.32 macallan
114 1.32 macallan struct wsscreen_descr tcx_defscreendesc = {
115 1.32 macallan "default",
116 1.32 macallan 0, 0,
117 1.32 macallan NULL,
118 1.32 macallan 8, 16,
119 1.32 macallan WSSCREEN_WSCOLORS,
120 1.32 macallan };
121 1.32 macallan
122 1.32 macallan const struct wsscreen_descr *_tcx_scrlist[] = {
123 1.32 macallan &tcx_defscreendesc,
124 1.32 macallan /* XXX other formats, graphics screen? */
125 1.32 macallan };
126 1.32 macallan
127 1.32 macallan struct wsscreen_list tcx_screenlist = {
128 1.32 macallan sizeof(_tcx_scrlist) / sizeof(struct wsscreen_descr *),
129 1.32 macallan _tcx_scrlist
130 1.1 pk };
131 1.1 pk
132 1.7 darrenr /*
133 1.7 darrenr * The S24 provides the framebuffer RAM mapped in three ways:
134 1.7 darrenr * 26 bits per pixel, in 32-bit words; the low-order 24 bits are
135 1.7 darrenr * blue, green, and red values, and the other two bits select the
136 1.7 darrenr * display modes, per pixel);
137 1.7 darrenr * 24 bits per pixel, in 32-bit words; the high-order byte reads as
138 1.7 darrenr * zero, and is ignored on writes (so the mode bits cannot be altered);
139 1.7 darrenr * 8 bits per pixel, unpadded; writes to this space do not modify the
140 1.7 darrenr * other 18 bits.
141 1.7 darrenr */
142 1.7 darrenr #define TCX_CTL_8_MAPPED 0x00000000 /* 8 bits, uses color map */
143 1.7 darrenr #define TCX_CTL_24_MAPPED 0x01000000 /* 24 bits, uses color map */
144 1.7 darrenr #define TCX_CTL_24_LEVEL 0x03000000 /* 24 bits, ignores color map */
145 1.7 darrenr #define TCX_CTL_PIXELMASK 0x00FFFFFF /* mask for index/level */
146 1.7 darrenr
147 1.1 pk /* autoconfiguration driver */
148 1.31 cegger static void tcxattach(device_t, device_t, void *);
149 1.31 cegger static int tcxmatch(device_t, cfdata_t, void *);
150 1.31 cegger static void tcx_unblank(device_t);
151 1.1 pk
152 1.33 macallan CFATTACH_DECL_NEW(tcx, sizeof(struct tcx_softc),
153 1.12 thorpej tcxmatch, tcxattach, NULL, NULL);
154 1.1 pk
155 1.9 gehenna dev_type_open(tcxopen);
156 1.9 gehenna dev_type_close(tcxclose);
157 1.9 gehenna dev_type_ioctl(tcxioctl);
158 1.9 gehenna dev_type_mmap(tcxmmap);
159 1.9 gehenna
160 1.9 gehenna const struct cdevsw tcx_cdevsw = {
161 1.45 dholland .d_open = tcxopen,
162 1.45 dholland .d_close = tcxclose,
163 1.45 dholland .d_read = noread,
164 1.45 dholland .d_write = nowrite,
165 1.45 dholland .d_ioctl = tcxioctl,
166 1.45 dholland .d_stop = nostop,
167 1.45 dholland .d_tty = notty,
168 1.45 dholland .d_poll = nopoll,
169 1.45 dholland .d_mmap = tcxmmap,
170 1.45 dholland .d_kqfilter = nokqfilter,
171 1.45 dholland .d_flag = 0
172 1.9 gehenna };
173 1.9 gehenna
174 1.1 pk /* frame buffer generic driver */
175 1.1 pk static struct fbdriver tcx_fbdriver = {
176 1.13 jdolecek tcx_unblank, tcxopen, tcxclose, tcxioctl, nopoll, tcxmmap,
177 1.13 jdolecek nokqfilter
178 1.1 pk };
179 1.1 pk
180 1.17 perry static void tcx_reset(struct tcx_softc *);
181 1.17 perry static void tcx_loadcmap(struct tcx_softc *, int, int);
182 1.1 pk
183 1.32 macallan static int tcx_ioctl(void *, void *, u_long, void *, int, struct lwp *);
184 1.32 macallan static paddr_t tcx_mmap(void *, void *, off_t, int);
185 1.32 macallan
186 1.32 macallan static void tcx_init_screen(void *, struct vcons_screen *, int, long *);
187 1.36 macallan static void tcx_clearscreen(struct tcx_softc *, int);
188 1.32 macallan static void tcx_copyrows(void *, int, int, int);
189 1.32 macallan static void tcx_eraserows(void *, int, int, long);
190 1.32 macallan static void tcx_putchar(void *, int, int, u_int, long);
191 1.35 macallan static void tcx_set_video(struct tcx_softc *, int);
192 1.37 macallan static int tcx_do_cursor(struct tcx_softc *, struct wsdisplay_cursor *);
193 1.37 macallan static void tcx_set_cursor(struct tcx_softc *);
194 1.32 macallan
195 1.32 macallan struct wsdisplay_accessops tcx_accessops = {
196 1.32 macallan tcx_ioctl,
197 1.32 macallan tcx_mmap,
198 1.32 macallan NULL, /* vcons_alloc_screen */
199 1.32 macallan NULL, /* vcons_free_screen */
200 1.32 macallan NULL, /* vcons_show_screen */
201 1.32 macallan NULL, /* load_font */
202 1.32 macallan NULL, /* polls */
203 1.32 macallan NULL, /* scroll */
204 1.32 macallan };
205 1.32 macallan
206 1.1 pk #define OBPNAME "SUNW,tcx"
207 1.7 darrenr
208 1.7 darrenr #ifdef TCX_CG8
209 1.7 darrenr /*
210 1.7 darrenr * For CG8 emulation, we map the 32-bit-deep framebuffer at an offset of
211 1.7 darrenr * 256K; the cg8 space begins with a mono overlay plane and an overlay
212 1.7 darrenr * enable plane (128K bytes each, 1 bit per pixel), immediately followed
213 1.7 darrenr * by the color planes, 32 bits per pixel. We also map just the 32-bit
214 1.7 darrenr * framebuffer at 0x04000000 (TCX_USER_RAM_COMPAT), for compatibility
215 1.7 darrenr * with the cg8 driver.
216 1.7 darrenr */
217 1.7 darrenr #define TCX_CG8OVERLAY (256 * 1024)
218 1.7 darrenr #define TCX_SIZE_DFB32 (1152 * 900 * 4) /* max size of the framebuffer */
219 1.7 darrenr #endif
220 1.7 darrenr
221 1.1 pk /*
222 1.1 pk * Match a tcx.
223 1.1 pk */
224 1.1 pk int
225 1.31 cegger tcxmatch(device_t parent, cfdata_t cf, void *aux)
226 1.1 pk {
227 1.1 pk struct sbus_attach_args *sa = aux;
228 1.1 pk
229 1.46 macallan if (strcmp(sa->sa_name, OBPNAME) == 0)
230 1.46 macallan return 100; /* beat genfb */
231 1.46 macallan return 0;
232 1.1 pk }
233 1.1 pk
234 1.1 pk /*
235 1.1 pk * Attach a display.
236 1.1 pk */
237 1.1 pk void
238 1.31 cegger tcxattach(device_t parent, device_t self, void *args)
239 1.1 pk {
240 1.25 drochner struct tcx_softc *sc = device_private(self);
241 1.1 pk struct sbus_attach_args *sa = args;
242 1.32 macallan struct wsemuldisplaydev_attach_args aa;
243 1.32 macallan struct rasops_info *ri;
244 1.32 macallan unsigned long defattr;
245 1.1 pk int node, ramsize;
246 1.1 pk struct fbdevice *fb = &sc->sc_fb;
247 1.1 pk bus_space_handle_t bh;
248 1.32 macallan int isconsole, i, j;
249 1.32 macallan uint32_t confreg;
250 1.1 pk
251 1.33 macallan sc->sc_dev = self;
252 1.1 pk sc->sc_bustag = sa->sa_bustag;
253 1.1 pk node = sa->sa_node;
254 1.1 pk
255 1.37 macallan sc->sc_cursor_x = 0x7fff;
256 1.37 macallan sc->sc_cursor_y = 0x7fff;
257 1.37 macallan sc->sc_hotspot_x = 0;
258 1.37 macallan sc->sc_hotspot_y = 0;
259 1.37 macallan
260 1.1 pk fb->fb_driver = &tcx_fbdriver;
261 1.33 macallan fb->fb_device = sc->sc_dev;
262 1.1 pk /* Mask out invalid flags from the user. */
263 1.33 macallan fb->fb_flags = device_cfdata(sc->sc_dev)->cf_flags & FB_USERMASK;
264 1.7 darrenr /*
265 1.7 darrenr * The onboard framebuffer on the SS4 supports only 8-bit mode;
266 1.7 darrenr * it can be distinguished from the S24 card for the SS5 by the
267 1.7 darrenr * presence of the "tcx-8-bit" attribute on the SS4 version.
268 1.7 darrenr */
269 1.7 darrenr sc->sc_8bit = node_has_property(node, "tcx-8-bit");
270 1.32 macallan fb->fb_type.fb_depth = 8;
271 1.32 macallan fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
272 1.32 macallan
273 1.7 darrenr if (sc->sc_8bit) {
274 1.47 jdc printf(" (8-bit only TCX)\n");
275 1.32 macallan ramsize = 1024 * 1024;
276 1.7 darrenr } else {
277 1.32 macallan printf(" (S24)\n");
278 1.32 macallan ramsize = 4 * 1024 * 1024;
279 1.7 darrenr }
280 1.32 macallan
281 1.1 pk fb->fb_type.fb_cmsize = 256;
282 1.1 pk fb->fb_type.fb_size = ramsize;
283 1.40 macallan printf("%s: %s, %d x %d", device_xname(self), OBPNAME,
284 1.1 pk fb->fb_type.fb_width,
285 1.1 pk fb->fb_type.fb_height);
286 1.1 pk
287 1.40 macallan fb->fb_type.fb_type = FBTYPE_TCXCOLOR;
288 1.1 pk
289 1.1 pk if (sa->sa_nreg != TCX_NREG) {
290 1.48 martin aprint_error("\n");
291 1.48 martin aprint_error_dev(self, "only %d register sets\n",
292 1.48 martin sa->sa_nreg);
293 1.48 martin return;
294 1.48 martin }
295 1.48 martin if (sa->sa_reg[TCX_REG_STIP].oa_size < 0x1000) {
296 1.48 martin aprint_error("\n");
297 1.48 martin aprint_error_dev(self, "STIP register too small (0x%x)\n",
298 1.48 martin sa->sa_reg[TCX_REG_STIP].oa_size);
299 1.1 pk return;
300 1.1 pk }
301 1.48 martin
302 1.34 macallan memcpy(sc->sc_physaddr, sa->sa_reg,
303 1.8 thorpej sa->sa_nreg * sizeof(struct openprom_addr));
304 1.1 pk
305 1.1 pk /* Map the register banks we care about */
306 1.1 pk if (sbus_bus_map(sa->sa_bustag,
307 1.34 macallan sc->sc_physaddr[TCX_REG_THC].oa_space,
308 1.34 macallan sc->sc_physaddr[TCX_REG_THC].oa_base,
309 1.32 macallan 0x1000,
310 1.32 macallan BUS_SPACE_MAP_LINEAR, &sc->sc_thc) != 0) {
311 1.1 pk printf("tcxattach: cannot map thc registers\n");
312 1.1 pk return;
313 1.1 pk }
314 1.1 pk
315 1.1 pk if (sbus_bus_map(sa->sa_bustag,
316 1.34 macallan sc->sc_physaddr[TCX_REG_CMAP].oa_space,
317 1.34 macallan sc->sc_physaddr[TCX_REG_CMAP].oa_base,
318 1.32 macallan 0x1000,
319 1.32 macallan BUS_SPACE_MAP_LINEAR, &sc->sc_bt) != 0) {
320 1.1 pk printf("tcxattach: cannot map bt registers\n");
321 1.1 pk return;
322 1.1 pk }
323 1.1 pk
324 1.32 macallan /* map the 8bit dumb FB for the console */
325 1.32 macallan if (sbus_bus_map(sa->sa_bustag,
326 1.34 macallan sc->sc_physaddr[TCX_REG_DFB8].oa_space,
327 1.34 macallan sc->sc_physaddr[TCX_REG_DFB8].oa_base,
328 1.32 macallan 1024 * 1024,
329 1.7 darrenr BUS_SPACE_MAP_LINEAR,
330 1.16 pk &bh) != 0) {
331 1.32 macallan printf("tcxattach: cannot map framebuffer\n");
332 1.32 macallan return;
333 1.32 macallan }
334 1.32 macallan sc->sc_fbaddr = bus_space_vaddr(sa->sa_bustag, bh);
335 1.32 macallan
336 1.32 macallan /* RBLIT space */
337 1.32 macallan if (sbus_bus_map(sa->sa_bustag,
338 1.34 macallan sc->sc_physaddr[TCX_REG_RBLIT].oa_space,
339 1.34 macallan sc->sc_physaddr[TCX_REG_RBLIT].oa_base,
340 1.32 macallan 8 * 1024 * 1024,
341 1.32 macallan BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
342 1.32 macallan &bh) != 0) {
343 1.32 macallan printf("tcxattach: cannot map RBLIT space\n");
344 1.32 macallan return;
345 1.32 macallan }
346 1.32 macallan sc->sc_rblit = bus_space_vaddr(sa->sa_bustag, bh);
347 1.32 macallan
348 1.32 macallan /* RSTIP space */
349 1.32 macallan if (sbus_bus_map(sa->sa_bustag,
350 1.34 macallan sc->sc_physaddr[TCX_REG_RSTIP].oa_space,
351 1.34 macallan sc->sc_physaddr[TCX_REG_RSTIP].oa_base,
352 1.32 macallan 8 * 1024 * 1024,
353 1.32 macallan BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
354 1.32 macallan &bh) != 0) {
355 1.32 macallan printf("tcxattach: cannot map RSTIP space\n");
356 1.32 macallan return;
357 1.7 darrenr }
358 1.32 macallan sc->sc_rstip = bus_space_vaddr(sa->sa_bustag, bh);
359 1.7 darrenr
360 1.1 pk isconsole = fb_is_console(node);
361 1.1 pk
362 1.32 macallan confreg = bus_space_read_4(sa->sa_bustag, sc->sc_thc, THC_CONFIG);
363 1.1 pk printf(", id %d, rev %d, sense %d",
364 1.32 macallan (confreg & THC_CFG_FBID) >> THC_CFG_FBID_SHIFT,
365 1.32 macallan (confreg & THC_CFG_REV) >> THC_CFG_REV_SHIFT,
366 1.32 macallan (confreg & THC_CFG_SENSE) >> THC_CFG_SENSE_SHIFT
367 1.1 pk );
368 1.1 pk
369 1.1 pk /* reset cursor & frame buffer controls */
370 1.1 pk tcx_reset(sc);
371 1.1 pk
372 1.1 pk /* Initialize the default color map. */
373 1.32 macallan j = 0;
374 1.32 macallan for (i = 0; i < 256; i++) {
375 1.32 macallan
376 1.32 macallan sc->sc_cmap_red[i] = rasops_cmap[j];
377 1.32 macallan sc->sc_cmap_green[i] = rasops_cmap[j + 1];
378 1.32 macallan sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
379 1.32 macallan j += 3;
380 1.32 macallan }
381 1.1 pk tcx_loadcmap(sc, 0, 256);
382 1.1 pk
383 1.37 macallan tcx_set_cursor(sc);
384 1.1 pk /* enable video */
385 1.32 macallan confreg = bus_space_read_4(sa->sa_bustag, sc->sc_thc, THC_MISC);
386 1.32 macallan confreg |= THC_MISC_VIDEN;
387 1.32 macallan bus_space_write_4(sa->sa_bustag, sc->sc_thc, THC_MISC, confreg);
388 1.1 pk
389 1.1 pk if (isconsole) {
390 1.1 pk printf(" (console)\n");
391 1.1 pk } else
392 1.1 pk printf("\n");
393 1.1 pk
394 1.1 pk fb_attach(&sc->sc_fb, isconsole);
395 1.32 macallan
396 1.32 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
397 1.32 macallan wsfont_init();
398 1.32 macallan
399 1.32 macallan vcons_init(&sc->vd, sc, &tcx_defscreendesc, &tcx_accessops);
400 1.32 macallan sc->vd.init_screen = tcx_init_screen;
401 1.32 macallan
402 1.32 macallan vcons_init_screen(&sc->vd, &tcx_console_screen, 1, &defattr);
403 1.32 macallan tcx_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
404 1.32 macallan
405 1.32 macallan sc->sc_bg = (defattr >> 16) & 0xff;
406 1.36 macallan tcx_clearscreen(sc, 0);
407 1.32 macallan
408 1.32 macallan ri = &tcx_console_screen.scr_ri;
409 1.32 macallan
410 1.32 macallan tcx_defscreendesc.nrows = ri->ri_rows;
411 1.32 macallan tcx_defscreendesc.ncols = ri->ri_cols;
412 1.32 macallan tcx_defscreendesc.textops = &ri->ri_ops;
413 1.32 macallan tcx_defscreendesc.capabilities = ri->ri_caps;
414 1.32 macallan
415 1.32 macallan if(isconsole) {
416 1.32 macallan wsdisplay_cnattach(&tcx_defscreendesc, ri, 0, 0, defattr);
417 1.39 macallan vcons_replay_msgbuf(&tcx_console_screen);
418 1.32 macallan }
419 1.32 macallan
420 1.32 macallan aa.console = isconsole;
421 1.32 macallan aa.scrdata = &tcx_screenlist;
422 1.32 macallan aa.accessops = &tcx_accessops;
423 1.32 macallan aa.accesscookie = &sc->vd;
424 1.32 macallan
425 1.32 macallan config_found(self, &aa, wsemuldisplaydevprint);
426 1.32 macallan /*
427 1.32 macallan * we need to do this again - something overwrites a handful
428 1.32 macallan * palette registers and we end up with white in reg. 0
429 1.32 macallan */
430 1.32 macallan tcx_loadcmap(sc, 0, 256);
431 1.1 pk }
432 1.1 pk
433 1.1 pk int
434 1.27 dsl tcxopen(dev_t dev, int flags, int mode, struct lwp *l)
435 1.1 pk {
436 1.1 pk return (0);
437 1.1 pk }
438 1.1 pk
439 1.1 pk int
440 1.27 dsl tcxclose(dev_t dev, int flags, int mode, struct lwp *l)
441 1.1 pk {
442 1.25 drochner struct tcx_softc *sc = device_lookup_private(&tcx_cd, minor(dev));
443 1.1 pk
444 1.1 pk tcx_reset(sc);
445 1.34 macallan /* we may want to clear and redraw the console here */
446 1.1 pk return (0);
447 1.1 pk }
448 1.1 pk
449 1.1 pk int
450 1.26 dsl tcxioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
451 1.1 pk {
452 1.25 drochner struct tcx_softc *sc = device_lookup_private(&tcx_cd, minor(dev));
453 1.1 pk
454 1.1 pk switch (cmd) {
455 1.1 pk
456 1.1 pk case FBIOGTYPE:
457 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
458 1.1 pk break;
459 1.1 pk
460 1.1 pk case FBIOGATTR:
461 1.1 pk #define fba ((struct fbgattr *)data)
462 1.1 pk fba->real_type = sc->sc_fb.fb_type.fb_type;
463 1.1 pk fba->owner = 0; /* XXX ??? */
464 1.1 pk fba->fbtype = sc->sc_fb.fb_type;
465 1.1 pk fba->sattr.flags = 0;
466 1.1 pk fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
467 1.1 pk fba->sattr.dev_specific[0] = -1;
468 1.1 pk fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
469 1.1 pk fba->emu_types[1] = FBTYPE_SUN3COLOR;
470 1.1 pk fba->emu_types[2] = -1;
471 1.1 pk #undef fba
472 1.1 pk break;
473 1.34 macallan
474 1.1 pk case FBIOGETCMAP:
475 1.1 pk #define p ((struct fbcmap *)data)
476 1.34 macallan if (copyout(&sc->sc_cmap_red[p->index], p->red, p->count) != 0)
477 1.34 macallan return EINVAL;
478 1.34 macallan if (copyout(&sc->sc_cmap_green[p->index], p->green, p->count)
479 1.34 macallan != 0)
480 1.34 macallan return EINVAL;
481 1.34 macallan if (copyout(&sc->sc_cmap_blue[p->index], p->blue, p->count)
482 1.34 macallan != 0)
483 1.34 macallan return EINVAL;
484 1.34 macallan return 0;
485 1.1 pk
486 1.1 pk case FBIOPUTCMAP:
487 1.1 pk /* copy to software map */
488 1.34 macallan if (copyin(p->red, &sc->sc_cmap_red[p->index], p->count) != 0)
489 1.34 macallan return EINVAL;
490 1.34 macallan if (copyin(p->green, &sc->sc_cmap_green[p->index], p->count)
491 1.34 macallan != 0)
492 1.34 macallan return EINVAL;
493 1.34 macallan if (copyin(p->blue, &sc->sc_cmap_blue[p->index], p->count) != 0)
494 1.34 macallan return EINVAL;
495 1.1 pk tcx_loadcmap(sc, p->index, p->count);
496 1.1 pk #undef p
497 1.1 pk break;
498 1.1 pk case FBIOGVIDEO:
499 1.1 pk *(int *)data = sc->sc_blanked;
500 1.1 pk break;
501 1.1 pk
502 1.1 pk case FBIOSVIDEO:
503 1.35 macallan tcx_set_video(sc, *(int *)data);
504 1.1 pk break;
505 1.1 pk
506 1.1 pk default:
507 1.1 pk #ifdef DEBUG
508 1.1 pk log(LOG_NOTICE, "tcxioctl(0x%lx) (%s[%d])\n", cmd,
509 1.20 jdc l->l_proc->p_comm, l->l_proc->p_pid);
510 1.1 pk #endif
511 1.1 pk return (ENOTTY);
512 1.1 pk }
513 1.1 pk return (0);
514 1.1 pk }
515 1.1 pk
516 1.1 pk /*
517 1.1 pk * Clean up hardware state (e.g., after bootup or after X crashes).
518 1.1 pk */
519 1.1 pk static void
520 1.26 dsl tcx_reset(struct tcx_softc *sc)
521 1.1 pk {
522 1.37 macallan uint32_t reg;
523 1.1 pk
524 1.37 macallan reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
525 1.37 macallan reg |= THC_MISC_CURSRES;
526 1.37 macallan bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
527 1.1 pk }
528 1.1 pk
529 1.1 pk static void
530 1.27 dsl tcx_loadcmap(struct tcx_softc *sc, int start, int ncolors)
531 1.1 pk {
532 1.32 macallan int i;
533 1.32 macallan
534 1.32 macallan for (i = 0; i < ncolors; i++) {
535 1.32 macallan bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_ADDRESS,
536 1.32 macallan (start + i) << 24);
537 1.32 macallan bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_FB_LUT,
538 1.32 macallan sc->sc_cmap_red[i + start] << 24);
539 1.32 macallan bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_FB_LUT,
540 1.32 macallan sc->sc_cmap_green[i + start] << 24);
541 1.32 macallan bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_FB_LUT,
542 1.32 macallan sc->sc_cmap_blue[i + start] << 24);
543 1.1 pk }
544 1.32 macallan bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_ADDRESS, 0);
545 1.1 pk }
546 1.1 pk
547 1.1 pk static void
548 1.31 cegger tcx_unblank(device_t dev)
549 1.1 pk {
550 1.25 drochner struct tcx_softc *sc = device_private(dev);
551 1.1 pk
552 1.1 pk if (sc->sc_blanked) {
553 1.34 macallan uint32_t reg;
554 1.1 pk sc->sc_blanked = 0;
555 1.34 macallan reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
556 1.34 macallan reg &= ~THC_MISC_VSYNC_DISABLE;
557 1.34 macallan reg &= ~THC_MISC_HSYNC_DISABLE;
558 1.34 macallan reg |= THC_MISC_VIDEN;
559 1.34 macallan bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
560 1.1 pk }
561 1.1 pk }
562 1.1 pk
563 1.35 macallan static void
564 1.35 macallan tcx_set_video(struct tcx_softc *sc, int unblank)
565 1.35 macallan {
566 1.35 macallan uint32_t reg;
567 1.35 macallan if (unblank) {
568 1.35 macallan sc->sc_blanked = 0;
569 1.35 macallan reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
570 1.35 macallan reg &= ~THC_MISC_VSYNC_DISABLE;
571 1.35 macallan reg &= ~THC_MISC_HSYNC_DISABLE;
572 1.35 macallan reg |= THC_MISC_VIDEN;
573 1.35 macallan bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
574 1.35 macallan } else {
575 1.35 macallan sc->sc_blanked = 1;
576 1.35 macallan reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
577 1.35 macallan reg |= THC_MISC_VSYNC_DISABLE;
578 1.35 macallan reg |= THC_MISC_HSYNC_DISABLE;
579 1.35 macallan reg &= ~THC_MISC_VIDEN;
580 1.35 macallan bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
581 1.35 macallan }
582 1.35 macallan }
583 1.35 macallan
584 1.1 pk /*
585 1.1 pk * Base addresses at which users can mmap() the various pieces of a tcx.
586 1.1 pk */
587 1.1 pk #define TCX_USER_RAM 0x00000000
588 1.1 pk #define TCX_USER_RAM24 0x01000000
589 1.1 pk #define TCX_USER_RAM_COMPAT 0x04000000 /* cg3 emulation */
590 1.1 pk #define TCX_USER_STIP 0x10000000
591 1.1 pk #define TCX_USER_BLIT 0x20000000
592 1.1 pk #define TCX_USER_RDFB32 0x28000000
593 1.1 pk #define TCX_USER_RSTIP 0x30000000
594 1.1 pk #define TCX_USER_RBLIT 0x38000000
595 1.1 pk #define TCX_USER_TEC 0x70001000
596 1.1 pk #define TCX_USER_BTREGS 0x70002000
597 1.1 pk #define TCX_USER_THC 0x70004000
598 1.1 pk #define TCX_USER_DHC 0x70008000
599 1.1 pk #define TCX_USER_ALT 0x7000a000
600 1.1 pk #define TCX_USER_UART 0x7000c000
601 1.1 pk #define TCX_USER_VRT 0x7000e000
602 1.1 pk #define TCX_USER_ROM 0x70010000
603 1.1 pk
604 1.1 pk struct mmo {
605 1.1 pk u_int mo_uaddr; /* user (virtual) address */
606 1.1 pk u_int mo_size; /* size, or 0 for video ram size */
607 1.1 pk u_int mo_bank; /* register bank number */
608 1.1 pk };
609 1.1 pk
610 1.1 pk /*
611 1.1 pk * Return the address that would map the given device at the given
612 1.1 pk * offset, allowing for the given protection, or return -1 for error.
613 1.1 pk *
614 1.1 pk * XXX needs testing against `demanding' applications (e.g., aviator)
615 1.1 pk */
616 1.1 pk paddr_t
617 1.26 dsl tcxmmap(dev_t dev, off_t off, int prot)
618 1.1 pk {
619 1.25 drochner struct tcx_softc *sc = device_lookup_private(&tcx_cd, minor(dev));
620 1.34 macallan struct openprom_addr *rr = sc->sc_physaddr;
621 1.7 darrenr struct mmo *mo, *mo_end;
622 1.1 pk u_int u, sz;
623 1.1 pk static struct mmo mmo[] = {
624 1.1 pk { TCX_USER_RAM, 0, TCX_REG_DFB8 },
625 1.1 pk { TCX_USER_RAM24, 0, TCX_REG_DFB24 },
626 1.1 pk { TCX_USER_RAM_COMPAT, 0, TCX_REG_DFB8 },
627 1.1 pk
628 1.1 pk { TCX_USER_STIP, 1, TCX_REG_STIP },
629 1.1 pk { TCX_USER_BLIT, 1, TCX_REG_BLIT },
630 1.7 darrenr { TCX_USER_RDFB32, 0, TCX_REG_RDFB32 },
631 1.1 pk { TCX_USER_RSTIP, 1, TCX_REG_RSTIP },
632 1.1 pk { TCX_USER_RBLIT, 1, TCX_REG_RBLIT },
633 1.1 pk { TCX_USER_TEC, 1, TCX_REG_TEC },
634 1.1 pk { TCX_USER_BTREGS, 8192 /* XXX */, TCX_REG_CMAP },
635 1.40 macallan { TCX_USER_THC, 0x2000, TCX_REG_THC },
636 1.1 pk { TCX_USER_DHC, 1, TCX_REG_DHC },
637 1.1 pk { TCX_USER_ALT, 1, TCX_REG_ALT },
638 1.1 pk { TCX_USER_ROM, 65536, TCX_REG_ROM },
639 1.1 pk };
640 1.1 pk #define NMMO (sizeof mmo / sizeof *mmo)
641 1.1 pk
642 1.1 pk if (off & PGOFSET)
643 1.1 pk panic("tcxmmap");
644 1.1 pk
645 1.1 pk /*
646 1.1 pk * Entries with size 0 map video RAM (i.e., the size in fb data).
647 1.7 darrenr * Entries that map 32-bit deep regions are adjusted for their
648 1.7 darrenr * depth (fb_size gives the size of the 8-bit-deep region).
649 1.1 pk *
650 1.1 pk * Since we work in pages, the fact that the map offset table's
651 1.1 pk * sizes are sometimes bizarre (e.g., 1) is effectively ignored:
652 1.1 pk * one byte is as good as one page.
653 1.1 pk */
654 1.34 macallan
655 1.7 darrenr mo = mmo;
656 1.7 darrenr mo_end = &mmo[NMMO];
657 1.34 macallan
658 1.7 darrenr for (; mo < mo_end; mo++) {
659 1.1 pk if ((u_int)off < mo->mo_uaddr)
660 1.1 pk continue;
661 1.40 macallan
662 1.1 pk u = off - mo->mo_uaddr;
663 1.7 darrenr sz = mo->mo_size;
664 1.40 macallan
665 1.7 darrenr if (sz == 0) {
666 1.7 darrenr sz = sc->sc_fb.fb_type.fb_size;
667 1.7 darrenr /*
668 1.7 darrenr * check for the 32-bit-deep regions and adjust
669 1.7 darrenr * accordingly
670 1.7 darrenr */
671 1.7 darrenr if (mo->mo_uaddr == TCX_USER_RAM24 ||
672 1.7 darrenr mo->mo_uaddr == TCX_USER_RDFB32) {
673 1.7 darrenr if (sc->sc_8bit) {
674 1.7 darrenr /*
675 1.7 darrenr * not present on 8-bit hardware
676 1.7 darrenr */
677 1.7 darrenr continue;
678 1.7 darrenr }
679 1.7 darrenr sz *= 4;
680 1.7 darrenr }
681 1.7 darrenr }
682 1.40 macallan if (sz == 1)
683 1.40 macallan sz = rr[mo->mo_bank].oa_size;
684 1.40 macallan
685 1.1 pk if (u < sz) {
686 1.3 eeh return (bus_space_mmap(sc->sc_bustag,
687 1.8 thorpej BUS_ADDR(rr[mo->mo_bank].oa_space,
688 1.8 thorpej rr[mo->mo_bank].oa_base),
689 1.3 eeh u,
690 1.3 eeh prot,
691 1.3 eeh BUS_SPACE_MAP_LINEAR));
692 1.1 pk }
693 1.1 pk }
694 1.3 eeh return (-1);
695 1.1 pk }
696 1.32 macallan
697 1.32 macallan int
698 1.32 macallan tcx_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
699 1.32 macallan struct lwp *l)
700 1.32 macallan {
701 1.32 macallan struct vcons_data *vd = v;
702 1.32 macallan struct tcx_softc *sc = vd->cookie;
703 1.32 macallan struct wsdisplay_fbinfo *wdf;
704 1.32 macallan struct vcons_screen *ms = vd->active;
705 1.32 macallan
706 1.32 macallan switch (cmd) {
707 1.32 macallan case WSDISPLAYIO_GTYPE:
708 1.32 macallan *(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
709 1.32 macallan return 0;
710 1.32 macallan
711 1.32 macallan case FBIOGVIDEO:
712 1.32 macallan case WSDISPLAYIO_GVIDEO:
713 1.35 macallan *(int *)data = !sc->sc_blanked;
714 1.32 macallan return 0;
715 1.32 macallan
716 1.32 macallan case WSDISPLAYIO_SVIDEO:
717 1.32 macallan case FBIOSVIDEO:
718 1.32 macallan tcx_set_video(sc, *(int *)data);
719 1.32 macallan return 0;
720 1.35 macallan
721 1.32 macallan case WSDISPLAYIO_GINFO:
722 1.32 macallan wdf = (void *)data;
723 1.32 macallan wdf->height = ms->scr_ri.ri_height;
724 1.32 macallan wdf->width = ms->scr_ri.ri_width;
725 1.34 macallan if (sc->sc_8bit) {
726 1.34 macallan wdf->depth = 8;
727 1.34 macallan } else {
728 1.34 macallan wdf->depth = 32;
729 1.34 macallan }
730 1.32 macallan wdf->cmsize = 256;
731 1.32 macallan return 0;
732 1.34 macallan case WSDISPLAYIO_LINEBYTES:
733 1.34 macallan {
734 1.34 macallan int *ret = (int *)data;
735 1.34 macallan *ret = sc->sc_8bit ? ms->scr_ri.ri_width :
736 1.34 macallan ms->scr_ri.ri_width << 2;
737 1.34 macallan }
738 1.34 macallan return 0;
739 1.32 macallan #if 0
740 1.32 macallan case WSDISPLAYIO_GETCMAP:
741 1.32 macallan return tcx_getcmap(sc, (struct wsdisplay_cmap *)data);
742 1.32 macallan
743 1.32 macallan case WSDISPLAYIO_PUTCMAP:
744 1.32 macallan return tcx_putcmap(sc, (struct wsdisplay_cmap *)data);
745 1.32 macallan #endif
746 1.32 macallan case WSDISPLAYIO_SMODE:
747 1.32 macallan {
748 1.32 macallan int new_mode = *(int*)data;
749 1.32 macallan if (new_mode != sc->sc_mode)
750 1.32 macallan {
751 1.32 macallan sc->sc_mode = new_mode;
752 1.32 macallan if (new_mode == WSDISPLAYIO_MODE_EMUL)
753 1.32 macallan {
754 1.34 macallan tcx_loadcmap(sc, 0, 256);
755 1.36 macallan tcx_clearscreen(sc, 0);
756 1.32 macallan vcons_redraw_screen(ms);
757 1.36 macallan } else if (!sc->sc_8bit)
758 1.36 macallan tcx_clearscreen(sc, 3);
759 1.32 macallan }
760 1.32 macallan }
761 1.37 macallan case WSDISPLAYIO_GCURPOS:
762 1.37 macallan {
763 1.37 macallan struct wsdisplay_curpos *cp = (void *)data;
764 1.37 macallan
765 1.37 macallan cp->x = sc->sc_cursor_x;
766 1.37 macallan cp->y = sc->sc_cursor_y;
767 1.37 macallan }
768 1.37 macallan return 0;
769 1.37 macallan
770 1.37 macallan case WSDISPLAYIO_SCURPOS:
771 1.37 macallan {
772 1.37 macallan struct wsdisplay_curpos *cp = (void *)data;
773 1.37 macallan
774 1.37 macallan sc->sc_cursor_x = cp->x;
775 1.37 macallan sc->sc_cursor_y = cp->y;
776 1.37 macallan tcx_set_cursor(sc);
777 1.37 macallan }
778 1.37 macallan return 0;
779 1.37 macallan
780 1.37 macallan case WSDISPLAYIO_GCURMAX:
781 1.37 macallan {
782 1.37 macallan struct wsdisplay_curpos *cp = (void *)data;
783 1.37 macallan
784 1.37 macallan cp->x = 32;
785 1.37 macallan cp->y = 32;
786 1.37 macallan }
787 1.37 macallan return 0;
788 1.37 macallan
789 1.37 macallan case WSDISPLAYIO_SCURSOR:
790 1.37 macallan {
791 1.37 macallan struct wsdisplay_cursor *cursor = (void *)data;
792 1.37 macallan
793 1.37 macallan return tcx_do_cursor(sc, cursor);
794 1.37 macallan }
795 1.32 macallan }
796 1.32 macallan return EPASSTHROUGH;
797 1.32 macallan }
798 1.32 macallan
799 1.32 macallan static paddr_t
800 1.32 macallan tcx_mmap(void *v, void *vs, off_t offset, int prot)
801 1.32 macallan {
802 1.32 macallan struct vcons_data *vd = v;
803 1.32 macallan struct tcx_softc *sc = vd->cookie;
804 1.32 macallan
805 1.32 macallan /* 'regular' framebuffer mmap()ing */
806 1.34 macallan if (sc->sc_8bit) {
807 1.34 macallan /* on 8Bit boards hand over the 8 bit aperture */
808 1.34 macallan if (offset > 1024 * 1024)
809 1.34 macallan return -1;
810 1.34 macallan return bus_space_mmap(sc->sc_bustag,
811 1.34 macallan sc->sc_physaddr[TCX_REG_DFB8].oa_base + offset, 0, prot,
812 1.32 macallan BUS_SPACE_MAP_LINEAR);
813 1.34 macallan } else {
814 1.34 macallan /* ... but if we have a 24bit aperture we use it */
815 1.34 macallan if (offset > 1024 * 1024 * 4)
816 1.34 macallan return -1;
817 1.34 macallan return bus_space_mmap(sc->sc_bustag,
818 1.34 macallan sc->sc_physaddr[TCX_REG_DFB24].oa_base + offset, 0, prot,
819 1.32 macallan BUS_SPACE_MAP_LINEAR);
820 1.32 macallan }
821 1.32 macallan return -1;
822 1.32 macallan }
823 1.32 macallan
824 1.32 macallan static void
825 1.32 macallan tcx_init_screen(void *cookie, struct vcons_screen *scr,
826 1.32 macallan int existing, long *defattr)
827 1.32 macallan {
828 1.32 macallan struct tcx_softc *sc = cookie;
829 1.32 macallan struct rasops_info *ri = &scr->scr_ri;
830 1.32 macallan
831 1.32 macallan ri->ri_depth = 8;
832 1.32 macallan ri->ri_width = sc->sc_fb.fb_type.fb_width;
833 1.32 macallan ri->ri_height = sc->sc_fb.fb_type.fb_height;
834 1.32 macallan ri->ri_stride = sc->sc_fb.fb_linebytes;
835 1.32 macallan ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
836 1.32 macallan
837 1.32 macallan ri->ri_bits = sc->sc_fbaddr;
838 1.32 macallan
839 1.44 macallan rasops_init(ri, 0, 0);
840 1.32 macallan ri->ri_caps = WSSCREEN_WSCOLORS;
841 1.32 macallan rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
842 1.32 macallan ri->ri_width / ri->ri_font->fontwidth);
843 1.32 macallan
844 1.32 macallan /* enable acceleration */
845 1.32 macallan ri->ri_ops.copyrows = tcx_copyrows;
846 1.32 macallan ri->ri_ops.eraserows = tcx_eraserows;
847 1.32 macallan ri->ri_ops.putchar = tcx_putchar;
848 1.32 macallan #if 0
849 1.32 macallan ri->ri_ops.cursor = tcx_cursor;
850 1.32 macallan ri->ri_ops.copycols = tcx_copycols;
851 1.32 macallan ri->ri_ops.erasecols = tcx_erasecols;
852 1.32 macallan #endif
853 1.32 macallan }
854 1.32 macallan
855 1.32 macallan static void
856 1.36 macallan tcx_clearscreen(struct tcx_softc *sc, int spc)
857 1.32 macallan {
858 1.32 macallan uint64_t bg = ((uint64_t)sc->sc_bg << 32) | 0xffffffffLL;
859 1.36 macallan uint64_t spc64;
860 1.32 macallan int i;
861 1.32 macallan
862 1.36 macallan spc64 = spc & 3;
863 1.36 macallan spc64 = spc64 << 56;
864 1.36 macallan
865 1.32 macallan for (i = 0; i < 1024 * 1024; i += 32)
866 1.36 macallan sc->sc_rstip[i] = bg | spc64;
867 1.32 macallan }
868 1.32 macallan
869 1.32 macallan static void
870 1.32 macallan tcx_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
871 1.32 macallan {
872 1.32 macallan struct rasops_info *ri = cookie;
873 1.32 macallan struct vcons_screen *scr = ri->ri_hw;
874 1.32 macallan struct tcx_softc *sc = scr->scr_cookie;
875 1.32 macallan int i, last, first, len, dest, leftover;
876 1.32 macallan
877 1.32 macallan i = ri->ri_width * ri->ri_font->fontheight * nrows;
878 1.32 macallan len = i & 0xffffe0;
879 1.32 macallan leftover = i & 0x1f;
880 1.32 macallan if (srcrow < dstrow) {
881 1.32 macallan /* we must go bottom to top */
882 1.32 macallan first = ri->ri_width *
883 1.32 macallan (ri->ri_font->fontheight * srcrow + ri->ri_yorigin);
884 1.32 macallan last = first + len;
885 1.32 macallan dest = ri->ri_width *
886 1.32 macallan (ri->ri_font->fontheight * dstrow + ri->ri_yorigin) + len;
887 1.32 macallan if (leftover > 0) {
888 1.32 macallan sc->sc_rblit[dest + 32] =
889 1.32 macallan (uint64_t)((leftover - 1) << 24) |
890 1.32 macallan (uint64_t)(i + 32);
891 1.32 macallan }
892 1.32 macallan for (i = last; i >= first; i -= 32) {
893 1.32 macallan sc->sc_rblit[dest] = 0x300000001f000000LL | (uint64_t)i;
894 1.32 macallan dest -= 32;
895 1.32 macallan }
896 1.32 macallan } else {
897 1.32 macallan /* top to bottom */
898 1.32 macallan first = ri->ri_width *
899 1.32 macallan (ri->ri_font->fontheight * srcrow + ri->ri_yorigin);
900 1.32 macallan dest = ri->ri_width *
901 1.32 macallan (ri->ri_font->fontheight * dstrow + ri->ri_yorigin);
902 1.32 macallan last = first + len;
903 1.32 macallan for (i = first; i <= last; i+= 32) {
904 1.32 macallan sc->sc_rblit[dest] = 0x300000001f000000LL | (uint64_t)i;
905 1.32 macallan dest += 32;
906 1.32 macallan }
907 1.32 macallan if (leftover > 0) {
908 1.32 macallan sc->sc_rblit[dest] =
909 1.32 macallan (uint64_t)((leftover - 1) << 24) | (uint64_t)i;
910 1.32 macallan }
911 1.32 macallan }
912 1.32 macallan }
913 1.32 macallan
914 1.32 macallan static void
915 1.32 macallan tcx_eraserows(void *cookie, int start, int nrows, long attr)
916 1.32 macallan {
917 1.32 macallan struct rasops_info *ri = cookie;
918 1.32 macallan struct vcons_screen *scr = ri->ri_hw;
919 1.32 macallan struct tcx_softc *sc = scr->scr_cookie;
920 1.32 macallan uint64_t temp;
921 1.32 macallan int i, last, first, len, leftover;
922 1.32 macallan
923 1.32 macallan i = ri->ri_width * ri->ri_font->fontheight * nrows;
924 1.32 macallan len = i & 0xffffe0;
925 1.32 macallan leftover = i & 0x1f;
926 1.32 macallan first = ri->ri_width *
927 1.32 macallan (ri->ri_font->fontheight * start + ri->ri_yorigin);
928 1.32 macallan last = first + len;
929 1.32 macallan temp = 0x30000000ffffffffLL |
930 1.32 macallan ((uint64_t)ri->ri_devcmap[(attr >> 16) & 0xff] << 32);
931 1.32 macallan
932 1.32 macallan for (i = first; i <= last; i+= 32)
933 1.32 macallan sc->sc_rblit[i] = temp;
934 1.32 macallan
935 1.32 macallan if (leftover > 0) {
936 1.32 macallan temp &= 0xffffffffffffffffLL << (32 - leftover);
937 1.32 macallan sc->sc_rblit[i] = temp;
938 1.32 macallan }
939 1.32 macallan }
940 1.32 macallan /*
941 1.32 macallan * The stipple engine is 100% retarded. All drawing operations have to start
942 1.32 macallan * at 32 pixel boundaries so we'll have to deal with characters being split.
943 1.32 macallan */
944 1.32 macallan
945 1.32 macallan static void
946 1.32 macallan tcx_putchar(void *cookie, int row, int col, u_int c, long attr)
947 1.32 macallan {
948 1.32 macallan struct rasops_info *ri = cookie;
949 1.43 macallan struct wsdisplay_font *font = PICK_FONT(ri, c);
950 1.32 macallan struct vcons_screen *scr = ri->ri_hw;
951 1.32 macallan struct tcx_softc *sc = scr->scr_cookie;
952 1.32 macallan uint64_t bg, fg, temp, mask;
953 1.32 macallan int addr, i, uc, shift;
954 1.32 macallan uint32_t fmask;
955 1.32 macallan uint8_t *cdata;
956 1.32 macallan uint16_t *wdata;
957 1.32 macallan
958 1.43 macallan addr = ri->ri_xorigin + col * font->fontwidth +
959 1.43 macallan (ri->ri_yorigin + row * font->fontheight) * ri->ri_width;
960 1.32 macallan
961 1.32 macallan /* check if the character is crossing a 32 pixel boundary */
962 1.32 macallan if ((addr & 0xffffe0) ==
963 1.43 macallan ((addr + font->fontwidth - 1) & 0xffffe0)) {
964 1.32 macallan /* phew, not split */
965 1.32 macallan shift = addr & 0x1f;
966 1.32 macallan addr &= 0xffffe0;
967 1.43 macallan fmask = 0xffffffff >> (32 - font->fontwidth);
968 1.43 macallan fmask = fmask << (32 - font->fontwidth - shift);
969 1.32 macallan mask = fmask;
970 1.32 macallan bg = 0x3000000000000000LL |
971 1.32 macallan ((uint64_t)ri->ri_devcmap[(attr >> 16) & 0xff] &
972 1.32 macallan 0xff) << 32;
973 1.32 macallan bg |= mask;
974 1.32 macallan temp = 0x3000000000000000LL |
975 1.32 macallan ((uint64_t)ri->ri_devcmap[(attr >> 24) & 0xff] & 0xff) <<
976 1.32 macallan 32;
977 1.43 macallan uc = c - font->firstchar;
978 1.43 macallan cdata = (uint8_t *)font->data + uc * ri->ri_fontscale;
979 1.32 macallan
980 1.43 macallan if (font->fontwidth < 9) {
981 1.32 macallan /* byte by byte */
982 1.43 macallan for (i = 0; i < font->fontheight; i++) {
983 1.32 macallan sc->sc_rstip[addr] = bg;
984 1.32 macallan if (*cdata != 0) {
985 1.32 macallan if (shift > 24) {
986 1.32 macallan fg = (uint64_t)*cdata >>
987 1.32 macallan (shift - 24);
988 1.32 macallan } else {
989 1.32 macallan fg = (uint64_t)*cdata <<
990 1.32 macallan (24 - shift);
991 1.32 macallan }
992 1.32 macallan sc->sc_rstip[addr] = fg | temp;
993 1.32 macallan }
994 1.32 macallan cdata++;
995 1.32 macallan addr += ri->ri_width;
996 1.32 macallan }
997 1.43 macallan } else if (font->fontwidth < 17) {
998 1.32 macallan /* short by short */
999 1.32 macallan wdata = (uint16_t *)cdata;
1000 1.43 macallan for (i = 0; i < font->fontheight; i++) {
1001 1.32 macallan sc->sc_rstip[addr] = bg;
1002 1.32 macallan if (*wdata != 0) {
1003 1.32 macallan if (shift > 16) {
1004 1.32 macallan fg = temp | (uint64_t)*wdata >>
1005 1.32 macallan (shift - 16);
1006 1.32 macallan } else {
1007 1.32 macallan fg = temp | (uint64_t)*wdata <<
1008 1.32 macallan (16 - shift);
1009 1.32 macallan }
1010 1.32 macallan sc->sc_rstip[addr] = fg;
1011 1.32 macallan }
1012 1.32 macallan wdata++;
1013 1.32 macallan addr += ri->ri_width;
1014 1.32 macallan }
1015 1.32 macallan }
1016 1.32 macallan } else {
1017 1.32 macallan /* and now the split case ( man this hardware is dumb ) */
1018 1.32 macallan uint64_t bgr, maskr, fgr;
1019 1.32 macallan uint32_t bork;
1020 1.32 macallan
1021 1.32 macallan shift = addr & 0x1f;
1022 1.32 macallan addr &= 0xffffe0;
1023 1.32 macallan mask = 0xffffffff >> shift;
1024 1.32 macallan maskr = (uint64_t)(0xffffffffUL <<
1025 1.43 macallan (32 - (font->fontwidth + shift - 32)));
1026 1.32 macallan bg = 0x3000000000000000LL |
1027 1.32 macallan ((uint64_t)ri->ri_devcmap[(attr >> 16) & 0xff] &
1028 1.32 macallan 0xff) << 32;
1029 1.32 macallan bgr = bg | maskr;
1030 1.32 macallan bg |= mask;
1031 1.32 macallan temp = 0x3000000000000000LL |
1032 1.32 macallan ((uint64_t)ri->ri_devcmap[(attr >> 24) & 0xff] & 0xff) <<
1033 1.32 macallan 32;
1034 1.32 macallan
1035 1.43 macallan uc = c - font->firstchar;
1036 1.43 macallan cdata = (uint8_t *)font->data + uc * ri->ri_fontscale;
1037 1.32 macallan
1038 1.43 macallan if (font->fontwidth < 9) {
1039 1.32 macallan /* byte by byte */
1040 1.43 macallan for (i = 0; i < font->fontheight; i++) {
1041 1.32 macallan sc->sc_rstip[addr] = bg;
1042 1.32 macallan sc->sc_rstip[addr + 32] = bgr;
1043 1.32 macallan bork = *cdata;
1044 1.32 macallan if (bork != 0) {
1045 1.32 macallan fg = (uint64_t)bork >> (shift - 24);
1046 1.32 macallan sc->sc_rstip[addr] = fg | temp;
1047 1.32 macallan fgr = (uint64_t)(bork << (52 - shift));
1048 1.32 macallan sc->sc_rstip[addr] = fgr | temp;
1049 1.32 macallan }
1050 1.32 macallan cdata++;
1051 1.32 macallan addr += ri->ri_width;
1052 1.32 macallan }
1053 1.43 macallan } else if (font->fontwidth < 17) {
1054 1.32 macallan /* short by short */
1055 1.32 macallan wdata = (uint16_t *)cdata;
1056 1.43 macallan for (i = 0; i < font->fontheight; i++) {
1057 1.32 macallan sc->sc_rstip[addr] = bg;
1058 1.32 macallan sc->sc_rstip[addr + 32] = bgr;
1059 1.32 macallan bork = *wdata;
1060 1.32 macallan if (bork != 0) {
1061 1.32 macallan fg = (uint64_t)bork >> (shift - 16);
1062 1.32 macallan sc->sc_rstip[addr] = fg | temp;
1063 1.32 macallan fgr = (uint64_t)(bork << (48 - shift));
1064 1.32 macallan sc->sc_rstip[addr + 32] = fgr | temp;
1065 1.32 macallan }
1066 1.32 macallan wdata++;
1067 1.32 macallan addr += ri->ri_width;
1068 1.32 macallan }
1069 1.32 macallan }
1070 1.32 macallan
1071 1.32 macallan }
1072 1.32 macallan }
1073 1.32 macallan
1074 1.37 macallan static int
1075 1.37 macallan tcx_do_cursor(struct tcx_softc *sc, struct wsdisplay_cursor *cur)
1076 1.37 macallan {
1077 1.37 macallan if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
1078 1.37 macallan
1079 1.37 macallan if (cur->enable) {
1080 1.37 macallan tcx_set_cursor(sc);
1081 1.37 macallan } else {
1082 1.37 macallan /* move the cursor out of sight */
1083 1.37 macallan bus_space_write_4(sc->sc_bustag, sc->sc_thc,
1084 1.37 macallan THC_CURSOR_POS, 0x7fff7fff);
1085 1.37 macallan }
1086 1.37 macallan }
1087 1.37 macallan if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
1088 1.37 macallan
1089 1.37 macallan sc->sc_hotspot_x = cur->hot.x;
1090 1.37 macallan sc->sc_hotspot_y = cur->hot.y;
1091 1.37 macallan tcx_set_cursor(sc);
1092 1.37 macallan }
1093 1.37 macallan if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
1094 1.37 macallan
1095 1.37 macallan sc->sc_cursor_x = cur->pos.x;
1096 1.37 macallan sc->sc_cursor_y = cur->pos.y;
1097 1.37 macallan tcx_set_cursor(sc);
1098 1.37 macallan }
1099 1.37 macallan if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
1100 1.37 macallan #if 0
1101 1.38 macallan /*
1102 1.38 macallan * apparently we're not writing in the right register here - if we do
1103 1.38 macallan * this the screen goes all funky
1104 1.38 macallan */
1105 1.37 macallan int i;
1106 1.37 macallan
1107 1.37 macallan for (i = 0; i < cur->cmap.count; i++) {
1108 1.37 macallan bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_ADDRESS,
1109 1.37 macallan (cur->cmap.index + i + 2) << 24);
1110 1.37 macallan bus_space_write_4(sc->sc_bustag, sc->sc_bt,
1111 1.37 macallan DAC_CURSOR_LUT, cur->cmap.red[i] << 24);
1112 1.37 macallan bus_space_write_4(sc->sc_bustag, sc->sc_bt,
1113 1.37 macallan DAC_CURSOR_LUT, cur->cmap.green[i] << 24);
1114 1.37 macallan bus_space_write_4(sc->sc_bustag, sc->sc_bt,
1115 1.37 macallan DAC_CURSOR_LUT, cur->cmap.blue[i] << 24);
1116 1.37 macallan }
1117 1.37 macallan #endif
1118 1.37 macallan }
1119 1.37 macallan if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
1120 1.37 macallan int i;
1121 1.37 macallan uint32_t temp, poof;
1122 1.37 macallan
1123 1.37 macallan for (i = 0; i < 128; i += 4) {
1124 1.37 macallan memcpy(&temp, &cur->mask[i], 4);
1125 1.37 macallan printf("%08x -> ", temp);
1126 1.37 macallan poof = ((temp & 0x80808080) >> 7) |
1127 1.37 macallan ((temp & 0x40404040) >> 5) |
1128 1.37 macallan ((temp & 0x20202020) >> 3) |
1129 1.37 macallan ((temp & 0x10101010) >> 1) |
1130 1.37 macallan ((temp & 0x08080808) << 1) |
1131 1.37 macallan ((temp & 0x04040404) << 3) |
1132 1.37 macallan ((temp & 0x02020202) << 5) |
1133 1.37 macallan ((temp & 0x01010101) << 7);
1134 1.37 macallan printf("%08x\n", poof);
1135 1.37 macallan bus_space_write_4(sc->sc_bustag, sc->sc_thc,
1136 1.37 macallan THC_CURSOR_1 + i, poof);
1137 1.37 macallan memcpy(&temp, &cur->image[i], 4);
1138 1.37 macallan poof = ((temp & 0x80808080) >> 7) |
1139 1.37 macallan ((temp & 0x40404040) >> 5) |
1140 1.37 macallan ((temp & 0x20202020) >> 3) |
1141 1.37 macallan ((temp & 0x10101010) >> 1) |
1142 1.37 macallan ((temp & 0x08080808) << 1) |
1143 1.37 macallan ((temp & 0x04040404) << 3) |
1144 1.37 macallan ((temp & 0x02020202) << 5) |
1145 1.37 macallan ((temp & 0x01010101) << 7);
1146 1.37 macallan bus_space_write_4(sc->sc_bustag, sc->sc_thc,
1147 1.37 macallan THC_CURSOR_0 + i, poof);
1148 1.37 macallan }
1149 1.37 macallan }
1150 1.37 macallan return 0;
1151 1.37 macallan }
1152 1.37 macallan
1153 1.37 macallan static void
1154 1.37 macallan tcx_set_cursor(struct tcx_softc *sc)
1155 1.37 macallan {
1156 1.37 macallan uint32_t reg;
1157 1.37 macallan
1158 1.37 macallan reg = (sc->sc_cursor_x - sc->sc_hotspot_x) << 16 |
1159 1.37 macallan ((sc->sc_cursor_y - sc->sc_hotspot_y) & 0xffff);
1160 1.37 macallan bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_CURSOR_POS, reg);
1161 1.37 macallan }
1162 1.37 macallan
1163