Yidi Lin has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/47896 )
Change subject: WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API ......................................................................
WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API
Add mtlib_fw_prop structure to describe the components that are needed for loading a firmware.
Change-Id: Iba363483215252a5aa5ccd7f13043c0d126855f4 Signed-off-by: Yidi Lin yidi.lin@mediatek.com --- M src/soc/mediatek/common/include/soc/mtlib_common.h M src/soc/mediatek/common/mtlib.c M src/soc/mediatek/mt8192/dpm.c M src/soc/mediatek/mt8192/mcupm.c M src/soc/mediatek/mt8192/sspm.c 5 files changed, 73 insertions(+), 24 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/47896/1
diff --git a/src/soc/mediatek/common/include/soc/mtlib_common.h b/src/soc/mediatek/common/include/soc/mtlib_common.h index a2eba62..ff7d292 100644 --- a/src/soc/mediatek/common/include/soc/mtlib_common.h +++ b/src/soc/mediatek/common/include/soc/mtlib_common.h @@ -3,6 +3,16 @@ #ifndef SOC_MEDIATEK_MTLIB_COMMON_H #define SOC_MEDIATEK_MTLIB_COMMON_H
-int mtlib_load_and_run(const char *fw_name, void *addr, void(*reset_mcu)(void)); +struct mtlib_fw_prop { + const char *name; /* The firmware file name in CBFS */ + void *addr; /* The address for running the firmware*/ + void *buf; /* The buffer for loading the firmware*/ + size_t buf_size; /* The buffer size */ + size_t size; /* The firmware real size */ + void *priv; /* The additional data required by the reset callback */ + void (*reset)(struct mtlib_fw_prop *fw); /* The reset callback */ +}; + +int mtlib_load_and_run(struct mtlib_fw_prop *fw);
#endif /* SOC_MEDIATEK_MTLIB_COMMON_H */ diff --git a/src/soc/mediatek/common/mtlib.c b/src/soc/mediatek/common/mtlib.c index 8fe5d4b..aa1bcfe 100644 --- a/src/soc/mediatek/common/mtlib.c +++ b/src/soc/mediatek/common/mtlib.c @@ -7,31 +7,32 @@ #include <soc/symbols.h> #include <timer.h>
-int mtlib_load_and_run(const char *fw_name, void *addr, void (*reset_mcu)(void)) +int mtlib_load_and_run(struct mtlib_fw_prop *fw) { struct stopwatch sw; - size_t blob_bytes; + + if (!fw) + return CB_ERR_ARG;
stopwatch_init(&sw);
- /* Assume MCU firmwares are loaded after DRAM is ready. */ - blob_bytes = cbfs_boot_load_file(fw_name, _dram_dma, REGION_SIZE(dram_dma), - CBFS_TYPE_RAW); - if (blob_bytes == 0) { - printk(BIOS_ERR, "%s: Failed to load %s.\n", __func__, fw_name); + fw->size = cbfs_boot_load_file(fw->name, fw->buf, fw->buf_size, CBFS_TYPE_RAW); + if (fw->size == 0) { + printk(BIOS_ERR, "%s: Failed to load %s.\n", __func__, fw->name); return CB_ERR; }
- memcpy(addr, _dram_dma, blob_bytes); + if (fw->addr) { + memcpy(fw->addr, fw->buf, fw->size); + /* Memory barrier to ensure data is flushed before we release the reset pin. */ + mb(); + }
- /* Memory barrier to ensure data is flushed before we release the reset pin. */ - mb(); - - if (reset_mcu != NULL) - reset_mcu(); + if (fw->reset) + fw->reset(fw);
printk(BIOS_DEBUG, "%s: Load %s in %ld msecs, size %zd bytes\n", - __func__, fw_name, stopwatch_duration_msecs(&sw), blob_bytes); + __func__, fw->name, stopwatch_duration_msecs(&sw), fw->size);
return CB_SUCCESS; } diff --git a/src/soc/mediatek/mt8192/dpm.c b/src/soc/mediatek/mt8192/dpm.c index 4f2aa46..54b428b 100644 --- a/src/soc/mediatek/mt8192/dpm.c +++ b/src/soc/mediatek/mt8192/dpm.c @@ -4,11 +4,12 @@ #include <device/mmio.h> #include <soc/dpm.h> #include <soc/mtlib_common.h> +#include <soc/symbols.h>
#define DPM_DM_FW_FILE "dpm.dm" #define DPM_PM_FW_FILE "dpm.pm"
-static void reset_dpm(void) +static void reset_dpm(struct mtlib_fw_prop *fw) { /* write bootargs */ write32(&mtk_dpm->twam_window_len, 0x0); @@ -18,16 +19,33 @@ write32(&mtk_dpm->sw_rstn, read32(&mtk_dpm->sw_rstn) | 0x1); }
+static struct mtlib_fw_prop dpm_fw[] = { + { + .name = DPM_DM_FW_FILE, + .addr = (void *)DPM_DM_SRAM_BASE, + }, + { + .name = DPM_PM_FW_FILE, + .addr = (void *)DPM_PM_SRAM_BASE, + .reset = reset_dpm, + }, +}; + int dpm_init(void) { + int ret; + + dpm_fw[0].buf = _dram_dma; + dpm_fw[0].buf_size = REGION_SIZE(dram_dma); + dpm_fw[1].buf = _dram_dma; + dpm_fw[1].buf_size = REGION_SIZE(dram_dma); + /* config DPM SRAM layout */ write32(&mtk_dpm->sw_rstn, read32(&mtk_dpm->sw_rstn) | 0x10000000);
- int ret; - - if (mtlib_load_and_run(DPM_DM_FW_FILE, (void *)DPM_DM_SRAM_BASE, NULL)) + if (mtlib_load_and_run(&dpm_fw[0])) ret = -1; - else if (mtlib_load_and_run(DPM_PM_FW_FILE, (void *)DPM_PM_SRAM_BASE, reset_dpm)) + else if (mtlib_load_and_run(&dpm_fw[1])) ret = -2; else ret = 0; diff --git a/src/soc/mediatek/mt8192/mcupm.c b/src/soc/mediatek/mt8192/mcupm.c index a9cff7e..1b647a4 100644 --- a/src/soc/mediatek/mt8192/mcupm.c +++ b/src/soc/mediatek/mt8192/mcupm.c @@ -4,21 +4,31 @@ #include <device/mmio.h> #include <soc/mcupm.h> #include <soc/mtlib_common.h> +#include <soc/symbols.h>
#define ABNORMALBOOT_REG (0x0C55FAA0) #define MCUPM_FW_FILE "mcupm.bin"
-static void reset_mcupm(void) +static void reset_mcupm(struct mtlib_fw_prop *fw) { /* Clear abnormal boot register */ write32((void *)ABNORMALBOOT_REG, 0x0); write32(&mt8192_mcupm->sw_rstn, 0x1); }
+static struct mtlib_fw_prop mcupm = { + .name = MCUPM_FW_FILE, + .addr = (void *)MCUPM_SRAM_BASE, + .reset = reset_mcupm, +}; + void mcupm_init(void) { + mcupm.buf = _dram_dma; + mcupm.buf_size = REGION_SIZE(dram_dma); + write32(&mt8192_mcupm->sw_rstn, 0x0);
- if (mtlib_load_and_run(MCUPM_FW_FILE, (void *)MCUPM_SRAM_BASE, reset_mcupm)) + if (mtlib_load_and_run(&mcupm)) die("%s() failed\n", __func__); } diff --git a/src/soc/mediatek/mt8192/sspm.c b/src/soc/mediatek/mt8192/sspm.c index 0245e3b..76d1b26 100644 --- a/src/soc/mediatek/mt8192/sspm.c +++ b/src/soc/mediatek/mt8192/sspm.c @@ -4,17 +4,27 @@ #include <device/mmio.h> #include <soc/mtlib_common.h> #include <soc/sspm.h> +#include <soc/symbols.h>
#define SSPM_FW_FILE "sspm.bin"
-static void reset_sspm(void) +static void reset_sspm(struct mtlib_fw_prop *fw) { write32(&mt8192_sspm->sw_rstn, 0x1); }
+static struct mtlib_fw_prop sspm = { + .name = SSPM_FW_FILE, + .addr = (void *)SSPM_SRAM_BASE, + .reset = reset_sspm, +}; + void sspm_init(void) { - if (mtlib_load_and_run(SSPM_FW_FILE, (void *)SSPM_SRAM_BASE, reset_sspm)) + sspm.buf = _dram_dma; + sspm.buf_size = REGION_SIZE(dram_dma); + + if (mtlib_load_and_run(&sspm)) printk(BIOS_ERR, "%s() failed\n", __func__);
}
Hello Xi Chen, Hung-Te Lin, build bot (Jenkins), tinghan shen, Paul Menzel, Xixi Chen, Yu-Ping Wu,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/47896
to look at the new patch set (#7).
Change subject: WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API ......................................................................
WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API
Add mtlib_fw_prop structure to describe the components that are needed for loading a firmware.
Change-Id: Iba363483215252a5aa5ccd7f13043c0d126855f4 Signed-off-by: Yidi Lin yidi.lin@mediatek.com --- M src/soc/mediatek/common/include/soc/mtlib_common.h M src/soc/mediatek/common/mtlib.c M src/soc/mediatek/mt8192/dpm.c M src/soc/mediatek/mt8192/mcupm.c M src/soc/mediatek/mt8192/spm.c M src/soc/mediatek/mt8192/sspm.c 6 files changed, 108 insertions(+), 53 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/47896/7
Hello Xi Chen, Hung-Te Lin, build bot (Jenkins), tinghan shen, Paul Menzel, Xixi Chen, Yu-Ping Wu,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/47896
to look at the new patch set (#8).
Change subject: WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API ......................................................................
WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API
Add mtlib_fw_prop structure to describe the components that are needed for loading a firmware.
Change-Id: Iba363483215252a5aa5ccd7f13043c0d126855f4 Signed-off-by: Yidi Lin yidi.lin@mediatek.com --- M src/soc/mediatek/common/include/soc/mtlib_common.h M src/soc/mediatek/common/mtlib.c M src/soc/mediatek/mt8192/dpm.c M src/soc/mediatek/mt8192/mcupm.c M src/soc/mediatek/mt8192/spm.c M src/soc/mediatek/mt8192/sspm.c 6 files changed, 108 insertions(+), 53 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/47896/8
Hello Xi Chen, Hung-Te Lin, build bot (Jenkins), tinghan shen, Paul Menzel, Xixi Chen, Yu-Ping Wu,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/47896
to look at the new patch set (#9).
Change subject: WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API ......................................................................
WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API
Add mtlib_fw_prop structure to describe the components that are needed for loading a firmware.
Change-Id: Iba363483215252a5aa5ccd7f13043c0d126855f4 Signed-off-by: Yidi Lin yidi.lin@mediatek.com --- M src/soc/mediatek/common/include/soc/mtlib_common.h M src/soc/mediatek/common/mtlib.c M src/soc/mediatek/mt8192/dpm.c M src/soc/mediatek/mt8192/mcupm.c M src/soc/mediatek/mt8192/spm.c M src/soc/mediatek/mt8192/sspm.c 6 files changed, 105 insertions(+), 52 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/47896/9
Hello Xi Chen, Hung-Te Lin, build bot (Jenkins), tinghan shen, Paul Menzel, Xixi Chen, Yu-Ping Wu,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/47896
to look at the new patch set (#10).
Change subject: WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API ......................................................................
WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API
Add mtlib_fw_prop structure to describe the components that are needed for loading a firmware.
Change-Id: Iba363483215252a5aa5ccd7f13043c0d126855f4 Signed-off-by: Yidi Lin yidi.lin@mediatek.com --- M src/soc/mediatek/common/include/soc/mtlib_common.h M src/soc/mediatek/common/mtlib.c M src/soc/mediatek/mt8192/dpm.c M src/soc/mediatek/mt8192/mcupm.c M src/soc/mediatek/mt8192/spm.c M src/soc/mediatek/mt8192/sspm.c 6 files changed, 105 insertions(+), 52 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/47896/10
Hung-Te Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/47896 )
Change subject: WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API ......................................................................
Patch Set 10:
(2 comments)
https://review.coreboot.org/c/coreboot/+/47896/10/src/soc/mediatek/common/in... File src/soc/mediatek/common/include/soc/mtlib_common.h:
https://review.coreboot.org/c/coreboot/+/47896/10/src/soc/mediatek/common/in... PS10, Line 6: mtlib_fw_prop what about
struct mtlib_mcu { const char *firmware_name; void *run_address; void *run_size; void *load_buffer; void *buffer_size; void *priv; void (*reset)... }
https://review.coreboot.org/c/coreboot/+/47896/10/src/soc/mediatek/common/in... PS10, Line 16: mtlib_load_and_run what about call this mtlib_init_mcu?
Yidi Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/47896 )
Change subject: WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API ......................................................................
Patch Set 10:
(2 comments)
please move to the chain of CB:48442 for review
https://review.coreboot.org/c/coreboot/+/47896/10/src/soc/mediatek/common/in... File src/soc/mediatek/common/include/soc/mtlib_common.h:
https://review.coreboot.org/c/coreboot/+/47896/10/src/soc/mediatek/common/in... PS10, Line 6: mtlib_fw_prop
what about […]
Done
https://review.coreboot.org/c/coreboot/+/47896/10/src/soc/mediatek/common/in... PS10, Line 16: mtlib_load_and_run
what about call this mtlib_init_mcu?
Done
Yidi Lin has abandoned this change. ( https://review.coreboot.org/c/coreboot/+/47896 )
Change subject: WIP: mediatek/common/mtlib.c: Refactor mtlib_load_and_run API ......................................................................
Abandoned