crash_dump_32.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * 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/highmem.h>
  9. #include <linux/crash_dump.h>
  10. #include <asm/uaccess.h>
  11. static void *kdump_buf_page;
  12. /**
  13. * copy_oldmem_page - copy one page from "oldmem"
  14. * @pfn: page frame number to be copied
  15. * @buf: target memory address for the copy; this can be in kernel address
  16. * space or user address space (see @userbuf)
  17. * @csize: number of bytes to copy
  18. * @offset: offset in bytes into the page (based on pfn) to begin the copy
  19. * @userbuf: if set, @buf is in user address space, use copy_to_user(),
  20. * otherwise @buf is in kernel address space, use memcpy().
  21. *
  22. * Copy a page from "oldmem". For this page, there is no pte mapped
  23. * in the current kernel. We stitch up a pte, similar to kmap_atomic.
  24. *
  25. * Calling copy_to_user() in atomic context is not desirable. Hence first
  26. * copying the data to a pre-allocated kernel page and then copying to user
  27. * space in non-atomic context.
  28. */
  29. ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
  30. size_t csize, unsigned long offset, int userbuf)
  31. {
  32. void *vaddr;
  33. if (!csize)
  34. return 0;
  35. vaddr = kmap_atomic_pfn(pfn, KM_PTE0);
  36. if (!userbuf) {
  37. memcpy(buf, (vaddr + offset), csize);
  38. kunmap_atomic(vaddr, KM_PTE0);
  39. } else {
  40. if (!kdump_buf_page) {
  41. printk(KERN_WARNING "Kdump: Kdump buffer page not"
  42. " allocated\n");
  43. kunmap_atomic(vaddr, KM_PTE0);
  44. return -EFAULT;
  45. }
  46. copy_page(kdump_buf_page, vaddr);
  47. kunmap_atomic(vaddr, KM_PTE0);
  48. if (copy_to_user(buf, (kdump_buf_page + offset), csize))
  49. return -EFAULT;
  50. }
  51. return csize;
  52. }
  53. static int __init kdump_buf_page_init(void)
  54. {
  55. int ret = 0;
  56. kdump_buf_page = kmalloc(PAGE_SIZE, GFP_KERNEL);
  57. if (!kdump_buf_page) {
  58. printk(KERN_WARNING "Kdump: Failed to allocate kdump buffer"
  59. " page\n");
  60. ret = -ENOMEM;
  61. }
  62. return ret;
  63. }
  64. arch_initcall(kdump_buf_page_init);