zcore.c 19 KB

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