crash_dump.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * arch/arm/kernel/crash_dump.c
  3. *
  4. * Copyright (C) 2010 Nokia Corporation.
  5. * Author: Mika Westerberg
  6. *
  7. * This code is taken from arch/x86/kernel/crash_dump_64.c
  8. * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
  9. * Copyright (C) IBM Corporation, 2004. All rights reserved
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/errno.h>
  16. #include <linux/crash_dump.h>
  17. #include <linux/uaccess.h>
  18. #include <linux/io.h>
  19. /* stores the physical address of elf header of crash image */
  20. unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
  21. /**
  22. * copy_oldmem_page() - copy one page from old kernel memory
  23. * @pfn: page frame number to be copied
  24. * @buf: buffer where the copied page is placed
  25. * @csize: number of bytes to copy
  26. * @offset: offset in bytes into the page
  27. * @userbuf: if set, @buf is int he user address space
  28. *
  29. * This function copies one page from old kernel memory into buffer pointed by
  30. * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes
  31. * copied or negative error in case of failure.
  32. */
  33. ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
  34. size_t csize, unsigned long offset,
  35. int userbuf)
  36. {
  37. void *vaddr;
  38. if (!csize)
  39. return 0;
  40. vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE);
  41. if (!vaddr)
  42. return -ENOMEM;
  43. if (userbuf) {
  44. if (copy_to_user(buf, vaddr + offset, csize)) {
  45. iounmap(vaddr);
  46. return -EFAULT;
  47. }
  48. } else {
  49. memcpy(buf, vaddr + offset, csize);
  50. }
  51. iounmap(vaddr);
  52. return csize;
  53. }