From b5a066377101dfc54e36589969cc436c0200212b Mon Sep 17 00:00:00 2001 From: Konstantin Porotchkin Date: Sun, 28 Feb 2021 16:12:56 +0200 Subject: [PATCH] plat/marvell/armada: postpone MSS CPU startup to BL31 stage Normally the CP MSS CPU was started at the end of FW load to IRAM at BL2. However, (especailly in secure boot mode), some bus attributes should be changed from defaults before the MSS CPU tries to access shared resources. This patch starts to use CP MSS SRAM for FW load in both secure and non-secure boot modes. The FW loader inserts a magic number into MSS SRAM as an indicator of successfully loaded FS during the BL2 stage and skips releasing the MSS CPU from the reset state. Then, at BL31 stage, the MSS CPU is released from reset following the call to cp110_init function that handles all the required bus attributes configurations. Change-Id: Idcf81cc350a086835abed365154051dd79f1ce2e Signed-off-by: Konstantin Porotchkin Reviewed-on: https://sj1git1.cavium.com/c/IP/SW/boot/atf/+/46890 Tested-by: sa_ip-sw-jenkins --- plat/marvell/armada/a8k/common/mss/mss_a8k.mk | 3 +- .../armada/a8k/common/mss/mss_bl2_setup.c | 12 +----- .../armada/a8k/common/mss/mss_bl31_setup.c | 37 +++++++++++++++++++ plat/marvell/armada/a8k/common/mss/mss_defs.h | 33 +++++++++++++++++ .../armada/a8k/common/plat_bl31_setup.c | 6 +++ .../armada/common/mss/mss_scp_bootloader.c | 32 ++++++---------- 6 files changed, 92 insertions(+), 31 deletions(-) create mode 100644 plat/marvell/armada/a8k/common/mss/mss_bl31_setup.c create mode 100644 plat/marvell/armada/a8k/common/mss/mss_defs.h diff --git a/plat/marvell/armada/a8k/common/mss/mss_a8k.mk b/plat/marvell/armada/a8k/common/mss/mss_a8k.mk index d8d492193..315fc8741 100644 --- a/plat/marvell/armada/a8k/common/mss/mss_a8k.mk +++ b/plat/marvell/armada/a8k/common/mss/mss_a8k.mk @@ -11,7 +11,8 @@ A8K_MSS_SOURCE := $(PLAT_MARVELL)/a8k/common/mss BL2_SOURCES += $(A8K_MSS_SOURCE)/mss_bl2_setup.c \ $(MARVELL_MOCHI_DRV) -BL31_SOURCES += $(A8K_MSS_SOURCE)/mss_pm_ipc.c +BL31_SOURCES += $(A8K_MSS_SOURCE)/mss_pm_ipc.c \ + $(A8K_MSS_SOURCE)/mss_bl31_setup.c PLAT_INCLUDES += -I$(A8K_MSS_SOURCE) diff --git a/plat/marvell/armada/a8k/common/mss/mss_bl2_setup.c b/plat/marvell/armada/a8k/common/mss/mss_bl2_setup.c index 71fa2b868..dee2d5b0b 100644 --- a/plat/marvell/armada/a8k/common/mss/mss_bl2_setup.c +++ b/plat/marvell/armada/a8k/common/mss/mss_bl2_setup.c @@ -16,7 +16,7 @@ #include #include /* timer functionality */ - +#include "mss_defs.h" #include "mss_scp_bootloader.h" /* MSS windows configuration */ @@ -30,10 +30,6 @@ #define MSS_EXTERNAL_ADDR_MASK 0xfffffff #define MSS_INTERNAL_ACCESS_BIT 28 -#define MSS_AP_REGS_OFFSET 0x580000 -#define MSS_CP_SRAM_OFFSET 0x220000 -#define MSS_CP_REGS_OFFSET 0x280000 - struct addr_map_win ccu_mem_map[] = { {MVEBU_CP_REGS_BASE(0), 0x4000000, IO_0_TID} }; @@ -130,11 +126,7 @@ uintptr_t bl2_plat_get_cp_mss_regs(int ap_idx, int cp_idx) uintptr_t bl2_plat_get_cp_mss_sram(int ap_idx, int cp_idx) { - if (is_secure()) { - return MVEBU_CP_REGS_BASE(cp_idx) + MSS_CP_SRAM_OFFSET; - } - - return 0; /* SRAM will not be used */ + return MVEBU_CP_REGS_BASE(cp_idx) + MSS_CP_SRAM_OFFSET; } uintptr_t bl2_plat_get_ap_mss_regs(int ap_idx) diff --git a/plat/marvell/armada/a8k/common/mss/mss_bl31_setup.c b/plat/marvell/armada/a8k/common/mss/mss_bl31_setup.c new file mode 100644 index 000000000..52a892956 --- /dev/null +++ b/plat/marvell/armada/a8k/common/mss/mss_bl31_setup.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Marvell International Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + * https://spdx.org/licenses + */ + +#include + +#include +#include +#include + +#include + +#include "mss_defs.h" + +void mss_start_cp_cm3(int cp) +{ + uint32_t magic; + uintptr_t sram = MVEBU_CP_REGS_BASE(cp) + MSS_CP_SRAM_OFFSET; + uintptr_t regs = MVEBU_CP_REGS_BASE(cp) + MSS_CP_REGS_OFFSET; + + magic = mmio_read_32(sram); + + /* Make sure the FW was loaded */ + if (magic != MSS_FW_READY_MAGIC) { + return; + } + + NOTICE("Starting CP%d MSS CPU\n", cp); + /* remove the magic */ + mmio_write_32(sram, 0); + /* Release M3 from reset */ + mmio_write_32(MSS_M3_RSTCR(regs), + (MSS_M3_RSTCR_RST_OFF << MSS_M3_RSTCR_RST_OFFSET)); +} diff --git a/plat/marvell/armada/a8k/common/mss/mss_defs.h b/plat/marvell/armada/a8k/common/mss/mss_defs.h new file mode 100644 index 000000000..6956461a5 --- /dev/null +++ b/plat/marvell/armada/a8k/common/mss/mss_defs.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Marvell International Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + * https://spdx.org/licenses + */ + +#ifndef MSS_DEFS_H +#define MSS_DEFS_H + +#define MSS_DMA_SRCBR(base) (base + 0xC0) +#define MSS_DMA_DSTBR(base) (base + 0xC4) +#define MSS_DMA_CTRLR(base) (base + 0xC8) +#define MSS_M3_RSTCR(base) (base + 0xFC) + +#define MSS_DMA_CTRLR_SIZE_OFFSET (0) +#define MSS_DMA_CTRLR_REQ_OFFSET (15) +#define MSS_DMA_CTRLR_REQ_SET (1) +#define MSS_DMA_CTRLR_ACK_OFFSET (12) +#define MSS_DMA_CTRLR_ACK_MASK (0x1) +#define MSS_DMA_CTRLR_ACK_READY (1) +#define MSS_M3_RSTCR_RST_OFFSET (0) +#define MSS_M3_RSTCR_RST_OFF (1) + +#define MSS_FW_READY_MAGIC 0x46575144 /* FWRD */ + +#define MSS_AP_REGS_OFFSET 0x00580000 +#define MSS_CP_SRAM_OFFSET 0x00220000 +#define MSS_CP_REGS_OFFSET 0x00280000 + +void mss_start_cp_cm3(int cp); + +#endif /* MSS_DEFS_H */ diff --git a/plat/marvell/armada/a8k/common/plat_bl31_setup.c b/plat/marvell/armada/a8k/common/plat_bl31_setup.c index 50dcd2891..db85cce85 100644 --- a/plat/marvell/armada/a8k/common/plat_bl31_setup.c +++ b/plat/marvell/armada/a8k/common/plat_bl31_setup.c @@ -19,6 +19,7 @@ #if MSS_SUPPORT #include #include +#include #endif /* In Armada-8k family AP806/AP807, CP0 connected to PIDI @@ -124,6 +125,11 @@ void bl31_plat_arch_setup(void) STREAM_ID_BASE + (cp * MAX_STREAM_ID_PER_CP)); marvell_bl31_mpp_init(cp); + +#if MSS_SUPPORT + /* Release CP MSS CPU from reset once the CP init is done */ + mss_start_cp_cm3(cp); +#endif } for (cp = 1; cp < CP_COUNT; cp++) diff --git a/plat/marvell/armada/common/mss/mss_scp_bootloader.c b/plat/marvell/armada/common/mss/mss_scp_bootloader.c index 72a304a80..fbede1b1a 100644 --- a/plat/marvell/armada/common/mss/mss_scp_bootloader.c +++ b/plat/marvell/armada/common/mss/mss_scp_bootloader.c @@ -19,22 +19,9 @@ #include #include #include +#include #include -#define MSS_DMA_SRCBR(base) (base + 0xC0) -#define MSS_DMA_DSTBR(base) (base + 0xC4) -#define MSS_DMA_CTRLR(base) (base + 0xC8) -#define MSS_M3_RSTCR(base) (base + 0xFC) - -#define MSS_DMA_CTRLR_SIZE_OFFSET (0) -#define MSS_DMA_CTRLR_REQ_OFFSET (15) -#define MSS_DMA_CTRLR_REQ_SET (1) -#define MSS_DMA_CTRLR_ACK_OFFSET (12) -#define MSS_DMA_CTRLR_ACK_MASK (0x1) -#define MSS_DMA_CTRLR_ACK_READY (1) -#define MSS_M3_RSTCR_RST_OFFSET (0) -#define MSS_M3_RSTCR_RST_OFF (1) - #define MSS_DMA_TIMEOUT 1000 #define MSS_EXTERNAL_SPACE 0x50000000 #define MSS_EXTERNAL_ADDR_MASK 0xfffffff @@ -161,15 +148,20 @@ static int mss_image_load(uint32_t src_addr, uint32_t size, bl2_plat_configure_mss_windows(mss_regs); - /* Wipe the MSS SRAM after using it as copy buffer */ - if (sram) { + if (sram != 0) { + /* Wipe the MSS SRAM after using it as copy buffer */ memset((void *)sram, 0, MSS_SRAM_SIZE); + NOTICE("CP MSS startup is postponed\n"); + /* FW loaded, but CPU startup postponed until final CP setup */ + mmio_write_32(sram, MSS_FW_READY_MAGIC); + dsb(); + } else { + /* Release M3 from reset */ + mmio_write_32(MSS_M3_RSTCR(mss_regs), + (MSS_M3_RSTCR_RST_OFF << + MSS_M3_RSTCR_RST_OFFSET)); } - /* Release M3 from reset */ - mmio_write_32(MSS_M3_RSTCR(mss_regs), - (MSS_M3_RSTCR_RST_OFF << MSS_M3_RSTCR_RST_OFFSET)); - NOTICE("Done\n"); return 0; -- GitLab