Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/config.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/proc_fs.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/seq_file.h> |
| 28 | #include <asm/uaccess.h> |
Kelly Daly | 15b1718 | 2005-11-02 11:55:28 +1100 | [diff] [blame] | 29 | #include <asm/iseries/hv_lp_config.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/lppaca.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/hvcall.h> |
Stephen Rothwell | 1ababe1 | 2005-08-03 14:35:25 +1000 | [diff] [blame] | 32 | #include <asm/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/rtas.h> |
| 34 | #include <asm/system.h> |
| 35 | #include <asm/time.h> |
Kelly Daly | 7b487bb | 2005-11-02 13:48:25 +1100 | [diff] [blame] | 36 | #include <asm/iseries/it_exp_vpd_panel.h> |
Michael Ellerman | 856509d | 2005-06-25 14:54:42 -0700 | [diff] [blame] | 37 | #include <asm/prom.h> |
Paul Mackerras | 271c3f3 | 2005-11-11 23:04:40 +1100 | [diff] [blame] | 38 | #include <asm/vdso_datapage.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Will Schmidt | 34422fe | 2006-03-31 09:07:48 -0600 | [diff] [blame] | 40 | #define MODULE_VERS "1.7" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define MODULE_NAME "lparcfg" |
| 42 | |
| 43 | /* #define LPARCFG_DEBUG */ |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | static struct proc_dir_entry *proc_ppc64_lparcfg; |
| 46 | #define LPARCFG_BUFF_SIZE 4096 |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | /* |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 49 | * Track sum of all purrs across all processors. This is used to further |
| 50 | * calculate usage values by different applications |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | */ |
| 52 | static unsigned long get_purr(void) |
| 53 | { |
| 54 | unsigned long sum_purr = 0; |
| 55 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
KAMEZAWA Hiroyuki | 0e55195 | 2006-03-28 14:50:51 -0800 | [diff] [blame] | 57 | for_each_possible_cpu(cpu) { |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 58 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
| 59 | sum_purr += lppaca[cpu].emulated_time_base; |
| 60 | else { |
| 61 | struct cpu_usage *cu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 63 | cu = &per_cpu(cpu_usage_array, cpu); |
| 64 | sum_purr += cu->current_tb; |
| 65 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | return sum_purr; |
| 68 | } |
| 69 | |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 70 | #ifdef CONFIG_PPC_ISERIES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
David Gibson | d3d2176 | 2005-11-10 15:26:20 +1100 | [diff] [blame] | 72 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | * Methods used to fetch LPAR data when running on an iSeries platform. |
| 74 | */ |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 75 | static int iseries_lparcfg_data(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 77 | unsigned long pool_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | int shared, entitled_capacity, max_entitled_capacity; |
| 79 | int processors, max_processors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | unsigned long purr = get_purr(); |
| 81 | |
David Gibson | 3356bb9 | 2006-01-13 10:26:42 +1100 | [diff] [blame] | 82 | shared = (int)(get_lppaca()->shared_proc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | seq_printf(m, "system_active_processors=%d\n", |
| 85 | (int)HvLpConfig_getSystemPhysicalProcessors()); |
| 86 | |
| 87 | seq_printf(m, "system_potential_processors=%d\n", |
| 88 | (int)HvLpConfig_getSystemPhysicalProcessors()); |
| 89 | |
| 90 | processors = (int)HvLpConfig_getPhysicalProcessors(); |
| 91 | seq_printf(m, "partition_active_processors=%d\n", processors); |
| 92 | |
| 93 | max_processors = (int)HvLpConfig_getMaxPhysicalProcessors(); |
| 94 | seq_printf(m, "partition_potential_processors=%d\n", max_processors); |
| 95 | |
| 96 | if (shared) { |
| 97 | entitled_capacity = HvLpConfig_getSharedProcUnits(); |
| 98 | max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits(); |
| 99 | } else { |
| 100 | entitled_capacity = processors * 100; |
| 101 | max_entitled_capacity = max_processors * 100; |
| 102 | } |
| 103 | seq_printf(m, "partition_entitled_capacity=%d\n", entitled_capacity); |
| 104 | |
| 105 | seq_printf(m, "partition_max_entitled_capacity=%d\n", |
| 106 | max_entitled_capacity); |
| 107 | |
| 108 | if (shared) { |
| 109 | pool_id = HvLpConfig_getSharedPoolIndex(); |
| 110 | seq_printf(m, "pool=%d\n", (int)pool_id); |
| 111 | seq_printf(m, "pool_capacity=%d\n", |
| 112 | (int)(HvLpConfig_getNumProcsInSharedPool(pool_id) * |
| 113 | 100)); |
| 114 | seq_printf(m, "purr=%ld\n", purr); |
| 115 | } |
| 116 | |
| 117 | seq_printf(m, "shared_processor_mode=%d\n", shared); |
| 118 | |
| 119 | return 0; |
| 120 | } |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 121 | |
| 122 | #else /* CONFIG_PPC_ISERIES */ |
| 123 | |
| 124 | static int iseries_lparcfg_data(struct seq_file *m, void *v) |
| 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | #endif /* CONFIG_PPC_ISERIES */ |
| 130 | |
| 131 | #ifdef CONFIG_PPC_PSERIES |
David Gibson | d3d2176 | 2005-11-10 15:26:20 +1100 | [diff] [blame] | 132 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | * Methods used to fetch LPAR data when running on a pSeries platform. |
| 134 | */ |
Stephen Rothwell | d786795 | 2005-11-14 17:14:51 +1100 | [diff] [blame] | 135 | /* find a better place for this function... */ |
| 136 | static void log_plpar_hcall_return(unsigned long rc, char *tag) |
| 137 | { |
| 138 | if (rc == 0) /* success, return */ |
| 139 | return; |
| 140 | /* check for null tag ? */ |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 141 | if (rc == H_HARDWARE) |
Stephen Rothwell | d786795 | 2005-11-14 17:14:51 +1100 | [diff] [blame] | 142 | printk(KERN_INFO |
| 143 | "plpar-hcall (%s) failed with hardware fault\n", tag); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 144 | else if (rc == H_FUNCTION) |
Stephen Rothwell | d786795 | 2005-11-14 17:14:51 +1100 | [diff] [blame] | 145 | printk(KERN_INFO |
| 146 | "plpar-hcall (%s) failed; function not allowed\n", tag); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 147 | else if (rc == H_AUTHORITY) |
Stephen Rothwell | d786795 | 2005-11-14 17:14:51 +1100 | [diff] [blame] | 148 | printk(KERN_INFO |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 149 | "plpar-hcall (%s) failed; not authorized to this" |
| 150 | " function\n", tag); |
| 151 | else if (rc == H_PARAMETER) |
Stephen Rothwell | d786795 | 2005-11-14 17:14:51 +1100 | [diff] [blame] | 152 | printk(KERN_INFO "plpar-hcall (%s) failed; Bad parameter(s)\n", |
| 153 | tag); |
| 154 | else |
| 155 | printk(KERN_INFO |
| 156 | "plpar-hcall (%s) failed with unexpected rc(0x%lx)\n", |
| 157 | tag, rc); |
| 158 | |
| 159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * H_GET_PPP hcall returns info in 4 parms. |
| 163 | * entitled_capacity,unallocated_capacity, |
| 164 | * aggregation, resource_capability). |
| 165 | * |
David Gibson | d3d2176 | 2005-11-10 15:26:20 +1100 | [diff] [blame] | 166 | * R4 = Entitled Processor Capacity Percentage. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | * R5 = Unallocated Processor Capacity Percentage. |
| 168 | * R6 (AABBCCDDEEFFGGHH). |
| 169 | * XXXX - reserved (0) |
| 170 | * XXXX - reserved (0) |
| 171 | * XXXX - Group Number |
| 172 | * XXXX - Pool Number. |
| 173 | * R7 (IIJJKKLLMMNNOOPP). |
| 174 | * XX - reserved. (0) |
| 175 | * XX - bit 0-6 reserved (0). bit 7 is Capped indicator. |
| 176 | * XX - variable processor Capacity Weight |
| 177 | * XX - Unallocated Variable Processor Capacity Weight. |
| 178 | * XXXX - Active processors in Physical Processor Pool. |
David Gibson | d3d2176 | 2005-11-10 15:26:20 +1100 | [diff] [blame] | 179 | * XXXX - Processors active on platform. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | */ |
| 181 | static unsigned int h_get_ppp(unsigned long *entitled, |
| 182 | unsigned long *unallocated, |
| 183 | unsigned long *aggregation, |
| 184 | unsigned long *resource) |
| 185 | { |
| 186 | unsigned long rc; |
| 187 | rc = plpar_hcall_4out(H_GET_PPP, 0, 0, 0, 0, entitled, unallocated, |
| 188 | aggregation, resource); |
| 189 | |
| 190 | log_plpar_hcall_return(rc, "H_GET_PPP"); |
| 191 | |
| 192 | return rc; |
| 193 | } |
| 194 | |
| 195 | static void h_pic(unsigned long *pool_idle_time, unsigned long *num_procs) |
| 196 | { |
| 197 | unsigned long rc; |
| 198 | unsigned long dummy; |
| 199 | rc = plpar_hcall(H_PIC, 0, 0, 0, 0, pool_idle_time, num_procs, &dummy); |
| 200 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 201 | if (rc != H_AUTHORITY) |
Anton Blanchard | 8acb888 | 2005-11-11 13:53:11 +1100 | [diff] [blame] | 202 | log_plpar_hcall_return(rc, "H_PIC"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | #define SPLPAR_CHARACTERISTICS_TOKEN 20 |
| 206 | #define SPLPAR_MAXLENGTH 1026*(sizeof(char)) |
| 207 | |
| 208 | /* |
| 209 | * parse_system_parameter_string() |
| 210 | * Retrieve the potential_processors, max_entitled_capacity and friends |
| 211 | * through the get-system-parameter rtas call. Replace keyword strings as |
| 212 | * necessary. |
| 213 | */ |
| 214 | static void parse_system_parameter_string(struct seq_file *m) |
| 215 | { |
| 216 | int call_status; |
| 217 | |
Will Schmidt | 34422fe | 2006-03-31 09:07:48 -0600 | [diff] [blame] | 218 | unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | if (!local_buffer) { |
| 220 | printk(KERN_ERR "%s %s kmalloc failure at line %d \n", |
| 221 | __FILE__, __FUNCTION__, __LINE__); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | spin_lock(&rtas_data_buf_lock); |
| 226 | memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH); |
| 227 | call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1, |
| 228 | NULL, |
| 229 | SPLPAR_CHARACTERISTICS_TOKEN, |
Will Schmidt | 34422fe | 2006-03-31 09:07:48 -0600 | [diff] [blame] | 230 | __pa(rtas_data_buf), |
| 231 | RTAS_DATA_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH); |
| 233 | spin_unlock(&rtas_data_buf_lock); |
| 234 | |
| 235 | if (call_status != 0) { |
| 236 | printk(KERN_INFO |
| 237 | "%s %s Error calling get-system-parameter (0x%x)\n", |
| 238 | __FILE__, __FUNCTION__, call_status); |
| 239 | } else { |
| 240 | int splpar_strlen; |
| 241 | int idx, w_idx; |
| 242 | char *workbuffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL); |
| 243 | if (!workbuffer) { |
| 244 | printk(KERN_ERR "%s %s kmalloc failure at line %d \n", |
| 245 | __FILE__, __FUNCTION__, __LINE__); |
David Gibson | d3d2176 | 2005-11-10 15:26:20 +1100 | [diff] [blame] | 246 | kfree(local_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return; |
| 248 | } |
| 249 | #ifdef LPARCFG_DEBUG |
| 250 | printk(KERN_INFO "success calling get-system-parameter \n"); |
| 251 | #endif |
Will Schmidt | 34422fe | 2006-03-31 09:07:48 -0600 | [diff] [blame] | 252 | splpar_strlen = local_buffer[0] * 256 + local_buffer[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | local_buffer += 2; /* step over strlen value */ |
| 254 | |
| 255 | memset(workbuffer, 0, SPLPAR_MAXLENGTH); |
| 256 | w_idx = 0; |
| 257 | idx = 0; |
| 258 | while ((*local_buffer) && (idx < splpar_strlen)) { |
| 259 | workbuffer[w_idx++] = local_buffer[idx++]; |
| 260 | if ((local_buffer[idx] == ',') |
| 261 | || (local_buffer[idx] == '\0')) { |
| 262 | workbuffer[w_idx] = '\0'; |
| 263 | if (w_idx) { |
| 264 | /* avoid the empty string */ |
| 265 | seq_printf(m, "%s\n", workbuffer); |
| 266 | } |
| 267 | memset(workbuffer, 0, SPLPAR_MAXLENGTH); |
| 268 | idx++; /* skip the comma */ |
| 269 | w_idx = 0; |
| 270 | } else if (local_buffer[idx] == '=') { |
| 271 | /* code here to replace workbuffer contents |
| 272 | with different keyword strings */ |
| 273 | if (0 == strcmp(workbuffer, "MaxEntCap")) { |
| 274 | strcpy(workbuffer, |
| 275 | "partition_max_entitled_capacity"); |
| 276 | w_idx = strlen(workbuffer); |
| 277 | } |
| 278 | if (0 == strcmp(workbuffer, "MaxPlatProcs")) { |
| 279 | strcpy(workbuffer, |
| 280 | "system_potential_processors"); |
| 281 | w_idx = strlen(workbuffer); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | kfree(workbuffer); |
| 286 | local_buffer -= 2; /* back up over strlen value */ |
| 287 | } |
| 288 | kfree(local_buffer); |
| 289 | } |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* Return the number of processors in the system. |
| 292 | * This function reads through the device tree and counts |
| 293 | * the virtual processors, this does not include threads. |
| 294 | */ |
| 295 | static int lparcfg_count_active_processors(void) |
| 296 | { |
| 297 | struct device_node *cpus_dn = NULL; |
| 298 | int count = 0; |
| 299 | |
| 300 | while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) { |
| 301 | #ifdef LPARCFG_DEBUG |
| 302 | printk(KERN_ERR "cpus_dn %p \n", cpus_dn); |
| 303 | #endif |
| 304 | count++; |
| 305 | } |
| 306 | return count; |
| 307 | } |
| 308 | |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 309 | static int pseries_lparcfg_data(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
| 311 | int partition_potential_processors; |
| 312 | int partition_active_processors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | struct device_node *rtas_node; |
Olof Johansson | 2b9a32e | 2006-02-15 21:40:44 -0600 | [diff] [blame] | 314 | int *lrdrp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | rtas_node = find_path_device("/rtas"); |
Olof Johansson | 2b9a32e | 2006-02-15 21:40:44 -0600 | [diff] [blame] | 317 | if (rtas_node) |
| 318 | lrdrp = (int *)get_property(rtas_node, "ibm,lrdr-capacity", |
| 319 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
| 321 | if (lrdrp == NULL) { |
Paul Mackerras | 271c3f3 | 2005-11-11 23:04:40 +1100 | [diff] [blame] | 322 | partition_potential_processors = vdso_data->processorCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } else { |
| 324 | partition_potential_processors = *(lrdrp + 4); |
| 325 | } |
| 326 | |
| 327 | partition_active_processors = lparcfg_count_active_processors(); |
| 328 | |
Stephen Rothwell | 1ababe1 | 2005-08-03 14:35:25 +1000 | [diff] [blame] | 329 | if (firmware_has_feature(FW_FEATURE_SPLPAR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | unsigned long h_entitled, h_unallocated; |
| 331 | unsigned long h_aggregation, h_resource; |
| 332 | unsigned long pool_idle_time, pool_procs; |
| 333 | unsigned long purr; |
| 334 | |
| 335 | h_get_ppp(&h_entitled, &h_unallocated, &h_aggregation, |
| 336 | &h_resource); |
| 337 | |
| 338 | seq_printf(m, "R4=0x%lx\n", h_entitled); |
| 339 | seq_printf(m, "R5=0x%lx\n", h_unallocated); |
| 340 | seq_printf(m, "R6=0x%lx\n", h_aggregation); |
| 341 | seq_printf(m, "R7=0x%lx\n", h_resource); |
| 342 | |
| 343 | purr = get_purr(); |
| 344 | |
| 345 | /* this call handles the ibm,get-system-parameter contents */ |
| 346 | parse_system_parameter_string(m); |
| 347 | |
| 348 | seq_printf(m, "partition_entitled_capacity=%ld\n", h_entitled); |
| 349 | |
| 350 | seq_printf(m, "group=%ld\n", (h_aggregation >> 2 * 8) & 0xffff); |
| 351 | |
| 352 | seq_printf(m, "system_active_processors=%ld\n", |
| 353 | (h_resource >> 0 * 8) & 0xffff); |
| 354 | |
| 355 | /* pool related entries are apropriate for shared configs */ |
David Gibson | 3356bb9 | 2006-01-13 10:26:42 +1100 | [diff] [blame] | 356 | if (lppaca[0].shared_proc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
| 358 | h_pic(&pool_idle_time, &pool_procs); |
| 359 | |
| 360 | seq_printf(m, "pool=%ld\n", |
| 361 | (h_aggregation >> 0 * 8) & 0xffff); |
| 362 | |
| 363 | /* report pool_capacity in percentage */ |
| 364 | seq_printf(m, "pool_capacity=%ld\n", |
| 365 | ((h_resource >> 2 * 8) & 0xffff) * 100); |
| 366 | |
| 367 | seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time); |
| 368 | |
| 369 | seq_printf(m, "pool_num_procs=%ld\n", pool_procs); |
| 370 | } |
| 371 | |
| 372 | seq_printf(m, "unallocated_capacity_weight=%ld\n", |
| 373 | (h_resource >> 4 * 8) & 0xFF); |
| 374 | |
| 375 | seq_printf(m, "capacity_weight=%ld\n", |
| 376 | (h_resource >> 5 * 8) & 0xFF); |
| 377 | |
| 378 | seq_printf(m, "capped=%ld\n", (h_resource >> 6 * 8) & 0x01); |
| 379 | |
| 380 | seq_printf(m, "unallocated_capacity=%ld\n", h_unallocated); |
| 381 | |
| 382 | seq_printf(m, "purr=%ld\n", purr); |
| 383 | |
| 384 | } else { /* non SPLPAR case */ |
| 385 | |
| 386 | seq_printf(m, "system_active_processors=%d\n", |
| 387 | partition_potential_processors); |
| 388 | |
| 389 | seq_printf(m, "system_potential_processors=%d\n", |
| 390 | partition_potential_processors); |
| 391 | |
| 392 | seq_printf(m, "partition_max_entitled_capacity=%d\n", |
| 393 | partition_potential_processors * 100); |
| 394 | |
| 395 | seq_printf(m, "partition_entitled_capacity=%d\n", |
| 396 | partition_active_processors * 100); |
| 397 | } |
| 398 | |
| 399 | seq_printf(m, "partition_active_processors=%d\n", |
| 400 | partition_active_processors); |
| 401 | |
| 402 | seq_printf(m, "partition_potential_processors=%d\n", |
| 403 | partition_potential_processors); |
| 404 | |
David Gibson | 3356bb9 | 2006-01-13 10:26:42 +1100 | [diff] [blame] | 405 | seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | /* |
| 411 | * Interface for changing system parameters (variable capacity weight |
| 412 | * and entitled capacity). Format of input is "param_name=value"; |
| 413 | * anything after value is ignored. Valid parameters at this time are |
| 414 | * "partition_entitled_capacity" and "capacity_weight". We use |
| 415 | * H_SET_PPP to alter parameters. |
| 416 | * |
| 417 | * This function should be invoked only on systems with |
| 418 | * FW_FEATURE_SPLPAR. |
| 419 | */ |
| 420 | static ssize_t lparcfg_write(struct file *file, const char __user * buf, |
| 421 | size_t count, loff_t * off) |
| 422 | { |
| 423 | char *kbuf; |
| 424 | char *tmp; |
| 425 | u64 new_entitled, *new_entitled_ptr = &new_entitled; |
| 426 | u8 new_weight, *new_weight_ptr = &new_weight; |
| 427 | |
| 428 | unsigned long current_entitled; /* parameters for h_get_ppp */ |
| 429 | unsigned long dummy; |
| 430 | unsigned long resource; |
| 431 | u8 current_weight; |
| 432 | |
| 433 | ssize_t retval = -ENOMEM; |
| 434 | |
| 435 | kbuf = kmalloc(count, GFP_KERNEL); |
| 436 | if (!kbuf) |
| 437 | goto out; |
| 438 | |
| 439 | retval = -EFAULT; |
| 440 | if (copy_from_user(kbuf, buf, count)) |
| 441 | goto out; |
| 442 | |
| 443 | retval = -EINVAL; |
| 444 | kbuf[count - 1] = '\0'; |
| 445 | tmp = strchr(kbuf, '='); |
| 446 | if (!tmp) |
| 447 | goto out; |
| 448 | |
| 449 | *tmp++ = '\0'; |
| 450 | |
| 451 | if (!strcmp(kbuf, "partition_entitled_capacity")) { |
| 452 | char *endp; |
| 453 | *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); |
| 454 | if (endp == tmp) |
| 455 | goto out; |
| 456 | new_weight_ptr = ¤t_weight; |
| 457 | } else if (!strcmp(kbuf, "capacity_weight")) { |
| 458 | char *endp; |
| 459 | *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); |
| 460 | if (endp == tmp) |
| 461 | goto out; |
| 462 | new_entitled_ptr = ¤t_entitled; |
| 463 | } else |
| 464 | goto out; |
| 465 | |
| 466 | /* Get our current parameters */ |
| 467 | retval = h_get_ppp(¤t_entitled, &dummy, &dummy, &resource); |
| 468 | if (retval) { |
| 469 | retval = -EIO; |
| 470 | goto out; |
| 471 | } |
| 472 | |
| 473 | current_weight = (resource >> 5 * 8) & 0xFF; |
| 474 | |
jimix@watson.ibm.com | 8ae5b28 | 2006-05-17 12:00:35 -0400 | [diff] [blame] | 475 | pr_debug("%s: current_entitled = %lu, current_weight = %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | __FUNCTION__, current_entitled, current_weight); |
| 477 | |
jimix@watson.ibm.com | 8ae5b28 | 2006-05-17 12:00:35 -0400 | [diff] [blame] | 478 | pr_debug("%s: new_entitled = %lu, new_weight = %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | __FUNCTION__, *new_entitled_ptr, *new_weight_ptr); |
| 480 | |
| 481 | retval = plpar_hcall_norets(H_SET_PPP, *new_entitled_ptr, |
| 482 | *new_weight_ptr); |
| 483 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 484 | if (retval == H_SUCCESS || retval == H_CONSTRAINED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | retval = count; |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 486 | } else if (retval == H_BUSY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | retval = -EBUSY; |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 488 | } else if (retval == H_HARDWARE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | retval = -EIO; |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 490 | } else if (retval == H_PARAMETER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | retval = -EINVAL; |
| 492 | } else { |
| 493 | printk(KERN_WARNING "%s: received unknown hv return code %ld", |
| 494 | __FUNCTION__, retval); |
| 495 | retval = -EIO; |
| 496 | } |
| 497 | |
Anton Blanchard | 8acb888 | 2005-11-11 13:53:11 +1100 | [diff] [blame] | 498 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | kfree(kbuf); |
| 500 | return retval; |
| 501 | } |
| 502 | |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 503 | #else /* CONFIG_PPC_PSERIES */ |
| 504 | |
| 505 | static int pseries_lparcfg_data(struct seq_file *m, void *v) |
| 506 | { |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static ssize_t lparcfg_write(struct file *file, const char __user * buf, |
| 511 | size_t count, loff_t * off) |
| 512 | { |
| 513 | return count; |
| 514 | } |
| 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | #endif /* CONFIG_PPC_PSERIES */ |
| 517 | |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 518 | static int lparcfg_data(struct seq_file *m, void *v) |
| 519 | { |
| 520 | struct device_node *rootdn; |
| 521 | const char *model = ""; |
| 522 | const char *system_id = ""; |
| 523 | const char *tmp; |
| 524 | unsigned int *lp_index_ptr, lp_index = 0; |
| 525 | |
| 526 | seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS); |
| 527 | |
| 528 | rootdn = find_path_device("/"); |
| 529 | if (rootdn) { |
| 530 | tmp = get_property(rootdn, "model", NULL); |
| 531 | if (tmp) { |
| 532 | model = tmp; |
| 533 | /* Skip "IBM," - see platforms/iseries/dt.c */ |
| 534 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
| 535 | model += 4; |
| 536 | } |
| 537 | tmp = get_property(rootdn, "system-id", NULL); |
| 538 | if (tmp) { |
| 539 | system_id = tmp; |
| 540 | /* Skip "IBM," - see platforms/iseries/dt.c */ |
| 541 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
| 542 | system_id += 4; |
| 543 | } |
| 544 | lp_index_ptr = (unsigned int *) |
| 545 | get_property(rootdn, "ibm,partition-no", NULL); |
| 546 | if (lp_index_ptr) |
| 547 | lp_index = *lp_index_ptr; |
| 548 | } |
| 549 | seq_printf(m, "serial_number=%s\n", system_id); |
| 550 | seq_printf(m, "system_type=%s\n", model); |
| 551 | seq_printf(m, "partition_id=%d\n", (int)lp_index); |
| 552 | |
| 553 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
| 554 | return iseries_lparcfg_data(m, v); |
| 555 | return pseries_lparcfg_data(m, v); |
| 556 | } |
| 557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | static int lparcfg_open(struct inode *inode, struct file *file) |
| 559 | { |
| 560 | return single_open(file, lparcfg_data, NULL); |
| 561 | } |
| 562 | |
| 563 | struct file_operations lparcfg_fops = { |
Anton Blanchard | 8acb888 | 2005-11-11 13:53:11 +1100 | [diff] [blame] | 564 | .owner = THIS_MODULE, |
| 565 | .read = seq_read, |
| 566 | .open = lparcfg_open, |
| 567 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | }; |
| 569 | |
| 570 | int __init lparcfg_init(void) |
| 571 | { |
| 572 | struct proc_dir_entry *ent; |
Wim Coekaerts | 7183926 | 2005-09-05 20:22:47 -0700 | [diff] [blame] | 573 | mode_t mode = S_IRUSR | S_IRGRP | S_IROTH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | /* Allow writing if we have FW_FEATURE_SPLPAR */ |
Stephen Rothwell | 16e9f99 | 2006-06-29 15:07:42 +1000 | [diff] [blame^] | 576 | if (firmware_has_feature(FW_FEATURE_SPLPAR) && |
| 577 | !firmware_has_feature(FW_FEATURE_ISERIES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | lparcfg_fops.write = lparcfg_write; |
| 579 | mode |= S_IWUSR; |
| 580 | } |
| 581 | |
| 582 | ent = create_proc_entry("ppc64/lparcfg", mode, NULL); |
| 583 | if (ent) { |
| 584 | ent->proc_fops = &lparcfg_fops; |
| 585 | ent->data = kmalloc(LPARCFG_BUFF_SIZE, GFP_KERNEL); |
| 586 | if (!ent->data) { |
| 587 | printk(KERN_ERR |
| 588 | "Failed to allocate buffer for lparcfg\n"); |
| 589 | remove_proc_entry("lparcfg", ent->parent); |
| 590 | return -ENOMEM; |
| 591 | } |
| 592 | } else { |
| 593 | printk(KERN_ERR "Failed to create ppc64/lparcfg\n"); |
| 594 | return -EIO; |
| 595 | } |
| 596 | |
| 597 | proc_ppc64_lparcfg = ent; |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | void __exit lparcfg_cleanup(void) |
| 602 | { |
| 603 | if (proc_ppc64_lparcfg) { |
Jesper Juhl | b2325fe | 2005-11-07 01:01:35 -0800 | [diff] [blame] | 604 | kfree(proc_ppc64_lparcfg->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | module_init(lparcfg_init); |
| 610 | module_exit(lparcfg_cleanup); |
| 611 | MODULE_DESCRIPTION("Interface for LPAR configuration data"); |
| 612 | MODULE_AUTHOR("Dave Engebretsen"); |
| 613 | MODULE_LICENSE("GPL"); |