sclp_early.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 <linux/memblock.h>
  11. #include <asm/ctl_reg.h>
  12. #include <asm/sclp.h>
  13. #include <asm/ipl.h>
  14. #include <asm/setup.h>
  15. #include <asm/facility.h>
  16. #include "sclp_sdias.h"
  17. #include "sclp.h"
  18. static struct sclp_ipl_info sclp_ipl_info;
  19. struct sclp_info sclp;
  20. EXPORT_SYMBOL(sclp);
  21. static void __init sclp_early_facilities_detect(void)
  22. {
  23. struct sclp_core_entry *cpue;
  24. struct read_info_sccb *sccb;
  25. u16 boot_cpu_address, cpu;
  26. sccb = sclp_early_get_info();
  27. if (!sccb)
  28. return;
  29. sclp.facilities = sccb->facilities;
  30. sclp.has_sprp = !!(sccb->fac84 & 0x02);
  31. sclp.has_core_type = !!(sccb->fac84 & 0x01);
  32. sclp.has_gsls = !!(sccb->fac85 & 0x80);
  33. sclp.has_64bscao = !!(sccb->fac116 & 0x80);
  34. sclp.has_cmma = !!(sccb->fac116 & 0x40);
  35. sclp.has_esca = !!(sccb->fac116 & 0x08);
  36. sclp.has_pfmfi = !!(sccb->fac117 & 0x40);
  37. sclp.has_ibs = !!(sccb->fac117 & 0x20);
  38. sclp.has_gisaf = !!(sccb->fac118 & 0x08);
  39. sclp.has_hvs = !!(sccb->fac119 & 0x80);
  40. sclp.has_kss = !!(sccb->fac98 & 0x01);
  41. sclp.has_aisii = !!(sccb->fac118 & 0x40);
  42. sclp.has_aeni = !!(sccb->fac118 & 0x20);
  43. sclp.has_aisi = !!(sccb->fac118 & 0x10);
  44. sclp.has_zpci_lsi = !!(sccb->fac118 & 0x01);
  45. if (sccb->fac85 & 0x02)
  46. S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
  47. if (sccb->fac91 & 0x40)
  48. S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_GUEST;
  49. if (sccb->cpuoff > 134) {
  50. sclp.has_diag318 = !!(sccb->byte_134 & 0x80);
  51. sclp.has_iplcc = !!(sccb->byte_134 & 0x02);
  52. }
  53. if (sccb->cpuoff > 137)
  54. sclp.has_sipl = !!(sccb->cbl & 0x4000);
  55. sclp.rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
  56. sclp.rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
  57. sclp.rzm <<= 20;
  58. sclp.ibc = sccb->ibc;
  59. if (sccb->hamaxpow && sccb->hamaxpow < 64)
  60. sclp.hamax = (1UL << sccb->hamaxpow) - 1;
  61. else
  62. sclp.hamax = U64_MAX;
  63. if (!sccb->hcpua) {
  64. if (MACHINE_IS_VM)
  65. sclp.max_cores = 64;
  66. else
  67. sclp.max_cores = sccb->ncpurl;
  68. } else {
  69. sclp.max_cores = sccb->hcpua + 1;
  70. }
  71. boot_cpu_address = stap();
  72. cpue = (void *)sccb + sccb->cpuoff;
  73. for (cpu = 0; cpu < sccb->ncpurl; cpue++, cpu++) {
  74. if (boot_cpu_address != cpue->core_id)
  75. continue;
  76. sclp.has_siif = cpue->siif;
  77. sclp.has_sigpif = cpue->sigpif;
  78. sclp.has_sief2 = cpue->sief2;
  79. sclp.has_gpere = cpue->gpere;
  80. sclp.has_ib = cpue->ib;
  81. sclp.has_cei = cpue->cei;
  82. sclp.has_skey = cpue->skey;
  83. break;
  84. }
  85. /* Save IPL information */
  86. sclp_ipl_info.is_valid = 1;
  87. if (sccb->fac91 & 0x2)
  88. sclp_ipl_info.has_dump = 1;
  89. memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
  90. if (sccb->hsa_size)
  91. sclp.hsa_size = (sccb->hsa_size - 1) * PAGE_SIZE;
  92. sclp.mtid = (sccb->fac42 & 0x80) ? (sccb->fac42 & 31) : 0;
  93. sclp.mtid_cp = (sccb->fac42 & 0x80) ? (sccb->fac43 & 31) : 0;
  94. sclp.mtid_prev = (sccb->fac42 & 0x80) ? (sccb->fac66 & 31) : 0;
  95. sclp.hmfai = sccb->hmfai;
  96. sclp.has_dirq = !!(sccb->cpudirq & 0x80);
  97. }
  98. /*
  99. * This function will be called after sclp_early_facilities_detect(), which gets
  100. * called from early.c code. The sclp_early_facilities_detect() function retrieves
  101. * and saves the IPL information.
  102. */
  103. void __init sclp_early_get_ipl_info(struct sclp_ipl_info *info)
  104. {
  105. *info = sclp_ipl_info;
  106. }
  107. int __init sclp_early_get_core_info(struct sclp_core_info *info)
  108. {
  109. struct read_cpu_info_sccb *sccb;
  110. int length = test_facility(140) ? EXT_SCCB_READ_CPU : PAGE_SIZE;
  111. int rc = 0;
  112. if (!SCLP_HAS_CPU_INFO)
  113. return -EOPNOTSUPP;
  114. sccb = memblock_alloc_low(length, PAGE_SIZE);
  115. if (!sccb)
  116. return -ENOMEM;
  117. memset(sccb, 0, length);
  118. sccb->header.length = length;
  119. sccb->header.control_mask[2] = 0x80;
  120. if (sclp_early_cmd(SCLP_CMDW_READ_CPU_INFO, sccb)) {
  121. rc = -EIO;
  122. goto out;
  123. }
  124. if (sccb->header.response_code != 0x0010) {
  125. rc = -EIO;
  126. goto out;
  127. }
  128. sclp_fill_core_info(info, sccb);
  129. out:
  130. memblock_free(sccb, length);
  131. return rc;
  132. }
  133. static void __init sclp_early_console_detect(struct init_sccb *sccb)
  134. {
  135. if (sccb->header.response_code != 0x20)
  136. return;
  137. if (sclp_early_con_check_vt220(sccb))
  138. sclp.has_vt220 = 1;
  139. if (sclp_early_con_check_linemode(sccb))
  140. sclp.has_linemode = 1;
  141. }
  142. void __init __no_sanitize_address sclp_early_adjust_va(void)
  143. {
  144. sclp_early_sccb = __va((unsigned long)sclp_early_sccb);
  145. }
  146. void __init sclp_early_detect(void)
  147. {
  148. void *sccb = sclp_early_sccb;
  149. sclp_early_facilities_detect();
  150. /*
  151. * Turn off SCLP event notifications. Also save remote masks in the
  152. * sccb. These are sufficient to detect sclp console capabilities.
  153. */
  154. sclp_early_set_event_mask(sccb, 0, 0);
  155. sclp_early_console_detect(sccb);
  156. }