ipl.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * ipl/reipl/dump support for Linux on s390.
  4. *
  5. * Copyright IBM Corp. 2005, 2012
  6. * Author(s): Michael Holzheu <holzheu@de.ibm.com>
  7. * Heiko Carstens <heiko.carstens@de.ibm.com>
  8. * Volker Sameske <sameske@de.ibm.com>
  9. */
  10. #include <linux/types.h>
  11. #include <linux/export.h>
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. #include <linux/delay.h>
  15. #include <linux/reboot.h>
  16. #include <linux/ctype.h>
  17. #include <linux/fs.h>
  18. #include <linux/gfp.h>
  19. #include <linux/crash_dump.h>
  20. #include <linux/debug_locks.h>
  21. #include <asm/diag.h>
  22. #include <asm/ipl.h>
  23. #include <asm/smp.h>
  24. #include <asm/setup.h>
  25. #include <asm/cpcmd.h>
  26. #include <asm/ebcdic.h>
  27. #include <asm/sclp.h>
  28. #include <asm/checksum.h>
  29. #include <asm/debug.h>
  30. #include <asm/os_info.h>
  31. #include "entry.h"
  32. #define IPL_PARM_BLOCK_VERSION 0
  33. #define IPL_UNKNOWN_STR "unknown"
  34. #define IPL_CCW_STR "ccw"
  35. #define IPL_FCP_STR "fcp"
  36. #define IPL_FCP_DUMP_STR "fcp_dump"
  37. #define IPL_NSS_STR "nss"
  38. #define DUMP_CCW_STR "ccw"
  39. #define DUMP_FCP_STR "fcp"
  40. #define DUMP_NONE_STR "none"
  41. /*
  42. * Four shutdown trigger types are supported:
  43. * - panic
  44. * - halt
  45. * - power off
  46. * - reipl
  47. * - restart
  48. */
  49. #define ON_PANIC_STR "on_panic"
  50. #define ON_HALT_STR "on_halt"
  51. #define ON_POFF_STR "on_poff"
  52. #define ON_REIPL_STR "on_reboot"
  53. #define ON_RESTART_STR "on_restart"
  54. struct shutdown_action;
  55. struct shutdown_trigger {
  56. char *name;
  57. struct shutdown_action *action;
  58. };
  59. /*
  60. * The following shutdown action types are supported:
  61. */
  62. #define SHUTDOWN_ACTION_IPL_STR "ipl"
  63. #define SHUTDOWN_ACTION_REIPL_STR "reipl"
  64. #define SHUTDOWN_ACTION_DUMP_STR "dump"
  65. #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
  66. #define SHUTDOWN_ACTION_STOP_STR "stop"
  67. #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
  68. struct shutdown_action {
  69. char *name;
  70. void (*fn) (struct shutdown_trigger *trigger);
  71. int (*init) (void);
  72. int init_rc;
  73. };
  74. static char *ipl_type_str(enum ipl_type type)
  75. {
  76. switch (type) {
  77. case IPL_TYPE_CCW:
  78. return IPL_CCW_STR;
  79. case IPL_TYPE_FCP:
  80. return IPL_FCP_STR;
  81. case IPL_TYPE_FCP_DUMP:
  82. return IPL_FCP_DUMP_STR;
  83. case IPL_TYPE_NSS:
  84. return IPL_NSS_STR;
  85. case IPL_TYPE_UNKNOWN:
  86. default:
  87. return IPL_UNKNOWN_STR;
  88. }
  89. }
  90. enum dump_type {
  91. DUMP_TYPE_NONE = 1,
  92. DUMP_TYPE_CCW = 2,
  93. DUMP_TYPE_FCP = 4,
  94. };
  95. static char *dump_type_str(enum dump_type type)
  96. {
  97. switch (type) {
  98. case DUMP_TYPE_NONE:
  99. return DUMP_NONE_STR;
  100. case DUMP_TYPE_CCW:
  101. return DUMP_CCW_STR;
  102. case DUMP_TYPE_FCP:
  103. return DUMP_FCP_STR;
  104. default:
  105. return NULL;
  106. }
  107. }
  108. static int ipl_block_valid;
  109. static struct ipl_parameter_block ipl_block;
  110. static int reipl_capabilities = IPL_TYPE_UNKNOWN;
  111. static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
  112. static struct ipl_parameter_block *reipl_block_fcp;
  113. static struct ipl_parameter_block *reipl_block_ccw;
  114. static struct ipl_parameter_block *reipl_block_nss;
  115. static struct ipl_parameter_block *reipl_block_actual;
  116. static int dump_capabilities = DUMP_TYPE_NONE;
  117. static enum dump_type dump_type = DUMP_TYPE_NONE;
  118. static struct ipl_parameter_block *dump_block_fcp;
  119. static struct ipl_parameter_block *dump_block_ccw;
  120. static struct sclp_ipl_info sclp_ipl_info;
  121. static inline int __diag308(unsigned long subcode, void *addr)
  122. {
  123. register unsigned long _addr asm("0") = (unsigned long) addr;
  124. register unsigned long _rc asm("1") = 0;
  125. asm volatile(
  126. " diag %0,%2,0x308\n"
  127. "0: nopr %%r7\n"
  128. EX_TABLE(0b,0b)
  129. : "+d" (_addr), "+d" (_rc)
  130. : "d" (subcode) : "cc", "memory");
  131. return _rc;
  132. }
  133. int diag308(unsigned long subcode, void *addr)
  134. {
  135. diag_stat_inc(DIAG_STAT_X308);
  136. return __diag308(subcode, addr);
  137. }
  138. EXPORT_SYMBOL_GPL(diag308);
  139. /* SYSFS */
  140. #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
  141. static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
  142. struct kobj_attribute *attr, \
  143. char *page) \
  144. { \
  145. return snprintf(page, PAGE_SIZE, _format, ##args); \
  146. }
  147. #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
  148. static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
  149. struct kobj_attribute *attr, \
  150. const char *buf, size_t len) \
  151. { \
  152. unsigned long long ssid, devno; \
  153. \
  154. if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
  155. return -EINVAL; \
  156. \
  157. if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
  158. return -EINVAL; \
  159. \
  160. _ipl_blk.ssid = ssid; \
  161. _ipl_blk.devno = devno; \
  162. return len; \
  163. }
  164. #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
  165. IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
  166. _ipl_blk.ssid, _ipl_blk.devno); \
  167. IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
  168. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  169. __ATTR(_name, (S_IRUGO | S_IWUSR), \
  170. sys_##_prefix##_##_name##_show, \
  171. sys_##_prefix##_##_name##_store) \
  172. #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
  173. IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
  174. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  175. __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
  176. #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
  177. IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
  178. static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
  179. struct kobj_attribute *attr, \
  180. const char *buf, size_t len) \
  181. { \
  182. unsigned long long value; \
  183. if (sscanf(buf, _fmt_in, &value) != 1) \
  184. return -EINVAL; \
  185. _value = value; \
  186. return len; \
  187. } \
  188. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  189. __ATTR(_name,(S_IRUGO | S_IWUSR), \
  190. sys_##_prefix##_##_name##_show, \
  191. sys_##_prefix##_##_name##_store)
  192. #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
  193. IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
  194. static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
  195. struct kobj_attribute *attr, \
  196. const char *buf, size_t len) \
  197. { \
  198. strncpy(_value, buf, sizeof(_value) - 1); \
  199. strim(_value); \
  200. return len; \
  201. } \
  202. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  203. __ATTR(_name,(S_IRUGO | S_IWUSR), \
  204. sys_##_prefix##_##_name##_show, \
  205. sys_##_prefix##_##_name##_store)
  206. /*
  207. * ipl section
  208. */
  209. static __init enum ipl_type get_ipl_type(void)
  210. {
  211. if (!ipl_block_valid)
  212. return IPL_TYPE_UNKNOWN;
  213. switch (ipl_block.hdr.pbt) {
  214. case DIAG308_IPL_TYPE_CCW:
  215. return IPL_TYPE_CCW;
  216. case DIAG308_IPL_TYPE_FCP:
  217. if (ipl_block.ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
  218. return IPL_TYPE_FCP_DUMP;
  219. else
  220. return IPL_TYPE_FCP;
  221. }
  222. return IPL_TYPE_UNKNOWN;
  223. }
  224. struct ipl_info ipl_info;
  225. EXPORT_SYMBOL_GPL(ipl_info);
  226. static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
  227. char *page)
  228. {
  229. return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
  230. }
  231. static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
  232. /* VM IPL PARM routines */
  233. static size_t reipl_get_ascii_vmparm(char *dest, size_t size,
  234. const struct ipl_parameter_block *ipb)
  235. {
  236. int i;
  237. size_t len;
  238. char has_lowercase = 0;
  239. len = 0;
  240. if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
  241. (ipb->ipl_info.ccw.vm_parm_len > 0)) {
  242. len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
  243. memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
  244. /* If at least one character is lowercase, we assume mixed
  245. * case; otherwise we convert everything to lowercase.
  246. */
  247. for (i = 0; i < len; i++)
  248. if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
  249. (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
  250. (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
  251. has_lowercase = 1;
  252. break;
  253. }
  254. if (!has_lowercase)
  255. EBC_TOLOWER(dest, len);
  256. EBCASC(dest, len);
  257. }
  258. dest[len] = 0;
  259. return len;
  260. }
  261. size_t append_ipl_vmparm(char *dest, size_t size)
  262. {
  263. size_t rc;
  264. rc = 0;
  265. if (ipl_block_valid && ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW)
  266. rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
  267. else
  268. dest[0] = 0;
  269. return rc;
  270. }
  271. static ssize_t ipl_vm_parm_show(struct kobject *kobj,
  272. struct kobj_attribute *attr, char *page)
  273. {
  274. char parm[DIAG308_VMPARM_SIZE + 1] = {};
  275. append_ipl_vmparm(parm, sizeof(parm));
  276. return sprintf(page, "%s\n", parm);
  277. }
  278. static size_t scpdata_length(const char* buf, size_t count)
  279. {
  280. while (count) {
  281. if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
  282. break;
  283. count--;
  284. }
  285. return count;
  286. }
  287. static size_t reipl_append_ascii_scpdata(char *dest, size_t size,
  288. const struct ipl_parameter_block *ipb)
  289. {
  290. size_t count;
  291. size_t i;
  292. int has_lowercase;
  293. count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data,
  294. ipb->ipl_info.fcp.scp_data_len));
  295. if (!count)
  296. goto out;
  297. has_lowercase = 0;
  298. for (i = 0; i < count; i++) {
  299. if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
  300. count = 0;
  301. goto out;
  302. }
  303. if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
  304. has_lowercase = 1;
  305. }
  306. if (has_lowercase)
  307. memcpy(dest, ipb->ipl_info.fcp.scp_data, count);
  308. else
  309. for (i = 0; i < count; i++)
  310. dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]);
  311. out:
  312. dest[count] = '\0';
  313. return count;
  314. }
  315. size_t append_ipl_scpdata(char *dest, size_t len)
  316. {
  317. size_t rc;
  318. rc = 0;
  319. if (ipl_block_valid && ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP)
  320. rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
  321. else
  322. dest[0] = 0;
  323. return rc;
  324. }
  325. static struct kobj_attribute sys_ipl_vm_parm_attr =
  326. __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
  327. static ssize_t sys_ipl_device_show(struct kobject *kobj,
  328. struct kobj_attribute *attr, char *page)
  329. {
  330. switch (ipl_info.type) {
  331. case IPL_TYPE_CCW:
  332. return sprintf(page, "0.%x.%04x\n", ipl_block.ipl_info.ccw.ssid,
  333. ipl_block.ipl_info.ccw.devno);
  334. case IPL_TYPE_FCP:
  335. case IPL_TYPE_FCP_DUMP:
  336. return sprintf(page, "0.0.%04x\n",
  337. ipl_block.ipl_info.fcp.devno);
  338. default:
  339. return 0;
  340. }
  341. }
  342. static struct kobj_attribute sys_ipl_device_attr =
  343. __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
  344. static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
  345. struct bin_attribute *attr, char *buf,
  346. loff_t off, size_t count)
  347. {
  348. return memory_read_from_buffer(buf, count, &off, &ipl_block,
  349. ipl_block.hdr.len);
  350. }
  351. static struct bin_attribute ipl_parameter_attr =
  352. __BIN_ATTR(binary_parameter, S_IRUGO, ipl_parameter_read, NULL,
  353. PAGE_SIZE);
  354. static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
  355. struct bin_attribute *attr, char *buf,
  356. loff_t off, size_t count)
  357. {
  358. unsigned int size = ipl_block.ipl_info.fcp.scp_data_len;
  359. void *scp_data = &ipl_block.ipl_info.fcp.scp_data;
  360. return memory_read_from_buffer(buf, count, &off, scp_data, size);
  361. }
  362. static struct bin_attribute ipl_scp_data_attr =
  363. __BIN_ATTR(scp_data, S_IRUGO, ipl_scp_data_read, NULL, PAGE_SIZE);
  364. static struct bin_attribute *ipl_fcp_bin_attrs[] = {
  365. &ipl_parameter_attr,
  366. &ipl_scp_data_attr,
  367. NULL,
  368. };
  369. /* FCP ipl device attributes */
  370. DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n",
  371. (unsigned long long)ipl_block.ipl_info.fcp.wwpn);
  372. DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n",
  373. (unsigned long long)ipl_block.ipl_info.fcp.lun);
  374. DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n",
  375. (unsigned long long)ipl_block.ipl_info.fcp.bootprog);
  376. DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n",
  377. (unsigned long long)ipl_block.ipl_info.fcp.br_lba);
  378. static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
  379. struct kobj_attribute *attr, char *page)
  380. {
  381. char loadparm[LOADPARM_LEN + 1] = {};
  382. if (!sclp_ipl_info.is_valid)
  383. return sprintf(page, "#unknown#\n");
  384. memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
  385. EBCASC(loadparm, LOADPARM_LEN);
  386. strim(loadparm);
  387. return sprintf(page, "%s\n", loadparm);
  388. }
  389. static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
  390. __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
  391. static struct attribute *ipl_fcp_attrs[] = {
  392. &sys_ipl_type_attr.attr,
  393. &sys_ipl_device_attr.attr,
  394. &sys_ipl_fcp_wwpn_attr.attr,
  395. &sys_ipl_fcp_lun_attr.attr,
  396. &sys_ipl_fcp_bootprog_attr.attr,
  397. &sys_ipl_fcp_br_lba_attr.attr,
  398. &sys_ipl_ccw_loadparm_attr.attr,
  399. NULL,
  400. };
  401. static struct attribute_group ipl_fcp_attr_group = {
  402. .attrs = ipl_fcp_attrs,
  403. .bin_attrs = ipl_fcp_bin_attrs,
  404. };
  405. /* CCW ipl device attributes */
  406. static struct attribute *ipl_ccw_attrs_vm[] = {
  407. &sys_ipl_type_attr.attr,
  408. &sys_ipl_device_attr.attr,
  409. &sys_ipl_ccw_loadparm_attr.attr,
  410. &sys_ipl_vm_parm_attr.attr,
  411. NULL,
  412. };
  413. static struct attribute *ipl_ccw_attrs_lpar[] = {
  414. &sys_ipl_type_attr.attr,
  415. &sys_ipl_device_attr.attr,
  416. &sys_ipl_ccw_loadparm_attr.attr,
  417. NULL,
  418. };
  419. static struct attribute_group ipl_ccw_attr_group_vm = {
  420. .attrs = ipl_ccw_attrs_vm,
  421. };
  422. static struct attribute_group ipl_ccw_attr_group_lpar = {
  423. .attrs = ipl_ccw_attrs_lpar
  424. };
  425. /* UNKNOWN ipl device attributes */
  426. static struct attribute *ipl_unknown_attrs[] = {
  427. &sys_ipl_type_attr.attr,
  428. NULL,
  429. };
  430. static struct attribute_group ipl_unknown_attr_group = {
  431. .attrs = ipl_unknown_attrs,
  432. };
  433. static struct kset *ipl_kset;
  434. static void __ipl_run(void *unused)
  435. {
  436. __bpon();
  437. diag308(DIAG308_LOAD_CLEAR, NULL);
  438. }
  439. static void ipl_run(struct shutdown_trigger *trigger)
  440. {
  441. smp_call_ipl_cpu(__ipl_run, NULL);
  442. }
  443. static int __init ipl_init(void)
  444. {
  445. int rc;
  446. ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
  447. if (!ipl_kset) {
  448. rc = -ENOMEM;
  449. goto out;
  450. }
  451. switch (ipl_info.type) {
  452. case IPL_TYPE_CCW:
  453. if (MACHINE_IS_VM)
  454. rc = sysfs_create_group(&ipl_kset->kobj,
  455. &ipl_ccw_attr_group_vm);
  456. else
  457. rc = sysfs_create_group(&ipl_kset->kobj,
  458. &ipl_ccw_attr_group_lpar);
  459. break;
  460. case IPL_TYPE_FCP:
  461. case IPL_TYPE_FCP_DUMP:
  462. rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
  463. break;
  464. default:
  465. rc = sysfs_create_group(&ipl_kset->kobj,
  466. &ipl_unknown_attr_group);
  467. break;
  468. }
  469. out:
  470. if (rc)
  471. panic("ipl_init failed: rc = %i\n", rc);
  472. return 0;
  473. }
  474. static struct shutdown_action __refdata ipl_action = {
  475. .name = SHUTDOWN_ACTION_IPL_STR,
  476. .fn = ipl_run,
  477. .init = ipl_init,
  478. };
  479. /*
  480. * reipl shutdown action: Reboot Linux on shutdown.
  481. */
  482. /* VM IPL PARM attributes */
  483. static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
  484. char *page)
  485. {
  486. char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
  487. reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
  488. return sprintf(page, "%s\n", vmparm);
  489. }
  490. static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
  491. size_t vmparm_max,
  492. const char *buf, size_t len)
  493. {
  494. int i, ip_len;
  495. /* ignore trailing newline */
  496. ip_len = len;
  497. if ((len > 0) && (buf[len - 1] == '\n'))
  498. ip_len--;
  499. if (ip_len > vmparm_max)
  500. return -EINVAL;
  501. /* parm is used to store kernel options, check for common chars */
  502. for (i = 0; i < ip_len; i++)
  503. if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
  504. return -EINVAL;
  505. memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
  506. ipb->ipl_info.ccw.vm_parm_len = ip_len;
  507. if (ip_len > 0) {
  508. ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
  509. memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
  510. ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
  511. } else {
  512. ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
  513. }
  514. return len;
  515. }
  516. /* NSS wrapper */
  517. static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
  518. struct kobj_attribute *attr, char *page)
  519. {
  520. return reipl_generic_vmparm_show(reipl_block_nss, page);
  521. }
  522. static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
  523. struct kobj_attribute *attr,
  524. const char *buf, size_t len)
  525. {
  526. return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
  527. }
  528. /* CCW wrapper */
  529. static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
  530. struct kobj_attribute *attr, char *page)
  531. {
  532. return reipl_generic_vmparm_show(reipl_block_ccw, page);
  533. }
  534. static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
  535. struct kobj_attribute *attr,
  536. const char *buf, size_t len)
  537. {
  538. return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
  539. }
  540. static struct kobj_attribute sys_reipl_nss_vmparm_attr =
  541. __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
  542. reipl_nss_vmparm_store);
  543. static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
  544. __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
  545. reipl_ccw_vmparm_store);
  546. /* FCP reipl device attributes */
  547. static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
  548. struct bin_attribute *attr,
  549. char *buf, loff_t off, size_t count)
  550. {
  551. size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len;
  552. void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data;
  553. return memory_read_from_buffer(buf, count, &off, scp_data, size);
  554. }
  555. static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
  556. struct bin_attribute *attr,
  557. char *buf, loff_t off, size_t count)
  558. {
  559. size_t scpdata_len = count;
  560. size_t padding;
  561. if (off)
  562. return -EINVAL;
  563. memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf, count);
  564. if (scpdata_len % 8) {
  565. padding = 8 - (scpdata_len % 8);
  566. memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len,
  567. 0, padding);
  568. scpdata_len += padding;
  569. }
  570. reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len;
  571. reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len;
  572. reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len;
  573. return count;
  574. }
  575. static struct bin_attribute sys_reipl_fcp_scp_data_attr =
  576. __BIN_ATTR(scp_data, (S_IRUGO | S_IWUSR), reipl_fcp_scpdata_read,
  577. reipl_fcp_scpdata_write, DIAG308_SCPDATA_SIZE);
  578. static struct bin_attribute *reipl_fcp_bin_attrs[] = {
  579. &sys_reipl_fcp_scp_data_attr,
  580. NULL,
  581. };
  582. DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%llx\n",
  583. reipl_block_fcp->ipl_info.fcp.wwpn);
  584. DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%llx\n",
  585. reipl_block_fcp->ipl_info.fcp.lun);
  586. DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
  587. reipl_block_fcp->ipl_info.fcp.bootprog);
  588. DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
  589. reipl_block_fcp->ipl_info.fcp.br_lba);
  590. DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  591. reipl_block_fcp->ipl_info.fcp.devno);
  592. static void reipl_get_ascii_loadparm(char *loadparm,
  593. struct ipl_parameter_block *ibp)
  594. {
  595. memcpy(loadparm, ibp->hdr.loadparm, LOADPARM_LEN);
  596. EBCASC(loadparm, LOADPARM_LEN);
  597. loadparm[LOADPARM_LEN] = 0;
  598. strim(loadparm);
  599. }
  600. static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
  601. char *page)
  602. {
  603. char buf[LOADPARM_LEN + 1];
  604. reipl_get_ascii_loadparm(buf, ipb);
  605. return sprintf(page, "%s\n", buf);
  606. }
  607. static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
  608. const char *buf, size_t len)
  609. {
  610. int i, lp_len;
  611. /* ignore trailing newline */
  612. lp_len = len;
  613. if ((len > 0) && (buf[len - 1] == '\n'))
  614. lp_len--;
  615. /* loadparm can have max 8 characters and must not start with a blank */
  616. if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
  617. return -EINVAL;
  618. /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
  619. for (i = 0; i < lp_len; i++) {
  620. if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
  621. (buf[i] == '.'))
  622. continue;
  623. return -EINVAL;
  624. }
  625. /* initialize loadparm with blanks */
  626. memset(ipb->hdr.loadparm, ' ', LOADPARM_LEN);
  627. /* copy and convert to ebcdic */
  628. memcpy(ipb->hdr.loadparm, buf, lp_len);
  629. ASCEBC(ipb->hdr.loadparm, LOADPARM_LEN);
  630. ipb->hdr.flags |= DIAG308_FLAGS_LP_VALID;
  631. return len;
  632. }
  633. /* FCP wrapper */
  634. static ssize_t reipl_fcp_loadparm_show(struct kobject *kobj,
  635. struct kobj_attribute *attr, char *page)
  636. {
  637. return reipl_generic_loadparm_show(reipl_block_fcp, page);
  638. }
  639. static ssize_t reipl_fcp_loadparm_store(struct kobject *kobj,
  640. struct kobj_attribute *attr,
  641. const char *buf, size_t len)
  642. {
  643. return reipl_generic_loadparm_store(reipl_block_fcp, buf, len);
  644. }
  645. static struct kobj_attribute sys_reipl_fcp_loadparm_attr =
  646. __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_fcp_loadparm_show,
  647. reipl_fcp_loadparm_store);
  648. static struct attribute *reipl_fcp_attrs[] = {
  649. &sys_reipl_fcp_device_attr.attr,
  650. &sys_reipl_fcp_wwpn_attr.attr,
  651. &sys_reipl_fcp_lun_attr.attr,
  652. &sys_reipl_fcp_bootprog_attr.attr,
  653. &sys_reipl_fcp_br_lba_attr.attr,
  654. &sys_reipl_fcp_loadparm_attr.attr,
  655. NULL,
  656. };
  657. static struct attribute_group reipl_fcp_attr_group = {
  658. .attrs = reipl_fcp_attrs,
  659. .bin_attrs = reipl_fcp_bin_attrs,
  660. };
  661. /* CCW reipl device attributes */
  662. DEFINE_IPL_CCW_ATTR_RW(reipl_ccw, device, reipl_block_ccw->ipl_info.ccw);
  663. /* NSS wrapper */
  664. static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
  665. struct kobj_attribute *attr, char *page)
  666. {
  667. return reipl_generic_loadparm_show(reipl_block_nss, page);
  668. }
  669. static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
  670. struct kobj_attribute *attr,
  671. const char *buf, size_t len)
  672. {
  673. return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
  674. }
  675. /* CCW wrapper */
  676. static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
  677. struct kobj_attribute *attr, char *page)
  678. {
  679. return reipl_generic_loadparm_show(reipl_block_ccw, page);
  680. }
  681. static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
  682. struct kobj_attribute *attr,
  683. const char *buf, size_t len)
  684. {
  685. return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
  686. }
  687. static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
  688. __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
  689. reipl_ccw_loadparm_store);
  690. static struct attribute *reipl_ccw_attrs_vm[] = {
  691. &sys_reipl_ccw_device_attr.attr,
  692. &sys_reipl_ccw_loadparm_attr.attr,
  693. &sys_reipl_ccw_vmparm_attr.attr,
  694. NULL,
  695. };
  696. static struct attribute *reipl_ccw_attrs_lpar[] = {
  697. &sys_reipl_ccw_device_attr.attr,
  698. &sys_reipl_ccw_loadparm_attr.attr,
  699. NULL,
  700. };
  701. static struct attribute_group reipl_ccw_attr_group_vm = {
  702. .name = IPL_CCW_STR,
  703. .attrs = reipl_ccw_attrs_vm,
  704. };
  705. static struct attribute_group reipl_ccw_attr_group_lpar = {
  706. .name = IPL_CCW_STR,
  707. .attrs = reipl_ccw_attrs_lpar,
  708. };
  709. /* NSS reipl device attributes */
  710. static void reipl_get_ascii_nss_name(char *dst,
  711. struct ipl_parameter_block *ipb)
  712. {
  713. memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
  714. EBCASC(dst, NSS_NAME_SIZE);
  715. dst[NSS_NAME_SIZE] = 0;
  716. }
  717. static ssize_t reipl_nss_name_show(struct kobject *kobj,
  718. struct kobj_attribute *attr, char *page)
  719. {
  720. char nss_name[NSS_NAME_SIZE + 1] = {};
  721. reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
  722. return sprintf(page, "%s\n", nss_name);
  723. }
  724. static ssize_t reipl_nss_name_store(struct kobject *kobj,
  725. struct kobj_attribute *attr,
  726. const char *buf, size_t len)
  727. {
  728. int nss_len;
  729. /* ignore trailing newline */
  730. nss_len = len;
  731. if ((len > 0) && (buf[len - 1] == '\n'))
  732. nss_len--;
  733. if (nss_len > NSS_NAME_SIZE)
  734. return -EINVAL;
  735. memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
  736. if (nss_len > 0) {
  737. reipl_block_nss->ipl_info.ccw.vm_flags |=
  738. DIAG308_VM_FLAGS_NSS_VALID;
  739. memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
  740. ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
  741. EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
  742. } else {
  743. reipl_block_nss->ipl_info.ccw.vm_flags &=
  744. ~DIAG308_VM_FLAGS_NSS_VALID;
  745. }
  746. return len;
  747. }
  748. static struct kobj_attribute sys_reipl_nss_name_attr =
  749. __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
  750. reipl_nss_name_store);
  751. static struct kobj_attribute sys_reipl_nss_loadparm_attr =
  752. __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
  753. reipl_nss_loadparm_store);
  754. static struct attribute *reipl_nss_attrs[] = {
  755. &sys_reipl_nss_name_attr.attr,
  756. &sys_reipl_nss_loadparm_attr.attr,
  757. &sys_reipl_nss_vmparm_attr.attr,
  758. NULL,
  759. };
  760. static struct attribute_group reipl_nss_attr_group = {
  761. .name = IPL_NSS_STR,
  762. .attrs = reipl_nss_attrs,
  763. };
  764. void set_os_info_reipl_block(void)
  765. {
  766. os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual,
  767. reipl_block_actual->hdr.len);
  768. }
  769. /* reipl type */
  770. static int reipl_set_type(enum ipl_type type)
  771. {
  772. if (!(reipl_capabilities & type))
  773. return -EINVAL;
  774. switch(type) {
  775. case IPL_TYPE_CCW:
  776. reipl_block_actual = reipl_block_ccw;
  777. break;
  778. case IPL_TYPE_FCP:
  779. reipl_block_actual = reipl_block_fcp;
  780. break;
  781. case IPL_TYPE_NSS:
  782. reipl_block_actual = reipl_block_nss;
  783. break;
  784. default:
  785. break;
  786. }
  787. reipl_type = type;
  788. return 0;
  789. }
  790. static ssize_t reipl_type_show(struct kobject *kobj,
  791. struct kobj_attribute *attr, char *page)
  792. {
  793. return sprintf(page, "%s\n", ipl_type_str(reipl_type));
  794. }
  795. static ssize_t reipl_type_store(struct kobject *kobj,
  796. struct kobj_attribute *attr,
  797. const char *buf, size_t len)
  798. {
  799. int rc = -EINVAL;
  800. if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
  801. rc = reipl_set_type(IPL_TYPE_CCW);
  802. else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
  803. rc = reipl_set_type(IPL_TYPE_FCP);
  804. else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
  805. rc = reipl_set_type(IPL_TYPE_NSS);
  806. return (rc != 0) ? rc : len;
  807. }
  808. static struct kobj_attribute reipl_type_attr =
  809. __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
  810. static struct kset *reipl_kset;
  811. static struct kset *reipl_fcp_kset;
  812. static void __reipl_run(void *unused)
  813. {
  814. switch (reipl_type) {
  815. case IPL_TYPE_CCW:
  816. diag308(DIAG308_SET, reipl_block_ccw);
  817. diag308(DIAG308_LOAD_CLEAR, NULL);
  818. break;
  819. case IPL_TYPE_FCP:
  820. diag308(DIAG308_SET, reipl_block_fcp);
  821. diag308(DIAG308_LOAD_CLEAR, NULL);
  822. break;
  823. case IPL_TYPE_NSS:
  824. diag308(DIAG308_SET, reipl_block_nss);
  825. diag308(DIAG308_LOAD_CLEAR, NULL);
  826. break;
  827. case IPL_TYPE_UNKNOWN:
  828. diag308(DIAG308_LOAD_CLEAR, NULL);
  829. break;
  830. case IPL_TYPE_FCP_DUMP:
  831. break;
  832. }
  833. disabled_wait((unsigned long) __builtin_return_address(0));
  834. }
  835. static void reipl_run(struct shutdown_trigger *trigger)
  836. {
  837. smp_call_ipl_cpu(__reipl_run, NULL);
  838. }
  839. static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
  840. {
  841. ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
  842. ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
  843. ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  844. ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  845. }
  846. static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
  847. {
  848. /* LOADPARM */
  849. /* check if read scp info worked and set loadparm */
  850. if (sclp_ipl_info.is_valid)
  851. memcpy(ipb->hdr.loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
  852. else
  853. /* read scp info failed: set empty loadparm (EBCDIC blanks) */
  854. memset(ipb->hdr.loadparm, 0x40, LOADPARM_LEN);
  855. ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
  856. /* VM PARM */
  857. if (MACHINE_IS_VM && ipl_block_valid &&
  858. (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
  859. ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
  860. ipb->ipl_info.ccw.vm_parm_len =
  861. ipl_block.ipl_info.ccw.vm_parm_len;
  862. memcpy(ipb->ipl_info.ccw.vm_parm,
  863. ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
  864. }
  865. }
  866. static int __init reipl_nss_init(void)
  867. {
  868. int rc;
  869. if (!MACHINE_IS_VM)
  870. return 0;
  871. reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
  872. if (!reipl_block_nss)
  873. return -ENOMEM;
  874. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
  875. if (rc)
  876. return rc;
  877. reipl_block_ccw_init(reipl_block_nss);
  878. reipl_capabilities |= IPL_TYPE_NSS;
  879. return 0;
  880. }
  881. static int __init reipl_ccw_init(void)
  882. {
  883. int rc;
  884. reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  885. if (!reipl_block_ccw)
  886. return -ENOMEM;
  887. rc = sysfs_create_group(&reipl_kset->kobj,
  888. MACHINE_IS_VM ? &reipl_ccw_attr_group_vm
  889. : &reipl_ccw_attr_group_lpar);
  890. if (rc)
  891. return rc;
  892. reipl_block_ccw_init(reipl_block_ccw);
  893. if (ipl_info.type == IPL_TYPE_CCW) {
  894. reipl_block_ccw->ipl_info.ccw.ssid = ipl_block.ipl_info.ccw.ssid;
  895. reipl_block_ccw->ipl_info.ccw.devno = ipl_block.ipl_info.ccw.devno;
  896. reipl_block_ccw_fill_parms(reipl_block_ccw);
  897. }
  898. reipl_capabilities |= IPL_TYPE_CCW;
  899. return 0;
  900. }
  901. static int __init reipl_fcp_init(void)
  902. {
  903. int rc;
  904. reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  905. if (!reipl_block_fcp)
  906. return -ENOMEM;
  907. /* sysfs: create fcp kset for mixing attr group and bin attrs */
  908. reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
  909. &reipl_kset->kobj);
  910. if (!reipl_fcp_kset) {
  911. free_page((unsigned long) reipl_block_fcp);
  912. return -ENOMEM;
  913. }
  914. rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
  915. if (rc) {
  916. kset_unregister(reipl_fcp_kset);
  917. free_page((unsigned long) reipl_block_fcp);
  918. return rc;
  919. }
  920. if (ipl_info.type == IPL_TYPE_FCP) {
  921. memcpy(reipl_block_fcp, &ipl_block, sizeof(ipl_block));
  922. /*
  923. * Fix loadparm: There are systems where the (SCSI) LOADPARM
  924. * is invalid in the SCSI IPL parameter block, so take it
  925. * always from sclp_ipl_info.
  926. */
  927. memcpy(reipl_block_fcp->hdr.loadparm, sclp_ipl_info.loadparm,
  928. LOADPARM_LEN);
  929. } else {
  930. reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  931. reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  932. reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  933. reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  934. reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
  935. }
  936. reipl_capabilities |= IPL_TYPE_FCP;
  937. return 0;
  938. }
  939. static int __init reipl_type_init(void)
  940. {
  941. enum ipl_type reipl_type = ipl_info.type;
  942. struct ipl_parameter_block *reipl_block;
  943. unsigned long size;
  944. reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size);
  945. if (!reipl_block)
  946. goto out;
  947. /*
  948. * If we have an OS info reipl block, this will be used
  949. */
  950. if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_FCP) {
  951. memcpy(reipl_block_fcp, reipl_block, size);
  952. reipl_type = IPL_TYPE_FCP;
  953. } else if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_CCW) {
  954. memcpy(reipl_block_ccw, reipl_block, size);
  955. reipl_type = IPL_TYPE_CCW;
  956. }
  957. out:
  958. return reipl_set_type(reipl_type);
  959. }
  960. static int __init reipl_init(void)
  961. {
  962. int rc;
  963. reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
  964. if (!reipl_kset)
  965. return -ENOMEM;
  966. rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
  967. if (rc) {
  968. kset_unregister(reipl_kset);
  969. return rc;
  970. }
  971. rc = reipl_ccw_init();
  972. if (rc)
  973. return rc;
  974. rc = reipl_fcp_init();
  975. if (rc)
  976. return rc;
  977. rc = reipl_nss_init();
  978. if (rc)
  979. return rc;
  980. return reipl_type_init();
  981. }
  982. static struct shutdown_action __refdata reipl_action = {
  983. .name = SHUTDOWN_ACTION_REIPL_STR,
  984. .fn = reipl_run,
  985. .init = reipl_init,
  986. };
  987. /*
  988. * dump shutdown action: Dump Linux on shutdown.
  989. */
  990. /* FCP dump device attributes */
  991. DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%llx\n",
  992. dump_block_fcp->ipl_info.fcp.wwpn);
  993. DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%llx\n",
  994. dump_block_fcp->ipl_info.fcp.lun);
  995. DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
  996. dump_block_fcp->ipl_info.fcp.bootprog);
  997. DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
  998. dump_block_fcp->ipl_info.fcp.br_lba);
  999. DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  1000. dump_block_fcp->ipl_info.fcp.devno);
  1001. static struct attribute *dump_fcp_attrs[] = {
  1002. &sys_dump_fcp_device_attr.attr,
  1003. &sys_dump_fcp_wwpn_attr.attr,
  1004. &sys_dump_fcp_lun_attr.attr,
  1005. &sys_dump_fcp_bootprog_attr.attr,
  1006. &sys_dump_fcp_br_lba_attr.attr,
  1007. NULL,
  1008. };
  1009. static struct attribute_group dump_fcp_attr_group = {
  1010. .name = IPL_FCP_STR,
  1011. .attrs = dump_fcp_attrs,
  1012. };
  1013. /* CCW dump device attributes */
  1014. DEFINE_IPL_CCW_ATTR_RW(dump_ccw, device, dump_block_ccw->ipl_info.ccw);
  1015. static struct attribute *dump_ccw_attrs[] = {
  1016. &sys_dump_ccw_device_attr.attr,
  1017. NULL,
  1018. };
  1019. static struct attribute_group dump_ccw_attr_group = {
  1020. .name = IPL_CCW_STR,
  1021. .attrs = dump_ccw_attrs,
  1022. };
  1023. /* dump type */
  1024. static int dump_set_type(enum dump_type type)
  1025. {
  1026. if (!(dump_capabilities & type))
  1027. return -EINVAL;
  1028. dump_type = type;
  1029. return 0;
  1030. }
  1031. static ssize_t dump_type_show(struct kobject *kobj,
  1032. struct kobj_attribute *attr, char *page)
  1033. {
  1034. return sprintf(page, "%s\n", dump_type_str(dump_type));
  1035. }
  1036. static ssize_t dump_type_store(struct kobject *kobj,
  1037. struct kobj_attribute *attr,
  1038. const char *buf, size_t len)
  1039. {
  1040. int rc = -EINVAL;
  1041. if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
  1042. rc = dump_set_type(DUMP_TYPE_NONE);
  1043. else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
  1044. rc = dump_set_type(DUMP_TYPE_CCW);
  1045. else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
  1046. rc = dump_set_type(DUMP_TYPE_FCP);
  1047. return (rc != 0) ? rc : len;
  1048. }
  1049. static struct kobj_attribute dump_type_attr =
  1050. __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
  1051. static struct kset *dump_kset;
  1052. static void diag308_dump(void *dump_block)
  1053. {
  1054. diag308(DIAG308_SET, dump_block);
  1055. while (1) {
  1056. if (diag308(DIAG308_LOAD_NORMAL_DUMP, NULL) != 0x302)
  1057. break;
  1058. udelay_simple(USEC_PER_SEC);
  1059. }
  1060. }
  1061. static void __dump_run(void *unused)
  1062. {
  1063. switch (dump_type) {
  1064. case DUMP_TYPE_CCW:
  1065. diag308_dump(dump_block_ccw);
  1066. break;
  1067. case DUMP_TYPE_FCP:
  1068. diag308_dump(dump_block_fcp);
  1069. break;
  1070. default:
  1071. break;
  1072. }
  1073. }
  1074. static void dump_run(struct shutdown_trigger *trigger)
  1075. {
  1076. if (dump_type == DUMP_TYPE_NONE)
  1077. return;
  1078. smp_send_stop();
  1079. smp_call_ipl_cpu(__dump_run, NULL);
  1080. }
  1081. static int __init dump_ccw_init(void)
  1082. {
  1083. int rc;
  1084. dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  1085. if (!dump_block_ccw)
  1086. return -ENOMEM;
  1087. rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
  1088. if (rc) {
  1089. free_page((unsigned long)dump_block_ccw);
  1090. return rc;
  1091. }
  1092. dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  1093. dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  1094. dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  1095. dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  1096. dump_capabilities |= DUMP_TYPE_CCW;
  1097. return 0;
  1098. }
  1099. static int __init dump_fcp_init(void)
  1100. {
  1101. int rc;
  1102. if (!sclp_ipl_info.has_dump)
  1103. return 0; /* LDIPL DUMP is not installed */
  1104. dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  1105. if (!dump_block_fcp)
  1106. return -ENOMEM;
  1107. rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
  1108. if (rc) {
  1109. free_page((unsigned long)dump_block_fcp);
  1110. return rc;
  1111. }
  1112. dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  1113. dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  1114. dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  1115. dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  1116. dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
  1117. dump_capabilities |= DUMP_TYPE_FCP;
  1118. return 0;
  1119. }
  1120. static int __init dump_init(void)
  1121. {
  1122. int rc;
  1123. dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
  1124. if (!dump_kset)
  1125. return -ENOMEM;
  1126. rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
  1127. if (rc) {
  1128. kset_unregister(dump_kset);
  1129. return rc;
  1130. }
  1131. rc = dump_ccw_init();
  1132. if (rc)
  1133. return rc;
  1134. rc = dump_fcp_init();
  1135. if (rc)
  1136. return rc;
  1137. dump_set_type(DUMP_TYPE_NONE);
  1138. return 0;
  1139. }
  1140. static struct shutdown_action __refdata dump_action = {
  1141. .name = SHUTDOWN_ACTION_DUMP_STR,
  1142. .fn = dump_run,
  1143. .init = dump_init,
  1144. };
  1145. static void dump_reipl_run(struct shutdown_trigger *trigger)
  1146. {
  1147. unsigned long ipib = (unsigned long) reipl_block_actual;
  1148. unsigned int csum;
  1149. csum = (__force unsigned int)
  1150. csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
  1151. mem_assign_absolute(S390_lowcore.ipib, ipib);
  1152. mem_assign_absolute(S390_lowcore.ipib_checksum, csum);
  1153. dump_run(trigger);
  1154. }
  1155. static struct shutdown_action __refdata dump_reipl_action = {
  1156. .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
  1157. .fn = dump_reipl_run,
  1158. };
  1159. /*
  1160. * vmcmd shutdown action: Trigger vm command on shutdown.
  1161. */
  1162. static char vmcmd_on_reboot[128];
  1163. static char vmcmd_on_panic[128];
  1164. static char vmcmd_on_halt[128];
  1165. static char vmcmd_on_poff[128];
  1166. static char vmcmd_on_restart[128];
  1167. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
  1168. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
  1169. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
  1170. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
  1171. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
  1172. static struct attribute *vmcmd_attrs[] = {
  1173. &sys_vmcmd_on_reboot_attr.attr,
  1174. &sys_vmcmd_on_panic_attr.attr,
  1175. &sys_vmcmd_on_halt_attr.attr,
  1176. &sys_vmcmd_on_poff_attr.attr,
  1177. &sys_vmcmd_on_restart_attr.attr,
  1178. NULL,
  1179. };
  1180. static struct attribute_group vmcmd_attr_group = {
  1181. .attrs = vmcmd_attrs,
  1182. };
  1183. static struct kset *vmcmd_kset;
  1184. static void vmcmd_run(struct shutdown_trigger *trigger)
  1185. {
  1186. char *cmd;
  1187. if (strcmp(trigger->name, ON_REIPL_STR) == 0)
  1188. cmd = vmcmd_on_reboot;
  1189. else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
  1190. cmd = vmcmd_on_panic;
  1191. else if (strcmp(trigger->name, ON_HALT_STR) == 0)
  1192. cmd = vmcmd_on_halt;
  1193. else if (strcmp(trigger->name, ON_POFF_STR) == 0)
  1194. cmd = vmcmd_on_poff;
  1195. else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
  1196. cmd = vmcmd_on_restart;
  1197. else
  1198. return;
  1199. if (strlen(cmd) == 0)
  1200. return;
  1201. __cpcmd(cmd, NULL, 0, NULL);
  1202. }
  1203. static int vmcmd_init(void)
  1204. {
  1205. if (!MACHINE_IS_VM)
  1206. return -EOPNOTSUPP;
  1207. vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
  1208. if (!vmcmd_kset)
  1209. return -ENOMEM;
  1210. return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
  1211. }
  1212. static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
  1213. vmcmd_run, vmcmd_init};
  1214. /*
  1215. * stop shutdown action: Stop Linux on shutdown.
  1216. */
  1217. static void stop_run(struct shutdown_trigger *trigger)
  1218. {
  1219. if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
  1220. strcmp(trigger->name, ON_RESTART_STR) == 0)
  1221. disabled_wait((unsigned long) __builtin_return_address(0));
  1222. smp_stop_cpu();
  1223. }
  1224. static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
  1225. stop_run, NULL};
  1226. /* action list */
  1227. static struct shutdown_action *shutdown_actions_list[] = {
  1228. &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
  1229. &vmcmd_action, &stop_action};
  1230. #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
  1231. /*
  1232. * Trigger section
  1233. */
  1234. static struct kset *shutdown_actions_kset;
  1235. static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
  1236. size_t len)
  1237. {
  1238. int i;
  1239. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  1240. if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
  1241. if (shutdown_actions_list[i]->init_rc) {
  1242. return shutdown_actions_list[i]->init_rc;
  1243. } else {
  1244. trigger->action = shutdown_actions_list[i];
  1245. return len;
  1246. }
  1247. }
  1248. }
  1249. return -EINVAL;
  1250. }
  1251. /* on reipl */
  1252. static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
  1253. &reipl_action};
  1254. static ssize_t on_reboot_show(struct kobject *kobj,
  1255. struct kobj_attribute *attr, char *page)
  1256. {
  1257. return sprintf(page, "%s\n", on_reboot_trigger.action->name);
  1258. }
  1259. static ssize_t on_reboot_store(struct kobject *kobj,
  1260. struct kobj_attribute *attr,
  1261. const char *buf, size_t len)
  1262. {
  1263. return set_trigger(buf, &on_reboot_trigger, len);
  1264. }
  1265. static struct kobj_attribute on_reboot_attr = __ATTR_RW(on_reboot);
  1266. static void do_machine_restart(char *__unused)
  1267. {
  1268. smp_send_stop();
  1269. on_reboot_trigger.action->fn(&on_reboot_trigger);
  1270. reipl_run(NULL);
  1271. }
  1272. void (*_machine_restart)(char *command) = do_machine_restart;
  1273. /* on panic */
  1274. static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
  1275. static ssize_t on_panic_show(struct kobject *kobj,
  1276. struct kobj_attribute *attr, char *page)
  1277. {
  1278. return sprintf(page, "%s\n", on_panic_trigger.action->name);
  1279. }
  1280. static ssize_t on_panic_store(struct kobject *kobj,
  1281. struct kobj_attribute *attr,
  1282. const char *buf, size_t len)
  1283. {
  1284. return set_trigger(buf, &on_panic_trigger, len);
  1285. }
  1286. static struct kobj_attribute on_panic_attr = __ATTR_RW(on_panic);
  1287. static void do_panic(void)
  1288. {
  1289. lgr_info_log();
  1290. on_panic_trigger.action->fn(&on_panic_trigger);
  1291. stop_run(&on_panic_trigger);
  1292. }
  1293. /* on restart */
  1294. static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
  1295. &stop_action};
  1296. static ssize_t on_restart_show(struct kobject *kobj,
  1297. struct kobj_attribute *attr, char *page)
  1298. {
  1299. return sprintf(page, "%s\n", on_restart_trigger.action->name);
  1300. }
  1301. static ssize_t on_restart_store(struct kobject *kobj,
  1302. struct kobj_attribute *attr,
  1303. const char *buf, size_t len)
  1304. {
  1305. return set_trigger(buf, &on_restart_trigger, len);
  1306. }
  1307. static struct kobj_attribute on_restart_attr = __ATTR_RW(on_restart);
  1308. static void __do_restart(void *ignore)
  1309. {
  1310. __arch_local_irq_stosm(0x04); /* enable DAT */
  1311. smp_send_stop();
  1312. #ifdef CONFIG_CRASH_DUMP
  1313. crash_kexec(NULL);
  1314. #endif
  1315. on_restart_trigger.action->fn(&on_restart_trigger);
  1316. stop_run(&on_restart_trigger);
  1317. }
  1318. void do_restart(void)
  1319. {
  1320. tracing_off();
  1321. debug_locks_off();
  1322. lgr_info_log();
  1323. smp_call_online_cpu(__do_restart, NULL);
  1324. }
  1325. /* on halt */
  1326. static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
  1327. static ssize_t on_halt_show(struct kobject *kobj,
  1328. struct kobj_attribute *attr, char *page)
  1329. {
  1330. return sprintf(page, "%s\n", on_halt_trigger.action->name);
  1331. }
  1332. static ssize_t on_halt_store(struct kobject *kobj,
  1333. struct kobj_attribute *attr,
  1334. const char *buf, size_t len)
  1335. {
  1336. return set_trigger(buf, &on_halt_trigger, len);
  1337. }
  1338. static struct kobj_attribute on_halt_attr = __ATTR_RW(on_halt);
  1339. static void do_machine_halt(void)
  1340. {
  1341. smp_send_stop();
  1342. on_halt_trigger.action->fn(&on_halt_trigger);
  1343. stop_run(&on_halt_trigger);
  1344. }
  1345. void (*_machine_halt)(void) = do_machine_halt;
  1346. /* on power off */
  1347. static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
  1348. static ssize_t on_poff_show(struct kobject *kobj,
  1349. struct kobj_attribute *attr, char *page)
  1350. {
  1351. return sprintf(page, "%s\n", on_poff_trigger.action->name);
  1352. }
  1353. static ssize_t on_poff_store(struct kobject *kobj,
  1354. struct kobj_attribute *attr,
  1355. const char *buf, size_t len)
  1356. {
  1357. return set_trigger(buf, &on_poff_trigger, len);
  1358. }
  1359. static struct kobj_attribute on_poff_attr = __ATTR_RW(on_poff);
  1360. static void do_machine_power_off(void)
  1361. {
  1362. smp_send_stop();
  1363. on_poff_trigger.action->fn(&on_poff_trigger);
  1364. stop_run(&on_poff_trigger);
  1365. }
  1366. void (*_machine_power_off)(void) = do_machine_power_off;
  1367. static struct attribute *shutdown_action_attrs[] = {
  1368. &on_restart_attr.attr,
  1369. &on_reboot_attr.attr,
  1370. &on_panic_attr.attr,
  1371. &on_halt_attr.attr,
  1372. &on_poff_attr.attr,
  1373. NULL,
  1374. };
  1375. static struct attribute_group shutdown_action_attr_group = {
  1376. .attrs = shutdown_action_attrs,
  1377. };
  1378. static void __init shutdown_triggers_init(void)
  1379. {
  1380. shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
  1381. firmware_kobj);
  1382. if (!shutdown_actions_kset)
  1383. goto fail;
  1384. if (sysfs_create_group(&shutdown_actions_kset->kobj,
  1385. &shutdown_action_attr_group))
  1386. goto fail;
  1387. return;
  1388. fail:
  1389. panic("shutdown_triggers_init failed\n");
  1390. }
  1391. static void __init shutdown_actions_init(void)
  1392. {
  1393. int i;
  1394. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  1395. if (!shutdown_actions_list[i]->init)
  1396. continue;
  1397. shutdown_actions_list[i]->init_rc =
  1398. shutdown_actions_list[i]->init();
  1399. }
  1400. }
  1401. static int __init s390_ipl_init(void)
  1402. {
  1403. char str[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
  1404. sclp_early_get_ipl_info(&sclp_ipl_info);
  1405. /*
  1406. * Fix loadparm: There are systems where the (SCSI) LOADPARM
  1407. * returned by read SCP info is invalid (contains EBCDIC blanks)
  1408. * when the system has been booted via diag308. In that case we use
  1409. * the value from diag308, if available.
  1410. *
  1411. * There are also systems where diag308 store does not work in
  1412. * case the system is booted from HMC. Fortunately in this case
  1413. * READ SCP info provides the correct value.
  1414. */
  1415. if (memcmp(sclp_ipl_info.loadparm, str, sizeof(str)) == 0 && ipl_block_valid)
  1416. memcpy(sclp_ipl_info.loadparm, ipl_block.hdr.loadparm, LOADPARM_LEN);
  1417. shutdown_actions_init();
  1418. shutdown_triggers_init();
  1419. return 0;
  1420. }
  1421. __initcall(s390_ipl_init);
  1422. static void __init strncpy_skip_quote(char *dst, char *src, int n)
  1423. {
  1424. int sx, dx;
  1425. dx = 0;
  1426. for (sx = 0; src[sx] != 0; sx++) {
  1427. if (src[sx] == '"')
  1428. continue;
  1429. dst[dx++] = src[sx];
  1430. if (dx >= n)
  1431. break;
  1432. }
  1433. }
  1434. static int __init vmcmd_on_reboot_setup(char *str)
  1435. {
  1436. if (!MACHINE_IS_VM)
  1437. return 1;
  1438. strncpy_skip_quote(vmcmd_on_reboot, str, 127);
  1439. vmcmd_on_reboot[127] = 0;
  1440. on_reboot_trigger.action = &vmcmd_action;
  1441. return 1;
  1442. }
  1443. __setup("vmreboot=", vmcmd_on_reboot_setup);
  1444. static int __init vmcmd_on_panic_setup(char *str)
  1445. {
  1446. if (!MACHINE_IS_VM)
  1447. return 1;
  1448. strncpy_skip_quote(vmcmd_on_panic, str, 127);
  1449. vmcmd_on_panic[127] = 0;
  1450. on_panic_trigger.action = &vmcmd_action;
  1451. return 1;
  1452. }
  1453. __setup("vmpanic=", vmcmd_on_panic_setup);
  1454. static int __init vmcmd_on_halt_setup(char *str)
  1455. {
  1456. if (!MACHINE_IS_VM)
  1457. return 1;
  1458. strncpy_skip_quote(vmcmd_on_halt, str, 127);
  1459. vmcmd_on_halt[127] = 0;
  1460. on_halt_trigger.action = &vmcmd_action;
  1461. return 1;
  1462. }
  1463. __setup("vmhalt=", vmcmd_on_halt_setup);
  1464. static int __init vmcmd_on_poff_setup(char *str)
  1465. {
  1466. if (!MACHINE_IS_VM)
  1467. return 1;
  1468. strncpy_skip_quote(vmcmd_on_poff, str, 127);
  1469. vmcmd_on_poff[127] = 0;
  1470. on_poff_trigger.action = &vmcmd_action;
  1471. return 1;
  1472. }
  1473. __setup("vmpoff=", vmcmd_on_poff_setup);
  1474. static int on_panic_notify(struct notifier_block *self,
  1475. unsigned long event, void *data)
  1476. {
  1477. do_panic();
  1478. return NOTIFY_OK;
  1479. }
  1480. static struct notifier_block on_panic_nb = {
  1481. .notifier_call = on_panic_notify,
  1482. .priority = INT_MIN,
  1483. };
  1484. void __init setup_ipl(void)
  1485. {
  1486. BUILD_BUG_ON(sizeof(struct ipl_parameter_block) != PAGE_SIZE);
  1487. ipl_info.type = get_ipl_type();
  1488. switch (ipl_info.type) {
  1489. case IPL_TYPE_CCW:
  1490. ipl_info.data.ccw.dev_id.ssid = ipl_block.ipl_info.ccw.ssid;
  1491. ipl_info.data.ccw.dev_id.devno = ipl_block.ipl_info.ccw.devno;
  1492. break;
  1493. case IPL_TYPE_FCP:
  1494. case IPL_TYPE_FCP_DUMP:
  1495. ipl_info.data.fcp.dev_id.ssid = 0;
  1496. ipl_info.data.fcp.dev_id.devno = ipl_block.ipl_info.fcp.devno;
  1497. ipl_info.data.fcp.wwpn = ipl_block.ipl_info.fcp.wwpn;
  1498. ipl_info.data.fcp.lun = ipl_block.ipl_info.fcp.lun;
  1499. break;
  1500. case IPL_TYPE_NSS:
  1501. case IPL_TYPE_UNKNOWN:
  1502. /* We have no info to copy */
  1503. break;
  1504. }
  1505. atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
  1506. }
  1507. void __init ipl_store_parameters(void)
  1508. {
  1509. int rc;
  1510. rc = diag308(DIAG308_STORE, &ipl_block);
  1511. if (rc == DIAG308_RC_OK && ipl_block.hdr.version <= IPL_MAX_SUPPORTED_VERSION)
  1512. ipl_block_valid = 1;
  1513. }
  1514. void s390_reset_system(void)
  1515. {
  1516. /* Disable prefixing */
  1517. set_prefix(0);
  1518. /* Disable lowcore protection */
  1519. __ctl_clear_bit(0, 28);
  1520. diag308_reset();
  1521. }