Hung-Te Lin has submitted this change. ( https://review.coreboot.org/c/coreboot/+/46930 )
Change subject: soc/mediatek/common: Add common API for loading firmwares ......................................................................
soc/mediatek/common: Add common API for loading firmwares
Add mtk_init_mcu to load the firmware to the specified memory address and run the firmware. This function also measures the load time and the blob size. For example:
mtk_init_mcu: Loaded (and reset) dpm.pm in 15 msecs (14004 bytes)
Signed-off-by: Yidi Lin yidi.lin@mediatek.com Change-Id: Ie94001bbda25fe015f43172e92a1006e059de223 Reviewed-on: https://review.coreboot.org/c/coreboot/+/46930 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Hung-Te Lin hungte@chromium.org --- A src/soc/mediatek/common/include/soc/mcu_common.h A src/soc/mediatek/common/mcu.c M src/soc/mediatek/mt8192/Makefile.inc 3 files changed, 57 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Hung-Te Lin: Looks good to me, approved
diff --git a/src/soc/mediatek/common/include/soc/mcu_common.h b/src/soc/mediatek/common/include/soc/mcu_common.h new file mode 100644 index 0000000..974da52 --- /dev/null +++ b/src/soc/mediatek/common/include/soc/mcu_common.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef SOC_MEDIATEK_MTLIB_COMMON_H +#define SOC_MEDIATEK_MTLIB_COMMON_H + +struct mtk_mcu { + const char *firmware_name; /* The firmware file name in CBFS */ + void *run_address; /* The address for running the firmware */ + size_t run_size; /* The buffer for loading the firmware */ + void *load_buffer; /* The buffer size */ + size_t buffer_size; /* The firmware real size */ + void *priv; /* The additional data required by the reset callback */ + void (*reset)(struct mtk_mcu *mcu); /* The reset callback */ +}; + +int mtk_init_mcu(struct mtk_mcu *mcu); + +#endif /* SOC_MEDIATEK_MTLIB_COMMON_H */ diff --git a/src/soc/mediatek/common/mcu.c b/src/soc/mediatek/common/mcu.c new file mode 100644 index 0000000..d0a1107 --- /dev/null +++ b/src/soc/mediatek/common/mcu.c @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <arch/barrier.h> +#include <cbfs.h> +#include <console/console.h> +#include <soc/mcu_common.h> +#include <soc/symbols.h> +#include <timer.h> + +int mtk_init_mcu(struct mtk_mcu *mcu) +{ + struct stopwatch sw; + + if (!mcu) + return CB_ERR_ARG; + + stopwatch_init(&sw); + + mcu->run_size = cbfs_load(mcu->firmware_name, mcu->load_buffer, mcu->buffer_size); + if (mcu->run_size == 0) { + printk(BIOS_ERR, "%s: Failed to load %s\n", __func__, mcu->firmware_name); + return CB_ERR; + } + + if (mcu->run_address) { + memcpy(mcu->run_address, mcu->load_buffer, mcu->run_size); + /* Memory barrier to ensure data is flushed before resetting MCU. */ + mb(); + } + + if (mcu->reset) + mcu->reset(mcu); + + printk(BIOS_DEBUG, "%s: Loaded (and reset) %s in %ld msecs (%zd bytes)\n", + __func__, mcu->firmware_name, stopwatch_duration_msecs(&sw), mcu->run_size); + + return CB_SUCCESS; +} diff --git a/src/soc/mediatek/mt8192/Makefile.inc b/src/soc/mediatek/mt8192/Makefile.inc index 421968d..8c7fe0d 100644 --- a/src/soc/mediatek/mt8192/Makefile.inc +++ b/src/soc/mediatek/mt8192/Makefile.inc @@ -39,6 +39,7 @@ ramstage-y += ../common/gpio.c gpio.c ramstage-y += emi.c ramstage-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c +ramstage-y += ../common/mcu.c ramstage-y += ../common/mmu_operations.c mmu_operations.c ramstage-y += ../common/mtcmos.c mtcmos.c ramstage-y += soc.c