ipl.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475
  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 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 ipl_action = {SHUTDOWN_ACTION_IPL_STR, ipl_run,
  406. ipl_init};
  407. /*
  408. * reipl shutdown action: Reboot Linux on shutdown.
  409. */
  410. /* FCP reipl device attributes */
  411. DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
  412. reipl_block_fcp->ipl_info.fcp.wwpn);
  413. DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
  414. reipl_block_fcp->ipl_info.fcp.lun);
  415. DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
  416. reipl_block_fcp->ipl_info.fcp.bootprog);
  417. DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
  418. reipl_block_fcp->ipl_info.fcp.br_lba);
  419. DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  420. reipl_block_fcp->ipl_info.fcp.devno);
  421. static struct attribute *reipl_fcp_attrs[] = {
  422. &sys_reipl_fcp_device_attr.attr,
  423. &sys_reipl_fcp_wwpn_attr.attr,
  424. &sys_reipl_fcp_lun_attr.attr,
  425. &sys_reipl_fcp_bootprog_attr.attr,
  426. &sys_reipl_fcp_br_lba_attr.attr,
  427. NULL,
  428. };
  429. static struct attribute_group reipl_fcp_attr_group = {
  430. .name = IPL_FCP_STR,
  431. .attrs = reipl_fcp_attrs,
  432. };
  433. /* CCW reipl device attributes */
  434. DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
  435. reipl_block_ccw->ipl_info.ccw.devno);
  436. static void reipl_get_ascii_loadparm(char *loadparm)
  437. {
  438. memcpy(loadparm, &reipl_block_ccw->ipl_info.ccw.load_param,
  439. LOADPARM_LEN);
  440. EBCASC(loadparm, LOADPARM_LEN);
  441. loadparm[LOADPARM_LEN] = 0;
  442. strstrip(loadparm);
  443. }
  444. static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
  445. struct kobj_attribute *attr, char *page)
  446. {
  447. char buf[LOADPARM_LEN + 1];
  448. reipl_get_ascii_loadparm(buf);
  449. return sprintf(page, "%s\n", buf);
  450. }
  451. static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
  452. struct kobj_attribute *attr,
  453. const char *buf, size_t len)
  454. {
  455. int i, lp_len;
  456. /* ignore trailing newline */
  457. lp_len = len;
  458. if ((len > 0) && (buf[len - 1] == '\n'))
  459. lp_len--;
  460. /* loadparm can have max 8 characters and must not start with a blank */
  461. if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
  462. return -EINVAL;
  463. /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
  464. for (i = 0; i < lp_len; i++) {
  465. if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
  466. (buf[i] == '.'))
  467. continue;
  468. return -EINVAL;
  469. }
  470. /* initialize loadparm with blanks */
  471. memset(&reipl_block_ccw->ipl_info.ccw.load_param, ' ', LOADPARM_LEN);
  472. /* copy and convert to ebcdic */
  473. memcpy(&reipl_block_ccw->ipl_info.ccw.load_param, buf, lp_len);
  474. ASCEBC(reipl_block_ccw->ipl_info.ccw.load_param, LOADPARM_LEN);
  475. return len;
  476. }
  477. static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
  478. __ATTR(loadparm, 0644, reipl_ccw_loadparm_show,
  479. reipl_ccw_loadparm_store);
  480. static struct attribute *reipl_ccw_attrs[] = {
  481. &sys_reipl_ccw_device_attr.attr,
  482. &sys_reipl_ccw_loadparm_attr.attr,
  483. NULL,
  484. };
  485. static struct attribute_group reipl_ccw_attr_group = {
  486. .name = IPL_CCW_STR,
  487. .attrs = reipl_ccw_attrs,
  488. };
  489. /* NSS reipl device attributes */
  490. DEFINE_IPL_ATTR_STR_RW(reipl_nss, name, "%s\n", "%s\n", reipl_nss_name);
  491. static struct attribute *reipl_nss_attrs[] = {
  492. &sys_reipl_nss_name_attr.attr,
  493. NULL,
  494. };
  495. static struct attribute_group reipl_nss_attr_group = {
  496. .name = IPL_NSS_STR,
  497. .attrs = reipl_nss_attrs,
  498. };
  499. /* reipl type */
  500. static int reipl_set_type(enum ipl_type type)
  501. {
  502. if (!(reipl_capabilities & type))
  503. return -EINVAL;
  504. switch(type) {
  505. case IPL_TYPE_CCW:
  506. if (MACHINE_IS_VM)
  507. reipl_method = REIPL_METHOD_CCW_VM;
  508. else
  509. reipl_method = REIPL_METHOD_CCW_CIO;
  510. break;
  511. case IPL_TYPE_FCP:
  512. if (diag308_set_works)
  513. reipl_method = REIPL_METHOD_FCP_RW_DIAG;
  514. else if (MACHINE_IS_VM)
  515. reipl_method = REIPL_METHOD_FCP_RO_VM;
  516. else
  517. reipl_method = REIPL_METHOD_FCP_RO_DIAG;
  518. break;
  519. case IPL_TYPE_FCP_DUMP:
  520. reipl_method = REIPL_METHOD_FCP_DUMP;
  521. break;
  522. case IPL_TYPE_NSS:
  523. reipl_method = REIPL_METHOD_NSS;
  524. break;
  525. case IPL_TYPE_UNKNOWN:
  526. reipl_method = REIPL_METHOD_DEFAULT;
  527. break;
  528. default:
  529. BUG();
  530. }
  531. reipl_type = type;
  532. return 0;
  533. }
  534. static ssize_t reipl_type_show(struct kobject *kobj,
  535. struct kobj_attribute *attr, char *page)
  536. {
  537. return sprintf(page, "%s\n", ipl_type_str(reipl_type));
  538. }
  539. static ssize_t reipl_type_store(struct kobject *kobj,
  540. struct kobj_attribute *attr,
  541. const char *buf, size_t len)
  542. {
  543. int rc = -EINVAL;
  544. if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
  545. rc = reipl_set_type(IPL_TYPE_CCW);
  546. else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
  547. rc = reipl_set_type(IPL_TYPE_FCP);
  548. else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
  549. rc = reipl_set_type(IPL_TYPE_NSS);
  550. return (rc != 0) ? rc : len;
  551. }
  552. static struct kobj_attribute reipl_type_attr =
  553. __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
  554. static struct kset *reipl_kset;
  555. void reipl_run(struct shutdown_trigger *trigger)
  556. {
  557. struct ccw_dev_id devid;
  558. static char buf[100];
  559. char loadparm[LOADPARM_LEN + 1];
  560. switch (reipl_method) {
  561. case REIPL_METHOD_CCW_CIO:
  562. devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
  563. if (ipl_info.type == IPL_TYPE_CCW && devid.devno == ipl_devno)
  564. diag308(DIAG308_IPL, NULL);
  565. devid.ssid = 0;
  566. reipl_ccw_dev(&devid);
  567. break;
  568. case REIPL_METHOD_CCW_VM:
  569. reipl_get_ascii_loadparm(loadparm);
  570. if (strlen(loadparm) == 0)
  571. sprintf(buf, "IPL %X CLEAR",
  572. reipl_block_ccw->ipl_info.ccw.devno);
  573. else
  574. sprintf(buf, "IPL %X CLEAR LOADPARM '%s'",
  575. reipl_block_ccw->ipl_info.ccw.devno, loadparm);
  576. __cpcmd(buf, NULL, 0, NULL);
  577. break;
  578. case REIPL_METHOD_CCW_DIAG:
  579. diag308(DIAG308_SET, reipl_block_ccw);
  580. diag308(DIAG308_IPL, NULL);
  581. break;
  582. case REIPL_METHOD_FCP_RW_DIAG:
  583. diag308(DIAG308_SET, reipl_block_fcp);
  584. diag308(DIAG308_IPL, NULL);
  585. break;
  586. case REIPL_METHOD_FCP_RO_DIAG:
  587. diag308(DIAG308_IPL, NULL);
  588. break;
  589. case REIPL_METHOD_FCP_RO_VM:
  590. __cpcmd("IPL", NULL, 0, NULL);
  591. break;
  592. case REIPL_METHOD_NSS:
  593. sprintf(buf, "IPL %s", reipl_nss_name);
  594. __cpcmd(buf, NULL, 0, NULL);
  595. break;
  596. case REIPL_METHOD_DEFAULT:
  597. if (MACHINE_IS_VM)
  598. __cpcmd("IPL", NULL, 0, NULL);
  599. diag308(DIAG308_IPL, NULL);
  600. break;
  601. case REIPL_METHOD_FCP_DUMP:
  602. default:
  603. break;
  604. }
  605. }
  606. static void __init reipl_probe(void)
  607. {
  608. void *buffer;
  609. buffer = (void *) get_zeroed_page(GFP_KERNEL);
  610. if (!buffer)
  611. return;
  612. if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK)
  613. diag308_set_works = 1;
  614. free_page((unsigned long)buffer);
  615. }
  616. static int __init reipl_nss_init(void)
  617. {
  618. int rc;
  619. if (!MACHINE_IS_VM)
  620. return 0;
  621. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
  622. if (rc)
  623. return rc;
  624. strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
  625. reipl_capabilities |= IPL_TYPE_NSS;
  626. return 0;
  627. }
  628. static int __init reipl_ccw_init(void)
  629. {
  630. int rc;
  631. reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  632. if (!reipl_block_ccw)
  633. return -ENOMEM;
  634. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_ccw_attr_group);
  635. if (rc) {
  636. free_page((unsigned long)reipl_block_ccw);
  637. return rc;
  638. }
  639. reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  640. reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  641. reipl_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  642. reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  643. /* check if read scp info worked and set loadparm */
  644. if (sclp_ipl_info.is_valid)
  645. memcpy(reipl_block_ccw->ipl_info.ccw.load_param,
  646. &sclp_ipl_info.loadparm, LOADPARM_LEN);
  647. else
  648. /* read scp info failed: set empty loadparm (EBCDIC blanks) */
  649. memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40,
  650. LOADPARM_LEN);
  651. /* FIXME: check for diag308_set_works when enabling diag ccw reipl */
  652. if (!MACHINE_IS_VM)
  653. sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
  654. if (ipl_info.type == IPL_TYPE_CCW)
  655. reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
  656. reipl_capabilities |= IPL_TYPE_CCW;
  657. return 0;
  658. }
  659. static int __init reipl_fcp_init(void)
  660. {
  661. int rc;
  662. if ((!diag308_set_works) && (ipl_info.type != IPL_TYPE_FCP))
  663. return 0;
  664. if ((!diag308_set_works) && (ipl_info.type == IPL_TYPE_FCP))
  665. make_attrs_ro(reipl_fcp_attrs);
  666. reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  667. if (!reipl_block_fcp)
  668. return -ENOMEM;
  669. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
  670. if (rc) {
  671. free_page((unsigned long)reipl_block_fcp);
  672. return rc;
  673. }
  674. if (ipl_info.type == IPL_TYPE_FCP) {
  675. memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
  676. } else {
  677. reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  678. reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  679. reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  680. reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  681. reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
  682. }
  683. reipl_capabilities |= IPL_TYPE_FCP;
  684. return 0;
  685. }
  686. static int reipl_init(void)
  687. {
  688. int rc;
  689. reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
  690. if (!reipl_kset)
  691. return -ENOMEM;
  692. rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
  693. if (rc) {
  694. kset_unregister(reipl_kset);
  695. return rc;
  696. }
  697. rc = reipl_ccw_init();
  698. if (rc)
  699. return rc;
  700. rc = reipl_fcp_init();
  701. if (rc)
  702. return rc;
  703. rc = reipl_nss_init();
  704. if (rc)
  705. return rc;
  706. rc = reipl_set_type(ipl_info.type);
  707. if (rc)
  708. return rc;
  709. return 0;
  710. }
  711. static struct shutdown_action reipl_action = {SHUTDOWN_ACTION_REIPL_STR,
  712. reipl_run, reipl_init};
  713. /*
  714. * dump shutdown action: Dump Linux on shutdown.
  715. */
  716. /* FCP dump device attributes */
  717. DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
  718. dump_block_fcp->ipl_info.fcp.wwpn);
  719. DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
  720. dump_block_fcp->ipl_info.fcp.lun);
  721. DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
  722. dump_block_fcp->ipl_info.fcp.bootprog);
  723. DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
  724. dump_block_fcp->ipl_info.fcp.br_lba);
  725. DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  726. dump_block_fcp->ipl_info.fcp.devno);
  727. static struct attribute *dump_fcp_attrs[] = {
  728. &sys_dump_fcp_device_attr.attr,
  729. &sys_dump_fcp_wwpn_attr.attr,
  730. &sys_dump_fcp_lun_attr.attr,
  731. &sys_dump_fcp_bootprog_attr.attr,
  732. &sys_dump_fcp_br_lba_attr.attr,
  733. NULL,
  734. };
  735. static struct attribute_group dump_fcp_attr_group = {
  736. .name = IPL_FCP_STR,
  737. .attrs = dump_fcp_attrs,
  738. };
  739. /* CCW dump device attributes */
  740. DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
  741. dump_block_ccw->ipl_info.ccw.devno);
  742. static struct attribute *dump_ccw_attrs[] = {
  743. &sys_dump_ccw_device_attr.attr,
  744. NULL,
  745. };
  746. static struct attribute_group dump_ccw_attr_group = {
  747. .name = IPL_CCW_STR,
  748. .attrs = dump_ccw_attrs,
  749. };
  750. /* dump type */
  751. static int dump_set_type(enum dump_type type)
  752. {
  753. if (!(dump_capabilities & type))
  754. return -EINVAL;
  755. switch (type) {
  756. case DUMP_TYPE_CCW:
  757. if (MACHINE_IS_VM)
  758. dump_method = DUMP_METHOD_CCW_VM;
  759. else
  760. dump_method = DUMP_METHOD_CCW_CIO;
  761. break;
  762. case DUMP_TYPE_FCP:
  763. dump_method = DUMP_METHOD_FCP_DIAG;
  764. break;
  765. default:
  766. dump_method = DUMP_METHOD_NONE;
  767. }
  768. dump_type = type;
  769. return 0;
  770. }
  771. static ssize_t dump_type_show(struct kobject *kobj,
  772. struct kobj_attribute *attr, char *page)
  773. {
  774. return sprintf(page, "%s\n", dump_type_str(dump_type));
  775. }
  776. static ssize_t dump_type_store(struct kobject *kobj,
  777. struct kobj_attribute *attr,
  778. const char *buf, size_t len)
  779. {
  780. int rc = -EINVAL;
  781. if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
  782. rc = dump_set_type(DUMP_TYPE_NONE);
  783. else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
  784. rc = dump_set_type(DUMP_TYPE_CCW);
  785. else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
  786. rc = dump_set_type(DUMP_TYPE_FCP);
  787. return (rc != 0) ? rc : len;
  788. }
  789. static struct kobj_attribute dump_type_attr =
  790. __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
  791. static struct kset *dump_kset;
  792. static void dump_run(struct shutdown_trigger *trigger)
  793. {
  794. struct ccw_dev_id devid;
  795. static char buf[100];
  796. switch (dump_method) {
  797. case DUMP_METHOD_CCW_CIO:
  798. smp_send_stop();
  799. devid.devno = dump_block_ccw->ipl_info.ccw.devno;
  800. devid.ssid = 0;
  801. reipl_ccw_dev(&devid);
  802. break;
  803. case DUMP_METHOD_CCW_VM:
  804. smp_send_stop();
  805. sprintf(buf, "STORE STATUS");
  806. __cpcmd(buf, NULL, 0, NULL);
  807. sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
  808. __cpcmd(buf, NULL, 0, NULL);
  809. break;
  810. case DUMP_METHOD_CCW_DIAG:
  811. diag308(DIAG308_SET, dump_block_ccw);
  812. diag308(DIAG308_DUMP, NULL);
  813. break;
  814. case DUMP_METHOD_FCP_DIAG:
  815. diag308(DIAG308_SET, dump_block_fcp);
  816. diag308(DIAG308_DUMP, NULL);
  817. break;
  818. case DUMP_METHOD_NONE:
  819. default:
  820. return;
  821. }
  822. printk(KERN_EMERG "Dump failed!\n");
  823. }
  824. static int __init dump_ccw_init(void)
  825. {
  826. int rc;
  827. dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  828. if (!dump_block_ccw)
  829. return -ENOMEM;
  830. rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
  831. if (rc) {
  832. free_page((unsigned long)dump_block_ccw);
  833. return rc;
  834. }
  835. dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  836. dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  837. dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  838. dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  839. dump_capabilities |= DUMP_TYPE_CCW;
  840. return 0;
  841. }
  842. static int __init dump_fcp_init(void)
  843. {
  844. int rc;
  845. if (!sclp_ipl_info.has_dump)
  846. return 0; /* LDIPL DUMP is not installed */
  847. if (!diag308_set_works)
  848. return 0;
  849. dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  850. if (!dump_block_fcp)
  851. return -ENOMEM;
  852. rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
  853. if (rc) {
  854. free_page((unsigned long)dump_block_fcp);
  855. return rc;
  856. }
  857. dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  858. dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  859. dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  860. dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  861. dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
  862. dump_capabilities |= DUMP_TYPE_FCP;
  863. return 0;
  864. }
  865. static int dump_init(void)
  866. {
  867. int rc;
  868. dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
  869. if (!dump_kset)
  870. return -ENOMEM;
  871. rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
  872. if (rc) {
  873. kset_unregister(dump_kset);
  874. return rc;
  875. }
  876. rc = dump_ccw_init();
  877. if (rc)
  878. return rc;
  879. rc = dump_fcp_init();
  880. if (rc)
  881. return rc;
  882. dump_set_type(DUMP_TYPE_NONE);
  883. return 0;
  884. }
  885. static struct shutdown_action dump_action = {SHUTDOWN_ACTION_DUMP_STR,
  886. dump_run, dump_init};
  887. /*
  888. * vmcmd shutdown action: Trigger vm command on shutdown.
  889. */
  890. static char vmcmd_on_reboot[128];
  891. static char vmcmd_on_panic[128];
  892. static char vmcmd_on_halt[128];
  893. static char vmcmd_on_poff[128];
  894. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
  895. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
  896. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
  897. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
  898. static struct attribute *vmcmd_attrs[] = {
  899. &sys_vmcmd_on_reboot_attr.attr,
  900. &sys_vmcmd_on_panic_attr.attr,
  901. &sys_vmcmd_on_halt_attr.attr,
  902. &sys_vmcmd_on_poff_attr.attr,
  903. NULL,
  904. };
  905. static struct attribute_group vmcmd_attr_group = {
  906. .attrs = vmcmd_attrs,
  907. };
  908. static struct kset *vmcmd_kset;
  909. static void vmcmd_run(struct shutdown_trigger *trigger)
  910. {
  911. char *cmd, *next_cmd;
  912. if (strcmp(trigger->name, ON_REIPL_STR) == 0)
  913. cmd = vmcmd_on_reboot;
  914. else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
  915. cmd = vmcmd_on_panic;
  916. else if (strcmp(trigger->name, ON_HALT_STR) == 0)
  917. cmd = vmcmd_on_halt;
  918. else if (strcmp(trigger->name, ON_POFF_STR) == 0)
  919. cmd = vmcmd_on_poff;
  920. else
  921. return;
  922. if (strlen(cmd) == 0)
  923. return;
  924. do {
  925. next_cmd = strchr(cmd, '\n');
  926. if (next_cmd) {
  927. next_cmd[0] = 0;
  928. next_cmd += 1;
  929. }
  930. __cpcmd(cmd, NULL, 0, NULL);
  931. cmd = next_cmd;
  932. } while (cmd != NULL);
  933. }
  934. static int vmcmd_init(void)
  935. {
  936. if (!MACHINE_IS_VM)
  937. return -ENOTSUPP;
  938. vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
  939. if (!vmcmd_kset)
  940. return -ENOMEM;
  941. return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
  942. }
  943. static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
  944. vmcmd_run, vmcmd_init};
  945. /*
  946. * stop shutdown action: Stop Linux on shutdown.
  947. */
  948. static void stop_run(struct shutdown_trigger *trigger)
  949. {
  950. if (strcmp(trigger->name, ON_PANIC_STR) == 0)
  951. disabled_wait((unsigned long) __builtin_return_address(0));
  952. else {
  953. signal_processor(smp_processor_id(), sigp_stop);
  954. for (;;);
  955. }
  956. }
  957. static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
  958. stop_run, NULL};
  959. /* action list */
  960. static struct shutdown_action *shutdown_actions_list[] = {
  961. &ipl_action, &reipl_action, &dump_action, &vmcmd_action, &stop_action};
  962. #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
  963. /*
  964. * Trigger section
  965. */
  966. static struct kset *shutdown_actions_kset;
  967. static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
  968. size_t len)
  969. {
  970. int i;
  971. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  972. if (!shutdown_actions_list[i])
  973. continue;
  974. if (strncmp(buf, shutdown_actions_list[i]->name,
  975. strlen(shutdown_actions_list[i]->name)) == 0) {
  976. trigger->action = shutdown_actions_list[i];
  977. return len;
  978. }
  979. }
  980. return -EINVAL;
  981. }
  982. /* on reipl */
  983. static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
  984. &reipl_action};
  985. static ssize_t on_reboot_show(struct kobject *kobj,
  986. struct kobj_attribute *attr, char *page)
  987. {
  988. return sprintf(page, "%s\n", on_reboot_trigger.action->name);
  989. }
  990. static ssize_t on_reboot_store(struct kobject *kobj,
  991. struct kobj_attribute *attr,
  992. const char *buf, size_t len)
  993. {
  994. return set_trigger(buf, &on_reboot_trigger, len);
  995. }
  996. static struct kobj_attribute on_reboot_attr =
  997. __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
  998. static void do_machine_restart(char *__unused)
  999. {
  1000. smp_send_stop();
  1001. on_reboot_trigger.action->fn(&on_reboot_trigger);
  1002. reipl_run(NULL);
  1003. }
  1004. void (*_machine_restart)(char *command) = do_machine_restart;
  1005. /* on panic */
  1006. static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
  1007. static ssize_t on_panic_show(struct kobject *kobj,
  1008. struct kobj_attribute *attr, char *page)
  1009. {
  1010. return sprintf(page, "%s\n", on_panic_trigger.action->name);
  1011. }
  1012. static ssize_t on_panic_store(struct kobject *kobj,
  1013. struct kobj_attribute *attr,
  1014. const char *buf, size_t len)
  1015. {
  1016. return set_trigger(buf, &on_panic_trigger, len);
  1017. }
  1018. static struct kobj_attribute on_panic_attr =
  1019. __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
  1020. static void do_panic(void)
  1021. {
  1022. on_panic_trigger.action->fn(&on_panic_trigger);
  1023. stop_run(&on_panic_trigger);
  1024. }
  1025. /* on halt */
  1026. static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
  1027. static ssize_t on_halt_show(struct kobject *kobj,
  1028. struct kobj_attribute *attr, char *page)
  1029. {
  1030. return sprintf(page, "%s\n", on_halt_trigger.action->name);
  1031. }
  1032. static ssize_t on_halt_store(struct kobject *kobj,
  1033. struct kobj_attribute *attr,
  1034. const char *buf, size_t len)
  1035. {
  1036. return set_trigger(buf, &on_halt_trigger, len);
  1037. }
  1038. static struct kobj_attribute on_halt_attr =
  1039. __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
  1040. static void do_machine_halt(void)
  1041. {
  1042. smp_send_stop();
  1043. on_halt_trigger.action->fn(&on_halt_trigger);
  1044. stop_run(&on_halt_trigger);
  1045. }
  1046. void (*_machine_halt)(void) = do_machine_halt;
  1047. /* on power off */
  1048. static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
  1049. static ssize_t on_poff_show(struct kobject *kobj,
  1050. struct kobj_attribute *attr, char *page)
  1051. {
  1052. return sprintf(page, "%s\n", on_poff_trigger.action->name);
  1053. }
  1054. static ssize_t on_poff_store(struct kobject *kobj,
  1055. struct kobj_attribute *attr,
  1056. const char *buf, size_t len)
  1057. {
  1058. return set_trigger(buf, &on_poff_trigger, len);
  1059. }
  1060. static struct kobj_attribute on_poff_attr =
  1061. __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
  1062. static void do_machine_power_off(void)
  1063. {
  1064. smp_send_stop();
  1065. on_poff_trigger.action->fn(&on_poff_trigger);
  1066. stop_run(&on_poff_trigger);
  1067. }
  1068. void (*_machine_power_off)(void) = do_machine_power_off;
  1069. static void __init shutdown_triggers_init(void)
  1070. {
  1071. shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
  1072. firmware_kobj);
  1073. if (!shutdown_actions_kset)
  1074. goto fail;
  1075. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1076. &on_reboot_attr.attr))
  1077. goto fail;
  1078. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1079. &on_panic_attr.attr))
  1080. goto fail;
  1081. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1082. &on_halt_attr.attr))
  1083. goto fail;
  1084. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1085. &on_poff_attr.attr))
  1086. goto fail;
  1087. return;
  1088. fail:
  1089. panic("shutdown_triggers_init failed\n");
  1090. }
  1091. static void __init shutdown_actions_init(void)
  1092. {
  1093. int i;
  1094. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  1095. if (!shutdown_actions_list[i]->init)
  1096. continue;
  1097. if (shutdown_actions_list[i]->init())
  1098. shutdown_actions_list[i] = NULL;
  1099. }
  1100. }
  1101. static int __init s390_ipl_init(void)
  1102. {
  1103. reipl_probe();
  1104. shutdown_actions_init();
  1105. shutdown_triggers_init();
  1106. return 0;
  1107. }
  1108. __initcall(s390_ipl_init);
  1109. static void __init strncpy_skip_quote(char *dst, char *src, int n)
  1110. {
  1111. int sx, dx;
  1112. dx = 0;
  1113. for (sx = 0; src[sx] != 0; sx++) {
  1114. if (src[sx] == '"')
  1115. continue;
  1116. dst[dx++] = src[sx];
  1117. if (dx >= n)
  1118. break;
  1119. }
  1120. }
  1121. static int __init vmcmd_on_reboot_setup(char *str)
  1122. {
  1123. if (!MACHINE_IS_VM)
  1124. return 1;
  1125. strncpy_skip_quote(vmcmd_on_reboot, str, 127);
  1126. vmcmd_on_reboot[127] = 0;
  1127. on_reboot_trigger.action = &vmcmd_action;
  1128. return 1;
  1129. }
  1130. __setup("vmreboot=", vmcmd_on_reboot_setup);
  1131. static int __init vmcmd_on_panic_setup(char *str)
  1132. {
  1133. if (!MACHINE_IS_VM)
  1134. return 1;
  1135. strncpy_skip_quote(vmcmd_on_panic, str, 127);
  1136. vmcmd_on_panic[127] = 0;
  1137. on_panic_trigger.action = &vmcmd_action;
  1138. return 1;
  1139. }
  1140. __setup("vmpanic=", vmcmd_on_panic_setup);
  1141. static int __init vmcmd_on_halt_setup(char *str)
  1142. {
  1143. if (!MACHINE_IS_VM)
  1144. return 1;
  1145. strncpy_skip_quote(vmcmd_on_halt, str, 127);
  1146. vmcmd_on_halt[127] = 0;
  1147. on_halt_trigger.action = &vmcmd_action;
  1148. return 1;
  1149. }
  1150. __setup("vmhalt=", vmcmd_on_halt_setup);
  1151. static int __init vmcmd_on_poff_setup(char *str)
  1152. {
  1153. if (!MACHINE_IS_VM)
  1154. return 1;
  1155. strncpy_skip_quote(vmcmd_on_poff, str, 127);
  1156. vmcmd_on_poff[127] = 0;
  1157. on_poff_trigger.action = &vmcmd_action;
  1158. return 1;
  1159. }
  1160. __setup("vmpoff=", vmcmd_on_poff_setup);
  1161. static int on_panic_notify(struct notifier_block *self,
  1162. unsigned long event, void *data)
  1163. {
  1164. do_panic();
  1165. return NOTIFY_OK;
  1166. }
  1167. static struct notifier_block on_panic_nb = {
  1168. .notifier_call = on_panic_notify,
  1169. .priority = 0,
  1170. };
  1171. void __init setup_ipl(void)
  1172. {
  1173. ipl_info.type = get_ipl_type();
  1174. switch (ipl_info.type) {
  1175. case IPL_TYPE_CCW:
  1176. ipl_info.data.ccw.dev_id.devno = ipl_devno;
  1177. ipl_info.data.ccw.dev_id.ssid = 0;
  1178. break;
  1179. case IPL_TYPE_FCP:
  1180. case IPL_TYPE_FCP_DUMP:
  1181. ipl_info.data.fcp.dev_id.devno =
  1182. IPL_PARMBLOCK_START->ipl_info.fcp.devno;
  1183. ipl_info.data.fcp.dev_id.ssid = 0;
  1184. ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
  1185. ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
  1186. break;
  1187. case IPL_TYPE_NSS:
  1188. strncpy(ipl_info.data.nss.name, kernel_nss_name,
  1189. sizeof(ipl_info.data.nss.name));
  1190. break;
  1191. case IPL_TYPE_UNKNOWN:
  1192. default:
  1193. /* We have no info to copy */
  1194. break;
  1195. }
  1196. atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
  1197. }
  1198. void __init ipl_save_parameters(void)
  1199. {
  1200. struct cio_iplinfo iplinfo;
  1201. unsigned int *ipl_ptr;
  1202. void *src, *dst;
  1203. if (cio_get_iplinfo(&iplinfo))
  1204. return;
  1205. ipl_devno = iplinfo.devno;
  1206. ipl_flags |= IPL_DEVNO_VALID;
  1207. if (!iplinfo.is_qdio)
  1208. return;
  1209. ipl_flags |= IPL_PARMBLOCK_VALID;
  1210. ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
  1211. src = (void *)(unsigned long)*ipl_ptr;
  1212. dst = (void *)IPL_PARMBLOCK_ORIGIN;
  1213. memmove(dst, src, PAGE_SIZE);
  1214. *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
  1215. }
  1216. static LIST_HEAD(rcall);
  1217. static DEFINE_MUTEX(rcall_mutex);
  1218. void register_reset_call(struct reset_call *reset)
  1219. {
  1220. mutex_lock(&rcall_mutex);
  1221. list_add(&reset->list, &rcall);
  1222. mutex_unlock(&rcall_mutex);
  1223. }
  1224. EXPORT_SYMBOL_GPL(register_reset_call);
  1225. void unregister_reset_call(struct reset_call *reset)
  1226. {
  1227. mutex_lock(&rcall_mutex);
  1228. list_del(&reset->list);
  1229. mutex_unlock(&rcall_mutex);
  1230. }
  1231. EXPORT_SYMBOL_GPL(unregister_reset_call);
  1232. static void do_reset_calls(void)
  1233. {
  1234. struct reset_call *reset;
  1235. list_for_each_entry(reset, &rcall, list)
  1236. reset->fn();
  1237. }
  1238. u32 dump_prefix_page;
  1239. void s390_reset_system(void)
  1240. {
  1241. struct _lowcore *lc;
  1242. lc = (struct _lowcore *)(unsigned long) store_prefix();
  1243. /* Stack for interrupt/machine check handler */
  1244. lc->panic_stack = S390_lowcore.panic_stack;
  1245. /* Save prefix page address for dump case */
  1246. dump_prefix_page = (u32)(unsigned long) lc;
  1247. /* Disable prefixing */
  1248. set_prefix(0);
  1249. /* Disable lowcore protection */
  1250. __ctl_clear_bit(0,28);
  1251. /* Set new machine check handler */
  1252. S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
  1253. S390_lowcore.mcck_new_psw.addr =
  1254. PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
  1255. /* Set new program check handler */
  1256. S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
  1257. S390_lowcore.program_new_psw.addr =
  1258. PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
  1259. do_reset_calls();
  1260. }