ccci_lk_load_img_plat.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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) 2016. 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. #include <sys/types.h>
  32. #include <stdint.h>
  33. #include <platform/partition.h>
  34. #include <platform/mt_typedefs.h>
  35. #include <platform/boot_mode.h>
  36. #include <platform/mt_reg_base.h>
  37. #include <platform/errno.h>
  38. #include <printf.h>
  39. #include <string.h>
  40. #include <malloc.h>
  41. #include <libfdt.h>
  42. #include <platform/mt_gpt.h>
  43. #include <debug.h>
  44. #define MODULE_NAME "LK_LD_MD"
  45. #include "ccci_ld_md_core.h"
  46. #include "ccci_ld_md_errno.h"
  47. /***************************************************************************************************
  48. ** Feature Option setting part
  49. ***************************************************************************************************/
  50. #define ENABLE_EMI_PROTECTION
  51. #ifdef ENABLE_EMI_PROTECTION
  52. #include <platform/emi_mpu.h>
  53. #endif
  54. /***************************************************************************************************
  55. ** HW remap section
  56. ***************************************************************************************************/
  57. /*-------- Register base part -------------------------------*/
  58. /* HW remap for MD1 */
  59. #define MD1_BANK0_MAP0 (0x10001300)
  60. #define MD1_BANK0_MAP1 (0x10001304)
  61. #define MD1_BANK4_MAP0 (0x10001308)
  62. #define MD1_BANK4_MAP1 (0x1000130C)
  63. /* HW remap lock register */
  64. #define MD_HW_REMAP_LOCK (0x10000F00)
  65. #define MD1_LOCK (1<<16)
  66. static int md_mem_ro_rw_remapping(unsigned int md_id, unsigned int addr)
  67. {
  68. unsigned int md_img_start_addr;
  69. unsigned int hw_remapping_bank0_map0;
  70. unsigned int write_val;
  71. switch (md_id) {
  72. case 0: // MD1
  73. hw_remapping_bank0_map0 = MD1_BANK0_MAP0;
  74. break;
  75. default:
  76. ALWAYS_LOG("Invalid md id:%d\n", md_id);
  77. return -1;
  78. }
  79. md_img_start_addr = addr - 0x80000000;
  80. ALWAYS_LOG("---> Map 0x00000000 to 0x%x for MD%d\n", addr, md_id+1);
  81. /* For MDx_BANK0_MAP0 */
  82. write_val = (((md_img_start_addr >> 24) | 1) & 0xFF) \
  83. + ((((md_img_start_addr + 0x02000000) >> 16) | 1<<8) & 0xFF00) \
  84. + ((((md_img_start_addr + 0x04000000) >> 8) | 1<<16) & 0xFF0000) \
  85. + ((((md_img_start_addr + 0x06000000) >> 0) | 1<<24) & 0xFF000000);
  86. DRV_WriteReg32(hw_remapping_bank0_map0, write_val);
  87. ALWAYS_LOG("BANK0_MAP0 value:0x%X\n", DRV_Reg32(hw_remapping_bank0_map0));
  88. return 0;
  89. }
  90. static int md_smem_rw_remapping(unsigned int md_id, unsigned int addr)
  91. {
  92. unsigned int md_smem_start_addr;
  93. unsigned int hw_remapping_bank4_map0;
  94. unsigned int hw_remapping_bank4_map1 = 0;
  95. unsigned int write_val;
  96. switch (md_id) {
  97. case 0: // MD1
  98. hw_remapping_bank4_map0 = MD1_BANK4_MAP0;
  99. hw_remapping_bank4_map1 = MD1_BANK4_MAP1;
  100. break;
  101. default:
  102. ALWAYS_LOG("Invalid md id:%d\n", md_id);
  103. return -LD_ERR_PLAT_INVALID_MD_ID;
  104. }
  105. md_smem_start_addr = addr - 0x80000000;
  106. ALWAYS_LOG("---> Map 0x40000000 to 0x%x for MD%d\n", addr, md_id+1);
  107. /* For MDx_BANK0_MAP0 */
  108. write_val = (((md_smem_start_addr >> 24) | 1) & 0xFF) \
  109. + ((((md_smem_start_addr + 0x02000000) >> 16) | 1<<8) & 0xFF00) \
  110. + ((((md_smem_start_addr + 0x04000000) >> 8) | 1<<16) & 0xFF0000) \
  111. + ((((md_smem_start_addr + 0x06000000) >> 0) | 1<<24) & 0xFF000000);
  112. DRV_WriteReg32(hw_remapping_bank4_map0, write_val);
  113. ALWAYS_LOG("BANK4_MAP0 value:0x%X\n", DRV_Reg32(hw_remapping_bank4_map0));
  114. /* For MDx_BANK0_MAP1 */
  115. write_val = ((((md_smem_start_addr + 0x08000000) >> 24) | 1) & 0xFF) \
  116. + ((((md_smem_start_addr + 0x0A000000) >> 16) | 1<<8) & 0xFF00) \
  117. + ((((md_smem_start_addr + 0x0C000000) >> 8) | 1<<16) & 0xFF0000) \
  118. + ((((md_smem_start_addr + 0x0E000000) >> 0) | 1<<24) & 0xFF000000);
  119. DRV_WriteReg32(hw_remapping_bank4_map1, write_val);
  120. ALWAYS_LOG("BANK4_MAP1 value:0x%X\n", DRV_Reg32(hw_remapping_bank4_map1));
  121. return 0;
  122. }
  123. static void md_emi_remapping_lock(unsigned int md_id)
  124. {
  125. unsigned int reg_val;
  126. unsigned int lock_bit;
  127. switch (md_id) {
  128. case 0: // MD1
  129. lock_bit = MD1_LOCK;
  130. break;
  131. default:
  132. ALWAYS_LOG("Invalid md id:%d for lock\n", md_id);
  133. return;
  134. }
  135. reg_val = DRV_Reg32(MD_HW_REMAP_LOCK);
  136. ALWAYS_LOG("before hw remap lock: MD1[%d]\n", !!(reg_val&MD1_LOCK));
  137. DRV_WriteReg32(MD_HW_REMAP_LOCK, (reg_val|lock_bit));
  138. reg_val = DRV_Reg32(MD_HW_REMAP_LOCK);
  139. ALWAYS_LOG("After hw remap lock: MD1[%d](0x%x)[0x%x]\n", !!(reg_val&MD1_LOCK), reg_val, MD_HW_REMAP_LOCK);
  140. }
  141. /* =================================================== */
  142. /* MPU Region defination */
  143. /* =================================================== */
  144. /* Note: This structure should sync with Kernel!!!! */
  145. typedef struct _mpu_cfg {
  146. unsigned int start;
  147. unsigned int end;
  148. int region;
  149. unsigned int permission;
  150. int relate_region;
  151. } mpu_cfg_t;
  152. /* =================================================================== */
  153. /* | Region | D0(AP) | D1(MD0) |D2(CONNSYS)| D3(MM) */
  154. /* ------------+------------------------------------------------------ */
  155. /* Secure OS | 0 |RW(S) |Forbidden |Forbidden |Forbidden */
  156. /* ------------+------------------------------------------------------ */
  157. /* MD0 ROM | 1 |RO(S/NS) |RO(S/NS) |Forbidden |Forbidden */
  158. /* ------------+------------------------------------------------------ */
  159. /* MD0 R/W+ | 2 |Forbidden |No protect |Forbidden |Forbidden */
  160. /* ------------+------------------------------------------------------ */
  161. /* MD0 Share | 3 |No protect|No protect |Forbidden |Forbidden */
  162. /* ------------+------------------------------------------------------ */
  163. /* CONNSYS Code| 4 |Forbidden |Forbidden |RO(S/NS) |Forbidden */
  164. /* ------------+------------------------------------------------------ */
  165. /* AP-Con Share| 5 |No protect|Forbidden |No product |Forbidden */
  166. /* ------------+------------------------------------------------------ */
  167. /* AP | 6~7 |No protect|RO(S/NS) |Forbidden |No protect */
  168. /* =================================================================== */
  169. #define MPU_REGION_ID_SEC_OS 0
  170. #define MPU_REGION_ID_MD1_ROM 1
  171. #define MPU_REGION_ID_MD1_RW 2
  172. #define MPU_REGION_ID_MD1_SMEM 3
  173. #define MPU_REGION_ID_TOTAL_NUM 8
  174. #define MPU_MDOMAIN_ID_AP 0
  175. #define MPU_MDOMAIN_ID_MD 1
  176. #define MPU_MDOMAIN_ID_TOTAL_NUM 4
  177. #ifdef ENABLE_EMI_PROTECTION
  178. static const unsigned int mpu_att_default[MPU_REGION_ID_TOTAL_NUM][MPU_MDOMAIN_ID_TOTAL_NUM] = {
  179. /*=======================================================================*/
  180. /* No | | D0(AP) | D1(MD1) | D2(CONN) | D3(Res) | D4(MM) */
  181. /*--------------+--------------------------------------------------------*/
  182. /* 0*/{ SEC_RW , FORBIDDEN , FORBIDDEN , FORBIDDEN},
  183. /* 1*/{ SEC_R_NSEC_R , SEC_R_NSEC_R , FORBIDDEN , FORBIDDEN},
  184. /* 2*/{ FORBIDDEN , NO_PROTECTION, FORBIDDEN , FORBIDDEN},
  185. /* 3*/{ NO_PROTECTION, NO_PROTECTION, FORBIDDEN , FORBIDDEN},
  186. /* 4*/{ SEC_R_NSEC_R , NO_PROTECTION, FORBIDDEN , FORBIDDEN},
  187. /* 5*/{ NO_PROTECTION, NO_PROTECTION, FORBIDDEN , FORBIDDEN},
  188. /* 6*/{ NO_PROTECTION, FORBIDDEN , FORBIDDEN , FORBIDDEN},
  189. /* 7*/{ NO_PROTECTION , NO_PROTECTION, FORBIDDEN , FORBIDDEN},
  190. /*=======================================================================*/
  191. };
  192. static unsigned int get_mpu_region_default_access_att(int region, int lock)
  193. {
  194. return SET_ACCESS_PERMISSON(lock, mpu_att_default[region][3], mpu_att_default[region][2],
  195. mpu_att_default[region][1], mpu_att_default[region][0]);
  196. }
  197. #endif
  198. static void get_mpu_attr_str(int lock, int curr_attr, char buf[], int size)
  199. {
  200. char ch = lock?'L':'U';
  201. snprintf(buf, 24, "%d-%d-%d-%d-%d-%d-%d-%d(%c)",
  202. curr_attr&7, (curr_attr>>3)&7, (curr_attr>>6)&7, (curr_attr>>9)&7,
  203. (curr_attr>>12)&7, (curr_attr>>15)&7, (curr_attr>>18)&7, (curr_attr>>21)&7, ch);
  204. }
  205. static const int free_mpu_region[] = {-1};
  206. static int curr_free_mpu_idx;
  207. static int get_free_mpu_region(void)
  208. {
  209. int ret;
  210. if (curr_free_mpu_idx < (int)(sizeof(free_mpu_region)/sizeof(int))) {
  211. ret = free_mpu_region[curr_free_mpu_idx];
  212. curr_free_mpu_idx++;
  213. } else
  214. ret = -LD_ERR_PLAT_MPU_REGION_EMPTY;
  215. return ret;
  216. }
  217. static void ccci_mem_access_cfg(mpu_cfg_t *mpu_cfg_list, int clear)
  218. {
  219. #ifdef ENABLE_EMI_PROTECTION
  220. mpu_cfg_t *curr;
  221. unsigned int curr_attr;
  222. char buf[24];
  223. if (NULL == mpu_cfg_list)
  224. return;
  225. curr = mpu_cfg_list;
  226. curr_attr = SET_ACCESS_PERMISSON(0, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION);
  227. while (curr->region != -1) {
  228. if (clear) {
  229. emi_mpu_set_region_protection( 0, /*START_ADDR*/
  230. 0, /*END_ADDR*/
  231. curr->region, /*region*/
  232. curr_attr);
  233. ALWAYS_LOG("Clr MPU:S:0x%x E:0x%x A:<%d>[0~7]%d-%d-%d-%d-%d-%d-%d-%d\n", 0, 0,
  234. curr->region, curr_attr&7, (curr_attr>>3)&7, (curr_attr>>6)&7,
  235. (curr_attr>>9)&7, (curr_attr>>12)&7, (curr_attr>>15)&7,
  236. (curr_attr>>18)&7, (curr_attr>>21)&7);
  237. } else {
  238. emi_mpu_set_region_protection( curr->start, /*START_ADDR*/
  239. curr->end, /*END_ADDR*/
  240. curr->region, /*region*/
  241. curr->permission);
  242. curr_attr = curr->permission;
  243. get_mpu_attr_str(0, curr_attr, buf, 24);
  244. ALWAYS_LOG("Set MPU:S:0x%x E:0x%x A:<%d>[0~7]%s\n", curr->start,
  245. curr->end, curr->region, buf);
  246. }
  247. curr++;
  248. }
  249. #endif
  250. }
  251. /*--------- Implement one by one -------------------------------------------------------------------------------*/
  252. int plat_get_padding_mpu_num(void)
  253. {
  254. return (int)(sizeof(free_mpu_region)/sizeof(unsigned int)) - 1;
  255. }
  256. int plat_dt_reserve_mem_size_fixup(void *fdt)
  257. {
  258. int offset, sub_offset;
  259. /* -------- Remove device tree item ----------------------- */
  260. offset = fdt_path_offset(fdt, "/reserved-memory");
  261. sub_offset = fdt_subnode_offset(fdt, offset, "reserve-memory-ccci_md1");
  262. if (sub_offset) {
  263. DT_DBG_LOG("get md1 reserve-mem success. offset: %d, sub_off: %d\n",
  264. offset, sub_offset);
  265. /* kill this node */
  266. fdt_del_node(fdt, sub_offset);
  267. } else
  268. ALWAYS_LOG("ignore md1 reserve-mem.\n");
  269. return 0;
  270. }
  271. /*---------------------------------------------------------------------------------------------------*/
  272. /* Global variable for share memory */
  273. /*---------------------------------------------------------------------------------------------------*/
  274. #define AP_MD1_SMEM_SIZE 0x200000 /* 2M */
  275. typedef struct _smem_layout {
  276. unsigned long long base_addr;
  277. unsigned int ap_md1_smem_offset;
  278. unsigned int ap_md1_smem_size;
  279. unsigned int ap_md3_smem_offset;
  280. unsigned int ap_md3_smem_size;
  281. unsigned int md1_md3_smem_offset;
  282. unsigned int md1_md3_smem_size;
  283. unsigned int total_smem_size;
  284. } smem_layout_t;
  285. static smem_layout_t smem_info;
  286. /*---------------------------------------------------------------------------------------------------*/
  287. /* HW remap function implement */
  288. /*---------------------------------------------------------------------------------------------------*/
  289. int plat_apply_hw_remap_for_md_ro_rw(void* info)
  290. {
  291. modem_info_t *md_ld_info = (modem_info_t *)info;
  292. return md_mem_ro_rw_remapping((unsigned int)md_ld_info->md_id, (unsigned int)md_ld_info->base_addr);
  293. }
  294. int plat_apply_hw_remap_for_md_smem(void *addr, int size)
  295. {
  296. smem_info.base_addr = (unsigned int)addr;
  297. return 0;
  298. }
  299. /*---------------------------------------------------------------------------------------------------*/
  300. /* check header info collection by plat_post_hdr_info */
  301. /*---------------------------------------------------------------------------------------------------*/
  302. void plat_post_hdr_info(void* hdr, int ver, int id)
  303. {
  304. /* R8 no need */
  305. }
  306. /*---------------------------------------------------------------------------------------------------*/
  307. /* MPU static global variable and mpu relate function implement */
  308. /*---------------------------------------------------------------------------------------------------*/
  309. #define MPU_REGION_TOTAL_NUM (4) /* = MD1+MD3 */
  310. static mpu_cfg_t mpu_tbl[MPU_REGION_TOTAL_NUM];
  311. static int s_g_curr_mpu_num;
  312. /*
  313. ** if set start=0x0, end=0x10000, the actural protected area will be 0x0-0x1FFFF,
  314. ** here we use 64KB align, MPU actually request 32KB align since MT6582, but this works...
  315. ** we assume emi_mpu_set_region_protection will round end address down to 64KB align.
  316. */
  317. static void dump_received_pure_mpu_setting(struct image_section_desc *mem_info, int item_num)
  318. {
  319. int i;
  320. for (i =0; i < item_num; i++)
  321. MPU_DBG_LOG("mpu sec dec %d: offset:%x, size:%x, mpu_attr:%x, ext_flag:%x, relate_idx:%x\n", i,
  322. mem_info[i].offset, mem_info[i].size, mem_info[i].mpu_attr,
  323. mem_info[i].ext_flag, mem_info[i].relate_idx);
  324. }
  325. int plat_send_mpu_info_to_platorm(void *p_md_ld_info, void *p_mem_info)
  326. {
  327. #ifdef ENABLE_EMI_PROTECTION
  328. modem_info_t *md_ld_info = (modem_info_t *)p_md_ld_info;
  329. struct image_section_desc *mem_info = (struct image_section_desc *)p_mem_info;
  330. int md_id = md_ld_info->md_id;
  331. int ret;
  332. int i;
  333. char buf[24];
  334. if (md_id == MD_SYS1) {
  335. /* RO part */
  336. mpu_tbl[s_g_curr_mpu_num].permission = get_mpu_region_default_access_att(MPU_REGION_ID_MD1_ROM, 1);
  337. mpu_tbl[s_g_curr_mpu_num].start = (unsigned int)md_ld_info->base_addr + mem_info[0].offset;
  338. mpu_tbl[s_g_curr_mpu_num].end = mpu_tbl[s_g_curr_mpu_num].start + mem_info[0].size;
  339. mpu_tbl[s_g_curr_mpu_num].region = MPU_REGION_ID_MD1_ROM;
  340. /* 64K align */
  341. mpu_tbl[s_g_curr_mpu_num].end = ((mpu_tbl[s_g_curr_mpu_num].end + 0xFFFF)&(~0xFFFF)) - 1;
  342. s_g_curr_mpu_num++;
  343. /* RW part */
  344. mpu_tbl[s_g_curr_mpu_num].permission = get_mpu_region_default_access_att(MPU_REGION_ID_MD1_RW, 1);
  345. mpu_tbl[s_g_curr_mpu_num].start = (unsigned int)md_ld_info->base_addr + mem_info[1].offset;
  346. mpu_tbl[s_g_curr_mpu_num].end = mpu_tbl[s_g_curr_mpu_num].start + mem_info[1].size;
  347. mpu_tbl[s_g_curr_mpu_num].region = MPU_REGION_ID_MD1_RW;
  348. /* 64K align */
  349. mpu_tbl[s_g_curr_mpu_num].end = ((mpu_tbl[s_g_curr_mpu_num].end + 0xFFFF)&(~0xFFFF)) - 1;
  350. s_g_curr_mpu_num++;
  351. }
  352. for (i =0; i < s_g_curr_mpu_num; i++) {
  353. get_mpu_attr_str(0, mpu_tbl[i].permission, buf, 24);
  354. MPU_DBG_LOG("plat mpu dec %d: region:%d[%d], start:0x%x, end:0x%x, attr:%s\n", i,
  355. mpu_tbl[i].region, mpu_tbl[i].relate_region, mpu_tbl[i].start, mpu_tbl[i].end, buf);
  356. }
  357. #endif
  358. return 0;
  359. }
  360. /*------------------------------------------------------------------------------------------------*/
  361. /* Suppor function for share memory calculate */
  362. /*------------------------------------------------------------------------------------------------*/
  363. static int cal_share_mem_layout(int load_flag)
  364. {
  365. /* MD Share memory layout */
  366. /* AP <--> MD1 */
  367. if (load_flag & (1<<MD_SYS1)) {
  368. smem_info.ap_md1_smem_size = AP_MD1_SMEM_SIZE;
  369. smem_info.ap_md1_smem_offset = 0;
  370. smem_info.md1_md3_smem_offset = 0;
  371. smem_info.md1_md3_smem_size = 0;
  372. smem_info.ap_md3_smem_offset = 0;
  373. smem_info.ap_md3_smem_size = 0;
  374. smem_info.total_smem_size = smem_info.ap_md1_smem_size;
  375. }
  376. /* insert share memory layout to lk info */
  377. if (insert_ccci_tag_inf("smem_layout", (char*)&smem_info, sizeof(smem_layout_t)) < 0)
  378. ALWAYS_LOG("insert smem_layout fail\n");
  379. ALWAYS_LOG("smem_info.base_addr: %x\n", (unsigned int)smem_info.base_addr);
  380. ALWAYS_LOG("smem_info.ap_md1_smem_offset: %x\n", smem_info.ap_md1_smem_offset);
  381. ALWAYS_LOG("smem_info.ap_md1_smem_size: %x\n", smem_info.ap_md1_smem_size);
  382. ALWAYS_LOG("smem_info.ap_md3_smem_offset: %x\n", smem_info.ap_md3_smem_offset);
  383. ALWAYS_LOG("smem_info.ap_md3_smem_size: %x\n", smem_info.ap_md3_smem_size);
  384. ALWAYS_LOG("smem_info.md1_md3_smem_offset: %x\n", smem_info.md1_md3_smem_offset);
  385. ALWAYS_LOG("smem_info.md1_md3_smem_size: %x\n", smem_info.md1_md3_smem_size);
  386. ALWAYS_LOG("smem_info.total_smem_size: %x\n", smem_info.total_smem_size);
  387. return (int)smem_info.total_smem_size;
  388. }
  389. static void boot_to_dummy_ap_mode(int load_md_flag);
  390. /*------------------------------------------------------------------------------------------------*/
  391. /* Note: This function using global variable
  392. ** if set start=0x0, end=0x10000, the actural protected area will be 0x0-0x1FFFF,
  393. ** here we use 64KB align, MPU actually request 32KB align since MT6582, but this works...
  394. ** we assume emi_mpu_set_region_protection will round end address down to 64KB align.
  395. */
  396. int plat_apply_platform_setting(int load_md_flag)
  397. {
  398. int smem_final_size;
  399. #ifdef DUMMY_AP_MODE
  400. /* This function will never return */
  401. ALWAYS_LOG("boot to dummy ap mode!!!\n");
  402. boot_to_dummy_ap_mode(load_md_flag);
  403. return 0;
  404. #endif
  405. /* Check loading validation */
  406. if ((load_md_flag & (1<<MD_SYS1)) == 0) {
  407. ALWAYS_LOG("md1 not enable\n");
  408. return 0;
  409. }
  410. smem_final_size = cal_share_mem_layout(load_md_flag);
  411. #ifdef ENABLE_EMI_PROTECTION
  412. ALWAYS_LOG("ap md1 share mem MPU need configure\n");
  413. mpu_tbl[s_g_curr_mpu_num].region = MPU_REGION_ID_MD1_SMEM;
  414. mpu_tbl[s_g_curr_mpu_num].permission = get_mpu_region_default_access_att(MPU_REGION_ID_MD1_SMEM, 0);
  415. mpu_tbl[s_g_curr_mpu_num].start = (unsigned int)smem_info.base_addr + smem_info.ap_md1_smem_offset;
  416. mpu_tbl[s_g_curr_mpu_num].end = (unsigned int)smem_info.base_addr + smem_info.ap_md1_smem_offset
  417. + smem_info.ap_md1_smem_size;
  418. mpu_tbl[s_g_curr_mpu_num].end = ((mpu_tbl[s_g_curr_mpu_num].end + 0xFFFF)&(~0xFFFF)) - 1;
  419. s_g_curr_mpu_num++;
  420. #endif
  421. mpu_tbl[s_g_curr_mpu_num].region = -1; /* mark for end */
  422. /* Insert mpu tag info */
  423. if (insert_ccci_tag_inf("md_mpu_inf", (char*)mpu_tbl, sizeof(mpu_cfg_t)*s_g_curr_mpu_num) < 0)
  424. ALWAYS_LOG("insert md_mpu_inf fail\n");
  425. if (insert_ccci_tag_inf("md_mpu_num", (char*)&s_g_curr_mpu_num, sizeof(int)) < 0)
  426. ALWAYS_LOG("insert md_mpu_num fail\n");
  427. /* Apply all MPU setting */
  428. ccci_mem_access_cfg(mpu_tbl, 0);
  429. /* Apply share memory HW remap setting and lock it */
  430. if (load_md_flag & (1<<MD_SYS1)) {
  431. md_smem_rw_remapping(MD_SYS1, (unsigned int)(smem_info.base_addr + smem_info.ap_md1_smem_offset));
  432. md_emi_remapping_lock(MD_SYS1);
  433. }
  434. return smem_final_size;
  435. }
  436. /*------------------------------------------------------------------------------------------------*/
  437. /* platform configure setting info. */
  438. /*------------------------------------------------------------------------------------------------*/
  439. long long plat_ccci_get_ld_md_plat_setting(char cfg_name[])
  440. {
  441. if (strcmp(cfg_name, "share_memory_size") == 0) {
  442. return (long long)(AP_MD1_SMEM_SIZE);
  443. }
  444. if (strcmp(cfg_name, "share_mem_limit") == 0)
  445. return 0x100000000LL;
  446. if (strcmp(cfg_name, "ro_rw_mem_limit") == 0) {
  447. return 0x100000000LL;
  448. }
  449. if (strcmp(cfg_name, "ro_rw_mem_align") == 0)
  450. return 0x2000000LL;
  451. if (strcmp(cfg_name, "share_mem_align") == 0)
  452. return 0x2000000LL;
  453. if (strcmp(cfg_name, "ld_version") == 0) {
  454. return 0x40000;/* xxxx_yyyy, xxxx: main id, yyyy sub id */
  455. }
  456. if (strcmp(cfg_name, "rat_plat_ver") == 0)
  457. return RAT_VER_R8;
  458. return -1LL;
  459. }
  460. #ifdef DUMMY_AP_MODE
  461. #include <platform/mt_irq.h>
  462. extern void dummy_ap_boot_up_md(int md_en_flag);
  463. extern void load_modem_image(void);
  464. extern int dummy_ap_irq_helper(unsigned int);
  465. /* Remember add this function to file platform.c(platform code) */
  466. void dummy_ap_entry(void)
  467. {
  468. load_modem_image();
  469. }
  470. /* Remember add this function to file interrupts.c(platform code) */
  471. void dummy_ap_irq_handler(unsigned int irq)
  472. {
  473. if (dummy_ap_irq_helper(irq)) {
  474. mt_irq_ack(irq);
  475. mt_irq_unmask(irq);
  476. }
  477. }
  478. void boot_to_dummy_ap_mode(int load_md_flag)
  479. {
  480. dummy_ap_boot_up_md(load_md_flag);
  481. }
  482. #endif