zcore.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /*
  2. * zcore module to export memory content and register sets for creating system
  3. * dumps on SCSI disks (zfcpdump). The "zcore/mem" debugfs file shows the same
  4. * dump format as s390 standalone dumps.
  5. *
  6. * For more information please refer to Documentation/s390/zfcpdump.txt
  7. *
  8. * Copyright IBM Corp. 2003, 2008
  9. * Author(s): Michael Holzheu
  10. */
  11. #define KMSG_COMPONENT "zdump"
  12. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/miscdevice.h>
  16. #include <linux/debugfs.h>
  17. #include <linux/module.h>
  18. #include <linux/memblock.h>
  19. #include <asm/asm-offsets.h>
  20. #include <asm/ipl.h>
  21. #include <asm/sclp.h>
  22. #include <asm/setup.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/debug.h>
  25. #include <asm/processor.h>
  26. #include <asm/irqflags.h>
  27. #include <asm/checksum.h>
  28. #include <asm/switch_to.h>
  29. #include "sclp.h"
  30. #define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
  31. #define TO_USER 1
  32. #define TO_KERNEL 0
  33. #define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
  34. enum arch_id {
  35. ARCH_S390 = 0,
  36. ARCH_S390X = 1,
  37. };
  38. /* dump system info */
  39. struct sys_info {
  40. enum arch_id arch;
  41. unsigned long sa_base;
  42. u32 sa_size;
  43. int cpu_map[NR_CPUS];
  44. unsigned long mem_size;
  45. struct save_area lc_mask;
  46. };
  47. struct ipib_info {
  48. unsigned long ipib;
  49. u32 checksum;
  50. } __attribute__((packed));
  51. static struct sys_info sys_info;
  52. static struct debug_info *zcore_dbf;
  53. static int hsa_available;
  54. static struct dentry *zcore_dir;
  55. static struct dentry *zcore_file;
  56. static struct dentry *zcore_memmap_file;
  57. static struct dentry *zcore_reipl_file;
  58. static struct dentry *zcore_hsa_file;
  59. static struct ipl_parameter_block *ipl_block;
  60. /*
  61. * Copy memory from HSA to kernel or user memory (not reentrant):
  62. *
  63. * @dest: Kernel or user buffer where memory should be copied to
  64. * @src: Start address within HSA where data should be copied
  65. * @count: Size of buffer, which should be copied
  66. * @mode: Either TO_KERNEL or TO_USER
  67. */
  68. int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode)
  69. {
  70. int offs, blk_num;
  71. static char buf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
  72. if (!hsa_available)
  73. return -ENODATA;
  74. if (count == 0)
  75. return 0;
  76. /* copy first block */
  77. offs = 0;
  78. if ((src % PAGE_SIZE) != 0) {
  79. blk_num = src / PAGE_SIZE + 2;
  80. if (sclp_sdias_copy(buf, blk_num, 1)) {
  81. TRACE("sclp_sdias_copy() failed\n");
  82. return -EIO;
  83. }
  84. offs = min((PAGE_SIZE - (src % PAGE_SIZE)), count);
  85. if (mode == TO_USER) {
  86. if (copy_to_user((__force __user void*) dest,
  87. buf + (src % PAGE_SIZE), offs))
  88. return -EFAULT;
  89. } else
  90. memcpy(dest, buf + (src % PAGE_SIZE), offs);
  91. }
  92. if (offs == count)
  93. goto out;
  94. /* copy middle */
  95. for (; (offs + PAGE_SIZE) <= count; offs += PAGE_SIZE) {
  96. blk_num = (src + offs) / PAGE_SIZE + 2;
  97. if (sclp_sdias_copy(buf, blk_num, 1)) {
  98. TRACE("sclp_sdias_copy() failed\n");
  99. return -EIO;
  100. }
  101. if (mode == TO_USER) {
  102. if (copy_to_user((__force __user void*) dest + offs,
  103. buf, PAGE_SIZE))
  104. return -EFAULT;
  105. } else
  106. memcpy(dest + offs, buf, PAGE_SIZE);
  107. }
  108. if (offs == count)
  109. goto out;
  110. /* copy last block */
  111. blk_num = (src + offs) / PAGE_SIZE + 2;
  112. if (sclp_sdias_copy(buf, blk_num, 1)) {
  113. TRACE("sclp_sdias_copy() failed\n");
  114. return -EIO;
  115. }
  116. if (mode == TO_USER) {
  117. if (copy_to_user((__force __user void*) dest + offs, buf,
  118. count - offs))
  119. return -EFAULT;
  120. } else
  121. memcpy(dest + offs, buf, count - offs);
  122. out:
  123. return 0;
  124. }
  125. static int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
  126. {
  127. return memcpy_hsa((void __force *) dest, src, count, TO_USER);
  128. }
  129. static int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
  130. {
  131. return memcpy_hsa(dest, src, count, TO_KERNEL);
  132. }
  133. static int __init init_cpu_info(enum arch_id arch)
  134. {
  135. struct save_area_ext *sa_ext;
  136. /* get info for boot cpu from lowcore, stored in the HSA */
  137. sa_ext = dump_save_areas.areas[0];
  138. if (!sa_ext)
  139. return -ENOMEM;
  140. if (memcpy_hsa_kernel(&sa_ext->sa, sys_info.sa_base,
  141. sys_info.sa_size) < 0) {
  142. TRACE("could not copy from HSA\n");
  143. kfree(sa_ext);
  144. return -EIO;
  145. }
  146. if (MACHINE_HAS_VX)
  147. save_vx_regs_safe(sa_ext->vx_regs);
  148. return 0;
  149. }
  150. static DEFINE_MUTEX(zcore_mutex);
  151. #define DUMP_VERSION 0x5
  152. #define DUMP_MAGIC 0xa8190173618f23fdULL
  153. #define DUMP_ARCH_S390X 2
  154. #define DUMP_ARCH_S390 1
  155. #define HEADER_SIZE 4096
  156. /* dump header dumped according to s390 crash dump format */
  157. struct zcore_header {
  158. u64 magic;
  159. u32 version;
  160. u32 header_size;
  161. u32 dump_level;
  162. u32 page_size;
  163. u64 mem_size;
  164. u64 mem_start;
  165. u64 mem_end;
  166. u32 num_pages;
  167. u32 pad1;
  168. u64 tod;
  169. struct cpuid cpu_id;
  170. u32 arch_id;
  171. u32 volnr;
  172. u32 build_arch;
  173. u64 rmem_size;
  174. u8 mvdump;
  175. u16 cpu_cnt;
  176. u16 real_cpu_cnt;
  177. u8 end_pad1[0x200-0x061];
  178. u64 mvdump_sign;
  179. u64 mvdump_zipl_time;
  180. u8 end_pad2[0x800-0x210];
  181. u32 lc_vec[512];
  182. } __attribute__((packed,__aligned__(16)));
  183. static struct zcore_header zcore_header = {
  184. .magic = DUMP_MAGIC,
  185. .version = DUMP_VERSION,
  186. .header_size = 4096,
  187. .dump_level = 0,
  188. .page_size = PAGE_SIZE,
  189. .mem_start = 0,
  190. .build_arch = DUMP_ARCH_S390X,
  191. };
  192. /*
  193. * Copy lowcore info to buffer. Use map in order to copy only register parts.
  194. *
  195. * @buf: User buffer
  196. * @sa: Pointer to save area
  197. * @sa_off: Offset in save area to copy
  198. * @len: Number of bytes to copy
  199. */
  200. static int copy_lc(void __user *buf, void *sa, int sa_off, int len)
  201. {
  202. int i;
  203. char *lc_mask = (char*)&sys_info.lc_mask;
  204. for (i = 0; i < len; i++) {
  205. if (!lc_mask[i + sa_off])
  206. continue;
  207. if (copy_to_user(buf + i, sa + sa_off + i, 1))
  208. return -EFAULT;
  209. }
  210. return 0;
  211. }
  212. /*
  213. * Copy lowcores info to memory, if necessary
  214. *
  215. * @buf: User buffer
  216. * @addr: Start address of buffer in dump memory
  217. * @count: Size of buffer
  218. */
  219. static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
  220. {
  221. unsigned long end;
  222. int i;
  223. if (count == 0)
  224. return 0;
  225. end = start + count;
  226. for (i = 0; i < dump_save_areas.count; i++) {
  227. unsigned long cp_start, cp_end; /* copy range */
  228. unsigned long sa_start, sa_end; /* save area range */
  229. unsigned long prefix;
  230. unsigned long sa_off, len, buf_off;
  231. struct save_area *save_area = &dump_save_areas.areas[i]->sa;
  232. prefix = save_area->pref_reg;
  233. sa_start = prefix + sys_info.sa_base;
  234. sa_end = prefix + sys_info.sa_base + sys_info.sa_size;
  235. if ((end < sa_start) || (start > sa_end))
  236. continue;
  237. cp_start = max(start, sa_start);
  238. cp_end = min(end, sa_end);
  239. buf_off = cp_start - start;
  240. sa_off = cp_start - sa_start;
  241. len = cp_end - cp_start;
  242. TRACE("copy_lc for: %lx\n", start);
  243. if (copy_lc(buf + buf_off, save_area, sa_off, len))
  244. return -EFAULT;
  245. }
  246. return 0;
  247. }
  248. /*
  249. * Release the HSA
  250. */
  251. static void release_hsa(void)
  252. {
  253. diag308(DIAG308_REL_HSA, NULL);
  254. hsa_available = 0;
  255. }
  256. /*
  257. * Read routine for zcore character device
  258. * First 4K are dump header
  259. * Next 32MB are HSA Memory
  260. * Rest is read from absolute Memory
  261. */
  262. static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
  263. loff_t *ppos)
  264. {
  265. unsigned long mem_start; /* Start address in memory */
  266. size_t mem_offs; /* Offset in dump memory */
  267. size_t hdr_count; /* Size of header part of output buffer */
  268. size_t size;
  269. int rc;
  270. mutex_lock(&zcore_mutex);
  271. if (*ppos > (sys_info.mem_size + HEADER_SIZE)) {
  272. rc = -EINVAL;
  273. goto fail;
  274. }
  275. count = min(count, (size_t) (sys_info.mem_size + HEADER_SIZE - *ppos));
  276. /* Copy dump header */
  277. if (*ppos < HEADER_SIZE) {
  278. size = min(count, (size_t) (HEADER_SIZE - *ppos));
  279. if (copy_to_user(buf, &zcore_header + *ppos, size)) {
  280. rc = -EFAULT;
  281. goto fail;
  282. }
  283. hdr_count = size;
  284. mem_start = 0;
  285. } else {
  286. hdr_count = 0;
  287. mem_start = *ppos - HEADER_SIZE;
  288. }
  289. mem_offs = 0;
  290. /* Copy from HSA data */
  291. if (*ppos < sclp.hsa_size + HEADER_SIZE) {
  292. size = min((count - hdr_count),
  293. (size_t) (sclp.hsa_size - mem_start));
  294. rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
  295. if (rc)
  296. goto fail;
  297. mem_offs += size;
  298. }
  299. /* Copy from real mem */
  300. size = count - mem_offs - hdr_count;
  301. rc = copy_to_user_real(buf + hdr_count + mem_offs,
  302. (void *) mem_start + mem_offs, size);
  303. if (rc)
  304. goto fail;
  305. /*
  306. * Since s390 dump analysis tools like lcrash or crash
  307. * expect register sets in the prefix pages of the cpus,
  308. * we copy them into the read buffer, if necessary.
  309. * buf + hdr_count: Start of memory part of output buffer
  310. * mem_start: Start memory address to copy from
  311. * count - hdr_count: Size of memory area to copy
  312. */
  313. if (zcore_add_lc(buf + hdr_count, mem_start, count - hdr_count)) {
  314. rc = -EFAULT;
  315. goto fail;
  316. }
  317. *ppos += count;
  318. fail:
  319. mutex_unlock(&zcore_mutex);
  320. return (rc < 0) ? rc : count;
  321. }
  322. static int zcore_open(struct inode *inode, struct file *filp)
  323. {
  324. if (!hsa_available)
  325. return -ENODATA;
  326. else
  327. return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
  328. }
  329. static int zcore_release(struct inode *inode, struct file *filep)
  330. {
  331. if (hsa_available)
  332. release_hsa();
  333. return 0;
  334. }
  335. static loff_t zcore_lseek(struct file *file, loff_t offset, int orig)
  336. {
  337. loff_t rc;
  338. mutex_lock(&zcore_mutex);
  339. switch (orig) {
  340. case 0:
  341. file->f_pos = offset;
  342. rc = file->f_pos;
  343. break;
  344. case 1:
  345. file->f_pos += offset;
  346. rc = file->f_pos;
  347. break;
  348. default:
  349. rc = -EINVAL;
  350. }
  351. mutex_unlock(&zcore_mutex);
  352. return rc;
  353. }
  354. static const struct file_operations zcore_fops = {
  355. .owner = THIS_MODULE,
  356. .llseek = zcore_lseek,
  357. .read = zcore_read,
  358. .open = zcore_open,
  359. .release = zcore_release,
  360. };
  361. static ssize_t zcore_memmap_read(struct file *filp, char __user *buf,
  362. size_t count, loff_t *ppos)
  363. {
  364. return simple_read_from_buffer(buf, count, ppos, filp->private_data,
  365. memblock.memory.cnt * CHUNK_INFO_SIZE);
  366. }
  367. static int zcore_memmap_open(struct inode *inode, struct file *filp)
  368. {
  369. struct memblock_region *reg;
  370. char *buf;
  371. int i = 0;
  372. buf = kzalloc(memblock.memory.cnt * CHUNK_INFO_SIZE, GFP_KERNEL);
  373. if (!buf) {
  374. return -ENOMEM;
  375. }
  376. for_each_memblock(memory, reg) {
  377. sprintf(buf + (i++ * CHUNK_INFO_SIZE), "%016llx %016llx ",
  378. (unsigned long long) reg->base,
  379. (unsigned long long) reg->size);
  380. }
  381. filp->private_data = buf;
  382. return nonseekable_open(inode, filp);
  383. }
  384. static int zcore_memmap_release(struct inode *inode, struct file *filp)
  385. {
  386. kfree(filp->private_data);
  387. return 0;
  388. }
  389. static const struct file_operations zcore_memmap_fops = {
  390. .owner = THIS_MODULE,
  391. .read = zcore_memmap_read,
  392. .open = zcore_memmap_open,
  393. .release = zcore_memmap_release,
  394. .llseek = no_llseek,
  395. };
  396. static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
  397. size_t count, loff_t *ppos)
  398. {
  399. if (ipl_block) {
  400. diag308(DIAG308_SET, ipl_block);
  401. diag308(DIAG308_IPL, NULL);
  402. }
  403. return count;
  404. }
  405. static int zcore_reipl_open(struct inode *inode, struct file *filp)
  406. {
  407. return nonseekable_open(inode, filp);
  408. }
  409. static int zcore_reipl_release(struct inode *inode, struct file *filp)
  410. {
  411. return 0;
  412. }
  413. static const struct file_operations zcore_reipl_fops = {
  414. .owner = THIS_MODULE,
  415. .write = zcore_reipl_write,
  416. .open = zcore_reipl_open,
  417. .release = zcore_reipl_release,
  418. .llseek = no_llseek,
  419. };
  420. static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
  421. size_t count, loff_t *ppos)
  422. {
  423. static char str[18];
  424. if (hsa_available)
  425. snprintf(str, sizeof(str), "%lx\n", sclp.hsa_size);
  426. else
  427. snprintf(str, sizeof(str), "0\n");
  428. return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
  429. }
  430. static ssize_t zcore_hsa_write(struct file *filp, const char __user *buf,
  431. size_t count, loff_t *ppos)
  432. {
  433. char value;
  434. if (*ppos != 0)
  435. return -EPIPE;
  436. if (copy_from_user(&value, buf, 1))
  437. return -EFAULT;
  438. if (value != '0')
  439. return -EINVAL;
  440. release_hsa();
  441. return count;
  442. }
  443. static const struct file_operations zcore_hsa_fops = {
  444. .owner = THIS_MODULE,
  445. .write = zcore_hsa_write,
  446. .read = zcore_hsa_read,
  447. .open = nonseekable_open,
  448. .llseek = no_llseek,
  449. };
  450. static void __init set_lc_mask(struct save_area *map)
  451. {
  452. memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
  453. memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
  454. memset(&map->psw, 0xff, sizeof(map->psw));
  455. memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
  456. memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
  457. memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
  458. memset(&map->timer, 0xff, sizeof(map->timer));
  459. memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
  460. memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
  461. memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
  462. }
  463. /*
  464. * Initialize dump globals for a given architecture
  465. */
  466. static int __init sys_info_init(enum arch_id arch, unsigned long mem_end)
  467. {
  468. int rc;
  469. switch (arch) {
  470. case ARCH_S390X:
  471. pr_alert("DETECTED 'S390X (64 bit) OS'\n");
  472. break;
  473. case ARCH_S390:
  474. pr_alert("DETECTED 'S390 (32 bit) OS'\n");
  475. break;
  476. default:
  477. pr_alert("0x%x is an unknown architecture.\n",arch);
  478. return -EINVAL;
  479. }
  480. sys_info.sa_base = SAVE_AREA_BASE;
  481. sys_info.sa_size = sizeof(struct save_area);
  482. sys_info.arch = arch;
  483. set_lc_mask(&sys_info.lc_mask);
  484. rc = init_cpu_info(arch);
  485. if (rc)
  486. return rc;
  487. sys_info.mem_size = mem_end;
  488. return 0;
  489. }
  490. static int __init check_sdias(void)
  491. {
  492. if (!sclp.hsa_size) {
  493. TRACE("Could not determine HSA size\n");
  494. return -ENODEV;
  495. }
  496. return 0;
  497. }
  498. static int __init get_mem_info(unsigned long *mem, unsigned long *end)
  499. {
  500. struct memblock_region *reg;
  501. for_each_memblock(memory, reg) {
  502. *mem += reg->size;
  503. *end = max_t(unsigned long, *end, reg->base + reg->size);
  504. }
  505. return 0;
  506. }
  507. static void __init zcore_header_init(int arch, struct zcore_header *hdr,
  508. unsigned long mem_size)
  509. {
  510. u32 prefix;
  511. int i;
  512. if (arch == ARCH_S390X)
  513. hdr->arch_id = DUMP_ARCH_S390X;
  514. else
  515. hdr->arch_id = DUMP_ARCH_S390;
  516. hdr->mem_size = mem_size;
  517. hdr->rmem_size = mem_size;
  518. hdr->mem_end = sys_info.mem_size;
  519. hdr->num_pages = mem_size / PAGE_SIZE;
  520. hdr->tod = get_tod_clock();
  521. get_cpu_id(&hdr->cpu_id);
  522. for (i = 0; i < dump_save_areas.count; i++) {
  523. prefix = dump_save_areas.areas[i]->sa.pref_reg;
  524. hdr->real_cpu_cnt++;
  525. if (!prefix)
  526. continue;
  527. hdr->lc_vec[hdr->cpu_cnt] = prefix;
  528. hdr->cpu_cnt++;
  529. }
  530. }
  531. /*
  532. * Provide IPL parameter information block from either HSA or memory
  533. * for future reipl
  534. */
  535. static int __init zcore_reipl_init(void)
  536. {
  537. struct ipib_info ipib_info;
  538. int rc;
  539. rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
  540. if (rc)
  541. return rc;
  542. if (ipib_info.ipib == 0)
  543. return 0;
  544. ipl_block = (void *) __get_free_page(GFP_KERNEL);
  545. if (!ipl_block)
  546. return -ENOMEM;
  547. if (ipib_info.ipib < sclp.hsa_size)
  548. rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
  549. else
  550. rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
  551. if (rc || csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
  552. ipib_info.checksum) {
  553. TRACE("Checksum does not match\n");
  554. free_page((unsigned long) ipl_block);
  555. ipl_block = NULL;
  556. }
  557. return 0;
  558. }
  559. static int __init zcore_init(void)
  560. {
  561. unsigned long mem_size, mem_end;
  562. unsigned char arch;
  563. int rc;
  564. mem_size = mem_end = 0;
  565. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  566. return -ENODATA;
  567. if (OLDMEM_BASE)
  568. return -ENODATA;
  569. zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
  570. debug_register_view(zcore_dbf, &debug_sprintf_view);
  571. debug_set_level(zcore_dbf, 6);
  572. TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno);
  573. TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
  574. TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
  575. rc = sclp_sdias_init();
  576. if (rc)
  577. goto fail;
  578. rc = check_sdias();
  579. if (rc)
  580. goto fail;
  581. hsa_available = 1;
  582. rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
  583. if (rc)
  584. goto fail;
  585. if (arch == ARCH_S390) {
  586. pr_alert("The 64-bit dump tool cannot be used for a "
  587. "32-bit system\n");
  588. rc = -EINVAL;
  589. goto fail;
  590. }
  591. rc = get_mem_info(&mem_size, &mem_end);
  592. if (rc)
  593. goto fail;
  594. rc = sys_info_init(arch, mem_end);
  595. if (rc)
  596. goto fail;
  597. zcore_header_init(arch, &zcore_header, mem_size);
  598. rc = zcore_reipl_init();
  599. if (rc)
  600. goto fail;
  601. zcore_dir = debugfs_create_dir("zcore" , NULL);
  602. if (!zcore_dir) {
  603. rc = -ENOMEM;
  604. goto fail;
  605. }
  606. zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL,
  607. &zcore_fops);
  608. if (!zcore_file) {
  609. rc = -ENOMEM;
  610. goto fail_dir;
  611. }
  612. zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
  613. NULL, &zcore_memmap_fops);
  614. if (!zcore_memmap_file) {
  615. rc = -ENOMEM;
  616. goto fail_file;
  617. }
  618. zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
  619. NULL, &zcore_reipl_fops);
  620. if (!zcore_reipl_file) {
  621. rc = -ENOMEM;
  622. goto fail_memmap_file;
  623. }
  624. zcore_hsa_file = debugfs_create_file("hsa", S_IRUSR|S_IWUSR, zcore_dir,
  625. NULL, &zcore_hsa_fops);
  626. if (!zcore_hsa_file) {
  627. rc = -ENOMEM;
  628. goto fail_reipl_file;
  629. }
  630. return 0;
  631. fail_reipl_file:
  632. debugfs_remove(zcore_reipl_file);
  633. fail_memmap_file:
  634. debugfs_remove(zcore_memmap_file);
  635. fail_file:
  636. debugfs_remove(zcore_file);
  637. fail_dir:
  638. debugfs_remove(zcore_dir);
  639. fail:
  640. diag308(DIAG308_REL_HSA, NULL);
  641. return rc;
  642. }
  643. static void __exit zcore_exit(void)
  644. {
  645. debug_unregister(zcore_dbf);
  646. sclp_sdias_exit();
  647. free_page((unsigned long) ipl_block);
  648. debugfs_remove(zcore_hsa_file);
  649. debugfs_remove(zcore_reipl_file);
  650. debugfs_remove(zcore_memmap_file);
  651. debugfs_remove(zcore_file);
  652. debugfs_remove(zcore_dir);
  653. diag308(DIAG308_REL_HSA, NULL);
  654. }
  655. MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
  656. MODULE_DESCRIPTION("zcore module for zfcpdump support");
  657. MODULE_LICENSE("GPL");
  658. subsys_initcall(zcore_init);
  659. module_exit(zcore_exit);