soc/mediatek: Extract spm_parse_firmware to common
spm_parse_firmware can be shared by MT8192 and MT8195. TEST=emerge-asurada coreboot; Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com> Change-Id: I54d9672aa9ee9078ec9fe3fa4f2e9fe860a50636 Reviewed-on: https://review.coreboot.org/c/coreboot/+/55139 Reviewed-by: Rex-BC Chen <rex-bc.chen@mediatek.corp-partner.google.com> Reviewed-by: Yu-Ping Wu <yupingso@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
c6c54439f8
commit
80373767ed
|
@ -0,0 +1,9 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#ifndef SOC_MEDIATEK_SPM_COMMON_H
|
||||||
|
#define SOC_MEDIATEK_SPM_COMMON_H
|
||||||
|
|
||||||
|
#include <soc/mcu_common.h>
|
||||||
|
|
||||||
|
void spm_parse_firmware(struct mtk_mcu *mcu);
|
||||||
|
#endif /* SOC_MEDIATEK_SPM_COMMON_H */
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <console/console.h>
|
||||||
|
#include <soc/mcu_common.h>
|
||||||
|
#include <soc/spm.h>
|
||||||
|
#include <soc/spm_common.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <timer.h>
|
||||||
|
|
||||||
|
#define SPMFW_HEADER_SIZE 16
|
||||||
|
|
||||||
|
void spm_parse_firmware(struct mtk_mcu *mcu)
|
||||||
|
{
|
||||||
|
size_t file_size, copy_size;
|
||||||
|
int offset;
|
||||||
|
u16 firmware_size;
|
||||||
|
|
||||||
|
struct dyna_load_pcm *pcm = (struct dyna_load_pcm *)mcu->priv;
|
||||||
|
file_size = mcu->run_size;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* spmfw layout:
|
||||||
|
* u16 firmware_size
|
||||||
|
* u32 binary[firmware_size]
|
||||||
|
* struct pcm_desc descriptor
|
||||||
|
* char *version
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Firmware size */
|
||||||
|
offset = 0;
|
||||||
|
copy_size = sizeof(firmware_size);
|
||||||
|
memcpy(&firmware_size, mcu->load_buffer + offset, copy_size);
|
||||||
|
printk(BIOS_DEBUG, "SPM: binary array size = %#x\n", firmware_size);
|
||||||
|
|
||||||
|
/* Binary */
|
||||||
|
offset = SPMFW_HEADER_SIZE; /* binary start offset */
|
||||||
|
copy_size = firmware_size * sizeof(u32);
|
||||||
|
assert(offset < file_size);
|
||||||
|
pcm->buf = (u8 *)(mcu->load_buffer + offset);
|
||||||
|
|
||||||
|
/* Descriptor */
|
||||||
|
offset += copy_size;
|
||||||
|
assert(offset < file_size);
|
||||||
|
copy_size = sizeof(pcm->desc);
|
||||||
|
memcpy(&pcm->desc, mcu->load_buffer + offset, copy_size);
|
||||||
|
|
||||||
|
/* Firmware size and total words need to be the same */
|
||||||
|
assert(firmware_size == pcm->desc.total_words);
|
||||||
|
|
||||||
|
/* Version */
|
||||||
|
offset += copy_size;
|
||||||
|
assert(offset < file_size);
|
||||||
|
printk(BIOS_INFO, "SPM: spmfw (version %s)\n", (u8 *)mcu->load_buffer + offset);
|
||||||
|
}
|
|
@ -60,7 +60,7 @@ ramstage-y += ../common/mtcmos.c mtcmos.c
|
||||||
ramstage-y += ../common/pmif.c
|
ramstage-y += ../common/pmif.c
|
||||||
ramstage-y += ../common/rtc.c ../common/rtc_mt6359p.c
|
ramstage-y += ../common/rtc.c ../common/rtc_mt6359p.c
|
||||||
ramstage-y += soc.c
|
ramstage-y += soc.c
|
||||||
ramstage-y += spm.c
|
ramstage-y += ../common/spm.c spm.c
|
||||||
ramstage-y += ../common/sspm.c
|
ramstage-y += ../common/sspm.c
|
||||||
ramstage-y += ../common/timer.c
|
ramstage-y += ../common/timer.c
|
||||||
ramstage-y += ../common/uart.c
|
ramstage-y += ../common/uart.c
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
#include <device/mmio.h>
|
#include <device/mmio.h>
|
||||||
#include <soc/mcu_common.h>
|
#include <soc/mcu_common.h>
|
||||||
#include <soc/spm.h>
|
#include <soc/spm.h>
|
||||||
|
#include <soc/spm_common.h>
|
||||||
#include <soc/symbols.h>
|
#include <soc/symbols.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <timer.h>
|
#include <timer.h>
|
||||||
|
|
||||||
#define SPM_SYSTEM_BASE_OFFSET 0x40000000
|
#define SPM_SYSTEM_BASE_OFFSET 0x40000000
|
||||||
#define SPMFW_HEADER_SIZE 16
|
|
||||||
|
|
||||||
static const struct pwr_ctrl spm_init_ctrl = {
|
static const struct pwr_ctrl spm_init_ctrl = {
|
||||||
/* Auto-gen Start */
|
/* Auto-gen Start */
|
||||||
|
@ -476,50 +476,6 @@ static void spm_init_pcm_register(void)
|
||||||
write32(&mtk_spm->pcm_pwr_io_en, 0);
|
write32(&mtk_spm->pcm_pwr_io_en, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spm_parse_firmware(struct mtk_mcu *mcu)
|
|
||||||
{
|
|
||||||
size_t file_size, copy_size;
|
|
||||||
int offset;
|
|
||||||
u16 firmware_size;
|
|
||||||
|
|
||||||
struct dyna_load_pcm *pcm = (struct dyna_load_pcm *)mcu->priv;
|
|
||||||
file_size = mcu->run_size;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* spmfw layout:
|
|
||||||
* u16 firmware_size
|
|
||||||
* u32 binary[firmware_size]
|
|
||||||
* struct pcm_desc descriptor
|
|
||||||
* char *version
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Firmware size */
|
|
||||||
offset = 0;
|
|
||||||
copy_size = sizeof(firmware_size);
|
|
||||||
memcpy(&firmware_size, mcu->load_buffer + offset, copy_size);
|
|
||||||
printk(BIOS_DEBUG, "SPM: binary array size = %#x\n", firmware_size);
|
|
||||||
|
|
||||||
/* Binary */
|
|
||||||
offset = SPMFW_HEADER_SIZE; /* binary start offset */
|
|
||||||
copy_size = firmware_size * sizeof(u32);
|
|
||||||
assert(offset < file_size);
|
|
||||||
pcm->buf = (u8 *)(mcu->load_buffer + offset);
|
|
||||||
|
|
||||||
/* Descriptor */
|
|
||||||
offset += copy_size;
|
|
||||||
assert(offset < file_size);
|
|
||||||
copy_size = sizeof(pcm->desc);
|
|
||||||
memcpy(&pcm->desc, mcu->load_buffer + offset, copy_size);
|
|
||||||
|
|
||||||
/* Firmware size and total words need to be the same */
|
|
||||||
assert(firmware_size == pcm->desc.total_words);
|
|
||||||
|
|
||||||
/* Version */
|
|
||||||
offset += copy_size;
|
|
||||||
assert(offset < file_size);
|
|
||||||
printk(BIOS_INFO, "SPM: spmfw (version %s)\n", (u8 *)mcu->load_buffer + offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void spm_set_wakeup_event(const struct pwr_ctrl *pwrctrl)
|
static void spm_set_wakeup_event(const struct pwr_ctrl *pwrctrl)
|
||||||
{
|
{
|
||||||
u32 val, mask;
|
u32 val, mask;
|
||||||
|
|
Loading…
Reference in New Issue