| 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> |
| 10 | #include "boot.h" |
| 11 | |
| 12 | static unsigned long als[] = { FACILITIES_ALS }; |
| 13 | |
| 14 | static void u16_to_decimal(char *str, u16 val) |
| 15 | { |
| 16 | int div = 1; |
| 17 | |
| 18 | while (div * 10 <= val) |
| 19 | div *= 10; |
| 20 | while (div) { |
| 21 | *str++ = '0' + val / div; |
| 22 | val %= div; |
| 23 | div /= 10; |
| 24 | } |
| 25 | *str = '\0'; |
| 26 | } |
| 27 | |
| 28 | void print_missing_facilities(void) |
| 29 | { |
| 30 | static char als_str[80] = "Missing facilities: " ; |
| 31 | unsigned long val; |
| 32 | char val_str[6]; |
| 33 | int i, j, first; |
| 34 | |
| 35 | first = 1; |
| 36 | for (i = 0; i < ARRAY_SIZE(als); i++) { |
| 37 | val = ~stfle_fac_list[i] & als[i]; |
| 38 | for (j = 0; j < BITS_PER_LONG; j++) { |
| 39 | if (!(val & (1UL << (BITS_PER_LONG - 1 - j)))) |
| 40 | continue; |
| 41 | if (!first) |
| 42 | strcat(als_str, "," ); |
| 43 | /* |
| 44 | * Make sure we stay within one line. Consider that |
| 45 | * each facility bit adds up to five characters and |
| 46 | * z/VM adds a four character prefix. |
| 47 | */ |
| 48 | if (strlen(als_str) > 70) { |
| 49 | boot_emerg("%s\n" , als_str); |
| 50 | *als_str = '\0'; |
| 51 | } |
| 52 | u16_to_decimal(val_str, i * BITS_PER_LONG + j); |
| 53 | strcat(als_str, val_str); |
| 54 | first = 0; |
| 55 | } |
| 56 | } |
| 57 | boot_emerg("%s\n" , als_str); |
| 58 | } |
| 59 | |
| 60 | static void facility_mismatch(void) |
| 61 | { |
| 62 | struct cpuid id; |
| 63 | |
| 64 | get_cpu_id(&id); |
| 65 | boot_emerg("The Linux kernel requires more recent processor hardware\n" ); |
| 66 | boot_emerg("Detected machine-type number: %4x\n" , id.machine); |
| 67 | print_missing_facilities(); |
| 68 | boot_emerg("See z/Architecture Principles of Operation - Facility Indications\n" ); |
| 69 | disabled_wait(); |
| 70 | } |
| 71 | |
| 72 | void verify_facilities(void) |
| 73 | { |
| 74 | int i; |
| 75 | |
| 76 | __stfle(stfle_fac_list, ARRAY_SIZE(stfle_fac_list)); |
| 77 | for (i = 0; i < ARRAY_SIZE(als); i++) { |
| 78 | if ((stfle_fac_list[i] & als[i]) != als[i]) |
| 79 | facility_mismatch(); |
| 80 | } |
| 81 | } |
| 82 | |