soc.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. * Copyright 2022 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <arch.h>
  8. #include <caam.h>
  9. #include <cci.h>
  10. #include <common/debug.h>
  11. #include <dcfg.h>
  12. #ifdef I2C_INIT
  13. #include <i2c.h>
  14. #endif
  15. #include <lib/mmio.h>
  16. #include <lib/xlat_tables/xlat_tables_v2.h>
  17. #include <ls_interconnect.h>
  18. #include <nxp_smmu.h>
  19. #include <nxp_timer.h>
  20. #include <plat_console.h>
  21. #include <plat_gic.h>
  22. #include <plat_tzc400.h>
  23. #include <pmu.h>
  24. #if defined(NXP_SFP_ENABLED)
  25. #include <sfp.h>
  26. #endif
  27. #include <errata.h>
  28. #ifdef CONFIG_OCRAM_ECC_EN
  29. #include <ocram.h>
  30. #endif
  31. #include <plat_common.h>
  32. #include <platform_def.h>
  33. #include <soc.h>
  34. static unsigned char _power_domain_tree_desc[NUMBER_OF_CLUSTERS + 2];
  35. static struct soc_type soc_list[] = {
  36. SOC_ENTRY(LS1044A, LS1044A, 1, 4),
  37. SOC_ENTRY(LS1044AE, LS1044AE, 1, 4),
  38. SOC_ENTRY(LS1048A, LS1048A, 1, 4),
  39. SOC_ENTRY(LS1048AE, LS1048AE, 1, 4),
  40. SOC_ENTRY(LS1084A, LS1084A, 2, 4),
  41. SOC_ENTRY(LS1084AE, LS1084AE, 2, 4),
  42. SOC_ENTRY(LS1088A, LS1088A, 2, 4),
  43. SOC_ENTRY(LS1088AE, LS1088AE, 2, 4),
  44. };
  45. static dcfg_init_info_t dcfg_init_data = {
  46. .g_nxp_dcfg_addr = NXP_DCFG_ADDR,
  47. .nxp_sysclk_freq = NXP_SYSCLK_FREQ,
  48. .nxp_ddrclk_freq = NXP_DDRCLK_FREQ,
  49. .nxp_plat_clk_divider = NXP_PLATFORM_CLK_DIVIDER,
  50. };
  51. /*
  52. * This function dynamically constructs the topology according to
  53. * SoC Flavor and returns it.
  54. */
  55. const unsigned char *plat_get_power_domain_tree_desc(void)
  56. {
  57. unsigned int i;
  58. uint8_t num_clusters, cores_per_cluster;
  59. get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
  60. /*
  61. * The highest level is the system level. The next level is constituted
  62. * by clusters and then cores in clusters.
  63. */
  64. _power_domain_tree_desc[0] = 1;
  65. _power_domain_tree_desc[1] = num_clusters;
  66. for (i = 0; i < _power_domain_tree_desc[1]; i++) {
  67. _power_domain_tree_desc[i + 2] = cores_per_cluster;
  68. }
  69. return _power_domain_tree_desc;
  70. }
  71. CASSERT(NUMBER_OF_CLUSTERS && NUMBER_OF_CLUSTERS <= 256,
  72. assert_invalid_ls1088a_cluster_count);
  73. /*
  74. * This function returns the core count within the cluster corresponding to
  75. * `mpidr`.
  76. */
  77. unsigned int plat_ls_get_cluster_core_count(u_register_t mpidr)
  78. {
  79. return CORES_PER_CLUSTER;
  80. }
  81. /*
  82. * This function returns the total number of cores in the SoC
  83. */
  84. unsigned int get_tot_num_cores(void)
  85. {
  86. uint8_t num_clusters, cores_per_cluster;
  87. get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
  88. return (num_clusters * cores_per_cluster);
  89. }
  90. /*
  91. * This function returns the PMU IDLE Cluster mask.
  92. */
  93. unsigned int get_pmu_idle_cluster_mask(void)
  94. {
  95. uint8_t num_clusters, cores_per_cluster;
  96. get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
  97. return ((1 << num_clusters) - 2);
  98. }
  99. /*
  100. * This function returns the PMU Flush Cluster mask.
  101. */
  102. unsigned int get_pmu_flush_cluster_mask(void)
  103. {
  104. uint8_t num_clusters, cores_per_cluster;
  105. get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
  106. return ((1 << num_clusters) - 2);
  107. }
  108. /*
  109. * This function returns the PMU IDLE Core mask.
  110. */
  111. unsigned int get_pmu_idle_core_mask(void)
  112. {
  113. return ((1 << get_tot_num_cores()) - 2);
  114. }
  115. #ifdef IMAGE_BL2
  116. void soc_bl2_prepare_exit(void)
  117. {
  118. #if defined(NXP_SFP_ENABLED) && defined(DISABLE_FUSE_WRITE)
  119. set_sfp_wr_disable();
  120. #endif
  121. }
  122. void soc_preload_setup(void)
  123. {
  124. }
  125. /*
  126. * This function returns the boot device based on RCW_SRC
  127. */
  128. enum boot_device get_boot_dev(void)
  129. {
  130. enum boot_device src = BOOT_DEVICE_NONE;
  131. uint32_t porsr1;
  132. uint32_t rcw_src, val;
  133. porsr1 = read_reg_porsr1();
  134. rcw_src = (porsr1 & PORSR1_RCW_MASK) >> PORSR1_RCW_SHIFT;
  135. /* RCW SRC NOR */
  136. val = rcw_src & RCW_SRC_TYPE_MASK;
  137. if (val == NOR_16B_VAL) {
  138. src = BOOT_DEVICE_IFC_NOR;
  139. INFO("RCW BOOT SRC is IFC NOR\n");
  140. } else {
  141. val = rcw_src & RCW_SRC_SERIAL_MASK;
  142. switch (val) {
  143. case QSPI_VAL:
  144. src = BOOT_DEVICE_QSPI;
  145. INFO("RCW BOOT SRC is QSPI\n");
  146. break;
  147. case SDHC_VAL:
  148. src = BOOT_DEVICE_EMMC;
  149. INFO("RCW BOOT SRC is SD/EMMC\n");
  150. break;
  151. case EMMC_VAL:
  152. src = BOOT_DEVICE_EMMC;
  153. INFO("RCW BOOT SRC is SD/EMMC\n");
  154. break;
  155. default:
  156. src = BOOT_DEVICE_NONE;
  157. }
  158. }
  159. return src;
  160. }
  161. /*
  162. * This function sets up access permissions on memory regions
  163. */
  164. void soc_mem_access(void)
  165. {
  166. dram_regions_info_t *info_dram_regions = get_dram_regions_info();
  167. int i = 0;
  168. struct tzc400_reg tzc400_reg_list[MAX_NUM_TZC_REGION];
  169. int dram_idx, index = 1;
  170. for (dram_idx = 0; dram_idx < info_dram_regions->num_dram_regions;
  171. dram_idx++) {
  172. if (info_dram_regions->region[i].size == 0) {
  173. ERROR("DDR init failure, or");
  174. ERROR("DRAM regions not populated correctly.\n");
  175. break;
  176. }
  177. index = populate_tzc400_reg_list(tzc400_reg_list,
  178. dram_idx, index,
  179. info_dram_regions->region[dram_idx].addr,
  180. info_dram_regions->region[dram_idx].size,
  181. NXP_SECURE_DRAM_SIZE, NXP_SP_SHRD_DRAM_SIZE);
  182. }
  183. mem_access_setup(NXP_TZC_ADDR, index,
  184. tzc400_reg_list);
  185. }
  186. /*
  187. * This function implements soc specific erratum
  188. * This is called before DDR is initialized or MMU is enabled
  189. */
  190. void soc_early_init(void)
  191. {
  192. enum boot_device dev;
  193. dram_regions_info_t *dram_regions_info = get_dram_regions_info();
  194. #ifdef CONFIG_OCRAM_ECC_EN
  195. ocram_init(NXP_OCRAM_ADDR, NXP_OCRAM_SIZE);
  196. #endif
  197. dcfg_init(&dcfg_init_data);
  198. #if LOG_LEVEL > 0
  199. /* Initialize the console to provide early debug support */
  200. plat_console_init(NXP_CONSOLE_ADDR,
  201. NXP_UART_CLK_DIVIDER, NXP_CONSOLE_BAUDRATE);
  202. #endif
  203. enable_timer_base_to_cluster(NXP_PMU_ADDR);
  204. enable_core_tb(NXP_PMU_ADDR);
  205. /*
  206. * Use the region(NXP_SD_BLOCK_BUF_ADDR + NXP_SD_BLOCK_BUF_SIZE)
  207. * as dma of sd
  208. */
  209. dev = get_boot_dev();
  210. if (dev == BOOT_DEVICE_EMMC) {
  211. mmap_add_region(NXP_SD_BLOCK_BUF_ADDR, NXP_SD_BLOCK_BUF_ADDR,
  212. NXP_SD_BLOCK_BUF_SIZE,
  213. MT_DEVICE | MT_RW | MT_NS);
  214. }
  215. /*
  216. * Unlock write access for SMMU SMMU_CBn_ACTLR in all Non-secure contexts.
  217. */
  218. smmu_cache_unlock(NXP_SMMU_ADDR);
  219. INFO("SMMU Cache Unlocking is Configured.\n");
  220. #if TRUSTED_BOARD_BOOT
  221. uint32_t mode;
  222. sfp_init(NXP_SFP_ADDR);
  223. /*
  224. * For secure boot disable SMMU.
  225. * Later when platform security policy comes in picture,
  226. * this might get modified based on the policy
  227. */
  228. if (check_boot_mode_secure(&mode) == true) {
  229. bypass_smmu(NXP_SMMU_ADDR);
  230. }
  231. /*
  232. * For Mbedtls currently crypto is not supported via CAAM
  233. * enable it when that support is there. In tbbr.mk
  234. * the CAAM_INTEG is set as 0.
  235. */
  236. #ifndef MBEDTLS_X509
  237. /* Initialize the crypto accelerator if enabled */
  238. if (is_sec_enabled() == false) {
  239. INFO("SEC is disabled.\n");
  240. } else {
  241. sec_init(NXP_CAAM_ADDR);
  242. }
  243. #endif
  244. #endif
  245. soc_errata();
  246. delay_timer_init(NXP_TIMER_ADDR);
  247. i2c_init(NXP_I2C_ADDR);
  248. dram_regions_info->total_dram_size = init_ddr();
  249. }
  250. #else /* !IMAGE_BL2 */
  251. void soc_early_platform_setup2(void)
  252. {
  253. dcfg_init(&dcfg_init_data);
  254. /*
  255. * Initialize system level generic timer for Socs
  256. */
  257. delay_timer_init(NXP_TIMER_ADDR);
  258. #if LOG_LEVEL > 0
  259. /* Initialize the console to provide early debug support */
  260. plat_console_init(NXP_CONSOLE_ADDR,
  261. NXP_UART_CLK_DIVIDER, NXP_CONSOLE_BAUDRATE);
  262. #endif
  263. }
  264. void soc_platform_setup(void)
  265. {
  266. /* Initialize the GIC driver, cpu and distributor interfaces */
  267. static uintptr_t target_mask_array[PLATFORM_CORE_COUNT];
  268. static interrupt_prop_t ls_interrupt_props[] = {
  269. PLAT_LS_G1S_IRQ_PROPS(INTR_GROUP1S),
  270. PLAT_LS_G0_IRQ_PROPS(INTR_GROUP0)
  271. };
  272. plat_ls_gic_driver_init(NXP_GICD_ADDR, NXP_GICR_ADDR,
  273. PLATFORM_CORE_COUNT,
  274. ls_interrupt_props,
  275. ARRAY_SIZE(ls_interrupt_props),
  276. target_mask_array,
  277. plat_core_pos);
  278. plat_ls_gic_init();
  279. enable_init_timer();
  280. }
  281. /*
  282. * This function initializes the soc from the BL31 module
  283. */
  284. void soc_init(void)
  285. {
  286. uint8_t num_clusters, cores_per_cluster;
  287. /* low-level init of the soc */
  288. soc_init_lowlevel();
  289. _init_global_data();
  290. soc_init_percpu();
  291. _initialize_psci();
  292. /*
  293. * Initialize Interconnect for this cluster during cold boot.
  294. * No need for locks as no other CPU is active.
  295. */
  296. cci_init(NXP_CCI_ADDR, cci_map, ARRAY_SIZE(cci_map));
  297. /*
  298. * Enable Interconnect coherency for the primary CPU's cluster.
  299. */
  300. get_cluster_info(soc_list, ARRAY_SIZE(soc_list), &num_clusters, &cores_per_cluster);
  301. plat_ls_interconnect_enter_coherency(num_clusters);
  302. /* set platform security policies */
  303. _set_platform_security();
  304. /* Initialize the crypto accelerator if enabled */
  305. if (is_sec_enabled() == false) {
  306. INFO("SEC is disabled.\n");
  307. } else {
  308. sec_init(NXP_CAAM_ADDR);
  309. }
  310. }
  311. void soc_runtime_setup(void)
  312. {
  313. }
  314. #endif /* IMAGE_BL2 */
  315. /*
  316. * Function to return the SoC SYS CLK
  317. */
  318. unsigned int get_sys_clk(void)
  319. {
  320. return NXP_SYSCLK_FREQ;
  321. }
  322. /*
  323. * Function returns the base counter frequency
  324. * after reading the first entry at CNTFID0 (0x20 offset).
  325. *
  326. * Function is used by:
  327. * 1. ARM common code for PSCI management.
  328. * 2. ARM Generic Timer init.
  329. */
  330. unsigned int plat_get_syscnt_freq2(void)
  331. {
  332. unsigned int counter_base_frequency;
  333. /*
  334. * Below register specifies the base frequency of the system counter.
  335. * As per NXP Board Manuals:
  336. * The system counter always works with SYS_REF_CLK/4 frequency clock.
  337. */
  338. counter_base_frequency = mmio_read_32(NXP_TIMER_ADDR + CNTFID_OFF);
  339. return counter_base_frequency;
  340. }