1ab14de6cSHeiko Carstens /* 2ab14de6cSHeiko Carstens * arch/s390/kernel/early.c 3ab14de6cSHeiko Carstens * 4155af2f9SHans-Joachim Picht * Copyright IBM Corp. 2007, 2009 5ab14de6cSHeiko Carstens * Author(s): Hongjie Yang <hongjie@us.ibm.com>, 6ab14de6cSHeiko Carstens * Heiko Carstens <heiko.carstens@de.ibm.com> 7ab14de6cSHeiko Carstens */ 8ab14de6cSHeiko Carstens 911af97e1SHendrik Brueckner #define KMSG_COMPONENT "setup" 1011af97e1SHendrik Brueckner #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 1111af97e1SHendrik Brueckner 1292e6ecf3SChristian Borntraeger #include <linux/compiler.h> 13ab14de6cSHeiko Carstens #include <linux/init.h> 14ab14de6cSHeiko Carstens #include <linux/errno.h> 15ab14de6cSHeiko Carstens #include <linux/string.h> 16ab14de6cSHeiko Carstens #include <linux/ctype.h> 17dfd9f7abSHeiko Carstens #include <linux/ftrace.h> 18ab14de6cSHeiko Carstens #include <linux/lockdep.h> 19ab14de6cSHeiko Carstens #include <linux/module.h> 20ab14de6cSHeiko Carstens #include <linux/pfn.h> 21ab14de6cSHeiko Carstens #include <linux/uaccess.h> 2211af97e1SHendrik Brueckner #include <linux/kernel.h> 23a0443fbbSHendrik Brueckner #include <asm/ebcdic.h> 2446b05d26SMichael Holzheu #include <asm/ipl.h> 25ab14de6cSHeiko Carstens #include <asm/lowcore.h> 26ab14de6cSHeiko Carstens #include <asm/processor.h> 27ab14de6cSHeiko Carstens #include <asm/sections.h> 28ab14de6cSHeiko Carstens #include <asm/setup.h> 2992e6ecf3SChristian Borntraeger #include <asm/sysinfo.h> 30ab14de6cSHeiko Carstens #include <asm/cpcmd.h> 31ab14de6cSHeiko Carstens #include <asm/sclp.h> 32a806170eSHeiko Carstens #include "entry.h" 33ab14de6cSHeiko Carstens 34ab14de6cSHeiko Carstens /* 35ab14de6cSHeiko Carstens * Create a Kernel NSS if the SAVESYS= parameter is defined 36ab14de6cSHeiko Carstens */ 37a0443fbbSHendrik Brueckner #define DEFSYS_CMD_SIZE 128 38ab14de6cSHeiko Carstens #define SAVESYS_CMD_SIZE 32 39ab14de6cSHeiko Carstens 40ab14de6cSHeiko Carstens char kernel_nss_name[NSS_NAME_SIZE + 1]; 41ab14de6cSHeiko Carstens 42a0443fbbSHendrik Brueckner static void __init setup_boot_command_line(void); 43a0443fbbSHendrik Brueckner 44b6112ccbSMartin Schwidefsky /* 45b6112ccbSMartin Schwidefsky * Get the TOD clock running. 46b6112ccbSMartin Schwidefsky */ 47b6112ccbSMartin Schwidefsky static void __init reset_tod_clock(void) 48b6112ccbSMartin Schwidefsky { 49b6112ccbSMartin Schwidefsky u64 time; 50b6112ccbSMartin Schwidefsky 51b6112ccbSMartin Schwidefsky if (store_clock(&time) == 0) 52b6112ccbSMartin Schwidefsky return; 53b6112ccbSMartin Schwidefsky /* TOD clock not running. Set the clock to Unix Epoch. */ 54b6112ccbSMartin Schwidefsky if (set_clock(TOD_UNIX_EPOCH) != 0 || store_clock(&time) != 0) 55b6112ccbSMartin Schwidefsky disabled_wait(0); 56b6112ccbSMartin Schwidefsky 57b6112ccbSMartin Schwidefsky sched_clock_base_cc = TOD_UNIX_EPOCH; 58b89031e0SMartin Schwidefsky S390_lowcore.last_update_clock = sched_clock_base_cc; 59b6112ccbSMartin Schwidefsky } 60a0443fbbSHendrik Brueckner 61ab14de6cSHeiko Carstens #ifdef CONFIG_SHARED_KERNEL 62a0443fbbSHendrik Brueckner int __init savesys_ipl_nss(char *cmd, const int cmdlen); 63a0443fbbSHendrik Brueckner 64a0443fbbSHendrik Brueckner asm( 65a0443fbbSHendrik Brueckner " .section .init.text,\"ax\",@progbits\n" 66a0443fbbSHendrik Brueckner " .align 4\n" 67a0443fbbSHendrik Brueckner " .type savesys_ipl_nss, @function\n" 68a0443fbbSHendrik Brueckner "savesys_ipl_nss:\n" 69a0443fbbSHendrik Brueckner #ifdef CONFIG_64BIT 70a0443fbbSHendrik Brueckner " stmg 6,15,48(15)\n" 71a0443fbbSHendrik Brueckner " lgr 14,3\n" 72a0443fbbSHendrik Brueckner " sam31\n" 73a0443fbbSHendrik Brueckner " diag 2,14,0x8\n" 74a0443fbbSHendrik Brueckner " sam64\n" 75a0443fbbSHendrik Brueckner " lgr 2,14\n" 76a0443fbbSHendrik Brueckner " lmg 6,15,48(15)\n" 77a0443fbbSHendrik Brueckner #else 78a0443fbbSHendrik Brueckner " stm 6,15,24(15)\n" 79a0443fbbSHendrik Brueckner " lr 14,3\n" 80a0443fbbSHendrik Brueckner " diag 2,14,0x8\n" 81a0443fbbSHendrik Brueckner " lr 2,14\n" 82a0443fbbSHendrik Brueckner " lm 6,15,24(15)\n" 83a0443fbbSHendrik Brueckner #endif 84a0443fbbSHendrik Brueckner " br 14\n" 8518764463SHeiko Carstens " .size savesys_ipl_nss, .-savesys_ipl_nss\n" 8618764463SHeiko Carstens " .previous\n"); 87a0443fbbSHendrik Brueckner 88684d2fd4SHendrik Brueckner static __initdata char upper_command_line[COMMAND_LINE_SIZE]; 89684d2fd4SHendrik Brueckner 90ab14de6cSHeiko Carstens static noinline __init void create_kernel_nss(void) 91ab14de6cSHeiko Carstens { 92ab14de6cSHeiko Carstens unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size; 93ab14de6cSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD 94ab14de6cSHeiko Carstens unsigned int sinitrd_pfn, einitrd_pfn; 95ab14de6cSHeiko Carstens #endif 96ab14de6cSHeiko Carstens int response; 9769ac43b0SChen Liu int hlen; 98a0443fbbSHendrik Brueckner size_t len; 99ab14de6cSHeiko Carstens char *savesys_ptr; 100ab14de6cSHeiko Carstens char defsys_cmd[DEFSYS_CMD_SIZE]; 101ab14de6cSHeiko Carstens char savesys_cmd[SAVESYS_CMD_SIZE]; 102ab14de6cSHeiko Carstens 103ab14de6cSHeiko Carstens /* Do nothing if we are not running under VM */ 104ab14de6cSHeiko Carstens if (!MACHINE_IS_VM) 105ab14de6cSHeiko Carstens return; 106ab14de6cSHeiko Carstens 107ab14de6cSHeiko Carstens /* Convert COMMAND_LINE to upper case */ 108a0443fbbSHendrik Brueckner for (i = 0; i < strlen(boot_command_line); i++) 109a0443fbbSHendrik Brueckner upper_command_line[i] = toupper(boot_command_line[i]); 110ab14de6cSHeiko Carstens 111ab14de6cSHeiko Carstens savesys_ptr = strstr(upper_command_line, "SAVESYS="); 112ab14de6cSHeiko Carstens 113ab14de6cSHeiko Carstens if (!savesys_ptr) 114ab14de6cSHeiko Carstens return; 115ab14de6cSHeiko Carstens 116ab14de6cSHeiko Carstens savesys_ptr += 8; /* Point to the beginning of the NSS name */ 117ab14de6cSHeiko Carstens for (i = 0; i < NSS_NAME_SIZE; i++) { 118ab14de6cSHeiko Carstens if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0') 119ab14de6cSHeiko Carstens break; 120ab14de6cSHeiko Carstens kernel_nss_name[i] = savesys_ptr[i]; 121ab14de6cSHeiko Carstens } 122ab14de6cSHeiko Carstens 123ab14de6cSHeiko Carstens stext_pfn = PFN_DOWN(__pa(&_stext)); 124ab14de6cSHeiko Carstens eshared_pfn = PFN_DOWN(__pa(&_eshared)); 125ab14de6cSHeiko Carstens end_pfn = PFN_UP(__pa(&_end)); 126ab14de6cSHeiko Carstens min_size = end_pfn << 2; 127ab14de6cSHeiko Carstens 12869ac43b0SChen Liu hlen = snprintf(defsys_cmd, DEFSYS_CMD_SIZE, 12969ac43b0SChen Liu "DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X", 13069ac43b0SChen Liu kernel_nss_name, stext_pfn - 1, stext_pfn, 13169ac43b0SChen Liu eshared_pfn - 1, eshared_pfn, end_pfn); 132ab14de6cSHeiko Carstens 133ab14de6cSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD 134ab14de6cSHeiko Carstens if (INITRD_START && INITRD_SIZE) { 135ab14de6cSHeiko Carstens sinitrd_pfn = PFN_DOWN(__pa(INITRD_START)); 136ab14de6cSHeiko Carstens einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE)); 137ab14de6cSHeiko Carstens min_size = einitrd_pfn << 2; 13869ac43b0SChen Liu hlen += snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen, 13969ac43b0SChen Liu " EW %.5X-%.5X", sinitrd_pfn, einitrd_pfn); 140ab14de6cSHeiko Carstens } 141ab14de6cSHeiko Carstens #endif 142ab14de6cSHeiko Carstens 14369ac43b0SChen Liu snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen, 14469ac43b0SChen Liu " EW MINSIZE=%.7iK PARMREGS=0-13", min_size); 14569ac43b0SChen Liu defsys_cmd[DEFSYS_CMD_SIZE - 1] = '\0'; 146894e491eSHeiko Carstens snprintf(savesys_cmd, SAVESYS_CMD_SIZE, "SAVESYS %s \n IPL %s", 147ab14de6cSHeiko Carstens kernel_nss_name, kernel_nss_name); 148894e491eSHeiko Carstens savesys_cmd[SAVESYS_CMD_SIZE - 1] = '\0'; 149ab14de6cSHeiko Carstens 150ab14de6cSHeiko Carstens __cpcmd(defsys_cmd, NULL, 0, &response); 151ab14de6cSHeiko Carstens 152583b33bcSHongjie Yang if (response != 0) { 15311af97e1SHendrik Brueckner pr_err("Defining the Linux kernel NSS failed with rc=%d\n", 15411af97e1SHendrik Brueckner response); 155583b33bcSHongjie Yang kernel_nss_name[0] = '\0'; 156ab14de6cSHeiko Carstens return; 157583b33bcSHongjie Yang } 158ab14de6cSHeiko Carstens 159a0443fbbSHendrik Brueckner len = strlen(savesys_cmd); 160a0443fbbSHendrik Brueckner ASCEBC(savesys_cmd, len); 161a0443fbbSHendrik Brueckner response = savesys_ipl_nss(savesys_cmd, len); 162ab14de6cSHeiko Carstens 163a0443fbbSHendrik Brueckner /* On success: response is equal to the command size, 164a0443fbbSHendrik Brueckner * max SAVESYS_CMD_SIZE 165a0443fbbSHendrik Brueckner * On error: response contains the numeric portion of cp error message. 166a0443fbbSHendrik Brueckner * for SAVESYS it will be >= 263 16711af97e1SHendrik Brueckner * for missing privilege class, it will be 1 168a0443fbbSHendrik Brueckner */ 16911af97e1SHendrik Brueckner if (response > SAVESYS_CMD_SIZE || response == 1) { 17011af97e1SHendrik Brueckner pr_err("Saving the Linux kernel NSS failed with rc=%d\n", 17111af97e1SHendrik Brueckner response); 172583b33bcSHongjie Yang kernel_nss_name[0] = '\0'; 173ab14de6cSHeiko Carstens return; 174583b33bcSHongjie Yang } 175ab14de6cSHeiko Carstens 176b89031e0SMartin Schwidefsky /* re-initialize cputime accounting. */ 177b89031e0SMartin Schwidefsky sched_clock_base_cc = get_clock(); 178b89031e0SMartin Schwidefsky S390_lowcore.last_update_clock = sched_clock_base_cc; 179b89031e0SMartin Schwidefsky S390_lowcore.last_update_timer = 0x7fffffffffffffffULL; 180b89031e0SMartin Schwidefsky S390_lowcore.user_timer = 0; 181b89031e0SMartin Schwidefsky S390_lowcore.system_timer = 0; 182b89031e0SMartin Schwidefsky asm volatile("SPT 0(%0)" : : "a" (&S390_lowcore.last_update_timer)); 183b89031e0SMartin Schwidefsky 184a0443fbbSHendrik Brueckner /* re-setup boot command line with new ipl vm parms */ 185a0443fbbSHendrik Brueckner ipl_update_parameters(); 186a0443fbbSHendrik Brueckner setup_boot_command_line(); 187a0443fbbSHendrik Brueckner 188ab14de6cSHeiko Carstens ipl_flags = IPL_NSS_VALID; 189ab14de6cSHeiko Carstens } 190ab14de6cSHeiko Carstens 191ab14de6cSHeiko Carstens #else /* CONFIG_SHARED_KERNEL */ 192ab14de6cSHeiko Carstens 193ab14de6cSHeiko Carstens static inline void create_kernel_nss(void) { } 194ab14de6cSHeiko Carstens 195ab14de6cSHeiko Carstens #endif /* CONFIG_SHARED_KERNEL */ 196ab14de6cSHeiko Carstens 197ab14de6cSHeiko Carstens /* 198ab14de6cSHeiko Carstens * Clear bss memory 199ab14de6cSHeiko Carstens */ 200ab14de6cSHeiko Carstens static noinline __init void clear_bss_section(void) 201ab14de6cSHeiko Carstens { 202229d9c6dSHeiko Carstens memset(__bss_start, 0, __bss_stop - __bss_start); 203ab14de6cSHeiko Carstens } 204ab14de6cSHeiko Carstens 205ab14de6cSHeiko Carstens /* 206ab14de6cSHeiko Carstens * Initialize storage key for kernel pages 207ab14de6cSHeiko Carstens */ 208ab14de6cSHeiko Carstens static noinline __init void init_kernel_storage_key(void) 209ab14de6cSHeiko Carstens { 210ab14de6cSHeiko Carstens unsigned long end_pfn, init_pfn; 211ab14de6cSHeiko Carstens 212ab14de6cSHeiko Carstens end_pfn = PFN_UP(__pa(&_end)); 213ab14de6cSHeiko Carstens 214ab14de6cSHeiko Carstens for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++) 215e2b8d7afSMartin Schwidefsky page_set_storage_key(init_pfn << PAGE_SHIFT, 216e2b8d7afSMartin Schwidefsky PAGE_DEFAULT_KEY, 0); 217ab14de6cSHeiko Carstens } 218ab14de6cSHeiko Carstens 21992e6ecf3SChristian Borntraeger static __initdata struct sysinfo_3_2_2 vmms __aligned(PAGE_SIZE); 22092e6ecf3SChristian Borntraeger 221ab14de6cSHeiko Carstens static noinline __init void detect_machine_type(void) 222ab14de6cSHeiko Carstens { 22327d71602SMartin Schwidefsky /* Check current-configuration-level */ 22427d71602SMartin Schwidefsky if ((stsi(NULL, 0, 0, 0) >> 28) <= 2) { 22527d71602SMartin Schwidefsky S390_lowcore.machine_flags |= MACHINE_FLAG_LPAR; 22692e6ecf3SChristian Borntraeger return; 22727d71602SMartin Schwidefsky } 22827d71602SMartin Schwidefsky /* Get virtual-machine cpu information. */ 22927d71602SMartin Schwidefsky if (stsi(&vmms, 3, 2, 2) == -ENOSYS || !vmms.count) 23092e6ecf3SChristian Borntraeger return; 231ab14de6cSHeiko Carstens 23292e6ecf3SChristian Borntraeger /* Running under KVM? If not we assume z/VM */ 23392e6ecf3SChristian Borntraeger if (!memcmp(vmms.vm[0].cpi, "\xd2\xe5\xd4", 3)) 234d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_KVM; 23592e6ecf3SChristian Borntraeger else 236d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_VM; 237ab14de6cSHeiko Carstens } 238ab14de6cSHeiko Carstens 2395f954c34SHeiko Carstens static __init void early_pgm_check_handler(void) 240ab14de6cSHeiko Carstens { 241ab14de6cSHeiko Carstens unsigned long addr; 242ab14de6cSHeiko Carstens const struct exception_table_entry *fixup; 243ab14de6cSHeiko Carstens 244ab14de6cSHeiko Carstens addr = S390_lowcore.program_old_psw.addr; 245ab14de6cSHeiko Carstens fixup = search_exception_tables(addr & PSW_ADDR_INSN); 246ab14de6cSHeiko Carstens if (!fixup) 247ab14de6cSHeiko Carstens disabled_wait(0); 248ab14de6cSHeiko Carstens S390_lowcore.program_old_psw.addr = fixup->fixup | PSW_ADDR_AMODE; 249ab14de6cSHeiko Carstens } 250ab14de6cSHeiko Carstens 2515f954c34SHeiko Carstens static noinline __init void setup_lowcore_early(void) 252ab14de6cSHeiko Carstens { 253ab14de6cSHeiko Carstens psw_t psw; 254ab14de6cSHeiko Carstens 255b50511e4SMartin Schwidefsky psw.mask = PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA; 256ab14de6cSHeiko Carstens psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_ext_handler; 257ab14de6cSHeiko Carstens S390_lowcore.external_new_psw = psw; 258ab14de6cSHeiko Carstens psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler; 259ab14de6cSHeiko Carstens S390_lowcore.program_new_psw = psw; 260ab14de6cSHeiko Carstens s390_base_pgm_handler_fn = early_pgm_check_handler; 261ab14de6cSHeiko Carstens } 262ab14de6cSHeiko Carstens 26314375bc4SMartin Schwidefsky static noinline __init void setup_facility_list(void) 26414375bc4SMartin Schwidefsky { 26514375bc4SMartin Schwidefsky unsigned long nr; 26614375bc4SMartin Schwidefsky 26714375bc4SMartin Schwidefsky S390_lowcore.stfl_fac_list = 0; 26814375bc4SMartin Schwidefsky asm volatile( 26914375bc4SMartin Schwidefsky " .insn s,0xb2b10000,0(0)\n" /* stfl */ 27014375bc4SMartin Schwidefsky "0:\n" 27114375bc4SMartin Schwidefsky EX_TABLE(0b,0b) : "=m" (S390_lowcore.stfl_fac_list)); 27214375bc4SMartin Schwidefsky memcpy(&S390_lowcore.stfle_fac_list, &S390_lowcore.stfl_fac_list, 4); 27314375bc4SMartin Schwidefsky nr = 4; /* # bytes stored by stfl */ 27414375bc4SMartin Schwidefsky if (test_facility(7)) { 27514375bc4SMartin Schwidefsky /* More facility bits available with stfle */ 27614375bc4SMartin Schwidefsky register unsigned long reg0 asm("0") = MAX_FACILITY_BIT/64 - 1; 27714375bc4SMartin Schwidefsky asm volatile(".insn s,0xb2b00000,%0" /* stfle */ 27814375bc4SMartin Schwidefsky : "=m" (S390_lowcore.stfle_fac_list), "+d" (reg0) 27914375bc4SMartin Schwidefsky : : "cc"); 28014375bc4SMartin Schwidefsky nr = (reg0 + 1) * 8; /* # bytes stored by stfle */ 28114375bc4SMartin Schwidefsky } 28214375bc4SMartin Schwidefsky memset((char *) S390_lowcore.stfle_fac_list + nr, 0, 28314375bc4SMartin Schwidefsky MAX_FACILITY_BIT/8 - nr); 28414375bc4SMartin Schwidefsky } 28514375bc4SMartin Schwidefsky 28653492b1dSGerald Schaefer static noinline __init void setup_hpage(void) 28753492b1dSGerald Schaefer { 28853492b1dSGerald Schaefer #ifndef CONFIG_DEBUG_PAGEALLOC 28914375bc4SMartin Schwidefsky if (!test_facility(2) || !test_facility(8)) 29053492b1dSGerald Schaefer return; 291d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_HPAGE; 29253492b1dSGerald Schaefer __ctl_set_bit(0, 23); 29353492b1dSGerald Schaefer #endif 29453492b1dSGerald Schaefer } 29553492b1dSGerald Schaefer 2962e5061e4SHeiko Carstens static __init void detect_mvpg(void) 2972e5061e4SHeiko Carstens { 2982e5061e4SHeiko Carstens #ifndef CONFIG_64BIT 2992e5061e4SHeiko Carstens int rc; 3002e5061e4SHeiko Carstens 3012e5061e4SHeiko Carstens asm volatile( 3022e5061e4SHeiko Carstens " la 0,0\n" 3032e5061e4SHeiko Carstens " mvpg %2,%2\n" 3042e5061e4SHeiko Carstens "0: la %0,0\n" 3052e5061e4SHeiko Carstens "1:\n" 3062e5061e4SHeiko Carstens EX_TABLE(0b,1b) 3072e5061e4SHeiko Carstens : "=d" (rc) : "0" (-EOPNOTSUPP), "a" (0) : "memory", "cc", "0"); 3082e5061e4SHeiko Carstens if (!rc) 309d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_MVPG; 3102e5061e4SHeiko Carstens #endif 3112e5061e4SHeiko Carstens } 3122e5061e4SHeiko Carstens 3132e5061e4SHeiko Carstens static __init void detect_ieee(void) 3142e5061e4SHeiko Carstens { 3152e5061e4SHeiko Carstens #ifndef CONFIG_64BIT 3162e5061e4SHeiko Carstens int rc, tmp; 3172e5061e4SHeiko Carstens 3182e5061e4SHeiko Carstens asm volatile( 3192e5061e4SHeiko Carstens " efpc %1,0\n" 3202e5061e4SHeiko Carstens "0: la %0,0\n" 3212e5061e4SHeiko Carstens "1:\n" 3222e5061e4SHeiko Carstens EX_TABLE(0b,1b) 3232e5061e4SHeiko Carstens : "=d" (rc), "=d" (tmp): "0" (-EOPNOTSUPP) : "cc"); 3242e5061e4SHeiko Carstens if (!rc) 325d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_IEEE; 3262e5061e4SHeiko Carstens #endif 3272e5061e4SHeiko Carstens } 3282e5061e4SHeiko Carstens 3292e5061e4SHeiko Carstens static __init void detect_csp(void) 3302e5061e4SHeiko Carstens { 3312e5061e4SHeiko Carstens #ifndef CONFIG_64BIT 3322e5061e4SHeiko Carstens int rc; 3332e5061e4SHeiko Carstens 3342e5061e4SHeiko Carstens asm volatile( 3352e5061e4SHeiko Carstens " la 0,0\n" 3362e5061e4SHeiko Carstens " la 1,0\n" 3372e5061e4SHeiko Carstens " la 2,4\n" 3382e5061e4SHeiko Carstens " csp 0,2\n" 3392e5061e4SHeiko Carstens "0: la %0,0\n" 3402e5061e4SHeiko Carstens "1:\n" 3412e5061e4SHeiko Carstens EX_TABLE(0b,1b) 3422e5061e4SHeiko Carstens : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc", "0", "1", "2"); 3432e5061e4SHeiko Carstens if (!rc) 344d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_CSP; 3452e5061e4SHeiko Carstens #endif 3462e5061e4SHeiko Carstens } 3472e5061e4SHeiko Carstens 3482e5061e4SHeiko Carstens static __init void detect_diag9c(void) 3492e5061e4SHeiko Carstens { 3502e5061e4SHeiko Carstens unsigned int cpu_address; 3512e5061e4SHeiko Carstens int rc; 3522e5061e4SHeiko Carstens 3532e5061e4SHeiko Carstens cpu_address = stap(); 3542e5061e4SHeiko Carstens asm volatile( 3552e5061e4SHeiko Carstens " diag %2,0,0x9c\n" 3562e5061e4SHeiko Carstens "0: la %0,0\n" 3572e5061e4SHeiko Carstens "1:\n" 3582e5061e4SHeiko Carstens EX_TABLE(0b,1b) 3592e5061e4SHeiko Carstens : "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc"); 3602e5061e4SHeiko Carstens if (!rc) 361d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG9C; 3622e5061e4SHeiko Carstens } 3632e5061e4SHeiko Carstens 3642e5061e4SHeiko Carstens static __init void detect_diag44(void) 3652e5061e4SHeiko Carstens { 3662e5061e4SHeiko Carstens #ifdef CONFIG_64BIT 3672e5061e4SHeiko Carstens int rc; 3682e5061e4SHeiko Carstens 3692e5061e4SHeiko Carstens asm volatile( 3702e5061e4SHeiko Carstens " diag 0,0,0x44\n" 3712e5061e4SHeiko Carstens "0: la %0,0\n" 3722e5061e4SHeiko Carstens "1:\n" 3732e5061e4SHeiko Carstens EX_TABLE(0b,1b) 3742e5061e4SHeiko Carstens : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc"); 3752e5061e4SHeiko Carstens if (!rc) 376d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG44; 3772e5061e4SHeiko Carstens #endif 3782e5061e4SHeiko Carstens } 3792e5061e4SHeiko Carstens 3802e5061e4SHeiko Carstens static __init void detect_machine_facilities(void) 3812e5061e4SHeiko Carstens { 3822e5061e4SHeiko Carstens #ifdef CONFIG_64BIT 38314375bc4SMartin Schwidefsky if (test_facility(3)) 384d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_IDTE; 38514375bc4SMartin Schwidefsky if (test_facility(8)) 386d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_PFMF; 3879186d7a9SHeiko Carstens if (test_facility(11)) 3889186d7a9SHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_TOPOLOGY; 38914375bc4SMartin Schwidefsky if (test_facility(27)) 390d3135e0cSHeiko Carstens S390_lowcore.machine_flags |= MACHINE_FLAG_MVCOS; 39114375bc4SMartin Schwidefsky if (test_facility(40)) 392cd3b70f5SCarsten Otte S390_lowcore.machine_flags |= MACHINE_FLAG_SPP; 393cfa1e7e1SJan Glauber if (test_facility(25)) 394cfa1e7e1SJan Glauber S390_lowcore.machine_flags |= MACHINE_FLAG_STCKF; 3952e5061e4SHeiko Carstens #endif 3962e5061e4SHeiko Carstens } 3972e5061e4SHeiko Carstens 398761cdf6aSHeiko Carstens static __init void rescue_initrd(void) 399761cdf6aSHeiko Carstens { 400761cdf6aSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD 40127e7318cSHeiko Carstens unsigned long min_initrd_addr = (unsigned long) _end + (4UL << 20); 402761cdf6aSHeiko Carstens /* 40327e7318cSHeiko Carstens * Just like in case of IPL from VM reader we make sure there is a 40427e7318cSHeiko Carstens * gap of 4MB between end of kernel and start of initrd. 40527e7318cSHeiko Carstens * That way we can also be sure that saving an NSS will succeed, 40627e7318cSHeiko Carstens * which however only requires different segments. 407761cdf6aSHeiko Carstens */ 408761cdf6aSHeiko Carstens if (!INITRD_START || !INITRD_SIZE) 409761cdf6aSHeiko Carstens return; 41027e7318cSHeiko Carstens if (INITRD_START >= min_initrd_addr) 411761cdf6aSHeiko Carstens return; 41227e7318cSHeiko Carstens memmove((void *) min_initrd_addr, (void *) INITRD_START, INITRD_SIZE); 41327e7318cSHeiko Carstens INITRD_START = min_initrd_addr; 414761cdf6aSHeiko Carstens #endif 415761cdf6aSHeiko Carstens } 416761cdf6aSHeiko Carstens 417a0443fbbSHendrik Brueckner /* Set up boot command line */ 418684d2fd4SHendrik Brueckner static void __init append_to_cmdline(size_t (*ipl_data)(char *, size_t)) 419684d2fd4SHendrik Brueckner { 420684d2fd4SHendrik Brueckner char *parm, *delim; 421684d2fd4SHendrik Brueckner size_t rc, len; 422684d2fd4SHendrik Brueckner 423684d2fd4SHendrik Brueckner len = strlen(boot_command_line); 424684d2fd4SHendrik Brueckner 425684d2fd4SHendrik Brueckner delim = boot_command_line + len; /* '\0' character position */ 426684d2fd4SHendrik Brueckner parm = boot_command_line + len + 1; /* append right after '\0' */ 427684d2fd4SHendrik Brueckner 428684d2fd4SHendrik Brueckner rc = ipl_data(parm, COMMAND_LINE_SIZE - len - 1); 429684d2fd4SHendrik Brueckner if (rc) { 430684d2fd4SHendrik Brueckner if (*parm == '=') 431684d2fd4SHendrik Brueckner memmove(boot_command_line, parm + 1, rc); 432684d2fd4SHendrik Brueckner else 433684d2fd4SHendrik Brueckner *delim = ' '; /* replace '\0' with space */ 434684d2fd4SHendrik Brueckner } 435684d2fd4SHendrik Brueckner } 436684d2fd4SHendrik Brueckner 437*1fb81057SMichael Holzheu static inline int has_ebcdic_char(const char *str) 438a0443fbbSHendrik Brueckner { 43961fd330dSMartin Schwidefsky int i; 44061fd330dSMartin Schwidefsky 441*1fb81057SMichael Holzheu for (i = 0; str[i]; i++) 442*1fb81057SMichael Holzheu if (str[i] & 0x80) 443*1fb81057SMichael Holzheu return 1; 444*1fb81057SMichael Holzheu return 0; 445*1fb81057SMichael Holzheu } 44661fd330dSMartin Schwidefsky 447*1fb81057SMichael Holzheu static void __init setup_boot_command_line(void) 448*1fb81057SMichael Holzheu { 449*1fb81057SMichael Holzheu COMMAND_LINE[ARCH_COMMAND_LINE_SIZE - 1] = 0; 450*1fb81057SMichael Holzheu /* convert arch command line to ascii if necessary */ 451*1fb81057SMichael Holzheu if (has_ebcdic_char(COMMAND_LINE)) 452*1fb81057SMichael Holzheu EBCASC(COMMAND_LINE, ARCH_COMMAND_LINE_SIZE); 453a0443fbbSHendrik Brueckner /* copy arch command line */ 45461fd330dSMartin Schwidefsky strlcpy(boot_command_line, strstrip(COMMAND_LINE), 45561fd330dSMartin Schwidefsky ARCH_COMMAND_LINE_SIZE); 456a0443fbbSHendrik Brueckner 457a0443fbbSHendrik Brueckner /* append IPL PARM data to the boot command line */ 458684d2fd4SHendrik Brueckner if (MACHINE_IS_VM) 459684d2fd4SHendrik Brueckner append_to_cmdline(append_ipl_vmparm); 460684d2fd4SHendrik Brueckner 461684d2fd4SHendrik Brueckner append_to_cmdline(append_ipl_scpdata); 462a0443fbbSHendrik Brueckner } 463a0443fbbSHendrik Brueckner 464a0443fbbSHendrik Brueckner 465ab14de6cSHeiko Carstens /* 466ab14de6cSHeiko Carstens * Save ipl parameters, clear bss memory, initialize storage keys 467ab14de6cSHeiko Carstens * and create a kernel NSS at startup if the SAVESYS= parm is defined 468ab14de6cSHeiko Carstens */ 469ab14de6cSHeiko Carstens void __init startup_init(void) 470ab14de6cSHeiko Carstens { 471b6112ccbSMartin Schwidefsky reset_tod_clock(); 472ab14de6cSHeiko Carstens ipl_save_parameters(); 473761cdf6aSHeiko Carstens rescue_initrd(); 474ab14de6cSHeiko Carstens clear_bss_section(); 475ab14de6cSHeiko Carstens init_kernel_storage_key(); 476ab14de6cSHeiko Carstens lockdep_init(); 477ab14de6cSHeiko Carstens lockdep_off(); 478ab14de6cSHeiko Carstens sort_main_extable(); 479ab14de6cSHeiko Carstens setup_lowcore_early(); 48014375bc4SMartin Schwidefsky setup_facility_list(); 481a0443fbbSHendrik Brueckner detect_machine_type(); 482a0443fbbSHendrik Brueckner ipl_update_parameters(); 483a0443fbbSHendrik Brueckner setup_boot_command_line(); 484a0443fbbSHendrik Brueckner create_kernel_nss(); 4852e5061e4SHeiko Carstens detect_mvpg(); 4862e5061e4SHeiko Carstens detect_ieee(); 4872e5061e4SHeiko Carstens detect_csp(); 4882e5061e4SHeiko Carstens detect_diag9c(); 4892e5061e4SHeiko Carstens detect_diag44(); 4902e5061e4SHeiko Carstens detect_machine_facilities(); 49153492b1dSGerald Schaefer setup_hpage(); 49283119ad4SHeiko Carstens sclp_facilities_detect(); 49323d17421SHeiko Carstens detect_memory_layout(memory_chunk); 494dfd9f7abSHeiko Carstens #ifdef CONFIG_DYNAMIC_FTRACE 495dfd9f7abSHeiko Carstens S390_lowcore.ftrace_func = (unsigned long)ftrace_caller; 496dfd9f7abSHeiko Carstens #endif 497ab14de6cSHeiko Carstens lockdep_on(); 498ab14de6cSHeiko Carstens } 499