1 /* 2 * Copyright (c) 2021-2023, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch_helpers.h> 8 #include <common/debug.h> 9 #include <common/desc_image_load.h> 10 #include <drivers/arm/css/sds.h> 11 #include <libfdt.h> 12 13 #include "morello_def.h" 14 #include <plat/arm/common/plat_arm.h> 15 #include <plat/common/platform.h> 16 17 /* In client mode, a part of the DDR memory is reserved for Tag bits. 18 * Calculate the usable memory size after subtracting the Tag memory. 19 */ 20 static inline uint64_t get_mem_client_mode(uint64_t size) 21 { 22 return (size - (size / 128ULL)); 23 } 24 25 /******************************************************************************* 26 * This function inserts Platform information via device tree nodes as, 27 * platform-info { 28 * local-ddr-size = <0x0 0x0>; 29 *#ifdef TARGET_PLATFORM_SOC 30 * remote-ddr-size = <0x0 0x0>; 31 * remote-chip-count = <0x0>; 32 * multichip-mode = <0x0>; 33 * scc-config = <0x0>; 34 *#endif 35 * }; 36 ******************************************************************************/ 37 static int plat_morello_append_config_node(struct morello_plat_info *plat_info) 38 { 39 bl_mem_params_node_t *mem_params; 40 void *fdt; 41 int nodeoffset, err; 42 uint64_t usable_mem_size; 43 44 usable_mem_size = plat_info->local_ddr_size; 45 46 mem_params = get_bl_mem_params_node(NT_FW_CONFIG_ID); 47 if (mem_params == NULL) { 48 ERROR("NT_FW CONFIG base address is NULL\n"); 49 return -1; 50 } 51 52 fdt = (void *)(mem_params->image_info.image_base); 53 54 /* Check the validity of the fdt */ 55 if (fdt_check_header(fdt) != 0) { 56 ERROR("Invalid NT_FW_CONFIG DTB passed\n"); 57 return -1; 58 } 59 60 nodeoffset = fdt_subnode_offset(fdt, 0, "platform-info"); 61 if (nodeoffset < 0) { 62 ERROR("NT_FW_CONFIG: Failed to get platform-info node offset\n"); 63 return -1; 64 } 65 66 #ifdef TARGET_PLATFORM_SOC 67 err = fdt_setprop_u64(fdt, nodeoffset, "remote-ddr-size", 68 plat_info->remote_ddr_size); 69 if (err < 0) { 70 ERROR("NT_FW_CONFIG: Failed to set remote-ddr-size\n"); 71 return -1; 72 } 73 74 err = fdt_setprop_u32(fdt, nodeoffset, "remote-chip-count", 75 plat_info->remote_chip_count); 76 if (err < 0) { 77 ERROR("NT_FW_CONFIG: Failed to set remote-chip-count\n"); 78 return -1; 79 } 80 81 err = fdt_setprop_u32(fdt, nodeoffset, "multichip-mode", 82 plat_info->multichip_mode); 83 if (err < 0) { 84 ERROR("NT_FW_CONFIG: Failed to set multichip-mode\n"); 85 return -1; 86 } 87 88 err = fdt_setprop_u32(fdt, nodeoffset, "scc-config", 89 plat_info->scc_config); 90 if (err < 0) { 91 ERROR("NT_FW_CONFIG: Failed to set scc-config\n"); 92 return -1; 93 } 94 95 if (plat_info->scc_config & MORELLO_SCC_CLIENT_MODE_MASK) { 96 usable_mem_size = get_mem_client_mode(plat_info->local_ddr_size); 97 } 98 #endif 99 err = fdt_setprop_u64(fdt, nodeoffset, "local-ddr-size", 100 usable_mem_size); 101 if (err < 0) { 102 ERROR("NT_FW_CONFIG: Failed to set local-ddr-size\n"); 103 return -1; 104 } 105 106 flush_dcache_range((uintptr_t)fdt, mem_params->image_info.image_size); 107 108 return 0; 109 } 110 111 /******************************************************************************* 112 * This function returns the list of executable images. 113 ******************************************************************************/ 114 bl_params_t *plat_get_next_bl_params(void) 115 { 116 int ret; 117 struct morello_plat_info plat_info; 118 119 ret = sds_init(); 120 if (ret != SDS_OK) { 121 ERROR("SDS initialization failed. ret:%d\n", ret); 122 panic(); 123 } 124 125 ret = sds_struct_read(MORELLO_SDS_PLATFORM_INFO_STRUCT_ID, 126 MORELLO_SDS_PLATFORM_INFO_OFFSET, 127 &plat_info, 128 MORELLO_SDS_PLATFORM_INFO_SIZE, 129 SDS_ACCESS_MODE_NON_CACHED); 130 if (ret != SDS_OK) { 131 ERROR("Error getting platform info from SDS. ret:%d\n", ret); 132 panic(); 133 } 134 135 /* Validate plat_info SDS */ 136 #ifdef TARGET_PLATFORM_FVP 137 if (plat_info.local_ddr_size == 0U) { 138 #else 139 if ((plat_info.local_ddr_size == 0U) 140 || (plat_info.local_ddr_size > MORELLO_MAX_DDR_CAPACITY) 141 || (plat_info.remote_ddr_size > MORELLO_MAX_DDR_CAPACITY) 142 || (plat_info.remote_chip_count > MORELLO_MAX_REMOTE_CHIP_COUNT) 143 ){ 144 #endif 145 ERROR("platform info SDS is corrupted\n"); 146 panic(); 147 } 148 149 ret = plat_morello_append_config_node(&plat_info); 150 if (ret != 0) { 151 panic(); 152 } 153 154 return arm_get_next_bl_params(); 155 } 156