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