als.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. * The code within this file will be called very early. It may _not_
  13. * access anything within the bss section, since that is not cleared
  14. * yet and may contain data (e.g. initrd) that must be saved by other
  15. * code.
  16. * For temporary objects the stack (16k) should be used.
  17. */
  18. static unsigned long als[] = { FACILITIES_ALS };
  19. static void u16_to_hex(char *str, u16 val)
  20. {
  21. int i, num;
  22. for (i = 1; i <= 4; i++) {
  23. num = (val >> (16 - 4 * i)) & 0xf;
  24. if (num >= 10)
  25. num += 7;
  26. *str++ = '0' + num;
  27. }
  28. *str = '\0';
  29. }
  30. static void print_machine_type(void)
  31. {
  32. static char mach_str[80] = "Detected machine-type number: ";
  33. char type_str[5];
  34. struct cpuid id;
  35. get_cpu_id(&id);
  36. u16_to_hex(type_str, id.machine);
  37. strcat(mach_str, type_str);
  38. strcat(mach_str, "\n");
  39. sclp_early_printk(mach_str);
  40. }
  41. static void u16_to_decimal(char *str, u16 val)
  42. {
  43. int div = 1;
  44. while (div * 10 <= val)
  45. div *= 10;
  46. while (div) {
  47. *str++ = '0' + val / div;
  48. val %= div;
  49. div /= 10;
  50. }
  51. *str = '\0';
  52. }
  53. void print_missing_facilities(void)
  54. {
  55. static char als_str[80] = "Missing facilities: ";
  56. unsigned long val;
  57. char val_str[6];
  58. int i, j, first;
  59. first = 1;
  60. for (i = 0; i < ARRAY_SIZE(als); i++) {
  61. val = ~stfle_fac_list[i] & als[i];
  62. for (j = 0; j < BITS_PER_LONG; j++) {
  63. if (!(val & (1UL << (BITS_PER_LONG - 1 - j))))
  64. continue;
  65. if (!first)
  66. strcat(als_str, ",");
  67. /*
  68. * Make sure we stay within one line. Consider that
  69. * each facility bit adds up to five characters and
  70. * z/VM adds a four character prefix.
  71. */
  72. if (strlen(als_str) > 70) {
  73. strcat(als_str, "\n");
  74. sclp_early_printk(als_str);
  75. *als_str = '\0';
  76. }
  77. u16_to_decimal(val_str, i * BITS_PER_LONG + j);
  78. strcat(als_str, val_str);
  79. first = 0;
  80. }
  81. }
  82. strcat(als_str, "\n");
  83. sclp_early_printk(als_str);
  84. }
  85. static void facility_mismatch(void)
  86. {
  87. sclp_early_printk("The Linux kernel requires more recent processor hardware\n");
  88. print_machine_type();
  89. print_missing_facilities();
  90. sclp_early_printk("See Principles of Operations for facility bits\n");
  91. disabled_wait();
  92. }
  93. void verify_facilities(void)
  94. {
  95. int i;
  96. __stfle(stfle_fac_list, ARRAY_SIZE(stfle_fac_list));
  97. for (i = 0; i < ARRAY_SIZE(als); i++) {
  98. if ((stfle_fac_list[i] & als[i]) != als[i])
  99. facility_mismatch();
  100. }
  101. }