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