crash_dump.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * crash_dump.c - Memory preserving reboot related code.
  3. *
  4. * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
  5. * Copyright (C) IBM Corporation, 2004. All rights reserved
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/crash_dump.h>
  9. #include <linux/io.h>
  10. #include <asm/uaccess.h>
  11. /* Stores the physical address of elf header of crash image. */
  12. unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
  13. /*
  14. * Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
  15. * is_kdump_kernel() to determine if we are booting after a panic. Hence
  16. * ifdef it under CONFIG_CRASH_DUMP and not CONFIG_PROC_VMCORE.
  17. *
  18. * elfcorehdr= specifies the location of elf core header
  19. * stored by the crashed kernel.
  20. */
  21. static int __init parse_elfcorehdr(char *arg)
  22. {
  23. if (!arg)
  24. return -EINVAL;
  25. elfcorehdr_addr = memparse(arg, &arg);
  26. return 0;
  27. }
  28. early_param("elfcorehdr", parse_elfcorehdr);
  29. /**
  30. * copy_oldmem_page - copy one page from "oldmem"
  31. * @pfn: page frame number to be copied
  32. * @buf: target memory address for the copy; this can be in kernel address
  33. * space or user address space (see @userbuf)
  34. * @csize: number of bytes to copy
  35. * @offset: offset in bytes into the page (based on pfn) to begin the copy
  36. * @userbuf: if set, @buf is in user address space, use copy_to_user(),
  37. * otherwise @buf is in kernel address space, use memcpy().
  38. *
  39. * Copy a page from "oldmem". For this page, there is no pte mapped
  40. * in the current kernel. We stitch up a pte, similar to kmap_atomic.
  41. */
  42. ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
  43. size_t csize, unsigned long offset, int userbuf)
  44. {
  45. void *vaddr;
  46. if (!csize)
  47. return 0;
  48. vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE);
  49. if (userbuf) {
  50. if (copy_to_user(buf, (vaddr + offset), csize)) {
  51. iounmap(vaddr);
  52. return -EFAULT;
  53. }
  54. } else
  55. memcpy(buf, (vaddr + offset), csize);
  56. iounmap(vaddr);
  57. return csize;
  58. }