iwlwifi: mvm: fix version check for GEO_TX_POWER_LIMIT support
[linux/fpc-iii.git] / arch / s390 / boot / als.c
blobd592e0d90d9fbbae85e41719674467e725b54f67
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright IBM Corp. 2016
4 */
5 #include <linux/kernel.h>
6 #include <asm/processor.h>
7 #include <asm/facility.h>
8 #include <asm/lowcore.h>
9 #include <asm/sclp.h>
12 * The code within this file will be called very early. It may _not_
13 * access anything within the bss section, since that is not cleared
14 * yet and may contain data (e.g. initrd) that must be saved by other
15 * code.
16 * For temporary objects the stack (16k) should be used.
19 static unsigned long als[] = { FACILITIES_ALS };
21 static void u16_to_hex(char *str, u16 val)
23 int i, num;
25 for (i = 1; i <= 4; i++) {
26 num = (val >> (16 - 4 * i)) & 0xf;
27 if (num >= 10)
28 num += 7;
29 *str++ = '0' + num;
31 *str = '\0';
34 static void print_machine_type(void)
36 static char mach_str[80] = "Detected machine-type number: ";
37 char type_str[5];
38 struct cpuid id;
40 get_cpu_id(&id);
41 u16_to_hex(type_str, id.machine);
42 strcat(mach_str, type_str);
43 strcat(mach_str, "\n");
44 sclp_early_printk(mach_str);
47 static void u16_to_decimal(char *str, u16 val)
49 int div = 1;
51 while (div * 10 <= val)
52 div *= 10;
53 while (div) {
54 *str++ = '0' + val / div;
55 val %= div;
56 div /= 10;
58 *str = '\0';
61 static void print_missing_facilities(void)
63 static char als_str[80] = "Missing facilities: ";
64 unsigned long val;
65 char val_str[6];
66 int i, j, first;
68 first = 1;
69 for (i = 0; i < ARRAY_SIZE(als); i++) {
70 val = ~S390_lowcore.stfle_fac_list[i] & als[i];
71 for (j = 0; j < BITS_PER_LONG; j++) {
72 if (!(val & (1UL << (BITS_PER_LONG - 1 - j))))
73 continue;
74 if (!first)
75 strcat(als_str, ",");
77 * Make sure we stay within one line. Consider that
78 * each facility bit adds up to five characters and
79 * z/VM adds a four character prefix.
81 if (strlen(als_str) > 70) {
82 strcat(als_str, "\n");
83 sclp_early_printk(als_str);
84 *als_str = '\0';
86 u16_to_decimal(val_str, i * BITS_PER_LONG + j);
87 strcat(als_str, val_str);
88 first = 0;
91 strcat(als_str, "\n");
92 sclp_early_printk(als_str);
93 sclp_early_printk("See Principles of Operations for facility bits\n");
96 static void facility_mismatch(void)
98 sclp_early_printk("The Linux kernel requires more recent processor hardware\n");
99 print_machine_type();
100 print_missing_facilities();
101 disabled_wait(0x8badcccc);
104 void verify_facilities(void)
106 int i;
108 for (i = 0; i < ARRAY_SIZE(S390_lowcore.stfle_fac_list); i++)
109 S390_lowcore.stfle_fac_list[i] = 0;
110 asm volatile(
111 " stfl 0(0)\n"
112 : "=m" (S390_lowcore.stfl_fac_list));
113 S390_lowcore.stfle_fac_list[0] = (u64)S390_lowcore.stfl_fac_list << 32;
114 if (S390_lowcore.stfl_fac_list & 0x01000000) {
115 register unsigned long reg0 asm("0") = ARRAY_SIZE(als) - 1;
117 asm volatile(".insn s,0xb2b00000,0(%1)" /* stfle */
118 : "+d" (reg0)
119 : "a" (&S390_lowcore.stfle_fac_list)
120 : "memory", "cc");
122 for (i = 0; i < ARRAY_SIZE(als); i++) {
123 if ((S390_lowcore.stfle_fac_list[i] & als[i]) != als[i])
124 facility_mismatch();