mt_scp_excep.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #ifndef _MT_SCP_EXCEP_H_
  32. #define _MT_SCP_EXCEP_H_
  33. typedef short __s16;
  34. typedef int __s32;
  35. typedef long long __s64;
  36. typedef unsigned short __u16;
  37. typedef unsigned int __u32;
  38. typedef unsigned long long __u64;
  39. struct TaskContextType {
  40. unsigned int r0;
  41. unsigned int r1;
  42. unsigned int r2;
  43. unsigned int r3;
  44. unsigned int r4;
  45. unsigned int r5;
  46. unsigned int r6;
  47. unsigned int r7;
  48. unsigned int r8;
  49. unsigned int r9;
  50. unsigned int r10;
  51. unsigned int r11;
  52. unsigned int r12;
  53. unsigned int sp; /* after pop r0-r3, lr, pc, xpsr */
  54. unsigned int lr; /* lr before exception */
  55. unsigned int pc; /* pc before exception */
  56. unsigned int psr; /* xpsr before exeption */
  57. unsigned int control; /* nPRIV bit & FPCA bit meaningful, SPSEL bit = 0 */
  58. unsigned int exc_return; /* current lr */
  59. unsigned int msp; /* msp */
  60. };
  61. #define CRASH_SUMMARY_LENGTH 12
  62. #define CRASH_MEMORY_HEADER_SIZE (8 * 1024)
  63. #define CRASH_MEMORY_OFFSET (0x800)
  64. #define CRASH_MEMORY_LENGTH (512 * 1024 - CRASH_MEMORY_OFFSET)
  65. #define CRASH_DRAM_OFFSET (0x80000)
  66. #define CRASH_DRAM_LENGTH (0x100000)
  67. #define CRASH_REG_SIZE (9 * 32)
  68. #define ELF_NGREGS 18
  69. #define ELF_PRARGSZ (80)
  70. #define EM_ARM 40 /* ARM 32 bit */
  71. #define ELF_CORE_EFLAGS 0
  72. #define CORE_STR "CORE"
  73. #define EI_NIDENT 16
  74. struct elf32_hdr {
  75. unsigned char e_ident[EI_NIDENT];
  76. __u16 e_type;
  77. __u16 e_machine;
  78. __u32 e_version;
  79. __u32 e_entry;
  80. __u32 e_phoff;
  81. __u32 e_shoff;
  82. __u32 e_flags;
  83. __u16 e_ehsize;
  84. __u16 e_phentsize;
  85. __u16 e_phnum;
  86. __u16 e_shentsize;
  87. __u16 e_shnum;
  88. __u16 e_shstrndx;
  89. };
  90. struct elf32_phdr {
  91. __u32 p_type;
  92. __u32 p_offset;
  93. __u32 p_vaddr;
  94. __u32 p_paddr;
  95. __u32 p_filesz;
  96. __u32 p_memsz;
  97. __u32 p_flags;
  98. __u32 p_align;
  99. };
  100. #define EI_CLASS 4
  101. #define EI_DATA 5
  102. #define EI_VERSION 6
  103. #define EI_OSABI 7
  104. #define EI_PAD 8
  105. #define ELFCLASS32 1
  106. #define ELFDATA2LSB 1
  107. #define EV_CURRENT 1
  108. #define ELFOSABI_NONE 0
  109. #define NT_PRSTATUS 1
  110. #define NT_PRPSINFO 3
  111. struct elf32_note {
  112. __u32 n_namesz;
  113. __u32 n_descsz;
  114. __u32 n_type;
  115. };
  116. /* scp reg dump*/
  117. struct scp_reg_dump_list {
  118. uint32_t scp_reg_magic;
  119. uint32_t ap_resource;
  120. uint32_t bus_resource;
  121. uint32_t slp_protect;
  122. uint32_t cpu_sleep_status;
  123. uint32_t clk_sw_sel;
  124. uint32_t clk_enable;
  125. uint32_t clk_high_core;
  126. uint32_t debug_wdt_sp;
  127. uint32_t debug_wdt_lr;
  128. uint32_t debug_wdt_psp;
  129. uint32_t debug_wdt_pc;
  130. uint32_t debug_addr_s2r;
  131. uint32_t debug_addr_dma;
  132. uint32_t debug_addr_spi0;
  133. uint32_t debug_addr_spi1;
  134. uint32_t debug_addr_spi2;
  135. uint32_t debug_bus_status;
  136. uint32_t debug_infra_mon;
  137. uint32_t infra_addr_latch;
  138. uint32_t ddebug_latch;
  139. uint32_t pdebug_latch;
  140. uint32_t pc_value;
  141. uint32_t scp_reg_magic_end;
  142. };
  143. struct scp_dump_header_list {
  144. uint32_t scp_head_magic;
  145. struct scp_region_info_st scp_region_info;
  146. uint32_t scp_head_magic_end;
  147. };
  148. struct MemoryDump {
  149. struct elf32_hdr elf;
  150. struct elf32_phdr nhdr;
  151. struct elf32_phdr phdr;
  152. char notes[CRASH_MEMORY_HEADER_SIZE-sizeof(struct elf32_hdr)
  153. -sizeof(struct elf32_phdr)-sizeof(struct elf32_phdr)
  154. -sizeof(struct scp_dump_header_list)];
  155. /* ram dump total header size(elf+nhdr+phdr+header)
  156. * must be fixed at CRASH_MEMORY_HEADER_SIZE
  157. */
  158. struct scp_dump_header_list scp_dump_header;
  159. /*scp sram*/
  160. char memory[CRASH_MEMORY_LENGTH];
  161. /*scp reg*/
  162. struct scp_reg_dump_list scp_reg_dump;
  163. };
  164. enum scp_core_id {
  165. SCP_A_ID = 0,
  166. SCP_CORE_TOTAL = 1,
  167. };
  168. #define ET_CORE 4
  169. #define AED_LOG_PRINT_SIZE SZ_16K
  170. #define SCP_LOCK_OFS 0xE0
  171. #define SCP_TCM_LOCK_BIT (1 << 20)
  172. enum scp_excep_id {
  173. EXCEP_LOAD_FIRMWARE = 0,
  174. EXCEP_RESET,
  175. EXCEP_BOOTUP,
  176. EXCEP_RUNTIME,
  177. SCP_NR_EXCEP,
  178. };
  179. void scp_aed(enum scp_excep_id type, enum scp_core_id id);
  180. void scp_aed_reset(enum scp_excep_id type, enum scp_core_id id);
  181. void scp_aed_reset_inplace(enum scp_excep_id type, enum scp_core_id id);
  182. void scp_get_log(enum scp_core_id id);
  183. char *scp_get_last_log(enum scp_core_id id);
  184. void scp_A_dump_regs(void);
  185. uint32_t scp_dump_pc(void);
  186. uint32_t scp_dump_lr(void);
  187. void aed_scp_exception_api(const int *log, int log_size, const int *phy,
  188. int phy_size, const char *detail, const int db_opt);
  189. void scp_excep_cleanup(void);
  190. int scp_crash_dump(void *crash_buffer);
  191. enum { r0, r1, r2, r3, r12, lr, pc, psr};
  192. #endif