blob: ec9c218778d2eae7d93f23fb15720b4421a46142 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass509805b2015-01-27 22:13:39 -07002/*
3 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
Simon Glass509805b2015-01-27 22:13:39 -07004 */
5
6#include <common.h>
Simon Glass5c2aabf2019-09-25 08:56:32 -06007#include <acpi_s3.h>
Bin Mengcf200302017-04-21 07:24:39 -07008#include <dm.h>
Simon Glass509805b2015-01-27 22:13:39 -07009#include <errno.h>
Bin Mengcf200302017-04-21 07:24:39 -070010#include <rtc.h>
Bin Mengcf200302017-04-21 07:24:39 -070011#include <asm/cmos_layout.h>
12#include <asm/early_cmos.h>
Simon Glass509805b2015-01-27 22:13:39 -070013#include <asm/io.h>
Bin Meng07793c082015-10-11 21:37:42 -070014#include <asm/mrccache.h>
Simon Glass509805b2015-01-27 22:13:39 -070015#include <asm/post.h>
16#include <asm/processor.h>
Simon Glass6c34fc12019-09-25 08:00:11 -060017#include <asm/fsp1/fsp_support.h>
Simon Glass509805b2015-01-27 22:13:39 -070018
Simon Glassdaa93d92015-07-31 09:31:31 -060019DECLARE_GLOBAL_DATA_PTR;
20
Simon Glass9de10272019-12-06 21:42:10 -070021static void *fsp_prepare_mrc_cache(void)
22{
23 struct mrc_data_container *cache;
24 struct mrc_region entry;
25 int ret;
26
27 ret = mrccache_get_region(MRC_TYPE_NORMAL, NULL, &entry);
28 if (ret)
29 return NULL;
30
31 cache = mrccache_find_current(&entry);
32 if (!cache)
33 return NULL;
34
35 debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
36 cache->data, cache->data_size, cache->checksum);
37
38 return cache->data;
39}
40
Simon Glass295c4232017-03-28 10:27:18 -060041int arch_fsp_init(void)
Bin Mengd560c5c2015-06-07 11:33:14 +080042{
Bin Meng07793c082015-10-11 21:37:42 -070043 void *nvs;
Bin Mengcf200302017-04-21 07:24:39 -070044 int stack = CONFIG_FSP_TEMP_RAM_ADDR;
Bin Mengacb4bf92017-04-21 07:24:31 -070045 int boot_mode = BOOT_FULL_CONFIG;
46#ifdef CONFIG_HAVE_ACPI_RESUME
47 int prev_sleep_state = chipset_prev_sleep_state();
Bin Mengef61f772017-04-21 07:24:32 -070048 gd->arch.prev_sleep_state = prev_sleep_state;
Bin Mengacb4bf92017-04-21 07:24:31 -070049#endif
Bin Meng07793c082015-10-11 21:37:42 -070050
Bin Meng12440cd2015-08-20 06:40:19 -070051 if (!gd->arch.hob_list) {
Simon Glassf755a452019-09-25 08:11:27 -060052 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE))
53 nvs = fsp_prepare_mrc_cache();
54 else
55 nvs = NULL;
Bin Mengacb4bf92017-04-21 07:24:31 -070056
57#ifdef CONFIG_HAVE_ACPI_RESUME
58 if (prev_sleep_state == ACPI_S3) {
59 if (nvs == NULL) {
60 /* If waking from S3 and no cache then */
61 debug("No MRC cache found in S3 resume path\n");
62 post_code(POST_RESUME_FAILURE);
63 /* Clear Sleep Type */
64 chipset_clear_sleep_state();
65 /* Reboot */
66 debug("Rebooting..\n");
Bin Meng6e577142018-07-19 03:07:32 -070067 outb(SYS_RST | RST_CPU, IO_PORT_RESET);
Bin Mengacb4bf92017-04-21 07:24:31 -070068 /* Should not reach here.. */
69 panic("Reboot System");
70 }
71
Bin Mengcf200302017-04-21 07:24:39 -070072 /*
Vagrant Cascadian973c0992019-05-03 14:28:37 -080073 * DM is not available yet at this point, hence call
Bin Mengcf200302017-04-21 07:24:39 -070074 * CMOS access library which does not depend on DM.
75 */
76 stack = cmos_read32(CMOS_FSP_STACK_ADDR);
Bin Mengacb4bf92017-04-21 07:24:31 -070077 boot_mode = BOOT_ON_S3_RESUME;
78 }
79#endif
Bin Meng12440cd2015-08-20 06:40:19 -070080 /*
81 * The first time we enter here, call fsp_init().
82 * Note the execution does not return to this function,
83 * instead it jumps to fsp_continue().
84 */
Bin Mengcf200302017-04-21 07:24:39 -070085 fsp_init(stack, boot_mode, nvs);
Bin Meng12440cd2015-08-20 06:40:19 -070086 } else {
87 /*
88 * The second time we enter here, adjust the size of malloc()
89 * pool before relocation. Given gd->malloc_base was adjusted
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +010090 * after the call to board_init_f_init_reserve() in arch/x86/
91 * cpu/start.S, we should fix up gd->malloc_limit here.
Bin Meng12440cd2015-08-20 06:40:19 -070092 */
93 gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
94 }
Bin Mengd560c5c2015-06-07 11:33:14 +080095
96 return 0;
97}