hypfs_diag.c 17 KB

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