^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright IBM Corp. 2007, 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author(s): Hongjie Yang <hongjie@us.ibm.com>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Heiko Carstens <heiko.carstens@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define KMSG_COMPONENT "setup"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/lockdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/pfn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/ebcdic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/ipl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/lowcore.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/sysinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/cpcmd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/sclp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/facility.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <asm/boot_data.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "entry.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static void __init reset_tod_clock(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u64 time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (store_tod_clock(&time) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* TOD clock not running. Set the clock to Unix Epoch. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (set_tod_clock(TOD_UNIX_EPOCH) != 0 || store_tod_clock(&time) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) disabled_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) memset(tod_clock_base, 0, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) *(__u64 *) &tod_clock_base[1] = TOD_UNIX_EPOCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) S390_lowcore.last_update_clock = TOD_UNIX_EPOCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * Initialize storage key for kernel pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static noinline __init void init_kernel_storage_key(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #if PAGE_DEFAULT_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned long end_pfn, init_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) end_pfn = PFN_UP(__pa(_end));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) page_set_storage_key(init_pfn << PAGE_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) PAGE_DEFAULT_KEY, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static __initdata char sysinfo_page[PAGE_SIZE] __aligned(PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static noinline __init void detect_machine_type(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct sysinfo_3_2_2 *vmms = (struct sysinfo_3_2_2 *)&sysinfo_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* Check current-configuration-level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (stsi(NULL, 0, 0, 0) <= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) S390_lowcore.machine_flags |= MACHINE_FLAG_LPAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Get virtual-machine cpu information. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (stsi(vmms, 3, 2, 2) || !vmms->count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* Detect known hypervisors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (!memcmp(vmms->vm[0].cpi, "\xd2\xe5\xd4", 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) S390_lowcore.machine_flags |= MACHINE_FLAG_KVM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) else if (!memcmp(vmms->vm[0].cpi, "\xa9\x61\xe5\xd4", 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) S390_lowcore.machine_flags |= MACHINE_FLAG_VM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* Remove leading, trailing and double whitespace. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static inline void strim_all(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) s = strim(str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (s != str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) memmove(str, s, strlen(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) while (*str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (!isspace(*str++))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (isspace(*str)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) s = skip_spaces(str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) memmove(str, s, strlen(s) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static noinline __init void setup_arch_string(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct sysinfo_1_1_1 *mach = (struct sysinfo_1_1_1 *)&sysinfo_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct sysinfo_3_2_2 *vm = (struct sysinfo_3_2_2 *)&sysinfo_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) char mstr[80], hvstr[17];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (stsi(mach, 1, 1, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) EBCASC(mach->manufacturer, sizeof(mach->manufacturer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) EBCASC(mach->type, sizeof(mach->type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) EBCASC(mach->model, sizeof(mach->model));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) EBCASC(mach->model_capacity, sizeof(mach->model_capacity));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) sprintf(mstr, "%-16.16s %-4.4s %-16.16s %-16.16s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) mach->manufacturer, mach->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) mach->model, mach->model_capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) strim_all(mstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (stsi(vm, 3, 2, 2) == 0 && vm->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) EBCASC(vm->vm[0].cpi, sizeof(vm->vm[0].cpi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) sprintf(hvstr, "%-16.16s", vm->vm[0].cpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) strim_all(hvstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) sprintf(hvstr, "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MACHINE_IS_LPAR ? "LPAR" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) MACHINE_IS_VM ? "z/VM" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) MACHINE_IS_KVM ? "KVM" : "unknown");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) dump_stack_set_arch_desc("%s (%s)", mstr, hvstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static __init void setup_topology(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int max_mnest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (!test_facility(11))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) S390_lowcore.machine_flags |= MACHINE_FLAG_TOPOLOGY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) for (max_mnest = 6; max_mnest > 1; max_mnest--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (stsi(&sysinfo_page, 15, 1, max_mnest) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) topology_max_mnest = max_mnest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static void early_pgm_check_handler(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) const struct exception_table_entry *fixup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) unsigned long cr0, cr0_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) addr = S390_lowcore.program_old_psw.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) fixup = s390_search_extables(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (!fixup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) disabled_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* Disable low address protection before storing into lowcore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) __ctl_store(cr0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) cr0_new = cr0 & ~(1UL << 28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) __ctl_load(cr0_new, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) S390_lowcore.program_old_psw.addr = extable_fixup(fixup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) __ctl_load(cr0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static noinline __init void setup_lowcore_early(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) psw_t psw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) psw.mask = PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (IS_ENABLED(CONFIG_KASAN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) psw.mask |= PSW_MASK_DAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) psw.addr = (unsigned long) s390_base_ext_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) S390_lowcore.external_new_psw = psw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) psw.addr = (unsigned long) s390_base_pgm_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) S390_lowcore.program_new_psw = psw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) s390_base_pgm_handler_fn = early_pgm_check_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) S390_lowcore.preempt_count = INIT_PREEMPT_COUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static noinline __init void setup_facility_list(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) memcpy(S390_lowcore.alt_stfle_fac_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) S390_lowcore.stfle_fac_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) sizeof(S390_lowcore.alt_stfle_fac_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (!IS_ENABLED(CONFIG_KERNEL_NOBP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) __clear_facility(82, S390_lowcore.alt_stfle_fac_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static __init void detect_diag9c(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) unsigned int cpu_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) cpu_address = stap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) diag_stat_inc(DIAG_STAT_X09C);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) " diag %2,0,0x9c\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) "0: la %0,0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) "1:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) EX_TABLE(0b,1b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) : "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG9C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static __init void detect_machine_facilities(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (test_facility(8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) __ctl_set_bit(0, 23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (test_facility(78))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (test_facility(3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) S390_lowcore.machine_flags |= MACHINE_FLAG_IDTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (test_facility(50) && test_facility(73)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) S390_lowcore.machine_flags |= MACHINE_FLAG_TE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) __ctl_set_bit(0, 55);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (test_facility(51))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_LC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (test_facility(129)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) S390_lowcore.machine_flags |= MACHINE_FLAG_VX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) __ctl_set_bit(0, 17);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (test_facility(130) && !noexec_disabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) S390_lowcore.machine_flags |= MACHINE_FLAG_NX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) __ctl_set_bit(0, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (test_facility(133))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) S390_lowcore.machine_flags |= MACHINE_FLAG_GS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (test_facility(139) && (tod_clock_base[1] & 0x80)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* Enabled signed clock comparator comparisons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) S390_lowcore.machine_flags |= MACHINE_FLAG_SCC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) clock_comparator_max = -1ULL >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) __ctl_set_bit(0, 53);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (IS_ENABLED(CONFIG_PCI) && test_facility(153)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) S390_lowcore.machine_flags |= MACHINE_FLAG_PCI_MIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* the control bit is set during PCI initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static inline void save_vector_registers(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #ifdef CONFIG_CRASH_DUMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (test_facility(129))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) save_vx_regs(boot_cpu_vector_save_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static inline void setup_control_registers(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) unsigned long reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) __ctl_store(reg, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) reg |= CR0_LOW_ADDRESS_PROTECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) reg |= CR0_EMERGENCY_SIGNAL_SUBMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) reg |= CR0_EXTERNAL_CALL_SUBMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) __ctl_load(reg, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static inline void setup_access_registers(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) unsigned int acrs[NUM_ACRS] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) restore_access_regs(acrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static int __init disable_vector_extension(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) S390_lowcore.machine_flags &= ~MACHINE_FLAG_VX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) __ctl_clear_bit(0, 17);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) early_param("novx", disable_vector_extension);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) char __bootdata(early_command_line)[COMMAND_LINE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static void __init setup_boot_command_line(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* copy arch command line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) strlcpy(boot_command_line, early_command_line, ARCH_COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static void __init check_image_bootable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (!memcmp(EP_STRING, (void *)EP_OFFSET, strlen(EP_STRING)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) sclp_early_printk("Linux kernel boot failure: An attempt to boot a vmlinux ELF image failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) sclp_early_printk("This image does not contain all parts necessary for starting up. Use\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) sclp_early_printk("bzImage or arch/s390/boot/compressed/vmlinux instead.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) disabled_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) void __init startup_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) reset_tod_clock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) check_image_bootable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) time_early_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) init_kernel_storage_key();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) lockdep_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) setup_lowcore_early();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) setup_facility_list();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) detect_machine_type();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) setup_arch_string();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) setup_boot_command_line();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) detect_diag9c();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) detect_machine_facilities();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) save_vector_registers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) setup_topology();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) sclp_early_detect();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) setup_control_registers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) setup_access_registers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) lockdep_on();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }