hypfs_diag.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * fs/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 (" diag %2,%0,0x204\n"
  292. "0: \n" ".section __ex_table,\"a\"\n"
  293. #ifndef __s390x__
  294. " .align 4\n"
  295. " .long 0b,0b\n"
  296. #else
  297. " .align 8\n"
  298. " .quad 0b,0b\n"
  299. #endif
  300. ".previous":"+d" (_subcode), "+d"(_size)
  301. :"d"(addr)
  302. :"memory");
  303. if (_subcode)
  304. return -1;
  305. else
  306. return _size;
  307. }
  308. /*
  309. * For the old diag subcode 4 with simple data format we have to use real
  310. * memory. If we use subcode 6 or 7 with extended data format, we can (and
  311. * should) use vmalloc, since we need a lot of memory in that case. Currently
  312. * up to 93 pages!
  313. */
  314. static void diag204_free_buffer(void)
  315. {
  316. if (!diag204_buf)
  317. return;
  318. if (diag204_buf_vmalloc) {
  319. vfree(diag204_buf_vmalloc);
  320. diag204_buf_vmalloc = NULL;
  321. } else {
  322. free_pages((unsigned long) diag204_buf, 0);
  323. }
  324. diag204_buf_pages = 0;
  325. diag204_buf = NULL;
  326. }
  327. static void *diag204_alloc_vbuf(int pages)
  328. {
  329. /* The buffer has to be page aligned! */
  330. diag204_buf_vmalloc = vmalloc(PAGE_SIZE * (pages + 1));
  331. if (!diag204_buf_vmalloc)
  332. return ERR_PTR(-ENOMEM);
  333. diag204_buf = (void*)((unsigned long)diag204_buf_vmalloc
  334. & ~0xfffUL) + 0x1000;
  335. diag204_buf_pages = pages;
  336. return diag204_buf;
  337. }
  338. static void *diag204_alloc_rbuf(void)
  339. {
  340. diag204_buf = (void*)__get_free_pages(GFP_KERNEL,0);
  341. if (diag204_buf)
  342. return ERR_PTR(-ENOMEM);
  343. diag204_buf_pages = 1;
  344. return diag204_buf;
  345. }
  346. static void *diag204_get_buffer(enum diag204_format fmt, int *pages)
  347. {
  348. if (diag204_buf) {
  349. *pages = diag204_buf_pages;
  350. return diag204_buf;
  351. }
  352. if (fmt == INFO_SIMPLE) {
  353. *pages = 1;
  354. return diag204_alloc_rbuf();
  355. } else {/* INFO_EXT */
  356. *pages = diag204(SUBC_RSI | INFO_EXT, 0, NULL);
  357. if (*pages <= 0)
  358. return ERR_PTR(-ENOSYS);
  359. else
  360. return diag204_alloc_vbuf(*pages);
  361. }
  362. }
  363. /*
  364. * diag204_probe() has to find out, which type of diagnose 204 implementation
  365. * we have on our machine. Currently there are three possible scanarios:
  366. * - subcode 4 + simple data format (only one page)
  367. * - subcode 4-6 + extended data format
  368. * - subcode 4-7 + extended data format
  369. *
  370. * Subcode 5 is used to retrieve the size of the data, provided by subcodes
  371. * 6 and 7. Subcode 7 basically has the same function as subcode 6. In addition
  372. * to subcode 6 it provides also information about secondary cpus.
  373. * In order to get as much information as possible, we first try
  374. * subcode 7, then 6 and if both fail, we use subcode 4.
  375. */
  376. static int diag204_probe(void)
  377. {
  378. void *buf;
  379. int pages, rc;
  380. buf = diag204_get_buffer(INFO_EXT, &pages);
  381. if (!IS_ERR(buf)) {
  382. if (diag204(SUBC_STIB7 | INFO_EXT, pages, buf) >= 0) {
  383. diag204_store_sc = SUBC_STIB7;
  384. diag204_info_type = INFO_EXT;
  385. goto out;
  386. }
  387. if (diag204(SUBC_STIB6 | INFO_EXT, pages, buf) >= 0) {
  388. diag204_store_sc = SUBC_STIB7;
  389. diag204_info_type = INFO_EXT;
  390. goto out;
  391. }
  392. diag204_free_buffer();
  393. }
  394. /* subcodes 6 and 7 failed, now try subcode 4 */
  395. buf = diag204_get_buffer(INFO_SIMPLE, &pages);
  396. if (IS_ERR(buf)) {
  397. rc = PTR_ERR(buf);
  398. goto fail_alloc;
  399. }
  400. if (diag204(SUBC_STIB4 | INFO_SIMPLE, pages, buf) >= 0) {
  401. diag204_store_sc = SUBC_STIB4;
  402. diag204_info_type = INFO_SIMPLE;
  403. goto out;
  404. } else {
  405. rc = -ENOSYS;
  406. goto fail_store;
  407. }
  408. out:
  409. rc = 0;
  410. fail_store:
  411. diag204_free_buffer();
  412. fail_alloc:
  413. return rc;
  414. }
  415. static void *diag204_store(void)
  416. {
  417. void *buf;
  418. int pages;
  419. buf = diag204_get_buffer(diag204_info_type, &pages);
  420. if (IS_ERR(buf))
  421. goto out;
  422. if (diag204(diag204_store_sc | diag204_info_type, pages, buf) < 0)
  423. return ERR_PTR(-ENOSYS);
  424. out:
  425. return buf;
  426. }
  427. /* Diagnose 224 functions */
  428. static void diag224(void *ptr)
  429. {
  430. asm volatile(" diag %0,%1,0x224\n"
  431. : :"d" (0), "d"(ptr) : "memory");
  432. }
  433. static int diag224_get_name_table(void)
  434. {
  435. /* memory must be below 2GB */
  436. diag224_cpu_names = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
  437. if (!diag224_cpu_names)
  438. return -ENOMEM;
  439. diag224(diag224_cpu_names);
  440. EBCASC(diag224_cpu_names + 16, (*diag224_cpu_names + 1) * 16);
  441. return 0;
  442. }
  443. static void diag224_delete_name_table(void)
  444. {
  445. kfree(diag224_cpu_names);
  446. }
  447. static int diag224_idx2name(int index, char *name)
  448. {
  449. memcpy(name, diag224_cpu_names + ((index + 1) * CPU_NAME_LEN),
  450. CPU_NAME_LEN);
  451. name[CPU_NAME_LEN] = 0;
  452. strstrip(name);
  453. return 0;
  454. }
  455. __init int hypfs_diag_init(void)
  456. {
  457. int rc;
  458. if (diag204_probe()) {
  459. printk(KERN_ERR "hypfs: diag 204 not working.");
  460. return -ENODATA;
  461. }
  462. rc = diag224_get_name_table();
  463. if (rc) {
  464. diag224_delete_name_table();
  465. printk(KERN_ERR "hypfs: could not get name table.\n");
  466. }
  467. return rc;
  468. }
  469. __exit void hypfs_diag_exit(void)
  470. {
  471. diag224_delete_name_table();
  472. diag204_free_buffer();
  473. }
  474. /*
  475. * Functions to create the directory structure
  476. * *******************************************
  477. */
  478. static int hypfs_create_cpu_files(struct super_block *sb,
  479. struct dentry *cpus_dir, void *cpu_info)
  480. {
  481. struct dentry *cpu_dir;
  482. char buffer[TMP_SIZE];
  483. void *rc;
  484. snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_info_type,
  485. cpu_info));
  486. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  487. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  488. cpu_info__acc_time(diag204_info_type, cpu_info) -
  489. cpu_info__lp_time(diag204_info_type, cpu_info));
  490. if (IS_ERR(rc))
  491. return PTR_ERR(rc);
  492. rc = hypfs_create_u64(sb, cpu_dir, "cputime",
  493. cpu_info__lp_time(diag204_info_type, cpu_info));
  494. if (IS_ERR(rc))
  495. return PTR_ERR(rc);
  496. if (diag204_info_type == INFO_EXT) {
  497. rc = hypfs_create_u64(sb, cpu_dir, "onlinetime",
  498. cpu_info__online_time(diag204_info_type,
  499. cpu_info));
  500. if (IS_ERR(rc))
  501. return PTR_ERR(rc);
  502. }
  503. diag224_idx2name(cpu_info__ctidx(diag204_info_type, cpu_info), buffer);
  504. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  505. if (IS_ERR(rc))
  506. return PTR_ERR(rc);
  507. return 0;
  508. }
  509. static void *hypfs_create_lpar_files(struct super_block *sb,
  510. struct dentry *systems_dir, void *part_hdr)
  511. {
  512. struct dentry *cpus_dir;
  513. struct dentry *lpar_dir;
  514. char lpar_name[LPAR_NAME_LEN + 1];
  515. void *cpu_info;
  516. int i;
  517. part_hdr__part_name(diag204_info_type, part_hdr, lpar_name);
  518. lpar_name[LPAR_NAME_LEN] = 0;
  519. lpar_dir = hypfs_mkdir(sb, systems_dir, lpar_name);
  520. if (IS_ERR(lpar_dir))
  521. return lpar_dir;
  522. cpus_dir = hypfs_mkdir(sb, lpar_dir, "cpus");
  523. if (IS_ERR(cpus_dir))
  524. return cpus_dir;
  525. cpu_info = part_hdr + part_hdr__size(diag204_info_type);
  526. for (i = 0; i < part_hdr__rcpus(diag204_info_type, part_hdr); i++) {
  527. int rc;
  528. rc = hypfs_create_cpu_files(sb, cpus_dir, cpu_info);
  529. if (rc)
  530. return ERR_PTR(rc);
  531. cpu_info += cpu_info__size(diag204_info_type);
  532. }
  533. return cpu_info;
  534. }
  535. static int hypfs_create_phys_cpu_files(struct super_block *sb,
  536. struct dentry *cpus_dir, void *cpu_info)
  537. {
  538. struct dentry *cpu_dir;
  539. char buffer[TMP_SIZE];
  540. void *rc;
  541. snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_info_type,
  542. cpu_info));
  543. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  544. if (IS_ERR(cpu_dir))
  545. return PTR_ERR(cpu_dir);
  546. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  547. phys_cpu__mgm_time(diag204_info_type, cpu_info));
  548. if (IS_ERR(rc))
  549. return PTR_ERR(rc);
  550. diag224_idx2name(phys_cpu__ctidx(diag204_info_type, cpu_info), buffer);
  551. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  552. if (IS_ERR(rc))
  553. return PTR_ERR(rc);
  554. return 0;
  555. }
  556. static void *hypfs_create_phys_files(struct super_block *sb,
  557. struct dentry *parent_dir, void *phys_hdr)
  558. {
  559. int i;
  560. void *cpu_info;
  561. struct dentry *cpus_dir;
  562. cpus_dir = hypfs_mkdir(sb, parent_dir, "cpus");
  563. if (IS_ERR(cpus_dir))
  564. return cpus_dir;
  565. cpu_info = phys_hdr + phys_hdr__size(diag204_info_type);
  566. for (i = 0; i < phys_hdr__cpus(diag204_info_type, phys_hdr); i++) {
  567. int rc;
  568. rc = hypfs_create_phys_cpu_files(sb, cpus_dir, cpu_info);
  569. if (rc)
  570. return ERR_PTR(rc);
  571. cpu_info += phys_cpu__size(diag204_info_type);
  572. }
  573. return cpu_info;
  574. }
  575. int hypfs_diag_create_files(struct super_block *sb, struct dentry *root)
  576. {
  577. struct dentry *systems_dir, *hyp_dir;
  578. void *time_hdr, *part_hdr;
  579. int i, rc;
  580. void *buffer, *ptr;
  581. buffer = diag204_store();
  582. if (IS_ERR(buffer))
  583. return PTR_ERR(buffer);
  584. systems_dir = hypfs_mkdir(sb, root, "systems");
  585. if (IS_ERR(systems_dir)) {
  586. rc = PTR_ERR(systems_dir);
  587. goto err_out;
  588. }
  589. time_hdr = (struct x_info_blk_hdr *)buffer;
  590. part_hdr = time_hdr + info_blk_hdr__size(diag204_info_type);
  591. for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr); i++) {
  592. part_hdr = hypfs_create_lpar_files(sb, systems_dir, part_hdr);
  593. if (IS_ERR(part_hdr)) {
  594. rc = PTR_ERR(part_hdr);
  595. goto err_out;
  596. }
  597. }
  598. if (info_blk_hdr__flags(diag204_info_type, time_hdr) & LPAR_PHYS_FLG) {
  599. ptr = hypfs_create_phys_files(sb, root, part_hdr);
  600. if (IS_ERR(ptr)) {
  601. rc = PTR_ERR(ptr);
  602. goto err_out;
  603. }
  604. }
  605. hyp_dir = hypfs_mkdir(sb, root, "hyp");
  606. if (IS_ERR(hyp_dir)) {
  607. rc = PTR_ERR(hyp_dir);
  608. goto err_out;
  609. }
  610. ptr = hypfs_create_str(sb, hyp_dir, "type", "LPAR Hypervisor");
  611. if (IS_ERR(ptr)) {
  612. rc = PTR_ERR(ptr);
  613. goto err_out;
  614. }
  615. rc = 0;
  616. err_out:
  617. return rc;
  618. }