diff options
author | Huayang Duan <huayang.duan@mediatek.com> | 2019-08-27 13:36:14 +0800 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2019-10-09 22:22:41 +0000 |
commit | 078332e4d82a9a2edfa4e3fbcdc8b0b78356f989 (patch) | |
tree | f5f576fa261890f34eae1648d9224ef6fe1f3be8 /src/soc/mediatek | |
parent | 846be446d3099544c2d1029ca2b7884c1641441d (diff) | |
download | coreboot-078332e4d82a9a2edfa4e3fbcdc8b0b78356f989.tar.xz |
soc/mediatek/mt8183: Run DRAM full calibration
Load the calibration params from flash first and check the correctness
of the params. If the params have correct format, perform DRAM fast
calibration with these params to reduce bootup time. Otherwise, load the
DRAM blob and perform DRAM full calibration.
Bootup time of DRAM partial calibration:
- 1,349,385 usecs with low frequency
- 924,698 usecs with middle frequency
- 1,270,089 usecs with high frequency
3,544,172 usecs in total.
Bootup time of DRAM fast calibration:
- 216,663 usecs with low frequency
- 328,220 usecs with middle frequency
- 322,612 usecs with high frequency
867,495 usecs in total.
BUG=b:139099592
BRANCH=none
TEST=emerge-kukui coreboot
Change-Id: I8de29b14b1fb24b3b4f351c855c5c4d8f350cc34
Signed-off-by: Huayang Duan <huayang.duan@mediatek.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35110
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Diffstat (limited to 'src/soc/mediatek')
-rw-r--r-- | src/soc/mediatek/mt8183/Makefile.inc | 8 | ||||
-rw-r--r-- | src/soc/mediatek/mt8183/include/soc/emi.h | 4 | ||||
-rw-r--r-- | src/soc/mediatek/mt8183/memory.c | 137 |
3 files changed, 144 insertions, 5 deletions
diff --git a/src/soc/mediatek/mt8183/Makefile.inc b/src/soc/mediatek/mt8183/Makefile.inc index 72a4d9cf62..70fd08052c 100644 --- a/src/soc/mediatek/mt8183/Makefile.inc +++ b/src/soc/mediatek/mt8183/Makefile.inc @@ -81,6 +81,14 @@ sspm.bin-file := $(MT8183_BLOB_DIR)/sspm.bin sspm.bin-type := raw sspm.bin-compression := $(CBFS_COMPRESS_FLAG) +DRAM_CBFS := $(CONFIG_CBFS_PREFIX)/dram +$(DRAM_CBFS)-file := $(MT8183_BLOB_DIR)/dram.elf +$(DRAM_CBFS)-type := stage +$(DRAM_CBFS)-compression := none +ifneq ($(wildcard $($(DRAM_CBFS)-file)),) + cbfs-files-y += $(DRAM_CBFS) +endif + BL31_MAKEARGS += PLAT=mt8183 CPPFLAGS_common += -Isrc/soc/mediatek/mt8183/include diff --git a/src/soc/mediatek/mt8183/include/soc/emi.h b/src/soc/mediatek/mt8183/include/soc/emi.h index ab21bc7e12..624c0a4ac3 100644 --- a/src/soc/mediatek/mt8183/include/soc/emi.h +++ b/src/soc/mediatek/mt8183/include/soc/emi.h @@ -71,6 +71,8 @@ struct sdram_params { u16 delay_cell_unit; }; +struct dramc_param_ops; + enum { LP4X_DDR1600, LP4X_DDR2400, @@ -86,6 +88,6 @@ size_t sdram_size(void); const struct sdram_params *get_sdram_config(void); void enable_emi_dcm(void); void mt_set_emi(const struct sdram_params *freq_params); -void mt_mem_init(const struct sdram_params *freq_params); +void mt_mem_init(struct dramc_param_ops *dparam_ops); #endif /* SOC_MEDIATEK_MT8183_EMI_H */ diff --git a/src/soc/mediatek/mt8183/memory.c b/src/soc/mediatek/mt8183/memory.c index 67f6c65363..c2ddb999de 100644 --- a/src/soc/mediatek/mt8183/memory.c +++ b/src/soc/mediatek/mt8183/memory.c @@ -14,18 +14,18 @@ */ #include <assert.h> +#include <cbfs.h> #include <console/console.h> +#include <soc/dramc_param.h> #include <soc/dramc_pi_api.h> #include <soc/emi.h> +#include <string.h> #include <symbols.h> -void mt_mem_init(const struct sdram_params *freq_params) +static void mt_mem_test(void) { u64 rank_size[RANK_MAX]; - /* memory calibration */ - mt_set_emi(freq_params); - if (CONFIG(MEMORY_TEST)) { size_t r; u8 *addr = _dram; @@ -49,3 +49,132 @@ void mt_mem_init(const struct sdram_params *freq_params) } } } + +static void dump_param_header(const struct dramc_param *dparam) +{ + const struct dramc_param_header *header = &dparam->header; + + printk(BIOS_DEBUG, "header.status = %#x\n", header->status); + printk(BIOS_DEBUG, "header.magic = %#x (expected: %#x)\n", + header->magic, DRAMC_PARAM_HEADER_MAGIC); + printk(BIOS_DEBUG, "header.version = %#x (expected: %#x)\n", + header->version, DRAMC_PARAM_HEADER_VERSION); + printk(BIOS_DEBUG, "header.size = %#x (expected: %#lx)\n", + header->size, sizeof(*dparam)); + printk(BIOS_DEBUG, "header.config = %#x\n", header->config); + printk(BIOS_DEBUG, "header.flags = %#x\n", header->flags); + printk(BIOS_DEBUG, "header.checksum = %#x\n", header->checksum); +} + +static int dram_run_fast_calibration(const struct dramc_param *dparam, + u16 config) +{ + if (!is_valid_dramc_param(dparam)) { + printk(BIOS_WARNING, + "Invalid DRAM calibration data from flash\n"); + dump_param_header(dparam); + return -1; + } + + if (dparam->header.config != config) { + printk(BIOS_WARNING, + "Incompatible config for calibration data from flash " + "(expected: %#x, saved: %#x)\n", + config, dparam->header.config); + return -1; + } + + return 0; +} + +static int dram_run_full_calibration(struct dramc_param *dparam, u16 config) +{ + initialize_dramc_param(dparam, config); + + /* Load and run the provided blob for full-calibration if available */ + struct prog dram = PROG_INIT(PROG_REFCODE, CONFIG_CBFS_PREFIX "/dram"); + + if (prog_locate(&dram)) + return -1; + + if (cbfs_prog_stage_load(&dram)) + return -2; + + prog_set_entry(&dram, prog_entry(&dram), dparam); + prog_run(&dram); + + if (dparam->header.status != DRAMC_SUCCESS) { + printk(BIOS_ERR, "Full calibration failed: status = %d\n", + dparam->header.status); + return -3; + } + + if (!(dparam->header.flags & DRAMC_FLAG_HAS_SAVED_DATA)) { + printk(BIOS_ERR, + "Full calibration executed without saving parameters. " + "Please ensure the blob is built properly.\n"); + return -4; + } + + return 0; +} + +static void set_source_to_flash(struct sdram_params *freq_params) +{ + for (u8 shuffle = DRAM_DFS_SHUFFLE_1; shuffle < DRAM_DFS_SHUFFLE_MAX; + shuffle++) + freq_params[shuffle].source = DRAMC_PARAM_SOURCE_FLASH; +} + +static void init_sdram_params(struct sdram_params *dst, + const struct sdram_params *src) +{ + for (u8 shuffle = DRAM_DFS_SHUFFLE_1; shuffle < DRAM_DFS_SHUFFLE_MAX; + shuffle++) + memcpy(&dst[shuffle], src, sizeof(*dst)); +} + +void mt_mem_init(struct dramc_param_ops *dparam_ops) +{ + struct dramc_param *dparam = dparam_ops->param; + struct sdram_params *freq_params = dparam->freq_params; + + u16 config = 0; + if (CONFIG(MT8183_DRAM_EMCP)) + config |= DRAMC_CONFIG_EMCP; + + /* Load calibration params from flash and run fast calibration */ + if (dparam_ops->read_from_flash(dparam)) { + if (dram_run_fast_calibration(dparam, config) == 0) { + printk(BIOS_INFO, + "DRAM calibraion params loaded from flash\n"); + mt_set_emi(freq_params); + mt_mem_test(); + return; + } + } else { + printk(BIOS_WARNING, + "Failed to read calibration data from flash\n"); + } + + /* Run full calibration */ + int err = dram_run_full_calibration(dparam, config); + if (err == 0) { + printk(BIOS_INFO, "Successfully loaded DRAM blobs and " + "ran DRAM calibration\n"); + set_source_to_flash(dparam->freq_params); + dparam_ops->write_to_flash(dparam); + printk(BIOS_DEBUG, "Calibration params saved to flash: " + "version=%#x, size=#%x\n", + dparam->header.version, dparam->header.size); + return; + } + + printk(BIOS_ERR, "Failed to do full calibration (%d), " + "falling back to load default sdram param\n", err); + + /* Init params from sdram configs and run partial calibration */ + init_sdram_params(freq_params, get_sdram_config()); + mt_set_emi(freq_params); + mt_mem_test(); +} |