zcore.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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_area_create(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. #ifdef CONFIG_64BIT
  191. .build_arch = DUMP_ARCH_S390X,
  192. #else
  193. .build_arch = DUMP_ARCH_S390,
  194. #endif
  195. };
  196. /*
  197. * Copy lowcore info to buffer. Use map in order to copy only register parts.
  198. *
  199. * @buf: User buffer
  200. * @sa: Pointer to save area
  201. * @sa_off: Offset in save area to copy
  202. * @len: Number of bytes to copy
  203. */
  204. static int copy_lc(void __user *buf, void *sa, int sa_off, int len)
  205. {
  206. int i;
  207. char *lc_mask = (char*)&sys_info.lc_mask;
  208. for (i = 0; i < len; i++) {
  209. if (!lc_mask[i + sa_off])
  210. continue;
  211. if (copy_to_user(buf + i, sa + sa_off + i, 1))
  212. return -EFAULT;
  213. }
  214. return 0;
  215. }
  216. /*
  217. * Copy lowcores info to memory, if necessary
  218. *
  219. * @buf: User buffer
  220. * @addr: Start address of buffer in dump memory
  221. * @count: Size of buffer
  222. */
  223. static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
  224. {
  225. unsigned long end;
  226. int i;
  227. if (count == 0)
  228. return 0;
  229. end = start + count;
  230. for (i = 0; i < dump_save_areas.count; i++) {
  231. unsigned long cp_start, cp_end; /* copy range */
  232. unsigned long sa_start, sa_end; /* save area range */
  233. unsigned long prefix;
  234. unsigned long sa_off, len, buf_off;
  235. struct save_area *save_area = &dump_save_areas.areas[i]->sa;
  236. prefix = save_area->pref_reg;
  237. sa_start = prefix + sys_info.sa_base;
  238. sa_end = prefix + sys_info.sa_base + sys_info.sa_size;
  239. if ((end < sa_start) || (start > sa_end))
  240. continue;
  241. cp_start = max(start, sa_start);
  242. cp_end = min(end, sa_end);
  243. buf_off = cp_start - start;
  244. sa_off = cp_start - sa_start;
  245. len = cp_end - cp_start;
  246. TRACE("copy_lc for: %lx\n", start);
  247. if (copy_lc(buf + buf_off, save_area, sa_off, len))
  248. return -EFAULT;
  249. }
  250. return 0;
  251. }
  252. /*
  253. * Release the HSA
  254. */
  255. static void release_hsa(void)
  256. {
  257. diag308(DIAG308_REL_HSA, NULL);
  258. hsa_available = 0;
  259. }
  260. /*
  261. * Read routine for zcore character device
  262. * First 4K are dump header
  263. * Next 32MB are HSA Memory
  264. * Rest is read from absolute Memory
  265. */
  266. static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
  267. loff_t *ppos)
  268. {
  269. unsigned long mem_start; /* Start address in memory */
  270. size_t mem_offs; /* Offset in dump memory */
  271. size_t hdr_count; /* Size of header part of output buffer */
  272. size_t size;
  273. int rc;
  274. mutex_lock(&zcore_mutex);
  275. if (*ppos > (sys_info.mem_size + HEADER_SIZE)) {
  276. rc = -EINVAL;
  277. goto fail;
  278. }
  279. count = min(count, (size_t) (sys_info.mem_size + HEADER_SIZE - *ppos));
  280. /* Copy dump header */
  281. if (*ppos < HEADER_SIZE) {
  282. size = min(count, (size_t) (HEADER_SIZE - *ppos));
  283. if (copy_to_user(buf, &zcore_header + *ppos, size)) {
  284. rc = -EFAULT;
  285. goto fail;
  286. }
  287. hdr_count = size;
  288. mem_start = 0;
  289. } else {
  290. hdr_count = 0;
  291. mem_start = *ppos - HEADER_SIZE;
  292. }
  293. mem_offs = 0;
  294. /* Copy from HSA data */
  295. if (*ppos < sclp_get_hsa_size() + HEADER_SIZE) {
  296. size = min((count - hdr_count),
  297. (size_t) (sclp_get_hsa_size() - mem_start));
  298. rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
  299. if (rc)
  300. goto fail;
  301. mem_offs += size;
  302. }
  303. /* Copy from real mem */
  304. size = count - mem_offs - hdr_count;
  305. rc = copy_to_user_real(buf + hdr_count + mem_offs,
  306. (void *) mem_start + mem_offs, size);
  307. if (rc)
  308. goto fail;
  309. /*
  310. * Since s390 dump analysis tools like lcrash or crash
  311. * expect register sets in the prefix pages of the cpus,
  312. * we copy them into the read buffer, if necessary.
  313. * buf + hdr_count: Start of memory part of output buffer
  314. * mem_start: Start memory address to copy from
  315. * count - hdr_count: Size of memory area to copy
  316. */
  317. if (zcore_add_lc(buf + hdr_count, mem_start, count - hdr_count)) {
  318. rc = -EFAULT;
  319. goto fail;
  320. }
  321. *ppos += count;
  322. fail:
  323. mutex_unlock(&zcore_mutex);
  324. return (rc < 0) ? rc : count;
  325. }
  326. static int zcore_open(struct inode *inode, struct file *filp)
  327. {
  328. if (!hsa_available)
  329. return -ENODATA;
  330. else
  331. return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
  332. }
  333. static int zcore_release(struct inode *inode, struct file *filep)
  334. {
  335. if (hsa_available)
  336. release_hsa();
  337. return 0;
  338. }
  339. static loff_t zcore_lseek(struct file *file, loff_t offset, int orig)
  340. {
  341. loff_t rc;
  342. mutex_lock(&zcore_mutex);
  343. switch (orig) {
  344. case 0:
  345. file->f_pos = offset;
  346. rc = file->f_pos;
  347. break;
  348. case 1:
  349. file->f_pos += offset;
  350. rc = file->f_pos;
  351. break;
  352. default:
  353. rc = -EINVAL;
  354. }
  355. mutex_unlock(&zcore_mutex);
  356. return rc;
  357. }
  358. static const struct file_operations zcore_fops = {
  359. .owner = THIS_MODULE,
  360. .llseek = zcore_lseek,
  361. .read = zcore_read,
  362. .open = zcore_open,
  363. .release = zcore_release,
  364. };
  365. static ssize_t zcore_memmap_read(struct file *filp, char __user *buf,
  366. size_t count, loff_t *ppos)
  367. {
  368. return simple_read_from_buffer(buf, count, ppos, filp->private_data,
  369. memblock.memory.cnt * CHUNK_INFO_SIZE);
  370. }
  371. static int zcore_memmap_open(struct inode *inode, struct file *filp)
  372. {
  373. struct memblock_region *reg;
  374. char *buf;
  375. int i = 0;
  376. buf = kzalloc(memblock.memory.cnt * CHUNK_INFO_SIZE, GFP_KERNEL);
  377. if (!buf) {
  378. return -ENOMEM;
  379. }
  380. for_each_memblock(memory, reg) {
  381. sprintf(buf + (i++ * CHUNK_INFO_SIZE), "%016llx %016llx ",
  382. (unsigned long long) reg->base,
  383. (unsigned long long) reg->size);
  384. }
  385. filp->private_data = buf;
  386. return nonseekable_open(inode, filp);
  387. }
  388. static int zcore_memmap_release(struct inode *inode, struct file *filp)
  389. {
  390. kfree(filp->private_data);
  391. return 0;
  392. }
  393. static const struct file_operations zcore_memmap_fops = {
  394. .owner = THIS_MODULE,
  395. .read = zcore_memmap_read,
  396. .open = zcore_memmap_open,
  397. .release = zcore_memmap_release,
  398. .llseek = no_llseek,
  399. };
  400. static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
  401. size_t count, loff_t *ppos)
  402. {
  403. if (ipl_block) {
  404. diag308(DIAG308_SET, ipl_block);
  405. diag308(DIAG308_IPL, NULL);
  406. }
  407. return count;
  408. }
  409. static int zcore_reipl_open(struct inode *inode, struct file *filp)
  410. {
  411. return nonseekable_open(inode, filp);
  412. }
  413. static int zcore_reipl_release(struct inode *inode, struct file *filp)
  414. {
  415. return 0;
  416. }
  417. static const struct file_operations zcore_reipl_fops = {
  418. .owner = THIS_MODULE,
  419. .write = zcore_reipl_write,
  420. .open = zcore_reipl_open,
  421. .release = zcore_reipl_release,
  422. .llseek = no_llseek,
  423. };
  424. static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
  425. size_t count, loff_t *ppos)
  426. {
  427. static char str[18];
  428. if (hsa_available)
  429. snprintf(str, sizeof(str), "%lx\n", sclp_get_hsa_size());
  430. else
  431. snprintf(str, sizeof(str), "0\n");
  432. return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
  433. }
  434. static ssize_t zcore_hsa_write(struct file *filp, const char __user *buf,
  435. size_t count, loff_t *ppos)
  436. {
  437. char value;
  438. if (*ppos != 0)
  439. return -EPIPE;
  440. if (copy_from_user(&value, buf, 1))
  441. return -EFAULT;
  442. if (value != '0')
  443. return -EINVAL;
  444. release_hsa();
  445. return count;
  446. }
  447. static const struct file_operations zcore_hsa_fops = {
  448. .owner = THIS_MODULE,
  449. .write = zcore_hsa_write,
  450. .read = zcore_hsa_read,
  451. .open = nonseekable_open,
  452. .llseek = no_llseek,
  453. };
  454. #ifdef CONFIG_32BIT
  455. static void __init set_lc_mask(struct save_area *map)
  456. {
  457. memset(&map->ext_save, 0xff, sizeof(map->ext_save));
  458. memset(&map->timer, 0xff, sizeof(map->timer));
  459. memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
  460. memset(&map->psw, 0xff, sizeof(map->psw));
  461. memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
  462. memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
  463. memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
  464. memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
  465. memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
  466. }
  467. #else /* CONFIG_32BIT */
  468. static void __init set_lc_mask(struct save_area *map)
  469. {
  470. memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
  471. memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
  472. memset(&map->psw, 0xff, sizeof(map->psw));
  473. memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
  474. memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
  475. memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
  476. memset(&map->timer, 0xff, sizeof(map->timer));
  477. memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
  478. memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
  479. memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
  480. }
  481. #endif /* CONFIG_32BIT */
  482. /*
  483. * Initialize dump globals for a given architecture
  484. */
  485. static int __init sys_info_init(enum arch_id arch, unsigned long mem_end)
  486. {
  487. int rc;
  488. switch (arch) {
  489. case ARCH_S390X:
  490. pr_alert("DETECTED 'S390X (64 bit) OS'\n");
  491. break;
  492. case ARCH_S390:
  493. pr_alert("DETECTED 'S390 (32 bit) OS'\n");
  494. break;
  495. default:
  496. pr_alert("0x%x is an unknown architecture.\n",arch);
  497. return -EINVAL;
  498. }
  499. sys_info.sa_base = SAVE_AREA_BASE;
  500. sys_info.sa_size = sizeof(struct save_area);
  501. sys_info.arch = arch;
  502. set_lc_mask(&sys_info.lc_mask);
  503. rc = init_cpu_info(arch);
  504. if (rc)
  505. return rc;
  506. sys_info.mem_size = mem_end;
  507. return 0;
  508. }
  509. static int __init check_sdias(void)
  510. {
  511. if (!sclp_get_hsa_size()) {
  512. TRACE("Could not determine HSA size\n");
  513. return -ENODEV;
  514. }
  515. return 0;
  516. }
  517. static int __init get_mem_info(unsigned long *mem, unsigned long *end)
  518. {
  519. struct memblock_region *reg;
  520. for_each_memblock(memory, reg) {
  521. *mem += reg->size;
  522. *end = max_t(unsigned long, *end, reg->base + reg->size);
  523. }
  524. return 0;
  525. }
  526. static void __init zcore_header_init(int arch, struct zcore_header *hdr,
  527. unsigned long mem_size)
  528. {
  529. u32 prefix;
  530. int i;
  531. if (arch == ARCH_S390X)
  532. hdr->arch_id = DUMP_ARCH_S390X;
  533. else
  534. hdr->arch_id = DUMP_ARCH_S390;
  535. hdr->mem_size = mem_size;
  536. hdr->rmem_size = mem_size;
  537. hdr->mem_end = sys_info.mem_size;
  538. hdr->num_pages = mem_size / PAGE_SIZE;
  539. hdr->tod = get_tod_clock();
  540. get_cpu_id(&hdr->cpu_id);
  541. for (i = 0; i < dump_save_areas.count; i++) {
  542. prefix = dump_save_areas.areas[i]->sa.pref_reg;
  543. hdr->real_cpu_cnt++;
  544. if (!prefix)
  545. continue;
  546. hdr->lc_vec[hdr->cpu_cnt] = prefix;
  547. hdr->cpu_cnt++;
  548. }
  549. }
  550. /*
  551. * Provide IPL parameter information block from either HSA or memory
  552. * for future reipl
  553. */
  554. static int __init zcore_reipl_init(void)
  555. {
  556. struct ipib_info ipib_info;
  557. int rc;
  558. rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
  559. if (rc)
  560. return rc;
  561. if (ipib_info.ipib == 0)
  562. return 0;
  563. ipl_block = (void *) __get_free_page(GFP_KERNEL);
  564. if (!ipl_block)
  565. return -ENOMEM;
  566. if (ipib_info.ipib < sclp_get_hsa_size())
  567. rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
  568. else
  569. rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
  570. if (rc || csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
  571. ipib_info.checksum) {
  572. TRACE("Checksum does not match\n");
  573. free_page((unsigned long) ipl_block);
  574. ipl_block = NULL;
  575. }
  576. return 0;
  577. }
  578. static int __init zcore_init(void)
  579. {
  580. unsigned long mem_size, mem_end;
  581. unsigned char arch;
  582. int rc;
  583. mem_size = mem_end = 0;
  584. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  585. return -ENODATA;
  586. if (OLDMEM_BASE)
  587. return -ENODATA;
  588. zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
  589. debug_register_view(zcore_dbf, &debug_sprintf_view);
  590. debug_set_level(zcore_dbf, 6);
  591. TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno);
  592. TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
  593. TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
  594. rc = sclp_sdias_init();
  595. if (rc)
  596. goto fail;
  597. rc = check_sdias();
  598. if (rc)
  599. goto fail;
  600. hsa_available = 1;
  601. rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
  602. if (rc)
  603. goto fail;
  604. #ifdef CONFIG_64BIT
  605. if (arch == ARCH_S390) {
  606. pr_alert("The 64-bit dump tool cannot be used for a "
  607. "32-bit system\n");
  608. rc = -EINVAL;
  609. goto fail;
  610. }
  611. #else /* CONFIG_64BIT */
  612. if (arch == ARCH_S390X) {
  613. pr_alert("The 32-bit dump tool cannot be used for a "
  614. "64-bit system\n");
  615. rc = -EINVAL;
  616. goto fail;
  617. }
  618. #endif /* CONFIG_64BIT */
  619. rc = get_mem_info(&mem_size, &mem_end);
  620. if (rc)
  621. goto fail;
  622. rc = sys_info_init(arch, mem_end);
  623. if (rc)
  624. goto fail;
  625. zcore_header_init(arch, &zcore_header, mem_size);
  626. rc = zcore_reipl_init();
  627. if (rc)
  628. goto fail;
  629. zcore_dir = debugfs_create_dir("zcore" , NULL);
  630. if (!zcore_dir) {
  631. rc = -ENOMEM;
  632. goto fail;
  633. }
  634. zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL,
  635. &zcore_fops);
  636. if (!zcore_file) {
  637. rc = -ENOMEM;
  638. goto fail_dir;
  639. }
  640. zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
  641. NULL, &zcore_memmap_fops);
  642. if (!zcore_memmap_file) {
  643. rc = -ENOMEM;
  644. goto fail_file;
  645. }
  646. zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
  647. NULL, &zcore_reipl_fops);
  648. if (!zcore_reipl_file) {
  649. rc = -ENOMEM;
  650. goto fail_memmap_file;
  651. }
  652. zcore_hsa_file = debugfs_create_file("hsa", S_IRUSR|S_IWUSR, zcore_dir,
  653. NULL, &zcore_hsa_fops);
  654. if (!zcore_hsa_file) {
  655. rc = -ENOMEM;
  656. goto fail_reipl_file;
  657. }
  658. return 0;
  659. fail_reipl_file:
  660. debugfs_remove(zcore_reipl_file);
  661. fail_memmap_file:
  662. debugfs_remove(zcore_memmap_file);
  663. fail_file:
  664. debugfs_remove(zcore_file);
  665. fail_dir:
  666. debugfs_remove(zcore_dir);
  667. fail:
  668. diag308(DIAG308_REL_HSA, NULL);
  669. return rc;
  670. }
  671. static void __exit zcore_exit(void)
  672. {
  673. debug_unregister(zcore_dbf);
  674. sclp_sdias_exit();
  675. free_page((unsigned long) ipl_block);
  676. debugfs_remove(zcore_hsa_file);
  677. debugfs_remove(zcore_reipl_file);
  678. debugfs_remove(zcore_memmap_file);
  679. debugfs_remove(zcore_file);
  680. debugfs_remove(zcore_dir);
  681. diag308(DIAG308_REL_HSA, NULL);
  682. }
  683. MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
  684. MODULE_DESCRIPTION("zcore module for zfcpdump support");
  685. MODULE_LICENSE("GPL");
  686. subsys_initcall(zcore_init);
  687. module_exit(zcore_exit);