blob: 117f36a84829f88b2b71aba568e0374f94697cce [file] [log] [blame]
Simon Glass466c7852019-12-06 21:42:18 -07001// SPDX-License-Identifier: Intel
2/*
3 * Copyright (C) 2015-2016 Intel Corp.
4 * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.)
5 * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.)
6 * Mostly taken from coreboot fsp2_0/memory_init.c
7 */
8
9#include <common.h>
10#include <binman.h>
Simon Glass1ea97892020-05-10 11:40:00 -060011#include <bootstage.h>
Simon Glass466c7852019-12-06 21:42:18 -070012#include <asm/mrccache.h>
13#include <asm/fsp/fsp_infoheader.h>
14#include <asm/fsp2/fsp_api.h>
15#include <asm/fsp2/fsp_internal.h>
16#include <asm/arch/fsp/fsp_configs.h>
17#include <asm/arch/fsp/fsp_m_upd.h>
18
19static int prepare_mrc_cache_type(enum mrc_type_t type,
20 struct mrc_data_container **cachep)
21{
22 struct mrc_data_container *cache;
23 struct mrc_region entry;
24 int ret;
25
26 ret = mrccache_get_region(type, NULL, &entry);
27 if (ret)
28 return ret;
29 cache = mrccache_find_current(&entry);
30 if (!cache)
31 return -ENOENT;
32
33 log_debug("MRC at %x, size %x\n", (uint)cache->data, cache->data_size);
34 *cachep = cache;
35
36 return 0;
37}
38
39int prepare_mrc_cache(struct fspm_upd *upd)
40{
41 struct mrc_data_container *cache;
42 int ret;
43
44 ret = prepare_mrc_cache_type(MRC_TYPE_NORMAL, &cache);
45 if (ret)
46 return log_msg_ret("Cannot get normal cache", ret);
47 upd->arch.nvs_buffer_ptr = cache->data;
48
49 ret = prepare_mrc_cache_type(MRC_TYPE_VAR, &cache);
50 if (ret)
51 return log_msg_ret("Cannot get var cache", ret);
52 upd->config.variable_nvs_buffer_ptr = cache->data;
53
54 return 0;
55}
56
57int fsp_memory_init(bool s3wake, bool use_spi_flash)
58{
59 struct fspm_upd upd, *fsp_upd;
60 fsp_memory_init_func func;
61 struct binman_entry entry;
62 struct fsp_header *hdr;
63 struct hob_header *hob;
64 struct udevice *dev;
65 int ret;
66
67 ret = fsp_locate_fsp(FSP_M, &entry, use_spi_flash, &dev, &hdr, NULL);
68 if (ret)
69 return log_msg_ret("locate FSP", ret);
70 debug("Found FSP_M at %x, size %x\n", hdr->img_base, hdr->img_size);
71
72 /* Copy over the default config */
73 fsp_upd = (struct fspm_upd *)(hdr->img_base + hdr->cfg_region_off);
74 if (fsp_upd->header.signature != FSPM_UPD_SIGNATURE)
75 return log_msg_ret("Bad UPD signature", -EPERM);
76 memcpy(&upd, fsp_upd, sizeof(upd));
77
78 ret = fspm_update_config(dev, &upd);
79 if (ret)
80 return log_msg_ret("Could not setup config", ret);
81
82 debug("SDRAM init...");
Simon Glassea6a6092020-05-10 11:39:59 -060083 bootstage_start(BOOTSTAGE_ID_ACCUM_FSP_M, "fsp-m");
Simon Glass466c7852019-12-06 21:42:18 -070084 func = (fsp_memory_init_func)(hdr->img_base + hdr->fsp_mem_init);
85 ret = func(&upd, &hob);
Simon Glassea6a6092020-05-10 11:39:59 -060086 bootstage_accum(BOOTSTAGE_ID_ACCUM_FSP_M);
Simon Glass466c7852019-12-06 21:42:18 -070087 if (ret)
88 return log_msg_ret("SDRAM init fail\n", ret);
89
90 gd->arch.hob_list = hob;
91 debug("done\n");
92
93 ret = fspm_done(dev);
94 if (ret)
95 return log_msg_ret("fsm_done\n", ret);
96
97 return 0;
98}