hypfs_diag.c 17 KB

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