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