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