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/console.h> 14 #include <linux/export.h> 15 #include <linux/memblock.h> 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> 24 #include <asm/ps3gpu.h> 25 26 #include "platform.h" 27 28 #if defined(DEBUG) 29 #define DBG udbg_printf 30 #else 31 #define DBG pr_debug 32 #endif 33 34 /* mutex synchronizing GPU accesses and video mode changes */ 35 DEFINE_MUTEX(ps3_gpu_mutex); 36 EXPORT_SYMBOL_GPL(ps3_gpu_mutex); 37 38 static union ps3_firmware_version ps3_firmware_version; 39 40 void ps3_get_firmware_version(union ps3_firmware_version *v) 41 { 42 *v = ps3_firmware_version; 43 } 44 EXPORT_SYMBOL_GPL(ps3_get_firmware_version); 45 46 int 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; 54 55 return (ps3_firmware_version.raw > x.raw) - 56 (ps3_firmware_version.raw < x.raw); 57 } 58 EXPORT_SYMBOL_GPL(ps3_compare_firmware_version); 59 60 static 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 71 static void __noreturn ps3_restart(char *cmd) 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 79 static 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 87 static void __noreturn ps3_halt(void) 88 { 89 DBG("%s:%d\n", __func__, __LINE__); 90 91 smp_send_stop(); 92 ps3_sys_manager_halt(); /* never returns */ 93 } 94 95 static 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"); 104 panic_flush_kmsg_end(); 105 106 while(1) 107 lv1_pause(1); 108 } 109 110 #if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE) || \ 111 defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE) 112 static void __init prealloc(struct ps3_prealloc *p) 113 { 114 if (!p->size) 115 return; 116 117 p->address = memblock_alloc(p->size, p->align); 118 if (!p->address) 119 panic("%s: Failed to allocate %lu bytes align=0x%lx\n", 120 __func__, p->size, p->align); 121 122 printk(KERN_INFO "%s: %lu bytes at %p\n", p->name, p->size, 123 p->address); 124 } 125 #endif 126 127 #if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE) 128 struct ps3_prealloc ps3fb_videomemory = { 129 .name = "ps3fb videomemory", 130 .size = CONFIG_FB_PS3_DEFAULT_SIZE_M*1024*1024, 131 .align = 1024*1024 /* the GPU requires 1 MiB alignment */ 132 }; 133 EXPORT_SYMBOL_GPL(ps3fb_videomemory); 134 #define prealloc_ps3fb_videomemory() prealloc(&ps3fb_videomemory) 135 136 static 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 } 145 early_param("ps3fb", early_parse_ps3fb); 146 #else 147 #define prealloc_ps3fb_videomemory() do { } while (0) 148 #endif 149 150 #if defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE) 151 struct ps3_prealloc ps3flash_bounce_buffer = { 152 .name = "ps3flash bounce buffer", 153 .size = 256*1024, 154 .align = 256*1024 155 }; 156 EXPORT_SYMBOL_GPL(ps3flash_bounce_buffer); 157 #define prealloc_ps3flash_bounce_buffer() prealloc(&ps3flash_bounce_buffer) 158 159 static 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 } 169 early_param("ps3flash", early_parse_ps3flash); 170 #else 171 #define prealloc_ps3flash_bounce_buffer() do { } while (0) 172 #endif 173 174 static int ps3_set_dabr(unsigned long dabr, unsigned long dabrx) 175 { 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; 181 182 return lv1_set_dabr(dabr, dabrx) ? -1 : 0; 183 } 184 185 static void __init ps3_setup_arch(void) 186 { 187 u64 tmp; 188 189 DBG(" -> %s:%d\n", __func__, __LINE__); 190 191 lv1_get_version_info(&ps3_firmware_version.raw, &tmp); 192 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); 196 197 ps3_spu_set_platform(); 198 199 #ifdef CONFIG_SMP 200 smp_init_ps3(); 201 #endif 202 203 #ifdef CONFIG_DUMMY_CONSOLE 204 conswitchp = &dummy_con; 205 #endif 206 207 prealloc_ps3fb_videomemory(); 208 prealloc_ps3flash_bounce_buffer(); 209 210 ppc_md.power_save = ps3_power_save; 211 ps3_os_area_init(); 212 213 DBG(" <- %s:%d\n", __func__, __LINE__); 214 } 215 216 static void __init ps3_progress(char *s, unsigned short hex) 217 { 218 printk("*** %04x : %s\n", hex, s ? s : ""); 219 } 220 221 void __init ps3_early_mm_init(void) 222 { 223 unsigned long htab_size; 224 225 ps3_mm_init(); 226 ps3_mm_vas_create(&htab_size); 227 ps3_hpte_init(htab_size); 228 } 229 230 static int __init ps3_probe(void) 231 { 232 DBG(" -> %s:%d\n", __func__, __LINE__); 233 234 if (!of_machine_is_compatible("sony,ps3")) 235 return 0; 236 237 ps3_os_area_save_params(); 238 239 pm_power_off = ps3_power_off; 240 241 DBG(" <- %s:%d\n", __func__, __LINE__); 242 return 1; 243 } 244 245 #if defined(CONFIG_KEXEC_CORE) 246 static void ps3_kexec_cpu_down(int crash_shutdown, int secondary) 247 { 248 int cpu = smp_processor_id(); 249 250 DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu); 251 252 ps3_smp_cleanup_cpu(cpu); 253 ps3_shutdown_IRQ(cpu); 254 255 DBG(" <- %s:%d\n", __func__, __LINE__); 256 } 257 #endif 258 259 define_machine(ps3) { 260 .name = "PS3", 261 .probe = ps3_probe, 262 .setup_arch = ps3_setup_arch, 263 .init_IRQ = ps3_init_IRQ, 264 .panic = ps3_panic, 265 .get_boot_time = ps3_get_boot_time, 266 .set_dabr = ps3_set_dabr, 267 .calibrate_decr = ps3_calibrate_decr, 268 .progress = ps3_progress, 269 .restart = ps3_restart, 270 .halt = ps3_halt, 271 #if defined(CONFIG_KEXEC_CORE) 272 .kexec_cpu_down = ps3_kexec_cpu_down, 273 #endif 274 }; 275