Deepak Pandey | 9cbacf6 | 2018-08-08 10:32:51 +0530 | [diff] [blame] | 1 | /* |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved. |
Deepak Pandey | 9cbacf6 | 2018-08-08 10:32:51 +0530 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <platform_def.h> |
| 8 | |
Antonio Nino Diaz | 1b0c6f1 | 2019-01-23 21:08:43 +0000 | [diff] [blame] | 9 | #include <drivers/arm/css/css_mhu_doorbell.h> |
Antonio Nino Diaz | c30db5b | 2019-01-23 20:37:32 +0000 | [diff] [blame] | 10 | #include <drivers/arm/css/scmi.h> |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 11 | #include <drivers/arm/css/sds.h> |
| 12 | #include <common/debug.h> |
| 13 | #include <lib/mmio.h> |
| 14 | #include <lib/utils.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 15 | #include <plat/arm/common/plat_arm.h> |
| 16 | |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 17 | #include "n1sdp_def.h" |
| 18 | |
| 19 | /* |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 20 | * Platform information structure stored in SDS. |
| 21 | * This structure holds information about platform's DDR |
| 22 | * size which will be used to zero out the memory before |
| 23 | * enabling the ECC capability as well as information |
| 24 | * about multichip setup |
| 25 | * - multichip mode |
| 26 | * - slave_count |
| 27 | * - Local DDR size in GB, DDR memory in master board |
| 28 | * - Remote DDR size in GB, DDR memory in slave board |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 29 | */ |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 30 | struct n1sdp_plat_info { |
| 31 | bool multichip_mode; |
| 32 | uint8_t slave_count; |
| 33 | uint8_t local_ddr_size; |
| 34 | uint8_t remote_ddr_size; |
| 35 | } __packed; |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * BL33 image information structure stored in SDS. |
| 39 | * This structure holds the source & destination addresses and |
| 40 | * the size of the BL33 image which will be loaded by BL31. |
| 41 | */ |
| 42 | struct n1sdp_bl33_info { |
| 43 | uint32_t bl33_src_addr; |
| 44 | uint32_t bl33_dst_addr; |
| 45 | uint32_t bl33_size; |
| 46 | }; |
| 47 | |
Deepak Pandey | 9cbacf6 | 2018-08-08 10:32:51 +0530 | [diff] [blame] | 48 | static scmi_channel_plat_info_t n1sdp_scmi_plat_info = { |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 49 | .scmi_mbx_mem = N1SDP_SCMI_PAYLOAD_BASE, |
| 50 | .db_reg_addr = PLAT_CSS_MHU_BASE + CSS_SCMI_MHU_DB_REG_OFF, |
| 51 | .db_preserve_mask = 0xfffffffe, |
| 52 | .db_modify_mask = 0x1, |
| 53 | .ring_doorbell = &mhu_ring_doorbell |
Deepak Pandey | 9cbacf6 | 2018-08-08 10:32:51 +0530 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | scmi_channel_plat_info_t *plat_css_get_scmi_info() |
| 57 | { |
| 58 | return &n1sdp_scmi_plat_info; |
| 59 | } |
Chandni Cherukuri | e4bf6a0 | 2018-11-14 13:43:59 +0530 | [diff] [blame] | 60 | |
| 61 | const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops) |
| 62 | { |
| 63 | return css_scmi_override_pm_ops(ops); |
| 64 | } |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 65 | |
| 66 | /* |
| 67 | * N1SDP platform supports RDIMMs with ECC capability. To use the ECC |
| 68 | * capability, the entire DDR memory space has to be zeroed out before |
| 69 | * enabling the ECC bits in DMC620. Zeroing out several gigabytes of |
| 70 | * memory from SCP is quite time consuming so the following function |
| 71 | * is added to zero out the DDR memory from application processor which is |
| 72 | * much faster compared to SCP. BL33 binary cannot be copied to DDR memory |
| 73 | * before enabling ECC so copy_bl33 function is added to copy BL33 binary |
| 74 | * from IOFPGA-DDR3 memory to main DDR4 memory. |
| 75 | */ |
| 76 | |
Manish Pandey | b68e286 | 2019-09-11 17:07:40 +0100 | [diff] [blame] | 77 | void dmc_ecc_setup(uint8_t ddr_size_gb) |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 78 | { |
| 79 | uint64_t dram2_size; |
| 80 | |
| 81 | dram2_size = (ddr_size_gb * 1024UL * 1024UL * 1024UL) - |
| 82 | ARM_DRAM1_SIZE; |
| 83 | |
| 84 | INFO("Zeroing DDR memories\n"); |
| 85 | zero_normalmem((void *)ARM_DRAM1_BASE, ARM_DRAM1_SIZE); |
| 86 | flush_dcache_range(ARM_DRAM1_BASE, ARM_DRAM1_SIZE); |
| 87 | zero_normalmem((void *)ARM_DRAM2_BASE, dram2_size); |
| 88 | flush_dcache_range(ARM_DRAM2_BASE, dram2_size); |
| 89 | |
| 90 | INFO("Enabling ECC on DMCs\n"); |
Manoj Kumar | 75e4ccb | 2019-07-22 16:10:12 +0100 | [diff] [blame] | 91 | /* Set DMCs to CONFIG state before writing ERR0CTLR0 register */ |
| 92 | mmio_write_32(N1SDP_DMC0_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_CONFIG); |
| 93 | mmio_write_32(N1SDP_DMC1_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_CONFIG); |
| 94 | |
| 95 | /* Enable ECC in DMCs */ |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 96 | mmio_setbits_32(N1SDP_DMC0_ERR0CTLR0_REG, N1SDP_DMC_ERR0CTLR0_ECC_EN); |
| 97 | mmio_setbits_32(N1SDP_DMC1_ERR0CTLR0_REG, N1SDP_DMC_ERR0CTLR0_ECC_EN); |
Manoj Kumar | 75e4ccb | 2019-07-22 16:10:12 +0100 | [diff] [blame] | 98 | |
| 99 | /* Set DMCs to READY state */ |
| 100 | mmio_write_32(N1SDP_DMC0_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_READY); |
| 101 | mmio_write_32(N1SDP_DMC1_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_READY); |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Manish Pandey | b68e286 | 2019-09-11 17:07:40 +0100 | [diff] [blame] | 104 | void remote_dmc_ecc_setup(uint8_t remote_ddr_size) |
| 105 | { |
| 106 | uint64_t remote_dram2_size; |
| 107 | |
| 108 | remote_dram2_size = (remote_ddr_size * 1024UL * 1024UL * 1024UL) - |
| 109 | N1SDP_REMOTE_DRAM1_SIZE; |
| 110 | /* multichip setup */ |
| 111 | INFO("Zeroing remote DDR memories\n"); |
| 112 | zero_normalmem((void *)N1SDP_REMOTE_DRAM1_BASE, |
| 113 | N1SDP_REMOTE_DRAM1_SIZE); |
| 114 | flush_dcache_range(N1SDP_REMOTE_DRAM1_BASE, N1SDP_REMOTE_DRAM1_SIZE); |
| 115 | zero_normalmem((void *)N1SDP_REMOTE_DRAM2_BASE, remote_dram2_size); |
| 116 | flush_dcache_range(N1SDP_REMOTE_DRAM2_BASE, remote_dram2_size); |
| 117 | |
| 118 | INFO("Enabling ECC on remote DMCs\n"); |
| 119 | /* Set DMCs to CONFIG state before writing ERR0CTLR0 register */ |
| 120 | mmio_write_32(N1SDP_REMOTE_DMC0_MEMC_CMD_REG, |
| 121 | N1SDP_DMC_MEMC_CMD_CONFIG); |
| 122 | mmio_write_32(N1SDP_REMOTE_DMC1_MEMC_CMD_REG, |
| 123 | N1SDP_DMC_MEMC_CMD_CONFIG); |
| 124 | |
| 125 | /* Enable ECC in DMCs */ |
| 126 | mmio_setbits_32(N1SDP_REMOTE_DMC0_ERR0CTLR0_REG, |
| 127 | N1SDP_DMC_ERR0CTLR0_ECC_EN); |
| 128 | mmio_setbits_32(N1SDP_REMOTE_DMC1_ERR0CTLR0_REG, |
| 129 | N1SDP_DMC_ERR0CTLR0_ECC_EN); |
| 130 | |
| 131 | /* Set DMCs to READY state */ |
| 132 | mmio_write_32(N1SDP_REMOTE_DMC0_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_READY); |
| 133 | mmio_write_32(N1SDP_REMOTE_DMC1_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_READY); |
| 134 | } |
| 135 | |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 136 | void copy_bl33(uint32_t src, uint32_t dst, uint32_t size) |
| 137 | { |
| 138 | uint32_t i; |
| 139 | |
| 140 | INFO("Copying BL33 to DDR memory\n"); |
| 141 | for (i = 0; i < size; i = i + 8) |
| 142 | mmio_write_64((dst + i), mmio_read_64(src + i)); |
| 143 | |
| 144 | for (i = 0; i < size; i = i + 8) { |
| 145 | if (mmio_read_64(src + i) != mmio_read_64(dst + i)) { |
| 146 | ERROR("Copy failed!\n"); |
| 147 | panic(); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void bl31_platform_setup(void) |
| 153 | { |
| 154 | int ret; |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 155 | struct n1sdp_plat_info plat_info; |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 156 | struct n1sdp_bl33_info bl33_info; |
| 157 | |
| 158 | arm_bl31_platform_setup(); |
| 159 | |
| 160 | ret = sds_init(); |
| 161 | if (ret != SDS_OK) { |
| 162 | ERROR("SDS initialization failed\n"); |
| 163 | panic(); |
| 164 | } |
| 165 | |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 166 | ret = sds_struct_read(N1SDP_SDS_PLATFORM_INFO_STRUCT_ID, |
| 167 | N1SDP_SDS_PLATFORM_INFO_OFFSET, |
| 168 | &plat_info, |
| 169 | N1SDP_SDS_PLATFORM_INFO_SIZE, |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 170 | SDS_ACCESS_MODE_NON_CACHED); |
| 171 | if (ret != SDS_OK) { |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 172 | ERROR("Error getting platform info from SDS\n"); |
| 173 | panic(); |
| 174 | } |
| 175 | /* Validate plat_info SDS */ |
| 176 | if ((plat_info.local_ddr_size == 0) |
| 177 | || (plat_info.local_ddr_size > N1SDP_MAX_DDR_CAPACITY_GB) |
| 178 | || (plat_info.remote_ddr_size > N1SDP_MAX_DDR_CAPACITY_GB) |
| 179 | || (plat_info.slave_count > N1SDP_MAX_SLAVE_COUNT)) { |
| 180 | ERROR("platform info SDS is corrupted\n"); |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 181 | panic(); |
| 182 | } |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 183 | |
| 184 | dmc_ecc_setup(plat_info.local_ddr_size); |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 185 | |
Manish Pandey | b68e286 | 2019-09-11 17:07:40 +0100 | [diff] [blame] | 186 | /* Check if remote memory is present */ |
| 187 | if ((plat_info.multichip_mode) && (plat_info.remote_ddr_size != 0)) |
| 188 | remote_dmc_ecc_setup(plat_info.remote_ddr_size); |
| 189 | |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 190 | ret = sds_struct_read(N1SDP_SDS_BL33_INFO_STRUCT_ID, |
| 191 | N1SDP_SDS_BL33_INFO_OFFSET, |
| 192 | &bl33_info, |
| 193 | N1SDP_SDS_BL33_INFO_SIZE, |
| 194 | SDS_ACCESS_MODE_NON_CACHED); |
| 195 | if (ret != SDS_OK) { |
| 196 | ERROR("Error getting BL33 info from SDS\n"); |
| 197 | panic(); |
| 198 | } |
| 199 | copy_bl33(bl33_info.bl33_src_addr, |
| 200 | bl33_info.bl33_dst_addr, |
| 201 | bl33_info.bl33_size); |
| 202 | /* |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 203 | * Pass platform information to BL33. This method is followed as |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 204 | * currently there is no BL1/BL2 involved in boot flow of N1SDP. |
| 205 | * When TBBR is implemented for N1SDP, this method should be removed |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 206 | * and platform information should be passed to BL33 using NT_FW_CONFIG |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 207 | * passing mechanism. |
| 208 | */ |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 209 | mmio_write_32(N1SDP_PLATFORM_INFO_BASE, *(uint32_t *)&plat_info); |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 210 | } |