projects/linux·blob master · refs

303 lines · 6.6 KiB

1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * PS3 platform setup routines.
4 *
5 * Copyright (C) 2006 Sony Computer Entertainment Inc.
6 * Copyright 2006 Sony Corp.
7 */
8
9#include <linux/kernel.h>
10#include <linux/delay.h>
11#include <linux/fs.h>
12#include <linux/root_dev.h>
13#include <linux/sysfs.h>
14#include <linux/console.h>
15#include <linux/export.h>
16#include <linux/memblock.h>
17#include <linux/of.h>
18
19#include <asm/machdep.h>
20#include <asm/firmware.h>
21#include <asm/time.h>
22#include <asm/iommu.h>
23#include <asm/udbg.h>
24#include <asm/lv1call.h>
25#include <asm/ps3gpu.h>
26
27#include "platform.h"
28
29#if defined(DEBUG)
30#define DBG udbg_printf
31#else
32#define DBG pr_debug
33#endif
34
35/* mutex synchronizing GPU accesses and video mode changes */
36DEFINE_MUTEX(ps3_gpu_mutex);
37EXPORT_SYMBOL_GPL(ps3_gpu_mutex);
38
39static union ps3_firmware_version ps3_firmware_version;
40static char ps3_firmware_version_str[16];
41
42void ps3_get_firmware_version(union ps3_firmware_version *v)
43{
44 *v = ps3_firmware_version;
45}
46EXPORT_SYMBOL_GPL(ps3_get_firmware_version);
47
48int ps3_compare_firmware_version(u16 major, u16 minor, u16 rev)
49{
50 union ps3_firmware_version x;
51
52 x.pad = 0;
53 x.major = major;
54 x.minor = minor;
55 x.rev = rev;
56
57 return (ps3_firmware_version.raw > x.raw) -
58 (ps3_firmware_version.raw < x.raw);
59}
60EXPORT_SYMBOL_GPL(ps3_compare_firmware_version);
61
62static void ps3_power_save(void)
63{
64 /*
65 * lv1_pause() puts the PPE thread into inactive state until an
66 * irq on an unmasked plug exists. MSR[EE] has no effect.
67 * flags: 0 = wake on DEC interrupt, 1 = ignore DEC interrupt.
68 */
69
70 lv1_pause(0);
71}
72
73static void __noreturn ps3_restart(char *cmd)
74{
75 DBG("%s:%d cmd '%s'\n", __func__, __LINE__, cmd);
76
77 smp_send_stop();
78 ps3_sys_manager_restart(); /* never returns */
79}
80
81static void ps3_power_off(void)
82{
83 DBG("%s:%d\n", __func__, __LINE__);
84
85 smp_send_stop();
86 ps3_sys_manager_power_off(); /* never returns */
87}
88
89static void __noreturn ps3_halt(void)
90{
91 DBG("%s:%d\n", __func__, __LINE__);
92
93 smp_send_stop();
94 ps3_sys_manager_halt(); /* never returns */
95}
96
97static void ps3_panic(char *str)
98{
99 DBG("%s:%d %s\n", __func__, __LINE__, str);
100
101 smp_send_stop();
102 printk("\n");
103 printk(" System does not reboot automatically.\n");
104 printk(" Please press POWER button.\n");
105 printk("\n");
106 panic_flush_kmsg_end();
107
108 while(1)
109 lv1_pause(1);
110}
111
112#if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE) || \
113 defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
114static void __init prealloc(struct ps3_prealloc *p)
115{
116 if (!p->size)
117 return;
118
119 p->address = memblock_alloc_or_panic(p->size, p->align);
120
121 printk(KERN_INFO "%s: %lu bytes at %p\n", p->name, p->size,
122 p->address);
123}
124#endif
125
126#if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE)
127struct ps3_prealloc ps3fb_videomemory = {
128 .name = "ps3fb videomemory",
129 .size = CONFIG_FB_PS3_DEFAULT_SIZE_M*1024*1024,
130 .align = 1024*1024 /* the GPU requires 1 MiB alignment */
131};
132EXPORT_SYMBOL_GPL(ps3fb_videomemory);
133#define prealloc_ps3fb_videomemory() prealloc(&ps3fb_videomemory)
134
135static int __init early_parse_ps3fb(char *p)
136{
137 if (!p)
138 return 1;
139
140 ps3fb_videomemory.size = ALIGN(memparse(p, &p),
141 ps3fb_videomemory.align);
142 return 0;
143}
144early_param("ps3fb", early_parse_ps3fb);
145#else
146#define prealloc_ps3fb_videomemory() do { } while (0)
147#endif
148
149#if defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
150struct ps3_prealloc ps3flash_bounce_buffer = {
151 .name = "ps3flash bounce buffer",
152 .size = 256*1024,
153 .align = 256*1024
154};
155EXPORT_SYMBOL_GPL(ps3flash_bounce_buffer);
156#define prealloc_ps3flash_bounce_buffer() prealloc(&ps3flash_bounce_buffer)
157
158static int __init early_parse_ps3flash(char *p)
159{
160 if (!p)
161 return 1;
162
163 if (!strcmp(p, "off"))
164 ps3flash_bounce_buffer.size = 0;
165
166 return 0;
167}
168early_param("ps3flash", early_parse_ps3flash);
169#else
170#define prealloc_ps3flash_bounce_buffer() do { } while (0)
171#endif
172
173static int ps3_set_dabr(unsigned long dabr, unsigned long dabrx)
174{
175 /* Have to set at least one bit in the DABRX */
176 if (dabrx == 0 && dabr == 0)
177 dabrx = DABRX_USER;
178 /* hypervisor only allows us to set BTI, Kernel and user */
179 dabrx &= DABRX_BTI | DABRX_KERNEL | DABRX_USER;
180
181 return lv1_set_dabr(dabr, dabrx) ? -1 : 0;
182}
183
184static ssize_t ps3_fw_version_show(struct kobject *kobj,
185 struct kobj_attribute *attr, char *buf)
186{
187 return sysfs_emit(buf, "%s\n", ps3_firmware_version_str);
188}
189
190static int __init ps3_setup_sysfs(void)
191{
192 static struct kobj_attribute attr = __ATTR(fw-version, S_IRUGO,
193 ps3_fw_version_show, NULL);
194 static struct kobject *kobj;
195 int result;
196
197 kobj = kobject_create_and_add("ps3", firmware_kobj);
198
199 if (!kobj) {
200 pr_warn("%s:%d: kobject_create_and_add failed.\n", __func__,
201 __LINE__);
202 return -ENOMEM;
203 }
204
205 result = sysfs_create_file(kobj, &attr.attr);
206
207 if (result) {
208 pr_warn("%s:%d: sysfs_create_file failed.\n", __func__,
209 __LINE__);
210 kobject_put(kobj);
211 return -ENOMEM;
212 }
213
214 return 0;
215}
216core_initcall(ps3_setup_sysfs);
217
218static void __init ps3_setup_arch(void)
219{
220 u64 tmp;
221
222 DBG(" -> %s:%d\n", __func__, __LINE__);
223
224 lv1_get_version_info(&ps3_firmware_version.raw, &tmp);
225
226 snprintf(ps3_firmware_version_str, sizeof(ps3_firmware_version_str),
227 "%u.%u.%u", ps3_firmware_version.major,
228 ps3_firmware_version.minor, ps3_firmware_version.rev);
229
230 printk(KERN_INFO "PS3 firmware version %s\n", ps3_firmware_version_str);
231
232 ps3_spu_set_platform();
233
234#ifdef CONFIG_SMP
235 smp_init_ps3();
236#endif
237
238 prealloc_ps3fb_videomemory();
239 prealloc_ps3flash_bounce_buffer();
240
241 ppc_md.power_save = ps3_power_save;
242 ps3_os_area_init();
243
244 DBG(" <- %s:%d\n", __func__, __LINE__);
245}
246
247static void __init ps3_progress(char *s, unsigned short hex)
248{
249 printk("*** %04x : %s\n", hex, s ? s : "");
250}
251
252void __init ps3_early_mm_init(void)
253{
254 unsigned long htab_size;
255
256 ps3_mm_init();
257 ps3_mm_vas_create(&htab_size);
258 ps3_hpte_init(htab_size);
259}
260
261static int __init ps3_probe(void)
262{
263 DBG(" -> %s:%d\n", __func__, __LINE__);
264
265 ps3_os_area_save_params();
266
267 pm_power_off = ps3_power_off;
268
269 DBG(" <- %s:%d\n", __func__, __LINE__);
270 return 1;
271}
272
273#if defined(CONFIG_KEXEC_CORE)
274static void ps3_kexec_cpu_down(int crash_shutdown, int secondary)
275{
276 int cpu = smp_processor_id();
277
278 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
279
280 ps3_smp_cleanup_cpu(cpu);
281 ps3_shutdown_IRQ(cpu);
282
283 DBG(" <- %s:%d\n", __func__, __LINE__);
284}
285#endif
286
287define_machine(ps3) {
288 .name = "PS3",
289 .compatible = "sony,ps3",
290 .probe = ps3_probe,
291 .setup_arch = ps3_setup_arch,
292 .init_IRQ = ps3_init_IRQ,
293 .panic = ps3_panic,
294 .get_boot_time = ps3_get_boot_time,
295 .set_dabr = ps3_set_dabr,
296 .calibrate_decr = ps3_calibrate_decr,
297 .progress = ps3_progress,
298 .restart = ps3_restart,
299 .halt = ps3_halt,
300#if defined(CONFIG_KEXEC_CORE)
301 .kexec_cpu_down = ps3_kexec_cpu_down,
302#endif
303};