s390/sclp: unify basic sclp access by exposing "struct sclp"
[deliverable/linux.git] / drivers / s390 / char / zcore.c
CommitLineData
411ed322
MH
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 *
a53c8fab 8 * Copyright IBM Corp. 2003, 2008
411ed322
MH
9 * Author(s): Michael Holzheu
10 */
11
17159dc6
MH
12#define KMSG_COMPONENT "zdump"
13#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14
411ed322 15#include <linux/init.h>
5a0e3ad6 16#include <linux/slab.h>
411ed322 17#include <linux/miscdevice.h>
411ed322 18#include <linux/debugfs.h>
3948a102 19#include <linux/module.h>
50be6345
PH
20#include <linux/memblock.h>
21
cbb870c8 22#include <asm/asm-offsets.h>
411ed322
MH
23#include <asm/ipl.h>
24#include <asm/sclp.h>
25#include <asm/setup.h>
411ed322
MH
26#include <asm/uaccess.h>
27#include <asm/debug.h>
28#include <asm/processor.h>
29#include <asm/irqflags.h>
159d1ff8 30#include <asm/checksum.h>
a62bc073 31#include <asm/switch_to.h>
763968e2 32#include "sclp.h"
411ed322
MH
33
34#define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
411ed322 35
6f79d332
MH
36#define TO_USER 1
37#define TO_KERNEL 0
12e0c95e 38#define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
411ed322
MH
39
40enum arch_id {
41 ARCH_S390 = 0,
42 ARCH_S390X = 1,
43};
44
45/* dump system info */
46
47struct sys_info {
f64ca217
HC
48 enum arch_id arch;
49 unsigned long sa_base;
50 u32 sa_size;
51 int cpu_map[NR_CPUS];
52 unsigned long mem_size;
53 struct save_area lc_mask;
411ed322
MH
54};
55
099b7651
FM
56struct ipib_info {
57 unsigned long ipib;
58 u32 checksum;
59} __attribute__((packed));
60
411ed322
MH
61static struct sys_info sys_info;
62static struct debug_info *zcore_dbf;
63static int hsa_available;
64static struct dentry *zcore_dir;
65static struct dentry *zcore_file;
12e0c95e 66static struct dentry *zcore_memmap_file;
099b7651 67static struct dentry *zcore_reipl_file;
b4b3d128 68static struct dentry *zcore_hsa_file;
099b7651 69static struct ipl_parameter_block *ipl_block;
411ed322
MH
70
71/*
72 * Copy memory from HSA to kernel or user memory (not reentrant):
73 *
74 * @dest: Kernel or user buffer where memory should be copied to
75 * @src: Start address within HSA where data should be copied
76 * @count: Size of buffer, which should be copied
77 * @mode: Either TO_KERNEL or TO_USER
78 */
6f79d332 79int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode)
411ed322
MH
80{
81 int offs, blk_num;
82 static char buf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
83
b4b3d128
MH
84 if (!hsa_available)
85 return -ENODATA;
411ed322
MH
86 if (count == 0)
87 return 0;
88
89 /* copy first block */
90 offs = 0;
91 if ((src % PAGE_SIZE) != 0) {
92 blk_num = src / PAGE_SIZE + 2;
93 if (sclp_sdias_copy(buf, blk_num, 1)) {
94 TRACE("sclp_sdias_copy() failed\n");
95 return -EIO;
96 }
97 offs = min((PAGE_SIZE - (src % PAGE_SIZE)), count);
98 if (mode == TO_USER) {
99 if (copy_to_user((__force __user void*) dest,
100 buf + (src % PAGE_SIZE), offs))
101 return -EFAULT;
102 } else
103 memcpy(dest, buf + (src % PAGE_SIZE), offs);
104 }
105 if (offs == count)
106 goto out;
107
108 /* copy middle */
109 for (; (offs + PAGE_SIZE) <= count; offs += PAGE_SIZE) {
110 blk_num = (src + offs) / PAGE_SIZE + 2;
111 if (sclp_sdias_copy(buf, blk_num, 1)) {
112 TRACE("sclp_sdias_copy() failed\n");
113 return -EIO;
114 }
115 if (mode == TO_USER) {
116 if (copy_to_user((__force __user void*) dest + offs,
117 buf, PAGE_SIZE))
118 return -EFAULT;
119 } else
120 memcpy(dest + offs, buf, PAGE_SIZE);
121 }
122 if (offs == count)
123 goto out;
124
125 /* copy last block */
126 blk_num = (src + offs) / PAGE_SIZE + 2;
127 if (sclp_sdias_copy(buf, blk_num, 1)) {
128 TRACE("sclp_sdias_copy() failed\n");
129 return -EIO;
130 }
131 if (mode == TO_USER) {
132 if (copy_to_user((__force __user void*) dest + offs, buf,
241fd9bc 133 count - offs))
411ed322
MH
134 return -EFAULT;
135 } else
136 memcpy(dest + offs, buf, count - offs);
137out:
138 return 0;
139}
140
141static int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
142{
143 return memcpy_hsa((void __force *) dest, src, count, TO_USER);
144}
145
146static int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
147{
148 return memcpy_hsa(dest, src, count, TO_KERNEL);
149}
150
411ed322
MH
151static int __init init_cpu_info(enum arch_id arch)
152{
a62bc073 153 struct save_area_ext *sa_ext;
411ed322
MH
154
155 /* get info for boot cpu from lowcore, stored in the HSA */
156
a62bc073
MH
157 sa_ext = dump_save_area_create(0);
158 if (!sa_ext)
411ed322 159 return -ENOMEM;
a62bc073
MH
160 if (memcpy_hsa_kernel(&sa_ext->sa, sys_info.sa_base,
161 sys_info.sa_size) < 0) {
2a062ab4 162 TRACE("could not copy from HSA\n");
a62bc073 163 kfree(sa_ext);
411ed322
MH
164 return -EIO;
165 }
a62bc073
MH
166 if (MACHINE_HAS_VX)
167 save_vx_regs_safe(sa_ext->vx_regs);
411ed322
MH
168 return 0;
169}
170
171static DEFINE_MUTEX(zcore_mutex);
172
0cbde8ee 173#define DUMP_VERSION 0x5
411ed322
MH
174#define DUMP_MAGIC 0xa8190173618f23fdULL
175#define DUMP_ARCH_S390X 2
176#define DUMP_ARCH_S390 1
177#define HEADER_SIZE 4096
178
179/* dump header dumped according to s390 crash dump format */
180
181struct zcore_header {
182 u64 magic;
183 u32 version;
184 u32 header_size;
185 u32 dump_level;
186 u32 page_size;
187 u64 mem_size;
188 u64 mem_start;
189 u64 mem_end;
190 u32 num_pages;
191 u32 pad1;
192 u64 tod;
e86a6ed6 193 struct cpuid cpu_id;
411ed322 194 u32 arch_id;
ce444823 195 u32 volnr;
411ed322 196 u32 build_arch;
ce444823 197 u64 rmem_size;
0cbde8ee
MH
198 u8 mvdump;
199 u16 cpu_cnt;
200 u16 real_cpu_cnt;
201 u8 end_pad1[0x200-0x061];
202 u64 mvdump_sign;
203 u64 mvdump_zipl_time;
204 u8 end_pad2[0x800-0x210];
205 u32 lc_vec[512];
411ed322
MH
206} __attribute__((packed,__aligned__(16)));
207
208static struct zcore_header zcore_header = {
209 .magic = DUMP_MAGIC,
210 .version = DUMP_VERSION,
211 .header_size = 4096,
212 .dump_level = 0,
213 .page_size = PAGE_SIZE,
214 .mem_start = 0,
411ed322 215 .build_arch = DUMP_ARCH_S390X,
411ed322
MH
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 */
226static 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 */
247static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
248{
249 unsigned long end;
58952942 250 int i;
411ed322
MH
251
252 if (count == 0)
253 return 0;
254
255 end = start + count;
58952942 256 for (i = 0; i < dump_save_areas.count; i++) {
411ed322
MH
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;
a62bc073 261 struct save_area *save_area = &dump_save_areas.areas[i]->sa;
411ed322 262
58952942 263 prefix = save_area->pref_reg;
411ed322
MH
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))
58952942 268 continue;
411ed322
MH
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);
58952942 277 if (copy_lc(buf + buf_off, save_area, sa_off, len))
411ed322 278 return -EFAULT;
411ed322
MH
279 }
280 return 0;
281}
282
b4b3d128
MH
283/*
284 * Release the HSA
285 */
286static void release_hsa(void)
287{
288 diag308(DIAG308_REL_HSA, NULL);
289 hsa_available = 0;
290}
291
411ed322
MH
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 */
298static 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 */
37c5f6c8 333 if (*ppos < sclp.hsa_size + HEADER_SIZE) {
e657d8fe 334 size = min((count - hdr_count),
37c5f6c8 335 (size_t) (sclp.hsa_size - mem_start));
411ed322
MH
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;
7f0bf656
MH
345 rc = copy_to_user_real(buf + hdr_count + mem_offs,
346 (void *) mem_start + mem_offs, size);
411ed322
MH
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;
363fail:
364 mutex_unlock(&zcore_mutex);
365 return (rc < 0) ? rc : count;
366}
367
368static 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
376static int zcore_release(struct inode *inode, struct file *filep)
377{
b4b3d128
MH
378 if (hsa_available)
379 release_hsa();
411ed322
MH
380 return 0;
381}
382
383static 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
5c81cdbe 404static const struct file_operations zcore_fops = {
411ed322
MH
405 .owner = THIS_MODULE,
406 .llseek = zcore_lseek,
407 .read = zcore_read,
408 .open = zcore_open,
409 .release = zcore_release,
410};
411
12e0c95e
FM
412static 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,
50be6345 416 memblock.memory.cnt * CHUNK_INFO_SIZE);
12e0c95e
FM
417}
418
419static int zcore_memmap_open(struct inode *inode, struct file *filp)
420{
50be6345 421 struct memblock_region *reg;
12e0c95e 422 char *buf;
50be6345 423 int i = 0;
12e0c95e 424
50be6345 425 buf = kzalloc(memblock.memory.cnt * CHUNK_INFO_SIZE, GFP_KERNEL);
12e0c95e 426 if (!buf) {
12e0c95e
FM
427 return -ENOMEM;
428 }
50be6345
PH
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);
12e0c95e 433 }
12e0c95e 434 filp->private_data = buf;
58ea91c0 435 return nonseekable_open(inode, filp);
12e0c95e
FM
436}
437
438static int zcore_memmap_release(struct inode *inode, struct file *filp)
439{
440 kfree(filp->private_data);
441 return 0;
442}
443
444static 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,
6038f373 449 .llseek = no_llseek,
12e0c95e
FM
450};
451
099b7651
FM
452static 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
462static int zcore_reipl_open(struct inode *inode, struct file *filp)
463{
58ea91c0 464 return nonseekable_open(inode, filp);
099b7651
FM
465}
466
467static int zcore_reipl_release(struct inode *inode, struct file *filp)
468{
469 return 0;
470}
471
472static 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,
6038f373 477 .llseek = no_llseek,
099b7651
FM
478};
479
b4b3d128
MH
480static 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)
37c5f6c8 486 snprintf(str, sizeof(str), "%lx\n", sclp.hsa_size);
b4b3d128
MH
487 else
488 snprintf(str, sizeof(str), "0\n");
489 return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
490}
491
492static 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
507static 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
f64ca217 515static void __init set_lc_mask(struct save_area *map)
411ed322 516{
f64ca217
HC
517 memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
518 memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
519 memset(&map->psw, 0xff, sizeof(map->psw));
520 memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
521 memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
522 memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
523 memset(&map->timer, 0xff, sizeof(map->timer));
524 memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
525 memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
526 memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
411ed322
MH
527}
528
529/*
530 * Initialize dump globals for a given architecture
531 */
7b1e427d 532static int __init sys_info_init(enum arch_id arch, unsigned long mem_end)
411ed322 533{
2a062ab4
MH
534 int rc;
535
411ed322
MH
536 switch (arch) {
537 case ARCH_S390X:
17159dc6 538 pr_alert("DETECTED 'S390X (64 bit) OS'\n");
411ed322
MH
539 break;
540 case ARCH_S390:
17159dc6 541 pr_alert("DETECTED 'S390 (32 bit) OS'\n");
411ed322
MH
542 break;
543 default:
17159dc6 544 pr_alert("0x%x is an unknown architecture.\n",arch);
411ed322
MH
545 return -EINVAL;
546 }
f64ca217
HC
547 sys_info.sa_base = SAVE_AREA_BASE;
548 sys_info.sa_size = sizeof(struct save_area);
411ed322 549 sys_info.arch = arch;
f64ca217 550 set_lc_mask(&sys_info.lc_mask);
2a062ab4
MH
551 rc = init_cpu_info(arch);
552 if (rc)
553 return rc;
7b1e427d 554 sys_info.mem_size = mem_end;
411ed322
MH
555
556 return 0;
557}
558
559static int __init check_sdias(void)
560{
37c5f6c8 561 if (!sclp.hsa_size) {
2a062ab4 562 TRACE("Could not determine HSA size\n");
e657d8fe 563 return -ENODEV;
411ed322
MH
564 }
565 return 0;
566}
567
7b1e427d 568static int __init get_mem_info(unsigned long *mem, unsigned long *end)
12e0c95e 569{
50be6345 570 struct memblock_region *reg;
12e0c95e 571
50be6345
PH
572 for_each_memblock(memory, reg) {
573 *mem += reg->size;
574 *end = max_t(unsigned long, *end, reg->base + reg->size);
12e0c95e 575 }
12e0c95e
FM
576 return 0;
577}
578
7b1e427d
HC
579static void __init zcore_header_init(int arch, struct zcore_header *hdr,
580 unsigned long mem_size)
411ed322 581{
0cbde8ee 582 u32 prefix;
7b1e427d 583 int i;
12e0c95e 584
411ed322
MH
585 if (arch == ARCH_S390X)
586 hdr->arch_id = DUMP_ARCH_S390X;
587 else
588 hdr->arch_id = DUMP_ARCH_S390;
7b1e427d
HC
589 hdr->mem_size = mem_size;
590 hdr->rmem_size = mem_size;
411ed322 591 hdr->mem_end = sys_info.mem_size;
7b1e427d 592 hdr->num_pages = mem_size / PAGE_SIZE;
1aae0560 593 hdr->tod = get_tod_clock();
411ed322 594 get_cpu_id(&hdr->cpu_id);
58952942 595 for (i = 0; i < dump_save_areas.count; i++) {
a62bc073 596 prefix = dump_save_areas.areas[i]->sa.pref_reg;
0cbde8ee
MH
597 hdr->real_cpu_cnt++;
598 if (!prefix)
599 continue;
600 hdr->lc_vec[hdr->cpu_cnt] = prefix;
601 hdr->cpu_cnt++;
602 }
411ed322
MH
603}
604
099b7651
FM
605/*
606 * Provide IPL parameter information block from either HSA or memory
607 * for future reipl
608 */
609static int __init zcore_reipl_init(void)
610{
611 struct ipib_info ipib_info;
612 int rc;
613
614 rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
615 if (rc)
616 return rc;
617 if (ipib_info.ipib == 0)
618 return 0;
619 ipl_block = (void *) __get_free_page(GFP_KERNEL);
620 if (!ipl_block)
621 return -ENOMEM;
37c5f6c8 622 if (ipib_info.ipib < sclp.hsa_size)
099b7651
FM
623 rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
624 else
92fe3132 625 rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
76ef964c 626 if (rc || csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
159d1ff8 627 ipib_info.checksum) {
099b7651
FM
628 TRACE("Checksum does not match\n");
629 free_page((unsigned long) ipl_block);
630 ipl_block = NULL;
631 }
632 return 0;
633}
634
411ed322
MH
635static int __init zcore_init(void)
636{
7b1e427d 637 unsigned long mem_size, mem_end;
411ed322
MH
638 unsigned char arch;
639 int rc;
640
7b1e427d 641 mem_size = mem_end = 0;
411ed322
MH
642 if (ipl_info.type != IPL_TYPE_FCP_DUMP)
643 return -ENODATA;
3f25dc4f
MH
644 if (OLDMEM_BASE)
645 return -ENODATA;
411ed322
MH
646
647 zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
648 debug_register_view(zcore_dbf, &debug_sprintf_view);
649 debug_set_level(zcore_dbf, 6);
650
651 TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno);
652 TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
653 TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
654
763968e2 655 rc = sclp_sdias_init();
411ed322
MH
656 if (rc)
657 goto fail;
658
659 rc = check_sdias();
2a062ab4 660 if (rc)
411ed322 661 goto fail;
b4b3d128 662 hsa_available = 1;
411ed322
MH
663
664 rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
2a062ab4 665 if (rc)
411ed322 666 goto fail;
411ed322 667
f64ca217
HC
668 if (arch == ARCH_S390) {
669 pr_alert("The 64-bit dump tool cannot be used for a "
670 "32-bit system\n");
671 rc = -EINVAL;
672 goto fail;
673 }
411ed322 674
7b1e427d 675 rc = get_mem_info(&mem_size, &mem_end);
2a062ab4 676 if (rc)
411ed322 677 goto fail;
411ed322 678
7b1e427d 679 rc = sys_info_init(arch, mem_end);
12e0c95e
FM
680 if (rc)
681 goto fail;
7b1e427d 682 zcore_header_init(arch, &zcore_header, mem_size);
411ed322 683
099b7651
FM
684 rc = zcore_reipl_init();
685 if (rc)
686 goto fail;
687
411ed322
MH
688 zcore_dir = debugfs_create_dir("zcore" , NULL);
689 if (!zcore_dir) {
690 rc = -ENOMEM;
691 goto fail;
692 }
693 zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL,
694 &zcore_fops);
695 if (!zcore_file) {
411ed322 696 rc = -ENOMEM;
12e0c95e
FM
697 goto fail_dir;
698 }
699 zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
700 NULL, &zcore_memmap_fops);
701 if (!zcore_memmap_file) {
702 rc = -ENOMEM;
703 goto fail_file;
411ed322 704 }
099b7651
FM
705 zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
706 NULL, &zcore_reipl_fops);
707 if (!zcore_reipl_file) {
708 rc = -ENOMEM;
709 goto fail_memmap_file;
710 }
b4b3d128
MH
711 zcore_hsa_file = debugfs_create_file("hsa", S_IRUSR|S_IWUSR, zcore_dir,
712 NULL, &zcore_hsa_fops);
713 if (!zcore_hsa_file) {
714 rc = -ENOMEM;
715 goto fail_reipl_file;
716 }
411ed322
MH
717 return 0;
718
b4b3d128
MH
719fail_reipl_file:
720 debugfs_remove(zcore_reipl_file);
099b7651
FM
721fail_memmap_file:
722 debugfs_remove(zcore_memmap_file);
12e0c95e
FM
723fail_file:
724 debugfs_remove(zcore_file);
725fail_dir:
726 debugfs_remove(zcore_dir);
411ed322
MH
727fail:
728 diag308(DIAG308_REL_HSA, NULL);
729 return rc;
730}
731
411ed322
MH
732static void __exit zcore_exit(void)
733{
734 debug_unregister(zcore_dbf);
763968e2 735 sclp_sdias_exit();
099b7651 736 free_page((unsigned long) ipl_block);
b4b3d128 737 debugfs_remove(zcore_hsa_file);
099b7651
FM
738 debugfs_remove(zcore_reipl_file);
739 debugfs_remove(zcore_memmap_file);
740 debugfs_remove(zcore_file);
741 debugfs_remove(zcore_dir);
411ed322
MH
742 diag308(DIAG308_REL_HSA, NULL);
743}
744
099b7651 745MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
411ed322
MH
746MODULE_DESCRIPTION("zcore module for zfcpdump support");
747MODULE_LICENSE("GPL");
748
749subsys_initcall(zcore_init);
750module_exit(zcore_exit);
This page took 1.068291 seconds and 5 git commands to generate.