ipl.c 49 KB

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