blob: aee2a05044f8ab0ccda947e27e2924e71b4b494a [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>
Simon Glass9bc15642020-02-03 07:36:16 -070010#include <malloc.h>
Bin Mengcf200302017-04-21 07:24:39 -070011#include <rtc.h>
Bin Mengcf200302017-04-21 07:24:39 -070012#include <asm/cmos_layout.h>
13#include <asm/early_cmos.h>
Simon Glass509805b2015-01-27 22:13:39 -070014#include <asm/io.h>
Bin Meng07793c082015-10-11 21:37:42 -070015#include <asm/mrccache.h>
Simon Glass509805b2015-01-27 22:13:39 -070016#include <asm/post.h>
17#include <asm/processor.h>
Simon Glass6c34fc12019-09-25 08:00:11 -060018#include <asm/fsp1/fsp_support.h>
Simon Glass509805b2015-01-27 22:13:39 -070019
Simon Glassdaa93d92015-07-31 09:31:31 -060020DECLARE_GLOBAL_DATA_PTR;
21
Simon Glass9de10272019-12-06 21:42:10 -070022static void *fsp_prepare_mrc_cache(void)
23{
24 struct mrc_data_container *cache;
25 struct mrc_region entry;
26 int ret;
27
28 ret = mrccache_get_region(MRC_TYPE_NORMAL, NULL, &entry);
29 if (ret)
30 return NULL;
31
32 cache = mrccache_find_current(&entry);
33 if (!cache)
34 return NULL;
35
36 debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
37 cache->data, cache->data_size, cache->checksum);
38
39 return cache->data;
40}
41
Simon Glass295c4232017-03-28 10:27:18 -060042int arch_fsp_init(void)
Bin Mengd560c5c2015-06-07 11:33:14 +080043{
Bin Meng07793c082015-10-11 21:37:42 -070044 void *nvs;
Bin Mengcf200302017-04-21 07:24:39 -070045 int stack = CONFIG_FSP_TEMP_RAM_ADDR;
Bin Mengacb4bf92017-04-21 07:24:31 -070046 int boot_mode = BOOT_FULL_CONFIG;
47#ifdef CONFIG_HAVE_ACPI_RESUME
48 int prev_sleep_state = chipset_prev_sleep_state();
Bin Mengef61f772017-04-21 07:24:32 -070049 gd->arch.prev_sleep_state = prev_sleep_state;
Bin Mengacb4bf92017-04-21 07:24:31 -070050#endif
Bin Meng07793c082015-10-11 21:37:42 -070051
Bin Meng12440cd2015-08-20 06:40:19 -070052 if (!gd->arch.hob_list) {
Simon Glassf755a452019-09-25 08:11:27 -060053 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE))
54 nvs = fsp_prepare_mrc_cache();
55 else
56 nvs = NULL;
Bin Mengacb4bf92017-04-21 07:24:31 -070057
58#ifdef CONFIG_HAVE_ACPI_RESUME
59 if (prev_sleep_state == ACPI_S3) {
60 if (nvs == NULL) {
61 /* If waking from S3 and no cache then */
62 debug("No MRC cache found in S3 resume path\n");
63 post_code(POST_RESUME_FAILURE);
64 /* Clear Sleep Type */
65 chipset_clear_sleep_state();
66 /* Reboot */
67 debug("Rebooting..\n");
Bin Meng6e577142018-07-19 03:07:32 -070068 outb(SYS_RST | RST_CPU, IO_PORT_RESET);
Bin Mengacb4bf92017-04-21 07:24:31 -070069 /* Should not reach here.. */
70 panic("Reboot System");
71 }
72
Bin Mengcf200302017-04-21 07:24:39 -070073 /*
Vagrant Cascadian973c0992019-05-03 14:28:37 -080074 * DM is not available yet at this point, hence call
Bin Mengcf200302017-04-21 07:24:39 -070075 * CMOS access library which does not depend on DM.
76 */
77 stack = cmos_read32(CMOS_FSP_STACK_ADDR);
Bin Mengacb4bf92017-04-21 07:24:31 -070078 boot_mode = BOOT_ON_S3_RESUME;
79 }
80#endif
Bin Meng12440cd2015-08-20 06:40:19 -070081 /*
82 * The first time we enter here, call fsp_init().
83 * Note the execution does not return to this function,
84 * instead it jumps to fsp_continue().
85 */
Bin Mengcf200302017-04-21 07:24:39 -070086 fsp_init(stack, boot_mode, nvs);
Bin Meng12440cd2015-08-20 06:40:19 -070087 } else {
88 /*
89 * The second time we enter here, adjust the size of malloc()
90 * pool before relocation. Given gd->malloc_base was adjusted
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +010091 * after the call to board_init_f_init_reserve() in arch/x86/
92 * cpu/start.S, we should fix up gd->malloc_limit here.
Bin Meng12440cd2015-08-20 06:40:19 -070093 */
94 gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
95 }
Bin Mengd560c5c2015-06-07 11:33:14 +080096
97 return 0;
98}