blob: da351cf097c074e94769db11f2a4d071e168e429 [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 Glass509805b2015-01-27 22:13:39 -070016#include <asm/io.h>
Bin Meng07793c082015-10-11 21:37:42 -070017#include <asm/mrccache.h>
Simon Glass509805b2015-01-27 22:13:39 -070018#include <asm/post.h>
19#include <asm/processor.h>
Simon Glass6c34fc12019-09-25 08:00:11 -060020#include <asm/fsp1/fsp_support.h>
Simon Glass509805b2015-01-27 22:13:39 -070021
Simon Glassdaa93d92015-07-31 09:31:31 -060022DECLARE_GLOBAL_DATA_PTR;
23
Simon Glass9de10272019-12-06 21:42:10 -070024static void *fsp_prepare_mrc_cache(void)
25{
26 struct mrc_data_container *cache;
27 struct mrc_region entry;
28 int ret;
29
30 ret = mrccache_get_region(MRC_TYPE_NORMAL, NULL, &entry);
31 if (ret)
32 return NULL;
33
34 cache = mrccache_find_current(&entry);
35 if (!cache)
36 return NULL;
37
38 debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
39 cache->data, cache->data_size, cache->checksum);
40
41 return cache->data;
42}
43
Simon Glass295c4232017-03-28 10:27:18 -060044int arch_fsp_init(void)
Bin Mengd560c5c2015-06-07 11:33:14 +080045{
Bin Meng07793c082015-10-11 21:37:42 -070046 void *nvs;
Bin Mengcf200302017-04-21 07:24:39 -070047 int stack = CONFIG_FSP_TEMP_RAM_ADDR;
Bin Mengacb4bf92017-04-21 07:24:31 -070048 int boot_mode = BOOT_FULL_CONFIG;
Simon Glasse6ad2022020-07-09 18:43:16 -060049 int prev_sleep_state;
50
51 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
52 prev_sleep_state = chipset_prev_sleep_state();
53 gd->arch.prev_sleep_state = prev_sleep_state;
54 }
Bin Meng07793c082015-10-11 21:37:42 -070055
Bin Meng12440cd2015-08-20 06:40:19 -070056 if (!gd->arch.hob_list) {
Simon Glassf755a452019-09-25 08:11:27 -060057 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE))
58 nvs = fsp_prepare_mrc_cache();
59 else
60 nvs = NULL;
Bin Mengacb4bf92017-04-21 07:24:31 -070061
Simon Glasse6ad2022020-07-09 18:43:16 -060062 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) &&
63 prev_sleep_state == ACPI_S3) {
Bin Mengacb4bf92017-04-21 07:24:31 -070064 if (nvs == NULL) {
65 /* If waking from S3 and no cache then */
66 debug("No MRC cache found in S3 resume path\n");
67 post_code(POST_RESUME_FAILURE);
68 /* Clear Sleep Type */
69 chipset_clear_sleep_state();
70 /* Reboot */
71 debug("Rebooting..\n");
Bin Meng6e577142018-07-19 03:07:32 -070072 outb(SYS_RST | RST_CPU, IO_PORT_RESET);
Bin Mengacb4bf92017-04-21 07:24:31 -070073 /* Should not reach here.. */
74 panic("Reboot System");
75 }
76
Bin Mengcf200302017-04-21 07:24:39 -070077 /*
Vagrant Cascadian973c0992019-05-03 14:28:37 -080078 * DM is not available yet at this point, hence call
Bin Mengcf200302017-04-21 07:24:39 -070079 * CMOS access library which does not depend on DM.
80 */
81 stack = cmos_read32(CMOS_FSP_STACK_ADDR);
Bin Mengacb4bf92017-04-21 07:24:31 -070082 boot_mode = BOOT_ON_S3_RESUME;
83 }
Simon Glasse6ad2022020-07-09 18:43:16 -060084
Bin Meng12440cd2015-08-20 06:40:19 -070085 /*
86 * The first time we enter here, call fsp_init().
87 * Note the execution does not return to this function,
88 * instead it jumps to fsp_continue().
89 */
Bin Mengcf200302017-04-21 07:24:39 -070090 fsp_init(stack, boot_mode, nvs);
Bin Meng12440cd2015-08-20 06:40:19 -070091 } else {
92 /*
93 * The second time we enter here, adjust the size of malloc()
94 * pool before relocation. Given gd->malloc_base was adjusted
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +010095 * after the call to board_init_f_init_reserve() in arch/x86/
96 * cpu/start.S, we should fix up gd->malloc_limit here.
Bin Meng12440cd2015-08-20 06:40:19 -070097 */
98 gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
99 }
Bin Mengd560c5c2015-06-07 11:33:14 +0800100
101 return 0;
102}