hypfs_diag.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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 (" 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((unsigned long)SUBC_STIB7 |
  383. (unsigned long)INFO_EXT, pages, buf) >= 0) {
  384. diag204_store_sc = SUBC_STIB7;
  385. diag204_info_type = INFO_EXT;
  386. goto out;
  387. }
  388. if (diag204((unsigned long)SUBC_STIB6 |
  389. (unsigned long)INFO_EXT, pages, buf) >= 0) {
  390. diag204_store_sc = SUBC_STIB7;
  391. diag204_info_type = INFO_EXT;
  392. goto out;
  393. }
  394. diag204_free_buffer();
  395. }
  396. /* subcodes 6 and 7 failed, now try subcode 4 */
  397. buf = diag204_get_buffer(INFO_SIMPLE, &pages);
  398. if (IS_ERR(buf)) {
  399. rc = PTR_ERR(buf);
  400. goto fail_alloc;
  401. }
  402. if (diag204((unsigned long)SUBC_STIB4 |
  403. (unsigned long)INFO_SIMPLE, pages, buf) >= 0) {
  404. diag204_store_sc = SUBC_STIB4;
  405. diag204_info_type = INFO_SIMPLE;
  406. goto out;
  407. } else {
  408. rc = -ENOSYS;
  409. goto fail_store;
  410. }
  411. out:
  412. rc = 0;
  413. fail_store:
  414. diag204_free_buffer();
  415. fail_alloc:
  416. return rc;
  417. }
  418. static void *diag204_store(void)
  419. {
  420. void *buf;
  421. int pages;
  422. buf = diag204_get_buffer(diag204_info_type, &pages);
  423. if (IS_ERR(buf))
  424. goto out;
  425. if (diag204((unsigned long)diag204_store_sc |
  426. (unsigned long)diag204_info_type, pages, buf) < 0)
  427. return ERR_PTR(-ENOSYS);
  428. out:
  429. return buf;
  430. }
  431. /* Diagnose 224 functions */
  432. static void diag224(void *ptr)
  433. {
  434. asm volatile(" diag %0,%1,0x224\n"
  435. : :"d" (0), "d"(ptr) : "memory");
  436. }
  437. static int diag224_get_name_table(void)
  438. {
  439. /* memory must be below 2GB */
  440. diag224_cpu_names = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
  441. if (!diag224_cpu_names)
  442. return -ENOMEM;
  443. diag224(diag224_cpu_names);
  444. EBCASC(diag224_cpu_names + 16, (*diag224_cpu_names + 1) * 16);
  445. return 0;
  446. }
  447. static void diag224_delete_name_table(void)
  448. {
  449. kfree(diag224_cpu_names);
  450. }
  451. static int diag224_idx2name(int index, char *name)
  452. {
  453. memcpy(name, diag224_cpu_names + ((index + 1) * CPU_NAME_LEN),
  454. CPU_NAME_LEN);
  455. name[CPU_NAME_LEN] = 0;
  456. strstrip(name);
  457. return 0;
  458. }
  459. __init int hypfs_diag_init(void)
  460. {
  461. int rc;
  462. if (diag204_probe()) {
  463. printk(KERN_ERR "hypfs: diag 204 not working.");
  464. return -ENODATA;
  465. }
  466. rc = diag224_get_name_table();
  467. if (rc) {
  468. diag224_delete_name_table();
  469. printk(KERN_ERR "hypfs: could not get name table.\n");
  470. }
  471. return rc;
  472. }
  473. void hypfs_diag_exit(void)
  474. {
  475. diag224_delete_name_table();
  476. diag204_free_buffer();
  477. }
  478. /*
  479. * Functions to create the directory structure
  480. * *******************************************
  481. */
  482. static int hypfs_create_cpu_files(struct super_block *sb,
  483. struct dentry *cpus_dir, void *cpu_info)
  484. {
  485. struct dentry *cpu_dir;
  486. char buffer[TMP_SIZE];
  487. void *rc;
  488. snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_info_type,
  489. cpu_info));
  490. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  491. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  492. cpu_info__acc_time(diag204_info_type, cpu_info) -
  493. cpu_info__lp_time(diag204_info_type, cpu_info));
  494. if (IS_ERR(rc))
  495. return PTR_ERR(rc);
  496. rc = hypfs_create_u64(sb, cpu_dir, "cputime",
  497. cpu_info__lp_time(diag204_info_type, cpu_info));
  498. if (IS_ERR(rc))
  499. return PTR_ERR(rc);
  500. if (diag204_info_type == INFO_EXT) {
  501. rc = hypfs_create_u64(sb, cpu_dir, "onlinetime",
  502. cpu_info__online_time(diag204_info_type,
  503. cpu_info));
  504. if (IS_ERR(rc))
  505. return PTR_ERR(rc);
  506. }
  507. diag224_idx2name(cpu_info__ctidx(diag204_info_type, cpu_info), buffer);
  508. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  509. if (IS_ERR(rc))
  510. return PTR_ERR(rc);
  511. return 0;
  512. }
  513. static void *hypfs_create_lpar_files(struct super_block *sb,
  514. struct dentry *systems_dir, void *part_hdr)
  515. {
  516. struct dentry *cpus_dir;
  517. struct dentry *lpar_dir;
  518. char lpar_name[LPAR_NAME_LEN + 1];
  519. void *cpu_info;
  520. int i;
  521. part_hdr__part_name(diag204_info_type, part_hdr, lpar_name);
  522. lpar_name[LPAR_NAME_LEN] = 0;
  523. lpar_dir = hypfs_mkdir(sb, systems_dir, lpar_name);
  524. if (IS_ERR(lpar_dir))
  525. return lpar_dir;
  526. cpus_dir = hypfs_mkdir(sb, lpar_dir, "cpus");
  527. if (IS_ERR(cpus_dir))
  528. return cpus_dir;
  529. cpu_info = part_hdr + part_hdr__size(diag204_info_type);
  530. for (i = 0; i < part_hdr__rcpus(diag204_info_type, part_hdr); i++) {
  531. int rc;
  532. rc = hypfs_create_cpu_files(sb, cpus_dir, cpu_info);
  533. if (rc)
  534. return ERR_PTR(rc);
  535. cpu_info += cpu_info__size(diag204_info_type);
  536. }
  537. return cpu_info;
  538. }
  539. static int hypfs_create_phys_cpu_files(struct super_block *sb,
  540. struct dentry *cpus_dir, void *cpu_info)
  541. {
  542. struct dentry *cpu_dir;
  543. char buffer[TMP_SIZE];
  544. void *rc;
  545. snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_info_type,
  546. cpu_info));
  547. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  548. if (IS_ERR(cpu_dir))
  549. return PTR_ERR(cpu_dir);
  550. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  551. phys_cpu__mgm_time(diag204_info_type, cpu_info));
  552. if (IS_ERR(rc))
  553. return PTR_ERR(rc);
  554. diag224_idx2name(phys_cpu__ctidx(diag204_info_type, cpu_info), buffer);
  555. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  556. if (IS_ERR(rc))
  557. return PTR_ERR(rc);
  558. return 0;
  559. }
  560. static void *hypfs_create_phys_files(struct super_block *sb,
  561. struct dentry *parent_dir, void *phys_hdr)
  562. {
  563. int i;
  564. void *cpu_info;
  565. struct dentry *cpus_dir;
  566. cpus_dir = hypfs_mkdir(sb, parent_dir, "cpus");
  567. if (IS_ERR(cpus_dir))
  568. return cpus_dir;
  569. cpu_info = phys_hdr + phys_hdr__size(diag204_info_type);
  570. for (i = 0; i < phys_hdr__cpus(diag204_info_type, phys_hdr); i++) {
  571. int rc;
  572. rc = hypfs_create_phys_cpu_files(sb, cpus_dir, cpu_info);
  573. if (rc)
  574. return ERR_PTR(rc);
  575. cpu_info += phys_cpu__size(diag204_info_type);
  576. }
  577. return cpu_info;
  578. }
  579. int hypfs_diag_create_files(struct super_block *sb, struct dentry *root)
  580. {
  581. struct dentry *systems_dir, *hyp_dir;
  582. void *time_hdr, *part_hdr;
  583. int i, rc;
  584. void *buffer, *ptr;
  585. buffer = diag204_store();
  586. if (IS_ERR(buffer))
  587. return PTR_ERR(buffer);
  588. systems_dir = hypfs_mkdir(sb, root, "systems");
  589. if (IS_ERR(systems_dir)) {
  590. rc = PTR_ERR(systems_dir);
  591. goto err_out;
  592. }
  593. time_hdr = (struct x_info_blk_hdr *)buffer;
  594. part_hdr = time_hdr + info_blk_hdr__size(diag204_info_type);
  595. for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr); i++) {
  596. part_hdr = hypfs_create_lpar_files(sb, systems_dir, part_hdr);
  597. if (IS_ERR(part_hdr)) {
  598. rc = PTR_ERR(part_hdr);
  599. goto err_out;
  600. }
  601. }
  602. if (info_blk_hdr__flags(diag204_info_type, time_hdr) & LPAR_PHYS_FLG) {
  603. ptr = hypfs_create_phys_files(sb, root, part_hdr);
  604. if (IS_ERR(ptr)) {
  605. rc = PTR_ERR(ptr);
  606. goto err_out;
  607. }
  608. }
  609. hyp_dir = hypfs_mkdir(sb, root, "hyp");
  610. if (IS_ERR(hyp_dir)) {
  611. rc = PTR_ERR(hyp_dir);
  612. goto err_out;
  613. }
  614. ptr = hypfs_create_str(sb, hyp_dir, "type", "LPAR Hypervisor");
  615. if (IS_ERR(ptr)) {
  616. rc = PTR_ERR(ptr);
  617. goto err_out;
  618. }
  619. rc = 0;
  620. err_out:
  621. return rc;
  622. }