1ab14de6cSHeiko Carstens /* 2155af2f9SHans-Joachim Picht * Copyright IBM Corp. 2007, 2009 3ab14de6cSHeiko Carstens * Author(s): Hongjie Yang <hongjie@us.ibm.com>, 4ab14de6cSHeiko Carstens * Heiko Carstens <heiko.carstens@de.ibm.com> 5ab14de6cSHeiko Carstens */ 6ab14de6cSHeiko Carstens 711af97e1SHendrik Brueckner #define KMSG_COMPONENT "setup" 811af97e1SHendrik Brueckner #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 911af97e1SHendrik Brueckner 1092e6ecf3SChristian Borntraeger #include <linux/compiler.h> 11ab14de6cSHeiko Carstens #include <linux/init.h> 12ab14de6cSHeiko Carstens #include <linux/errno.h> 13ab14de6cSHeiko Carstens #include <linux/string.h> 14ab14de6cSHeiko Carstens #include <linux/ctype.h> 15ab14de6cSHeiko Carstens #include <linux/lockdep.h> 16dcc096c5SPaul Gortmaker #include <linux/extable.h> 17ab14de6cSHeiko Carstens #include <linux/pfn.h> 18ab14de6cSHeiko Carstens #include <linux/uaccess.h> 1911af97e1SHendrik Brueckner #include <linux/kernel.h> 201ec2772eSMartin Schwidefsky #include <asm/diag.h> 21a0443fbbSHendrik Brueckner #include <asm/ebcdic.h> 2246b05d26SMichael Holzheu #include <asm/ipl.h> 23ab14de6cSHeiko Carstens #include <asm/lowcore.h> 24ab14de6cSHeiko Carstens #include <asm/processor.h> 25ab14de6cSHeiko Carstens #include <asm/sections.h> 26ab14de6cSHeiko Carstens #include <asm/setup.h> 2792e6ecf3SChristian Borntraeger #include <asm/sysinfo.h> 28ab14de6cSHeiko Carstens #include <asm/cpcmd.h> 29ab14de6cSHeiko Carstens #include <asm/sclp.h> 30a0616cdeSDavid Howells #include <asm/facility.h> 31a806170eSHeiko Carstens #include "entry.h" 32ab14de6cSHeiko Carstens 33ab14de6cSHeiko Carstens /* 34ab14de6cSHeiko Carstens * Create a Kernel NSS if the SAVESYS= parameter is defined 35ab14de6cSHeiko Carstens */ 36a0443fbbSHendrik Brueckner #define DEFSYS_CMD_SIZE 128 37ab14de6cSHeiko Carstens #define SAVESYS_CMD_SIZE 32 38ab14de6cSHeiko Carstens 39ab14de6cSHeiko Carstens char kernel_nss_name[NSS_NAME_SIZE + 1]; 40ab14de6cSHeiko Carstens 41a0443fbbSHendrik Brueckner static void __init setup_boot_command_line(void); 42a0443fbbSHendrik Brueckner 43b6112ccbSMartin Schwidefsky /* 44b6112ccbSMartin Schwidefsky * Get the TOD clock running. 45b6112ccbSMartin Schwidefsky */ 46b6112ccbSMartin Schwidefsky static void __init reset_tod_clock(void) 47b6112ccbSMartin Schwidefsky { 48b6112ccbSMartin Schwidefsky u64 time; 49b6112ccbSMartin Schwidefsky 501aae0560SHeiko Carstens if (store_tod_clock(&time) == 0) 51b6112ccbSMartin Schwidefsky return; 52b6112ccbSMartin Schwidefsky /* TOD clock not running. Set the clock to Unix Epoch. */ 531aae0560SHeiko Carstens if (set_tod_clock(TOD_UNIX_EPOCH) != 0 || store_tod_clock(&time) != 0) 54b6112ccbSMartin Schwidefsky disabled_wait(0); 55b6112ccbSMartin Schwidefsky 56b6112ccbSMartin Schwidefsky sched_clock_base_cc = TOD_UNIX_EPOCH; 57b89031e0SMartin Schwidefsky S390_lowcore.last_update_clock = sched_clock_base_cc; 58b6112ccbSMartin Schwidefsky } 59a0443fbbSHendrik Brueckner 60ab14de6cSHeiko Carstens #ifdef CONFIG_SHARED_KERNEL 61a0443fbbSHendrik Brueckner int __init savesys_ipl_nss(char *cmd, const int cmdlen); 62a0443fbbSHendrik Brueckner 63a0443fbbSHendrik Brueckner asm( 64a0443fbbSHendrik Brueckner " .section .init.text,\"ax\",@progbits\n" 65a0443fbbSHendrik Brueckner " .align 4\n" 66a0443fbbSHendrik Brueckner " .type savesys_ipl_nss, @function\n" 67a0443fbbSHendrik Brueckner "savesys_ipl_nss:\n" 68a0443fbbSHendrik Brueckner " stmg 6,15,48(15)\n" 69a0443fbbSHendrik Brueckner " lgr 14,3\n" 70a0443fbbSHendrik Brueckner " sam31\n" 71a0443fbbSHendrik Brueckner " diag 2,14,0x8\n" 72a0443fbbSHendrik Brueckner " sam64\n" 73a0443fbbSHendrik Brueckner " lgr 2,14\n" 74a0443fbbSHendrik Brueckner " lmg 6,15,48(15)\n" 75a0443fbbSHendrik Brueckner " br 14\n" 7618764463SHeiko Carstens " .size savesys_ipl_nss, .-savesys_ipl_nss\n" 7718764463SHeiko Carstens " .previous\n"); 78a0443fbbSHendrik Brueckner 79684d2fd4SHendrik Brueckner static __initdata char upper_command_line[COMMAND_LINE_SIZE]; 80684d2fd4SHendrik Brueckner 81ab14de6cSHeiko Carstens static noinline __init void create_kernel_nss(void) 82ab14de6cSHeiko Carstens { 83ab14de6cSHeiko Carstens unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size; 84ab14de6cSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD 85ab14de6cSHeiko Carstens unsigned int sinitrd_pfn, einitrd_pfn; 86ab14de6cSHeiko Carstens #endif 87ab14de6cSHeiko Carstens int response; 8869ac43b0SChen Liu int hlen; 89a0443fbbSHendrik Brueckner size_t len; 90ab14de6cSHeiko Carstens char *savesys_ptr; 91ab14de6cSHeiko Carstens char defsys_cmd[DEFSYS_CMD_SIZE]; 92ab14de6cSHeiko Carstens char savesys_cmd[SAVESYS_CMD_SIZE]; 93ab14de6cSHeiko Carstens 94ab14de6cSHeiko Carstens /* Do nothing if we are not running under VM */ 95ab14de6cSHeiko Carstens if (!MACHINE_IS_VM) 96ab14de6cSHeiko Carstens return; 97ab14de6cSHeiko Carstens 98ab14de6cSHeiko Carstens /* Convert COMMAND_LINE to upper case */ 99a0443fbbSHendrik Brueckner for (i = 0; i < strlen(boot_command_line); i++) 100a0443fbbSHendrik Brueckner upper_command_line[i] = toupper(boot_command_line[i]); 101ab14de6cSHeiko Carstens 102ab14de6cSHeiko Carstens savesys_ptr = strstr(upper_command_line, "SAVESYS="); 103ab14de6cSHeiko Carstens 104ab14de6cSHeiko Carstens if (!savesys_ptr) 105ab14de6cSHeiko Carstens return; 106ab14de6cSHeiko Carstens 107ab14de6cSHeiko Carstens savesys_ptr += 8; /* Point to the beginning of the NSS name */ 108ab14de6cSHeiko Carstens for (i = 0; i < NSS_NAME_SIZE; i++) { 109ab14de6cSHeiko Carstens if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0') 110ab14de6cSHeiko Carstens break; 111ab14de6cSHeiko Carstens kernel_nss_name[i] = savesys_ptr[i]; 112ab14de6cSHeiko Carstens } 113ab14de6cSHeiko Carstens 114ab14de6cSHeiko Carstens stext_pfn = PFN_DOWN(__pa(&_stext)); 115ab14de6cSHeiko Carstens eshared_pfn = PFN_DOWN(__pa(&_eshared)); 116ab14de6cSHeiko Carstens end_pfn = PFN_UP(__pa(&_end)); 117ab14de6cSHeiko Carstens min_size = end_pfn << 2; 118ab14de6cSHeiko Carstens 11969ac43b0SChen Liu hlen = snprintf(defsys_cmd, DEFSYS_CMD_SIZE, 12069ac43b0SChen Liu "DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X", 12169ac43b0SChen Liu kernel_nss_name, stext_pfn - 1, stext_pfn, 12269ac43b0SChen Liu eshared_pfn - 1, eshared_pfn, end_pfn); 123ab14de6cSHeiko Carstens 124ab14de6cSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD 125ab14de6cSHeiko Carstens if (INITRD_START && INITRD_SIZE) { 126ab14de6cSHeiko Carstens sinitrd_pfn = PFN_DOWN(__pa(INITRD_START)); 127ab14de6cSHeiko Carstens einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE)); 128ab14de6cSHeiko Carstens min_size = einitrd_pfn << 2; 12969ac43b0SChen Liu hlen += snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen, 13069ac43b0SChen Liu " EW %.5X-%.5X", sinitrd_pfn, einitrd_pfn); 131ab14de6cSHeiko Carstens } 132ab14de6cSHeiko Carstens #endif 133ab14de6cSHeiko Carstens 13469ac43b0SChen Liu snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen, 13569ac43b0SChen Liu " EW MINSIZE=%.7iK PARMREGS=0-13", min_size); 13669ac43b0SChen Liu defsys_cmd[DEFSYS_CMD_SIZE - 1] = '\0'; 137894e491eSHeiko Carstens snprintf(savesys_cmd, SAVESYS_CMD_SIZE, "SAVESYS %s \n IPL %s", 138ab14de6cSHeiko Carstens kernel_nss_name, kernel_nss_name); 139894e491eSHeiko Carstens savesys_cmd[SAVESYS_CMD_SIZE - 1] = '\0'; 140ab14de6cSHeiko Carstens 141ab14de6cSHeiko Carstens __cpcmd(defsys_cmd, NULL, 0, &response); 142ab14de6cSHeiko Carstens 143583b33bcSHongjie Yang if (response != 0) { 14411af97e1SHendrik Brueckner pr_err("Defining the Linux kernel NSS failed with rc=%d\n", 14511af97e1SHendrik Brueckner response); 146583b33bcSHongjie Yang kernel_nss_name[0] = '\0'; 147ab14de6cSHeiko Carstens return; 148583b33bcSHongjie Yang } 149ab14de6cSHeiko Carstens 150a0443fbbSHendrik Brueckner len = strlen(savesys_cmd); 151a0443fbbSHendrik Brueckner ASCEBC(savesys_cmd, len); 152a0443fbbSHendrik Brueckner response = savesys_ipl_nss(savesys_cmd, len); 153ab14de6cSHeiko Carstens 154a0443fbbSHendrik Brueckner /* On success: response is equal to the command size, 155a0443fbbSHendrik Brueckner * max SAVESYS_CMD_SIZE 156a0443fbbSHendrik Brueckner * On error: response contains the numeric portion of cp error message. 157a0443fbbSHendrik Brueckner * for SAVESYS it will be >= 263 15811af97e1SHendrik Brueckner * for missing privilege class, it will be 1 159a0443fbbSHendrik Brueckner */ 16011af97e1SHendrik Brueckner if (response > SAVESYS_CMD_SIZE || response == 1) { 16111af97e1SHendrik Brueckner pr_err("Saving the Linux kernel NSS failed with rc=%d\n", 16211af97e1SHendrik Brueckner response); 163583b33bcSHongjie Yang kernel_nss_name[0] = '\0'; 164ab14de6cSHeiko Carstens return; 165583b33bcSHongjie Yang } 166ab14de6cSHeiko Carstens 167b89031e0SMartin Schwidefsky /* re-initialize cputime accounting. */ 1681aae0560SHeiko Carstens sched_clock_base_cc = get_tod_clock(); 169b89031e0SMartin Schwidefsky S390_lowcore.last_update_clock = sched_clock_base_cc; 170b89031e0SMartin Schwidefsky S390_lowcore.last_update_timer = 0x7fffffffffffffffULL; 171b89031e0SMartin Schwidefsky S390_lowcore.user_timer = 0; 172b89031e0SMartin Schwidefsky S390_lowcore.system_timer = 0; 173b89031e0SMartin Schwidefsky asm volatile("SPT 0(%0)" : : "a" (&S390_lowcore.last_update_timer)); 174b89031e0SMartin Schwidefsky 175a0443fbbSHendrik Brueckner /* re-setup boot command line with new ipl vm parms */ 176a0443fbbSHendrik Brueckner ipl_update_parameters(); 177a0443fbbSHendrik Brueckner setup_boot_command_line(); 178a0443fbbSHendrik Brueckner 179ab14de6cSHeiko Carstens ipl_flags = IPL_NSS_VALID; 180ab14de6cSHeiko Carstens } 181ab14de6cSHeiko Carstens 182ab14de6cSHeiko Carstens #else /* CONFIG_SHARED_KERNEL */ 183ab14de6cSHeiko Carstens 184ab14de6cSHeiko Carstens static inline void create_kernel_nss(void) { } 185ab14de6cSHeiko Carstens 186ab14de6cSHeiko Carstens #endif /* CONFIG_SHARED_KERNEL */ 187ab14de6cSHeiko Carstens 188ab14de6cSHeiko Carstens /* 189ab14de6cSHeiko Carstens * Clear bss memory 190ab14de6cSHeiko Carstens */ 191ab14de6cSHeiko Carstens static noinline __init void clear_bss_section(void) 192ab14de6cSHeiko Carstens { 193229d9c6dSHeiko Carstens memset(__bss_start, 0, __bss_stop - __bss_start); 194ab14de6cSHeiko Carstens } 195ab14de6cSHeiko Carstens 196ab14de6cSHeiko Carstens /* 197ab14de6cSHeiko Carstens * Initialize storage key for kernel pages 198ab14de6cSHeiko Carstens */ 199ab14de6cSHeiko Carstens static noinline __init void init_kernel_storage_key(void) 200ab14de6cSHeiko Carstens { 201127c1fefSMartin Schwidefsky #if PAGE_DEFAULT_KEY 202ab14de6cSHeiko Carstens unsigned long end_pfn, init_pfn; 203ab14de6cSHeiko Carstens 204ab14de6cSHeiko Carstens end_pfn = PFN_UP(__pa(&_end)); 205ab14de6cSHeiko Carstens 206ab14de6cSHeiko Carstens for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++) 207e2b8d7afSMartin Schwidefsky page_set_storage_key(init_pfn << PAGE_SHIFT, 208e2b8d7afSMartin Schwidefsky PAGE_DEFAULT_KEY, 0); 209127c1fefSMartin Schwidefsky #endif 210ab14de6cSHeiko Carstens } 211ab14de6cSHeiko Carstens 212fade4dc4SHeiko Carstens static __initdata char sysinfo_page[PAGE_SIZE] __aligned(PAGE_SIZE); 21392e6ecf3SChristian Borntraeger 214ab14de6cSHeiko Carstens static noinline __init void detect_machine_type(void) 215ab14de6cSHeiko Carstens { 216fade4dc4SHeiko Carstens struct sysinfo_3_2_2 *vmms = (struct sysinfo_3_2_2 *)&sysinfo_page; 217fade4dc4SHeiko Carstens 21827d71602SMartin Schwidefsky /* Check current-configuration-level */ 219caf757c6SHeiko Carstens if (stsi(NULL, 0, 0, 0) <= 2) { 22027d71602SMartin Schwidefsky S390_lowcore.machine_flags |= MACHINE_FLAG_LPAR; 22192e6ecf3SChristian Borntraeger return; 22227d71602SMartin Schwidefsky } 22327d71602SMartin Schwidefsky /* Get virtual-machine cpu information. */ 224caf757c6SHeiko Carstens if (stsi(vmms, 3, 2, 2) || !vmms->count) 22592e6ecf3SChristian Borntraeger return; 226ab14de6cSHeiko Carstens 22792e6ecf3SChristian Borntraeger /* Running under KVM? If not we assume z/VM */ 228fade4dc4SHeiko Carstens if (!memcmp(vmms->vm[0].cpi, "\xd2\xe5\xd4", 3)) 229d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_KVM; 23092e6ecf3SChristian Borntraeger else 231d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_VM; 232ab14de6cSHeiko Carstens } 233ab14de6cSHeiko Carstens 2344b8fe77aSChristian Borntraeger static noinline __init void setup_arch_string(void) 2354b8fe77aSChristian Borntraeger { 2364b8fe77aSChristian Borntraeger struct sysinfo_1_1_1 *mach = (struct sysinfo_1_1_1 *)&sysinfo_page; 2374b8fe77aSChristian Borntraeger 2384b8fe77aSChristian Borntraeger if (stsi(mach, 1, 1, 1)) 2394b8fe77aSChristian Borntraeger return; 2404b8fe77aSChristian Borntraeger EBCASC(mach->manufacturer, sizeof(mach->manufacturer)); 2414b8fe77aSChristian Borntraeger EBCASC(mach->type, sizeof(mach->type)); 2424b8fe77aSChristian Borntraeger EBCASC(mach->model, sizeof(mach->model)); 2434b8fe77aSChristian Borntraeger EBCASC(mach->model_capacity, sizeof(mach->model_capacity)); 2444b8fe77aSChristian Borntraeger dump_stack_set_arch_desc("%-16.16s %-4.4s %-16.16s %-16.16s (%s)", 2454b8fe77aSChristian Borntraeger mach->manufacturer, 2464b8fe77aSChristian Borntraeger mach->type, 2474b8fe77aSChristian Borntraeger mach->model, 2484b8fe77aSChristian Borntraeger mach->model_capacity, 2494b8fe77aSChristian Borntraeger MACHINE_IS_LPAR ? "LPAR" : 2504b8fe77aSChristian Borntraeger MACHINE_IS_VM ? "z/VM" : 2514b8fe77aSChristian Borntraeger MACHINE_IS_KVM ? "KVM" : "unknown"); 2524b8fe77aSChristian Borntraeger } 2534b8fe77aSChristian Borntraeger 254fade4dc4SHeiko Carstens static __init void setup_topology(void) 255fade4dc4SHeiko Carstens { 256fade4dc4SHeiko Carstens int max_mnest; 257fade4dc4SHeiko Carstens 258fade4dc4SHeiko Carstens if (!test_facility(11)) 259fade4dc4SHeiko Carstens return; 260fade4dc4SHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_TOPOLOGY; 261fade4dc4SHeiko Carstens for (max_mnest = 6; max_mnest > 1; max_mnest--) { 262caf757c6SHeiko Carstens if (stsi(&sysinfo_page, 15, 1, max_mnest) == 0) 263fade4dc4SHeiko Carstens break; 264fade4dc4SHeiko Carstens } 265fade4dc4SHeiko Carstens topology_max_mnest = max_mnest; 266fade4dc4SHeiko Carstens } 267fade4dc4SHeiko Carstens 268a3415703SMichael Holzheu static void early_pgm_check_handler(void) 269ab14de6cSHeiko Carstens { 270ab14de6cSHeiko Carstens const struct exception_table_entry *fixup; 27150be6345SPhilipp Hachtmann unsigned long cr0, cr0_new; 272eb608fb3SHeiko Carstens unsigned long addr; 273ab14de6cSHeiko Carstens 274ab14de6cSHeiko Carstens addr = S390_lowcore.program_old_psw.addr; 2759cb1ccecSHeiko Carstens fixup = search_exception_tables(addr); 276ab14de6cSHeiko Carstens if (!fixup) 277ab14de6cSHeiko Carstens disabled_wait(0); 27850be6345SPhilipp Hachtmann /* Disable low address protection before storing into lowcore. */ 27950be6345SPhilipp Hachtmann __ctl_store(cr0, 0, 0); 28050be6345SPhilipp Hachtmann cr0_new = cr0 & ~(1UL << 28); 28150be6345SPhilipp Hachtmann __ctl_load(cr0_new, 0, 0); 282fecc868aSHeiko Carstens S390_lowcore.program_old_psw.addr = extable_fixup(fixup); 28350be6345SPhilipp Hachtmann __ctl_load(cr0, 0, 0); 284ab14de6cSHeiko Carstens } 285ab14de6cSHeiko Carstens 2865f954c34SHeiko Carstens static noinline __init void setup_lowcore_early(void) 287ab14de6cSHeiko Carstens { 288ab14de6cSHeiko Carstens psw_t psw; 289ab14de6cSHeiko Carstens 290b50511e4SMartin Schwidefsky psw.mask = PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA; 291fecc868aSHeiko Carstens psw.addr = (unsigned long) s390_base_ext_handler; 292ab14de6cSHeiko Carstens S390_lowcore.external_new_psw = psw; 293fecc868aSHeiko Carstens psw.addr = (unsigned long) s390_base_pgm_handler; 294ab14de6cSHeiko Carstens S390_lowcore.program_new_psw = psw; 295ab14de6cSHeiko Carstens s390_base_pgm_handler_fn = early_pgm_check_handler; 296ab14de6cSHeiko Carstens } 297ab14de6cSHeiko Carstens 29814375bc4SMartin Schwidefsky static noinline __init void setup_facility_list(void) 29914375bc4SMartin Schwidefsky { 3003ab121abSMichael Holzheu stfle(S390_lowcore.stfle_fac_list, 3013ab121abSMichael Holzheu ARRAY_SIZE(S390_lowcore.stfle_fac_list)); 30214375bc4SMartin Schwidefsky } 30314375bc4SMartin Schwidefsky 3042e5061e4SHeiko Carstens static __init void detect_diag9c(void) 3052e5061e4SHeiko Carstens { 3062e5061e4SHeiko Carstens unsigned int cpu_address; 3072e5061e4SHeiko Carstens int rc; 3082e5061e4SHeiko Carstens 3092e5061e4SHeiko Carstens cpu_address = stap(); 3101ec2772eSMartin Schwidefsky diag_stat_inc(DIAG_STAT_X09C); 3112e5061e4SHeiko Carstens asm volatile( 3122e5061e4SHeiko Carstens " diag %2,0,0x9c\n" 3132e5061e4SHeiko Carstens "0: la %0,0\n" 3142e5061e4SHeiko Carstens "1:\n" 3152e5061e4SHeiko Carstens EX_TABLE(0b,1b) 3162e5061e4SHeiko Carstens : "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc"); 3172e5061e4SHeiko Carstens if (!rc) 318d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG9C; 3192e5061e4SHeiko Carstens } 3202e5061e4SHeiko Carstens 3212e5061e4SHeiko Carstens static __init void detect_diag44(void) 3222e5061e4SHeiko Carstens { 3232e5061e4SHeiko Carstens int rc; 3242e5061e4SHeiko Carstens 3251ec2772eSMartin Schwidefsky diag_stat_inc(DIAG_STAT_X044); 3262e5061e4SHeiko Carstens asm volatile( 3272e5061e4SHeiko Carstens " diag 0,0,0x44\n" 3282e5061e4SHeiko Carstens "0: la %0,0\n" 3292e5061e4SHeiko Carstens "1:\n" 3302e5061e4SHeiko Carstens EX_TABLE(0b,1b) 3312e5061e4SHeiko Carstens : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc"); 3322e5061e4SHeiko Carstens if (!rc) 333d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG44; 3342e5061e4SHeiko Carstens } 3352e5061e4SHeiko Carstens 3362e5061e4SHeiko Carstens static __init void detect_machine_facilities(void) 3372e5061e4SHeiko Carstens { 3383c7ef08bSHeiko Carstens if (test_facility(8)) { 3393c7ef08bSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT1; 3403c7ef08bSHeiko Carstens __ctl_set_bit(0, 23); 3413c7ef08bSHeiko Carstens } 34285e9d0e5SHeiko Carstens if (test_facility(78)) 34385e9d0e5SHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT2; 34414375bc4SMartin Schwidefsky if (test_facility(3)) 345d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_IDTE; 34614375bc4SMartin Schwidefsky if (test_facility(40)) 34723d18e8dSHendrik Brueckner S390_lowcore.machine_flags |= MACHINE_FLAG_LPP; 348d35339a4SMartin Schwidefsky if (test_facility(50) && test_facility(73)) 349d35339a4SMartin Schwidefsky S390_lowcore.machine_flags |= MACHINE_FLAG_TE; 3501b948d6cSMartin Schwidefsky if (test_facility(51)) 3511b948d6cSMartin Schwidefsky S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_LC; 352b5510d9bSHendrik Brueckner if (test_facility(129)) { 35380703617SMartin Schwidefsky S390_lowcore.machine_flags |= MACHINE_FLAG_VX; 354b5510d9bSHendrik Brueckner __ctl_set_bit(0, 17); 3552e5061e4SHeiko Carstens } 356b5510d9bSHendrik Brueckner } 357b5510d9bSHendrik Brueckner 3581a36a39eSMartin Schwidefsky static inline void save_vector_registers(void) 3591a36a39eSMartin Schwidefsky { 3601a36a39eSMartin Schwidefsky #ifdef CONFIG_CRASH_DUMP 3611a36a39eSMartin Schwidefsky if (test_facility(129)) 3621a36a39eSMartin Schwidefsky save_vx_regs(boot_cpu_vector_save_area); 3631a36a39eSMartin Schwidefsky #endif 3641a36a39eSMartin Schwidefsky } 3651a36a39eSMartin Schwidefsky 366b5510d9bSHendrik Brueckner static int __init disable_vector_extension(char *str) 367b5510d9bSHendrik Brueckner { 368b5510d9bSHendrik Brueckner S390_lowcore.machine_flags &= ~MACHINE_FLAG_VX; 369b5510d9bSHendrik Brueckner __ctl_clear_bit(0, 17); 370b5510d9bSHendrik Brueckner return 1; 371b5510d9bSHendrik Brueckner } 372b5510d9bSHendrik Brueckner early_param("novx", disable_vector_extension); 3732e5061e4SHeiko Carstens 37461b0b016SMartin Schwidefsky static int __init cad_setup(char *str) 3752c72a44eSMartin Schwidefsky { 37661b0b016SMartin Schwidefsky int val; 37761b0b016SMartin Schwidefsky 37861b0b016SMartin Schwidefsky get_option(&str, &val); 37961b0b016SMartin Schwidefsky if (val && test_facility(128)) 38061b0b016SMartin Schwidefsky S390_lowcore.machine_flags |= MACHINE_FLAG_CAD; 3812c72a44eSMartin Schwidefsky return 0; 3822c72a44eSMartin Schwidefsky } 38361b0b016SMartin Schwidefsky early_param("cad", cad_setup); 3842c72a44eSMartin Schwidefsky 3852c72a44eSMartin Schwidefsky static int __init cad_init(void) 3862c72a44eSMartin Schwidefsky { 3872c72a44eSMartin Schwidefsky if (MACHINE_HAS_CAD) 3882c72a44eSMartin Schwidefsky /* Enable problem state CAD. */ 3892c72a44eSMartin Schwidefsky __ctl_set_bit(2, 3); 3902c72a44eSMartin Schwidefsky return 0; 3912c72a44eSMartin Schwidefsky } 3922c72a44eSMartin Schwidefsky early_initcall(cad_init); 3932c72a44eSMartin Schwidefsky 394761cdf6aSHeiko Carstens static __init void rescue_initrd(void) 395761cdf6aSHeiko Carstens { 396761cdf6aSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD 39727e7318cSHeiko Carstens unsigned long min_initrd_addr = (unsigned long) _end + (4UL << 20); 398761cdf6aSHeiko Carstens /* 39927e7318cSHeiko Carstens * Just like in case of IPL from VM reader we make sure there is a 40027e7318cSHeiko Carstens * gap of 4MB between end of kernel and start of initrd. 40127e7318cSHeiko Carstens * That way we can also be sure that saving an NSS will succeed, 40227e7318cSHeiko Carstens * which however only requires different segments. 403761cdf6aSHeiko Carstens */ 404761cdf6aSHeiko Carstens if (!INITRD_START || !INITRD_SIZE) 405761cdf6aSHeiko Carstens return; 40627e7318cSHeiko Carstens if (INITRD_START >= min_initrd_addr) 407761cdf6aSHeiko Carstens return; 40827e7318cSHeiko Carstens memmove((void *) min_initrd_addr, (void *) INITRD_START, INITRD_SIZE); 40927e7318cSHeiko Carstens INITRD_START = min_initrd_addr; 410761cdf6aSHeiko Carstens #endif 411761cdf6aSHeiko Carstens } 412761cdf6aSHeiko Carstens 413a0443fbbSHendrik Brueckner /* Set up boot command line */ 414684d2fd4SHendrik Brueckner static void __init append_to_cmdline(size_t (*ipl_data)(char *, size_t)) 415684d2fd4SHendrik Brueckner { 416684d2fd4SHendrik Brueckner char *parm, *delim; 417684d2fd4SHendrik Brueckner size_t rc, len; 418684d2fd4SHendrik Brueckner 419684d2fd4SHendrik Brueckner len = strlen(boot_command_line); 420684d2fd4SHendrik Brueckner 421684d2fd4SHendrik Brueckner delim = boot_command_line + len; /* '\0' character position */ 422684d2fd4SHendrik Brueckner parm = boot_command_line + len + 1; /* append right after '\0' */ 423684d2fd4SHendrik Brueckner 424684d2fd4SHendrik Brueckner rc = ipl_data(parm, COMMAND_LINE_SIZE - len - 1); 425684d2fd4SHendrik Brueckner if (rc) { 426684d2fd4SHendrik Brueckner if (*parm == '=') 427684d2fd4SHendrik Brueckner memmove(boot_command_line, parm + 1, rc); 428684d2fd4SHendrik Brueckner else 429684d2fd4SHendrik Brueckner *delim = ' '; /* replace '\0' with space */ 430684d2fd4SHendrik Brueckner } 431684d2fd4SHendrik Brueckner } 432684d2fd4SHendrik Brueckner 4331fb81057SMichael Holzheu static inline int has_ebcdic_char(const char *str) 434a0443fbbSHendrik Brueckner { 43561fd330dSMartin Schwidefsky int i; 43661fd330dSMartin Schwidefsky 4371fb81057SMichael Holzheu for (i = 0; str[i]; i++) 4381fb81057SMichael Holzheu if (str[i] & 0x80) 4391fb81057SMichael Holzheu return 1; 4401fb81057SMichael Holzheu return 0; 4411fb81057SMichael Holzheu } 44261fd330dSMartin Schwidefsky 4431fb81057SMichael Holzheu static void __init setup_boot_command_line(void) 4441fb81057SMichael Holzheu { 4451fb81057SMichael Holzheu COMMAND_LINE[ARCH_COMMAND_LINE_SIZE - 1] = 0; 4461fb81057SMichael Holzheu /* convert arch command line to ascii if necessary */ 4471fb81057SMichael Holzheu if (has_ebcdic_char(COMMAND_LINE)) 4481fb81057SMichael Holzheu EBCASC(COMMAND_LINE, ARCH_COMMAND_LINE_SIZE); 449a0443fbbSHendrik Brueckner /* copy arch command line */ 45061fd330dSMartin Schwidefsky strlcpy(boot_command_line, strstrip(COMMAND_LINE), 45161fd330dSMartin Schwidefsky ARCH_COMMAND_LINE_SIZE); 452a0443fbbSHendrik Brueckner 453a0443fbbSHendrik Brueckner /* append IPL PARM data to the boot command line */ 454684d2fd4SHendrik Brueckner if (MACHINE_IS_VM) 455684d2fd4SHendrik Brueckner append_to_cmdline(append_ipl_vmparm); 456684d2fd4SHendrik Brueckner 457684d2fd4SHendrik Brueckner append_to_cmdline(append_ipl_scpdata); 458a0443fbbSHendrik Brueckner } 459a0443fbbSHendrik Brueckner 460ab14de6cSHeiko Carstens /* 461ab14de6cSHeiko Carstens * Save ipl parameters, clear bss memory, initialize storage keys 462ab14de6cSHeiko Carstens * and create a kernel NSS at startup if the SAVESYS= parm is defined 463ab14de6cSHeiko Carstens */ 464ab14de6cSHeiko Carstens void __init startup_init(void) 465ab14de6cSHeiko Carstens { 466b6112ccbSMartin Schwidefsky reset_tod_clock(); 467ab14de6cSHeiko Carstens ipl_save_parameters(); 468761cdf6aSHeiko Carstens rescue_initrd(); 469ab14de6cSHeiko Carstens clear_bss_section(); 470*b1c0854dSMartin Schwidefsky time_early_init(); 471ab14de6cSHeiko Carstens init_kernel_storage_key(); 472ab14de6cSHeiko Carstens lockdep_off(); 473ab14de6cSHeiko Carstens setup_lowcore_early(); 47414375bc4SMartin Schwidefsky setup_facility_list(); 475a0443fbbSHendrik Brueckner detect_machine_type(); 4764b8fe77aSChristian Borntraeger setup_arch_string(); 477a0443fbbSHendrik Brueckner ipl_update_parameters(); 478a0443fbbSHendrik Brueckner setup_boot_command_line(); 479a0443fbbSHendrik Brueckner create_kernel_nss(); 4802e5061e4SHeiko Carstens detect_diag9c(); 4812e5061e4SHeiko Carstens detect_diag44(); 4822e5061e4SHeiko Carstens detect_machine_facilities(); 4831a36a39eSMartin Schwidefsky save_vector_registers(); 484fade4dc4SHeiko Carstens setup_topology(); 4857b50da53SMichael Holzheu sclp_early_detect(); 486ab14de6cSHeiko Carstens lockdep_on(); 487ab14de6cSHeiko Carstens } 488