blob: c8f2c09b6a77142e795145ee8702db1de91a2169 [file] [log] [blame]
Simon Glass466c7852019-12-06 21:42:18 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
7#include <common.h>
Simon Glass466c7852019-12-06 21:42:18 -07008#include <handoff.h>
9#include <spl.h>
Simon Glass50461092020-04-08 16:57:35 -060010#include <acpi/acpi_s3.h>
Simon Glass466c7852019-12-06 21:42:18 -070011#include <asm/arch/cpu.h>
12#include <asm/fsp/fsp_support.h>
13#include <asm/fsp2/fsp_api.h>
14#include <asm/fsp2/fsp_internal.h>
15
16int dram_init(void)
17{
18 int ret;
19
20 if (spl_phase() == PHASE_SPL) {
21#ifdef CONFIG_HAVE_ACPI_RESUME
22 bool s3wake = gd->arch.prev_sleep_state == ACPI_S3;
23#else
24 bool s3wake = false;
25#endif
26
27 ret = fsp_memory_init(s3wake,
28 IS_ENABLED(CONFIG_APL_BOOT_FROM_FAST_SPI_FLASH));
29 if (ret) {
30 debug("Memory init failed (err=%x)\n", ret);
31 return ret;
32 }
33
34 /* The FSP has already set up DRAM, so grab the info we need */
35 ret = fsp_scan_for_ram_size();
36 if (ret)
37 return ret;
38
39#ifdef CONFIG_ENABLE_MRC_CACHE
40 gd->arch.mrc[MRC_TYPE_NORMAL].buf =
41 fsp_get_nvs_data(gd->arch.hob_list,
42 &gd->arch.mrc[MRC_TYPE_NORMAL].len);
43 gd->arch.mrc[MRC_TYPE_VAR].buf =
44 fsp_get_var_nvs_data(gd->arch.hob_list,
45 &gd->arch.mrc[MRC_TYPE_VAR].len);
46 log_debug("normal %x, var %x\n",
47 gd->arch.mrc[MRC_TYPE_NORMAL].len,
48 gd->arch.mrc[MRC_TYPE_VAR].len);
49#endif
50 } else {
51#if CONFIG_IS_ENABLED(HANDOFF)
52 struct spl_handoff *ho = gd->spl_handoff;
53
54 if (!ho) {
55 debug("No SPL handoff found\n");
56 return -ESTRPIPE;
57 }
58 gd->ram_size = ho->ram_size;
59 handoff_load_dram_banks(ho);
60#endif
61 ret = arch_fsps_preinit();
62 if (ret)
63 return log_msg_ret("fsp_s_preinit", ret);
64 }
65
66 return 0;
67}
68
69ulong board_get_usable_ram_top(ulong total_size)
70{
71#if CONFIG_IS_ENABLED(HANDOFF)
72 struct spl_handoff *ho = gd->spl_handoff;
73
74 return ho->arch.usable_ram_top;
75#endif
76
77 return gd->ram_top;
78}