treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 167
[linux-2.6-block.git] / arch / powerpc / platforms / ps3 / setup.c
CommitLineData
873e65bc 1// SPDX-License-Identifier: GPL-2.0-only
f58a9d17
GL
2/*
3 * PS3 platform setup routines.
4 *
5 * Copyright (C) 2006 Sony Computer Entertainment Inc.
6 * Copyright 2006 Sony Corp.
f58a9d17
GL
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/console.h>
66b15db6 14#include <linux/export.h>
57c8a661 15#include <linux/memblock.h>
f58a9d17
GL
16
17#include <asm/machdep.h>
18#include <asm/firmware.h>
19#include <asm/time.h>
20#include <asm/iommu.h>
21#include <asm/udbg.h>
22#include <asm/prom.h>
23#include <asm/lv1call.h>
d3352c9f 24#include <asm/ps3gpu.h>
f58a9d17
GL
25
26#include "platform.h"
27
28#if defined(DEBUG)
83bb643d 29#define DBG udbg_printf
f58a9d17 30#else
83bb643d 31#define DBG pr_debug
f58a9d17
GL
32#endif
33
9b82f3e6
GU
34/* mutex synchronizing GPU accesses and video mode changes */
35DEFINE_MUTEX(ps3_gpu_mutex);
36EXPORT_SYMBOL_GPL(ps3_gpu_mutex);
37
1322810c
MM
38static union ps3_firmware_version ps3_firmware_version;
39
40void ps3_get_firmware_version(union ps3_firmware_version *v)
66b44954 41{
1322810c
MM
42 *v = ps3_firmware_version;
43}
44EXPORT_SYMBOL_GPL(ps3_get_firmware_version);
66b44954 45
1322810c
MM
46int ps3_compare_firmware_version(u16 major, u16 minor, u16 rev)
47{
48 union ps3_firmware_version x;
49
50 x.pad = 0;
51 x.major = major;
52 x.minor = minor;
53 x.rev = rev;
66b44954 54
fc43dca9
MM
55 return (ps3_firmware_version.raw > x.raw) -
56 (ps3_firmware_version.raw < x.raw);
66b44954 57}
1322810c 58EXPORT_SYMBOL_GPL(ps3_compare_firmware_version);
66b44954 59
f58a9d17
GL
60static void ps3_power_save(void)
61{
62 /*
63 * lv1_pause() puts the PPE thread into inactive state until an
64 * irq on an unmasked plug exists. MSR[EE] has no effect.
65 * flags: 0 = wake on DEC interrupt, 1 = ignore DEC interrupt.
66 */
67
68 lv1_pause(0);
69}
70
95ec77c0 71static void __noreturn ps3_restart(char *cmd)
fde5efd0
GL
72{
73 DBG("%s:%d cmd '%s'\n", __func__, __LINE__, cmd);
74
75 smp_send_stop();
76 ps3_sys_manager_restart(); /* never returns */
77}
78
79static void ps3_power_off(void)
80{
81 DBG("%s:%d\n", __func__, __LINE__);
82
83 smp_send_stop();
84 ps3_sys_manager_power_off(); /* never returns */
85}
86
95ec77c0 87static void __noreturn ps3_halt(void)
ca052f79
GU
88{
89 DBG("%s:%d\n", __func__, __LINE__);
90
91 smp_send_stop();
92 ps3_sys_manager_halt(); /* never returns */
93}
94
ab9dbf77
DG
95static void ps3_panic(char *str)
96{
97 DBG("%s:%d %s\n", __func__, __LINE__, str);
98
99 smp_send_stop();
100 printk("\n");
101 printk(" System does not reboot automatically.\n");
102 printk(" Please press POWER button.\n");
103 printk("\n");
35adacd6 104 panic_flush_kmsg_end();
ab9dbf77
DG
105
106 while(1)
107 lv1_pause(1);
108}
109
32d73318
GU
110#if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE) || \
111 defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
cba684f5 112static void __init prealloc(struct ps3_prealloc *p)
fbdb3e5b
GU
113{
114 if (!p->size)
115 return;
116
eb31d559 117 p->address = memblock_alloc(p->size, p->align);
8a7f97b9
MR
118 if (!p->address)
119 panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
120 __func__, p->size, p->align);
fbdb3e5b
GU
121
122 printk(KERN_INFO "%s: %lu bytes at %p\n", p->name, p->size,
123 p->address);
124}
32d73318 125#endif
fbdb3e5b 126
32d73318 127#if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE)
fbdb3e5b 128struct ps3_prealloc ps3fb_videomemory = {
9e6b99bd
GU
129 .name = "ps3fb videomemory",
130 .size = CONFIG_FB_PS3_DEFAULT_SIZE_M*1024*1024,
131 .align = 1024*1024 /* the GPU requires 1 MiB alignment */
fbdb3e5b 132};
9e6b99bd 133EXPORT_SYMBOL_GPL(ps3fb_videomemory);
fbdb3e5b
GU
134#define prealloc_ps3fb_videomemory() prealloc(&ps3fb_videomemory)
135
136static int __init early_parse_ps3fb(char *p)
137{
138 if (!p)
139 return 1;
140
141 ps3fb_videomemory.size = _ALIGN_UP(memparse(p, &p),
142 ps3fb_videomemory.align);
143 return 0;
144}
145early_param("ps3fb", early_parse_ps3fb);
146#else
147#define prealloc_ps3fb_videomemory() do { } while (0)
148#endif
149
32d73318
GU
150#if defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
151struct ps3_prealloc ps3flash_bounce_buffer = {
152 .name = "ps3flash bounce buffer",
153 .size = 256*1024,
154 .align = 256*1024
155};
156EXPORT_SYMBOL_GPL(ps3flash_bounce_buffer);
157#define prealloc_ps3flash_bounce_buffer() prealloc(&ps3flash_bounce_buffer)
158
159static int __init early_parse_ps3flash(char *p)
160{
161 if (!p)
162 return 1;
163
164 if (!strcmp(p, "off"))
165 ps3flash_bounce_buffer.size = 0;
166
167 return 0;
168}
169early_param("ps3flash", early_parse_ps3flash);
170#else
171#define prealloc_ps3flash_bounce_buffer() do { } while (0)
172#endif
173
4474ef05 174static int ps3_set_dabr(unsigned long dabr, unsigned long dabrx)
f0a1d024 175{
4474ef05
MN
176 /* Have to set at least one bit in the DABRX */
177 if (dabrx == 0 && dabr == 0)
178 dabrx = DABRX_USER;
179 /* hypervisor only allows us to set BTI, Kernel and user */
180 dabrx &= DABRX_BTI | DABRX_KERNEL | DABRX_USER;
f0a1d024 181
4474ef05 182 return lv1_set_dabr(dabr, dabrx) ? -1 : 0;
f0a1d024 183}
fbdb3e5b 184
f58a9d17
GL
185static void __init ps3_setup_arch(void)
186{
816cb49a 187 u64 tmp;
66b44954 188
f58a9d17
GL
189 DBG(" -> %s:%d\n", __func__, __LINE__);
190
816cb49a
GL
191 lv1_get_version_info(&ps3_firmware_version.raw, &tmp);
192
1322810c
MM
193 printk(KERN_INFO "PS3 firmware version %u.%u.%u\n",
194 ps3_firmware_version.major, ps3_firmware_version.minor,
195 ps3_firmware_version.rev);
66b44954 196
f58a9d17 197 ps3_spu_set_platform();
f58a9d17
GL
198
199#ifdef CONFIG_SMP
200 smp_init_ps3();
201#endif
202
203#ifdef CONFIG_DUMMY_CONSOLE
204 conswitchp = &dummy_con;
205#endif
206
fbdb3e5b 207 prealloc_ps3fb_videomemory();
32d73318
GU
208 prealloc_ps3flash_bounce_buffer();
209
f58a9d17 210 ppc_md.power_save = ps3_power_save;
7db19421 211 ps3_os_area_init();
f58a9d17
GL
212
213 DBG(" <- %s:%d\n", __func__, __LINE__);
214}
215
216static void __init ps3_progress(char *s, unsigned short hex)
217{
218 printk("*** %04x : %s\n", hex, s ? s : "");
219}
220
166dd7d3 221void __init ps3_early_mm_init(void)
f58a9d17
GL
222{
223 unsigned long htab_size;
166dd7d3
BH
224
225 ps3_mm_init();
226 ps3_mm_vas_create(&htab_size);
227 ps3_hpte_init(htab_size);
228}
229
230static int __init ps3_probe(void)
231{
f58a9d17
GL
232 DBG(" -> %s:%d\n", __func__, __LINE__);
233
406b0b6a 234 if (!of_machine_is_compatible("sony,ps3"))
f58a9d17
GL
235 return 0;
236
01263e88 237 ps3_os_area_save_params();
406b0b6a 238
9178ba29 239 pm_power_off = ps3_power_off;
f58a9d17
GL
240
241 DBG(" <- %s:%d\n", __func__, __LINE__);
242 return 1;
243}
244
da665885 245#if defined(CONFIG_KEXEC_CORE)
f58a9d17
GL
246static void ps3_kexec_cpu_down(int crash_shutdown, int secondary)
247{
9263e85a 248 int cpu = smp_processor_id();
f58a9d17 249
9263e85a 250 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
f58a9d17 251
9263e85a
GL
252 ps3_smp_cleanup_cpu(cpu);
253 ps3_shutdown_IRQ(cpu);
f58a9d17
GL
254
255 DBG(" <- %s:%d\n", __func__, __LINE__);
256}
257#endif
258
259define_machine(ps3) {
260 .name = "PS3",
261 .probe = ps3_probe,
262 .setup_arch = ps3_setup_arch,
f58a9d17 263 .init_IRQ = ps3_init_IRQ,
ab9dbf77 264 .panic = ps3_panic,
f58a9d17 265 .get_boot_time = ps3_get_boot_time,
f0a1d024 266 .set_dabr = ps3_set_dabr,
f58a9d17
GL
267 .calibrate_decr = ps3_calibrate_decr,
268 .progress = ps3_progress,
fde5efd0 269 .restart = ps3_restart,
ca052f79 270 .halt = ps3_halt,
da665885 271#if defined(CONFIG_KEXEC_CORE)
f58a9d17 272 .kexec_cpu_down = ps3_kexec_cpu_down,
f58a9d17
GL
273#endif
274};