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