fadump-internal.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Firmware-Assisted Dump internal code.
  4. *
  5. * Copyright 2011, Mahesh Salgaonkar, IBM Corporation.
  6. * Copyright 2019, Hari Bathini, IBM Corporation.
  7. */
  8. #ifndef _ASM_POWERPC_FADUMP_INTERNAL_H
  9. #define _ASM_POWERPC_FADUMP_INTERNAL_H
  10. /* Maximum number of memory regions kernel supports */
  11. #define FADUMP_MAX_MEM_REGS 128
  12. #ifndef CONFIG_PRESERVE_FA_DUMP
  13. /* The upper limit percentage for user specified boot memory size (25%) */
  14. #define MAX_BOOT_MEM_RATIO 4
  15. #define memblock_num_regions(memblock_type) (memblock.memblock_type.cnt)
  16. /* FAD commands */
  17. #define FADUMP_REGISTER 1
  18. #define FADUMP_UNREGISTER 2
  19. #define FADUMP_INVALIDATE 3
  20. /*
  21. * Copy the ascii values for first 8 characters from a string into u64
  22. * variable at their respective indexes.
  23. * e.g.
  24. * The string "FADMPINF" will be converted into 0x4641444d50494e46
  25. */
  26. static inline u64 fadump_str_to_u64(const char *str)
  27. {
  28. u64 val = 0;
  29. int i;
  30. for (i = 0; i < sizeof(val); i++)
  31. val = (*str) ? (val << 8) | *str++ : val << 8;
  32. return val;
  33. }
  34. #define FADUMP_CPU_UNKNOWN (~((u32)0))
  35. #define FADUMP_CRASH_INFO_MAGIC fadump_str_to_u64("FADMPINF")
  36. /* fadump crash info structure */
  37. struct fadump_crash_info_header {
  38. u64 magic_number;
  39. u64 elfcorehdr_addr;
  40. u32 crashing_cpu;
  41. struct pt_regs regs;
  42. struct cpumask cpu_mask;
  43. };
  44. struct fadump_memory_range {
  45. u64 base;
  46. u64 size;
  47. };
  48. /* fadump memory ranges info */
  49. #define RNG_NAME_SZ 16
  50. struct fadump_mrange_info {
  51. char name[RNG_NAME_SZ];
  52. struct fadump_memory_range *mem_ranges;
  53. u32 mem_ranges_sz;
  54. u32 mem_range_cnt;
  55. u32 max_mem_ranges;
  56. bool is_static;
  57. };
  58. /* Platform specific callback functions */
  59. struct fadump_ops;
  60. /* Firmware-assisted dump configuration details. */
  61. struct fw_dump {
  62. unsigned long reserve_dump_area_start;
  63. unsigned long reserve_dump_area_size;
  64. /* cmd line option during boot */
  65. unsigned long reserve_bootvar;
  66. unsigned long cpu_state_data_size;
  67. u64 cpu_state_dest_vaddr;
  68. u32 cpu_state_data_version;
  69. u32 cpu_state_entry_size;
  70. unsigned long hpte_region_size;
  71. unsigned long boot_memory_size;
  72. u64 boot_mem_dest_addr;
  73. u64 boot_mem_addr[FADUMP_MAX_MEM_REGS];
  74. u64 boot_mem_sz[FADUMP_MAX_MEM_REGS];
  75. u64 boot_mem_top;
  76. u64 boot_mem_regs_cnt;
  77. unsigned long fadumphdr_addr;
  78. unsigned long cpu_notes_buf_vaddr;
  79. unsigned long cpu_notes_buf_size;
  80. /*
  81. * Maximum size supported by firmware to copy from source to
  82. * destination address per entry.
  83. */
  84. u64 max_copy_size;
  85. u64 kernel_metadata;
  86. int ibm_configure_kernel_dump;
  87. unsigned long fadump_enabled:1;
  88. unsigned long fadump_supported:1;
  89. unsigned long dump_active:1;
  90. unsigned long dump_registered:1;
  91. unsigned long nocma:1;
  92. struct fadump_ops *ops;
  93. };
  94. struct fadump_ops {
  95. u64 (*fadump_init_mem_struct)(struct fw_dump *fadump_conf);
  96. u64 (*fadump_get_metadata_size)(void);
  97. int (*fadump_setup_metadata)(struct fw_dump *fadump_conf);
  98. u64 (*fadump_get_bootmem_min)(void);
  99. int (*fadump_register)(struct fw_dump *fadump_conf);
  100. int (*fadump_unregister)(struct fw_dump *fadump_conf);
  101. int (*fadump_invalidate)(struct fw_dump *fadump_conf);
  102. void (*fadump_cleanup)(struct fw_dump *fadump_conf);
  103. int (*fadump_process)(struct fw_dump *fadump_conf);
  104. void (*fadump_region_show)(struct fw_dump *fadump_conf,
  105. struct seq_file *m);
  106. void (*fadump_trigger)(struct fadump_crash_info_header *fdh,
  107. const char *msg);
  108. };
  109. /* Helper functions */
  110. s32 __init fadump_setup_cpu_notes_buf(u32 num_cpus);
  111. void fadump_free_cpu_notes_buf(void);
  112. u32 *__init fadump_regs_to_elf_notes(u32 *buf, struct pt_regs *regs);
  113. void __init fadump_update_elfcore_header(char *bufp);
  114. bool is_fadump_boot_mem_contiguous(void);
  115. bool is_fadump_reserved_mem_contiguous(void);
  116. #else /* !CONFIG_PRESERVE_FA_DUMP */
  117. /* Firmware-assisted dump configuration details. */
  118. struct fw_dump {
  119. u64 boot_mem_top;
  120. u64 dump_active;
  121. };
  122. #endif /* CONFIG_PRESERVE_FA_DUMP */
  123. #ifdef CONFIG_PPC_PSERIES
  124. extern void rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
  125. #else
  126. static inline void
  127. rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
  128. #endif
  129. #ifdef CONFIG_PPC_POWERNV
  130. extern void opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
  131. #else
  132. static inline void
  133. opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
  134. #endif
  135. #endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */