zcore.c 19 KB

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