summaryrefslogtreecommitdiffstats
path: root/arch/s390/boot/als.c
blob: 11e0c3d5dbc8c143f68363b85fd093472d5aaf87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-License-Identifier: GPL-2.0
/*
 *    Copyright IBM Corp. 2016
 */
#include <linux/kernel.h>
#include <asm/processor.h>
#include <asm/facility.h>
#include <asm/lowcore.h>
#include <asm/sclp.h>
#include "boot.h"

static unsigned long als[] = { FACILITIES_ALS };

static void u16_to_decimal(char *str, u16 val)
{
	int div = 1;

	while (div * 10 <= val)
		div *= 10;
	while (div) {
		*str++ = '0' + val / div;
		val %= div;
		div /= 10;
	}
	*str = '\0';
}

void print_missing_facilities(void)
{
	static char als_str[80] = "Missing facilities: ";
	unsigned long val;
	char val_str[6];
	int i, j, first;

	first = 1;
	for (i = 0; i < ARRAY_SIZE(als); i++) {
		val = ~stfle_fac_list[i] & als[i];
		for (j = 0; j < BITS_PER_LONG; j++) {
			if (!(val & (1UL << (BITS_PER_LONG - 1 - j))))
				continue;
			if (!first)
				strcat(als_str, ",");
			/*
			 * Make sure we stay within one line. Consider that
			 * each facility bit adds up to five characters and
			 * z/VM adds a four character prefix.
			 */
			if (strlen(als_str) > 70) {
				boot_printk("%s\n", als_str);
				*als_str = '\0';
			}
			u16_to_decimal(val_str, i * BITS_PER_LONG + j);
			strcat(als_str, val_str);
			first = 0;
		}
	}
	boot_printk("%s\n", als_str);
}

static void facility_mismatch(void)
{
	struct cpuid id;

	get_cpu_id(&id);
	boot_printk("The Linux kernel requires more recent processor hardware\n");
	boot_printk("Detected machine-type number: %4x\n", id.machine);
	print_missing_facilities();
	boot_printk("See Principles of Operations for facility bits\n");
	disabled_wait();
}

void verify_facilities(void)
{
	int i;

	__stfle(stfle_fac_list, ARRAY_SIZE(stfle_fac_list));
	for (i = 0; i < ARRAY_SIZE(als); i++) {
		if ((stfle_fac_list[i] & als[i]) != als[i])
			facility_mismatch();
	}
}