blob: c492cee90e0f15a33492927982c995fcc5eecdeb [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
Will Schmidt34422fe2006-03-31 09:07:48 -060038#define MODULE_VERS "1.7"
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;
44#define LPARCFG_BUFF_SIZE 4096
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/*
Stephen Rothwell16e9f992006-06-29 15:07:42 +100047 * Track sum of all purrs across all processors. This is used to further
48 * calculate usage values by different applications
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 */
50static unsigned long get_purr(void)
51{
52 unsigned long sum_purr = 0;
53 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
KAMEZAWA Hiroyuki0e551952006-03-28 14:50:51 -080055 for_each_possible_cpu(cpu) {
Stephen Rothwell16e9f992006-06-29 15:07:42 +100056 if (firmware_has_feature(FW_FEATURE_ISERIES))
57 sum_purr += lppaca[cpu].emulated_time_base;
58 else {
59 struct cpu_usage *cu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Stephen Rothwell16e9f992006-06-29 15:07:42 +100061 cu = &per_cpu(cpu_usage_array, cpu);
62 sum_purr += cu->current_tb;
63 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 }
65 return sum_purr;
66}
67
Stephen Rothwell16e9f992006-06-29 15:07:42 +100068#ifdef CONFIG_PPC_ISERIES
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
David Gibsond3d21762005-11-10 15:26:20 +110070/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 * Methods used to fetch LPAR data when running on an iSeries platform.
72 */
Stephen Rothwell16e9f992006-06-29 15:07:42 +100073static int iseries_lparcfg_data(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Stephen Rothwell16e9f992006-06-29 15:07:42 +100075 unsigned long pool_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 int shared, entitled_capacity, max_entitled_capacity;
77 int processors, max_processors;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 unsigned long purr = get_purr();
79
David Gibson3356bb92006-01-13 10:26:42 +110080 shared = (int)(get_lppaca()->shared_proc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 seq_printf(m, "system_active_processors=%d\n",
83 (int)HvLpConfig_getSystemPhysicalProcessors());
84
85 seq_printf(m, "system_potential_processors=%d\n",
86 (int)HvLpConfig_getSystemPhysicalProcessors());
87
88 processors = (int)HvLpConfig_getPhysicalProcessors();
89 seq_printf(m, "partition_active_processors=%d\n", processors);
90
91 max_processors = (int)HvLpConfig_getMaxPhysicalProcessors();
92 seq_printf(m, "partition_potential_processors=%d\n", max_processors);
93
94 if (shared) {
95 entitled_capacity = HvLpConfig_getSharedProcUnits();
96 max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits();
97 } else {
98 entitled_capacity = processors * 100;
99 max_entitled_capacity = max_processors * 100;
100 }
101 seq_printf(m, "partition_entitled_capacity=%d\n", entitled_capacity);
102
103 seq_printf(m, "partition_max_entitled_capacity=%d\n",
104 max_entitled_capacity);
105
106 if (shared) {
107 pool_id = HvLpConfig_getSharedPoolIndex();
108 seq_printf(m, "pool=%d\n", (int)pool_id);
109 seq_printf(m, "pool_capacity=%d\n",
110 (int)(HvLpConfig_getNumProcsInSharedPool(pool_id) *
111 100));
112 seq_printf(m, "purr=%ld\n", purr);
113 }
114
115 seq_printf(m, "shared_processor_mode=%d\n", shared);
116
117 return 0;
118}
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000119
120#else /* CONFIG_PPC_ISERIES */
121
122static int iseries_lparcfg_data(struct seq_file *m, void *v)
123{
124 return 0;
125}
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#endif /* CONFIG_PPC_ISERIES */
128
129#ifdef CONFIG_PPC_PSERIES
David Gibsond3d21762005-11-10 15:26:20 +1100130/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 * Methods used to fetch LPAR data when running on a pSeries platform.
132 */
Stephen Rothwelld7867952005-11-14 17:14:51 +1100133static void log_plpar_hcall_return(unsigned long rc, char *tag)
134{
Will Schmidte7273d22007-03-13 06:21:16 +1100135 switch(rc) {
136 case 0:
Stephen Rothwelld7867952005-11-14 17:14:51 +1100137 return;
Will Schmidte7273d22007-03-13 06:21:16 +1100138 case H_HARDWARE:
139 printk(KERN_INFO "plpar-hcall (%s) "
140 "Hardware fault\n", tag);
141 return;
142 case H_FUNCTION:
143 printk(KERN_INFO "plpar-hcall (%s) "
144 "Function not allowed\n", tag);
145 return;
146 case H_AUTHORITY:
147 printk(KERN_INFO "plpar-hcall (%s) "
148 "Not authorized to this function\n", tag);
149 return;
150 case H_PARAMETER:
151 printk(KERN_INFO "plpar-hcall (%s) "
152 "Bad parameter(s)\n",tag);
153 return;
154 default:
155 printk(KERN_INFO "plpar-hcall (%s) "
156 "Unexpected rc(0x%lx)\n", tag, rc);
157 }
Stephen Rothwelld7867952005-11-14 17:14:51 +1100158}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160/*
161 * H_GET_PPP hcall returns info in 4 parms.
162 * entitled_capacity,unallocated_capacity,
163 * aggregation, resource_capability).
164 *
David Gibsond3d21762005-11-10 15:26:20 +1100165 * R4 = Entitled Processor Capacity Percentage.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 * R5 = Unallocated Processor Capacity Percentage.
167 * R6 (AABBCCDDEEFFGGHH).
168 * XXXX - reserved (0)
169 * XXXX - reserved (0)
170 * XXXX - Group Number
171 * XXXX - Pool Number.
172 * R7 (IIJJKKLLMMNNOOPP).
173 * XX - reserved. (0)
174 * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
175 * XX - variable processor Capacity Weight
176 * XX - Unallocated Variable Processor Capacity Weight.
177 * XXXX - Active processors in Physical Processor Pool.
David Gibsond3d21762005-11-10 15:26:20 +1100178 * XXXX - Processors active on platform.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 */
180static unsigned int h_get_ppp(unsigned long *entitled,
181 unsigned long *unallocated,
182 unsigned long *aggregation,
183 unsigned long *resource)
184{
185 unsigned long rc;
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000186 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
187
188 rc = plpar_hcall(H_GET_PPP, retbuf);
189
190 *entitled = retbuf[0];
191 *unallocated = retbuf[1];
192 *aggregation = retbuf[2];
193 *resource = retbuf[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 log_plpar_hcall_return(rc, "H_GET_PPP");
196
197 return rc;
198}
199
200static void h_pic(unsigned long *pool_idle_time, unsigned long *num_procs)
201{
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];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200210 if (rc != H_AUTHORITY)
Anton Blanchard8acb8882005-11-11 13:53:11 +1100211 log_plpar_hcall_return(rc, "H_PIC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#define SPLPAR_CHARACTERISTICS_TOKEN 20
215#define SPLPAR_MAXLENGTH 1026*(sizeof(char))
216
217/*
218 * parse_system_parameter_string()
219 * Retrieve the potential_processors, max_entitled_capacity and friends
220 * through the get-system-parameter rtas call. Replace keyword strings as
221 * necessary.
222 */
223static void parse_system_parameter_string(struct seq_file *m)
224{
225 int call_status;
226
Will Schmidt34422fe2006-03-31 09:07:48 -0600227 unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (!local_buffer) {
229 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
230 __FILE__, __FUNCTION__, __LINE__);
231 return;
232 }
233
234 spin_lock(&rtas_data_buf_lock);
235 memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
236 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
237 NULL,
238 SPLPAR_CHARACTERISTICS_TOKEN,
Will Schmidt34422fe2006-03-31 09:07:48 -0600239 __pa(rtas_data_buf),
240 RTAS_DATA_BUF_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
242 spin_unlock(&rtas_data_buf_lock);
243
244 if (call_status != 0) {
245 printk(KERN_INFO
246 "%s %s Error calling get-system-parameter (0x%x)\n",
247 __FILE__, __FUNCTION__, call_status);
248 } else {
249 int splpar_strlen;
250 int idx, w_idx;
251 char *workbuffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
252 if (!workbuffer) {
253 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
254 __FILE__, __FUNCTION__, __LINE__);
David Gibsond3d21762005-11-10 15:26:20 +1100255 kfree(local_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 return;
257 }
258#ifdef LPARCFG_DEBUG
259 printk(KERN_INFO "success calling get-system-parameter \n");
260#endif
Will Schmidt34422fe2006-03-31 09:07:48 -0600261 splpar_strlen = local_buffer[0] * 256 + local_buffer[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 local_buffer += 2; /* step over strlen value */
263
264 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
265 w_idx = 0;
266 idx = 0;
267 while ((*local_buffer) && (idx < splpar_strlen)) {
268 workbuffer[w_idx++] = local_buffer[idx++];
269 if ((local_buffer[idx] == ',')
270 || (local_buffer[idx] == '\0')) {
271 workbuffer[w_idx] = '\0';
272 if (w_idx) {
273 /* avoid the empty string */
274 seq_printf(m, "%s\n", workbuffer);
275 }
276 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
277 idx++; /* skip the comma */
278 w_idx = 0;
279 } else if (local_buffer[idx] == '=') {
280 /* code here to replace workbuffer contents
281 with different keyword strings */
282 if (0 == strcmp(workbuffer, "MaxEntCap")) {
283 strcpy(workbuffer,
284 "partition_max_entitled_capacity");
285 w_idx = strlen(workbuffer);
286 }
287 if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
288 strcpy(workbuffer,
289 "system_potential_processors");
290 w_idx = strlen(workbuffer);
291 }
292 }
293 }
294 kfree(workbuffer);
295 local_buffer -= 2; /* back up over strlen value */
296 }
297 kfree(local_buffer);
298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300/* Return the number of processors in the system.
301 * This function reads through the device tree and counts
302 * the virtual processors, this does not include threads.
303 */
304static int lparcfg_count_active_processors(void)
305{
306 struct device_node *cpus_dn = NULL;
307 int count = 0;
308
309 while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
310#ifdef LPARCFG_DEBUG
311 printk(KERN_ERR "cpus_dn %p \n", cpus_dn);
312#endif
313 count++;
314 }
315 return count;
316}
317
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000318static int pseries_lparcfg_data(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
320 int partition_potential_processors;
321 int partition_active_processors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 struct device_node *rtas_node;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000323 const int *lrdrp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000325 rtas_node = of_find_node_by_path("/rtas");
Olof Johansson2b9a32e2006-02-15 21:40:44 -0600326 if (rtas_node)
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000327 lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 if (lrdrp == NULL) {
Paul Mackerras271c3f32005-11-11 23:04:40 +1100330 partition_potential_processors = vdso_data->processorCount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 } else {
332 partition_potential_processors = *(lrdrp + 4);
333 }
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000334 of_node_put(rtas_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 partition_active_processors = lparcfg_count_active_processors();
337
Stephen Rothwell1ababe12005-08-03 14:35:25 +1000338 if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 unsigned long h_entitled, h_unallocated;
340 unsigned long h_aggregation, h_resource;
341 unsigned long pool_idle_time, pool_procs;
342 unsigned long purr;
343
344 h_get_ppp(&h_entitled, &h_unallocated, &h_aggregation,
345 &h_resource);
346
347 seq_printf(m, "R4=0x%lx\n", h_entitled);
348 seq_printf(m, "R5=0x%lx\n", h_unallocated);
349 seq_printf(m, "R6=0x%lx\n", h_aggregation);
350 seq_printf(m, "R7=0x%lx\n", h_resource);
351
352 purr = get_purr();
353
354 /* this call handles the ibm,get-system-parameter contents */
355 parse_system_parameter_string(m);
356
357 seq_printf(m, "partition_entitled_capacity=%ld\n", h_entitled);
358
359 seq_printf(m, "group=%ld\n", (h_aggregation >> 2 * 8) & 0xffff);
360
361 seq_printf(m, "system_active_processors=%ld\n",
362 (h_resource >> 0 * 8) & 0xffff);
363
364 /* pool related entries are apropriate for shared configs */
David Gibson3356bb92006-01-13 10:26:42 +1100365 if (lppaca[0].shared_proc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 h_pic(&pool_idle_time, &pool_procs);
368
369 seq_printf(m, "pool=%ld\n",
370 (h_aggregation >> 0 * 8) & 0xffff);
371
372 /* report pool_capacity in percentage */
373 seq_printf(m, "pool_capacity=%ld\n",
374 ((h_resource >> 2 * 8) & 0xffff) * 100);
375
376 seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
377
378 seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
379 }
380
381 seq_printf(m, "unallocated_capacity_weight=%ld\n",
382 (h_resource >> 4 * 8) & 0xFF);
383
384 seq_printf(m, "capacity_weight=%ld\n",
385 (h_resource >> 5 * 8) & 0xFF);
386
387 seq_printf(m, "capped=%ld\n", (h_resource >> 6 * 8) & 0x01);
388
389 seq_printf(m, "unallocated_capacity=%ld\n", h_unallocated);
390
391 seq_printf(m, "purr=%ld\n", purr);
392
393 } else { /* non SPLPAR case */
394
395 seq_printf(m, "system_active_processors=%d\n",
396 partition_potential_processors);
397
398 seq_printf(m, "system_potential_processors=%d\n",
399 partition_potential_processors);
400
401 seq_printf(m, "partition_max_entitled_capacity=%d\n",
402 partition_potential_processors * 100);
403
404 seq_printf(m, "partition_entitled_capacity=%d\n",
405 partition_active_processors * 100);
406 }
407
408 seq_printf(m, "partition_active_processors=%d\n",
409 partition_active_processors);
410
411 seq_printf(m, "partition_potential_processors=%d\n",
412 partition_potential_processors);
413
David Gibson3356bb92006-01-13 10:26:42 +1100414 seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 return 0;
417}
418
419/*
420 * Interface for changing system parameters (variable capacity weight
421 * and entitled capacity). Format of input is "param_name=value";
422 * anything after value is ignored. Valid parameters at this time are
423 * "partition_entitled_capacity" and "capacity_weight". We use
424 * H_SET_PPP to alter parameters.
425 *
426 * This function should be invoked only on systems with
427 * FW_FEATURE_SPLPAR.
428 */
429static ssize_t lparcfg_write(struct file *file, const char __user * buf,
430 size_t count, loff_t * off)
431{
432 char *kbuf;
433 char *tmp;
434 u64 new_entitled, *new_entitled_ptr = &new_entitled;
435 u8 new_weight, *new_weight_ptr = &new_weight;
436
437 unsigned long current_entitled; /* parameters for h_get_ppp */
438 unsigned long dummy;
439 unsigned long resource;
440 u8 current_weight;
441
442 ssize_t retval = -ENOMEM;
443
Stephen Rothwell0524aad2007-02-05 16:14:05 -0800444 if (!firmware_has_feature(FW_FEATURE_SPLPAR) ||
445 firmware_has_feature(FW_FEATURE_ISERIES))
446 return -EINVAL;
447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 kbuf = kmalloc(count, GFP_KERNEL);
449 if (!kbuf)
450 goto out;
451
452 retval = -EFAULT;
453 if (copy_from_user(kbuf, buf, count))
454 goto out;
455
456 retval = -EINVAL;
457 kbuf[count - 1] = '\0';
458 tmp = strchr(kbuf, '=');
459 if (!tmp)
460 goto out;
461
462 *tmp++ = '\0';
463
464 if (!strcmp(kbuf, "partition_entitled_capacity")) {
465 char *endp;
466 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
467 if (endp == tmp)
468 goto out;
469 new_weight_ptr = &current_weight;
470 } else if (!strcmp(kbuf, "capacity_weight")) {
471 char *endp;
472 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
473 if (endp == tmp)
474 goto out;
475 new_entitled_ptr = &current_entitled;
476 } else
477 goto out;
478
479 /* Get our current parameters */
480 retval = h_get_ppp(&current_entitled, &dummy, &dummy, &resource);
481 if (retval) {
482 retval = -EIO;
483 goto out;
484 }
485
486 current_weight = (resource >> 5 * 8) & 0xFF;
487
jimix@watson.ibm.com8ae5b282006-05-17 12:00:35 -0400488 pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 __FUNCTION__, current_entitled, current_weight);
490
jimix@watson.ibm.com8ae5b282006-05-17 12:00:35 -0400491 pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 __FUNCTION__, *new_entitled_ptr, *new_weight_ptr);
493
494 retval = plpar_hcall_norets(H_SET_PPP, *new_entitled_ptr,
495 *new_weight_ptr);
496
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200497 if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 retval = count;
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200499 } else if (retval == H_BUSY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 retval = -EBUSY;
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200501 } else if (retval == H_HARDWARE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 retval = -EIO;
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200503 } else if (retval == H_PARAMETER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 retval = -EINVAL;
505 } else {
506 printk(KERN_WARNING "%s: received unknown hv return code %ld",
507 __FUNCTION__, retval);
508 retval = -EIO;
509 }
510
Anton Blanchard8acb8882005-11-11 13:53:11 +1100511out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 kfree(kbuf);
513 return retval;
514}
515
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000516#else /* CONFIG_PPC_PSERIES */
517
518static int pseries_lparcfg_data(struct seq_file *m, void *v)
519{
520 return 0;
521}
522
523static ssize_t lparcfg_write(struct file *file, const char __user * buf,
524 size_t count, loff_t * off)
525{
Stephen Rothwell0524aad2007-02-05 16:14:05 -0800526 return -EINVAL;
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000527}
528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#endif /* CONFIG_PPC_PSERIES */
530
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000531static int lparcfg_data(struct seq_file *m, void *v)
532{
533 struct device_node *rootdn;
534 const char *model = "";
535 const char *system_id = "";
536 const char *tmp;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000537 const unsigned int *lp_index_ptr;
538 unsigned int lp_index = 0;
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000539
540 seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS);
541
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000542 rootdn = of_find_node_by_path("/");
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000543 if (rootdn) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000544 tmp = of_get_property(rootdn, "model", NULL);
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000545 if (tmp) {
546 model = tmp;
547 /* Skip "IBM," - see platforms/iseries/dt.c */
548 if (firmware_has_feature(FW_FEATURE_ISERIES))
549 model += 4;
550 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000551 tmp = of_get_property(rootdn, "system-id", NULL);
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000552 if (tmp) {
553 system_id = tmp;
554 /* Skip "IBM," - see platforms/iseries/dt.c */
555 if (firmware_has_feature(FW_FEATURE_ISERIES))
556 system_id += 4;
557 }
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000558 lp_index_ptr = of_get_property(rootdn, "ibm,partition-no",
559 NULL);
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000560 if (lp_index_ptr)
561 lp_index = *lp_index_ptr;
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000562 of_node_put(rootdn);
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000563 }
564 seq_printf(m, "serial_number=%s\n", system_id);
565 seq_printf(m, "system_type=%s\n", model);
566 seq_printf(m, "partition_id=%d\n", (int)lp_index);
567
568 if (firmware_has_feature(FW_FEATURE_ISERIES))
569 return iseries_lparcfg_data(m, v);
570 return pseries_lparcfg_data(m, v);
571}
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573static int lparcfg_open(struct inode *inode, struct file *file)
574{
575 return single_open(file, lparcfg_data, NULL);
576}
577
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800578const struct file_operations lparcfg_fops = {
Anton Blanchard8acb8882005-11-11 13:53:11 +1100579 .owner = THIS_MODULE,
580 .read = seq_read,
Stephen Rothwell0524aad2007-02-05 16:14:05 -0800581 .write = lparcfg_write,
Anton Blanchard8acb8882005-11-11 13:53:11 +1100582 .open = lparcfg_open,
583 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584};
585
586int __init lparcfg_init(void)
587{
588 struct proc_dir_entry *ent;
Wim Coekaerts71839262005-09-05 20:22:47 -0700589 mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 /* Allow writing if we have FW_FEATURE_SPLPAR */
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000592 if (firmware_has_feature(FW_FEATURE_SPLPAR) &&
Stephen Rothwell0524aad2007-02-05 16:14:05 -0800593 !firmware_has_feature(FW_FEATURE_ISERIES))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 mode |= S_IWUSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 ent = create_proc_entry("ppc64/lparcfg", mode, NULL);
597 if (ent) {
598 ent->proc_fops = &lparcfg_fops;
599 ent->data = kmalloc(LPARCFG_BUFF_SIZE, GFP_KERNEL);
600 if (!ent->data) {
601 printk(KERN_ERR
602 "Failed to allocate buffer for lparcfg\n");
603 remove_proc_entry("lparcfg", ent->parent);
604 return -ENOMEM;
605 }
606 } else {
607 printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
608 return -EIO;
609 }
610
611 proc_ppc64_lparcfg = ent;
612 return 0;
613}
614
615void __exit lparcfg_cleanup(void)
616{
617 if (proc_ppc64_lparcfg) {
Jesper Juhlb2325fe2005-11-07 01:01:35 -0800618 kfree(proc_ppc64_lparcfg->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
620 }
621}
622
623module_init(lparcfg_init);
624module_exit(lparcfg_cleanup);
625MODULE_DESCRIPTION("Interface for LPAR configuration data");
626MODULE_AUTHOR("Dave Engebretsen");
627MODULE_LICENSE("GPL");