Deepak Pandey | 9cbacf6 | 2018-08-08 10:32:51 +0530 | [diff] [blame] | 1 | /* |
sah01 | 6ec01e8 | 2021-06-06 14:38:01 +0530 | [diff] [blame] | 2 | * Copyright (c) 2018-2022, Arm Limited. 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 | |
Max Shvetsov | 0ac3941 | 2019-11-19 11:01:26 +0000 | [diff] [blame] | 7 | #include <common/debug.h> |
Antonio Nino Diaz | 1b0c6f1 | 2019-01-23 21:08:43 +0000 | [diff] [blame] | 8 | #include <drivers/arm/css/css_mhu_doorbell.h> |
Antonio Nino Diaz | c30db5b | 2019-01-23 20:37:32 +0000 | [diff] [blame] | 9 | #include <drivers/arm/css/scmi.h> |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 10 | #include <drivers/arm/css/sds.h> |
Manish Pandey | 2c44a44 | 2019-10-14 17:37:38 +0100 | [diff] [blame] | 11 | #include <drivers/arm/gic600_multichip.h> |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 12 | #include <lib/mmio.h> |
| 13 | #include <lib/utils.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 14 | #include <plat/arm/common/plat_arm.h> |
| 15 | |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 16 | #include "n1sdp_def.h" |
sah01 | 6ec01e8 | 2021-06-06 14:38:01 +0530 | [diff] [blame] | 17 | #include <platform_def.h> |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 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 |
sah01 | 6ec01e8 | 2021-06-06 14:38:01 +0530 | [diff] [blame] | 26 | * - secondary_count |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 27 | * - Local DDR size in GB, DDR memory in master board |
sah01 | 6ec01e8 | 2021-06-06 14:38:01 +0530 | [diff] [blame] | 28 | * - Remote DDR size in GB, DDR memory in secondary 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; |
sah01 | 6ec01e8 | 2021-06-06 14:38:01 +0530 | [diff] [blame] | 32 | uint8_t secondary_count; |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 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 | |
Deepak Pandey | 9cbacf6 | 2018-08-08 10:32:51 +0530 | [diff] [blame] | 37 | static scmi_channel_plat_info_t n1sdp_scmi_plat_info = { |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 38 | .scmi_mbx_mem = N1SDP_SCMI_PAYLOAD_BASE, |
| 39 | .db_reg_addr = PLAT_CSS_MHU_BASE + CSS_SCMI_MHU_DB_REG_OFF, |
| 40 | .db_preserve_mask = 0xfffffffe, |
| 41 | .db_modify_mask = 0x1, |
| 42 | .ring_doorbell = &mhu_ring_doorbell |
Deepak Pandey | 9cbacf6 | 2018-08-08 10:32:51 +0530 | [diff] [blame] | 43 | }; |
| 44 | |
Manish Pandey | 2c44a44 | 2019-10-14 17:37:38 +0100 | [diff] [blame] | 45 | static struct gic600_multichip_data n1sdp_multichip_data __init = { |
| 46 | .rt_owner_base = PLAT_ARM_GICD_BASE, |
| 47 | .rt_owner = 0, |
| 48 | .chip_count = 1, |
| 49 | .chip_addrs = { |
| 50 | PLAT_ARM_GICD_BASE >> 16, |
| 51 | PLAT_ARM_GICD_BASE >> 16 |
| 52 | }, |
| 53 | .spi_ids = { |
Sayanta Pattanayak | fcf6852 | 2020-07-31 12:59:24 +0530 | [diff] [blame] | 54 | {32, 479}, |
| 55 | {512, 959} |
Manish Pandey | 2c44a44 | 2019-10-14 17:37:38 +0100 | [diff] [blame] | 56 | } |
| 57 | }; |
| 58 | |
| 59 | static uintptr_t n1sdp_multichip_gicr_frames[3] = { |
| 60 | PLAT_ARM_GICR_BASE, |
| 61 | PLAT_ARM_GICR_BASE + PLAT_ARM_REMOTE_CHIP_OFFSET, |
| 62 | 0 |
| 63 | }; |
| 64 | |
Aditya Angadi | 7f8837b | 2019-12-31 14:23:53 +0530 | [diff] [blame] | 65 | scmi_channel_plat_info_t *plat_css_get_scmi_info(int channel_id) |
Deepak Pandey | 9cbacf6 | 2018-08-08 10:32:51 +0530 | [diff] [blame] | 66 | { |
| 67 | return &n1sdp_scmi_plat_info; |
| 68 | } |
Chandni Cherukuri | e4bf6a0 | 2018-11-14 13:43:59 +0530 | [diff] [blame] | 69 | |
| 70 | const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops) |
| 71 | { |
| 72 | return css_scmi_override_pm_ops(ops); |
| 73 | } |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * N1SDP platform supports RDIMMs with ECC capability. To use the ECC |
| 77 | * capability, the entire DDR memory space has to be zeroed out before |
| 78 | * enabling the ECC bits in DMC620. Zeroing out several gigabytes of |
| 79 | * memory from SCP is quite time consuming so the following function |
| 80 | * is added to zero out the DDR memory from application processor which is |
sah01 | 6ec01e8 | 2021-06-06 14:38:01 +0530 | [diff] [blame] | 81 | * much faster compared to SCP. Local DDR memory is zeroed out during BL2 |
| 82 | * stage. If remote chip is connected, it's DDR memory is zeroed out here. |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 83 | */ |
| 84 | |
Manish Pandey | b68e286 | 2019-09-11 17:07:40 +0100 | [diff] [blame] | 85 | void remote_dmc_ecc_setup(uint8_t remote_ddr_size) |
| 86 | { |
| 87 | uint64_t remote_dram2_size; |
| 88 | |
| 89 | remote_dram2_size = (remote_ddr_size * 1024UL * 1024UL * 1024UL) - |
| 90 | N1SDP_REMOTE_DRAM1_SIZE; |
| 91 | /* multichip setup */ |
| 92 | INFO("Zeroing remote DDR memories\n"); |
| 93 | zero_normalmem((void *)N1SDP_REMOTE_DRAM1_BASE, |
| 94 | N1SDP_REMOTE_DRAM1_SIZE); |
| 95 | flush_dcache_range(N1SDP_REMOTE_DRAM1_BASE, N1SDP_REMOTE_DRAM1_SIZE); |
| 96 | zero_normalmem((void *)N1SDP_REMOTE_DRAM2_BASE, remote_dram2_size); |
| 97 | flush_dcache_range(N1SDP_REMOTE_DRAM2_BASE, remote_dram2_size); |
| 98 | |
| 99 | INFO("Enabling ECC on remote DMCs\n"); |
| 100 | /* Set DMCs to CONFIG state before writing ERR0CTLR0 register */ |
| 101 | mmio_write_32(N1SDP_REMOTE_DMC0_MEMC_CMD_REG, |
| 102 | N1SDP_DMC_MEMC_CMD_CONFIG); |
| 103 | mmio_write_32(N1SDP_REMOTE_DMC1_MEMC_CMD_REG, |
| 104 | N1SDP_DMC_MEMC_CMD_CONFIG); |
| 105 | |
| 106 | /* Enable ECC in DMCs */ |
| 107 | mmio_setbits_32(N1SDP_REMOTE_DMC0_ERR0CTLR0_REG, |
| 108 | N1SDP_DMC_ERR0CTLR0_ECC_EN); |
| 109 | mmio_setbits_32(N1SDP_REMOTE_DMC1_ERR0CTLR0_REG, |
| 110 | N1SDP_DMC_ERR0CTLR0_ECC_EN); |
| 111 | |
| 112 | /* Set DMCs to READY state */ |
| 113 | mmio_write_32(N1SDP_REMOTE_DMC0_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_READY); |
| 114 | mmio_write_32(N1SDP_REMOTE_DMC1_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_READY); |
| 115 | } |
| 116 | |
Manish Pandey | 2c44a44 | 2019-10-14 17:37:38 +0100 | [diff] [blame] | 117 | void n1sdp_bl31_multichip_setup(void) |
| 118 | { |
| 119 | plat_arm_override_gicr_frames(n1sdp_multichip_gicr_frames); |
| 120 | gic600_multichip_init(&n1sdp_multichip_data); |
| 121 | } |
| 122 | |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 123 | void bl31_platform_setup(void) |
| 124 | { |
| 125 | int ret; |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 126 | struct n1sdp_plat_info plat_info; |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 127 | |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 128 | ret = sds_init(); |
| 129 | if (ret != SDS_OK) { |
| 130 | ERROR("SDS initialization failed\n"); |
| 131 | panic(); |
| 132 | } |
| 133 | |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 134 | ret = sds_struct_read(N1SDP_SDS_PLATFORM_INFO_STRUCT_ID, |
| 135 | N1SDP_SDS_PLATFORM_INFO_OFFSET, |
| 136 | &plat_info, |
| 137 | N1SDP_SDS_PLATFORM_INFO_SIZE, |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 138 | SDS_ACCESS_MODE_NON_CACHED); |
| 139 | if (ret != SDS_OK) { |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 140 | ERROR("Error getting platform info from SDS\n"); |
| 141 | panic(); |
| 142 | } |
| 143 | /* Validate plat_info SDS */ |
| 144 | if ((plat_info.local_ddr_size == 0) |
| 145 | || (plat_info.local_ddr_size > N1SDP_MAX_DDR_CAPACITY_GB) |
| 146 | || (plat_info.remote_ddr_size > N1SDP_MAX_DDR_CAPACITY_GB) |
sah01 | 6ec01e8 | 2021-06-06 14:38:01 +0530 | [diff] [blame] | 147 | || (plat_info.secondary_count > N1SDP_MAX_SECONDARY_COUNT)) { |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 148 | ERROR("platform info SDS is corrupted\n"); |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 149 | panic(); |
| 150 | } |
Manish Pandey | 2f3203f | 2019-10-07 17:47:46 +0100 | [diff] [blame] | 151 | |
Manish Pandey | 2c44a44 | 2019-10-14 17:37:38 +0100 | [diff] [blame] | 152 | if (plat_info.multichip_mode) { |
sah01 | 6ec01e8 | 2021-06-06 14:38:01 +0530 | [diff] [blame] | 153 | n1sdp_multichip_data.chip_count = plat_info.secondary_count + 1; |
Manish Pandey | 2c44a44 | 2019-10-14 17:37:38 +0100 | [diff] [blame] | 154 | n1sdp_bl31_multichip_setup(); |
| 155 | } |
| 156 | arm_bl31_platform_setup(); |
| 157 | |
Manish Pandey | b68e286 | 2019-09-11 17:07:40 +0100 | [diff] [blame] | 158 | /* Check if remote memory is present */ |
| 159 | if ((plat_info.multichip_mode) && (plat_info.remote_ddr_size != 0)) |
| 160 | remote_dmc_ecc_setup(plat_info.remote_ddr_size); |
Manoj Kumar | 69bebd8 | 2019-06-21 17:07:13 +0100 | [diff] [blame] | 161 | } |