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