blob: 20926171822dd3518666a91920e2c80aa1472ba9 [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>
Bin Mengcf200302017-04-21 07:24:39 -07007#include <dm.h>
Simon Glass509805b2015-01-27 22:13:39 -07008#include <errno.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070011#include <malloc.h>
Bin Mengcf200302017-04-21 07:24:39 -070012#include <rtc.h>
Simon Glass50461092020-04-08 16:57:35 -060013#include <acpi/acpi_s3.h>
Bin Mengcf200302017-04-21 07:24:39 -070014#include <asm/cmos_layout.h>
15#include <asm/early_cmos.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Simon Glass509805b2015-01-27 22:13:39 -070017#include <asm/io.h>
Bin Meng07793c082015-10-11 21:37:42 -070018#include <asm/mrccache.h>
Simon Glass509805b2015-01-27 22:13:39 -070019#include <asm/post.h>
20#include <asm/processor.h>
Simon Glass6c34fc12019-09-25 08:00:11 -060021#include <asm/fsp1/fsp_support.h>
Simon Glass509805b2015-01-27 22:13:39 -070022
Simon Glassdaa93d92015-07-31 09:31:31 -060023DECLARE_GLOBAL_DATA_PTR;
24
Simon Glass9de10272019-12-06 21:42:10 -070025static void *fsp_prepare_mrc_cache(void)
26{
27 struct mrc_data_container *cache;
28 struct mrc_region entry;
29 int ret;
30
31 ret = mrccache_get_region(MRC_TYPE_NORMAL, NULL, &entry);
32 if (ret)
33 return NULL;
34
35 cache = mrccache_find_current(&entry);
36 if (!cache)
37 return NULL;
38
39 debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
40 cache->data, cache->data_size, cache->checksum);
41
42 return cache->data;
43}
44
Simon Glass295c4232017-03-28 10:27:18 -060045int arch_fsp_init(void)
Bin Mengd560c5c2015-06-07 11:33:14 +080046{
Bin Meng07793c082015-10-11 21:37:42 -070047 void *nvs;
Bin Mengcf200302017-04-21 07:24:39 -070048 int stack = CONFIG_FSP_TEMP_RAM_ADDR;
Bin Mengacb4bf92017-04-21 07:24:31 -070049 int boot_mode = BOOT_FULL_CONFIG;
Simon Glasse6ad2022020-07-09 18:43:16 -060050 int prev_sleep_state;
51
52 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
53 prev_sleep_state = chipset_prev_sleep_state();
54 gd->arch.prev_sleep_state = prev_sleep_state;
55 }
Bin Meng07793c082015-10-11 21:37:42 -070056
Bin Meng12440cd2015-08-20 06:40:19 -070057 if (!gd->arch.hob_list) {
Simon Glassf755a452019-09-25 08:11:27 -060058 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE))
59 nvs = fsp_prepare_mrc_cache();
60 else
61 nvs = NULL;
Bin Mengacb4bf92017-04-21 07:24:31 -070062
Simon Glasse6ad2022020-07-09 18:43:16 -060063 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) &&
64 prev_sleep_state == ACPI_S3) {
Bin Mengacb4bf92017-04-21 07:24:31 -070065 if (nvs == NULL) {
66 /* If waking from S3 and no cache then */
67 debug("No MRC cache found in S3 resume path\n");
68 post_code(POST_RESUME_FAILURE);
69 /* Clear Sleep Type */
70 chipset_clear_sleep_state();
71 /* Reboot */
72 debug("Rebooting..\n");
Bin Meng6e577142018-07-19 03:07:32 -070073 outb(SYS_RST | RST_CPU, IO_PORT_RESET);
Bin Mengacb4bf92017-04-21 07:24:31 -070074 /* Should not reach here.. */
75 panic("Reboot System");
76 }
77
Bin Mengcf200302017-04-21 07:24:39 -070078 /*
Vagrant Cascadian973c0992019-05-03 14:28:37 -080079 * DM is not available yet at this point, hence call
Bin Mengcf200302017-04-21 07:24:39 -070080 * CMOS access library which does not depend on DM.
81 */
82 stack = cmos_read32(CMOS_FSP_STACK_ADDR);
Bin Mengacb4bf92017-04-21 07:24:31 -070083 boot_mode = BOOT_ON_S3_RESUME;
84 }
Simon Glasse6ad2022020-07-09 18:43:16 -060085
Bin Meng12440cd2015-08-20 06:40:19 -070086 /*
87 * The first time we enter here, call fsp_init().
88 * Note the execution does not return to this function,
89 * instead it jumps to fsp_continue().
90 */
Bin Mengcf200302017-04-21 07:24:39 -070091 fsp_init(stack, boot_mode, nvs);
Bin Meng12440cd2015-08-20 06:40:19 -070092 } else {
93 /*
94 * The second time we enter here, adjust the size of malloc()
95 * pool before relocation. Given gd->malloc_base was adjusted
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +010096 * after the call to board_init_f_init_reserve() in arch/x86/
97 * cpu/start.S, we should fix up gd->malloc_limit here.
Bin Meng12440cd2015-08-20 06:40:19 -070098 */
99 gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
100 }
Bin Mengd560c5c2015-06-07 11:33:14 +0800101
102 return 0;
103}