sclp_early.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * SCLP early driver
  3. *
  4. * Copyright IBM Corp. 2013
  5. */
  6. #define KMSG_COMPONENT "sclp_early"
  7. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  8. #include <asm/ctl_reg.h>
  9. #include <asm/sclp.h>
  10. #include <asm/ipl.h>
  11. #include "sclp_sdias.h"
  12. #include "sclp.h"
  13. #define SCLP_CMDW_READ_SCP_INFO 0x00020001
  14. #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
  15. struct read_info_sccb {
  16. struct sccb_header header; /* 0-7 */
  17. u16 rnmax; /* 8-9 */
  18. u8 rnsize; /* 10 */
  19. u8 _pad_11[16 - 11]; /* 11-15 */
  20. u16 ncpurl; /* 16-17 */
  21. u16 cpuoff; /* 18-19 */
  22. u8 _pad_20[24 - 20]; /* 20-23 */
  23. u8 loadparm[8]; /* 24-31 */
  24. u8 _pad_32[42 - 32]; /* 32-41 */
  25. u8 fac42; /* 42 */
  26. u8 fac43; /* 43 */
  27. u8 _pad_44[48 - 44]; /* 44-47 */
  28. u64 facilities; /* 48-55 */
  29. u8 _pad_56[66 - 56]; /* 56-65 */
  30. u8 fac66; /* 66 */
  31. u8 _pad_67[76 - 67]; /* 67-83 */
  32. u32 ibc; /* 76-79 */
  33. u8 _pad80[84 - 80]; /* 80-83 */
  34. u8 fac84; /* 84 */
  35. u8 fac85; /* 85 */
  36. u8 _pad_86[91 - 86]; /* 86-90 */
  37. u8 flags; /* 91 */
  38. u8 _pad_92[100 - 92]; /* 92-99 */
  39. u32 rnsize2; /* 100-103 */
  40. u64 rnmax2; /* 104-111 */
  41. u8 _pad_112[120 - 112]; /* 112-119 */
  42. u16 hcpua; /* 120-121 */
  43. u8 _pad_122[4096 - 122]; /* 122-4095 */
  44. } __packed __aligned(PAGE_SIZE);
  45. static char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE) __initdata;
  46. static struct sclp_ipl_info sclp_ipl_info;
  47. struct sclp_info sclp;
  48. EXPORT_SYMBOL(sclp);
  49. static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
  50. {
  51. int rc;
  52. __ctl_set_bit(0, 9);
  53. rc = sclp_service_call(cmd, sccb);
  54. if (rc)
  55. goto out;
  56. __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
  57. PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
  58. local_irq_disable();
  59. out:
  60. /* Contents of the sccb might have changed. */
  61. barrier();
  62. __ctl_clear_bit(0, 9);
  63. return rc;
  64. }
  65. static int __init sclp_read_info_early(struct read_info_sccb *sccb)
  66. {
  67. int rc, i;
  68. sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
  69. SCLP_CMDW_READ_SCP_INFO};
  70. for (i = 0; i < ARRAY_SIZE(commands); i++) {
  71. do {
  72. memset(sccb, 0, sizeof(*sccb));
  73. sccb->header.length = sizeof(*sccb);
  74. sccb->header.function_code = 0x80;
  75. sccb->header.control_mask[2] = 0x80;
  76. rc = sclp_cmd_sync_early(commands[i], sccb);
  77. } while (rc == -EBUSY);
  78. if (rc)
  79. break;
  80. if (sccb->header.response_code == 0x10)
  81. return 0;
  82. if (sccb->header.response_code != 0x1f0)
  83. break;
  84. }
  85. return -EIO;
  86. }
  87. static void __init sclp_facilities_detect(struct read_info_sccb *sccb)
  88. {
  89. struct sclp_core_entry *cpue;
  90. u16 boot_cpu_address, cpu;
  91. if (sclp_read_info_early(sccb))
  92. return;
  93. sclp.facilities = sccb->facilities;
  94. sclp.has_sprp = !!(sccb->fac84 & 0x02);
  95. sclp.has_core_type = !!(sccb->fac84 & 0x01);
  96. if (sccb->fac85 & 0x02)
  97. S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
  98. sclp.rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
  99. sclp.rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
  100. sclp.rzm <<= 20;
  101. sclp.ibc = sccb->ibc;
  102. if (!sccb->hcpua) {
  103. if (MACHINE_IS_VM)
  104. sclp.max_cores = 64;
  105. else
  106. sclp.max_cores = sccb->ncpurl;
  107. } else {
  108. sclp.max_cores = sccb->hcpua + 1;
  109. }
  110. boot_cpu_address = stap();
  111. cpue = (void *)sccb + sccb->cpuoff;
  112. for (cpu = 0; cpu < sccb->ncpurl; cpue++, cpu++) {
  113. if (boot_cpu_address != cpue->core_id)
  114. continue;
  115. sclp.has_siif = cpue->siif;
  116. sclp.has_sigpif = cpue->sigpif;
  117. break;
  118. }
  119. /* Save IPL information */
  120. sclp_ipl_info.is_valid = 1;
  121. if (sccb->flags & 0x2)
  122. sclp_ipl_info.has_dump = 1;
  123. memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
  124. sclp.mtid = (sccb->fac42 & 0x80) ? (sccb->fac42 & 31) : 0;
  125. sclp.mtid_cp = (sccb->fac42 & 0x80) ? (sccb->fac43 & 31) : 0;
  126. sclp.mtid_prev = (sccb->fac42 & 0x80) ? (sccb->fac66 & 31) : 0;
  127. }
  128. /*
  129. * This function will be called after sclp_facilities_detect(), which gets
  130. * called from early.c code. The sclp_facilities_detect() function retrieves
  131. * and saves the IPL information.
  132. */
  133. void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
  134. {
  135. *info = sclp_ipl_info;
  136. }
  137. static int __init sclp_cmd_early(sclp_cmdw_t cmd, void *sccb)
  138. {
  139. int rc;
  140. do {
  141. rc = sclp_cmd_sync_early(cmd, sccb);
  142. } while (rc == -EBUSY);
  143. if (rc)
  144. return -EIO;
  145. if (((struct sccb_header *) sccb)->response_code != 0x0020)
  146. return -EIO;
  147. return 0;
  148. }
  149. static void __init sccb_init_eq_size(struct sdias_sccb *sccb)
  150. {
  151. memset(sccb, 0, sizeof(*sccb));
  152. sccb->hdr.length = sizeof(*sccb);
  153. sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
  154. sccb->evbuf.hdr.type = EVTYP_SDIAS;
  155. sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
  156. sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
  157. sccb->evbuf.event_id = 4712;
  158. sccb->evbuf.dbs = 1;
  159. }
  160. static int __init sclp_set_event_mask(struct init_sccb *sccb,
  161. unsigned long receive_mask,
  162. unsigned long send_mask)
  163. {
  164. memset(sccb, 0, sizeof(*sccb));
  165. sccb->header.length = sizeof(*sccb);
  166. sccb->mask_length = sizeof(sccb_mask_t);
  167. sccb->receive_mask = receive_mask;
  168. sccb->send_mask = send_mask;
  169. return sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
  170. }
  171. static long __init sclp_hsa_size_init(struct sdias_sccb *sccb)
  172. {
  173. sccb_init_eq_size(sccb);
  174. if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
  175. return -EIO;
  176. if (sccb->evbuf.blk_cnt == 0)
  177. return 0;
  178. return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
  179. }
  180. static long __init sclp_hsa_copy_wait(struct sccb_header *sccb)
  181. {
  182. memset(sccb, 0, PAGE_SIZE);
  183. sccb->length = PAGE_SIZE;
  184. if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
  185. return -EIO;
  186. if (((struct sdias_sccb *) sccb)->evbuf.blk_cnt == 0)
  187. return 0;
  188. return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
  189. }
  190. static void __init sclp_hsa_size_detect(void *sccb)
  191. {
  192. long size;
  193. /* First try synchronous interface (LPAR) */
  194. if (sclp_set_event_mask(sccb, 0, 0x40000010))
  195. return;
  196. size = sclp_hsa_size_init(sccb);
  197. if (size < 0)
  198. return;
  199. if (size != 0)
  200. goto out;
  201. /* Then try asynchronous interface (z/VM) */
  202. if (sclp_set_event_mask(sccb, 0x00000010, 0x40000010))
  203. return;
  204. size = sclp_hsa_size_init(sccb);
  205. if (size < 0)
  206. return;
  207. size = sclp_hsa_copy_wait(sccb);
  208. if (size < 0)
  209. return;
  210. out:
  211. sclp.hsa_size = size;
  212. }
  213. static unsigned int __init sclp_con_check_linemode(struct init_sccb *sccb)
  214. {
  215. if (!(sccb->sclp_send_mask & EVTYP_OPCMD_MASK))
  216. return 0;
  217. if (!(sccb->sclp_receive_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)))
  218. return 0;
  219. return 1;
  220. }
  221. static void __init sclp_console_detect(struct init_sccb *sccb)
  222. {
  223. if (sccb->header.response_code != 0x20)
  224. return;
  225. if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
  226. sclp.has_vt220 = 1;
  227. if (sclp_con_check_linemode(sccb))
  228. sclp.has_linemode = 1;
  229. }
  230. void __init sclp_early_detect(void)
  231. {
  232. void *sccb = &sccb_early;
  233. sclp_facilities_detect(sccb);
  234. sclp_hsa_size_detect(sccb);
  235. /* Turn off SCLP event notifications. Also save remote masks in the
  236. * sccb. These are sufficient to detect sclp console capabilities.
  237. */
  238. sclp_set_event_mask(sccb, 0, 0);
  239. sclp_console_detect(sccb);
  240. }