hypfs_diag.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * arch/s390/hypfs/hypfs_diag.c
  3. * Hypervisor filesystem for Linux on s390. Diag 204 and 224
  4. * implementation.
  5. *
  6. * Copyright (C) IBM Corp. 2006
  7. * Author(s): Michael Holzheu <holzheu@de.ibm.com>
  8. */
  9. #include <linux/types.h>
  10. #include <linux/errno.h>
  11. #include <linux/string.h>
  12. #include <linux/vmalloc.h>
  13. #include <asm/ebcdic.h>
  14. #include "hypfs.h"
  15. #define LPAR_NAME_LEN 8 /* lpar name len in diag 204 data */
  16. #define CPU_NAME_LEN 16 /* type name len of cpus in diag224 name table */
  17. #define TMP_SIZE 64 /* size of temporary buffers */
  18. /* diag 204 subcodes */
  19. enum diag204_sc {
  20. SUBC_STIB4 = 4,
  21. SUBC_RSI = 5,
  22. SUBC_STIB6 = 6,
  23. SUBC_STIB7 = 7
  24. };
  25. /* The two available diag 204 data formats */
  26. enum diag204_format {
  27. INFO_SIMPLE = 0,
  28. INFO_EXT = 0x00010000
  29. };
  30. /* bit is set in flags, when physical cpu info is included in diag 204 data */
  31. #define LPAR_PHYS_FLG 0x80
  32. static char *diag224_cpu_names; /* diag 224 name table */
  33. static enum diag204_sc diag204_store_sc; /* used subcode for store */
  34. static enum diag204_format diag204_info_type; /* used diag 204 data format */
  35. static void *diag204_buf; /* 4K aligned buffer for diag204 data */
  36. static void *diag204_buf_vmalloc; /* vmalloc pointer for diag204 data */
  37. static int diag204_buf_pages; /* number of pages for diag204 data */
  38. /*
  39. * DIAG 204 data structures and member access functions.
  40. *
  41. * Since we have two different diag 204 data formats for old and new s390
  42. * machines, we do not access the structs directly, but use getter functions for
  43. * each struct member instead. This should make the code more readable.
  44. */
  45. /* Time information block */
  46. struct info_blk_hdr {
  47. __u8 npar;
  48. __u8 flags;
  49. __u16 tslice;
  50. __u16 phys_cpus;
  51. __u16 this_part;
  52. __u64 curtod;
  53. } __attribute__ ((packed));
  54. struct x_info_blk_hdr {
  55. __u8 npar;
  56. __u8 flags;
  57. __u16 tslice;
  58. __u16 phys_cpus;
  59. __u16 this_part;
  60. __u64 curtod1;
  61. __u64 curtod2;
  62. char reserved[40];
  63. } __attribute__ ((packed));
  64. static inline int info_blk_hdr__size(enum diag204_format type)
  65. {
  66. if (type == INFO_SIMPLE)
  67. return sizeof(struct info_blk_hdr);
  68. else /* INFO_EXT */
  69. return sizeof(struct x_info_blk_hdr);
  70. }
  71. static inline __u8 info_blk_hdr__npar(enum diag204_format type, void *hdr)
  72. {
  73. if (type == INFO_SIMPLE)
  74. return ((struct info_blk_hdr *)hdr)->npar;
  75. else /* INFO_EXT */
  76. return ((struct x_info_blk_hdr *)hdr)->npar;
  77. }
  78. static inline __u8 info_blk_hdr__flags(enum diag204_format type, void *hdr)
  79. {
  80. if (type == INFO_SIMPLE)
  81. return ((struct info_blk_hdr *)hdr)->flags;
  82. else /* INFO_EXT */
  83. return ((struct x_info_blk_hdr *)hdr)->flags;
  84. }
  85. static inline __u16 info_blk_hdr__pcpus(enum diag204_format type, void *hdr)
  86. {
  87. if (type == INFO_SIMPLE)
  88. return ((struct info_blk_hdr *)hdr)->phys_cpus;
  89. else /* INFO_EXT */
  90. return ((struct x_info_blk_hdr *)hdr)->phys_cpus;
  91. }
  92. /* Partition header */
  93. struct part_hdr {
  94. __u8 pn;
  95. __u8 cpus;
  96. char reserved[6];
  97. char part_name[LPAR_NAME_LEN];
  98. } __attribute__ ((packed));
  99. struct x_part_hdr {
  100. __u8 pn;
  101. __u8 cpus;
  102. __u8 rcpus;
  103. __u8 pflag;
  104. __u32 mlu;
  105. char part_name[LPAR_NAME_LEN];
  106. char lpc_name[8];
  107. char os_name[8];
  108. __u64 online_cs;
  109. __u64 online_es;
  110. __u8 upid;
  111. char reserved1[3];
  112. __u32 group_mlu;
  113. char group_name[8];
  114. char reserved2[32];
  115. } __attribute__ ((packed));
  116. static inline int part_hdr__size(enum diag204_format type)
  117. {
  118. if (type == INFO_SIMPLE)
  119. return sizeof(struct part_hdr);
  120. else /* INFO_EXT */
  121. return sizeof(struct x_part_hdr);
  122. }
  123. static inline __u8 part_hdr__rcpus(enum diag204_format type, void *hdr)
  124. {
  125. if (type == INFO_SIMPLE)
  126. return ((struct part_hdr *)hdr)->cpus;
  127. else /* INFO_EXT */
  128. return ((struct x_part_hdr *)hdr)->rcpus;
  129. }
  130. static inline void part_hdr__part_name(enum diag204_format type, void *hdr,
  131. char *name)
  132. {
  133. if (type == INFO_SIMPLE)
  134. memcpy(name, ((struct part_hdr *)hdr)->part_name,
  135. LPAR_NAME_LEN);
  136. else /* INFO_EXT */
  137. memcpy(name, ((struct x_part_hdr *)hdr)->part_name,
  138. LPAR_NAME_LEN);
  139. EBCASC(name, LPAR_NAME_LEN);
  140. name[LPAR_NAME_LEN] = 0;
  141. strstrip(name);
  142. }
  143. struct cpu_info {
  144. __u16 cpu_addr;
  145. char reserved1[2];
  146. __u8 ctidx;
  147. __u8 cflag;
  148. __u16 weight;
  149. __u64 acc_time;
  150. __u64 lp_time;
  151. } __attribute__ ((packed));
  152. struct x_cpu_info {
  153. __u16 cpu_addr;
  154. char reserved1[2];
  155. __u8 ctidx;
  156. __u8 cflag;
  157. __u16 weight;
  158. __u64 acc_time;
  159. __u64 lp_time;
  160. __u16 min_weight;
  161. __u16 cur_weight;
  162. __u16 max_weight;
  163. char reseved2[2];
  164. __u64 online_time;
  165. __u64 wait_time;
  166. __u32 pma_weight;
  167. __u32 polar_weight;
  168. char reserved3[40];
  169. } __attribute__ ((packed));
  170. /* CPU info block */
  171. static inline int cpu_info__size(enum diag204_format type)
  172. {
  173. if (type == INFO_SIMPLE)
  174. return sizeof(struct cpu_info);
  175. else /* INFO_EXT */
  176. return sizeof(struct x_cpu_info);
  177. }
  178. static inline __u8 cpu_info__ctidx(enum diag204_format type, void *hdr)
  179. {
  180. if (type == INFO_SIMPLE)
  181. return ((struct cpu_info *)hdr)->ctidx;
  182. else /* INFO_EXT */
  183. return ((struct x_cpu_info *)hdr)->ctidx;
  184. }
  185. static inline __u16 cpu_info__cpu_addr(enum diag204_format type, void *hdr)
  186. {
  187. if (type == INFO_SIMPLE)
  188. return ((struct cpu_info *)hdr)->cpu_addr;
  189. else /* INFO_EXT */
  190. return ((struct x_cpu_info *)hdr)->cpu_addr;
  191. }
  192. static inline __u64 cpu_info__acc_time(enum diag204_format type, void *hdr)
  193. {
  194. if (type == INFO_SIMPLE)
  195. return ((struct cpu_info *)hdr)->acc_time;
  196. else /* INFO_EXT */
  197. return ((struct x_cpu_info *)hdr)->acc_time;
  198. }
  199. static inline __u64 cpu_info__lp_time(enum diag204_format type, void *hdr)
  200. {
  201. if (type == INFO_SIMPLE)
  202. return ((struct cpu_info *)hdr)->lp_time;
  203. else /* INFO_EXT */
  204. return ((struct x_cpu_info *)hdr)->lp_time;
  205. }
  206. static inline __u64 cpu_info__online_time(enum diag204_format type, void *hdr)
  207. {
  208. if (type == INFO_SIMPLE)
  209. return 0; /* online_time not available in simple info */
  210. else /* INFO_EXT */
  211. return ((struct x_cpu_info *)hdr)->online_time;
  212. }
  213. /* Physical header */
  214. struct phys_hdr {
  215. char reserved1[1];
  216. __u8 cpus;
  217. char reserved2[6];
  218. char mgm_name[8];
  219. } __attribute__ ((packed));
  220. struct x_phys_hdr {
  221. char reserved1[1];
  222. __u8 cpus;
  223. char reserved2[6];
  224. char mgm_name[8];
  225. char reserved3[80];
  226. } __attribute__ ((packed));
  227. static inline int phys_hdr__size(enum diag204_format type)
  228. {
  229. if (type == INFO_SIMPLE)
  230. return sizeof(struct phys_hdr);
  231. else /* INFO_EXT */
  232. return sizeof(struct x_phys_hdr);
  233. }
  234. static inline __u8 phys_hdr__cpus(enum diag204_format type, void *hdr)
  235. {
  236. if (type == INFO_SIMPLE)
  237. return ((struct phys_hdr *)hdr)->cpus;
  238. else /* INFO_EXT */
  239. return ((struct x_phys_hdr *)hdr)->cpus;
  240. }
  241. /* Physical CPU info block */
  242. struct phys_cpu {
  243. __u16 cpu_addr;
  244. char reserved1[2];
  245. __u8 ctidx;
  246. char reserved2[3];
  247. __u64 mgm_time;
  248. char reserved3[8];
  249. } __attribute__ ((packed));
  250. struct x_phys_cpu {
  251. __u16 cpu_addr;
  252. char reserved1[2];
  253. __u8 ctidx;
  254. char reserved2[3];
  255. __u64 mgm_time;
  256. char reserved3[80];
  257. } __attribute__ ((packed));
  258. static inline int phys_cpu__size(enum diag204_format type)
  259. {
  260. if (type == INFO_SIMPLE)
  261. return sizeof(struct phys_cpu);
  262. else /* INFO_EXT */
  263. return sizeof(struct x_phys_cpu);
  264. }
  265. static inline __u16 phys_cpu__cpu_addr(enum diag204_format type, void *hdr)
  266. {
  267. if (type == INFO_SIMPLE)
  268. return ((struct phys_cpu *)hdr)->cpu_addr;
  269. else /* INFO_EXT */
  270. return ((struct x_phys_cpu *)hdr)->cpu_addr;
  271. }
  272. static inline __u64 phys_cpu__mgm_time(enum diag204_format type, void *hdr)
  273. {
  274. if (type == INFO_SIMPLE)
  275. return ((struct phys_cpu *)hdr)->mgm_time;
  276. else /* INFO_EXT */
  277. return ((struct x_phys_cpu *)hdr)->mgm_time;
  278. }
  279. static inline __u64 phys_cpu__ctidx(enum diag204_format type, void *hdr)
  280. {
  281. if (type == INFO_SIMPLE)
  282. return ((struct phys_cpu *)hdr)->ctidx;
  283. else /* INFO_EXT */
  284. return ((struct x_phys_cpu *)hdr)->ctidx;
  285. }
  286. /* Diagnose 204 functions */
  287. static int diag204(unsigned long subcode, unsigned long size, void *addr)
  288. {
  289. register unsigned long _subcode asm("0") = subcode;
  290. register unsigned long _size asm("1") = size;
  291. asm volatile(
  292. " diag %2,%0,0x204\n"
  293. "0:\n"
  294. EX_TABLE(0b,0b)
  295. : "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
  296. if (_subcode)
  297. return -1;
  298. return _size;
  299. }
  300. /*
  301. * For the old diag subcode 4 with simple data format we have to use real
  302. * memory. If we use subcode 6 or 7 with extended data format, we can (and
  303. * should) use vmalloc, since we need a lot of memory in that case. Currently
  304. * up to 93 pages!
  305. */
  306. static void diag204_free_buffer(void)
  307. {
  308. if (!diag204_buf)
  309. return;
  310. if (diag204_buf_vmalloc) {
  311. vfree(diag204_buf_vmalloc);
  312. diag204_buf_vmalloc = NULL;
  313. } else {
  314. free_pages((unsigned long) diag204_buf, 0);
  315. }
  316. diag204_buf_pages = 0;
  317. diag204_buf = NULL;
  318. }
  319. static void *diag204_alloc_vbuf(int pages)
  320. {
  321. /* The buffer has to be page aligned! */
  322. diag204_buf_vmalloc = vmalloc(PAGE_SIZE * (pages + 1));
  323. if (!diag204_buf_vmalloc)
  324. return ERR_PTR(-ENOMEM);
  325. diag204_buf = (void*)((unsigned long)diag204_buf_vmalloc
  326. & ~0xfffUL) + 0x1000;
  327. diag204_buf_pages = pages;
  328. return diag204_buf;
  329. }
  330. static void *diag204_alloc_rbuf(void)
  331. {
  332. diag204_buf = (void*)__get_free_pages(GFP_KERNEL,0);
  333. if (!diag204_buf)
  334. return ERR_PTR(-ENOMEM);
  335. diag204_buf_pages = 1;
  336. return diag204_buf;
  337. }
  338. static void *diag204_get_buffer(enum diag204_format fmt, int *pages)
  339. {
  340. if (diag204_buf) {
  341. *pages = diag204_buf_pages;
  342. return diag204_buf;
  343. }
  344. if (fmt == INFO_SIMPLE) {
  345. *pages = 1;
  346. return diag204_alloc_rbuf();
  347. } else {/* INFO_EXT */
  348. *pages = diag204((unsigned long)SUBC_RSI |
  349. (unsigned long)INFO_EXT, 0, NULL);
  350. if (*pages <= 0)
  351. return ERR_PTR(-ENOSYS);
  352. else
  353. return diag204_alloc_vbuf(*pages);
  354. }
  355. }
  356. /*
  357. * diag204_probe() has to find out, which type of diagnose 204 implementation
  358. * we have on our machine. Currently there are three possible scanarios:
  359. * - subcode 4 + simple data format (only one page)
  360. * - subcode 4-6 + extended data format
  361. * - subcode 4-7 + extended data format
  362. *
  363. * Subcode 5 is used to retrieve the size of the data, provided by subcodes
  364. * 6 and 7. Subcode 7 basically has the same function as subcode 6. In addition
  365. * to subcode 6 it provides also information about secondary cpus.
  366. * In order to get as much information as possible, we first try
  367. * subcode 7, then 6 and if both fail, we use subcode 4.
  368. */
  369. static int diag204_probe(void)
  370. {
  371. void *buf;
  372. int pages, rc;
  373. buf = diag204_get_buffer(INFO_EXT, &pages);
  374. if (!IS_ERR(buf)) {
  375. if (diag204((unsigned long)SUBC_STIB7 |
  376. (unsigned long)INFO_EXT, pages, buf) >= 0) {
  377. diag204_store_sc = SUBC_STIB7;
  378. diag204_info_type = INFO_EXT;
  379. goto out;
  380. }
  381. if (diag204((unsigned long)SUBC_STIB6 |
  382. (unsigned long)INFO_EXT, pages, buf) >= 0) {
  383. diag204_store_sc = SUBC_STIB7;
  384. diag204_info_type = INFO_EXT;
  385. goto out;
  386. }
  387. diag204_free_buffer();
  388. }
  389. /* subcodes 6 and 7 failed, now try subcode 4 */
  390. buf = diag204_get_buffer(INFO_SIMPLE, &pages);
  391. if (IS_ERR(buf)) {
  392. rc = PTR_ERR(buf);
  393. goto fail_alloc;
  394. }
  395. if (diag204((unsigned long)SUBC_STIB4 |
  396. (unsigned long)INFO_SIMPLE, pages, buf) >= 0) {
  397. diag204_store_sc = SUBC_STIB4;
  398. diag204_info_type = INFO_SIMPLE;
  399. goto out;
  400. } else {
  401. rc = -ENOSYS;
  402. goto fail_store;
  403. }
  404. out:
  405. rc = 0;
  406. fail_store:
  407. diag204_free_buffer();
  408. fail_alloc:
  409. return rc;
  410. }
  411. static void *diag204_store(void)
  412. {
  413. void *buf;
  414. int pages;
  415. buf = diag204_get_buffer(diag204_info_type, &pages);
  416. if (IS_ERR(buf))
  417. goto out;
  418. if (diag204((unsigned long)diag204_store_sc |
  419. (unsigned long)diag204_info_type, pages, buf) < 0)
  420. return ERR_PTR(-ENOSYS);
  421. out:
  422. return buf;
  423. }
  424. /* Diagnose 224 functions */
  425. static void diag224(void *ptr)
  426. {
  427. asm volatile("diag %0,%1,0x224" : :"d" (0), "d"(ptr) : "memory");
  428. }
  429. static int diag224_get_name_table(void)
  430. {
  431. /* memory must be below 2GB */
  432. diag224_cpu_names = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
  433. if (!diag224_cpu_names)
  434. return -ENOMEM;
  435. diag224(diag224_cpu_names);
  436. EBCASC(diag224_cpu_names + 16, (*diag224_cpu_names + 1) * 16);
  437. return 0;
  438. }
  439. static void diag224_delete_name_table(void)
  440. {
  441. kfree(diag224_cpu_names);
  442. }
  443. static int diag224_idx2name(int index, char *name)
  444. {
  445. memcpy(name, diag224_cpu_names + ((index + 1) * CPU_NAME_LEN),
  446. CPU_NAME_LEN);
  447. name[CPU_NAME_LEN] = 0;
  448. strstrip(name);
  449. return 0;
  450. }
  451. __init int hypfs_diag_init(void)
  452. {
  453. int rc;
  454. if (diag204_probe()) {
  455. printk(KERN_ERR "hypfs: diag 204 not working.");
  456. return -ENODATA;
  457. }
  458. rc = diag224_get_name_table();
  459. if (rc) {
  460. diag204_free_buffer();
  461. printk(KERN_ERR "hypfs: could not get name table.\n");
  462. }
  463. return rc;
  464. }
  465. void hypfs_diag_exit(void)
  466. {
  467. diag224_delete_name_table();
  468. diag204_free_buffer();
  469. }
  470. /*
  471. * Functions to create the directory structure
  472. * *******************************************
  473. */
  474. static int hypfs_create_cpu_files(struct super_block *sb,
  475. struct dentry *cpus_dir, void *cpu_info)
  476. {
  477. struct dentry *cpu_dir;
  478. char buffer[TMP_SIZE];
  479. void *rc;
  480. snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_info_type,
  481. cpu_info));
  482. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  483. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  484. cpu_info__acc_time(diag204_info_type, cpu_info) -
  485. cpu_info__lp_time(diag204_info_type, cpu_info));
  486. if (IS_ERR(rc))
  487. return PTR_ERR(rc);
  488. rc = hypfs_create_u64(sb, cpu_dir, "cputime",
  489. cpu_info__lp_time(diag204_info_type, cpu_info));
  490. if (IS_ERR(rc))
  491. return PTR_ERR(rc);
  492. if (diag204_info_type == INFO_EXT) {
  493. rc = hypfs_create_u64(sb, cpu_dir, "onlinetime",
  494. cpu_info__online_time(diag204_info_type,
  495. cpu_info));
  496. if (IS_ERR(rc))
  497. return PTR_ERR(rc);
  498. }
  499. diag224_idx2name(cpu_info__ctidx(diag204_info_type, cpu_info), buffer);
  500. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  501. if (IS_ERR(rc))
  502. return PTR_ERR(rc);
  503. return 0;
  504. }
  505. static void *hypfs_create_lpar_files(struct super_block *sb,
  506. struct dentry *systems_dir, void *part_hdr)
  507. {
  508. struct dentry *cpus_dir;
  509. struct dentry *lpar_dir;
  510. char lpar_name[LPAR_NAME_LEN + 1];
  511. void *cpu_info;
  512. int i;
  513. part_hdr__part_name(diag204_info_type, part_hdr, lpar_name);
  514. lpar_name[LPAR_NAME_LEN] = 0;
  515. lpar_dir = hypfs_mkdir(sb, systems_dir, lpar_name);
  516. if (IS_ERR(lpar_dir))
  517. return lpar_dir;
  518. cpus_dir = hypfs_mkdir(sb, lpar_dir, "cpus");
  519. if (IS_ERR(cpus_dir))
  520. return cpus_dir;
  521. cpu_info = part_hdr + part_hdr__size(diag204_info_type);
  522. for (i = 0; i < part_hdr__rcpus(diag204_info_type, part_hdr); i++) {
  523. int rc;
  524. rc = hypfs_create_cpu_files(sb, cpus_dir, cpu_info);
  525. if (rc)
  526. return ERR_PTR(rc);
  527. cpu_info += cpu_info__size(diag204_info_type);
  528. }
  529. return cpu_info;
  530. }
  531. static int hypfs_create_phys_cpu_files(struct super_block *sb,
  532. struct dentry *cpus_dir, void *cpu_info)
  533. {
  534. struct dentry *cpu_dir;
  535. char buffer[TMP_SIZE];
  536. void *rc;
  537. snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_info_type,
  538. cpu_info));
  539. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  540. if (IS_ERR(cpu_dir))
  541. return PTR_ERR(cpu_dir);
  542. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  543. phys_cpu__mgm_time(diag204_info_type, cpu_info));
  544. if (IS_ERR(rc))
  545. return PTR_ERR(rc);
  546. diag224_idx2name(phys_cpu__ctidx(diag204_info_type, cpu_info), buffer);
  547. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  548. if (IS_ERR(rc))
  549. return PTR_ERR(rc);
  550. return 0;
  551. }
  552. static void *hypfs_create_phys_files(struct super_block *sb,
  553. struct dentry *parent_dir, void *phys_hdr)
  554. {
  555. int i;
  556. void *cpu_info;
  557. struct dentry *cpus_dir;
  558. cpus_dir = hypfs_mkdir(sb, parent_dir, "cpus");
  559. if (IS_ERR(cpus_dir))
  560. return cpus_dir;
  561. cpu_info = phys_hdr + phys_hdr__size(diag204_info_type);
  562. for (i = 0; i < phys_hdr__cpus(diag204_info_type, phys_hdr); i++) {
  563. int rc;
  564. rc = hypfs_create_phys_cpu_files(sb, cpus_dir, cpu_info);
  565. if (rc)
  566. return ERR_PTR(rc);
  567. cpu_info += phys_cpu__size(diag204_info_type);
  568. }
  569. return cpu_info;
  570. }
  571. int hypfs_diag_create_files(struct super_block *sb, struct dentry *root)
  572. {
  573. struct dentry *systems_dir, *hyp_dir;
  574. void *time_hdr, *part_hdr;
  575. int i, rc;
  576. void *buffer, *ptr;
  577. buffer = diag204_store();
  578. if (IS_ERR(buffer))
  579. return PTR_ERR(buffer);
  580. systems_dir = hypfs_mkdir(sb, root, "systems");
  581. if (IS_ERR(systems_dir)) {
  582. rc = PTR_ERR(systems_dir);
  583. goto err_out;
  584. }
  585. time_hdr = (struct x_info_blk_hdr *)buffer;
  586. part_hdr = time_hdr + info_blk_hdr__size(diag204_info_type);
  587. for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr); i++) {
  588. part_hdr = hypfs_create_lpar_files(sb, systems_dir, part_hdr);
  589. if (IS_ERR(part_hdr)) {
  590. rc = PTR_ERR(part_hdr);
  591. goto err_out;
  592. }
  593. }
  594. if (info_blk_hdr__flags(diag204_info_type, time_hdr) & LPAR_PHYS_FLG) {
  595. ptr = hypfs_create_phys_files(sb, root, part_hdr);
  596. if (IS_ERR(ptr)) {
  597. rc = PTR_ERR(ptr);
  598. goto err_out;
  599. }
  600. }
  601. hyp_dir = hypfs_mkdir(sb, root, "hyp");
  602. if (IS_ERR(hyp_dir)) {
  603. rc = PTR_ERR(hyp_dir);
  604. goto err_out;
  605. }
  606. ptr = hypfs_create_str(sb, hyp_dir, "type", "LPAR Hypervisor");
  607. if (IS_ERR(ptr)) {
  608. rc = PTR_ERR(ptr);
  609. goto err_out;
  610. }
  611. rc = 0;
  612. err_out:
  613. return rc;
  614. }