blob: 23f34daa044a0e7ad9cc6d2b6686c94c2c6611b7 [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>
Kelly Daly7b487bb2005-11-02 13:48:25 +110035#include <asm/iseries/it_exp_vpd_panel.h>
Michael Ellerman856509d2005-06-25 14:54:42 -070036#include <asm/prom.h>
Paul Mackerras271c3f32005-11-11 23:04:40 +110037#include <asm/vdso_datapage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Will Schmidt34422fe2006-03-31 09:07:48 -060039#define MODULE_VERS "1.7"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define MODULE_NAME "lparcfg"
41
42/* #define LPARCFG_DEBUG */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static struct proc_dir_entry *proc_ppc64_lparcfg;
45#define LPARCFG_BUFF_SIZE 4096
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/*
Stephen Rothwell16e9f992006-06-29 15:07:42 +100048 * Track sum of all purrs across all processors. This is used to further
49 * calculate usage values by different applications
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 */
51static unsigned long get_purr(void)
52{
53 unsigned long sum_purr = 0;
54 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
KAMEZAWA Hiroyuki0e551952006-03-28 14:50:51 -080056 for_each_possible_cpu(cpu) {
Stephen Rothwell16e9f992006-06-29 15:07:42 +100057 if (firmware_has_feature(FW_FEATURE_ISERIES))
58 sum_purr += lppaca[cpu].emulated_time_base;
59 else {
60 struct cpu_usage *cu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Stephen Rothwell16e9f992006-06-29 15:07:42 +100062 cu = &per_cpu(cpu_usage_array, cpu);
63 sum_purr += cu->current_tb;
64 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 }
66 return sum_purr;
67}
68
Stephen Rothwell16e9f992006-06-29 15:07:42 +100069#ifdef CONFIG_PPC_ISERIES
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
David Gibsond3d21762005-11-10 15:26:20 +110071/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * Methods used to fetch LPAR data when running on an iSeries platform.
73 */
Stephen Rothwell16e9f992006-06-29 15:07:42 +100074static int iseries_lparcfg_data(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Stephen Rothwell16e9f992006-06-29 15:07:42 +100076 unsigned long pool_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 int shared, entitled_capacity, max_entitled_capacity;
78 int processors, max_processors;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 unsigned long purr = get_purr();
80
David Gibson3356bb92006-01-13 10:26:42 +110081 shared = (int)(get_lppaca()->shared_proc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 seq_printf(m, "system_active_processors=%d\n",
84 (int)HvLpConfig_getSystemPhysicalProcessors());
85
86 seq_printf(m, "system_potential_processors=%d\n",
87 (int)HvLpConfig_getSystemPhysicalProcessors());
88
89 processors = (int)HvLpConfig_getPhysicalProcessors();
90 seq_printf(m, "partition_active_processors=%d\n", processors);
91
92 max_processors = (int)HvLpConfig_getMaxPhysicalProcessors();
93 seq_printf(m, "partition_potential_processors=%d\n", max_processors);
94
95 if (shared) {
96 entitled_capacity = HvLpConfig_getSharedProcUnits();
97 max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits();
98 } else {
99 entitled_capacity = processors * 100;
100 max_entitled_capacity = max_processors * 100;
101 }
102 seq_printf(m, "partition_entitled_capacity=%d\n", entitled_capacity);
103
104 seq_printf(m, "partition_max_entitled_capacity=%d\n",
105 max_entitled_capacity);
106
107 if (shared) {
108 pool_id = HvLpConfig_getSharedPoolIndex();
109 seq_printf(m, "pool=%d\n", (int)pool_id);
110 seq_printf(m, "pool_capacity=%d\n",
111 (int)(HvLpConfig_getNumProcsInSharedPool(pool_id) *
112 100));
113 seq_printf(m, "purr=%ld\n", purr);
114 }
115
116 seq_printf(m, "shared_processor_mode=%d\n", shared);
117
118 return 0;
119}
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000120
121#else /* CONFIG_PPC_ISERIES */
122
123static int iseries_lparcfg_data(struct seq_file *m, void *v)
124{
125 return 0;
126}
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#endif /* CONFIG_PPC_ISERIES */
129
130#ifdef CONFIG_PPC_PSERIES
David Gibsond3d21762005-11-10 15:26:20 +1100131/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 * Methods used to fetch LPAR data when running on a pSeries platform.
133 */
Stephen Rothwelld7867952005-11-14 17:14:51 +1100134/* find a better place for this function... */
135static void log_plpar_hcall_return(unsigned long rc, char *tag)
136{
137 if (rc == 0) /* success, return */
138 return;
139/* check for null tag ? */
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200140 if (rc == H_HARDWARE)
Stephen Rothwelld7867952005-11-14 17:14:51 +1100141 printk(KERN_INFO
142 "plpar-hcall (%s) failed with hardware fault\n", tag);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200143 else if (rc == H_FUNCTION)
Stephen Rothwelld7867952005-11-14 17:14:51 +1100144 printk(KERN_INFO
145 "plpar-hcall (%s) failed; function not allowed\n", tag);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200146 else if (rc == H_AUTHORITY)
Stephen Rothwelld7867952005-11-14 17:14:51 +1100147 printk(KERN_INFO
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200148 "plpar-hcall (%s) failed; not authorized to this"
149 " function\n", tag);
150 else if (rc == H_PARAMETER)
Stephen Rothwelld7867952005-11-14 17:14:51 +1100151 printk(KERN_INFO "plpar-hcall (%s) failed; Bad parameter(s)\n",
152 tag);
153 else
154 printk(KERN_INFO
155 "plpar-hcall (%s) failed with unexpected rc(0x%lx)\n",
156 tag, rc);
157
158}
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;
186 rc = plpar_hcall_4out(H_GET_PPP, 0, 0, 0, 0, entitled, unallocated,
187 aggregation, resource);
188
189 log_plpar_hcall_return(rc, "H_GET_PPP");
190
191 return rc;
192}
193
194static void h_pic(unsigned long *pool_idle_time, unsigned long *num_procs)
195{
196 unsigned long rc;
197 unsigned long dummy;
198 rc = plpar_hcall(H_PIC, 0, 0, 0, 0, pool_idle_time, num_procs, &dummy);
199
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200200 if (rc != H_AUTHORITY)
Anton Blanchard8acb8882005-11-11 13:53:11 +1100201 log_plpar_hcall_return(rc, "H_PIC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202}
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#define SPLPAR_CHARACTERISTICS_TOKEN 20
205#define SPLPAR_MAXLENGTH 1026*(sizeof(char))
206
207/*
208 * parse_system_parameter_string()
209 * Retrieve the potential_processors, max_entitled_capacity and friends
210 * through the get-system-parameter rtas call. Replace keyword strings as
211 * necessary.
212 */
213static void parse_system_parameter_string(struct seq_file *m)
214{
215 int call_status;
216
Will Schmidt34422fe2006-03-31 09:07:48 -0600217 unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 if (!local_buffer) {
219 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
220 __FILE__, __FUNCTION__, __LINE__);
221 return;
222 }
223
224 spin_lock(&rtas_data_buf_lock);
225 memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
226 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
227 NULL,
228 SPLPAR_CHARACTERISTICS_TOKEN,
Will Schmidt34422fe2006-03-31 09:07:48 -0600229 __pa(rtas_data_buf),
230 RTAS_DATA_BUF_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
232 spin_unlock(&rtas_data_buf_lock);
233
234 if (call_status != 0) {
235 printk(KERN_INFO
236 "%s %s Error calling get-system-parameter (0x%x)\n",
237 __FILE__, __FUNCTION__, call_status);
238 } else {
239 int splpar_strlen;
240 int idx, w_idx;
241 char *workbuffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
242 if (!workbuffer) {
243 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
244 __FILE__, __FUNCTION__, __LINE__);
David Gibsond3d21762005-11-10 15:26:20 +1100245 kfree(local_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 return;
247 }
248#ifdef LPARCFG_DEBUG
249 printk(KERN_INFO "success calling get-system-parameter \n");
250#endif
Will Schmidt34422fe2006-03-31 09:07:48 -0600251 splpar_strlen = local_buffer[0] * 256 + local_buffer[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 local_buffer += 2; /* step over strlen value */
253
254 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
255 w_idx = 0;
256 idx = 0;
257 while ((*local_buffer) && (idx < splpar_strlen)) {
258 workbuffer[w_idx++] = local_buffer[idx++];
259 if ((local_buffer[idx] == ',')
260 || (local_buffer[idx] == '\0')) {
261 workbuffer[w_idx] = '\0';
262 if (w_idx) {
263 /* avoid the empty string */
264 seq_printf(m, "%s\n", workbuffer);
265 }
266 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
267 idx++; /* skip the comma */
268 w_idx = 0;
269 } else if (local_buffer[idx] == '=') {
270 /* code here to replace workbuffer contents
271 with different keyword strings */
272 if (0 == strcmp(workbuffer, "MaxEntCap")) {
273 strcpy(workbuffer,
274 "partition_max_entitled_capacity");
275 w_idx = strlen(workbuffer);
276 }
277 if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
278 strcpy(workbuffer,
279 "system_potential_processors");
280 w_idx = strlen(workbuffer);
281 }
282 }
283 }
284 kfree(workbuffer);
285 local_buffer -= 2; /* back up over strlen value */
286 }
287 kfree(local_buffer);
288}
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290/* Return the number of processors in the system.
291 * This function reads through the device tree and counts
292 * the virtual processors, this does not include threads.
293 */
294static int lparcfg_count_active_processors(void)
295{
296 struct device_node *cpus_dn = NULL;
297 int count = 0;
298
299 while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
300#ifdef LPARCFG_DEBUG
301 printk(KERN_ERR "cpus_dn %p \n", cpus_dn);
302#endif
303 count++;
304 }
305 return count;
306}
307
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000308static int pseries_lparcfg_data(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 int partition_potential_processors;
311 int partition_active_processors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 struct device_node *rtas_node;
Olof Johansson2b9a32e2006-02-15 21:40:44 -0600313 int *lrdrp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 rtas_node = find_path_device("/rtas");
Olof Johansson2b9a32e2006-02-15 21:40:44 -0600316 if (rtas_node)
317 lrdrp = (int *)get_property(rtas_node, "ibm,lrdr-capacity",
318 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 if (lrdrp == NULL) {
Paul Mackerras271c3f32005-11-11 23:04:40 +1100321 partition_potential_processors = vdso_data->processorCount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 } else {
323 partition_potential_processors = *(lrdrp + 4);
324 }
325
326 partition_active_processors = lparcfg_count_active_processors();
327
Stephen Rothwell1ababe12005-08-03 14:35:25 +1000328 if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 unsigned long h_entitled, h_unallocated;
330 unsigned long h_aggregation, h_resource;
331 unsigned long pool_idle_time, pool_procs;
332 unsigned long purr;
333
334 h_get_ppp(&h_entitled, &h_unallocated, &h_aggregation,
335 &h_resource);
336
337 seq_printf(m, "R4=0x%lx\n", h_entitled);
338 seq_printf(m, "R5=0x%lx\n", h_unallocated);
339 seq_printf(m, "R6=0x%lx\n", h_aggregation);
340 seq_printf(m, "R7=0x%lx\n", h_resource);
341
342 purr = get_purr();
343
344 /* this call handles the ibm,get-system-parameter contents */
345 parse_system_parameter_string(m);
346
347 seq_printf(m, "partition_entitled_capacity=%ld\n", h_entitled);
348
349 seq_printf(m, "group=%ld\n", (h_aggregation >> 2 * 8) & 0xffff);
350
351 seq_printf(m, "system_active_processors=%ld\n",
352 (h_resource >> 0 * 8) & 0xffff);
353
354 /* pool related entries are apropriate for shared configs */
David Gibson3356bb92006-01-13 10:26:42 +1100355 if (lppaca[0].shared_proc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 h_pic(&pool_idle_time, &pool_procs);
358
359 seq_printf(m, "pool=%ld\n",
360 (h_aggregation >> 0 * 8) & 0xffff);
361
362 /* report pool_capacity in percentage */
363 seq_printf(m, "pool_capacity=%ld\n",
364 ((h_resource >> 2 * 8) & 0xffff) * 100);
365
366 seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
367
368 seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
369 }
370
371 seq_printf(m, "unallocated_capacity_weight=%ld\n",
372 (h_resource >> 4 * 8) & 0xFF);
373
374 seq_printf(m, "capacity_weight=%ld\n",
375 (h_resource >> 5 * 8) & 0xFF);
376
377 seq_printf(m, "capped=%ld\n", (h_resource >> 6 * 8) & 0x01);
378
379 seq_printf(m, "unallocated_capacity=%ld\n", h_unallocated);
380
381 seq_printf(m, "purr=%ld\n", purr);
382
383 } else { /* non SPLPAR case */
384
385 seq_printf(m, "system_active_processors=%d\n",
386 partition_potential_processors);
387
388 seq_printf(m, "system_potential_processors=%d\n",
389 partition_potential_processors);
390
391 seq_printf(m, "partition_max_entitled_capacity=%d\n",
392 partition_potential_processors * 100);
393
394 seq_printf(m, "partition_entitled_capacity=%d\n",
395 partition_active_processors * 100);
396 }
397
398 seq_printf(m, "partition_active_processors=%d\n",
399 partition_active_processors);
400
401 seq_printf(m, "partition_potential_processors=%d\n",
402 partition_potential_processors);
403
David Gibson3356bb92006-01-13 10:26:42 +1100404 seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 return 0;
407}
408
409/*
410 * Interface for changing system parameters (variable capacity weight
411 * and entitled capacity). Format of input is "param_name=value";
412 * anything after value is ignored. Valid parameters at this time are
413 * "partition_entitled_capacity" and "capacity_weight". We use
414 * H_SET_PPP to alter parameters.
415 *
416 * This function should be invoked only on systems with
417 * FW_FEATURE_SPLPAR.
418 */
419static ssize_t lparcfg_write(struct file *file, const char __user * buf,
420 size_t count, loff_t * off)
421{
422 char *kbuf;
423 char *tmp;
424 u64 new_entitled, *new_entitled_ptr = &new_entitled;
425 u8 new_weight, *new_weight_ptr = &new_weight;
426
427 unsigned long current_entitled; /* parameters for h_get_ppp */
428 unsigned long dummy;
429 unsigned long resource;
430 u8 current_weight;
431
432 ssize_t retval = -ENOMEM;
433
434 kbuf = kmalloc(count, GFP_KERNEL);
435 if (!kbuf)
436 goto out;
437
438 retval = -EFAULT;
439 if (copy_from_user(kbuf, buf, count))
440 goto out;
441
442 retval = -EINVAL;
443 kbuf[count - 1] = '\0';
444 tmp = strchr(kbuf, '=');
445 if (!tmp)
446 goto out;
447
448 *tmp++ = '\0';
449
450 if (!strcmp(kbuf, "partition_entitled_capacity")) {
451 char *endp;
452 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
453 if (endp == tmp)
454 goto out;
455 new_weight_ptr = &current_weight;
456 } else if (!strcmp(kbuf, "capacity_weight")) {
457 char *endp;
458 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
459 if (endp == tmp)
460 goto out;
461 new_entitled_ptr = &current_entitled;
462 } else
463 goto out;
464
465 /* Get our current parameters */
466 retval = h_get_ppp(&current_entitled, &dummy, &dummy, &resource);
467 if (retval) {
468 retval = -EIO;
469 goto out;
470 }
471
472 current_weight = (resource >> 5 * 8) & 0xFF;
473
jimix@watson.ibm.com8ae5b282006-05-17 12:00:35 -0400474 pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 __FUNCTION__, current_entitled, current_weight);
476
jimix@watson.ibm.com8ae5b282006-05-17 12:00:35 -0400477 pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 __FUNCTION__, *new_entitled_ptr, *new_weight_ptr);
479
480 retval = plpar_hcall_norets(H_SET_PPP, *new_entitled_ptr,
481 *new_weight_ptr);
482
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200483 if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 retval = count;
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200485 } else if (retval == H_BUSY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 retval = -EBUSY;
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200487 } else if (retval == H_HARDWARE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 retval = -EIO;
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200489 } else if (retval == H_PARAMETER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 retval = -EINVAL;
491 } else {
492 printk(KERN_WARNING "%s: received unknown hv return code %ld",
493 __FUNCTION__, retval);
494 retval = -EIO;
495 }
496
Anton Blanchard8acb8882005-11-11 13:53:11 +1100497out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 kfree(kbuf);
499 return retval;
500}
501
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000502#else /* CONFIG_PPC_PSERIES */
503
504static int pseries_lparcfg_data(struct seq_file *m, void *v)
505{
506 return 0;
507}
508
509static ssize_t lparcfg_write(struct file *file, const char __user * buf,
510 size_t count, loff_t * off)
511{
512 return count;
513}
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#endif /* CONFIG_PPC_PSERIES */
516
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000517static int lparcfg_data(struct seq_file *m, void *v)
518{
519 struct device_node *rootdn;
520 const char *model = "";
521 const char *system_id = "";
522 const char *tmp;
523 unsigned int *lp_index_ptr, lp_index = 0;
524
525 seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS);
526
527 rootdn = find_path_device("/");
528 if (rootdn) {
529 tmp = get_property(rootdn, "model", NULL);
530 if (tmp) {
531 model = tmp;
532 /* Skip "IBM," - see platforms/iseries/dt.c */
533 if (firmware_has_feature(FW_FEATURE_ISERIES))
534 model += 4;
535 }
536 tmp = get_property(rootdn, "system-id", NULL);
537 if (tmp) {
538 system_id = tmp;
539 /* Skip "IBM," - see platforms/iseries/dt.c */
540 if (firmware_has_feature(FW_FEATURE_ISERIES))
541 system_id += 4;
542 }
543 lp_index_ptr = (unsigned int *)
544 get_property(rootdn, "ibm,partition-no", NULL);
545 if (lp_index_ptr)
546 lp_index = *lp_index_ptr;
547 }
548 seq_printf(m, "serial_number=%s\n", system_id);
549 seq_printf(m, "system_type=%s\n", model);
550 seq_printf(m, "partition_id=%d\n", (int)lp_index);
551
552 if (firmware_has_feature(FW_FEATURE_ISERIES))
553 return iseries_lparcfg_data(m, v);
554 return pseries_lparcfg_data(m, v);
555}
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557static int lparcfg_open(struct inode *inode, struct file *file)
558{
559 return single_open(file, lparcfg_data, NULL);
560}
561
562struct file_operations lparcfg_fops = {
Anton Blanchard8acb8882005-11-11 13:53:11 +1100563 .owner = THIS_MODULE,
564 .read = seq_read,
565 .open = lparcfg_open,
566 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567};
568
569int __init lparcfg_init(void)
570{
571 struct proc_dir_entry *ent;
Wim Coekaerts71839262005-09-05 20:22:47 -0700572 mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 /* Allow writing if we have FW_FEATURE_SPLPAR */
Stephen Rothwell16e9f992006-06-29 15:07:42 +1000575 if (firmware_has_feature(FW_FEATURE_SPLPAR) &&
576 !firmware_has_feature(FW_FEATURE_ISERIES)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 lparcfg_fops.write = lparcfg_write;
578 mode |= S_IWUSR;
579 }
580
581 ent = create_proc_entry("ppc64/lparcfg", mode, NULL);
582 if (ent) {
583 ent->proc_fops = &lparcfg_fops;
584 ent->data = kmalloc(LPARCFG_BUFF_SIZE, GFP_KERNEL);
585 if (!ent->data) {
586 printk(KERN_ERR
587 "Failed to allocate buffer for lparcfg\n");
588 remove_proc_entry("lparcfg", ent->parent);
589 return -ENOMEM;
590 }
591 } else {
592 printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
593 return -EIO;
594 }
595
596 proc_ppc64_lparcfg = ent;
597 return 0;
598}
599
600void __exit lparcfg_cleanup(void)
601{
602 if (proc_ppc64_lparcfg) {
Jesper Juhlb2325fe2005-11-07 01:01:35 -0800603 kfree(proc_ppc64_lparcfg->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
605 }
606}
607
608module_init(lparcfg_init);
609module_exit(lparcfg_cleanup);
610MODULE_DESCRIPTION("Interface for LPAR configuration data");
611MODULE_AUTHOR("Dave Engebretsen");
612MODULE_LICENSE("GPL");