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