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/HvLpConfig.h>
30 #include <asm/iSeries/ItLpPaca.h>
31 #include <asm/iSeries/LparData.h>
32 #include <asm/hvcall.h>
33 #include <asm/cputable.h>
35 #include <asm/system.h>
37 #define MODULE_VERS "1.3"
38 #define MODULE_NAME "lparcfg"
40 /* #define LPARCFG_DEBUG */
42 /* find a better place for this function... */
43 void log_plpar_hcall_return(unsigned long rc,char * tag)
45 if (rc ==0 ) /* success, return */
47 /* check for null tag ? */
49 printk(KERN_INFO "plpar-hcall (%s) failed with hardware fault\n",tag);
50 else if (rc == H_Function)
51 printk(KERN_INFO "plpar-hcall (%s) failed; function not allowed\n",tag);
52 else if (rc == H_Authority)
53 printk(KERN_INFO "plpar-hcall (%s) failed; not authorized to this function\n",tag);
54 else if (rc == H_Parameter)
55 printk(KERN_INFO "plpar-hcall (%s) failed; Bad parameter(s)\n",tag);
57 printk(KERN_INFO "plpar-hcall (%s) failed with unexpected rc(0x%lx)\n",tag,rc);
62 static struct proc_dir_entry *proc_ppc64_lparcfg;
63 #define LPARCFG_BUFF_SIZE 4096
65 #ifdef CONFIG_PPC_ISERIES
67 #define lparcfg_write NULL
70 * Methods used to fetch LPAR data when running on an iSeries platform.
72 static int lparcfg_data(struct seq_file *m, void *v)
74 unsigned long pool_id, lp_index;
75 int shared, entitled_capacity, max_entitled_capacity;
76 int processors, max_processors;
77 struct paca_struct *lpaca = get_paca();
79 shared = (int)(lpaca->lppaca_ptr->xSharedProc);
80 seq_printf(m, "serial_number=%c%c%c%c%c%c%c\n",
81 e2a(xItExtVpdPanel.mfgID[2]),
82 e2a(xItExtVpdPanel.mfgID[3]),
83 e2a(xItExtVpdPanel.systemSerial[1]),
84 e2a(xItExtVpdPanel.systemSerial[2]),
85 e2a(xItExtVpdPanel.systemSerial[3]),
86 e2a(xItExtVpdPanel.systemSerial[4]),
87 e2a(xItExtVpdPanel.systemSerial[5]));
89 seq_printf(m, "system_type=%c%c%c%c\n",
90 e2a(xItExtVpdPanel.machineType[0]),
91 e2a(xItExtVpdPanel.machineType[1]),
92 e2a(xItExtVpdPanel.machineType[2]),
93 e2a(xItExtVpdPanel.machineType[3]));
95 lp_index = HvLpConfig_getLpIndex();
96 seq_printf(m, "partition_id=%d\n", (int)lp_index);
98 seq_printf(m, "system_active_processors=%d\n",
99 (int)HvLpConfig_getSystemPhysicalProcessors());
101 seq_printf(m, "system_potential_processors=%d\n",
102 (int)HvLpConfig_getSystemPhysicalProcessors());
104 processors = (int)HvLpConfig_getPhysicalProcessors();
105 seq_printf(m, "partition_active_processors=%d\n", processors);
107 max_processors = (int)HvLpConfig_getMaxPhysicalProcessors();
108 seq_printf(m, "partition_potential_processors=%d\n", max_processors);
111 entitled_capacity = HvLpConfig_getSharedProcUnits();
112 max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits();
114 entitled_capacity = processors * 100;
115 max_entitled_capacity = max_processors * 100;
117 seq_printf(m, "partition_entitled_capacity=%d\n", entitled_capacity);
119 seq_printf(m, "partition_max_entitled_capacity=%d\n",
120 max_entitled_capacity);
123 pool_id = HvLpConfig_getSharedPoolIndex();
124 seq_printf(m, "pool=%d\n", (int)pool_id);
125 seq_printf(m, "pool_capacity=%d\n",
126 (int)(HvLpConfig_getNumProcsInSharedPool(pool_id)*100));
129 seq_printf(m, "shared_processor_mode=%d\n", shared);
133 #endif /* CONFIG_PPC_ISERIES */
135 #ifdef CONFIG_PPC_PSERIES
137 * Methods used to fetch LPAR data when running on a pSeries platform.
141 * H_GET_PPP hcall returns info in 4 parms.
142 * entitled_capacity,unallocated_capacity,
143 * aggregation, resource_capability).
145 * R4 = Entitled Processor Capacity Percentage.
146 * R5 = Unallocated Processor Capacity Percentage.
147 * R6 (AABBCCDDEEFFGGHH).
148 * XXXX - reserved (0)
149 * XXXX - reserved (0)
150 * XXXX - Group Number
151 * XXXX - Pool Number.
152 * R7 (IIJJKKLLMMNNOOPP).
154 * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
155 * XX - variable processor Capacity Weight
156 * XX - Unallocated Variable Processor Capacity Weight.
157 * XXXX - Active processors in Physical Processor Pool.
158 * XXXX - Processors active on platform.
160 static unsigned int h_get_ppp(unsigned long *entitled,
161 unsigned long *unallocated, unsigned long *aggregation,
162 unsigned long *resource)
165 rc = plpar_hcall_4out(H_GET_PPP,0,0,0,0,entitled,unallocated,aggregation,resource);
167 log_plpar_hcall_return(rc, "H_GET_PPP");
172 static void h_pic(unsigned long *pool_idle_time, unsigned long *num_procs)
176 rc = plpar_hcall(H_PIC, 0, 0, 0, 0, pool_idle_time, num_procs, &dummy);
178 log_plpar_hcall_return(rc, "H_PIC");
181 static unsigned long get_purr(void);
182 /* ToDo: get sum of purr across all processors. The purr collection code
183 * is coming, but at this time is still problematic, so for now this
184 * function will return 0.
186 static unsigned long get_purr()
188 unsigned long sum_purr=0;
192 #define SPLPAR_CHARACTERISTICS_TOKEN 20
193 #define SPLPAR_MAXLENGTH 1026*(sizeof(char))
196 * parse_system_parameter_string()
197 * Retrieve the potential_processors, max_entitled_capacity and friends
198 * through the get-system-parameter rtas call. Replace keyword strings as
201 static void parse_system_parameter_string(struct seq_file *m)
205 char * local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
207 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
208 __FILE__, __FUNCTION__, __LINE__);
212 spin_lock(&rtas_data_buf_lock);
213 memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
214 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
216 SPLPAR_CHARACTERISTICS_TOKEN,
217 __pa(rtas_data_buf));
218 memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
219 spin_unlock(&rtas_data_buf_lock);
221 if (call_status != 0) {
222 printk(KERN_INFO "%s %s Error calling get-system-parameter (0x%x)\n",
223 __FILE__, __FUNCTION__, call_status);
227 char * workbuffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
229 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",__FILE__,__FUNCTION__,__LINE__);
234 printk(KERN_INFO "success calling get-system-parameter \n");
236 splpar_strlen = local_buffer[0] * 16 + local_buffer[1];
237 local_buffer += 2; /* step over strlen value */
239 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
242 while ((*local_buffer) && (idx < splpar_strlen)) {
243 workbuffer[w_idx++] = local_buffer[idx++];
244 if ((local_buffer[idx] == ',')
245 || (local_buffer[idx] == '\0')) {
246 workbuffer[w_idx] = '\0';
248 /* avoid the empty string */
249 seq_printf(m, "%s\n", workbuffer);
251 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
252 idx++; /* skip the comma */
254 } else if (local_buffer[idx] == '=') {
255 /* code here to replace workbuffer contents
256 with different keyword strings */
257 if (0 == strcmp(workbuffer,"MaxEntCap")) {
258 strcpy(workbuffer, "partition_max_entitled_capacity");
259 w_idx = strlen(workbuffer);
261 if (0 == strcmp(workbuffer,"MaxPlatProcs")) {
262 strcpy(workbuffer, "system_potential_processors");
263 w_idx = strlen(workbuffer);
268 local_buffer -= 2; /* back up over strlen value */
273 static int lparcfg_count_active_processors(void);
275 /* Return the number of processors in the system.
276 * This function reads through the device tree and counts
277 * the virtual processors, this does not include threads.
279 static int lparcfg_count_active_processors(void)
281 struct device_node *cpus_dn = NULL;
284 while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
286 printk(KERN_ERR "cpus_dn %p \n",cpus_dn);
293 static int lparcfg_data(struct seq_file *m, void *v)
295 int system_active_processors;
296 struct device_node *rootdn;
297 const char *model = "";
298 const char *system_id = "";
299 unsigned int *lp_index_ptr, lp_index = 0;
300 struct device_node *rtas_node;
303 rootdn = find_path_device("/");
305 model = get_property(rootdn, "model", NULL);
306 system_id = get_property(rootdn, "system-id", NULL);
307 lp_index_ptr = (unsigned int *)
308 get_property(rootdn, "ibm,partition-no", NULL);
310 lp_index = *lp_index_ptr;
314 seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS);
316 seq_printf(m, "serial_number=%s\n", system_id);
318 seq_printf(m, "system_type=%s\n", model);
320 seq_printf(m, "partition_id=%d\n", (int)lp_index);
322 rtas_node = find_path_device("/rtas");
323 lrdrp = (int *)get_property(rtas_node, "ibm,lrdr-capacity", NULL);
326 system_active_processors = systemcfg->processorCount;
328 system_active_processors = *(lrdrp + 4);
331 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
332 unsigned long h_entitled, h_unallocated;
333 unsigned long h_aggregation, h_resource;
334 unsigned long pool_idle_time, pool_procs;
337 h_get_ppp(&h_entitled, &h_unallocated, &h_aggregation,
340 seq_printf(m, "R4=0x%lx\n", h_entitled);
341 seq_printf(m, "R5=0x%lx\n", h_unallocated);
342 seq_printf(m, "R6=0x%lx\n", h_aggregation);
343 seq_printf(m, "R7=0x%lx\n", h_resource);
345 h_pic(&pool_idle_time, &pool_procs);
349 /* this call handles the ibm,get-system-parameter contents */
350 parse_system_parameter_string(m);
352 seq_printf(m, "partition_entitled_capacity=%ld\n",
355 seq_printf(m, "pool=%ld\n",
356 (h_aggregation >> 0*8) & 0xffff);
358 seq_printf(m, "group=%ld\n",
359 (h_aggregation >> 2*8) & 0xffff);
361 seq_printf(m, "system_active_processors=%ld\n",
362 (h_resource >> 0*8) & 0xffff);
364 seq_printf(m, "pool_capacity=%ld\n",
365 (h_resource >> 2*8) & 0xffff);
367 seq_printf(m, "unallocated_capacity_weight=%ld\n",
368 (h_resource >> 4*8) & 0xFF);
370 seq_printf(m, "capacity_weight=%ld\n",
371 (h_resource >> 5*8) & 0xFF);
373 seq_printf(m, "capped=%ld\n",
374 (h_resource >> 6*8) & 0x01);
376 seq_printf(m, "unallocated_capacity=%ld\n",
379 seq_printf(m, "pool_idle_time=%ld\n",
382 seq_printf(m, "pool_num_procs=%ld\n",
385 seq_printf(m, "purr=%ld\n",
388 } else /* non SPLPAR case */ {
389 seq_printf(m, "system_active_processors=%d\n",
390 system_active_processors);
392 seq_printf(m, "system_potential_processors=%d\n",
393 system_active_processors);
395 seq_printf(m, "partition_max_entitled_capacity=%d\n",
396 100*system_active_processors);
398 seq_printf(m, "partition_entitled_capacity=%d\n",
399 system_active_processors*100);
402 seq_printf(m, "partition_active_processors=%d\n",
403 (int) lparcfg_count_active_processors());
405 seq_printf(m, "partition_potential_processors=%d\n",
406 system_active_processors);
408 seq_printf(m, "shared_processor_mode=%d\n",
409 paca[0].lppaca.xSharedProc);
415 * Interface for changing system parameters (variable capacity weight
416 * and entitled capacity). Format of input is "param_name=value";
417 * anything after value is ignored. Valid parameters at this time are
418 * "partition_entitled_capacity" and "capacity_weight". We use
419 * H_SET_PPP to alter parameters.
421 * This function should be invoked only on systems with
424 static ssize_t lparcfg_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
428 u64 new_entitled, *new_entitled_ptr = &new_entitled;
429 u8 new_weight, *new_weight_ptr = &new_weight;
431 unsigned long current_entitled; /* parameters for h_get_ppp */
433 unsigned long resource;
436 ssize_t retval = -ENOMEM;
438 kbuf = kmalloc(count, GFP_KERNEL);
443 if (copy_from_user(kbuf, buf, count))
447 kbuf[count - 1] = '\0';
448 tmp = strchr(kbuf, '=');
454 if (!strcmp(kbuf, "partition_entitled_capacity")) {
456 *new_entitled_ptr = (u64)simple_strtoul(tmp, &endp, 10);
459 new_weight_ptr = ¤t_weight;
460 } else if (!strcmp(kbuf, "capacity_weight")) {
462 *new_weight_ptr = (u8)simple_strtoul(tmp, &endp, 10);
465 new_entitled_ptr = ¤t_entitled;
469 /* Get our current parameters */
470 retval = h_get_ppp(¤t_entitled, &dummy, &dummy, &resource);
476 current_weight = (resource>>5*8)&0xFF;
478 pr_debug("%s: current_entitled = %lu, current_weight = %lu\n",
479 __FUNCTION__, current_entitled, current_weight);
481 pr_debug("%s: new_entitled = %lu, new_weight = %lu\n",
482 __FUNCTION__, *new_entitled_ptr, *new_weight_ptr);
484 retval = plpar_hcall_norets(H_SET_PPP, *new_entitled_ptr,
487 if (retval == H_Success || retval == H_Constrained) {
489 } else if (retval == H_Busy) {
491 } else if (retval == H_Hardware) {
493 } else if (retval == H_Parameter) {
496 printk(KERN_WARNING "%s: received unknown hv return code %ld",
497 __FUNCTION__, retval);
506 #endif /* CONFIG_PPC_PSERIES */
508 static int lparcfg_open(struct inode * inode, struct file * file)
510 return single_open(file,lparcfg_data,NULL);
513 struct file_operations lparcfg_fops = {
517 release: single_release,
520 int __init lparcfg_init(void)
522 struct proc_dir_entry *ent;
523 mode_t mode = S_IRUSR;
525 /* Allow writing if we have FW_FEATURE_SPLPAR */
526 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
527 lparcfg_fops.write = lparcfg_write;
531 ent = create_proc_entry("ppc64/lparcfg", mode, NULL);
533 ent->proc_fops = &lparcfg_fops;
534 ent->data = kmalloc(LPARCFG_BUFF_SIZE, GFP_KERNEL);
536 printk(KERN_ERR "Failed to allocate buffer for lparcfg\n");
537 remove_proc_entry("lparcfg", ent->parent);
541 printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
545 proc_ppc64_lparcfg = ent;
549 void __exit lparcfg_cleanup(void)
551 if (proc_ppc64_lparcfg) {
552 if (proc_ppc64_lparcfg->data) {
553 kfree(proc_ppc64_lparcfg->data);
555 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
559 module_init(lparcfg_init);
560 module_exit(lparcfg_cleanup);
561 MODULE_DESCRIPTION("Interface for LPAR configuration data");
562 MODULE_AUTHOR("Dave Engebretsen");
563 MODULE_LICENSE("GPL");