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