ccci_lk_load_img_plat.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  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) 2019. 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 <assert.h>
  43. #include <platform/mt_gpt.h>
  44. #include <platform/mt_emi_mpu.h>
  45. #include <mtk_secure_api.h>
  46. #include <debug.h>
  47. #define MODULE_NAME "LK_LD_MD"
  48. #include "ccci_ld_md_core.h"
  49. #include "ccci_ld_md_errno.h"
  50. #include "plat_atf_sec_call.h"
  51. #define CCCI_USE_DFD_OFFSET_0
  52. #ifdef CCCI_USE_DFD_OFFSET_0
  53. #include <libfdt.h>
  54. #include <fdt_op.h>
  55. #include <dfd.h>
  56. extern const struct plt_cfg_dfd cfg_dfd;
  57. #endif
  58. #include <mt_boot.h>
  59. int md_sib_rw_remapping(unsigned long long addr);
  60. #ifdef MTK_DFD_ENABLE_CACHE_DUMP
  61. #define CCCI_SMEM_SIZE_DFD (8*1024*1024)
  62. #else
  63. #define CCCI_SMEM_SIZE_DFD (448*1024)
  64. #endif
  65. #define CCCI_SMEM_SIZE_SECURITY (1*1024*1024) /* security smem total size */
  66. #define CCCI_SMEM_SIZE_UDC_NONCACHE (25536*1024)
  67. #define CCCI_SMEM_SIZE_UDC_CACHE (512*1024)
  68. #define CCCI_SMEM_WIFI_MD_PROXY (64*1024)
  69. #define CCCI_SMEM_SIZE_CCB_DHL (2*1024*1024)
  70. #define CCCI_SMEM_SIZE_RAW_DHL (62*1024*1024)
  71. #define CCCI_SMEM_SIZE_LWA (0) // (8*1024*1024)
  72. #define CCB_DATA_BUF_SIZE (CCCI_SMEM_SIZE_CCB_DHL + CCCI_SMEM_SIZE_RAW_DHL)
  73. #define CACHABLE_SMEM_MAX_SIZE (128*1024*1024)
  74. #define CCB_DATA_BUF_DEFAULT_GEAR 12 /* NOTE: This value may be different at different platform */
  75. /***************************************************************************************************
  76. ** Feature Option setting part
  77. ***************************************************************************************************/
  78. #define ENABLE_EMI_PROTECTION
  79. #define MPU_REGION_CONSYS_EN
  80. #define CCCI_SECURE_RET_VALUE_LK 0xfffffffffffffff1
  81. /*------------------------------------------------------------------------------------------------*/
  82. /* Suppor function for share memory calculate */
  83. /*------------------------------------------------------------------------------------------------*/
  84. /* copy from kernel */
  85. enum SMEM_USER_ID {
  86. /* this should remain to be 0 for backward compatibility */
  87. SMEM_USER_RAW_DBM = 0,
  88. /* sequence in CCB users matters, must align with ccb_configs[] */
  89. SMEM_USER_CCB_START,
  90. SMEM_USER_CCB_DHL = SMEM_USER_CCB_START,
  91. SMEM_USER_CCB_MD_MONITOR,
  92. SMEM_USER_CCB_META,
  93. SMEM_USER_CCB_END = SMEM_USER_CCB_META,
  94. /* squence of other users does not matter */
  95. SMEM_USER_RAW_CCB_CTRL,
  96. SMEM_USER_RAW_DHL,
  97. SMEM_USER_RAW_MDM,
  98. SMEM_USER_RAW_NETD,
  99. SMEM_USER_RAW_USB,
  100. SMEM_USER_RAW_AUDIO,
  101. SMEM_USER_RAW_DFD,
  102. SMEM_USER_RAW_LWA,
  103. SMEM_USER_RAW_MDCCCI_DBG,
  104. SMEM_USER_RAW_MDSS_DBG,
  105. SMEM_USER_RAW_RUNTIME_DATA,
  106. SMEM_USER_RAW_FORCE_ASSERT,
  107. SMEM_USER_CCISM_SCP,
  108. SMEM_USER_RAW_MD2MD,
  109. SMEM_USER_RAW_RESERVED,
  110. SMEM_USER_CCISM_MCU,
  111. SMEM_USER_CCISM_MCU_EXP,
  112. SMEM_USER_SMART_LOGGING,
  113. SMEM_USER_RAW_MD_CONSYS,
  114. SMEM_USER_RAW_PHY_CAP,
  115. SMEM_USER_RAW_USIP,
  116. SMEM_USER_RESV_0,// Sync to MT6779 SMEM_USER_MAX_K,
  117. SMEM_USER_ALIGN_PADDING, // Sync to MT6779 SMEM_USER_NON_PADDING
  118. SMEM_USER_RAW_UDC_DATA,
  119. SMEM_USER_RAW_UDC_DESCTAB,
  120. SMEM_USER_RAW_AMMS_POS,
  121. SMEM_USER_RAW_AMMS_ALIGN_PADDING,
  122. SMEM_USER_MD_WIFI_PROXY,
  123. SMEM_USER_MD_NVRAM_CACHE,
  124. SMEM_USER_LOW_POWER,
  125. SMEM_USER_SECURITY_SMEM,
  126. SMEM_USER_LAST, /* Make sure USER ID sync with Kernel before SMEM_USER_LAST */
  127. /* Note, if you add more user, please update the followig table: smem_align_ref[] */
  128. };
  129. static const unsigned int smem_align_ref[SMEM_USER_LAST] = {
  130. 0, /* SMEM_USER_RAW_DBM */
  131. 1024*1024, /* SMEM_USER_CCB_DHL */
  132. 0, /* SMEM_USER_CCB_MD_MONITOR */
  133. 0, /* SMEM_USER_CCB_META */
  134. 0, /* SMEM_USER_RAW_CCB_CTRL */
  135. 0, /* SMEM_USER_RAW_DHL */
  136. 0, /* SMEM_USER_RAW_MDM */
  137. 0, /* SMEM_USER_RAW_NETD */
  138. 0, /* SMEM_USER_RAW_USB */
  139. 0, /* SMEM_USER_RAW_AUDIO */
  140. 16*1024*1024, /* SMEM_USER_RAW_DFD 97 */
  141. 0, /* SMEM_USER_RAW_LWA */
  142. 0, /* SMEM_USER_RAW_MDCCCI_DBG */
  143. 0, /* SMEM_USER_RAW_MDSS_DBG */
  144. 0, /* SMEM_USER_RAW_RUNTIME_DATA */
  145. 0, /* SMEM_USER_RAW_FORCE_ASSERT */
  146. 0, /* SMEM_USER_CCISM_SCP */
  147. 0, /* SMEM_USER_RAW_MD2MD */
  148. 0, /* SMEM_USER_RAW_RESERVED */
  149. 0, /* SMEM_USER_CCISM_MCU */
  150. 0, /* SMEM_USER_CCISM_MCU_EXP */
  151. 0, /* SMEM_USER_SMART_LOGGING */
  152. 64*1024, /* SMEM_USER_RAW_MD_CONSYS */
  153. 0, /* SMEM_USER_RAW_PHY_CAP */
  154. 128, /* SMEM_USER_RAW_USIP */
  155. 0, /* SMEM_USER_RESV_0 */
  156. 0, /* SMEM_USER_ALIGN_PADDING */
  157. 4*1024, /* SMEM_USER_RAW_UDC_DATA */
  158. 4*1024, /* SMEM_USER_RAW_UDC_DESCTAB */
  159. 64*1024, /* SMEM_USER_RAW_AMMS_POS */
  160. 0, /* SMEM_USER_RAW_AMMS_ALIGN_PADDING */
  161. 0, /* SMEM_USER_MD_WIFI_PROXY */
  162. 64, /* SMEM_USER_MD_NVRAM_CACHE */
  163. 0, /* SMEM_USER_LOW_POWER */
  164. 1024*1024, /*SMEM_USER_AP_MD1_SECURITY_SMEM,*/
  165. };
  166. static unsigned int get_align_ref(unsigned int id)
  167. {
  168. if (id >= SMEM_USER_LAST)
  169. return 0;
  170. return smem_align_ref[id];
  171. }
  172. static unsigned int get_align_sz(unsigned int val, unsigned int align)
  173. {
  174. unsigned int tmp;
  175. tmp = val;
  176. return ((val + align - 1) & (~(align - 1))) - tmp;
  177. }
  178. static unsigned int get_align_sz_by_user(unsigned int val, enum SMEM_USER_ID user)
  179. {
  180. unsigned int align;
  181. align = get_align_ref(user);
  182. if (!align)
  183. return 0;
  184. return get_align_sz(val, align);
  185. }
  186. /*---------------------------------------------------------------------------------------------------*/
  187. /* Global variable for share memory */
  188. /*---------------------------------------------------------------------------------------------------*/
  189. static unsigned int ap_md1_smem_size_at_img;
  190. static unsigned int amms_pos_size_at_img;
  191. static unsigned int consys_size_at_img;
  192. static unsigned int udc_support_at_img;
  193. static unsigned int nv_cache_shm_size_at_img;
  194. static unsigned int amms_pos_offset;
  195. #define AP_MD1_SMEM_SIZE 0x100000
  196. #define MAX_SMEM_SIZE 0x10000000 //history: 6M-->256M-->64M-->256M
  197. typedef struct _smem_layout {
  198. unsigned long long base_addr;
  199. unsigned int ap_md1_smem_offset;
  200. /* ap_md1_smem_size: this is for MD MPU, not total ap_md1 share size. */
  201. unsigned int ap_md1_smem_size;
  202. unsigned int ap_md3_smem_offset;
  203. unsigned int ap_md3_smem_size;
  204. unsigned int md1_md3_smem_offset;
  205. unsigned int md1_md3_smem_size;
  206. unsigned int total_smem_size;
  207. } smem_layout_t;
  208. static smem_layout_t smem_info;
  209. typedef struct _ccb_layout {
  210. unsigned long long ccb_data_buffer_addr;
  211. unsigned int ccb_data_buffer_size;
  212. } ccb_layout_t;
  213. static ccb_layout_t ccb_info;
  214. typedef struct _nc_smem_node {
  215. unsigned int ap_offset;
  216. unsigned int md_offset;
  217. unsigned int size;
  218. unsigned int id;
  219. } nc_smem_node;
  220. static nc_smem_node nc_smem_info_ext[] = {
  221. {0, 0, 0, SMEM_USER_RAW_UDC_DATA},
  222. {0, 0, 0, SMEM_USER_MD_WIFI_PROXY},
  223. {0, 0, 0, SMEM_USER_RAW_DFD},
  224. {0, 0, 0, SMEM_USER_SECURITY_SMEM},
  225. };
  226. static void update_nc_smem_info(unsigned int id, unsigned int ap, unsigned int md, unsigned int size)
  227. {
  228. unsigned int i;
  229. for (i = 0; i < sizeof(nc_smem_info_ext)/sizeof(nc_smem_node); i++) {
  230. if (nc_smem_info_ext[i].id == id) {
  231. nc_smem_info_ext[i].ap_offset = ap;
  232. nc_smem_info_ext[i].md_offset = md;
  233. nc_smem_info_ext[i].size = size;
  234. return;
  235. }
  236. }
  237. ALWAYS_LOG("un-support NC smem user id:%d\n", id);
  238. assert(0);
  239. }
  240. static void add_nc_smem_to_tag_inf(void)
  241. {
  242. unsigned int num = sizeof(nc_smem_info_ext)/sizeof(nc_smem_node);
  243. if (insert_ccci_tag_inf("nc_smem_info_ext",
  244. (char*)nc_smem_info_ext, sizeof(nc_smem_info_ext)) < 0) {
  245. ALWAYS_LOG("insert nc_smem_info_ext fail\n");
  246. return;
  247. }
  248. if (insert_ccci_tag_inf("nc_smem_info_ext_num",
  249. (char*)&num, sizeof(int)) < 0)
  250. ALWAYS_LOG("insert nc_smem_info_ext_num fail\n");
  251. }
  252. static int get_nc_smem_info(unsigned int id, unsigned int *ap, unsigned int *md, unsigned int *size)
  253. {
  254. unsigned int i;
  255. for (i = 0; i < sizeof(nc_smem_info_ext)/sizeof(nc_smem_node); i++) {
  256. if (nc_smem_info_ext[i].id == id) {
  257. *ap = nc_smem_info_ext[i].ap_offset;
  258. *md = nc_smem_info_ext[i].md_offset;
  259. *size = nc_smem_info_ext[i].size;
  260. return 0;
  261. }
  262. }
  263. ALWAYS_LOG("un-support NC smem user id:%d for get\n", id);
  264. return -1;
  265. }
  266. typedef struct _csmem_item {
  267. unsigned long long csmem_buffer_addr;
  268. unsigned int md_offset;
  269. unsigned int csmem_buffer_size;
  270. unsigned int item_cnt;
  271. } csmem_item_t;
  272. static csmem_item_t csmem_info;
  273. #if WITH_GZ_MD_SHAREMEM
  274. extern BOOT_ARGUMENT *g_boot_arg;
  275. #endif
  276. void plat_md_bank4_amms_pos_notify_secure(unsigned long ap_view_addr,
  277. unsigned long md_view_addr, unsigned long length)
  278. {
  279. unsigned long addr_get,length_get;
  280. mt_secure_call(MTK_SIP_LK_AMMS_MD_POS_ADDR_AARCH32, ap_view_addr, 0, 0, 0);
  281. addr_get = mt_secure_call(MTK_SIP_LK_AMMS_GET_MD_POS_ADDR_AARCH32, 0, 0, 0, 0);
  282. mt_secure_call(MTK_SIP_LK_AMMS_MD_POS_MD_VIEW_ADDR_AARCH32, md_view_addr, 0, 0, 0);
  283. mt_secure_call(MTK_SIP_LK_AMMS_MD_POS_LENGTH_AARCH32, length, 0, 0, 0);
  284. length_get = mt_secure_call(MTK_SIP_LK_AMMS_GET_MD_POS_LENGTH_AARCH32, 0, 0, 0, 0);
  285. ALWAYS_LOG("mt_secure_call: set_pos_addr = 0x%lx(0x%lx), get_pos_addr = 0x%lx length=0x%lx get_length=0x%lx\n",
  286. ap_view_addr, md_view_addr, addr_get, length, length_get);
  287. }
  288. void plat_amms_pos_notify_secure(void *addr)
  289. {
  290. /* notify other user, such as ATF */
  291. if (amms_pos_size_at_img)
  292. plat_md_bank4_amms_pos_notify_secure(
  293. (unsigned long)(addr + amms_pos_offset),
  294. 0x40000000 + amms_pos_offset, amms_pos_size_at_img);
  295. }
  296. typedef struct _sib_item {
  297. unsigned long long md1_sib_addr;
  298. unsigned int md1_sib_size;
  299. } sib_item_t;
  300. #ifdef ENABLE_EMI_PROTECTION
  301. static void md_sib_mpu_set(sib_item_t *sib_cfg);
  302. #endif
  303. static void sib_memory_init(void)
  304. {
  305. unsigned int sib_size;
  306. sib_item_t sib_info;
  307. /* sib part */
  308. memset(&sib_info, 0, sizeof(sib_item_t));
  309. sib_size = str2uint(get_env("md1_phy_cap_gear"));
  310. ALWAYS_LOG("env[sib_size]%x.\n", sib_size);
  311. sib_info.md1_sib_size = sib_size * 1024 * 1024;
  312. if (sib_info.md1_sib_size > 0x60000000)
  313. sib_info.md1_sib_size = 0x60000000;
  314. if (sib_info.md1_sib_size) {
  315. sib_info.md1_sib_addr = resv_sib_named_memory("md1_sib_mem", sib_info.md1_sib_size);
  316. ALWAYS_LOG("md1_sib_addr = 0x%llx\n", sib_info.md1_sib_addr);
  317. if (sib_info.md1_sib_addr == 0) {
  318. ALWAYS_LOG("allocate MD phy capture memory fail\n");
  319. return;
  320. } else
  321. md_sib_rw_remapping(sib_info.md1_sib_addr);
  322. } else {
  323. ALWAYS_LOG("MD phy capture memory size is 0\n");
  324. return;
  325. }
  326. if (insert_ccci_tag_inf("md1_sib_info", (char*)&sib_info,
  327. sizeof(sib_info)) < 0)
  328. ALWAYS_LOG("insert md1_sib_addr fail\n");
  329. #ifdef ENABLE_EMI_PROTECTION
  330. md_sib_mpu_set(&sib_info);
  331. #endif
  332. }
  333. #ifdef CCCI_USE_DFD_OFFSET_0
  334. static int get_dfd_size_from_dts(unsigned int *dfd_size)
  335. {
  336. int nodeoffset;
  337. unsigned int *data = NULL;
  338. int len = 0;
  339. int dfd_enabled;
  340. char *node_1 = "mediatek,dfd_cache";
  341. char *node_2 = "mediatek,enabled";
  342. void *kernel_fdt = get_kernel_fdt();
  343. if (kernel_fdt == NULL) {
  344. ALWAYS_LOG("[%s] error: kernel fdt is NULL!\n", __func__);
  345. return -1;
  346. }
  347. nodeoffset = fdt_node_offset_by_compatible(kernel_fdt, -1, node_1);
  348. if (nodeoffset < 0) {
  349. ALWAYS_LOG("[%s] error: '%s' not found!\n", __func__, node_1);
  350. return -1;
  351. }
  352. data = (unsigned int *)fdt_getprop(kernel_fdt,
  353. nodeoffset, node_2, &len);
  354. if (data == NULL) {
  355. ALWAYS_LOG("[%s] error: get '%s' fail.\n", __func__, node_2);
  356. return -1;
  357. }
  358. dfd_enabled = fdt32_to_cpu(*(unsigned int *)data);
  359. if (dfd_enabled)
  360. *dfd_size = cfg_dfd.large_buffer_length;
  361. else
  362. *dfd_size = cfg_dfd.buffer_length;
  363. ALWAYS_LOG("[%s] DFD dfd_enabled = %d, len = %d, dfd_size = %u\n",
  364. __func__, dfd_enabled, len, *dfd_size);
  365. return 0;
  366. }
  367. static int cal_nc_share_mem_size(void)
  368. {
  369. unsigned int align_sz, nc_size, offset, size;
  370. sib_memory_init(); /* Alloc large size memory, at 1st */
  371. /* MD Share memory layout */
  372. /* AP <--> MD1 */
  373. smem_info.ap_md1_smem_offset = 0;
  374. smem_info.md1_md3_smem_offset = 0;
  375. smem_info.ap_md3_smem_offset = 0;
  376. smem_info.md1_md3_smem_size = 0;
  377. smem_info.ap_md3_smem_size = 0;
  378. nc_size = 0;
  379. /* DFD */
  380. if (get_dfd_size_from_dts(&size) < 0)
  381. size = CCCI_SMEM_SIZE_DFD;
  382. align_sz = get_align_sz_by_user(nc_size, SMEM_USER_RAW_DFD);
  383. ALWAYS_LOG("[NC] align size for DFD: 0x%x\n", align_sz);
  384. nc_size += align_sz;
  385. offset = nc_size;
  386. nc_size += size;
  387. ALWAYS_LOG("[NC] block: DFD: 0x%x(0x%x)<0x%x>\n", offset, size, nc_size);
  388. update_nc_smem_info(SMEM_USER_RAW_DFD, offset, offset, size);
  389. /* UDC */
  390. if (udc_support_at_img) {
  391. size = CCCI_SMEM_SIZE_UDC_NONCACHE;
  392. align_sz = get_align_sz_by_user(nc_size, SMEM_USER_RAW_UDC_DATA);
  393. ALWAYS_LOG("[NC] align size for UDC: 0x%x\n", align_sz);
  394. nc_size += align_sz;
  395. offset = nc_size;
  396. nc_size += size;
  397. ALWAYS_LOG("[NC] block: UDC: 0x%x(0x%x)<0x%x>\n", offset, size, nc_size);
  398. update_nc_smem_info(SMEM_USER_RAW_UDC_DATA, offset, offset, size);
  399. }
  400. /* WIFI Proxy */
  401. size = CCCI_SMEM_WIFI_MD_PROXY;
  402. align_sz = get_align_sz_by_user(nc_size, SMEM_USER_MD_WIFI_PROXY);
  403. ALWAYS_LOG("[NC] align size for WIFI Proxy: 0x%x\n", align_sz);
  404. nc_size += align_sz;
  405. offset = nc_size;
  406. nc_size += size;
  407. ALWAYS_LOG("[NC] block: WIFI proxy: 0x%x(0x%x)<0x%x>\n", offset, size, nc_size);
  408. update_nc_smem_info(SMEM_USER_MD_WIFI_PROXY, offset, offset, size);
  409. /*CCCI_SMEM_AP_MD_SECURITY*/
  410. size = CCCI_SMEM_SIZE_SECURITY;
  411. align_sz = get_align_sz_by_user(nc_size, SMEM_USER_SECURITY_SMEM);
  412. ALWAYS_LOG("[NC] align size for SECURITY: 0x%x\n", align_sz);
  413. nc_size += align_sz;
  414. offset = nc_size;
  415. nc_size += size;
  416. ALWAYS_LOG("[NC] block: AP_MD1_SECURITY: 0x%x(0x%x)<0x%x>\n", offset, size, nc_size);
  417. update_nc_smem_info(SMEM_USER_SECURITY_SMEM, offset, offset, size);
  418. /* AMMS POS */
  419. if (amms_pos_size_at_img) {
  420. align_sz = get_align_sz_by_user(nc_size, SMEM_USER_RAW_AMMS_POS);
  421. ALWAYS_LOG("[NC] align size for AMMS POS: 0x%x\n", align_sz);
  422. nc_size += align_sz;
  423. amms_pos_offset = nc_size;
  424. align_sz = (nc_size + 0x400000 -1)&(~(0x400000 -1));
  425. align_sz -= nc_size;
  426. ALWAYS_LOG("[NC] align size for AMMS POS(4M): 0x%x\n", align_sz);
  427. amms_pos_size_at_img += align_sz;
  428. nc_size += amms_pos_size_at_img;
  429. /*pass AMMS POS size to Kernel*/
  430. if (insert_ccci_tag_inf("smem_amms_pos_size",
  431. (char*)&amms_pos_size_at_img, sizeof(int)) < 0)
  432. ALWAYS_LOG("insert amms_pos_size fail\n");
  433. ALWAYS_LOG("amms_pos_size: 0x%x\n", amms_pos_size_at_img);
  434. }
  435. /* AP/MD CCCI */
  436. offset = nc_size;
  437. size = AP_MD1_SMEM_SIZE;
  438. nc_size += size;
  439. ALWAYS_LOG("[NC] block: AP/MD CCCI: 0x%x(0x%x)<0x%x>\n", offset, size, nc_size);
  440. align_sz = get_align_sz(nc_size, 0x10000); /* 64K align */
  441. ALWAYS_LOG("[NC] align size for final: 0x%x\n", align_sz);
  442. nc_size += align_sz;
  443. smem_info.ap_md1_smem_size = nc_size;
  444. /* total_smem_size: in factly, this is for MD MPU, not ap-md share total size. */
  445. smem_info.total_smem_size = nc_size;
  446. ALWAYS_LOG("smem_info.ap_md1_smem_offset: %x\n", smem_info.ap_md1_smem_offset);
  447. ALWAYS_LOG("smem_info.ap_md1_smem_size: %x\n", smem_info.ap_md1_smem_size);
  448. ALWAYS_LOG("smem_info.ap_md3_smem_offset: %x\n", smem_info.ap_md3_smem_offset);
  449. ALWAYS_LOG("smem_info.ap_md3_smem_size: %x\n", smem_info.ap_md3_smem_size);
  450. ALWAYS_LOG("smem_info.md1_md3_smem_offset: %x\n", smem_info.md1_md3_smem_offset);
  451. ALWAYS_LOG("smem_info.md1_md3_smem_size: %x\n", smem_info.md1_md3_smem_size);
  452. ALWAYS_LOG("smem_info.total_smem_size: %x\n", smem_info.total_smem_size);
  453. ALWAYS_LOG("amms_pos_offset: %x\n", amms_pos_offset);
  454. add_nc_smem_to_tag_inf();
  455. return (int)smem_info.total_smem_size; /* non-cacheable */
  456. }
  457. #else
  458. static int cal_nc_share_mem_size(void)
  459. {
  460. unsigned int align_sz, nc_size, offset, size;
  461. sib_memory_init(); /* Alloc large size memory, at 1st */
  462. /* MD Share memory layout */
  463. /* AP <--> MD1 */
  464. smem_info.ap_md1_smem_offset = 0;
  465. smem_info.md1_md3_smem_offset = 0;
  466. smem_info.ap_md3_smem_offset = 0;
  467. smem_info.md1_md3_smem_size = 0;
  468. smem_info.ap_md3_smem_size = 0;
  469. nc_size = 0;
  470. /* AP/MD CCCI */
  471. offset = 0;
  472. size = AP_MD1_SMEM_SIZE;
  473. nc_size += size;
  474. ALWAYS_LOG("[NC] block: AP/MD CCCI: 0x%x(0x%x)<0x%x>\n", offset, size, nc_size);
  475. /* UDC */
  476. if (udc_support_at_img) {
  477. size = CCCI_SMEM_SIZE_UDC_NONCACHE;
  478. align_sz = get_align_sz_by_user(nc_size, SMEM_USER_RAW_UDC_DATA);
  479. ALWAYS_LOG("[NC] align size for UDC: 0x%x\n", align_sz);
  480. nc_size += align_sz;
  481. offset = nc_size;
  482. nc_size += size;
  483. ALWAYS_LOG("[NC] block: UDC: 0x%x(0x%x)<0x%x>\n", offset, size, nc_size);
  484. update_nc_smem_info(SMEM_USER_RAW_UDC_DATA, offset, offset, size);
  485. }
  486. /* WIFI Proxy */
  487. size = CCCI_SMEM_WIFI_MD_PROXY;
  488. align_sz = get_align_sz_by_user(nc_size, SMEM_USER_MD_WIFI_PROXY);
  489. ALWAYS_LOG("[NC] align size for WIFI Proxy: 0x%x\n", align_sz);
  490. nc_size += align_sz;
  491. offset = nc_size;
  492. nc_size += size;
  493. ALWAYS_LOG("[NC] block: WIFI proxy: 0x%x(0x%x)<0x%x>\n", offset, size, nc_size);
  494. update_nc_smem_info(SMEM_USER_MD_WIFI_PROXY, offset, offset, size);
  495. /* DFD */
  496. size = CCCI_SMEM_SIZE_DFD;
  497. align_sz = get_align_sz_by_user(nc_size, SMEM_USER_RAW_DFD);
  498. ALWAYS_LOG("[NC] align size for DFD: 0x%x\n", align_sz);
  499. nc_size += align_sz;
  500. offset = nc_size;
  501. nc_size += size;
  502. ALWAYS_LOG("[NC] block: DFD: 0x%x(0x%x)<0x%x>\n", offset, size, nc_size);
  503. update_nc_smem_info(SMEM_USER_RAW_DFD, offset, offset, size);
  504. /* AMMS POS */
  505. if (amms_pos_size_at_img) {
  506. align_sz = get_align_sz_by_user(nc_size, SMEM_USER_RAW_AMMS_POS);
  507. ALWAYS_LOG("[NC] align size for AMMS POS: 0x%x\n", align_sz);
  508. nc_size += align_sz;
  509. amms_pos_offset = nc_size;
  510. align_sz = (nc_size + 0x400000 -1)&(~(0x400000 -1));
  511. align_sz -= nc_size;
  512. ALWAYS_LOG("[NC] align size for AMMS POS(4M): 0x%x\n", align_sz);
  513. amms_pos_size_at_img += align_sz;
  514. nc_size += amms_pos_size_at_img;
  515. /*pass AMMS POS size to Kernel*/
  516. if (insert_ccci_tag_inf("smem_amms_pos_size",
  517. (char*)&amms_pos_size_at_img, sizeof(int)) < 0)
  518. ALWAYS_LOG("insert amms_pos_size fail\n");
  519. ALWAYS_LOG("amms_pos_size: 0x%x\n", amms_pos_size_at_img);
  520. }
  521. align_sz = get_align_sz(nc_size, 0x10000); /* 64K align */
  522. ALWAYS_LOG("[NC] align size for final: 0x%x\n", align_sz);
  523. nc_size += align_sz;
  524. smem_info.ap_md1_smem_size = nc_size;
  525. /* total_smem_size: in factly, this is for MD MPU, not ap-md share total size. */
  526. smem_info.total_smem_size = nc_size;
  527. ALWAYS_LOG("smem_info.ap_md1_smem_offset: %x\n", smem_info.ap_md1_smem_offset);
  528. ALWAYS_LOG("smem_info.ap_md1_smem_size: %x\n", smem_info.ap_md1_smem_size);
  529. ALWAYS_LOG("smem_info.ap_md3_smem_offset: %x\n", smem_info.ap_md3_smem_offset);
  530. ALWAYS_LOG("smem_info.ap_md3_smem_size: %x\n", smem_info.ap_md3_smem_size);
  531. ALWAYS_LOG("smem_info.md1_md3_smem_offset: %x\n", smem_info.md1_md3_smem_offset);
  532. ALWAYS_LOG("smem_info.md1_md3_smem_size: %x\n", smem_info.md1_md3_smem_size);
  533. ALWAYS_LOG("smem_info.total_smem_size: %x\n", smem_info.total_smem_size);
  534. ALWAYS_LOG("amms_pos_offset: %x\n", amms_pos_offset);
  535. add_nc_smem_to_tag_inf();
  536. return (int)smem_info.total_smem_size; /* non-cacheable */
  537. }
  538. #endif
  539. #define SMEM_MD_CONSYS_SIZE (43*1024*1024)
  540. #define SMEM_MD_NVRAM_CACHE_SIZE (18*1024*1024) /* LID */
  541. #define SMEM_MD_USIP_SIZE (384*1024) /* Audio */
  542. static csmem_item_t csmem_layout[] = {
  543. {0, 0, SMEM_MD_CONSYS_SIZE, SMEM_USER_RAW_MD_CONSYS},
  544. {0, 0, SMEM_MD_NVRAM_CACHE_SIZE, SMEM_USER_MD_NVRAM_CACHE},
  545. {0, 0, (22*1024*1024), SMEM_USER_CCB_START},
  546. {0, 0, 0, SMEM_USER_RAW_UDC_DESCTAB},
  547. {0, 0, SMEM_MD_USIP_SIZE, SMEM_USER_RAW_USIP}, /* audio */
  548. };
  549. /* Dynamic CCB seciton */
  550. struct ccb_gear_id_mapping {
  551. unsigned int gear_id;
  552. unsigned int size;
  553. };
  554. const struct ccb_gear_id_mapping ccb_support_tbl[] = {
  555. {1, 22 * 1024 * 1024},
  556. {2, 12 * 1024 * 1024},
  557. {3, 0 * 1024 * 1024},
  558. {4, 32 * 1024 * 1024},
  559. {11, 4 * 1024 * 1024},
  560. {12, 64 * 1024 * 1024}
  561. };
  562. static unsigned int get_ccb_size_from_gear_id(unsigned int gear_id)
  563. {
  564. int i;
  565. for (i = 0; i < (int)(sizeof(ccb_support_tbl)/sizeof(struct ccb_gear_id_mapping)); i++) {
  566. if (gear_id == ccb_support_tbl[i].gear_id)
  567. return ccb_support_tbl[i].size;
  568. }
  569. return 0xFFFFFFFF;
  570. }
  571. static void set_ccb_gear_val(unsigned int gear_id)
  572. {
  573. int ret;
  574. char env_buf[12];
  575. memset(env_buf, 0, sizeof(env_buf));
  576. snprintf(env_buf, sizeof(env_buf), "%u", gear_id);
  577. ret = set_env("md1_ccb_cap_gear", env_buf);
  578. if (ret < 0) {
  579. ALWAYS_LOG("set env[md1_ccb_cap_gear]fail, ret=%d\n", ret);
  580. assert(0);
  581. } else
  582. ALWAYS_LOG("set env[md1_ccb_cap_gear]%d\n", gear_id);
  583. }
  584. static unsigned int get_ccb_gear_val(void)
  585. {
  586. unsigned int md1_ccb_cap_gear;
  587. unsigned int md1_ccb_size;
  588. if (g_boot_mode == META_BOOT || true == get_atm_enable_status()) {
  589. ALWAYS_LOG("meta mode[md1_ccb_cap_gear]%d\n", CCB_DATA_BUF_DEFAULT_GEAR);
  590. set_ccb_gear_val(CCB_DATA_BUF_DEFAULT_GEAR);
  591. return CCB_DATA_BUF_DEFAULT_GEAR;
  592. }
  593. md1_ccb_cap_gear = str2uint(get_env("md1_ccb_cap_gear"));
  594. if (md1_ccb_cap_gear != 0) {
  595. md1_ccb_size = get_ccb_size_from_gear_id(md1_ccb_cap_gear);
  596. if (md1_ccb_size == 0xFFFFFFFF) {
  597. ALWAYS_LOG("CCB cfg abnormal!!! un-support ccb gear id: %d\n", md1_ccb_cap_gear);
  598. assert(0);
  599. }
  600. ALWAYS_LOG("get env[md1_ccb_cap_gear]%d\n", md1_ccb_cap_gear);
  601. return md1_ccb_cap_gear;
  602. } else {
  603. #ifdef MTK_DYNAMIC_CCB_BUFFER_GEAR_ID
  604. md1_ccb_cap_gear = MTK_DYNAMIC_CCB_BUFFER_GEAR_ID;
  605. #else
  606. md1_ccb_cap_gear = CCB_DATA_BUF_DEFAULT_GEAR;
  607. #endif
  608. set_ccb_gear_val(md1_ccb_cap_gear);
  609. return md1_ccb_cap_gear;
  610. }
  611. }
  612. static void set_gear_id_list()
  613. {
  614. int ret;
  615. ret = set_env("md1_ccb_gear_list",
  616. "1(2,20);2(2,10);3(0,0);4(2,30);11(2,2);12(2,62)");
  617. if (ret) {
  618. ALWAYS_LOG("set_gear_id_list error: %x\n", ret);
  619. }
  620. }
  621. static int cal_c_smem_size_and_layout(int load_flag)
  622. {
  623. unsigned int md1_ccb_cap_gear;
  624. unsigned int md1_bank4_cache_offset;
  625. unsigned int md1_ccb_size = CCB_DATA_BUF_SIZE;
  626. unsigned char *ccb_data_buf = NULL;
  627. unsigned char *cacheable_buf = NULL;
  628. unsigned int cacheable_buf_sz = 0;
  629. unsigned int i;
  630. unsigned int alignment;
  631. unsigned int offset;
  632. unsigned int region_size;
  633. unsigned int padding_size;
  634. #if WITH_GZ_MD_SHAREMEM
  635. unsigned int mtee_support = 1;
  636. #endif
  637. ALWAYS_LOG("smem_info.base_addr: %x\n", (unsigned int)smem_info.base_addr);
  638. md1_ccb_cap_gear = get_ccb_gear_val();
  639. md1_ccb_size = get_ccb_size_from_gear_id(md1_ccb_cap_gear);
  640. set_gear_id_list();
  641. ALWAYS_LOG("allocate ccb data buffer0x%x\n", md1_ccb_size);
  642. if (insert_ccci_tag_inf("ccb_gear_id", (char*)&md1_ccb_cap_gear, sizeof(unsigned int)) < 0)
  643. ALWAYS_LOG("insert ccb_gear_id fail\n");
  644. /* cacheable MD cacheable share memory layout */
  645. offset = 0;
  646. for (i = 0; i < sizeof(csmem_layout)/sizeof(csmem_item_t); i++) {
  647. /* Runtime update for special */
  648. switch (csmem_layout[i].item_cnt) {
  649. case SMEM_USER_RAW_MD_CONSYS:
  650. csmem_layout[i].csmem_buffer_size = consys_size_at_img;
  651. ALWAYS_LOG("cal_c_smem_size_and_layout: 0x%x\n", consys_size_at_img);
  652. break;
  653. case SMEM_USER_CCB_START:
  654. csmem_layout[i].csmem_buffer_size = md1_ccb_size;
  655. break;
  656. case SMEM_USER_RAW_UDC_DESCTAB:
  657. if (udc_support_at_img) {
  658. csmem_layout[i].csmem_buffer_size = CCCI_SMEM_SIZE_UDC_CACHE;
  659. ALWAYS_LOG("UDC cache size: 0x%x\n", CCCI_SMEM_SIZE_UDC_CACHE);
  660. }
  661. break;
  662. case SMEM_USER_MD_NVRAM_CACHE:
  663. if (nv_cache_shm_size_at_img) {
  664. csmem_layout[i].csmem_buffer_size = nv_cache_shm_size_at_img;
  665. ALWAYS_LOG("NV cache size adjust to: 0x%x\n",
  666. nv_cache_shm_size_at_img);
  667. }
  668. break;
  669. default:
  670. break;
  671. }
  672. region_size = csmem_layout[i].csmem_buffer_size;
  673. alignment = get_align_ref(csmem_layout[i].item_cnt);
  674. if (offset && alignment) {
  675. padding_size = get_align_sz(offset, alignment);
  676. if (padding_size) {
  677. offset += padding_size;
  678. cacheable_buf_sz += padding_size;
  679. }
  680. } else
  681. padding_size = 0;
  682. csmem_layout[i].md_offset = offset;
  683. cacheable_buf_sz += region_size;
  684. offset += region_size;
  685. }
  686. if (cacheable_buf_sz != 0) {
  687. ALWAYS_LOG("[C] before align: 0x%x\n", cacheable_buf_sz);
  688. cacheable_buf_sz += get_align_sz(cacheable_buf_sz, 0x10000);
  689. ALWAYS_LOG("[C] after align: 0x%x\n", cacheable_buf_sz);
  690. cacheable_buf = ccci_request_mem(cacheable_buf_sz, 0x90000000LL, 0x2000000L);
  691. }
  692. if (cacheable_buf_sz == 0) {
  693. csmem_info.csmem_buffer_addr = 0;
  694. csmem_info.csmem_buffer_size = 0;
  695. csmem_info.item_cnt = 0;
  696. ccb_info.ccb_data_buffer_addr = 0;
  697. ccb_info.ccb_data_buffer_size = 0;
  698. ALWAYS_LOG("allocate ccb data buffer share memory fail\n");
  699. } else {
  700. csmem_info.csmem_buffer_addr = (unsigned long long)((unsigned long)cacheable_buf);
  701. csmem_info.md_offset = MAX_SMEM_SIZE - CACHABLE_SMEM_MAX_SIZE;
  702. csmem_info.csmem_buffer_size = cacheable_buf_sz;
  703. csmem_info.item_cnt = sizeof(csmem_layout)/sizeof(csmem_item_t);
  704. ALWAYS_LOG("cache_buffer_addr: %x\n", (unsigned int)csmem_info.csmem_buffer_addr);
  705. ALWAYS_LOG("cache_buffer_size: %x\n", csmem_info.csmem_buffer_size);
  706. ALWAYS_LOG("cache_buffer_itm_cnt: %x\n", (unsigned int)csmem_info.item_cnt);
  707. for (i = 0; i < sizeof(csmem_layout)/sizeof(csmem_item_t); i++) {
  708. csmem_layout[i].csmem_buffer_addr = (unsigned long long)csmem_layout[i].md_offset
  709. + csmem_info.csmem_buffer_addr;
  710. if (csmem_layout[i].item_cnt == SMEM_USER_CCB_START)
  711. ccb_data_buf = (unsigned char *)((unsigned long)csmem_layout[i].csmem_buffer_addr);
  712. }
  713. if (insert_ccci_tag_inf("md1_bank4_cache_info", (char *)&csmem_info,
  714. sizeof(csmem_info)) < 0)
  715. ALWAYS_LOG("insert md1_smem_cahce_info fail\n");
  716. if (insert_ccci_tag_inf("md1_bank4_cache_layout", (char *)&csmem_layout,
  717. sizeof(csmem_layout)) < 0)
  718. ALWAYS_LOG("insert md1_smem_cahce_layout fail\n");
  719. for (i = 0; i < sizeof(csmem_layout)/sizeof(csmem_item_t); i++) {
  720. ALWAYS_LOG("cache[%d]_buffer_addr: %x\n", i,
  721. (unsigned int)csmem_layout[i].csmem_buffer_addr);
  722. ALWAYS_LOG("cache[%d]_buffer_offset: %x\n", i,
  723. (unsigned int)csmem_layout[i].md_offset);
  724. ALWAYS_LOG("cache[%d]_buffer_size: %x\n", i,
  725. csmem_layout[i].csmem_buffer_size);
  726. }
  727. ccb_info.ccb_data_buffer_addr = (unsigned long long)((unsigned long)ccb_data_buf);
  728. ccb_info.ccb_data_buffer_size = md1_ccb_size;
  729. /* CCB must in last 2*32M */
  730. md1_bank4_cache_offset = MAX_SMEM_SIZE - CACHABLE_SMEM_MAX_SIZE;
  731. if (insert_ccci_tag_inf("md1_smem_cahce_offset", (char*)&md1_bank4_cache_offset,
  732. sizeof(md1_bank4_cache_offset)) < 0)
  733. ALWAYS_LOG("insert md1_smem_cahce_offset fail\n");
  734. if (insert_ccci_tag_inf("ccb_info", (char*)&ccb_info, sizeof(ccb_layout_t)) < 0)
  735. ALWAYS_LOG("insert ccb_info fail\n");
  736. ALWAYS_LOG("ccb_info.ccb_data_buffer_addr: %x\n", (unsigned int)ccb_info.ccb_data_buffer_addr);
  737. ALWAYS_LOG("ccb_info.ccb_data_buffer_size: %x\n", ccb_info.ccb_data_buffer_size);
  738. }
  739. /* cacheable memory End */
  740. ALWAYS_LOG("smem_info.total_smem_size: %x\n", smem_info.total_smem_size);
  741. /* insert share memory layout to lk info */
  742. if (insert_ccci_tag_inf("smem_layout", (char*)&smem_info, sizeof(smem_layout_t)) < 0)
  743. ALWAYS_LOG("insert smem_layout fail\n");
  744. /* slot 5 */
  745. #if WITH_GZ_MD_SHAREMEM
  746. if (g_boot_arg->gz_md_shm_pa && g_boot_arg->gz_md_shm_sz) {
  747. ALWAYS_LOG("mtee.base_addr: 0x%x, 0x%x\n",
  748. (unsigned int)g_boot_arg->gz_md_shm_pa, g_boot_arg->gz_md_shm_sz);
  749. if (insert_ccci_tag_inf("mtee_support", (char *)&mtee_support,
  750. sizeof(mtee_support)) < 0)
  751. ALWAYS_LOG("insert mtee_support fail\n");
  752. }
  753. #endif
  754. return (int)smem_info.total_smem_size;
  755. }
  756. /***************************************************************************************************
  757. ** HW remap section
  758. ***************************************************************************************************/
  759. extern unsigned int ddr_enable_4gb(void)__attribute__((weak));
  760. static int is_4gb_ddr_support_en(void)
  761. {
  762. int ret;
  763. if (ddr_enable_4gb) {
  764. ret = ddr_enable_4gb();
  765. ALWAYS_LOG("ddr_enable_4GB sta:%d\n", ret);
  766. return ret;
  767. } else {
  768. ALWAYS_LOG("ddr 4GB disable\n");
  769. return 0;
  770. }
  771. }
  772. int md_sib_rw_remapping(unsigned long long addr)
  773. {
  774. unsigned long long md_sib_start_addr;
  775. size_t r1, r2, r3;
  776. size_t ret;
  777. ALWAYS_LOG("[%s] addr: 0x%llX\n", __func__, addr);
  778. md_sib_start_addr = addr;
  779. ret = mt_secure_call_ret4(MTK_SIP_BL_CCCI_CONTROL_AARCH32,
  780. MD_SIB_HW_REMAP,
  781. (u32)md_sib_start_addr, (u32)(md_sib_start_addr >> 32), 0,
  782. &r1, &r2, &r3);
  783. if (ret == (size_t)CCCI_SECURE_RET_VALUE_LK) {
  784. ALWAYS_LOG("[%s] error: MD_SIB_HW_REMAP fail: 0x%zX\n", __func__, ret);
  785. return -1;
  786. } else {
  787. ALWAYS_LOG("SIBLOG_BANK_MAP0 value:0x%X\n", r1);
  788. ALWAYS_LOG("SIBLOG_BANK_MAP1 value:0x%X\n", r2);
  789. ALWAYS_LOG("SIBLOG_BANK_MAP2 value:0x%X\n", r3);
  790. }
  791. return 0;
  792. }
  793. static int md_mem_ro_rw_remapping(unsigned int md_id, unsigned long long addr)
  794. {
  795. unsigned long long md_img_start_addr;
  796. size_t ret, r1, r2, r3;
  797. ALWAYS_LOG("---> Map 0x00000000 to 0x%llx for MD%d\n", addr, md_id+1);
  798. md_img_start_addr = addr; /* 0M~256M */
  799. ret = mt_secure_call_ret4(MTK_SIP_BL_CCCI_CONTROL_AARCH32,
  800. MD_BANK0_HW_REMAP,
  801. (u32)md_img_start_addr, (u32)(md_img_start_addr >> 32), 0,
  802. &r1, &r2, &r3);
  803. if (ret == (size_t)CCCI_SECURE_RET_VALUE_LK) {
  804. ALWAYS_LOG("[%s] error: MD_BANK0_HW_REMAP fail: 0x%zX\n", __func__, ret);
  805. return -1;
  806. } else {
  807. ALWAYS_LOG("BANK0_MAP0 value:0x%X\n", r1);
  808. ALWAYS_LOG("BANK0_MAP1 value:0x%X\n", r2);
  809. ALWAYS_LOG("BANK0_MAP2 value:0x%X\n", r3);
  810. }
  811. /* md_img_start_addr = addr + 0x10000000; *//* 256M~512M ATF will add */
  812. ret = mt_secure_call_ret4(MTK_SIP_BL_CCCI_CONTROL_AARCH32,
  813. MD_BANK1_HW_REMAP,
  814. (u32)md_img_start_addr, (u32)(md_img_start_addr >> 32), 0,
  815. &r1, &r2, &r3);
  816. if (ret == (size_t)CCCI_SECURE_RET_VALUE_LK) {
  817. ALWAYS_LOG("[%s] error: MD_BANK1_HW_REMAP fail: 0x%zX\n", __func__, ret);
  818. return -1;
  819. } else {
  820. ALWAYS_LOG("BANK1_MAP0 value:0x%zX\n", ret);
  821. ALWAYS_LOG("BANK1_MAP1 value:0x%X\n", r1);
  822. ALWAYS_LOG("BANK1_MAP2 value:0x%X\n", r2);
  823. ALWAYS_LOG("BANK1_MAP3 value:0x%X\n", r3);
  824. }
  825. return 0;
  826. }
  827. static int md_bank4_remapping_by_slot(unsigned int md_id, unsigned long long addr, int slot)
  828. {
  829. unsigned long long md_smem_start_addr;
  830. size_t ret, r1;
  831. ALWAYS_LOG("[%s] addr: 0x%llX\n", __func__, addr);
  832. md_smem_start_addr = addr;
  833. ret = mt_secure_call_ret2(MTK_SIP_BL_CCCI_CONTROL_AARCH32,
  834. MD_BANK4_HW_REMAP,
  835. (u32)md_smem_start_addr, (u32)(md_smem_start_addr >> 32), (size_t)slot,
  836. &r1);
  837. if (ret == (size_t)CCCI_SECURE_RET_VALUE_LK) {
  838. ALWAYS_LOG("[%s] error: MD_BANK4_HW_REMAP fail: 0x%zX\n", __func__, ret);
  839. return -1;
  840. } else
  841. ALWAYS_LOG("BANK4_MAP(%d) value:0x%X\n", slot, r1);
  842. return 0;
  843. }
  844. static int md_smem_rw_remapping(unsigned int md_id, unsigned long long addr)
  845. {
  846. unsigned int i, csmem_32M_cnt;
  847. ALWAYS_LOG("---> Map 0x40000000 to 0x%llx for MD%d\n", addr, md_id+1);
  848. csmem_32M_cnt = 8 - CACHABLE_SMEM_MAX_SIZE/(32*1024*1024);
  849. for (i = 0; i < csmem_32M_cnt; i++)
  850. md_bank4_remapping_by_slot(md_id, addr + 0x2000000*i, i);
  851. #if WITH_GZ_MD_SHAREMEM
  852. if (g_boot_arg->gz_md_shm_pa && g_boot_arg->gz_md_shm_sz) {
  853. md_bank4_remapping_by_slot(MD_SYS1, g_boot_arg->gz_md_shm_pa, 5);
  854. }
  855. #endif
  856. /* remapping cacheable to last 2*32M in bank4 */
  857. ALWAYS_LOG("---> Map 0x40000000+0x%x to 0x%llx for MD%d\n", csmem_info.md_offset,
  858. csmem_info.csmem_buffer_addr, md_id+1);
  859. for (i = csmem_32M_cnt; i < 8; i++)
  860. md_bank4_remapping_by_slot(md_id,
  861. csmem_info.csmem_buffer_addr + 0x2000000*(unsigned long long)(i-csmem_32M_cnt), i);
  862. return 0;
  863. }
  864. /* =================================================== */
  865. /* MPU Region defination */
  866. /* =================================================== */
  867. /* Note: This structure should sync with Kernel!!!! */
  868. typedef unsigned long long mpu_att_t;
  869. typedef struct _mpu_cfg {
  870. unsigned int start;
  871. unsigned int end;
  872. int region;
  873. unsigned int permission[EMI_MPU_DGROUP_NUM];
  874. int relate_region;
  875. } mpu_cfg_t;
  876. #define MPU_REGION_ID_MD1_SECURE_SHARE 8
  877. #define MPU_REGION_ID_MD1_ROM 10
  878. #define MPU_REGION_ID_MD_DSP1 11 /*DSP RO*/
  879. #define MPU_REGION_ID_MD_DSP2 12 /*DSP RW*/
  880. #define MPU_REGION_ID_MD_DRDI 13
  881. #define MPU_REGION_ID_MD1_MCURW_HWRW 14
  882. #define MPU_REGION_ID_MD1_MCURW_HWRO 15
  883. #define MPU_REGION_ID_MD1_MCURO_HWRW 16
  884. #define MPU_REGION_ID_MD1_TRACE_TOP 17
  885. #define MPU_REGION_ID_PADDING1 22
  886. #define MPU_REGION_ID_MD_CONSYS 23
  887. #define MPU_REGION_ID_MD1_C_SMEM 24 /* AP/MD SHM C */
  888. #define MPU_REGION_ID_MD1_NC_SMEM 25 /* AP/MD SHM UC */
  889. #define MPU_REGION_ID_AP 31
  890. #define MPU_REGION_ID_TOTAL_NUM (MPU_REGION_ID_AP + 1)
  891. #define MPU_MDOMAIN_ID_AP 0
  892. #define MPU_MDOMAIN_ID_MD1 1
  893. #define MPU_MDOMAIN_ID_MDHW 7
  894. #define MPU_MDOMAIN_ID_TOTAL_NUM 16
  895. static const mpu_att_t mpu_att_default[MPU_REGION_ID_TOTAL_NUM][MPU_MDOMAIN_ID_TOTAL_NUM] = {
  896. /*===================================================================================================================*/
  897. /* No | | D0(AP) | D1(MD1) | D2(CONN) | D3(SCP) | D4(MM) | D5(Rsv ) | D6(MFG) | D7(MDHW)
  898. |D8(SSPM) |D9(SPM) |D10(ADSP) | D11-15(Rsv) */
  899. /*--------------+-----------------------------------------------------------------------------------------------------------------------*/
  900. /* 0*/{}, /*Secure OS*/
  901. /* 1*/{}, /*ATF*/
  902. /* 2*/{}, /*Secure Memory*/
  903. /* 3*/{}, /*Tinysys-SSPM ROM*/
  904. /* 4*/{}, /*Tinysys-SSPM share buffer*/
  905. /* 5*/{}, /*Tinysys-SCP ROM*/
  906. /* 6*/{}, /*Tinysys-SCP share buffer*/
  907. /* 7*/{}, /*Trusted UI*/
  908. /* 8*/{ NO_PROTECTION, NO_PROTECTION, [2 ... 15] = FORBIDDEN}, /*Security CCCI share memory*/
  909. /* 9*/{}, /*AMMS*/
  910. /*10*/{ SEC_R_NSEC_R, SEC_R_NSEC_R, [2 ... 6] = FORBIDDEN, SEC_R_NSEC_R, [8 ... 15] = FORBIDDEN},
  911. /*11*/{ SEC_R_NSEC_R, SEC_R_NSEC_R, [2 ... 6] = FORBIDDEN, SEC_R_NSEC_R, [8 ... 15] = FORBIDDEN},
  912. /*12*/{ SEC_R_NSEC_R, NO_PROTECTION, [2 ... 6] = FORBIDDEN, NO_PROTECTION, [8 ... 15] = FORBIDDEN},
  913. /*13*/{ SEC_R_NSEC_R, SEC_R_NSEC_R, [2 ... 6] = FORBIDDEN, SEC_R_NSEC_R, [8 ... 15] = FORBIDDEN}, /*DRDI*/
  914. /*14*/{ SEC_R_NSEC_R, NO_PROTECTION, [2 ... 6] = FORBIDDEN, NO_PROTECTION, [8 ... 15] = FORBIDDEN},
  915. /*15*/{ SEC_R_NSEC_R, NO_PROTECTION, [2 ... 6] = FORBIDDEN, SEC_R_NSEC_R, [8 ... 15] = FORBIDDEN},
  916. /*16*/{ SEC_R_NSEC_R, SEC_R_NSEC_R, [2 ... 6] = FORBIDDEN, NO_PROTECTION, [8 ... 15] = FORBIDDEN},
  917. /*17*/{ SEC_R_NSEC_R, [1 ... 6] = FORBIDDEN, NO_PROTECTION, [8 ... 15] = FORBIDDEN}, /*MD trace_top*/
  918. /*18*/{},
  919. /*19*/{},
  920. /*20*/{},
  921. /*21*/{}, /*VPU*/
  922. /*22*/{}, /* Padding */
  923. /*23*/{ SEC_R_NSEC_R, NO_PROTECTION, NO_PROTECTION, [3 ... 6] = FORBIDDEN, NO_PROTECTION, [8 ... 15] = FORBIDDEN}, /* WIFI Driver */
  924. /*24*/{ NO_PROTECTION, NO_PROTECTION, [2 ... 6] = FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN,
  925. NO_PROTECTION, [11 ... 15] = FORBIDDEN},
  926. /*25*/{ NO_PROTECTION, NO_PROTECTION, FORBIDDEN, NO_PROTECTION,[4 ... 6] = FORBIDDEN, NO_PROTECTION,
  927. [8 ... 15] = FORBIDDEN},
  928. /*26*/{}, /*WIFI EMI FW*/
  929. /*27*/{}, /*WMT*/
  930. /*28*/{}, /*ADSP*/
  931. /*29*/{}, /*GPS offload*/
  932. /*30*/{}, /*Set in LK MD dynamic*/
  933. /*31*/{}, /* no need setting */
  934. };
  935. #define MPU_STR_BUF_SIZE 64
  936. static void get_mpu_attr_str(int lock, unsigned int apc[EMI_MPU_DGROUP_NUM], char buf[], int size)
  937. {
  938. unsigned long long curr_attr;
  939. char ch = lock?'L':'U';
  940. if (EMI_MPU_DGROUP_NUM != 2) {
  941. ALWAYS_LOG("[error]abnormal mpu domain group number %d\n", EMI_MPU_DGROUP_NUM);
  942. return;
  943. }
  944. curr_attr = ((unsigned long long)apc[1] << 32) | apc[0];
  945. snprintf(buf, size, "%lld-%lld-%lld-%lld-%lld-%lld-%lld-%lld-%lld-%lld-%lld-%lld-%lld-%lld-%lld-%lld(%c)",
  946. curr_attr&7, (curr_attr>>3)&7, (curr_attr>>6)&7, (curr_attr>>9)&7,
  947. (curr_attr>>12)&7, (curr_attr>>15)&7, (curr_attr>>18)&7, (curr_attr>>21)&7,
  948. (curr_attr>>32)&7, (curr_attr>>35)&7, (curr_attr>>38)&7, (curr_attr>>41)&7,
  949. (curr_attr>>44)&7, (curr_attr>>47)&7, (curr_attr>>50)&7, (curr_attr>>53)&7, ch);
  950. }
  951. static const unsigned char region_mapping_at_hdr_md1[] = {
  952. MPU_REGION_ID_MD1_ROM, MPU_REGION_ID_MD1_MCURO_HWRW, MPU_REGION_ID_MD1_MCURW_HWRO,
  953. MPU_REGION_ID_MD1_MCURW_HWRW
  954. };
  955. static const int free_mpu_region[] = {MPU_REGION_ID_PADDING1, -1, -1};
  956. static int curr_free_mpu_idx;
  957. static int get_free_mpu_region(void)
  958. {
  959. int ret;
  960. if (curr_free_mpu_idx < (int)(sizeof(free_mpu_region)/sizeof(int))) {
  961. ret = free_mpu_region[curr_free_mpu_idx];
  962. curr_free_mpu_idx++;
  963. } else
  964. ret = -LD_ERR_PLAT_MPU_REGION_EMPTY;
  965. return ret;
  966. }
  967. static void get_mpu_region_default_access_att(
  968. unsigned int apc[EMI_MPU_DGROUP_NUM], int region, int lock)
  969. {
  970. #ifdef ENABLE_EMI_PROTECTION
  971. SET_ACCESS_PERMISSION(apc, lock,
  972. mpu_att_default[region][15], mpu_att_default[region][14],
  973. mpu_att_default[region][13], mpu_att_default[region][12],
  974. mpu_att_default[region][11], mpu_att_default[region][10],
  975. mpu_att_default[region][9], mpu_att_default[region][8],
  976. mpu_att_default[region][7], mpu_att_default[region][6],
  977. mpu_att_default[region][5], mpu_att_default[region][4],
  978. mpu_att_default[region][3], mpu_att_default[region][2],
  979. mpu_att_default[region][1], mpu_att_default[region][0]);
  980. #endif
  981. }
  982. static void mpu_attr_calculate(
  983. unsigned int apc[EMI_MPU_DGROUP_NUM], int region_id, unsigned int request_attr)
  984. {
  985. mpu_att_t tmp_mpu_att[MPU_MDOMAIN_ID_TOTAL_NUM], i;
  986. for (i = 0; i < MPU_MDOMAIN_ID_TOTAL_NUM; i++)
  987. tmp_mpu_att[i] = mpu_att_default[region_id][i];
  988. /* AP MD1 MDHW: AP */
  989. if ((request_attr & 0xF) <= FORBIDDEN)
  990. tmp_mpu_att[MPU_MDOMAIN_ID_AP] = (request_attr & 0xF);
  991. /* AP MD1 MDHW: MD1 */
  992. request_attr = (request_attr >> 4);
  993. if ((request_attr & 0xF) <= FORBIDDEN)
  994. tmp_mpu_att[MPU_MDOMAIN_ID_MD1] = (request_attr & 0xF);
  995. /* AP MD1 MDHW: MDHW */
  996. request_attr = (request_attr >> 4);
  997. if ((request_attr & 0xF) <= FORBIDDEN)
  998. tmp_mpu_att[MPU_MDOMAIN_ID_MDHW] = (request_attr & 0xF);
  999. #ifdef ENABLE_EMI_PROTECTION
  1000. /* MPU region lock */
  1001. SET_ACCESS_PERMISSION(apc, 1,
  1002. tmp_mpu_att[15], tmp_mpu_att[14],
  1003. tmp_mpu_att[13], tmp_mpu_att[12],
  1004. tmp_mpu_att[11], tmp_mpu_att[10],
  1005. tmp_mpu_att[9], tmp_mpu_att[8],
  1006. tmp_mpu_att[7], tmp_mpu_att[6],
  1007. tmp_mpu_att[5], tmp_mpu_att[4],
  1008. tmp_mpu_att[3], tmp_mpu_att[2],
  1009. tmp_mpu_att[1], tmp_mpu_att[0]);
  1010. #endif
  1011. }
  1012. static void ccci_mem_access_cfg(mpu_cfg_t *mpu_cfg_list, int clear)
  1013. {
  1014. #ifdef ENABLE_EMI_PROTECTION
  1015. mpu_cfg_t *curr;
  1016. struct emi_region_info_t region_info;
  1017. unsigned int curr_attr[EMI_MPU_DGROUP_NUM];
  1018. char buf[MPU_STR_BUF_SIZE];
  1019. int i;
  1020. if (NULL == mpu_cfg_list)
  1021. return;
  1022. SET_ACCESS_PERMISSION(curr_attr, 0,
  1023. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  1024. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  1025. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  1026. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION);
  1027. for (curr = mpu_cfg_list; curr->region != -1; curr++) {
  1028. if (clear) {
  1029. region_info.region = (unsigned int)curr->region;
  1030. emi_mpu_clear_protection(&region_info);
  1031. get_mpu_attr_str(0, curr_attr, buf, MPU_STR_BUF_SIZE);
  1032. ALWAYS_LOG("Clr MPU:S:0x%x E:0x%x A:<%d>[0~15]%s\n",
  1033. 0, 0, curr->region, buf);
  1034. } else {
  1035. region_info.start = curr->start;
  1036. region_info.end = curr->end;
  1037. region_info.region = (unsigned int)curr->region;
  1038. for (i = 0; i < EMI_MPU_DGROUP_NUM; i++)
  1039. region_info.apc[i] = curr->permission[i];
  1040. emi_mpu_set_protection(&region_info);
  1041. get_mpu_attr_str(0, curr->permission, buf, MPU_STR_BUF_SIZE);
  1042. ALWAYS_LOG("Set MPU:S:0x%x E:0x%x A:<%d>[0~15]%s\n",
  1043. curr->start, curr->end, curr->region, buf);
  1044. }
  1045. }
  1046. #endif
  1047. }
  1048. /*--------- Implement one by one -------------------------------------------------------------------------------*/
  1049. int plat_get_padding_mpu_num(void)
  1050. {
  1051. return (int)(sizeof(free_mpu_region)/sizeof(unsigned int)) - 1;
  1052. }
  1053. void plat_notify_secure(unsigned long base_addr)
  1054. {
  1055. unsigned long addr_get;
  1056. mt_secure_call(MTK_SIP_LK_AMMS_MD_BASE_ADDR_AARCH32, base_addr, 0, 0, 0);
  1057. addr_get = mt_secure_call(MTK_SIP_LK_AMMS_GET_MD_BASE_ADDR_AARCH32, 0, 0, 0, 0);
  1058. ALWAYS_LOG("mt_secure_call: set_addr = 0x%lx, get_addr = 0x%lx\n", base_addr, addr_get);
  1059. }
  1060. /*---------------------------------------------------------------------------------------------------*/
  1061. /* HW remap function implement */
  1062. /*---------------------------------------------------------------------------------------------------*/
  1063. int plat_apply_hw_remap_for_md_ro_rw(void* info)
  1064. {
  1065. modem_info_t *md_ld_info = (modem_info_t *)info;
  1066. plat_notify_secure(md_ld_info->base_addr);
  1067. #ifdef DUMMY_AP_MODE
  1068. DRV_WriteReg32(0x10209100, (md_ld_info->base_addr >> 24));
  1069. #endif
  1070. return md_mem_ro_rw_remapping((unsigned int)md_ld_info->md_id, md_ld_info->base_addr);
  1071. }
  1072. int plat_apply_hw_remap_for_md_smem(void *addr, int size)
  1073. {
  1074. /* For share memory final size depends on MD number, just store start address and size
  1075. ** actual setting will do later
  1076. */
  1077. smem_info.base_addr = (unsigned long long)((unsigned long)addr);
  1078. return 0;
  1079. }
  1080. int mtk_ccci_get_dfd_smem_info(unsigned long long *ap_addr, unsigned int *md_addr, unsigned int *size)
  1081. {
  1082. unsigned int ap_offset;
  1083. unsigned int md_offset;
  1084. unsigned int smem_size;
  1085. if (!smem_info.base_addr) {
  1086. ALWAYS_LOG("[ccci]%s share memory not initialized done\n", __func__);
  1087. return -1;
  1088. }
  1089. if (get_nc_smem_info(SMEM_USER_RAW_DFD, &ap_offset, &md_offset, &smem_size) < 0)
  1090. return -1;
  1091. if (ap_addr)
  1092. *ap_addr = smem_info.base_addr + ap_offset;
  1093. if (md_addr)
  1094. *md_addr = 0x40000000 + md_offset;
  1095. if (size)
  1096. *size = smem_size;
  1097. ALWAYS_LOG("[ccci]%s: ap_addr = 0x%llx, md_addr = 0x%x, size = 0x%x\n", __func__,
  1098. smem_info.base_addr + ap_offset, 0x40000000 + md_offset, smem_size);
  1099. return 0;
  1100. }
  1101. int mtk_ccci_get_security_smem_info(unsigned long long *ap_addr, unsigned int *md_addr, unsigned int *size)
  1102. {
  1103. unsigned int ap_offset;
  1104. unsigned int md_offset;
  1105. unsigned int smem_size;
  1106. if (!smem_info.base_addr) {
  1107. ALWAYS_LOG("[ccci]%s share memory not initialized done\n", __func__);
  1108. return -1;
  1109. }
  1110. if (get_nc_smem_info(SMEM_USER_SECURITY_SMEM, &ap_offset, &md_offset, &smem_size) < 0)
  1111. return -1;
  1112. if (ap_addr)
  1113. *ap_addr = smem_info.base_addr + ap_offset;
  1114. if (md_addr)
  1115. *md_addr = 0x40000000 + md_offset;
  1116. if (size)
  1117. *size = smem_size;
  1118. ALWAYS_LOG("[ccci]%s: ap_addr = 0x%llx, md_addr = 0x%x, size = 0x%x\n", __func__,
  1119. smem_info.base_addr + ap_offset, 0x40000000 + md_offset, smem_size);
  1120. return 0;
  1121. }
  1122. /*---------------------------------------------------------------------------------------------------*/
  1123. /* check header info collection by plat_post_hdr_info */
  1124. /*---------------------------------------------------------------------------------------------------*/
  1125. void plat_post_hdr_info(void* hdr, int ver, int id)
  1126. {
  1127. if (id == MD_SYS1) {
  1128. ap_md1_smem_size_at_img =
  1129. ((struct md_check_header_v6*)hdr)->ap_md_smem_size;
  1130. //parsing check-header: AMMS POS, CONSYS
  1131. amms_pos_size_at_img =
  1132. ((struct md_check_header_v6*)hdr)->amms_pos_size;
  1133. consys_size_at_img =
  1134. ((struct md_check_header_v6*)hdr)->consys_size;
  1135. udc_support_at_img =
  1136. ((struct md_check_header_v6*)hdr)->udc_support;
  1137. nv_cache_shm_size_at_img =
  1138. ((struct md_check_header_v6*)hdr)->nv_cache_shm_size;
  1139. ALWAYS_LOG("[ccci]parse check-header: amms_pos_size = 0x%x, consys_size = 0x%x, udc_support = %d, nv_cache_size = 0x%x\n",
  1140. amms_pos_size_at_img, consys_size_at_img,
  1141. udc_support_at_img, nv_cache_shm_size_at_img);
  1142. }
  1143. }
  1144. /*---------------------------------------------------------------------------------------------------*/
  1145. /* MPU static global variable and mpu relate function implement */
  1146. /*---------------------------------------------------------------------------------------------------*/
  1147. #define MPU_REGION_TOTAL_NUM (16) /* = MD1+MD3 */
  1148. static mpu_cfg_t mpu_tbl[MPU_REGION_TOTAL_NUM];
  1149. static int s_g_curr_mpu_num;
  1150. /*
  1151. ** if set start=0x0, end=0x10000, the actural protected area will be 0x0-0x1FFFF,
  1152. ** here we use 64KB align, MPU actually request 32KB align since MT6582, but this works...
  1153. ** we assume emi_mpu_set_region_protection will round end address down to 64KB align.
  1154. */
  1155. static void dump_received_pure_mpu_setting(struct image_section_desc *mem_info, int item_num)
  1156. {
  1157. int i;
  1158. for (i =0; i < item_num; i++)
  1159. MPU_DBG_LOG("mpu sec dec %d: offset:%x, size:%x, mpu_attr:%x, ext_flag:%x, relate_idx:%x\n", i,
  1160. mem_info[i].offset, mem_info[i].size, mem_info[i].mpu_attr,
  1161. mem_info[i].ext_flag, mem_info[i].relate_idx);
  1162. }
  1163. static int find_bind_mpu_region(mpu_cfg_t *mpu_tbl_hdr, int item_num, unsigned int bind_key)
  1164. {
  1165. int i;
  1166. for (i = 0; i < item_num; i++) {
  1167. if (mpu_tbl_hdr[i].relate_region == (int)bind_key)
  1168. return i;
  1169. }
  1170. return -1;
  1171. }
  1172. static int md1_mpu_setting_process(void *p_md_ld_info, void *p_mem_info, mpu_cfg_t *mpu_tbl_hdr)
  1173. {
  1174. modem_info_t *md_ld_info = (modem_info_t *)p_md_ld_info;
  1175. struct image_section_desc *mem_info = (struct image_section_desc *)p_mem_info;
  1176. int normal_region_num = 0;
  1177. int total_region_num = 0;
  1178. int curr_idx = 0;
  1179. int i, j;
  1180. //int all_range_region_idx = -1;
  1181. int bind_idx;
  1182. int free_region_id;
  1183. int didi_region_idx = -1;
  1184. /* Calculate mpu num and padding num */
  1185. for (i = 0; i < MPU_REGION_TOTAL_NUM; i++) {
  1186. if ((mem_info[i].offset == 0) && (mem_info[i].size == 0))
  1187. break;
  1188. //if (mem_info[i].ext_flag & MD_ALL_RANGE)
  1189. // all_range_region_idx = i;
  1190. if (mem_info[i].ext_flag & MD_DRDI_REGION)
  1191. didi_region_idx = i;
  1192. }
  1193. total_region_num = i;
  1194. dump_received_pure_mpu_setting(mem_info, total_region_num);
  1195. for (i = 0; i < total_region_num; i++) {
  1196. if (mem_info[i].ext_flag & (MD_DRDI_REGION|MD_ALL_RANGE|NEED_REMOVE|NEED_MPU_MORE))
  1197. continue;
  1198. /* Process normal case first */
  1199. if (curr_idx >= (int)(sizeof(region_mapping_at_hdr_md1)/sizeof(unsigned char))) {
  1200. ALWAYS_LOG("[error]md%d: mpu region too more %d\n", md_ld_info->md_id+1,
  1201. (int)(sizeof(region_mapping_at_hdr_md1)/sizeof(unsigned char)));
  1202. return -LD_ERR_PLAT_MPU_REGION_TOO_MORE;
  1203. }
  1204. mpu_tbl_hdr[curr_idx].start = (unsigned int)md_ld_info->base_addr + mem_info[i].offset;
  1205. mpu_tbl_hdr[curr_idx].end = mpu_tbl_hdr[curr_idx].start + mem_info[i].size;
  1206. mpu_tbl_hdr[curr_idx].end = ((mpu_tbl_hdr[curr_idx].end + 0xFFFF)&(~0xFFFF)) - 1;/* 64K align */
  1207. mpu_attr_calculate(
  1208. mpu_tbl_hdr[curr_idx].permission, region_mapping_at_hdr_md1[curr_idx], mem_info[i].mpu_attr);
  1209. mpu_tbl_hdr[curr_idx].region = (int)region_mapping_at_hdr_md1[curr_idx];
  1210. mpu_tbl_hdr[curr_idx].relate_region = mem_info[i].relate_idx;
  1211. curr_idx++;
  1212. normal_region_num++;
  1213. }
  1214. if (normal_region_num != (int)(sizeof(region_mapping_at_hdr_md1)/sizeof(unsigned char))) {
  1215. ALWAYS_LOG("[error]md%d: mpu region not sync %d:%d\n", md_ld_info->md_id+1, normal_region_num,
  1216. (int)(sizeof(region_mapping_at_hdr_md1)/sizeof(unsigned char)));
  1217. return -LD_ERR_PLAT_MPU_REGION_NUM_NOT_SYNC;
  1218. }
  1219. for (i = 0; i < total_region_num; i++) {
  1220. if (mem_info[i].ext_flag & NEED_MPU_MORE) {
  1221. bind_idx = find_bind_mpu_region(mpu_tbl_hdr, curr_idx, mem_info[i].relate_idx);
  1222. if (bind_idx >= 0) {
  1223. mpu_tbl_hdr[curr_idx].start = (unsigned int)md_ld_info->base_addr + mem_info[i].offset;
  1224. mpu_tbl_hdr[curr_idx].end = mpu_tbl_hdr[curr_idx].start + mem_info[i].size;
  1225. /* 64K align */
  1226. mpu_tbl_hdr[curr_idx].end = ((mpu_tbl_hdr[curr_idx].end + 0xFFFF)&(~0xFFFF)) - 1;
  1227. for (j = 0; j < EMI_MPU_DGROUP_NUM; j++)
  1228. mpu_tbl_hdr[curr_idx].permission[j] = mpu_tbl_hdr[bind_idx].permission[j];
  1229. /* setting relate region */
  1230. free_region_id = get_free_mpu_region();
  1231. if (free_region_id < 0) {
  1232. ALWAYS_LOG("[error]abnormal free region id %d +\n", free_region_id);
  1233. return -LD_ERR_PLAT_ABNORMAL_FREE_REGION;
  1234. }
  1235. mpu_tbl_hdr[curr_idx].region = free_region_id;
  1236. mpu_tbl_hdr[curr_idx].relate_region = mem_info[i].relate_idx;
  1237. mpu_tbl_hdr[bind_idx].relate_region = free_region_id;
  1238. curr_idx++;
  1239. } else {
  1240. ALWAYS_LOG("md%d: padding array abnormal\n", md_ld_info->md_id+1);
  1241. return -LD_ERR_PLAT_ABNORMAL_PAD_ARRAY;
  1242. }
  1243. }
  1244. }
  1245. /* Apply DRDI if needed */
  1246. if (didi_region_idx >= 0) {
  1247. get_mpu_region_default_access_att(mpu_tbl_hdr[curr_idx].permission, MPU_REGION_ID_MD_DRDI, 1);
  1248. mpu_tbl_hdr[curr_idx].start = (unsigned int)md_ld_info->base_addr + mem_info[didi_region_idx].offset;
  1249. mpu_tbl_hdr[curr_idx].end = mpu_tbl_hdr[curr_idx].start + mem_info[didi_region_idx].size;
  1250. /* 64K align */
  1251. mpu_tbl_hdr[curr_idx].end = ((mpu_tbl_hdr[curr_idx].end + 0xFFFF)&(~0xFFFF)) - 1;
  1252. mpu_tbl_hdr[curr_idx].region = MPU_REGION_ID_MD_DRDI;
  1253. mpu_tbl_hdr[curr_idx].relate_region = 0;
  1254. curr_idx++;
  1255. }
  1256. /* Clear logic relate index to 0 to mark as end */
  1257. for (i = 0; i < curr_idx; i++) {
  1258. if (mpu_tbl_hdr[i].relate_region >= LOGIC_BINDING_IDX_START)
  1259. mpu_tbl_hdr[i].relate_region = 0;
  1260. }
  1261. return curr_idx;
  1262. }
  1263. int plat_send_mpu_info_to_platorm(void *p_md_ld_info, void *p_mem_info)
  1264. {
  1265. modem_info_t *md_ld_info = (modem_info_t *)p_md_ld_info;
  1266. struct image_section_desc *mem_info = (struct image_section_desc *)p_mem_info;
  1267. int md_id = md_ld_info->md_id;
  1268. int ret;
  1269. int i;
  1270. char buf[MPU_STR_BUF_SIZE];
  1271. if (md_id == MD_SYS1) {
  1272. ret = md1_mpu_setting_process(p_md_ld_info, p_mem_info, &mpu_tbl[s_g_curr_mpu_num]);
  1273. if (ret > 0)
  1274. s_g_curr_mpu_num += ret;
  1275. } else if (md_id == MD1_DSP) {
  1276. /* RO part */
  1277. get_mpu_region_default_access_att(mpu_tbl[s_g_curr_mpu_num].permission, MPU_REGION_ID_MD_DSP1, 1);
  1278. mpu_tbl[s_g_curr_mpu_num].start = (unsigned int)md_ld_info->base_addr + mem_info[0].offset;
  1279. mpu_tbl[s_g_curr_mpu_num].end = mpu_tbl[s_g_curr_mpu_num].start + mem_info[0].size;
  1280. mpu_tbl[s_g_curr_mpu_num].region = MPU_REGION_ID_MD_DSP1;
  1281. /* 64K align */
  1282. mpu_tbl[s_g_curr_mpu_num].end = ((mpu_tbl[s_g_curr_mpu_num].end + 0xFFFF)&(~0xFFFF)) - 1;
  1283. s_g_curr_mpu_num++;
  1284. /* RW part */
  1285. get_mpu_region_default_access_att(mpu_tbl[s_g_curr_mpu_num].permission, MPU_REGION_ID_MD_DSP2, 1);
  1286. mpu_tbl[s_g_curr_mpu_num].start = (unsigned int)md_ld_info->base_addr + mem_info[1].offset;
  1287. mpu_tbl[s_g_curr_mpu_num].end = mpu_tbl[s_g_curr_mpu_num].start + mem_info[1].size;
  1288. mpu_tbl[s_g_curr_mpu_num].region = MPU_REGION_ID_MD_DSP2;
  1289. /* 64K align */
  1290. mpu_tbl[s_g_curr_mpu_num].end = ((mpu_tbl[s_g_curr_mpu_num].end + 0xFFFF)&(~0xFFFF)) - 1;
  1291. s_g_curr_mpu_num++;
  1292. }
  1293. for (i =0; i < s_g_curr_mpu_num; i++) {
  1294. get_mpu_attr_str(0, mpu_tbl[i].permission, buf, MPU_STR_BUF_SIZE);
  1295. MPU_DBG_LOG("plat mpu dec %d: region:%d[%d], start:0x%x, end:0x%x, attr:%s\n", i,
  1296. mpu_tbl[i].region, mpu_tbl[i].relate_region, mpu_tbl[i].start, mpu_tbl[i].end, buf);
  1297. }
  1298. return 0;
  1299. }
  1300. #ifdef MPU_REGION_CONSYS_EN
  1301. static void emi_mpu_region_setting(unsigned int region, unsigned long long start, unsigned long long end, char name[])
  1302. {
  1303. #ifdef ENABLE_EMI_PROTECTION
  1304. struct emi_region_info_t region_info;
  1305. char buf[MPU_STR_BUF_SIZE];
  1306. SET_ACCESS_PERMISSION(region_info.apc, 0,
  1307. mpu_att_default[region][15], mpu_att_default[region][14],
  1308. mpu_att_default[region][13], mpu_att_default[region][12],
  1309. mpu_att_default[region][11], mpu_att_default[region][10],
  1310. mpu_att_default[region][9], mpu_att_default[region][8],
  1311. mpu_att_default[region][7], mpu_att_default[region][6],
  1312. mpu_att_default[region][5], mpu_att_default[region][4],
  1313. mpu_att_default[region][3], mpu_att_default[region][2],
  1314. mpu_att_default[region][1], mpu_att_default[region][0]);
  1315. region_info.start = start;
  1316. region_info.end = end;
  1317. region_info.region = region;
  1318. emi_mpu_set_protection(&region_info);
  1319. get_mpu_attr_str(0, region_info.apc, buf, MPU_STR_BUF_SIZE);
  1320. ALWAYS_LOG("Set MPU:S:0x%llx E:0x%llx A:<%d>[0~15]%s(%s)\n",
  1321. start, end, region, buf, name);
  1322. #endif
  1323. }
  1324. static void md_special_mpu_set()
  1325. {
  1326. unsigned int i;
  1327. for (i = 0; i < sizeof(csmem_layout)/sizeof(csmem_item_t); i++) {
  1328. if (!csmem_layout[i].csmem_buffer_size) {
  1329. ALWAYS_LOG("csmem[%d]<%d> size 0, skip\n", i, csmem_layout[i].item_cnt);
  1330. continue;
  1331. }
  1332. if (csmem_layout[i].item_cnt == SMEM_USER_RAW_MD_CONSYS) {
  1333. emi_mpu_region_setting(MPU_REGION_ID_MD_CONSYS,
  1334. (csmem_layout[i].md_offset + csmem_info.csmem_buffer_addr),
  1335. (csmem_layout[i].md_offset +csmem_layout[i].csmem_buffer_size + csmem_info.csmem_buffer_addr - 1),
  1336. "CONSYS");
  1337. break;
  1338. }
  1339. }
  1340. }
  1341. void md_sib_mpu_set(sib_item_t *sib_cfg)
  1342. {
  1343. emi_mpu_region_setting(MPU_REGION_ID_MD1_TRACE_TOP, sib_cfg->md1_sib_addr,
  1344. sib_cfg->md1_sib_addr + sib_cfg->md1_sib_size -1, "SIB");
  1345. }
  1346. #endif
  1347. static void boot_to_dummy_ap_mode(int load_md_flag);
  1348. /*------------------------------------------------------------------------------------------------*/
  1349. /* Note: This function using global variable
  1350. ** if set start=0x0, end=0x10000, the actural protected area will be 0x0-0x1FFFF,
  1351. ** here we use 64KB align, MPU actually request 32KB align since MT6582, but this works...
  1352. ** we assume emi_mpu_set_region_protection will round end address down to 64KB align.
  1353. */
  1354. int plat_apply_platform_setting(int load_md_flag)
  1355. {
  1356. int smem_final_size;
  1357. unsigned int ap_offset;
  1358. unsigned int md_offset;
  1359. unsigned int smem_size;
  1360. #ifdef DUMMY_AP_MODE
  1361. /* This function will never return */
  1362. ALWAYS_LOG("boot to dummy ap mode!!!\n");
  1363. boot_to_dummy_ap_mode(load_md_flag);
  1364. return 0;
  1365. #endif
  1366. /* Check loading validation */
  1367. if (((load_md_flag & (1<<MD_SYS1)) == 0) && (load_md_flag & (1<<MD_SYS3))) {
  1368. ALWAYS_LOG("md3 depends on md1,but md1 not loaded\n");
  1369. return -LD_ERR_PLAT_MD1_NOT_RDY;
  1370. }
  1371. if ((load_md_flag & ((1<<MD_SYS1)|(1<<MD_SYS3))) == 0) {
  1372. ALWAYS_LOG("both md1 and md3 not enable\n");
  1373. return 0;
  1374. }
  1375. smem_final_size = cal_c_smem_size_and_layout(load_md_flag);
  1376. ALWAYS_LOG("ap md1 share mem MPU need configure\n");
  1377. mpu_tbl[s_g_curr_mpu_num].region = MPU_REGION_ID_MD1_NC_SMEM;
  1378. get_mpu_region_default_access_att(mpu_tbl[s_g_curr_mpu_num].permission, MPU_REGION_ID_MD1_NC_SMEM, 0);
  1379. mpu_tbl[s_g_curr_mpu_num].start = (unsigned int)smem_info.base_addr + smem_info.ap_md1_smem_offset;
  1380. mpu_tbl[s_g_curr_mpu_num].end = (unsigned int)smem_info.base_addr + smem_info.ap_md1_smem_offset
  1381. + smem_final_size; /* ap_md1 share && phy_cap had 2M overlap */
  1382. mpu_tbl[s_g_curr_mpu_num].end = ((mpu_tbl[s_g_curr_mpu_num].end + 0xFFFF)&(~0xFFFF)) - 1;
  1383. s_g_curr_mpu_num++;
  1384. if (get_nc_smem_info(SMEM_USER_SECURITY_SMEM, &ap_offset, &md_offset, &smem_size) < 0)
  1385. return -1;
  1386. mpu_tbl[s_g_curr_mpu_num].region = MPU_REGION_ID_MD1_SECURE_SHARE;
  1387. get_mpu_region_default_access_att(mpu_tbl[s_g_curr_mpu_num].permission, MPU_REGION_ID_MD1_SECURE_SHARE, 0);
  1388. mpu_tbl[s_g_curr_mpu_num].start = (unsigned int)smem_info.base_addr + ap_offset;
  1389. mpu_tbl[s_g_curr_mpu_num].end = (unsigned int)smem_info.base_addr + ap_offset
  1390. + CCCI_SMEM_SIZE_SECURITY;
  1391. mpu_tbl[s_g_curr_mpu_num].end = ((mpu_tbl[s_g_curr_mpu_num].end + 0xFFFF)&(~0xFFFF)) - 1;
  1392. s_g_curr_mpu_num++;
  1393. /* add for ccb data buffer mpu */
  1394. mpu_tbl[s_g_curr_mpu_num].region = MPU_REGION_ID_MD1_C_SMEM;
  1395. get_mpu_region_default_access_att(mpu_tbl[s_g_curr_mpu_num].permission, MPU_REGION_ID_MD1_C_SMEM, 0);
  1396. mpu_tbl[s_g_curr_mpu_num].start = (unsigned int)csmem_info.csmem_buffer_addr;//ccb_info.ccb_data_buffer_addr;
  1397. mpu_tbl[s_g_curr_mpu_num].end = (unsigned int)csmem_info.csmem_buffer_addr + csmem_info.csmem_buffer_size;//ccb_info.ccb_data_buffer_addr + ccb_info.ccb_data_buffer_size;
  1398. mpu_tbl[s_g_curr_mpu_num].end = ((mpu_tbl[s_g_curr_mpu_num].end + 0xFFFF)&(~0xFFFF)) - 1;
  1399. s_g_curr_mpu_num++;
  1400. mpu_tbl[s_g_curr_mpu_num].region = -1; /* mark for end */
  1401. /* Insert mpu tag info */
  1402. if (insert_ccci_tag_inf("md_mpu_inf", (char*)mpu_tbl, sizeof(mpu_cfg_t)*s_g_curr_mpu_num) < 0)
  1403. ALWAYS_LOG("insert md_mpu_inf fail\n");
  1404. if (insert_ccci_tag_inf("md_mpu_num", (char*)&s_g_curr_mpu_num, sizeof(int)) < 0)
  1405. ALWAYS_LOG("insert md_mpu_num fail\n");
  1406. /* Apply all MPU setting */
  1407. ccci_mem_access_cfg(mpu_tbl, 0);
  1408. #ifdef MPU_REGION_CONSYS_EN
  1409. md_special_mpu_set();
  1410. #endif
  1411. /* Apply share memory HW remap setting */
  1412. if (load_md_flag & (1<<MD_SYS1))
  1413. md_smem_rw_remapping(MD_SYS1, (unsigned int)(smem_info.base_addr + smem_info.ap_md1_smem_offset));
  1414. return smem_final_size;
  1415. }
  1416. /*****************************************************************************/
  1417. /* Memory --- limit and align settings */
  1418. /*****************************************************************************/
  1419. /* Share memory cacheable for MD */
  1420. #define SMEM_CACHE_ALIGNMENT 0x2000000L
  1421. #define SMEM_CACHE_LIMIT 0x90000000LL
  1422. /* Share memory non-cacheable for MD */
  1423. #define SMEM_NONCACHE_ALIGNMENT 0x2000000L
  1424. #define SMEM_NONCACHE_LIMIT 0x90000000LL
  1425. /* RO + RW memory non-cacheable for MD */
  1426. #define RO_RW_MEM_ALIGNMENT 0x2000000L
  1427. #ifdef DUMMY_AP_MODE
  1428. #define RO_RW_MEM_LIMIT 0xC0000000LL
  1429. #else
  1430. #define RO_RW_MEM_LIMIT 0xC0000000LL
  1431. #endif
  1432. /* SIB memory */
  1433. #define SIB_SMEM_ALIGNMENT 0x8000000L
  1434. #define SIB_SMEM_LIMIT 0x200000000LL
  1435. /*------------------------------------------------------------------------------------------------*/
  1436. /* platform configure setting info. */
  1437. /*------------------------------------------------------------------------------------------------*/
  1438. long long plat_ccci_get_ld_md_plat_setting(char cfg_name[])
  1439. {
  1440. if (strcmp(cfg_name, "share_memory_size") == 0) {
  1441. #ifdef DUMMY_AP_MODE
  1442. return 0x200000;
  1443. #endif
  1444. /* only for non-cacheable part. */
  1445. return (long long)cal_nc_share_mem_size();
  1446. }
  1447. if (strcmp(cfg_name, "share_mem_limit") == 0)
  1448. return 0x90000000LL;
  1449. if (strcmp(cfg_name, "ro_rw_mem_limit") == 0)
  1450. return 0xC0000000LL;
  1451. if (strcmp(cfg_name, "ro_rw_mem_align") == 0)
  1452. return 0x2000000LL;
  1453. if (strcmp(cfg_name, "share_mem_align") == 0)
  1454. return 0x2000000LL;
  1455. if (strcmp(cfg_name, "ld_version") == 0) {
  1456. #ifdef DUMMY_AP_MODE
  1457. return 0x20001;
  1458. #endif
  1459. return 0x30000;/* xxxx_yyyy, xxxx: main id, yyyy sub id */
  1460. }
  1461. if (strcmp(cfg_name, "rat_plat_ver") == 0)
  1462. return RAT_VER_93;
  1463. return -1LL;
  1464. }
  1465. /* CCCI tag info memory */
  1466. #define TAG_MEM_ALIGNMENT 0x1000L
  1467. #define TAG_MEM_LIMIT 0xC0000000LL
  1468. #define PLAT_DEFAULT_CCB_GEAR 1
  1469. struct mem_attr_setting {
  1470. char *name;
  1471. unsigned long long limit;
  1472. unsigned long align;
  1473. };
  1474. const struct mem_attr_setting c_md_mem_attr_cfg[] = {
  1475. {"ap_md_c_smem", SMEM_CACHE_LIMIT, SMEM_CACHE_ALIGNMENT},
  1476. {"ap_md_nc_smem", SMEM_NONCACHE_LIMIT, SMEM_NONCACHE_ALIGNMENT},
  1477. {"md_mem_usage", RO_RW_MEM_LIMIT, RO_RW_MEM_ALIGNMENT},
  1478. {"ccci_tag_mem", TAG_MEM_LIMIT, TAG_MEM_ALIGNMENT},
  1479. {"md3rom", RO_RW_MEM_LIMIT, RO_RW_MEM_ALIGNMENT},
  1480. {"md1_sib_mem", SIB_SMEM_LIMIT, SIB_SMEM_ALIGNMENT},
  1481. {NULL, 0LL, 0L},
  1482. };
  1483. int get_mem_limit_and_align(char key[], unsigned long long *limit, unsigned long *align)
  1484. {
  1485. int i = 0;
  1486. int mem_attr_num =
  1487. sizeof(c_md_mem_attr_cfg)/sizeof(struct mem_attr_setting);
  1488. while(1) {
  1489. if (i >= mem_attr_num) {
  1490. ALWAYS_LOG("invalid index i=%d\n", i);
  1491. break;
  1492. }
  1493. if (!c_md_mem_attr_cfg[i].name)
  1494. break;
  1495. if (strcmp(key, c_md_mem_attr_cfg[i].name) == 0) {
  1496. if (limit)
  1497. *limit = c_md_mem_attr_cfg[i].limit;
  1498. if (align)
  1499. *align = c_md_mem_attr_cfg[i].align;
  1500. return 0;
  1501. }
  1502. i++;
  1503. }
  1504. return -1;
  1505. }
  1506. #ifdef DUMMY_AP_MODE
  1507. #include <platform/mt_irq.h>
  1508. extern void dummy_ap_boot_up_md(int md_en_flag);
  1509. extern void load_modem_image(void);
  1510. extern int dummy_ap_irq_helper(unsigned int);
  1511. /* Remember add this function to file platform.c(platform code) */
  1512. void dummy_ap_entry(void)
  1513. {
  1514. load_modem_image();
  1515. }
  1516. /* Remember add this function to file interrupts.c(platform code) */
  1517. void dummy_ap_irq_handler(unsigned int irq)
  1518. {
  1519. if (dummy_ap_irq_helper(irq)) {
  1520. mt_irq_ack(irq);
  1521. mt_irq_unmask(irq);
  1522. }
  1523. }
  1524. void boot_to_dummy_ap_mode(int load_md_flag)
  1525. {
  1526. md_smem_rw_remapping(MD_SYS1, smem_info.base_addr);
  1527. /* Before boot dummy AP, clear share memory */
  1528. memset((void*)((unsigned long)smem_info.base_addr), 0, 0x200000);
  1529. dummy_ap_boot_up_md(load_md_flag);
  1530. }
  1531. #endif