2 * Copyright (c) 2011-2014 Nathan Whitehorn
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/sysctl.h>
34 #include <sys/limits.h>
42 #include <machine/platform.h>
43 #include <machine/pmap.h>
45 #include <dev/vt/vt.h>
46 #include <dev/vt/hw/fb/vt_fb.h>
47 #include <dev/vt/colors/vt_termcolors.h>
49 #include "ps3-hvcall.h"
51 #define PS3FB_SIZE (4*1024*1024)
53 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET 0x0100
54 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC 0x0101
55 #define L1GPU_DISPLAY_SYNC_HSYNC 1
56 #define L1GPU_DISPLAY_SYNC_VSYNC 2
57 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP 0x0102
59 static vd_init_t ps3fb_init;
60 static vd_probe_t ps3fb_probe;
61 void ps3fb_remap(void);
64 struct fb_info fb_info;
67 uint64_t sc_fbcontext;
68 uint64_t sc_dma_control;
69 uint64_t sc_driver_info;
71 uint64_t sc_reports_size;
74 static struct vt_driver vt_ps3fb_driver = {
76 .vd_probe = ps3fb_probe,
77 .vd_init = ps3fb_init,
78 .vd_blank = vt_fb_blank,
79 .vd_bitbltchr = vt_fb_bitbltchr,
80 .vd_maskbitbltchr = vt_fb_maskbitbltchr,
81 /* Better than VGA, but still generic driver. */
82 .vd_priority = VD_PRIORITY_GENERIC + 1,
85 VT_DRIVER_DECLARE(vt_ps3fb, vt_ps3fb_driver);
86 static struct ps3fb_softc ps3fb_softc;
89 ps3fb_probe(struct vt_device *vd)
91 struct ps3fb_softc *sc;
99 TUNABLE_INT_FETCH("hw.syscons.disable", &disable);
106 root = OF_finddevice("/");
107 if (OF_getprop(root, "compatible", compatible, sizeof(compatible)) <= 0)
110 if (strncmp(compatible, "sony,ps3", sizeof(compatible)) != 0)
113 TUNABLE_STR_FETCH("hw.platform", compatible, sizeof(compatible));
114 if (strcmp(compatible, "ps3") != 0)
118 return (CN_INTERNAL);
124 struct ps3fb_softc *sc;
125 vm_offset_t va, fb_paddr;
132 lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET,
134 lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET,
136 lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
137 0,L1GPU_DISPLAY_SYNC_VSYNC,0,0);
138 lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
139 1,L1GPU_DISPLAY_SYNC_VSYNC,0,0);
140 lv1_gpu_memory_allocate(PS3FB_SIZE, 0, 0, 0, 0, &sc->sc_fbhandle,
142 lv1_gpu_context_allocate(sc->sc_fbhandle, 0, &sc->sc_fbcontext,
143 &sc->sc_dma_control, &sc->sc_driver_info, &sc->sc_reports,
144 &sc->sc_reports_size);
146 lv1_gpu_context_attribute(sc->sc_fbcontext,
147 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 0, 0, 0, 0);
148 lv1_gpu_context_attribute(sc->sc_fbcontext,
149 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0);
151 sc->fb_info.fb_pbase = fb_paddr;
152 for (va = 0; va < PS3FB_SIZE; va += PAGE_SIZE)
153 pmap_kenter_attr(0x10000000 + va, fb_paddr + va,
154 VM_MEMATTR_WRITE_COMBINING);
158 ps3fb_init(struct vt_device *vd)
160 struct ps3fb_softc *sc;
163 vd->vd_softc = sc = &ps3fb_softc;
165 /* XXX: get from HV repository */
166 sc->fb_info.fb_depth = 32;
167 sc->fb_info.fb_height = 480;
168 sc->fb_info.fb_width = 720;
169 sc->fb_info.fb_stride = sc->fb_info.fb_width*4;
170 sc->fb_info.fb_size = sc->fb_info.fb_height * sc->fb_info.fb_stride;
171 sc->fb_info.fb_bpp = sc->fb_info.fb_stride / sc->fb_info.fb_width * 8;
174 * The loader puts the FB at 0x10000000, so use that for now.
177 sc->fb_info.fb_vbase = 0x10000000;
179 /* 32-bit VGA palette */
180 vt_generate_vga_palette(sc->fb_info.fb_cmap, COLOR_FORMAT_RGB,
181 255, 16, 255, 8, 255, 0);
183 /* Set correct graphics context */
184 lv1_gpu_context_attribute(sc->sc_fbcontext,
185 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 0, 0, 0, 0);
186 lv1_gpu_context_attribute(sc->sc_fbcontext,
187 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0);
189 fb_probe(&sc->fb_info);
192 /* Clear the screen. */
193 vt_fb_blank(vd, TC_BLACK);
195 return (CN_INTERNAL);