2019-12-07 04:42:18 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright 2019 Google LLC
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
2020-11-04 16:57:38 +00:00
|
|
|
#define LOG_CATEGORY LOGC_ARCH
|
|
|
|
|
2019-12-07 04:42:18 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <handoff.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2019-12-07 04:42:18 +00:00
|
|
|
#include <spl.h>
|
2020-04-08 22:57:35 +00:00
|
|
|
#include <acpi/acpi_s3.h>
|
2019-12-07 04:42:18 +00:00
|
|
|
#include <asm/arch/cpu.h>
|
|
|
|
#include <asm/fsp/fsp_support.h>
|
|
|
|
#include <asm/fsp2/fsp_api.h>
|
|
|
|
#include <asm/fsp2/fsp_internal.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-04-26 15:12:53 +00:00
|
|
|
#include <linux/sizes.h>
|
2019-12-07 04:42:18 +00:00
|
|
|
|
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2020-04-26 15:12:53 +00:00
|
|
|
if (!ll_boot_init()) {
|
|
|
|
/* Use a small and safe amount of 1GB */
|
|
|
|
gd->ram_size = SZ_1G;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-07 04:42:18 +00:00
|
|
|
if (spl_phase() == PHASE_SPL) {
|
|
|
|
bool s3wake = false;
|
2020-07-10 00:43:16 +00:00
|
|
|
|
|
|
|
s3wake = IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) &&
|
|
|
|
gd->arch.prev_sleep_state == ACPI_S3;
|
2019-12-07 04:42:18 +00:00
|
|
|
|
|
|
|
ret = fsp_memory_init(s3wake,
|
|
|
|
IS_ENABLED(CONFIG_APL_BOOT_FROM_FAST_SPI_FLASH));
|
|
|
|
if (ret) {
|
2020-11-04 16:57:38 +00:00
|
|
|
log_debug("Memory init failed (err=%x)\n", ret);
|
2019-12-07 04:42:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The FSP has already set up DRAM, so grab the info we need */
|
|
|
|
ret = fsp_scan_for_ram_size();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
#ifdef CONFIG_ENABLE_MRC_CACHE
|
|
|
|
gd->arch.mrc[MRC_TYPE_NORMAL].buf =
|
|
|
|
fsp_get_nvs_data(gd->arch.hob_list,
|
|
|
|
&gd->arch.mrc[MRC_TYPE_NORMAL].len);
|
|
|
|
gd->arch.mrc[MRC_TYPE_VAR].buf =
|
|
|
|
fsp_get_var_nvs_data(gd->arch.hob_list,
|
|
|
|
&gd->arch.mrc[MRC_TYPE_VAR].len);
|
|
|
|
log_debug("normal %x, var %x\n",
|
|
|
|
gd->arch.mrc[MRC_TYPE_NORMAL].len,
|
|
|
|
gd->arch.mrc[MRC_TYPE_VAR].len);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
#if CONFIG_IS_ENABLED(HANDOFF)
|
|
|
|
struct spl_handoff *ho = gd->spl_handoff;
|
|
|
|
|
|
|
|
if (!ho) {
|
2020-11-04 16:57:38 +00:00
|
|
|
log_debug("No SPL handoff found\n");
|
2019-12-07 04:42:18 +00:00
|
|
|
return -ESTRPIPE;
|
|
|
|
}
|
|
|
|
gd->ram_size = ho->ram_size;
|
|
|
|
handoff_load_dram_banks(ho);
|
|
|
|
#endif
|
|
|
|
ret = arch_fsps_preinit();
|
|
|
|
if (ret)
|
|
|
|
return log_msg_ret("fsp_s_preinit", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-08-12 18:16:58 +00:00
|
|
|
phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
|
2019-12-07 04:42:18 +00:00
|
|
|
{
|
2020-04-26 15:12:53 +00:00
|
|
|
if (!ll_boot_init())
|
|
|
|
return gd->ram_size;
|
|
|
|
|
2019-12-07 04:42:18 +00:00
|
|
|
#if CONFIG_IS_ENABLED(HANDOFF)
|
|
|
|
struct spl_handoff *ho = gd->spl_handoff;
|
|
|
|
|
2020-11-04 16:57:38 +00:00
|
|
|
log_debug("usable_ram_top = %lx\n", ho->arch.usable_ram_top);
|
|
|
|
|
2019-12-07 04:42:18 +00:00
|
|
|
return ho->arch.usable_ram_top;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return gd->ram_top;
|
|
|
|
}
|