2017-11-24 15:00:32 +01:00
// SPDX-License-Identifier: GPL-2.0
2005-04-16 15:20:36 -07:00
/*
* S390 version
2012-07-20 11:15:04 +02:00
* Copyright IBM Corp . 1999 , 2012
2005-04-16 15:20:36 -07:00
* Author ( s ) : Hartmut Penner ( hp @ de . ibm . com ) ,
* Martin Schwidefsky ( schwidefsky @ de . ibm . com )
*
* Derived from " arch/i386/kernel/setup.c "
* Copyright ( C ) 1995 , Linus Torvalds
*/
/*
* This file handles the architecture - dependent parts of initialization
*/
2008-12-25 13:39:40 +01:00
# define KMSG_COMPONENT "setup"
# define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
2005-04-16 15:20:36 -07:00
# include <linux/errno.h>
2013-01-07 13:56:17 +01:00
# include <linux/export.h>
2005-04-16 15:20:36 -07:00
# include <linux/sched.h>
2017-02-08 18:51:36 +01:00
# include <linux/sched/task.h>
2017-02-05 14:47:12 +01:00
# include <linux/cpu.h>
2005-04-16 15:20:36 -07:00
# include <linux/kernel.h>
2011-12-08 10:22:09 -08:00
# include <linux/memblock.h>
2005-04-16 15:20:36 -07:00
# include <linux/mm.h>
# include <linux/stddef.h>
# include <linux/unistd.h>
# include <linux/ptrace.h>
2014-08-11 12:20:58 +02:00
# include <linux/random.h>
2005-04-16 15:20:36 -07:00
# include <linux/user.h>
# include <linux/tty.h>
# include <linux/ioport.h>
# include <linux/delay.h>
# include <linux/init.h>
# include <linux/initrd.h>
# include <linux/root_dev.h>
# include <linux/console.h>
# include <linux/kernel_stat.h>
2020-09-11 10:56:52 +02:00
# include <linux/dma-map-ops.h>
2005-10-30 15:00:11 -08:00
# include <linux/device.h>
2006-06-29 15:08:25 +02:00
# include <linux/notifier.h>
2006-09-20 15:58:41 +02:00
# include <linux/pfn.h>
2007-02-05 21:18:24 +01:00
# include <linux/ctype.h>
2007-02-05 21:16:47 +01:00
# include <linux/reboot.h>
2008-04-17 07:46:12 +02:00
# include <linux/topology.h>
2011-10-30 15:16:40 +01:00
# include <linux/kexec.h>
# include <linux/crash_dump.h>
# include <linux/memory.h>
2012-02-27 10:01:52 +01:00
# include <linux/compat.h>
2017-09-12 16:37:33 +02:00
# include <linux/start_kernel.h>
2020-12-08 19:47:15 +01:00
# include <linux/hugetlb.h>
2021-08-27 08:36:06 +02:00
# include <linux/kmemleak.h>
2005-04-16 15:20:36 -07:00
2019-02-21 14:23:04 +01:00
# include <asm/boot_data.h>
2007-02-21 10:55:21 +01:00
# include <asm/ipl.h>
2012-03-30 09:40:55 +02:00
# include <asm/facility.h>
2005-04-16 15:20:36 -07:00
# include <asm/smp.h>
# include <asm/mmu_context.h>
# include <asm/cpcmd.h>
# include <asm/lowcore.h>
2017-10-12 13:24:47 +02:00
# include <asm/nmi.h>
2005-04-16 15:20:36 -07:00
# include <asm/irq.h>
2005-05-01 08:58:58 -07:00
# include <asm/page.h>
# include <asm/ptrace.h>
2006-06-25 05:49:30 -07:00
# include <asm/sections.h>
2007-02-05 21:18:24 +01:00
# include <asm/ebcdic.h>
2011-10-30 15:16:40 +01:00
# include <asm/diag.h>
2012-03-11 11:59:34 -04:00
# include <asm/os_info.h>
2012-06-11 16:06:59 +02:00
# include <asm/sclp.h>
2019-01-28 08:33:08 +01:00
# include <asm/stacktrace.h>
2014-08-11 12:20:58 +02:00
# include <asm/sysinfo.h>
2014-03-06 18:25:13 +01:00
# include <asm/numa.h>
s390: introduce CPU alternatives
Implement CPU alternatives, which allows to optionally patch newer
instructions at runtime, based on CPU facilities availability.
A new kernel boot parameter "noaltinstr" disables patching.
Current implementation is derived from x86 alternatives. Although
ideal instructions padding (when altinstr is longer then oldinstr)
is added at compile time, and no oldinstr nops optimization has to be
done at runtime. Also couple of compile time sanity checks are done:
1. oldinstr and altinstr must be <= 254 bytes long,
2. oldinstr and altinstr must not have an odd length.
alternative(oldinstr, altinstr, facility);
alternative_2(oldinstr, altinstr1, facility1, altinstr2, facility2);
Both compile time and runtime padding consists of either 6/4/2 bytes nop
or a jump (brcl) + 2 bytes nop filler if padding is longer then 6 bytes.
.altinstructions and .altinstr_replacement sections are part of
__init_begin : __init_end region and are freed after initialization.
Signed-off-by: Vasily Gorbik <gor@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2017-10-12 13:01:47 +02:00
# include <asm/alternative.h>
2018-01-26 12:46:47 +01:00
# include <asm/nospec-branch.h>
2018-04-11 11:56:55 +02:00
# include <asm/mem_detect.h>
2019-04-01 19:11:03 +02:00
# include <asm/uv.h>
2020-01-22 13:38:22 +01:00
# include <asm/asm-offsets.h>
2012-03-11 11:59:26 -04:00
# include "entry.h"
2007-02-05 21:18:17 +01:00
2005-04-16 15:20:36 -07:00
/*
* Machine setup . .
*/
unsigned int console_mode = 0 ;
2009-03-26 15:24:04 +01:00
EXPORT_SYMBOL ( console_mode ) ;
2005-04-16 15:20:36 -07:00
unsigned int console_devno = - 1 ;
2009-03-26 15:24:04 +01:00
EXPORT_SYMBOL ( console_devno ) ;
2005-04-16 15:20:36 -07:00
unsigned int console_irq = - 1 ;
2009-03-26 15:24:04 +01:00
EXPORT_SYMBOL ( console_irq ) ;
2021-06-15 19:17:36 +02:00
/*
* Some code and data needs to stay below 2 GB , even when the kernel would be
* relocated above 2 GB , because it has to use 31 bit addresses .
2021-08-04 13:40:31 +02:00
* Such code and data is part of the . amode31 section .
2021-06-15 19:17:36 +02:00
*/
2021-09-27 14:18:26 +02:00
unsigned long __amode31_ref __samode31 = ( unsigned long ) & _samode31 ;
unsigned long __amode31_ref __eamode31 = ( unsigned long ) & _eamode31 ;
unsigned long __amode31_ref __stext_amode31 = ( unsigned long ) & _stext_amode31 ;
unsigned long __amode31_ref __etext_amode31 = ( unsigned long ) & _etext_amode31 ;
2021-08-04 13:40:31 +02:00
struct exception_table_entry __amode31_ref * __start_amode31_ex_table = _start_amode31_ex_table ;
struct exception_table_entry __amode31_ref * __stop_amode31_ex_table = _stop_amode31_ex_table ;
2021-06-15 19:17:36 +02:00
/*
* Control registers CR2 , CR5 and CR15 are initialized with addresses
2021-08-04 13:40:31 +02:00
* of tables that must be placed below 2 G which is handled by the AMODE31
2021-06-15 19:17:36 +02:00
* sections .
2021-08-04 13:40:31 +02:00
* Because the AMODE31 sections are relocated below 2 G at startup ,
2021-06-15 19:17:36 +02:00
* the content of control registers CR2 , CR5 and CR15 must be updated
* with new addresses after the relocation . The initial initialization of
2021-08-04 13:40:31 +02:00
* control registers occurs in head64 . S and then gets updated again after AMODE31
* relocation . We must access the relevant AMODE31 tables indirectly via
* pointers placed in the . amode31 . refs linker section . Those pointers get
* updated automatically during AMODE31 relocation and always contain a valid
* address within AMODE31 sections .
2021-06-15 19:17:36 +02:00
*/
2021-08-04 13:40:31 +02:00
static __amode31_data u32 __ctl_duct_amode31 [ 16 ] __aligned ( 64 ) ;
2021-06-15 19:17:36 +02:00
2021-08-04 13:40:31 +02:00
static __amode31_data u64 __ctl_aste_amode31 [ 8 ] __aligned ( 64 ) = {
2021-06-15 19:17:36 +02:00
[ 1 ] = 0xffffffffffffffff
} ;
2021-08-04 13:40:31 +02:00
static __amode31_data u32 __ctl_duald_amode31 [ 32 ] __aligned ( 128 ) = {
2021-06-15 19:17:36 +02:00
0x80000000 , 0 , 0 , 0 ,
0x80000000 , 0 , 0 , 0 ,
0x80000000 , 0 , 0 , 0 ,
0x80000000 , 0 , 0 , 0 ,
0x80000000 , 0 , 0 , 0 ,
0x80000000 , 0 , 0 , 0 ,
0x80000000 , 0 , 0 , 0 ,
0x80000000 , 0 , 0 , 0
} ;
2021-08-04 13:40:31 +02:00
static __amode31_data u32 __ctl_linkage_stack_amode31 [ 8 ] __aligned ( 64 ) = {
2021-06-15 19:17:36 +02:00
0 , 0 , 0x89000000 , 0 ,
0 , 0 , 0x8a000000 , 0
} ;
2021-08-04 13:40:31 +02:00
static u64 __amode31_ref * __ctl_aste = __ctl_aste_amode31 ;
static u32 __amode31_ref * __ctl_duald = __ctl_duald_amode31 ;
static u32 __amode31_ref * __ctl_linkage_stack = __ctl_linkage_stack_amode31 ;
static u32 __amode31_ref * __ctl_duct = __ctl_duct_amode31 ;
2021-06-15 19:17:36 +02:00
2017-11-17 18:44:28 +01:00
int __bootdata ( noexec_disabled ) ;
2020-10-19 11:01:33 +02:00
unsigned long __bootdata ( ident_map_size ) ;
2018-04-11 11:56:55 +02:00
struct mem_detect_info __bootdata ( mem_detect ) ;
2021-06-15 14:15:07 +02:00
struct initrd_data __bootdata ( initrd_data ) ;
2005-04-16 15:20:36 -07:00
2019-02-03 21:37:20 +01:00
unsigned long __bootdata_preserved ( __kaslr_offset ) ;
2021-09-27 14:18:26 +02:00
unsigned long __bootdata ( __amode31_base ) ;
2020-01-30 22:16:27 -08:00
unsigned int __bootdata_preserved ( zlib_dfltcc_support ) ;
EXPORT_SYMBOL ( zlib_dfltcc_support ) ;
2021-05-05 22:01:10 +02:00
u64 __bootdata_preserved ( stfle_fac_list [ 16 ] ) ;
EXPORT_SYMBOL ( stfle_fac_list ) ;
u64 __bootdata_preserved ( alt_stfle_fac_list [ 16 ] ) ;
2021-06-15 14:25:41 +02:00
struct oldmem_data __bootdata_preserved ( oldmem_data ) ;
2019-02-03 21:37:20 +01:00
2011-12-27 11:27:07 +01:00
unsigned long VMALLOC_START ;
EXPORT_SYMBOL ( VMALLOC_START ) ;
unsigned long VMALLOC_END ;
EXPORT_SYMBOL ( VMALLOC_END ) ;
struct page * vmemmap ;
EXPORT_SYMBOL ( vmemmap ) ;
2020-09-11 12:51:59 +02:00
unsigned long vmemmap_size ;
2011-12-27 11:27:07 +01:00
2012-10-05 16:52:18 +02:00
unsigned long MODULES_VADDR ;
unsigned long MODULES_END ;
2009-03-26 15:23:43 +01:00
/* An array with a pointer to the lowcore of every CPU. */
2015-12-31 10:29:00 +01:00
struct lowcore * lowcore_ptr [ NR_CPUS ] ;
2009-03-26 15:23:43 +01:00
EXPORT_SYMBOL ( lowcore_ptr ) ;
2021-04-07 09:20:17 +02:00
DEFINE_STATIC_KEY_FALSE ( cpu_has_bear ) ;
2020-07-13 14:12:49 +02:00
/*
* The Write Back bit position in the physaddr is given by the SLPC PCI .
* Leaving the mask zero always uses write through which is safe
*/
unsigned long mio_wb_bit_mask __ro_after_init ;
2005-04-16 15:20:36 -07:00
/*
* This is set up by the setup - routine at boot - time
* for S390 need to find out , what we have to setup
* using address 0x10400 . . .
*/
# include <asm/setup.h>
/*
* condev = and conmode = setup parameter .
*/
static int __init condev_setup ( char * str )
{
int vdev ;
vdev = simple_strtoul ( str , & str , 0 ) ;
if ( vdev > = 0 & & vdev < 65536 ) {
console_devno = vdev ;
console_irq = - 1 ;
}
return 1 ;
}
__setup ( " condev= " , condev_setup ) ;
2009-08-23 18:09:06 +02:00
static void __init set_preferred_console ( void )
{
2016-07-07 07:52:38 +02:00
if ( CONSOLE_IS_3215 | | CONSOLE_IS_SCLP )
2009-08-23 18:09:06 +02:00
add_preferred_console ( " ttyS " , 0 , NULL ) ;
2009-09-11 10:28:56 +02:00
else if ( CONSOLE_IS_3270 )
2009-08-23 18:09:06 +02:00
add_preferred_console ( " tty3270 " , 0 , NULL ) ;
2016-07-07 07:52:38 +02:00
else if ( CONSOLE_IS_VT220 )
2021-04-27 21:40:10 +02:00
add_preferred_console ( " ttysclp " , 0 , NULL ) ;
2016-07-07 07:52:38 +02:00
else if ( CONSOLE_IS_HVC )
add_preferred_console ( " hvc " , 0 , NULL ) ;
2009-08-23 18:09:06 +02:00
}
2005-04-16 15:20:36 -07:00
static int __init conmode_setup ( char * str )
{
2008-02-05 16:50:41 +01:00
# if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
2019-08-19 17:32:44 +02:00
if ( ! strcmp ( str , " hwc " ) | | ! strcmp ( str , " sclp " ) )
2005-04-16 15:20:36 -07:00
SET_CONSOLE_SCLP ;
# endif
# if defined(CONFIG_TN3215_CONSOLE)
2019-08-19 17:32:44 +02:00
if ( ! strcmp ( str , " 3215 " ) )
2005-04-16 15:20:36 -07:00
SET_CONSOLE_3215 ;
# endif
# if defined(CONFIG_TN3270_CONSOLE)
2019-08-19 17:32:44 +02:00
if ( ! strcmp ( str , " 3270 " ) )
2005-04-16 15:20:36 -07:00
SET_CONSOLE_3270 ;
# endif
2009-08-23 18:09:06 +02:00
set_preferred_console ( ) ;
2005-04-16 15:20:36 -07:00
return 1 ;
}
__setup ( " conmode= " , conmode_setup ) ;
static void __init conmode_default ( void )
{
char query_buffer [ 1024 ] ;
char * ptr ;
if ( MACHINE_IS_VM ) {
2006-12-04 15:40:30 +01:00
cpcmd ( " QUERY CONSOLE " , query_buffer , 1024 , NULL ) ;
2005-04-16 15:20:36 -07:00
console_devno = simple_strtoul ( query_buffer + 5 , NULL , 16 ) ;
ptr = strstr ( query_buffer , " SUBCHANNEL = " ) ;
console_irq = simple_strtoul ( ptr + 13 , NULL , 16 ) ;
2006-12-04 15:40:30 +01:00
cpcmd ( " QUERY TERM " , query_buffer , 1024 , NULL ) ;
2005-04-16 15:20:36 -07:00
ptr = strstr ( query_buffer , " CONMODE " ) ;
/*
* Set the conmode to 3215 so that the device recognition
* will set the cu_type of the console to 3215. If the
* conmode is 3270 and we don ' t set it back then both
* 3215 and the 3270 driver will try to access the console
* device ( 3215 as console and 3270 as normal tty ) .
*/
2006-12-04 15:40:30 +01:00
cpcmd ( " TERM CONMODE 3215 " , NULL , 0 , NULL ) ;
2005-04-16 15:20:36 -07:00
if ( ptr = = NULL ) {
2008-02-05 16:50:41 +01:00
# if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
2005-04-16 15:20:36 -07:00
SET_CONSOLE_SCLP ;
# endif
return ;
}
2019-08-19 17:32:44 +02:00
if ( str_has_prefix ( ptr + 8 , " 3270 " ) ) {
2005-04-16 15:20:36 -07:00
# if defined(CONFIG_TN3270_CONSOLE)
SET_CONSOLE_3270 ;
# elif defined(CONFIG_TN3215_CONSOLE)
SET_CONSOLE_3215 ;
2008-02-05 16:50:41 +01:00
# elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
2005-04-16 15:20:36 -07:00
SET_CONSOLE_SCLP ;
# endif
2019-08-19 17:32:44 +02:00
} else if ( str_has_prefix ( ptr + 8 , " 3215 " ) ) {
2005-04-16 15:20:36 -07:00
# if defined(CONFIG_TN3215_CONSOLE)
SET_CONSOLE_3215 ;
# elif defined(CONFIG_TN3270_CONSOLE)
SET_CONSOLE_3270 ;
2008-02-05 16:50:41 +01:00
# elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
2005-04-16 15:20:36 -07:00
SET_CONSOLE_SCLP ;
# endif
}
2016-07-07 07:52:38 +02:00
} else if ( MACHINE_IS_KVM ) {
2016-08-25 15:17:02 -07:00
if ( sclp . has_vt220 & & IS_ENABLED ( CONFIG_SCLP_VT220_CONSOLE ) )
2016-07-07 07:52:38 +02:00
SET_CONSOLE_VT220 ;
2016-08-25 15:17:02 -07:00
else if ( sclp . has_linemode & & IS_ENABLED ( CONFIG_SCLP_CONSOLE ) )
2016-07-07 07:52:38 +02:00
SET_CONSOLE_SCLP ;
else
SET_CONSOLE_HVC ;
2005-04-16 15:20:36 -07:00
} else {
2008-02-05 16:50:41 +01:00
# if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
2005-04-16 15:20:36 -07:00
SET_CONSOLE_SCLP ;
# endif
}
}
2014-04-14 10:38:05 +02:00
# ifdef CONFIG_CRASH_DUMP
2013-04-30 17:18:46 +02:00
static void __init setup_zfcpdump ( void )
2007-04-27 16:01:49 +02:00
{
2020-09-29 20:24:55 +02:00
if ( ! is_ipl_type_dump ( ) )
2007-04-27 16:01:49 +02:00
return ;
2021-06-15 14:25:41 +02:00
if ( oldmem_data . start )
2011-11-14 11:19:05 +01:00
return ;
2013-04-30 17:18:46 +02:00
strcat ( boot_command_line , " cio_ignore=all,!ipldev,!condev " ) ;
2007-04-27 16:01:49 +02:00
console_loglevel = 2 ;
}
# else
2013-04-30 17:18:46 +02:00
static inline void setup_zfcpdump ( void ) { }
2014-04-14 10:38:05 +02:00
# endif /* CONFIG_CRASH_DUMP */
2007-04-27 16:01:49 +02:00
2005-04-16 15:20:36 -07:00
/*
* Reboot , halt and power_off stubs . They just call _machine_restart ,
* _machine_halt or _machine_power_off .
*/
void machine_restart ( char * command )
{
2007-11-20 11:13:31 +01:00
if ( ( ! in_interrupt ( ) & & ! in_atomic ( ) ) | | oops_in_progress )
2006-06-29 14:57:32 +02:00
/*
* Only unblank the console if we are called in enabled
* context or a bust_spinlocks cleared the way for us .
*/
console_unblank ( ) ;
2005-04-16 15:20:36 -07:00
_machine_restart ( command ) ;
}
void machine_halt ( void )
{
2006-06-29 14:57:32 +02:00
if ( ! in_interrupt ( ) | | oops_in_progress )
/*
* Only unblank the console if we are called in enabled
* context or a bust_spinlocks cleared the way for us .
*/
console_unblank ( ) ;
2005-04-16 15:20:36 -07:00
_machine_halt ( ) ;
}
void machine_power_off ( void )
{
2006-06-29 14:57:32 +02:00
if ( ! in_interrupt ( ) | | oops_in_progress )
/*
* Only unblank the console if we are called in enabled
* context or a bust_spinlocks cleared the way for us .
*/
console_unblank ( ) ;
2005-04-16 15:20:36 -07:00
_machine_power_off ( ) ;
}
2006-01-14 13:21:01 -08:00
/*
* Dummy power off function .
*/
void ( * pm_power_off ) ( void ) = machine_power_off ;
2013-01-07 13:56:17 +01:00
EXPORT_SYMBOL_GPL ( pm_power_off ) ;
2006-01-14 13:21:01 -08:00
2020-09-02 16:52:06 +02:00
void * restart_stack ;
2012-03-11 11:59:26 -04:00
2017-09-12 16:37:33 +02:00
unsigned long stack_alloc ( void )
{
# ifdef CONFIG_VMAP_STACK
2021-08-27 08:36:06 +02:00
void * ret ;
ret = __vmalloc_node ( THREAD_SIZE , THREAD_SIZE , THREADINFO_GFP ,
NUMA_NO_NODE , __builtin_return_address ( 0 ) ) ;
kmemleak_not_leak ( ret ) ;
return ( unsigned long ) ret ;
2017-09-12 16:37:33 +02:00
# else
2018-09-18 18:23:40 +02:00
return __get_free_pages ( GFP_KERNEL , THREAD_SIZE_ORDER ) ;
2017-09-12 16:37:33 +02:00
# endif
}
void stack_free ( unsigned long stack )
{
# ifdef CONFIG_VMAP_STACK
vfree ( ( void * ) stack ) ;
# else
2018-09-18 18:23:40 +02:00
free_pages ( stack , THREAD_SIZE_ORDER ) ;
2017-09-12 16:37:33 +02:00
# endif
}
int __init arch_early_irq_init ( void )
{
unsigned long stack ;
2018-09-18 18:23:40 +02:00
stack = __get_free_pages ( GFP_KERNEL , THREAD_SIZE_ORDER ) ;
2017-09-12 16:37:33 +02:00
if ( ! stack )
panic ( " Couldn't allocate async stack " ) ;
S390_lowcore . async_stack = stack + STACK_INIT_OFFSET ;
return 0 ;
}
void __init arch_call_rest_init ( void )
{
unsigned long stack ;
stack = stack_alloc ( ) ;
if ( ! stack )
panic ( " Couldn't allocate kernel stack " ) ;
current - > stack = ( void * ) stack ;
# ifdef CONFIG_VMAP_STACK
current - > stack_vm_area = ( void * ) stack ;
# endif
set_task_stack_end_magic ( current ) ;
stack + = STACK_INIT_OFFSET ;
S390_lowcore . kernel_stack = stack ;
2021-07-05 17:55:32 +02:00
call_on_stack_noreturn ( rest_init , stack ) ;
2017-09-12 16:37:33 +02:00
}
2019-02-14 15:40:56 +01:00
static void __init setup_lowcore_dat_off ( void )
2005-05-01 08:58:57 -07:00
{
2020-09-24 01:01:29 +02:00
unsigned long int_psw_mask = PSW_KERNEL_BITS ;
2021-02-03 09:02:51 +01:00
unsigned long mcck_stack ;
2015-12-31 10:29:00 +01:00
struct lowcore * lc ;
2005-05-01 08:58:57 -07:00
2020-09-24 01:01:29 +02:00
if ( IS_ENABLED ( CONFIG_KASAN ) )
int_psw_mask | = PSW_MASK_DAT ;
2005-05-01 08:58:57 -07:00
/*
* Setup lowcore for boot cpu
*/
2017-07-05 07:37:27 +02:00
BUILD_BUG_ON ( sizeof ( struct lowcore ) ! = LC_PAGES * PAGE_SIZE ) ;
2018-10-30 15:08:04 -07:00
lc = memblock_alloc_low ( sizeof ( * lc ) , sizeof ( * lc ) ) ;
2019-03-11 23:30:31 -07:00
if ( ! lc )
panic ( " %s: Failed to allocate %zu bytes align=%zx \n " ,
__func__ , sizeof ( * lc ) , sizeof ( * lc ) ) ;
2013-09-24 09:14:56 +02:00
lc - > restart_psw . mask = PSW_KERNEL_BITS ;
2016-01-18 12:49:44 +01:00
lc - > restart_psw . addr = ( unsigned long ) restart_int_handler ;
2020-09-24 01:01:29 +02:00
lc - > external_new_psw . mask = int_psw_mask | PSW_MASK_MCHECK ;
2016-01-18 12:49:44 +01:00
lc - > external_new_psw . addr = ( unsigned long ) ext_int_handler ;
2020-09-24 01:01:29 +02:00
lc - > svc_new_psw . mask = int_psw_mask | PSW_MASK_MCHECK ;
2016-01-18 12:49:44 +01:00
lc - > svc_new_psw . addr = ( unsigned long ) system_call ;
2020-09-24 01:01:29 +02:00
lc - > program_new_psw . mask = int_psw_mask | PSW_MASK_MCHECK ;
2016-01-18 12:49:44 +01:00
lc - > program_new_psw . addr = ( unsigned long ) pgm_check_handler ;
2013-09-24 09:14:56 +02:00
lc - > mcck_new_psw . mask = PSW_KERNEL_BITS ;
2016-01-18 12:49:44 +01:00
lc - > mcck_new_psw . addr = ( unsigned long ) mcck_int_handler ;
2020-09-24 01:01:29 +02:00
lc - > io_new_psw . mask = int_psw_mask | PSW_MASK_MCHECK ;
2016-01-18 12:49:44 +01:00
lc - > io_new_psw . addr = ( unsigned long ) io_int_handler ;
2016-10-27 12:41:39 +02:00
lc - > clock_comparator = clock_comparator_max ;
2017-09-12 16:37:33 +02:00
lc - > nodat_stack = ( ( unsigned long ) & init_thread_union )
2013-04-24 10:20:43 +02:00
+ THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof ( struct pt_regs ) ;
2016-11-08 11:08:26 +01:00
lc - > current_task = ( unsigned long ) & init_task ;
2016-03-10 10:32:21 +01:00
lc - > lpp = LPP_MAGIC ;
2009-04-14 15:36:16 +02:00
lc - > machine_flags = S390_lowcore . machine_flags ;
2016-10-25 12:21:44 +02:00
lc - > preempt_count = S390_lowcore . preempt_count ;
2021-12-10 16:32:11 +01:00
nmi_alloc_mcesa_early ( & lc - > mcesad ) ;
2020-11-21 11:14:56 +01:00
lc - > sys_enter_timer = S390_lowcore . sys_enter_timer ;
2009-04-14 15:36:29 +02:00
lc - > exit_timer = S390_lowcore . exit_timer ;
lc - > user_timer = S390_lowcore . user_timer ;
lc - > system_timer = S390_lowcore . system_timer ;
lc - > steal_timer = S390_lowcore . steal_timer ;
lc - > last_update_timer = S390_lowcore . last_update_timer ;
lc - > last_update_clock = S390_lowcore . last_update_clock ;
2012-03-11 11:59:26 -04:00
2017-09-12 16:37:33 +02:00
/*
* Allocate the global restart stack which is the same for
* all CPUs in cast * one * of them does a PSW restart .
*/
2018-10-30 15:08:04 -07:00
restart_stack = memblock_alloc ( THREAD_SIZE , THREAD_SIZE ) ;
2019-03-11 23:30:31 -07:00
if ( ! restart_stack )
panic ( " %s: Failed to allocate %lu bytes align=0x%lx \n " ,
__func__ , THREAD_SIZE , THREAD_SIZE ) ;
2017-09-12 16:37:33 +02:00
restart_stack + = STACK_INIT_OFFSET ;
2012-03-11 11:59:26 -04:00
/*
* Set up PSW restart to call ipl . c : do_restart ( ) . Copy the relevant
2013-12-13 12:53:42 +01:00
* restart data to the absolute zero lowcore . This is necessary if
2012-03-11 11:59:26 -04:00
* PSW restart is done on an offline CPU that has lowcore zero .
*/
lc - > restart_stack = ( unsigned long ) restart_stack ;
lc - > restart_fn = ( unsigned long ) do_restart ;
lc - > restart_data = 0 ;
2021-08-24 15:30:21 +02:00
lc - > restart_source = - 1U ;
2012-05-24 14:35:16 +02:00
2021-02-03 09:02:51 +01:00
mcck_stack = ( unsigned long ) memblock_alloc ( THREAD_SIZE , THREAD_SIZE ) ;
if ( ! mcck_stack )
panic ( " %s: Failed to allocate %lu bytes align=0x%lx \n " ,
__func__ , THREAD_SIZE , THREAD_SIZE ) ;
lc - > mcck_stack = mcck_stack + STACK_INIT_OFFSET ;
2012-05-24 14:35:16 +02:00
/* Setup absolute zero lowcore */
2022-03-17 15:03:03 +01:00
put_abs_lowcore ( restart_stack , lc - > restart_stack ) ;
put_abs_lowcore ( restart_fn , lc - > restart_fn ) ;
put_abs_lowcore ( restart_data , lc - > restart_data ) ;
put_abs_lowcore ( restart_source , lc - > restart_source ) ;
put_abs_lowcore ( restart_psw , lc - > restart_psw ) ;
2012-03-11 11:59:26 -04:00
2014-04-07 18:25:23 +02:00
lc - > spinlock_lockval = arch_spin_lockval ( 0 ) ;
s390/spinlock: introduce spinlock wait queueing
The queued spinlock code for s390 follows the principles of the common
code qspinlock implementation but with a few notable differences.
The format of the spinlock_t locking word differs, s390 needs to store
the logical CPU number of the lock holder in the spinlock_t to be able
to use the diagnose 9c directed yield hypervisor call.
The inline code sequences for spin_lock and spin_unlock are nice and
short. The inline portion of a spin_lock now typically looks like this:
lhi %r0,0 # 0 indicates an empty lock
l %r1,0x3a0 # CPU number + 1 from lowcore
cs %r0,%r1,<some_lock> # lock operation
jnz call_wait # on failure call wait function
locked:
...
call_wait:
la %r2,<some_lock>
brasl %r14,arch_spin_lock_wait
j locked
A spin_unlock is as simple as before:
lhi %r0,0
sth %r0,2(%r2) # unlock operation
After a CPU has queued itself it may not enable interrupts again for the
arch_spin_lock_flags() variant. The arch_spin_lock_wait_flags wait function
is removed.
To improve performance the code implements opportunistic lock stealing.
If the wait function finds a spinlock_t that indicates that the lock is
free but there are queued waiters, the CPU may steal the lock up to three
times without queueing itself. The lock stealing update the steal counter
in the lock word to prevent more than 3 steals. The counter is reset at
the time the CPU next in the queue successfully takes the lock.
While the queued spinlocks improve performance in a system with dedicated
CPUs, in a virtualized environment with continuously overcommitted CPUs
the queued spinlocks can have a negative effect on performance. This
is due to the fact that a queued CPU that is preempted by the hypervisor
will block the queue at some point even without holding the lock. With
the classic spinlock it does not matter if a CPU is preempted that waits
for the lock. Therefore use the queued spinlock code only if the system
runs with dedicated CPUs and fall back to classic spinlocks when running
with shared CPUs.
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2017-03-24 17:25:02 +01:00
lc - > spinlock_index = 0 ;
arch_spin_lock_setup ( 0 ) ;
2020-01-22 13:38:22 +01:00
lc - > return_lpswe = gen_lpswe ( __LC_RETURN_PSW ) ;
lc - > return_mcck_lpswe = gen_lpswe ( __LC_RETURN_MCCK_PSW ) ;
2021-07-07 17:33:38 +01:00
lc - > preempt_count = PREEMPT_DISABLED ;
2014-04-07 18:25:23 +02:00
2022-03-30 19:50:16 +02:00
set_prefix ( __pa ( lc ) ) ;
2009-03-26 15:23:43 +01:00
lowcore_ptr [ 0 ] = lc ;
2005-05-01 08:58:57 -07:00
}
2019-02-14 15:40:56 +01:00
static void __init setup_lowcore_dat_on ( void )
{
2021-08-24 15:30:21 +02:00
struct lowcore * lc = lowcore_ptr [ 0 ] ;
2022-03-17 15:03:03 +01:00
int cr ;
2021-08-24 15:30:21 +02:00
2019-02-18 18:10:08 +01:00
__ctl_clear_bit ( 0 , 28 ) ;
S390_lowcore . external_new_psw . mask | = PSW_MASK_DAT ;
S390_lowcore . svc_new_psw . mask | = PSW_MASK_DAT ;
S390_lowcore . program_new_psw . mask | = PSW_MASK_DAT ;
S390_lowcore . io_new_psw . mask | = PSW_MASK_DAT ;
2021-08-24 15:30:21 +02:00
__ctl_store ( S390_lowcore . cregs_save_area , 0 , 15 ) ;
2019-02-18 18:10:08 +01:00
__ctl_set_bit ( 0 , 28 ) ;
2022-03-17 15:03:03 +01:00
put_abs_lowcore ( restart_flags , RESTART_FLAG_CTLREGS ) ;
put_abs_lowcore ( program_new_psw , lc - > program_new_psw ) ;
for ( cr = 0 ; cr < ARRAY_SIZE ( lc - > cregs_save_area ) ; cr + + )
put_abs_lowcore ( cregs_save_area [ cr ] , lc - > cregs_save_area [ cr ] ) ;
2019-02-14 15:40:56 +01:00
}
2011-03-23 10:15:59 +01:00
static struct resource code_resource = {
. name = " Kernel code " ,
2016-01-26 21:57:22 +01:00
. flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM ,
2011-03-23 10:15:59 +01:00
} ;
static struct resource data_resource = {
. name = " Kernel data " ,
2016-01-26 21:57:22 +01:00
. flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM ,
2011-03-23 10:15:59 +01:00
} ;
2011-03-23 10:16:00 +01:00
static struct resource bss_resource = {
. name = " Kernel bss " ,
2016-01-26 21:57:22 +01:00
. flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM ,
2011-03-23 10:16:00 +01:00
} ;
2011-03-23 10:15:59 +01:00
static struct resource __initdata * standard_resources [ ] = {
& code_resource ,
& data_resource ,
2011-03-23 10:16:00 +01:00
& bss_resource ,
2011-03-23 10:15:59 +01:00
} ;
static void __init setup_resources ( void )
2005-05-01 08:58:57 -07:00
{
2011-03-23 10:15:59 +01:00
struct resource * res , * std_res , * sub_res ;
2020-10-13 16:58:08 -07:00
phys_addr_t start , end ;
2014-01-29 18:16:01 +01:00
int j ;
2020-10-13 16:58:08 -07:00
u64 i ;
2005-05-01 08:58:57 -07:00
2018-02-20 13:28:33 +01:00
code_resource . start = ( unsigned long ) _text ;
code_resource . end = ( unsigned long ) _etext - 1 ;
data_resource . start = ( unsigned long ) _etext ;
data_resource . end = ( unsigned long ) _edata - 1 ;
bss_resource . start = ( unsigned long ) __bss_start ;
bss_resource . end = ( unsigned long ) __bss_stop - 1 ;
2006-06-25 05:49:30 -07:00
2020-10-13 16:58:08 -07:00
for_each_mem_range ( i , & start , & end ) {
2018-10-30 15:08:04 -07:00
res = memblock_alloc ( sizeof ( * res ) , 8 ) ;
2019-03-11 23:30:31 -07:00
if ( ! res )
panic ( " %s: Failed to allocate %zu bytes align=0x%x \n " ,
__func__ , sizeof ( * res ) , 8 ) ;
2016-01-26 21:57:22 +01:00
res - > flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM ;
2014-01-29 18:16:01 +01:00
res - > name = " System RAM " ;
2020-10-13 16:58:08 -07:00
res - > start = start ;
/*
* In memblock , end points to the first byte after the
* range while in resourses , end points to the last byte in
* the range .
*/
res - > end = end - 1 ;
2005-05-01 08:58:57 -07:00
request_resource ( & iomem_resource , res ) ;
2007-02-05 21:18:24 +01:00
2011-03-23 10:15:59 +01:00
for ( j = 0 ; j < ARRAY_SIZE ( standard_resources ) ; j + + ) {
std_res = standard_resources [ j ] ;
if ( std_res - > start < res - > start | |
std_res - > start > res - > end )
continue ;
if ( std_res - > end > res - > end ) {
2018-10-30 15:08:04 -07:00
sub_res = memblock_alloc ( sizeof ( * sub_res ) , 8 ) ;
2019-03-11 23:30:31 -07:00
if ( ! sub_res )
panic ( " %s: Failed to allocate %zu bytes align=0x%x \n " ,
__func__ , sizeof ( * sub_res ) , 8 ) ;
2011-03-23 10:15:59 +01:00
* sub_res = * std_res ;
sub_res - > end = res - > end ;
std_res - > start = res - > end + 1 ;
request_resource ( res , sub_res ) ;
} else {
request_resource ( res , std_res ) ;
}
2007-02-05 21:18:24 +01:00
}
2005-05-01 08:58:57 -07:00
}
2016-05-31 09:14:00 +02:00
# ifdef CONFIG_CRASH_DUMP
/*
* Re - add removed crash kernel memory as reserved memory . This makes
* sure it will be mapped with the identity mapping and struct pages
* will be created , so it can be resized later on .
* However add it later since the crash kernel resource should not be
* part of the System RAM resource .
*/
if ( crashk_res . end ) {
2021-11-05 13:44:49 -07:00
memblock_add_node ( crashk_res . start , resource_size ( & crashk_res ) ,
0 , MEMBLOCK_NONE ) ;
2016-05-31 09:14:00 +02:00
memblock_reserve ( crashk_res . start , resource_size ( & crashk_res ) ) ;
insert_resource ( & iomem_resource , & crashk_res ) ;
}
# endif
2005-05-01 08:58:57 -07:00
}
2020-10-06 22:12:39 +02:00
static void __init setup_memory_end ( void )
2006-12-04 15:40:56 +01:00
{
2021-10-14 13:45:35 +02:00
memblock_remove ( ident_map_size , PHYS_ADDR_MAX - ident_map_size ) ;
2020-10-06 22:12:39 +02:00
max_pfn = max_low_pfn = PFN_DOWN ( ident_map_size ) ;
2020-10-19 11:01:33 +02:00
pr_notice ( " The maximum memory size is %luMB \n " , ident_map_size > > 20 ) ;
2006-12-04 15:40:56 +01:00
}
2011-10-30 15:16:40 +01:00
# ifdef CONFIG_CRASH_DUMP
/*
2020-04-24 10:39:04 +02:00
* When kdump is enabled , we have to ensure that no memory from the area
* [ 0 - crashkernel memory size ] is set offline - it will be exchanged with
* the crashkernel memory region when kdump is triggered . The crashkernel
* memory region can never get offlined ( pages are unmovable ) .
2011-10-30 15:16:40 +01:00
*/
static int kdump_mem_notifier ( struct notifier_block * nb ,
unsigned long action , void * data )
{
struct memory_notify * arg = data ;
2014-07-10 18:14:20 +02:00
if ( action ! = MEM_GOING_OFFLINE )
return NOTIFY_OK ;
2011-10-30 15:16:40 +01:00
if ( arg - > start_pfn < PFN_DOWN ( resource_size ( & crashk_res ) ) )
return NOTIFY_BAD ;
2020-04-24 10:39:04 +02:00
return NOTIFY_OK ;
2011-10-30 15:16:40 +01:00
}
static struct notifier_block kdump_mem_nb = {
. notifier_call = kdump_mem_notifier ,
} ;
# endif
/*
* Reserve memory for kdump kernel to be loaded with kexec
*/
static void __init reserve_crashkernel ( void )
{
# ifdef CONFIG_CRASH_DUMP
unsigned long long crash_base , crash_size ;
2014-01-29 18:16:01 +01:00
phys_addr_t low , high ;
2011-10-30 15:16:40 +01:00
int rc ;
2020-10-19 11:01:33 +02:00
rc = parse_crashkernel ( boot_command_line , ident_map_size , & crash_size ,
2011-10-30 15:16:40 +01:00
& crash_base ) ;
2014-01-29 18:16:01 +01:00
2011-10-30 15:16:44 +01:00
crash_base = ALIGN ( crash_base , KEXEC_CRASH_MEM_ALIGN ) ;
crash_size = ALIGN ( crash_size , KEXEC_CRASH_MEM_ALIGN ) ;
2014-01-29 18:16:01 +01:00
if ( rc | | crash_size = = 0 )
2011-10-30 15:16:40 +01:00
return ;
2014-01-29 18:16:01 +01:00
if ( memblock . memory . regions [ 0 ] . size < crash_size ) {
pr_info ( " crashkernel reservation failed: %s \n " ,
" first memory chunk must be at least crashkernel size " ) ;
2011-10-30 15:16:40 +01:00
return ;
}
2014-01-29 18:16:01 +01:00
2021-06-15 14:25:41 +02:00
low = crash_base ? : oldmem_data . start ;
2014-01-29 18:16:01 +01:00
high = low + crash_size ;
2021-06-15 14:25:41 +02:00
if ( low > = oldmem_data . start & & high < = oldmem_data . start + oldmem_data . size ) {
2014-01-29 18:16:01 +01:00
/* The crashkernel fits into OLDMEM, reuse OLDMEM */
crash_base = low ;
} else {
/* Find suitable area in free memory */
2015-05-06 13:18:59 +02:00
low = max_t ( unsigned long , crash_size , sclp . hsa_size ) ;
2014-01-29 18:16:01 +01:00
high = crash_base ? crash_base + crash_size : ULONG_MAX ;
if ( crash_base & & crash_base < low ) {
pr_info ( " crashkernel reservation failed: %s \n " ,
" crash_base too low " ) ;
return ;
}
low = crash_base ? : low ;
2021-09-02 15:00:26 -07:00
crash_base = memblock_phys_alloc_range ( crash_size ,
KEXEC_CRASH_MEM_ALIGN ,
low , high ) ;
2014-01-29 18:16:01 +01:00
}
if ( ! crash_base ) {
pr_info ( " crashkernel reservation failed: %s \n " ,
" no suitable area found " ) ;
2011-10-30 15:16:40 +01:00
return ;
}
2014-01-29 18:16:01 +01:00
2021-09-02 15:00:26 -07:00
if ( register_memory_notifier ( & kdump_mem_nb ) ) {
2021-11-05 13:43:19 -07:00
memblock_phys_free ( crash_base , crash_size ) ;
2014-01-29 18:16:01 +01:00
return ;
2021-09-02 15:00:26 -07:00
}
2014-01-29 18:16:01 +01:00
2021-06-15 14:25:41 +02:00
if ( ! oldmem_data . start & & MACHINE_IS_VM )
2011-10-30 15:16:40 +01:00
diag10_range ( PFN_DOWN ( crash_base ) , PFN_DOWN ( crash_size ) ) ;
crashk_res . start = crash_base ;
crashk_res . end = crash_base + crash_size - 1 ;
2014-01-29 18:16:01 +01:00
memblock_remove ( crash_base , crash_size ) ;
2011-10-30 15:16:40 +01:00
pr_info ( " Reserving %lluMB of memory at %lluMB "
" for crashkernel (System RAM: %luMB) \n " ,
2014-01-29 18:16:01 +01:00
crash_size > > 20 , crash_base > > 20 ,
( unsigned long ) memblock . memory . total_size > > 20 ) ;
2012-03-11 11:59:34 -04:00
os_info_crashkernel_add ( crash_base , crash_size ) ;
2011-10-30 15:16:40 +01:00
# endif
}
2014-01-29 18:16:01 +01:00
/*
* Reserve the initrd from being used by memblock
*/
static void __init reserve_initrd ( void )
2005-05-01 08:58:57 -07:00
{
2014-01-29 18:16:01 +01:00
# ifdef CONFIG_BLK_DEV_INITRD
2021-06-15 14:15:07 +02:00
if ( ! initrd_data . start | | ! initrd_data . size )
2016-12-27 14:47:42 +01:00
return ;
2021-10-07 15:01:39 +02:00
initrd_start = ( unsigned long ) __va ( initrd_data . start ) ;
2021-06-15 14:15:07 +02:00
initrd_end = initrd_start + initrd_data . size ;
memblock_reserve ( initrd_data . start , initrd_data . size ) ;
2014-01-29 18:16:01 +01:00
# endif
}
2005-04-16 15:20:36 -07:00
2019-02-21 14:23:04 +01:00
/*
* Reserve the memory area used to pass the certificate lists
*/
static void __init reserve_certificate_list ( void )
{
if ( ipl_cert_list_addr )
memblock_reserve ( ipl_cert_list_addr , ipl_cert_list_size ) ;
}
2018-04-11 11:56:55 +02:00
static void __init reserve_mem_detect_info ( void )
{
unsigned long start , size ;
get_mem_detect_reserved ( & start , & size ) ;
if ( size )
memblock_reserve ( start , size ) ;
}
static void __init free_mem_detect_info ( void )
{
unsigned long start , size ;
get_mem_detect_reserved ( & start , & size ) ;
if ( size )
2021-11-05 13:43:19 -07:00
memblock_phys_free ( start , size ) ;
2018-04-11 11:56:55 +02:00
}
2018-09-24 15:27:30 +02:00
static const char * __init get_mem_info_source ( void )
{
switch ( mem_detect . info_source ) {
case MEM_DETECT_SCLP_STOR_INFO :
return " sclp storage info " ;
case MEM_DETECT_DIAG260 :
return " diag260 " ;
case MEM_DETECT_SCLP_READ_INFO :
return " sclp read info " ;
case MEM_DETECT_BIN_SEARCH :
return " binary search " ;
}
return " none " ;
}
2018-04-11 11:56:55 +02:00
static void __init memblock_add_mem_detect_info ( void )
{
unsigned long start , end ;
int i ;
2020-10-13 16:57:54 -07:00
pr_debug ( " physmem info source: %s (%hhd) \n " ,
get_mem_info_source ( ) , mem_detect . info_source ) ;
2018-04-11 11:56:55 +02:00
/* keep memblock lists close to the kernel */
memblock_set_bottom_up ( true ) ;
2020-01-30 22:14:20 -08:00
for_each_mem_detect_block ( i , & start , & end ) {
memblock_add ( start , end - start ) ;
2018-04-11 11:56:55 +02:00
memblock_physmem_add ( start , end - start ) ;
2020-01-30 22:14:20 -08:00
}
2018-04-11 11:56:55 +02:00
memblock_set_bottom_up ( false ) ;
2020-02-19 13:29:15 +01:00
memblock_set_node ( 0 , ULONG_MAX , & memblock . memory , 0 ) ;
2018-04-11 11:56:55 +02:00
}
2014-01-29 18:16:01 +01:00
/*
* Check for initrd being in usable memory
*/
static void __init check_initrd ( void )
{
# ifdef CONFIG_BLK_DEV_INITRD
2021-06-15 14:15:07 +02:00
if ( initrd_data . start & & initrd_data . size & &
! memblock_is_region_memory ( initrd_data . start , initrd_data . size ) ) {
2016-12-13 16:19:11 +01:00
pr_err ( " The initial RAM disk does not fit into the memory \n " ) ;
2021-11-05 13:43:19 -07:00
memblock_phys_free ( initrd_data . start , initrd_data . size ) ;
2014-01-29 18:16:01 +01:00
initrd_start = initrd_end = 0 ;
}
# endif
}
/*
2015-06-16 14:03:37 +02:00
* Reserve memory used for lowcore / command line / kernel image .
2014-01-29 18:16:01 +01:00
*/
static void __init reserve_kernel ( void )
{
2021-06-16 14:10:03 +02:00
memblock_reserve ( 0 , STARTUP_NORMAL_OFFSET ) ;
2022-02-09 11:25:09 +01:00
memblock_reserve ( OLDMEM_BASE , sizeof ( unsigned long ) ) ;
memblock_reserve ( OLDMEM_SIZE , sizeof ( unsigned long ) ) ;
2021-09-27 14:18:26 +02:00
memblock_reserve ( __amode31_base , __eamode31 - __samode31 ) ;
2021-01-21 13:06:02 +01:00
memblock_reserve ( __pa ( sclp_early_sccb ) , EXT_SCCB_READ_SCP ) ;
memblock_reserve ( __pa ( _stext ) , _end - _stext ) ;
2014-01-29 18:16:01 +01:00
}
2006-09-20 15:58:41 +02:00
2014-01-29 18:16:01 +01:00
static void __init setup_memory ( void )
{
2020-10-13 16:58:08 -07:00
phys_addr_t start , end ;
u64 i ;
2005-04-16 15:20:36 -07:00
/*
2014-01-29 18:16:01 +01:00
* Init storage key for present memory
2005-04-16 15:20:36 -07:00
*/
2020-10-13 16:58:08 -07:00
for_each_mem_range ( i , & start , & end )
storage_key_init_range ( start , end ) ;
2005-05-01 08:58:58 -07:00
psw_set_key ( PAGE_DEFAULT_KEY ) ;
2005-05-01 08:58:57 -07:00
}
2005-04-16 15:20:36 -07:00
2021-08-04 13:40:31 +02:00
static void __init relocate_amode31_section ( void )
2021-06-15 19:17:36 +02:00
{
2021-09-27 14:18:26 +02:00
unsigned long amode31_size = __eamode31 - __samode31 ;
long amode31_offset = __amode31_base - __samode31 ;
2021-06-15 19:17:36 +02:00
long * ptr ;
2021-08-04 13:40:31 +02:00
pr_info ( " Relocating AMODE31 section of size 0x%08lx \n " , amode31_size ) ;
2021-06-15 19:17:36 +02:00
2021-08-04 13:40:31 +02:00
/* Move original AMODE31 section to the new one */
2021-09-27 14:18:26 +02:00
memmove ( ( void * ) __amode31_base , ( void * ) __samode31 , amode31_size ) ;
2021-08-04 13:40:31 +02:00
/* Zero out the old AMODE31 section to catch invalid accesses within it */
memset ( ( void * ) __samode31 , 0 , amode31_size ) ;
2021-06-15 19:17:36 +02:00
2021-08-04 13:40:31 +02:00
/* Update all AMODE31 region references */
for ( ptr = _start_amode31_refs ; ptr ! = _end_amode31_refs ; ptr + + )
* ptr + = amode31_offset ;
2021-06-15 19:17:36 +02:00
}
2021-08-04 13:40:31 +02:00
/* This must be called after AMODE31 relocation */
2021-06-15 19:17:36 +02:00
static void __init setup_cr ( void )
{
union ctlreg2 cr2 ;
union ctlreg5 cr5 ;
union ctlreg15 cr15 ;
__ctl_duct [ 1 ] = ( unsigned long ) __ctl_aste ;
__ctl_duct [ 2 ] = ( unsigned long ) __ctl_aste ;
__ctl_duct [ 4 ] = ( unsigned long ) __ctl_duald ;
/* Update control registers CR2, CR5 and CR15 */
__ctl_store ( cr2 . val , 2 , 2 ) ;
__ctl_store ( cr5 . val , 5 , 5 ) ;
__ctl_store ( cr15 . val , 15 , 15 ) ;
cr2 . ducto = ( unsigned long ) __ctl_duct > > 6 ;
cr5 . pasteo = ( unsigned long ) __ctl_duct > > 6 ;
cr15 . lsea = ( unsigned long ) __ctl_linkage_stack > > 3 ;
__ctl_load ( cr2 . val , 2 , 2 ) ;
__ctl_load ( cr5 . val , 5 , 5 ) ;
__ctl_load ( cr15 . val , 15 , 15 ) ;
}
2014-08-11 12:20:58 +02:00
/*
* Add system information as device randomness
*/
static void __init setup_randomness ( void )
{
struct sysinfo_3_2_2 * vmms ;
2021-10-07 12:14:09 +02:00
vmms = memblock_alloc ( PAGE_SIZE , PAGE_SIZE ) ;
2019-03-11 23:29:26 -07:00
if ( ! vmms )
panic ( " Failed to allocate memory for sysinfo structure \n " ) ;
2017-02-04 11:40:36 +01:00
if ( stsi ( vmms , 3 , 2 , 2 ) = = 0 & & vmms - > count )
2017-02-05 23:03:18 +01:00
add_device_randomness ( & vmms - > vm , sizeof ( vmms - > vm [ 0 ] ) * vmms - > count ) ;
2021-11-06 14:48:06 -07:00
memblock_free ( vmms , PAGE_SIZE ) ;
2014-08-11 12:20:58 +02:00
}
2016-04-01 15:42:15 +02:00
/*
* Find the correct size for the task_struct . This depends on
* the size of the struct fpu at the end of the thread_struct
* which is embedded in the task_struct .
*/
static void __init setup_task_size ( void )
{
int task_size = sizeof ( struct task_struct ) ;
if ( ! MACHINE_HAS_VX ) {
task_size - = sizeof ( __vector128 ) * __NUM_VXRS ;
task_size + = sizeof ( freg_t ) * __NUM_FPRS ;
}
arch_task_struct_size = task_size ;
}
2018-12-06 17:30:04 -05:00
/*
* Issue diagnose 318 to set the control program name and
* version codes .
*/
static void __init setup_control_program_code ( void )
{
union diag318_info diag318_info = {
. cpnc = CPNC_LINUX ,
2020-06-22 11:46:35 -04:00
. cpvc = 0 ,
2018-12-06 17:30:04 -05:00
} ;
if ( ! sclp . has_diag318 )
return ;
diag_stat_inc ( DIAG_STAT_X318 ) ;
asm volatile ( " diag %0,0,0x318 \n " : : " d " ( diag318_info . val ) ) ;
}
2019-02-21 14:23:04 +01:00
/*
* Print the component list from the IPL report
*/
static void __init log_component_list ( void )
{
struct ipl_rb_component_entry * ptr , * end ;
char * str ;
if ( ! early_ipl_comp_list_addr )
return ;
2019-12-18 11:24:43 +01:00
if ( ipl_block . hdr . flags & IPL_PL_FLAG_SIPL )
2019-02-21 14:23:04 +01:00
pr_info ( " Linux is running with Secure-IPL enabled \n " ) ;
else
pr_info ( " Linux is running with Secure-IPL disabled \n " ) ;
ptr = ( void * ) early_ipl_comp_list_addr ;
end = ( void * ) ptr + early_ipl_comp_list_size ;
pr_info ( " The IPL report contains the following components: \n " ) ;
while ( ptr < end ) {
if ( ptr - > flags & IPL_RB_COMPONENT_FLAG_SIGNED ) {
if ( ptr - > flags & IPL_RB_COMPONENT_FLAG_VERIFIED )
str = " signed, verified " ;
else
str = " signed, verification failed " ;
} else {
str = " not signed " ;
}
pr_info ( " %016llx - %016llx (%s) \n " ,
ptr - > addr , ptr - > addr + ptr - > len , str ) ;
ptr + + ;
}
}
2005-05-01 08:58:57 -07:00
/*
* Setup function called from init / main . c just after the banner
* was printed .
*/
2005-04-16 15:20:36 -07:00
2012-03-11 11:59:26 -04:00
void __init setup_arch ( char * * cmdline_p )
2005-05-01 08:58:57 -07:00
{
2005-04-16 15:20:36 -07:00
/*
2005-05-01 08:58:57 -07:00
* print what head . S has found out about the machine
2005-04-16 15:20:36 -07:00
*/
2008-03-25 18:47:44 +01:00
if ( MACHINE_IS_VM )
2008-12-25 13:39:40 +01:00
pr_info ( " Linux is running as a z/VM "
" guest operating system in 64-bit mode \n " ) ;
2009-08-23 18:09:06 +02:00
else if ( MACHINE_IS_KVM )
2008-12-25 13:39:40 +01:00
pr_info ( " Linux is running under KVM in 64-bit mode \n " ) ;
2010-02-26 22:37:38 +01:00
else if ( MACHINE_IS_LPAR )
2008-12-25 13:39:40 +01:00
pr_info ( " Linux is running natively in 64-bit mode \n " ) ;
2018-11-09 09:21:47 +01:00
else
pr_info ( " Linux is running as a guest in 64-bit mode \n " ) ;
2005-05-01 08:58:57 -07:00
2019-02-21 14:23:04 +01:00
log_component_list ( ) ;
2008-07-14 09:59:09 +02:00
/* Have one command line that is parsed and saved in /proc/cmdline */
/* boot_command_line has been already set up in early.c */
* cmdline_p = boot_command_line ;
2006-03-24 03:15:15 -08:00
2005-05-01 08:58:57 -07:00
ROOT_DEV = Root_RAM0 ;
2006-03-24 03:15:15 -08:00
2021-07-07 18:08:57 -07:00
setup_initial_init_mm ( _text , _etext , _edata , _end ) ;
2006-03-24 03:15:15 -08:00
2018-04-11 08:35:23 +02:00
if ( IS_ENABLED ( CONFIG_EXPOLINE_AUTO ) )
nospec_auto_detect ( ) ;
2020-06-18 17:17:19 +02:00
jump_label_init ( ) ;
2006-03-24 03:15:15 -08:00
parse_early_param ( ) ;
2015-10-14 15:53:06 +02:00
# ifdef CONFIG_CRASH_DUMP
/* Deactivate elfcorehdr= kernel parameter */
elfcorehdr_addr = ELFCORE_ADDR_MAX ;
# endif
2012-03-11 11:59:34 -04:00
os_info_init ( ) ;
2008-01-26 14:11:11 +01:00
setup_ipl ( ) ;
2016-04-01 15:42:15 +02:00
setup_task_size ( ) ;
2018-12-06 17:30:04 -05:00
setup_control_program_code ( ) ;
2014-01-29 18:16:01 +01:00
/* Do some memory reservations *before* memory is added to memblock */
reserve_kernel ( ) ;
reserve_initrd ( ) ;
2019-02-21 14:23:04 +01:00
reserve_certificate_list ( ) ;
2018-04-11 11:56:55 +02:00
reserve_mem_detect_info ( ) ;
2021-10-14 13:33:45 +02:00
memblock_set_current_limit ( ident_map_size ) ;
2014-01-29 18:16:01 +01:00
memblock_allow_resize ( ) ;
/* Get information about *all* installed memory */
2018-04-11 11:56:55 +02:00
memblock_add_mem_detect_info ( ) ;
2014-01-29 18:16:01 +01:00
2018-04-11 11:56:55 +02:00
free_mem_detect_info ( ) ;
2021-10-14 13:45:35 +02:00
setup_memory_end ( ) ;
memblock_dump_all ( ) ;
setup_memory ( ) ;
2014-01-29 18:16:01 +01:00
2021-08-04 13:40:31 +02:00
relocate_amode31_section ( ) ;
2021-06-15 19:17:36 +02:00
setup_cr ( ) ;
2020-09-11 11:38:21 +02:00
setup_uv ( ) ;
2020-10-19 11:01:33 +02:00
dma_contiguous_reserve ( ident_map_size ) ;
2017-08-07 15:16:15 +02:00
vmcp_cma_reserve ( ) ;
2020-12-08 19:47:15 +01:00
if ( MACHINE_HAS_EDAT2 )
hugetlb_cma_reserve ( PUD_SHIFT - PAGE_SHIFT ) ;
2014-01-29 18:16:01 +01:00
check_initrd ( ) ;
reserve_crashkernel ( ) ;
2015-10-29 10:28:26 +01:00
# ifdef CONFIG_CRASH_DUMP
2015-05-26 19:05:23 +02:00
/*
* Be aware that smp_save_dump_cpus ( ) triggers a system reset .
* Therefore CPU and device initialization should be done afterwards .
*/
smp_save_dump_cpus ( ) ;
2015-10-29 10:28:26 +01:00
# endif
2014-01-29 18:16:01 +01:00
2005-05-01 08:58:57 -07:00
setup_resources ( ) ;
2019-02-14 15:40:56 +01:00
setup_lowcore_dat_off ( ) ;
2013-12-16 14:31:26 +01:00
smp_fill_possible_mask ( ) ;
2016-04-14 12:35:22 +02:00
cpu_detect_mhz_feature ( ) ;
2005-04-16 15:20:36 -07:00
cpu_init ( ) ;
2014-03-06 18:25:13 +01:00
numa_setup ( ) ;
2016-12-03 09:48:01 +01:00
smp_detect_cpus ( ) ;
2016-12-03 09:50:21 +01:00
topology_init_early ( ) ;
2005-04-16 15:20:36 -07:00
2021-04-07 09:20:17 +02:00
if ( test_facility ( 193 ) )
static_branch_enable ( & cpu_has_bear ) ;
2005-04-16 15:20:36 -07:00
/*
* Create kernel page tables and switch to virtual addressing .
*/
paging_init ( ) ;
2019-02-14 15:40:56 +01:00
/*
* After paging_init created the kernel page table , the new PSWs
* in lowcore can now run with DAT enabled .
*/
setup_lowcore_dat_on ( ) ;
2005-04-16 15:20:36 -07:00
/* Setup default console */
conmode_default ( ) ;
2009-08-23 18:09:06 +02:00
set_preferred_console ( ) ;
2007-04-27 16:01:49 +02:00
s390: introduce CPU alternatives
Implement CPU alternatives, which allows to optionally patch newer
instructions at runtime, based on CPU facilities availability.
A new kernel boot parameter "noaltinstr" disables patching.
Current implementation is derived from x86 alternatives. Although
ideal instructions padding (when altinstr is longer then oldinstr)
is added at compile time, and no oldinstr nops optimization has to be
done at runtime. Also couple of compile time sanity checks are done:
1. oldinstr and altinstr must be <= 254 bytes long,
2. oldinstr and altinstr must not have an odd length.
alternative(oldinstr, altinstr, facility);
alternative_2(oldinstr, altinstr1, facility1, altinstr2, facility2);
Both compile time and runtime padding consists of either 6/4/2 bytes nop
or a jump (brcl) + 2 bytes nop filler if padding is longer then 6 bytes.
.altinstructions and .altinstr_replacement sections are part of
__init_begin : __init_end region and are freed after initialization.
Signed-off-by: Vasily Gorbik <gor@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2017-10-12 13:01:47 +02:00
apply_alternative_instructions ( ) ;
2018-01-26 12:46:47 +01:00
if ( IS_ENABLED ( CONFIG_EXPOLINE ) )
nospec_init_branches ( ) ;
s390: introduce CPU alternatives
Implement CPU alternatives, which allows to optionally patch newer
instructions at runtime, based on CPU facilities availability.
A new kernel boot parameter "noaltinstr" disables patching.
Current implementation is derived from x86 alternatives. Although
ideal instructions padding (when altinstr is longer then oldinstr)
is added at compile time, and no oldinstr nops optimization has to be
done at runtime. Also couple of compile time sanity checks are done:
1. oldinstr and altinstr must be <= 254 bytes long,
2. oldinstr and altinstr must not have an odd length.
alternative(oldinstr, altinstr, facility);
alternative_2(oldinstr, altinstr1, facility1, altinstr2, facility2);
Both compile time and runtime padding consists of either 6/4/2 bytes nop
or a jump (brcl) + 2 bytes nop filler if padding is longer then 6 bytes.
.altinstructions and .altinstr_replacement sections are part of
__init_begin : __init_end region and are freed after initialization.
Signed-off-by: Vasily Gorbik <gor@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2017-10-12 13:01:47 +02:00
2020-09-29 20:24:55 +02:00
/* Setup zfcp/nvme dump support */
2013-04-30 17:18:46 +02:00
setup_zfcpdump ( ) ;
2014-08-11 12:20:58 +02:00
/* Add system specific data to the random pool */
setup_randomness ( ) ;
2005-04-16 15:20:36 -07:00
}