hypfs_diag.c 18 KB

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