crash_dump.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. /**
  20. * copy_oldmem_page() - copy one page from old kernel memory
  21. * @pfn: page frame number to be copied
  22. * @buf: buffer where the copied page is placed
  23. * @csize: number of bytes to copy
  24. * @offset: offset in bytes into the page
  25. * @userbuf: if set, @buf is int he user address space
  26. *
  27. * This function copies one page from old kernel memory into buffer pointed by
  28. * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes
  29. * copied or negative error in case of failure.
  30. */
  31. ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
  32. size_t csize, unsigned long offset,
  33. int userbuf)
  34. {
  35. void *vaddr;
  36. if (!csize)
  37. return 0;
  38. vaddr = ioremap(__pfn_to_phys(pfn), PAGE_SIZE);
  39. if (!vaddr)
  40. return -ENOMEM;
  41. if (userbuf) {
  42. if (copy_to_user(buf, vaddr + offset, csize)) {
  43. iounmap(vaddr);
  44. return -EFAULT;
  45. }
  46. } else {
  47. memcpy(buf, vaddr + offset, csize);
  48. }
  49. iounmap(vaddr);
  50. return csize;
  51. }