als.c 2.9 KB

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