ipl.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. /*
  2. * arch/s390/kernel/ipl.c
  3. * ipl/reipl/dump support for Linux on s390.
  4. *
  5. * Copyright IBM Corp. 2005,2007
  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/module.h>
  12. #include <linux/device.h>
  13. #include <linux/delay.h>
  14. #include <linux/reboot.h>
  15. #include <linux/ctype.h>
  16. #include <asm/ipl.h>
  17. #include <asm/smp.h>
  18. #include <asm/setup.h>
  19. #include <asm/cpcmd.h>
  20. #include <asm/cio.h>
  21. #include <asm/ebcdic.h>
  22. #include <asm/reset.h>
  23. #include <asm/sclp.h>
  24. #define IPL_PARM_BLOCK_VERSION 0
  25. #define IPL_UNKNOWN_STR "unknown"
  26. #define IPL_CCW_STR "ccw"
  27. #define IPL_FCP_STR "fcp"
  28. #define IPL_FCP_DUMP_STR "fcp_dump"
  29. #define IPL_NSS_STR "nss"
  30. #define DUMP_CCW_STR "ccw"
  31. #define DUMP_FCP_STR "fcp"
  32. #define DUMP_NONE_STR "none"
  33. /*
  34. * Four shutdown trigger types are supported:
  35. * - panic
  36. * - halt
  37. * - power off
  38. * - reipl
  39. */
  40. #define ON_PANIC_STR "on_panic"
  41. #define ON_HALT_STR "on_halt"
  42. #define ON_POFF_STR "on_poff"
  43. #define ON_REIPL_STR "on_reboot"
  44. struct shutdown_action;
  45. struct shutdown_trigger {
  46. char *name;
  47. struct shutdown_action *action;
  48. };
  49. /*
  50. * Five shutdown action types are supported:
  51. */
  52. #define SHUTDOWN_ACTION_IPL_STR "ipl"
  53. #define SHUTDOWN_ACTION_REIPL_STR "reipl"
  54. #define SHUTDOWN_ACTION_DUMP_STR "dump"
  55. #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
  56. #define SHUTDOWN_ACTION_STOP_STR "stop"
  57. struct shutdown_action {
  58. char *name;
  59. void (*fn) (struct shutdown_trigger *trigger);
  60. int (*init) (void);
  61. };
  62. static char *ipl_type_str(enum ipl_type type)
  63. {
  64. switch (type) {
  65. case IPL_TYPE_CCW:
  66. return IPL_CCW_STR;
  67. case IPL_TYPE_FCP:
  68. return IPL_FCP_STR;
  69. case IPL_TYPE_FCP_DUMP:
  70. return IPL_FCP_DUMP_STR;
  71. case IPL_TYPE_NSS:
  72. return IPL_NSS_STR;
  73. case IPL_TYPE_UNKNOWN:
  74. default:
  75. return IPL_UNKNOWN_STR;
  76. }
  77. }
  78. enum dump_type {
  79. DUMP_TYPE_NONE = 1,
  80. DUMP_TYPE_CCW = 2,
  81. DUMP_TYPE_FCP = 4,
  82. };
  83. static char *dump_type_str(enum dump_type type)
  84. {
  85. switch (type) {
  86. case DUMP_TYPE_NONE:
  87. return DUMP_NONE_STR;
  88. case DUMP_TYPE_CCW:
  89. return DUMP_CCW_STR;
  90. case DUMP_TYPE_FCP:
  91. return DUMP_FCP_STR;
  92. default:
  93. return NULL;
  94. }
  95. }
  96. /*
  97. * Must be in data section since the bss section
  98. * is not cleared when these are accessed.
  99. */
  100. static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
  101. u32 ipl_flags __attribute__((__section__(".data"))) = 0;
  102. enum ipl_method {
  103. REIPL_METHOD_CCW_CIO,
  104. REIPL_METHOD_CCW_DIAG,
  105. REIPL_METHOD_CCW_VM,
  106. REIPL_METHOD_FCP_RO_DIAG,
  107. REIPL_METHOD_FCP_RW_DIAG,
  108. REIPL_METHOD_FCP_RO_VM,
  109. REIPL_METHOD_FCP_DUMP,
  110. REIPL_METHOD_NSS,
  111. REIPL_METHOD_DEFAULT,
  112. };
  113. enum dump_method {
  114. DUMP_METHOD_NONE,
  115. DUMP_METHOD_CCW_CIO,
  116. DUMP_METHOD_CCW_DIAG,
  117. DUMP_METHOD_CCW_VM,
  118. DUMP_METHOD_FCP_DIAG,
  119. };
  120. static int diag308_set_works = 0;
  121. static int reipl_capabilities = IPL_TYPE_UNKNOWN;
  122. static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
  123. static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
  124. static struct ipl_parameter_block *reipl_block_fcp;
  125. static struct ipl_parameter_block *reipl_block_ccw;
  126. static char reipl_nss_name[NSS_NAME_SIZE + 1];
  127. static int dump_capabilities = DUMP_TYPE_NONE;
  128. static enum dump_type dump_type = DUMP_TYPE_NONE;
  129. static enum dump_method dump_method = DUMP_METHOD_NONE;
  130. static struct ipl_parameter_block *dump_block_fcp;
  131. static struct ipl_parameter_block *dump_block_ccw;
  132. static struct sclp_ipl_info sclp_ipl_info;
  133. int diag308(unsigned long subcode, void *addr)
  134. {
  135. register unsigned long _addr asm("0") = (unsigned long) addr;
  136. register unsigned long _rc asm("1") = 0;
  137. asm volatile(
  138. " diag %0,%2,0x308\n"
  139. "0:\n"
  140. EX_TABLE(0b,0b)
  141. : "+d" (_addr), "+d" (_rc)
  142. : "d" (subcode) : "cc", "memory");
  143. return _rc;
  144. }
  145. EXPORT_SYMBOL_GPL(diag308);
  146. /* SYSFS */
  147. #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
  148. static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
  149. struct kobj_attribute *attr, \
  150. char *page) \
  151. { \
  152. return sprintf(page, _format, _value); \
  153. } \
  154. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  155. __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
  156. #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
  157. static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
  158. struct kobj_attribute *attr, \
  159. char *page) \
  160. { \
  161. return sprintf(page, _fmt_out, \
  162. (unsigned long long) _value); \
  163. } \
  164. static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
  165. struct kobj_attribute *attr, \
  166. const char *buf, size_t len) \
  167. { \
  168. unsigned long long value; \
  169. if (sscanf(buf, _fmt_in, &value) != 1) \
  170. return -EINVAL; \
  171. _value = value; \
  172. return len; \
  173. } \
  174. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  175. __ATTR(_name,(S_IRUGO | S_IWUSR), \
  176. sys_##_prefix##_##_name##_show, \
  177. sys_##_prefix##_##_name##_store);
  178. #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
  179. static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
  180. struct kobj_attribute *attr, \
  181. char *page) \
  182. { \
  183. return sprintf(page, _fmt_out, _value); \
  184. } \
  185. static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
  186. struct kobj_attribute *attr, \
  187. const char *buf, size_t len) \
  188. { \
  189. strncpy(_value, buf, sizeof(_value) - 1); \
  190. strstrip(_value); \
  191. return len; \
  192. } \
  193. static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
  194. __ATTR(_name,(S_IRUGO | S_IWUSR), \
  195. sys_##_prefix##_##_name##_show, \
  196. sys_##_prefix##_##_name##_store);
  197. static void make_attrs_ro(struct attribute **attrs)
  198. {
  199. while (*attrs) {
  200. (*attrs)->mode = S_IRUGO;
  201. attrs++;
  202. }
  203. }
  204. /*
  205. * ipl section
  206. */
  207. static __init enum ipl_type get_ipl_type(void)
  208. {
  209. struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
  210. if (ipl_flags & IPL_NSS_VALID)
  211. return IPL_TYPE_NSS;
  212. if (!(ipl_flags & IPL_DEVNO_VALID))
  213. return IPL_TYPE_UNKNOWN;
  214. if (!(ipl_flags & IPL_PARMBLOCK_VALID))
  215. return IPL_TYPE_CCW;
  216. if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
  217. return IPL_TYPE_UNKNOWN;
  218. if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
  219. return IPL_TYPE_UNKNOWN;
  220. if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
  221. return IPL_TYPE_FCP_DUMP;
  222. return IPL_TYPE_FCP;
  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. static ssize_t sys_ipl_device_show(struct kobject *kobj,
  233. struct kobj_attribute *attr, char *page)
  234. {
  235. struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
  236. switch (ipl_info.type) {
  237. case IPL_TYPE_CCW:
  238. return sprintf(page, "0.0.%04x\n", ipl_devno);
  239. case IPL_TYPE_FCP:
  240. case IPL_TYPE_FCP_DUMP:
  241. return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
  242. default:
  243. return 0;
  244. }
  245. }
  246. static struct kobj_attribute sys_ipl_device_attr =
  247. __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
  248. static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
  249. char *buf, loff_t off, size_t count)
  250. {
  251. unsigned int size = IPL_PARMBLOCK_SIZE;
  252. if (off > size)
  253. return 0;
  254. if (off + count > size)
  255. count = size - off;
  256. memcpy(buf, (void *)IPL_PARMBLOCK_START + off, count);
  257. return count;
  258. }
  259. static struct bin_attribute ipl_parameter_attr = {
  260. .attr = {
  261. .name = "binary_parameter",
  262. .mode = S_IRUGO,
  263. },
  264. .size = PAGE_SIZE,
  265. .read = &ipl_parameter_read,
  266. };
  267. static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
  268. char *buf, loff_t off, size_t count)
  269. {
  270. unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
  271. void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
  272. if (off > size)
  273. return 0;
  274. if (off + count > size)
  275. count = size - off;
  276. memcpy(buf, scp_data + off, count);
  277. return count;
  278. }
  279. static struct bin_attribute ipl_scp_data_attr = {
  280. .attr = {
  281. .name = "scp_data",
  282. .mode = S_IRUGO,
  283. },
  284. .size = PAGE_SIZE,
  285. .read = ipl_scp_data_read,
  286. };
  287. /* FCP ipl device attributes */
  288. DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
  289. IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
  290. DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
  291. IPL_PARMBLOCK_START->ipl_info.fcp.lun);
  292. DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
  293. IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
  294. DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
  295. IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
  296. static struct attribute *ipl_fcp_attrs[] = {
  297. &sys_ipl_type_attr.attr,
  298. &sys_ipl_device_attr.attr,
  299. &sys_ipl_fcp_wwpn_attr.attr,
  300. &sys_ipl_fcp_lun_attr.attr,
  301. &sys_ipl_fcp_bootprog_attr.attr,
  302. &sys_ipl_fcp_br_lba_attr.attr,
  303. NULL,
  304. };
  305. static struct attribute_group ipl_fcp_attr_group = {
  306. .attrs = ipl_fcp_attrs,
  307. };
  308. /* CCW ipl device attributes */
  309. static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
  310. struct kobj_attribute *attr, char *page)
  311. {
  312. char loadparm[LOADPARM_LEN + 1] = {};
  313. if (!sclp_ipl_info.is_valid)
  314. return sprintf(page, "#unknown#\n");
  315. memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
  316. EBCASC(loadparm, LOADPARM_LEN);
  317. strstrip(loadparm);
  318. return sprintf(page, "%s\n", loadparm);
  319. }
  320. static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
  321. __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
  322. static struct attribute *ipl_ccw_attrs[] = {
  323. &sys_ipl_type_attr.attr,
  324. &sys_ipl_device_attr.attr,
  325. &sys_ipl_ccw_loadparm_attr.attr,
  326. NULL,
  327. };
  328. static struct attribute_group ipl_ccw_attr_group = {
  329. .attrs = ipl_ccw_attrs,
  330. };
  331. /* NSS ipl device attributes */
  332. DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
  333. static struct attribute *ipl_nss_attrs[] = {
  334. &sys_ipl_type_attr.attr,
  335. &sys_ipl_nss_name_attr.attr,
  336. NULL,
  337. };
  338. static struct attribute_group ipl_nss_attr_group = {
  339. .attrs = ipl_nss_attrs,
  340. };
  341. /* UNKNOWN ipl device attributes */
  342. static struct attribute *ipl_unknown_attrs[] = {
  343. &sys_ipl_type_attr.attr,
  344. NULL,
  345. };
  346. static struct attribute_group ipl_unknown_attr_group = {
  347. .attrs = ipl_unknown_attrs,
  348. };
  349. static struct kset *ipl_kset;
  350. static int __init ipl_register_fcp_files(void)
  351. {
  352. int rc;
  353. rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
  354. if (rc)
  355. goto out;
  356. rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
  357. if (rc)
  358. goto out_ipl_parm;
  359. rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
  360. if (!rc)
  361. goto out;
  362. sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
  363. out_ipl_parm:
  364. sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
  365. out:
  366. return rc;
  367. }
  368. static void ipl_run(struct shutdown_trigger *trigger)
  369. {
  370. diag308(DIAG308_IPL, NULL);
  371. if (MACHINE_IS_VM)
  372. __cpcmd("IPL", NULL, 0, NULL);
  373. else if (ipl_info.type == IPL_TYPE_CCW)
  374. reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
  375. }
  376. static int __init ipl_init(void)
  377. {
  378. int rc;
  379. ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
  380. if (!ipl_kset) {
  381. rc = -ENOMEM;
  382. goto out;
  383. }
  384. switch (ipl_info.type) {
  385. case IPL_TYPE_CCW:
  386. rc = sysfs_create_group(&ipl_kset->kobj, &ipl_ccw_attr_group);
  387. break;
  388. case IPL_TYPE_FCP:
  389. case IPL_TYPE_FCP_DUMP:
  390. rc = ipl_register_fcp_files();
  391. break;
  392. case IPL_TYPE_NSS:
  393. rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
  394. break;
  395. default:
  396. rc = sysfs_create_group(&ipl_kset->kobj,
  397. &ipl_unknown_attr_group);
  398. break;
  399. }
  400. out:
  401. if (rc)
  402. panic("ipl_init failed: rc = %i\n", rc);
  403. return 0;
  404. }
  405. static struct shutdown_action __refdata ipl_action = {
  406. .name = SHUTDOWN_ACTION_IPL_STR,
  407. .fn = ipl_run,
  408. .init = ipl_init,
  409. };
  410. /*
  411. * reipl shutdown action: Reboot Linux on shutdown.
  412. */
  413. /* FCP reipl device attributes */
  414. DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
  415. reipl_block_fcp->ipl_info.fcp.wwpn);
  416. DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
  417. reipl_block_fcp->ipl_info.fcp.lun);
  418. DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
  419. reipl_block_fcp->ipl_info.fcp.bootprog);
  420. DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
  421. reipl_block_fcp->ipl_info.fcp.br_lba);
  422. DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  423. reipl_block_fcp->ipl_info.fcp.devno);
  424. static struct attribute *reipl_fcp_attrs[] = {
  425. &sys_reipl_fcp_device_attr.attr,
  426. &sys_reipl_fcp_wwpn_attr.attr,
  427. &sys_reipl_fcp_lun_attr.attr,
  428. &sys_reipl_fcp_bootprog_attr.attr,
  429. &sys_reipl_fcp_br_lba_attr.attr,
  430. NULL,
  431. };
  432. static struct attribute_group reipl_fcp_attr_group = {
  433. .name = IPL_FCP_STR,
  434. .attrs = reipl_fcp_attrs,
  435. };
  436. /* CCW reipl device attributes */
  437. DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
  438. reipl_block_ccw->ipl_info.ccw.devno);
  439. static void reipl_get_ascii_loadparm(char *loadparm)
  440. {
  441. memcpy(loadparm, &reipl_block_ccw->ipl_info.ccw.load_param,
  442. LOADPARM_LEN);
  443. EBCASC(loadparm, LOADPARM_LEN);
  444. loadparm[LOADPARM_LEN] = 0;
  445. strstrip(loadparm);
  446. }
  447. static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
  448. struct kobj_attribute *attr, char *page)
  449. {
  450. char buf[LOADPARM_LEN + 1];
  451. reipl_get_ascii_loadparm(buf);
  452. return sprintf(page, "%s\n", buf);
  453. }
  454. static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
  455. struct kobj_attribute *attr,
  456. const char *buf, size_t len)
  457. {
  458. int i, lp_len;
  459. /* ignore trailing newline */
  460. lp_len = len;
  461. if ((len > 0) && (buf[len - 1] == '\n'))
  462. lp_len--;
  463. /* loadparm can have max 8 characters and must not start with a blank */
  464. if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
  465. return -EINVAL;
  466. /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
  467. for (i = 0; i < lp_len; i++) {
  468. if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
  469. (buf[i] == '.'))
  470. continue;
  471. return -EINVAL;
  472. }
  473. /* initialize loadparm with blanks */
  474. memset(&reipl_block_ccw->ipl_info.ccw.load_param, ' ', LOADPARM_LEN);
  475. /* copy and convert to ebcdic */
  476. memcpy(&reipl_block_ccw->ipl_info.ccw.load_param, buf, lp_len);
  477. ASCEBC(reipl_block_ccw->ipl_info.ccw.load_param, LOADPARM_LEN);
  478. return len;
  479. }
  480. static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
  481. __ATTR(loadparm, 0644, reipl_ccw_loadparm_show,
  482. reipl_ccw_loadparm_store);
  483. static struct attribute *reipl_ccw_attrs[] = {
  484. &sys_reipl_ccw_device_attr.attr,
  485. &sys_reipl_ccw_loadparm_attr.attr,
  486. NULL,
  487. };
  488. static struct attribute_group reipl_ccw_attr_group = {
  489. .name = IPL_CCW_STR,
  490. .attrs = reipl_ccw_attrs,
  491. };
  492. /* NSS reipl device attributes */
  493. DEFINE_IPL_ATTR_STR_RW(reipl_nss, name, "%s\n", "%s\n", reipl_nss_name);
  494. static struct attribute *reipl_nss_attrs[] = {
  495. &sys_reipl_nss_name_attr.attr,
  496. NULL,
  497. };
  498. static struct attribute_group reipl_nss_attr_group = {
  499. .name = IPL_NSS_STR,
  500. .attrs = reipl_nss_attrs,
  501. };
  502. /* reipl type */
  503. static int reipl_set_type(enum ipl_type type)
  504. {
  505. if (!(reipl_capabilities & type))
  506. return -EINVAL;
  507. switch(type) {
  508. case IPL_TYPE_CCW:
  509. if (diag308_set_works)
  510. reipl_method = REIPL_METHOD_CCW_DIAG;
  511. else if (MACHINE_IS_VM)
  512. reipl_method = REIPL_METHOD_CCW_VM;
  513. else
  514. reipl_method = REIPL_METHOD_CCW_CIO;
  515. break;
  516. case IPL_TYPE_FCP:
  517. if (diag308_set_works)
  518. reipl_method = REIPL_METHOD_FCP_RW_DIAG;
  519. else if (MACHINE_IS_VM)
  520. reipl_method = REIPL_METHOD_FCP_RO_VM;
  521. else
  522. reipl_method = REIPL_METHOD_FCP_RO_DIAG;
  523. break;
  524. case IPL_TYPE_FCP_DUMP:
  525. reipl_method = REIPL_METHOD_FCP_DUMP;
  526. break;
  527. case IPL_TYPE_NSS:
  528. reipl_method = REIPL_METHOD_NSS;
  529. break;
  530. case IPL_TYPE_UNKNOWN:
  531. reipl_method = REIPL_METHOD_DEFAULT;
  532. break;
  533. default:
  534. BUG();
  535. }
  536. reipl_type = type;
  537. return 0;
  538. }
  539. static ssize_t reipl_type_show(struct kobject *kobj,
  540. struct kobj_attribute *attr, char *page)
  541. {
  542. return sprintf(page, "%s\n", ipl_type_str(reipl_type));
  543. }
  544. static ssize_t reipl_type_store(struct kobject *kobj,
  545. struct kobj_attribute *attr,
  546. const char *buf, size_t len)
  547. {
  548. int rc = -EINVAL;
  549. if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
  550. rc = reipl_set_type(IPL_TYPE_CCW);
  551. else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
  552. rc = reipl_set_type(IPL_TYPE_FCP);
  553. else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
  554. rc = reipl_set_type(IPL_TYPE_NSS);
  555. return (rc != 0) ? rc : len;
  556. }
  557. static struct kobj_attribute reipl_type_attr =
  558. __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
  559. static struct kset *reipl_kset;
  560. static void reipl_run(struct shutdown_trigger *trigger)
  561. {
  562. struct ccw_dev_id devid;
  563. static char buf[100];
  564. char loadparm[LOADPARM_LEN + 1];
  565. switch (reipl_method) {
  566. case REIPL_METHOD_CCW_CIO:
  567. devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
  568. devid.ssid = 0;
  569. reipl_ccw_dev(&devid);
  570. break;
  571. case REIPL_METHOD_CCW_VM:
  572. reipl_get_ascii_loadparm(loadparm);
  573. if (strlen(loadparm) == 0)
  574. sprintf(buf, "IPL %X CLEAR",
  575. reipl_block_ccw->ipl_info.ccw.devno);
  576. else
  577. sprintf(buf, "IPL %X CLEAR LOADPARM '%s'",
  578. reipl_block_ccw->ipl_info.ccw.devno, loadparm);
  579. __cpcmd(buf, NULL, 0, NULL);
  580. break;
  581. case REIPL_METHOD_CCW_DIAG:
  582. diag308(DIAG308_SET, reipl_block_ccw);
  583. diag308(DIAG308_IPL, NULL);
  584. break;
  585. case REIPL_METHOD_FCP_RW_DIAG:
  586. diag308(DIAG308_SET, reipl_block_fcp);
  587. diag308(DIAG308_IPL, NULL);
  588. break;
  589. case REIPL_METHOD_FCP_RO_DIAG:
  590. diag308(DIAG308_IPL, NULL);
  591. break;
  592. case REIPL_METHOD_FCP_RO_VM:
  593. __cpcmd("IPL", NULL, 0, NULL);
  594. break;
  595. case REIPL_METHOD_NSS:
  596. sprintf(buf, "IPL %s", reipl_nss_name);
  597. __cpcmd(buf, NULL, 0, NULL);
  598. break;
  599. case REIPL_METHOD_DEFAULT:
  600. if (MACHINE_IS_VM)
  601. __cpcmd("IPL", NULL, 0, NULL);
  602. diag308(DIAG308_IPL, NULL);
  603. break;
  604. case REIPL_METHOD_FCP_DUMP:
  605. default:
  606. break;
  607. }
  608. disabled_wait((unsigned long) __builtin_return_address(0));
  609. }
  610. static void __init reipl_probe(void)
  611. {
  612. void *buffer;
  613. buffer = (void *) get_zeroed_page(GFP_KERNEL);
  614. if (!buffer)
  615. return;
  616. if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK)
  617. diag308_set_works = 1;
  618. free_page((unsigned long)buffer);
  619. }
  620. static int __init reipl_nss_init(void)
  621. {
  622. int rc;
  623. if (!MACHINE_IS_VM)
  624. return 0;
  625. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
  626. if (rc)
  627. return rc;
  628. strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
  629. reipl_capabilities |= IPL_TYPE_NSS;
  630. return 0;
  631. }
  632. static int __init reipl_ccw_init(void)
  633. {
  634. int rc;
  635. reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  636. if (!reipl_block_ccw)
  637. return -ENOMEM;
  638. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_ccw_attr_group);
  639. if (rc) {
  640. free_page((unsigned long)reipl_block_ccw);
  641. return rc;
  642. }
  643. reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  644. reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  645. reipl_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  646. reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  647. reipl_block_ccw->hdr.flags = DIAG308_FLAGS_LP_VALID;
  648. /* check if read scp info worked and set loadparm */
  649. if (sclp_ipl_info.is_valid)
  650. memcpy(reipl_block_ccw->ipl_info.ccw.load_param,
  651. &sclp_ipl_info.loadparm, LOADPARM_LEN);
  652. else
  653. /* read scp info failed: set empty loadparm (EBCDIC blanks) */
  654. memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40,
  655. LOADPARM_LEN);
  656. if (!MACHINE_IS_VM && !diag308_set_works)
  657. sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
  658. if (ipl_info.type == IPL_TYPE_CCW)
  659. reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
  660. reipl_capabilities |= IPL_TYPE_CCW;
  661. return 0;
  662. }
  663. static int __init reipl_fcp_init(void)
  664. {
  665. int rc;
  666. if ((!diag308_set_works) && (ipl_info.type != IPL_TYPE_FCP))
  667. return 0;
  668. if ((!diag308_set_works) && (ipl_info.type == IPL_TYPE_FCP))
  669. make_attrs_ro(reipl_fcp_attrs);
  670. reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  671. if (!reipl_block_fcp)
  672. return -ENOMEM;
  673. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
  674. if (rc) {
  675. free_page((unsigned long)reipl_block_fcp);
  676. return rc;
  677. }
  678. if (ipl_info.type == IPL_TYPE_FCP) {
  679. memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
  680. } else {
  681. reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  682. reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  683. reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  684. reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  685. reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
  686. }
  687. reipl_capabilities |= IPL_TYPE_FCP;
  688. return 0;
  689. }
  690. static int __init reipl_init(void)
  691. {
  692. int rc;
  693. reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
  694. if (!reipl_kset)
  695. return -ENOMEM;
  696. rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
  697. if (rc) {
  698. kset_unregister(reipl_kset);
  699. return rc;
  700. }
  701. rc = reipl_ccw_init();
  702. if (rc)
  703. return rc;
  704. rc = reipl_fcp_init();
  705. if (rc)
  706. return rc;
  707. rc = reipl_nss_init();
  708. if (rc)
  709. return rc;
  710. rc = reipl_set_type(ipl_info.type);
  711. if (rc)
  712. return rc;
  713. return 0;
  714. }
  715. static struct shutdown_action __refdata reipl_action = {
  716. .name = SHUTDOWN_ACTION_REIPL_STR,
  717. .fn = reipl_run,
  718. .init = reipl_init,
  719. };
  720. /*
  721. * dump shutdown action: Dump Linux on shutdown.
  722. */
  723. /* FCP dump device attributes */
  724. DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
  725. dump_block_fcp->ipl_info.fcp.wwpn);
  726. DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
  727. dump_block_fcp->ipl_info.fcp.lun);
  728. DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
  729. dump_block_fcp->ipl_info.fcp.bootprog);
  730. DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
  731. dump_block_fcp->ipl_info.fcp.br_lba);
  732. DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  733. dump_block_fcp->ipl_info.fcp.devno);
  734. static struct attribute *dump_fcp_attrs[] = {
  735. &sys_dump_fcp_device_attr.attr,
  736. &sys_dump_fcp_wwpn_attr.attr,
  737. &sys_dump_fcp_lun_attr.attr,
  738. &sys_dump_fcp_bootprog_attr.attr,
  739. &sys_dump_fcp_br_lba_attr.attr,
  740. NULL,
  741. };
  742. static struct attribute_group dump_fcp_attr_group = {
  743. .name = IPL_FCP_STR,
  744. .attrs = dump_fcp_attrs,
  745. };
  746. /* CCW dump device attributes */
  747. DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
  748. dump_block_ccw->ipl_info.ccw.devno);
  749. static struct attribute *dump_ccw_attrs[] = {
  750. &sys_dump_ccw_device_attr.attr,
  751. NULL,
  752. };
  753. static struct attribute_group dump_ccw_attr_group = {
  754. .name = IPL_CCW_STR,
  755. .attrs = dump_ccw_attrs,
  756. };
  757. /* dump type */
  758. static int dump_set_type(enum dump_type type)
  759. {
  760. if (!(dump_capabilities & type))
  761. return -EINVAL;
  762. switch (type) {
  763. case DUMP_TYPE_CCW:
  764. if (diag308_set_works)
  765. dump_method = DUMP_METHOD_CCW_DIAG;
  766. else if (MACHINE_IS_VM)
  767. dump_method = DUMP_METHOD_CCW_VM;
  768. else
  769. dump_method = DUMP_METHOD_CCW_CIO;
  770. break;
  771. case DUMP_TYPE_FCP:
  772. dump_method = DUMP_METHOD_FCP_DIAG;
  773. break;
  774. default:
  775. dump_method = DUMP_METHOD_NONE;
  776. }
  777. dump_type = type;
  778. return 0;
  779. }
  780. static ssize_t dump_type_show(struct kobject *kobj,
  781. struct kobj_attribute *attr, char *page)
  782. {
  783. return sprintf(page, "%s\n", dump_type_str(dump_type));
  784. }
  785. static ssize_t dump_type_store(struct kobject *kobj,
  786. struct kobj_attribute *attr,
  787. const char *buf, size_t len)
  788. {
  789. int rc = -EINVAL;
  790. if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
  791. rc = dump_set_type(DUMP_TYPE_NONE);
  792. else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
  793. rc = dump_set_type(DUMP_TYPE_CCW);
  794. else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
  795. rc = dump_set_type(DUMP_TYPE_FCP);
  796. return (rc != 0) ? rc : len;
  797. }
  798. static struct kobj_attribute dump_type_attr =
  799. __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
  800. static struct kset *dump_kset;
  801. static void dump_run(struct shutdown_trigger *trigger)
  802. {
  803. struct ccw_dev_id devid;
  804. static char buf[100];
  805. switch (dump_method) {
  806. case DUMP_METHOD_CCW_CIO:
  807. smp_send_stop();
  808. devid.devno = dump_block_ccw->ipl_info.ccw.devno;
  809. devid.ssid = 0;
  810. reipl_ccw_dev(&devid);
  811. break;
  812. case DUMP_METHOD_CCW_VM:
  813. smp_send_stop();
  814. sprintf(buf, "STORE STATUS");
  815. __cpcmd(buf, NULL, 0, NULL);
  816. sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
  817. __cpcmd(buf, NULL, 0, NULL);
  818. break;
  819. case DUMP_METHOD_CCW_DIAG:
  820. diag308(DIAG308_SET, dump_block_ccw);
  821. diag308(DIAG308_DUMP, NULL);
  822. break;
  823. case DUMP_METHOD_FCP_DIAG:
  824. diag308(DIAG308_SET, dump_block_fcp);
  825. diag308(DIAG308_DUMP, NULL);
  826. break;
  827. case DUMP_METHOD_NONE:
  828. default:
  829. return;
  830. }
  831. printk(KERN_EMERG "Dump failed!\n");
  832. }
  833. static int __init dump_ccw_init(void)
  834. {
  835. int rc;
  836. dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  837. if (!dump_block_ccw)
  838. return -ENOMEM;
  839. rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
  840. if (rc) {
  841. free_page((unsigned long)dump_block_ccw);
  842. return rc;
  843. }
  844. dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  845. dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  846. dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  847. dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  848. dump_capabilities |= DUMP_TYPE_CCW;
  849. return 0;
  850. }
  851. static int __init dump_fcp_init(void)
  852. {
  853. int rc;
  854. if (!sclp_ipl_info.has_dump)
  855. return 0; /* LDIPL DUMP is not installed */
  856. if (!diag308_set_works)
  857. return 0;
  858. dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  859. if (!dump_block_fcp)
  860. return -ENOMEM;
  861. rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
  862. if (rc) {
  863. free_page((unsigned long)dump_block_fcp);
  864. return rc;
  865. }
  866. dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  867. dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  868. dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  869. dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  870. dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
  871. dump_capabilities |= DUMP_TYPE_FCP;
  872. return 0;
  873. }
  874. static int __init dump_init(void)
  875. {
  876. int rc;
  877. dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
  878. if (!dump_kset)
  879. return -ENOMEM;
  880. rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
  881. if (rc) {
  882. kset_unregister(dump_kset);
  883. return rc;
  884. }
  885. rc = dump_ccw_init();
  886. if (rc)
  887. return rc;
  888. rc = dump_fcp_init();
  889. if (rc)
  890. return rc;
  891. dump_set_type(DUMP_TYPE_NONE);
  892. return 0;
  893. }
  894. static struct shutdown_action __refdata dump_action = {
  895. .name = SHUTDOWN_ACTION_DUMP_STR,
  896. .fn = dump_run,
  897. .init = dump_init,
  898. };
  899. /*
  900. * vmcmd shutdown action: Trigger vm command on shutdown.
  901. */
  902. static char vmcmd_on_reboot[128];
  903. static char vmcmd_on_panic[128];
  904. static char vmcmd_on_halt[128];
  905. static char vmcmd_on_poff[128];
  906. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
  907. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
  908. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
  909. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
  910. static struct attribute *vmcmd_attrs[] = {
  911. &sys_vmcmd_on_reboot_attr.attr,
  912. &sys_vmcmd_on_panic_attr.attr,
  913. &sys_vmcmd_on_halt_attr.attr,
  914. &sys_vmcmd_on_poff_attr.attr,
  915. NULL,
  916. };
  917. static struct attribute_group vmcmd_attr_group = {
  918. .attrs = vmcmd_attrs,
  919. };
  920. static struct kset *vmcmd_kset;
  921. static void vmcmd_run(struct shutdown_trigger *trigger)
  922. {
  923. char *cmd, *next_cmd;
  924. if (strcmp(trigger->name, ON_REIPL_STR) == 0)
  925. cmd = vmcmd_on_reboot;
  926. else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
  927. cmd = vmcmd_on_panic;
  928. else if (strcmp(trigger->name, ON_HALT_STR) == 0)
  929. cmd = vmcmd_on_halt;
  930. else if (strcmp(trigger->name, ON_POFF_STR) == 0)
  931. cmd = vmcmd_on_poff;
  932. else
  933. return;
  934. if (strlen(cmd) == 0)
  935. return;
  936. do {
  937. next_cmd = strchr(cmd, '\n');
  938. if (next_cmd) {
  939. next_cmd[0] = 0;
  940. next_cmd += 1;
  941. }
  942. __cpcmd(cmd, NULL, 0, NULL);
  943. cmd = next_cmd;
  944. } while (cmd != NULL);
  945. }
  946. static int vmcmd_init(void)
  947. {
  948. if (!MACHINE_IS_VM)
  949. return -ENOTSUPP;
  950. vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
  951. if (!vmcmd_kset)
  952. return -ENOMEM;
  953. return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
  954. }
  955. static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
  956. vmcmd_run, vmcmd_init};
  957. /*
  958. * stop shutdown action: Stop Linux on shutdown.
  959. */
  960. static void stop_run(struct shutdown_trigger *trigger)
  961. {
  962. if (strcmp(trigger->name, ON_PANIC_STR) == 0)
  963. disabled_wait((unsigned long) __builtin_return_address(0));
  964. else {
  965. signal_processor(smp_processor_id(), sigp_stop);
  966. for (;;);
  967. }
  968. }
  969. static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
  970. stop_run, NULL};
  971. /* action list */
  972. static struct shutdown_action *shutdown_actions_list[] = {
  973. &ipl_action, &reipl_action, &dump_action, &vmcmd_action, &stop_action};
  974. #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
  975. /*
  976. * Trigger section
  977. */
  978. static struct kset *shutdown_actions_kset;
  979. static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
  980. size_t len)
  981. {
  982. int i;
  983. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  984. if (!shutdown_actions_list[i])
  985. continue;
  986. if (strncmp(buf, shutdown_actions_list[i]->name,
  987. strlen(shutdown_actions_list[i]->name)) == 0) {
  988. trigger->action = shutdown_actions_list[i];
  989. return len;
  990. }
  991. }
  992. return -EINVAL;
  993. }
  994. /* on reipl */
  995. static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
  996. &reipl_action};
  997. static ssize_t on_reboot_show(struct kobject *kobj,
  998. struct kobj_attribute *attr, char *page)
  999. {
  1000. return sprintf(page, "%s\n", on_reboot_trigger.action->name);
  1001. }
  1002. static ssize_t on_reboot_store(struct kobject *kobj,
  1003. struct kobj_attribute *attr,
  1004. const char *buf, size_t len)
  1005. {
  1006. return set_trigger(buf, &on_reboot_trigger, len);
  1007. }
  1008. static struct kobj_attribute on_reboot_attr =
  1009. __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
  1010. static void do_machine_restart(char *__unused)
  1011. {
  1012. smp_send_stop();
  1013. on_reboot_trigger.action->fn(&on_reboot_trigger);
  1014. reipl_run(NULL);
  1015. }
  1016. void (*_machine_restart)(char *command) = do_machine_restart;
  1017. /* on panic */
  1018. static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
  1019. static ssize_t on_panic_show(struct kobject *kobj,
  1020. struct kobj_attribute *attr, char *page)
  1021. {
  1022. return sprintf(page, "%s\n", on_panic_trigger.action->name);
  1023. }
  1024. static ssize_t on_panic_store(struct kobject *kobj,
  1025. struct kobj_attribute *attr,
  1026. const char *buf, size_t len)
  1027. {
  1028. return set_trigger(buf, &on_panic_trigger, len);
  1029. }
  1030. static struct kobj_attribute on_panic_attr =
  1031. __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
  1032. static void do_panic(void)
  1033. {
  1034. on_panic_trigger.action->fn(&on_panic_trigger);
  1035. stop_run(&on_panic_trigger);
  1036. }
  1037. /* on halt */
  1038. static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
  1039. static ssize_t on_halt_show(struct kobject *kobj,
  1040. struct kobj_attribute *attr, char *page)
  1041. {
  1042. return sprintf(page, "%s\n", on_halt_trigger.action->name);
  1043. }
  1044. static ssize_t on_halt_store(struct kobject *kobj,
  1045. struct kobj_attribute *attr,
  1046. const char *buf, size_t len)
  1047. {
  1048. return set_trigger(buf, &on_halt_trigger, len);
  1049. }
  1050. static struct kobj_attribute on_halt_attr =
  1051. __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
  1052. static void do_machine_halt(void)
  1053. {
  1054. smp_send_stop();
  1055. on_halt_trigger.action->fn(&on_halt_trigger);
  1056. stop_run(&on_halt_trigger);
  1057. }
  1058. void (*_machine_halt)(void) = do_machine_halt;
  1059. /* on power off */
  1060. static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
  1061. static ssize_t on_poff_show(struct kobject *kobj,
  1062. struct kobj_attribute *attr, char *page)
  1063. {
  1064. return sprintf(page, "%s\n", on_poff_trigger.action->name);
  1065. }
  1066. static ssize_t on_poff_store(struct kobject *kobj,
  1067. struct kobj_attribute *attr,
  1068. const char *buf, size_t len)
  1069. {
  1070. return set_trigger(buf, &on_poff_trigger, len);
  1071. }
  1072. static struct kobj_attribute on_poff_attr =
  1073. __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
  1074. static void do_machine_power_off(void)
  1075. {
  1076. smp_send_stop();
  1077. on_poff_trigger.action->fn(&on_poff_trigger);
  1078. stop_run(&on_poff_trigger);
  1079. }
  1080. void (*_machine_power_off)(void) = do_machine_power_off;
  1081. static void __init shutdown_triggers_init(void)
  1082. {
  1083. shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
  1084. firmware_kobj);
  1085. if (!shutdown_actions_kset)
  1086. goto fail;
  1087. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1088. &on_reboot_attr.attr))
  1089. goto fail;
  1090. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1091. &on_panic_attr.attr))
  1092. goto fail;
  1093. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1094. &on_halt_attr.attr))
  1095. goto fail;
  1096. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1097. &on_poff_attr.attr))
  1098. goto fail;
  1099. return;
  1100. fail:
  1101. panic("shutdown_triggers_init failed\n");
  1102. }
  1103. static void __init shutdown_actions_init(void)
  1104. {
  1105. int i;
  1106. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  1107. if (!shutdown_actions_list[i]->init)
  1108. continue;
  1109. if (shutdown_actions_list[i]->init())
  1110. shutdown_actions_list[i] = NULL;
  1111. }
  1112. }
  1113. static int __init s390_ipl_init(void)
  1114. {
  1115. reipl_probe();
  1116. sclp_get_ipl_info(&sclp_ipl_info);
  1117. shutdown_actions_init();
  1118. shutdown_triggers_init();
  1119. return 0;
  1120. }
  1121. __initcall(s390_ipl_init);
  1122. static void __init strncpy_skip_quote(char *dst, char *src, int n)
  1123. {
  1124. int sx, dx;
  1125. dx = 0;
  1126. for (sx = 0; src[sx] != 0; sx++) {
  1127. if (src[sx] == '"')
  1128. continue;
  1129. dst[dx++] = src[sx];
  1130. if (dx >= n)
  1131. break;
  1132. }
  1133. }
  1134. static int __init vmcmd_on_reboot_setup(char *str)
  1135. {
  1136. if (!MACHINE_IS_VM)
  1137. return 1;
  1138. strncpy_skip_quote(vmcmd_on_reboot, str, 127);
  1139. vmcmd_on_reboot[127] = 0;
  1140. on_reboot_trigger.action = &vmcmd_action;
  1141. return 1;
  1142. }
  1143. __setup("vmreboot=", vmcmd_on_reboot_setup);
  1144. static int __init vmcmd_on_panic_setup(char *str)
  1145. {
  1146. if (!MACHINE_IS_VM)
  1147. return 1;
  1148. strncpy_skip_quote(vmcmd_on_panic, str, 127);
  1149. vmcmd_on_panic[127] = 0;
  1150. on_panic_trigger.action = &vmcmd_action;
  1151. return 1;
  1152. }
  1153. __setup("vmpanic=", vmcmd_on_panic_setup);
  1154. static int __init vmcmd_on_halt_setup(char *str)
  1155. {
  1156. if (!MACHINE_IS_VM)
  1157. return 1;
  1158. strncpy_skip_quote(vmcmd_on_halt, str, 127);
  1159. vmcmd_on_halt[127] = 0;
  1160. on_halt_trigger.action = &vmcmd_action;
  1161. return 1;
  1162. }
  1163. __setup("vmhalt=", vmcmd_on_halt_setup);
  1164. static int __init vmcmd_on_poff_setup(char *str)
  1165. {
  1166. if (!MACHINE_IS_VM)
  1167. return 1;
  1168. strncpy_skip_quote(vmcmd_on_poff, str, 127);
  1169. vmcmd_on_poff[127] = 0;
  1170. on_poff_trigger.action = &vmcmd_action;
  1171. return 1;
  1172. }
  1173. __setup("vmpoff=", vmcmd_on_poff_setup);
  1174. static int on_panic_notify(struct notifier_block *self,
  1175. unsigned long event, void *data)
  1176. {
  1177. do_panic();
  1178. return NOTIFY_OK;
  1179. }
  1180. static struct notifier_block on_panic_nb = {
  1181. .notifier_call = on_panic_notify,
  1182. .priority = 0,
  1183. };
  1184. void __init setup_ipl(void)
  1185. {
  1186. ipl_info.type = get_ipl_type();
  1187. switch (ipl_info.type) {
  1188. case IPL_TYPE_CCW:
  1189. ipl_info.data.ccw.dev_id.devno = ipl_devno;
  1190. ipl_info.data.ccw.dev_id.ssid = 0;
  1191. break;
  1192. case IPL_TYPE_FCP:
  1193. case IPL_TYPE_FCP_DUMP:
  1194. ipl_info.data.fcp.dev_id.devno =
  1195. IPL_PARMBLOCK_START->ipl_info.fcp.devno;
  1196. ipl_info.data.fcp.dev_id.ssid = 0;
  1197. ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
  1198. ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
  1199. break;
  1200. case IPL_TYPE_NSS:
  1201. strncpy(ipl_info.data.nss.name, kernel_nss_name,
  1202. sizeof(ipl_info.data.nss.name));
  1203. break;
  1204. case IPL_TYPE_UNKNOWN:
  1205. default:
  1206. /* We have no info to copy */
  1207. break;
  1208. }
  1209. atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
  1210. }
  1211. void __init ipl_save_parameters(void)
  1212. {
  1213. struct cio_iplinfo iplinfo;
  1214. unsigned int *ipl_ptr;
  1215. void *src, *dst;
  1216. if (cio_get_iplinfo(&iplinfo))
  1217. return;
  1218. ipl_devno = iplinfo.devno;
  1219. ipl_flags |= IPL_DEVNO_VALID;
  1220. if (!iplinfo.is_qdio)
  1221. return;
  1222. ipl_flags |= IPL_PARMBLOCK_VALID;
  1223. ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
  1224. src = (void *)(unsigned long)*ipl_ptr;
  1225. dst = (void *)IPL_PARMBLOCK_ORIGIN;
  1226. memmove(dst, src, PAGE_SIZE);
  1227. *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
  1228. }
  1229. static LIST_HEAD(rcall);
  1230. static DEFINE_MUTEX(rcall_mutex);
  1231. void register_reset_call(struct reset_call *reset)
  1232. {
  1233. mutex_lock(&rcall_mutex);
  1234. list_add(&reset->list, &rcall);
  1235. mutex_unlock(&rcall_mutex);
  1236. }
  1237. EXPORT_SYMBOL_GPL(register_reset_call);
  1238. void unregister_reset_call(struct reset_call *reset)
  1239. {
  1240. mutex_lock(&rcall_mutex);
  1241. list_del(&reset->list);
  1242. mutex_unlock(&rcall_mutex);
  1243. }
  1244. EXPORT_SYMBOL_GPL(unregister_reset_call);
  1245. static void do_reset_calls(void)
  1246. {
  1247. struct reset_call *reset;
  1248. list_for_each_entry(reset, &rcall, list)
  1249. reset->fn();
  1250. }
  1251. u32 dump_prefix_page;
  1252. void s390_reset_system(void)
  1253. {
  1254. struct _lowcore *lc;
  1255. lc = (struct _lowcore *)(unsigned long) store_prefix();
  1256. /* Stack for interrupt/machine check handler */
  1257. lc->panic_stack = S390_lowcore.panic_stack;
  1258. /* Save prefix page address for dump case */
  1259. dump_prefix_page = (u32)(unsigned long) lc;
  1260. /* Disable prefixing */
  1261. set_prefix(0);
  1262. /* Disable lowcore protection */
  1263. __ctl_clear_bit(0,28);
  1264. /* Set new machine check handler */
  1265. S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
  1266. S390_lowcore.mcck_new_psw.addr =
  1267. PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
  1268. /* Set new program check handler */
  1269. S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
  1270. S390_lowcore.program_new_psw.addr =
  1271. PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
  1272. do_reset_calls();
  1273. }