1
2
3
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>
10
11
12
13
14
15
16
17
18
19static unsigned long als[] = { FACILITIES_ALS };
20
21static void u16_to_hex(char *str, u16 val)
22{
23 int i, num;
24
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;
30 }
31 *str = '\0';
32}
33
34static void print_machine_type(void)
35{
36 static char mach_str[80] = "Detected machine-type number: ";
37 char type_str[5];
38 struct cpuid id;
39
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);
45}
46
47static void 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 print_missing_facilities(void)
62{
63 static char als_str[80] = "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
78
79
80
81 if (strlen(als_str) > 70) {
82 strcat(als_str, "\n");
83 sclp_early_printk(als_str);
84 *als_str = '\0';
85 }
86 u16_to_decimal(val_str, i * BITS_PER_LONG + j);
87 strcat(als_str, val_str);
88 first = 0;
89 }
90 }
91 strcat(als_str, "\n");
92 sclp_early_printk(als_str);
93 sclp_early_printk("See Principles of Operations for facility bits\n");
94}
95
96static void facility_mismatch(void)
97{
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);
102}
103
104void verify_facilities(void)
105{
106 int i;
107
108 __stfle(S390_lowcore.stfle_fac_list, ARRAY_SIZE(S390_lowcore.stfle_fac_list));
109 for (i = 0; i < ARRAY_SIZE(als); i++) {
110 if ((S390_lowcore.stfle_fac_list[i] & als[i]) != als[i])
111 facility_mismatch();
112 }
113}
114