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