blob: 86e5b3ed10d878c0c039a7dae8e31677d2e47bdb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070021#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 Daly15b17182005-11-02 11:55:28 +110028#include <asm/iseries/hv_lp_config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/lppaca.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/hvcall.h>
Stephen Rothwell1ababe12005-08-03 14:35:25 +100031#include <asm/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/rtas.h>
33#include <asm/system.h>
34#include <asm/time.h>
Michael Ellerman856509d2005-06-25 14:54:42 -070035#include <asm/prom.h>
Paul Mackerras271c3f32005-11-11 23:04:40 +110036#include <asm/vdso_datapage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Nathan Fontenotdfc34032008-07-24 04:27:30 +100038#define MODULE_VERS "1.8"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define MODULE_NAME "lparcfg"
40
41/* #define LPARCFG_DEBUG */
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static struct proc_dir_entry *proc_ppc64_lparcfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/*
Stephen Rothwell16e9f992006-06-29 15:07:42 +100046 * Track sum of all purrs across all processors. This is used to further
47 * calculate usage values by different applications
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 */
49static unsigned long get_purr(void)
50{
51 unsigned long sum_purr = 0;
52 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
KAMEZAWA Hiroyuki0e551952006-03-28 14:50:51 -080054 for_each_possible_cpu(cpu) {
Stephen Rothwell16e9f992006-06-29 15:07:42 +100055 if (firmware_has_feature(FW_FEATURE_ISERIES))
56 sum_purr += lppaca[cpu].emulated_time_base;
57 else {
58 struct cpu_usage *cu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Stephen Rothwell16e9f992006-06-29 15:07:42 +100060 cu = &per_cpu(cpu_usage_array, cpu);
61 sum_purr += cu->current_tb;
62 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 }
64 return sum_purr;
65}
66
Stephen Rothwell16e9f992006-06-29 15:07:42 +100067#ifdef CONFIG_PPC_ISERIES
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
David Gibsond3d21762005-11-10 15:26:20 +110069/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 * Methods used to fetch LPAR data when running on an iSeries platform.
71 */
Stephen Rothwell16e9f992006-06-29 15:07:42 +100072static int iseries_lparcfg_data(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Stephen Rothwell16e9f992006-06-29 15:07:42 +100074 unsigned long pool_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 int shared, entitled_capacity, max_entitled_capacity;
76 int processors, max_processors;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 unsigned long purr = get_purr();
78
Hugh Dickins048c8bc2006-11-01 05:44:54 +110079 shared = (int)(local_paca->lppaca_ptr->shared_proc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
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 Rothwell16e9f992006-06-29 15:07:42 +1000118
119#else /* CONFIG_PPC_ISERIES */
120
121static int iseries_lparcfg_data(struct seq_file *m, void *v)
122{
123 return 0;
124}
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#endif /* CONFIG_PPC_ISERIES */
127
128#ifdef CONFIG_PPC_PSERIES
David Gibsond3d21762005-11-10 15:26:20 +1100129/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 * Methods used to fetch LPAR data when running on a pSeries platform.
131 */
Nathan Fontenotdfc34032008-07-24 04:27:30 +1000132/**
133 * h_get_mpp
134 * H_GET_MPP hcall returns info in 7 parms
135 */
136int 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}
159EXPORT_SYMBOL(h_get_mpp);
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161/*
162 * H_GET_PPP hcall returns info in 4 parms.
163 * entitled_capacity,unallocated_capacity,
164 * aggregation, resource_capability).
165 *
David Gibsond3d21762005-11-10 15:26:20 +1100166 * R4 = Entitled Processor Capacity Percentage.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 * R5 = Unallocated Processor Capacity Percentage.
168 * R6 (AABBCCDDEEFFGGHH).
169 * XXXX - reserved (0)
170 * XXXX - reserved (0)
171 * XXXX - Group Number
172 * XXXX - Pool Number.
173 * R7 (IIJJKKLLMMNNOOPP).
174 * XX - reserved. (0)
175 * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
176 * XX - variable processor Capacity Weight
177 * XX - Unallocated Variable Processor Capacity Weight.
178 * XXXX - Active processors in Physical Processor Pool.
David Gibsond3d21762005-11-10 15:26:20 +1100179 * XXXX - Processors active on platform.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 */
181static unsigned int h_get_ppp(unsigned long *entitled,
182 unsigned long *unallocated,
183 unsigned long *aggregation,
184 unsigned long *resource)
185{
186 unsigned long rc;
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000187 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
188
189 rc = plpar_hcall(H_GET_PPP, retbuf);
190
191 *entitled = retbuf[0];
192 *unallocated = retbuf[1];
193 *aggregation = retbuf[2];
194 *resource = retbuf[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 return rc;
197}
198
Nathan Fotenot11529392008-07-24 04:25:16 +1000199static unsigned h_pic(unsigned long *pool_idle_time,
200 unsigned long *num_procs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
202 unsigned long rc;
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000203 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
204
205 rc = plpar_hcall(H_PIC, retbuf);
206
207 *pool_idle_time = retbuf[0];
208 *num_procs = retbuf[1];
Nathan Fotenot11529392008-07-24 04:25:16 +1000209
210 return rc;
211}
212
213/*
214 * parse_ppp_data
215 * Parse out the data returned from h_get_ppp and h_pic
216 */
217static void parse_ppp_data(struct seq_file *m)
218{
219 unsigned long h_entitled, h_unallocated;
220 unsigned long h_aggregation, h_resource;
221 int rc;
222
223 rc = h_get_ppp(&h_entitled, &h_unallocated, &h_aggregation,
224 &h_resource);
225 if (rc)
226 return;
227
228 seq_printf(m, "partition_entitled_capacity=%ld\n", h_entitled);
229 seq_printf(m, "group=%ld\n", (h_aggregation >> 2 * 8) & 0xffff);
230 seq_printf(m, "system_active_processors=%ld\n",
231 (h_resource >> 0 * 8) & 0xffff);
232
233 /* pool related entries are apropriate for shared configs */
234 if (lppaca[0].shared_proc) {
235 unsigned long pool_idle_time, pool_procs;
236
237 seq_printf(m, "pool=%ld\n", (h_aggregation >> 0 * 8) & 0xffff);
238
239 /* report pool_capacity in percentage */
240 seq_printf(m, "pool_capacity=%ld\n",
241 ((h_resource >> 2 * 8) & 0xffff) * 100);
242
243 h_pic(&pool_idle_time, &pool_procs);
244 seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
245 seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
246 }
247
248 seq_printf(m, "unallocated_capacity_weight=%ld\n",
249 (h_resource >> 4 * 8) & 0xFF);
250
251 seq_printf(m, "capacity_weight=%ld\n", (h_resource >> 5 * 8) & 0xFF);
252 seq_printf(m, "capped=%ld\n", (h_resource >> 6 * 8) & 0x01);
253 seq_printf(m, "unallocated_capacity=%ld\n", h_unallocated);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
Nathan Fontenotdfc34032008-07-24 04:27:30 +1000256/**
257 * parse_mpp_data
258 * Parse out data returned from h_get_mpp
259 */
260static void parse_mpp_data(struct seq_file *m)
261{
262 struct hvcall_mpp_data mpp_data;
263 int rc;
264
265 rc = h_get_mpp(&mpp_data);
266 if (rc)
267 return;
268
269 seq_printf(m, "entitled_memory=%ld\n", mpp_data.entitled_mem);
270
271 if (mpp_data.mapped_mem != -1)
272 seq_printf(m, "mapped_entitled_memory=%ld\n",
273 mpp_data.mapped_mem);
274
275 seq_printf(m, "entitled_memory_group_number=%d\n", mpp_data.group_num);
276 seq_printf(m, "entitled_memory_pool_number=%d\n", mpp_data.pool_num);
277
278 seq_printf(m, "entitled_memory_weight=%d\n", mpp_data.mem_weight);
279 seq_printf(m, "unallocated_entitled_memory_weight=%d\n",
280 mpp_data.unallocated_mem_weight);
281 seq_printf(m, "unallocated_io_mapping_entitlement=%ld\n",
282 mpp_data.unallocated_entitlement);
283
284 if (mpp_data.pool_size != -1)
285 seq_printf(m, "entitled_memory_pool_size=%ld bytes\n",
286 mpp_data.pool_size);
287
288 seq_printf(m, "entitled_memory_loan_request=%ld\n",
289 mpp_data.loan_request);
290
291 seq_printf(m, "backing_memory=%ld bytes\n", mpp_data.backing_mem);
292}
293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294#define SPLPAR_CHARACTERISTICS_TOKEN 20
295#define SPLPAR_MAXLENGTH 1026*(sizeof(char))
296
297/*
298 * parse_system_parameter_string()
299 * Retrieve the potential_processors, max_entitled_capacity and friends
300 * through the get-system-parameter rtas call. Replace keyword strings as
301 * necessary.
302 */
303static void parse_system_parameter_string(struct seq_file *m)
304{
305 int call_status;
306
Will Schmidt34422fe2006-03-31 09:07:48 -0600307 unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 if (!local_buffer) {
309 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100310 __FILE__, __func__, __LINE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 return;
312 }
313
314 spin_lock(&rtas_data_buf_lock);
315 memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
316 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
317 NULL,
318 SPLPAR_CHARACTERISTICS_TOKEN,
Will Schmidt34422fe2006-03-31 09:07:48 -0600319 __pa(rtas_data_buf),
320 RTAS_DATA_BUF_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
322 spin_unlock(&rtas_data_buf_lock);
323
324 if (call_status != 0) {
325 printk(KERN_INFO
326 "%s %s Error calling get-system-parameter (0x%x)\n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100327 __FILE__, __func__, call_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 } else {
329 int splpar_strlen;
330 int idx, w_idx;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700331 char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (!workbuffer) {
333 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100334 __FILE__, __func__, __LINE__);
David Gibsond3d21762005-11-10 15:26:20 +1100335 kfree(local_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return;
337 }
338#ifdef LPARCFG_DEBUG
339 printk(KERN_INFO "success calling get-system-parameter \n");
340#endif
Will Schmidt34422fe2006-03-31 09:07:48 -0600341 splpar_strlen = local_buffer[0] * 256 + local_buffer[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 local_buffer += 2; /* step over strlen value */
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 w_idx = 0;
345 idx = 0;
346 while ((*local_buffer) && (idx < splpar_strlen)) {
347 workbuffer[w_idx++] = local_buffer[idx++];
348 if ((local_buffer[idx] == ',')
349 || (local_buffer[idx] == '\0')) {
350 workbuffer[w_idx] = '\0';
351 if (w_idx) {
352 /* avoid the empty string */
353 seq_printf(m, "%s\n", workbuffer);
354 }
355 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
356 idx++; /* skip the comma */
357 w_idx = 0;
358 } else if (local_buffer[idx] == '=') {
359 /* code here to replace workbuffer contents
360 with different keyword strings */
361 if (0 == strcmp(workbuffer, "MaxEntCap")) {
362 strcpy(workbuffer,
363 "partition_max_entitled_capacity");
364 w_idx = strlen(workbuffer);
365 }
366 if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
367 strcpy(workbuffer,
368 "system_potential_processors");
369 w_idx = strlen(workbuffer);
370 }
371 }
372 }
373 kfree(workbuffer);
374 local_buffer -= 2; /* back up over strlen value */
375 }
376 kfree(local_buffer);
377}
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379/* Return the number of processors in the system.
380 * This function reads through the device tree and counts
381 * the virtual processors, this does not include threads.
382 */
383static int lparcfg_count_active_processors(void)
384{
385 struct device_node *cpus_dn = NULL;
386 int count = 0;
387
388 while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
389#ifdef LPARCFG_DEBUG
390 printk(KERN_ERR "cpus_dn %p \n", cpus_dn);
391#endif
392 count++;
393 }
394 return count;
395}
396
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000397static int pseries_lparcfg_data(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399 int partition_potential_processors;
400 int partition_active_processors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 struct device_node *rtas_node;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000402 const int *lrdrp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000404 rtas_node = of_find_node_by_path("/rtas");
Olof Johansson2b9a32e2006-02-15 21:40:44 -0600405 if (rtas_node)
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000406 lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 if (lrdrp == NULL) {
Paul Mackerras271c3f32005-11-11 23:04:40 +1100409 partition_potential_processors = vdso_data->processorCount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 } else {
411 partition_potential_processors = *(lrdrp + 4);
412 }
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000413 of_node_put(rtas_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 partition_active_processors = lparcfg_count_active_processors();
416
Stephen Rothwell1ababe12005-08-03 14:35:25 +1000417 if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /* this call handles the ibm,get-system-parameter contents */
419 parse_system_parameter_string(m);
Nathan Fotenot11529392008-07-24 04:25:16 +1000420 parse_ppp_data(m);
Nathan Fontenotdfc34032008-07-24 04:27:30 +1000421 parse_mpp_data(m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Nathan Fotenot11529392008-07-24 04:25:16 +1000423 seq_printf(m, "purr=%ld\n", get_purr());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 } else { /* non SPLPAR case */
425
426 seq_printf(m, "system_active_processors=%d\n",
427 partition_potential_processors);
428
429 seq_printf(m, "system_potential_processors=%d\n",
430 partition_potential_processors);
431
432 seq_printf(m, "partition_max_entitled_capacity=%d\n",
433 partition_potential_processors * 100);
434
435 seq_printf(m, "partition_entitled_capacity=%d\n",
436 partition_active_processors * 100);
437 }
438
439 seq_printf(m, "partition_active_processors=%d\n",
440 partition_active_processors);
441
442 seq_printf(m, "partition_potential_processors=%d\n",
443 partition_potential_processors);
444
David Gibson3356bb92006-01-13 10:26:42 +1100445 seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 return 0;
448}
449
Nathan Fotenot11529392008-07-24 04:25:16 +1000450static ssize_t update_ppp(u64 *entitlement, u8 *weight)
451{
452 unsigned long current_entitled;
453 unsigned long dummy;
454 unsigned long resource;
455 u8 current_weight, new_weight;
456 u64 new_entitled;
457 ssize_t retval;
458
459 /* Get our current parameters */
460 retval = h_get_ppp(&current_entitled, &dummy, &dummy, &resource);
461 if (retval)
462 return retval;
463
464 current_weight = (resource >> 5 * 8) & 0xFF;
465
466 if (entitlement) {
467 new_weight = current_weight;
468 new_entitled = *entitlement;
469 } else if (weight) {
470 new_weight = *weight;
471 new_entitled = current_entitled;
472 } else
473 return -EINVAL;
474
475 pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
476 __FUNCTION__, current_entitled, current_weight);
477
478 pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
479 __FUNCTION__, new_entitled, new_weight);
480
481 retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight);
482 return retval;
483}
484
Nathan Fontenotdfc34032008-07-24 04:27:30 +1000485/**
486 * update_mpp
487 *
488 * Update the memory entitlement and weight for the partition. Caller must
489 * specify either a new entitlement or weight, not both, to be updated
490 * since the h_set_mpp call takes both entitlement and weight as parameters.
491 */
492static ssize_t update_mpp(u64 *entitlement, u8 *weight)
493{
494 struct hvcall_mpp_data mpp_data;
495 u64 new_entitled;
496 u8 new_weight;
497 ssize_t rc;
498
499 rc = h_get_mpp(&mpp_data);
500 if (rc)
501 return rc;
502
503 if (entitlement) {
504 new_weight = mpp_data.mem_weight;
505 new_entitled = *entitlement;
506 } else if (weight) {
507 new_weight = *weight;
508 new_entitled = mpp_data.entitled_mem;
509 } else
510 return -EINVAL;
511
512 pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
513 __FUNCTION__, mpp_data.entitled_mem, mpp_data.mem_weight);
514
515 pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
516 __FUNCTION__, new_entitled, new_weight);
517
518 rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight);
519 return rc;
520}
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522/*
523 * Interface for changing system parameters (variable capacity weight
524 * and entitled capacity). Format of input is "param_name=value";
525 * anything after value is ignored. Valid parameters at this time are
526 * "partition_entitled_capacity" and "capacity_weight". We use
527 * H_SET_PPP to alter parameters.
528 *
529 * This function should be invoked only on systems with
530 * FW_FEATURE_SPLPAR.
531 */
532static ssize_t lparcfg_write(struct file *file, const char __user * buf,
533 size_t count, loff_t * off)
534{
535 char *kbuf;
536 char *tmp;
537 u64 new_entitled, *new_entitled_ptr = &new_entitled;
538 u8 new_weight, *new_weight_ptr = &new_weight;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 ssize_t retval = -ENOMEM;
540
Stephen Rothwell0524aad2007-02-05 16:14:05 -0800541 if (!firmware_has_feature(FW_FEATURE_SPLPAR) ||
542 firmware_has_feature(FW_FEATURE_ISERIES))
543 return -EINVAL;
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 kbuf = kmalloc(count, GFP_KERNEL);
546 if (!kbuf)
547 goto out;
548
549 retval = -EFAULT;
550 if (copy_from_user(kbuf, buf, count))
551 goto out;
552
553 retval = -EINVAL;
554 kbuf[count - 1] = '\0';
555 tmp = strchr(kbuf, '=');
556 if (!tmp)
557 goto out;
558
559 *tmp++ = '\0';
560
561 if (!strcmp(kbuf, "partition_entitled_capacity")) {
562 char *endp;
563 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
564 if (endp == tmp)
565 goto out;
Nathan Fotenot11529392008-07-24 04:25:16 +1000566
567 retval = update_ppp(new_entitled_ptr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 } else if (!strcmp(kbuf, "capacity_weight")) {
569 char *endp;
570 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
571 if (endp == tmp)
572 goto out;
Nathan Fotenot11529392008-07-24 04:25:16 +1000573
574 retval = update_ppp(NULL, new_weight_ptr);
Nathan Fontenotdfc34032008-07-24 04:27:30 +1000575 } else if (!strcmp(kbuf, "entitled_memory")) {
576 char *endp;
577 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
578 if (endp == tmp)
579 goto out;
580
581 retval = update_mpp(new_entitled_ptr, NULL);
582 } else if (!strcmp(kbuf, "entitled_memory_weight")) {
583 char *endp;
584 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
585 if (endp == tmp)
586 goto out;
587
588 retval = update_mpp(NULL, new_weight_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 } else
590 goto out;
591
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200592 if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 retval = count;
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200594 } else if (retval == H_BUSY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 retval = -EBUSY;
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200596 } else if (retval == H_HARDWARE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 retval = -EIO;
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200598 } else if (retval == H_PARAMETER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 retval = -EINVAL;
600 } else {
601 printk(KERN_WARNING "%s: received unknown hv return code %ld",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100602 __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 retval = -EIO;
604 }
605
Anton Blanchard8acb8882005-11-11 13:53:11 +1100606out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 kfree(kbuf);
608 return retval;
609}
610
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000611#else /* CONFIG_PPC_PSERIES */
612
613static int pseries_lparcfg_data(struct seq_file *m, void *v)
614{
615 return 0;
616}
617
618static ssize_t lparcfg_write(struct file *file, const char __user * buf,
619 size_t count, loff_t * off)
620{
Stephen Rothwell0524aad2007-02-05 16:14:05 -0800621 return -EINVAL;
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000622}
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624#endif /* CONFIG_PPC_PSERIES */
625
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000626static int lparcfg_data(struct seq_file *m, void *v)
627{
628 struct device_node *rootdn;
629 const char *model = "";
630 const char *system_id = "";
631 const char *tmp;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000632 const unsigned int *lp_index_ptr;
633 unsigned int lp_index = 0;
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000634
635 seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS);
636
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000637 rootdn = of_find_node_by_path("/");
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000638 if (rootdn) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000639 tmp = of_get_property(rootdn, "model", NULL);
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000640 if (tmp) {
641 model = tmp;
642 /* Skip "IBM," - see platforms/iseries/dt.c */
643 if (firmware_has_feature(FW_FEATURE_ISERIES))
644 model += 4;
645 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000646 tmp = of_get_property(rootdn, "system-id", NULL);
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000647 if (tmp) {
648 system_id = tmp;
649 /* Skip "IBM," - see platforms/iseries/dt.c */
650 if (firmware_has_feature(FW_FEATURE_ISERIES))
651 system_id += 4;
652 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000653 lp_index_ptr = of_get_property(rootdn, "ibm,partition-no",
654 NULL);
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000655 if (lp_index_ptr)
656 lp_index = *lp_index_ptr;
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000657 of_node_put(rootdn);
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000658 }
659 seq_printf(m, "serial_number=%s\n", system_id);
660 seq_printf(m, "system_type=%s\n", model);
661 seq_printf(m, "partition_id=%d\n", (int)lp_index);
662
663 if (firmware_has_feature(FW_FEATURE_ISERIES))
664 return iseries_lparcfg_data(m, v);
665 return pseries_lparcfg_data(m, v);
666}
667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668static int lparcfg_open(struct inode *inode, struct file *file)
669{
670 return single_open(file, lparcfg_data, NULL);
671}
672
Michael Ellerman1c21a292008-05-08 14:27:19 +1000673static const struct file_operations lparcfg_fops = {
Anton Blanchard8acb8882005-11-11 13:53:11 +1100674 .owner = THIS_MODULE,
675 .read = seq_read,
Stephen Rothwell0524aad2007-02-05 16:14:05 -0800676 .write = lparcfg_write,
Anton Blanchard8acb8882005-11-11 13:53:11 +1100677 .open = lparcfg_open,
678 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679};
680
Michael Ellerman1c21a292008-05-08 14:27:19 +1000681static int __init lparcfg_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
683 struct proc_dir_entry *ent;
Wim Coekaerts71839262005-09-05 20:22:47 -0700684 mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686 /* Allow writing if we have FW_FEATURE_SPLPAR */
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000687 if (firmware_has_feature(FW_FEATURE_SPLPAR) &&
Stephen Rothwell0524aad2007-02-05 16:14:05 -0800688 !firmware_has_feature(FW_FEATURE_ISERIES))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 mode |= S_IWUSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Denis V. Lunev66747132008-04-29 01:02:26 -0700691 ent = proc_create("ppc64/lparcfg", mode, NULL, &lparcfg_fops);
692 if (!ent) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
694 return -EIO;
695 }
696
697 proc_ppc64_lparcfg = ent;
698 return 0;
699}
700
Michael Ellerman1c21a292008-05-08 14:27:19 +1000701static void __exit lparcfg_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
Nathan Lynch0d9dc4b2007-12-05 03:03:49 +1100703 if (proc_ppc64_lparcfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
706
707module_init(lparcfg_init);
708module_exit(lparcfg_cleanup);
709MODULE_DESCRIPTION("Interface for LPAR configuration data");
710MODULE_AUTHOR("Dave Engebretsen");
711MODULE_LICENSE("GPL");