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