| 1 |
/* |
| 2 |
* Copyright (c) 2020-2024, Arm Limited and Contributors. All rights reserved. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <common/debug.h> |
| 8 |
#include <drivers/arm/gic600_multichip.h> |
| 9 |
#include <plat/arm/common/plat_arm.h> |
| 10 |
#include <plat/common/platform.h> |
| 11 |
#include <services/el3_spmc_ffa_memory.h> |
| 12 |
|
| 13 |
#include <nrd_plat.h> |
| 14 |
#include <rdn2_ras.h> |
| 15 |
|
| 16 |
#if defined(IMAGE_BL31) |
| 17 |
#if (NRD_PLATFORM_VARIANT == 2) |
| 18 |
static const mmap_region_t rdn2mc_dynamic_mmap[] = { |
| 19 |
#if NRD_CHIP_COUNT > 1 |
| 20 |
NRD_CSS_SHARED_RAM_MMAP(1), |
| 21 |
NRD_CSS_PERIPH_MMAP(1), |
| 22 |
#endif |
| 23 |
#if NRD_CHIP_COUNT > 2 |
| 24 |
NRD_CSS_SHARED_RAM_MMAP(2), |
| 25 |
NRD_CSS_PERIPH_MMAP(2), |
| 26 |
#endif |
| 27 |
#if NRD_CHIP_COUNT > 3 |
| 28 |
NRD_CSS_SHARED_RAM_MMAP(3), |
| 29 |
NRD_CSS_PERIPH_MMAP(3), |
| 30 |
#endif |
| 31 |
}; |
| 32 |
#endif |
| 33 |
|
| 34 |
#if (NRD_PLATFORM_VARIANT == 2) |
| 35 |
static struct gic600_multichip_data rdn2mc_multichip_data __init = { |
| 36 |
.rt_owner_base = PLAT_ARM_GICD_BASE, |
| 37 |
.rt_owner = 0, |
| 38 |
.chip_count = NRD_CHIP_COUNT, |
| 39 |
.chip_addrs = { |
| 40 |
PLAT_ARM_GICD_BASE >> 16, |
| 41 |
#if NRD_CHIP_COUNT > 1 |
| 42 |
(PLAT_ARM_GICD_BASE + NRD_REMOTE_CHIP_MEM_OFFSET(1)) >> 16, |
| 43 |
#endif |
| 44 |
#if NRD_CHIP_COUNT > 2 |
| 45 |
(PLAT_ARM_GICD_BASE + NRD_REMOTE_CHIP_MEM_OFFSET(2)) >> 16, |
| 46 |
#endif |
| 47 |
#if NRD_CHIP_COUNT > 3 |
| 48 |
(PLAT_ARM_GICD_BASE + NRD_REMOTE_CHIP_MEM_OFFSET(3)) >> 16, |
| 49 |
#endif |
| 50 |
}, |
| 51 |
.spi_ids = { |
| 52 |
{PLAT_ARM_GICD_BASE, |
| 53 |
NRD_CHIP0_SPI_MIN, |
| 54 |
NRD_CHIP0_SPI_MAX}, |
| 55 |
#if NRD_CHIP_COUNT > 1 |
| 56 |
{PLAT_ARM_GICD_BASE, |
| 57 |
NRD_CHIP1_SPI_MIN, |
| 58 |
NRD_CHIP1_SPI_MAX}, |
| 59 |
#endif |
| 60 |
#if NRD_CHIP_COUNT > 2 |
| 61 |
{PLAT_ARM_GICD_BASE, |
| 62 |
NRD_CHIP2_SPI_MIN, |
| 63 |
NRD_CHIP2_SPI_MAX}, |
| 64 |
#endif |
| 65 |
#if NRD_CHIP_COUNT > 3 |
| 66 |
{PLAT_ARM_GICD_BASE, |
| 67 |
NRD_CHIP3_SPI_MIN, |
| 68 |
NRD_CHIP3_SPI_MAX}, |
| 69 |
#endif |
| 70 |
} |
| 71 |
}; |
| 72 |
#endif |
| 73 |
|
| 74 |
#if (NRD_PLATFORM_VARIANT == 2) |
| 75 |
static uintptr_t rdn2mc_multichip_gicr_frames[] = { |
| 76 |
/* Chip 0's GICR Base */ |
| 77 |
PLAT_ARM_GICR_BASE, |
| 78 |
#if NRD_CHIP_COUNT > 1 |
| 79 |
/* Chip 1's GICR BASE */ |
| 80 |
PLAT_ARM_GICR_BASE + NRD_REMOTE_CHIP_MEM_OFFSET(1), |
| 81 |
#endif |
| 82 |
#if NRD_CHIP_COUNT > 2 |
| 83 |
/* Chip 2's GICR BASE */ |
| 84 |
PLAT_ARM_GICR_BASE + NRD_REMOTE_CHIP_MEM_OFFSET(2), |
| 85 |
#endif |
| 86 |
#if NRD_CHIP_COUNT > 3 |
| 87 |
/* Chip 3's GICR BASE */ |
| 88 |
PLAT_ARM_GICR_BASE + NRD_REMOTE_CHIP_MEM_OFFSET(3), |
| 89 |
#endif |
| 90 |
UL(0) /* Zero Termination */ |
| 91 |
}; |
| 92 |
#endif |
| 93 |
#endif /* IMAGE_BL31 */ |
| 94 |
|
| 95 |
unsigned int plat_arm_nrd_get_platform_id(void) |
| 96 |
{ |
| 97 |
return mmio_read_32(SID_REG_BASE + SID_SYSTEM_ID_OFFSET) |
| 98 |
& SID_SYSTEM_ID_PART_NUM_MASK; |
| 99 |
} |
| 100 |
|
| 101 |
unsigned int plat_arm_nrd_get_config_id(void) |
| 102 |
{ |
| 103 |
return mmio_read_32(SID_REG_BASE + SID_SYSTEM_CFG_OFFSET); |
| 104 |
} |
| 105 |
|
| 106 |
unsigned int plat_arm_nrd_get_multi_chip_mode(void) |
| 107 |
{ |
| 108 |
return (mmio_read_32(SID_REG_BASE + SID_NODE_ID_OFFSET) & |
| 109 |
SID_MULTI_CHIP_MODE_MASK) >> |
| 110 |
SID_MULTI_CHIP_MODE_SHIFT; |
| 111 |
} |
| 112 |
|
| 113 |
#if defined(IMAGE_BL31) |
| 114 |
void bl31_platform_setup(void) |
| 115 |
{ |
| 116 |
#if (NRD_PLATFORM_VARIANT == 2) |
| 117 |
int ret; |
| 118 |
unsigned int i; |
| 119 |
|
| 120 |
if (plat_arm_nrd_get_multi_chip_mode() == 0) { |
| 121 |
ERROR("Chip Count is %u but multi-chip mode is not enabled\n", |
| 122 |
NRD_CHIP_COUNT); |
| 123 |
panic(); |
| 124 |
} else { |
| 125 |
INFO("Enabling multi-chip support for RD-N2 variant\n"); |
| 126 |
|
| 127 |
for (i = 0; i < ARRAY_SIZE(rdn2mc_dynamic_mmap); i++) { |
| 128 |
ret = mmap_add_dynamic_region( |
| 129 |
rdn2mc_dynamic_mmap[i].base_pa, |
| 130 |
rdn2mc_dynamic_mmap[i].base_va, |
| 131 |
rdn2mc_dynamic_mmap[i].size, |
| 132 |
rdn2mc_dynamic_mmap[i].attr); |
| 133 |
if (ret != 0) { |
| 134 |
ERROR("Failed to add dynamic mmap entry for" |
| 135 |
" i: %d " "(ret=%d)\n", i, ret); |
| 136 |
panic(); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
plat_arm_override_gicr_frames( |
| 141 |
rdn2mc_multichip_gicr_frames); |
| 142 |
gic600_multichip_init(&rdn2mc_multichip_data); |
| 143 |
} |
| 144 |
#endif |
| 145 |
|
| 146 |
nrd_bl31_common_platform_setup(); |
| 147 |
|
| 148 |
#if ENABLE_FEAT_RAS && FFH_SUPPORT |
| 149 |
nrd_ras_platform_setup(&ras_config); |
| 150 |
#endif |
| 151 |
} |
| 152 |
#endif /* IMAGE_BL31 */ |
| 153 |
|
| 154 |
#if SPMC_AT_EL3 |
| 155 |
|
| 156 |
#define DATASTORE_SIZE 1024 |
| 157 |
|
| 158 |
__section("arm_el3_tzc_dram") uint8_t plat_spmc_shmem_datastore[DATASTORE_SIZE]; |
| 159 |
|
| 160 |
int plat_spmc_shmem_datastore_get(uint8_t **datastore, size_t *size) |
| 161 |
{ |
| 162 |
*datastore = plat_spmc_shmem_datastore; |
| 163 |
*size = DATASTORE_SIZE; |
| 164 |
return 0; |
| 165 |
} |
| 166 |
|
| 167 |
/* |
| 168 |
* Add dummy implementations of memory management related platform hooks. |
| 169 |
* Memory share/lend operation are not required on RdN2 platform. |
| 170 |
*/ |
| 171 |
int plat_spmc_shmem_begin(struct ffa_mtd *desc) |
| 172 |
{ |
| 173 |
return 0; |
| 174 |
} |
| 175 |
|
| 176 |
int plat_spmc_shmem_reclaim(struct ffa_mtd *desc) |
| 177 |
{ |
| 178 |
return 0; |
| 179 |
} |
| 180 |
|
| 181 |
int plat_spmd_handle_group0_interrupt(uint32_t intid) |
| 182 |
{ |
| 183 |
/* |
| 184 |
* As of now, there are no sources of Group0 secure interrupt enabled |
| 185 |
* for RDN2. |
| 186 |
*/ |
| 187 |
(void)intid; |
| 188 |
return -1; |
| 189 |
} |
| 190 |
#endif |