]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - sys/powerpc/ps3/ps3_syscons.c
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / sys / powerpc / ps3 / ps3_syscons.c
1 /*-
2  * Copyright (c) 2003 Peter Grehan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/module.h>
33 #include <sys/bus.h>
34 #include <sys/kernel.h>
35 #include <sys/sysctl.h>
36 #include <sys/limits.h>
37 #include <sys/conf.h>
38 #include <sys/cons.h>
39 #include <sys/proc.h>
40 #include <sys/fcntl.h>
41 #include <sys/malloc.h>
42 #include <sys/fbio.h>
43 #include <sys/consio.h>
44
45 #include <vm/vm.h>
46 #include <vm/pmap.h>
47
48 #include <machine/bus.h>
49 #include <machine/sc_machdep.h>
50 #include <machine/platform.h>
51 #include <machine/pmap.h>
52
53 #include <sys/rman.h>
54
55 #include <dev/fb/fbreg.h>
56 #include <dev/syscons/syscons.h>
57
58 #include "ps3-hvcall.h"
59
60 #define PS3FB_SIZE (4*1024*1024)
61
62 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET        0x0100
63 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC            0x0101
64 #define  L1GPU_DISPLAY_SYNC_HSYNC                       1
65 #define  L1GPU_DISPLAY_SYNC_VSYNC                       2
66 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP            0x0102
67
68 extern u_char dflt_font_16[];
69 extern u_char dflt_font_14[];
70 extern u_char dflt_font_8[];
71
72 static int ps3fb_configure(int flags);
73 void ps3fb_remap(void);
74
75 static vi_probe_t ps3fb_probe;
76 static vi_init_t ps3fb_init;
77 static vi_get_info_t ps3fb_get_info;
78 static vi_query_mode_t ps3fb_query_mode;
79 static vi_set_mode_t ps3fb_set_mode;
80 static vi_save_font_t ps3fb_save_font;
81 static vi_load_font_t ps3fb_load_font;
82 static vi_show_font_t ps3fb_show_font;
83 static vi_save_palette_t ps3fb_save_palette;
84 static vi_load_palette_t ps3fb_load_palette;
85 static vi_set_border_t ps3fb_set_border;
86 static vi_save_state_t ps3fb_save_state;
87 static vi_load_state_t ps3fb_load_state;
88 static vi_set_win_org_t ps3fb_set_win_org;
89 static vi_read_hw_cursor_t ps3fb_read_hw_cursor;
90 static vi_set_hw_cursor_t ps3fb_set_hw_cursor;
91 static vi_set_hw_cursor_shape_t ps3fb_set_hw_cursor_shape;
92 static vi_blank_display_t ps3fb_blank_display;
93 static vi_mmap_t ps3fb_mmap;
94 static vi_ioctl_t ps3fb_ioctl;
95 static vi_clear_t ps3fb_clear;
96 static vi_fill_rect_t ps3fb_fill_rect;
97 static vi_bitblt_t ps3fb_bitblt;
98 static vi_diag_t ps3fb_diag;
99 static vi_save_cursor_palette_t ps3fb_save_cursor_palette;
100 static vi_load_cursor_palette_t ps3fb_load_cursor_palette;
101 static vi_copy_t ps3fb_copy;
102 static vi_putp_t ps3fb_putp;
103 static vi_putc_t ps3fb_putc;
104 static vi_puts_t ps3fb_puts;
105 static vi_putm_t ps3fb_putm;
106
107 struct ps3fb_softc {
108         video_adapter_t sc_va;
109         struct cdev     *sc_si;
110         int             sc_console;
111
112         intptr_t        sc_addr;
113         int             sc_height;
114         int             sc_width;
115         int             sc_stride;
116         int             sc_ncol;
117         int             sc_nrow;
118
119         int             sc_xmargin;
120         int             sc_ymargin;
121
122         u_char          *sc_font;
123         int             sc_font_height;
124 };
125
126 static video_switch_t ps3fbvidsw = {
127         .probe                  = ps3fb_probe,
128         .init                   = ps3fb_init,
129         .get_info               = ps3fb_get_info,
130         .query_mode             = ps3fb_query_mode,
131         .set_mode               = ps3fb_set_mode,
132         .save_font              = ps3fb_save_font,
133         .load_font              = ps3fb_load_font,
134         .show_font              = ps3fb_show_font,
135         .save_palette           = ps3fb_save_palette,
136         .load_palette           = ps3fb_load_palette,
137         .set_border             = ps3fb_set_border,
138         .save_state             = ps3fb_save_state,
139         .load_state             = ps3fb_load_state,
140         .set_win_org            = ps3fb_set_win_org,
141         .read_hw_cursor         = ps3fb_read_hw_cursor,
142         .set_hw_cursor          = ps3fb_set_hw_cursor,
143         .set_hw_cursor_shape    = ps3fb_set_hw_cursor_shape,
144         .blank_display          = ps3fb_blank_display,
145         .mmap                   = ps3fb_mmap,
146         .ioctl                  = ps3fb_ioctl,
147         .clear                  = ps3fb_clear,
148         .fill_rect              = ps3fb_fill_rect,
149         .bitblt                 = ps3fb_bitblt,
150         .diag                   = ps3fb_diag,
151         .save_cursor_palette    = ps3fb_save_cursor_palette,
152         .load_cursor_palette    = ps3fb_load_cursor_palette,
153         .copy                   = ps3fb_copy,
154         .putp                   = ps3fb_putp,
155         .putc                   = ps3fb_putc,
156         .puts                   = ps3fb_puts,
157         .putm                   = ps3fb_putm,
158 };
159
160 VIDEO_DRIVER(ps3fb, ps3fbvidsw, ps3fb_configure);
161
162 extern sc_rndr_sw_t txtrndrsw;
163 RENDERER(ps3fb, 0, txtrndrsw, gfb_set);
164
165 RENDERER_MODULE(ps3fb, gfb_set);
166
167 /*
168  * Define the iso6429-1983 colormap
169  */
170 static struct {
171         uint8_t red;
172         uint8_t green;
173         uint8_t blue;
174 } ps3fb_cmap[16] = {            /*  #     R    G    B   Color */
175                                 /*  -     -    -    -   ----- */
176         { 0x00, 0x00, 0x00 },   /*  0     0    0    0   Black */
177         { 0x00, 0x00, 0xaa },   /*  1     0    0  2/3   Blue  */
178         { 0x00, 0xaa, 0x00 },   /*  2     0  2/3    0   Green */
179         { 0x00, 0xaa, 0xaa },   /*  3     0  2/3  2/3   Cyan  */
180         { 0xaa, 0x00, 0x00 },   /*  4   2/3    0    0   Red   */
181         { 0xaa, 0x00, 0xaa },   /*  5   2/3    0  2/3   Magenta */
182         { 0xaa, 0x55, 0x00 },   /*  6   2/3  1/3    0   Brown */
183         { 0xaa, 0xaa, 0xaa },   /*  7   2/3  2/3  2/3   White */
184         { 0x55, 0x55, 0x55 },   /*  8   1/3  1/3  1/3   Gray  */
185         { 0x55, 0x55, 0xff },   /*  9   1/3  1/3    1   Bright Blue  */
186         { 0x55, 0xff, 0x55 },   /* 10   1/3    1  1/3   Bright Green */
187         { 0x55, 0xff, 0xff },   /* 11   1/3    1    1   Bright Cyan  */
188         { 0xff, 0x55, 0x55 },   /* 12     1  1/3  1/3   Bright Red   */
189         { 0xff, 0x55, 0xff },   /* 13     1  1/3    1   Bright Magenta */
190         { 0xff, 0xff, 0x80 },   /* 14     1    1  1/3   Bright Yellow */
191         { 0xff, 0xff, 0xff }    /* 15     1    1    1   Bright White */
192 };
193
194 #define TODO    printf("%s: unimplemented\n", __func__)
195
196 static u_int16_t ps3fb_static_window[ROW*COL];
197
198 static struct ps3fb_softc ps3fb_softc;
199
200 static __inline int
201 ps3fb_background(uint8_t attr)
202 {
203         return (attr >> 4);
204 }
205
206 static __inline int
207 ps3fb_foreground(uint8_t attr)
208 {
209         return (attr & 0x0f);
210 }
211
212 static u_int
213 ps3fb_pix32(int attr)
214 {
215         u_int retval;
216
217         retval = (ps3fb_cmap[attr].red  << 16) |
218                 (ps3fb_cmap[attr].green << 8) |
219                 ps3fb_cmap[attr].blue;
220
221         return (retval);
222 }
223
224 static int
225 ps3fb_configure(int flags)
226 {
227         struct ps3fb_softc *sc;
228         int disable;
229         char compatible[64];
230 #if 0
231         phandle_t root;
232 #endif
233         static int done = 0;
234
235         disable = 0;
236         TUNABLE_INT_FETCH("hw.syscons.disable", &disable);
237         if (disable != 0)
238                 return (0);
239
240         if (done != 0)
241                 return (0);
242         done = 1;
243
244         sc = &ps3fb_softc;
245
246 #if 0
247         root = OF_finddevice("/");
248         if (OF_getprop(root, "compatible", compatible, sizeof(compatible)) <= 0)
249                 return (0);
250         
251         if (strncmp(compatible, "sony,ps3", sizeof(compatible)) != 0)
252                 return (0);
253 #else
254         TUNABLE_STR_FETCH("hw.platform", compatible, sizeof(compatible));
255         if (strcmp(compatible, "ps3") != 0)
256                 return (0);
257 #endif
258
259         sc->sc_console = 1;
260
261         /* XXX: get from HV repository */
262         sc->sc_height = 480;
263         sc->sc_width = 720;
264         sc->sc_stride = sc->sc_width*4;
265
266         /*
267          * The loader puts the FB at 0x10000000, so use that for now.
268          */
269
270         sc->sc_addr = 0x10000000;
271         ps3fb_init(0, &sc->sc_va, 0);
272
273         return (0);
274 }
275
276 void
277 ps3fb_remap(void)
278 {
279         vm_offset_t va, fb_paddr;
280         uint64_t fbhandle, fbcontext;
281
282         lv1_gpu_close();
283         lv1_gpu_open(0);
284
285         lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET,
286             0,0,0,0);
287         lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET,
288             0,0,1,0);
289         lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
290             0,L1GPU_DISPLAY_SYNC_VSYNC,0,0);
291         lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
292             1,L1GPU_DISPLAY_SYNC_VSYNC,0,0);
293         lv1_gpu_memory_allocate(PS3FB_SIZE, 0, 0, 0, 0, &fbhandle, &fb_paddr);
294         lv1_gpu_context_allocate(fbhandle, 0, &fbcontext);
295
296         lv1_gpu_context_attribute(fbcontext,
297             L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 0, 0, 0, 0);
298         lv1_gpu_context_attribute(fbcontext,
299             L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0);
300
301         for (va = 0; va < PS3FB_SIZE; va += PAGE_SIZE)
302                 pmap_kenter_attr(0x10000000 + va, fb_paddr + va,
303                     VM_MEMATTR_WRITE_COMBINING); 
304 }
305
306 static int
307 ps3fb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
308 {
309         TODO;
310         return (0);
311 }
312
313 static int
314 ps3fb_init(int unit, video_adapter_t *adp, int flags)
315 {
316         struct ps3fb_softc *sc;
317         video_info_t *vi;
318         int cxborder, cyborder;
319         int font_height;
320
321         sc = (struct ps3fb_softc *)adp;
322         vi = &adp->va_info;
323
324         vid_init_struct(adp, "ps3fb", -1, unit);
325
326         /* The default font size can be overridden by loader */
327         font_height = 16;
328         TUNABLE_INT_FETCH("hw.syscons.fsize", &font_height);
329         if (font_height == 8) {
330                 sc->sc_font = dflt_font_8;
331                 sc->sc_font_height = 8;
332         } else if (font_height == 14) {
333                 sc->sc_font = dflt_font_14;
334                 sc->sc_font_height = 14;
335         } else {
336                 /* default is 8x16 */
337                 sc->sc_font = dflt_font_16;
338                 sc->sc_font_height = 16;
339         }
340
341         /* The user can set a border in chars - default is 1 char width */
342         cxborder = 8;
343         cyborder = 2;
344         TUNABLE_INT_FETCH("hw.syscons.xborder", &cxborder);
345         TUNABLE_INT_FETCH("hw.syscons.yborder", &cyborder);
346
347         vi->vi_cheight = sc->sc_font_height;
348         vi->vi_width = sc->sc_width/8 - 2*cxborder;
349         vi->vi_height = sc->sc_height/sc->sc_font_height - 2*cyborder;
350         vi->vi_cwidth = 8;
351
352         /*
353          * Clamp width/height to syscons maximums
354          */
355         if (vi->vi_width > COL)
356                 vi->vi_width = COL;
357         if (vi->vi_height > ROW)
358                 vi->vi_height = ROW;
359
360         sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
361         sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight))/2;
362
363         /*
364          * Avoid huge amounts of conditional code in syscons by
365          * defining a dummy h/w text display buffer.
366          */
367         adp->va_window = (vm_offset_t) ps3fb_static_window;
368
369         /*
370          * Enable future font-loading and flag color support, as well as 
371          * adding V_ADP_MODECHANGE so that we ps3fb_set_mode() gets called
372          * when the X server shuts down. This enables us to get the console
373          * back when X disappears.
374          */
375         adp->va_flags |= V_ADP_FONT | V_ADP_COLOR | V_ADP_MODECHANGE;
376
377         ps3fb_set_mode(&sc->sc_va, 0);
378         vid_register(&sc->sc_va);
379
380         return (0);
381 }
382
383 static int
384 ps3fb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
385 {
386         bcopy(&adp->va_info, info, sizeof(*info));
387         return (0);
388 }
389
390 static int
391 ps3fb_query_mode(video_adapter_t *adp, video_info_t *info)
392 {
393         TODO;
394         return (0);
395 }
396
397 static int
398 ps3fb_set_mode(video_adapter_t *adp, int mode)
399 {
400         struct ps3fb_softc *sc;
401
402         sc = (struct ps3fb_softc *)adp;
403
404         /* XXX: no real mode setting at the moment */
405
406         ps3fb_blank_display(&sc->sc_va, V_DISPLAY_ON);
407
408         return (0);
409 }
410
411 static int
412 ps3fb_save_font(video_adapter_t *adp, int page, int size, int width,
413     u_char *data, int c, int count)
414 {
415         TODO;
416         return (0);
417 }
418
419 static int
420 ps3fb_load_font(video_adapter_t *adp, int page, int size, int width,
421     u_char *data, int c, int count)
422 {
423         struct ps3fb_softc *sc;
424
425         sc = (struct ps3fb_softc *)adp;
426
427         /*
428          * syscons code has already determined that current width/height
429          * are unchanged for this new font
430          */
431         sc->sc_font = data;
432         return (0);
433 }
434
435 static int
436 ps3fb_show_font(video_adapter_t *adp, int page)
437 {
438
439         return (0);
440 }
441
442 static int
443 ps3fb_save_palette(video_adapter_t *adp, u_char *palette)
444 {
445         /* TODO; */
446         return (0);
447 }
448
449 static int
450 ps3fb_load_palette(video_adapter_t *adp, u_char *palette)
451 {
452         /* TODO; */
453         return (0);
454 }
455
456 static int
457 ps3fb_set_border(video_adapter_t *adp, int border)
458 {
459         /* XXX Be lazy for now and blank entire screen */
460         return (ps3fb_blank_display(adp, border));
461 }
462
463 static int
464 ps3fb_save_state(video_adapter_t *adp, void *p, size_t size)
465 {
466         TODO;
467         return (0);
468 }
469
470 static int
471 ps3fb_load_state(video_adapter_t *adp, void *p)
472 {
473         TODO;
474         return (0);
475 }
476
477 static int
478 ps3fb_set_win_org(video_adapter_t *adp, off_t offset)
479 {
480         TODO;
481         return (0);
482 }
483
484 static int
485 ps3fb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
486 {
487         *col = 0;
488         *row = 0;
489
490         return (0);
491 }
492
493 static int
494 ps3fb_set_hw_cursor(video_adapter_t *adp, int col, int row)
495 {
496
497         return (0);
498 }
499
500 static int
501 ps3fb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
502     int celsize, int blink)
503 {
504         return (0);
505 }
506
507 static int
508 ps3fb_blank_display(video_adapter_t *adp, int mode)
509 {
510         struct ps3fb_softc *sc;
511         int i;
512         uint32_t *addr;
513
514         sc = (struct ps3fb_softc *)adp;
515         addr = (uint32_t *) sc->sc_addr;
516
517         for (i = 0; i < (sc->sc_stride/4)*sc->sc_height; i++)
518                 *(addr + i) = ps3fb_pix32(ps3fb_background(SC_NORM_ATTR));
519
520         return (0);
521 }
522
523 static int
524 ps3fb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
525     int prot, vm_memattr_t *memattr)
526 {
527         struct ps3fb_softc *sc;
528
529         sc = (struct ps3fb_softc *)adp;
530
531         /*
532          * This might be a legacy VGA mem request: if so, just point it at the
533          * framebuffer, since it shouldn't be touched
534          */
535         if (offset < sc->sc_stride*sc->sc_height) {
536                 *paddr = sc->sc_addr + offset;
537                 return (0);
538         }
539
540         return (EINVAL);
541 }
542
543 static int
544 ps3fb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
545 {
546
547         return (0);
548 }
549
550 static int
551 ps3fb_clear(video_adapter_t *adp)
552 {
553         TODO;
554         return (0);
555 }
556
557 static int
558 ps3fb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
559 {
560         TODO;
561         return (0);
562 }
563
564 static int
565 ps3fb_bitblt(video_adapter_t *adp, ...)
566 {
567         TODO;
568         return (0);
569 }
570
571 static int
572 ps3fb_diag(video_adapter_t *adp, int level)
573 {
574         TODO;
575         return (0);
576 }
577
578 static int
579 ps3fb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
580 {
581         TODO;
582         return (0);
583 }
584
585 static int
586 ps3fb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
587 {
588         TODO;
589         return (0);
590 }
591
592 static int
593 ps3fb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
594 {
595         TODO;
596         return (0);
597 }
598
599 static int
600 ps3fb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
601     int size, int bpp, int bit_ltor, int byte_ltor)
602 {
603         TODO;
604         return (0);
605 }
606
607 static int
608 ps3fb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
609 {
610         struct ps3fb_softc *sc;
611         int row;
612         int col;
613         int i, j, k;
614         uint32_t *addr;
615         u_char *p;
616
617         sc = (struct ps3fb_softc *)adp;
618         row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
619         col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
620         p = sc->sc_font + c*sc->sc_font_height;
621         addr = (uint32_t *)sc->sc_addr
622                 + (row + sc->sc_ymargin)*(sc->sc_stride/4)
623                 + col + sc->sc_xmargin;
624
625         for (i = 0; i < sc->sc_font_height; i++) {
626                 for (j = 0, k = 7; j < 8; j++, k--) {
627                         if ((p[i] & (1 << k)) == 0)
628                                 *(addr + j) = ps3fb_pix32(ps3fb_background(a));
629                         else
630                                 *(addr + j) = ps3fb_pix32(ps3fb_foreground(a));
631                 }
632                 addr += (sc->sc_stride/4);
633         }
634
635         return (0);
636 }
637
638 static int
639 ps3fb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
640 {
641         int i;
642
643         for (i = 0; i < len; i++) {
644                 ps3fb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
645         }
646         return (0);
647 }
648
649 static int
650 ps3fb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
651     uint32_t pixel_mask, int size, int width)
652 {
653         struct ps3fb_softc *sc;
654         int i, j, k;
655         uint32_t fg, bg;
656         uint32_t *addr;
657
658         sc = (struct ps3fb_softc *)adp;
659         addr = (uint32_t *)sc->sc_addr
660                 + (y + sc->sc_ymargin)*(sc->sc_stride/4)
661                 + x + sc->sc_xmargin;
662
663         fg = ps3fb_pix32(ps3fb_foreground(SC_NORM_ATTR));
664         bg = ps3fb_pix32(ps3fb_background(SC_NORM_ATTR));
665
666         for (i = 0; i < size && i+y < sc->sc_height - 2*sc->sc_ymargin; i++) {
667                 for (j = 0, k = width; j < 8; j++, k--) {
668                         if (x + j >= sc->sc_width - 2*sc->sc_xmargin)
669                                 continue;
670
671                         if (pixel_image[i] & (1 << k))
672                                 *(addr + j) = (*(addr + j) == fg) ? bg : fg;
673                 }
674                 addr += (sc->sc_stride/4);
675         }
676
677         return (0);
678 }
679
680 /*
681  * Define the syscons nexus device attachment
682  */
683 static void
684 ps3fb_scidentify(driver_t *driver, device_t parent)
685 {
686         device_t child;
687
688         /*
689          * Add with a priority guaranteed to make it last on
690          * the device list
691          */
692         if (strcmp(installed_platform(), "ps3") == 0)
693                 child = BUS_ADD_CHILD(parent, INT_MAX, SC_DRIVER_NAME, 0);
694 }
695
696 static int
697 ps3fb_scprobe(device_t dev)
698 {
699         int error;
700
701         if (strcmp(installed_platform(), "ps3") != 0)
702                 return (ENXIO);
703
704         device_set_desc(dev, "System console");
705
706         error = sc_probe_unit(device_get_unit(dev), 
707             device_get_flags(dev) | SC_AUTODETECT_KBD);
708         if (error != 0)
709                 return (error);
710
711         /* This is a fake device, so make sure we added it ourselves */
712         return (BUS_PROBE_NOWILDCARD);
713 }
714
715 static int
716 ps3fb_scattach(device_t dev)
717 {
718         return (sc_attach_unit(device_get_unit(dev),
719             device_get_flags(dev) | SC_AUTODETECT_KBD));
720 }
721
722 static device_method_t ps3fb_sc_methods[] = {
723         DEVMETHOD(device_identify,      ps3fb_scidentify),
724         DEVMETHOD(device_probe,         ps3fb_scprobe),
725         DEVMETHOD(device_attach,        ps3fb_scattach),
726         { 0, 0 }
727 };
728
729 static driver_t ps3fb_sc_driver = {
730         SC_DRIVER_NAME,
731         ps3fb_sc_methods,
732         sizeof(sc_softc_t),
733 };
734
735 static devclass_t       sc_devclass;
736
737 DRIVER_MODULE(sc, nexus, ps3fb_sc_driver, sc_devclass, 0, 0);
738
739 /*
740  * Define a stub keyboard driver in case one hasn't been
741  * compiled into the kernel
742  */
743 #include <sys/kbio.h>
744 #include <dev/kbd/kbdreg.h>
745
746 static int dummy_kbd_configure(int flags);
747
748 keyboard_switch_t ps3dummysw;
749
750 static int
751 dummy_kbd_configure(int flags)
752 {
753
754         return (0);
755 }
756 KEYBOARD_DRIVER(ps3dummy, ps3dummysw, dummy_kbd_configure);
757