1 // SPDX-License-Identifier: Intel
3 * Copyright (C) 2015-2016 Intel Corp.
6 * Mostly taken from coreboot fsp2_0/memory_init.c
11 #include <bootstage.h>
14 #include <asm/global_data.h>
15 #include <asm/mrccache.h>
16 #include <asm/fsp/fsp_infoheader.h>
17 #include <asm/fsp2/fsp_api.h>
18 #include <asm/fsp2/fsp_internal.h>
19 #include <asm/arch/fsp/fsp_configs.h>
20 #include <asm/arch/fsp/fsp_m_upd.h>
22 static int prepare_mrc_cache_type(enum mrc_type_t type,
23 struct mrc_data_container **cachep)
25 struct mrc_data_container *cache;
26 struct mrc_region entry;
29 ret = mrccache_get_region(type, NULL, &entry);
32 cache = mrccache_find_current(&entry);
36 log_debug("MRC at %x, size %x\n", (uint)cache->data, cache->data_size);
42 int prepare_mrc_cache(struct fspm_upd *upd)
44 struct mrc_data_container *cache;
47 ret = prepare_mrc_cache_type(MRC_TYPE_NORMAL, &cache);
49 return log_msg_ret("Cannot get normal cache", ret);
50 upd->arch.nvs_buffer_ptr = cache->data;
52 ret = prepare_mrc_cache_type(MRC_TYPE_VAR, &cache);
54 return log_msg_ret("Cannot get var cache", ret);
55 upd->config.variable_nvs_buffer_ptr = cache->data;
60 int fsp_memory_init(bool s3wake, bool use_spi_flash)
62 struct fspm_upd upd, *fsp_upd;
63 fsp_memory_init_func func;
64 struct binman_entry entry;
65 struct fsp_header *hdr;
66 struct hob_header *hob;
71 log_debug("Locating FSP\n");
72 ret = fsp_locate_fsp(FSP_M, &entry, use_spi_flash, &dev, &hdr, NULL);
74 return log_msg_ret("locate FSP", ret);
75 debug("Found FSP_M at %x, size %x\n", hdr->img_base, hdr->img_size);
77 /* Copy over the default config */
78 fsp_upd = (struct fspm_upd *)(hdr->img_base + hdr->cfg_region_off);
79 if (fsp_upd->header.signature != FSPM_UPD_SIGNATURE)
80 return log_msg_ret("Bad UPD signature", -EPERM);
81 memcpy(&upd, fsp_upd, sizeof(upd));
83 delay = dev_read_u32_default(dev, "fspm,training-delay", 0);
84 ret = fspm_update_config(dev, &upd);
87 return log_msg_ret("Could not setup config", ret);
93 printf("SDRAM training (%d seconds)...", delay);
95 log_debug("SDRAM init...");
96 bootstage_start(BOOTSTAGE_ID_ACCUM_FSP_M, "fsp-m");
97 func = (fsp_memory_init_func)(hdr->img_base + hdr->fsp_mem_init);
98 ret = func(&upd, &hob);
99 bootstage_accum(BOOTSTAGE_ID_ACCUM_FSP_M);
106 return log_msg_ret("SDRAM init fail\n", ret);
108 gd->arch.hob_list = hob;
110 ret = fspm_done(dev);
112 return log_msg_ret("fsm_done\n", ret);