linux/arch/s390/hypfs/hypfs_diag.c
<<
>>
Prefs
   1/*
   2 *  arch/s390/hypfs/hypfs_diag.c
   3 *    Hypervisor filesystem for Linux on s390. Diag 204 and 224
   4 *    implementation.
   5 *
   6 *    Copyright IBM Corp. 2006, 2008
   7 *    Author(s): Michael Holzheu <holzheu@de.ibm.com>
   8 */
   9
  10#define KMSG_COMPONENT "hypfs"
  11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  12
  13#include <linux/types.h>
  14#include <linux/errno.h>
  15#include <linux/gfp.h>
  16#include <linux/slab.h>
  17#include <linux/string.h>
  18#include <linux/vmalloc.h>
  19#include <asm/ebcdic.h>
  20#include "hypfs.h"
  21
  22#define LPAR_NAME_LEN 8         /* lpar name len in diag 204 data */
  23#define CPU_NAME_LEN 16         /* type name len of cpus in diag224 name table */
  24#define TMP_SIZE 64             /* size of temporary buffers */
  25
  26/* diag 204 subcodes */
  27enum diag204_sc {
  28        SUBC_STIB4 = 4,
  29        SUBC_RSI = 5,
  30        SUBC_STIB6 = 6,
  31        SUBC_STIB7 = 7
  32};
  33
  34/* The two available diag 204 data formats */
  35enum diag204_format {
  36        INFO_SIMPLE = 0,
  37        INFO_EXT = 0x00010000
  38};
  39
  40/* bit is set in flags, when physical cpu info is included in diag 204 data */
  41#define LPAR_PHYS_FLG  0x80
  42
  43static char *diag224_cpu_names;                 /* diag 224 name table */
  44static enum diag204_sc diag204_store_sc;        /* used subcode for store */
  45static enum diag204_format diag204_info_type;   /* used diag 204 data format */
  46
  47static void *diag204_buf;               /* 4K aligned buffer for diag204 data */
  48static void *diag204_buf_vmalloc;       /* vmalloc pointer for diag204 data */
  49static int diag204_buf_pages;           /* number of pages for diag204 data */
  50
  51/*
  52 * DIAG 204 data structures and member access functions.
  53 *
  54 * Since we have two different diag 204 data formats for old and new s390
  55 * machines, we do not access the structs directly, but use getter functions for
  56 * each struct member instead. This should make the code more readable.
  57 */
  58
  59/* Time information block */
  60
  61struct info_blk_hdr {
  62        __u8  npar;
  63        __u8  flags;
  64        __u16 tslice;
  65        __u16 phys_cpus;
  66        __u16 this_part;
  67        __u64 curtod;
  68} __attribute__ ((packed));
  69
  70struct x_info_blk_hdr {
  71        __u8  npar;
  72        __u8  flags;
  73        __u16 tslice;
  74        __u16 phys_cpus;
  75        __u16 this_part;
  76        __u64 curtod1;
  77        __u64 curtod2;
  78        char reserved[40];
  79} __attribute__ ((packed));
  80
  81static inline int info_blk_hdr__size(enum diag204_format type)
  82{
  83        if (type == INFO_SIMPLE)
  84                return sizeof(struct info_blk_hdr);
  85        else /* INFO_EXT */
  86                return sizeof(struct x_info_blk_hdr);
  87}
  88
  89static inline __u8 info_blk_hdr__npar(enum diag204_format type, void *hdr)
  90{
  91        if (type == INFO_SIMPLE)
  92                return ((struct info_blk_hdr *)hdr)->npar;
  93        else /* INFO_EXT */
  94                return ((struct x_info_blk_hdr *)hdr)->npar;
  95}
  96
  97static inline __u8 info_blk_hdr__flags(enum diag204_format type, void *hdr)
  98{
  99        if (type == INFO_SIMPLE)
 100                return ((struct info_blk_hdr *)hdr)->flags;
 101        else /* INFO_EXT */
 102                return ((struct x_info_blk_hdr *)hdr)->flags;
 103}
 104
 105static inline __u16 info_blk_hdr__pcpus(enum diag204_format type, void *hdr)
 106{
 107        if (type == INFO_SIMPLE)
 108                return ((struct info_blk_hdr *)hdr)->phys_cpus;
 109        else /* INFO_EXT */
 110                return ((struct x_info_blk_hdr *)hdr)->phys_cpus;
 111}
 112
 113/* Partition header */
 114
 115struct part_hdr {
 116        __u8 pn;
 117        __u8 cpus;
 118        char reserved[6];
 119        char part_name[LPAR_NAME_LEN];
 120} __attribute__ ((packed));
 121
 122struct x_part_hdr {
 123        __u8  pn;
 124        __u8  cpus;
 125        __u8  rcpus;
 126        __u8  pflag;
 127        __u32 mlu;
 128        char  part_name[LPAR_NAME_LEN];
 129        char  lpc_name[8];
 130        char  os_name[8];
 131        __u64 online_cs;
 132        __u64 online_es;
 133        __u8  upid;
 134        char  reserved1[3];
 135        __u32 group_mlu;
 136        char  group_name[8];
 137        char  reserved2[32];
 138} __attribute__ ((packed));
 139
 140static inline int part_hdr__size(enum diag204_format type)
 141{
 142        if (type == INFO_SIMPLE)
 143                return sizeof(struct part_hdr);
 144        else /* INFO_EXT */
 145                return sizeof(struct x_part_hdr);
 146}
 147
 148static inline __u8 part_hdr__rcpus(enum diag204_format type, void *hdr)
 149{
 150        if (type == INFO_SIMPLE)
 151                return ((struct part_hdr *)hdr)->cpus;
 152        else /* INFO_EXT */
 153                return ((struct x_part_hdr *)hdr)->rcpus;
 154}
 155
 156static inline void part_hdr__part_name(enum diag204_format type, void *hdr,
 157                                       char *name)
 158{
 159        if (type == INFO_SIMPLE)
 160                memcpy(name, ((struct part_hdr *)hdr)->part_name,
 161                       LPAR_NAME_LEN);
 162        else /* INFO_EXT */
 163                memcpy(name, ((struct x_part_hdr *)hdr)->part_name,
 164                       LPAR_NAME_LEN);
 165        EBCASC(name, LPAR_NAME_LEN);
 166        name[LPAR_NAME_LEN] = 0;
 167        strstrip(name);
 168}
 169
 170struct cpu_info {
 171        __u16 cpu_addr;
 172        char  reserved1[2];
 173        __u8  ctidx;
 174        __u8  cflag;
 175        __u16 weight;
 176        __u64 acc_time;
 177        __u64 lp_time;
 178} __attribute__ ((packed));
 179
 180struct x_cpu_info {
 181        __u16 cpu_addr;
 182        char  reserved1[2];
 183        __u8  ctidx;
 184        __u8  cflag;
 185        __u16 weight;
 186        __u64 acc_time;
 187        __u64 lp_time;
 188        __u16 min_weight;
 189        __u16 cur_weight;
 190        __u16 max_weight;
 191        char  reseved2[2];
 192        __u64 online_time;
 193        __u64 wait_time;
 194        __u32 pma_weight;
 195        __u32 polar_weight;
 196        char  reserved3[40];
 197} __attribute__ ((packed));
 198
 199/* CPU info block */
 200
 201static inline int cpu_info__size(enum diag204_format type)
 202{
 203        if (type == INFO_SIMPLE)
 204                return sizeof(struct cpu_info);
 205        else /* INFO_EXT */
 206                return sizeof(struct x_cpu_info);
 207}
 208
 209static inline __u8 cpu_info__ctidx(enum diag204_format type, void *hdr)
 210{
 211        if (type == INFO_SIMPLE)
 212                return ((struct cpu_info *)hdr)->ctidx;
 213        else /* INFO_EXT */
 214                return ((struct x_cpu_info *)hdr)->ctidx;
 215}
 216
 217static inline __u16 cpu_info__cpu_addr(enum diag204_format type, void *hdr)
 218{
 219        if (type == INFO_SIMPLE)
 220                return ((struct cpu_info *)hdr)->cpu_addr;
 221        else /* INFO_EXT */
 222                return ((struct x_cpu_info *)hdr)->cpu_addr;
 223}
 224
 225static inline __u64 cpu_info__acc_time(enum diag204_format type, void *hdr)
 226{
 227        if (type == INFO_SIMPLE)
 228                return ((struct cpu_info *)hdr)->acc_time;
 229        else /* INFO_EXT */
 230                return ((struct x_cpu_info *)hdr)->acc_time;
 231}
 232
 233static inline __u64 cpu_info__lp_time(enum diag204_format type, void *hdr)
 234{
 235        if (type == INFO_SIMPLE)
 236                return ((struct cpu_info *)hdr)->lp_time;
 237        else /* INFO_EXT */
 238                return ((struct x_cpu_info *)hdr)->lp_time;
 239}
 240
 241static inline __u64 cpu_info__online_time(enum diag204_format type, void *hdr)
 242{
 243        if (type == INFO_SIMPLE)
 244                return 0;       /* online_time not available in simple info */
 245        else /* INFO_EXT */
 246                return ((struct x_cpu_info *)hdr)->online_time;
 247}
 248
 249/* Physical header */
 250
 251struct phys_hdr {
 252        char reserved1[1];
 253        __u8 cpus;
 254        char reserved2[6];
 255        char mgm_name[8];
 256} __attribute__ ((packed));
 257
 258struct x_phys_hdr {
 259        char reserved1[1];
 260        __u8 cpus;
 261        char reserved2[6];
 262        char mgm_name[8];
 263        char reserved3[80];
 264} __attribute__ ((packed));
 265
 266static inline int phys_hdr__size(enum diag204_format type)
 267{
 268        if (type == INFO_SIMPLE)
 269                return sizeof(struct phys_hdr);
 270        else /* INFO_EXT */
 271                return sizeof(struct x_phys_hdr);
 272}
 273
 274static inline __u8 phys_hdr__cpus(enum diag204_format type, void *hdr)
 275{
 276        if (type == INFO_SIMPLE)
 277                return ((struct phys_hdr *)hdr)->cpus;
 278        else /* INFO_EXT */
 279                return ((struct x_phys_hdr *)hdr)->cpus;
 280}
 281
 282/* Physical CPU info block */
 283
 284struct phys_cpu {
 285        __u16 cpu_addr;
 286        char  reserved1[2];
 287        __u8  ctidx;
 288        char  reserved2[3];
 289        __u64 mgm_time;
 290        char  reserved3[8];
 291} __attribute__ ((packed));
 292
 293struct x_phys_cpu {
 294        __u16 cpu_addr;
 295        char  reserved1[2];
 296        __u8  ctidx;
 297        char  reserved2[3];
 298        __u64 mgm_time;
 299        char  reserved3[80];
 300} __attribute__ ((packed));
 301
 302static inline int phys_cpu__size(enum diag204_format type)
 303{
 304        if (type == INFO_SIMPLE)
 305                return sizeof(struct phys_cpu);
 306        else /* INFO_EXT */
 307                return sizeof(struct x_phys_cpu);
 308}
 309
 310static inline __u16 phys_cpu__cpu_addr(enum diag204_format type, void *hdr)
 311{
 312        if (type == INFO_SIMPLE)
 313                return ((struct phys_cpu *)hdr)->cpu_addr;
 314        else /* INFO_EXT */
 315                return ((struct x_phys_cpu *)hdr)->cpu_addr;
 316}
 317
 318static inline __u64 phys_cpu__mgm_time(enum diag204_format type, void *hdr)
 319{
 320        if (type == INFO_SIMPLE)
 321                return ((struct phys_cpu *)hdr)->mgm_time;
 322        else /* INFO_EXT */
 323                return ((struct x_phys_cpu *)hdr)->mgm_time;
 324}
 325
 326static inline __u64 phys_cpu__ctidx(enum diag204_format type, void *hdr)
 327{
 328        if (type == INFO_SIMPLE)
 329                return ((struct phys_cpu *)hdr)->ctidx;
 330        else /* INFO_EXT */
 331                return ((struct x_phys_cpu *)hdr)->ctidx;
 332}
 333
 334/* Diagnose 204 functions */
 335
 336static int diag204(unsigned long subcode, unsigned long size, void *addr)
 337{
 338        register unsigned long _subcode asm("0") = subcode;
 339        register unsigned long _size asm("1") = size;
 340
 341        asm volatile(
 342                "       diag    %2,%0,0x204\n"
 343                "0:\n"
 344                EX_TABLE(0b,0b)
 345                : "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
 346        if (_subcode)
 347                return -1;
 348        return _size;
 349}
 350
 351/*
 352 * For the old diag subcode 4 with simple data format we have to use real
 353 * memory. If we use subcode 6 or 7 with extended data format, we can (and
 354 * should) use vmalloc, since we need a lot of memory in that case. Currently
 355 * up to 93 pages!
 356 */
 357
 358static void diag204_free_buffer(void)
 359{
 360        if (!diag204_buf)
 361                return;
 362        if (diag204_buf_vmalloc) {
 363                vfree(diag204_buf_vmalloc);
 364                diag204_buf_vmalloc = NULL;
 365        } else {
 366                free_pages((unsigned long) diag204_buf, 0);
 367        }
 368        diag204_buf_pages = 0;
 369        diag204_buf = NULL;
 370}
 371
 372static void *diag204_alloc_vbuf(int pages)
 373{
 374        /* The buffer has to be page aligned! */
 375        diag204_buf_vmalloc = vmalloc(PAGE_SIZE * (pages + 1));
 376        if (!diag204_buf_vmalloc)
 377                return ERR_PTR(-ENOMEM);
 378        diag204_buf = (void*)((unsigned long)diag204_buf_vmalloc
 379                                & ~0xfffUL) + 0x1000;
 380        diag204_buf_pages = pages;
 381        return diag204_buf;
 382}
 383
 384static void *diag204_alloc_rbuf(void)
 385{
 386        diag204_buf = (void*)__get_free_pages(GFP_KERNEL,0);
 387        if (!diag204_buf)
 388                return ERR_PTR(-ENOMEM);
 389        diag204_buf_pages = 1;
 390        return diag204_buf;
 391}
 392
 393static void *diag204_get_buffer(enum diag204_format fmt, int *pages)
 394{
 395        if (diag204_buf) {
 396                *pages = diag204_buf_pages;
 397                return diag204_buf;
 398        }
 399        if (fmt == INFO_SIMPLE) {
 400                *pages = 1;
 401                return diag204_alloc_rbuf();
 402        } else {/* INFO_EXT */
 403                *pages = diag204((unsigned long)SUBC_RSI |
 404                                 (unsigned long)INFO_EXT, 0, NULL);
 405                if (*pages <= 0)
 406                        return ERR_PTR(-ENOSYS);
 407                else
 408                        return diag204_alloc_vbuf(*pages);
 409        }
 410}
 411
 412/*
 413 * diag204_probe() has to find out, which type of diagnose 204 implementation
 414 * we have on our machine. Currently there are three possible scanarios:
 415 *   - subcode 4   + simple data format (only one page)
 416 *   - subcode 4-6 + extended data format
 417 *   - subcode 4-7 + extended data format
 418 *
 419 * Subcode 5 is used to retrieve the size of the data, provided by subcodes
 420 * 6 and 7. Subcode 7 basically has the same function as subcode 6. In addition
 421 * to subcode 6 it provides also information about secondary cpus.
 422 * In order to get as much information as possible, we first try
 423 * subcode 7, then 6 and if both fail, we use subcode 4.
 424 */
 425
 426static int diag204_probe(void)
 427{
 428        void *buf;
 429        int pages, rc;
 430
 431        buf = diag204_get_buffer(INFO_EXT, &pages);
 432        if (!IS_ERR(buf)) {
 433                if (diag204((unsigned long)SUBC_STIB7 |
 434                            (unsigned long)INFO_EXT, pages, buf) >= 0) {
 435                        diag204_store_sc = SUBC_STIB7;
 436                        diag204_info_type = INFO_EXT;
 437                        goto out;
 438                }
 439                if (diag204((unsigned long)SUBC_STIB6 |
 440                            (unsigned long)INFO_EXT, pages, buf) >= 0) {
 441                        diag204_store_sc = SUBC_STIB6;
 442                        diag204_info_type = INFO_EXT;
 443                        goto out;
 444                }
 445                diag204_free_buffer();
 446        }
 447
 448        /* subcodes 6 and 7 failed, now try subcode 4 */
 449
 450        buf = diag204_get_buffer(INFO_SIMPLE, &pages);
 451        if (IS_ERR(buf)) {
 452                rc = PTR_ERR(buf);
 453                goto fail_alloc;
 454        }
 455        if (diag204((unsigned long)SUBC_STIB4 |
 456                    (unsigned long)INFO_SIMPLE, pages, buf) >= 0) {
 457                diag204_store_sc = SUBC_STIB4;
 458                diag204_info_type = INFO_SIMPLE;
 459                goto out;
 460        } else {
 461                rc = -ENOSYS;
 462                goto fail_store;
 463        }
 464out:
 465        rc = 0;
 466fail_store:
 467        diag204_free_buffer();
 468fail_alloc:
 469        return rc;
 470}
 471
 472static void *diag204_store(void)
 473{
 474        void *buf;
 475        int pages;
 476
 477        buf = diag204_get_buffer(diag204_info_type, &pages);
 478        if (IS_ERR(buf))
 479                goto out;
 480        if (diag204((unsigned long)diag204_store_sc |
 481                    (unsigned long)diag204_info_type, pages, buf) < 0)
 482                return ERR_PTR(-ENOSYS);
 483out:
 484        return buf;
 485}
 486
 487/* Diagnose 224 functions */
 488
 489static int diag224(void *ptr)
 490{
 491        int rc = -ENOTSUPP;
 492
 493        asm volatile(
 494                "       diag    %1,%2,0x224\n"
 495                "0:     lhi     %0,0x0\n"
 496                "1:\n"
 497                EX_TABLE(0b,1b)
 498                : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
 499        return rc;
 500}
 501
 502static int diag224_get_name_table(void)
 503{
 504        /* memory must be below 2GB */
 505        diag224_cpu_names = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
 506        if (!diag224_cpu_names)
 507                return -ENOMEM;
 508        if (diag224(diag224_cpu_names)) {
 509                kfree(diag224_cpu_names);
 510                return -ENOTSUPP;
 511        }
 512        EBCASC(diag224_cpu_names + 16, (*diag224_cpu_names + 1) * 16);
 513        return 0;
 514}
 515
 516static void diag224_delete_name_table(void)
 517{
 518        kfree(diag224_cpu_names);
 519}
 520
 521static int diag224_idx2name(int index, char *name)
 522{
 523        memcpy(name, diag224_cpu_names + ((index + 1) * CPU_NAME_LEN),
 524                CPU_NAME_LEN);
 525        name[CPU_NAME_LEN] = 0;
 526        strstrip(name);
 527        return 0;
 528}
 529
 530__init int hypfs_diag_init(void)
 531{
 532        int rc;
 533
 534        if (diag204_probe()) {
 535                pr_err("The hardware system does not support hypfs\n");
 536                return -ENODATA;
 537        }
 538        rc = diag224_get_name_table();
 539        if (rc) {
 540                diag204_free_buffer();
 541                pr_err("The hardware system does not provide all "
 542                       "functions required by hypfs\n");
 543        }
 544        return rc;
 545}
 546
 547void hypfs_diag_exit(void)
 548{
 549        diag224_delete_name_table();
 550        diag204_free_buffer();
 551}
 552
 553/*
 554 * Functions to create the directory structure
 555 * *******************************************
 556 */
 557
 558static int hypfs_create_cpu_files(struct super_block *sb,
 559                                  struct dentry *cpus_dir, void *cpu_info)
 560{
 561        struct dentry *cpu_dir;
 562        char buffer[TMP_SIZE];
 563        void *rc;
 564
 565        snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_info_type,
 566                                                            cpu_info));
 567        cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
 568        rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
 569                              cpu_info__acc_time(diag204_info_type, cpu_info) -
 570                              cpu_info__lp_time(diag204_info_type, cpu_info));
 571        if (IS_ERR(rc))
 572                return PTR_ERR(rc);
 573        rc = hypfs_create_u64(sb, cpu_dir, "cputime",
 574                              cpu_info__lp_time(diag204_info_type, cpu_info));
 575        if (IS_ERR(rc))
 576                return PTR_ERR(rc);
 577        if (diag204_info_type == INFO_EXT) {
 578                rc = hypfs_create_u64(sb, cpu_dir, "onlinetime",
 579                                      cpu_info__online_time(diag204_info_type,
 580                                                            cpu_info));
 581                if (IS_ERR(rc))
 582                        return PTR_ERR(rc);
 583        }
 584        diag224_idx2name(cpu_info__ctidx(diag204_info_type, cpu_info), buffer);
 585        rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
 586        if (IS_ERR(rc))
 587                return PTR_ERR(rc);
 588        return 0;
 589}
 590
 591static void *hypfs_create_lpar_files(struct super_block *sb,
 592                                     struct dentry *systems_dir, void *part_hdr)
 593{
 594        struct dentry *cpus_dir;
 595        struct dentry *lpar_dir;
 596        char lpar_name[LPAR_NAME_LEN + 1];
 597        void *cpu_info;
 598        int i;
 599
 600        part_hdr__part_name(diag204_info_type, part_hdr, lpar_name);
 601        lpar_name[LPAR_NAME_LEN] = 0;
 602        lpar_dir = hypfs_mkdir(sb, systems_dir, lpar_name);
 603        if (IS_ERR(lpar_dir))
 604                return lpar_dir;
 605        cpus_dir = hypfs_mkdir(sb, lpar_dir, "cpus");
 606        if (IS_ERR(cpus_dir))
 607                return cpus_dir;
 608        cpu_info = part_hdr + part_hdr__size(diag204_info_type);
 609        for (i = 0; i < part_hdr__rcpus(diag204_info_type, part_hdr); i++) {
 610                int rc;
 611                rc = hypfs_create_cpu_files(sb, cpus_dir, cpu_info);
 612                if (rc)
 613                        return ERR_PTR(rc);
 614                cpu_info += cpu_info__size(diag204_info_type);
 615        }
 616        return cpu_info;
 617}
 618
 619static int hypfs_create_phys_cpu_files(struct super_block *sb,
 620                                       struct dentry *cpus_dir, void *cpu_info)
 621{
 622        struct dentry *cpu_dir;
 623        char buffer[TMP_SIZE];
 624        void *rc;
 625
 626        snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_info_type,
 627                                                            cpu_info));
 628        cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
 629        if (IS_ERR(cpu_dir))
 630                return PTR_ERR(cpu_dir);
 631        rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
 632                              phys_cpu__mgm_time(diag204_info_type, cpu_info));
 633        if (IS_ERR(rc))
 634                return PTR_ERR(rc);
 635        diag224_idx2name(phys_cpu__ctidx(diag204_info_type, cpu_info), buffer);
 636        rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
 637        if (IS_ERR(rc))
 638                return PTR_ERR(rc);
 639        return 0;
 640}
 641
 642static void *hypfs_create_phys_files(struct super_block *sb,
 643                                     struct dentry *parent_dir, void *phys_hdr)
 644{
 645        int i;
 646        void *cpu_info;
 647        struct dentry *cpus_dir;
 648
 649        cpus_dir = hypfs_mkdir(sb, parent_dir, "cpus");
 650        if (IS_ERR(cpus_dir))
 651                return cpus_dir;
 652        cpu_info = phys_hdr + phys_hdr__size(diag204_info_type);
 653        for (i = 0; i < phys_hdr__cpus(diag204_info_type, phys_hdr); i++) {
 654                int rc;
 655                rc = hypfs_create_phys_cpu_files(sb, cpus_dir, cpu_info);
 656                if (rc)
 657                        return ERR_PTR(rc);
 658                cpu_info += phys_cpu__size(diag204_info_type);
 659        }
 660        return cpu_info;
 661}
 662
 663int hypfs_diag_create_files(struct super_block *sb, struct dentry *root)
 664{
 665        struct dentry *systems_dir, *hyp_dir;
 666        void *time_hdr, *part_hdr;
 667        int i, rc;
 668        void *buffer, *ptr;
 669
 670        buffer = diag204_store();
 671        if (IS_ERR(buffer))
 672                return PTR_ERR(buffer);
 673
 674        systems_dir = hypfs_mkdir(sb, root, "systems");
 675        if (IS_ERR(systems_dir)) {
 676                rc = PTR_ERR(systems_dir);
 677                goto err_out;
 678        }
 679        time_hdr = (struct x_info_blk_hdr *)buffer;
 680        part_hdr = time_hdr + info_blk_hdr__size(diag204_info_type);
 681        for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr); i++) {
 682                part_hdr = hypfs_create_lpar_files(sb, systems_dir, part_hdr);
 683                if (IS_ERR(part_hdr)) {
 684                        rc = PTR_ERR(part_hdr);
 685                        goto err_out;
 686                }
 687        }
 688        if (info_blk_hdr__flags(diag204_info_type, time_hdr) & LPAR_PHYS_FLG) {
 689                ptr = hypfs_create_phys_files(sb, root, part_hdr);
 690                if (IS_ERR(ptr)) {
 691                        rc = PTR_ERR(ptr);
 692                        goto err_out;
 693                }
 694        }
 695        hyp_dir = hypfs_mkdir(sb, root, "hyp");
 696        if (IS_ERR(hyp_dir)) {
 697                rc = PTR_ERR(hyp_dir);
 698                goto err_out;
 699        }
 700        ptr = hypfs_create_str(sb, hyp_dir, "type", "LPAR Hypervisor");
 701        if (IS_ERR(ptr)) {
 702                rc = PTR_ERR(ptr);
 703                goto err_out;
 704        }
 705        rc = 0;
 706
 707err_out:
 708        return rc;
 709}
 710