ipl.c 52 KB

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