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