Merge tag 'iommu-updates-v4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/joro...
[deliverable/linux.git] / arch / s390 / hypfs / hypfs_diag.c
CommitLineData
24bbb1fa 1/*
24bbb1fa
MH
2 * Hypervisor filesystem for Linux on s390. Diag 204 and 224
3 * implementation.
4 *
f55495ba 5 * Copyright IBM Corp. 2006, 2008
24bbb1fa
MH
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 */
8
f55495ba
MH
9#define KMSG_COMPONENT "hypfs"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
24bbb1fa
MH
12#include <linux/types.h>
13#include <linux/errno.h>
33b26d79 14#include <linux/slab.h>
24bbb1fa
MH
15#include <linux/string.h>
16#include <linux/vmalloc.h>
57b28f66 17#include <linux/mm.h>
1ec2772e 18#include <asm/diag.h>
24bbb1fa
MH
19#include <asm/ebcdic.h>
20#include "hypfs.h"
21
22#define LPAR_NAME_LEN 8 /* lpar name len in diag 204 data */
23#define CPU_NAME_LEN 16 /* type name len of cpus in diag224 name table */
24#define TMP_SIZE 64 /* size of temporary buffers */
25
57b28f66
MH
26#define DBFS_D204_HDR_VERSION 0
27
24bbb1fa
MH
28/* diag 204 subcodes */
29enum diag204_sc {
30 SUBC_STIB4 = 4,
31 SUBC_RSI = 5,
32 SUBC_STIB6 = 6,
33 SUBC_STIB7 = 7
34};
35
36/* The two available diag 204 data formats */
37enum diag204_format {
38 INFO_SIMPLE = 0,
39 INFO_EXT = 0x00010000
40};
41
42/* bit is set in flags, when physical cpu info is included in diag 204 data */
43#define LPAR_PHYS_FLG 0x80
44
45static char *diag224_cpu_names; /* diag 224 name table */
46static enum diag204_sc diag204_store_sc; /* used subcode for store */
47static enum diag204_format diag204_info_type; /* used diag 204 data format */
48
49static void *diag204_buf; /* 4K aligned buffer for diag204 data */
50static void *diag204_buf_vmalloc; /* vmalloc pointer for diag204 data */
51static int diag204_buf_pages; /* number of pages for diag204 data */
52
57b28f66
MH
53static struct dentry *dbfs_d204_file;
54
24bbb1fa
MH
55/*
56 * DIAG 204 data structures and member access functions.
57 *
58 * Since we have two different diag 204 data formats for old and new s390
59 * machines, we do not access the structs directly, but use getter functions for
60 * each struct member instead. This should make the code more readable.
61 */
62
63/* Time information block */
64
65struct info_blk_hdr {
66 __u8 npar;
67 __u8 flags;
68 __u16 tslice;
69 __u16 phys_cpus;
70 __u16 this_part;
71 __u64 curtod;
72} __attribute__ ((packed));
73
74struct x_info_blk_hdr {
75 __u8 npar;
76 __u8 flags;
77 __u16 tslice;
78 __u16 phys_cpus;
79 __u16 this_part;
80 __u64 curtod1;
81 __u64 curtod2;
82 char reserved[40];
83} __attribute__ ((packed));
84
85static inline int info_blk_hdr__size(enum diag204_format type)
86{
87 if (type == INFO_SIMPLE)
88 return sizeof(struct info_blk_hdr);
89 else /* INFO_EXT */
90 return sizeof(struct x_info_blk_hdr);
91}
92
93static inline __u8 info_blk_hdr__npar(enum diag204_format type, void *hdr)
94{
95 if (type == INFO_SIMPLE)
96 return ((struct info_blk_hdr *)hdr)->npar;
97 else /* INFO_EXT */
98 return ((struct x_info_blk_hdr *)hdr)->npar;
99}
100
101static inline __u8 info_blk_hdr__flags(enum diag204_format type, void *hdr)
102{
103 if (type == INFO_SIMPLE)
104 return ((struct info_blk_hdr *)hdr)->flags;
105 else /* INFO_EXT */
106 return ((struct x_info_blk_hdr *)hdr)->flags;
107}
108
109static inline __u16 info_blk_hdr__pcpus(enum diag204_format type, void *hdr)
110{
111 if (type == INFO_SIMPLE)
112 return ((struct info_blk_hdr *)hdr)->phys_cpus;
113 else /* INFO_EXT */
114 return ((struct x_info_blk_hdr *)hdr)->phys_cpus;
115}
116
117/* Partition header */
118
119struct part_hdr {
120 __u8 pn;
121 __u8 cpus;
122 char reserved[6];
123 char part_name[LPAR_NAME_LEN];
124} __attribute__ ((packed));
125
126struct x_part_hdr {
127 __u8 pn;
128 __u8 cpus;
129 __u8 rcpus;
130 __u8 pflag;
131 __u32 mlu;
132 char part_name[LPAR_NAME_LEN];
133 char lpc_name[8];
134 char os_name[8];
135 __u64 online_cs;
136 __u64 online_es;
137 __u8 upid;
138 char reserved1[3];
139 __u32 group_mlu;
140 char group_name[8];
141 char reserved2[32];
142} __attribute__ ((packed));
143
144static inline int part_hdr__size(enum diag204_format type)
145{
146 if (type == INFO_SIMPLE)
147 return sizeof(struct part_hdr);
148 else /* INFO_EXT */
149 return sizeof(struct x_part_hdr);
150}
151
152static inline __u8 part_hdr__rcpus(enum diag204_format type, void *hdr)
153{
154 if (type == INFO_SIMPLE)
155 return ((struct part_hdr *)hdr)->cpus;
156 else /* INFO_EXT */
157 return ((struct x_part_hdr *)hdr)->rcpus;
158}
159
160static inline void part_hdr__part_name(enum diag204_format type, void *hdr,
161 char *name)
162{
163 if (type == INFO_SIMPLE)
164 memcpy(name, ((struct part_hdr *)hdr)->part_name,
165 LPAR_NAME_LEN);
166 else /* INFO_EXT */
167 memcpy(name, ((struct x_part_hdr *)hdr)->part_name,
168 LPAR_NAME_LEN);
169 EBCASC(name, LPAR_NAME_LEN);
170 name[LPAR_NAME_LEN] = 0;
1d802e24 171 strim(name);
24bbb1fa
MH
172}
173
174struct cpu_info {
175 __u16 cpu_addr;
176 char reserved1[2];
177 __u8 ctidx;
178 __u8 cflag;
179 __u16 weight;
180 __u64 acc_time;
181 __u64 lp_time;
182} __attribute__ ((packed));
183
184struct x_cpu_info {
185 __u16 cpu_addr;
186 char reserved1[2];
187 __u8 ctidx;
188 __u8 cflag;
189 __u16 weight;
190 __u64 acc_time;
191 __u64 lp_time;
192 __u16 min_weight;
193 __u16 cur_weight;
194 __u16 max_weight;
195 char reseved2[2];
196 __u64 online_time;
197 __u64 wait_time;
198 __u32 pma_weight;
199 __u32 polar_weight;
200 char reserved3[40];
201} __attribute__ ((packed));
202
203/* CPU info block */
204
205static inline int cpu_info__size(enum diag204_format type)
206{
207 if (type == INFO_SIMPLE)
208 return sizeof(struct cpu_info);
209 else /* INFO_EXT */
210 return sizeof(struct x_cpu_info);
211}
212
213static inline __u8 cpu_info__ctidx(enum diag204_format type, void *hdr)
214{
215 if (type == INFO_SIMPLE)
216 return ((struct cpu_info *)hdr)->ctidx;
217 else /* INFO_EXT */
218 return ((struct x_cpu_info *)hdr)->ctidx;
219}
220
221static inline __u16 cpu_info__cpu_addr(enum diag204_format type, void *hdr)
222{
223 if (type == INFO_SIMPLE)
224 return ((struct cpu_info *)hdr)->cpu_addr;
225 else /* INFO_EXT */
226 return ((struct x_cpu_info *)hdr)->cpu_addr;
227}
228
229static inline __u64 cpu_info__acc_time(enum diag204_format type, void *hdr)
230{
231 if (type == INFO_SIMPLE)
232 return ((struct cpu_info *)hdr)->acc_time;
233 else /* INFO_EXT */
234 return ((struct x_cpu_info *)hdr)->acc_time;
235}
236
237static inline __u64 cpu_info__lp_time(enum diag204_format type, void *hdr)
238{
239 if (type == INFO_SIMPLE)
240 return ((struct cpu_info *)hdr)->lp_time;
241 else /* INFO_EXT */
242 return ((struct x_cpu_info *)hdr)->lp_time;
243}
244
245static inline __u64 cpu_info__online_time(enum diag204_format type, void *hdr)
246{
247 if (type == INFO_SIMPLE)
248 return 0; /* online_time not available in simple info */
249 else /* INFO_EXT */
250 return ((struct x_cpu_info *)hdr)->online_time;
251}
252
253/* Physical header */
254
255struct phys_hdr {
256 char reserved1[1];
257 __u8 cpus;
258 char reserved2[6];
259 char mgm_name[8];
260} __attribute__ ((packed));
261
262struct x_phys_hdr {
263 char reserved1[1];
264 __u8 cpus;
265 char reserved2[6];
266 char mgm_name[8];
267 char reserved3[80];
268} __attribute__ ((packed));
269
270static inline int phys_hdr__size(enum diag204_format type)
271{
272 if (type == INFO_SIMPLE)
273 return sizeof(struct phys_hdr);
274 else /* INFO_EXT */
275 return sizeof(struct x_phys_hdr);
276}
277
278static inline __u8 phys_hdr__cpus(enum diag204_format type, void *hdr)
279{
280 if (type == INFO_SIMPLE)
281 return ((struct phys_hdr *)hdr)->cpus;
282 else /* INFO_EXT */
283 return ((struct x_phys_hdr *)hdr)->cpus;
284}
285
286/* Physical CPU info block */
287
288struct phys_cpu {
289 __u16 cpu_addr;
290 char reserved1[2];
291 __u8 ctidx;
292 char reserved2[3];
293 __u64 mgm_time;
294 char reserved3[8];
295} __attribute__ ((packed));
296
297struct x_phys_cpu {
298 __u16 cpu_addr;
299 char reserved1[2];
300 __u8 ctidx;
301 char reserved2[3];
302 __u64 mgm_time;
303 char reserved3[80];
304} __attribute__ ((packed));
305
306static inline int phys_cpu__size(enum diag204_format type)
307{
308 if (type == INFO_SIMPLE)
309 return sizeof(struct phys_cpu);
310 else /* INFO_EXT */
311 return sizeof(struct x_phys_cpu);
312}
313
314static inline __u16 phys_cpu__cpu_addr(enum diag204_format type, void *hdr)
315{
316 if (type == INFO_SIMPLE)
317 return ((struct phys_cpu *)hdr)->cpu_addr;
318 else /* INFO_EXT */
319 return ((struct x_phys_cpu *)hdr)->cpu_addr;
320}
321
322static inline __u64 phys_cpu__mgm_time(enum diag204_format type, void *hdr)
323{
324 if (type == INFO_SIMPLE)
325 return ((struct phys_cpu *)hdr)->mgm_time;
326 else /* INFO_EXT */
327 return ((struct x_phys_cpu *)hdr)->mgm_time;
328}
329
330static inline __u64 phys_cpu__ctidx(enum diag204_format type, void *hdr)
331{
332 if (type == INFO_SIMPLE)
333 return ((struct phys_cpu *)hdr)->ctidx;
334 else /* INFO_EXT */
335 return ((struct x_phys_cpu *)hdr)->ctidx;
336}
337
338/* Diagnose 204 functions */
339
e030c112 340static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
24bbb1fa 341{
e030c112 342 register unsigned long _subcode asm("0") = *subcode;
24bbb1fa
MH
343 register unsigned long _size asm("1") = size;
344
94c12cc7
MS
345 asm volatile(
346 " diag %2,%0,0x204\n"
6c22c986 347 "0: nopr %%r7\n"
94c12cc7
MS
348 EX_TABLE(0b,0b)
349 : "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
e030c112 350 *subcode = _subcode;
94c12cc7 351 return _size;
24bbb1fa
MH
352}
353
1ec2772e
MS
354static int diag204(unsigned long subcode, unsigned long size, void *addr)
355{
356 diag_stat_inc(DIAG_STAT_X204);
e030c112
HC
357 size = __diag204(&subcode, size, addr);
358 if (subcode)
359 return -1;
360 return size;
1ec2772e
MS
361}
362
24bbb1fa
MH
363/*
364 * For the old diag subcode 4 with simple data format we have to use real
365 * memory. If we use subcode 6 or 7 with extended data format, we can (and
366 * should) use vmalloc, since we need a lot of memory in that case. Currently
367 * up to 93 pages!
368 */
369
370static void diag204_free_buffer(void)
371{
372 if (!diag204_buf)
373 return;
374 if (diag204_buf_vmalloc) {
375 vfree(diag204_buf_vmalloc);
376 diag204_buf_vmalloc = NULL;
377 } else {
378 free_pages((unsigned long) diag204_buf, 0);
379 }
24bbb1fa
MH
380 diag204_buf = NULL;
381}
382
57b28f66
MH
383static void *page_align_ptr(void *ptr)
384{
385 return (void *) PAGE_ALIGN((unsigned long) ptr);
386}
387
24bbb1fa
MH
388static void *diag204_alloc_vbuf(int pages)
389{
390 /* The buffer has to be page aligned! */
391 diag204_buf_vmalloc = vmalloc(PAGE_SIZE * (pages + 1));
392 if (!diag204_buf_vmalloc)
393 return ERR_PTR(-ENOMEM);
57b28f66 394 diag204_buf = page_align_ptr(diag204_buf_vmalloc);
24bbb1fa
MH
395 diag204_buf_pages = pages;
396 return diag204_buf;
397}
398
399static void *diag204_alloc_rbuf(void)
400{
401 diag204_buf = (void*)__get_free_pages(GFP_KERNEL,0);
86b22470 402 if (!diag204_buf)
24bbb1fa
MH
403 return ERR_PTR(-ENOMEM);
404 diag204_buf_pages = 1;
405 return diag204_buf;
406}
407
408static void *diag204_get_buffer(enum diag204_format fmt, int *pages)
409{
410 if (diag204_buf) {
411 *pages = diag204_buf_pages;
412 return diag204_buf;
413 }
414 if (fmt == INFO_SIMPLE) {
415 *pages = 1;
416 return diag204_alloc_rbuf();
417 } else {/* INFO_EXT */
23c100d9
MH
418 *pages = diag204((unsigned long)SUBC_RSI |
419 (unsigned long)INFO_EXT, 0, NULL);
24bbb1fa
MH
420 if (*pages <= 0)
421 return ERR_PTR(-ENOSYS);
422 else
423 return diag204_alloc_vbuf(*pages);
424 }
425}
426
427/*
428 * diag204_probe() has to find out, which type of diagnose 204 implementation
429 * we have on our machine. Currently there are three possible scanarios:
430 * - subcode 4 + simple data format (only one page)
431 * - subcode 4-6 + extended data format
432 * - subcode 4-7 + extended data format
433 *
434 * Subcode 5 is used to retrieve the size of the data, provided by subcodes
435 * 6 and 7. Subcode 7 basically has the same function as subcode 6. In addition
436 * to subcode 6 it provides also information about secondary cpus.
437 * In order to get as much information as possible, we first try
438 * subcode 7, then 6 and if both fail, we use subcode 4.
439 */
440
441static int diag204_probe(void)
442{
443 void *buf;
444 int pages, rc;
445
446 buf = diag204_get_buffer(INFO_EXT, &pages);
447 if (!IS_ERR(buf)) {
331c982d
MH
448 if (diag204((unsigned long)SUBC_STIB7 |
449 (unsigned long)INFO_EXT, pages, buf) >= 0) {
24bbb1fa
MH
450 diag204_store_sc = SUBC_STIB7;
451 diag204_info_type = INFO_EXT;
452 goto out;
453 }
331c982d
MH
454 if (diag204((unsigned long)SUBC_STIB6 |
455 (unsigned long)INFO_EXT, pages, buf) >= 0) {
7874b1b6 456 diag204_store_sc = SUBC_STIB6;
24bbb1fa
MH
457 diag204_info_type = INFO_EXT;
458 goto out;
459 }
460 diag204_free_buffer();
461 }
462
463 /* subcodes 6 and 7 failed, now try subcode 4 */
464
465 buf = diag204_get_buffer(INFO_SIMPLE, &pages);
466 if (IS_ERR(buf)) {
467 rc = PTR_ERR(buf);
468 goto fail_alloc;
469 }
331c982d
MH
470 if (diag204((unsigned long)SUBC_STIB4 |
471 (unsigned long)INFO_SIMPLE, pages, buf) >= 0) {
24bbb1fa
MH
472 diag204_store_sc = SUBC_STIB4;
473 diag204_info_type = INFO_SIMPLE;
474 goto out;
475 } else {
476 rc = -ENOSYS;
477 goto fail_store;
478 }
479out:
480 rc = 0;
481fail_store:
482 diag204_free_buffer();
483fail_alloc:
484 return rc;
485}
486
57b28f66
MH
487static int diag204_do_store(void *buf, int pages)
488{
489 int rc;
490
491 rc = diag204((unsigned long) diag204_store_sc |
492 (unsigned long) diag204_info_type, pages, buf);
493 return rc < 0 ? -ENOSYS : 0;
494}
495
24bbb1fa
MH
496static void *diag204_store(void)
497{
498 void *buf;
57b28f66 499 int pages, rc;
24bbb1fa
MH
500
501 buf = diag204_get_buffer(diag204_info_type, &pages);
502 if (IS_ERR(buf))
503 goto out;
57b28f66
MH
504 rc = diag204_do_store(buf, pages);
505 if (rc)
506 return ERR_PTR(rc);
24bbb1fa
MH
507out:
508 return buf;
509}
510
511/* Diagnose 224 functions */
512
c41d4e3e 513static int diag224(void *ptr)
24bbb1fa 514{
b8e660b8 515 int rc = -EOPNOTSUPP;
c41d4e3e 516
1ec2772e 517 diag_stat_inc(DIAG_STAT_X224);
c41d4e3e
MH
518 asm volatile(
519 " diag %1,%2,0x224\n"
520 "0: lhi %0,0x0\n"
521 "1:\n"
522 EX_TABLE(0b,1b)
523 : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
524 return rc;
24bbb1fa
MH
525}
526
527static int diag224_get_name_table(void)
528{
529 /* memory must be below 2GB */
530 diag224_cpu_names = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
531 if (!diag224_cpu_names)
532 return -ENOMEM;
c41d4e3e
MH
533 if (diag224(diag224_cpu_names)) {
534 kfree(diag224_cpu_names);
b8e660b8 535 return -EOPNOTSUPP;
c41d4e3e 536 }
24bbb1fa
MH
537 EBCASC(diag224_cpu_names + 16, (*diag224_cpu_names + 1) * 16);
538 return 0;
539}
540
541static void diag224_delete_name_table(void)
542{
543 kfree(diag224_cpu_names);
544}
545
546static int diag224_idx2name(int index, char *name)
547{
548 memcpy(name, diag224_cpu_names + ((index + 1) * CPU_NAME_LEN),
549 CPU_NAME_LEN);
550 name[CPU_NAME_LEN] = 0;
1d802e24 551 strim(name);
24bbb1fa
MH
552 return 0;
553}
554
57b28f66
MH
555struct dbfs_d204_hdr {
556 u64 len; /* Length of d204 buffer without header */
557 u16 version; /* Version of header */
558 u8 sc; /* Used subcode */
559 char reserved[53];
560} __attribute__ ((packed));
561
562struct dbfs_d204 {
563 struct dbfs_d204_hdr hdr; /* 64 byte header */
564 char buf[]; /* d204 buffer */
565} __attribute__ ((packed));
566
2fcb3686 567static int dbfs_d204_create(void **data, void **data_free_ptr, size_t *size)
57b28f66 568{
57b28f66
MH
569 struct dbfs_d204 *d204;
570 int rc, buf_size;
2fcb3686 571 void *base;
57b28f66 572
57b28f66 573 buf_size = PAGE_SIZE * (diag204_buf_pages + 1) + sizeof(d204->hdr);
dc8a5c99 574 base = vzalloc(buf_size);
2fcb3686
MH
575 if (!base)
576 return -ENOMEM;
2fcb3686
MH
577 d204 = page_align_ptr(base + sizeof(d204->hdr)) - sizeof(d204->hdr);
578 rc = diag204_do_store(d204->buf, diag204_buf_pages);
579 if (rc) {
580 vfree(base);
581 return rc;
57b28f66 582 }
57b28f66
MH
583 d204->hdr.version = DBFS_D204_HDR_VERSION;
584 d204->hdr.len = PAGE_SIZE * diag204_buf_pages;
585 d204->hdr.sc = diag204_store_sc;
2fcb3686
MH
586 *data = d204;
587 *data_free_ptr = base;
588 *size = d204->hdr.len + sizeof(struct dbfs_d204_hdr);
57b28f66
MH
589 return 0;
590}
591
2fcb3686
MH
592static struct hypfs_dbfs_file dbfs_file_d204 = {
593 .name = "diag_204",
594 .data_create = dbfs_d204_create,
595 .data_free = vfree,
57b28f66
MH
596};
597
24bbb1fa
MH
598__init int hypfs_diag_init(void)
599{
600 int rc;
601
602 if (diag204_probe()) {
f55495ba 603 pr_err("The hardware system does not support hypfs\n");
24bbb1fa
MH
604 return -ENODATA;
605 }
57b28f66 606 if (diag204_info_type == INFO_EXT) {
2fcb3686 607 rc = hypfs_dbfs_create_file(&dbfs_file_d204);
57b28f66 608 if (rc)
3c8ebca0 609 return rc;
57b28f66 610 }
3c8ebca0
MH
611 if (MACHINE_IS_LPAR) {
612 rc = diag224_get_name_table();
613 if (rc) {
614 pr_err("The hardware system does not provide all "
615 "functions required by hypfs\n");
616 debugfs_remove(dbfs_d204_file);
617 return rc;
618 }
619 }
620 return 0;
24bbb1fa
MH
621}
622
1375fc1f 623void hypfs_diag_exit(void)
24bbb1fa 624{
57b28f66 625 debugfs_remove(dbfs_d204_file);
24bbb1fa
MH
626 diag224_delete_name_table();
627 diag204_free_buffer();
2fcb3686 628 hypfs_dbfs_remove_file(&dbfs_file_d204);
24bbb1fa
MH
629}
630
631/*
632 * Functions to create the directory structure
633 * *******************************************
634 */
635
e334cf4f 636static int hypfs_create_cpu_files(struct dentry *cpus_dir, void *cpu_info)
24bbb1fa
MH
637{
638 struct dentry *cpu_dir;
639 char buffer[TMP_SIZE];
640 void *rc;
641
642 snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_info_type,
643 cpu_info));
a118cfdf
AV
644 cpu_dir = hypfs_mkdir(cpus_dir, buffer);
645 rc = hypfs_create_u64(cpu_dir, "mgmtime",
24bbb1fa
MH
646 cpu_info__acc_time(diag204_info_type, cpu_info) -
647 cpu_info__lp_time(diag204_info_type, cpu_info));
648 if (IS_ERR(rc))
649 return PTR_ERR(rc);
a118cfdf 650 rc = hypfs_create_u64(cpu_dir, "cputime",
24bbb1fa
MH
651 cpu_info__lp_time(diag204_info_type, cpu_info));
652 if (IS_ERR(rc))
653 return PTR_ERR(rc);
654 if (diag204_info_type == INFO_EXT) {
a118cfdf 655 rc = hypfs_create_u64(cpu_dir, "onlinetime",
24bbb1fa
MH
656 cpu_info__online_time(diag204_info_type,
657 cpu_info));
658 if (IS_ERR(rc))
659 return PTR_ERR(rc);
660 }
661 diag224_idx2name(cpu_info__ctidx(diag204_info_type, cpu_info), buffer);
a118cfdf 662 rc = hypfs_create_str(cpu_dir, "type", buffer);
5eba9bb8 663 return PTR_RET(rc);
24bbb1fa
MH
664}
665
e334cf4f 666static void *hypfs_create_lpar_files(struct dentry *systems_dir, void *part_hdr)
24bbb1fa
MH
667{
668 struct dentry *cpus_dir;
669 struct dentry *lpar_dir;
670 char lpar_name[LPAR_NAME_LEN + 1];
671 void *cpu_info;
672 int i;
673
674 part_hdr__part_name(diag204_info_type, part_hdr, lpar_name);
675 lpar_name[LPAR_NAME_LEN] = 0;
a118cfdf 676 lpar_dir = hypfs_mkdir(systems_dir, lpar_name);
24bbb1fa
MH
677 if (IS_ERR(lpar_dir))
678 return lpar_dir;
a118cfdf 679 cpus_dir = hypfs_mkdir(lpar_dir, "cpus");
24bbb1fa
MH
680 if (IS_ERR(cpus_dir))
681 return cpus_dir;
682 cpu_info = part_hdr + part_hdr__size(diag204_info_type);
683 for (i = 0; i < part_hdr__rcpus(diag204_info_type, part_hdr); i++) {
684 int rc;
e334cf4f 685 rc = hypfs_create_cpu_files(cpus_dir, cpu_info);
24bbb1fa
MH
686 if (rc)
687 return ERR_PTR(rc);
688 cpu_info += cpu_info__size(diag204_info_type);
689 }
690 return cpu_info;
691}
692
e334cf4f 693static int hypfs_create_phys_cpu_files(struct dentry *cpus_dir, void *cpu_info)
24bbb1fa
MH
694{
695 struct dentry *cpu_dir;
696 char buffer[TMP_SIZE];
697 void *rc;
698
699 snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_info_type,
700 cpu_info));
a118cfdf 701 cpu_dir = hypfs_mkdir(cpus_dir, buffer);
24bbb1fa
MH
702 if (IS_ERR(cpu_dir))
703 return PTR_ERR(cpu_dir);
a118cfdf 704 rc = hypfs_create_u64(cpu_dir, "mgmtime",
24bbb1fa
MH
705 phys_cpu__mgm_time(diag204_info_type, cpu_info));
706 if (IS_ERR(rc))
707 return PTR_ERR(rc);
708 diag224_idx2name(phys_cpu__ctidx(diag204_info_type, cpu_info), buffer);
a118cfdf 709 rc = hypfs_create_str(cpu_dir, "type", buffer);
5eba9bb8 710 return PTR_RET(rc);
24bbb1fa
MH
711}
712
e334cf4f 713static void *hypfs_create_phys_files(struct dentry *parent_dir, void *phys_hdr)
24bbb1fa
MH
714{
715 int i;
716 void *cpu_info;
717 struct dentry *cpus_dir;
718
a118cfdf 719 cpus_dir = hypfs_mkdir(parent_dir, "cpus");
24bbb1fa
MH
720 if (IS_ERR(cpus_dir))
721 return cpus_dir;
722 cpu_info = phys_hdr + phys_hdr__size(diag204_info_type);
723 for (i = 0; i < phys_hdr__cpus(diag204_info_type, phys_hdr); i++) {
724 int rc;
e334cf4f 725 rc = hypfs_create_phys_cpu_files(cpus_dir, cpu_info);
24bbb1fa
MH
726 if (rc)
727 return ERR_PTR(rc);
728 cpu_info += phys_cpu__size(diag204_info_type);
729 }
730 return cpu_info;
731}
732
e334cf4f 733int hypfs_diag_create_files(struct dentry *root)
24bbb1fa
MH
734{
735 struct dentry *systems_dir, *hyp_dir;
736 void *time_hdr, *part_hdr;
737 int i, rc;
738 void *buffer, *ptr;
739
740 buffer = diag204_store();
741 if (IS_ERR(buffer))
742 return PTR_ERR(buffer);
743
a118cfdf 744 systems_dir = hypfs_mkdir(root, "systems");
24bbb1fa
MH
745 if (IS_ERR(systems_dir)) {
746 rc = PTR_ERR(systems_dir);
747 goto err_out;
748 }
749 time_hdr = (struct x_info_blk_hdr *)buffer;
750 part_hdr = time_hdr + info_blk_hdr__size(diag204_info_type);
751 for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr); i++) {
e334cf4f 752 part_hdr = hypfs_create_lpar_files(systems_dir, part_hdr);
24bbb1fa
MH
753 if (IS_ERR(part_hdr)) {
754 rc = PTR_ERR(part_hdr);
755 goto err_out;
756 }
757 }
758 if (info_blk_hdr__flags(diag204_info_type, time_hdr) & LPAR_PHYS_FLG) {
e334cf4f 759 ptr = hypfs_create_phys_files(root, part_hdr);
24bbb1fa
MH
760 if (IS_ERR(ptr)) {
761 rc = PTR_ERR(ptr);
762 goto err_out;
763 }
764 }
a118cfdf 765 hyp_dir = hypfs_mkdir(root, "hyp");
24bbb1fa
MH
766 if (IS_ERR(hyp_dir)) {
767 rc = PTR_ERR(hyp_dir);
768 goto err_out;
769 }
a118cfdf 770 ptr = hypfs_create_str(hyp_dir, "type", "LPAR Hypervisor");
24bbb1fa
MH
771 if (IS_ERR(ptr)) {
772 rc = PTR_ERR(ptr);
773 goto err_out;
774 }
775 rc = 0;
776
777err_out:
778 return rc;
779}
This page took 0.731316 seconds and 5 git commands to generate.