2 * PowerPC64 LPAR Configuration Information Driver
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.
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.
17 * This driver creates a proc file at /proc/ppc64/lparcfg which contains
18 * keyword - value pairs that specify the configuration of the partition.
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/errno.h>
25 #include <linux/proc_fs.h>
26 #include <linux/init.h>
27 #include <linux/seq_file.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>
34 #include <asm/system.h>
36 #include <asm/iseries/it_exp_vpd_panel.h>
38 #include <asm/vdso_datapage.h>
40 #define MODULE_VERS "1.7"
41 #define MODULE_NAME "lparcfg"
43 /* #define LPARCFG_DEBUG */
45 static struct proc_dir_entry
*proc_ppc64_lparcfg
;
46 #define LPARCFG_BUFF_SIZE 4096
48 #ifdef CONFIG_PPC_ISERIES
51 * For iSeries legacy systems, the PPA purr function is available from the
52 * emulated_time_base field in the paca.
54 static unsigned long get_purr(void)
56 unsigned long sum_purr
= 0;
59 for_each_possible_cpu(cpu
) {
60 sum_purr
+= lppaca
[cpu
].emulated_time_base
;
63 printk(KERN_INFO
"get_purr for cpu (%d) has value (%ld) \n",
64 cpu
, lppaca
[cpu
].emulated_time_base
);
70 #define lparcfg_write NULL
73 * Methods used to fetch LPAR data when running on an iSeries platform.
75 static int lparcfg_data(struct seq_file
*m
, void *v
)
77 unsigned long pool_id
, lp_index
;
78 int shared
, entitled_capacity
, max_entitled_capacity
;
79 int processors
, max_processors
;
80 unsigned long purr
= get_purr();
82 seq_printf(m
, "%s %s \n", MODULE_NAME
, MODULE_VERS
);
84 shared
= (int)(get_lppaca()->shared_proc
);
85 seq_printf(m
, "serial_number=%c%c%c%c%c%c%c\n",
86 e2a(xItExtVpdPanel
.mfgID
[2]),
87 e2a(xItExtVpdPanel
.mfgID
[3]),
88 e2a(xItExtVpdPanel
.systemSerial
[1]),
89 e2a(xItExtVpdPanel
.systemSerial
[2]),
90 e2a(xItExtVpdPanel
.systemSerial
[3]),
91 e2a(xItExtVpdPanel
.systemSerial
[4]),
92 e2a(xItExtVpdPanel
.systemSerial
[5]));
94 seq_printf(m
, "system_type=%c%c%c%c\n",
95 e2a(xItExtVpdPanel
.machineType
[0]),
96 e2a(xItExtVpdPanel
.machineType
[1]),
97 e2a(xItExtVpdPanel
.machineType
[2]),
98 e2a(xItExtVpdPanel
.machineType
[3]));
100 lp_index
= HvLpConfig_getLpIndex();
101 seq_printf(m
, "partition_id=%d\n", (int)lp_index
);
103 seq_printf(m
, "system_active_processors=%d\n",
104 (int)HvLpConfig_getSystemPhysicalProcessors());
106 seq_printf(m
, "system_potential_processors=%d\n",
107 (int)HvLpConfig_getSystemPhysicalProcessors());
109 processors
= (int)HvLpConfig_getPhysicalProcessors();
110 seq_printf(m
, "partition_active_processors=%d\n", processors
);
112 max_processors
= (int)HvLpConfig_getMaxPhysicalProcessors();
113 seq_printf(m
, "partition_potential_processors=%d\n", max_processors
);
116 entitled_capacity
= HvLpConfig_getSharedProcUnits();
117 max_entitled_capacity
= HvLpConfig_getMaxSharedProcUnits();
119 entitled_capacity
= processors
* 100;
120 max_entitled_capacity
= max_processors
* 100;
122 seq_printf(m
, "partition_entitled_capacity=%d\n", entitled_capacity
);
124 seq_printf(m
, "partition_max_entitled_capacity=%d\n",
125 max_entitled_capacity
);
128 pool_id
= HvLpConfig_getSharedPoolIndex();
129 seq_printf(m
, "pool=%d\n", (int)pool_id
);
130 seq_printf(m
, "pool_capacity=%d\n",
131 (int)(HvLpConfig_getNumProcsInSharedPool(pool_id
) *
133 seq_printf(m
, "purr=%ld\n", purr
);
136 seq_printf(m
, "shared_processor_mode=%d\n", shared
);
140 #endif /* CONFIG_PPC_ISERIES */
142 #ifdef CONFIG_PPC_PSERIES
144 * Methods used to fetch LPAR data when running on a pSeries platform.
146 /* find a better place for this function... */
147 static void log_plpar_hcall_return(unsigned long rc
, char *tag
)
149 if (rc
== 0) /* success, return */
151 /* check for null tag ? */
152 if (rc
== H_HARDWARE
)
154 "plpar-hcall (%s) failed with hardware fault\n", tag
);
155 else if (rc
== H_FUNCTION
)
157 "plpar-hcall (%s) failed; function not allowed\n", tag
);
158 else if (rc
== H_AUTHORITY
)
160 "plpar-hcall (%s) failed; not authorized to this"
162 else if (rc
== H_PARAMETER
)
163 printk(KERN_INFO
"plpar-hcall (%s) failed; Bad parameter(s)\n",
167 "plpar-hcall (%s) failed with unexpected rc(0x%lx)\n",
173 * H_GET_PPP hcall returns info in 4 parms.
174 * entitled_capacity,unallocated_capacity,
175 * aggregation, resource_capability).
177 * R4 = Entitled Processor Capacity Percentage.
178 * R5 = Unallocated Processor Capacity Percentage.
179 * R6 (AABBCCDDEEFFGGHH).
180 * XXXX - reserved (0)
181 * XXXX - reserved (0)
182 * XXXX - Group Number
183 * XXXX - Pool Number.
184 * R7 (IIJJKKLLMMNNOOPP).
186 * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
187 * XX - variable processor Capacity Weight
188 * XX - Unallocated Variable Processor Capacity Weight.
189 * XXXX - Active processors in Physical Processor Pool.
190 * XXXX - Processors active on platform.
192 static unsigned int h_get_ppp(unsigned long *entitled
,
193 unsigned long *unallocated
,
194 unsigned long *aggregation
,
195 unsigned long *resource
)
198 rc
= plpar_hcall_4out(H_GET_PPP
, 0, 0, 0, 0, entitled
, unallocated
,
199 aggregation
, resource
);
201 log_plpar_hcall_return(rc
, "H_GET_PPP");
206 static void h_pic(unsigned long *pool_idle_time
, unsigned long *num_procs
)
210 rc
= plpar_hcall(H_PIC
, 0, 0, 0, 0, pool_idle_time
, num_procs
, &dummy
);
212 if (rc
!= H_AUTHORITY
)
213 log_plpar_hcall_return(rc
, "H_PIC");
216 /* Track sum of all purrs across all processors. This is used to further */
217 /* calculate usage values by different applications */
219 static unsigned long get_purr(void)
221 unsigned long sum_purr
= 0;
223 struct cpu_usage
*cu
;
225 for_each_possible_cpu(cpu
) {
226 cu
= &per_cpu(cpu_usage_array
, cpu
);
227 sum_purr
+= cu
->current_tb
;
232 #define SPLPAR_CHARACTERISTICS_TOKEN 20
233 #define SPLPAR_MAXLENGTH 1026*(sizeof(char))
236 * parse_system_parameter_string()
237 * Retrieve the potential_processors, max_entitled_capacity and friends
238 * through the get-system-parameter rtas call. Replace keyword strings as
241 static void parse_system_parameter_string(struct seq_file
*m
)
245 unsigned char *local_buffer
= kmalloc(SPLPAR_MAXLENGTH
, GFP_KERNEL
);
247 printk(KERN_ERR
"%s %s kmalloc failure at line %d \n",
248 __FILE__
, __FUNCTION__
, __LINE__
);
252 spin_lock(&rtas_data_buf_lock
);
253 memset(rtas_data_buf
, 0, SPLPAR_MAXLENGTH
);
254 call_status
= rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
256 SPLPAR_CHARACTERISTICS_TOKEN
,
259 memcpy(local_buffer
, rtas_data_buf
, SPLPAR_MAXLENGTH
);
260 spin_unlock(&rtas_data_buf_lock
);
262 if (call_status
!= 0) {
264 "%s %s Error calling get-system-parameter (0x%x)\n",
265 __FILE__
, __FUNCTION__
, call_status
);
269 char *workbuffer
= kmalloc(SPLPAR_MAXLENGTH
, GFP_KERNEL
);
271 printk(KERN_ERR
"%s %s kmalloc failure at line %d \n",
272 __FILE__
, __FUNCTION__
, __LINE__
);
277 printk(KERN_INFO
"success calling get-system-parameter \n");
279 splpar_strlen
= local_buffer
[0] * 256 + local_buffer
[1];
280 local_buffer
+= 2; /* step over strlen value */
282 memset(workbuffer
, 0, SPLPAR_MAXLENGTH
);
285 while ((*local_buffer
) && (idx
< splpar_strlen
)) {
286 workbuffer
[w_idx
++] = local_buffer
[idx
++];
287 if ((local_buffer
[idx
] == ',')
288 || (local_buffer
[idx
] == '\0')) {
289 workbuffer
[w_idx
] = '\0';
291 /* avoid the empty string */
292 seq_printf(m
, "%s\n", workbuffer
);
294 memset(workbuffer
, 0, SPLPAR_MAXLENGTH
);
295 idx
++; /* skip the comma */
297 } else if (local_buffer
[idx
] == '=') {
298 /* code here to replace workbuffer contents
299 with different keyword strings */
300 if (0 == strcmp(workbuffer
, "MaxEntCap")) {
302 "partition_max_entitled_capacity");
303 w_idx
= strlen(workbuffer
);
305 if (0 == strcmp(workbuffer
, "MaxPlatProcs")) {
307 "system_potential_processors");
308 w_idx
= strlen(workbuffer
);
313 local_buffer
-= 2; /* back up over strlen value */
318 /* Return the number of processors in the system.
319 * This function reads through the device tree and counts
320 * the virtual processors, this does not include threads.
322 static int lparcfg_count_active_processors(void)
324 struct device_node
*cpus_dn
= NULL
;
327 while ((cpus_dn
= of_find_node_by_type(cpus_dn
, "cpu"))) {
329 printk(KERN_ERR
"cpus_dn %p \n", cpus_dn
);
336 static int lparcfg_data(struct seq_file
*m
, void *v
)
338 int partition_potential_processors
;
339 int partition_active_processors
;
340 struct device_node
*rootdn
;
341 const char *model
= "";
342 const char *system_id
= "";
343 unsigned int *lp_index_ptr
, lp_index
= 0;
344 struct device_node
*rtas_node
;
347 rootdn
= find_path_device("/");
349 model
= get_property(rootdn
, "model", NULL
);
350 system_id
= get_property(rootdn
, "system-id", NULL
);
351 lp_index_ptr
= (unsigned int *)
352 get_property(rootdn
, "ibm,partition-no", NULL
);
354 lp_index
= *lp_index_ptr
;
357 seq_printf(m
, "%s %s \n", MODULE_NAME
, MODULE_VERS
);
359 seq_printf(m
, "serial_number=%s\n", system_id
);
361 seq_printf(m
, "system_type=%s\n", model
);
363 seq_printf(m
, "partition_id=%d\n", (int)lp_index
);
365 rtas_node
= find_path_device("/rtas");
367 lrdrp
= (int *)get_property(rtas_node
, "ibm,lrdr-capacity",
371 partition_potential_processors
= vdso_data
->processorCount
;
373 partition_potential_processors
= *(lrdrp
+ 4);
376 partition_active_processors
= lparcfg_count_active_processors();
378 if (firmware_has_feature(FW_FEATURE_SPLPAR
)) {
379 unsigned long h_entitled
, h_unallocated
;
380 unsigned long h_aggregation
, h_resource
;
381 unsigned long pool_idle_time
, pool_procs
;
384 h_get_ppp(&h_entitled
, &h_unallocated
, &h_aggregation
,
387 seq_printf(m
, "R4=0x%lx\n", h_entitled
);
388 seq_printf(m
, "R5=0x%lx\n", h_unallocated
);
389 seq_printf(m
, "R6=0x%lx\n", h_aggregation
);
390 seq_printf(m
, "R7=0x%lx\n", h_resource
);
394 /* this call handles the ibm,get-system-parameter contents */
395 parse_system_parameter_string(m
);
397 seq_printf(m
, "partition_entitled_capacity=%ld\n", h_entitled
);
399 seq_printf(m
, "group=%ld\n", (h_aggregation
>> 2 * 8) & 0xffff);
401 seq_printf(m
, "system_active_processors=%ld\n",
402 (h_resource
>> 0 * 8) & 0xffff);
404 /* pool related entries are apropriate for shared configs */
405 if (lppaca
[0].shared_proc
) {
407 h_pic(&pool_idle_time
, &pool_procs
);
409 seq_printf(m
, "pool=%ld\n",
410 (h_aggregation
>> 0 * 8) & 0xffff);
412 /* report pool_capacity in percentage */
413 seq_printf(m
, "pool_capacity=%ld\n",
414 ((h_resource
>> 2 * 8) & 0xffff) * 100);
416 seq_printf(m
, "pool_idle_time=%ld\n", pool_idle_time
);
418 seq_printf(m
, "pool_num_procs=%ld\n", pool_procs
);
421 seq_printf(m
, "unallocated_capacity_weight=%ld\n",
422 (h_resource
>> 4 * 8) & 0xFF);
424 seq_printf(m
, "capacity_weight=%ld\n",
425 (h_resource
>> 5 * 8) & 0xFF);
427 seq_printf(m
, "capped=%ld\n", (h_resource
>> 6 * 8) & 0x01);
429 seq_printf(m
, "unallocated_capacity=%ld\n", h_unallocated
);
431 seq_printf(m
, "purr=%ld\n", purr
);
433 } else { /* non SPLPAR case */
435 seq_printf(m
, "system_active_processors=%d\n",
436 partition_potential_processors
);
438 seq_printf(m
, "system_potential_processors=%d\n",
439 partition_potential_processors
);
441 seq_printf(m
, "partition_max_entitled_capacity=%d\n",
442 partition_potential_processors
* 100);
444 seq_printf(m
, "partition_entitled_capacity=%d\n",
445 partition_active_processors
* 100);
448 seq_printf(m
, "partition_active_processors=%d\n",
449 partition_active_processors
);
451 seq_printf(m
, "partition_potential_processors=%d\n",
452 partition_potential_processors
);
454 seq_printf(m
, "shared_processor_mode=%d\n", lppaca
[0].shared_proc
);
460 * Interface for changing system parameters (variable capacity weight
461 * and entitled capacity). Format of input is "param_name=value";
462 * anything after value is ignored. Valid parameters at this time are
463 * "partition_entitled_capacity" and "capacity_weight". We use
464 * H_SET_PPP to alter parameters.
466 * This function should be invoked only on systems with
469 static ssize_t
lparcfg_write(struct file
*file
, const char __user
* buf
,
470 size_t count
, loff_t
* off
)
474 u64 new_entitled
, *new_entitled_ptr
= &new_entitled
;
475 u8 new_weight
, *new_weight_ptr
= &new_weight
;
477 unsigned long current_entitled
; /* parameters for h_get_ppp */
479 unsigned long resource
;
482 ssize_t retval
= -ENOMEM
;
484 kbuf
= kmalloc(count
, GFP_KERNEL
);
489 if (copy_from_user(kbuf
, buf
, count
))
493 kbuf
[count
- 1] = '\0';
494 tmp
= strchr(kbuf
, '=');
500 if (!strcmp(kbuf
, "partition_entitled_capacity")) {
502 *new_entitled_ptr
= (u64
) simple_strtoul(tmp
, &endp
, 10);
505 new_weight_ptr
= ¤t_weight
;
506 } else if (!strcmp(kbuf
, "capacity_weight")) {
508 *new_weight_ptr
= (u8
) simple_strtoul(tmp
, &endp
, 10);
511 new_entitled_ptr
= ¤t_entitled
;
515 /* Get our current parameters */
516 retval
= h_get_ppp(¤t_entitled
, &dummy
, &dummy
, &resource
);
522 current_weight
= (resource
>> 5 * 8) & 0xFF;
524 pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
525 __FUNCTION__
, current_entitled
, current_weight
);
527 pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
528 __FUNCTION__
, *new_entitled_ptr
, *new_weight_ptr
);
530 retval
= plpar_hcall_norets(H_SET_PPP
, *new_entitled_ptr
,
533 if (retval
== H_SUCCESS
|| retval
== H_CONSTRAINED
) {
535 } else if (retval
== H_BUSY
) {
537 } else if (retval
== H_HARDWARE
) {
539 } else if (retval
== H_PARAMETER
) {
542 printk(KERN_WARNING
"%s: received unknown hv return code %ld",
543 __FUNCTION__
, retval
);
552 #endif /* CONFIG_PPC_PSERIES */
554 static int lparcfg_open(struct inode
*inode
, struct file
*file
)
556 return single_open(file
, lparcfg_data
, NULL
);
559 struct file_operations lparcfg_fops
= {
560 .owner
= THIS_MODULE
,
562 .open
= lparcfg_open
,
563 .release
= single_release
,
566 int __init
lparcfg_init(void)
568 struct proc_dir_entry
*ent
;
569 mode_t mode
= S_IRUSR
| S_IRGRP
| S_IROTH
;
571 /* Allow writing if we have FW_FEATURE_SPLPAR */
572 if (firmware_has_feature(FW_FEATURE_SPLPAR
)) {
573 lparcfg_fops
.write
= lparcfg_write
;
577 ent
= create_proc_entry("ppc64/lparcfg", mode
, NULL
);
579 ent
->proc_fops
= &lparcfg_fops
;
580 ent
->data
= kmalloc(LPARCFG_BUFF_SIZE
, GFP_KERNEL
);
583 "Failed to allocate buffer for lparcfg\n");
584 remove_proc_entry("lparcfg", ent
->parent
);
588 printk(KERN_ERR
"Failed to create ppc64/lparcfg\n");
592 proc_ppc64_lparcfg
= ent
;
596 void __exit
lparcfg_cleanup(void)
598 if (proc_ppc64_lparcfg
) {
599 kfree(proc_ppc64_lparcfg
->data
);
600 remove_proc_entry("lparcfg", proc_ppc64_lparcfg
->parent
);
604 module_init(lparcfg_init
);
605 module_exit(lparcfg_cleanup
);
606 MODULE_DESCRIPTION("Interface for LPAR configuration data");
607 MODULE_AUTHOR("Dave Engebretsen");
608 MODULE_LICENSE("GPL");