gsfb.c revision 1.14 1 /* $NetBSD: gsfb.c,v 1.14 2006/02/04 12:13:05 martin Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: gsfb.c,v 1.14 2006/02/04 12:13:05 martin Exp $");
41
42 #include "debug_playstation2.h"
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46
47 #include <machine/autoconf.h>
48
49 #include <dev/cons.h>
50
51 #include <dev/wscons/wsconsio.h>
52 #include <dev/wscons/wsdisplayvar.h>
53 #include <dev/wscons/wscons_callbacks.h>
54
55 #include <dev/wsfont/wsfont.h>
56
57 #include <playstation2/ee/eevar.h>
58 #include <playstation2/ee/gsvar.h>
59 #include <playstation2/ee/gsreg.h>
60 #include <playstation2/ee/dmacvar.h>
61 #include <playstation2/ee/dmacreg.h>
62
63 #ifdef DEBUG
64 #define STATIC
65 #else
66 #define STATIC static
67 #endif
68
69 STATIC struct gsfb {
70 int initialized;
71 int attached;
72 int is_console;
73 const struct wsscreen_descr *screen;
74 struct wsdisplay_font *font;
75 } gsfb;
76
77 STATIC void gsfb_dma_kick(paddr_t, size_t);
78 STATIC void gsfb_font_expand_psmct32(const struct wsdisplay_font *, u_int,
79 long, u_int32_t *);
80 STATIC inline void gsfb_set_cursor_pos(u_int32_t *, int, int, int, int);
81
82 #define ATTR_FG_GET(a) (((a )>> 24) & 0xf)
83 #define ATTR_BG_GET(a) (((a )>> 16) & 0xf)
84 #define ATTR_FG_SET(x) (((x) << 24) & 0x0f000000)
85 #define ATTR_BG_SET(x) (((x) << 16) & 0x000f0000)
86
87 STATIC const u_int32_t gsfb_ansi_psmct32[] = {
88 0x80000000, /* black */
89 0x800000aa, /* red */
90 0x8000aa00, /* green */
91 0x8000aaaa, /* brown */
92 0x80aa0000, /* blue */
93 0x80aa00aa, /* magenta */
94 0x80aaaa00, /* cyan */
95 0x80aaaaaa, /* white */
96 0x80000000, /* black */
97 0x800000ff, /* red */
98 0x8000ff00, /* green */
99 0x8000ffff, /* brown */
100 0x80ff0000, /* blue */
101 0x80ff00ff, /* magenta */
102 0x80ffff00, /* cyan */
103 0x80ffffff, /* black */
104 };
105
106 #define TRXPOS_DXY(f, x, y) \
107 ({ \
108 f[9] = ((x) & 0x000007ff) | (((y) << 16) & 0x07ff0000); \
109 })
110
111 #define TRXPOS_SY_DY(f, sy, dy) \
112 ({ \
113 f[8] = (((sy) << 16) & 0x07ff0000); \
114 f[9] = (((dy) << 16) & 0x07ff0000); \
115 })
116
117 #define TRXPOS_DXY_SXY(f, dx, dy, sx, sy) \
118 ({ \
119 f[8] = ((((sy) << 16) & 0x07ff0000) | ((sx) & 0x000007ff)); \
120 f[9] = ((((dy) << 16) & 0x07ff0000) | ((dx) & 0x000007ff)); \
121 })
122
123 STATIC u_int32_t gsfb_scroll_cmd_640x16[] __attribute__((__aligned__(16))) = {
124 0x00008004, 0x10000000, 0x0000000e, 0x00000000,
125 0x000a0000, 0x000a0000, 0x00000050, 0x00000000,
126 0x07ff0000, 0x07ff0000, 0x00000051, 0x00000000,
127 0x00000280, 0x00000010, 0x00000052, 0x00000000,
128 0x00000002, 0x00000000, 0x00000053, 0x00000000,
129 };
130
131 STATIC u_int32_t gsfb_cursor_cmd[] __attribute__((__aligned__(16))) = {
132 0x00008007, 0x10000000, 0x0000000e, 0x00000000,
133 0x00000001, 0x00000000, 0x0000001a, 0x00000000,
134 0x000000a4, 0x00000080, 0x00000042, 0x00000000,
135 0x00000046, 0x00000000, 0x00000000, 0x00000000,
136 0x80ffffff, 0x00000000, 0x00000001, 0x00000000,
137 0x00000000, 0x00000000, 0x0000000d, 0x00000000,
138 0x80ffffff, 0x00000000, 0x00000001, 0x00000000,
139 0x00000000, 0x00000000, 0x00000005, 0x00000000,
140 };
141
142 STATIC u_int32_t gsfb_copy_cmd_8x16[] __attribute__((__aligned__(16))) = {
143 0x00008004, 0x10000000, 0x0000000e, 0x00000000,
144 0x000a0000, 0x000a0000, 0x00000050, 0x00000000,
145 0x07ff07ff, 0x07ff07ff, 0x00000051, 0x00000000,
146 0x00000008, 0x00000010, 0x00000052, 0x00000000,
147 0x00000002, 0x00000000, 0x00000053, 0x00000000,
148 };
149
150 STATIC u_int32_t gsfb_init_cmd_640x480[] __attribute__((__aligned__(16))) = {
151 0x00008008, 0x10000000, 0x0000000e, 0x00000000,
152 0x000a0000, 0x00000000, 0x0000004c, 0x00000000,
153 0x00000096, 0x00000000, 0x0000004e, 0x00000000,
154 0x02800000, 0x01e00000, 0x00000040, 0x00000000,
155 0x00000006, 0x00000000, 0x00000000, 0x00000000,
156 0x80000000, 0x00000000, 0x00000001, 0x00000000,
157 0x00000000, 0x00000000, 0x0000000d, 0x00000000,
158 0x80000000, 0x00000000, 0x00000001, 0x00000000,
159 0x1e002800, 0x00000000, 0x00000005, 0x00000000,
160 };
161
162 STATIC u_int32_t gsfb_load_cmd_8x16_psmct32[(6 + 32) * 4]
163 __attribute__((__aligned__(16))) = {
164 /* GIF tag + GS command */
165 0x00000004, 0x10000000, 0x0000000e, 0x00000000,
166 0x00000000, 0x000a0000, 0x00000050, 0x00000000,
167 0x00000000, 0x00000000, 0x00000051, 0x00000000,
168 0x00000008, 0x00000016, 0x00000052, 0x00000000,
169 0x00000000, 0x00000000, 0x00000053, 0x00000000,
170 0x00008020, 0x08000000, 0x00000000, 0x00000000,
171 /* Load area */
172 #define FONT_SCRATCH_BASE (6 * 4)
173 };
174
175 #ifdef GSFB_DEBUG_MONITOR
176 #include <machine/stdarg.h>
177 STATIC const struct _gsfb_debug_window {
178 int start, nrow, attr;
179 } _gsfb_debug_window[3] = {
180 { 24, 2 , ATTR_BG_SET(WSCOL_BROWN) | ATTR_FG_SET(WSCOL_BLUE) },
181 { 26, 2 , ATTR_BG_SET(WSCOL_CYAN) | ATTR_FG_SET(WSCOL_BLUE) },
182 { 28, 2 , ATTR_BG_SET(WSCOL_WHITE) | ATTR_FG_SET(WSCOL_BLUE) },
183 };
184 STATIC char _gsfb_debug_buf[80 * 2];
185 #endif /* GSFB_DEBUG_MONITOR */
186
187 STATIC int gsfb_match(struct device *, struct cfdata *, void *);
188 STATIC void gsfb_attach(struct device *, struct device *, void *);
189
190 CFATTACH_DECL(gsfb, sizeof(struct device),
191 gsfb_match, gsfb_attach, NULL, NULL);
192
193 STATIC void gsfb_hwinit(void);
194 STATIC int gsfb_swinit(void);
195
196 /* console */
197 void gsfbcnprobe(struct consdev *);
198 void gsfbcninit(struct consdev *);
199
200 /* emul ops */
201 STATIC void _gsfb_cursor(void *, int, int, int);
202 STATIC int _gsfb_mapchar(void *, int, unsigned int *);
203 STATIC void _gsfb_putchar(void *, int, int, u_int, long);
204 STATIC void _gsfb_copycols(void *, int, int, int, int);
205 STATIC void _gsfb_erasecols(void *, int, int, int, long);
206 STATIC void _gsfb_copyrows(void *, int, int, int);
207 STATIC void _gsfb_eraserows(void *, int, int, long);
208 STATIC int _gsfb_allocattr(void *, int, int, int, long *);
209
210 /* access ops */
211 STATIC int _gsfb_ioctl(void *, u_long, caddr_t, int, struct lwp *);
212 STATIC paddr_t _gsfb_mmap(void *, off_t, int);
213 STATIC int _gsfb_alloc_screen(void *, const struct wsscreen_descr *, void **,
214 int *, int *, long *);
215 STATIC void _gsfb_free_screen(void *, void *);
216 STATIC int _gsfb_show_screen(void *, void *, int, void (*)(void *, int, int),
217 void *);
218 STATIC void _gsfb_pollc(void *, int);
219
220 /*
221 * wsdisplay attach args
222 * std: screen size 640 x 480, font size 8 x 16
223 */
224 #define GSFB_STD_SCREEN_WIDTH 640
225 #define GSFB_STD_SCREEN_HEIGHT 480
226 #define GSFB_STD_FONT_WIDTH 8
227 #define GSFB_STD_FONT_HEIGHT 16
228 const struct wsdisplay_emulops _gsfb_emulops = {
229 .cursor = _gsfb_cursor,
230 .mapchar = _gsfb_mapchar,
231 .putchar = _gsfb_putchar,
232 .copycols = _gsfb_copycols,
233 .erasecols = _gsfb_erasecols,
234 .copyrows = _gsfb_copyrows,
235 .eraserows = _gsfb_eraserows,
236 .allocattr = _gsfb_allocattr
237 };
238
239 const struct wsscreen_descr _gsfb_std_screen = {
240 .name = "std",
241 .ncols = 80,
242 #ifdef GSFB_DEBUG_MONITOR
243 .nrows = 24,
244 #else
245 .nrows = 30,
246 #endif
247 .textops = &_gsfb_emulops,
248 .fontwidth = 8,
249 .fontheight = 16,
250 .capabilities = WSSCREEN_UNDERLINE | WSSCREEN_HILIT |
251 WSSCREEN_WSCOLORS
252 };
253
254 const struct wsscreen_descr *_gsfb_screen_table[] = {
255 &_gsfb_std_screen,
256 };
257
258 struct wsscreen_list _gsfb_screen_list = {
259 .nscreens = sizeof(_gsfb_screen_table) /
260 sizeof(_gsfb_screen_table[0]),
261 .screens = _gsfb_screen_table
262 };
263
264 struct wsdisplay_accessops _gsfb_accessops = {
265 .ioctl = _gsfb_ioctl,
266 .mmap = _gsfb_mmap,
267 .alloc_screen = _gsfb_alloc_screen,
268 .free_screen = _gsfb_free_screen,
269 .show_screen = _gsfb_show_screen,
270 .load_font = 0,
271 .pollc = _gsfb_pollc
272 };
273
274 int
275 gsfb_match(struct device *parent, struct cfdata *cf, void *aux)
276 {
277 extern struct cfdriver gsfb_cd;
278 struct mainbus_attach_args *ma = aux;
279
280 if (strcmp(ma->ma_name, gsfb_cd.cd_name) != 0)
281 return (0);
282
283 return (!gsfb.attached);
284 }
285
286 void
287 gsfb_attach(struct device *parent, struct device *self, void *aux)
288 {
289 struct wsemuldisplaydev_attach_args wa;
290
291 gsfb.attached = 1;
292 if (!gsfb.is_console && gsfb_swinit() != 0)
293 return;
294
295 printf("\n");
296
297 wa.console = gsfb.is_console;
298 wa.scrdata = &_gsfb_screen_list;
299 wa.accessops = &_gsfb_accessops;
300 wa.accesscookie = &gsfb;
301
302 config_found(self, &wa, wsdisplaydevprint);
303 }
304
305 /*
306 * console
307 */
308 void
309 gsfbcnprobe(struct consdev *cndev)
310 {
311
312 cndev->cn_pri = CN_INTERNAL;
313 }
314
315 void
316 gsfbcninit(struct consdev *cndev)
317 {
318 paddr_t paddr = MIPS_KSEG0_TO_PHYS(gsfb_init_cmd_640x480);
319 long defattr = ATTR_BG_SET(WSCOL_BLACK) | ATTR_FG_SET(WSCOL_WHITE);
320
321 gsfb.is_console = 1;
322
323 gsfb_hwinit();
324 gsfb_swinit();
325
326 gsfb_dma_kick(paddr, sizeof gsfb_init_cmd_640x480);
327 #ifdef GSFB_DEBUG_MONITOR
328 {
329 const struct _gsfb_debug_window *win;
330 int i;
331
332 for (i = 0; i < 3; i++) {
333 win = &_gsfb_debug_window[i];
334 _gsfb_eraserows(0, win->start, win->nrow, win->attr);
335 }
336 }
337 #endif /* GSFB_DEBUG_MONITOR */
338
339 wsdisplay_cnattach(&_gsfb_std_screen, &gsfb, 0, 0, defattr);
340 }
341
342 void
343 gsfb_hwinit()
344 {
345 /*
346 gs_init(VESA_1A) hang up on SCPH-50000.
347 use bootloader's setting.
348 EN1 | CRTMOD | MMOD | AMOD | ALP(all 1.0)
349 */
350 _reg_write_8(GS_S_PMODE_REG, 0xffa5);
351
352 dmac_init();
353
354 /* reset GIF channel DMA */
355 _reg_write_4(D2_QWC_REG, 0);
356 _reg_write_4(D2_MADR_REG, 0);
357 _reg_write_4(D2_TADR_REG, 0);
358 _reg_write_4(D2_CHCR_REG, 0);
359 }
360
361 int
362 gsfb_swinit()
363 {
364 int font;
365
366 wsfont_init();
367 font = wsfont_find(NULL, 8, 16, 0, WSDISPLAY_FONTORDER_L2R,
368 WSDISPLAY_FONTORDER_L2R);
369 if (font < 0)
370 return (1);
371
372 if (wsfont_lock(font, &gsfb.font))
373 return (1);
374
375 gsfb.screen = &_gsfb_std_screen;
376 gsfb.initialized = 1;
377
378 return (0);
379 }
380
381 /*
382 * wsdisplay
383 */
384 void
385 _gsfb_cursor(void *cookie, int on, int row, int col)
386 {
387 paddr_t paddr = MIPS_KSEG0_TO_PHYS(gsfb_cursor_cmd);
388 u_int32_t *buf = (void *)MIPS_PHYS_TO_KSEG1(paddr);
389 struct wsdisplay_font *font = gsfb.font;
390
391 gsfb_set_cursor_pos(buf, col, row, font->fontwidth, font->fontheight);
392
393 gsfb_dma_kick(paddr, sizeof gsfb_cursor_cmd);
394 }
395
396 inline void
397 gsfb_set_cursor_pos(u_int32_t *p, int x, int y, int w, int h)
398 {
399
400 x *= w;
401 y *= h;
402 p[20] = ((x << 4) & 0xffff) | ((y << 20) & 0xffff0000);
403 p[28] = (((x + w) << 4) & 0xffff) | (((y + h) << 20) & 0xffff0000);
404 }
405
406 int
407 _gsfb_mapchar(void *cookie, int c, unsigned int *cp)
408 {
409 struct wsdisplay_font *font = gsfb.font;
410
411 if (font->encoding != WSDISPLAY_FONTENC_ISO)
412 if ((c = wsfont_map_unichar(font, c)) < 0)
413 goto nomap;
414
415 if (c < font->firstchar || c >= font->firstchar + font->numchars)
416 goto nomap;
417
418 *cp = c;
419 return (5);
420
421 nomap:
422 *cp = ' ';
423 return (0);
424 }
425
426 void
427 _gsfb_putchar(void *cookie, int row, int col, u_int uc, long attr)
428 {
429 paddr_t paddr = MIPS_KSEG0_TO_PHYS(gsfb_load_cmd_8x16_psmct32);
430 u_int32_t *buf = (void *)MIPS_PHYS_TO_KSEG1(paddr);
431 struct wsdisplay_font *font = gsfb.font;
432
433 /* copy font data to DMA region */
434 gsfb_font_expand_psmct32(font, uc, attr, &buf[FONT_SCRATCH_BASE]);
435
436 /* set destination position */
437 TRXPOS_DXY(buf, col * font->fontwidth, row * font->fontheight);
438
439 /* kick to GIF */
440 gsfb_dma_kick(paddr, sizeof gsfb_load_cmd_8x16_psmct32);
441 }
442
443 void
444 _gsfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
445 {
446 paddr_t paddr = MIPS_KSEG0_TO_PHYS(gsfb_copy_cmd_8x16);
447 u_int32_t *cmd = (void *)MIPS_PHYS_TO_KSEG1(paddr);
448 int y = gsfb.font->fontheight * row;
449 int w = gsfb.font->fontwidth;
450 int i;
451
452 if (dstcol > srccol) {
453 for (i = ncols - 1; i >= 0; i--) {
454 TRXPOS_DXY_SXY(cmd, (dstcol + i) * w, y, (srccol + i) * w, y);
455 gsfb_dma_kick(paddr, sizeof gsfb_copy_cmd_8x16);
456 }
457 } else {
458 for (i = 0; i < ncols; i++) {
459 TRXPOS_DXY_SXY(cmd, (dstcol + i) * w, y, (srccol + i) * w, y);
460 gsfb_dma_kick(paddr, sizeof gsfb_copy_cmd_8x16);
461 }
462 }
463 }
464
465 void
466 _gsfb_erasecols(void *cookie, int row, int startcol, int ncols, long attr)
467 {
468 int i;
469
470 for (i = 0; i < ncols; i++)
471 _gsfb_putchar(cookie, row, startcol + i, ' ', attr);
472 }
473
474 void
475 _gsfb_copyrows(void *cookie, int src, int dst, int num)
476 {
477 paddr_t paddr = MIPS_KSEG0_TO_PHYS(gsfb_scroll_cmd_640x16);
478 u_int32_t *cmd = (void *)MIPS_PHYS_TO_KSEG1(paddr);
479 int i;
480 int h = gsfb.font->fontheight;
481
482 if (dst > src) {
483 for (i = num - 1; i >= 0; i--) {
484 TRXPOS_SY_DY(cmd, (src + i) * h, (dst + i) * h);
485 gsfb_dma_kick(paddr, sizeof gsfb_scroll_cmd_640x16);
486 }
487 } else {
488 for (i = 0; i < num; i++) {
489 TRXPOS_SY_DY(cmd, (src + i) * h, (dst + i) * h);
490 gsfb_dma_kick(paddr, sizeof gsfb_scroll_cmd_640x16);
491 }
492 }
493 }
494
495 void
496 _gsfb_eraserows(void *cookie, int row, int nrow, long attr)
497 {
498 int i, j;
499
500 for (j = 0; j < nrow; j++)
501 for (i = 0; i < gsfb.screen->ncols; i++)
502 _gsfb_putchar(cookie, row + j, i, ' ', attr);
503 }
504
505 int
506 _gsfb_allocattr(void *cookie, int fg, int bg, int flags, long *attr)
507 {
508
509 if ((flags & WSATTR_BLINK) != 0)
510 return (EINVAL);
511
512 if ((flags & WSATTR_WSCOLORS) == 0) {
513 fg = WSCOL_WHITE;
514 bg = WSCOL_BLACK;
515 }
516
517 if ((flags & WSATTR_HILIT) != 0)
518 fg += 8;
519
520 flags = (flags & WSATTR_UNDERLINE) ? 1 : 0;
521
522
523 *attr = ATTR_BG_SET(bg) | ATTR_FG_SET(fg) | flags;
524
525 return (0);
526 }
527
528 int
529 _gsfb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l)
530 {
531
532 return (EPASSTHROUGH); /* Inappropriate ioctl for device */
533 }
534
535 paddr_t
536 _gsfb_mmap(void *v, off_t offset, int prot)
537 {
538
539 return (-1); /* can't mmap */
540 }
541
542 int
543 _gsfb_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
544 int *curxp, int *curyp, long *attrp)
545 {
546
547 *attrp = ATTR_BG_SET(WSCOL_BLACK) | ATTR_FG_SET(WSCOL_WHITE);
548
549 return (0);
550 }
551
552 void
553 _gsfb_free_screen(void *v, void *cookie)
554 {
555 }
556
557 int
558 _gsfb_show_screen(void *v, void *cookie, int waitok,
559 void (*cb)(void *, int, int), void *cbarg)
560 {
561
562 return (0);
563 }
564
565 void
566 _gsfb_pollc(void *v, int on)
567 {
568
569 }
570
571 /*
572 * font expansion
573 * PSMCT32 only
574 */
575 void
576 gsfb_font_expand_psmct32(const struct wsdisplay_font *font, u_int c, long attr,
577 u_int32_t *buf)
578 {
579 u_int32_t fg, bg;
580 u_int8_t *bitmap;
581 int i, j;
582
583 KDASSERT(((u_int32_t)buf & 15) == 0);
584
585 fg = gsfb_ansi_psmct32[ATTR_FG_GET(attr)];
586 bg = gsfb_ansi_psmct32[ATTR_BG_GET(attr)];
587
588 bitmap = (u_int8_t *)font->data + (c - font->firstchar) *
589 font->fontheight * font->stride;
590 for (i = 0; i < font->fontheight; i++, bitmap++) {
591 u_int32_t b = *bitmap;
592 for (j = 0; j < font->fontwidth; j++, b <<= 1)
593 *buf++ = (b & 0x80) ? fg : bg;
594 }
595 }
596
597 void
598 gsfb_dma_kick(paddr_t addr, size_t size)
599 {
600 /* Wait for previous DMA request complete */
601 while (_reg_read_4(D2_QWC_REG))
602 ;
603
604 /* Wait until GS FIFO empty */
605 while ((_reg_read_8(GS_S_CSR_REG) & (3 << 14)) != (1 << 14))
606 ;
607
608 /* wait for DMA complete */
609 dmac_bus_poll(D_CH2_GIF);
610
611 /* transfer addr */
612 _reg_write_4(D2_MADR_REG, addr);
613 /* transfer data size (unit qword) */
614 _reg_write_4(D2_QWC_REG, bytetoqwc(size));
615
616 /* kick DMA (normal-mode) */
617 dmac_chcr_write(D_CH2_GIF, D_CHCR_STR);
618 }
619
620 #ifdef GSFB_DEBUG_MONITOR
621 void
622 __gsfb_print(int window, const char *fmt, ...)
623 {
624 const struct _gsfb_debug_window *win;
625 int i, s, x, y, n, a;
626 u_int c;
627 va_list ap;
628
629 if (!gsfb.initialized)
630 return;
631
632 s = _intr_suspend();
633 win = &_gsfb_debug_window[window];
634 x = 0;
635 y = win->start;
636 n = win->nrow * 80;
637 a = win->attr;
638
639 va_start(ap, fmt);
640 vsnprintf(_gsfb_debug_buf, n, fmt, ap);
641 va_end(ap);
642
643 _gsfb_eraserows(0, y, win->nrow, a);
644
645 for (i = 0; i < n &&
646 (c = (u_int)_gsfb_debug_buf[i] & 0x7f) != 0; i++) {
647 if (c == '\n')
648 x = 0, y++;
649 else
650 _gsfb_putchar(0, y, x++, c, a);
651 }
652
653 _intr_resume(s);
654 }
655
656 void
657 __gsfb_print_hex(int a0, int a1, int a2, int a3)
658 {
659 __gsfb_print(2, "a0=%08x a1=%08x a2=%08x a3=%08x",
660 a0, a1, a2, a3);
661 }
662 #endif /* GSFB_DEBUG_MONITOR */
663