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.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 * This driver creates a proc file at /proc/ppc64/lparcfg which contains
15 * keyword - value pairs that specify the configuration of the partition.
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/errno.h>
21 #include <linux/proc_fs.h>
22 #include <linux/init.h>
23 #include <asm/uaccess.h>
24 #include <asm/iSeries/HvLpConfig.h>
25 #include <asm/iSeries/ItLpPaca.h>
26 #include <asm/hvcall.h>
27 #include <asm/cputable.h>
29 #define MODULE_VERSION "1.0"
30 #define MODULE_NAME "lparcfg"
32 static struct proc_dir_entry *proc_ppc64_lparcfg;
33 #define LPARCFG_BUFF_SIZE 4096
35 #ifdef CONFIG_PPC_ISERIES
36 static unsigned char e2a(unsigned char x)
116 * Methods used to fetch LPAR data when running on an iSeries platform.
118 static int lparcfg_data(unsigned char *buf, unsigned long size)
120 unsigned long n = 0, pool_id, lp_index;
121 int shared, entitled_capacity, max_entitled_capacity;
122 int processors, max_processors;
123 struct paca_struct *lpaca = get_paca();
125 if((buf == NULL) || (size > LPARCFG_BUFF_SIZE)) {
128 memset(buf, 0, size);
130 shared = (int)(lpaca->xLpPacaPtr->xSharedProc);
131 n += snprintf(buf, LPARCFG_BUFF_SIZE - n,
132 "serial_number=%c%c%c%c%c%c%c\n",
133 e2a(xItExtVpdPanel.mfgID[2]),
134 e2a(xItExtVpdPanel.mfgID[3]),
135 e2a(xItExtVpdPanel.systemSerial[1]),
136 e2a(xItExtVpdPanel.systemSerial[2]),
137 e2a(xItExtVpdPanel.systemSerial[3]),
138 e2a(xItExtVpdPanel.systemSerial[4]),
139 e2a(xItExtVpdPanel.systemSerial[5]));
141 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
142 "system_type=%c%c%c%c\n",
143 e2a(xItExtVpdPanel.machineType[0]),
144 e2a(xItExtVpdPanel.machineType[1]),
145 e2a(xItExtVpdPanel.machineType[2]),
146 e2a(xItExtVpdPanel.machineType[3]));
148 lp_index = HvLpConfig_getLpIndex();
149 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
150 "partition_id=%d\n", (int)lp_index);
152 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
153 "system_active_processors=%d\n",
154 (int)HvLpConfig_getSystemPhysicalProcessors());
156 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
157 "system_potential_processors=%d\n",
158 (int)HvLpConfig_getSystemPhysicalProcessors());
160 processors = (int)HvLpConfig_getPhysicalProcessors();
161 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
162 "partition_active_processors=%d\n", processors);
164 max_processors = (int)HvLpConfig_getMaxPhysicalProcessors();
165 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
166 "partition_potential_processors=%d\n", max_processors);
169 entitled_capacity = HvLpConfig_getSharedProcUnits();
170 max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits();
172 entitled_capacity = processors * 100;
173 max_entitled_capacity = max_processors * 100;
175 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
176 "partition_entitled_capacity=%d\n", entitled_capacity);
178 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
179 "partition_max_entitled_capacity=%d\n",
180 max_entitled_capacity);
183 pool_id = HvLpConfig_getSharedPoolIndex();
184 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n, "pool=%d\n",
186 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
187 "pool_capacity=%d\n", (int)(HvLpConfig_getNumProcsInSharedPool(pool_id)*100));
190 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
191 "shared_processor_mode=%d\n", shared);
195 #endif /* CONFIG_PPC_ISERIES */
197 #ifdef CONFIG_PPC_PSERIES
199 * Methods used to fetch LPAR data when running on a pSeries platform.
203 * H_GET_PPP hcall returns info in 4 parms.
204 * entitled_capacity,unallocated_capacity,
205 * aggregation, resource_capability).
207 * R4 = Entitled Processor Capacity Percentage.
208 * R5 = Unallocated Processor Capacity Percentage.
209 * R6 (AABBCCDDEEFFGGHH).
210 * XXXX - reserved (0)
211 * XXXX - reserved (0)
212 * XXXX - Group Number
213 * XXXX - Pool Number.
214 * R7 (PPOONNMMLLKKJJII)
216 * XX - bit 0-6 reserved (0). bit 7 is Capped indicator.
217 * XX - variable processor Capacity Weight
218 * XX - Unallocated Variable Processor Capacity Weight.
219 * XXXX - Active processors in Physical Processor Pool.
220 * XXXX - Processors active on platform.
222 unsigned int h_get_ppp(unsigned long *entitled,unsigned long *unallocated,unsigned long *aggregation,unsigned long *resource)
225 rc = plpar_hcall_4out(H_GET_PPP,0,0,0,0,entitled,unallocated,aggregation,resource);
230 * get_splpar_potential_characteristics().
231 * Retrieve the potential_processors and max_entitled_capacity values
232 * through the get-system-parameter rtas call.
234 #define SPLPAR_CHARACTERISTICS_TOKEN 20
235 #define SPLPAR_MAXLENGTH 1026*(sizeof(char))
236 unsigned int get_splpar_potential_characteristics()
238 /* return 0 for now. Underlying rtas functionality is not yet complete. 12/01/2003*/
242 unsigned long ret[2];
244 char * buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
246 printk("token for ibm,get-system-parameter (0x%x)\n",rtas_token("ibm,get-system-parameter"));
248 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
250 SPLPAR_CHARACTERISTICS_TOKEN,
255 if (call_status!=0) {
256 printk("Error calling get-system-parameter (0x%lx)\n",call_status);
260 printk("get-system-parameter (%s)\n",buffer);
262 /* TODO: Add code here to parse out value for system_potential_processors and partition_max_entitled_capacity */
268 static int lparcfg_data(unsigned char *buf, unsigned long size)
271 int shared, max_entitled_capacity;
272 int processors, system_active_processors, system_potential_processors;
273 struct device_node *root;
274 const char *model = "";
275 const char *system_id = "";
276 unsigned int *lp_index_ptr, lp_index = 0;
277 struct device_node *rtas_node;
279 unsigned long h_entitled,h_unallocated,h_aggregation,h_resource;
281 if((buf == NULL) || (size > LPARCFG_BUFF_SIZE)) {
284 memset(buf, 0, size);
286 root = find_path_device("/");
288 model = get_property(root, "model", NULL);
289 system_id = get_property(root, "system-id", NULL);
290 lp_index_ptr = (unsigned int *)get_property(root, "ibm,partition-no", NULL);
291 if(lp_index_ptr) lp_index = *lp_index_ptr;
294 n = snprintf(buf, LPARCFG_BUFF_SIZE - n,
295 "serial_number=%s\n", system_id);
297 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
298 "system_type=%s\n", model);
300 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
301 "partition_id=%d\n", (int)lp_index);
303 rtas_node = find_path_device("/rtas");
304 ip = (int *)get_property(rtas_node, "ibm,lrdr-capacity", NULL);
306 system_active_processors = systemcfg->processorCount;
308 system_active_processors = *(ip + 4);
311 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
312 h_get_ppp(&h_entitled,&h_unallocated,&h_aggregation,&h_resource);
314 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
315 "R4=0x%lx\n", h_entitled);
316 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
317 "R5=0x%lx\n", h_unallocated);
318 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
319 "R6=0x%lx\n", h_aggregation);
320 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
321 "R7=0x%lx\n", h_resource);
325 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
326 system_potential_processors = get_splpar_potential_characteristics();
327 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
328 "system_active_processors=%d\n",
329 (h_resource >> 2*8) & 0xffff);
330 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
331 "system_potential_processors=%d\n",
332 system_potential_processors);
334 system_potential_processors = system_active_processors;
335 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
336 "system_active_processors=%d\n",
337 system_active_processors);
338 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
339 "system_potential_processors=%d\n",
340 system_potential_processors);
343 processors = systemcfg->processorCount;
344 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
345 "partition_active_processors=%d\n", processors);
346 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
347 "partition_potential_processors=%d\n",
348 system_active_processors);
350 max_entitled_capacity = system_active_processors * 100;
351 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
352 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
353 "partition_entitled_capacity=%ld\n", h_entitled);
355 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
356 "partition_entitled_capacity=%d\n", system_active_processors*100);
359 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
360 "partition_max_entitled_capacity=%d\n",
361 max_entitled_capacity);
364 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
365 "shared_processor_mode=%d\n", shared);
367 if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
368 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
369 "pool=%d\n", (h_aggregation >> 0*8)&0xffff);
371 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
372 "pool_capacity=%d\n", (h_resource >> 3*8) &0xffff);
374 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
375 "group=%d\n", (h_aggregation >> 2*8)&0xffff);
377 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
378 "capped=%d\n", (h_resource >> 6*8)&0x40);
380 n += snprintf(buf+n, LPARCFG_BUFF_SIZE - n,
381 "capacity_weight=%d\n", (int)(h_resource>>5*8)&0xFF);
385 #endif /* CONFIG_PPC_PSERIES */
388 static ssize_t lparcfg_read(struct file *file, char *buf,
389 size_t count, loff_t *ppos)
391 struct proc_dir_entry *dp = file->f_dentry->d_inode->u.generic_ip;
392 unsigned long *data = (unsigned long *)dp->data;
398 printk(KERN_ERR "lparcfg: read failed no data\n");
408 if (p >= LPARCFG_BUFF_SIZE) return 0;
410 lparcfg_data((unsigned char *)data, LPARCFG_BUFF_SIZE);
411 if (count > (strlen((char *)data) - p))
412 count = (strlen((char *)data)) - p;
415 pnt = (char *)(data) + p;
416 copy_to_user(buf, (void *)pnt, count);
422 static int lparcfg_open(struct inode * inode, struct file * file)
424 struct proc_dir_entry *dp = file->f_dentry->d_inode->u.generic_ip;
425 unsigned int *data = (unsigned int *)dp->data;
428 printk(KERN_ERR "lparcfg: open failed no data\n");
435 struct file_operations lparcfg_fops = {
441 int __init lparcfg_init(void)
443 struct proc_dir_entry *ent;
445 ent = create_proc_entry("ppc64/lparcfg", S_IRUSR, NULL);
447 ent->proc_fops = &lparcfg_fops;
448 ent->data = kmalloc(LPARCFG_BUFF_SIZE, GFP_KERNEL);
450 printk(KERN_ERR "Failed to allocate buffer for lparcfg\n");
451 remove_proc_entry("lparcfg", ent->parent);
455 printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
459 proc_ppc64_lparcfg = ent;
463 void __exit lparcfg_cleanup(void)
465 if (proc_ppc64_lparcfg) {
466 if (proc_ppc64_lparcfg->data) {
467 kfree(proc_ppc64_lparcfg->data);
469 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
473 module_init(lparcfg_init);
474 module_exit(lparcfg_cleanup);
475 MODULE_DESCRIPTION("Interface for LPAR configuration data");
476 MODULE_AUTHOR("Dave Engebretsen");
477 MODULE_LICENSE("GPL");