wcfb.c revision 1.6
1/*	$NetBSD: wcfb.c,v 1.6 2010/03/10 05:16:17 macallan 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.6 2010/03/10 05:16:17 macallan 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
65static int	wcfb_match(device_t, cfdata_t, void *);
66static void	wcfb_attach(device_t, device_t, void *);
67static int	wcfb_ioctl(void *, void *, u_long, void *, int,
68		    struct lwp *);
69static paddr_t	wcfb_mmap(void *, void *, off_t, int);
70
71struct 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
109static void	wcfb_init_screen(void *, struct vcons_screen *, int, long *);
110
111CFATTACH_DECL_NEW(wcfb, sizeof(struct wcfb_softc),
112    wcfb_match, wcfb_attach, NULL, NULL);
113
114struct 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
125static void	wcfb_putchar(void *, int, int, u_int, long);
126static void	wcfb_cursor(void *, int, int, int);
127static void	wcfb_copycols(void *, int, int, int, int);
128static void	wcfb_erasecols(void *, int, int, int, long);
129static void	wcfb_copyrows(void *, int, int, int);
130static void	wcfb_eraserows(void *, int, int, long);
131
132static void 	wcfb_putpalreg(struct wcfb_softc *, int, int, int, int);
133
134static int
135wcfb_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
146static void
147wcfb_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
305static int
306wcfb_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			{
323				/*int new_mode = *(int*)data, i;*/
324			}
325			return 0;
326	}
327
328	return EPASSTHROUGH;
329}
330
331static paddr_t
332wcfb_mmap(void *v, void *vs, off_t offset, int prot)
333{
334	struct wcfb_softc *sc = v;
335
336	/* no point in allowing a wsfb map if we can't provide one */
337	/*
338	 * restrict all other mappings to processes with superuser privileges
339	 * or the kernel itself
340	 */
341	if (kauth_authorize_generic(kauth_cred_get(), KAUTH_GENERIC_ISSUSER,
342	    NULL) != 0) {
343		aprint_normal_dev(sc->sc_dev, "mmap() rejected.\n");
344		return -1;
345	}
346
347#ifdef WSFB_FAKE_VGA_FB
348	if ((offset >= 0xa0000) && (offset < 0xbffff)) {
349
350		return bus_space_mmap(sc->sc_memt, sc->sc_gen.sc_fboffset,
351		   offset - 0xa0000, prot, BUS_SPACE_MAP_LINEAR);
352	}
353#endif
354
355	return -1;
356}
357
358static void
359wcfb_init_screen(void *cookie, struct vcons_screen *scr,
360    int existing, long *defattr)
361{
362	struct wcfb_softc *sc = cookie;
363	struct rasops_info *ri = &scr->scr_ri;
364
365	ri->ri_depth = 8;
366	ri->ri_width = sc->sc_width;
367	ri->ri_height = sc->sc_height;
368	ri->ri_stride = sc->sc_stride;
369	ri->ri_flg = RI_CENTER /*| RI_FULLCLEAR*/;
370
371	ri->ri_bits = sc->sc_shadow;
372
373	if (existing) {
374		ri->ri_flg |= RI_CLEAR;
375	}
376
377	rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
378	ri->ri_caps = WSSCREEN_WSCOLORS;
379
380	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
381		    sc->sc_width / ri->ri_font->fontwidth);
382
383	ri->ri_hw = scr;
384	sc->putchar = ri->ri_ops.putchar;
385	sc->copyrows = ri->ri_ops.copyrows;
386	sc->eraserows = ri->ri_ops.eraserows;
387	sc->copycols = ri->ri_ops.copycols;
388	sc->erasecols = ri->ri_ops.erasecols;
389
390	ri->ri_ops.copyrows = wcfb_copyrows;
391	ri->ri_ops.copycols = wcfb_copycols;
392	ri->ri_ops.eraserows = wcfb_eraserows;
393	ri->ri_ops.erasecols = wcfb_erasecols;
394	ri->ri_ops.putchar = wcfb_putchar;
395	ri->ri_ops.cursor = wcfb_cursor;
396}
397
398static void
399wcfb_putchar(void *cookie, int row, int col, u_int c, long attr)
400{
401	struct rasops_info *ri = cookie;
402	struct vcons_screen *scr = ri->ri_hw;
403	struct wcfb_softc *sc = scr->scr_cookie;
404	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
405	    sc->sc_stride + ri->ri_xorigin + col * ri->ri_font->fontwidth;
406	uint8_t *from, *to0, *to1;
407	int i;
408
409	sc->putchar(ri, row, col, c, attr);
410	from = sc->sc_shadow + offset;
411	to0 = sc->sc_fb0 + offset;
412	to1 = sc->sc_fb1 + offset;
413	for (i = 0; i < ri->ri_font->fontheight; i++) {
414		memcpy(to0, from, ri->ri_font->fontwidth);
415		memcpy(to1, from, ri->ri_font->fontwidth);
416		to0 += sc->sc_stride;
417		to1 += sc->sc_stride;
418		from += sc->sc_stride;
419	}
420}
421
422static void
423wcfb_putpalreg(struct wcfb_softc *sc, int i, int r, int g, int b)
424{
425	uint32_t rgb;
426
427	bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_INDEX, i);
428	rgb = (b << 22) | (g << 12) | (r << 2);
429	bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_DATA, rgb);
430}
431
432static void
433wcfb_cursor(void *cookie, int on, int row, int col)
434{
435	struct rasops_info *ri = cookie;
436	struct vcons_screen *scr = ri->ri_hw;
437	struct wcfb_softc *sc = scr->scr_cookie;
438	int coffset;
439
440	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
441
442		if (ri->ri_flg & RI_CURSOR) {
443			/* remove cursor */
444			coffset = ri->ri_ccol + (ri->ri_crow * ri->ri_cols);
445#ifdef WSDISPLAY_SCROLLSUPPORT
446			coffset += scr->scr_offset_to_zero;
447#endif
448			wcfb_putchar(cookie, ri->ri_crow,
449			    ri->ri_ccol, scr->scr_chars[coffset],
450			    scr->scr_attrs[coffset]);
451			ri->ri_flg &= ~RI_CURSOR;
452		}
453		ri->ri_crow = row;
454		ri->ri_ccol = col;
455		if (on) {
456			long attr, revattr;
457			coffset = col + (row * ri->ri_cols);
458#ifdef WSDISPLAY_SCROLLSUPPORT
459			coffset += scr->scr_offset_to_zero;
460#endif
461			attr = scr->scr_attrs[coffset];
462			revattr = attr ^ 0xffff0000;
463
464			wcfb_putchar(cookie, ri->ri_crow, ri->ri_ccol,
465			    scr->scr_chars[coffset], revattr);
466			ri->ri_flg |= RI_CURSOR;
467		}
468	} else {
469		ri->ri_crow = row;
470		ri->ri_ccol = col;
471		ri->ri_flg &= ~RI_CURSOR;
472	}
473}
474
475static void
476wcfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
477{
478	struct rasops_info *ri = cookie;
479	struct vcons_screen *scr = ri->ri_hw;
480	struct wcfb_softc *sc = scr->scr_cookie;
481	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
482	    sc->sc_stride + ri->ri_xorigin + dstcol * ri->ri_font->fontwidth;
483	uint8_t *from, *to0, *to1;
484	int i;
485
486	sc->copycols(ri, row, srccol, dstcol, ncols);
487	from = sc->sc_shadow + offset;
488	to0 = sc->sc_fb0 + offset;
489	to1 = sc->sc_fb1 + offset;
490	for (i = 0; i < ri->ri_font->fontheight; i++) {
491		memcpy(to0, from, ri->ri_font->fontwidth * ncols);
492		memcpy(to1, from, ri->ri_font->fontwidth * ncols);
493		to0 += sc->sc_stride;
494		to1 += sc->sc_stride;
495		from += sc->sc_stride;
496	}
497}
498
499static void
500wcfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
501{
502	struct rasops_info *ri = cookie;
503	struct vcons_screen *scr = ri->ri_hw;
504	struct wcfb_softc *sc = scr->scr_cookie;
505	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
506	    sc->sc_stride + ri->ri_xorigin + startcol * ri->ri_font->fontwidth;
507	uint8_t *to0, *to1;
508	int i;
509
510	sc->erasecols(ri, row, startcol, ncols, fillattr);
511
512	to0 = sc->sc_fb0 + offset;
513	to1 = sc->sc_fb1 + offset;
514	for (i = 0; i < ri->ri_font->fontheight; i++) {
515		memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
516		    ri->ri_font->fontwidth * ncols);
517		memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
518		    ri->ri_font->fontwidth * ncols);
519		to0 += sc->sc_stride;
520		to1 += sc->sc_stride;
521	}
522}
523
524static void
525wcfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
526{
527	struct rasops_info *ri = cookie;
528	struct vcons_screen *scr = ri->ri_hw;
529	struct wcfb_softc *sc = scr->scr_cookie;
530	int offset = (ri->ri_yorigin + dstrow * ri->ri_font->fontheight) *
531	    sc->sc_stride + ri->ri_xorigin;
532	uint8_t *from, *to0, *to1;
533	int i;
534
535	sc->copyrows(ri, srcrow, dstrow, nrows);
536
537	from = sc->sc_shadow + offset;
538	to0 = sc->sc_fb0 + offset;
539	to1 = sc->sc_fb1 + offset;
540	for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
541		memcpy(to0, from, ri->ri_emuwidth);
542		memcpy(to1, from, ri->ri_emuwidth);
543		to0 += sc->sc_stride;
544		to1 += sc->sc_stride;
545		from += sc->sc_stride;
546	}
547}
548
549static void
550wcfb_eraserows(void *cookie, int row, int nrows, long fillattr)
551{
552	struct rasops_info *ri = cookie;
553	struct vcons_screen *scr = ri->ri_hw;
554	struct wcfb_softc *sc = scr->scr_cookie;
555	int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
556	    sc->sc_stride + ri->ri_xorigin;
557	uint8_t *to0, *to1;
558	int i;
559
560	sc->eraserows(ri, row, nrows, fillattr);
561
562	to0 = sc->sc_fb0 + offset;
563	to1 = sc->sc_fb1 + offset;
564	for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
565		memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
566		    ri->ri_emuwidth);
567		memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
568		    ri->ri_emuwidth);
569		to0 += sc->sc_stride;
570		to1 += sc->sc_stride;
571	}
572}
573