crash_dump.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef LINUX_CRASH_DUMP_H
  2. #define LINUX_CRASH_DUMP_H
  3. #ifdef CONFIG_CRASH_DUMP
  4. #include <linux/kexec.h>
  5. #include <linux/proc_fs.h>
  6. #include <linux/elf.h>
  7. #include <asm/pgtable.h> /* for pgprot_t */
  8. #define ELFCORE_ADDR_MAX (-1ULL)
  9. #define ELFCORE_ADDR_ERR (-2ULL)
  10. extern unsigned long long elfcorehdr_addr;
  11. extern unsigned long long elfcorehdr_size;
  12. extern int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size);
  13. extern void elfcorehdr_free(unsigned long long addr);
  14. extern ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos);
  15. extern ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos);
  16. extern int remap_oldmem_pfn_range(struct vm_area_struct *vma,
  17. unsigned long from, unsigned long pfn,
  18. unsigned long size, pgprot_t prot);
  19. extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
  20. unsigned long, int);
  21. void vmcore_cleanup(void);
  22. /* Architecture code defines this if there are other possible ELF
  23. * machine types, e.g. on bi-arch capable hardware. */
  24. #ifndef vmcore_elf_check_arch_cross
  25. #define vmcore_elf_check_arch_cross(x) 0
  26. #endif
  27. /*
  28. * Architecture code can redefine this if there are any special checks
  29. * needed for 32-bit ELF or 64-bit ELF vmcores. In case of 32-bit
  30. * only architecture, vmcore_elf64_check_arch can be set to zero.
  31. */
  32. #ifndef vmcore_elf32_check_arch
  33. #define vmcore_elf32_check_arch(x) elf_check_arch(x)
  34. #endif
  35. #ifndef vmcore_elf64_check_arch
  36. #define vmcore_elf64_check_arch(x) (elf_check_arch(x) || vmcore_elf_check_arch_cross(x))
  37. #endif
  38. /*
  39. * is_kdump_kernel() checks whether this kernel is booting after a panic of
  40. * previous kernel or not. This is determined by checking if previous kernel
  41. * has passed the elf core header address on command line.
  42. *
  43. * This is not just a test if CONFIG_CRASH_DUMP is enabled or not. It will
  44. * return 1 if CONFIG_CRASH_DUMP=y and if kernel is booting after a panic of
  45. * previous kernel.
  46. */
  47. static inline int is_kdump_kernel(void)
  48. {
  49. return (elfcorehdr_addr != ELFCORE_ADDR_MAX) ? 1 : 0;
  50. }
  51. /* is_vmcore_usable() checks if the kernel is booting after a panic and
  52. * the vmcore region is usable.
  53. *
  54. * This makes use of the fact that due to alignment -2ULL is not
  55. * a valid pointer, much in the vain of IS_ERR(), except
  56. * dealing directly with an unsigned long long rather than a pointer.
  57. */
  58. static inline int is_vmcore_usable(void)
  59. {
  60. return is_kdump_kernel() && elfcorehdr_addr != ELFCORE_ADDR_ERR ? 1 : 0;
  61. }
  62. /* vmcore_unusable() marks the vmcore as unusable,
  63. * without disturbing the logic of is_kdump_kernel()
  64. */
  65. static inline void vmcore_unusable(void)
  66. {
  67. if (is_kdump_kernel())
  68. elfcorehdr_addr = ELFCORE_ADDR_ERR;
  69. }
  70. #define HAVE_OLDMEM_PFN_IS_RAM 1
  71. extern int register_oldmem_pfn_is_ram(int (*fn)(unsigned long pfn));
  72. extern void unregister_oldmem_pfn_is_ram(void);
  73. #else /* !CONFIG_CRASH_DUMP */
  74. static inline int is_kdump_kernel(void) { return 0; }
  75. #endif /* CONFIG_CRASH_DUMP */
  76. extern unsigned long saved_max_pfn;
  77. #endif /* LINUX_CRASHDUMP_H */