• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/arch/powerpc/kernel/
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
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 <linux/slab.h>
28#include <asm/uaccess.h>
29#include <asm/iseries/hv_lp_config.h>
30#include <asm/lppaca.h>
31#include <asm/hvcall.h>
32#include <asm/firmware.h>
33#include <asm/rtas.h>
34#include <asm/system.h>
35#include <asm/time.h>
36#include <asm/prom.h>
37#include <asm/vdso_datapage.h>
38#include <asm/vio.h>
39#include <asm/mmu.h>
40
41#define MODULE_VERS "1.9"
42#define MODULE_NAME "lparcfg"
43
44/* #define LPARCFG_DEBUG */
45
46static struct proc_dir_entry *proc_ppc64_lparcfg;
47
48/*
49 * Track sum of all purrs across all processors. This is used to further
50 * calculate usage values by different applications
51 */
52static unsigned long get_purr(void)
53{
54	unsigned long sum_purr = 0;
55	int cpu;
56
57	for_each_possible_cpu(cpu) {
58		if (firmware_has_feature(FW_FEATURE_ISERIES))
59			sum_purr += lppaca[cpu].emulated_time_base;
60		else {
61			struct cpu_usage *cu;
62
63			cu = &per_cpu(cpu_usage_array, cpu);
64			sum_purr += cu->current_tb;
65		}
66	}
67	return sum_purr;
68}
69
70#ifdef CONFIG_PPC_ISERIES
71
72/*
73 * Methods used to fetch LPAR data when running on an iSeries platform.
74 */
75static int iseries_lparcfg_data(struct seq_file *m, void *v)
76{
77	unsigned long pool_id;
78	int shared, entitled_capacity, max_entitled_capacity;
79	int processors, max_processors;
80	unsigned long purr = get_purr();
81
82	shared = (int)(local_paca->lppaca_ptr->shared_proc);
83
84	seq_printf(m, "system_active_processors=%d\n",
85		   (int)HvLpConfig_getSystemPhysicalProcessors());
86
87	seq_printf(m, "system_potential_processors=%d\n",
88		   (int)HvLpConfig_getSystemPhysicalProcessors());
89
90	processors = (int)HvLpConfig_getPhysicalProcessors();
91	seq_printf(m, "partition_active_processors=%d\n", processors);
92
93	max_processors = (int)HvLpConfig_getMaxPhysicalProcessors();
94	seq_printf(m, "partition_potential_processors=%d\n", max_processors);
95
96	if (shared) {
97		entitled_capacity = HvLpConfig_getSharedProcUnits();
98		max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits();
99	} else {
100		entitled_capacity = processors * 100;
101		max_entitled_capacity = max_processors * 100;
102	}
103	seq_printf(m, "partition_entitled_capacity=%d\n", entitled_capacity);
104
105	seq_printf(m, "partition_max_entitled_capacity=%d\n",
106		   max_entitled_capacity);
107
108	if (shared) {
109		pool_id = HvLpConfig_getSharedPoolIndex();
110		seq_printf(m, "pool=%d\n", (int)pool_id);
111		seq_printf(m, "pool_capacity=%d\n",
112			   (int)(HvLpConfig_getNumProcsInSharedPool(pool_id) *
113				 100));
114		seq_printf(m, "purr=%ld\n", purr);
115	}
116
117	seq_printf(m, "shared_processor_mode=%d\n", shared);
118
119	return 0;
120}
121
122#else				/* CONFIG_PPC_ISERIES */
123
124static int iseries_lparcfg_data(struct seq_file *m, void *v)
125{
126	return 0;
127}
128
129#endif				/* CONFIG_PPC_ISERIES */
130
131#ifdef CONFIG_PPC_PSERIES
132/*
133 * Methods used to fetch LPAR data when running on a pSeries platform.
134 */
135/**
136 * h_get_mpp
137 * H_GET_MPP hcall returns info in 7 parms
138 */
139int h_get_mpp(struct hvcall_mpp_data *mpp_data)
140{
141	int rc;
142	unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
143
144	rc = plpar_hcall9(H_GET_MPP, retbuf);
145
146	mpp_data->entitled_mem = retbuf[0];
147	mpp_data->mapped_mem = retbuf[1];
148
149	mpp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
150	mpp_data->pool_num = retbuf[2] & 0xffff;
151
152	mpp_data->mem_weight = (retbuf[3] >> 7 * 8) & 0xff;
153	mpp_data->unallocated_mem_weight = (retbuf[3] >> 6 * 8) & 0xff;
154	mpp_data->unallocated_entitlement = retbuf[3] & 0xffffffffffff;
155
156	mpp_data->pool_size = retbuf[4];
157	mpp_data->loan_request = retbuf[5];
158	mpp_data->backing_mem = retbuf[6];
159
160	return rc;
161}
162EXPORT_SYMBOL(h_get_mpp);
163
164struct hvcall_ppp_data {
165	u64	entitlement;
166	u64	unallocated_entitlement;
167	u16	group_num;
168	u16	pool_num;
169	u8	capped;
170	u8	weight;
171	u8	unallocated_weight;
172	u16	active_procs_in_pool;
173	u16	active_system_procs;
174	u16	phys_platform_procs;
175	u32	max_proc_cap_avail;
176	u32	entitled_proc_cap_avail;
177};
178
179static unsigned int h_get_ppp(struct hvcall_ppp_data *ppp_data)
180{
181	unsigned long rc;
182	unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
183
184	rc = plpar_hcall9(H_GET_PPP, retbuf);
185
186	ppp_data->entitlement = retbuf[0];
187	ppp_data->unallocated_entitlement = retbuf[1];
188
189	ppp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
190	ppp_data->pool_num = retbuf[2] & 0xffff;
191
192	ppp_data->capped = (retbuf[3] >> 6 * 8) & 0x01;
193	ppp_data->weight = (retbuf[3] >> 5 * 8) & 0xff;
194	ppp_data->unallocated_weight = (retbuf[3] >> 4 * 8) & 0xff;
195	ppp_data->active_procs_in_pool = (retbuf[3] >> 2 * 8) & 0xffff;
196	ppp_data->active_system_procs = retbuf[3] & 0xffff;
197
198	ppp_data->phys_platform_procs = retbuf[4] >> 6 * 8;
199	ppp_data->max_proc_cap_avail = (retbuf[4] >> 3 * 8) & 0xffffff;
200	ppp_data->entitled_proc_cap_avail = retbuf[4] & 0xffffff;
201
202	return rc;
203}
204
205static unsigned h_pic(unsigned long *pool_idle_time,
206		      unsigned long *num_procs)
207{
208	unsigned long rc;
209	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
210
211	rc = plpar_hcall(H_PIC, retbuf);
212
213	*pool_idle_time = retbuf[0];
214	*num_procs = retbuf[1];
215
216	return rc;
217}
218
219/*
220 * parse_ppp_data
221 * Parse out the data returned from h_get_ppp and h_pic
222 */
223static void parse_ppp_data(struct seq_file *m)
224{
225	struct hvcall_ppp_data ppp_data;
226	struct device_node *root;
227	const int *perf_level;
228	int rc;
229
230	rc = h_get_ppp(&ppp_data);
231	if (rc)
232		return;
233
234	seq_printf(m, "partition_entitled_capacity=%lld\n",
235	           ppp_data.entitlement);
236	seq_printf(m, "group=%d\n", ppp_data.group_num);
237	seq_printf(m, "system_active_processors=%d\n",
238	           ppp_data.active_system_procs);
239
240	/* pool related entries are apropriate for shared configs */
241	if (lppaca[0].shared_proc) {
242		unsigned long pool_idle_time, pool_procs;
243
244		seq_printf(m, "pool=%d\n", ppp_data.pool_num);
245
246		/* report pool_capacity in percentage */
247		seq_printf(m, "pool_capacity=%d\n",
248			   ppp_data.active_procs_in_pool * 100);
249
250		h_pic(&pool_idle_time, &pool_procs);
251		seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
252		seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
253	}
254
255	seq_printf(m, "unallocated_capacity_weight=%d\n",
256		   ppp_data.unallocated_weight);
257	seq_printf(m, "capacity_weight=%d\n", ppp_data.weight);
258	seq_printf(m, "capped=%d\n", ppp_data.capped);
259	seq_printf(m, "unallocated_capacity=%lld\n",
260		   ppp_data.unallocated_entitlement);
261
262	/* The last bits of information returned from h_get_ppp are only
263	 * valid if the ibm,partition-performance-parameters-level
264	 * property is >= 1.
265	 */
266	root = of_find_node_by_path("/");
267	if (root) {
268		perf_level = of_get_property(root,
269				"ibm,partition-performance-parameters-level",
270					     NULL);
271		if (perf_level && (*perf_level >= 1)) {
272			seq_printf(m,
273			    "physical_procs_allocated_to_virtualization=%d\n",
274				   ppp_data.phys_platform_procs);
275			seq_printf(m, "max_proc_capacity_available=%d\n",
276				   ppp_data.max_proc_cap_avail);
277			seq_printf(m, "entitled_proc_capacity_available=%d\n",
278				   ppp_data.entitled_proc_cap_avail);
279		}
280
281		of_node_put(root);
282	}
283}
284
285/**
286 * parse_mpp_data
287 * Parse out data returned from h_get_mpp
288 */
289static void parse_mpp_data(struct seq_file *m)
290{
291	struct hvcall_mpp_data mpp_data;
292	int rc;
293
294	rc = h_get_mpp(&mpp_data);
295	if (rc)
296		return;
297
298	seq_printf(m, "entitled_memory=%ld\n", mpp_data.entitled_mem);
299
300	if (mpp_data.mapped_mem != -1)
301		seq_printf(m, "mapped_entitled_memory=%ld\n",
302		           mpp_data.mapped_mem);
303
304	seq_printf(m, "entitled_memory_group_number=%d\n", mpp_data.group_num);
305	seq_printf(m, "entitled_memory_pool_number=%d\n", mpp_data.pool_num);
306
307	seq_printf(m, "entitled_memory_weight=%d\n", mpp_data.mem_weight);
308	seq_printf(m, "unallocated_entitled_memory_weight=%d\n",
309	           mpp_data.unallocated_mem_weight);
310	seq_printf(m, "unallocated_io_mapping_entitlement=%ld\n",
311	           mpp_data.unallocated_entitlement);
312
313	if (mpp_data.pool_size != -1)
314		seq_printf(m, "entitled_memory_pool_size=%ld bytes\n",
315		           mpp_data.pool_size);
316
317	seq_printf(m, "entitled_memory_loan_request=%ld\n",
318	           mpp_data.loan_request);
319
320	seq_printf(m, "backing_memory=%ld bytes\n", mpp_data.backing_mem);
321}
322
323#define SPLPAR_CHARACTERISTICS_TOKEN 20
324#define SPLPAR_MAXLENGTH 1026*(sizeof(char))
325
326/*
327 * parse_system_parameter_string()
328 * Retrieve the potential_processors, max_entitled_capacity and friends
329 * through the get-system-parameter rtas call.  Replace keyword strings as
330 * necessary.
331 */
332static void parse_system_parameter_string(struct seq_file *m)
333{
334	int call_status;
335
336	unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
337	if (!local_buffer) {
338		printk(KERN_ERR "%s %s kmalloc failure at line %d\n",
339		       __FILE__, __func__, __LINE__);
340		return;
341	}
342
343	spin_lock(&rtas_data_buf_lock);
344	memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
345	call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
346				NULL,
347				SPLPAR_CHARACTERISTICS_TOKEN,
348				__pa(rtas_data_buf),
349				RTAS_DATA_BUF_SIZE);
350	memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
351	spin_unlock(&rtas_data_buf_lock);
352
353	if (call_status != 0) {
354		printk(KERN_INFO
355		       "%s %s Error calling get-system-parameter (0x%x)\n",
356		       __FILE__, __func__, call_status);
357	} else {
358		int splpar_strlen;
359		int idx, w_idx;
360		char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
361		if (!workbuffer) {
362			printk(KERN_ERR "%s %s kmalloc failure at line %d\n",
363			       __FILE__, __func__, __LINE__);
364			kfree(local_buffer);
365			return;
366		}
367#ifdef LPARCFG_DEBUG
368		printk(KERN_INFO "success calling get-system-parameter\n");
369#endif
370		splpar_strlen = local_buffer[0] * 256 + local_buffer[1];
371		local_buffer += 2;	/* step over strlen value */
372
373		w_idx = 0;
374		idx = 0;
375		while ((*local_buffer) && (idx < splpar_strlen)) {
376			workbuffer[w_idx++] = local_buffer[idx++];
377			if ((local_buffer[idx] == ',')
378			    || (local_buffer[idx] == '\0')) {
379				workbuffer[w_idx] = '\0';
380				if (w_idx) {
381					/* avoid the empty string */
382					seq_printf(m, "%s\n", workbuffer);
383				}
384				memset(workbuffer, 0, SPLPAR_MAXLENGTH);
385				idx++;	/* skip the comma */
386				w_idx = 0;
387			} else if (local_buffer[idx] == '=') {
388				/* code here to replace workbuffer contents
389				   with different keyword strings */
390				if (0 == strcmp(workbuffer, "MaxEntCap")) {
391					strcpy(workbuffer,
392					       "partition_max_entitled_capacity");
393					w_idx = strlen(workbuffer);
394				}
395				if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
396					strcpy(workbuffer,
397					       "system_potential_processors");
398					w_idx = strlen(workbuffer);
399				}
400			}
401		}
402		kfree(workbuffer);
403		local_buffer -= 2;	/* back up over strlen value */
404	}
405	kfree(local_buffer);
406}
407
408/* Return the number of processors in the system.
409 * This function reads through the device tree and counts
410 * the virtual processors, this does not include threads.
411 */
412static int lparcfg_count_active_processors(void)
413{
414	struct device_node *cpus_dn = NULL;
415	int count = 0;
416
417	while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
418#ifdef LPARCFG_DEBUG
419		printk(KERN_ERR "cpus_dn %p\n", cpus_dn);
420#endif
421		count++;
422	}
423	return count;
424}
425
426static void pseries_cmo_data(struct seq_file *m)
427{
428	int cpu;
429	unsigned long cmo_faults = 0;
430	unsigned long cmo_fault_time = 0;
431
432	seq_printf(m, "cmo_enabled=%d\n", firmware_has_feature(FW_FEATURE_CMO));
433
434	if (!firmware_has_feature(FW_FEATURE_CMO))
435		return;
436
437	for_each_possible_cpu(cpu) {
438		cmo_faults += lppaca[cpu].cmo_faults;
439		cmo_fault_time += lppaca[cpu].cmo_fault_time;
440	}
441
442	seq_printf(m, "cmo_faults=%lu\n", cmo_faults);
443	seq_printf(m, "cmo_fault_time_usec=%lu\n",
444		   cmo_fault_time / tb_ticks_per_usec);
445	seq_printf(m, "cmo_primary_psp=%d\n", cmo_get_primary_psp());
446	seq_printf(m, "cmo_secondary_psp=%d\n", cmo_get_secondary_psp());
447	seq_printf(m, "cmo_page_size=%lu\n", cmo_get_page_size());
448}
449
450static void splpar_dispatch_data(struct seq_file *m)
451{
452	int cpu;
453	unsigned long dispatches = 0;
454	unsigned long dispatch_dispersions = 0;
455
456	for_each_possible_cpu(cpu) {
457		dispatches += lppaca[cpu].yield_count;
458		dispatch_dispersions += lppaca[cpu].dispersion_count;
459	}
460
461	seq_printf(m, "dispatches=%lu\n", dispatches);
462	seq_printf(m, "dispatch_dispersions=%lu\n", dispatch_dispersions);
463}
464
465static void parse_em_data(struct seq_file *m)
466{
467	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
468
469	if (plpar_hcall(H_GET_EM_PARMS, retbuf) == H_SUCCESS)
470		seq_printf(m, "power_mode_data=%016lx\n", retbuf[0]);
471}
472
473static int pseries_lparcfg_data(struct seq_file *m, void *v)
474{
475	int partition_potential_processors;
476	int partition_active_processors;
477	struct device_node *rtas_node;
478	const int *lrdrp = NULL;
479
480	rtas_node = of_find_node_by_path("/rtas");
481	if (rtas_node)
482		lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL);
483
484	if (lrdrp == NULL) {
485		partition_potential_processors = vdso_data->processorCount;
486	} else {
487		partition_potential_processors = *(lrdrp + 4);
488	}
489	of_node_put(rtas_node);
490
491	partition_active_processors = lparcfg_count_active_processors();
492
493	if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
494		/* this call handles the ibm,get-system-parameter contents */
495		parse_system_parameter_string(m);
496		parse_ppp_data(m);
497		parse_mpp_data(m);
498		pseries_cmo_data(m);
499		splpar_dispatch_data(m);
500
501		seq_printf(m, "purr=%ld\n", get_purr());
502	} else {		/* non SPLPAR case */
503
504		seq_printf(m, "system_active_processors=%d\n",
505			   partition_potential_processors);
506
507		seq_printf(m, "system_potential_processors=%d\n",
508			   partition_potential_processors);
509
510		seq_printf(m, "partition_max_entitled_capacity=%d\n",
511			   partition_potential_processors * 100);
512
513		seq_printf(m, "partition_entitled_capacity=%d\n",
514			   partition_active_processors * 100);
515	}
516
517	seq_printf(m, "partition_active_processors=%d\n",
518		   partition_active_processors);
519
520	seq_printf(m, "partition_potential_processors=%d\n",
521		   partition_potential_processors);
522
523	seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc);
524
525	seq_printf(m, "slb_size=%d\n", mmu_slb_size);
526
527	parse_em_data(m);
528
529	return 0;
530}
531
532static ssize_t update_ppp(u64 *entitlement, u8 *weight)
533{
534	struct hvcall_ppp_data ppp_data;
535	u8 new_weight;
536	u64 new_entitled;
537	ssize_t retval;
538
539	/* Get our current parameters */
540	retval = h_get_ppp(&ppp_data);
541	if (retval)
542		return retval;
543
544	if (entitlement) {
545		new_weight = ppp_data.weight;
546		new_entitled = *entitlement;
547	} else if (weight) {
548		new_weight = *weight;
549		new_entitled = ppp_data.entitlement;
550	} else
551		return -EINVAL;
552
553	pr_debug("%s: current_entitled = %llu, current_weight = %u\n",
554		 __func__, ppp_data.entitlement, ppp_data.weight);
555
556	pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
557		 __func__, new_entitled, new_weight);
558
559	retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight);
560	return retval;
561}
562
563/**
564 * update_mpp
565 *
566 * Update the memory entitlement and weight for the partition.  Caller must
567 * specify either a new entitlement or weight, not both, to be updated
568 * since the h_set_mpp call takes both entitlement and weight as parameters.
569 */
570static ssize_t update_mpp(u64 *entitlement, u8 *weight)
571{
572	struct hvcall_mpp_data mpp_data;
573	u64 new_entitled;
574	u8 new_weight;
575	ssize_t rc;
576
577	if (entitlement) {
578		/* Check with vio to ensure the new memory entitlement
579		 * can be handled.
580		 */
581		rc = vio_cmo_entitlement_update(*entitlement);
582		if (rc)
583			return rc;
584	}
585
586	rc = h_get_mpp(&mpp_data);
587	if (rc)
588		return rc;
589
590	if (entitlement) {
591		new_weight = mpp_data.mem_weight;
592		new_entitled = *entitlement;
593	} else if (weight) {
594		new_weight = *weight;
595		new_entitled = mpp_data.entitled_mem;
596	} else
597		return -EINVAL;
598
599	pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
600	         __func__, mpp_data.entitled_mem, mpp_data.mem_weight);
601
602	pr_debug("%s: new_entitled = %llu, new_weight = %u\n",
603		 __func__, new_entitled, new_weight);
604
605	rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight);
606	return rc;
607}
608
609/*
610 * Interface for changing system parameters (variable capacity weight
611 * and entitled capacity).  Format of input is "param_name=value";
612 * anything after value is ignored.  Valid parameters at this time are
613 * "partition_entitled_capacity" and "capacity_weight".  We use
614 * H_SET_PPP to alter parameters.
615 *
616 * This function should be invoked only on systems with
617 * FW_FEATURE_SPLPAR.
618 */
619static ssize_t lparcfg_write(struct file *file, const char __user * buf,
620			     size_t count, loff_t * off)
621{
622	int kbuf_sz = 64;
623	char kbuf[kbuf_sz];
624	char *tmp;
625	u64 new_entitled, *new_entitled_ptr = &new_entitled;
626	u8 new_weight, *new_weight_ptr = &new_weight;
627	ssize_t retval;
628
629	if (!firmware_has_feature(FW_FEATURE_SPLPAR) ||
630			firmware_has_feature(FW_FEATURE_ISERIES))
631		return -EINVAL;
632
633	if (count > kbuf_sz)
634		return -EINVAL;
635
636	if (copy_from_user(kbuf, buf, count))
637		return -EFAULT;
638
639	kbuf[count - 1] = '\0';
640	tmp = strchr(kbuf, '=');
641	if (!tmp)
642		return -EINVAL;
643
644	*tmp++ = '\0';
645
646	if (!strcmp(kbuf, "partition_entitled_capacity")) {
647		char *endp;
648		*new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
649		if (endp == tmp)
650			return -EINVAL;
651
652		retval = update_ppp(new_entitled_ptr, NULL);
653	} else if (!strcmp(kbuf, "capacity_weight")) {
654		char *endp;
655		*new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
656		if (endp == tmp)
657			return -EINVAL;
658
659		retval = update_ppp(NULL, new_weight_ptr);
660	} else if (!strcmp(kbuf, "entitled_memory")) {
661		char *endp;
662		*new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
663		if (endp == tmp)
664			return -EINVAL;
665
666		retval = update_mpp(new_entitled_ptr, NULL);
667	} else if (!strcmp(kbuf, "entitled_memory_weight")) {
668		char *endp;
669		*new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
670		if (endp == tmp)
671			return -EINVAL;
672
673		retval = update_mpp(NULL, new_weight_ptr);
674	} else
675		return -EINVAL;
676
677	if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
678		retval = count;
679	} else if (retval == H_BUSY) {
680		retval = -EBUSY;
681	} else if (retval == H_HARDWARE) {
682		retval = -EIO;
683	} else if (retval == H_PARAMETER) {
684		retval = -EINVAL;
685	}
686
687	return retval;
688}
689
690#else				/* CONFIG_PPC_PSERIES */
691
692static int pseries_lparcfg_data(struct seq_file *m, void *v)
693{
694	return 0;
695}
696
697static ssize_t lparcfg_write(struct file *file, const char __user * buf,
698			     size_t count, loff_t * off)
699{
700	return -EINVAL;
701}
702
703#endif				/* CONFIG_PPC_PSERIES */
704
705static int lparcfg_data(struct seq_file *m, void *v)
706{
707	struct device_node *rootdn;
708	const char *model = "";
709	const char *system_id = "";
710	const char *tmp;
711	const unsigned int *lp_index_ptr;
712	unsigned int lp_index = 0;
713
714	seq_printf(m, "%s %s\n", MODULE_NAME, MODULE_VERS);
715
716	rootdn = of_find_node_by_path("/");
717	if (rootdn) {
718		tmp = of_get_property(rootdn, "model", NULL);
719		if (tmp) {
720			model = tmp;
721			/* Skip "IBM," - see platforms/iseries/dt.c */
722			if (firmware_has_feature(FW_FEATURE_ISERIES))
723				model += 4;
724		}
725		tmp = of_get_property(rootdn, "system-id", NULL);
726		if (tmp) {
727			system_id = tmp;
728			/* Skip "IBM," - see platforms/iseries/dt.c */
729			if (firmware_has_feature(FW_FEATURE_ISERIES))
730				system_id += 4;
731		}
732		lp_index_ptr = of_get_property(rootdn, "ibm,partition-no",
733					NULL);
734		if (lp_index_ptr)
735			lp_index = *lp_index_ptr;
736		of_node_put(rootdn);
737	}
738	seq_printf(m, "serial_number=%s\n", system_id);
739	seq_printf(m, "system_type=%s\n", model);
740	seq_printf(m, "partition_id=%d\n", (int)lp_index);
741
742	if (firmware_has_feature(FW_FEATURE_ISERIES))
743		return iseries_lparcfg_data(m, v);
744	return pseries_lparcfg_data(m, v);
745}
746
747static int lparcfg_open(struct inode *inode, struct file *file)
748{
749	return single_open(file, lparcfg_data, NULL);
750}
751
752static const struct file_operations lparcfg_fops = {
753	.owner		= THIS_MODULE,
754	.read		= seq_read,
755	.write		= lparcfg_write,
756	.open		= lparcfg_open,
757	.release	= single_release,
758};
759
760static int __init lparcfg_init(void)
761{
762	struct proc_dir_entry *ent;
763	mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
764
765	/* Allow writing if we have FW_FEATURE_SPLPAR */
766	if (firmware_has_feature(FW_FEATURE_SPLPAR) &&
767			!firmware_has_feature(FW_FEATURE_ISERIES))
768		mode |= S_IWUSR;
769
770	ent = proc_create("powerpc/lparcfg", mode, NULL, &lparcfg_fops);
771	if (!ent) {
772		printk(KERN_ERR "Failed to create powerpc/lparcfg\n");
773		return -EIO;
774	}
775
776	proc_ppc64_lparcfg = ent;
777	return 0;
778}
779
780static void __exit lparcfg_cleanup(void)
781{
782	if (proc_ppc64_lparcfg)
783		remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
784}
785
786module_init(lparcfg_init);
787module_exit(lparcfg_cleanup);
788MODULE_DESCRIPTION("Interface for LPAR configuration data");
789MODULE_AUTHOR("Dave Engebretsen");
790MODULE_LICENSE("GPL");
791