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