powerpc/pseries: Add memory entitlement capabilities to /proc/ppc64/lparcfg
[safe/jmp/linux-2.6] / arch / powerpc / kernel / lparcfg.c
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
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>
28 #include <asm/iseries/hv_lp_config.h>
29 #include <asm/lppaca.h>
30 #include <asm/hvcall.h>
31 #include <asm/firmware.h>
32 #include <asm/rtas.h>
33 #include <asm/system.h>
34 #include <asm/time.h>
35 #include <asm/prom.h>
36 #include <asm/vdso_datapage.h>
37
38 #define MODULE_VERS "1.8"
39 #define MODULE_NAME "lparcfg"
40
41 /* #define LPARCFG_DEBUG */
42
43 static struct proc_dir_entry *proc_ppc64_lparcfg;
44
45 /*
46  * Track sum of all purrs across all processors. This is used to further
47  * calculate usage values by different applications
48  */
49 static unsigned long get_purr(void)
50 {
51         unsigned long sum_purr = 0;
52         int cpu;
53
54         for_each_possible_cpu(cpu) {
55                 if (firmware_has_feature(FW_FEATURE_ISERIES))
56                         sum_purr += lppaca[cpu].emulated_time_base;
57                 else {
58                         struct cpu_usage *cu;
59
60                         cu = &per_cpu(cpu_usage_array, cpu);
61                         sum_purr += cu->current_tb;
62                 }
63         }
64         return sum_purr;
65 }
66
67 #ifdef CONFIG_PPC_ISERIES
68
69 /*
70  * Methods used to fetch LPAR data when running on an iSeries platform.
71  */
72 static int iseries_lparcfg_data(struct seq_file *m, void *v)
73 {
74         unsigned long pool_id;
75         int shared, entitled_capacity, max_entitled_capacity;
76         int processors, max_processors;
77         unsigned long purr = get_purr();
78
79         shared = (int)(local_paca->lppaca_ptr->shared_proc);
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 }
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
126 #endif                          /* CONFIG_PPC_ISERIES */
127
128 #ifdef CONFIG_PPC_PSERIES
129 /*
130  * Methods used to fetch LPAR data when running on a pSeries platform.
131  */
132 /**
133  * h_get_mpp
134  * H_GET_MPP hcall returns info in 7 parms
135  */
136 int h_get_mpp(struct hvcall_mpp_data *mpp_data)
137 {
138         int rc;
139         unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
140
141         rc = plpar_hcall9(H_GET_MPP, retbuf);
142
143         mpp_data->entitled_mem = retbuf[0];
144         mpp_data->mapped_mem = retbuf[1];
145
146         mpp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff;
147         mpp_data->pool_num = retbuf[2] & 0xffff;
148
149         mpp_data->mem_weight = (retbuf[3] >> 7 * 8) & 0xff;
150         mpp_data->unallocated_mem_weight = (retbuf[3] >> 6 * 8) & 0xff;
151         mpp_data->unallocated_entitlement = retbuf[3] & 0xffffffffffff;
152
153         mpp_data->pool_size = retbuf[4];
154         mpp_data->loan_request = retbuf[5];
155         mpp_data->backing_mem = retbuf[6];
156
157         return rc;
158 }
159 EXPORT_SYMBOL(h_get_mpp);
160
161 /*
162  * H_GET_PPP hcall returns info in 4 parms.
163  *  entitled_capacity,unallocated_capacity,
164  *  aggregation, resource_capability).
165  *
166  *  R4 = Entitled Processor Capacity Percentage.
167  *  R5 = Unallocated Processor Capacity Percentage.
168  *  R6 (AABBCCDDEEFFGGHH).
169  *      XXXX - reserved (0)
170  *          XXXX - reserved (0)
171  *              XXXX - Group Number
172  *                  XXXX - Pool Number.
173  *  R7 (IIJJKKLLMMNNOOPP).
174  *      XX - reserved. (0)
175  *        XX - bit 0-6 reserved (0).   bit 7 is Capped indicator.
176  *          XX - variable processor Capacity Weight
177  *            XX - Unallocated Variable Processor Capacity Weight.
178  *              XXXX - Active processors in Physical Processor Pool.
179  *                  XXXX  - Processors active on platform.
180  */
181 static unsigned int h_get_ppp(unsigned long *entitled,
182                               unsigned long *unallocated,
183                               unsigned long *aggregation,
184                               unsigned long *resource)
185 {
186         unsigned long rc;
187         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
188
189         rc = plpar_hcall(H_GET_PPP, retbuf);
190
191         *entitled = retbuf[0];
192         *unallocated = retbuf[1];
193         *aggregation = retbuf[2];
194         *resource = retbuf[3];
195
196         return rc;
197 }
198
199 static unsigned h_pic(unsigned long *pool_idle_time,
200                       unsigned long *num_procs)
201 {
202         unsigned long rc;
203         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
204
205         rc = plpar_hcall(H_PIC, retbuf);
206
207         *pool_idle_time = retbuf[0];
208         *num_procs = retbuf[1];
209
210         return rc;
211 }
212
213 /*
214  * parse_ppp_data
215  * Parse out the data returned from h_get_ppp and h_pic
216  */
217 static void parse_ppp_data(struct seq_file *m)
218 {
219         unsigned long h_entitled, h_unallocated;
220         unsigned long h_aggregation, h_resource;
221         int rc;
222
223         rc = h_get_ppp(&h_entitled, &h_unallocated, &h_aggregation,
224                        &h_resource);
225         if (rc)
226                 return;
227
228         seq_printf(m, "partition_entitled_capacity=%ld\n", h_entitled);
229         seq_printf(m, "group=%ld\n", (h_aggregation >> 2 * 8) & 0xffff);
230         seq_printf(m, "system_active_processors=%ld\n",
231                    (h_resource >> 0 * 8) & 0xffff);
232
233         /* pool related entries are apropriate for shared configs */
234         if (lppaca[0].shared_proc) {
235                 unsigned long pool_idle_time, pool_procs;
236
237                 seq_printf(m, "pool=%ld\n", (h_aggregation >> 0 * 8) & 0xffff);
238
239                 /* report pool_capacity in percentage */
240                 seq_printf(m, "pool_capacity=%ld\n",
241                            ((h_resource >> 2 * 8) & 0xffff) * 100);
242
243                 h_pic(&pool_idle_time, &pool_procs);
244                 seq_printf(m, "pool_idle_time=%ld\n", pool_idle_time);
245                 seq_printf(m, "pool_num_procs=%ld\n", pool_procs);
246         }
247
248         seq_printf(m, "unallocated_capacity_weight=%ld\n",
249                    (h_resource >> 4 * 8) & 0xFF);
250
251         seq_printf(m, "capacity_weight=%ld\n", (h_resource >> 5 * 8) & 0xFF);
252         seq_printf(m, "capped=%ld\n", (h_resource >> 6 * 8) & 0x01);
253         seq_printf(m, "unallocated_capacity=%ld\n", h_unallocated);
254 }
255
256 /**
257  * parse_mpp_data
258  * Parse out data returned from h_get_mpp
259  */
260 static void parse_mpp_data(struct seq_file *m)
261 {
262         struct hvcall_mpp_data mpp_data;
263         int rc;
264
265         rc = h_get_mpp(&mpp_data);
266         if (rc)
267                 return;
268
269         seq_printf(m, "entitled_memory=%ld\n", mpp_data.entitled_mem);
270
271         if (mpp_data.mapped_mem != -1)
272                 seq_printf(m, "mapped_entitled_memory=%ld\n",
273                            mpp_data.mapped_mem);
274
275         seq_printf(m, "entitled_memory_group_number=%d\n", mpp_data.group_num);
276         seq_printf(m, "entitled_memory_pool_number=%d\n", mpp_data.pool_num);
277
278         seq_printf(m, "entitled_memory_weight=%d\n", mpp_data.mem_weight);
279         seq_printf(m, "unallocated_entitled_memory_weight=%d\n",
280                    mpp_data.unallocated_mem_weight);
281         seq_printf(m, "unallocated_io_mapping_entitlement=%ld\n",
282                    mpp_data.unallocated_entitlement);
283
284         if (mpp_data.pool_size != -1)
285                 seq_printf(m, "entitled_memory_pool_size=%ld bytes\n",
286                            mpp_data.pool_size);
287
288         seq_printf(m, "entitled_memory_loan_request=%ld\n",
289                    mpp_data.loan_request);
290
291         seq_printf(m, "backing_memory=%ld bytes\n", mpp_data.backing_mem);
292 }
293
294 #define SPLPAR_CHARACTERISTICS_TOKEN 20
295 #define SPLPAR_MAXLENGTH 1026*(sizeof(char))
296
297 /*
298  * parse_system_parameter_string()
299  * Retrieve the potential_processors, max_entitled_capacity and friends
300  * through the get-system-parameter rtas call.  Replace keyword strings as
301  * necessary.
302  */
303 static void parse_system_parameter_string(struct seq_file *m)
304 {
305         int call_status;
306
307         unsigned char *local_buffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
308         if (!local_buffer) {
309                 printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
310                        __FILE__, __func__, __LINE__);
311                 return;
312         }
313
314         spin_lock(&rtas_data_buf_lock);
315         memset(rtas_data_buf, 0, SPLPAR_MAXLENGTH);
316         call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
317                                 NULL,
318                                 SPLPAR_CHARACTERISTICS_TOKEN,
319                                 __pa(rtas_data_buf),
320                                 RTAS_DATA_BUF_SIZE);
321         memcpy(local_buffer, rtas_data_buf, SPLPAR_MAXLENGTH);
322         spin_unlock(&rtas_data_buf_lock);
323
324         if (call_status != 0) {
325                 printk(KERN_INFO
326                        "%s %s Error calling get-system-parameter (0x%x)\n",
327                        __FILE__, __func__, call_status);
328         } else {
329                 int splpar_strlen;
330                 int idx, w_idx;
331                 char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
332                 if (!workbuffer) {
333                         printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
334                                __FILE__, __func__, __LINE__);
335                         kfree(local_buffer);
336                         return;
337                 }
338 #ifdef LPARCFG_DEBUG
339                 printk(KERN_INFO "success calling get-system-parameter \n");
340 #endif
341                 splpar_strlen = local_buffer[0] * 256 + local_buffer[1];
342                 local_buffer += 2;      /* step over strlen value */
343
344                 w_idx = 0;
345                 idx = 0;
346                 while ((*local_buffer) && (idx < splpar_strlen)) {
347                         workbuffer[w_idx++] = local_buffer[idx++];
348                         if ((local_buffer[idx] == ',')
349                             || (local_buffer[idx] == '\0')) {
350                                 workbuffer[w_idx] = '\0';
351                                 if (w_idx) {
352                                         /* avoid the empty string */
353                                         seq_printf(m, "%s\n", workbuffer);
354                                 }
355                                 memset(workbuffer, 0, SPLPAR_MAXLENGTH);
356                                 idx++;  /* skip the comma */
357                                 w_idx = 0;
358                         } else if (local_buffer[idx] == '=') {
359                                 /* code here to replace workbuffer contents
360                                    with different keyword strings */
361                                 if (0 == strcmp(workbuffer, "MaxEntCap")) {
362                                         strcpy(workbuffer,
363                                                "partition_max_entitled_capacity");
364                                         w_idx = strlen(workbuffer);
365                                 }
366                                 if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
367                                         strcpy(workbuffer,
368                                                "system_potential_processors");
369                                         w_idx = strlen(workbuffer);
370                                 }
371                         }
372                 }
373                 kfree(workbuffer);
374                 local_buffer -= 2;      /* back up over strlen value */
375         }
376         kfree(local_buffer);
377 }
378
379 /* Return the number of processors in the system.
380  * This function reads through the device tree and counts
381  * the virtual processors, this does not include threads.
382  */
383 static int lparcfg_count_active_processors(void)
384 {
385         struct device_node *cpus_dn = NULL;
386         int count = 0;
387
388         while ((cpus_dn = of_find_node_by_type(cpus_dn, "cpu"))) {
389 #ifdef LPARCFG_DEBUG
390                 printk(KERN_ERR "cpus_dn %p \n", cpus_dn);
391 #endif
392                 count++;
393         }
394         return count;
395 }
396
397 static int pseries_lparcfg_data(struct seq_file *m, void *v)
398 {
399         int partition_potential_processors;
400         int partition_active_processors;
401         struct device_node *rtas_node;
402         const int *lrdrp = NULL;
403
404         rtas_node = of_find_node_by_path("/rtas");
405         if (rtas_node)
406                 lrdrp = of_get_property(rtas_node, "ibm,lrdr-capacity", NULL);
407
408         if (lrdrp == NULL) {
409                 partition_potential_processors = vdso_data->processorCount;
410         } else {
411                 partition_potential_processors = *(lrdrp + 4);
412         }
413         of_node_put(rtas_node);
414
415         partition_active_processors = lparcfg_count_active_processors();
416
417         if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
418                 /* this call handles the ibm,get-system-parameter contents */
419                 parse_system_parameter_string(m);
420                 parse_ppp_data(m);
421                 parse_mpp_data(m);
422
423                 seq_printf(m, "purr=%ld\n", get_purr());
424         } else {                /* non SPLPAR case */
425
426                 seq_printf(m, "system_active_processors=%d\n",
427                            partition_potential_processors);
428
429                 seq_printf(m, "system_potential_processors=%d\n",
430                            partition_potential_processors);
431
432                 seq_printf(m, "partition_max_entitled_capacity=%d\n",
433                            partition_potential_processors * 100);
434
435                 seq_printf(m, "partition_entitled_capacity=%d\n",
436                            partition_active_processors * 100);
437         }
438
439         seq_printf(m, "partition_active_processors=%d\n",
440                    partition_active_processors);
441
442         seq_printf(m, "partition_potential_processors=%d\n",
443                    partition_potential_processors);
444
445         seq_printf(m, "shared_processor_mode=%d\n", lppaca[0].shared_proc);
446
447         return 0;
448 }
449
450 static ssize_t update_ppp(u64 *entitlement, u8 *weight)
451 {
452         unsigned long current_entitled;
453         unsigned long dummy;
454         unsigned long resource;
455         u8 current_weight, new_weight;
456         u64 new_entitled;
457         ssize_t retval;
458
459         /* Get our current parameters */
460         retval = h_get_ppp(&current_entitled, &dummy, &dummy, &resource);
461         if (retval)
462                 return retval;
463
464         current_weight = (resource >> 5 * 8) & 0xFF;
465
466         if (entitlement) {
467                 new_weight = current_weight;
468                 new_entitled = *entitlement;
469         } else if (weight) {
470                 new_weight = *weight;
471                 new_entitled = current_entitled;
472         } else
473                 return -EINVAL;
474
475         pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
476                  __FUNCTION__, current_entitled, current_weight);
477
478         pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
479                  __FUNCTION__, new_entitled, new_weight);
480
481         retval = plpar_hcall_norets(H_SET_PPP, new_entitled, new_weight);
482         return retval;
483 }
484
485 /**
486  * update_mpp
487  *
488  * Update the memory entitlement and weight for the partition.  Caller must
489  * specify either a new entitlement or weight, not both, to be updated
490  * since the h_set_mpp call takes both entitlement and weight as parameters.
491  */
492 static ssize_t update_mpp(u64 *entitlement, u8 *weight)
493 {
494         struct hvcall_mpp_data mpp_data;
495         u64 new_entitled;
496         u8 new_weight;
497         ssize_t rc;
498
499         rc = h_get_mpp(&mpp_data);
500         if (rc)
501                 return rc;
502
503         if (entitlement) {
504                 new_weight = mpp_data.mem_weight;
505                 new_entitled = *entitlement;
506         } else if (weight) {
507                 new_weight = *weight;
508                 new_entitled = mpp_data.entitled_mem;
509         } else
510                 return -EINVAL;
511
512         pr_debug("%s: current_entitled = %lu, current_weight = %u\n",
513                  __FUNCTION__, mpp_data.entitled_mem, mpp_data.mem_weight);
514
515         pr_debug("%s: new_entitled = %lu, new_weight = %u\n",
516                  __FUNCTION__, new_entitled, new_weight);
517
518         rc = plpar_hcall_norets(H_SET_MPP, new_entitled, new_weight);
519         return rc;
520 }
521
522 /*
523  * Interface for changing system parameters (variable capacity weight
524  * and entitled capacity).  Format of input is "param_name=value";
525  * anything after value is ignored.  Valid parameters at this time are
526  * "partition_entitled_capacity" and "capacity_weight".  We use
527  * H_SET_PPP to alter parameters.
528  *
529  * This function should be invoked only on systems with
530  * FW_FEATURE_SPLPAR.
531  */
532 static ssize_t lparcfg_write(struct file *file, const char __user * buf,
533                              size_t count, loff_t * off)
534 {
535         char *kbuf;
536         char *tmp;
537         u64 new_entitled, *new_entitled_ptr = &new_entitled;
538         u8 new_weight, *new_weight_ptr = &new_weight;
539         ssize_t retval = -ENOMEM;
540
541         if (!firmware_has_feature(FW_FEATURE_SPLPAR) ||
542                         firmware_has_feature(FW_FEATURE_ISERIES))
543                 return -EINVAL;
544
545         kbuf = kmalloc(count, GFP_KERNEL);
546         if (!kbuf)
547                 goto out;
548
549         retval = -EFAULT;
550         if (copy_from_user(kbuf, buf, count))
551                 goto out;
552
553         retval = -EINVAL;
554         kbuf[count - 1] = '\0';
555         tmp = strchr(kbuf, '=');
556         if (!tmp)
557                 goto out;
558
559         *tmp++ = '\0';
560
561         if (!strcmp(kbuf, "partition_entitled_capacity")) {
562                 char *endp;
563                 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
564                 if (endp == tmp)
565                         goto out;
566
567                 retval = update_ppp(new_entitled_ptr, NULL);
568         } else if (!strcmp(kbuf, "capacity_weight")) {
569                 char *endp;
570                 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
571                 if (endp == tmp)
572                         goto out;
573
574                 retval = update_ppp(NULL, new_weight_ptr);
575         } else if (!strcmp(kbuf, "entitled_memory")) {
576                 char *endp;
577                 *new_entitled_ptr = (u64) simple_strtoul(tmp, &endp, 10);
578                 if (endp == tmp)
579                         goto out;
580
581                 retval = update_mpp(new_entitled_ptr, NULL);
582         } else if (!strcmp(kbuf, "entitled_memory_weight")) {
583                 char *endp;
584                 *new_weight_ptr = (u8) simple_strtoul(tmp, &endp, 10);
585                 if (endp == tmp)
586                         goto out;
587
588                 retval = update_mpp(NULL, new_weight_ptr);
589         } else
590                 goto out;
591
592         if (retval == H_SUCCESS || retval == H_CONSTRAINED) {
593                 retval = count;
594         } else if (retval == H_BUSY) {
595                 retval = -EBUSY;
596         } else if (retval == H_HARDWARE) {
597                 retval = -EIO;
598         } else if (retval == H_PARAMETER) {
599                 retval = -EINVAL;
600         } else {
601                 printk(KERN_WARNING "%s: received unknown hv return code %ld",
602                        __func__, retval);
603                 retval = -EIO;
604         }
605
606 out:
607         kfree(kbuf);
608         return retval;
609 }
610
611 #else                           /* CONFIG_PPC_PSERIES */
612
613 static int pseries_lparcfg_data(struct seq_file *m, void *v)
614 {
615         return 0;
616 }
617
618 static ssize_t lparcfg_write(struct file *file, const char __user * buf,
619                              size_t count, loff_t * off)
620 {
621         return -EINVAL;
622 }
623
624 #endif                          /* CONFIG_PPC_PSERIES */
625
626 static int lparcfg_data(struct seq_file *m, void *v)
627 {
628         struct device_node *rootdn;
629         const char *model = "";
630         const char *system_id = "";
631         const char *tmp;
632         const unsigned int *lp_index_ptr;
633         unsigned int lp_index = 0;
634
635         seq_printf(m, "%s %s \n", MODULE_NAME, MODULE_VERS);
636
637         rootdn = of_find_node_by_path("/");
638         if (rootdn) {
639                 tmp = of_get_property(rootdn, "model", NULL);
640                 if (tmp) {
641                         model = tmp;
642                         /* Skip "IBM," - see platforms/iseries/dt.c */
643                         if (firmware_has_feature(FW_FEATURE_ISERIES))
644                                 model += 4;
645                 }
646                 tmp = of_get_property(rootdn, "system-id", NULL);
647                 if (tmp) {
648                         system_id = tmp;
649                         /* Skip "IBM," - see platforms/iseries/dt.c */
650                         if (firmware_has_feature(FW_FEATURE_ISERIES))
651                                 system_id += 4;
652                 }
653                 lp_index_ptr = of_get_property(rootdn, "ibm,partition-no",
654                                         NULL);
655                 if (lp_index_ptr)
656                         lp_index = *lp_index_ptr;
657                 of_node_put(rootdn);
658         }
659         seq_printf(m, "serial_number=%s\n", system_id);
660         seq_printf(m, "system_type=%s\n", model);
661         seq_printf(m, "partition_id=%d\n", (int)lp_index);
662
663         if (firmware_has_feature(FW_FEATURE_ISERIES))
664                 return iseries_lparcfg_data(m, v);
665         return pseries_lparcfg_data(m, v);
666 }
667
668 static int lparcfg_open(struct inode *inode, struct file *file)
669 {
670         return single_open(file, lparcfg_data, NULL);
671 }
672
673 static const struct file_operations lparcfg_fops = {
674         .owner          = THIS_MODULE,
675         .read           = seq_read,
676         .write          = lparcfg_write,
677         .open           = lparcfg_open,
678         .release        = single_release,
679 };
680
681 static int __init lparcfg_init(void)
682 {
683         struct proc_dir_entry *ent;
684         mode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
685
686         /* Allow writing if we have FW_FEATURE_SPLPAR */
687         if (firmware_has_feature(FW_FEATURE_SPLPAR) &&
688                         !firmware_has_feature(FW_FEATURE_ISERIES))
689                 mode |= S_IWUSR;
690
691         ent = proc_create("ppc64/lparcfg", mode, NULL, &lparcfg_fops);
692         if (!ent) {
693                 printk(KERN_ERR "Failed to create ppc64/lparcfg\n");
694                 return -EIO;
695         }
696
697         proc_ppc64_lparcfg = ent;
698         return 0;
699 }
700
701 static void __exit lparcfg_cleanup(void)
702 {
703         if (proc_ppc64_lparcfg)
704                 remove_proc_entry("lparcfg", proc_ppc64_lparcfg->parent);
705 }
706
707 module_init(lparcfg_init);
708 module_exit(lparcfg_cleanup);
709 MODULE_DESCRIPTION("Interface for LPAR configuration data");
710 MODULE_AUTHOR("Dave Engebretsen");
711 MODULE_LICENSE("GPL");