zcore.c 17 KB

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