| 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 | */ |
| 54 | static 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 | |
| 72 | struct 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 | */ |
| 112 | static 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 | |
| 138 | static 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 | */ |
| 156 | static void parse_ppp_data(struct seq_file *m) |
| 157 | { |
| 158 | struct hvcall_ppp_data ppp_data; |
| 159 | struct device_node *root; |
| 160 | const int *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_of(0).shared_proc) { |
| 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 && (*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 | */ |
| 222 | static 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 | */ |
| 260 | static 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 | */ |
| 289 | static 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 | */ |
| 370 | static 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 | |
| 384 | static 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 += lppaca_of(cpu).cmo_faults; |
| 397 | cmo_fault_time += 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 | |
| 408 | static 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 += lppaca_of(cpu).yield_count; |
| 416 | dispatch_dispersions += lppaca_of(cpu).dispersion_count; |
| 417 | } |
| 418 | |
| 419 | seq_printf(m, "dispatches=%lu\n", dispatches); |
| 420 | seq_printf(m, "dispatch_dispersions=%lu\n", dispatch_dispersions); |
| 421 | } |
| 422 | |
| 423 | static void parse_em_data(struct seq_file *m) |
| 424 | { |
| 425 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 426 | |
| 427 | if (firmware_has_feature(FW_FEATURE_LPAR) && |
| 428 | plpar_hcall(H_GET_EM_PARMS, retbuf) == H_SUCCESS) |
| 429 | seq_printf(m, "power_mode_data=%016lx\n", retbuf[0]); |
| 430 | } |
| 431 | |
| 432 | static int pseries_lparcfg_data(struct seq_file *m, void *v) |
| 433 | { |
| 434 | int partition_potential_processors; |
| 435 | int partition_active_processors; |
| 436 | struct device_node *rtas_node; |
| 437 | const int *lrdrp = NULL; |
| 438 | |
| 439 | rtas_node = of_find_node_by_path("/rtas"); |
| 440 | if (rtas_node) |
| 441 | lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL); |
| 442 | |
| 443 | if (lrdrp == NULL) { |
| 444 | partition_potential_processors = vdso_data->processorCount; |
| 445 | } else { |
| 446 | partition_potential_processors = *(lrdrp + 4); |
| 447 | } |
| 448 | of_node_put(rtas_node); |
| 449 | |
| 450 | partition_active_processors = lparcfg_count_active_processors(); |
| 451 | |
| 452 | if (firmware_has_feature(FW_FEATURE_SPLPAR)) { |
| 453 | /* this call handles the ibm,get-system-parameter contents */ |
| 454 | parse_system_parameter_string(m); |
| 455 | parse_ppp_data(m); |
| 456 | parse_mpp_data(m); |
| 457 | parse_mpp_x_data(m); |
| 458 | pseries_cmo_data(m); |
| 459 | splpar_dispatch_data(m); |
| 460 | |
| 461 | seq_printf(m, "purr=%ld\n", get_purr()); |
| 462 | } else { /* non SPLPAR case */ |
| 463 | |
| 464 | seq_printf(m, "system_active_processors=%d\n", |
| 465 | partition_potential_processors); |
| 466 | |
| 467 | seq_printf(m, "system_potential_processors=%d\n", |
| 468 | partition_potential_processors); |
| 469 | |
| 470 | seq_printf(m, "partition_max_entitled_capacity=%d\n", |
| 471 | partition_potential_processors * 100); |
| 472 | |
| 473 | seq_printf(m, "partition_entitled_capacity=%d\n", |
| 474 | partition_active_processors * 100); |
| 475 | } |
| 476 | |
| 477 | seq_printf(m, "partition_active_processors=%d\n", |
| 478 | partition_active_processors); |
| 479 | |
| 480 | seq_printf(m, "partition_potential_processors=%d\n", |
| 481 | partition_potential_processors); |
| 482 | |
| 483 | seq_printf(m, "shared_processor_mode=%d\n", lppaca_of(0).shared_proc); |
| 484 | |
| 485 | seq_printf(m, "slb_size=%d\n", mmu_slb_size); |
| 486 | |
| 487 | parse_em_data(m); |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | static ssize_t update_ppp(u64 *entitlement, u8 *weight) |
| 493 | { |
| 494 | struct hvcall_ppp_data ppp_data; |
| 495 | u8 new_weight; |
| 496 | u64 new_entitled; |
| 497 | ssize_t retval; |
| 498 | |
| 499 | /* Get our current parameters */ |
| 500 | retval = h_get_ppp(&ppp_data); |
| 501 | if (retval) |
| 502 | return retval; |
| 503 | |
| 504 | if (entitlement) { |
| 505 | new_weight = ppp_data.weight; |
| 506 | new_entitled = *entitlement; |
| 507 | } else if (weight) { |
| 508 | new_weight = *weight; |
| 509 | new_entitled = ppp_data.entitlement; |
| 510 | } else |
| 511 | return -EINVAL; |
| 512 | |
| 513 | pr_debug("%s: current_entitled = %llu, current_weight = %u\n", |
| 514 | __func__, ppp_data.entitlement, ppp_data.weight); |
| 515 | |
| 516 | pr_debug("%s: new_entitled = %llu, new_weight = %u\n", |
| 517 | __func__, new_entitled, new_weight); |
| 518 | |
| 519 | retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight); |
| 520 | return retval; |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * update_mpp |
| 525 | * |
| 526 | * Update the memory entitlement and weight for the partition. Caller must |
| 527 | * specify either a new entitlement or weight, not both, to be updated |
| 528 | * since the h_set_mpp call takes both entitlement and weight as parameters. |
| 529 | */ |
| 530 | static ssize_t update_mpp(u64 *entitlement, u8 *weight) |
| 531 | { |
| 532 | struct hvcall_mpp_data mpp_data; |
| 533 | u64 new_entitled; |
| 534 | u8 new_weight; |
| 535 | ssize_t rc; |
| 536 | |
| 537 | if (entitlement) { |
| 538 | /* Check with vio to ensure the new memory entitlement |
| 539 | * can be handled. |
| 540 | */ |
| 541 | rc = vio_cmo_entitlement_update(*entitlement); |
| 542 | if (rc) |
| 543 | return rc; |
| 544 | } |
| 545 | |
| 546 | rc = h_get_mpp(&mpp_data); |
| 547 | if (rc) |
| 548 | return rc; |
| 549 | |
| 550 | if (entitlement) { |
| 551 | new_weight = mpp_data.mem_weight; |
| 552 | new_entitled = *entitlement; |
| 553 | } else if (weight) { |
| 554 | new_weight = *weight; |
| 555 | new_entitled = mpp_data.entitled_mem; |
| 556 | } else |
| 557 | return -EINVAL; |
| 558 | |
| 559 | pr_debug("%s: current_entitled = %lu, current_weight = %u\n", |
| 560 | __func__, mpp_data.entitled_mem, mpp_data.mem_weight); |
| 561 | |
| 562 | pr_debug("%s: new_entitled = %llu, new_weight = %u\n", |
| 563 | __func__, new_entitled, new_weight); |
| 564 | |
| 565 | rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight); |
| 566 | return rc; |
| 567 | } |
| 568 | |
| 569 | /* |
| 570 | * Interface for changing system parameters (variable capacity weight |
| 571 | * and entitled capacity). Format of input is "param_name=value"; |
| 572 | * anything after value is ignored. Valid parameters at this time are |
| 573 | * "partition_entitled_capacity" and "capacity_weight". We use |
| 574 | * H_SET_PPP to alter parameters. |
| 575 | * |
| 576 | * This function should be invoked only on systems with |
| 577 | * FW_FEATURE_SPLPAR. |
| 578 | */ |
| 579 | static ssize_t lparcfg_write(struct file *file, const char __user * buf, |
| 580 | size_t count, loff_t * off) |
| 581 | { |
| 582 | int kbuf_sz = 64; |
| 583 | char kbuf[kbuf_sz]; |
| 584 | char *tmp; |
| 585 | u64 new_entitled, *new_entitled_ptr = &new_entitled; |
| 586 | u8 new_weight, *new_weight_ptr = &new_weight; |
| 587 | ssize_t retval; |
| 588 | |
| 589 | if (!firmware_has_feature(FW_FEATURE_SPLPAR)) |
| 590 | return -EINVAL; |
| 591 | |
| 592 | if (count > kbuf_sz) |
| 593 | return -EINVAL; |
| 594 | |
| 595 | if (copy_from_user(kbuf, buf, count)) |
| 596 | return -EFAULT; |
| 597 | |
| 598 | kbuf[count - 1] = '\0'; |
| 599 | tmp = strchr(kbuf, '='); |
| 600 | if (!tmp) |
| 601 | return -EINVAL; |
| 602 | |
| 603 | *tmp++ = '\0'; |
| 604 | |
| 605 | if (!strcmp(kbuf, "partition_entitled_capacity")) { |
| 606 | char *endp; |
| 607 | *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); |
| 608 | if (endp == tmp) |
| 609 | return -EINVAL; |
| 610 | |
| 611 | retval = update_ppp(new_entitled_ptr, NULL); |
| 612 | } else if (!strcmp(kbuf, "capacity_weight")) { |
| 613 | char *endp; |
| 614 | *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); |
| 615 | if (endp == tmp) |
| 616 | return -EINVAL; |
| 617 | |
| 618 | retval = update_ppp(NULL, new_weight_ptr); |
| 619 | } else if (!strcmp(kbuf, "entitled_memory")) { |
| 620 | char *endp; |
| 621 | *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); |
| 622 | if (endp == tmp) |
| 623 | return -EINVAL; |
| 624 | |
| 625 | retval = update_mpp(new_entitled_ptr, NULL); |
| 626 | } else if (!strcmp(kbuf, "entitled_memory_weight")) { |
| 627 | char *endp; |
| 628 | *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); |
| 629 | if (endp == tmp) |
| 630 | return -EINVAL; |
| 631 | |
| 632 | retval = update_mpp(NULL, new_weight_ptr); |
| 633 | } else |
| 634 | return -EINVAL; |
| 635 | |
| 636 | if (retval == H_SUCCESS || retval == H_CONSTRAINED) { |
| 637 | retval = count; |
| 638 | } else if (retval == H_BUSY) { |
| 639 | retval = -EBUSY; |
| 640 | } else if (retval == H_HARDWARE) { |
| 641 | retval = -EIO; |
| 642 | } else if (retval == H_PARAMETER) { |
| 643 | retval = -EINVAL; |
| 644 | } |
| 645 | |
| 646 | return retval; |
| 647 | } |
| 648 | |
| 649 | static int lparcfg_data(struct seq_file *m, void *v) |
| 650 | { |
| 651 | struct device_node *rootdn; |
| 652 | const char *model = ""; |
| 653 | const char *system_id = ""; |
| 654 | const char *tmp; |
| 655 | const unsigned int *lp_index_ptr; |
| 656 | unsigned int lp_index = 0; |
| 657 | |
| 658 | seq_printf(m, "%s %s\n", MODULE_NAME, MODULE_VERS); |
| 659 | |
| 660 | rootdn = of_find_node_by_path("/"); |
| 661 | if (rootdn) { |
| 662 | tmp = of_get_property(rootdn, "model", NULL); |
| 663 | if (tmp) |
| 664 | model = tmp; |
| 665 | tmp = of_get_property(rootdn, "system-id", NULL); |
| 666 | if (tmp) |
| 667 | system_id = tmp; |
| 668 | lp_index_ptr = of_get_property(rootdn, "ibm,partition-no", |
| 669 | NULL); |
| 670 | if (lp_index_ptr) |
| 671 | lp_index = *lp_index_ptr; |
| 672 | of_node_put(rootdn); |
| 673 | } |
| 674 | seq_printf(m, "serial_number=%s\n", system_id); |
| 675 | seq_printf(m, "system_type=%s\n", model); |
| 676 | seq_printf(m, "partition_id=%d\n", (int)lp_index); |
| 677 | |
| 678 | return pseries_lparcfg_data(m, v); |
| 679 | } |
| 680 | |
| 681 | static int lparcfg_open(struct inode *inode, struct file *file) |
| 682 | { |
| 683 | return single_open(file, lparcfg_data, NULL); |
| 684 | } |
| 685 | |
| 686 | static const struct file_operations lparcfg_fops = { |
| 687 | .read = seq_read, |
| 688 | .write = lparcfg_write, |
| 689 | .open = lparcfg_open, |
| 690 | .release = single_release, |
| 691 | .llseek = seq_lseek, |
| 692 | }; |
| 693 | |
| 694 | static int __init lparcfg_init(void) |
| 695 | { |
| 696 | umode_t mode = S_IRUSR | S_IRGRP | S_IROTH; |
| 697 | |
| 698 | /* Allow writing if we have FW_FEATURE_SPLPAR */ |
| 699 | if (firmware_has_feature(FW_FEATURE_SPLPAR)) |
| 700 | mode |= S_IWUSR; |
| 701 | |
| 702 | if (!proc_create("powerpc/lparcfg", mode, NULL, &lparcfg_fops)) { |
| 703 | printk(KERN_ERR "Failed to create powerpc/lparcfg\n"); |
| 704 | return -EIO; |
| 705 | } |
| 706 | return 0; |
| 707 | } |
| 708 | machine_device_initcall(pseries, lparcfg_init); |