blob: 43d32b7abefc3e261fe2c6781769ca4063327f2a [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;
49#ifdef CONFIG_HAVE_ACPI_RESUME
50 int prev_sleep_state = chipset_prev_sleep_state();
Bin Mengef61f772017-04-21 07:24:32 -070051 gd->arch.prev_sleep_state = prev_sleep_state;
Bin Mengacb4bf92017-04-21 07:24:31 -070052#endif
Bin Meng07793c082015-10-11 21:37:42 -070053
Bin Meng12440cd2015-08-20 06:40:19 -070054 if (!gd->arch.hob_list) {
Simon Glassf755a452019-09-25 08:11:27 -060055 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE))
56 nvs = fsp_prepare_mrc_cache();
57 else
58 nvs = NULL;
Bin Mengacb4bf92017-04-21 07:24:31 -070059
60#ifdef CONFIG_HAVE_ACPI_RESUME
61 if (prev_sleep_state == ACPI_S3) {
62 if (nvs == NULL) {
63 /* If waking from S3 and no cache then */
64 debug("No MRC cache found in S3 resume path\n");
65 post_code(POST_RESUME_FAILURE);
66 /* Clear Sleep Type */
67 chipset_clear_sleep_state();
68 /* Reboot */
69 debug("Rebooting..\n");
Bin Meng6e577142018-07-19 03:07:32 -070070 outb(SYS_RST | RST_CPU, IO_PORT_RESET);
Bin Mengacb4bf92017-04-21 07:24:31 -070071 /* Should not reach here.. */
72 panic("Reboot System");
73 }
74
Bin Mengcf200302017-04-21 07:24:39 -070075 /*
Vagrant Cascadian973c0992019-05-03 14:28:37 -080076 * DM is not available yet at this point, hence call
Bin Mengcf200302017-04-21 07:24:39 -070077 * CMOS access library which does not depend on DM.
78 */
79 stack = cmos_read32(CMOS_FSP_STACK_ADDR);
Bin Mengacb4bf92017-04-21 07:24:31 -070080 boot_mode = BOOT_ON_S3_RESUME;
81 }
82#endif
Bin Meng12440cd2015-08-20 06:40:19 -070083 /*
84 * The first time we enter here, call fsp_init().
85 * Note the execution does not return to this function,
86 * instead it jumps to fsp_continue().
87 */
Bin Mengcf200302017-04-21 07:24:39 -070088 fsp_init(stack, boot_mode, nvs);
Bin Meng12440cd2015-08-20 06:40:19 -070089 } else {
90 /*
91 * The second time we enter here, adjust the size of malloc()
92 * pool before relocation. Given gd->malloc_base was adjusted
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +010093 * after the call to board_init_f_init_reserve() in arch/x86/
94 * cpu/start.S, we should fix up gd->malloc_limit here.
Bin Meng12440cd2015-08-20 06:40:19 -070095 */
96 gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
97 }
Bin Mengd560c5c2015-06-07 11:33:14 +080098
99 return 0;
100}