hypfs_diag.c 17 KB

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