]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/powerpc/ps3/ps3_syscons.c
Use the new insecure-lan-zones option instead of listing each AS112 zone
[FreeBSD/FreeBSD.git] / sys / powerpc / ps3 / ps3_syscons.c
1 /*-
2  * Copyright (c) 2011-2014 Nathan Whitehorn
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/kernel.h>
33 #include <sys/sysctl.h>
34 #include <sys/limits.h>
35 #include <sys/conf.h>
36 #include <sys/cons.h>
37 #include <sys/fbio.h>
38
39 #include <vm/vm.h>
40 #include <vm/pmap.h>
41
42 #include <machine/platform.h>
43 #include <machine/pmap.h>
44
45 #include <dev/ofw/openfirm.h>
46 #include <dev/vt/vt.h>
47 #include <dev/vt/hw/fb/vt_fb.h>
48 #include <dev/vt/colors/vt_termcolors.h>
49
50 #include "ps3-hvcall.h"
51
52 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET        0x0100
53 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC            0x0101
54 #define  L1GPU_DISPLAY_SYNC_HSYNC                       1
55 #define  L1GPU_DISPLAY_SYNC_VSYNC                       2
56 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP            0x0102
57
58 static vd_init_t ps3fb_init;
59 static vd_probe_t ps3fb_probe;
60 void ps3fb_remap(void);
61
62 struct ps3fb_softc {
63         struct fb_info  fb_info;
64
65         uint64_t        sc_fbhandle;
66         uint64_t        sc_fbcontext;
67         uint64_t        sc_dma_control;
68         uint64_t        sc_driver_info;
69         uint64_t        sc_reports;
70         uint64_t        sc_reports_size;
71 };
72
73 static struct vt_driver vt_ps3fb_driver = {
74         .vd_name = "ps3fb",
75         .vd_probe = ps3fb_probe,
76         .vd_init = ps3fb_init,
77         .vd_blank = vt_fb_blank,
78         .vd_bitblt_text = vt_fb_bitblt_text,
79         .vd_bitblt_bmp = vt_fb_bitblt_bitmap,
80         .vd_drawrect = vt_fb_drawrect,
81         .vd_setpixel = vt_fb_setpixel,
82         .vd_fb_ioctl = vt_fb_ioctl,
83         .vd_fb_mmap = vt_fb_mmap,
84         /* Better than VGA, but still generic driver. */
85         .vd_priority = VD_PRIORITY_GENERIC + 1,
86 };
87
88 VT_DRIVER_DECLARE(vt_ps3fb, vt_ps3fb_driver);
89 static struct ps3fb_softc ps3fb_softc;
90
91 static int
92 ps3fb_probe(struct vt_device *vd)
93 {
94         struct ps3fb_softc *sc;
95         int disable;
96         char compatible[64];
97         phandle_t root;
98
99         disable = 0;
100         TUNABLE_INT_FETCH("hw.syscons.disable", &disable);
101         if (disable != 0)
102                 return (0);
103
104         sc = &ps3fb_softc;
105
106         TUNABLE_STR_FETCH("hw.platform", compatible, sizeof(compatible));
107         if (strcmp(compatible, "ps3") == 0)
108                 return (CN_INTERNAL);
109
110         root = OF_finddevice("/");
111         if (OF_getprop(root, "compatible", compatible, sizeof(compatible)) <= 0)
112                 return (CN_DEAD);
113         
114         if (strncmp(compatible, "sony,ps3", sizeof(compatible)) != 0)
115                 return (CN_DEAD);
116
117         return (CN_INTERNAL);
118 }
119
120 void
121 ps3fb_remap(void)
122 {
123         struct ps3fb_softc *sc;
124         vm_offset_t va, fb_paddr;
125
126         sc = &ps3fb_softc;
127
128         lv1_gpu_close();
129         lv1_gpu_open(0);
130
131         lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET,
132             0,0,0,0);
133         lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET,
134             0,0,1,0);
135         lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
136             0,L1GPU_DISPLAY_SYNC_VSYNC,0,0);
137         lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
138             1,L1GPU_DISPLAY_SYNC_VSYNC,0,0);
139         lv1_gpu_memory_allocate(roundup2(sc->fb_info.fb_size, 1024*1024),
140             0, 0, 0, 0, &sc->sc_fbhandle, &fb_paddr);
141         lv1_gpu_context_allocate(sc->sc_fbhandle, 0, &sc->sc_fbcontext,
142             &sc->sc_dma_control, &sc->sc_driver_info, &sc->sc_reports,
143             &sc->sc_reports_size);
144
145         lv1_gpu_context_attribute(sc->sc_fbcontext,
146             L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 0, 0, 0, 0);
147         lv1_gpu_context_attribute(sc->sc_fbcontext,
148             L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0);
149
150         sc->fb_info.fb_pbase = fb_paddr;
151         for (va = 0; va < sc->fb_info.fb_size; va += PAGE_SIZE)
152                 pmap_kenter_attr(0x10000000 + va, fb_paddr + va,
153                     VM_MEMATTR_WRITE_COMBINING);
154         sc->fb_info.fb_flags &= ~FB_FLAG_NOWRITE;
155 }
156
157 static int
158 ps3fb_init(struct vt_device *vd)
159 {
160         struct ps3fb_softc *sc;
161
162         /* Init softc */
163         vd->vd_softc = sc = &ps3fb_softc;
164
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         TUNABLE_INT_FETCH("hw.ps3fb.height", &sc->fb_info.fb_height);
170         TUNABLE_INT_FETCH("hw.ps3fb.width", &sc->fb_info.fb_width);
171         sc->fb_info.fb_stride = sc->fb_info.fb_width*4;
172         sc->fb_info.fb_size = sc->fb_info.fb_height * sc->fb_info.fb_stride;
173         sc->fb_info.fb_bpp = sc->fb_info.fb_stride / sc->fb_info.fb_width * 8;
174
175         /*
176          * Arbitrarily choose address for the framebuffer
177          */
178
179         sc->fb_info.fb_vbase = 0x10000000;
180         sc->fb_info.fb_flags |= FB_FLAG_NOWRITE; /* Not available yet */
181         sc->fb_info.fb_cmsize = 16;
182
183         /* 32-bit VGA palette */
184         vt_generate_cons_palette(sc->fb_info.fb_cmap, COLOR_FORMAT_RGB,
185             255, 0, 255, 8, 255, 16);
186
187         /* Set correct graphics context */
188         lv1_gpu_context_attribute(sc->sc_fbcontext,
189             L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 0, 0, 0, 0);
190         lv1_gpu_context_attribute(sc->sc_fbcontext,
191             L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0);
192
193         vt_fb_init(vd);
194
195         return (CN_INTERNAL);
196 }
197