2019-05-27 08:55:15 +02:00
// SPDX-License-Identifier: GPL-2.0-only
2006-11-23 00:46:51 +01:00
/*
* PS3 platform setup routines .
*
* Copyright ( C ) 2006 Sony Computer Entertainment Inc .
* Copyright 2006 Sony Corp .
*/
# include <linux/kernel.h>
# include <linux/delay.h>
# include <linux/fs.h>
# include <linux/root_dev.h>
# include <linux/console.h>
2011-05-27 10:46:24 -04:00
# include <linux/export.h>
2018-10-30 15:09:49 -07:00
# include <linux/memblock.h>
2006-11-23 00:46:51 +01:00
# include <asm/machdep.h>
# include <asm/firmware.h>
# include <asm/time.h>
# include <asm/iommu.h>
# include <asm/udbg.h>
# include <asm/prom.h>
# include <asm/lv1call.h>
2009-06-10 04:38:48 +00:00
# include <asm/ps3gpu.h>
2006-11-23 00:46:51 +01:00
# include "platform.h"
# if defined(DEBUG)
2007-06-16 07:19:23 +10:00
# define DBG udbg_printf
2006-11-23 00:46:51 +01:00
# else
2007-06-16 07:19:23 +10:00
# define DBG pr_debug
2006-11-23 00:46:51 +01:00
# endif
2008-10-30 08:12:58 +00:00
/* mutex synchronizing GPU accesses and video mode changes */
DEFINE_MUTEX ( ps3_gpu_mutex ) ;
EXPORT_SYMBOL_GPL ( ps3_gpu_mutex ) ;
2007-06-16 07:18:48 +10:00
static union ps3_firmware_version ps3_firmware_version ;
2021-06-04 15:58:25 +00:00
static char ps3_firmware_version_str [ 16 ] ;
2007-06-16 07:18:48 +10:00
void ps3_get_firmware_version ( union ps3_firmware_version * v )
2007-01-26 19:08:21 -08:00
{
2007-06-16 07:18:48 +10:00
* v = ps3_firmware_version ;
}
EXPORT_SYMBOL_GPL ( ps3_get_firmware_version ) ;
2007-01-26 19:08:21 -08:00
2007-06-16 07:18:48 +10:00
int ps3_compare_firmware_version ( u16 major , u16 minor , u16 rev )
{
union ps3_firmware_version x ;
x . pad = 0 ;
x . major = major ;
x . minor = minor ;
x . rev = rev ;
2007-01-26 19:08:21 -08:00
2007-08-29 20:30:25 +09:00
return ( ps3_firmware_version . raw > x . raw ) -
( ps3_firmware_version . raw < x . raw ) ;
2007-01-26 19:08:21 -08:00
}
2007-06-16 07:18:48 +10:00
EXPORT_SYMBOL_GPL ( ps3_compare_firmware_version ) ;
2007-01-26 19:08:21 -08:00
2006-11-23 00:46:51 +01:00
static void ps3_power_save ( void )
{
/*
* lv1_pause ( ) puts the PPE thread into inactive state until an
* irq on an unmasked plug exists . MSR [ EE ] has no effect .
* flags : 0 = wake on DEC interrupt , 1 = ignore DEC interrupt .
*/
lv1_pause ( 0 ) ;
}
2016-07-12 10:54:52 +10:00
static void __noreturn ps3_restart ( char * cmd )
2007-02-07 12:20:01 -08:00
{
DBG ( " %s:%d cmd '%s' \n " , __func__ , __LINE__ , cmd ) ;
smp_send_stop ( ) ;
ps3_sys_manager_restart ( ) ; /* never returns */
}
static void ps3_power_off ( void )
{
DBG ( " %s:%d \n " , __func__ , __LINE__ ) ;
smp_send_stop ( ) ;
ps3_sys_manager_power_off ( ) ; /* never returns */
}
2016-07-12 10:54:52 +10:00
static void __noreturn ps3_halt ( void )
2008-03-27 11:38:31 +11:00
{
DBG ( " %s:%d \n " , __func__ , __LINE__ ) ;
smp_send_stop ( ) ;
ps3_sys_manager_halt ( ) ; /* never returns */
}
2017-12-04 16:27:25 +11:00
static void ps3_panic ( char * str )
{
DBG ( " %s:%d %s \n " , __func__ , __LINE__ , str ) ;
smp_send_stop ( ) ;
printk ( " \n " ) ;
printk ( " System does not reboot automatically. \n " ) ;
printk ( " Please press POWER button. \n " ) ;
printk ( " \n " ) ;
powerpc/pseries, ps3: panic flush kernel messages before halting system
Platforms with a panic handler that halts the system can have problems
getting kernel messages out, because the panic notifiers are called
before kernel/panic.c does its flushing of printk buffers an console
etc.
This was attempted to be solved with commit a3b2cb30f252 ("powerpc: Do
not call ppc_md.panic in fadump panic notifier"), but that wasn't the
right approach and caused other problems, and was reverted by commit
ab9dbf771ff9.
Instead, the powernv shutdown paths have already had a similar
problem, fixed by taking the message flushing sequence from
kernel/panic.c. That's a little bit ugly, but while we have the code
duplicated, it will work for this case as well. So have ppc panic
handlers do the same flushing before they terminate.
Without this patch, a qemu pseries_le_defconfig guest stops silently
when issued the nmi command when xmon is off and no crash dumpers
enabled. Afterwards, an oops is printed by each CPU as expected.
Fixes: ab9dbf771ff9 ("Revert "powerpc: Do not call ppc_md.panic in fadump panic notifier"")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-24 02:49:23 +10:00
panic_flush_kmsg_end ( ) ;
2017-12-04 16:27:25 +11:00
while ( 1 )
lv1_pause ( 1 ) ;
}
2007-06-22 00:14:20 +10:00
# if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE) || \
defined ( CONFIG_PS3_FLASH ) | | defined ( CONFIG_PS3_FLASH_MODULE )
2007-07-31 17:22:00 +10:00
static void __init prealloc ( struct ps3_prealloc * p )
2007-02-12 00:55:22 -08:00
{
if ( ! p - > size )
return ;
2018-10-30 15:08:04 -07:00
p - > address = memblock_alloc ( p - > size , p - > align ) ;
2019-03-11 23:30:31 -07:00
if ( ! p - > address )
panic ( " %s: Failed to allocate %lu bytes align=0x%lx \n " ,
__func__ , p - > size , p - > align ) ;
2007-02-12 00:55:22 -08:00
printk ( KERN_INFO " %s: %lu bytes at %p \n " , p - > name , p - > size ,
p - > address ) ;
}
2007-06-22 00:14:20 +10:00
# endif
2007-02-12 00:55:22 -08:00
2007-06-22 00:14:20 +10:00
# if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE)
2007-02-12 00:55:22 -08:00
struct ps3_prealloc ps3fb_videomemory = {
2007-06-16 08:05:38 +10:00
. name = " ps3fb videomemory " ,
. size = CONFIG_FB_PS3_DEFAULT_SIZE_M * 1024 * 1024 ,
. align = 1024 * 1024 /* the GPU requires 1 MiB alignment */
2007-02-12 00:55:22 -08:00
} ;
2007-06-16 08:05:38 +10:00
EXPORT_SYMBOL_GPL ( ps3fb_videomemory ) ;
2007-02-12 00:55:22 -08:00
# define prealloc_ps3fb_videomemory() prealloc(&ps3fb_videomemory)
static int __init early_parse_ps3fb ( char * p )
{
if ( ! p )
return 1 ;
2020-04-20 18:36:36 +00:00
ps3fb_videomemory . size = ALIGN ( memparse ( p , & p ) ,
2007-02-12 00:55:22 -08:00
ps3fb_videomemory . align ) ;
return 0 ;
}
early_param ( " ps3fb " , early_parse_ps3fb ) ;
# else
# define prealloc_ps3fb_videomemory() do { } while (0)
# endif
2007-06-22 00:14:20 +10:00
# if defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
struct ps3_prealloc ps3flash_bounce_buffer = {
. name = " ps3flash bounce buffer " ,
. size = 256 * 1024 ,
. align = 256 * 1024
} ;
EXPORT_SYMBOL_GPL ( ps3flash_bounce_buffer ) ;
# define prealloc_ps3flash_bounce_buffer() prealloc(&ps3flash_bounce_buffer)
static int __init early_parse_ps3flash ( char * p )
{
if ( ! p )
return 1 ;
if ( ! strcmp ( p , " off " ) )
ps3flash_bounce_buffer . size = 0 ;
return 0 ;
}
early_param ( " ps3flash " , early_parse_ps3flash ) ;
# else
# define prealloc_ps3flash_bounce_buffer() do { } while (0)
# endif
2012-09-06 21:24:56 +00:00
static int ps3_set_dabr ( unsigned long dabr , unsigned long dabrx )
2007-05-01 07:00:50 +10:00
{
2012-09-06 21:24:56 +00:00
/* Have to set at least one bit in the DABRX */
if ( dabrx = = 0 & & dabr = = 0 )
dabrx = DABRX_USER ;
/* hypervisor only allows us to set BTI, Kernel and user */
dabrx & = DABRX_BTI | DABRX_KERNEL | DABRX_USER ;
2007-05-01 07:00:50 +10:00
2012-09-06 21:24:56 +00:00
return lv1_set_dabr ( dabr , dabrx ) ? - 1 : 0 ;
2007-05-01 07:00:50 +10:00
}
2007-02-12 00:55:22 -08:00
2021-06-04 15:58:25 +00:00
static ssize_t ps3_fw_version_show ( struct kobject * kobj ,
struct kobj_attribute * attr , char * buf )
{
return sprintf ( buf , " %s " , ps3_firmware_version_str ) ;
}
static int __init ps3_setup_sysfs ( void )
{
static struct kobj_attribute attr = __ATTR ( fw - version , S_IRUGO ,
ps3_fw_version_show , NULL ) ;
static struct kobject * kobj ;
int result ;
kobj = kobject_create_and_add ( " ps3 " , firmware_kobj ) ;
if ( ! kobj ) {
pr_warn ( " %s:%d: kobject_create_and_add failed. \n " , __func__ ,
__LINE__ ) ;
return - ENOMEM ;
}
result = sysfs_create_file ( kobj , & attr . attr ) ;
if ( result ) {
pr_warn ( " %s:%d: sysfs_create_file failed. \n " , __func__ ,
__LINE__ ) ;
kobject_put ( kobj ) ;
return - ENOMEM ;
}
return 0 ;
}
core_initcall ( ps3_setup_sysfs ) ;
2006-11-23 00:46:51 +01:00
static void __init ps3_setup_arch ( void )
{
2011-11-29 15:38:50 +00:00
u64 tmp ;
2007-01-26 19:08:21 -08:00
2006-11-23 00:46:51 +01:00
DBG ( " -> %s:%d \n " , __func__ , __LINE__ ) ;
2011-11-29 15:38:50 +00:00
lv1_get_version_info ( & ps3_firmware_version . raw , & tmp ) ;
2021-06-04 15:58:25 +00:00
snprintf ( ps3_firmware_version_str , sizeof ( ps3_firmware_version_str ) ,
" %u.%u.%u " , ps3_firmware_version . major ,
ps3_firmware_version . minor , ps3_firmware_version . rev ) ;
printk ( KERN_INFO " PS3 firmware version %s \n " , ps3_firmware_version_str ) ;
2007-01-26 19:08:21 -08:00
2006-11-23 00:46:51 +01:00
ps3_spu_set_platform ( ) ;
# ifdef CONFIG_SMP
smp_init_ps3 ( ) ;
# endif
2007-02-12 00:55:22 -08:00
prealloc_ps3fb_videomemory ( ) ;
2007-06-22 00:14:20 +10:00
prealloc_ps3flash_bounce_buffer ( ) ;
2006-11-23 00:46:51 +01:00
ppc_md . power_save = ps3_power_save ;
2007-10-07 07:35:47 +10:00
ps3_os_area_init ( ) ;
2006-11-23 00:46:51 +01:00
DBG ( " <- %s:%d \n " , __func__ , __LINE__ ) ;
}
static void __init ps3_progress ( char * s , unsigned short hex )
{
printk ( " *** %04x : %s \n " , hex , s ? s : " " ) ;
}
2016-07-05 15:03:51 +10:00
void __init ps3_early_mm_init ( void )
2006-11-23 00:46:51 +01:00
{
unsigned long htab_size ;
2016-07-05 15:03:51 +10:00
ps3_mm_init ( ) ;
ps3_mm_vas_create ( & htab_size ) ;
ps3_hpte_init ( htab_size ) ;
}
static int __init ps3_probe ( void )
{
2006-11-23 00:46:51 +01:00
DBG ( " -> %s:%d \n " , __func__ , __LINE__ ) ;
2016-07-05 15:04:00 +10:00
if ( ! of_machine_is_compatible ( " sony,ps3 " ) )
2006-11-23 00:46:51 +01:00
return 0 ;
2007-10-07 07:35:44 +10:00
ps3_os_area_save_params ( ) ;
2016-07-05 15:04:00 +10:00
2014-10-13 16:01:09 +02:00
pm_power_off = ps3_power_off ;
2006-11-23 00:46:51 +01:00
DBG ( " <- %s:%d \n " , __func__ , __LINE__ ) ;
return 1 ;
}
2016-11-29 23:45:50 +11:00
# if defined(CONFIG_KEXEC_CORE)
2006-11-23 00:46:51 +01:00
static void ps3_kexec_cpu_down ( int crash_shutdown , int secondary )
{
2007-06-16 07:19:32 +10:00
int cpu = smp_processor_id ( ) ;
2006-11-23 00:46:51 +01:00
2007-06-16 07:19:32 +10:00
DBG ( " -> %s:%d: (%d) \n " , __func__ , __LINE__ , cpu ) ;
2006-11-23 00:46:51 +01:00
2007-06-16 07:19:32 +10:00
ps3_smp_cleanup_cpu ( cpu ) ;
ps3_shutdown_IRQ ( cpu ) ;
2006-11-23 00:46:51 +01:00
DBG ( " <- %s:%d \n " , __func__ , __LINE__ ) ;
}
# endif
define_machine ( ps3 ) {
. name = " PS3 " ,
. probe = ps3_probe ,
. setup_arch = ps3_setup_arch ,
. init_IRQ = ps3_init_IRQ ,
2017-12-04 16:27:25 +11:00
. panic = ps3_panic ,
2006-11-23 00:46:51 +01:00
. get_boot_time = ps3_get_boot_time ,
2007-05-01 07:00:50 +10:00
. set_dabr = ps3_set_dabr ,
2006-11-23 00:46:51 +01:00
. calibrate_decr = ps3_calibrate_decr ,
. progress = ps3_progress ,
2007-02-07 12:20:01 -08:00
. restart = ps3_restart ,
2008-03-27 11:38:31 +11:00
. halt = ps3_halt ,
2016-11-29 23:45:50 +11:00
# if defined(CONFIG_KEXEC_CORE)
2006-11-23 00:46:51 +01:00
. kexec_cpu_down = ps3_kexec_cpu_down ,
# endif
} ;