gsfb.c revision 1.13 1 /* $NetBSD: gsfb.c,v 1.13 2005/12/24 23:24:01 perry 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.13 2005/12/24 23:24:01 perry 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 - 1) << 4) & 0xffff) |
404 (((y + h - 1) << 20) & 0xffff0000);
405 }
406
407 int
408 _gsfb_mapchar(void *cookie, int c, unsigned int *cp)
409 {
410 struct wsdisplay_font *font = gsfb.font;
411
412 if (font->encoding != WSDISPLAY_FONTENC_ISO)
413 if ((c = wsfont_map_unichar(font, c)) < 0)
414 goto nomap;
415
416 if (c < font->firstchar || c >= font->firstchar + font->numchars)
417 goto nomap;
418
419 *cp = c;
420 return (5);
421
422 nomap:
423 *cp = ' ';
424 return (0);
425 }
426
427 void
428 _gsfb_putchar(void *cookie, int row, int col, u_int uc, long attr)
429 {
430 paddr_t paddr = MIPS_KSEG0_TO_PHYS(gsfb_load_cmd_8x16_psmct32);
431 u_int32_t *buf = (void *)MIPS_PHYS_TO_KSEG1(paddr);
432 struct wsdisplay_font *font = gsfb.font;
433
434 /* copy font data to DMA region */
435 gsfb_font_expand_psmct32(font, uc, attr, &buf[FONT_SCRATCH_BASE]);
436
437 /* set destination position */
438 TRXPOS_DXY(buf, col * font->fontwidth, row * font->fontheight);
439
440 /* kick to GIF */
441 gsfb_dma_kick(paddr, sizeof gsfb_load_cmd_8x16_psmct32);
442 }
443
444 void
445 _gsfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
446 {
447 paddr_t paddr = MIPS_KSEG0_TO_PHYS(gsfb_copy_cmd_8x16);
448 u_int32_t *cmd = (void *)MIPS_PHYS_TO_KSEG1(paddr);
449 int y = gsfb.font->fontheight * row;
450 int w = gsfb.font->fontwidth;
451 int i;
452
453 if (dstcol > srccol) {
454 for (i = ncols - 1; i >= 0; i--) {
455 TRXPOS_DXY_SXY(cmd, (dstcol + i) * w, y, (srccol + i) * w, y);
456 gsfb_dma_kick(paddr, sizeof gsfb_copy_cmd_8x16);
457 }
458 } else {
459 for (i = 0; i < ncols; i++) {
460 TRXPOS_DXY_SXY(cmd, (dstcol + i) * w, y, (srccol + i) * w, y);
461 gsfb_dma_kick(paddr, sizeof gsfb_copy_cmd_8x16);
462 }
463 }
464 }
465
466 void
467 _gsfb_erasecols(void *cookie, int row, int startcol, int ncols, long attr)
468 {
469 int i;
470
471 for (i = 0; i < ncols; i++)
472 _gsfb_putchar(cookie, row, startcol + i, ' ', attr);
473 }
474
475 void
476 _gsfb_copyrows(void *cookie, int src, int dst, int num)
477 {
478 paddr_t paddr = MIPS_KSEG0_TO_PHYS(gsfb_scroll_cmd_640x16);
479 u_int32_t *cmd = (void *)MIPS_PHYS_TO_KSEG1(paddr);
480 int i;
481 int h = gsfb.font->fontheight;
482
483 if (dst > src) {
484 for (i = num - 1; i >= 0; i--) {
485 TRXPOS_SY_DY(cmd, (src + i) * h, (dst + i) * h);
486 gsfb_dma_kick(paddr, sizeof gsfb_scroll_cmd_640x16);
487 }
488 } else {
489 for (i = 0; i < num; i++) {
490 TRXPOS_SY_DY(cmd, (src + i) * h, (dst + i) * h);
491 gsfb_dma_kick(paddr, sizeof gsfb_scroll_cmd_640x16);
492 }
493 }
494 }
495
496 void
497 _gsfb_eraserows(void *cookie, int row, int nrow, long attr)
498 {
499 int i, j;
500
501 for (j = 0; j < nrow; j++)
502 for (i = 0; i < gsfb.screen->ncols; i++)
503 _gsfb_putchar(cookie, row + j, i, ' ', attr);
504 }
505
506 int
507 _gsfb_allocattr(void *cookie, int fg, int bg, int flags, long *attr)
508 {
509
510 if ((flags & WSATTR_BLINK) != 0)
511 return (EINVAL);
512
513 if ((flags & WSATTR_WSCOLORS) == 0) {
514 fg = WSCOL_WHITE;
515 bg = WSCOL_BLACK;
516 }
517
518 if ((flags & WSATTR_HILIT) != 0)
519 fg += 8;
520
521 flags = (flags & WSATTR_UNDERLINE) ? 1 : 0;
522
523
524 *attr = ATTR_BG_SET(bg) | ATTR_FG_SET(fg) | flags;
525
526 return (0);
527 }
528
529 int
530 _gsfb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l)
531 {
532
533 return (EPASSTHROUGH); /* Inappropriate ioctl for device */
534 }
535
536 paddr_t
537 _gsfb_mmap(void *v, off_t offset, int prot)
538 {
539
540 return (-1); /* can't mmap */
541 }
542
543 int
544 _gsfb_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
545 int *curxp, int *curyp, long *attrp)
546 {
547
548 *attrp = ATTR_BG_SET(WSCOL_BLACK) | ATTR_FG_SET(WSCOL_WHITE);
549
550 return (0);
551 }
552
553 void
554 _gsfb_free_screen(void *v, void *cookie)
555 {
556 }
557
558 int
559 _gsfb_show_screen(void *v, void *cookie, int waitok,
560 void (*cb)(void *, int, int), void *cbarg)
561 {
562
563 return (0);
564 }
565
566 void
567 _gsfb_pollc(void *v, int on)
568 {
569
570 }
571
572 /*
573 * font expansion
574 * PSMCT32 only
575 */
576 void
577 gsfb_font_expand_psmct32(const struct wsdisplay_font *font, u_int c, long attr,
578 u_int32_t *buf)
579 {
580 u_int32_t fg, bg;
581 u_int8_t *bitmap;
582 int i, j;
583
584 KDASSERT(((u_int32_t)buf & 15) == 0);
585
586 fg = gsfb_ansi_psmct32[ATTR_FG_GET(attr)];
587 bg = gsfb_ansi_psmct32[ATTR_BG_GET(attr)];
588
589 bitmap = (u_int8_t *)font->data + (c - font->firstchar) *
590 font->fontheight * font->stride;
591 for (i = 0; i < font->fontheight; i++, bitmap++) {
592 u_int32_t b = *bitmap;
593 for (j = 0; j < font->fontwidth; j++, b <<= 1)
594 *buf++ = (b & 0x80) ? fg : bg;
595 }
596 }
597
598 void
599 gsfb_dma_kick(paddr_t addr, size_t size)
600 {
601 /* Wait for previous DMA request complete */
602 while (_reg_read_4(D2_QWC_REG))
603 ;
604
605 /* Wait until GS FIFO empty */
606 while ((_reg_read_8(GS_S_CSR_REG) & (3 << 14)) != (1 << 14))
607 ;
608
609 /* wait for DMA complete */
610 dmac_bus_poll(D_CH2_GIF);
611
612 /* transfer addr */
613 _reg_write_4(D2_MADR_REG, addr);
614 /* transfer data size (unit qword) */
615 _reg_write_4(D2_QWC_REG, bytetoqwc(size));
616
617 /* kick DMA (normal-mode) */
618 dmac_chcr_write(D_CH2_GIF, D_CHCR_STR);
619 }
620
621 #ifdef GSFB_DEBUG_MONITOR
622 void
623 __gsfb_print(int window, const char *fmt, ...)
624 {
625 const struct _gsfb_debug_window *win;
626 int i, s, x, y, n, a;
627 u_int c;
628 va_list ap;
629
630 if (!gsfb.initialized)
631 return;
632
633 s = _intr_suspend();
634 win = &_gsfb_debug_window[window];
635 x = 0;
636 y = win->start;
637 n = win->nrow * 80;
638 a = win->attr;
639
640 va_start(ap, fmt);
641 vsnprintf(_gsfb_debug_buf, n, fmt, ap);
642 va_end(ap);
643
644 _gsfb_eraserows(0, y, win->nrow, a);
645
646 for (i = 0; i < n &&
647 (c = (u_int)_gsfb_debug_buf[i] & 0x7f) != 0; i++) {
648 if (c == '\n')
649 x = 0, y++;
650 else
651 _gsfb_putchar(0, y, x++, c, a);
652 }
653
654 _intr_resume(s);
655 }
656
657 void
658 __gsfb_print_hex(int a0, int a1, int a2, int a3)
659 {
660 __gsfb_print(2, "a0=%08x a1=%08x a2=%08x a3=%08x",
661 a0, a1, a2, a3);
662 }
663 #endif /* GSFB_DEBUG_MONITOR */
664