mt_scp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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_H_
  32. #define _MT_SCP_H_
  33. #define __O volatile /*!< Defines 'write only' permissions */
  34. #define __IO volatile /*!< Defines 'read / write' permissions */
  35. /*platform dependent address*/
  36. #ifdef MTK_MINIMUM_SCP_DRAM_SIZE
  37. #define SCP_DRAM_SIZE 0x00180000 // mblock_reserve requires max 1.5 MB
  38. #else
  39. #define SCP_DRAM_SIZE 0x00600000 // mblock_reserve requires max 6 MB(1MB platform image, 5MB overlay)
  40. #endif // MTK_MINIMUM_SCP_DRAM_SIZE
  41. #define SCP_DRAM_ALIGN 0x00100000 // due to l1c align = 1MB
  42. #define DRAM_ADDR_MAX 0x9FFFFFFF // max address can SCP remap
  43. #define DRAM_4GB_MAX 0xFFFFFFFF
  44. #define DRAM_4GB_OFFSET 0x40000000
  45. #define SCP_EMI_REGION 5
  46. #define ENABLE_SCP_EMI_PROTECTION (1)
  47. #define SCP_SRAM_BASE 0x10500000
  48. #define SCP_SRAM_SIZE 0x00080000
  49. #define SCP_MAX_SRAM_SIZE SCP_SRAM_SIZE
  50. #define SCP_CFG_BASE (SCP_SRAM_BASE + 0xC0000)
  51. #define SCP_AP_RESOURCE (SCP_CFG_BASE + 0x0004)
  52. #define SCP_BUS_RESOURCE (SCP_CFG_BASE + 0x0008)
  53. #define SCP_A_DEBUG_SP_REG (SCP_CFG_BASE + 0x00A8)
  54. #define SCP_A_DEBUG_LR_REG (SCP_CFG_BASE + 0x00AC)
  55. #define SCP_A_DEBUG_PSP_REG (SCP_CFG_BASE + 0x00B0)
  56. #define SCP_A_DEBUG_PC_REG (SCP_CFG_BASE + 0x00B4)
  57. #define SCP_WDT_SP (SCP_CFG_BASE + 0x00B8)
  58. #define SCP_WDT_LR (SCP_CFG_BASE + 0x00BC)
  59. #define SCP_WDT_PSP (SCP_CFG_BASE + 0x00C0)
  60. #define SCP_WDT_PC (SCP_CFG_BASE + 0x00C4)
  61. #define SCP_SLP_PROTECT_CFG (SCP_CFG_BASE + 0x00C8)
  62. #define SCP_SYS_CTRL (SCP_CFG_BASE + 0x00E4)
  63. #define AHB_SLICE_POST_WT 1
  64. #define AUTO_DDREN_BIT 18
  65. #define DDREN_FIX_VALUE_BIT 28
  66. #define BYPASS_P_L1C 30
  67. #define BYPASS_D_L1C 31
  68. #define BUS_QOS (SCP_CFG_BASE + 0xE8)
  69. #define AXI_AWULTRA 0
  70. #define AXI_ARULTRA 6
  71. #define SCP_BUS_CTRL (SCP_CFG_BASE + 0x00F0)
  72. #define dbg_irq_info_sel_shift 26
  73. #define dbg_irq_info_sel_mask (0x3 << 26)
  74. #define SCP_DEBUG_ADDR_S2R (SCP_CFG_BASE + 0x00F4)
  75. #define SCP_DEBUG_ADDR_DMA (SCP_CFG_BASE + 0x00F8)
  76. #define SCP_DEBUG_ADDR_SPI0 (SCP_CFG_BASE + 0x00FC)
  77. #define SCP_DEBUG_ADDR_SPI1 (SCP_CFG_BASE + 0x0100)
  78. #define SCP_DEBUG_ADDR_SPI2 (SCP_CFG_BASE + 0x0104)
  79. #define SCP_DEBUG_BUS_STATUS (SCP_CFG_BASE + 0x0110)
  80. #define SCP_CPU_SLEEP_STATUS (SCP_CFG_BASE + 0x0114)
  81. #define L1C_REMAP_CFG0 (SCP_CFG_BASE + 0x12C)
  82. #define L1C_SHIFT_MASK 0xfff00000
  83. #define L1C_ALIGN 0x00100000
  84. #define L1C_EXT_ADDR_SHIFT 20
  85. #define L1C_REMAP_CFG1 (SCP_CFG_BASE + 0x130)
  86. #define L1C_REMAP_CFG2 (SCP_CFG_BASE + 0x134)
  87. #define L1C_REMAP_CFG3 (SCP_CFG_BASE + 0x138)
  88. #define L1C_REMAP_OTHER (SCP_CFG_BASE + 0x13C)
  89. #define SCP_DEBUG_IRQ_INFO (SCP_CFG_BASE + 0x0160)
  90. #define SCP_SRAM_PDN (SCP_CFG_BASE + 0x402c)
  91. #define SCP_CLK_SEL (SCP_CFG_BASE + 0x4000)
  92. #define SCP_CLK_SW_SEL (SCP_CFG_BASE + 0x4000)
  93. #define SCP_CLK_EN (SCP_CFG_BASE + 0x4004)
  94. #define SCP_CLK_ENABLE (SCP_CFG_BASE + 0x4004)
  95. #define SCP_CFGREG_SW_RSTN (SCP_CFG_BASE + 0x0000)
  96. #define SCP_SLP_EN (SCP_CFG_BASE + 0x4020)
  97. #define SCP_CLR_CLK_CG (SCP_CFG_BASE + 0x4058)
  98. #define L1C_I_CTRL_CG 23
  99. #define L1C_D_CTRL_CG 24
  100. #define SCP_CLK_HIGH_CORE_CG (SCP_CFG_BASE + 0x405C)
  101. #define CLK_CTRL_L1_SRAM_PD (SCP_CFG_BASE + 0x4080)
  102. #define CLK_CTRL_TCM_TAIL_SRAM_PD (SCP_CFG_BASE + 0x4094)
  103. #define L1C_IL1C 0
  104. #define L1C_DL1C 1
  105. /* #define SCP_SYS_INFRA_MON (SCP_SCPSYS_BASE + 0x0D50) */
  106. #define L1C_BASE (SCP_SRAM_BASE + 0xD4000)
  107. #define L1C_SEL(x) ((L1C_REGISTER_T *)(L1C_BASE+x*0x3000))
  108. /* L1C_CON register definitions
  109. */
  110. #define L1C_CON_MCEN_OFFSET (0)
  111. #define L1C_CON_MCEN_MASK (1<<L1C_CON_MCEN_OFFSET)
  112. #define L1C_CON_CNTEN0_OFFSET (2)
  113. #define L1C_CON_CNTEN0_MASK (1<<L1C_CON_CNTEN0_OFFSET)
  114. #define L1C_CON_CNTEN1_OFFSET (3)
  115. #define L1C_CON_CNTEN1_MASK (1<<L1C_CON_CNTEN1_OFFSET)
  116. #define L1C_CON_L1CSIZE_OFFSET (8)
  117. #define L1C_CON_L1CSIZE_MASK (3<<L1C_CON_L1CSIZE_OFFSET)
  118. /* L1C_OP register definitions
  119. */
  120. #define L1C_OP_EN_OFFSET (0)
  121. #define L1C_OP_EN_MASK (1<<L1C_OP_EN_OFFSET)
  122. #define L1C_OP_OP_OFFSET (1)
  123. #define L1C_OP_OP_MASK (15<<L1C_OP_OP_OFFSET)
  124. #define L1C_WAY_NUM (1<<10)
  125. /* L1C_HCNT0L register definitions
  126. */
  127. #define L1C_HCNT0L_CHIT_CNT0_MASK (0xFFFFFFFFUL<<0)
  128. /* L1C_HCNT0U register definitions
  129. */
  130. #define L1C_HCNT0U_CHIT_CNT0_MASK (0xFFFFUL<<0)
  131. /* L1C_CCNT0L register definitions
  132. */
  133. #define L1C_CCNT0L_CACC_CNT0_MASK (0xFFFFFFFFUL<<0)
  134. /* L1C_CCNT0U register definitions
  135. */
  136. #define L1C_CCNT0U_CACC_CNT0_MASK (0xFFFFUL<<0)
  137. /* L1C_HCNT1L register definitions
  138. */
  139. #define L1C_HCNT1L_CHIT_CNT1_MASK (0xFFFFFFFFUL<<0)
  140. /* L1C_HCNT1U register definitions
  141. */
  142. #define L1C_HCNT1U_CHIT_CNT1_MASK (0xFFFFUL<<0)
  143. /* L1C_CCNT1L register definitions
  144. */
  145. #define L1C_CCNT1L_CACC_CNT1_MASK (0xFFFFFFFFUL<<0)
  146. /* L1C_CCNT1U register definitions
  147. */
  148. #define L1C_CCNT1U_CACC_CNT1_MASK (0xFFFFUL<<0)
  149. /* L1C_ENTRY_N register definitions
  150. */
  151. #define L1C_ENTRY_N_C_MASK (1<<8)
  152. #define L1C_ENTRY_BASEADDR_MASK (0xFFFFFUL<<12)
  153. /* L1C_END_ENTRY_N register definitions
  154. */
  155. #define L1C_END_ENTRY_N_BASEADDR_MASK (0xFFFFFUL<<12)
  156. #define MTK_L1C_LINE_SIZE (32) /**< L1C line size is 8-word(32-byte) */
  157. #define MTK_L1C_REGION_SIZE_UNIT (0x1000) /**< L1C region size must be 4KB aligned */
  158. #define DRAM_REGION_BASE 0x80000 /* l1c start from address 8M */
  159. #define DRAM_REGION_LENGTH (0x10000000 - DRAM_REGION_BASE) /* l1c end in the address, 256M */
  160. #define REGION_INFO_BASE 0x400
  161. #define SCP_LOADER_OFFSET 0x0
  162. #define SCP_LOADER_SIZE 0x400
  163. #define SCP_FW_OFFSET 0x800
  164. #define SCP_L1C_OFFSET 0x80000 //fixed offset
  165. #define SCP_L1C_SIZE 0x100000 //1MB
  166. #define SCP_L1C_BACKUO_OFFSET 0x180000 //fixed offset
  167. /*image name definition*/
  168. #define LOADER_NAME_SCP_A "tinysys-loader-CM4_A"
  169. #define FIRMWARE_NAME_SCP_A "tinysys-scp-CM4_A"
  170. #define L1C_NAME_SCP_A "tinysys-scp-CM4_A_dram"
  171. #define DO_NAME_SCP_A "tinysys-dos-CM4_A"
  172. #define DO_NAME_SCP_B "tinysys-dos-CM4_B"
  173. typedef enum {
  174. L1C_STATUS_INVALID_PARAMETER = -7, /**< Invalid parameter */
  175. L1C_STATUS_ERROR_BUSY = -6, /**< L1C is busy */
  176. L1C_STATUS_ERROR_L1C_SIZE = -5, /**< L1C size is invalid, total L1C size is not a value of type #l1c_size_t*/
  177. L1C_STATUS_ERROR_REGION = -4, /**< L1C region error, L1C region is not a value of type #l1c_region_t */
  178. L1C_STATUS_ERROR_REGION_ADDRESS = -3, /**< L1C region address error, L1C region address is not 4KB aligned */
  179. L1C_STATUS_ERROR_REGION_SIZE = -2, /**< L1C region size error, L1C region size is not a multiple of 4KB */
  180. L1C_STATUS_ERROR = -1, /**< L1C error , imprecise error*/
  181. L1C_STATUS_OK = 0 /**< L1C ok */
  182. } l1c_status_t;
  183. typedef enum {
  184. L1C_SIZE_0KB = 0, /**< No L1C */
  185. L1C_SIZE_8KB = 1, /**< L1C size is 8KB */
  186. L1C_SIZE_16KB = 2, /**< L1C size is 16KB */
  187. L1C_SIZE_32KB = 3, /**< L1C size is 32KB */
  188. L1C_SIZE_MAX /**< MAX L1C size (invalid) */
  189. } l1c_size_t;
  190. typedef enum {
  191. L1C_REGION_0 = 0, /**< L1C region 0 */
  192. L1C_REGION_1 = 1, /**< L1C region 1 */
  193. L1C_REGION_2 = 2, /**< L1C region 2 */
  194. L1C_REGION_3 = 3, /**< L1C region 3 */
  195. L1C_REGION_4 = 4, /**< L1C region 4 */
  196. L1C_REGION_5 = 5, /**< L1C region 5 */
  197. L1C_REGION_6 = 6, /**< L1C region 6 */
  198. L1C_REGION_7 = 7, /**< L1C region 7 */
  199. L1C_REGION_8 = 8, /**< L1C region 8 */
  200. L1C_REGION_9 = 9, /**< L1C region 9 */
  201. L1C_REGION_10 = 10, /**< L1C region 10 */
  202. L1C_REGION_11 = 11, /**< L1C region 11 */
  203. L1C_REGION_12 = 12, /**< L1C region 12 */
  204. L1C_REGION_13 = 13, /**< L1C region 13 */
  205. L1C_REGION_14 = 14, /**< L1C region 14 */
  206. L1C_REGION_15 = 15, /**< L1C region 15 */
  207. L1C_REGION_MAX /**< Max L1C region number (invalid) */
  208. } l1c_region_t;
  209. typedef enum {
  210. L1C_INVALIDATE_ALL_LINES = 1, /**< Invalidate all L1C line */
  211. L1C_INVALIDATE_ONE_LINE_BY_ADDRESS = 2, /**< Invalidate one line by address */
  212. L1C_INVALIDATE_ONE_LINE_BY_SET_WAY = 4, /**< Invalidate one line by set and way */
  213. L1C_FLUSH_ALL_LINES = 9, /**< Flush all L1C lines */
  214. L1C_FLUSH_ONE_LINE_BY_ADDRESS = 10, /**< Flush one line by address */
  215. L1C_FLUSH_ONE_LINE_BY_SET_WAY = 12 /**< Flush one line by set and way */
  216. } l1c_line_command_t;
  217. /* structure type to access the L1C register
  218. */
  219. typedef struct {
  220. __IO uint32_t L1C_CON;
  221. __IO uint32_t L1C_OP;
  222. __IO uint32_t L1C_HCNT0L;
  223. __IO uint32_t L1C_HCNT0U;
  224. __IO uint32_t L1C_CCNT0L;
  225. __IO uint32_t L1C_CCNT0U;
  226. __IO uint32_t L1C_HCNT1L;
  227. __IO uint32_t L1C_HCNT1U;
  228. __IO uint32_t L1C_CCNT1L;
  229. __IO uint32_t L1C_CCNT1U;
  230. uint32_t RESERVED0[1];
  231. __IO uint32_t L1C_REGION_EN;
  232. uint32_t RESERVED1[2036]; /**< (0x2000-12*4)/4 */
  233. __IO uint32_t L1C_ENTRY_N[16];
  234. __IO uint32_t L1C_END_ENTRY_N[16];
  235. } L1C_REGISTER_T;
  236. /******************************************************************************
  237. * 1. New entries must be appended to the end of the structure.
  238. * 2. Do NOT use conditional option such as #ifdef inside the structure.
  239. ******************************************************************************/
  240. struct scp_region_info_st {
  241. uint32_t ap_loader_start;
  242. uint32_t ap_loader_size;
  243. uint32_t ap_firmware_start;
  244. uint32_t ap_firmware_size;
  245. uint32_t ap_dram_start;
  246. uint32_t ap_dram_size;
  247. uint32_t ap_dram_backup_start;
  248. /* This is the size of the structure.
  249. * It can act as a version number if entries can only be
  250. * added to (not deleted from) the structure.
  251. * It should be the first entry of the structure, but for
  252. * compatibility reason, it is appended here.
  253. */
  254. uint32_t struct_size;
  255. uint32_t scp_log_thru_ap_uart;
  256. uint32_t TaskContext_ptr;
  257. uint32_t Il1c_con;
  258. uint32_t Dl1c_con;
  259. };
  260. typedef struct {
  261. uint32_t l1c_region_address; /**< L1C region start address */
  262. uint32_t l1c_region_size; /**< L1C region size */
  263. } l1c_region_config_t;
  264. #define L1C_POWER(y) ((y & 0x300) >> 8)
  265. #define L1C_SIZE(x) (((1 << L1C_POWER(x)) << 2) * 1024) /* formula: 2^power*4*1024 */
  266. #define L1C_INDEX(z) L1C_POWER(z)
  267. int load_scp(void);
  268. void disable_scp_hw(void);
  269. int platform_fdt_scp(void *fdt);
  270. void scp_l1c_init(unsigned int l1c_icon, unsigned int l1c_dcon);
  271. #endif