aee_platform_debug.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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 <malloc.h>
  32. #include <stdlib.h>
  33. #include <arch/arm/mmu.h>
  34. #include <dev/aee_platform_debug.h>
  35. #include <spm_common.h>
  36. #include <platform/dram_debug.h>
  37. #include <platform/plat_dbg_info.h>
  38. #include <platform/mt_reg_base.h>
  39. #include <platform/mt_typedefs.h>
  40. #include <platform/mtk_wdt.h>
  41. #include <platform/partition.h>
  42. #include <platform/platform_debug.h>
  43. #include "log_store_lk.h"
  44. #include <platform/msdc_utils.h>
  45. #include <plat_debug_interface.h>
  46. #include <ram_console.h>
  47. #include <reg.h>
  48. #include <fdt.h>
  49. #include <libfdt.h>
  50. #include <debug.h>
  51. #include <platform/mt_sspm.h>
  52. #include <mtk_mcdi.h>
  53. #ifdef MTK_AB_OTA_UPDATER
  54. #include <mt_boot.h>
  55. #endif
  56. int plt_get_cluster_id(unsigned int cpu_id, unsigned int *core_id_in_cluster)
  57. {
  58. if (core_id_in_cluster == NULL)
  59. return -1;
  60. *core_id_in_cluster = (cpu_id % 4);
  61. return (cpu_id / 4);
  62. }
  63. unsigned long plt_get_cpu_power_status_at_wdt(void)
  64. {
  65. unsigned long bitmask = 0, ret;
  66. ret = readl(SLEEP_BASE + cfg_pc_latch.spm_pwr_sts);
  67. /* CPU0 ~ CPU3 */
  68. bitmask |= (ret & (0xf << 9)) >> 9;
  69. /* CPU4 ~ CPU7 */
  70. bitmask |= (ret & (0xf << 16)) >> 12;
  71. return bitmask;
  72. }
  73. unsigned int plt_get_dfd_dump_type(void)
  74. {
  75. /* for mt6763 with DFD 3.0 -> always dump to DRAM*/
  76. if (cfg_dfd.version >= DFD_V3_0)
  77. return DFD_DUMP_TO_DRAM;
  78. else
  79. return DFD_DUMP_NOT_SUPPORT;
  80. }
  81. static unsigned int save_cpu_bus_data(u64 offset, int *len, CALLBACK dev_write)
  82. {
  83. char *buf = NULL;
  84. int ret;
  85. unsigned int datasize = 0;
  86. /* Save latch buffer */
  87. ret = latch_get((void **)&buf, len);
  88. if (buf != NULL) {
  89. if (*len > 0)
  90. datasize = dev_write(buf, *len);
  91. latch_put((void **)&buf);
  92. }
  93. /* Save systracker buffer */
  94. ret = systracker_get((void **)&buf, len, 8);
  95. if (buf != NULL) {
  96. if (*len > 0)
  97. datasize += dev_write(buf, *len);
  98. systracker_put((void **)&buf);
  99. }
  100. return datasize;
  101. }
  102. static unsigned int save_dfd_data(u64 offset, int *len, CALLBACK dev_write)
  103. {
  104. char *buf = NULL;
  105. unsigned int datasize = 0;
  106. /* Save dfd buffer */
  107. if (dfd_get((void **)&buf, len)) {
  108. datasize = dev_write(buf, *len);
  109. dfd_put((void **)&buf);
  110. }
  111. return datasize;
  112. }
  113. void platform_lastpc_postinit(void)
  114. {
  115. mt_secure_call(MTK_SIP_LK_LASTPC_AARCH32, 0, 0, 0);
  116. }
  117. /* SPM Debug Features */
  118. static unsigned int spm_wdt_latch_regs[] = {
  119. SLEEP_BASE + 0x800, /* PCM_WDT_LATCH_0 */
  120. SLEEP_BASE + 0x804, /* PCM_WDT_LATCH_1 */
  121. SLEEP_BASE + 0x808, /* PCM_WDT_LATCH_2 */
  122. SLEEP_BASE + 0x80c, /* PCM_WDT_LATCH_3 */
  123. SLEEP_BASE + 0x810, /* PCM_WDT_LATCH_4 */
  124. SLEEP_BASE + 0x814, /* PCM_WDT_LATCH_5 */
  125. SLEEP_BASE + 0x818, /* PCM_WDT_LATCH_6 */
  126. SLEEP_BASE + 0x81c, /* PCM_WDT_LATCH_7 */
  127. SLEEP_BASE + 0x820, /* PCM_WDT_LATCH_8 */
  128. SLEEP_BASE + 0x824, /* PCM_WDT_LATCH_9 */
  129. SLEEP_BASE + 0x838, /* PCM_WDT_LATCH_10 */
  130. SLEEP_BASE + 0x83c, /* PCM_WDT_LATCH_11 */
  131. SLEEP_BASE + 0x828, /* WDT_LATCH_SPARE0 */
  132. SLEEP_BASE + 0x82C, /* WDT_LATCH_SPARE1 */
  133. SLEEP_BASE + 0x830, /* WDT_LATCH_SPARE2 */
  134. SLEEP_BASE + 0x834, /* WDT_LATCH_SPARE3 */
  135. SLEEP_BASE + 0x914, /* SPM_ACK_CHK_LATCH */
  136. SLEEP_BASE + 0x934, /* SPM_ACK_CHK_LATCH2 */
  137. SLEEP_BASE + 0x954, /* SPM_ACK_CHK_LATCH3 */
  138. SLEEP_BASE + 0x974, /* SPM_ACK_CHK_LATCH4 */
  139. SLEEP_BASE + 0x780, /* WDT_LATCH_SPARE0_FIX */
  140. SLEEP_BASE + 0x784, /* WDT_LATCH_SPARE1_FIX */
  141. SLEEP_BASE + 0x788, /* WDT_LATCH_SPARE2_FIX */
  142. SLEEP_BASE + 0x78C, /* WDT_LATCH_SPARE3_FIX */
  143. SLEEP_BASE + 0x840, /* DCHA_GATING_LATCH_0 */
  144. SLEEP_BASE + 0x844, /* DCHA_GATING_LATCH_1 */
  145. SLEEP_BASE + 0x848, /* DCHA_GATING_LATCH_2 */
  146. SLEEP_BASE + 0x84c, /* DCHA_GATING_LATCH_3 */
  147. SLEEP_BASE + 0x850, /* DCHA_GATING_LATCH_4 */
  148. SLEEP_BASE + 0x854, /* DCHA_GATING_LATCH_5 */
  149. SLEEP_BASE + 0x858, /* DCHA_GATING_LATCH_6 */
  150. SLEEP_BASE + 0x85c, /* DCHA_GATING_LATCH_7 */
  151. SLEEP_BASE + 0x860, /* DCHB_GATING_LATCH_0 */
  152. SLEEP_BASE + 0x864, /* DCHB_GATING_LATCH_1 */
  153. SLEEP_BASE + 0x868, /* DCHB_GATING_LATCH_2 */
  154. SLEEP_BASE + 0x86c, /* DCHB_GATING_LATCH_3 */
  155. SLEEP_BASE + 0x870, /* DCHB_GATING_LATCH_4 */
  156. SLEEP_BASE + 0x874, /* DCHB_GATING_LATCH_5 */
  157. SLEEP_BASE + 0x878, /* DCHB_GATING_LATCH_6 */
  158. SLEEP_BASE + 0x87c, /* DCHB_GATING_LATCH_7 */
  159. SLEEP_BASE + 0x880, /* DCHA_LATCH_RSV0 */
  160. SLEEP_BASE + 0x884, /* DCHB_LATCH_RSV0 */
  161. };
  162. #define DVFSRC_DUMP (DVFSRC_BASE + 0x140)
  163. #define DVFSRC_SIZE 0x40
  164. #define SPM_DATA_BUF_LENGTH (4096)
  165. static int spm_dump_data(char *buf, int *wp)
  166. {
  167. unsigned int i;
  168. unsigned val;
  169. #ifdef SPM_FW_USE_PARTITION
  170. char part_name[16] = "spmfw";
  171. #ifdef MTK_AB_OTA_UPDATER
  172. get_AB_OTA_name((void *)&part_name, sizeof(part_name));
  173. #endif /* MTK_AB_OTA_UPDATER */
  174. #endif /* SPM_FW_USE_PARTITION */
  175. if (buf == NULL || wp == NULL)
  176. return -1;
  177. /*
  178. * Example output:
  179. * SPM Suspend debug regs(index 1) = 0x8320535
  180. * SPM Suspend debug regs(index 2) = 0xfe114200
  181. * SPM Suspend debug regs(index 3) = 0x3920fffe
  182. * SPM Suspend debug regs(index 4) = 0x3ac06f4f
  183. */
  184. for (i = 0; i < (sizeof(spm_wdt_latch_regs)/sizeof(unsigned int)); i++) {
  185. val = readl(spm_wdt_latch_regs[i]);
  186. *wp += sprintf(buf + *wp,
  187. "SPM debug regs(0x%x) = 0x%x\n",
  188. spm_wdt_latch_regs[i], val);
  189. }
  190. #ifdef SPM_FW_USE_PARTITION
  191. get_spmfw_version(part_name, "spmfw", buf, wp);
  192. #endif /* SPM_FW_USE_PARTITION */
  193. for (i = 0; i < DVFSRC_SIZE; i+=4) {
  194. val = readl(DVFSRC_DUMP+i);
  195. *wp += sprintf(buf + *wp,
  196. "DVFSRC debug regs(0x%x) = 0x%08x\n", DVFSRC_DUMP+i, val);
  197. }
  198. return 1;
  199. }
  200. int spm_data_get(void **data, int *len)
  201. {
  202. int ret;
  203. *len = 0;
  204. *data = malloc(SPM_DATA_BUF_LENGTH);
  205. if (*data == NULL)
  206. return 0;
  207. ret = spm_dump_data(*data, len);
  208. if (ret < 0 || *len > SPM_DATA_BUF_LENGTH) {
  209. *len = (*len > SPM_DATA_BUF_LENGTH) ? SPM_DATA_BUF_LENGTH : *len;
  210. return ret;
  211. }
  212. return 1;
  213. }
  214. void spm_data_put(void **data)
  215. {
  216. free(*data);
  217. }
  218. static unsigned int save_spm_data(u64 offset, int *len, CALLBACK dev_write)
  219. {
  220. char *buf = NULL;
  221. unsigned int datasize = 0;
  222. /* Save SPM buffer */
  223. spm_data_get((void **)&buf, len);
  224. if (buf != NULL) {
  225. if (*len > 0)
  226. datasize = dev_write(buf, *len);
  227. spm_data_put((void **)&buf);
  228. }
  229. return datasize;
  230. }
  231. /*
  232. * FOR DRAMC data and DRAM Calibration Log
  233. * This area is applied for DRAM related debug.
  234. */
  235. /* DRAMC data */
  236. static int plat_dram_debug_get(void **data, int *len)
  237. {
  238. *data = (void *)DRAM_DEBUG_SRAM_ADDRESS;
  239. *len = DRAM_DEBUG_SRAM_LENGTH;
  240. return 1;
  241. }
  242. bool plat_boot_in_ddr_rsv(void)
  243. {
  244. struct LAST_DRAMC_INFO_T *last_dramc_info;
  245. last_dramc_info = (struct LAST_DRAMC_INFO_T *) get_dbg_info_base(0xD8A3);
  246. if ((last_dramc_info->fatal_err_flag & (1 << DRAM_DEBUG_FLAG_DDR_RSV_BIT)) == 0)
  247. return false;
  248. else
  249. return true;
  250. }
  251. static int plat_dram_klog_get(void **data, int *len)
  252. {
  253. *data = (void *)DRAM_KLOG_SRAM_ADDRESS;
  254. *len = DRAM_KLOG_SRAM_LENGTH;
  255. return 1;
  256. }
  257. static bool plat_dram_has_klog(void)
  258. {
  259. /* not to overwrite klog in abnormal boot or in DDR reserve mode */
  260. if (ram_console_is_abnormal_boot() || plat_boot_in_ddr_rsv())
  261. return false;
  262. if (*(volatile unsigned int*)DRAM_KLOG_VALID_ADDRESS)
  263. return true;
  264. return false;
  265. }
  266. static unsigned int save_dram_data(u64 offset, int *len, CALLBACK dev_write)
  267. {
  268. char *buf = NULL;
  269. unsigned int datasize = 0, allsize = 0;
  270. if (plat_dram_debug_get((void **)&buf, len)) {
  271. datasize = dev_write(buf, *len);
  272. allsize = datasize;
  273. }
  274. if (plat_dram_klog_get((void **)&buf, len)) {
  275. buf = malloc(*len);
  276. if (buf) {
  277. mrdump_read_log(buf, *len, MRDUMP_EXPDB_DRAM_KLOG_OFFSET);
  278. datasize = dev_write(buf, *len);
  279. allsize += datasize;
  280. free(buf);
  281. }
  282. }
  283. return allsize;
  284. }
  285. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  286. #define SSPM_RETRY 10
  287. static unsigned int save_sspm_coredump(u64 offset, int *len, CALLBACK dev_write)
  288. {
  289. unsigned int buf = 0;
  290. unsigned int datasize = 0;
  291. int retry = SSPM_RETRY;
  292. if (!(*(unsigned int *)SSPM_BACKUP)) {
  293. return 0;
  294. }
  295. do {
  296. buf = *(unsigned int *)(SSPM_DM_ADDR);
  297. *len = *(int *)SSPM_DM_SZ;
  298. if ( (buf != 0) && (*len > 0) ) {
  299. datasize = dev_write( (unsigned int *)buf, *len);
  300. break;
  301. } else {
  302. udelay(100);
  303. }
  304. } while ( --retry);
  305. buf = *(unsigned int *)(SSPM_RM_ADDR);
  306. *len = *(int *)SSPM_RM_SZ;
  307. if ( (buf != 0) && (*len > 0) ) {
  308. datasize += dev_write( (unsigned int *)buf, *len);
  309. }
  310. return datasize;
  311. }
  312. static unsigned int save_sspm_data(u64 offset, int *len, CALLBACK dev_write)
  313. {
  314. #define SSPM_BUF_LEN 256
  315. char *buf = NULL;
  316. unsigned int datasize = 0;
  317. buf = malloc(SSPM_BUF_LEN);
  318. if (!buf) {
  319. return 0;
  320. }
  321. memset(buf, 0, SSPM_BUF_LEN);
  322. *len = snprintf(buf, SSPM_BUF_LEN,
  323. "AHB_STATUS: 0x%x\n"
  324. "AHB_M0_ADDR: 0x%x\n"
  325. "AHB_M1_ADDR: 0x%x\n"
  326. "PC: 0x%x\n",
  327. DRV_Reg32(SSPM_AHB_STATUS), DRV_Reg32(SSPM_AHB_M0_ADDR),
  328. DRV_Reg32(SSPM_AHB_M1_ADDR), DRV_Reg32(SSPM_PC));
  329. if (*len > 0) {
  330. datasize = dev_write(buf, (*len > SSPM_BUF_LEN ? SSPM_BUF_LEN : *len));
  331. }
  332. free(buf);
  333. return datasize;
  334. }
  335. static unsigned int save_sspm_xfile(u64 offset, int *len, CALLBACK dev_write)
  336. {
  337. unsigned int buf = 0;
  338. unsigned int datasize = 0;
  339. unsigned int sspm_info;
  340. int ret;
  341. /* Get the information stored in SSPM_INFO by preloader
  342. struct sspm_info_t {
  343. unsigned int sspm_dm_ofs;
  344. unsigned int sspm_dm_sz;
  345. unsigned int rd_ofs;
  346. unsigned int rd_sz;
  347. unsigned int xfile_addr;
  348. unsigned int xfile_sz;
  349. };
  350. */
  351. sspm_info = *(unsigned int *)SSPM_INFO;
  352. #ifdef MTK_3LEVEL_PAGETABLE
  353. ret = arch_mmu_map(ROUNDDOWN((uint64_t)sspm_info, SECTION_SIZE), ROUNDDOWN((uint32_t)sspm_info, SECTION_SIZE),
  354. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA, SECTION_SIZE);
  355. if (ret) {
  356. dprintf(CRITICAL, "kedump: mmu map to 0x%llx fail(%d)\n", ROUNDDOWN((uint64_t)sspm_info, SECTION_SIZE), ret);
  357. return 0;
  358. }
  359. #endif
  360. buf = *((unsigned int *)sspm_info + 4);
  361. *len = *((int *)sspm_info + 5);
  362. dprintf(CRITICAL, "buf 0x%x, len:0x%x\n", buf, *len);
  363. if ( (buf != 0) && (*len > 0) ) {
  364. datasize = dev_write( (unsigned int *)buf, *len);
  365. }
  366. return datasize;
  367. }
  368. static unsigned int save_sspm_last_log(u64 offset, int *len, CALLBACK dev_write)
  369. {
  370. unsigned int buf = 0;
  371. unsigned int datasize = 0;
  372. buf = *(unsigned int *)(SSPM_LASTK_ADDR);
  373. *len = *(int *)SSPM_LASTK_SZ;
  374. if ( (buf != 0) && (*len > 0) ) {
  375. datasize = dev_write( (unsigned int *)buf, *len);
  376. }
  377. return datasize;
  378. }
  379. #endif
  380. static int plat_write_dram_klog(void)
  381. {
  382. char *sram_base = NULL;
  383. int len = 0;
  384. if (plat_dram_klog_get((void **)&sram_base, (int *)&len)) {
  385. if (plat_dram_has_klog()) {
  386. mrdump_write_log(MRDUMP_EXPDB_DRAM_KLOG_OFFSET, sram_base, len);
  387. }
  388. }
  389. return 0;
  390. }
  391. /* SRAM for Hybrid CPU DVFS */
  392. #define HVFS_SRAM_ADDRESS 0x0011bc00
  393. #define HVFS_SRAM_LENGTH 0x1400 /* 5K bytes */
  394. static int plat_hvfs_data_get(void **data, int *len)
  395. {
  396. *data = (void *)HVFS_SRAM_ADDRESS;
  397. *len = HVFS_SRAM_LENGTH;
  398. return 1;
  399. }
  400. static unsigned int save_hvfs_data(u64 offset, int *len, CALLBACK dev_write)
  401. {
  402. char *buf = NULL;
  403. unsigned int datasize = 0;
  404. if (plat_hvfs_data_get((void **)&buf, len)) {
  405. datasize = dev_write(buf, *len);
  406. }
  407. return datasize;
  408. }
  409. static int plat_mcdi_data_get(void **data, int *len)
  410. {
  411. mcdi_setup_file_info_for_kedump();
  412. *data = (void *)MCDI_SRAM_ADDRESS;
  413. *len = MCDI_SRAM_LENGTH;
  414. return 1;
  415. }
  416. static unsigned int save_mcdi_data(u64 offset, int *len, CALLBACK dev_write)
  417. {
  418. char *buf = NULL;
  419. unsigned int datasize = 0;
  420. if (plat_mcdi_data_get((void **)&buf, len)) {
  421. datasize = dev_write(buf, *len);
  422. }
  423. return datasize;
  424. }
  425. /* platform initial function */
  426. int platform_debug_init(void)
  427. {
  428. /* function pointer assignment */
  429. plat_spm_data_get = save_spm_data;
  430. plat_dram_get = save_dram_data;
  431. plat_hvfs_get = save_hvfs_data;
  432. plat_cpu_bus_get = save_cpu_bus_data;
  433. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  434. plat_sspm_coredump_get = save_sspm_coredump;
  435. plat_sspm_data_get = save_sspm_data;
  436. plat_sspm_xfile_get = save_sspm_xfile;
  437. plat_sspm_log_get = save_sspm_last_log;
  438. #endif
  439. plat_mcdi_get = save_mcdi_data;
  440. /* check dfd_valid_before_reboot and efuse for DFD 3.0 */
  441. if ((readl(cfg_dfd.plat_sram_flag1) & 0x2) && (get_efuse_dfd_disabled() == 0x0)) {
  442. plat_dfd20_get = save_dfd_data;
  443. }
  444. /* routine tasks */
  445. plat_write_dram_klog();
  446. return 1;
  447. }
  448. extern int get_ccci_md_view_smem_addr(unsigned long long *ap_addr, unsigned int *md_addr);
  449. int dfd_set_base_addr(void *fdt)
  450. {
  451. int ret = 0;
  452. int offset;
  453. u64 addr;
  454. unsigned int md_addr;
  455. unsigned long long ap_addr;
  456. if (!fdt)
  457. return -1;
  458. ret = get_ccci_md_view_smem_addr(&ap_addr, &md_addr);
  459. if (ret < 0)
  460. return ret;
  461. offset = fdt_path_offset(fdt, "/chosen");
  462. if (offset < 0)
  463. return offset;
  464. /* pass base address to kernel */
  465. addr = cpu_to_fdt64(md_addr);
  466. ret = fdt_setprop(fdt, offset, "dfd,base_addr", &addr, sizeof(addr));
  467. if (ret < 0)
  468. return ret;
  469. /*
  470. * write base address[31:1] from AP view to plat_sram_flag2[31:1]
  471. * write base address[32:32] from AP view to plat_sram_flag2[0:0]
  472. */
  473. writel((ap_addr & ~(0x1)) | ((ap_addr >> 32) & 0x1),
  474. cfg_dfd.plat_sram_flag2);
  475. return ret;
  476. }