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