xref: /linux/drivers/s390/char/zcore.c (revision 3932b9ca55b0be314a36d3e84faff3e823c081f5)
1 /*
2  * zcore module to export memory content and register sets for creating system
3  * dumps on SCSI disks (zfcpdump). The "zcore/mem" debugfs file shows the same
4  * dump format as s390 standalone dumps.
5  *
6  * For more information please refer to Documentation/s390/zfcpdump.txt
7  *
8  * Copyright IBM Corp. 2003, 2008
9  * Author(s): Michael Holzheu
10  */
11 
12 #define KMSG_COMPONENT "zdump"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/miscdevice.h>
18 #include <linux/debugfs.h>
19 #include <linux/module.h>
20 #include <linux/memblock.h>
21 
22 #include <asm/asm-offsets.h>
23 #include <asm/ipl.h>
24 #include <asm/sclp.h>
25 #include <asm/setup.h>
26 #include <asm/uaccess.h>
27 #include <asm/debug.h>
28 #include <asm/processor.h>
29 #include <asm/irqflags.h>
30 #include <asm/checksum.h>
31 #include "sclp.h"
32 
33 #define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
34 
35 #define TO_USER		1
36 #define TO_KERNEL	0
37 #define CHUNK_INFO_SIZE	34 /* 2 16-byte char, each followed by blank */
38 
39 enum arch_id {
40 	ARCH_S390	= 0,
41 	ARCH_S390X	= 1,
42 };
43 
44 /* dump system info */
45 
46 struct sys_info {
47 	enum arch_id	 arch;
48 	unsigned long	 sa_base;
49 	u32		 sa_size;
50 	int		 cpu_map[NR_CPUS];
51 	unsigned long	 mem_size;
52 	struct save_area lc_mask;
53 };
54 
55 struct ipib_info {
56 	unsigned long	ipib;
57 	u32		checksum;
58 }  __attribute__((packed));
59 
60 static struct sys_info sys_info;
61 static struct debug_info *zcore_dbf;
62 static int hsa_available;
63 static struct dentry *zcore_dir;
64 static struct dentry *zcore_file;
65 static struct dentry *zcore_memmap_file;
66 static struct dentry *zcore_reipl_file;
67 static struct dentry *zcore_hsa_file;
68 static struct ipl_parameter_block *ipl_block;
69 
70 /*
71  * Copy memory from HSA to kernel or user memory (not reentrant):
72  *
73  * @dest:  Kernel or user buffer where memory should be copied to
74  * @src:   Start address within HSA where data should be copied
75  * @count: Size of buffer, which should be copied
76  * @mode:  Either TO_KERNEL or TO_USER
77  */
78 int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode)
79 {
80 	int offs, blk_num;
81 	static char buf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
82 
83 	if (!hsa_available)
84 		return -ENODATA;
85 	if (count == 0)
86 		return 0;
87 
88 	/* copy first block */
89 	offs = 0;
90 	if ((src % PAGE_SIZE) != 0) {
91 		blk_num = src / PAGE_SIZE + 2;
92 		if (sclp_sdias_copy(buf, blk_num, 1)) {
93 			TRACE("sclp_sdias_copy() failed\n");
94 			return -EIO;
95 		}
96 		offs = min((PAGE_SIZE - (src % PAGE_SIZE)), count);
97 		if (mode == TO_USER) {
98 			if (copy_to_user((__force __user void*) dest,
99 					 buf + (src % PAGE_SIZE), offs))
100 				return -EFAULT;
101 		} else
102 			memcpy(dest, buf + (src % PAGE_SIZE), offs);
103 	}
104 	if (offs == count)
105 		goto out;
106 
107 	/* copy middle */
108 	for (; (offs + PAGE_SIZE) <= count; offs += PAGE_SIZE) {
109 		blk_num = (src + offs) / PAGE_SIZE + 2;
110 		if (sclp_sdias_copy(buf, blk_num, 1)) {
111 			TRACE("sclp_sdias_copy() failed\n");
112 			return -EIO;
113 		}
114 		if (mode == TO_USER) {
115 			if (copy_to_user((__force __user void*) dest + offs,
116 					 buf, PAGE_SIZE))
117 				return -EFAULT;
118 		} else
119 			memcpy(dest + offs, buf, PAGE_SIZE);
120 	}
121 	if (offs == count)
122 		goto out;
123 
124 	/* copy last block */
125 	blk_num = (src + offs) / PAGE_SIZE + 2;
126 	if (sclp_sdias_copy(buf, blk_num, 1)) {
127 		TRACE("sclp_sdias_copy() failed\n");
128 		return -EIO;
129 	}
130 	if (mode == TO_USER) {
131 		if (copy_to_user((__force __user void*) dest + offs, buf,
132 				 count - offs))
133 			return -EFAULT;
134 	} else
135 		memcpy(dest + offs, buf, count - offs);
136 out:
137 	return 0;
138 }
139 
140 static int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
141 {
142 	return memcpy_hsa((void __force *) dest, src, count, TO_USER);
143 }
144 
145 static int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
146 {
147 	return memcpy_hsa(dest, src, count, TO_KERNEL);
148 }
149 
150 static int __init init_cpu_info(enum arch_id arch)
151 {
152 	struct save_area *sa;
153 
154 	/* get info for boot cpu from lowcore, stored in the HSA */
155 
156 	sa = dump_save_area_create(0);
157 	if (!sa)
158 		return -ENOMEM;
159 	if (memcpy_hsa_kernel(sa, sys_info.sa_base, sys_info.sa_size) < 0) {
160 		TRACE("could not copy from HSA\n");
161 		kfree(sa);
162 		return -EIO;
163 	}
164 	return 0;
165 }
166 
167 static DEFINE_MUTEX(zcore_mutex);
168 
169 #define DUMP_VERSION	0x5
170 #define DUMP_MAGIC	0xa8190173618f23fdULL
171 #define DUMP_ARCH_S390X	2
172 #define DUMP_ARCH_S390	1
173 #define HEADER_SIZE	4096
174 
175 /* dump header dumped according to s390 crash dump format */
176 
177 struct zcore_header {
178 	u64 magic;
179 	u32 version;
180 	u32 header_size;
181 	u32 dump_level;
182 	u32 page_size;
183 	u64 mem_size;
184 	u64 mem_start;
185 	u64 mem_end;
186 	u32 num_pages;
187 	u32 pad1;
188 	u64 tod;
189 	struct cpuid cpu_id;
190 	u32 arch_id;
191 	u32 volnr;
192 	u32 build_arch;
193 	u64 rmem_size;
194 	u8 mvdump;
195 	u16 cpu_cnt;
196 	u16 real_cpu_cnt;
197 	u8 end_pad1[0x200-0x061];
198 	u64 mvdump_sign;
199 	u64 mvdump_zipl_time;
200 	u8 end_pad2[0x800-0x210];
201 	u32 lc_vec[512];
202 } __attribute__((packed,__aligned__(16)));
203 
204 static struct zcore_header zcore_header = {
205 	.magic		= DUMP_MAGIC,
206 	.version	= DUMP_VERSION,
207 	.header_size	= 4096,
208 	.dump_level	= 0,
209 	.page_size	= PAGE_SIZE,
210 	.mem_start	= 0,
211 #ifdef CONFIG_64BIT
212 	.build_arch	= DUMP_ARCH_S390X,
213 #else
214 	.build_arch	= DUMP_ARCH_S390,
215 #endif
216 };
217 
218 /*
219  * Copy lowcore info to buffer. Use map in order to copy only register parts.
220  *
221  * @buf:    User buffer
222  * @sa:     Pointer to save area
223  * @sa_off: Offset in save area to copy
224  * @len:    Number of bytes to copy
225  */
226 static int copy_lc(void __user *buf, void *sa, int sa_off, int len)
227 {
228 	int i;
229 	char *lc_mask = (char*)&sys_info.lc_mask;
230 
231 	for (i = 0; i < len; i++) {
232 		if (!lc_mask[i + sa_off])
233 			continue;
234 		if (copy_to_user(buf + i, sa + sa_off + i, 1))
235 			return -EFAULT;
236 	}
237 	return 0;
238 }
239 
240 /*
241  * Copy lowcores info to memory, if necessary
242  *
243  * @buf:   User buffer
244  * @addr:  Start address of buffer in dump memory
245  * @count: Size of buffer
246  */
247 static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
248 {
249 	unsigned long end;
250 	int i;
251 
252 	if (count == 0)
253 		return 0;
254 
255 	end = start + count;
256 	for (i = 0; i < dump_save_areas.count; i++) {
257 		unsigned long cp_start, cp_end; /* copy range */
258 		unsigned long sa_start, sa_end; /* save area range */
259 		unsigned long prefix;
260 		unsigned long sa_off, len, buf_off;
261 		struct save_area *save_area = dump_save_areas.areas[i];
262 
263 		prefix = save_area->pref_reg;
264 		sa_start = prefix + sys_info.sa_base;
265 		sa_end = prefix + sys_info.sa_base + sys_info.sa_size;
266 
267 		if ((end < sa_start) || (start > sa_end))
268 			continue;
269 		cp_start = max(start, sa_start);
270 		cp_end = min(end, sa_end);
271 
272 		buf_off = cp_start - start;
273 		sa_off = cp_start - sa_start;
274 		len = cp_end - cp_start;
275 
276 		TRACE("copy_lc for: %lx\n", start);
277 		if (copy_lc(buf + buf_off, save_area, sa_off, len))
278 			return -EFAULT;
279 	}
280 	return 0;
281 }
282 
283 /*
284  * Release the HSA
285  */
286 static void release_hsa(void)
287 {
288 	diag308(DIAG308_REL_HSA, NULL);
289 	hsa_available = 0;
290 }
291 
292 /*
293  * Read routine for zcore character device
294  * First 4K are dump header
295  * Next 32MB are HSA Memory
296  * Rest is read from absolute Memory
297  */
298 static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
299 			  loff_t *ppos)
300 {
301 	unsigned long mem_start; /* Start address in memory */
302 	size_t mem_offs;	 /* Offset in dump memory */
303 	size_t hdr_count;	 /* Size of header part of output buffer */
304 	size_t size;
305 	int rc;
306 
307 	mutex_lock(&zcore_mutex);
308 
309 	if (*ppos > (sys_info.mem_size + HEADER_SIZE)) {
310 		rc = -EINVAL;
311 		goto fail;
312 	}
313 
314 	count = min(count, (size_t) (sys_info.mem_size + HEADER_SIZE - *ppos));
315 
316 	/* Copy dump header */
317 	if (*ppos < HEADER_SIZE) {
318 		size = min(count, (size_t) (HEADER_SIZE - *ppos));
319 		if (copy_to_user(buf, &zcore_header + *ppos, size)) {
320 			rc = -EFAULT;
321 			goto fail;
322 		}
323 		hdr_count = size;
324 		mem_start = 0;
325 	} else {
326 		hdr_count = 0;
327 		mem_start = *ppos - HEADER_SIZE;
328 	}
329 
330 	mem_offs = 0;
331 
332 	/* Copy from HSA data */
333 	if (*ppos < sclp_get_hsa_size() + HEADER_SIZE) {
334 		size = min((count - hdr_count),
335 			   (size_t) (sclp_get_hsa_size() - mem_start));
336 		rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
337 		if (rc)
338 			goto fail;
339 
340 		mem_offs += size;
341 	}
342 
343 	/* Copy from real mem */
344 	size = count - mem_offs - hdr_count;
345 	rc = copy_to_user_real(buf + hdr_count + mem_offs,
346 			       (void *) mem_start + mem_offs, size);
347 	if (rc)
348 		goto fail;
349 
350 	/*
351 	 * Since s390 dump analysis tools like lcrash or crash
352 	 * expect register sets in the prefix pages of the cpus,
353 	 * we copy them into the read buffer, if necessary.
354 	 * buf + hdr_count: Start of memory part of output buffer
355 	 * mem_start: Start memory address to copy from
356 	 * count - hdr_count: Size of memory area to copy
357 	 */
358 	if (zcore_add_lc(buf + hdr_count, mem_start, count - hdr_count)) {
359 		rc = -EFAULT;
360 		goto fail;
361 	}
362 	*ppos += count;
363 fail:
364 	mutex_unlock(&zcore_mutex);
365 	return (rc < 0) ? rc : count;
366 }
367 
368 static int zcore_open(struct inode *inode, struct file *filp)
369 {
370 	if (!hsa_available)
371 		return -ENODATA;
372 	else
373 		return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
374 }
375 
376 static int zcore_release(struct inode *inode, struct file *filep)
377 {
378 	if (hsa_available)
379 		release_hsa();
380 	return 0;
381 }
382 
383 static loff_t zcore_lseek(struct file *file, loff_t offset, int orig)
384 {
385 	loff_t rc;
386 
387 	mutex_lock(&zcore_mutex);
388 	switch (orig) {
389 	case 0:
390 		file->f_pos = offset;
391 		rc = file->f_pos;
392 		break;
393 	case 1:
394 		file->f_pos += offset;
395 		rc = file->f_pos;
396 		break;
397 	default:
398 		rc = -EINVAL;
399 	}
400 	mutex_unlock(&zcore_mutex);
401 	return rc;
402 }
403 
404 static const struct file_operations zcore_fops = {
405 	.owner		= THIS_MODULE,
406 	.llseek		= zcore_lseek,
407 	.read		= zcore_read,
408 	.open		= zcore_open,
409 	.release	= zcore_release,
410 };
411 
412 static ssize_t zcore_memmap_read(struct file *filp, char __user *buf,
413 				 size_t count, loff_t *ppos)
414 {
415 	return simple_read_from_buffer(buf, count, ppos, filp->private_data,
416 				       memblock.memory.cnt * CHUNK_INFO_SIZE);
417 }
418 
419 static int zcore_memmap_open(struct inode *inode, struct file *filp)
420 {
421 	struct memblock_region *reg;
422 	char *buf;
423 	int i = 0;
424 
425 	buf = kzalloc(memblock.memory.cnt * CHUNK_INFO_SIZE, GFP_KERNEL);
426 	if (!buf) {
427 		return -ENOMEM;
428 	}
429 	for_each_memblock(memory, reg) {
430 		sprintf(buf + (i++ * CHUNK_INFO_SIZE), "%016llx %016llx ",
431 			(unsigned long long) reg->base,
432 			(unsigned long long) reg->size);
433 	}
434 	filp->private_data = buf;
435 	return nonseekable_open(inode, filp);
436 }
437 
438 static int zcore_memmap_release(struct inode *inode, struct file *filp)
439 {
440 	kfree(filp->private_data);
441 	return 0;
442 }
443 
444 static const struct file_operations zcore_memmap_fops = {
445 	.owner		= THIS_MODULE,
446 	.read		= zcore_memmap_read,
447 	.open		= zcore_memmap_open,
448 	.release	= zcore_memmap_release,
449 	.llseek		= no_llseek,
450 };
451 
452 static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
453 				 size_t count, loff_t *ppos)
454 {
455 	if (ipl_block) {
456 		diag308(DIAG308_SET, ipl_block);
457 		diag308(DIAG308_IPL, NULL);
458 	}
459 	return count;
460 }
461 
462 static int zcore_reipl_open(struct inode *inode, struct file *filp)
463 {
464 	return nonseekable_open(inode, filp);
465 }
466 
467 static int zcore_reipl_release(struct inode *inode, struct file *filp)
468 {
469 	return 0;
470 }
471 
472 static const struct file_operations zcore_reipl_fops = {
473 	.owner		= THIS_MODULE,
474 	.write		= zcore_reipl_write,
475 	.open		= zcore_reipl_open,
476 	.release	= zcore_reipl_release,
477 	.llseek		= no_llseek,
478 };
479 
480 static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
481 			      size_t count, loff_t *ppos)
482 {
483 	static char str[18];
484 
485 	if (hsa_available)
486 		snprintf(str, sizeof(str), "%lx\n", sclp_get_hsa_size());
487 	else
488 		snprintf(str, sizeof(str), "0\n");
489 	return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
490 }
491 
492 static ssize_t zcore_hsa_write(struct file *filp, const char __user *buf,
493 			       size_t count, loff_t *ppos)
494 {
495 	char value;
496 
497 	if (*ppos != 0)
498 		return -EPIPE;
499 	if (copy_from_user(&value, buf, 1))
500 		return -EFAULT;
501 	if (value != '0')
502 		return -EINVAL;
503 	release_hsa();
504 	return count;
505 }
506 
507 static const struct file_operations zcore_hsa_fops = {
508 	.owner		= THIS_MODULE,
509 	.write		= zcore_hsa_write,
510 	.read		= zcore_hsa_read,
511 	.open		= nonseekable_open,
512 	.llseek		= no_llseek,
513 };
514 
515 #ifdef CONFIG_32BIT
516 
517 static void __init set_lc_mask(struct save_area *map)
518 {
519 	memset(&map->ext_save, 0xff, sizeof(map->ext_save));
520 	memset(&map->timer, 0xff, sizeof(map->timer));
521 	memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
522 	memset(&map->psw, 0xff, sizeof(map->psw));
523 	memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
524 	memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
525 	memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
526 	memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
527 	memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
528 }
529 
530 #else /* CONFIG_32BIT */
531 
532 static void __init set_lc_mask(struct save_area *map)
533 {
534 	memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
535 	memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
536 	memset(&map->psw, 0xff, sizeof(map->psw));
537 	memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
538 	memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
539 	memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
540 	memset(&map->timer, 0xff, sizeof(map->timer));
541 	memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
542 	memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
543 	memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
544 }
545 
546 #endif /* CONFIG_32BIT */
547 
548 /*
549  * Initialize dump globals for a given architecture
550  */
551 static int __init sys_info_init(enum arch_id arch, unsigned long mem_end)
552 {
553 	int rc;
554 
555 	switch (arch) {
556 	case ARCH_S390X:
557 		pr_alert("DETECTED 'S390X (64 bit) OS'\n");
558 		break;
559 	case ARCH_S390:
560 		pr_alert("DETECTED 'S390 (32 bit) OS'\n");
561 		break;
562 	default:
563 		pr_alert("0x%x is an unknown architecture.\n",arch);
564 		return -EINVAL;
565 	}
566 	sys_info.sa_base = SAVE_AREA_BASE;
567 	sys_info.sa_size = sizeof(struct save_area);
568 	sys_info.arch = arch;
569 	set_lc_mask(&sys_info.lc_mask);
570 	rc = init_cpu_info(arch);
571 	if (rc)
572 		return rc;
573 	sys_info.mem_size = mem_end;
574 
575 	return 0;
576 }
577 
578 static int __init check_sdias(void)
579 {
580 	if (!sclp_get_hsa_size()) {
581 		TRACE("Could not determine HSA size\n");
582 		return -ENODEV;
583 	}
584 	return 0;
585 }
586 
587 static int __init get_mem_info(unsigned long *mem, unsigned long *end)
588 {
589 	struct memblock_region *reg;
590 
591 	for_each_memblock(memory, reg) {
592 		*mem += reg->size;
593 		*end = max_t(unsigned long, *end, reg->base + reg->size);
594 	}
595 	return 0;
596 }
597 
598 static void __init zcore_header_init(int arch, struct zcore_header *hdr,
599 				     unsigned long mem_size)
600 {
601 	u32 prefix;
602 	int i;
603 
604 	if (arch == ARCH_S390X)
605 		hdr->arch_id = DUMP_ARCH_S390X;
606 	else
607 		hdr->arch_id = DUMP_ARCH_S390;
608 	hdr->mem_size = mem_size;
609 	hdr->rmem_size = mem_size;
610 	hdr->mem_end = sys_info.mem_size;
611 	hdr->num_pages = mem_size / PAGE_SIZE;
612 	hdr->tod = get_tod_clock();
613 	get_cpu_id(&hdr->cpu_id);
614 	for (i = 0; i < dump_save_areas.count; i++) {
615 		prefix = dump_save_areas.areas[i]->pref_reg;
616 		hdr->real_cpu_cnt++;
617 		if (!prefix)
618 			continue;
619 		hdr->lc_vec[hdr->cpu_cnt] = prefix;
620 		hdr->cpu_cnt++;
621 	}
622 }
623 
624 /*
625  * Provide IPL parameter information block from either HSA or memory
626  * for future reipl
627  */
628 static int __init zcore_reipl_init(void)
629 {
630 	struct ipib_info ipib_info;
631 	int rc;
632 
633 	rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
634 	if (rc)
635 		return rc;
636 	if (ipib_info.ipib == 0)
637 		return 0;
638 	ipl_block = (void *) __get_free_page(GFP_KERNEL);
639 	if (!ipl_block)
640 		return -ENOMEM;
641 	if (ipib_info.ipib < sclp_get_hsa_size())
642 		rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
643 	else
644 		rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
645 	if (rc || csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
646 	    ipib_info.checksum) {
647 		TRACE("Checksum does not match\n");
648 		free_page((unsigned long) ipl_block);
649 		ipl_block = NULL;
650 	}
651 	return 0;
652 }
653 
654 static int __init zcore_init(void)
655 {
656 	unsigned long mem_size, mem_end;
657 	unsigned char arch;
658 	int rc;
659 
660 	mem_size = mem_end = 0;
661 	if (ipl_info.type != IPL_TYPE_FCP_DUMP)
662 		return -ENODATA;
663 	if (OLDMEM_BASE)
664 		return -ENODATA;
665 
666 	zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
667 	debug_register_view(zcore_dbf, &debug_sprintf_view);
668 	debug_set_level(zcore_dbf, 6);
669 
670 	TRACE("devno:  %x\n", ipl_info.data.fcp.dev_id.devno);
671 	TRACE("wwpn:   %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
672 	TRACE("lun:    %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
673 
674 	rc = sclp_sdias_init();
675 	if (rc)
676 		goto fail;
677 
678 	rc = check_sdias();
679 	if (rc)
680 		goto fail;
681 	hsa_available = 1;
682 
683 	rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
684 	if (rc)
685 		goto fail;
686 
687 #ifdef CONFIG_64BIT
688 	if (arch == ARCH_S390) {
689 		pr_alert("The 64-bit dump tool cannot be used for a "
690 			 "32-bit system\n");
691 		rc = -EINVAL;
692 		goto fail;
693 	}
694 #else /* CONFIG_64BIT */
695 	if (arch == ARCH_S390X) {
696 		pr_alert("The 32-bit dump tool cannot be used for a "
697 			 "64-bit system\n");
698 		rc = -EINVAL;
699 		goto fail;
700 	}
701 #endif /* CONFIG_64BIT */
702 
703 	rc = get_mem_info(&mem_size, &mem_end);
704 	if (rc)
705 		goto fail;
706 
707 	rc = sys_info_init(arch, mem_end);
708 	if (rc)
709 		goto fail;
710 	zcore_header_init(arch, &zcore_header, mem_size);
711 
712 	rc = zcore_reipl_init();
713 	if (rc)
714 		goto fail;
715 
716 	zcore_dir = debugfs_create_dir("zcore" , NULL);
717 	if (!zcore_dir) {
718 		rc = -ENOMEM;
719 		goto fail;
720 	}
721 	zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL,
722 					 &zcore_fops);
723 	if (!zcore_file) {
724 		rc = -ENOMEM;
725 		goto fail_dir;
726 	}
727 	zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
728 						NULL, &zcore_memmap_fops);
729 	if (!zcore_memmap_file) {
730 		rc = -ENOMEM;
731 		goto fail_file;
732 	}
733 	zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
734 						NULL, &zcore_reipl_fops);
735 	if (!zcore_reipl_file) {
736 		rc = -ENOMEM;
737 		goto fail_memmap_file;
738 	}
739 	zcore_hsa_file = debugfs_create_file("hsa", S_IRUSR|S_IWUSR, zcore_dir,
740 					     NULL, &zcore_hsa_fops);
741 	if (!zcore_hsa_file) {
742 		rc = -ENOMEM;
743 		goto fail_reipl_file;
744 	}
745 	return 0;
746 
747 fail_reipl_file:
748 	debugfs_remove(zcore_reipl_file);
749 fail_memmap_file:
750 	debugfs_remove(zcore_memmap_file);
751 fail_file:
752 	debugfs_remove(zcore_file);
753 fail_dir:
754 	debugfs_remove(zcore_dir);
755 fail:
756 	diag308(DIAG308_REL_HSA, NULL);
757 	return rc;
758 }
759 
760 static void __exit zcore_exit(void)
761 {
762 	debug_unregister(zcore_dbf);
763 	sclp_sdias_exit();
764 	free_page((unsigned long) ipl_block);
765 	debugfs_remove(zcore_hsa_file);
766 	debugfs_remove(zcore_reipl_file);
767 	debugfs_remove(zcore_memmap_file);
768 	debugfs_remove(zcore_file);
769 	debugfs_remove(zcore_dir);
770 	diag308(DIAG308_REL_HSA, NULL);
771 }
772 
773 MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
774 MODULE_DESCRIPTION("zcore module for zfcpdump support");
775 MODULE_LICENSE("GPL");
776 
777 subsys_initcall(zcore_init);
778 module_exit(zcore_exit);
779