^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. 2016
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <asm/facility.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <asm/lowcore.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/sclp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "boot.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * The code within this file will be called very early. It may _not_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * access anything within the bss section, since that is not cleared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * yet and may contain data (e.g. initrd) that must be saved by other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * For temporary objects the stack (16k) should be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static unsigned long als[] = { FACILITIES_ALS };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static void u16_to_hex(char *str, u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int i, num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) for (i = 1; i <= 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) num = (val >> (16 - 4 * i)) & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (num >= 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) num += 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) *str++ = '0' + num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *str = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static void print_machine_type(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static char mach_str[80] = "Detected machine-type number: ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) char type_str[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct cpuid id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) get_cpu_id(&id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u16_to_hex(type_str, id.machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) strcat(mach_str, type_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) strcat(mach_str, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) sclp_early_printk(mach_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static void u16_to_decimal(char *str, u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int div = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) while (div * 10 <= val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) div *= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) while (div) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *str++ = '0' + val / div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) val %= div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) div /= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *str = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) void print_missing_facilities(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static char als_str[80] = "Missing facilities: ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) char val_str[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int i, j, first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) first = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) for (i = 0; i < ARRAY_SIZE(als); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) val = ~S390_lowcore.stfle_fac_list[i] & als[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) for (j = 0; j < BITS_PER_LONG; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (!(val & (1UL << (BITS_PER_LONG - 1 - j))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (!first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) strcat(als_str, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Make sure we stay within one line. Consider that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * each facility bit adds up to five characters and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * z/VM adds a four character prefix.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (strlen(als_str) > 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) strcat(als_str, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) sclp_early_printk(als_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *als_str = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u16_to_decimal(val_str, i * BITS_PER_LONG + j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) strcat(als_str, val_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) first = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) strcat(als_str, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) sclp_early_printk(als_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void facility_mismatch(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) sclp_early_printk("The Linux kernel requires more recent processor hardware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) print_machine_type();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) print_missing_facilities();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) sclp_early_printk("See Principles of Operations for facility bits\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) disabled_wait();
^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) void verify_facilities(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) __stfle(S390_lowcore.stfle_fac_list, ARRAY_SIZE(S390_lowcore.stfle_fac_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) for (i = 0; i < ARRAY_SIZE(als); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if ((S390_lowcore.stfle_fac_list[i] & als[i]) != als[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) facility_mismatch();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }