zcore.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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 <asm/asm-offsets.h>
  18. #include <asm/ipl.h>
  19. #include <asm/sclp.h>
  20. #include <asm/setup.h>
  21. #include <asm/sigp.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/debug.h>
  24. #include <asm/processor.h>
  25. #include <asm/irqflags.h>
  26. #include <asm/checksum.h>
  27. #include "sclp.h"
  28. #define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
  29. #define TO_USER 0
  30. #define TO_KERNEL 1
  31. #define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */
  32. enum arch_id {
  33. ARCH_S390 = 0,
  34. ARCH_S390X = 1,
  35. };
  36. /* dump system info */
  37. struct sys_info {
  38. enum arch_id arch;
  39. unsigned long sa_base;
  40. u32 sa_size;
  41. int cpu_map[NR_CPUS];
  42. unsigned long mem_size;
  43. struct save_area lc_mask;
  44. };
  45. struct ipib_info {
  46. unsigned long ipib;
  47. u32 checksum;
  48. } __attribute__((packed));
  49. static struct sys_info sys_info;
  50. static struct debug_info *zcore_dbf;
  51. static int hsa_available;
  52. static struct dentry *zcore_dir;
  53. static struct dentry *zcore_file;
  54. static struct dentry *zcore_memmap_file;
  55. static struct dentry *zcore_reipl_file;
  56. static struct ipl_parameter_block *ipl_block;
  57. /*
  58. * Copy memory from HSA to kernel or user memory (not reentrant):
  59. *
  60. * @dest: Kernel or user buffer where memory should be copied to
  61. * @src: Start address within HSA where data should be copied
  62. * @count: Size of buffer, which should be copied
  63. * @mode: Either TO_KERNEL or TO_USER
  64. */
  65. static int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode)
  66. {
  67. int offs, blk_num;
  68. static char buf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
  69. if (count == 0)
  70. return 0;
  71. /* copy first block */
  72. offs = 0;
  73. if ((src % PAGE_SIZE) != 0) {
  74. blk_num = src / PAGE_SIZE + 2;
  75. if (sclp_sdias_copy(buf, blk_num, 1)) {
  76. TRACE("sclp_sdias_copy() failed\n");
  77. return -EIO;
  78. }
  79. offs = min((PAGE_SIZE - (src % PAGE_SIZE)), count);
  80. if (mode == TO_USER) {
  81. if (copy_to_user((__force __user void*) dest,
  82. buf + (src % PAGE_SIZE), offs))
  83. return -EFAULT;
  84. } else
  85. memcpy(dest, buf + (src % PAGE_SIZE), offs);
  86. }
  87. if (offs == count)
  88. goto out;
  89. /* copy middle */
  90. for (; (offs + PAGE_SIZE) <= count; offs += PAGE_SIZE) {
  91. blk_num = (src + offs) / PAGE_SIZE + 2;
  92. if (sclp_sdias_copy(buf, blk_num, 1)) {
  93. TRACE("sclp_sdias_copy() failed\n");
  94. return -EIO;
  95. }
  96. if (mode == TO_USER) {
  97. if (copy_to_user((__force __user void*) dest + offs,
  98. buf, PAGE_SIZE))
  99. return -EFAULT;
  100. } else
  101. memcpy(dest + offs, buf, PAGE_SIZE);
  102. }
  103. if (offs == count)
  104. goto out;
  105. /* copy last block */
  106. blk_num = (src + offs) / PAGE_SIZE + 2;
  107. if (sclp_sdias_copy(buf, blk_num, 1)) {
  108. TRACE("sclp_sdias_copy() failed\n");
  109. return -EIO;
  110. }
  111. if (mode == TO_USER) {
  112. if (copy_to_user((__force __user void*) dest + offs, buf,
  113. PAGE_SIZE))
  114. return -EFAULT;
  115. } else
  116. memcpy(dest + offs, buf, count - offs);
  117. out:
  118. return 0;
  119. }
  120. static int memcpy_hsa_user(void __user *dest, unsigned long src, size_t count)
  121. {
  122. return memcpy_hsa((void __force *) dest, src, count, TO_USER);
  123. }
  124. static int memcpy_hsa_kernel(void *dest, unsigned long src, size_t count)
  125. {
  126. return memcpy_hsa(dest, src, count, TO_KERNEL);
  127. }
  128. static int memcpy_real_user(void __user *dest, unsigned long src, size_t count)
  129. {
  130. static char buf[4096];
  131. int offs = 0, size;
  132. while (offs < count) {
  133. size = min(sizeof(buf), count - offs);
  134. if (memcpy_real(buf, (void *) src + offs, size))
  135. return -EFAULT;
  136. if (copy_to_user(dest + offs, buf, size))
  137. return -EFAULT;
  138. offs += size;
  139. }
  140. return 0;
  141. }
  142. static int __init init_cpu_info(enum arch_id arch)
  143. {
  144. struct save_area *sa;
  145. /* get info for boot cpu from lowcore, stored in the HSA */
  146. sa = kmalloc(sizeof(*sa), GFP_KERNEL);
  147. if (!sa)
  148. return -ENOMEM;
  149. if (memcpy_hsa_kernel(sa, sys_info.sa_base, sys_info.sa_size) < 0) {
  150. TRACE("could not copy from HSA\n");
  151. kfree(sa);
  152. return -EIO;
  153. }
  154. zfcpdump_save_areas[0] = sa;
  155. return 0;
  156. }
  157. static DEFINE_MUTEX(zcore_mutex);
  158. #define DUMP_VERSION 0x5
  159. #define DUMP_MAGIC 0xa8190173618f23fdULL
  160. #define DUMP_ARCH_S390X 2
  161. #define DUMP_ARCH_S390 1
  162. #define HEADER_SIZE 4096
  163. /* dump header dumped according to s390 crash dump format */
  164. struct zcore_header {
  165. u64 magic;
  166. u32 version;
  167. u32 header_size;
  168. u32 dump_level;
  169. u32 page_size;
  170. u64 mem_size;
  171. u64 mem_start;
  172. u64 mem_end;
  173. u32 num_pages;
  174. u32 pad1;
  175. u64 tod;
  176. struct cpuid cpu_id;
  177. u32 arch_id;
  178. u32 volnr;
  179. u32 build_arch;
  180. u64 rmem_size;
  181. u8 mvdump;
  182. u16 cpu_cnt;
  183. u16 real_cpu_cnt;
  184. u8 end_pad1[0x200-0x061];
  185. u64 mvdump_sign;
  186. u64 mvdump_zipl_time;
  187. u8 end_pad2[0x800-0x210];
  188. u32 lc_vec[512];
  189. } __attribute__((packed,__aligned__(16)));
  190. static struct zcore_header zcore_header = {
  191. .magic = DUMP_MAGIC,
  192. .version = DUMP_VERSION,
  193. .header_size = 4096,
  194. .dump_level = 0,
  195. .page_size = PAGE_SIZE,
  196. .mem_start = 0,
  197. #ifdef CONFIG_64BIT
  198. .build_arch = DUMP_ARCH_S390X,
  199. #else
  200. .build_arch = DUMP_ARCH_S390,
  201. #endif
  202. };
  203. /*
  204. * Copy lowcore info to buffer. Use map in order to copy only register parts.
  205. *
  206. * @buf: User buffer
  207. * @sa: Pointer to save area
  208. * @sa_off: Offset in save area to copy
  209. * @len: Number of bytes to copy
  210. */
  211. static int copy_lc(void __user *buf, void *sa, int sa_off, int len)
  212. {
  213. int i;
  214. char *lc_mask = (char*)&sys_info.lc_mask;
  215. for (i = 0; i < len; i++) {
  216. if (!lc_mask[i + sa_off])
  217. continue;
  218. if (copy_to_user(buf + i, sa + sa_off + i, 1))
  219. return -EFAULT;
  220. }
  221. return 0;
  222. }
  223. /*
  224. * Copy lowcores info to memory, if necessary
  225. *
  226. * @buf: User buffer
  227. * @addr: Start address of buffer in dump memory
  228. * @count: Size of buffer
  229. */
  230. static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
  231. {
  232. unsigned long end;
  233. int i = 0;
  234. if (count == 0)
  235. return 0;
  236. end = start + count;
  237. while (zfcpdump_save_areas[i]) {
  238. unsigned long cp_start, cp_end; /* copy range */
  239. unsigned long sa_start, sa_end; /* save area range */
  240. unsigned long prefix;
  241. unsigned long sa_off, len, buf_off;
  242. prefix = zfcpdump_save_areas[i]->pref_reg;
  243. sa_start = prefix + sys_info.sa_base;
  244. sa_end = prefix + sys_info.sa_base + sys_info.sa_size;
  245. if ((end < sa_start) || (start > sa_end))
  246. goto next;
  247. cp_start = max(start, sa_start);
  248. cp_end = min(end, sa_end);
  249. buf_off = cp_start - start;
  250. sa_off = cp_start - sa_start;
  251. len = cp_end - cp_start;
  252. TRACE("copy_lc for: %lx\n", start);
  253. if (copy_lc(buf + buf_off, zfcpdump_save_areas[i], sa_off, len))
  254. return -EFAULT;
  255. next:
  256. i++;
  257. }
  258. return 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 < (ZFCPDUMP_HSA_SIZE + HEADER_SIZE)) {
  296. size = min((count - hdr_count), (size_t) (ZFCPDUMP_HSA_SIZE
  297. - 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 = memcpy_real_user(buf + hdr_count + mem_offs, mem_start + mem_offs,
  306. 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. diag308(DIAG308_REL_HSA, NULL);
  336. hsa_available = 0;
  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. MEMORY_CHUNKS * CHUNK_INFO_SIZE);
  370. }
  371. static int zcore_memmap_open(struct inode *inode, struct file *filp)
  372. {
  373. int i;
  374. char *buf;
  375. struct mem_chunk *chunk_array;
  376. chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
  377. GFP_KERNEL);
  378. if (!chunk_array)
  379. return -ENOMEM;
  380. detect_memory_layout(chunk_array);
  381. buf = kzalloc(MEMORY_CHUNKS * CHUNK_INFO_SIZE, GFP_KERNEL);
  382. if (!buf) {
  383. kfree(chunk_array);
  384. return -ENOMEM;
  385. }
  386. for (i = 0; i < MEMORY_CHUNKS; i++) {
  387. sprintf(buf + (i * CHUNK_INFO_SIZE), "%016llx %016llx ",
  388. (unsigned long long) chunk_array[i].addr,
  389. (unsigned long long) chunk_array[i].size);
  390. if (chunk_array[i].size == 0)
  391. break;
  392. }
  393. kfree(chunk_array);
  394. filp->private_data = buf;
  395. return nonseekable_open(inode, filp);
  396. }
  397. static int zcore_memmap_release(struct inode *inode, struct file *filp)
  398. {
  399. kfree(filp->private_data);
  400. return 0;
  401. }
  402. static const struct file_operations zcore_memmap_fops = {
  403. .owner = THIS_MODULE,
  404. .read = zcore_memmap_read,
  405. .open = zcore_memmap_open,
  406. .release = zcore_memmap_release,
  407. .llseek = no_llseek,
  408. };
  409. static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
  410. size_t count, loff_t *ppos)
  411. {
  412. if (ipl_block) {
  413. diag308(DIAG308_SET, ipl_block);
  414. diag308(DIAG308_IPL, NULL);
  415. }
  416. return count;
  417. }
  418. static int zcore_reipl_open(struct inode *inode, struct file *filp)
  419. {
  420. return nonseekable_open(inode, filp);
  421. }
  422. static int zcore_reipl_release(struct inode *inode, struct file *filp)
  423. {
  424. return 0;
  425. }
  426. static const struct file_operations zcore_reipl_fops = {
  427. .owner = THIS_MODULE,
  428. .write = zcore_reipl_write,
  429. .open = zcore_reipl_open,
  430. .release = zcore_reipl_release,
  431. .llseek = no_llseek,
  432. };
  433. #ifdef CONFIG_32BIT
  434. static void __init set_lc_mask(struct save_area *map)
  435. {
  436. memset(&map->ext_save, 0xff, sizeof(map->ext_save));
  437. memset(&map->timer, 0xff, sizeof(map->timer));
  438. memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
  439. memset(&map->psw, 0xff, sizeof(map->psw));
  440. memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
  441. memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
  442. memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
  443. memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
  444. memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
  445. }
  446. #else /* CONFIG_32BIT */
  447. static void __init set_lc_mask(struct save_area *map)
  448. {
  449. memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
  450. memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
  451. memset(&map->psw, 0xff, sizeof(map->psw));
  452. memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
  453. memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
  454. memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
  455. memset(&map->timer, 0xff, sizeof(map->timer));
  456. memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
  457. memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
  458. memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
  459. }
  460. #endif /* CONFIG_32BIT */
  461. /*
  462. * Initialize dump globals for a given architecture
  463. */
  464. static int __init sys_info_init(enum arch_id arch)
  465. {
  466. int rc;
  467. switch (arch) {
  468. case ARCH_S390X:
  469. pr_alert("DETECTED 'S390X (64 bit) OS'\n");
  470. break;
  471. case ARCH_S390:
  472. pr_alert("DETECTED 'S390 (32 bit) OS'\n");
  473. break;
  474. default:
  475. pr_alert("0x%x is an unknown architecture.\n",arch);
  476. return -EINVAL;
  477. }
  478. sys_info.sa_base = SAVE_AREA_BASE;
  479. sys_info.sa_size = sizeof(struct save_area);
  480. sys_info.arch = arch;
  481. set_lc_mask(&sys_info.lc_mask);
  482. rc = init_cpu_info(arch);
  483. if (rc)
  484. return rc;
  485. sys_info.mem_size = real_memory_size;
  486. return 0;
  487. }
  488. static int __init check_sdias(void)
  489. {
  490. int rc, act_hsa_size;
  491. rc = sclp_sdias_blk_count();
  492. if (rc < 0) {
  493. TRACE("Could not determine HSA size\n");
  494. return rc;
  495. }
  496. act_hsa_size = (rc - 1) * PAGE_SIZE;
  497. if (act_hsa_size < ZFCPDUMP_HSA_SIZE) {
  498. TRACE("HSA size too small: %i\n", act_hsa_size);
  499. return -EINVAL;
  500. }
  501. return 0;
  502. }
  503. static int __init get_mem_size(unsigned long *mem)
  504. {
  505. int i;
  506. struct mem_chunk *chunk_array;
  507. chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk),
  508. GFP_KERNEL);
  509. if (!chunk_array)
  510. return -ENOMEM;
  511. detect_memory_layout(chunk_array);
  512. for (i = 0; i < MEMORY_CHUNKS; i++) {
  513. if (chunk_array[i].size == 0)
  514. break;
  515. *mem += chunk_array[i].size;
  516. }
  517. kfree(chunk_array);
  518. return 0;
  519. }
  520. static int __init zcore_header_init(int arch, struct zcore_header *hdr)
  521. {
  522. int rc, i;
  523. unsigned long memory = 0;
  524. u32 prefix;
  525. if (arch == ARCH_S390X)
  526. hdr->arch_id = DUMP_ARCH_S390X;
  527. else
  528. hdr->arch_id = DUMP_ARCH_S390;
  529. rc = get_mem_size(&memory);
  530. if (rc)
  531. return rc;
  532. hdr->mem_size = memory;
  533. hdr->rmem_size = memory;
  534. hdr->mem_end = sys_info.mem_size;
  535. hdr->num_pages = memory / PAGE_SIZE;
  536. hdr->tod = get_clock();
  537. get_cpu_id(&hdr->cpu_id);
  538. for (i = 0; zfcpdump_save_areas[i]; i++) {
  539. prefix = zfcpdump_save_areas[i]->pref_reg;
  540. hdr->real_cpu_cnt++;
  541. if (!prefix)
  542. continue;
  543. hdr->lc_vec[hdr->cpu_cnt] = prefix;
  544. hdr->cpu_cnt++;
  545. }
  546. return 0;
  547. }
  548. /*
  549. * Provide IPL parameter information block from either HSA or memory
  550. * for future reipl
  551. */
  552. static int __init zcore_reipl_init(void)
  553. {
  554. struct ipib_info ipib_info;
  555. int rc;
  556. rc = memcpy_hsa_kernel(&ipib_info, __LC_DUMP_REIPL, sizeof(ipib_info));
  557. if (rc)
  558. return rc;
  559. if (ipib_info.ipib == 0)
  560. return 0;
  561. ipl_block = (void *) __get_free_page(GFP_KERNEL);
  562. if (!ipl_block)
  563. return -ENOMEM;
  564. if (ipib_info.ipib < ZFCPDUMP_HSA_SIZE)
  565. rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
  566. else
  567. rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
  568. if (rc || csum_partial(ipl_block, ipl_block->hdr.len, 0) !=
  569. ipib_info.checksum) {
  570. TRACE("Checksum does not match\n");
  571. free_page((unsigned long) ipl_block);
  572. ipl_block = NULL;
  573. }
  574. return 0;
  575. }
  576. static int __init zcore_init(void)
  577. {
  578. unsigned char arch;
  579. int rc;
  580. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  581. return -ENODATA;
  582. zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
  583. debug_register_view(zcore_dbf, &debug_sprintf_view);
  584. debug_set_level(zcore_dbf, 6);
  585. TRACE("devno: %x\n", ipl_info.data.fcp.dev_id.devno);
  586. TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
  587. TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
  588. rc = sclp_sdias_init();
  589. if (rc)
  590. goto fail;
  591. rc = check_sdias();
  592. if (rc)
  593. goto fail;
  594. rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
  595. if (rc)
  596. goto fail;
  597. #ifdef CONFIG_64BIT
  598. if (arch == ARCH_S390) {
  599. pr_alert("The 64-bit dump tool cannot be used for a "
  600. "32-bit system\n");
  601. rc = -EINVAL;
  602. goto fail;
  603. }
  604. #else /* CONFIG_64BIT */
  605. if (arch == ARCH_S390X) {
  606. pr_alert("The 32-bit dump tool cannot be used for a "
  607. "64-bit system\n");
  608. rc = -EINVAL;
  609. goto fail;
  610. }
  611. #endif /* CONFIG_64BIT */
  612. rc = sys_info_init(arch);
  613. if (rc)
  614. goto fail;
  615. rc = zcore_header_init(arch, &zcore_header);
  616. if (rc)
  617. goto fail;
  618. rc = zcore_reipl_init();
  619. if (rc)
  620. goto fail;
  621. zcore_dir = debugfs_create_dir("zcore" , NULL);
  622. if (!zcore_dir) {
  623. rc = -ENOMEM;
  624. goto fail;
  625. }
  626. zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL,
  627. &zcore_fops);
  628. if (!zcore_file) {
  629. rc = -ENOMEM;
  630. goto fail_dir;
  631. }
  632. zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir,
  633. NULL, &zcore_memmap_fops);
  634. if (!zcore_memmap_file) {
  635. rc = -ENOMEM;
  636. goto fail_file;
  637. }
  638. zcore_reipl_file = debugfs_create_file("reipl", S_IRUSR, zcore_dir,
  639. NULL, &zcore_reipl_fops);
  640. if (!zcore_reipl_file) {
  641. rc = -ENOMEM;
  642. goto fail_memmap_file;
  643. }
  644. hsa_available = 1;
  645. return 0;
  646. fail_memmap_file:
  647. debugfs_remove(zcore_memmap_file);
  648. fail_file:
  649. debugfs_remove(zcore_file);
  650. fail_dir:
  651. debugfs_remove(zcore_dir);
  652. fail:
  653. diag308(DIAG308_REL_HSA, NULL);
  654. return rc;
  655. }
  656. static void __exit zcore_exit(void)
  657. {
  658. debug_unregister(zcore_dbf);
  659. sclp_sdias_exit();
  660. free_page((unsigned long) ipl_block);
  661. debugfs_remove(zcore_reipl_file);
  662. debugfs_remove(zcore_memmap_file);
  663. debugfs_remove(zcore_file);
  664. debugfs_remove(zcore_dir);
  665. diag308(DIAG308_REL_HSA, NULL);
  666. }
  667. MODULE_AUTHOR("Copyright IBM Corp. 2003,2008");
  668. MODULE_DESCRIPTION("zcore module for zfcpdump support");
  669. MODULE_LICENSE("GPL");
  670. subsys_initcall(zcore_init);
  671. module_exit(zcore_exit);