als.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2016
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/init.h>
  7. #include <asm/processor.h>
  8. #include <asm/facility.h>
  9. #include <asm/lowcore.h>
  10. #include <asm/sclp.h>
  11. #include "entry.h"
  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. static unsigned long als[] __initdata = { FACILITIES_ALS };
  20. static void __init u16_to_hex(char *str, u16 val)
  21. {
  22. int i, num;
  23. for (i = 1; i <= 4; i++) {
  24. num = (val >> (16 - 4 * i)) & 0xf;
  25. if (num >= 10)
  26. num += 7;
  27. *str++ = '0' + num;
  28. }
  29. *str = '\0';
  30. }
  31. static void __init print_machine_type(void)
  32. {
  33. static char mach_str[80] __initdata = "Detected machine-type number: ";
  34. char type_str[5];
  35. struct cpuid id;
  36. get_cpu_id(&id);
  37. u16_to_hex(type_str, id.machine);
  38. strcat(mach_str, type_str);
  39. strcat(mach_str, "\n");
  40. sclp_early_printk(mach_str);
  41. }
  42. static void __init u16_to_decimal(char *str, u16 val)
  43. {
  44. int div = 1;
  45. while (div * 10 <= val)
  46. div *= 10;
  47. while (div) {
  48. *str++ = '0' + val / div;
  49. val %= div;
  50. div /= 10;
  51. }
  52. *str = '\0';
  53. }
  54. static void __init print_missing_facilities(void)
  55. {
  56. static char als_str[80] __initdata = "Missing facilities: ";
  57. unsigned long val;
  58. char val_str[6];
  59. int i, j, first;
  60. first = 1;
  61. for (i = 0; i < ARRAY_SIZE(als); i++) {
  62. val = ~S390_lowcore.stfle_fac_list[i] & als[i];
  63. for (j = 0; j < BITS_PER_LONG; j++) {
  64. if (!(val & (1UL << (BITS_PER_LONG - 1 - j))))
  65. continue;
  66. if (!first)
  67. strcat(als_str, ",");
  68. /*
  69. * Make sure we stay within one line. Consider that
  70. * each facility bit adds up to five characters and
  71. * z/VM adds a four character prefix.
  72. */
  73. if (strlen(als_str) > 70) {
  74. strcat(als_str, "\n");
  75. sclp_early_printk(als_str);
  76. *als_str = '\0';
  77. }
  78. u16_to_decimal(val_str, i * BITS_PER_LONG + j);
  79. strcat(als_str, val_str);
  80. first = 0;
  81. }
  82. }
  83. strcat(als_str, "\n");
  84. sclp_early_printk(als_str);
  85. sclp_early_printk("See Principles of Operations for facility bits\n");
  86. }
  87. static void __init facility_mismatch(void)
  88. {
  89. sclp_early_printk("The Linux kernel requires more recent processor hardware\n");
  90. print_machine_type();
  91. print_missing_facilities();
  92. disabled_wait(0x8badcccc);
  93. }
  94. void __init verify_facilities(void)
  95. {
  96. int i;
  97. for (i = 0; i < ARRAY_SIZE(S390_lowcore.stfle_fac_list); i++)
  98. S390_lowcore.stfle_fac_list[i] = 0;
  99. asm volatile(
  100. " stfl 0(0)\n"
  101. : "=m" (S390_lowcore.stfl_fac_list));
  102. S390_lowcore.stfle_fac_list[0] = (u64)S390_lowcore.stfl_fac_list << 32;
  103. if (S390_lowcore.stfl_fac_list & 0x01000000) {
  104. register unsigned long reg0 asm("0") = ARRAY_SIZE(als) - 1;
  105. asm volatile(".insn s,0xb2b00000,0(%1)" /* stfle */
  106. : "+d" (reg0)
  107. : "a" (&S390_lowcore.stfle_fac_list)
  108. : "memory", "cc");
  109. }
  110. for (i = 0; i < ARRAY_SIZE(als); i++) {
  111. if ((S390_lowcore.stfle_fac_list[i] & als[i]) != als[i])
  112. facility_mismatch();
  113. }
  114. }