Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/powerpc/ps3/ps3_syscons.c
39507 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause
3
*
4
* Copyright (c) 2011-2014 Nathan Whitehorn
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
* SUCH DAMAGE.
27
*/
28
29
#include <sys/param.h>
30
#include <sys/systm.h>
31
#include <sys/kernel.h>
32
#include <sys/sysctl.h>
33
#include <sys/limits.h>
34
#include <sys/conf.h>
35
#include <sys/cons.h>
36
#include <sys/fbio.h>
37
38
#include <vm/vm.h>
39
#include <vm/pmap.h>
40
41
#include <machine/platform.h>
42
43
#include <dev/ofw/openfirm.h>
44
#include <dev/vt/vt.h>
45
#include <dev/vt/hw/fb/vt_fb.h>
46
#include <dev/vt/colors/vt_termcolors.h>
47
48
#include "ps3-hvcall.h"
49
50
#define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET 0x0100
51
#define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC 0x0101
52
#define L1GPU_DISPLAY_SYNC_HSYNC 1
53
#define L1GPU_DISPLAY_SYNC_VSYNC 2
54
#define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP 0x0102
55
56
static vd_init_t ps3fb_init;
57
static vd_probe_t ps3fb_probe;
58
void ps3fb_remap(void);
59
60
struct ps3fb_softc {
61
struct fb_info fb_info;
62
63
uint64_t sc_fbhandle;
64
uint64_t sc_fbcontext;
65
uint64_t sc_dma_control;
66
uint64_t sc_driver_info;
67
uint64_t sc_reports;
68
uint64_t sc_reports_size;
69
};
70
71
static struct vt_driver vt_ps3fb_driver = {
72
.vd_name = "ps3fb",
73
.vd_probe = ps3fb_probe,
74
.vd_init = ps3fb_init,
75
.vd_blank = vt_fb_blank,
76
.vd_bitblt_text = vt_fb_bitblt_text,
77
.vd_bitblt_bmp = vt_fb_bitblt_bitmap,
78
.vd_drawrect = vt_fb_drawrect,
79
.vd_setpixel = vt_fb_setpixel,
80
.vd_fb_ioctl = vt_fb_ioctl,
81
.vd_fb_mmap = vt_fb_mmap,
82
/* Better than VGA, but still generic driver. */
83
.vd_priority = VD_PRIORITY_GENERIC + 1,
84
};
85
86
VT_DRIVER_DECLARE(vt_ps3fb, vt_ps3fb_driver);
87
static struct ps3fb_softc ps3fb_softc;
88
89
static int
90
ps3fb_probe(struct vt_device *vd)
91
{
92
int disable;
93
char compatible[64];
94
phandle_t root;
95
96
disable = 0;
97
TUNABLE_INT_FETCH("hw.syscons.disable", &disable);
98
if (disable != 0)
99
return (0);
100
101
TUNABLE_STR_FETCH("hw.platform", compatible, sizeof(compatible));
102
if (strcmp(compatible, "ps3") == 0)
103
return (CN_INTERNAL);
104
105
root = OF_finddevice("/");
106
if (OF_getprop(root, "compatible", compatible, sizeof(compatible)) <= 0)
107
return (CN_DEAD);
108
109
if (strncmp(compatible, "sony,ps3", sizeof(compatible)) != 0)
110
return (CN_DEAD);
111
112
return (CN_INTERNAL);
113
}
114
115
void
116
ps3fb_remap(void)
117
{
118
struct ps3fb_softc *sc;
119
vm_offset_t va, fb_paddr;
120
121
sc = &ps3fb_softc;
122
123
lv1_gpu_close();
124
lv1_gpu_open(0);
125
126
lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET,
127
0,0,0,0);
128
lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET,
129
0,0,1,0);
130
lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
131
0,L1GPU_DISPLAY_SYNC_VSYNC,0,0);
132
lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
133
1,L1GPU_DISPLAY_SYNC_VSYNC,0,0);
134
lv1_gpu_memory_allocate(roundup2(sc->fb_info.fb_size, 1024*1024),
135
0, 0, 0, 0, &sc->sc_fbhandle, &fb_paddr);
136
lv1_gpu_context_allocate(sc->sc_fbhandle, 0, &sc->sc_fbcontext,
137
&sc->sc_dma_control, &sc->sc_driver_info, &sc->sc_reports,
138
&sc->sc_reports_size);
139
140
lv1_gpu_context_attribute(sc->sc_fbcontext,
141
L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 0, 0, 0, 0);
142
lv1_gpu_context_attribute(sc->sc_fbcontext,
143
L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0);
144
145
sc->fb_info.fb_pbase = fb_paddr;
146
for (va = 0; va < sc->fb_info.fb_size; va += PAGE_SIZE)
147
pmap_kenter_attr(0x10000000 + va, fb_paddr + va,
148
VM_MEMATTR_WRITE_COMBINING);
149
sc->fb_info.fb_flags &= ~FB_FLAG_NOWRITE;
150
}
151
152
static int
153
ps3fb_init(struct vt_device *vd)
154
{
155
struct ps3fb_softc *sc;
156
char linux_video_mode[24];
157
int linux_video_mode_num = 0;
158
159
/* Init softc */
160
vd->vd_softc = sc = &ps3fb_softc;
161
162
sc->fb_info.fb_depth = 32;
163
sc->fb_info.fb_height = 1080;
164
sc->fb_info.fb_width = 1920;
165
166
/* See if the bootloader has passed a graphics mode to use */
167
bzero(linux_video_mode, sizeof(linux_video_mode));
168
TUNABLE_STR_FETCH("video", linux_video_mode, sizeof(linux_video_mode));
169
sscanf(linux_video_mode, "ps3fb:mode:%d", &linux_video_mode_num);
170
171
switch (linux_video_mode_num) {
172
case 1:
173
case 2:
174
sc->fb_info.fb_height = 480;
175
sc->fb_info.fb_width = 720;
176
break;
177
case 3:
178
case 8:
179
sc->fb_info.fb_height = 720;
180
sc->fb_info.fb_width = 1280;
181
break;
182
case 4:
183
case 5:
184
case 9:
185
case 10:
186
sc->fb_info.fb_height = 1080;
187
sc->fb_info.fb_width = 1920;
188
break;
189
case 6:
190
case 7:
191
sc->fb_info.fb_height = 576;
192
sc->fb_info.fb_width = 720;
193
break;
194
case 11:
195
sc->fb_info.fb_height = 768;
196
sc->fb_info.fb_width = 1024;
197
break;
198
case 12:
199
sc->fb_info.fb_height = 1024;
200
sc->fb_info.fb_width = 1280;
201
break;
202
case 13:
203
sc->fb_info.fb_height = 1200;
204
sc->fb_info.fb_width = 1920;
205
break;
206
}
207
208
/* Allow explicitly-specified values for us to override everything */
209
TUNABLE_INT_FETCH("hw.ps3fb.height", &sc->fb_info.fb_height);
210
TUNABLE_INT_FETCH("hw.ps3fb.width", &sc->fb_info.fb_width);
211
212
sc->fb_info.fb_stride = sc->fb_info.fb_width*4;
213
sc->fb_info.fb_size = sc->fb_info.fb_height * sc->fb_info.fb_stride;
214
sc->fb_info.fb_bpp = sc->fb_info.fb_stride / sc->fb_info.fb_width * 8;
215
216
/*
217
* Arbitrarily choose address for the framebuffer
218
*/
219
220
sc->fb_info.fb_vbase = 0x10000000;
221
sc->fb_info.fb_flags |= FB_FLAG_NOWRITE; /* Not available yet */
222
sc->fb_info.fb_cmsize = 16;
223
224
/* 32-bit VGA palette */
225
vt_config_cons_colors(&sc->fb_info, COLOR_FORMAT_RGB,
226
255, 16, 255, 8, 255, 0);
227
228
/* Set correct graphics context */
229
lv1_gpu_context_attribute(sc->sc_fbcontext,
230
L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 0, 0, 0, 0);
231
lv1_gpu_context_attribute(sc->sc_fbcontext,
232
L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0);
233
234
vt_fb_init(vd);
235
236
return (CN_INTERNAL);
237
}
238
239