]>
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> |
22e1a4dd | 37 | #include <asm/vio.h> |
1da177e4 | 38 | |
dfc3403f | 39 | #define MODULE_VERS "1.8" |
1da177e4 LT |
40 | #define MODULE_NAME "lparcfg" |
41 | ||
42 | /* #define LPARCFG_DEBUG */ | |
43 | ||
1da177e4 | 44 | static struct proc_dir_entry *proc_ppc64_lparcfg; |
1da177e4 | 45 | |
1da177e4 | 46 | /* |
16e9f994 SR |
47 | * Track sum of all purrs across all processors. This is used to further |
48 | * calculate usage values by different applications | |
1da177e4 LT |
49 | */ |
50 | static unsigned long get_purr(void) | |
51 | { | |
52 | unsigned long sum_purr = 0; | |
53 | int cpu; | |
1da177e4 | 54 | |
0e551954 | 55 | for_each_possible_cpu(cpu) { |
16e9f994 SR |
56 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
57 | sum_purr += lppaca[cpu].emulated_time_base; | |
58 | else { | |
59 | struct cpu_usage *cu; | |
1da177e4 | 60 | |
16e9f994 SR |
61 | cu = &per_cpu(cpu_usage_array, cpu); |
62 | sum_purr += cu->current_tb; | |
63 | } | |
1da177e4 LT |
64 | } |
65 | return sum_purr; | |
66 | } | |
67 | ||
16e9f994 | 68 | #ifdef CONFIG_PPC_ISERIES |
1da177e4 | 69 | |
d3d2176a | 70 | /* |
1da177e4 LT |
71 | * Methods used to fetch LPAR data when running on an iSeries platform. |
72 | */ | |
16e9f994 | 73 | static int iseries_lparcfg_data(struct seq_file *m, void *v) |
1da177e4 | 74 | { |
16e9f994 | 75 | unsigned long pool_id; |
1da177e4 LT |
76 | int shared, entitled_capacity, max_entitled_capacity; |
77 | int processors, max_processors; | |
1da177e4 LT |
78 | unsigned long purr = get_purr(); |
79 | ||
048c8bc9 | 80 | shared = (int)(local_paca->lppaca_ptr->shared_proc); |
1da177e4 LT |
81 | |
82 | seq_printf(m, "system_active_processors=%d\n", | |
83 | (int)HvLpConfig_getSystemPhysicalProcessors()); | |
84 | ||
85 | seq_printf(m, "system_potential_processors=%d\n", | |
86 | (int)HvLpConfig_getSystemPhysicalProcessors()); | |
87 | ||
88 | processors = (int)HvLpConfig_getPhysicalProcessors(); | |
89 | seq_printf(m, "partition_active_processors=%d\n", processors); | |
90 | ||
91 | max_processors = (int)HvLpConfig_getMaxPhysicalProcessors(); | |
92 | seq_printf(m, "partition_potential_processors=%d\n", max_processors); | |
93 | ||
94 | if (shared) { | |
95 | entitled_capacity = HvLpConfig_getSharedProcUnits(); | |
96 | max_entitled_capacity = HvLpConfig_getMaxSharedProcUnits(); | |
97 | } else { | |
98 | entitled_capacity = processors * 100; | |
99 | max_entitled_capacity = max_processors * 100; | |
100 | } | |
101 | seq_printf(m, "partition_entitled_capacity=%d\n", entitled_capacity); | |
102 | ||
103 | seq_printf(m, "partition_max_entitled_capacity=%d\n", | |
104 | max_entitled_capacity); | |
105 | ||
106 | if (shared) { | |
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) * | |
111 | 100)); | |
112 | seq_printf(m, "purr=%ld\n", purr); | |
113 | } | |
114 | ||
115 | seq_printf(m, "shared_processor_mode=%d\n", shared); | |
116 | ||
117 | return 0; | |
118 | } | |
16e9f994 SR |
119 | |
120 | #else /* CONFIG_PPC_ISERIES */ | |
121 | ||
122 | static int iseries_lparcfg_data(struct seq_file *m, void *v) | |
123 | { | |
124 | return 0; | |
125 | } | |
126 | ||
1da177e4 LT |
127 | #endif /* CONFIG_PPC_ISERIES */ |
128 | ||
129 | #ifdef CONFIG_PPC_PSERIES | |
d3d2176a | 130 | /* |
1da177e4 LT |
131 | * Methods used to fetch LPAR data when running on a pSeries platform. |
132 | */ | |
dfc3403f NF |
133 | /** |
134 | * h_get_mpp | |
135 | * H_GET_MPP hcall returns info in 7 parms | |
136 | */ | |
137 | int h_get_mpp(struct hvcall_mpp_data *mpp_data) | |
138 | { | |
139 | int rc; | |
140 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; | |
141 | ||
142 | rc = plpar_hcall9(H_GET_MPP, retbuf); | |
143 | ||
144 | mpp_data->entitled_mem = retbuf[0]; | |
145 | mpp_data->mapped_mem = retbuf[1]; | |
146 | ||
147 | mpp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff; | |
148 | mpp_data->pool_num = retbuf[2] & 0xffff; | |
149 | ||
150 | mpp_data->mem_weight = (retbuf[3] >> 7 * 8) & 0xff; | |
151 | mpp_data->unallocated_mem_weight = (retbuf[3] >> 6 * 8) & 0xff; | |
152 | mpp_data->unallocated_entitlement = retbuf[3] & 0xffffffffffff; | |
153 | ||
154 | mpp_data->pool_size = retbuf[4]; | |
155 | mpp_data->loan_request = retbuf[5]; | |
156 | mpp_data->backing_mem = retbuf[6]; | |
157 | ||
158 | return rc; | |
159 | } | |
160 | EXPORT_SYMBOL(h_get_mpp); | |
161 | ||
398778f7 RJ |
162 | struct hvcall_ppp_data { |
163 | u64 entitlement; | |
164 | u64 unallocated_entitlement; | |
165 | u16 group_num; | |
166 | u16 pool_num; | |
167 | u8 capped; | |
168 | u8 weight; | |
169 | u8 unallocated_weight; | |
170 | u16 active_procs_in_pool; | |
171 | u16 active_system_procs; | |
f03cdb3a NF |
172 | u16 phys_platform_procs; |
173 | u32 max_proc_cap_avail; | |
174 | u32 entitled_proc_cap_avail; | |
398778f7 RJ |
175 | }; |
176 | ||
1da177e4 LT |
177 | /* |
178 | * H_GET_PPP hcall returns info in 4 parms. | |
179 | * entitled_capacity,unallocated_capacity, | |
180 | * aggregation, resource_capability). | |
181 | * | |
d3d2176a | 182 | * R4 = Entitled Processor Capacity Percentage. |
1da177e4 LT |
183 | * R5 = Unallocated Processor Capacity Percentage. |
184 | * R6 (AABBCCDDEEFFGGHH). | |
185 | * XXXX - reserved (0) | |
186 | * XXXX - reserved (0) | |
187 | * XXXX - Group Number | |
188 | * XXXX - Pool Number. | |
189 | * R7 (IIJJKKLLMMNNOOPP). | |
190 | * XX - reserved. (0) | |
191 | * XX - bit 0-6 reserved (0). bit 7 is Capped indicator. | |
192 | * XX - variable processor Capacity Weight | |
193 | * XX - Unallocated Variable Processor Capacity Weight. | |
194 | * XXXX - Active processors in Physical Processor Pool. | |
d3d2176a | 195 | * XXXX - Processors active on platform. |
f03cdb3a NF |
196 | * R8 (QQQQRRRRRRSSSSSS). if ibm,partition-performance-parameters-level >= 1 |
197 | * XXXX - Physical platform procs allocated to virtualization. | |
198 | * XXXXXX - Max procs capacity % available to the partitions pool. | |
199 | * XXXXXX - Entitled procs capacity % available to the | |
200 | * partitions pool. | |
1da177e4 | 201 | */ |
398778f7 | 202 | static unsigned int h_get_ppp(struct hvcall_ppp_data *ppp_data) |
1da177e4 LT |
203 | { |
204 | unsigned long rc; | |
f03cdb3a | 205 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; |
b9377ffc | 206 | |
f03cdb3a | 207 | rc = plpar_hcall9(H_GET_PPP, retbuf); |
b9377ffc | 208 | |
398778f7 RJ |
209 | ppp_data->entitlement = retbuf[0]; |
210 | ppp_data->unallocated_entitlement = retbuf[1]; | |
211 | ||
212 | ppp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff; | |
213 | ppp_data->pool_num = retbuf[2] & 0xffff; | |
214 | ||
215 | ppp_data->capped = (retbuf[3] >> 6 * 8) & 0x01; | |
216 | ppp_data->weight = (retbuf[3] >> 5 * 8) & 0xff; | |
217 | ppp_data->unallocated_weight = (retbuf[3] >> 4 * 8) & 0xff; | |
218 | ppp_data->active_procs_in_pool = (retbuf[3] >> 2 * 8) & 0xffff; | |
219 | ppp_data->active_system_procs = retbuf[3] & 0xffff; | |
1da177e4 | 220 | |
f03cdb3a NF |
221 | ppp_data->phys_platform_procs = retbuf[4] >> 6 * 8; |
222 | ppp_data->max_proc_cap_avail = (retbuf[4] >> 3 * 8) & 0xffffff; | |
223 | ppp_data->entitled_proc_cap_avail = retbuf[4] & 0xffffff; | |
224 | ||
1da177e4 LT |
225 | return rc; |
226 | } | |
227 | ||
11529396 NF |
228 | static unsigned h_pic(unsigned long *pool_idle_time, |
229 | unsigned long *num_procs) | |
1da177e4 LT |
230 | { |
231 | unsigned long rc; | |
b9377ffc AB |
232 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
233 | ||
234 | rc = plpar_hcall(H_PIC, retbuf); | |
235 | ||
236 | *pool_idle_time = retbuf[0]; | |
237 | *num_procs = retbuf[1]; | |
11529396 NF |
238 | |
239 | return rc; | |
240 | } | |
241 | ||
242 | /* | |
243 | * parse_ppp_data | |
244 | * Parse out the data returned from h_get_ppp and h_pic | |
245 | */ | |
246 | static void parse_ppp_data(struct seq_file *m) | |
247 | { | |
398778f7 | 248 | struct hvcall_ppp_data ppp_data; |
f03cdb3a NF |
249 | struct device_node *root; |
250 | const int *perf_level; | |
11529396 NF |
251 | int rc; |
252 | ||
398778f7 | 253 | rc = h_get_ppp(&ppp_data); |
11529396 NF |
254 | if (rc) |
255 | return; | |
256 | ||
fe333321 | 257 | seq_printf(m, "partition_entitled_capacity=%lld\n", |
398778f7 RJ |
258 | ppp_data.entitlement); |
259 | seq_printf(m, "group=%d\n", ppp_data.group_num); | |
260 | seq_printf(m, "system_active_processors=%d\n", | |
261 | ppp_data.active_system_procs); | |
11529396 NF |
262 | |
263 | /* pool related entries are apropriate for shared configs */ | |
264 | if (lppaca[0].shared_proc) { | |
265 | unsigned long pool_idle_time, pool_procs; | |
266 | ||
398778f7 | 267 | seq_printf(m, "pool=%d\n", ppp_data.pool_num); |
11529396 NF |
268 | |
269 | /* report pool_capacity in percentage */ | |
398778f7 RJ |
270 | seq_printf(m, "pool_capacity=%d\n", |
271 | ppp_data.active_procs_in_pool * 100); | |
11529396 NF |
272 | |
273 | h_pic(&pool_idle_time, &pool_procs); | |
274 | seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time); | |
275 | seq_printf(m, "pool_num_procs=%ld\n", pool_procs); | |
276 | } | |
277 | ||
398778f7 RJ |
278 | seq_printf(m, "unallocated_capacity_weight=%d\n", |
279 | ppp_data.unallocated_weight); | |
280 | seq_printf(m, "capacity_weight=%d\n", ppp_data.weight); | |
281 | seq_printf(m, "capped=%d\n", ppp_data.capped); | |
fe333321 | 282 | seq_printf(m, "unallocated_capacity=%lld\n", |
398778f7 | 283 | ppp_data.unallocated_entitlement); |
f03cdb3a NF |
284 | |
285 | /* The last bits of information returned from h_get_ppp are only | |
286 | * valid if the ibm,partition-performance-parameters-level | |
287 | * property is >= 1. | |
288 | */ | |
289 | root = of_find_node_by_path("/"); | |
290 | if (root) { | |
291 | perf_level = of_get_property(root, | |
292 | "ibm,partition-performance-parameters-level", | |
293 | NULL); | |
294 | if (perf_level && (*perf_level >= 1)) { | |
295 | seq_printf(m, | |
296 | "physical_procs_allocated_to_virtualization=%d\n", | |
297 | ppp_data.phys_platform_procs); | |
298 | seq_printf(m, "max_proc_capacity_available=%d\n", | |
299 | ppp_data.max_proc_cap_avail); | |
300 | seq_printf(m, "entitled_proc_capacity_available=%d\n", | |
301 | ppp_data.entitled_proc_cap_avail); | |
302 | } | |
303 | ||
304 | of_node_put(root); | |
305 | } | |
1da177e4 LT |
306 | } |
307 | ||
dfc3403f NF |
308 | /** |
309 | * parse_mpp_data | |
310 | * Parse out data returned from h_get_mpp | |
311 | */ | |
312 | static void parse_mpp_data(struct seq_file *m) | |
313 | { | |
314 | struct hvcall_mpp_data mpp_data; | |
315 | int rc; | |
316 | ||
317 | rc = h_get_mpp(&mpp_data); | |
318 | if (rc) | |
319 | return; | |
320 | ||
321 | seq_printf(m, "entitled_memory=%ld\n", mpp_data.entitled_mem); | |
322 | ||
323 | if (mpp_data.mapped_mem != -1) | |
324 | seq_printf(m, "mapped_entitled_memory=%ld\n", | |
325 | mpp_data.mapped_mem); | |
326 | ||
327 | seq_printf(m, "entitled_memory_group_number=%d\n", mpp_data.group_num); | |
328 | seq_printf(m, "entitled_memory_pool_number=%d\n", mpp_data.pool_num); | |
329 | ||
330 | seq_printf(m, "entitled_memory_weight=%d\n", mpp_data.mem_weight); | |
331 | seq_printf(m, "unallocated_entitled_memory_weight=%d\n", | |
332 | mpp_data.unallocated_mem_weight); | |
333 | seq_printf(m, "unallocated_io_mapping_entitlement=%ld\n", | |
334 | mpp_data.unallocated_entitlement); | |
335 | ||
336 | if (mpp_data.pool_size != -1) | |
337 | seq_printf(m, "entitled_memory_pool_size=%ld bytes\n", | |
338 | mpp_data.pool_size); | |
339 | ||
340 | seq_printf(m, "entitled_memory_loan_request=%ld\n", | |
341 | mpp_data.loan_request); | |
342 | ||
343 | seq_printf(m, "backing_memory=%ld bytes\n", mpp_data.backing_mem); | |
344 | } | |
345 | ||
1da177e4 LT |
346 | #define SPLPAR_CHARACTERISTICS_TOKEN 20 |
347 | #define SPLPAR_MAXLENGTH 1026*(sizeof(char)) | |
348 | ||
349 | /* | |
350 | * parse_system_parameter_string() | |
351 | * Retrieve the potential_processors, max_entitled_capacity and friends | |
352 | * through the get-system-parameter rtas call. Replace keyword strings as | |
353 | * necessary. | |
354 | */ | |
355 | static void parse_system_parameter_string(struct seq_file *m) | |
356 | { | |
357 | int call_status; | |
358 | ||
34422fed | 359 | unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL); |
1da177e4 LT |
360 | if (!local_buffer) { |
361 | printk(KERN_ERR "%s %s kmalloc failure at line %d \n", | |
e48b1b45 | 362 | __FILE__, __func__, __LINE__); |
1da177e4 LT |
363 | return; |
364 | } | |
365 | ||
366 | spin_lock(&rtas_data_buf_lock); | |
367 | memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH); | |
368 | call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1, | |
369 | NULL, | |
370 | SPLPAR_CHARACTERISTICS_TOKEN, | |
34422fed WS |
371 | __pa(rtas_data_buf), |
372 | RTAS_DATA_BUF_SIZE); | |
1da177e4 LT |
373 | memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH); |
374 | spin_unlock(&rtas_data_buf_lock); | |
375 | ||
376 | if (call_status != 0) { | |
377 | printk(KERN_INFO | |
378 | "%s %s Error calling get-system-parameter (0x%x)\n", | |
e48b1b45 | 379 | __FILE__, __func__, call_status); |
1da177e4 LT |
380 | } else { |
381 | int splpar_strlen; | |
382 | int idx, w_idx; | |
dd00cc48 | 383 | char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL); |
1da177e4 LT |
384 | if (!workbuffer) { |
385 | printk(KERN_ERR "%s %s kmalloc failure at line %d \n", | |
e48b1b45 | 386 | __FILE__, __func__, __LINE__); |
d3d2176a | 387 | kfree(local_buffer); |
1da177e4 LT |
388 | return; |
389 | } | |
390 | #ifdef LPARCFG_DEBUG | |
391 | printk(KERN_INFO "success calling get-system-parameter \n"); | |
392 | #endif | |
34422fed | 393 | splpar_strlen = local_buffer[0] * 256 + local_buffer[1]; |
1da177e4 LT |
394 | local_buffer += 2; /* step over strlen value */ |
395 | ||
1da177e4 LT |
396 | w_idx = 0; |
397 | idx = 0; | |
398 | while ((*local_buffer) && (idx < splpar_strlen)) { | |
399 | workbuffer[w_idx++] = local_buffer[idx++]; | |
400 | if ((local_buffer[idx] == ',') | |
401 | || (local_buffer[idx] == '\0')) { | |
402 | workbuffer[w_idx] = '\0'; | |
403 | if (w_idx) { | |
404 | /* avoid the empty string */ | |
405 | seq_printf(m, "%s\n", workbuffer); | |
406 | } | |
407 | memset(workbuffer, 0, SPLPAR_MAXLENGTH); | |
408 | idx++; /* skip the comma */ | |
409 | w_idx = 0; | |
410 | } else if (local_buffer[idx] == '=') { | |
411 | /* code here to replace workbuffer contents | |
412 | with different keyword strings */ | |
413 | if (0 == strcmp(workbuffer, "MaxEntCap")) { | |
414 | strcpy(workbuffer, | |
415 | "partition_max_entitled_capacity"); | |
416 | w_idx = strlen(workbuffer); | |
417 | } | |
418 | if (0 == strcmp(workbuffer, "MaxPlatProcs")) { | |
419 | strcpy(workbuffer, | |
420 | "system_potential_processors"); | |
421 | w_idx = strlen(workbuffer); | |
422 | } | |
423 | } | |
424 | } | |
425 | kfree(workbuffer); | |
426 | local_buffer -= 2; /* back up over strlen value */ | |
427 | } | |
428 | kfree(local_buffer); | |
429 | } | |
430 | ||
1da177e4 LT |
431 | /* Return the number of processors in the system. |
432 | * This function reads through the device tree and counts | |
433 | * the virtual processors, this does not include threads. | |
434 | */ | |
435 | static int lparcfg_count_active_processors(void) | |
436 | { | |
437 | struct device_node *cpus_dn = NULL; | |
438 | int count = 0; | |
439 | ||
440 | while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) { | |
441 | #ifdef LPARCFG_DEBUG | |
442 | printk(KERN_ERR "cpus_dn %p \n", cpus_dn); | |
443 | #endif | |
444 | count++; | |
445 | } | |
446 | return count; | |
447 | } | |
448 | ||
ffa5abbd BK |
449 | static void pseries_cmo_data(struct seq_file *m) |
450 | { | |
451 | int cpu; | |
452 | unsigned long cmo_faults = 0; | |
453 | unsigned long cmo_fault_time = 0; | |
454 | ||
ac22429d RJ |
455 | seq_printf(m, "cmo_enabled=%d\n", firmware_has_feature(FW_FEATURE_CMO)); |
456 | ||
ffa5abbd BK |
457 | if (!firmware_has_feature(FW_FEATURE_CMO)) |
458 | return; | |
459 | ||
460 | for_each_possible_cpu(cpu) { | |
461 | cmo_faults += lppaca[cpu].cmo_faults; | |
462 | cmo_fault_time += lppaca[cpu].cmo_fault_time; | |
463 | } | |
464 | ||
465 | seq_printf(m, "cmo_faults=%lu\n", cmo_faults); | |
466 | seq_printf(m, "cmo_fault_time_usec=%lu\n", | |
467 | cmo_fault_time / tb_ticks_per_usec); | |
ac22429d RJ |
468 | seq_printf(m, "cmo_primary_psp=%d\n", cmo_get_primary_psp()); |
469 | seq_printf(m, "cmo_secondary_psp=%d\n", cmo_get_secondary_psp()); | |
470 | seq_printf(m, "cmo_page_size=%lu\n", cmo_get_page_size()); | |
ffa5abbd BK |
471 | } |
472 | ||
0559f0a7 AB |
473 | static void splpar_dispatch_data(struct seq_file *m) |
474 | { | |
475 | int cpu; | |
476 | unsigned long dispatches = 0; | |
477 | unsigned long dispatch_dispersions = 0; | |
478 | ||
479 | for_each_possible_cpu(cpu) { | |
480 | dispatches += lppaca[cpu].yield_count; | |
481 | dispatch_dispersions += lppaca[cpu].dispersion_count; | |
482 | } | |
483 | ||
484 | seq_printf(m, "dispatches=%lu\n", dispatches); | |
485 | seq_printf(m, "dispatch_dispersions=%lu\n", dispatch_dispersions); | |
486 | } | |
487 | ||
16e9f994 | 488 | static int pseries_lparcfg_data(struct seq_file *m, void *v) |
1da177e4 LT |
489 | { |
490 | int partition_potential_processors; | |
491 | int partition_active_processors; | |
1da177e4 | 492 | struct device_node *rtas_node; |
a7f67bdf | 493 | const int *lrdrp = NULL; |
1da177e4 | 494 | |
8c8dc322 | 495 | rtas_node = of_find_node_by_path("/rtas"); |
2b9a32ed | 496 | if (rtas_node) |
e2eb6392 | 497 | lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL); |
1da177e4 LT |
498 | |
499 | if (lrdrp == NULL) { | |
271c3f35 | 500 | partition_potential_processors = vdso_data->processorCount; |
1da177e4 LT |
501 | } else { |
502 | partition_potential_processors = *(lrdrp + 4); | |
503 | } | |
8c8dc322 | 504 | of_node_put(rtas_node); |
1da177e4 LT |
505 | |
506 | partition_active_processors = lparcfg_count_active_processors(); | |
507 | ||
1ababe11 | 508 | if (firmware_has_feature(FW_FEATURE_SPLPAR)) { |
1da177e4 LT |
509 | /* this call handles the ibm,get-system-parameter contents */ |
510 | parse_system_parameter_string(m); | |
11529396 | 511 | parse_ppp_data(m); |
dfc3403f | 512 | parse_mpp_data(m); |
ffa5abbd | 513 | pseries_cmo_data(m); |
0559f0a7 | 514 | splpar_dispatch_data(m); |
1da177e4 | 515 | |
11529396 | 516 | seq_printf(m, "purr=%ld\n", get_purr()); |
1da177e4 LT |
517 | } else { /* non SPLPAR case */ |
518 | ||
519 | seq_printf(m, "system_active_processors=%d\n", | |
520 | partition_potential_processors); | |
521 | ||
522 | seq_printf(m, "system_potential_processors=%d\n", | |
523 | partition_potential_processors); | |
524 | ||
525 | seq_printf(m, "partition_max_entitled_capacity=%d\n", | |
526 | partition_potential_processors * 100); | |
527 | ||
528 | seq_printf(m, "partition_entitled_capacity=%d\n", | |
529 | partition_active_processors * 100); | |
530 | } | |
531 | ||
532 | seq_printf(m, "partition_active_processors=%d\n", | |
533 | partition_active_processors); | |
534 | ||
535 | seq_printf(m, "partition_potential_processors=%d\n", | |
536 | partition_potential_processors); | |
537 | ||
3356bb9f | 538 | seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc); |
1da177e4 LT |
539 | |
540 | return 0; | |
541 | } | |
542 | ||
11529396 NF |
543 | static ssize_t update_ppp(u64 *entitlement, u8 *weight) |
544 | { | |
398778f7 RJ |
545 | struct hvcall_ppp_data ppp_data; |
546 | u8 new_weight; | |
11529396 NF |
547 | u64 new_entitled; |
548 | ssize_t retval; | |
549 | ||
550 | /* Get our current parameters */ | |
398778f7 | 551 | retval = h_get_ppp(&ppp_data); |
11529396 NF |
552 | if (retval) |
553 | return retval; | |
554 | ||
11529396 | 555 | if (entitlement) { |
398778f7 | 556 | new_weight = ppp_data.weight; |
11529396 NF |
557 | new_entitled = *entitlement; |
558 | } else if (weight) { | |
559 | new_weight = *weight; | |
398778f7 | 560 | new_entitled = ppp_data.entitlement; |
11529396 NF |
561 | } else |
562 | return -EINVAL; | |
563 | ||
fe333321 | 564 | pr_debug("%s: current_entitled = %llu, current_weight = %u\n", |
5df72bf3 | 565 | __func__, ppp_data.entitlement, ppp_data.weight); |
11529396 | 566 | |
fe333321 | 567 | pr_debug("%s: new_entitled = %llu, new_weight = %u\n", |
5df72bf3 | 568 | __func__, new_entitled, new_weight); |
11529396 NF |
569 | |
570 | retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight); | |
571 | return retval; | |
572 | } | |
573 | ||
dfc3403f NF |
574 | /** |
575 | * update_mpp | |
576 | * | |
577 | * Update the memory entitlement and weight for the partition. Caller must | |
578 | * specify either a new entitlement or weight, not both, to be updated | |
579 | * since the h_set_mpp call takes both entitlement and weight as parameters. | |
580 | */ | |
581 | static ssize_t update_mpp(u64 *entitlement, u8 *weight) | |
582 | { | |
583 | struct hvcall_mpp_data mpp_data; | |
584 | u64 new_entitled; | |
585 | u8 new_weight; | |
586 | ssize_t rc; | |
587 | ||
22e1a4dd NF |
588 | if (entitlement) { |
589 | /* Check with vio to ensure the new memory entitlement | |
590 | * can be handled. | |
591 | */ | |
592 | rc = vio_cmo_entitlement_update(*entitlement); | |
593 | if (rc) | |
594 | return rc; | |
595 | } | |
596 | ||
dfc3403f NF |
597 | rc = h_get_mpp(&mpp_data); |
598 | if (rc) | |
599 | return rc; | |
600 | ||
601 | if (entitlement) { | |
602 | new_weight = mpp_data.mem_weight; | |
603 | new_entitled = *entitlement; | |
604 | } else if (weight) { | |
605 | new_weight = *weight; | |
606 | new_entitled = mpp_data.entitled_mem; | |
607 | } else | |
608 | return -EINVAL; | |
609 | ||
610 | pr_debug("%s: current_entitled = %lu, current_weight = %u\n", | |
5df72bf3 | 611 | __func__, mpp_data.entitled_mem, mpp_data.mem_weight); |
dfc3403f | 612 | |
fe333321 | 613 | pr_debug("%s: new_entitled = %llu, new_weight = %u\n", |
5df72bf3 | 614 | __func__, new_entitled, new_weight); |
dfc3403f NF |
615 | |
616 | rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight); | |
617 | return rc; | |
618 | } | |
619 | ||
1da177e4 LT |
620 | /* |
621 | * Interface for changing system parameters (variable capacity weight | |
622 | * and entitled capacity). Format of input is "param_name=value"; | |
623 | * anything after value is ignored. Valid parameters at this time are | |
624 | * "partition_entitled_capacity" and "capacity_weight". We use | |
625 | * H_SET_PPP to alter parameters. | |
626 | * | |
627 | * This function should be invoked only on systems with | |
628 | * FW_FEATURE_SPLPAR. | |
629 | */ | |
630 | static ssize_t lparcfg_write(struct file *file, const char __user * buf, | |
631 | size_t count, loff_t * off) | |
632 | { | |
16c14b46 NF |
633 | int kbuf_sz = 64; |
634 | char kbuf[kbuf_sz]; | |
1da177e4 LT |
635 | char *tmp; |
636 | u64 new_entitled, *new_entitled_ptr = &new_entitled; | |
637 | u8 new_weight, *new_weight_ptr = &new_weight; | |
16c14b46 | 638 | ssize_t retval; |
1da177e4 | 639 | |
0524aad7 SR |
640 | if (!firmware_has_feature(FW_FEATURE_SPLPAR) || |
641 | firmware_has_feature(FW_FEATURE_ISERIES)) | |
642 | return -EINVAL; | |
643 | ||
16c14b46 NF |
644 | if (count > kbuf_sz) |
645 | return -EINVAL; | |
1da177e4 | 646 | |
1da177e4 | 647 | if (copy_from_user(kbuf, buf, count)) |
16c14b46 | 648 | return -EFAULT; |
1da177e4 | 649 | |
1da177e4 LT |
650 | kbuf[count - 1] = '\0'; |
651 | tmp = strchr(kbuf, '='); | |
652 | if (!tmp) | |
16c14b46 | 653 | return -EINVAL; |
1da177e4 LT |
654 | |
655 | *tmp++ = '\0'; | |
656 | ||
657 | if (!strcmp(kbuf, "partition_entitled_capacity")) { | |
658 | char *endp; | |
659 | *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); | |
660 | if (endp == tmp) | |
16c14b46 | 661 | return -EINVAL; |
11529396 NF |
662 | |
663 | retval = update_ppp(new_entitled_ptr, NULL); | |
1da177e4 LT |
664 | } else if (!strcmp(kbuf, "capacity_weight")) { |
665 | char *endp; | |
666 | *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); | |
667 | if (endp == tmp) | |
16c14b46 | 668 | return -EINVAL; |
1da177e4 | 669 | |
11529396 | 670 | retval = update_ppp(NULL, new_weight_ptr); |
dfc3403f NF |
671 | } else if (!strcmp(kbuf, "entitled_memory")) { |
672 | char *endp; | |
673 | *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10); | |
674 | if (endp == tmp) | |
16c14b46 | 675 | return -EINVAL; |
dfc3403f NF |
676 | |
677 | retval = update_mpp(new_entitled_ptr, NULL); | |
678 | } else if (!strcmp(kbuf, "entitled_memory_weight")) { | |
679 | char *endp; | |
680 | *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10); | |
681 | if (endp == tmp) | |
16c14b46 | 682 | return -EINVAL; |
dfc3403f NF |
683 | |
684 | retval = update_mpp(NULL, new_weight_ptr); | |
11529396 | 685 | } else |
16c14b46 | 686 | return -EINVAL; |
1da177e4 | 687 | |
706c8c93 | 688 | if (retval == H_SUCCESS || retval == H_CONSTRAINED) { |
1da177e4 | 689 | retval = count; |
706c8c93 | 690 | } else if (retval == H_BUSY) { |
1da177e4 | 691 | retval = -EBUSY; |
706c8c93 | 692 | } else if (retval == H_HARDWARE) { |
1da177e4 | 693 | retval = -EIO; |
706c8c93 | 694 | } else if (retval == H_PARAMETER) { |
1da177e4 | 695 | retval = -EINVAL; |
1da177e4 LT |
696 | } |
697 | ||
1da177e4 LT |
698 | return retval; |
699 | } | |
700 | ||
16e9f994 SR |
701 | #else /* CONFIG_PPC_PSERIES */ |
702 | ||
703 | static int pseries_lparcfg_data(struct seq_file *m, void *v) | |
704 | { | |
705 | return 0; | |
706 | } | |
707 | ||
708 | static ssize_t lparcfg_write(struct file *file, const char __user * buf, | |
709 | size_t count, loff_t * off) | |
710 | { | |
0524aad7 | 711 | return -EINVAL; |
16e9f994 SR |
712 | } |
713 | ||
1da177e4 LT |
714 | #endif /* CONFIG_PPC_PSERIES */ |
715 | ||
16e9f994 SR |
716 | static int lparcfg_data(struct seq_file *m, void *v) |
717 | { | |
718 | struct device_node *rootdn; | |
719 | const char *model = ""; | |
720 | const char *system_id = ""; | |
721 | const char *tmp; | |
a7f67bdf JK |
722 | const unsigned int *lp_index_ptr; |
723 | unsigned int lp_index = 0; | |
16e9f994 SR |
724 | |
725 | seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS); | |
726 | ||
8c8dc322 | 727 | rootdn = of_find_node_by_path("/"); |
16e9f994 | 728 | if (rootdn) { |
e2eb6392 | 729 | tmp = of_get_property(rootdn, "model", NULL); |
16e9f994 SR |
730 | if (tmp) { |
731 | model = tmp; | |
732 | /* Skip "IBM," - see platforms/iseries/dt.c */ | |
733 | if (firmware_has_feature(FW_FEATURE_ISERIES)) | |
734 | model += 4; | |
735 | } | |
e2eb6392 | 736 | tmp = of_get_property(rootdn, "system-id", NULL); |
16e9f994 SR |
737 | if (tmp) { |
738 | system_id = tmp; | |
739 | /* Skip "IBM," - see platforms/iseries/dt.c */ | |
740 | if (firmware_has_feature(FW_FEATURE_ISERIES)) | |
741 | system_id += 4; | |
742 | } | |
e2eb6392 SR |
743 | lp_index_ptr = of_get_property(rootdn, "ibm,partition-no", |
744 | NULL); | |
16e9f994 SR |
745 | if (lp_index_ptr) |
746 | lp_index = *lp_index_ptr; | |
8c8dc322 | 747 | of_node_put(rootdn); |
16e9f994 SR |
748 | } |
749 | seq_printf(m, "serial_number=%s\n", system_id); | |
750 | seq_printf(m, "system_type=%s\n", model); | |
751 | seq_printf(m, "partition_id=%d\n", (int)lp_index); | |
752 | ||
753 | if (firmware_has_feature(FW_FEATURE_ISERIES)) | |
754 | return iseries_lparcfg_data(m, v); | |
755 | return pseries_lparcfg_data(m, v); | |
756 | } | |
757 | ||
1da177e4 LT |
758 | static int lparcfg_open(struct inode *inode, struct file *file) |
759 | { | |
760 | return single_open(file, lparcfg_data, NULL); | |
761 | } | |
762 | ||
1c21a293 | 763 | static const struct file_operations lparcfg_fops = { |
8acb888c AB |
764 | .owner = THIS_MODULE, |
765 | .read = seq_read, | |
0524aad7 | 766 | .write = lparcfg_write, |
8acb888c AB |
767 | .open = lparcfg_open, |
768 | .release = single_release, | |
1da177e4 LT |
769 | }; |
770 | ||
1c21a293 | 771 | static int __init lparcfg_init(void) |
1da177e4 LT |
772 | { |
773 | struct proc_dir_entry *ent; | |
71839267 | 774 | mode_t mode = S_IRUSR | S_IRGRP | S_IROTH; |
1da177e4 LT |
775 | |
776 | /* Allow writing if we have FW_FEATURE_SPLPAR */ | |
16e9f994 | 777 | if (firmware_has_feature(FW_FEATURE_SPLPAR) && |
0524aad7 | 778 | !firmware_has_feature(FW_FEATURE_ISERIES)) |
1da177e4 | 779 | mode |= S_IWUSR; |
1da177e4 | 780 | |
66747138 DL |
781 | ent = proc_create("ppc64/lparcfg", mode, NULL, &lparcfg_fops); |
782 | if (!ent) { | |
1da177e4 LT |
783 | printk(KERN_ERR "Failed to create ppc64/lparcfg\n"); |
784 | return -EIO; | |
785 | } | |
786 | ||
787 | proc_ppc64_lparcfg = ent; | |
788 | return 0; | |
789 | } | |
790 | ||
1c21a293 | 791 | static void __exit lparcfg_cleanup(void) |
1da177e4 | 792 | { |
0d9dc4b4 | 793 | if (proc_ppc64_lparcfg) |
1da177e4 | 794 | remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent); |
1da177e4 LT |
795 | } |
796 | ||
797 | module_init(lparcfg_init); | |
798 | module_exit(lparcfg_cleanup); | |
799 | MODULE_DESCRIPTION("Interface for LPAR configuration data"); | |
800 | MODULE_AUTHOR("Dave Engebretsen"); | |
801 | MODULE_LICENSE("GPL"); |