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 * Nathan Lynch nathanl@austin.ibm.com
9 * Added lparcfg_write, Copyright (C) 2004 Nathan Lynch IBM Corporation.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
16 * This driver creates a proc file at /proc/ppc64/lparcfg which contains
17 * keyword - value pairs that specify the configuration of the partition.
20 #include <linux/config.h>
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 <asm/uaccess.h>
27 #include <asm/iSeries/HvLpConfig.h>
28 #include <asm/iSeries/ItLpPaca.h>
29 #include <asm/hvcall.h>
30 #include <asm/cputable.h>
32 #define MODULE_VERS "1.0"
33 #define MODULE_NAME "lparcfg"
35 static struct proc_dir_entry *proc_ppc64_lparcfg;
36 #define LPARCFG_BUFF_SIZE 4096
38 #ifdef CONFIG_PPC_ISERIES
40 #define lparcfg_write NULL
42 static unsigned char e2a(unsigned char x)
122 * Methods used to fetch LPAR data when running on an iSeries platform.
124 static int lparcfg_data(unsigned char *buf, unsigned long size)
126 unsigned long n = 0, pool_id, lp_index;
127 int shared, entitled_capacity, max_entitled_capacity;
128 int processors, max_processors;
129 struct paca_struct *lpaca = get_paca();
131 if((buf == NULL) || (size > LPARCFG_BUFF_SIZE)) {
134 memset(buf, 0, size);
136 shared = (int)(lpaca->xLpPacaPtr->xSharedProc);
137 n += scnprintf(buf, LPARCFG_BUFF_SIZE - n,
138 "serial_number=%c%c%c%c%c%c%c\n",
139 e2a(xItExtVpdPanel.mfgID[2]),
140 e2a(xItExtVpdPanel.mfgID[3]),
141 e2a(xItExtVpdPanel.systemSerial[1]),
142 e2a(xItExtVpdPanel.systemSerial[2]),
143 e2a(xItExtVpdPanel.systemSerial[3]),
144 e2a(xItExtVpdPanel.systemSerial[4]),
145 e2a(xItExtVpdPanel.systemSerial[5]));
147 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
148 "system_type=%c%c%c%c\n",
149 e2a(xItExtVpdPanel.machineType[0]),
150 e2a(xItExtVpdPanel.machineType[1]),
151 e2a(xItExtVpdPanel.machineType[2]),
152 e2a(xItExtVpdPanel.machineType[3]));
154 lp_index = HvLpConfig_getLpIndex();
155 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
156 "partition_id=%d\n", (int)lp_index);
158 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
159 "system_active_processors=%d\n",
160 (int)HvLpConfig_getSystemPhysicalProcessors());
162 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
163 "system_potential_processors=%d\n",
164 (int)HvLpConfig_getSystemPhysicalProcessors());
166 processors = (int)HvLpConfig_getPhysicalProcessors();
167 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
168 "partition_active_processors=%d\n", processors);
170 max_processors = (int)HvLpConfig_getMaxPhysicalProcessors();
171 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
172 "partition_potential_processors=%d\n", max_processors);
175 entitled_capacity = HvLpConfig_getSharedProcUnits();
176 max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits();
178 entitled_capacity = processors * 100;
179 max_entitled_capacity = max_processors * 100;
181 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
182 "partition_entitled_capacity=%d\n", entitled_capacity);
184 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
185 "partition_max_entitled_capacity=%d\n",
186 max_entitled_capacity);
189 pool_id = HvLpConfig_getSharedPoolIndex();
190 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n, "pool=%d\n",
192 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
193 "pool_capacity=%d\n", (int)(HvLpConfig_getNumProcsInSharedPool(pool_id)*100));
196 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
197 "shared_processor_mode=%d\n", shared);
201 #endif /* CONFIG_PPC_ISERIES */
203 #ifdef CONFIG_PPC_PSERIES
205 * Methods used to fetch LPAR data when running on a pSeries platform.
209 * H_GET_PPP hcall returns info in 4 parms.
210 * entitled_capacity,unallocated_capacity,
211 * aggregation, resource_capability).
213 * R4 = Entitled Processor Capacity Percentage.
214 * R5 = Unallocated Processor Capacity Percentage.
215 * R6 (AABBCCDDEEFFGGHH).
216 * XXXX - reserved (0)
217 * XXXX - reserved (0)
218 * XXXX - Group Number
219 * XXXX - Pool Number.
220 * R7 (PPOONNMMLLKKJJII)
222 * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
223 * XX - variable processor Capacity Weight
224 * XX - Unallocated Variable Processor Capacity Weight.
225 * XXXX - Active processors in Physical Processor Pool.
226 * XXXX - Processors active on platform.
228 unsigned int h_get_ppp(unsigned long *entitled,unsigned long *unallocated,unsigned long *aggregation,unsigned long *resource)
231 rc = plpar_hcall_4out(H_GET_PPP,0,0,0,0,entitled,unallocated,aggregation,resource);
236 * get_splpar_potential_characteristics().
237 * Retrieve the potential_processors and max_entitled_capacity values
238 * through the get-system-parameter rtas call.
240 #define SPLPAR_CHARACTERISTICS_TOKEN 20
241 #define SPLPAR_MAXLENGTH 1026*(sizeof(char))
242 unsigned int get_splpar_potential_characteristics(void)
244 /* return 0 for now. Underlying rtas functionality is not yet complete. 12/01/2003*/
248 unsigned long ret[2];
250 char * buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
252 printk("token for ibm,get-system-parameter (0x%x)\n",rtas_token("ibm,get-system-parameter"));
254 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
256 SPLPAR_CHARACTERISTICS_TOKEN,
261 if (call_status!=0) {
262 printk("Error calling get-system-parameter (0x%lx)\n",call_status);
266 printk("get-system-parameter (%s)\n",buffer);
268 /* TODO: Add code here to parse out value for system_potential_processors and partition_max_entitled_capacity */
274 static int lparcfg_data(unsigned char *buf, unsigned long size)
277 int shared, max_entitled_capacity;
278 int processors, system_active_processors, system_potential_processors;
279 struct device_node *root;
280 const char *model = "";
281 const char *system_id = "";
282 unsigned int *lp_index_ptr, lp_index = 0;
283 struct device_node *rtas_node;
285 unsigned long h_entitled,h_unallocated,h_aggregation,h_resource;
287 if((buf == NULL) || (size > LPARCFG_BUFF_SIZE)) {
290 memset(buf, 0, size);
292 root = find_path_device("/");
294 model = get_property(root, "model", NULL);
295 system_id = get_property(root, "system-id", NULL);
296 lp_index_ptr = (unsigned int *)get_property(root, "ibm,partition-no", NULL);
297 if(lp_index_ptr) lp_index = *lp_index_ptr;
300 n = scnprintf(buf, LPARCFG_BUFF_SIZE - n,
301 "serial_number=%s\n", system_id);
303 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
304 "system_type=%s\n", model);
306 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
307 "partition_id=%d\n", (int)lp_index);
309 rtas_node = find_path_device("/rtas");
310 ip = (int *)get_property(rtas_node, "ibm,lrdr-capacity", NULL);
312 system_active_processors = systemcfg->processorCount;
314 system_active_processors = *(ip + 4);
317 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
318 h_get_ppp(&h_entitled,&h_unallocated,&h_aggregation,&h_resource);
320 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
321 "R4=0x%lx\n", h_entitled);
322 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
323 "R5=0x%lx\n", h_unallocated);
324 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
325 "R6=0x%lx\n", h_aggregation);
326 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
327 "R7=0x%lx\n", h_resource);
331 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
332 system_potential_processors = get_splpar_potential_characteristics();
333 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
334 "system_active_processors=%ld\n",
335 (h_resource >> 2*8) & 0xffff);
336 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
337 "system_potential_processors=%d\n",
338 system_potential_processors);
340 system_potential_processors = system_active_processors;
341 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
342 "system_active_processors=%d\n",
343 system_active_processors);
344 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
345 "system_potential_processors=%d\n",
346 system_potential_processors);
349 processors = systemcfg->processorCount;
350 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
351 "partition_active_processors=%d\n", processors);
352 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
353 "partition_potential_processors=%d\n",
354 system_active_processors);
356 /* max_entitled_capacity will come out of get_splpar_potential_characteristics() when that function is complete */
357 max_entitled_capacity = system_active_processors * 100;
358 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
359 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
360 "partition_entitled_capacity=%ld\n", h_entitled);
362 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
363 "partition_entitled_capacity=%d\n", system_active_processors*100);
366 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
367 "partition_max_entitled_capacity=%d\n",
368 max_entitled_capacity);
371 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
372 "shared_processor_mode=%d\n", shared);
374 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
375 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
376 "pool=%ld\n", (h_aggregation >> 0*8)&0xffff);
378 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
379 "pool_capacity=%ld\n", (h_resource >> 3*8) &0xffff);
381 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
382 "group=%ld\n", (h_aggregation >> 2*8)&0xffff);
384 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
385 "capped=%ld\n", (h_resource >> 6*8)&0x40);
387 n += scnprintf(buf+n, LPARCFG_BUFF_SIZE - n,
388 "capacity_weight=%d\n", (int)(h_resource>>5*8)&0xFF);
394 * Interface for changing system parameters (variable capacity weight
395 * and entitled capacity). Format of input is "param_name=value";
396 * anything after value is ignored. Valid parameters at this time are
397 * "partition_entitled_capacity" and "capacity_weight". We use
398 * H_SET_PPP to alter parameters.
400 * This function should be invoked only on systems with
403 static ssize_t lparcfg_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
407 u64 new_entitled, *new_entitled_ptr = &new_entitled;
408 u8 new_weight, *new_weight_ptr = &new_weight;
410 unsigned long current_entitled; /* parameters for h_get_ppp */
412 unsigned long resource;
415 ssize_t retval = -ENOMEM;
417 kbuf = kmalloc(count, GFP_KERNEL);
422 if (copy_from_user(kbuf, buf, count))
426 kbuf[count - 1] = '\0';
427 tmp = strchr(kbuf, '=');
433 if (!strcmp(kbuf, "partition_entitled_capacity")) {
435 *new_entitled_ptr = (u64)simple_strtoul(tmp, &endp, 10);
438 new_weight_ptr = ¤t_weight;
439 } else if (!strcmp(kbuf, "capacity_weight")) {
441 *new_weight_ptr = (u8)simple_strtoul(tmp, &endp, 10);
444 new_entitled_ptr = ¤t_entitled;
448 /* Get our current parameters */
449 retval = h_get_ppp(¤t_entitled, &dummy, &dummy, &resource);
455 current_weight = (resource>>5*8)&0xFF;
457 pr_debug("%s: current_entitled = %lu, current_weight = %lu\n",
458 __FUNCTION__, current_entitled, current_weight);
460 pr_debug("%s: new_entitled = %lu, new_weight = %lu\n",
461 __FUNCTION__, *new_entitled_ptr, *new_weight_ptr);
463 retval = plpar_hcall_norets(H_SET_PPP, *new_entitled_ptr,
466 if (retval == H_Success || retval == H_Constrained) {
468 } else if (retval == H_Busy) {
470 } else if (retval == H_Hardware) {
472 } else if (retval == H_Parameter) {
475 printk(KERN_WARNING "%s: received unknown hv return code %ld",
476 __FUNCTION__, retval);
485 #endif /* CONFIG_PPC_PSERIES */
488 static ssize_t lparcfg_read(struct file *file, char *buf,
489 size_t count, loff_t *ppos)
491 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
492 unsigned long *data = (unsigned long *)dp->data;
498 printk(KERN_ERR "lparcfg: read failed no data\n");
508 if (p >= LPARCFG_BUFF_SIZE) return 0;
510 lparcfg_data((unsigned char *)data, LPARCFG_BUFF_SIZE);
511 if (count > (strlen((char *)data) - p))
512 count = (strlen((char *)data)) - p;
515 pnt = (char *)(data) + p;
516 copy_to_user(buf, (void *)pnt, count);
522 static int lparcfg_open(struct inode * inode, struct file * file)
524 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
525 unsigned int *data = (unsigned int *)dp->data;
528 printk(KERN_ERR "lparcfg: open failed no data\n");
535 struct file_operations lparcfg_fops = {
541 int __init lparcfg_init(void)
543 struct proc_dir_entry *ent;
544 mode_t mode = S_IRUSR;
546 /* Allow writing if we have FW_FEATURE_SPLPAR */
547 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
548 lparcfg_fops.write = lparcfg_write;
552 ent = create_proc_entry("ppc64/lparcfg", mode, NULL);
554 ent->proc_fops = &lparcfg_fops;
555 ent->data = kmalloc(LPARCFG_BUFF_SIZE, GFP_KERNEL);
557 printk(KERN_ERR "Failed to allocate buffer for lparcfg\n");
558 remove_proc_entry("lparcfg", ent->parent);
562 printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
566 proc_ppc64_lparcfg = ent;
570 void __exit lparcfg_cleanup(void)
572 if (proc_ppc64_lparcfg) {
573 if (proc_ppc64_lparcfg->data) {
574 kfree(proc_ppc64_lparcfg->data);
576 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
580 module_init(lparcfg_init);
581 module_exit(lparcfg_cleanup);
582 MODULE_DESCRIPTION("Interface for LPAR configuration data");
583 MODULE_AUTHOR("Dave Engebretsen");
584 MODULE_LICENSE("GPL");