blob: 47c48fbfb563d206dc401e8d6b0bc175d9185134 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Heiko Carstensbe2412c2016-06-27 15:52:38 +02002/*
3 * Copyright IBM Corp. 2016
4 */
5#include <linux/kernel.h>
Heiko Carstensbe2412c2016-06-27 15:52:38 +02006#include <asm/processor.h>
7#include <asm/facility.h>
8#include <asm/lowcore.h>
9#include <asm/sclp.h>
Vasily Gorbik6d85dac2019-02-27 17:36:35 +010010#include "boot.h"
Heiko Carstensbe2412c2016-06-27 15:52:38 +020011
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
Vasily Gorbik2dd26652018-06-12 15:14:51 +020020static unsigned long als[] = { FACILITIES_ALS };
Heiko Carstensbe2412c2016-06-27 15:52:38 +020021
Vasily Gorbik2dd26652018-06-12 15:14:51 +020022static void u16_to_hex(char *str, u16 val)
Heiko Carstens06ed55122016-06-28 14:40:07 +020023{
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
Vasily Gorbik2dd26652018-06-12 15:14:51 +020035static void print_machine_type(void)
Heiko Carstens06ed55122016-06-28 14:40:07 +020036{
Vasily Gorbik2dd26652018-06-12 15:14:51 +020037 static char mach_str[80] = "Detected machine-type number: ";
Heiko Carstens06ed55122016-06-28 14:40:07 +020038 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);
Heiko Carstens02407ba2017-02-02 10:33:20 +010044 strcat(mach_str, "\n");
Heiko Carstensd5ab7a32017-01-24 15:58:52 +010045 sclp_early_printk(mach_str);
Heiko Carstens06ed55122016-06-28 14:40:07 +020046}
47
Vasily Gorbik2dd26652018-06-12 15:14:51 +020048static void u16_to_decimal(char *str, u16 val)
Heiko Carstensa02d1982016-06-29 23:56:47 +020049{
50 int div = 1;
51
52 while (div * 10 <= val)
53 div *= 10;
54 while (div) {
55 *str++ = '0' + val / div;
56 val %= div;
57 div /= 10;
58 }
59 *str = '\0';
60}
61
Vasily Gorbik6d85dac2019-02-27 17:36:35 +010062void print_missing_facilities(void)
Heiko Carstensa02d1982016-06-29 23:56:47 +020063{
Vasily Gorbik2dd26652018-06-12 15:14:51 +020064 static char als_str[80] = "Missing facilities: ";
Heiko Carstensa02d1982016-06-29 23:56:47 +020065 unsigned long val;
66 char val_str[6];
67 int i, j, first;
68
69 first = 1;
70 for (i = 0; i < ARRAY_SIZE(als); i++) {
Sven Schnelle17e89e12021-05-05 22:01:10 +020071 val = ~stfle_fac_list[i] & als[i];
Heiko Carstensa02d1982016-06-29 23:56:47 +020072 for (j = 0; j < BITS_PER_LONG; j++) {
73 if (!(val & (1UL << (BITS_PER_LONG - 1 - j))))
74 continue;
75 if (!first)
76 strcat(als_str, ",");
77 /*
78 * Make sure we stay within one line. Consider that
79 * each facility bit adds up to five characters and
80 * z/VM adds a four character prefix.
81 */
82 if (strlen(als_str) > 70) {
Heiko Carstens02407ba2017-02-02 10:33:20 +010083 strcat(als_str, "\n");
Heiko Carstensd5ab7a32017-01-24 15:58:52 +010084 sclp_early_printk(als_str);
Heiko Carstensa02d1982016-06-29 23:56:47 +020085 *als_str = '\0';
86 }
87 u16_to_decimal(val_str, i * BITS_PER_LONG + j);
88 strcat(als_str, val_str);
89 first = 0;
90 }
91 }
Heiko Carstens02407ba2017-02-02 10:33:20 +010092 strcat(als_str, "\n");
Heiko Carstensd5ab7a32017-01-24 15:58:52 +010093 sclp_early_printk(als_str);
Heiko Carstensa02d1982016-06-29 23:56:47 +020094}
95
Vasily Gorbik2dd26652018-06-12 15:14:51 +020096static void facility_mismatch(void)
Heiko Carstens06ed55122016-06-28 14:40:07 +020097{
Heiko Carstens02407ba2017-02-02 10:33:20 +010098 sclp_early_printk("The Linux kernel requires more recent processor hardware\n");
Heiko Carstens06ed55122016-06-28 14:40:07 +020099 print_machine_type();
Heiko Carstensa02d1982016-06-29 23:56:47 +0200100 print_missing_facilities();
Vasily Gorbik6d85dac2019-02-27 17:36:35 +0100101 sclp_early_printk("See Principles of Operations for facility bits\n");
Martin Schwidefsky98587c22019-04-30 12:33:45 +0200102 disabled_wait();
Heiko Carstens06ed55122016-06-28 14:40:07 +0200103}
104
Vasily Gorbik2dd26652018-06-12 15:14:51 +0200105void verify_facilities(void)
Heiko Carstensbe2412c2016-06-27 15:52:38 +0200106{
107 int i;
108
Sven Schnelle17e89e12021-05-05 22:01:10 +0200109 __stfle(stfle_fac_list, ARRAY_SIZE(stfle_fac_list));
Heiko Carstensbe2412c2016-06-27 15:52:38 +0200110 for (i = 0; i < ARRAY_SIZE(als); i++) {
Sven Schnelle17e89e12021-05-05 22:01:10 +0200111 if ((stfle_fac_list[i] & als[i]) != als[i])
Heiko Carstens06ed55122016-06-28 14:40:07 +0200112 facility_mismatch();
Heiko Carstensbe2412c2016-06-27 15:52:38 +0200113 }
114}