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/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>
28 #include <asm/iseries/hv_lp_config.h>
29 #include <asm/lppaca.h>
30 #include <asm/hvcall.h>
31 #include <asm/firmware.h>
33 #include <asm/system.h>
36 #include <asm/vdso_datapage.h>
38 #define MODULE_VERS "1.7"
39 #define MODULE_NAME "lparcfg"
41 /* #define LPARCFG_DEBUG */
43 static struct proc_dir_entry
*proc_ppc64_lparcfg
;
44 #define LPARCFG_BUFF_SIZE 4096
47 * Track sum of all purrs across all processors. This is used to further
48 * calculate usage values by different applications
50 static unsigned long get_purr(void)
52 unsigned long sum_purr
= 0;
55 for_each_possible_cpu(cpu
) {
56 if (firmware_has_feature(FW_FEATURE_ISERIES
))
57 sum_purr
+= lppaca
[cpu
].emulated_time_base
;
61 cu
= &per_cpu(cpu_usage_array
, cpu
);
62 sum_purr
+= cu
->current_tb
;
68 #ifdef CONFIG_PPC_ISERIES
71 * Methods used to fetch LPAR data when running on an iSeries platform.
73 static int iseries_lparcfg_data(struct seq_file
*m
, void *v
)
75 unsigned long pool_id
;
76 int shared
, entitled_capacity
, max_entitled_capacity
;
77 int processors
, max_processors
;
78 unsigned long purr
= get_purr();
80 shared
= (int)(get_lppaca()->shared_proc
);
82 seq_printf(m
, "system_active_processors=%d\n",
83 (int)HvLpConfig_getSystemPhysicalProcessors());
85 seq_printf(m
, "system_potential_processors=%d\n",
86 (int)HvLpConfig_getSystemPhysicalProcessors());
88 processors
= (int)HvLpConfig_getPhysicalProcessors();
89 seq_printf(m
, "partition_active_processors=%d\n", processors
);
91 max_processors
= (int)HvLpConfig_getMaxPhysicalProcessors();
92 seq_printf(m
, "partition_potential_processors=%d\n", max_processors
);
95 entitled_capacity
= HvLpConfig_getSharedProcUnits();
96 max_entitled_capacity
= HvLpConfig_getMaxSharedProcUnits();
98 entitled_capacity
= processors
* 100;
99 max_entitled_capacity
= max_processors
* 100;
101 seq_printf(m
, "partition_entitled_capacity=%d\n", entitled_capacity
);
103 seq_printf(m
, "partition_max_entitled_capacity=%d\n",
104 max_entitled_capacity
);
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
) *
112 seq_printf(m
, "purr=%ld\n", purr
);
115 seq_printf(m
, "shared_processor_mode=%d\n", shared
);
120 #else /* CONFIG_PPC_ISERIES */
122 static int iseries_lparcfg_data(struct seq_file
*m
, void *v
)
127 #endif /* CONFIG_PPC_ISERIES */
129 #ifdef CONFIG_PPC_PSERIES
131 * Methods used to fetch LPAR data when running on a pSeries platform.
133 /* find a better place for this function... */
134 static void log_plpar_hcall_return(unsigned long rc
, char *tag
)
136 if (rc
== 0) /* success, return */
138 /* check for null tag ? */
139 if (rc
== H_HARDWARE
)
141 "plpar-hcall (%s) failed with hardware fault\n", tag
);
142 else if (rc
== H_FUNCTION
)
144 "plpar-hcall (%s) failed; function not allowed\n", tag
);
145 else if (rc
== H_AUTHORITY
)
147 "plpar-hcall (%s) failed; not authorized to this"
149 else if (rc
== H_PARAMETER
)
150 printk(KERN_INFO
"plpar-hcall (%s) failed; Bad parameter(s)\n",
154 "plpar-hcall (%s) failed with unexpected rc(0x%lx)\n",
160 * H_GET_PPP hcall returns info in 4 parms.
161 * entitled_capacity,unallocated_capacity,
162 * aggregation, resource_capability).
164 * R4 = Entitled Processor Capacity Percentage.
165 * R5 = Unallocated Processor Capacity Percentage.
166 * R6 (AABBCCDDEEFFGGHH).
167 * XXXX - reserved (0)
168 * XXXX - reserved (0)
169 * XXXX - Group Number
170 * XXXX - Pool Number.
171 * R7 (IIJJKKLLMMNNOOPP).
173 * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
174 * XX - variable processor Capacity Weight
175 * XX - Unallocated Variable Processor Capacity Weight.
176 * XXXX - Active processors in Physical Processor Pool.
177 * XXXX - Processors active on platform.
179 static unsigned int h_get_ppp(unsigned long *entitled
,
180 unsigned long *unallocated
,
181 unsigned long *aggregation
,
182 unsigned long *resource
)
185 unsigned long retbuf
[PLPAR_HCALL_BUFSIZE
];
187 rc
= plpar_hcall(H_GET_PPP
, retbuf
);
189 *entitled
= retbuf
[0];
190 *unallocated
= retbuf
[1];
191 *aggregation
= retbuf
[2];
192 *resource
= retbuf
[3];
194 log_plpar_hcall_return(rc
, "H_GET_PPP");
199 static void h_pic(unsigned long *pool_idle_time
, unsigned long *num_procs
)
202 unsigned long retbuf
[PLPAR_HCALL_BUFSIZE
];
204 rc
= plpar_hcall(H_PIC
, retbuf
);
206 *pool_idle_time
= retbuf
[0];
207 *num_procs
= retbuf
[1];
209 if (rc
!= H_AUTHORITY
)
210 log_plpar_hcall_return(rc
, "H_PIC");
213 #define SPLPAR_CHARACTERISTICS_TOKEN 20
214 #define SPLPAR_MAXLENGTH 1026*(sizeof(char))
217 * parse_system_parameter_string()
218 * Retrieve the potential_processors, max_entitled_capacity and friends
219 * through the get-system-parameter rtas call. Replace keyword strings as
222 static void parse_system_parameter_string(struct seq_file
*m
)
226 unsigned char *local_buffer
= kmalloc(SPLPAR_MAXLENGTH
, GFP_KERNEL
);
228 printk(KERN_ERR
"%s %s kmalloc failure at line %d \n",
229 __FILE__
, __FUNCTION__
, __LINE__
);
233 spin_lock(&rtas_data_buf_lock
);
234 memset(rtas_data_buf
, 0, SPLPAR_MAXLENGTH
);
235 call_status
= rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
237 SPLPAR_CHARACTERISTICS_TOKEN
,
240 memcpy(local_buffer
, rtas_data_buf
, SPLPAR_MAXLENGTH
);
241 spin_unlock(&rtas_data_buf_lock
);
243 if (call_status
!= 0) {
245 "%s %s Error calling get-system-parameter (0x%x)\n",
246 __FILE__
, __FUNCTION__
, call_status
);
250 char *workbuffer
= kmalloc(SPLPAR_MAXLENGTH
, GFP_KERNEL
);
252 printk(KERN_ERR
"%s %s kmalloc failure at line %d \n",
253 __FILE__
, __FUNCTION__
, __LINE__
);
258 printk(KERN_INFO
"success calling get-system-parameter \n");
260 splpar_strlen
= local_buffer
[0] * 256 + local_buffer
[1];
261 local_buffer
+= 2; /* step over strlen value */
263 memset(workbuffer
, 0, SPLPAR_MAXLENGTH
);
266 while ((*local_buffer
) && (idx
< splpar_strlen
)) {
267 workbuffer
[w_idx
++] = local_buffer
[idx
++];
268 if ((local_buffer
[idx
] == ',')
269 || (local_buffer
[idx
] == '\0')) {
270 workbuffer
[w_idx
] = '\0';
272 /* avoid the empty string */
273 seq_printf(m
, "%s\n", workbuffer
);
275 memset(workbuffer
, 0, SPLPAR_MAXLENGTH
);
276 idx
++; /* skip the comma */
278 } else if (local_buffer
[idx
] == '=') {
279 /* code here to replace workbuffer contents
280 with different keyword strings */
281 if (0 == strcmp(workbuffer
, "MaxEntCap")) {
283 "partition_max_entitled_capacity");
284 w_idx
= strlen(workbuffer
);
286 if (0 == strcmp(workbuffer
, "MaxPlatProcs")) {
288 "system_potential_processors");
289 w_idx
= strlen(workbuffer
);
294 local_buffer
-= 2; /* back up over strlen value */
299 /* Return the number of processors in the system.
300 * This function reads through the device tree and counts
301 * the virtual processors, this does not include threads.
303 static int lparcfg_count_active_processors(void)
305 struct device_node
*cpus_dn
= NULL
;
308 while ((cpus_dn
= of_find_node_by_type(cpus_dn
, "cpu"))) {
310 printk(KERN_ERR
"cpus_dn %p \n", cpus_dn
);
317 static int pseries_lparcfg_data(struct seq_file
*m
, void *v
)
319 int partition_potential_processors
;
320 int partition_active_processors
;
321 struct device_node
*rtas_node
;
322 const int *lrdrp
= NULL
;
324 rtas_node
= of_find_node_by_path("/rtas");
326 lrdrp
= of_get_property(rtas_node
, "ibm,lrdr-capacity", NULL
);
329 partition_potential_processors
= vdso_data
->processorCount
;
331 partition_potential_processors
= *(lrdrp
+ 4);
333 of_node_put(rtas_node
);
335 partition_active_processors
= lparcfg_count_active_processors();
337 if (firmware_has_feature(FW_FEATURE_SPLPAR
)) {
338 unsigned long h_entitled
, h_unallocated
;
339 unsigned long h_aggregation
, h_resource
;
340 unsigned long pool_idle_time
, pool_procs
;
343 h_get_ppp(&h_entitled
, &h_unallocated
, &h_aggregation
,
346 seq_printf(m
, "R4=0x%lx\n", h_entitled
);
347 seq_printf(m
, "R5=0x%lx\n", h_unallocated
);
348 seq_printf(m
, "R6=0x%lx\n", h_aggregation
);
349 seq_printf(m
, "R7=0x%lx\n", h_resource
);
353 /* this call handles the ibm,get-system-parameter contents */
354 parse_system_parameter_string(m
);
356 seq_printf(m
, "partition_entitled_capacity=%ld\n", h_entitled
);
358 seq_printf(m
, "group=%ld\n", (h_aggregation
>> 2 * 8) & 0xffff);
360 seq_printf(m
, "system_active_processors=%ld\n",
361 (h_resource
>> 0 * 8) & 0xffff);
363 /* pool related entries are apropriate for shared configs */
364 if (lppaca
[0].shared_proc
) {
366 h_pic(&pool_idle_time
, &pool_procs
);
368 seq_printf(m
, "pool=%ld\n",
369 (h_aggregation
>> 0 * 8) & 0xffff);
371 /* report pool_capacity in percentage */
372 seq_printf(m
, "pool_capacity=%ld\n",
373 ((h_resource
>> 2 * 8) & 0xffff) * 100);
375 seq_printf(m
, "pool_idle_time=%ld\n", pool_idle_time
);
377 seq_printf(m
, "pool_num_procs=%ld\n", pool_procs
);
380 seq_printf(m
, "unallocated_capacity_weight=%ld\n",
381 (h_resource
>> 4 * 8) & 0xFF);
383 seq_printf(m
, "capacity_weight=%ld\n",
384 (h_resource
>> 5 * 8) & 0xFF);
386 seq_printf(m
, "capped=%ld\n", (h_resource
>> 6 * 8) & 0x01);
388 seq_printf(m
, "unallocated_capacity=%ld\n", h_unallocated
);
390 seq_printf(m
, "purr=%ld\n", purr
);
392 } else { /* non SPLPAR case */
394 seq_printf(m
, "system_active_processors=%d\n",
395 partition_potential_processors
);
397 seq_printf(m
, "system_potential_processors=%d\n",
398 partition_potential_processors
);
400 seq_printf(m
, "partition_max_entitled_capacity=%d\n",
401 partition_potential_processors
* 100);
403 seq_printf(m
, "partition_entitled_capacity=%d\n",
404 partition_active_processors
* 100);
407 seq_printf(m
, "partition_active_processors=%d\n",
408 partition_active_processors
);
410 seq_printf(m
, "partition_potential_processors=%d\n",
411 partition_potential_processors
);
413 seq_printf(m
, "shared_processor_mode=%d\n", lppaca
[0].shared_proc
);
419 * Interface for changing system parameters (variable capacity weight
420 * and entitled capacity). Format of input is "param_name=value";
421 * anything after value is ignored. Valid parameters at this time are
422 * "partition_entitled_capacity" and "capacity_weight". We use
423 * H_SET_PPP to alter parameters.
425 * This function should be invoked only on systems with
428 static ssize_t
lparcfg_write(struct file
*file
, const char __user
* buf
,
429 size_t count
, loff_t
* off
)
433 u64 new_entitled
, *new_entitled_ptr
= &new_entitled
;
434 u8 new_weight
, *new_weight_ptr
= &new_weight
;
436 unsigned long current_entitled
; /* parameters for h_get_ppp */
438 unsigned long resource
;
441 ssize_t retval
= -ENOMEM
;
443 if (!firmware_has_feature(FW_FEATURE_SPLPAR
) ||
444 firmware_has_feature(FW_FEATURE_ISERIES
))
447 kbuf
= kmalloc(count
, GFP_KERNEL
);
452 if (copy_from_user(kbuf
, buf
, count
))
456 kbuf
[count
- 1] = '\0';
457 tmp
= strchr(kbuf
, '=');
463 if (!strcmp(kbuf
, "partition_entitled_capacity")) {
465 *new_entitled_ptr
= (u64
) simple_strtoul(tmp
, &endp
, 10);
468 new_weight_ptr
= ¤t_weight
;
469 } else if (!strcmp(kbuf
, "capacity_weight")) {
471 *new_weight_ptr
= (u8
) simple_strtoul(tmp
, &endp
, 10);
474 new_entitled_ptr
= ¤t_entitled
;
478 /* Get our current parameters */
479 retval
= h_get_ppp(¤t_entitled
, &dummy
, &dummy
, &resource
);
485 current_weight
= (resource
>> 5 * 8) & 0xFF;
487 pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
488 __FUNCTION__
, current_entitled
, current_weight
);
490 pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
491 __FUNCTION__
, *new_entitled_ptr
, *new_weight_ptr
);
493 retval
= plpar_hcall_norets(H_SET_PPP
, *new_entitled_ptr
,
496 if (retval
== H_SUCCESS
|| retval
== H_CONSTRAINED
) {
498 } else if (retval
== H_BUSY
) {
500 } else if (retval
== H_HARDWARE
) {
502 } else if (retval
== H_PARAMETER
) {
505 printk(KERN_WARNING
"%s: received unknown hv return code %ld",
506 __FUNCTION__
, retval
);
515 #else /* CONFIG_PPC_PSERIES */
517 static int pseries_lparcfg_data(struct seq_file
*m
, void *v
)
522 static ssize_t
lparcfg_write(struct file
*file
, const char __user
* buf
,
523 size_t count
, loff_t
* off
)
528 #endif /* CONFIG_PPC_PSERIES */
530 static int lparcfg_data(struct seq_file
*m
, void *v
)
532 struct device_node
*rootdn
;
533 const char *model
= "";
534 const char *system_id
= "";
536 const unsigned int *lp_index_ptr
;
537 unsigned int lp_index
= 0;
539 seq_printf(m
, "%s %s \n", MODULE_NAME
, MODULE_VERS
);
541 rootdn
= of_find_node_by_path("/");
543 tmp
= of_get_property(rootdn
, "model", NULL
);
546 /* Skip "IBM," - see platforms/iseries/dt.c */
547 if (firmware_has_feature(FW_FEATURE_ISERIES
))
550 tmp
= of_get_property(rootdn
, "system-id", NULL
);
553 /* Skip "IBM," - see platforms/iseries/dt.c */
554 if (firmware_has_feature(FW_FEATURE_ISERIES
))
557 lp_index_ptr
= of_get_property(rootdn
, "ibm,partition-no",
560 lp_index
= *lp_index_ptr
;
563 seq_printf(m
, "serial_number=%s\n", system_id
);
564 seq_printf(m
, "system_type=%s\n", model
);
565 seq_printf(m
, "partition_id=%d\n", (int)lp_index
);
567 if (firmware_has_feature(FW_FEATURE_ISERIES
))
568 return iseries_lparcfg_data(m
, v
);
569 return pseries_lparcfg_data(m
, v
);
572 static int lparcfg_open(struct inode
*inode
, struct file
*file
)
574 return single_open(file
, lparcfg_data
, NULL
);
577 const struct file_operations lparcfg_fops
= {
578 .owner
= THIS_MODULE
,
580 .write
= lparcfg_write
,
581 .open
= lparcfg_open
,
582 .release
= single_release
,
585 int __init
lparcfg_init(void)
587 struct proc_dir_entry
*ent
;
588 mode_t mode
= S_IRUSR
| S_IRGRP
| S_IROTH
;
590 /* Allow writing if we have FW_FEATURE_SPLPAR */
591 if (firmware_has_feature(FW_FEATURE_SPLPAR
) &&
592 !firmware_has_feature(FW_FEATURE_ISERIES
))
595 ent
= create_proc_entry("ppc64/lparcfg", mode
, NULL
);
597 ent
->proc_fops
= &lparcfg_fops
;
598 ent
->data
= kmalloc(LPARCFG_BUFF_SIZE
, GFP_KERNEL
);
601 "Failed to allocate buffer for lparcfg\n");
602 remove_proc_entry("lparcfg", ent
->parent
);
606 printk(KERN_ERR
"Failed to create ppc64/lparcfg\n");
610 proc_ppc64_lparcfg
= ent
;
614 void __exit
lparcfg_cleanup(void)
616 if (proc_ppc64_lparcfg
) {
617 kfree(proc_ppc64_lparcfg
->data
);
618 remove_proc_entry("lparcfg", proc_ppc64_lparcfg
->parent
);
622 module_init(lparcfg_init
);
623 module_exit(lparcfg_cleanup
);
624 MODULE_DESCRIPTION("Interface for LPAR configuration data");
625 MODULE_AUTHOR("Dave Engebretsen");
626 MODULE_LICENSE("GPL");