1 // SPDX-License-Identifier: GPL-2.0-only
3 * PS3 platform setup routines.
5 * Copyright (C) 2006 Sony Computer Entertainment Inc.
6 * Copyright 2006 Sony Corp.
9 #include <linux/kernel.h>
10 #include <linux/delay.h>
12 #include <linux/root_dev.h>
13 #include <linux/console.h>
14 #include <linux/export.h>
15 #include <linux/memblock.h>
18 #include <asm/machdep.h>
19 #include <asm/firmware.h>
21 #include <asm/iommu.h>
23 #include <asm/lv1call.h>
24 #include <asm/ps3gpu.h>
29 #define DBG udbg_printf
34 /* mutex synchronizing GPU accesses and video mode changes */
35 DEFINE_MUTEX(ps3_gpu_mutex
);
36 EXPORT_SYMBOL_GPL(ps3_gpu_mutex
);
38 static union ps3_firmware_version ps3_firmware_version
;
39 static char ps3_firmware_version_str
[16];
41 void ps3_get_firmware_version(union ps3_firmware_version
*v
)
43 *v
= ps3_firmware_version
;
45 EXPORT_SYMBOL_GPL(ps3_get_firmware_version
);
47 int ps3_compare_firmware_version(u16 major
, u16 minor
, u16 rev
)
49 union ps3_firmware_version x
;
56 return (ps3_firmware_version
.raw
> x
.raw
) -
57 (ps3_firmware_version
.raw
< x
.raw
);
59 EXPORT_SYMBOL_GPL(ps3_compare_firmware_version
);
61 static void ps3_power_save(void)
64 * lv1_pause() puts the PPE thread into inactive state until an
65 * irq on an unmasked plug exists. MSR[EE] has no effect.
66 * flags: 0 = wake on DEC interrupt, 1 = ignore DEC interrupt.
72 static void __noreturn
ps3_restart(char *cmd
)
74 DBG("%s:%d cmd '%s'\n", __func__
, __LINE__
, cmd
);
77 ps3_sys_manager_restart(); /* never returns */
80 static void ps3_power_off(void)
82 DBG("%s:%d\n", __func__
, __LINE__
);
85 ps3_sys_manager_power_off(); /* never returns */
88 static void __noreturn
ps3_halt(void)
90 DBG("%s:%d\n", __func__
, __LINE__
);
93 ps3_sys_manager_halt(); /* never returns */
96 static void ps3_panic(char *str
)
98 DBG("%s:%d %s\n", __func__
, __LINE__
, str
);
102 printk(" System does not reboot automatically.\n");
103 printk(" Please press POWER button.\n");
105 panic_flush_kmsg_end();
111 #if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE) || \
112 defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
113 static void __init
prealloc(struct ps3_prealloc
*p
)
118 p
->address
= memblock_alloc(p
->size
, p
->align
);
120 panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
121 __func__
, p
->size
, p
->align
);
123 printk(KERN_INFO
"%s: %lu bytes at %p\n", p
->name
, p
->size
,
128 #if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE)
129 struct ps3_prealloc ps3fb_videomemory
= {
130 .name
= "ps3fb videomemory",
131 .size
= CONFIG_FB_PS3_DEFAULT_SIZE_M
*1024*1024,
132 .align
= 1024*1024 /* the GPU requires 1 MiB alignment */
134 EXPORT_SYMBOL_GPL(ps3fb_videomemory
);
135 #define prealloc_ps3fb_videomemory() prealloc(&ps3fb_videomemory)
137 static int __init
early_parse_ps3fb(char *p
)
142 ps3fb_videomemory
.size
= ALIGN(memparse(p
, &p
),
143 ps3fb_videomemory
.align
);
146 early_param("ps3fb", early_parse_ps3fb
);
148 #define prealloc_ps3fb_videomemory() do { } while (0)
151 #if defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
152 struct ps3_prealloc ps3flash_bounce_buffer
= {
153 .name
= "ps3flash bounce buffer",
157 EXPORT_SYMBOL_GPL(ps3flash_bounce_buffer
);
158 #define prealloc_ps3flash_bounce_buffer() prealloc(&ps3flash_bounce_buffer)
160 static int __init
early_parse_ps3flash(char *p
)
165 if (!strcmp(p
, "off"))
166 ps3flash_bounce_buffer
.size
= 0;
170 early_param("ps3flash", early_parse_ps3flash
);
172 #define prealloc_ps3flash_bounce_buffer() do { } while (0)
175 static int ps3_set_dabr(unsigned long dabr
, unsigned long dabrx
)
177 /* Have to set at least one bit in the DABRX */
178 if (dabrx
== 0 && dabr
== 0)
180 /* hypervisor only allows us to set BTI, Kernel and user */
181 dabrx
&= DABRX_BTI
| DABRX_KERNEL
| DABRX_USER
;
183 return lv1_set_dabr(dabr
, dabrx
) ? -1 : 0;
186 static ssize_t
ps3_fw_version_show(struct kobject
*kobj
,
187 struct kobj_attribute
*attr
, char *buf
)
189 return sprintf(buf
, "%s", ps3_firmware_version_str
);
192 static int __init
ps3_setup_sysfs(void)
194 static struct kobj_attribute attr
= __ATTR(fw
-version
, S_IRUGO
,
195 ps3_fw_version_show
, NULL
);
196 static struct kobject
*kobj
;
199 kobj
= kobject_create_and_add("ps3", firmware_kobj
);
202 pr_warn("%s:%d: kobject_create_and_add failed.\n", __func__
,
207 result
= sysfs_create_file(kobj
, &attr
.attr
);
210 pr_warn("%s:%d: sysfs_create_file failed.\n", __func__
,
218 core_initcall(ps3_setup_sysfs
);
220 static void __init
ps3_setup_arch(void)
224 DBG(" -> %s:%d\n", __func__
, __LINE__
);
226 lv1_get_version_info(&ps3_firmware_version
.raw
, &tmp
);
228 snprintf(ps3_firmware_version_str
, sizeof(ps3_firmware_version_str
),
229 "%u.%u.%u", ps3_firmware_version
.major
,
230 ps3_firmware_version
.minor
, ps3_firmware_version
.rev
);
232 printk(KERN_INFO
"PS3 firmware version %s\n", ps3_firmware_version_str
);
234 ps3_spu_set_platform();
240 prealloc_ps3fb_videomemory();
241 prealloc_ps3flash_bounce_buffer();
243 ppc_md
.power_save
= ps3_power_save
;
246 DBG(" <- %s:%d\n", __func__
, __LINE__
);
249 static void __init
ps3_progress(char *s
, unsigned short hex
)
251 printk("*** %04x : %s\n", hex
, s
? s
: "");
254 void __init
ps3_early_mm_init(void)
256 unsigned long htab_size
;
259 ps3_mm_vas_create(&htab_size
);
260 ps3_hpte_init(htab_size
);
263 static int __init
ps3_probe(void)
265 DBG(" -> %s:%d\n", __func__
, __LINE__
);
267 ps3_os_area_save_params();
269 pm_power_off
= ps3_power_off
;
271 DBG(" <- %s:%d\n", __func__
, __LINE__
);
275 #if defined(CONFIG_KEXEC_CORE)
276 static void ps3_kexec_cpu_down(int crash_shutdown
, int secondary
)
278 int cpu
= smp_processor_id();
280 DBG(" -> %s:%d: (%d)\n", __func__
, __LINE__
, cpu
);
282 ps3_smp_cleanup_cpu(cpu
);
283 ps3_shutdown_IRQ(cpu
);
285 DBG(" <- %s:%d\n", __func__
, __LINE__
);
289 define_machine(ps3
) {
291 .compatible
= "sony,ps3",
293 .setup_arch
= ps3_setup_arch
,
294 .init_IRQ
= ps3_init_IRQ
,
296 .get_boot_time
= ps3_get_boot_time
,
297 .set_dabr
= ps3_set_dabr
,
298 .calibrate_decr
= ps3_calibrate_decr
,
299 .progress
= ps3_progress
,
300 .restart
= ps3_restart
,
302 #if defined(CONFIG_KEXEC_CORE)
303 .kexec_cpu_down
= ps3_kexec_cpu_down
,