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