sclp_early.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * SCLP early driver
  4. *
  5. * Copyright IBM Corp. 2013
  6. */
  7. #define KMSG_COMPONENT "sclp_early"
  8. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  9. #include <linux/errno.h>
  10. #include <asm/ctl_reg.h>
  11. #include <asm/sclp.h>
  12. #include <asm/ipl.h>
  13. #include "sclp_sdias.h"
  14. #include "sclp.h"
  15. static struct sclp_ipl_info sclp_ipl_info;
  16. struct sclp_info sclp;
  17. EXPORT_SYMBOL(sclp);
  18. static void __init sclp_early_facilities_detect(struct read_info_sccb *sccb)
  19. {
  20. struct sclp_core_entry *cpue;
  21. u16 boot_cpu_address, cpu;
  22. if (sclp_early_get_info(sccb))
  23. return;
  24. sclp.facilities = sccb->facilities;
  25. sclp.has_sprp = !!(sccb->fac84 & 0x02);
  26. sclp.has_core_type = !!(sccb->fac84 & 0x01);
  27. sclp.has_gsls = !!(sccb->fac85 & 0x80);
  28. sclp.has_64bscao = !!(sccb->fac116 & 0x80);
  29. sclp.has_cmma = !!(sccb->fac116 & 0x40);
  30. sclp.has_esca = !!(sccb->fac116 & 0x08);
  31. sclp.has_pfmfi = !!(sccb->fac117 & 0x40);
  32. sclp.has_ibs = !!(sccb->fac117 & 0x20);
  33. sclp.has_gisaf = !!(sccb->fac118 & 0x08);
  34. sclp.has_hvs = !!(sccb->fac119 & 0x80);
  35. sclp.has_kss = !!(sccb->fac98 & 0x01);
  36. if (sccb->fac85 & 0x02)
  37. S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
  38. if (sccb->fac91 & 0x40)
  39. S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_GUEST;
  40. sclp.rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
  41. sclp.rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
  42. sclp.rzm <<= 20;
  43. sclp.ibc = sccb->ibc;
  44. if (sccb->hamaxpow && sccb->hamaxpow < 64)
  45. sclp.hamax = (1UL << sccb->hamaxpow) - 1;
  46. else
  47. sclp.hamax = U64_MAX;
  48. if (!sccb->hcpua) {
  49. if (MACHINE_IS_VM)
  50. sclp.max_cores = 64;
  51. else
  52. sclp.max_cores = sccb->ncpurl;
  53. } else {
  54. sclp.max_cores = sccb->hcpua + 1;
  55. }
  56. boot_cpu_address = stap();
  57. cpue = (void *)sccb + sccb->cpuoff;
  58. for (cpu = 0; cpu < sccb->ncpurl; cpue++, cpu++) {
  59. if (boot_cpu_address != cpue->core_id)
  60. continue;
  61. sclp.has_siif = cpue->siif;
  62. sclp.has_sigpif = cpue->sigpif;
  63. sclp.has_sief2 = cpue->sief2;
  64. sclp.has_gpere = cpue->gpere;
  65. sclp.has_ib = cpue->ib;
  66. sclp.has_cei = cpue->cei;
  67. sclp.has_skey = cpue->skey;
  68. break;
  69. }
  70. /* Save IPL information */
  71. sclp_ipl_info.is_valid = 1;
  72. if (sccb->fac91 & 0x2)
  73. sclp_ipl_info.has_dump = 1;
  74. memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
  75. if (sccb->hsa_size)
  76. sclp.hsa_size = (sccb->hsa_size - 1) * PAGE_SIZE;
  77. sclp.mtid = (sccb->fac42 & 0x80) ? (sccb->fac42 & 31) : 0;
  78. sclp.mtid_cp = (sccb->fac42 & 0x80) ? (sccb->fac43 & 31) : 0;
  79. sclp.mtid_prev = (sccb->fac42 & 0x80) ? (sccb->fac66 & 31) : 0;
  80. sclp.hmfai = sccb->hmfai;
  81. }
  82. /*
  83. * This function will be called after sclp_early_facilities_detect(), which gets
  84. * called from early.c code. The sclp_early_facilities_detect() function retrieves
  85. * and saves the IPL information.
  86. */
  87. void __init sclp_early_get_ipl_info(struct sclp_ipl_info *info)
  88. {
  89. *info = sclp_ipl_info;
  90. }
  91. static struct sclp_core_info sclp_early_core_info __initdata;
  92. static int sclp_early_core_info_valid __initdata;
  93. static void __init sclp_early_init_core_info(struct read_cpu_info_sccb *sccb)
  94. {
  95. if (!SCLP_HAS_CPU_INFO)
  96. return;
  97. memset(sccb, 0, sizeof(*sccb));
  98. sccb->header.length = sizeof(*sccb);
  99. if (sclp_early_cmd(SCLP_CMDW_READ_CPU_INFO, sccb))
  100. return;
  101. if (sccb->header.response_code != 0x0010)
  102. return;
  103. sclp_fill_core_info(&sclp_early_core_info, sccb);
  104. sclp_early_core_info_valid = 1;
  105. }
  106. int __init sclp_early_get_core_info(struct sclp_core_info *info)
  107. {
  108. if (!sclp_early_core_info_valid)
  109. return -EIO;
  110. *info = sclp_early_core_info;
  111. return 0;
  112. }
  113. static void __init sclp_early_console_detect(struct init_sccb *sccb)
  114. {
  115. if (sccb->header.response_code != 0x20)
  116. return;
  117. if (sclp_early_con_check_vt220(sccb))
  118. sclp.has_vt220 = 1;
  119. if (sclp_early_con_check_linemode(sccb))
  120. sclp.has_linemode = 1;
  121. }
  122. void __init sclp_early_detect(void)
  123. {
  124. void *sccb = &sclp_early_sccb;
  125. sclp_early_facilities_detect(sccb);
  126. sclp_early_init_core_info(sccb);
  127. /*
  128. * Turn off SCLP event notifications. Also save remote masks in the
  129. * sccb. These are sufficient to detect sclp console capabilities.
  130. */
  131. sclp_early_set_event_mask(sccb, 0, 0);
  132. sclp_early_console_detect(sccb);
  133. }