]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
1da177e4 LT |
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> | |
15b17189 | 28 | #include <asm/iseries/hv_lp_config.h> |
1da177e4 | 29 | #include <asm/lppaca.h> |
1da177e4 | 30 | #include <asm/hvcall.h> |
1ababe11 | 31 | #include <asm/firmware.h> |
1da177e4 LT |
32 | #include <asm/rtas.h> |
33 | #include <asm/system.h> | |
34 | #include <asm/time.h> | |
856509d5 | 35 | #include <asm/prom.h> |
271c3f35 | 36 | #include <asm/vdso_datapage.h> |
1da177e4 | 37 | |
dfc3403f | 38 | #define MODULE_VERS "1.8" |
1da177e4 LT |
39 | #define MODULE_NAME "lparcfg" |
40 | ||
41 | /* #define LPARCFG_DEBUG */ | |
42 | ||
1da177e4 | 43 | static struct proc_dir_entry *proc_ppc64_lparcfg; |
1da177e4 | 44 | |
1da177e4 | 45 | /* |
16e9f994 SR |
46 | * Track sum of all purrs across all processors. This is used to further |
47 | * calculate usage values by different applications | |
1da177e4 LT |
48 | */ |
49 | static unsigned long get_purr(void) | |
50 | { | |
51 | unsigned long sum_purr = 0; | |
52 | int cpu; | |
1da177e4 | 53 | |
0e551954 | 54 | for_each_possible_cpu(cpu) { |
16e9f994 SR |
55 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
56 | sum_purr += lppaca[cpu].emulated_time_base; | |
57 | else { | |
58 | struct cpu_usage *cu; | |
1da177e4 | 59 | |
16e9f994 SR |
60 | cu = &per_cpu(cpu_usage_array, cpu); |
61 | sum_purr += cu->current_tb; | |
62 | } | |
1da177e4 LT |
63 | } |
64 | return sum_purr; | |
65 | } | |
66 | ||
16e9f994 | 67 | #ifdef CONFIG_PPC_ISERIES |
1da177e4 | 68 | |
d3d2176a | 69 | /* |
1da177e4 LT |
70 | * Methods used to fetch LPAR data when running on an iSeries platform. |
71 | */ | |
16e9f994 | 72 | static int iseries_lparcfg_data(struct seq_file *m, void *v) |
1da177e4 | 73 | { |
16e9f994 | 74 | unsigned long pool_id; |
1da177e4 LT |
75 | int shared, entitled_capacity, max_entitled_capacity; |
76 | int processors, max_processors; | |
1da177e4 LT |
77 | unsigned long purr = get_purr(); |
78 | ||
048c8bc9 | 79 | shared = (int)(local_paca->lppaca_ptr->shared_proc); |
1da177e4 LT |
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 | } | |
16e9f994 SR |
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 | ||
1da177e4 LT |
126 | #endif /* CONFIG_PPC_ISERIES */ |
127 | ||
128 | #ifdef CONFIG_PPC_PSERIES | |
d3d2176a | 129 | /* |
1da177e4 LT |
130 | * Methods used to fetch LPAR data when running on a pSeries platform. |
131 | */ | |
dfc3403f NF |
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 | ||
398778f7 RJ |
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 | ||
1da177e4 LT |
173 | /* |
174 | * H_GET_PPP hcall returns info in 4 parms. | |
175 | * entitled_capacity,unallocated_capacity, | |
176 | * aggregation, resource_capability). | |
177 | * | |
d3d2176a | 178 | * R4 = Entitled Processor Capacity Percentage. |
1da177e4 LT |
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. | |
d3d2176a | 191 | * XXXX - Processors active on platform. |
1da177e4 | 192 | */ |
398778f7 | 193 | static unsigned int h_get_ppp(struct hvcall_ppp_data *ppp_data) |
1da177e4 LT |
194 | { |
195 | unsigned long rc; | |
b9377ffc AB |
196 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
197 | ||
198 | rc = plpar_hcall(H_GET_PPP, retbuf); | |
199 | ||
398778f7 RJ |
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; | |
1da177e4 | 211 | |
1da177e4 LT |
212 | return rc; |
213 | } | |
214 | ||
11529396 NF |
215 | static unsigned h_pic(unsigned long *pool_idle_time, |
216 | unsigned long *num_procs) | |
1da177e4 LT |
217 | { |
218 | unsigned long rc; | |
b9377ffc AB |
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]; | |
11529396 NF |
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 | { | |
398778f7 | 235 | struct hvcall_ppp_data ppp_data; |
11529396 NF |
236 | int rc; |
237 | ||
398778f7 | 238 | rc = h_get_ppp(&ppp_data); |
11529396 NF |
239 | if (rc) |
240 | return; | |
241 | ||
398778f7 RJ |
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); | |
11529396 NF |
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 | ||
398778f7 | 252 | seq_printf(m, "pool=%d\n", ppp_data.pool_num); |
11529396 NF |
253 | |
254 | /* report pool_capacity in percentage */ | |
398778f7 RJ |
255 | seq_printf(m, "pool_capacity=%d\n", |
256 | ppp_data.active_procs_in_pool * 100); | |
11529396 NF |
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 | ||
398778f7 RJ |
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); | |
1da177e4 LT |
269 | } |
270 | ||
dfc3403f NF |
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 | ||
1da177e4 LT |
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 | ||
34422fed | 322 | unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL); |
1da177e4 LT |
323 | if (!local_buffer) { |
324 | printk(KERN_ERR "%s %s kmalloc failure at line %d \n", | |
e48b1b45 | 325 | __FILE__, __func__, __LINE__); |
1da177e4 LT |
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, | |
34422fed WS |
334 | __pa(rtas_data_buf), |
335 | RTAS_DATA_BUF_SIZE); | |
1da177e4 LT |
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", | |
e48b1b45 | 342 | __FILE__, __func__, call_status); |
1da177e4 LT |
343 | } else { |
344 | int splpar_strlen; | |
345 | int idx, w_idx; | |
dd00cc48 | 346 | char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL); |
1da177e4 LT |
347 | if (!workbuffer) { |
348 | printk(KERN_ERR "%s %s kmalloc failure at line %d \n", | |
e48b1b45 | 349 | __FILE__, __func__, __LINE__); |
d3d2176a | 350 | kfree(local_buffer); |
1da177e4 LT |
351 | return; |
352 | } | |
353 | #ifdef LPARCFG_DEBUG | |
354 | printk(KERN_INFO "success calling get-system-parameter \n"); | |
355 | #endif | |
34422fed | 356 | splpar_strlen = local_buffer[0] * 256 + local_buffer[1]; |
1da177e4 LT |
357 | local_buffer += 2; /* step over strlen value */ |
358 | ||
1da177e4 LT |
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 | ||
1da177e4 LT |
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 | ||
16e9f994 | 412 | static int pseries_lparcfg_data(struct seq_file *m, void *v) |
1da177e4 LT |
413 | { |
414 | int partition_potential_processors; | |
415 | int partition_active_processors; | |
1da177e4 | 416 | struct device_node *rtas_node; |
a7f67bdf | 417 | const int *lrdrp = NULL; |
1da177e4 | 418 | |
8c8dc322 | 419 | rtas_node = of_find_node_by_path("/rtas"); |
2b9a32ed | 420 | if (rtas_node) |
e2eb6392 | 421 | lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL); |
1da177e4 LT |
422 | |
423 | if (lrdrp == NULL) { | |
271c3f35 | 424 | partition_potential_processors = vdso_data->processorCount; |
1da177e4 LT |
425 | } else { |
426 | partition_potential_processors = *(lrdrp + 4); | |
427 | } | |
8c8dc322 | 428 | of_node_put(rtas_node); |
1da177e4 LT |
429 | |
430 | partition_active_processors = lparcfg_count_active_processors(); | |
431 | ||
1ababe11 | 432 | if (firmware_has_feature(FW_FEATURE_SPLPAR)) { |
1da177e4 LT |
433 | /* this call handles the ibm,get-system-parameter contents */ |
434 | parse_system_parameter_string(m); | |
11529396 | 435 | parse_ppp_data(m); |
dfc3403f | 436 | parse_mpp_data(m); |
1da177e4 | 437 | |
11529396 | 438 | seq_printf(m, "purr=%ld\n", get_purr()); |
1da177e4 LT |
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 | ||
3356bb9f | 460 | seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc); |
1da177e4 LT |
461 | |
462 | return 0; | |
463 | } | |
464 | ||
11529396 NF |
465 | static ssize_t update_ppp(u64 *entitlement, u8 *weight) |
466 | { | |
398778f7 RJ |
467 | struct hvcall_ppp_data ppp_data; |
468 | u8 new_weight; | |
11529396 NF |
469 | u64 new_entitled; |
470 | ssize_t retval; | |
471 | ||
472 | /* Get our current parameters */ | |
398778f7 | 473 | retval = h_get_ppp(&ppp_data); |
11529396 NF |
474 | if (retval) |
475 | return retval; | |
476 | ||
11529396 | 477 | if (entitlement) { |
398778f7 | 478 | new_weight = ppp_data.weight; |
11529396 NF |
479 | new_entitled = *entitlement; |
480 | } else if (weight) { | |
481 | new_weight = *weight; | |
398778f7 | 482 | new_entitled = ppp_data.entitlement; |
11529396 NF |
483 | } else |
484 | return -EINVAL; | |
485 | ||
486 | pr_debug("%s: current_entitled = %lu, current_weight = %u\n", | |
398778f7 | 487 | __FUNCTION__, ppp_data.entitlement, ppp_data.weight); |
11529396 NF |
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 | ||
dfc3403f NF |
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 | ||
1da177e4 LT |
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; | |
1da177e4 LT |
550 | ssize_t retval = -ENOMEM; |
551 | ||
0524aad7 SR |
552 | if (!firmware_has_feature(FW_FEATURE_SPLPAR) || |
553 | firmware_has_feature(FW_FEATURE_ISERIES)) | |
554 | return -EINVAL; | |
555 | ||
1da177e4 LT |
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; | |
11529396 NF |
577 | |
578 | retval = update_ppp(new_entitled_ptr, NULL); | |
1da177e4 LT |
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; | |
1da177e4 | 584 | |
11529396 | 585 | retval = update_ppp(NULL, new_weight_ptr); |
dfc3403f NF |
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); | |
11529396 | 600 | } else |
1da177e4 | 601 | goto out; |
1da177e4 | 602 | |
706c8c93 | 603 | if (retval == H_SUCCESS || retval == H_CONSTRAINED) { |
1da177e4 | 604 | retval = count; |
706c8c93 | 605 | } else if (retval == H_BUSY) { |
1da177e4 | 606 | retval = -EBUSY; |
706c8c93 | 607 | } else if (retval == H_HARDWARE) { |
1da177e4 | 608 | retval = -EIO; |
706c8c93 | 609 | } else if (retval == H_PARAMETER) { |
1da177e4 LT |
610 | retval = -EINVAL; |
611 | } else { | |
612 | printk(KERN_WARNING "%s: received unknown hv return code %ld", | |
e48b1b45 | 613 | __func__, retval); |
1da177e4 LT |
614 | retval = -EIO; |
615 | } | |
616 | ||
8acb888c | 617 | out: |
1da177e4 LT |
618 | kfree(kbuf); |
619 | return retval; | |
620 | } | |
621 | ||
16e9f994 SR |
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 | { | |
0524aad7 | 632 | return -EINVAL; |
16e9f994 SR |
633 | } |
634 | ||
1da177e4 LT |
635 | #endif /* CONFIG_PPC_PSERIES */ |
636 | ||
16e9f994 SR |
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; | |
a7f67bdf JK |
643 | const unsigned int *lp_index_ptr; |
644 | unsigned int lp_index = 0; | |
16e9f994 SR |
645 | |
646 | seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS); | |
647 | ||
8c8dc322 | 648 | rootdn = of_find_node_by_path("/"); |
16e9f994 | 649 | if (rootdn) { |
e2eb6392 | 650 | tmp = of_get_property(rootdn, "model", NULL); |
16e9f994 SR |
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 | } | |
e2eb6392 | 657 | tmp = of_get_property(rootdn, "system-id", NULL); |
16e9f994 SR |
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 | } | |
e2eb6392 SR |
664 | lp_index_ptr = of_get_property(rootdn, "ibm,partition-no", |
665 | NULL); | |
16e9f994 SR |
666 | if (lp_index_ptr) |
667 | lp_index = *lp_index_ptr; | |
8c8dc322 | 668 | of_node_put(rootdn); |
16e9f994 SR |
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 | ||
1da177e4 LT |
679 | static int lparcfg_open(struct inode *inode, struct file *file) |
680 | { | |
681 | return single_open(file, lparcfg_data, NULL); | |
682 | } | |
683 | ||
1c21a293 | 684 | static const struct file_operations lparcfg_fops = { |
8acb888c AB |
685 | .owner = THIS_MODULE, |
686 | .read = seq_read, | |
0524aad7 | 687 | .write = lparcfg_write, |
8acb888c AB |
688 | .open = lparcfg_open, |
689 | .release = single_release, | |
1da177e4 LT |
690 | }; |
691 | ||
1c21a293 | 692 | static int __init lparcfg_init(void) |
1da177e4 LT |
693 | { |
694 | struct proc_dir_entry *ent; | |
71839267 | 695 | mode_t mode = S_IRUSR | S_IRGRP | S_IROTH; |
1da177e4 LT |
696 | |
697 | /* Allow writing if we have FW_FEATURE_SPLPAR */ | |
16e9f994 | 698 | if (firmware_has_feature(FW_FEATURE_SPLPAR) && |
0524aad7 | 699 | !firmware_has_feature(FW_FEATURE_ISERIES)) |
1da177e4 | 700 | mode |= S_IWUSR; |
1da177e4 | 701 | |
66747138 DL |
702 | ent = proc_create("ppc64/lparcfg", mode, NULL, &lparcfg_fops); |
703 | if (!ent) { | |
1da177e4 LT |
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 | ||
1c21a293 | 712 | static void __exit lparcfg_cleanup(void) |
1da177e4 | 713 | { |
0d9dc4b4 | 714 | if (proc_ppc64_lparcfg) |
1da177e4 | 715 | remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent); |
1da177e4 LT |
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"); |