fadump.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Firmware Assisted dump header file.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright 2011 IBM Corporation
  19. * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
  20. */
  21. #ifndef __PPC64_FA_DUMP_H__
  22. #define __PPC64_FA_DUMP_H__
  23. #ifdef CONFIG_FA_DUMP
  24. /*
  25. * The RMA region will be saved for later dumping when kernel crashes.
  26. * RMA is Real Mode Area, the first block of logical memory address owned
  27. * by logical partition, containing the storage that may be accessed with
  28. * translate off.
  29. */
  30. #define RMA_START 0x0
  31. #define RMA_END (ppc64_rma_size)
  32. /*
  33. * On some Power systems where RMO is 128MB, it still requires minimum of
  34. * 256MB for kernel to boot successfully. When kdump infrastructure is
  35. * configured to save vmcore over network, we run into OOM issue while
  36. * loading modules related to network setup. Hence we need aditional 64M
  37. * of memory to avoid OOM issue.
  38. */
  39. #define MIN_BOOT_MEM (((RMA_END < (0x1UL << 28)) ? (0x1UL << 28) : RMA_END) \
  40. + (0x1UL << 26))
  41. #define memblock_num_regions(memblock_type) (memblock.memblock_type.cnt)
  42. #ifndef ELF_CORE_EFLAGS
  43. #define ELF_CORE_EFLAGS 0
  44. #endif
  45. /* Firmware provided dump sections */
  46. #define FADUMP_CPU_STATE_DATA 0x0001
  47. #define FADUMP_HPTE_REGION 0x0002
  48. #define FADUMP_REAL_MODE_REGION 0x0011
  49. /* Dump request flag */
  50. #define FADUMP_REQUEST_FLAG 0x00000001
  51. /* FAD commands */
  52. #define FADUMP_REGISTER 1
  53. #define FADUMP_UNREGISTER 2
  54. #define FADUMP_INVALIDATE 3
  55. /* Dump status flag */
  56. #define FADUMP_ERROR_FLAG 0x2000
  57. #define FADUMP_CPU_ID_MASK ((1UL << 32) - 1)
  58. #define CPU_UNKNOWN (~((u32)0))
  59. /* Utility macros */
  60. #define SKIP_TO_NEXT_CPU(reg_entry) \
  61. ({ \
  62. while (be64_to_cpu(reg_entry->reg_id) != REG_ID("CPUEND")) \
  63. reg_entry++; \
  64. reg_entry++; \
  65. })
  66. /* Kernel Dump section info */
  67. struct fadump_section {
  68. __be32 request_flag;
  69. __be16 source_data_type;
  70. __be16 error_flags;
  71. __be64 source_address;
  72. __be64 source_len;
  73. __be64 bytes_dumped;
  74. __be64 destination_address;
  75. };
  76. /* ibm,configure-kernel-dump header. */
  77. struct fadump_section_header {
  78. __be32 dump_format_version;
  79. __be16 dump_num_sections;
  80. __be16 dump_status_flag;
  81. __be32 offset_first_dump_section;
  82. /* Fields for disk dump option. */
  83. __be32 dd_block_size;
  84. __be64 dd_block_offset;
  85. __be64 dd_num_blocks;
  86. __be32 dd_offset_disk_path;
  87. /* Maximum time allowed to prevent an automatic dump-reboot. */
  88. __be32 max_time_auto;
  89. };
  90. /*
  91. * Firmware Assisted dump memory structure. This structure is required for
  92. * registering future kernel dump with power firmware through rtas call.
  93. *
  94. * No disk dump option. Hence disk dump path string section is not included.
  95. */
  96. struct fadump_mem_struct {
  97. struct fadump_section_header header;
  98. /* Kernel dump sections */
  99. struct fadump_section cpu_state_data;
  100. struct fadump_section hpte_region;
  101. struct fadump_section rmr_region;
  102. };
  103. /* Firmware-assisted dump configuration details. */
  104. struct fw_dump {
  105. unsigned long cpu_state_data_size;
  106. unsigned long hpte_region_size;
  107. unsigned long boot_memory_size;
  108. unsigned long reserve_dump_area_start;
  109. unsigned long reserve_dump_area_size;
  110. /* cmd line option during boot */
  111. unsigned long reserve_bootvar;
  112. unsigned long fadumphdr_addr;
  113. unsigned long cpu_notes_buf;
  114. unsigned long cpu_notes_buf_size;
  115. int ibm_configure_kernel_dump;
  116. unsigned long fadump_enabled:1;
  117. unsigned long fadump_supported:1;
  118. unsigned long dump_active:1;
  119. unsigned long dump_registered:1;
  120. };
  121. /*
  122. * Copy the ascii values for first 8 characters from a string into u64
  123. * variable at their respective indexes.
  124. * e.g.
  125. * The string "FADMPINF" will be converted into 0x4641444d50494e46
  126. */
  127. static inline u64 str_to_u64(const char *str)
  128. {
  129. u64 val = 0;
  130. int i;
  131. for (i = 0; i < sizeof(val); i++)
  132. val = (*str) ? (val << 8) | *str++ : val << 8;
  133. return val;
  134. }
  135. #define STR_TO_HEX(x) str_to_u64(x)
  136. #define REG_ID(x) str_to_u64(x)
  137. #define FADUMP_CRASH_INFO_MAGIC STR_TO_HEX("FADMPINF")
  138. #define REGSAVE_AREA_MAGIC STR_TO_HEX("REGSAVE")
  139. /* The firmware-assisted dump format.
  140. *
  141. * The register save area is an area in the partition's memory used to preserve
  142. * the register contents (CPU state data) for the active CPUs during a firmware
  143. * assisted dump. The dump format contains register save area header followed
  144. * by register entries. Each list of registers for a CPU starts with
  145. * "CPUSTRT" and ends with "CPUEND".
  146. */
  147. /* Register save area header. */
  148. struct fadump_reg_save_area_header {
  149. __be64 magic_number;
  150. __be32 version;
  151. __be32 num_cpu_offset;
  152. };
  153. /* Register entry. */
  154. struct fadump_reg_entry {
  155. __be64 reg_id;
  156. __be64 reg_value;
  157. };
  158. /* fadump crash info structure */
  159. struct fadump_crash_info_header {
  160. u64 magic_number;
  161. u64 elfcorehdr_addr;
  162. u32 crashing_cpu;
  163. struct pt_regs regs;
  164. struct cpumask cpu_online_mask;
  165. };
  166. struct fad_crash_memory_ranges {
  167. unsigned long long base;
  168. unsigned long long size;
  169. };
  170. extern int early_init_dt_scan_fw_dump(unsigned long node,
  171. const char *uname, int depth, void *data);
  172. extern int fadump_reserve_mem(void);
  173. extern int setup_fadump(void);
  174. extern int is_fadump_active(void);
  175. extern void crash_fadump(struct pt_regs *, const char *);
  176. extern void fadump_cleanup(void);
  177. #else /* CONFIG_FA_DUMP */
  178. static inline int is_fadump_active(void) { return 0; }
  179. static inline void crash_fadump(struct pt_regs *regs, const char *str) { }
  180. #endif
  181. #endif