Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 1 | // 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 Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 8 | #include <handoff.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 11 | #include <spl.h> |
Simon Glass | 5046109 | 2020-04-08 16:57:35 -0600 | [diff] [blame] | 12 | #include <acpi/acpi_s3.h> |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 13 | #include <asm/arch/cpu.h> |
| 14 | #include <asm/fsp/fsp_support.h> |
| 15 | #include <asm/fsp2/fsp_api.h> |
| 16 | #include <asm/fsp2/fsp_internal.h> |
Simon Glass | d89c4a3 | 2020-04-26 09:12:53 -0600 | [diff] [blame] | 17 | #include <linux/sizes.h> |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 18 | |
| 19 | int dram_init(void) |
| 20 | { |
| 21 | int ret; |
| 22 | |
Simon Glass | d89c4a3 | 2020-04-26 09:12:53 -0600 | [diff] [blame] | 23 | if (!ll_boot_init()) { |
| 24 | /* Use a small and safe amount of 1GB */ |
| 25 | gd->ram_size = SZ_1G; |
| 26 | |
| 27 | return 0; |
| 28 | } |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 29 | if (spl_phase() == PHASE_SPL) { |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 30 | bool s3wake = false; |
Simon Glass | e6ad202 | 2020-07-09 18:43:16 -0600 | [diff] [blame] | 31 | |
| 32 | s3wake = IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) && |
| 33 | gd->arch.prev_sleep_state == ACPI_S3; |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 34 | |
| 35 | ret = fsp_memory_init(s3wake, |
| 36 | IS_ENABLED(CONFIG_APL_BOOT_FROM_FAST_SPI_FLASH)); |
| 37 | if (ret) { |
| 38 | debug("Memory init failed (err=%x)\n", ret); |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | /* The FSP has already set up DRAM, so grab the info we need */ |
| 43 | ret = fsp_scan_for_ram_size(); |
| 44 | if (ret) |
| 45 | return ret; |
| 46 | |
| 47 | #ifdef CONFIG_ENABLE_MRC_CACHE |
| 48 | gd->arch.mrc[MRC_TYPE_NORMAL].buf = |
| 49 | fsp_get_nvs_data(gd->arch.hob_list, |
| 50 | &gd->arch.mrc[MRC_TYPE_NORMAL].len); |
| 51 | gd->arch.mrc[MRC_TYPE_VAR].buf = |
| 52 | fsp_get_var_nvs_data(gd->arch.hob_list, |
| 53 | &gd->arch.mrc[MRC_TYPE_VAR].len); |
| 54 | log_debug("normal %x, var %x\n", |
| 55 | gd->arch.mrc[MRC_TYPE_NORMAL].len, |
| 56 | gd->arch.mrc[MRC_TYPE_VAR].len); |
| 57 | #endif |
| 58 | } else { |
| 59 | #if CONFIG_IS_ENABLED(HANDOFF) |
| 60 | struct spl_handoff *ho = gd->spl_handoff; |
| 61 | |
| 62 | if (!ho) { |
| 63 | debug("No SPL handoff found\n"); |
| 64 | return -ESTRPIPE; |
| 65 | } |
| 66 | gd->ram_size = ho->ram_size; |
| 67 | handoff_load_dram_banks(ho); |
| 68 | #endif |
| 69 | ret = arch_fsps_preinit(); |
| 70 | if (ret) |
| 71 | return log_msg_ret("fsp_s_preinit", ret); |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | ulong board_get_usable_ram_top(ulong total_size) |
| 78 | { |
Simon Glass | d89c4a3 | 2020-04-26 09:12:53 -0600 | [diff] [blame] | 79 | if (!ll_boot_init()) |
| 80 | return gd->ram_size; |
| 81 | |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 82 | #if CONFIG_IS_ENABLED(HANDOFF) |
| 83 | struct spl_handoff *ho = gd->spl_handoff; |
| 84 | |
| 85 | return ho->arch.usable_ram_top; |
| 86 | #endif |
| 87 | |
| 88 | return gd->ram_top; |
| 89 | } |