linux/arch/powerpc/platforms/pseries/lparcfg.c
<<
>>
Prefs
   1/*
   2 * PowerPC64 LPAR Configuration Information Driver
   3 *
   4 * Dave Engebretsen engebret@us.ibm.com
   5 *    Copyright (c) 2003 Dave Engebretsen
   6 * Will Schmidt willschm@us.ibm.com
   7 *    SPLPAR updates, Copyright (c) 2003 Will Schmidt IBM Corporation.
   8 *    seq_file updates, Copyright (c) 2004 Will Schmidt IBM Corporation.
   9 * Nathan Lynch nathanl@austin.ibm.com
  10 *    Added lparcfg_write, Copyright (C) 2004 Nathan Lynch IBM Corporation.
  11 *
  12 *      This program is free software; you can redistribute it and/or
  13 *      modify it under the terms of the GNU General Public License
  14 *      as published by the Free Software Foundation; either version
  15 *      2 of the License, or (at your option) any later version.
  16 *
  17 * This driver creates a proc file at /proc/ppc64/lparcfg which contains
  18 * keyword - value pairs that specify the configuration of the partition.
  19 */
  20
  21#include <linux/module.h>
  22#include <linux/types.h>
  23#include <linux/errno.h>
  24#include <linux/proc_fs.h>
  25#include <linux/init.h>
  26#include <linux/seq_file.h>
  27#include <linux/slab.h>
  28#include <asm/uaccess.h>
  29#include <asm/lppaca.h>
  30#include <asm/hvcall.h>
  31#include <asm/firmware.h>
  32#include <asm/rtas.h>
  33#include <asm/time.h>
  34#include <asm/prom.h>
  35#include <asm/vdso_datapage.h>
  36#include <asm/vio.h>
  37#include <asm/mmu.h>
  38#include <asm/machdep.h>
  39
  40
  41/*
  42 * This isn't a module but we expose that to userspace
  43 * via /proc so leave the definitions here
  44 */
  45#define MODULE_VERS "1.9"
  46#define MODULE_NAME "lparcfg"
  47
  48/* #define LPARCFG_DEBUG */
  49
  50/*
  51 * Track sum of all purrs across all processors. This is used to further
  52 * calculate usage values by different applications
  53 */
  54static unsigned long get_purr(void)
  55{
  56        unsigned long sum_purr = 0;
  57        int cpu;
  58
  59        for_each_possible_cpu(cpu) {
  60                struct cpu_usage *cu;
  61
  62                cu = &per_cpu(cpu_usage_array, cpu);
  63                sum_purr += cu->current_tb;
  64        }
  65        return sum_purr;
  66}
  67
  68/*
  69 * Methods used to fetch LPAR data when running on a pSeries platform.
  70 */
  71
  72struct hvcall_ppp_data {
  73        u64     entitlement;
  74        u64     unallocated_entitlement;
  75        u16     group_num;
  76        u16     pool_num;
  77        u8      capped;
  78        u8      weight;
  79        u8      unallocated_weight;
  80        u16     active_procs_in_pool;
  81        u16     active_system_procs;
  82        u16     phys_platform_procs;
  83        u32     max_proc_cap_avail;
  84        u32     entitled_proc_cap_avail;
  85};
  86
  87/*
  88 * H_GET_PPP hcall returns info in 4 parms.
  89 *  entitled_capacity,unallocated_capacity,
  90 *  aggregation, resource_capability).
  91 *
  92 *  R4 = Entitled Processor Capacity Percentage.
  93 *  R5 = Unallocated Processor Capacity Percentage.
  94 *  R6 (AABBCCDDEEFFGGHH).
  95 *      XXXX - reserved (0)
  96 *          XXXX - reserved (0)
  97 *              XXXX - Group Number
  98 *                  XXXX - Pool Number.
  99 *  R7 (IIJJKKLLMMNNOOPP).
 100 *      XX - reserved. (0)
 101 *        XX - bit 0-6 reserved (0).   bit 7 is Capped indicator.
 102 *          XX - variable processor Capacity Weight
 103 *            XX - Unallocated Variable Processor Capacity Weight.
 104 *              XXXX - Active processors in Physical Processor Pool.
 105 *                  XXXX  - Processors active on platform.
 106 *  R8 (QQQQRRRRRRSSSSSS). if ibm,partition-performance-parameters-level >= 1
 107 *      XXXX - Physical platform procs allocated to virtualization.
 108 *          XXXXXX - Max procs capacity % available to the partitions pool.
 109 *                XXXXXX - Entitled procs capacity % available to the
 110 *                         partitions pool.
 111 */
 112static unsigned int h_get_ppp(struct hvcall_ppp_data *ppp_data)
 113{
 114        unsigned long rc;
 115        unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
 116
 117        rc = plpar_hcall9(H_GET_PPP, retbuf);
 118
 119        ppp_data->entitlement = retbuf[0];
 120        ppp_data->unallocated_entitlement = retbuf[1];
 121
 122        ppp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
 123        ppp_data->pool_num = retbuf[2] & 0xffff;
 124
 125        ppp_data->capped = (retbuf[3] >> 6 * 8) & 0x01;
 126        ppp_data->weight = (retbuf[3] >> 5 * 8) & 0xff;
 127        ppp_data->unallocated_weight = (retbuf[3] >> 4 * 8) & 0xff;
 128        ppp_data->active_procs_in_pool = (retbuf[3] >> 2 * 8) & 0xffff;
 129        ppp_data->active_system_procs = retbuf[3] & 0xffff;
 130
 131        ppp_data->phys_platform_procs = retbuf[4] >> 6 * 8;
 132        ppp_data->max_proc_cap_avail = (retbuf[4] >> 3 * 8) & 0xffffff;
 133        ppp_data->entitled_proc_cap_avail = retbuf[4] & 0xffffff;
 134
 135        return rc;
 136}
 137
 138static unsigned h_pic(unsigned long *pool_idle_time,
 139                      unsigned long *num_procs)
 140{
 141        unsigned long rc;
 142        unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
 143
 144        rc = plpar_hcall(H_PIC, retbuf);
 145
 146        *pool_idle_time = retbuf[0];
 147        *num_procs = retbuf[1];
 148
 149        return rc;
 150}
 151
 152/*
 153 * parse_ppp_data
 154 * Parse out the data returned from h_get_ppp and h_pic
 155 */
 156static void parse_ppp_data(struct seq_file *m)
 157{
 158        struct hvcall_ppp_data ppp_data;
 159        struct device_node *root;
 160        const __be32 *perf_level;
 161        int rc;
 162
 163        rc = h_get_ppp(&ppp_data);
 164        if (rc)
 165                return;
 166
 167        seq_printf(m, "partition_entitled_capacity=%lld\n",
 168                   ppp_data.entitlement);
 169        seq_printf(m, "group=%d\n", ppp_data.group_num);
 170        seq_printf(m, "system_active_processors=%d\n",
 171                   ppp_data.active_system_procs);
 172
 173        /* pool related entries are appropriate for shared configs */
 174        if (lppaca_shared_proc(get_lppaca())) {
 175                unsigned long pool_idle_time, pool_procs;
 176
 177                seq_printf(m, "pool=%d\n", ppp_data.pool_num);
 178
 179                /* report pool_capacity in percentage */
 180                seq_printf(m, "pool_capacity=%d\n",
 181                           ppp_data.active_procs_in_pool * 100);
 182
 183                h_pic(&pool_idle_time, &pool_procs);
 184                seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
 185                seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
 186        }
 187
 188        seq_printf(m, "unallocated_capacity_weight=%d\n",
 189                   ppp_data.unallocated_weight);
 190        seq_printf(m, "capacity_weight=%d\n", ppp_data.weight);
 191        seq_printf(m, "capped=%d\n", ppp_data.capped);
 192        seq_printf(m, "unallocated_capacity=%lld\n",
 193                   ppp_data.unallocated_entitlement);
 194
 195        /* The last bits of information returned from h_get_ppp are only
 196         * valid if the ibm,partition-performance-parameters-level
 197         * property is >= 1.
 198         */
 199        root = of_find_node_by_path("/");
 200        if (root) {
 201                perf_level = of_get_property(root,
 202                                "ibm,partition-performance-parameters-level",
 203                                             NULL);
 204                if (perf_level && (be32_to_cpup(perf_level) >= 1)) {
 205                        seq_printf(m,
 206                            "physical_procs_allocated_to_virtualization=%d\n",
 207                                   ppp_data.phys_platform_procs);
 208                        seq_printf(m, "max_proc_capacity_available=%d\n",
 209                                   ppp_data.max_proc_cap_avail);
 210                        seq_printf(m, "entitled_proc_capacity_available=%d\n",
 211                                   ppp_data.entitled_proc_cap_avail);
 212                }
 213
 214                of_node_put(root);
 215        }
 216}
 217
 218/**
 219 * parse_mpp_data
 220 * Parse out data returned from h_get_mpp
 221 */
 222static void parse_mpp_data(struct seq_file *m)
 223{
 224        struct hvcall_mpp_data mpp_data;
 225        int rc;
 226
 227        rc = h_get_mpp(&mpp_data);
 228        if (rc)
 229                return;
 230
 231        seq_printf(m, "entitled_memory=%ld\n", mpp_data.entitled_mem);
 232
 233        if (mpp_data.mapped_mem != -1)
 234                seq_printf(m, "mapped_entitled_memory=%ld\n",
 235                           mpp_data.mapped_mem);
 236
 237        seq_printf(m, "entitled_memory_group_number=%d\n", mpp_data.group_num);
 238        seq_printf(m, "entitled_memory_pool_number=%d\n", mpp_data.pool_num);
 239
 240        seq_printf(m, "entitled_memory_weight=%d\n", mpp_data.mem_weight);
 241        seq_printf(m, "unallocated_entitled_memory_weight=%d\n",
 242                   mpp_data.unallocated_mem_weight);
 243        seq_printf(m, "unallocated_io_mapping_entitlement=%ld\n",
 244                   mpp_data.unallocated_entitlement);
 245
 246        if (mpp_data.pool_size != -1)
 247                seq_printf(m, "entitled_memory_pool_size=%ld bytes\n",
 248                           mpp_data.pool_size);
 249
 250        seq_printf(m, "entitled_memory_loan_request=%ld\n",
 251                   mpp_data.loan_request);
 252
 253        seq_printf(m, "backing_memory=%ld bytes\n", mpp_data.backing_mem);
 254}
 255
 256/**
 257 * parse_mpp_x_data
 258 * Parse out data returned from h_get_mpp_x
 259 */
 260static void parse_mpp_x_data(struct seq_file *m)
 261{
 262        struct hvcall_mpp_x_data mpp_x_data;
 263
 264        if (!firmware_has_feature(FW_FEATURE_XCMO))
 265                return;
 266        if (h_get_mpp_x(&mpp_x_data))
 267                return;
 268
 269        seq_printf(m, "coalesced_bytes=%ld\n", mpp_x_data.coalesced_bytes);
 270
 271        if (mpp_x_data.pool_coalesced_bytes)
 272                seq_printf(m, "pool_coalesced_bytes=%ld\n",
 273                           mpp_x_data.pool_coalesced_bytes);
 274        if (mpp_x_data.pool_purr_cycles)
 275                seq_printf(m, "coalesce_pool_purr=%ld\n", mpp_x_data.pool_purr_cycles);
 276        if (mpp_x_data.pool_spurr_cycles)
 277                seq_printf(m, "coalesce_pool_spurr=%ld\n", mpp_x_data.pool_spurr_cycles);
 278}
 279
 280#define SPLPAR_CHARACTERISTICS_TOKEN 20
 281#define SPLPAR_MAXLENGTH 1026*(sizeof(char))
 282
 283/*
 284 * parse_system_parameter_string()
 285 * Retrieve the potential_processors, max_entitled_capacity and friends
 286 * through the get-system-parameter rtas call.  Replace keyword strings as
 287 * necessary.
 288 */
 289static void parse_system_parameter_string(struct seq_file *m)
 290{
 291        int call_status;
 292
 293        unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
 294        if (!local_buffer) {
 295                printk(KERN_ERR "%s %s kmalloc failure at line %d\n",
 296                       __FILE__, __func__, __LINE__);
 297                return;
 298        }
 299
 300        spin_lock(&rtas_data_buf_lock);
 301        memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
 302        call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
 303                                NULL,
 304                                SPLPAR_CHARACTERISTICS_TOKEN,
 305                                __pa(rtas_data_buf),
 306                                RTAS_DATA_BUF_SIZE);
 307        memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
 308        local_buffer[SPLPAR_MAXLENGTH - 1] = '\0';
 309        spin_unlock(&rtas_data_buf_lock);
 310
 311        if (call_status != 0) {
 312                printk(KERN_INFO
 313                       "%s %s Error calling get-system-parameter (0x%x)\n",
 314                       __FILE__, __func__, call_status);
 315        } else {
 316                int splpar_strlen;
 317                int idx, w_idx;
 318                char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
 319                if (!workbuffer) {
 320                        printk(KERN_ERR "%s %s kmalloc failure at line %d\n",
 321                               __FILE__, __func__, __LINE__);
 322                        kfree(local_buffer);
 323                        return;
 324                }
 325#ifdef LPARCFG_DEBUG
 326                printk(KERN_INFO "success calling get-system-parameter\n");
 327#endif
 328                splpar_strlen = local_buffer[0] * 256 + local_buffer[1];
 329                local_buffer += 2;      /* step over strlen value */
 330
 331                w_idx = 0;
 332                idx = 0;
 333                while ((*local_buffer) && (idx < splpar_strlen)) {
 334                        workbuffer[w_idx++] = local_buffer[idx++];
 335                        if ((local_buffer[idx] == ',')
 336                            || (local_buffer[idx] == '\0')) {
 337                                workbuffer[w_idx] = '\0';
 338                                if (w_idx) {
 339                                        /* avoid the empty string */
 340                                        seq_printf(m, "%s\n", workbuffer);
 341                                }
 342                                memset(workbuffer, 0, SPLPAR_MAXLENGTH);
 343                                idx++;  /* skip the comma */
 344                                w_idx = 0;
 345                        } else if (local_buffer[idx] == '=') {
 346                                /* code here to replace workbuffer contents
 347                                   with different keyword strings */
 348                                if (0 == strcmp(workbuffer, "MaxEntCap")) {
 349                                        strcpy(workbuffer,
 350                                               "partition_max_entitled_capacity");
 351                                        w_idx = strlen(workbuffer);
 352                                }
 353                                if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
 354                                        strcpy(workbuffer,
 355                                               "system_potential_processors");
 356                                        w_idx = strlen(workbuffer);
 357                                }
 358                        }
 359                }
 360                kfree(workbuffer);
 361                local_buffer -= 2;      /* back up over strlen value */
 362        }
 363        kfree(local_buffer);
 364}
 365
 366/* Return the number of processors in the system.
 367 * This function reads through the device tree and counts
 368 * the virtual processors, this does not include threads.
 369 */
 370static int lparcfg_count_active_processors(void)
 371{
 372        struct device_node *cpus_dn = NULL;
 373        int count = 0;
 374
 375        while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
 376#ifdef LPARCFG_DEBUG
 377                printk(KERN_ERR "cpus_dn %p\n", cpus_dn);
 378#endif
 379                count++;
 380        }
 381        return count;
 382}
 383
 384static void pseries_cmo_data(struct seq_file *m)
 385{
 386        int cpu;
 387        unsigned long cmo_faults = 0;
 388        unsigned long cmo_fault_time = 0;
 389
 390        seq_printf(m, "cmo_enabled=%d\n", firmware_has_feature(FW_FEATURE_CMO));
 391
 392        if (!firmware_has_feature(FW_FEATURE_CMO))
 393                return;
 394
 395        for_each_possible_cpu(cpu) {
 396                cmo_faults += be64_to_cpu(lppaca_of(cpu).cmo_faults);
 397                cmo_fault_time += be64_to_cpu(lppaca_of(cpu).cmo_fault_time);
 398        }
 399
 400        seq_printf(m, "cmo_faults=%lu\n", cmo_faults);
 401        seq_printf(m, "cmo_fault_time_usec=%lu\n",
 402                   cmo_fault_time / tb_ticks_per_usec);
 403        seq_printf(m, "cmo_primary_psp=%d\n", cmo_get_primary_psp());
 404        seq_printf(m, "cmo_secondary_psp=%d\n", cmo_get_secondary_psp());
 405        seq_printf(m, "cmo_page_size=%lu\n", cmo_get_page_size());
 406}
 407
 408static void splpar_dispatch_data(struct seq_file *m)
 409{
 410        int cpu;
 411        unsigned long dispatches = 0;
 412        unsigned long dispatch_dispersions = 0;
 413
 414        for_each_possible_cpu(cpu) {
 415                dispatches += be32_to_cpu(lppaca_of(cpu).yield_count);
 416                dispatch_dispersions +=
 417                        be32_to_cpu(lppaca_of(cpu).dispersion_count);
 418        }
 419
 420        seq_printf(m, "dispatches=%lu\n", dispatches);
 421        seq_printf(m, "dispatch_dispersions=%lu\n", dispatch_dispersions);
 422}
 423
 424static void parse_em_data(struct seq_file *m)
 425{
 426        unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
 427
 428        if (firmware_has_feature(FW_FEATURE_LPAR) &&
 429            plpar_hcall(H_GET_EM_PARMS, retbuf) == H_SUCCESS)
 430                seq_printf(m, "power_mode_data=%016lx\n", retbuf[0]);
 431}
 432
 433static int pseries_lparcfg_data(struct seq_file *m, void *v)
 434{
 435        int partition_potential_processors;
 436        int partition_active_processors;
 437        struct device_node *rtas_node;
 438        const __be32 *lrdrp = NULL;
 439
 440        rtas_node = of_find_node_by_path("/rtas");
 441        if (rtas_node)
 442                lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL);
 443
 444        if (lrdrp == NULL) {
 445                partition_potential_processors = vdso_data->processorCount;
 446        } else {
 447                partition_potential_processors = be32_to_cpup(lrdrp + 4);
 448        }
 449        of_node_put(rtas_node);
 450
 451        partition_active_processors = lparcfg_count_active_processors();
 452
 453        if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
 454                /* this call handles the ibm,get-system-parameter contents */
 455                parse_system_parameter_string(m);
 456                parse_ppp_data(m);
 457                parse_mpp_data(m);
 458                parse_mpp_x_data(m);
 459                pseries_cmo_data(m);
 460                splpar_dispatch_data(m);
 461
 462                seq_printf(m, "purr=%ld\n", get_purr());
 463        } else {                /* non SPLPAR case */
 464
 465                seq_printf(m, "system_active_processors=%d\n",
 466                           partition_potential_processors);
 467
 468                seq_printf(m, "system_potential_processors=%d\n",
 469                           partition_potential_processors);
 470
 471                seq_printf(m, "partition_max_entitled_capacity=%d\n",
 472                           partition_potential_processors * 100);
 473
 474                seq_printf(m, "partition_entitled_capacity=%d\n",
 475                           partition_active_processors * 100);
 476        }
 477
 478        seq_printf(m, "partition_active_processors=%d\n",
 479                   partition_active_processors);
 480
 481        seq_printf(m, "partition_potential_processors=%d\n",
 482                   partition_potential_processors);
 483
 484        seq_printf(m, "shared_processor_mode=%d\n",
 485                   lppaca_shared_proc(get_lppaca()));
 486
 487        seq_printf(m, "slb_size=%d\n", mmu_slb_size);
 488
 489        parse_em_data(m);
 490
 491        return 0;
 492}
 493
 494static ssize_t update_ppp(u64 *entitlement, u8 *weight)
 495{
 496        struct hvcall_ppp_data ppp_data;
 497        u8 new_weight;
 498        u64 new_entitled;
 499        ssize_t retval;
 500
 501        /* Get our current parameters */
 502        retval = h_get_ppp(&ppp_data);
 503        if (retval)
 504                return retval;
 505
 506        if (entitlement) {
 507                new_weight = ppp_data.weight;
 508                new_entitled = *entitlement;
 509        } else if (weight) {
 510                new_weight = *weight;
 511                new_entitled = ppp_data.entitlement;
 512        } else
 513                return -EINVAL;
 514
 515        pr_debug("%s: current_entitled = %llu, current_weight = %u\n",
 516                 __func__, ppp_data.entitlement, ppp_data.weight);
 517
 518        pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
 519                 __func__, new_entitled, new_weight);
 520
 521        retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight);
 522        return retval;
 523}
 524
 525/**
 526 * update_mpp
 527 *
 528 * Update the memory entitlement and weight for the partition.  Caller must
 529 * specify either a new entitlement or weight, not both, to be updated
 530 * since the h_set_mpp call takes both entitlement and weight as parameters.
 531 */
 532static ssize_t update_mpp(u64 *entitlement, u8 *weight)
 533{
 534        struct hvcall_mpp_data mpp_data;
 535        u64 new_entitled;
 536        u8 new_weight;
 537        ssize_t rc;
 538
 539        if (entitlement) {
 540                /* Check with vio to ensure the new memory entitlement
 541                 * can be handled.
 542                 */
 543                rc = vio_cmo_entitlement_update(*entitlement);
 544                if (rc)
 545                        return rc;
 546        }
 547
 548        rc = h_get_mpp(&mpp_data);
 549        if (rc)
 550                return rc;
 551
 552        if (entitlement) {
 553                new_weight = mpp_data.mem_weight;
 554                new_entitled = *entitlement;
 555        } else if (weight) {
 556                new_weight = *weight;
 557                new_entitled = mpp_data.entitled_mem;
 558        } else
 559                return -EINVAL;
 560
 561        pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
 562                 __func__, mpp_data.entitled_mem, mpp_data.mem_weight);
 563
 564        pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
 565                 __func__, new_entitled, new_weight);
 566
 567        rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight);
 568        return rc;
 569}
 570
 571/*
 572 * Interface for changing system parameters (variable capacity weight
 573 * and entitled capacity).  Format of input is "param_name=value";
 574 * anything after value is ignored.  Valid parameters at this time are
 575 * "partition_entitled_capacity" and "capacity_weight".  We use
 576 * H_SET_PPP to alter parameters.
 577 *
 578 * This function should be invoked only on systems with
 579 * FW_FEATURE_SPLPAR.
 580 */
 581static ssize_t lparcfg_write(struct file *file, const char __user * buf,
 582                             size_t count, loff_t * off)
 583{
 584        int kbuf_sz = 64;
 585        char kbuf[kbuf_sz];
 586        char *tmp;
 587        u64 new_entitled, *new_entitled_ptr = &new_entitled;
 588        u8 new_weight, *new_weight_ptr = &new_weight;
 589        ssize_t retval;
 590
 591        if (!firmware_has_feature(FW_FEATURE_SPLPAR))
 592                return -EINVAL;
 593
 594        if (count > kbuf_sz)
 595                return -EINVAL;
 596
 597        if (copy_from_user(kbuf, buf, count))
 598                return -EFAULT;
 599
 600        kbuf[count - 1] = '\0';
 601        tmp = strchr(kbuf, '=');
 602        if (!tmp)
 603                return -EINVAL;
 604
 605        *tmp++ = '\0';
 606
 607        if (!strcmp(kbuf, "partition_entitled_capacity")) {
 608                char *endp;
 609                *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
 610                if (endp == tmp)
 611                        return -EINVAL;
 612
 613                retval = update_ppp(new_entitled_ptr, NULL);
 614        } else if (!strcmp(kbuf, "capacity_weight")) {
 615                char *endp;
 616                *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
 617                if (endp == tmp)
 618                        return -EINVAL;
 619
 620                retval = update_ppp(NULL, new_weight_ptr);
 621        } else if (!strcmp(kbuf, "entitled_memory")) {
 622                char *endp;
 623                *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
 624                if (endp == tmp)
 625                        return -EINVAL;
 626
 627                retval = update_mpp(new_entitled_ptr, NULL);
 628        } else if (!strcmp(kbuf, "entitled_memory_weight")) {
 629                char *endp;
 630                *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
 631                if (endp == tmp)
 632                        return -EINVAL;
 633
 634                retval = update_mpp(NULL, new_weight_ptr);
 635        } else
 636                return -EINVAL;
 637
 638        if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
 639                retval = count;
 640        } else if (retval == H_BUSY) {
 641                retval = -EBUSY;
 642        } else if (retval == H_HARDWARE) {
 643                retval = -EIO;
 644        } else if (retval == H_PARAMETER) {
 645                retval = -EINVAL;
 646        }
 647
 648        return retval;
 649}
 650
 651static int lparcfg_data(struct seq_file *m, void *v)
 652{
 653        struct device_node *rootdn;
 654        const char *model = "";
 655        const char *system_id = "";
 656        const char *tmp;
 657        const __be32 *lp_index_ptr;
 658        unsigned int lp_index = 0;
 659
 660        seq_printf(m, "%s %s\n", MODULE_NAME, MODULE_VERS);
 661
 662        rootdn = of_find_node_by_path("/");
 663        if (rootdn) {
 664                tmp = of_get_property(rootdn, "model", NULL);
 665                if (tmp)
 666                        model = tmp;
 667                tmp = of_get_property(rootdn, "system-id", NULL);
 668                if (tmp)
 669                        system_id = tmp;
 670                lp_index_ptr = of_get_property(rootdn, "ibm,partition-no",
 671                                        NULL);
 672                if (lp_index_ptr)
 673                        lp_index = be32_to_cpup(lp_index_ptr);
 674                of_node_put(rootdn);
 675        }
 676        seq_printf(m, "serial_number=%s\n", system_id);
 677        seq_printf(m, "system_type=%s\n", model);
 678        seq_printf(m, "partition_id=%d\n", (int)lp_index);
 679
 680        return pseries_lparcfg_data(m, v);
 681}
 682
 683static int lparcfg_open(struct inode *inode, struct file *file)
 684{
 685        return single_open(file, lparcfg_data, NULL);
 686}
 687
 688static const struct file_operations lparcfg_fops = {
 689        .read           = seq_read,
 690        .write          = lparcfg_write,
 691        .open           = lparcfg_open,
 692        .release        = single_release,
 693        .llseek         = seq_lseek,
 694};
 695
 696static int __init lparcfg_init(void)
 697{
 698        umode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
 699
 700        /* Allow writing if we have FW_FEATURE_SPLPAR */
 701        if (firmware_has_feature(FW_FEATURE_SPLPAR))
 702                mode |= S_IWUSR;
 703
 704        if (!proc_create("powerpc/lparcfg", mode, NULL, &lparcfg_fops)) {
 705                printk(KERN_ERR "Failed to create powerpc/lparcfg\n");
 706                return -EIO;
 707        }
 708        return 0;
 709}
 710machine_device_initcall(pseries, lparcfg_init);
 711