als.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. strcat(mach_str, "\n");
  39. sclp_early_printk(mach_str);
  40. }
  41. static void __init 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. static void __init print_missing_facilities(void)
  54. {
  55. static char als_str[80] __initdata = "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 = ~S390_lowcore.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. sclp_early_printk("See Principles of Operations for facility bits\n");
  85. }
  86. static void __init facility_mismatch(void)
  87. {
  88. sclp_early_printk("The Linux kernel requires more recent processor hardware\n");
  89. print_machine_type();
  90. print_missing_facilities();
  91. disabled_wait(0x8badcccc);
  92. }
  93. void __init verify_facilities(void)
  94. {
  95. int i;
  96. for (i = 0; i < ARRAY_SIZE(S390_lowcore.stfle_fac_list); i++)
  97. S390_lowcore.stfle_fac_list[i] = 0;
  98. asm volatile(
  99. " stfl 0(0)\n"
  100. : "=m" (S390_lowcore.stfl_fac_list));
  101. S390_lowcore.stfle_fac_list[0] = (u64)S390_lowcore.stfl_fac_list << 32;
  102. if (S390_lowcore.stfl_fac_list & 0x01000000) {
  103. register unsigned long reg0 asm("0") = ARRAY_SIZE(als) - 1;
  104. asm volatile(".insn s,0xb2b00000,0(%1)" /* stfle */
  105. : "+d" (reg0)
  106. : "a" (&S390_lowcore.stfle_fac_list)
  107. : "memory", "cc");
  108. }
  109. for (i = 0; i < ARRAY_SIZE(als); i++) {
  110. if ((S390_lowcore.stfle_fac_list[i] & als[i]) != als[i])
  111. facility_mismatch();
  112. }
  113. }