blob: 3d8e4d63f51418c876f9918e0be77be628d2afb3 [file] [log] [blame]
Michael Holzheu411ed322007-04-27 16:01:49 +02001/*
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 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02008 * Copyright IBM Corp. 2003, 2008
Michael Holzheu411ed322007-04-27 16:01:49 +02009 * Author(s): Michael Holzheu
10 */
11
Michael Holzheu17159dc62008-12-25 13:39:51 +010012#define KMSG_COMPONENT "zdump"
13#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14
Michael Holzheu411ed322007-04-27 16:01:49 +020015#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020017#include <linux/miscdevice.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020018#include <linux/debugfs.h>
Heiko Carstens3948a102011-10-30 15:16:55 +010019#include <linux/module.h>
Heiko Carstenscbb870c2010-02-26 22:37:43 +010020#include <asm/asm-offsets.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020021#include <asm/ipl.h>
22#include <asm/sclp.h>
23#include <asm/setup.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020024#include <asm/uaccess.h>
25#include <asm/debug.h>
26#include <asm/processor.h>
27#include <asm/irqflags.h>
Frank Munzert159d1ff2009-03-26 15:24:45 +010028#include <asm/checksum.h>
Heiko Carstens763968e2007-05-10 15:45:46 +020029#include "sclp.h"
Michael Holzheu411ed322007-04-27 16:01:49 +020030
31#define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
Michael Holzheu411ed322007-04-27 16:01:49 +020032
Michael Holzheu6f79d332013-09-11 14:24:54 -070033#define TO_USER 1
34#define TO_KERNEL 0
Frank Munzert12e0c952008-07-17 17:16:40 +020035#define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
Michael Holzheu411ed322007-04-27 16:01:49 +020036
37enum arch_id {
38 ARCH_S390 = 0,
39 ARCH_S390X = 1,
40};
41
42/* dump system info */
43
44struct sys_info {
Heiko Carstensf64ca212010-02-26 22:37:32 +010045 enum arch_id arch;
46 unsigned long sa_base;
47 u32 sa_size;
48 int cpu_map[NR_CPUS];
49 unsigned long mem_size;
50 struct save_area lc_mask;
Michael Holzheu411ed322007-04-27 16:01:49 +020051};
52
Frank Munzert099b7652009-03-26 15:23:43 +010053struct ipib_info {
54 unsigned long ipib;
55 u32 checksum;
56} __attribute__((packed));
57
Michael Holzheu411ed322007-04-27 16:01:49 +020058static struct sys_info sys_info;
59static struct debug_info *zcore_dbf;
60static int hsa_available;
61static struct dentry *zcore_dir;
62static struct dentry *zcore_file;
Frank Munzert12e0c952008-07-17 17:16:40 +020063static struct dentry *zcore_memmap_file;
Frank Munzert099b7652009-03-26 15:23:43 +010064static struct dentry *zcore_reipl_file;
Michael Holzheub4b3d122013-01-21 18:37:41 +010065static struct dentry *zcore_hsa_file;
Frank Munzert099b7652009-03-26 15:23:43 +010066static struct ipl_parameter_block *ipl_block;
Michael Holzheu411ed322007-04-27 16:01:49 +020067
68/*
69 * Copy memory from HSA to kernel or user memory (not reentrant):
70 *
71 * @dest: Kernel or user buffer where memory should be copied to
72 * @src: Start address within HSA where data should be copied
73 * @count: Size of buffer, which should be copied
74 * @mode: Either TO_KERNEL or TO_USER
75 */
Michael Holzheu6f79d332013-09-11 14:24:54 -070076int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode)
Michael Holzheu411ed322007-04-27 16:01:49 +020077{
78 int offs, blk_num;
79 static char buf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
80
Michael Holzheub4b3d122013-01-21 18:37:41 +010081 if (!hsa_available)
82 return -ENODATA;
Michael Holzheu411ed322007-04-27 16:01:49 +020083 if (count == 0)
84 return 0;
85
86 /* copy first block */
87 offs = 0;
88 if ((src % PAGE_SIZE) != 0) {
89 blk_num = src / PAGE_SIZE + 2;
90 if (sclp_sdias_copy(buf, blk_num, 1)) {
91 TRACE("sclp_sdias_copy() failed\n");
92 return -EIO;
93 }
94 offs = min((PAGE_SIZE - (src % PAGE_SIZE)), count);
95 if (mode == TO_USER) {
96 if (copy_to_user((__force __user void*) dest,
97 buf + (src % PAGE_SIZE), offs))
98 return -EFAULT;
99 } else
100 memcpy(dest, buf + (src % PAGE_SIZE), offs);
101 }
102 if (offs == count)
103 goto out;
104
105 /* copy middle */
106 for (; (offs + PAGE_SIZE) <= count; offs += PAGE_SIZE) {
107 blk_num = (src + offs) / PAGE_SIZE + 2;
108 if (sclp_sdias_copy(buf, blk_num, 1)) {
109 TRACE("sclp_sdias_copy() failed\n");
110 return -EIO;
111 }
112 if (mode == TO_USER) {
113 if (copy_to_user((__force __user void*) dest + offs,
114 buf, PAGE_SIZE))
115 return -EFAULT;
116 } else
117 memcpy(dest + offs, buf, PAGE_SIZE);
118 }
119 if (offs == count)
120 goto out;
121
122 /* copy last block */
123 blk_num = (src + offs) / PAGE_SIZE + 2;
124 if (sclp_sdias_copy(buf, blk_num, 1)) {
125 TRACE("sclp_sdias_copy() failed\n");
126 return -EIO;
127 }
128 if (mode == TO_USER) {
129 if (copy_to_user((__force __user void*) dest + offs, buf,
Michael Holzheu241fd9b2013-04-19 18:03:02 +0200130 count - offs))
Michael Holzheu411ed322007-04-27 16:01:49 +0200131 return -EFAULT;
132 } else
133 memcpy(dest + offs, buf, count - offs);
134out:
135 return 0;
136}
137
138static int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
139{
140 return memcpy_hsa((void __force *) dest, src, count, TO_USER);
141}
142
143static int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
144{
145 return memcpy_hsa(dest, src, count, TO_KERNEL);
146}
147
Michael Holzheu411ed322007-04-27 16:01:49 +0200148static int __init init_cpu_info(enum arch_id arch)
149{
Heiko Carstensf64ca212010-02-26 22:37:32 +0100150 struct save_area *sa;
Michael Holzheu411ed322007-04-27 16:01:49 +0200151
152 /* get info for boot cpu from lowcore, stored in the HSA */
153
Michael Holzheu58952942013-10-11 10:29:23 +0200154 sa = dump_save_area_create(0);
Michael Holzheu2a062ab2008-07-14 09:59:38 +0200155 if (!sa)
Michael Holzheu411ed322007-04-27 16:01:49 +0200156 return -ENOMEM;
Michael Holzheu411ed322007-04-27 16:01:49 +0200157 if (memcpy_hsa_kernel(sa, sys_info.sa_base, sys_info.sa_size) < 0) {
Michael Holzheu2a062ab2008-07-14 09:59:38 +0200158 TRACE("could not copy from HSA\n");
Michael Holzheu411ed322007-04-27 16:01:49 +0200159 kfree(sa);
160 return -EIO;
161 }
Michael Holzheu411ed322007-04-27 16:01:49 +0200162 return 0;
163}
164
165static DEFINE_MUTEX(zcore_mutex);
166
Michael Holzheu0cbde8e2010-02-26 22:37:55 +0100167#define DUMP_VERSION 0x5
Michael Holzheu411ed322007-04-27 16:01:49 +0200168#define DUMP_MAGIC 0xa8190173618f23fdULL
169#define DUMP_ARCH_S390X 2
170#define DUMP_ARCH_S390 1
171#define HEADER_SIZE 4096
172
173/* dump header dumped according to s390 crash dump format */
174
175struct zcore_header {
176 u64 magic;
177 u32 version;
178 u32 header_size;
179 u32 dump_level;
180 u32 page_size;
181 u64 mem_size;
182 u64 mem_start;
183 u64 mem_end;
184 u32 num_pages;
185 u32 pad1;
186 u64 tod;
Heiko Carstense86a6ed2009-09-11 10:29:04 +0200187 struct cpuid cpu_id;
Michael Holzheu411ed322007-04-27 16:01:49 +0200188 u32 arch_id;
Michael Holzheuce444822007-06-19 13:10:02 +0200189 u32 volnr;
Michael Holzheu411ed322007-04-27 16:01:49 +0200190 u32 build_arch;
Michael Holzheuce444822007-06-19 13:10:02 +0200191 u64 rmem_size;
Michael Holzheu0cbde8e2010-02-26 22:37:55 +0100192 u8 mvdump;
193 u16 cpu_cnt;
194 u16 real_cpu_cnt;
195 u8 end_pad1[0x200-0x061];
196 u64 mvdump_sign;
197 u64 mvdump_zipl_time;
198 u8 end_pad2[0x800-0x210];
199 u32 lc_vec[512];
Michael Holzheu411ed322007-04-27 16:01:49 +0200200} __attribute__((packed,__aligned__(16)));
201
202static struct zcore_header zcore_header = {
203 .magic = DUMP_MAGIC,
204 .version = DUMP_VERSION,
205 .header_size = 4096,
206 .dump_level = 0,
207 .page_size = PAGE_SIZE,
208 .mem_start = 0,
Heiko Carstensf64ca212010-02-26 22:37:32 +0100209#ifdef CONFIG_64BIT
Michael Holzheu411ed322007-04-27 16:01:49 +0200210 .build_arch = DUMP_ARCH_S390X,
211#else
212 .build_arch = DUMP_ARCH_S390,
213#endif
214};
215
216/*
217 * Copy lowcore info to buffer. Use map in order to copy only register parts.
218 *
219 * @buf: User buffer
220 * @sa: Pointer to save area
221 * @sa_off: Offset in save area to copy
222 * @len: Number of bytes to copy
223 */
224static int copy_lc(void __user *buf, void *sa, int sa_off, int len)
225{
226 int i;
227 char *lc_mask = (char*)&sys_info.lc_mask;
228
229 for (i = 0; i < len; i++) {
230 if (!lc_mask[i + sa_off])
231 continue;
232 if (copy_to_user(buf + i, sa + sa_off + i, 1))
233 return -EFAULT;
234 }
235 return 0;
236}
237
238/*
239 * Copy lowcores info to memory, if necessary
240 *
241 * @buf: User buffer
242 * @addr: Start address of buffer in dump memory
243 * @count: Size of buffer
244 */
245static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
246{
247 unsigned long end;
Michael Holzheu58952942013-10-11 10:29:23 +0200248 int i;
Michael Holzheu411ed322007-04-27 16:01:49 +0200249
250 if (count == 0)
251 return 0;
252
253 end = start + count;
Michael Holzheu58952942013-10-11 10:29:23 +0200254 for (i = 0; i < dump_save_areas.count; i++) {
Michael Holzheu411ed322007-04-27 16:01:49 +0200255 unsigned long cp_start, cp_end; /* copy range */
256 unsigned long sa_start, sa_end; /* save area range */
257 unsigned long prefix;
258 unsigned long sa_off, len, buf_off;
Michael Holzheu58952942013-10-11 10:29:23 +0200259 struct save_area *save_area = dump_save_areas.areas[i];
Michael Holzheu411ed322007-04-27 16:01:49 +0200260
Michael Holzheu58952942013-10-11 10:29:23 +0200261 prefix = save_area->pref_reg;
Michael Holzheu411ed322007-04-27 16:01:49 +0200262 sa_start = prefix + sys_info.sa_base;
263 sa_end = prefix + sys_info.sa_base + sys_info.sa_size;
264
265 if ((end < sa_start) || (start > sa_end))
Michael Holzheu58952942013-10-11 10:29:23 +0200266 continue;
Michael Holzheu411ed322007-04-27 16:01:49 +0200267 cp_start = max(start, sa_start);
268 cp_end = min(end, sa_end);
269
270 buf_off = cp_start - start;
271 sa_off = cp_start - sa_start;
272 len = cp_end - cp_start;
273
274 TRACE("copy_lc for: %lx\n", start);
Michael Holzheu58952942013-10-11 10:29:23 +0200275 if (copy_lc(buf + buf_off, save_area, sa_off, len))
Michael Holzheu411ed322007-04-27 16:01:49 +0200276 return -EFAULT;
Michael Holzheu411ed322007-04-27 16:01:49 +0200277 }
278 return 0;
279}
280
281/*
Michael Holzheub4b3d122013-01-21 18:37:41 +0100282 * Release the HSA
283 */
284static void release_hsa(void)
285{
286 diag308(DIAG308_REL_HSA, NULL);
287 hsa_available = 0;
288}
289
290/*
Michael Holzheu411ed322007-04-27 16:01:49 +0200291 * Read routine for zcore character device
292 * First 4K are dump header
293 * Next 32MB are HSA Memory
294 * Rest is read from absolute Memory
295 */
296static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
297 loff_t *ppos)
298{
299 unsigned long mem_start; /* Start address in memory */
300 size_t mem_offs; /* Offset in dump memory */
301 size_t hdr_count; /* Size of header part of output buffer */
302 size_t size;
303 int rc;
304
305 mutex_lock(&zcore_mutex);
306
307 if (*ppos > (sys_info.mem_size + HEADER_SIZE)) {
308 rc = -EINVAL;
309 goto fail;
310 }
311
312 count = min(count, (size_t) (sys_info.mem_size + HEADER_SIZE - *ppos));
313
314 /* Copy dump header */
315 if (*ppos < HEADER_SIZE) {
316 size = min(count, (size_t) (HEADER_SIZE - *ppos));
317 if (copy_to_user(buf, &zcore_header + *ppos, size)) {
318 rc = -EFAULT;
319 goto fail;
320 }
321 hdr_count = size;
322 mem_start = 0;
323 } else {
324 hdr_count = 0;
325 mem_start = *ppos - HEADER_SIZE;
326 }
327
328 mem_offs = 0;
329
330 /* Copy from HSA data */
Michael Holzheue657d8f2013-11-13 10:38:27 +0100331 if (*ppos < sclp_get_hsa_size() + HEADER_SIZE) {
332 size = min((count - hdr_count),
333 (size_t) (sclp_get_hsa_size() - mem_start));
Michael Holzheu411ed322007-04-27 16:01:49 +0200334 rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
335 if (rc)
336 goto fail;
337
338 mem_offs += size;
339 }
340
341 /* Copy from real mem */
342 size = count - mem_offs - hdr_count;
Michael Holzheu7f0bf6562011-10-30 15:16:39 +0100343 rc = copy_to_user_real(buf + hdr_count + mem_offs,
344 (void *) mem_start + mem_offs, size);
Michael Holzheu411ed322007-04-27 16:01:49 +0200345 if (rc)
346 goto fail;
347
348 /*
349 * Since s390 dump analysis tools like lcrash or crash
350 * expect register sets in the prefix pages of the cpus,
351 * we copy them into the read buffer, if necessary.
352 * buf + hdr_count: Start of memory part of output buffer
353 * mem_start: Start memory address to copy from
354 * count - hdr_count: Size of memory area to copy
355 */
356 if (zcore_add_lc(buf + hdr_count, mem_start, count - hdr_count)) {
357 rc = -EFAULT;
358 goto fail;
359 }
360 *ppos += count;
361fail:
362 mutex_unlock(&zcore_mutex);
363 return (rc < 0) ? rc : count;
364}
365
366static int zcore_open(struct inode *inode, struct file *filp)
367{
368 if (!hsa_available)
369 return -ENODATA;
370 else
371 return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
372}
373
374static int zcore_release(struct inode *inode, struct file *filep)
375{
Michael Holzheub4b3d122013-01-21 18:37:41 +0100376 if (hsa_available)
377 release_hsa();
Michael Holzheu411ed322007-04-27 16:01:49 +0200378 return 0;
379}
380
381static loff_t zcore_lseek(struct file *file, loff_t offset, int orig)
382{
383 loff_t rc;
384
385 mutex_lock(&zcore_mutex);
386 switch (orig) {
387 case 0:
388 file->f_pos = offset;
389 rc = file->f_pos;
390 break;
391 case 1:
392 file->f_pos += offset;
393 rc = file->f_pos;
394 break;
395 default:
396 rc = -EINVAL;
397 }
398 mutex_unlock(&zcore_mutex);
399 return rc;
400}
401
Jan Engelhardt5c81cdb2008-01-26 14:11:29 +0100402static const struct file_operations zcore_fops = {
Michael Holzheu411ed322007-04-27 16:01:49 +0200403 .owner = THIS_MODULE,
404 .llseek = zcore_lseek,
405 .read = zcore_read,
406 .open = zcore_open,
407 .release = zcore_release,
408};
409
Frank Munzert12e0c952008-07-17 17:16:40 +0200410static ssize_t zcore_memmap_read(struct file *filp, char __user *buf,
411 size_t count, loff_t *ppos)
412{
413 return simple_read_from_buffer(buf, count, ppos, filp->private_data,
414 MEMORY_CHUNKS * CHUNK_INFO_SIZE);
415}
416
417static int zcore_memmap_open(struct inode *inode, struct file *filp)
418{
419 int i;
420 char *buf;
421 struct mem_chunk *chunk_array;
422
423 chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
424 GFP_KERNEL);
425 if (!chunk_array)
426 return -ENOMEM;
Heiko Carstensdf1bd592013-04-30 10:34:04 +0200427 detect_memory_layout(chunk_array, 0);
Frank Munzert12e0c952008-07-17 17:16:40 +0200428 buf = kzalloc(MEMORY_CHUNKS * CHUNK_INFO_SIZE, GFP_KERNEL);
429 if (!buf) {
430 kfree(chunk_array);
431 return -ENOMEM;
432 }
433 for (i = 0; i < MEMORY_CHUNKS; i++) {
434 sprintf(buf + (i * CHUNK_INFO_SIZE), "%016llx %016llx ",
435 (unsigned long long) chunk_array[i].addr,
436 (unsigned long long) chunk_array[i].size);
437 if (chunk_array[i].size == 0)
438 break;
439 }
440 kfree(chunk_array);
441 filp->private_data = buf;
Martin Schwidefsky58ea91c2010-05-17 10:00:07 +0200442 return nonseekable_open(inode, filp);
Frank Munzert12e0c952008-07-17 17:16:40 +0200443}
444
445static int zcore_memmap_release(struct inode *inode, struct file *filp)
446{
447 kfree(filp->private_data);
448 return 0;
449}
450
451static const struct file_operations zcore_memmap_fops = {
452 .owner = THIS_MODULE,
453 .read = zcore_memmap_read,
454 .open = zcore_memmap_open,
455 .release = zcore_memmap_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200456 .llseek = no_llseek,
Frank Munzert12e0c952008-07-17 17:16:40 +0200457};
458
Frank Munzert099b7652009-03-26 15:23:43 +0100459static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
460 size_t count, loff_t *ppos)
461{
462 if (ipl_block) {
463 diag308(DIAG308_SET, ipl_block);
464 diag308(DIAG308_IPL, NULL);
465 }
466 return count;
467}
468
469static int zcore_reipl_open(struct inode *inode, struct file *filp)
470{
Martin Schwidefsky58ea91c2010-05-17 10:00:07 +0200471 return nonseekable_open(inode, filp);
Frank Munzert099b7652009-03-26 15:23:43 +0100472}
473
474static int zcore_reipl_release(struct inode *inode, struct file *filp)
475{
476 return 0;
477}
478
479static const struct file_operations zcore_reipl_fops = {
480 .owner = THIS_MODULE,
481 .write = zcore_reipl_write,
482 .open = zcore_reipl_open,
483 .release = zcore_reipl_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200484 .llseek = no_llseek,
Frank Munzert099b7652009-03-26 15:23:43 +0100485};
486
Michael Holzheub4b3d122013-01-21 18:37:41 +0100487static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
488 size_t count, loff_t *ppos)
489{
490 static char str[18];
491
492 if (hsa_available)
Michael Holzheue657d8f2013-11-13 10:38:27 +0100493 snprintf(str, sizeof(str), "%lx\n", sclp_get_hsa_size());
Michael Holzheub4b3d122013-01-21 18:37:41 +0100494 else
495 snprintf(str, sizeof(str), "0\n");
496 return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
497}
498
499static ssize_t zcore_hsa_write(struct file *filp, const char __user *buf,
500 size_t count, loff_t *ppos)
501{
502 char value;
503
504 if (*ppos != 0)
505 return -EPIPE;
506 if (copy_from_user(&value, buf, 1))
507 return -EFAULT;
508 if (value != '0')
509 return -EINVAL;
510 release_hsa();
511 return count;
512}
513
514static const struct file_operations zcore_hsa_fops = {
515 .owner = THIS_MODULE,
516 .write = zcore_hsa_write,
517 .read = zcore_hsa_read,
518 .open = nonseekable_open,
519 .llseek = no_llseek,
520};
521
Heiko Carstensf64ca212010-02-26 22:37:32 +0100522#ifdef CONFIG_32BIT
Michael Holzheu411ed322007-04-27 16:01:49 +0200523
Heiko Carstensf64ca212010-02-26 22:37:32 +0100524static void __init set_lc_mask(struct save_area *map)
Michael Holzheu411ed322007-04-27 16:01:49 +0200525{
Heiko Carstensf64ca212010-02-26 22:37:32 +0100526 memset(&map->ext_save, 0xff, sizeof(map->ext_save));
527 memset(&map->timer, 0xff, sizeof(map->timer));
528 memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
529 memset(&map->psw, 0xff, sizeof(map->psw));
530 memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
531 memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
532 memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
533 memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
534 memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
Michael Holzheu411ed322007-04-27 16:01:49 +0200535}
536
Heiko Carstensf64ca212010-02-26 22:37:32 +0100537#else /* CONFIG_32BIT */
538
539static void __init set_lc_mask(struct save_area *map)
Michael Holzheu411ed322007-04-27 16:01:49 +0200540{
Heiko Carstensf64ca212010-02-26 22:37:32 +0100541 memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
542 memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
543 memset(&map->psw, 0xff, sizeof(map->psw));
544 memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
545 memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
546 memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
547 memset(&map->timer, 0xff, sizeof(map->timer));
548 memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
549 memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
550 memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
Michael Holzheu411ed322007-04-27 16:01:49 +0200551}
552
Heiko Carstensf64ca212010-02-26 22:37:32 +0100553#endif /* CONFIG_32BIT */
554
Michael Holzheu411ed322007-04-27 16:01:49 +0200555/*
556 * Initialize dump globals for a given architecture
557 */
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200558static int __init sys_info_init(enum arch_id arch, unsigned long mem_end)
Michael Holzheu411ed322007-04-27 16:01:49 +0200559{
Michael Holzheu2a062ab2008-07-14 09:59:38 +0200560 int rc;
561
Michael Holzheu411ed322007-04-27 16:01:49 +0200562 switch (arch) {
563 case ARCH_S390X:
Michael Holzheu17159dc62008-12-25 13:39:51 +0100564 pr_alert("DETECTED 'S390X (64 bit) OS'\n");
Michael Holzheu411ed322007-04-27 16:01:49 +0200565 break;
566 case ARCH_S390:
Michael Holzheu17159dc62008-12-25 13:39:51 +0100567 pr_alert("DETECTED 'S390 (32 bit) OS'\n");
Michael Holzheu411ed322007-04-27 16:01:49 +0200568 break;
569 default:
Michael Holzheu17159dc62008-12-25 13:39:51 +0100570 pr_alert("0x%x is an unknown architecture.\n",arch);
Michael Holzheu411ed322007-04-27 16:01:49 +0200571 return -EINVAL;
572 }
Heiko Carstensf64ca212010-02-26 22:37:32 +0100573 sys_info.sa_base = SAVE_AREA_BASE;
574 sys_info.sa_size = sizeof(struct save_area);
Michael Holzheu411ed322007-04-27 16:01:49 +0200575 sys_info.arch = arch;
Heiko Carstensf64ca212010-02-26 22:37:32 +0100576 set_lc_mask(&sys_info.lc_mask);
Michael Holzheu2a062ab2008-07-14 09:59:38 +0200577 rc = init_cpu_info(arch);
578 if (rc)
579 return rc;
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200580 sys_info.mem_size = mem_end;
Michael Holzheu411ed322007-04-27 16:01:49 +0200581
582 return 0;
583}
584
585static int __init check_sdias(void)
586{
Michael Holzheue657d8f2013-11-13 10:38:27 +0100587 if (!sclp_get_hsa_size()) {
Michael Holzheu2a062ab2008-07-14 09:59:38 +0200588 TRACE("Could not determine HSA size\n");
Michael Holzheue657d8f2013-11-13 10:38:27 +0100589 return -ENODEV;
Michael Holzheu411ed322007-04-27 16:01:49 +0200590 }
591 return 0;
592}
593
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200594static int __init get_mem_info(unsigned long *mem, unsigned long *end)
Michael Holzheu411ed322007-04-27 16:01:49 +0200595{
Frank Munzert12e0c952008-07-17 17:16:40 +0200596 int i;
597 struct mem_chunk *chunk_array;
598
599 chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
600 GFP_KERNEL);
601 if (!chunk_array)
602 return -ENOMEM;
Heiko Carstensdf1bd592013-04-30 10:34:04 +0200603 detect_memory_layout(chunk_array, 0);
Frank Munzert12e0c952008-07-17 17:16:40 +0200604 for (i = 0; i < MEMORY_CHUNKS; i++) {
605 if (chunk_array[i].size == 0)
606 break;
607 *mem += chunk_array[i].size;
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200608 *end = max(*end, chunk_array[i].addr + chunk_array[i].size);
Frank Munzert12e0c952008-07-17 17:16:40 +0200609 }
610 kfree(chunk_array);
611 return 0;
612}
613
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200614static void __init zcore_header_init(int arch, struct zcore_header *hdr,
615 unsigned long mem_size)
Frank Munzert12e0c952008-07-17 17:16:40 +0200616{
Michael Holzheu0cbde8e2010-02-26 22:37:55 +0100617 u32 prefix;
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200618 int i;
Frank Munzert12e0c952008-07-17 17:16:40 +0200619
Michael Holzheu411ed322007-04-27 16:01:49 +0200620 if (arch == ARCH_S390X)
621 hdr->arch_id = DUMP_ARCH_S390X;
622 else
623 hdr->arch_id = DUMP_ARCH_S390;
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200624 hdr->mem_size = mem_size;
625 hdr->rmem_size = mem_size;
Michael Holzheu411ed322007-04-27 16:01:49 +0200626 hdr->mem_end = sys_info.mem_size;
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200627 hdr->num_pages = mem_size / PAGE_SIZE;
Heiko Carstens1aae0562013-01-30 09:49:40 +0100628 hdr->tod = get_tod_clock();
Michael Holzheu411ed322007-04-27 16:01:49 +0200629 get_cpu_id(&hdr->cpu_id);
Michael Holzheu58952942013-10-11 10:29:23 +0200630 for (i = 0; i < dump_save_areas.count; i++) {
631 prefix = dump_save_areas.areas[i]->pref_reg;
Michael Holzheu0cbde8e2010-02-26 22:37:55 +0100632 hdr->real_cpu_cnt++;
633 if (!prefix)
634 continue;
635 hdr->lc_vec[hdr->cpu_cnt] = prefix;
636 hdr->cpu_cnt++;
637 }
Michael Holzheu411ed322007-04-27 16:01:49 +0200638}
639
Frank Munzert099b7652009-03-26 15:23:43 +0100640/*
641 * Provide IPL parameter information block from either HSA or memory
642 * for future reipl
643 */
644static int __init zcore_reipl_init(void)
645{
646 struct ipib_info ipib_info;
647 int rc;
648
649 rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
650 if (rc)
651 return rc;
652 if (ipib_info.ipib == 0)
653 return 0;
654 ipl_block = (void *) __get_free_page(GFP_KERNEL);
655 if (!ipl_block)
656 return -ENOMEM;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100657 if (ipib_info.ipib < sclp_get_hsa_size())
Frank Munzert099b7652009-03-26 15:23:43 +0100658 rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
659 else
Michael Holzheu92fe3132010-03-24 11:49:50 +0100660 rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
Michael Holzheu76ef9642010-04-22 17:17:07 +0200661 if (rc || csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
Frank Munzert159d1ff2009-03-26 15:24:45 +0100662 ipib_info.checksum) {
Frank Munzert099b7652009-03-26 15:23:43 +0100663 TRACE("Checksum does not match\n");
664 free_page((unsigned long) ipl_block);
665 ipl_block = NULL;
666 }
667 return 0;
668}
669
Michael Holzheu411ed322007-04-27 16:01:49 +0200670static int __init zcore_init(void)
671{
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200672 unsigned long mem_size, mem_end;
Michael Holzheu411ed322007-04-27 16:01:49 +0200673 unsigned char arch;
674 int rc;
675
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200676 mem_size = mem_end = 0;
Michael Holzheu411ed322007-04-27 16:01:49 +0200677 if (ipl_info.type != IPL_TYPE_FCP_DUMP)
678 return -ENODATA;
Michael Holzheu3f25dc42011-11-14 11:19:05 +0100679 if (OLDMEM_BASE)
680 return -ENODATA;
Michael Holzheu411ed322007-04-27 16:01:49 +0200681
682 zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
683 debug_register_view(zcore_dbf, &debug_sprintf_view);
684 debug_set_level(zcore_dbf, 6);
685
686 TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno);
687 TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
688 TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
689
Heiko Carstens763968e2007-05-10 15:45:46 +0200690 rc = sclp_sdias_init();
Michael Holzheu411ed322007-04-27 16:01:49 +0200691 if (rc)
692 goto fail;
693
694 rc = check_sdias();
Michael Holzheu2a062ab2008-07-14 09:59:38 +0200695 if (rc)
Michael Holzheu411ed322007-04-27 16:01:49 +0200696 goto fail;
Michael Holzheub4b3d122013-01-21 18:37:41 +0100697 hsa_available = 1;
Michael Holzheu411ed322007-04-27 16:01:49 +0200698
699 rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
Michael Holzheu2a062ab2008-07-14 09:59:38 +0200700 if (rc)
Michael Holzheu411ed322007-04-27 16:01:49 +0200701 goto fail;
Michael Holzheu411ed322007-04-27 16:01:49 +0200702
Heiko Carstensf64ca212010-02-26 22:37:32 +0100703#ifdef CONFIG_64BIT
704 if (arch == ARCH_S390) {
705 pr_alert("The 64-bit dump tool cannot be used for a "
706 "32-bit system\n");
707 rc = -EINVAL;
708 goto fail;
709 }
710#else /* CONFIG_64BIT */
Michael Holzheu411ed322007-04-27 16:01:49 +0200711 if (arch == ARCH_S390X) {
Michael Holzheu17159dc62008-12-25 13:39:51 +0100712 pr_alert("The 32-bit dump tool cannot be used for a "
713 "64-bit system\n");
Michael Holzheu411ed322007-04-27 16:01:49 +0200714 rc = -EINVAL;
715 goto fail;
716 }
Heiko Carstensf64ca212010-02-26 22:37:32 +0100717#endif /* CONFIG_64BIT */
Michael Holzheu411ed322007-04-27 16:01:49 +0200718
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200719 rc = get_mem_info(&mem_size, &mem_end);
Michael Holzheu2a062ab2008-07-14 09:59:38 +0200720 if (rc)
Michael Holzheu411ed322007-04-27 16:01:49 +0200721 goto fail;
Michael Holzheu411ed322007-04-27 16:01:49 +0200722
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200723 rc = sys_info_init(arch, mem_end);
Frank Munzert12e0c952008-07-17 17:16:40 +0200724 if (rc)
725 goto fail;
Heiko Carstens7b1e4272013-04-27 13:43:34 +0200726 zcore_header_init(arch, &zcore_header, mem_size);
Michael Holzheu411ed322007-04-27 16:01:49 +0200727
Frank Munzert099b7652009-03-26 15:23:43 +0100728 rc = zcore_reipl_init();
729 if (rc)
730 goto fail;
731
Michael Holzheu411ed322007-04-27 16:01:49 +0200732 zcore_dir = debugfs_create_dir("zcore" , NULL);
733 if (!zcore_dir) {
734 rc = -ENOMEM;
735 goto fail;
736 }
737 zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL,
738 &zcore_fops);
739 if (!zcore_file) {
Michael Holzheu411ed322007-04-27 16:01:49 +0200740 rc = -ENOMEM;
Frank Munzert12e0c952008-07-17 17:16:40 +0200741 goto fail_dir;
742 }
743 zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
744 NULL, &zcore_memmap_fops);
745 if (!zcore_memmap_file) {
746 rc = -ENOMEM;
747 goto fail_file;
Michael Holzheu411ed322007-04-27 16:01:49 +0200748 }
Frank Munzert099b7652009-03-26 15:23:43 +0100749 zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
750 NULL, &zcore_reipl_fops);
751 if (!zcore_reipl_file) {
752 rc = -ENOMEM;
753 goto fail_memmap_file;
754 }
Michael Holzheub4b3d122013-01-21 18:37:41 +0100755 zcore_hsa_file = debugfs_create_file("hsa", S_IRUSR|S_IWUSR, zcore_dir,
756 NULL, &zcore_hsa_fops);
757 if (!zcore_hsa_file) {
758 rc = -ENOMEM;
759 goto fail_reipl_file;
760 }
Michael Holzheu411ed322007-04-27 16:01:49 +0200761 return 0;
762
Michael Holzheub4b3d122013-01-21 18:37:41 +0100763fail_reipl_file:
764 debugfs_remove(zcore_reipl_file);
Frank Munzert099b7652009-03-26 15:23:43 +0100765fail_memmap_file:
766 debugfs_remove(zcore_memmap_file);
Frank Munzert12e0c952008-07-17 17:16:40 +0200767fail_file:
768 debugfs_remove(zcore_file);
769fail_dir:
770 debugfs_remove(zcore_dir);
Michael Holzheu411ed322007-04-27 16:01:49 +0200771fail:
772 diag308(DIAG308_REL_HSA, NULL);
773 return rc;
774}
775
Michael Holzheu411ed322007-04-27 16:01:49 +0200776static void __exit zcore_exit(void)
777{
778 debug_unregister(zcore_dbf);
Heiko Carstens763968e2007-05-10 15:45:46 +0200779 sclp_sdias_exit();
Frank Munzert099b7652009-03-26 15:23:43 +0100780 free_page((unsigned long) ipl_block);
Michael Holzheub4b3d122013-01-21 18:37:41 +0100781 debugfs_remove(zcore_hsa_file);
Frank Munzert099b7652009-03-26 15:23:43 +0100782 debugfs_remove(zcore_reipl_file);
783 debugfs_remove(zcore_memmap_file);
784 debugfs_remove(zcore_file);
785 debugfs_remove(zcore_dir);
Michael Holzheu411ed322007-04-27 16:01:49 +0200786 diag308(DIAG308_REL_HSA, NULL);
787}
788
Frank Munzert099b7652009-03-26 15:23:43 +0100789MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
Michael Holzheu411ed322007-04-27 16:01:49 +0200790MODULE_DESCRIPTION("zcore module for zfcpdump support");
791MODULE_LICENSE("GPL");
792
793subsys_initcall(zcore_init);
794module_exit(zcore_exit);