hypfs_diag.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. * Hypervisor filesystem for Linux on s390. Diag 204 and 224
  3. * implementation.
  4. *
  5. * Copyright IBM Corp. 2006, 2008
  6. * Author(s): Michael Holzheu <holzheu@de.ibm.com>
  7. */
  8. #define KMSG_COMPONENT "hypfs"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/types.h>
  11. #include <linux/errno.h>
  12. #include <linux/slab.h>
  13. #include <linux/string.h>
  14. #include <linux/vmalloc.h>
  15. #include <linux/mm.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. #define DBFS_D204_HDR_VERSION 0
  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. static struct dentry *dbfs_d204_file;
  43. /*
  44. * DIAG 204 data structures and member access functions.
  45. *
  46. * Since we have two different diag 204 data formats for old and new s390
  47. * machines, we do not access the structs directly, but use getter functions for
  48. * each struct member instead. This should make the code more readable.
  49. */
  50. /* Time information block */
  51. struct info_blk_hdr {
  52. __u8 npar;
  53. __u8 flags;
  54. __u16 tslice;
  55. __u16 phys_cpus;
  56. __u16 this_part;
  57. __u64 curtod;
  58. } __attribute__ ((packed));
  59. struct x_info_blk_hdr {
  60. __u8 npar;
  61. __u8 flags;
  62. __u16 tslice;
  63. __u16 phys_cpus;
  64. __u16 this_part;
  65. __u64 curtod1;
  66. __u64 curtod2;
  67. char reserved[40];
  68. } __attribute__ ((packed));
  69. static inline int info_blk_hdr__size(enum diag204_format type)
  70. {
  71. if (type == INFO_SIMPLE)
  72. return sizeof(struct info_blk_hdr);
  73. else /* INFO_EXT */
  74. return sizeof(struct x_info_blk_hdr);
  75. }
  76. static inline __u8 info_blk_hdr__npar(enum diag204_format type, void *hdr)
  77. {
  78. if (type == INFO_SIMPLE)
  79. return ((struct info_blk_hdr *)hdr)->npar;
  80. else /* INFO_EXT */
  81. return ((struct x_info_blk_hdr *)hdr)->npar;
  82. }
  83. static inline __u8 info_blk_hdr__flags(enum diag204_format type, void *hdr)
  84. {
  85. if (type == INFO_SIMPLE)
  86. return ((struct info_blk_hdr *)hdr)->flags;
  87. else /* INFO_EXT */
  88. return ((struct x_info_blk_hdr *)hdr)->flags;
  89. }
  90. static inline __u16 info_blk_hdr__pcpus(enum diag204_format type, void *hdr)
  91. {
  92. if (type == INFO_SIMPLE)
  93. return ((struct info_blk_hdr *)hdr)->phys_cpus;
  94. else /* INFO_EXT */
  95. return ((struct x_info_blk_hdr *)hdr)->phys_cpus;
  96. }
  97. /* Partition header */
  98. struct part_hdr {
  99. __u8 pn;
  100. __u8 cpus;
  101. char reserved[6];
  102. char part_name[LPAR_NAME_LEN];
  103. } __attribute__ ((packed));
  104. struct x_part_hdr {
  105. __u8 pn;
  106. __u8 cpus;
  107. __u8 rcpus;
  108. __u8 pflag;
  109. __u32 mlu;
  110. char part_name[LPAR_NAME_LEN];
  111. char lpc_name[8];
  112. char os_name[8];
  113. __u64 online_cs;
  114. __u64 online_es;
  115. __u8 upid;
  116. char reserved1[3];
  117. __u32 group_mlu;
  118. char group_name[8];
  119. char reserved2[32];
  120. } __attribute__ ((packed));
  121. static inline int part_hdr__size(enum diag204_format type)
  122. {
  123. if (type == INFO_SIMPLE)
  124. return sizeof(struct part_hdr);
  125. else /* INFO_EXT */
  126. return sizeof(struct x_part_hdr);
  127. }
  128. static inline __u8 part_hdr__rcpus(enum diag204_format type, void *hdr)
  129. {
  130. if (type == INFO_SIMPLE)
  131. return ((struct part_hdr *)hdr)->cpus;
  132. else /* INFO_EXT */
  133. return ((struct x_part_hdr *)hdr)->rcpus;
  134. }
  135. static inline void part_hdr__part_name(enum diag204_format type, void *hdr,
  136. char *name)
  137. {
  138. if (type == INFO_SIMPLE)
  139. memcpy(name, ((struct part_hdr *)hdr)->part_name,
  140. LPAR_NAME_LEN);
  141. else /* INFO_EXT */
  142. memcpy(name, ((struct x_part_hdr *)hdr)->part_name,
  143. LPAR_NAME_LEN);
  144. EBCASC(name, LPAR_NAME_LEN);
  145. name[LPAR_NAME_LEN] = 0;
  146. strim(name);
  147. }
  148. struct cpu_info {
  149. __u16 cpu_addr;
  150. char reserved1[2];
  151. __u8 ctidx;
  152. __u8 cflag;
  153. __u16 weight;
  154. __u64 acc_time;
  155. __u64 lp_time;
  156. } __attribute__ ((packed));
  157. struct x_cpu_info {
  158. __u16 cpu_addr;
  159. char reserved1[2];
  160. __u8 ctidx;
  161. __u8 cflag;
  162. __u16 weight;
  163. __u64 acc_time;
  164. __u64 lp_time;
  165. __u16 min_weight;
  166. __u16 cur_weight;
  167. __u16 max_weight;
  168. char reseved2[2];
  169. __u64 online_time;
  170. __u64 wait_time;
  171. __u32 pma_weight;
  172. __u32 polar_weight;
  173. char reserved3[40];
  174. } __attribute__ ((packed));
  175. /* CPU info block */
  176. static inline int cpu_info__size(enum diag204_format type)
  177. {
  178. if (type == INFO_SIMPLE)
  179. return sizeof(struct cpu_info);
  180. else /* INFO_EXT */
  181. return sizeof(struct x_cpu_info);
  182. }
  183. static inline __u8 cpu_info__ctidx(enum diag204_format type, void *hdr)
  184. {
  185. if (type == INFO_SIMPLE)
  186. return ((struct cpu_info *)hdr)->ctidx;
  187. else /* INFO_EXT */
  188. return ((struct x_cpu_info *)hdr)->ctidx;
  189. }
  190. static inline __u16 cpu_info__cpu_addr(enum diag204_format type, void *hdr)
  191. {
  192. if (type == INFO_SIMPLE)
  193. return ((struct cpu_info *)hdr)->cpu_addr;
  194. else /* INFO_EXT */
  195. return ((struct x_cpu_info *)hdr)->cpu_addr;
  196. }
  197. static inline __u64 cpu_info__acc_time(enum diag204_format type, void *hdr)
  198. {
  199. if (type == INFO_SIMPLE)
  200. return ((struct cpu_info *)hdr)->acc_time;
  201. else /* INFO_EXT */
  202. return ((struct x_cpu_info *)hdr)->acc_time;
  203. }
  204. static inline __u64 cpu_info__lp_time(enum diag204_format type, void *hdr)
  205. {
  206. if (type == INFO_SIMPLE)
  207. return ((struct cpu_info *)hdr)->lp_time;
  208. else /* INFO_EXT */
  209. return ((struct x_cpu_info *)hdr)->lp_time;
  210. }
  211. static inline __u64 cpu_info__online_time(enum diag204_format type, void *hdr)
  212. {
  213. if (type == INFO_SIMPLE)
  214. return 0; /* online_time not available in simple info */
  215. else /* INFO_EXT */
  216. return ((struct x_cpu_info *)hdr)->online_time;
  217. }
  218. /* Physical header */
  219. struct phys_hdr {
  220. char reserved1[1];
  221. __u8 cpus;
  222. char reserved2[6];
  223. char mgm_name[8];
  224. } __attribute__ ((packed));
  225. struct x_phys_hdr {
  226. char reserved1[1];
  227. __u8 cpus;
  228. char reserved2[6];
  229. char mgm_name[8];
  230. char reserved3[80];
  231. } __attribute__ ((packed));
  232. static inline int phys_hdr__size(enum diag204_format type)
  233. {
  234. if (type == INFO_SIMPLE)
  235. return sizeof(struct phys_hdr);
  236. else /* INFO_EXT */
  237. return sizeof(struct x_phys_hdr);
  238. }
  239. static inline __u8 phys_hdr__cpus(enum diag204_format type, void *hdr)
  240. {
  241. if (type == INFO_SIMPLE)
  242. return ((struct phys_hdr *)hdr)->cpus;
  243. else /* INFO_EXT */
  244. return ((struct x_phys_hdr *)hdr)->cpus;
  245. }
  246. /* Physical CPU info block */
  247. struct phys_cpu {
  248. __u16 cpu_addr;
  249. char reserved1[2];
  250. __u8 ctidx;
  251. char reserved2[3];
  252. __u64 mgm_time;
  253. char reserved3[8];
  254. } __attribute__ ((packed));
  255. struct x_phys_cpu {
  256. __u16 cpu_addr;
  257. char reserved1[2];
  258. __u8 ctidx;
  259. char reserved2[3];
  260. __u64 mgm_time;
  261. char reserved3[80];
  262. } __attribute__ ((packed));
  263. static inline int phys_cpu__size(enum diag204_format type)
  264. {
  265. if (type == INFO_SIMPLE)
  266. return sizeof(struct phys_cpu);
  267. else /* INFO_EXT */
  268. return sizeof(struct x_phys_cpu);
  269. }
  270. static inline __u16 phys_cpu__cpu_addr(enum diag204_format type, void *hdr)
  271. {
  272. if (type == INFO_SIMPLE)
  273. return ((struct phys_cpu *)hdr)->cpu_addr;
  274. else /* INFO_EXT */
  275. return ((struct x_phys_cpu *)hdr)->cpu_addr;
  276. }
  277. static inline __u64 phys_cpu__mgm_time(enum diag204_format type, void *hdr)
  278. {
  279. if (type == INFO_SIMPLE)
  280. return ((struct phys_cpu *)hdr)->mgm_time;
  281. else /* INFO_EXT */
  282. return ((struct x_phys_cpu *)hdr)->mgm_time;
  283. }
  284. static inline __u64 phys_cpu__ctidx(enum diag204_format type, void *hdr)
  285. {
  286. if (type == INFO_SIMPLE)
  287. return ((struct phys_cpu *)hdr)->ctidx;
  288. else /* INFO_EXT */
  289. return ((struct x_phys_cpu *)hdr)->ctidx;
  290. }
  291. /* Diagnose 204 functions */
  292. static int diag204(unsigned long subcode, unsigned long size, void *addr)
  293. {
  294. register unsigned long _subcode asm("0") = subcode;
  295. register unsigned long _size asm("1") = size;
  296. asm volatile(
  297. " diag %2,%0,0x204\n"
  298. "0:\n"
  299. EX_TABLE(0b,0b)
  300. : "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
  301. if (_subcode)
  302. return -1;
  303. return _size;
  304. }
  305. /*
  306. * For the old diag subcode 4 with simple data format we have to use real
  307. * memory. If we use subcode 6 or 7 with extended data format, we can (and
  308. * should) use vmalloc, since we need a lot of memory in that case. Currently
  309. * up to 93 pages!
  310. */
  311. static void diag204_free_buffer(void)
  312. {
  313. if (!diag204_buf)
  314. return;
  315. if (diag204_buf_vmalloc) {
  316. vfree(diag204_buf_vmalloc);
  317. diag204_buf_vmalloc = NULL;
  318. } else {
  319. free_pages((unsigned long) diag204_buf, 0);
  320. }
  321. diag204_buf = NULL;
  322. }
  323. static void *page_align_ptr(void *ptr)
  324. {
  325. return (void *) PAGE_ALIGN((unsigned long) ptr);
  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 = page_align_ptr(diag204_buf_vmalloc);
  334. diag204_buf_pages = pages;
  335. return diag204_buf;
  336. }
  337. static void *diag204_alloc_rbuf(void)
  338. {
  339. diag204_buf = (void*)__get_free_pages(GFP_KERNEL,0);
  340. if (!diag204_buf)
  341. return ERR_PTR(-ENOMEM);
  342. diag204_buf_pages = 1;
  343. return diag204_buf;
  344. }
  345. static void *diag204_get_buffer(enum diag204_format fmt, int *pages)
  346. {
  347. if (diag204_buf) {
  348. *pages = diag204_buf_pages;
  349. return diag204_buf;
  350. }
  351. if (fmt == INFO_SIMPLE) {
  352. *pages = 1;
  353. return diag204_alloc_rbuf();
  354. } else {/* INFO_EXT */
  355. *pages = diag204((unsigned long)SUBC_RSI |
  356. (unsigned long)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_STIB6;
  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 int diag204_do_store(void *buf, int pages)
  419. {
  420. int rc;
  421. rc = diag204((unsigned long) diag204_store_sc |
  422. (unsigned long) diag204_info_type, pages, buf);
  423. return rc < 0 ? -ENOSYS : 0;
  424. }
  425. static void *diag204_store(void)
  426. {
  427. void *buf;
  428. int pages, rc;
  429. buf = diag204_get_buffer(diag204_info_type, &pages);
  430. if (IS_ERR(buf))
  431. goto out;
  432. rc = diag204_do_store(buf, pages);
  433. if (rc)
  434. return ERR_PTR(rc);
  435. out:
  436. return buf;
  437. }
  438. /* Diagnose 224 functions */
  439. static int diag224(void *ptr)
  440. {
  441. int rc = -EOPNOTSUPP;
  442. asm volatile(
  443. " diag %1,%2,0x224\n"
  444. "0: lhi %0,0x0\n"
  445. "1:\n"
  446. EX_TABLE(0b,1b)
  447. : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
  448. return rc;
  449. }
  450. static int diag224_get_name_table(void)
  451. {
  452. /* memory must be below 2GB */
  453. diag224_cpu_names = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
  454. if (!diag224_cpu_names)
  455. return -ENOMEM;
  456. if (diag224(diag224_cpu_names)) {
  457. kfree(diag224_cpu_names);
  458. return -EOPNOTSUPP;
  459. }
  460. EBCASC(diag224_cpu_names + 16, (*diag224_cpu_names + 1) * 16);
  461. return 0;
  462. }
  463. static void diag224_delete_name_table(void)
  464. {
  465. kfree(diag224_cpu_names);
  466. }
  467. static int diag224_idx2name(int index, char *name)
  468. {
  469. memcpy(name, diag224_cpu_names + ((index + 1) * CPU_NAME_LEN),
  470. CPU_NAME_LEN);
  471. name[CPU_NAME_LEN] = 0;
  472. strim(name);
  473. return 0;
  474. }
  475. struct dbfs_d204_hdr {
  476. u64 len; /* Length of d204 buffer without header */
  477. u16 version; /* Version of header */
  478. u8 sc; /* Used subcode */
  479. char reserved[53];
  480. } __attribute__ ((packed));
  481. struct dbfs_d204 {
  482. struct dbfs_d204_hdr hdr; /* 64 byte header */
  483. char buf[]; /* d204 buffer */
  484. } __attribute__ ((packed));
  485. static int dbfs_d204_create(void **data, void **data_free_ptr, size_t *size)
  486. {
  487. struct dbfs_d204 *d204;
  488. int rc, buf_size;
  489. void *base;
  490. buf_size = PAGE_SIZE * (diag204_buf_pages + 1) + sizeof(d204->hdr);
  491. base = vzalloc(buf_size);
  492. if (!base)
  493. return -ENOMEM;
  494. d204 = page_align_ptr(base + sizeof(d204->hdr)) - sizeof(d204->hdr);
  495. rc = diag204_do_store(d204->buf, diag204_buf_pages);
  496. if (rc) {
  497. vfree(base);
  498. return rc;
  499. }
  500. d204->hdr.version = DBFS_D204_HDR_VERSION;
  501. d204->hdr.len = PAGE_SIZE * diag204_buf_pages;
  502. d204->hdr.sc = diag204_store_sc;
  503. *data = d204;
  504. *data_free_ptr = base;
  505. *size = d204->hdr.len + sizeof(struct dbfs_d204_hdr);
  506. return 0;
  507. }
  508. static struct hypfs_dbfs_file dbfs_file_d204 = {
  509. .name = "diag_204",
  510. .data_create = dbfs_d204_create,
  511. .data_free = vfree,
  512. };
  513. __init int hypfs_diag_init(void)
  514. {
  515. int rc;
  516. if (diag204_probe()) {
  517. pr_err("The hardware system does not support hypfs\n");
  518. return -ENODATA;
  519. }
  520. if (diag204_info_type == INFO_EXT) {
  521. rc = hypfs_dbfs_create_file(&dbfs_file_d204);
  522. if (rc)
  523. return rc;
  524. }
  525. if (MACHINE_IS_LPAR) {
  526. rc = diag224_get_name_table();
  527. if (rc) {
  528. pr_err("The hardware system does not provide all "
  529. "functions required by hypfs\n");
  530. debugfs_remove(dbfs_d204_file);
  531. return rc;
  532. }
  533. }
  534. return 0;
  535. }
  536. void hypfs_diag_exit(void)
  537. {
  538. debugfs_remove(dbfs_d204_file);
  539. diag224_delete_name_table();
  540. diag204_free_buffer();
  541. hypfs_dbfs_remove_file(&dbfs_file_d204);
  542. }
  543. /*
  544. * Functions to create the directory structure
  545. * *******************************************
  546. */
  547. static int hypfs_create_cpu_files(struct super_block *sb,
  548. struct dentry *cpus_dir, void *cpu_info)
  549. {
  550. struct dentry *cpu_dir;
  551. char buffer[TMP_SIZE];
  552. void *rc;
  553. snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_info_type,
  554. cpu_info));
  555. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  556. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  557. cpu_info__acc_time(diag204_info_type, cpu_info) -
  558. cpu_info__lp_time(diag204_info_type, cpu_info));
  559. if (IS_ERR(rc))
  560. return PTR_ERR(rc);
  561. rc = hypfs_create_u64(sb, cpu_dir, "cputime",
  562. cpu_info__lp_time(diag204_info_type, cpu_info));
  563. if (IS_ERR(rc))
  564. return PTR_ERR(rc);
  565. if (diag204_info_type == INFO_EXT) {
  566. rc = hypfs_create_u64(sb, cpu_dir, "onlinetime",
  567. cpu_info__online_time(diag204_info_type,
  568. cpu_info));
  569. if (IS_ERR(rc))
  570. return PTR_ERR(rc);
  571. }
  572. diag224_idx2name(cpu_info__ctidx(diag204_info_type, cpu_info), buffer);
  573. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  574. if (IS_ERR(rc))
  575. return PTR_ERR(rc);
  576. return 0;
  577. }
  578. static void *hypfs_create_lpar_files(struct super_block *sb,
  579. struct dentry *systems_dir, void *part_hdr)
  580. {
  581. struct dentry *cpus_dir;
  582. struct dentry *lpar_dir;
  583. char lpar_name[LPAR_NAME_LEN + 1];
  584. void *cpu_info;
  585. int i;
  586. part_hdr__part_name(diag204_info_type, part_hdr, lpar_name);
  587. lpar_name[LPAR_NAME_LEN] = 0;
  588. lpar_dir = hypfs_mkdir(sb, systems_dir, lpar_name);
  589. if (IS_ERR(lpar_dir))
  590. return lpar_dir;
  591. cpus_dir = hypfs_mkdir(sb, lpar_dir, "cpus");
  592. if (IS_ERR(cpus_dir))
  593. return cpus_dir;
  594. cpu_info = part_hdr + part_hdr__size(diag204_info_type);
  595. for (i = 0; i < part_hdr__rcpus(diag204_info_type, part_hdr); i++) {
  596. int rc;
  597. rc = hypfs_create_cpu_files(sb, cpus_dir, cpu_info);
  598. if (rc)
  599. return ERR_PTR(rc);
  600. cpu_info += cpu_info__size(diag204_info_type);
  601. }
  602. return cpu_info;
  603. }
  604. static int hypfs_create_phys_cpu_files(struct super_block *sb,
  605. struct dentry *cpus_dir, void *cpu_info)
  606. {
  607. struct dentry *cpu_dir;
  608. char buffer[TMP_SIZE];
  609. void *rc;
  610. snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_info_type,
  611. cpu_info));
  612. cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer);
  613. if (IS_ERR(cpu_dir))
  614. return PTR_ERR(cpu_dir);
  615. rc = hypfs_create_u64(sb, cpu_dir, "mgmtime",
  616. phys_cpu__mgm_time(diag204_info_type, cpu_info));
  617. if (IS_ERR(rc))
  618. return PTR_ERR(rc);
  619. diag224_idx2name(phys_cpu__ctidx(diag204_info_type, cpu_info), buffer);
  620. rc = hypfs_create_str(sb, cpu_dir, "type", buffer);
  621. if (IS_ERR(rc))
  622. return PTR_ERR(rc);
  623. return 0;
  624. }
  625. static void *hypfs_create_phys_files(struct super_block *sb,
  626. struct dentry *parent_dir, void *phys_hdr)
  627. {
  628. int i;
  629. void *cpu_info;
  630. struct dentry *cpus_dir;
  631. cpus_dir = hypfs_mkdir(sb, parent_dir, "cpus");
  632. if (IS_ERR(cpus_dir))
  633. return cpus_dir;
  634. cpu_info = phys_hdr + phys_hdr__size(diag204_info_type);
  635. for (i = 0; i < phys_hdr__cpus(diag204_info_type, phys_hdr); i++) {
  636. int rc;
  637. rc = hypfs_create_phys_cpu_files(sb, cpus_dir, cpu_info);
  638. if (rc)
  639. return ERR_PTR(rc);
  640. cpu_info += phys_cpu__size(diag204_info_type);
  641. }
  642. return cpu_info;
  643. }
  644. int hypfs_diag_create_files(struct super_block *sb, struct dentry *root)
  645. {
  646. struct dentry *systems_dir, *hyp_dir;
  647. void *time_hdr, *part_hdr;
  648. int i, rc;
  649. void *buffer, *ptr;
  650. buffer = diag204_store();
  651. if (IS_ERR(buffer))
  652. return PTR_ERR(buffer);
  653. systems_dir = hypfs_mkdir(sb, root, "systems");
  654. if (IS_ERR(systems_dir)) {
  655. rc = PTR_ERR(systems_dir);
  656. goto err_out;
  657. }
  658. time_hdr = (struct x_info_blk_hdr *)buffer;
  659. part_hdr = time_hdr + info_blk_hdr__size(diag204_info_type);
  660. for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr); i++) {
  661. part_hdr = hypfs_create_lpar_files(sb, systems_dir, part_hdr);
  662. if (IS_ERR(part_hdr)) {
  663. rc = PTR_ERR(part_hdr);
  664. goto err_out;
  665. }
  666. }
  667. if (info_blk_hdr__flags(diag204_info_type, time_hdr) & LPAR_PHYS_FLG) {
  668. ptr = hypfs_create_phys_files(sb, root, part_hdr);
  669. if (IS_ERR(ptr)) {
  670. rc = PTR_ERR(ptr);
  671. goto err_out;
  672. }
  673. }
  674. hyp_dir = hypfs_mkdir(sb, root, "hyp");
  675. if (IS_ERR(hyp_dir)) {
  676. rc = PTR_ERR(hyp_dir);
  677. goto err_out;
  678. }
  679. ptr = hypfs_create_str(sb, hyp_dir, "type", "LPAR Hypervisor");
  680. if (IS_ERR(ptr)) {
  681. rc = PTR_ERR(ptr);
  682. goto err_out;
  683. }
  684. rc = 0;
  685. err_out:
  686. return rc;
  687. }