Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * PowerPC64 LPAR Configuration Information Driver | |
3 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
17 | * This driver creates a proc file at /proc/ppc64/lparcfg which contains | |
18 | * keyword - value pairs that specify the configuration of the partition. | |
19 | */ | |
20 | ||
1da177e4 LT |
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> | |
15b17189 | 28 | #include <asm/iseries/hv_lp_config.h> |
1da177e4 | 29 | #include <asm/lppaca.h> |
1da177e4 | 30 | #include <asm/hvcall.h> |
1ababe11 | 31 | #include <asm/firmware.h> |
1da177e4 LT |
32 | #include <asm/rtas.h> |
33 | #include <asm/system.h> | |
34 | #include <asm/time.h> | |
856509d5 | 35 | #include <asm/prom.h> |
271c3f35 | 36 | #include <asm/vdso_datapage.h> |
1da177e4 | 37 | |
34422fed | 38 | #define MODULE_VERS "1.7" |
1da177e4 LT |
39 | #define MODULE_NAME "lparcfg" |
40 | ||
41 | /* #define LPARCFG_DEBUG */ | |
42 | ||
1da177e4 | 43 | static struct proc_dir_entry *proc_ppc64_lparcfg; |
1da177e4 | 44 | |
1da177e4 | 45 | /* |
16e9f994 SR |
46 | * Track sum of all purrs across all processors. This is used to further |
47 | * calculate usage values by different applications | |
1da177e4 LT |
48 | */ |
49 | static unsigned long get_purr(void) | |
50 | { | |
51 | unsigned long sum_purr = 0; | |
52 | int cpu; | |
1da177e4 | 53 | |
0e551954 | 54 | for_each_possible_cpu(cpu) { |
16e9f994 SR |
55 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
56 | sum_purr += lppaca[cpu].emulated_time_base; | |
57 | else { | |
58 | struct cpu_usage *cu; | |
1da177e4 | 59 | |
16e9f994 SR |
60 | cu = &per_cpu(cpu_usage_array, cpu); |
61 | sum_purr += cu->current_tb; | |
62 | } | |
1da177e4 LT |
63 | } |
64 | return sum_purr; | |
65 | } | |
66 | ||
16e9f994 | 67 | #ifdef CONFIG_PPC_ISERIES |
1da177e4 | 68 | |
d3d2176a | 69 | /* |
1da177e4 LT |
70 | * Methods used to fetch LPAR data when running on an iSeries platform. |
71 | */ | |
16e9f994 | 72 | static int iseries_lparcfg_data(struct seq_file *m, void *v) |
1da177e4 | 73 | { |
16e9f994 | 74 | unsigned long pool_id; |
1da177e4 LT |
75 | int shared, entitled_capacity, max_entitled_capacity; |
76 | int processors, max_processors; | |
1da177e4 LT |
77 | unsigned long purr = get_purr(); |
78 | ||
048c8bc9 | 79 | shared = (int)(local_paca->lppaca_ptr->shared_proc); |
1da177e4 LT |
80 | |
81 | seq_printf(m, "system_active_processors=%d\n", | |
82 | (int)HvLpConfig_getSystemPhysicalProcessors()); | |
83 | ||
84 | seq_printf(m, "system_potential_processors=%d\n", | |
85 | (int)HvLpConfig_getSystemPhysicalProcessors()); | |
86 | ||
87 | processors = (int)HvLpConfig_getPhysicalProcessors(); | |
88 | seq_printf(m, "partition_active_processors=%d\n", processors); | |
89 | ||
90 | max_processors = (int)HvLpConfig_getMaxPhysicalProcessors(); | |
91 | seq_printf(m, "partition_potential_processors=%d\n", max_processors); | |
92 | ||
93 | if (shared) { | |
94 | entitled_capacity = HvLpConfig_getSharedProcUnits(); | |
95 | max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits(); | |
96 | } else { | |
97 | entitled_capacity = processors * 100; | |
98 | max_entitled_capacity = max_processors * 100; | |
99 | } | |
100 | seq_printf(m, "partition_entitled_capacity=%d\n", entitled_capacity); | |
101 | ||
102 | seq_printf(m, "partition_max_entitled_capacity=%d\n", | |
103 | max_entitled_capacity); | |
104 | ||
105 | if (shared) { | |
106 | pool_id = HvLpConfig_getSharedPoolIndex(); | |
107 | seq_printf(m, "pool=%d\n", (int)pool_id); | |
108 | seq_printf(m, "pool_capacity=%d\n", | |
109 | (int)(HvLpConfig_getNumProcsInSharedPool(pool_id) * | |
110 | 100)); | |
111 | seq_printf(m, "purr=%ld\n", purr); | |
112 | } | |
113 | ||
114 | seq_printf(m, "shared_processor_mode=%d\n", shared); | |
115 | ||
116 | return 0; | |
117 | } | |
16e9f994 SR |
118 | |
119 | #else /* CONFIG_PPC_ISERIES */ | |
120 | ||
121 | static int iseries_lparcfg_data(struct seq_file *m, void *v) | |
122 | { | |
123 | return 0; | |
124 | } | |
125 | ||
1da177e4 LT |
126 | #endif /* CONFIG_PPC_ISERIES */ |
127 | ||
128 | #ifdef CONFIG_PPC_PSERIES | |
d3d2176a | 129 | /* |
1da177e4 LT |
130 | * Methods used to fetch LPAR data when running on a pSeries platform. |
131 | */ | |
d7867959 SR |
132 | static void log_plpar_hcall_return(unsigned long rc, char *tag) |
133 | { | |
e7273d2a WS |
134 | switch(rc) { |
135 | case 0: | |
d7867959 | 136 | return; |
e7273d2a WS |
137 | case H_HARDWARE: |
138 | printk(KERN_INFO "plpar-hcall (%s) " | |
139 | "Hardware fault\n", tag); | |
140 | return; | |
141 | case H_FUNCTION: | |
142 | printk(KERN_INFO "plpar-hcall (%s) " | |
143 | "Function not allowed\n", tag); | |
144 | return; | |
145 | case H_AUTHORITY: | |
146 | printk(KERN_INFO "plpar-hcall (%s) " | |
147 | "Not authorized to this function\n", tag); | |
148 | return; | |
149 | case H_PARAMETER: | |
150 | printk(KERN_INFO "plpar-hcall (%s) " | |
151 | "Bad parameter(s)\n",tag); | |
152 | return; | |
153 | default: | |
154 | printk(KERN_INFO "plpar-hcall (%s) " | |
155 | "Unexpected rc(0x%lx)\n", tag, rc); | |
156 | } | |
d7867959 | 157 | } |
1da177e4 LT |
158 | |
159 | /* | |
160 | * H_GET_PPP hcall returns info in 4 parms. | |
161 | * entitled_capacity,unallocated_capacity, | |
162 | * aggregation, resource_capability). | |
163 | * | |
d3d2176a | 164 | * R4 = Entitled Processor Capacity Percentage. |
1da177e4 LT |
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). | |
172 | * XX - reserved. (0) | |
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. | |
d3d2176a | 177 | * XXXX - Processors active on platform. |
1da177e4 LT |
178 | */ |
179 | static unsigned int h_get_ppp(unsigned long *entitled, | |
180 | unsigned long *unallocated, | |
181 | unsigned long *aggregation, | |
182 | unsigned long *resource) | |
183 | { | |
184 | unsigned long rc; | |
b9377ffc AB |
185 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
186 | ||
187 | rc = plpar_hcall(H_GET_PPP, retbuf); | |
188 | ||
189 | *entitled = retbuf[0]; | |
190 | *unallocated = retbuf[1]; | |
191 | *aggregation = retbuf[2]; | |
192 | *resource = retbuf[3]; | |
1da177e4 LT |
193 | |
194 | log_plpar_hcall_return(rc, "H_GET_PPP"); | |
195 | ||
196 | return rc; | |
197 | } | |
198 | ||
199 | static void h_pic(unsigned long *pool_idle_time, unsigned long *num_procs) | |
200 | { | |
201 | unsigned long rc; | |
b9377ffc AB |
202 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
203 | ||
204 | rc = plpar_hcall(H_PIC, retbuf); | |
205 | ||
206 | *pool_idle_time = retbuf[0]; | |
207 | *num_procs = retbuf[1]; | |
1da177e4 | 208 | |
706c8c93 | 209 | if (rc != H_AUTHORITY) |
8acb888c | 210 | log_plpar_hcall_return(rc, "H_PIC"); |
1da177e4 LT |
211 | } |
212 | ||
1da177e4 LT |
213 | #define SPLPAR_CHARACTERISTICS_TOKEN 20 |
214 | #define SPLPAR_MAXLENGTH 1026*(sizeof(char)) | |
215 | ||
216 | /* | |
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 | |
220 | * necessary. | |
221 | */ | |
222 | static void parse_system_parameter_string(struct seq_file *m) | |
223 | { | |
224 | int call_status; | |
225 | ||
34422fed | 226 | unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL); |
1da177e4 LT |
227 | if (!local_buffer) { |
228 | printk(KERN_ERR "%s %s kmalloc failure at line %d \n", | |
229 | __FILE__, __FUNCTION__, __LINE__); | |
230 | return; | |
231 | } | |
232 | ||
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, | |
236 | NULL, | |
237 | SPLPAR_CHARACTERISTICS_TOKEN, | |
34422fed WS |
238 | __pa(rtas_data_buf), |
239 | RTAS_DATA_BUF_SIZE); | |
1da177e4 LT |
240 | memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH); |
241 | spin_unlock(&rtas_data_buf_lock); | |
242 | ||
243 | if (call_status != 0) { | |
244 | printk(KERN_INFO | |
245 | "%s %s Error calling get-system-parameter (0x%x)\n", | |
246 | __FILE__, __FUNCTION__, call_status); | |
247 | } else { | |
248 | int splpar_strlen; | |
249 | int idx, w_idx; | |
dd00cc48 | 250 | char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL); |
1da177e4 LT |
251 | if (!workbuffer) { |
252 | printk(KERN_ERR "%s %s kmalloc failure at line %d \n", | |
253 | __FILE__, __FUNCTION__, __LINE__); | |
d3d2176a | 254 | kfree(local_buffer); |
1da177e4 LT |
255 | return; |
256 | } | |
257 | #ifdef LPARCFG_DEBUG | |
258 | printk(KERN_INFO "success calling get-system-parameter \n"); | |
259 | #endif | |
34422fed | 260 | splpar_strlen = local_buffer[0] * 256 + local_buffer[1]; |
1da177e4 LT |
261 | local_buffer += 2; /* step over strlen value */ |
262 | ||
1da177e4 LT |
263 | w_idx = 0; |
264 | idx = 0; | |
265 | while ((*local_buffer) && (idx < splpar_strlen)) { | |
266 | workbuffer[w_idx++] = local_buffer[idx++]; | |
267 | if ((local_buffer[idx] == ',') | |
268 | || (local_buffer[idx] == '\0')) { | |
269 | workbuffer[w_idx] = '\0'; | |
270 | if (w_idx) { | |
271 | /* avoid the empty string */ | |
272 | seq_printf(m, "%s\n", workbuffer); | |
273 | } | |
274 | memset(workbuffer, 0, SPLPAR_MAXLENGTH); | |
275 | idx++; /* skip the comma */ | |
276 | w_idx = 0; | |
277 | } else if (local_buffer[idx] == '=') { | |
278 | /* code here to replace workbuffer contents | |
279 | with different keyword strings */ | |
280 | if (0 == strcmp(workbuffer, "MaxEntCap")) { | |
281 | strcpy(workbuffer, | |
282 | "partition_max_entitled_capacity"); | |
283 | w_idx = strlen(workbuffer); | |
284 | } | |
285 | if (0 == strcmp(workbuffer, "MaxPlatProcs")) { | |
286 | strcpy(workbuffer, | |
287 | "system_potential_processors"); | |
288 | w_idx = strlen(workbuffer); | |
289 | } | |
290 | } | |
291 | } | |
292 | kfree(workbuffer); | |
293 | local_buffer -= 2; /* back up over strlen value */ | |
294 | } | |
295 | kfree(local_buffer); | |
296 | } | |
297 | ||
1da177e4 LT |
298 | /* Return the number of processors in the system. |
299 | * This function reads through the device tree and counts | |
300 | * the virtual processors, this does not include threads. | |
301 | */ | |
302 | static int lparcfg_count_active_processors(void) | |
303 | { | |
304 | struct device_node *cpus_dn = NULL; | |
305 | int count = 0; | |
306 | ||
307 | while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) { | |
308 | #ifdef LPARCFG_DEBUG | |
309 | printk(KERN_ERR "cpus_dn %p \n", cpus_dn); | |
310 | #endif | |
311 | count++; | |
312 | } | |
313 | return count; | |
314 | } | |
315 | ||
16e9f994 | 316 | static int pseries_lparcfg_data(struct seq_file *m, void *v) |
1da177e4 LT |
317 | { |
318 | int partition_potential_processors; | |
319 | int partition_active_processors; | |
1da177e4 | 320 | struct device_node *rtas_node; |
a7f67bdf | 321 | const int *lrdrp = NULL; |
1da177e4 | 322 | |
8c8dc322 | 323 | rtas_node = of_find_node_by_path("/rtas"); |
2b9a32ed | 324 | if (rtas_node) |
e2eb6392 | 325 | lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL); |
1da177e4 LT |
326 | |
327 | if (lrdrp == NULL) { | |
271c3f35 | 328 | partition_potential_processors = vdso_data->processorCount; |
1da177e4 LT |
329 | } else { |
330 | partition_potential_processors = *(lrdrp + 4); | |
331 | } | |
8c8dc322 | 332 | of_node_put(rtas_node); |
1da177e4 LT |
333 | |
334 | partition_active_processors = lparcfg_count_active_processors(); | |
335 | ||
1ababe11 | 336 | if (firmware_has_feature(FW_FEATURE_SPLPAR)) { |
1da177e4 LT |
337 | unsigned long h_entitled, h_unallocated; |
338 | unsigned long h_aggregation, h_resource; | |
339 | unsigned long pool_idle_time, pool_procs; | |
340 | unsigned long purr; | |
341 | ||
342 | h_get_ppp(&h_entitled, &h_unallocated, &h_aggregation, | |
343 | &h_resource); | |
344 | ||
345 | seq_printf(m, "R4=0x%lx\n", h_entitled); | |
346 | seq_printf(m, "R5=0x%lx\n", h_unallocated); | |
347 | seq_printf(m, "R6=0x%lx\n", h_aggregation); | |
348 | seq_printf(m, "R7=0x%lx\n", h_resource); | |
349 | ||
350 | purr = get_purr(); | |
351 | ||
352 | /* this call handles the ibm,get-system-parameter contents */ | |
353 | parse_system_parameter_string(m); | |
354 | ||
355 | seq_printf(m, "partition_entitled_capacity=%ld\n", h_entitled); | |
356 | ||
357 | seq_printf(m, "group=%ld\n", (h_aggregation >> 2 * 8) & 0xffff); | |
358 | ||
359 | seq_printf(m, "system_active_processors=%ld\n", | |
360 | (h_resource >> 0 * 8) & 0xffff); | |
361 | ||
362 | /* pool related entries are apropriate for shared configs */ | |
3356bb9f | 363 | if (lppaca[0].shared_proc) { |
1da177e4 LT |
364 | |
365 | h_pic(&pool_idle_time, &pool_procs); | |
366 | ||
367 | seq_printf(m, "pool=%ld\n", | |
368 | (h_aggregation >> 0 * 8) & 0xffff); | |
369 | ||
370 | /* report pool_capacity in percentage */ | |
371 | seq_printf(m, "pool_capacity=%ld\n", | |
372 | ((h_resource >> 2 * 8) & 0xffff) * 100); | |
373 | ||
374 | seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time); | |
375 | ||
376 | seq_printf(m, "pool_num_procs=%ld\n", pool_procs); | |
377 | } | |
378 | ||
379 | seq_printf(m, "unallocated_capacity_weight=%ld\n", | |
380 | (h_resource >> 4 * 8) & 0xFF); | |
381 | ||
382 | seq_printf(m, "capacity_weight=%ld\n", | |
383 | (h_resource >> 5 * 8) & 0xFF); | |
384 | ||
385 | seq_printf(m, "capped=%ld\n", (h_resource >> 6 * 8) & 0x01); | |
386 | ||
387 | seq_printf(m, "unallocated_capacity=%ld\n", h_unallocated); | |
388 | ||
389 | seq_printf(m, "purr=%ld\n", purr); | |
390 | ||
391 | } else { /* non SPLPAR case */ | |
392 | ||
393 | seq_printf(m, "system_active_processors=%d\n", | |
394 | partition_potential_processors); | |
395 | ||
396 | seq_printf(m, "system_potential_processors=%d\n", | |
397 | partition_potential_processors); | |
398 | ||
399 | seq_printf(m, "partition_max_entitled_capacity=%d\n", | |
400 | partition_potential_processors * 100); | |
401 | ||
402 | seq_printf(m, "partition_entitled_capacity=%d\n", | |
403 | partition_active_processors * 100); | |
404 | } | |
405 | ||
406 | seq_printf(m, "partition_active_processors=%d\n", | |
407 | partition_active_processors); | |
408 | ||
409 | seq_printf(m, "partition_potential_processors=%d\n", | |
410 | partition_potential_processors); | |
411 | ||
3356bb9f | 412 | seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc); |
1da177e4 LT |
413 | |
414 | return 0; | |
415 | } | |
416 | ||
417 | /* | |
418 | * Interface for changing system parameters (variable capacity weight | |
419 | * and entitled capacity). Format of input is "param_name=value"; | |
420 | * anything after value is ignored. Valid parameters at this time are | |
421 | * "partition_entitled_capacity" and "capacity_weight". We use | |
422 | * H_SET_PPP to alter parameters. | |
423 | * | |
424 | * This function should be invoked only on systems with | |
425 | * FW_FEATURE_SPLPAR. | |
426 | */ | |
427 | static ssize_t lparcfg_write(struct file *file, const char __user * buf, | |
428 | size_t count, loff_t * off) | |
429 | { | |
430 | char *kbuf; | |
431 | char *tmp; | |
432 | u64 new_entitled, *new_entitled_ptr = &new_entitled; | |
433 | u8 new_weight, *new_weight_ptr = &new_weight; | |
434 | ||
435 | unsigned long current_entitled; /* parameters for h_get_ppp */ | |
436 | unsigned long dummy; | |
437 | unsigned long resource; | |
438 | u8 current_weight; | |
439 | ||
440 | ssize_t retval = -ENOMEM; | |
441 | ||
0524aad7 SR |
442 | if (!firmware_has_feature(FW_FEATURE_SPLPAR) || |
443 | firmware_has_feature(FW_FEATURE_ISERIES)) | |
444 | return -EINVAL; | |
445 | ||
1da177e4 LT |
446 | kbuf = kmalloc(count, GFP_KERNEL); |
447 | if (!kbuf) | |
448 | goto out; | |
449 | ||
450 | retval = -EFAULT; | |
451 | if (copy_from_user(kbuf, buf, count)) | |
452 | goto out; | |
453 | ||
454 | retval = -EINVAL; | |
455 | kbuf[count - 1] = '\0'; | |
456 | tmp = strchr(kbuf, '='); | |
457 | if (!tmp) | |
458 | goto out; | |
459 | ||
460 | *tmp++ = '\0'; | |
461 | ||
462 | if (!strcmp(kbuf, "partition_entitled_capacity")) { | |
463 | char *endp; | |
464 | *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); | |
465 | if (endp == tmp) | |
466 | goto out; | |
467 | new_weight_ptr = ¤t_weight; | |
468 | } else if (!strcmp(kbuf, "capacity_weight")) { | |
469 | char *endp; | |
470 | *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); | |
471 | if (endp == tmp) | |
472 | goto out; | |
473 | new_entitled_ptr = ¤t_entitled; | |
474 | } else | |
475 | goto out; | |
476 | ||
477 | /* Get our current parameters */ | |
478 | retval = h_get_ppp(¤t_entitled, &dummy, &dummy, &resource); | |
479 | if (retval) { | |
480 | retval = -EIO; | |
481 | goto out; | |
482 | } | |
483 | ||
484 | current_weight = (resource >> 5 * 8) & 0xFF; | |
485 | ||
8ae5b280 | 486 | pr_debug("%s: current_entitled = %lu, current_weight = %u\n", |
1da177e4 LT |
487 | __FUNCTION__, current_entitled, current_weight); |
488 | ||
8ae5b280 | 489 | pr_debug("%s: new_entitled = %lu, new_weight = %u\n", |
1da177e4 LT |
490 | __FUNCTION__, *new_entitled_ptr, *new_weight_ptr); |
491 | ||
492 | retval = plpar_hcall_norets(H_SET_PPP, *new_entitled_ptr, | |
493 | *new_weight_ptr); | |
494 | ||
706c8c93 | 495 | if (retval == H_SUCCESS || retval == H_CONSTRAINED) { |
1da177e4 | 496 | retval = count; |
706c8c93 | 497 | } else if (retval == H_BUSY) { |
1da177e4 | 498 | retval = -EBUSY; |
706c8c93 | 499 | } else if (retval == H_HARDWARE) { |
1da177e4 | 500 | retval = -EIO; |
706c8c93 | 501 | } else if (retval == H_PARAMETER) { |
1da177e4 LT |
502 | retval = -EINVAL; |
503 | } else { | |
504 | printk(KERN_WARNING "%s: received unknown hv return code %ld", | |
505 | __FUNCTION__, retval); | |
506 | retval = -EIO; | |
507 | } | |
508 | ||
8acb888c | 509 | out: |
1da177e4 LT |
510 | kfree(kbuf); |
511 | return retval; | |
512 | } | |
513 | ||
16e9f994 SR |
514 | #else /* CONFIG_PPC_PSERIES */ |
515 | ||
516 | static int pseries_lparcfg_data(struct seq_file *m, void *v) | |
517 | { | |
518 | return 0; | |
519 | } | |
520 | ||
521 | static ssize_t lparcfg_write(struct file *file, const char __user * buf, | |
522 | size_t count, loff_t * off) | |
523 | { | |
0524aad7 | 524 | return -EINVAL; |
16e9f994 SR |
525 | } |
526 | ||
1da177e4 LT |
527 | #endif /* CONFIG_PPC_PSERIES */ |
528 | ||
16e9f994 SR |
529 | static int lparcfg_data(struct seq_file *m, void *v) |
530 | { | |
531 | struct device_node *rootdn; | |
532 | const char *model = ""; | |
533 | const char *system_id = ""; | |
534 | const char *tmp; | |
a7f67bdf JK |
535 | const unsigned int *lp_index_ptr; |
536 | unsigned int lp_index = 0; | |
16e9f994 SR |
537 | |
538 | seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS); | |
539 | ||
8c8dc322 | 540 | rootdn = of_find_node_by_path("/"); |
16e9f994 | 541 | if (rootdn) { |
e2eb6392 | 542 | tmp = of_get_property(rootdn, "model", NULL); |
16e9f994 SR |
543 | if (tmp) { |
544 | model = tmp; | |
545 | /* Skip "IBM," - see platforms/iseries/dt.c */ | |
546 | if (firmware_has_feature(FW_FEATURE_ISERIES)) | |
547 | model += 4; | |
548 | } | |
e2eb6392 | 549 | tmp = of_get_property(rootdn, "system-id", NULL); |
16e9f994 SR |
550 | if (tmp) { |
551 | system_id = tmp; | |
552 | /* Skip "IBM," - see platforms/iseries/dt.c */ | |
553 | if (firmware_has_feature(FW_FEATURE_ISERIES)) | |
554 | system_id += 4; | |
555 | } | |
e2eb6392 SR |
556 | lp_index_ptr = of_get_property(rootdn, "ibm,partition-no", |
557 | NULL); | |
16e9f994 SR |
558 | if (lp_index_ptr) |
559 | lp_index = *lp_index_ptr; | |
8c8dc322 | 560 | of_node_put(rootdn); |
16e9f994 SR |
561 | } |
562 | seq_printf(m, "serial_number=%s\n", system_id); | |
563 | seq_printf(m, "system_type=%s\n", model); | |
564 | seq_printf(m, "partition_id=%d\n", (int)lp_index); | |
565 | ||
566 | if (firmware_has_feature(FW_FEATURE_ISERIES)) | |
567 | return iseries_lparcfg_data(m, v); | |
568 | return pseries_lparcfg_data(m, v); | |
569 | } | |
570 | ||
1da177e4 LT |
571 | static int lparcfg_open(struct inode *inode, struct file *file) |
572 | { | |
573 | return single_open(file, lparcfg_data, NULL); | |
574 | } | |
575 | ||
5dfe4c96 | 576 | const struct file_operations lparcfg_fops = { |
8acb888c AB |
577 | .owner = THIS_MODULE, |
578 | .read = seq_read, | |
0524aad7 | 579 | .write = lparcfg_write, |
8acb888c AB |
580 | .open = lparcfg_open, |
581 | .release = single_release, | |
1da177e4 LT |
582 | }; |
583 | ||
584 | int __init lparcfg_init(void) | |
585 | { | |
586 | struct proc_dir_entry *ent; | |
71839267 | 587 | mode_t mode = S_IRUSR | S_IRGRP | S_IROTH; |
1da177e4 LT |
588 | |
589 | /* Allow writing if we have FW_FEATURE_SPLPAR */ | |
16e9f994 | 590 | if (firmware_has_feature(FW_FEATURE_SPLPAR) && |
0524aad7 | 591 | !firmware_has_feature(FW_FEATURE_ISERIES)) |
1da177e4 | 592 | mode |= S_IWUSR; |
1da177e4 LT |
593 | |
594 | ent = create_proc_entry("ppc64/lparcfg", mode, NULL); | |
595 | if (ent) { | |
596 | ent->proc_fops = &lparcfg_fops; | |
1da177e4 LT |
597 | } else { |
598 | printk(KERN_ERR "Failed to create ppc64/lparcfg\n"); | |
599 | return -EIO; | |
600 | } | |
601 | ||
602 | proc_ppc64_lparcfg = ent; | |
603 | return 0; | |
604 | } | |
605 | ||
606 | void __exit lparcfg_cleanup(void) | |
607 | { | |
0d9dc4b4 | 608 | if (proc_ppc64_lparcfg) |
1da177e4 | 609 | remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent); |
1da177e4 LT |
610 | } |
611 | ||
612 | module_init(lparcfg_init); | |
613 | module_exit(lparcfg_cleanup); | |
614 | MODULE_DESCRIPTION("Interface for LPAR configuration data"); | |
615 | MODULE_AUTHOR("Dave Engebretsen"); | |
616 | MODULE_LICENSE("GPL"); |