als.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. static unsigned long als[] = { FACILITIES_ALS };
  12. static void u16_to_decimal(char *str, u16 val)
  13. {
  14. int div = 1;
  15. while (div * 10 <= val)
  16. div *= 10;
  17. while (div) {
  18. *str++ = '0' + val / div;
  19. val %= div;
  20. div /= 10;
  21. }
  22. *str = '\0';
  23. }
  24. void print_missing_facilities(void)
  25. {
  26. static char als_str[80] = "Missing facilities: ";
  27. unsigned long val;
  28. char val_str[6];
  29. int i, j, first;
  30. first = 1;
  31. for (i = 0; i < ARRAY_SIZE(als); i++) {
  32. val = ~stfle_fac_list[i] & als[i];
  33. for (j = 0; j < BITS_PER_LONG; j++) {
  34. if (!(val & (1UL << (BITS_PER_LONG - 1 - j))))
  35. continue;
  36. if (!first)
  37. strcat(als_str, ",");
  38. /*
  39. * Make sure we stay within one line. Consider that
  40. * each facility bit adds up to five characters and
  41. * z/VM adds a four character prefix.
  42. */
  43. if (strlen(als_str) > 70) {
  44. boot_printk("%s\n", als_str);
  45. *als_str = '\0';
  46. }
  47. u16_to_decimal(val_str, i * BITS_PER_LONG + j);
  48. strcat(als_str, val_str);
  49. first = 0;
  50. }
  51. }
  52. boot_printk("%s\n", als_str);
  53. }
  54. static void facility_mismatch(void)
  55. {
  56. struct cpuid id;
  57. get_cpu_id(&id);
  58. boot_printk("The Linux kernel requires more recent processor hardware\n");
  59. boot_printk("Detected machine-type number: %4x\n", id.machine);
  60. print_missing_facilities();
  61. boot_printk("See Principles of Operations for facility bits\n");
  62. disabled_wait();
  63. }
  64. void verify_facilities(void)
  65. {
  66. int i;
  67. __stfle(stfle_fac_list, ARRAY_SIZE(stfle_fac_list));
  68. for (i = 0; i < ARRAY_SIZE(als); i++) {
  69. if ((stfle_fac_list[i] & als[i]) != als[i])
  70. facility_mismatch();
  71. }
  72. }