hypfs_diag.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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((unsigned long)SUBC_RSI |
  357. (unsigned long)INFO_EXT, 0, NULL);
  358. if (*pages <= 0)
  359. return ERR_PTR(-ENOSYS);
  360. else
  361. return diag204_alloc_vbuf(*pages);
  362. }
  363. }
  364. /*
  365. * diag204_probe() has to find out, which type of diagnose 204 implementation
  366. * we have on our machine. Currently there are three possible scanarios:
  367. * - subcode 4 + simple data format (only one page)
  368. * - subcode 4-6 + extended data format
  369. * - subcode 4-7 + extended data format
  370. *
  371. * Subcode 5 is used to retrieve the size of the data, provided by subcodes
  372. * 6 and 7. Subcode 7 basically has the same function as subcode 6. In addition
  373. * to subcode 6 it provides also information about secondary cpus.
  374. * In order to get as much information as possible, we first try
  375. * subcode 7, then 6 and if both fail, we use subcode 4.
  376. */
  377. static int diag204_probe(void)
  378. {
  379. void *buf;
  380. int pages, rc;
  381. buf = diag204_get_buffer(INFO_EXT, &pages);
  382. if (!IS_ERR(buf)) {
  383. if (diag204((unsigned long)SUBC_STIB7 |
  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. if (diag204((unsigned long)SUBC_STIB6 |
  390. (unsigned long)INFO_EXT, pages, buf) >= 0) {
  391. diag204_store_sc = SUBC_STIB7;
  392. diag204_info_type = INFO_EXT;
  393. goto out;
  394. }
  395. diag204_free_buffer();
  396. }
  397. /* subcodes 6 and 7 failed, now try subcode 4 */
  398. buf = diag204_get_buffer(INFO_SIMPLE, &pages);
  399. if (IS_ERR(buf)) {
  400. rc = PTR_ERR(buf);
  401. goto fail_alloc;
  402. }
  403. if (diag204((unsigned long)SUBC_STIB4 |
  404. (unsigned long)INFO_SIMPLE, pages, buf) >= 0) {
  405. diag204_store_sc = SUBC_STIB4;
  406. diag204_info_type = INFO_SIMPLE;
  407. goto out;
  408. } else {
  409. rc = -ENOSYS;
  410. goto fail_store;
  411. }
  412. out:
  413. rc = 0;
  414. fail_store:
  415. diag204_free_buffer();
  416. fail_alloc:
  417. return rc;
  418. }
  419. static void *diag204_store(void)
  420. {
  421. void *buf;
  422. int pages;
  423. buf = diag204_get_buffer(diag204_info_type, &pages);
  424. if (IS_ERR(buf))
  425. goto out;
  426. if (diag204((unsigned long)diag204_store_sc |
  427. (unsigned long)diag204_info_type, pages, buf) < 0)
  428. return ERR_PTR(-ENOSYS);
  429. out:
  430. return buf;
  431. }
  432. /* Diagnose 224 functions */
  433. static void diag224(void *ptr)
  434. {
  435. asm volatile(" diag %0,%1,0x224\n"
  436. : :"d" (0), "d"(ptr) : "memory");
  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. diag224(diag224_cpu_names);
  445. EBCASC(diag224_cpu_names + 16, (*diag224_cpu_names + 1) * 16);
  446. return 0;
  447. }
  448. static void diag224_delete_name_table(void)
  449. {
  450. kfree(diag224_cpu_names);
  451. }
  452. static int diag224_idx2name(int index, char *name)
  453. {
  454. memcpy(name, diag224_cpu_names + ((index + 1) * CPU_NAME_LEN),
  455. CPU_NAME_LEN);
  456. name[CPU_NAME_LEN] = 0;
  457. strstrip(name);
  458. return 0;
  459. }
  460. __init int hypfs_diag_init(void)
  461. {
  462. int rc;
  463. if (diag204_probe()) {
  464. printk(KERN_ERR "hypfs: diag 204 not working.");
  465. return -ENODATA;
  466. }
  467. rc = diag224_get_name_table();
  468. if (rc) {
  469. diag224_delete_name_table();
  470. printk(KERN_ERR "hypfs: could not get name table.\n");
  471. }
  472. return rc;
  473. }
  474. void hypfs_diag_exit(void)
  475. {
  476. diag224_delete_name_table();
  477. diag204_free_buffer();
  478. }
  479. /*
  480. * Functions to create the directory structure
  481. * *******************************************
  482. */
  483. static int hypfs_create_cpu_files(struct super_block *sb,
  484. struct dentry *cpus_dir, void *cpu_info)
  485. {
  486. struct dentry *cpu_dir;
  487. char buffer[TMP_SIZE];
  488. void *rc;
  489. snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_info_type,
  490. cpu_info));
  491. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  492. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  493. cpu_info__acc_time(diag204_info_type, cpu_info) -
  494. cpu_info__lp_time(diag204_info_type, cpu_info));
  495. if (IS_ERR(rc))
  496. return PTR_ERR(rc);
  497. rc = hypfs_create_u64(sb, cpu_dir, "cputime",
  498. cpu_info__lp_time(diag204_info_type, cpu_info));
  499. if (IS_ERR(rc))
  500. return PTR_ERR(rc);
  501. if (diag204_info_type == INFO_EXT) {
  502. rc = hypfs_create_u64(sb, cpu_dir, "onlinetime",
  503. cpu_info__online_time(diag204_info_type,
  504. cpu_info));
  505. if (IS_ERR(rc))
  506. return PTR_ERR(rc);
  507. }
  508. diag224_idx2name(cpu_info__ctidx(diag204_info_type, cpu_info), buffer);
  509. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  510. if (IS_ERR(rc))
  511. return PTR_ERR(rc);
  512. return 0;
  513. }
  514. static void *hypfs_create_lpar_files(struct super_block *sb,
  515. struct dentry *systems_dir, void *part_hdr)
  516. {
  517. struct dentry *cpus_dir;
  518. struct dentry *lpar_dir;
  519. char lpar_name[LPAR_NAME_LEN + 1];
  520. void *cpu_info;
  521. int i;
  522. part_hdr__part_name(diag204_info_type, part_hdr, lpar_name);
  523. lpar_name[LPAR_NAME_LEN] = 0;
  524. lpar_dir = hypfs_mkdir(sb, systems_dir, lpar_name);
  525. if (IS_ERR(lpar_dir))
  526. return lpar_dir;
  527. cpus_dir = hypfs_mkdir(sb, lpar_dir, "cpus");
  528. if (IS_ERR(cpus_dir))
  529. return cpus_dir;
  530. cpu_info = part_hdr + part_hdr__size(diag204_info_type);
  531. for (i = 0; i < part_hdr__rcpus(diag204_info_type, part_hdr); i++) {
  532. int rc;
  533. rc = hypfs_create_cpu_files(sb, cpus_dir, cpu_info);
  534. if (rc)
  535. return ERR_PTR(rc);
  536. cpu_info += cpu_info__size(diag204_info_type);
  537. }
  538. return cpu_info;
  539. }
  540. static int hypfs_create_phys_cpu_files(struct super_block *sb,
  541. struct dentry *cpus_dir, void *cpu_info)
  542. {
  543. struct dentry *cpu_dir;
  544. char buffer[TMP_SIZE];
  545. void *rc;
  546. snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_info_type,
  547. cpu_info));
  548. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  549. if (IS_ERR(cpu_dir))
  550. return PTR_ERR(cpu_dir);
  551. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  552. phys_cpu__mgm_time(diag204_info_type, cpu_info));
  553. if (IS_ERR(rc))
  554. return PTR_ERR(rc);
  555. diag224_idx2name(phys_cpu__ctidx(diag204_info_type, cpu_info), buffer);
  556. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  557. if (IS_ERR(rc))
  558. return PTR_ERR(rc);
  559. return 0;
  560. }
  561. static void *hypfs_create_phys_files(struct super_block *sb,
  562. struct dentry *parent_dir, void *phys_hdr)
  563. {
  564. int i;
  565. void *cpu_info;
  566. struct dentry *cpus_dir;
  567. cpus_dir = hypfs_mkdir(sb, parent_dir, "cpus");
  568. if (IS_ERR(cpus_dir))
  569. return cpus_dir;
  570. cpu_info = phys_hdr + phys_hdr__size(diag204_info_type);
  571. for (i = 0; i < phys_hdr__cpus(diag204_info_type, phys_hdr); i++) {
  572. int rc;
  573. rc = hypfs_create_phys_cpu_files(sb, cpus_dir, cpu_info);
  574. if (rc)
  575. return ERR_PTR(rc);
  576. cpu_info += phys_cpu__size(diag204_info_type);
  577. }
  578. return cpu_info;
  579. }
  580. int hypfs_diag_create_files(struct super_block *sb, struct dentry *root)
  581. {
  582. struct dentry *systems_dir, *hyp_dir;
  583. void *time_hdr, *part_hdr;
  584. int i, rc;
  585. void *buffer, *ptr;
  586. buffer = diag204_store();
  587. if (IS_ERR(buffer))
  588. return PTR_ERR(buffer);
  589. systems_dir = hypfs_mkdir(sb, root, "systems");
  590. if (IS_ERR(systems_dir)) {
  591. rc = PTR_ERR(systems_dir);
  592. goto err_out;
  593. }
  594. time_hdr = (struct x_info_blk_hdr *)buffer;
  595. part_hdr = time_hdr + info_blk_hdr__size(diag204_info_type);
  596. for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr); i++) {
  597. part_hdr = hypfs_create_lpar_files(sb, systems_dir, part_hdr);
  598. if (IS_ERR(part_hdr)) {
  599. rc = PTR_ERR(part_hdr);
  600. goto err_out;
  601. }
  602. }
  603. if (info_blk_hdr__flags(diag204_info_type, time_hdr) & LPAR_PHYS_FLG) {
  604. ptr = hypfs_create_phys_files(sb, root, part_hdr);
  605. if (IS_ERR(ptr)) {
  606. rc = PTR_ERR(ptr);
  607. goto err_out;
  608. }
  609. }
  610. hyp_dir = hypfs_mkdir(sb, root, "hyp");
  611. if (IS_ERR(hyp_dir)) {
  612. rc = PTR_ERR(hyp_dir);
  613. goto err_out;
  614. }
  615. ptr = hypfs_create_str(sb, hyp_dir, "type", "LPAR Hypervisor");
  616. if (IS_ERR(ptr)) {
  617. rc = PTR_ERR(ptr);
  618. goto err_out;
  619. }
  620. rc = 0;
  621. err_out:
  622. return rc;
  623. }