ipl.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487
  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. 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. }
  609. static void __init reipl_probe(void)
  610. {
  611. void *buffer;
  612. buffer = (void *) get_zeroed_page(GFP_KERNEL);
  613. if (!buffer)
  614. return;
  615. if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK)
  616. diag308_set_works = 1;
  617. free_page((unsigned long)buffer);
  618. }
  619. static int __init reipl_nss_init(void)
  620. {
  621. int rc;
  622. if (!MACHINE_IS_VM)
  623. return 0;
  624. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
  625. if (rc)
  626. return rc;
  627. strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
  628. reipl_capabilities |= IPL_TYPE_NSS;
  629. return 0;
  630. }
  631. static int __init reipl_ccw_init(void)
  632. {
  633. int rc;
  634. reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  635. if (!reipl_block_ccw)
  636. return -ENOMEM;
  637. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_ccw_attr_group);
  638. if (rc) {
  639. free_page((unsigned long)reipl_block_ccw);
  640. return rc;
  641. }
  642. reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  643. reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  644. reipl_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  645. reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  646. reipl_block_ccw->hdr.flags = DIAG308_FLAGS_LP_VALID;
  647. /* check if read scp info worked and set loadparm */
  648. if (sclp_ipl_info.is_valid)
  649. memcpy(reipl_block_ccw->ipl_info.ccw.load_param,
  650. &sclp_ipl_info.loadparm, LOADPARM_LEN);
  651. else
  652. /* read scp info failed: set empty loadparm (EBCDIC blanks) */
  653. memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40,
  654. LOADPARM_LEN);
  655. if (!MACHINE_IS_VM && !diag308_set_works)
  656. sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
  657. if (ipl_info.type == IPL_TYPE_CCW)
  658. reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
  659. reipl_capabilities |= IPL_TYPE_CCW;
  660. return 0;
  661. }
  662. static int __init reipl_fcp_init(void)
  663. {
  664. int rc;
  665. if ((!diag308_set_works) && (ipl_info.type != IPL_TYPE_FCP))
  666. return 0;
  667. if ((!diag308_set_works) && (ipl_info.type == IPL_TYPE_FCP))
  668. make_attrs_ro(reipl_fcp_attrs);
  669. reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  670. if (!reipl_block_fcp)
  671. return -ENOMEM;
  672. rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
  673. if (rc) {
  674. free_page((unsigned long)reipl_block_fcp);
  675. return rc;
  676. }
  677. if (ipl_info.type == IPL_TYPE_FCP) {
  678. memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
  679. } else {
  680. reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  681. reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  682. reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  683. reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  684. reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
  685. }
  686. reipl_capabilities |= IPL_TYPE_FCP;
  687. return 0;
  688. }
  689. static int __init reipl_init(void)
  690. {
  691. int rc;
  692. reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
  693. if (!reipl_kset)
  694. return -ENOMEM;
  695. rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
  696. if (rc) {
  697. kset_unregister(reipl_kset);
  698. return rc;
  699. }
  700. rc = reipl_ccw_init();
  701. if (rc)
  702. return rc;
  703. rc = reipl_fcp_init();
  704. if (rc)
  705. return rc;
  706. rc = reipl_nss_init();
  707. if (rc)
  708. return rc;
  709. rc = reipl_set_type(ipl_info.type);
  710. if (rc)
  711. return rc;
  712. return 0;
  713. }
  714. static struct shutdown_action __refdata reipl_action = {
  715. .name = SHUTDOWN_ACTION_REIPL_STR,
  716. .fn = reipl_run,
  717. .init = reipl_init,
  718. };
  719. /*
  720. * dump shutdown action: Dump Linux on shutdown.
  721. */
  722. /* FCP dump device attributes */
  723. DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
  724. dump_block_fcp->ipl_info.fcp.wwpn);
  725. DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
  726. dump_block_fcp->ipl_info.fcp.lun);
  727. DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
  728. dump_block_fcp->ipl_info.fcp.bootprog);
  729. DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
  730. dump_block_fcp->ipl_info.fcp.br_lba);
  731. DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
  732. dump_block_fcp->ipl_info.fcp.devno);
  733. static struct attribute *dump_fcp_attrs[] = {
  734. &sys_dump_fcp_device_attr.attr,
  735. &sys_dump_fcp_wwpn_attr.attr,
  736. &sys_dump_fcp_lun_attr.attr,
  737. &sys_dump_fcp_bootprog_attr.attr,
  738. &sys_dump_fcp_br_lba_attr.attr,
  739. NULL,
  740. };
  741. static struct attribute_group dump_fcp_attr_group = {
  742. .name = IPL_FCP_STR,
  743. .attrs = dump_fcp_attrs,
  744. };
  745. /* CCW dump device attributes */
  746. DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
  747. dump_block_ccw->ipl_info.ccw.devno);
  748. static struct attribute *dump_ccw_attrs[] = {
  749. &sys_dump_ccw_device_attr.attr,
  750. NULL,
  751. };
  752. static struct attribute_group dump_ccw_attr_group = {
  753. .name = IPL_CCW_STR,
  754. .attrs = dump_ccw_attrs,
  755. };
  756. /* dump type */
  757. static int dump_set_type(enum dump_type type)
  758. {
  759. if (!(dump_capabilities & type))
  760. return -EINVAL;
  761. switch (type) {
  762. case DUMP_TYPE_CCW:
  763. if (diag308_set_works)
  764. dump_method = DUMP_METHOD_CCW_DIAG;
  765. else if (MACHINE_IS_VM)
  766. dump_method = DUMP_METHOD_CCW_VM;
  767. else
  768. dump_method = DUMP_METHOD_CCW_CIO;
  769. break;
  770. case DUMP_TYPE_FCP:
  771. dump_method = DUMP_METHOD_FCP_DIAG;
  772. break;
  773. default:
  774. dump_method = DUMP_METHOD_NONE;
  775. }
  776. dump_type = type;
  777. return 0;
  778. }
  779. static ssize_t dump_type_show(struct kobject *kobj,
  780. struct kobj_attribute *attr, char *page)
  781. {
  782. return sprintf(page, "%s\n", dump_type_str(dump_type));
  783. }
  784. static ssize_t dump_type_store(struct kobject *kobj,
  785. struct kobj_attribute *attr,
  786. const char *buf, size_t len)
  787. {
  788. int rc = -EINVAL;
  789. if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
  790. rc = dump_set_type(DUMP_TYPE_NONE);
  791. else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
  792. rc = dump_set_type(DUMP_TYPE_CCW);
  793. else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
  794. rc = dump_set_type(DUMP_TYPE_FCP);
  795. return (rc != 0) ? rc : len;
  796. }
  797. static struct kobj_attribute dump_type_attr =
  798. __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
  799. static struct kset *dump_kset;
  800. static void dump_run(struct shutdown_trigger *trigger)
  801. {
  802. struct ccw_dev_id devid;
  803. static char buf[100];
  804. switch (dump_method) {
  805. case DUMP_METHOD_CCW_CIO:
  806. smp_send_stop();
  807. devid.devno = dump_block_ccw->ipl_info.ccw.devno;
  808. devid.ssid = 0;
  809. reipl_ccw_dev(&devid);
  810. break;
  811. case DUMP_METHOD_CCW_VM:
  812. smp_send_stop();
  813. sprintf(buf, "STORE STATUS");
  814. __cpcmd(buf, NULL, 0, NULL);
  815. sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
  816. __cpcmd(buf, NULL, 0, NULL);
  817. break;
  818. case DUMP_METHOD_CCW_DIAG:
  819. diag308(DIAG308_SET, dump_block_ccw);
  820. diag308(DIAG308_DUMP, NULL);
  821. break;
  822. case DUMP_METHOD_FCP_DIAG:
  823. diag308(DIAG308_SET, dump_block_fcp);
  824. diag308(DIAG308_DUMP, NULL);
  825. break;
  826. case DUMP_METHOD_NONE:
  827. default:
  828. return;
  829. }
  830. printk(KERN_EMERG "Dump failed!\n");
  831. }
  832. static int __init dump_ccw_init(void)
  833. {
  834. int rc;
  835. dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
  836. if (!dump_block_ccw)
  837. return -ENOMEM;
  838. rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
  839. if (rc) {
  840. free_page((unsigned long)dump_block_ccw);
  841. return rc;
  842. }
  843. dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
  844. dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
  845. dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
  846. dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
  847. dump_capabilities |= DUMP_TYPE_CCW;
  848. return 0;
  849. }
  850. static int __init dump_fcp_init(void)
  851. {
  852. int rc;
  853. if (!sclp_ipl_info.has_dump)
  854. return 0; /* LDIPL DUMP is not installed */
  855. if (!diag308_set_works)
  856. return 0;
  857. dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
  858. if (!dump_block_fcp)
  859. return -ENOMEM;
  860. rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
  861. if (rc) {
  862. free_page((unsigned long)dump_block_fcp);
  863. return rc;
  864. }
  865. dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
  866. dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
  867. dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
  868. dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
  869. dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
  870. dump_capabilities |= DUMP_TYPE_FCP;
  871. return 0;
  872. }
  873. static int __init dump_init(void)
  874. {
  875. int rc;
  876. dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
  877. if (!dump_kset)
  878. return -ENOMEM;
  879. rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
  880. if (rc) {
  881. kset_unregister(dump_kset);
  882. return rc;
  883. }
  884. rc = dump_ccw_init();
  885. if (rc)
  886. return rc;
  887. rc = dump_fcp_init();
  888. if (rc)
  889. return rc;
  890. dump_set_type(DUMP_TYPE_NONE);
  891. return 0;
  892. }
  893. static struct shutdown_action __refdata dump_action = {
  894. .name = SHUTDOWN_ACTION_DUMP_STR,
  895. .fn = dump_run,
  896. .init = dump_init,
  897. };
  898. /*
  899. * vmcmd shutdown action: Trigger vm command on shutdown.
  900. */
  901. static char vmcmd_on_reboot[128];
  902. static char vmcmd_on_panic[128];
  903. static char vmcmd_on_halt[128];
  904. static char vmcmd_on_poff[128];
  905. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
  906. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
  907. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
  908. DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
  909. static struct attribute *vmcmd_attrs[] = {
  910. &sys_vmcmd_on_reboot_attr.attr,
  911. &sys_vmcmd_on_panic_attr.attr,
  912. &sys_vmcmd_on_halt_attr.attr,
  913. &sys_vmcmd_on_poff_attr.attr,
  914. NULL,
  915. };
  916. static struct attribute_group vmcmd_attr_group = {
  917. .attrs = vmcmd_attrs,
  918. };
  919. static struct kset *vmcmd_kset;
  920. static void vmcmd_run(struct shutdown_trigger *trigger)
  921. {
  922. char *cmd, *next_cmd;
  923. if (strcmp(trigger->name, ON_REIPL_STR) == 0)
  924. cmd = vmcmd_on_reboot;
  925. else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
  926. cmd = vmcmd_on_panic;
  927. else if (strcmp(trigger->name, ON_HALT_STR) == 0)
  928. cmd = vmcmd_on_halt;
  929. else if (strcmp(trigger->name, ON_POFF_STR) == 0)
  930. cmd = vmcmd_on_poff;
  931. else
  932. return;
  933. if (strlen(cmd) == 0)
  934. return;
  935. do {
  936. next_cmd = strchr(cmd, '\n');
  937. if (next_cmd) {
  938. next_cmd[0] = 0;
  939. next_cmd += 1;
  940. }
  941. __cpcmd(cmd, NULL, 0, NULL);
  942. cmd = next_cmd;
  943. } while (cmd != NULL);
  944. }
  945. static int vmcmd_init(void)
  946. {
  947. if (!MACHINE_IS_VM)
  948. return -ENOTSUPP;
  949. vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
  950. if (!vmcmd_kset)
  951. return -ENOMEM;
  952. return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
  953. }
  954. static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
  955. vmcmd_run, vmcmd_init};
  956. /*
  957. * stop shutdown action: Stop Linux on shutdown.
  958. */
  959. static void stop_run(struct shutdown_trigger *trigger)
  960. {
  961. if (strcmp(trigger->name, ON_PANIC_STR) == 0)
  962. disabled_wait((unsigned long) __builtin_return_address(0));
  963. else {
  964. signal_processor(smp_processor_id(), sigp_stop);
  965. for (;;);
  966. }
  967. }
  968. static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
  969. stop_run, NULL};
  970. /* action list */
  971. static struct shutdown_action *shutdown_actions_list[] = {
  972. &ipl_action, &reipl_action, &dump_action, &vmcmd_action, &stop_action};
  973. #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
  974. /*
  975. * Trigger section
  976. */
  977. static struct kset *shutdown_actions_kset;
  978. static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
  979. size_t len)
  980. {
  981. int i;
  982. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  983. if (!shutdown_actions_list[i])
  984. continue;
  985. if (strncmp(buf, shutdown_actions_list[i]->name,
  986. strlen(shutdown_actions_list[i]->name)) == 0) {
  987. trigger->action = shutdown_actions_list[i];
  988. return len;
  989. }
  990. }
  991. return -EINVAL;
  992. }
  993. /* on reipl */
  994. static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
  995. &reipl_action};
  996. static ssize_t on_reboot_show(struct kobject *kobj,
  997. struct kobj_attribute *attr, char *page)
  998. {
  999. return sprintf(page, "%s\n", on_reboot_trigger.action->name);
  1000. }
  1001. static ssize_t on_reboot_store(struct kobject *kobj,
  1002. struct kobj_attribute *attr,
  1003. const char *buf, size_t len)
  1004. {
  1005. return set_trigger(buf, &on_reboot_trigger, len);
  1006. }
  1007. static struct kobj_attribute on_reboot_attr =
  1008. __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
  1009. static void do_machine_restart(char *__unused)
  1010. {
  1011. smp_send_stop();
  1012. on_reboot_trigger.action->fn(&on_reboot_trigger);
  1013. reipl_run(NULL);
  1014. }
  1015. void (*_machine_restart)(char *command) = do_machine_restart;
  1016. /* on panic */
  1017. static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
  1018. static ssize_t on_panic_show(struct kobject *kobj,
  1019. struct kobj_attribute *attr, char *page)
  1020. {
  1021. return sprintf(page, "%s\n", on_panic_trigger.action->name);
  1022. }
  1023. static ssize_t on_panic_store(struct kobject *kobj,
  1024. struct kobj_attribute *attr,
  1025. const char *buf, size_t len)
  1026. {
  1027. return set_trigger(buf, &on_panic_trigger, len);
  1028. }
  1029. static struct kobj_attribute on_panic_attr =
  1030. __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
  1031. static void do_panic(void)
  1032. {
  1033. on_panic_trigger.action->fn(&on_panic_trigger);
  1034. stop_run(&on_panic_trigger);
  1035. }
  1036. /* on halt */
  1037. static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
  1038. static ssize_t on_halt_show(struct kobject *kobj,
  1039. struct kobj_attribute *attr, char *page)
  1040. {
  1041. return sprintf(page, "%s\n", on_halt_trigger.action->name);
  1042. }
  1043. static ssize_t on_halt_store(struct kobject *kobj,
  1044. struct kobj_attribute *attr,
  1045. const char *buf, size_t len)
  1046. {
  1047. return set_trigger(buf, &on_halt_trigger, len);
  1048. }
  1049. static struct kobj_attribute on_halt_attr =
  1050. __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
  1051. static void do_machine_halt(void)
  1052. {
  1053. smp_send_stop();
  1054. on_halt_trigger.action->fn(&on_halt_trigger);
  1055. stop_run(&on_halt_trigger);
  1056. }
  1057. void (*_machine_halt)(void) = do_machine_halt;
  1058. /* on power off */
  1059. static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
  1060. static ssize_t on_poff_show(struct kobject *kobj,
  1061. struct kobj_attribute *attr, char *page)
  1062. {
  1063. return sprintf(page, "%s\n", on_poff_trigger.action->name);
  1064. }
  1065. static ssize_t on_poff_store(struct kobject *kobj,
  1066. struct kobj_attribute *attr,
  1067. const char *buf, size_t len)
  1068. {
  1069. return set_trigger(buf, &on_poff_trigger, len);
  1070. }
  1071. static struct kobj_attribute on_poff_attr =
  1072. __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
  1073. static void do_machine_power_off(void)
  1074. {
  1075. smp_send_stop();
  1076. on_poff_trigger.action->fn(&on_poff_trigger);
  1077. stop_run(&on_poff_trigger);
  1078. }
  1079. void (*_machine_power_off)(void) = do_machine_power_off;
  1080. static void __init shutdown_triggers_init(void)
  1081. {
  1082. shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
  1083. firmware_kobj);
  1084. if (!shutdown_actions_kset)
  1085. goto fail;
  1086. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1087. &on_reboot_attr.attr))
  1088. goto fail;
  1089. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1090. &on_panic_attr.attr))
  1091. goto fail;
  1092. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1093. &on_halt_attr.attr))
  1094. goto fail;
  1095. if (sysfs_create_file(&shutdown_actions_kset->kobj,
  1096. &on_poff_attr.attr))
  1097. goto fail;
  1098. return;
  1099. fail:
  1100. panic("shutdown_triggers_init failed\n");
  1101. }
  1102. static void __init shutdown_actions_init(void)
  1103. {
  1104. int i;
  1105. for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
  1106. if (!shutdown_actions_list[i]->init)
  1107. continue;
  1108. if (shutdown_actions_list[i]->init())
  1109. shutdown_actions_list[i] = NULL;
  1110. }
  1111. }
  1112. static int __init s390_ipl_init(void)
  1113. {
  1114. reipl_probe();
  1115. sclp_get_ipl_info(&sclp_ipl_info);
  1116. shutdown_actions_init();
  1117. shutdown_triggers_init();
  1118. return 0;
  1119. }
  1120. __initcall(s390_ipl_init);
  1121. static void __init strncpy_skip_quote(char *dst, char *src, int n)
  1122. {
  1123. int sx, dx;
  1124. dx = 0;
  1125. for (sx = 0; src[sx] != 0; sx++) {
  1126. if (src[sx] == '"')
  1127. continue;
  1128. dst[dx++] = src[sx];
  1129. if (dx >= n)
  1130. break;
  1131. }
  1132. }
  1133. static int __init vmcmd_on_reboot_setup(char *str)
  1134. {
  1135. if (!MACHINE_IS_VM)
  1136. return 1;
  1137. strncpy_skip_quote(vmcmd_on_reboot, str, 127);
  1138. vmcmd_on_reboot[127] = 0;
  1139. on_reboot_trigger.action = &vmcmd_action;
  1140. return 1;
  1141. }
  1142. __setup("vmreboot=", vmcmd_on_reboot_setup);
  1143. static int __init vmcmd_on_panic_setup(char *str)
  1144. {
  1145. if (!MACHINE_IS_VM)
  1146. return 1;
  1147. strncpy_skip_quote(vmcmd_on_panic, str, 127);
  1148. vmcmd_on_panic[127] = 0;
  1149. on_panic_trigger.action = &vmcmd_action;
  1150. return 1;
  1151. }
  1152. __setup("vmpanic=", vmcmd_on_panic_setup);
  1153. static int __init vmcmd_on_halt_setup(char *str)
  1154. {
  1155. if (!MACHINE_IS_VM)
  1156. return 1;
  1157. strncpy_skip_quote(vmcmd_on_halt, str, 127);
  1158. vmcmd_on_halt[127] = 0;
  1159. on_halt_trigger.action = &vmcmd_action;
  1160. return 1;
  1161. }
  1162. __setup("vmhalt=", vmcmd_on_halt_setup);
  1163. static int __init vmcmd_on_poff_setup(char *str)
  1164. {
  1165. if (!MACHINE_IS_VM)
  1166. return 1;
  1167. strncpy_skip_quote(vmcmd_on_poff, str, 127);
  1168. vmcmd_on_poff[127] = 0;
  1169. on_poff_trigger.action = &vmcmd_action;
  1170. return 1;
  1171. }
  1172. __setup("vmpoff=", vmcmd_on_poff_setup);
  1173. static int on_panic_notify(struct notifier_block *self,
  1174. unsigned long event, void *data)
  1175. {
  1176. do_panic();
  1177. return NOTIFY_OK;
  1178. }
  1179. static struct notifier_block on_panic_nb = {
  1180. .notifier_call = on_panic_notify,
  1181. .priority = 0,
  1182. };
  1183. void __init setup_ipl(void)
  1184. {
  1185. ipl_info.type = get_ipl_type();
  1186. switch (ipl_info.type) {
  1187. case IPL_TYPE_CCW:
  1188. ipl_info.data.ccw.dev_id.devno = ipl_devno;
  1189. ipl_info.data.ccw.dev_id.ssid = 0;
  1190. break;
  1191. case IPL_TYPE_FCP:
  1192. case IPL_TYPE_FCP_DUMP:
  1193. ipl_info.data.fcp.dev_id.devno =
  1194. IPL_PARMBLOCK_START->ipl_info.fcp.devno;
  1195. ipl_info.data.fcp.dev_id.ssid = 0;
  1196. ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
  1197. ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
  1198. break;
  1199. case IPL_TYPE_NSS:
  1200. strncpy(ipl_info.data.nss.name, kernel_nss_name,
  1201. sizeof(ipl_info.data.nss.name));
  1202. break;
  1203. case IPL_TYPE_UNKNOWN:
  1204. default:
  1205. /* We have no info to copy */
  1206. break;
  1207. }
  1208. atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
  1209. }
  1210. void __init ipl_save_parameters(void)
  1211. {
  1212. struct cio_iplinfo iplinfo;
  1213. unsigned int *ipl_ptr;
  1214. void *src, *dst;
  1215. if (cio_get_iplinfo(&iplinfo))
  1216. return;
  1217. ipl_devno = iplinfo.devno;
  1218. ipl_flags |= IPL_DEVNO_VALID;
  1219. if (!iplinfo.is_qdio)
  1220. return;
  1221. ipl_flags |= IPL_PARMBLOCK_VALID;
  1222. ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
  1223. src = (void *)(unsigned long)*ipl_ptr;
  1224. dst = (void *)IPL_PARMBLOCK_ORIGIN;
  1225. memmove(dst, src, PAGE_SIZE);
  1226. *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
  1227. }
  1228. static LIST_HEAD(rcall);
  1229. static DEFINE_MUTEX(rcall_mutex);
  1230. void register_reset_call(struct reset_call *reset)
  1231. {
  1232. mutex_lock(&rcall_mutex);
  1233. list_add(&reset->list, &rcall);
  1234. mutex_unlock(&rcall_mutex);
  1235. }
  1236. EXPORT_SYMBOL_GPL(register_reset_call);
  1237. void unregister_reset_call(struct reset_call *reset)
  1238. {
  1239. mutex_lock(&rcall_mutex);
  1240. list_del(&reset->list);
  1241. mutex_unlock(&rcall_mutex);
  1242. }
  1243. EXPORT_SYMBOL_GPL(unregister_reset_call);
  1244. static void do_reset_calls(void)
  1245. {
  1246. struct reset_call *reset;
  1247. list_for_each_entry(reset, &rcall, list)
  1248. reset->fn();
  1249. }
  1250. u32 dump_prefix_page;
  1251. void s390_reset_system(void)
  1252. {
  1253. struct _lowcore *lc;
  1254. lc = (struct _lowcore *)(unsigned long) store_prefix();
  1255. /* Stack for interrupt/machine check handler */
  1256. lc->panic_stack = S390_lowcore.panic_stack;
  1257. /* Save prefix page address for dump case */
  1258. dump_prefix_page = (u32)(unsigned long) lc;
  1259. /* Disable prefixing */
  1260. set_prefix(0);
  1261. /* Disable lowcore protection */
  1262. __ctl_clear_bit(0,28);
  1263. /* Set new machine check handler */
  1264. S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
  1265. S390_lowcore.mcck_new_psw.addr =
  1266. PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
  1267. /* Set new program check handler */
  1268. S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
  1269. S390_lowcore.program_new_psw.addr =
  1270. PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
  1271. do_reset_calls();
  1272. }