xref: /netbsd-src/sys/dev/pci/wcfb.c (revision 5bbd2a12505d72a8177929a37b5cee489d0a1cfd)
1 /*	$NetBSD: wcfb.c,v 1.11 2012/03/13 18:40:34 elad Exp $ */
2 
3 /*-
4  * Copyright (c) 2010 Michael Lorenz
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: wcfb.c,v 1.11 2012/03/13 18:40:34 elad Exp $");
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/device.h>
36 #include <sys/proc.h>
37 #include <sys/mutex.h>
38 #include <sys/ioctl.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
41 #include <sys/kauth.h>
42 #include <sys/kmem.h>
43 
44 #include <dev/pci/pcidevs.h>
45 #include <dev/pci/pcireg.h>
46 #include <dev/pci/pcivar.h>
47 #include <dev/pci/pciio.h>
48 #include <dev/pci/wcfbreg.h>
49 
50 #include <dev/wscons/wsdisplayvar.h>
51 #include <dev/wscons/wsconsio.h>
52 #include <dev/wsfont/wsfont.h>
53 #include <dev/rasops/rasops.h>
54 #include <dev/wscons/wsdisplay_vconsvar.h>
55 #include <dev/pci/wsdisplay_pci.h>
56 
57 #include "opt_wsfb.h"
58 #include "opt_wsdisplay_compat.h"
59 
60 #ifdef WCFB_DEBUG
61 # define DPRINTF printf
62 #else
63 # define DPRINTF while (0) printf
64 #endif
65 
66 static int	wcfb_match(device_t, cfdata_t, void *);
67 static void	wcfb_attach(device_t, device_t, void *);
68 static int	wcfb_ioctl(void *, void *, u_long, void *, int,
69 		    struct lwp *);
70 static paddr_t	wcfb_mmap(void *, void *, off_t, int);
71 
72 struct wcfb_softc {
73 	device_t sc_dev;
74 
75 	pci_chipset_tag_t sc_pc;
76 	pcitag_t sc_pcitag;
77 
78 	bus_space_tag_t sc_memt;
79 	bus_space_tag_t sc_regt, sc_wtft;
80 	bus_space_tag_t sc_iot;
81 
82 	bus_space_handle_t sc_fbh, sc_wtfh;
83 	bus_space_handle_t sc_regh;
84 	bus_addr_t sc_fb, sc_reg, sc_wtf;
85 	bus_size_t sc_fbsize, sc_regsize, sc_wtfsize;
86 
87 	int sc_width, sc_height, sc_stride;
88 	int sc_locked;
89 	uint8_t *sc_fbaddr, *sc_fb0, *sc_fb1, *sc_shadow;
90 	struct vcons_screen sc_console_screen;
91 	struct wsscreen_descr sc_defaultscreen_descr;
92 	const struct wsscreen_descr *sc_screens[1];
93 	struct wsscreen_list sc_screenlist;
94 	struct vcons_data vd;
95 	int sc_mode;
96 	u_char sc_cmap_red[256];
97 	u_char sc_cmap_green[256];
98 	u_char sc_cmap_blue[256];
99 	uint32_t sc_fb0off, sc_fb1off;
100 
101 	void (*copycols)(void *, int, int, int, int);
102 	void (*erasecols)(void *, int, int, int, long);
103 	void (*copyrows)(void *, int, int, int);
104 	void (*eraserows)(void *, int, int, long);
105 	void (*putchar)(void *, int, int, u_int, long);
106 	void (*cursor)(void *, int, int, int);
107 
108 };
109 
110 static void	wcfb_init_screen(void *, struct vcons_screen *, int, long *);
111 
112 CFATTACH_DECL_NEW(wcfb, sizeof(struct wcfb_softc),
113     wcfb_match, wcfb_attach, NULL, NULL);
114 
115 struct wsdisplay_accessops wcfb_accessops = {
116 	wcfb_ioctl,
117 	wcfb_mmap,
118 	NULL,	/* alloc_screen */
119 	NULL,	/* free_screen */
120 	NULL,	/* show_screen */
121 	NULL, 	/* load_font */
122 	NULL,	/* pollc */
123 	NULL	/* scroll */
124 };
125 
126 static void	wcfb_putchar(void *, int, int, u_int, long);
127 static void	wcfb_cursor(void *, int, int, int);
128 static void	wcfb_copycols(void *, int, int, int, int);
129 static void	wcfb_erasecols(void *, int, int, int, long);
130 static void	wcfb_copyrows(void *, int, int, int);
131 static void	wcfb_eraserows(void *, int, int, long);
132 
133 static void 	wcfb_putpalreg(struct wcfb_softc *, int, int, int, int);
134 
135 static int
136 wcfb_match(device_t parent, cfdata_t match, void *aux)
137 {
138 	struct pci_attach_args *pa = aux;
139 
140 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_3DLABS &&
141 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_WILDCAT5110)
142 		return 100;
143 
144 	return 0;
145 }
146 
147 static void
148 wcfb_attach(device_t parent, device_t self, void *aux)
149 {
150 	struct wcfb_softc *sc = device_private(self);
151 	struct pci_attach_args *pa = aux;
152 	struct rasops_info	*ri;
153 	prop_dictionary_t	dict;
154 	struct wsemuldisplaydev_attach_args aa;
155 	int 			i, j;
156 	uint32_t		reg;
157 	unsigned long		defattr;
158 	bool			is_console = 0;
159 	void *wtf;
160 
161 	sc->sc_dev = self;
162 	sc->putchar = NULL;
163 	pci_aprint_devinfo(pa, NULL);
164 
165 	dict = device_properties(self);
166 	prop_dictionary_get_bool(dict, "is_console", &is_console);
167 #ifndef WCFB_DEBUG
168 	if (!is_console) return;
169 #endif
170 	sc->sc_memt = pa->pa_memt;
171 	sc->sc_iot = pa->pa_iot;
172 	sc->sc_pc = pa->pa_pc;
173 	sc->sc_pcitag = pa->pa_tag;
174 
175 	if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_MEM, 0,
176 	    &sc->sc_regt, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
177 		aprint_error("%s: failed to map registers.\n",
178 		    device_xname(sc->sc_dev));
179 	}
180 
181 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
182 	    &sc->sc_memt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
183 		aprint_error("%s: failed to map framebuffer.\n",
184 		    device_xname(sc->sc_dev));
185 	}
186 
187 	if (pci_mapreg_map(pa, 0x18, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
188 	    &sc->sc_wtft, &sc->sc_wtfh, &sc->sc_wtf, &sc->sc_wtfsize)) {
189 		aprint_error("%s: failed to map wtf.\n",
190 		    device_xname(sc->sc_dev));
191 	}
192 	wtf = bus_space_vaddr(sc->sc_wtft, sc->sc_wtfh);
193 	memset(wtf, 0, 0x100000);
194 
195 	sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
196 
197 	sc->sc_fb0off =
198 	    bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_FB8_ADDR0) - sc->sc_fb;
199 	sc->sc_fb0 = sc->sc_fbaddr + sc->sc_fb0off;
200 	sc->sc_fb1off =
201 	    bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_FB8_ADDR1) - sc->sc_fb;
202 	sc->sc_fb1 = sc->sc_fbaddr + sc->sc_fb1off;
203 
204 	reg = bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_RESOLUTION);
205 	sc->sc_height = (reg >> 16) + 1;
206 	sc->sc_width = (reg & 0xffff) + 1;
207 	sc->sc_stride = 1 <<
208 	    ((bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_CONFIG) &
209 	      0x00ff0000) >> 16);
210 	printf("%s: %d x %d, %d\n", device_xname(sc->sc_dev),
211 	    sc->sc_width, sc->sc_height, sc->sc_stride);
212 
213 	sc->sc_shadow = kmem_alloc(sc->sc_stride * sc->sc_height, KM_SLEEP);
214 	if (sc->sc_shadow == NULL) {
215 		printf("%s: failed to allocate shadow buffer\n",
216 		    device_xname(self));
217 		return;
218 	}
219 
220 	for (i = 0x40; i < 0x100; i += 16) {
221 		printf("%04x:", i);
222 		for (j = 0; j < 16; j += 4) {
223 			printf(" %08x", bus_space_read_4(sc->sc_regt,
224 			    sc->sc_regh, 0x8000 + i + j));
225 		}
226 		printf("\n");
227 	}
228 
229 	/* make sure video output is on */
230 	bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_DPMS_STATE, WC_DPMS_ON);
231 
232 	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
233 		"default",
234 		0, 0,
235 		NULL,
236 		8, 16,
237 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
238 		NULL
239 	};
240 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
241 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
242 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
243 	sc->sc_locked = 0;
244 
245 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
246 	    &wcfb_accessops);
247 	sc->vd.init_screen = wcfb_init_screen;
248 
249 	/* init engine here */
250 #if 0
251 	wcfb_init(sc);
252 #endif
253 
254 	ri = &sc->sc_console_screen.scr_ri;
255 
256 	j = 0;
257 	for (i = 0; i < 256; i++) {
258 
259 		sc->sc_cmap_red[i] = rasops_cmap[j];
260 		sc->sc_cmap_green[i] = rasops_cmap[j + 1];
261 		sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
262 		wcfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
263 		    rasops_cmap[j + 2]);
264 		j += 3;
265 	}
266 
267 	if (is_console) {
268 		vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
269 		    &defattr);
270 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
271 
272 		memset(sc->sc_fb0, ri->ri_devcmap[(defattr >> 16) & 0xff],
273 		    sc->sc_stride * sc->sc_height);
274 		memset(sc->sc_fb1, ri->ri_devcmap[(defattr >> 16) & 0xff],
275 		    sc->sc_stride * sc->sc_height);
276 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
277 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
278 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
279 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
280 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
281 		    defattr);
282 		vcons_replay_msgbuf(&sc->sc_console_screen);
283 	} else {
284 		/*
285 		 * since we're not the console we can postpone the rest
286 		 * until someone actually allocates a screen for us
287 		 */
288 		memset(sc->sc_fb0, WS_DEFAULT_BG,
289 		    sc->sc_stride * sc->sc_height);
290 		memset(sc->sc_fb1, WS_DEFAULT_BG,
291 		    sc->sc_stride * sc->sc_height);
292 		return;
293 	}
294 
295 	aa.console = is_console;
296 	aa.scrdata = &sc->sc_screenlist;
297 	aa.accessops = &wcfb_accessops;
298 	aa.accesscookie = &sc->vd;
299 
300 	config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
301 }
302 
303 static int
304 wcfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
305     struct lwp *l)
306 {
307 	struct wcfb_softc *sc = v;
308 
309 	switch (cmd) {
310 	case WSDISPLAYIO_GTYPE:
311 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
312 		return 0;
313 
314 	/* PCI config read/write passthrough. */
315 	case PCI_IOC_CFGREAD:
316 	case PCI_IOC_CFGWRITE:
317 		return pci_devioctl(sc->sc_pc, sc->sc_pcitag,
318 		    cmd, data, flag, l);
319 
320 	case WSDISPLAYIO_GET_BUSID:
321 		return wsdisplayio_busid_pci(sc->sc_dev, sc->sc_pc,
322 		    sc->sc_pcitag, data);
323 
324 	case WSDISPLAYIO_SMODE: {
325 		/*int new_mode = *(int*)data, i;*/
326 		}
327 		return 0;
328 	}
329 
330 	return EPASSTHROUGH;
331 }
332 
333 static paddr_t
334 wcfb_mmap(void *v, void *vs, off_t offset, int prot)
335 {
336 	struct wcfb_softc *sc = v;
337 
338 	/* no point in allowing a wsfb map if we can't provide one */
339 	/*
340 	 * restrict all other mappings to processes with superuser privileges
341 	 * or the kernel itself
342 	 */
343 	if (kauth_authorize_machdep(kauth_cred_get(), KAUTH_MACHDEP_UNMANAGEDMEM,
344 	    NULL, NULL, NULL, NULL) != 0) {
345 		aprint_normal_dev(sc->sc_dev, "mmap() rejected.\n");
346 		return -1;
347 	}
348 
349 #ifdef WSFB_FAKE_VGA_FB
350 	if ((offset >= 0xa0000) && (offset < 0xbffff)) {
351 
352 		return bus_space_mmap(sc->sc_memt, sc->sc_gen.sc_fboffset,
353 		   offset - 0xa0000, prot, BUS_SPACE_MAP_LINEAR);
354 	}
355 #endif
356 
357 	return -1;
358 }
359 
360 static void
361 wcfb_init_screen(void *cookie, struct vcons_screen *scr,
362     int existing, long *defattr)
363 {
364 	struct wcfb_softc *sc = cookie;
365 	struct rasops_info *ri = &scr->scr_ri;
366 
367 	ri->ri_depth = 8;
368 	ri->ri_width = sc->sc_width;
369 	ri->ri_height = sc->sc_height;
370 	ri->ri_stride = sc->sc_stride;
371 	ri->ri_flg = RI_CENTER /*| RI_FULLCLEAR*/;
372 
373 	ri->ri_bits = sc->sc_shadow;
374 
375 	if (existing) {
376 		ri->ri_flg |= RI_CLEAR;
377 	}
378 
379 	rasops_init(ri, 0, 0);
380 	ri->ri_caps = WSSCREEN_WSCOLORS;
381 
382 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
383 		    sc->sc_width / ri->ri_font->fontwidth);
384 
385 	ri->ri_hw = scr;
386 	sc->putchar = ri->ri_ops.putchar;
387 	sc->copyrows = ri->ri_ops.copyrows;
388 	sc->eraserows = ri->ri_ops.eraserows;
389 	sc->copycols = ri->ri_ops.copycols;
390 	sc->erasecols = ri->ri_ops.erasecols;
391 
392 	ri->ri_ops.copyrows = wcfb_copyrows;
393 	ri->ri_ops.copycols = wcfb_copycols;
394 	ri->ri_ops.eraserows = wcfb_eraserows;
395 	ri->ri_ops.erasecols = wcfb_erasecols;
396 	ri->ri_ops.putchar = wcfb_putchar;
397 	ri->ri_ops.cursor = wcfb_cursor;
398 }
399 
400 static void
401 wcfb_putchar(void *cookie, int row, int col, u_int c, long attr)
402 {
403 	struct rasops_info *ri = cookie;
404 	struct vcons_screen *scr = ri->ri_hw;
405 	struct wcfb_softc *sc = scr->scr_cookie;
406 	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
407 	    sc->sc_stride + ri->ri_xorigin + col * ri->ri_font->fontwidth;
408 	uint8_t *from, *to0, *to1;
409 	int i;
410 
411 	sc->putchar(ri, row, col, c, attr);
412 	from = sc->sc_shadow + offset;
413 	to0 = sc->sc_fb0 + offset;
414 	to1 = sc->sc_fb1 + offset;
415 	for (i = 0; i < ri->ri_font->fontheight; i++) {
416 		memcpy(to0, from, ri->ri_font->fontwidth);
417 		memcpy(to1, from, ri->ri_font->fontwidth);
418 		to0 += sc->sc_stride;
419 		to1 += sc->sc_stride;
420 		from += sc->sc_stride;
421 	}
422 }
423 
424 static void
425 wcfb_putpalreg(struct wcfb_softc *sc, int i, int r, int g, int b)
426 {
427 	uint32_t rgb;
428 
429 	bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_INDEX, i);
430 	rgb = (b << 22) | (g << 12) | (r << 2);
431 	bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_DATA, rgb);
432 }
433 
434 static void
435 wcfb_cursor(void *cookie, int on, int row, int col)
436 {
437 	struct rasops_info *ri = cookie;
438 	struct vcons_screen *scr = ri->ri_hw;
439 	struct wcfb_softc *sc = scr->scr_cookie;
440 	int coffset;
441 
442 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
443 
444 		if (ri->ri_flg & RI_CURSOR) {
445 			/* remove cursor */
446 			coffset = ri->ri_ccol + (ri->ri_crow * ri->ri_cols);
447 #ifdef WSDISPLAY_SCROLLSUPPORT
448 			coffset += scr->scr_offset_to_zero;
449 #endif
450 			wcfb_putchar(cookie, ri->ri_crow,
451 			    ri->ri_ccol, scr->scr_chars[coffset],
452 			    scr->scr_attrs[coffset]);
453 			ri->ri_flg &= ~RI_CURSOR;
454 		}
455 		ri->ri_crow = row;
456 		ri->ri_ccol = col;
457 		if (on) {
458 			long attr, revattr;
459 			coffset = col + (row * ri->ri_cols);
460 #ifdef WSDISPLAY_SCROLLSUPPORT
461 			coffset += scr->scr_offset_to_zero;
462 #endif
463 			attr = scr->scr_attrs[coffset];
464 			revattr = attr ^ 0xffff0000;
465 
466 			wcfb_putchar(cookie, ri->ri_crow, ri->ri_ccol,
467 			    scr->scr_chars[coffset], revattr);
468 			ri->ri_flg |= RI_CURSOR;
469 		}
470 	} else {
471 		ri->ri_crow = row;
472 		ri->ri_ccol = col;
473 		ri->ri_flg &= ~RI_CURSOR;
474 	}
475 }
476 
477 static void
478 wcfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
479 {
480 	struct rasops_info *ri = cookie;
481 	struct vcons_screen *scr = ri->ri_hw;
482 	struct wcfb_softc *sc = scr->scr_cookie;
483 	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
484 	    sc->sc_stride + ri->ri_xorigin + dstcol * ri->ri_font->fontwidth;
485 	uint8_t *from, *to0, *to1;
486 	int i;
487 
488 	sc->copycols(ri, row, srccol, dstcol, ncols);
489 	from = sc->sc_shadow + offset;
490 	to0 = sc->sc_fb0 + offset;
491 	to1 = sc->sc_fb1 + offset;
492 	for (i = 0; i < ri->ri_font->fontheight; i++) {
493 		memcpy(to0, from, ri->ri_font->fontwidth * ncols);
494 		memcpy(to1, from, ri->ri_font->fontwidth * ncols);
495 		to0 += sc->sc_stride;
496 		to1 += sc->sc_stride;
497 		from += sc->sc_stride;
498 	}
499 }
500 
501 static void
502 wcfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
503 {
504 	struct rasops_info *ri = cookie;
505 	struct vcons_screen *scr = ri->ri_hw;
506 	struct wcfb_softc *sc = scr->scr_cookie;
507 	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
508 	    sc->sc_stride + ri->ri_xorigin + startcol * ri->ri_font->fontwidth;
509 	uint8_t *to0, *to1;
510 	int i;
511 
512 	sc->erasecols(ri, row, startcol, ncols, fillattr);
513 
514 	to0 = sc->sc_fb0 + offset;
515 	to1 = sc->sc_fb1 + offset;
516 	for (i = 0; i < ri->ri_font->fontheight; i++) {
517 		memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
518 		    ri->ri_font->fontwidth * ncols);
519 		memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
520 		    ri->ri_font->fontwidth * ncols);
521 		to0 += sc->sc_stride;
522 		to1 += sc->sc_stride;
523 	}
524 }
525 
526 static void
527 wcfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
528 {
529 	struct rasops_info *ri = cookie;
530 	struct vcons_screen *scr = ri->ri_hw;
531 	struct wcfb_softc *sc = scr->scr_cookie;
532 	int offset = (ri->ri_yorigin + dstrow * ri->ri_font->fontheight) *
533 	    sc->sc_stride + ri->ri_xorigin;
534 	uint8_t *from, *to0, *to1;
535 	int i;
536 
537 	sc->copyrows(ri, srcrow, dstrow, nrows);
538 
539 	from = sc->sc_shadow + offset;
540 	to0 = sc->sc_fb0 + offset;
541 	to1 = sc->sc_fb1 + offset;
542 	for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
543 		memcpy(to0, from, ri->ri_emuwidth);
544 		memcpy(to1, from, ri->ri_emuwidth);
545 		to0 += sc->sc_stride;
546 		to1 += sc->sc_stride;
547 		from += sc->sc_stride;
548 	}
549 }
550 
551 static void
552 wcfb_eraserows(void *cookie, int row, int nrows, long fillattr)
553 {
554 	struct rasops_info *ri = cookie;
555 	struct vcons_screen *scr = ri->ri_hw;
556 	struct wcfb_softc *sc = scr->scr_cookie;
557 	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
558 	    sc->sc_stride + ri->ri_xorigin;
559 	uint8_t *to0, *to1;
560 	int i;
561 
562 	sc->eraserows(ri, row, nrows, fillattr);
563 
564 	to0 = sc->sc_fb0 + offset;
565 	to1 = sc->sc_fb1 + offset;
566 	for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
567 		memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
568 		    ri->ri_emuwidth);
569 		memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
570 		    ri->ri_emuwidth);
571 		to0 += sc->sc_stride;
572 		to1 += sc->sc_stride;
573 	}
574 }
575