blob: cc42cad20bd6dbbc0dc20e8c1e7d4f00fedb89cc [file] [log] [blame]
Simon Glass509805b2015-01-27 22:13:39 -07001/*
2 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <errno.h>
Bin Mengacb4bf92017-04-21 07:24:31 -07009#include <asm/acpi_s3.h>
Simon Glass509805b2015-01-27 22:13:39 -070010#include <asm/io.h>
Bin Meng07793c082015-10-11 21:37:42 -070011#include <asm/mrccache.h>
Simon Glass509805b2015-01-27 22:13:39 -070012#include <asm/post.h>
13#include <asm/processor.h>
14#include <asm/fsp/fsp_support.h>
15
Simon Glassdaa93d92015-07-31 09:31:31 -060016DECLARE_GLOBAL_DATA_PTR;
17
Simon Glassee7c36f2017-03-28 10:27:30 -060018int checkcpu(void)
19{
20 return 0;
21}
22
Simon Glass509805b2015-01-27 22:13:39 -070023int print_cpuinfo(void)
24{
25 post_code(POST_CPU_INFO);
26 return default_print_cpuinfo();
27}
28
Simon Glassfa912732015-08-10 07:05:07 -060029int fsp_init_phase_pci(void)
Simon Glass509805b2015-01-27 22:13:39 -070030{
31 u32 status;
32
33 /* call into FspNotify */
34 debug("Calling into FSP (notify phase INIT_PHASE_PCI): ");
35 status = fsp_notify(NULL, INIT_PHASE_PCI);
Simon Glassfa912732015-08-10 07:05:07 -060036 if (status)
Simon Glass509805b2015-01-27 22:13:39 -070037 debug("fail, error code %x\n", status);
38 else
39 debug("OK\n");
40
Simon Glassfa912732015-08-10 07:05:07 -060041 return status ? -EPERM : 0;
42}
43
Simon Glass509805b2015-01-27 22:13:39 -070044void board_final_cleanup(void)
45{
46 u32 status;
47
48 /* call into FspNotify */
49 debug("Calling into FSP (notify phase INIT_PHASE_BOOT): ");
50 status = fsp_notify(NULL, INIT_PHASE_BOOT);
Simon Glass38252292015-08-12 19:33:07 -060051 if (status)
Simon Glass509805b2015-01-27 22:13:39 -070052 debug("fail, error code %x\n", status);
53 else
54 debug("OK\n");
55
56 return;
57}
Bin Mengd560c5c2015-06-07 11:33:14 +080058
Bin Meng07793c082015-10-11 21:37:42 -070059static __maybe_unused void *fsp_prepare_mrc_cache(void)
60{
61 struct mrc_data_container *cache;
62 struct mrc_region entry;
63 int ret;
64
65 ret = mrccache_get_region(NULL, &entry);
66 if (ret)
67 return NULL;
68
69 cache = mrccache_find_current(&entry);
70 if (!cache)
71 return NULL;
72
73 debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
74 cache->data, cache->data_size, cache->checksum);
75
76 return cache->data;
77}
78
Simon Glass295c4232017-03-28 10:27:18 -060079int arch_fsp_init(void)
Bin Mengd560c5c2015-06-07 11:33:14 +080080{
Bin Meng07793c082015-10-11 21:37:42 -070081 void *nvs;
Bin Mengacb4bf92017-04-21 07:24:31 -070082 int boot_mode = BOOT_FULL_CONFIG;
83#ifdef CONFIG_HAVE_ACPI_RESUME
84 int prev_sleep_state = chipset_prev_sleep_state();
85#endif
Bin Meng07793c082015-10-11 21:37:42 -070086
Bin Meng12440cd2015-08-20 06:40:19 -070087 if (!gd->arch.hob_list) {
Bin Meng07793c082015-10-11 21:37:42 -070088#ifdef CONFIG_ENABLE_MRC_CACHE
89 nvs = fsp_prepare_mrc_cache();
90#else
91 nvs = NULL;
92#endif
Bin Mengacb4bf92017-04-21 07:24:31 -070093
94#ifdef CONFIG_HAVE_ACPI_RESUME
95 if (prev_sleep_state == ACPI_S3) {
96 if (nvs == NULL) {
97 /* If waking from S3 and no cache then */
98 debug("No MRC cache found in S3 resume path\n");
99 post_code(POST_RESUME_FAILURE);
100 /* Clear Sleep Type */
101 chipset_clear_sleep_state();
102 /* Reboot */
103 debug("Rebooting..\n");
104 reset_cpu(0);
105 /* Should not reach here.. */
106 panic("Reboot System");
107 }
108
109 boot_mode = BOOT_ON_S3_RESUME;
110 }
111#endif
Bin Meng12440cd2015-08-20 06:40:19 -0700112 /*
113 * The first time we enter here, call fsp_init().
114 * Note the execution does not return to this function,
115 * instead it jumps to fsp_continue().
116 */
Bin Mengacb4bf92017-04-21 07:24:31 -0700117 fsp_init(CONFIG_FSP_TEMP_RAM_ADDR, boot_mode, nvs);
Bin Meng12440cd2015-08-20 06:40:19 -0700118 } else {
119 /*
120 * The second time we enter here, adjust the size of malloc()
121 * pool before relocation. Given gd->malloc_base was adjusted
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +0100122 * after the call to board_init_f_init_reserve() in arch/x86/
123 * cpu/start.S, we should fix up gd->malloc_limit here.
Bin Meng12440cd2015-08-20 06:40:19 -0700124 */
125 gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
126 }
Bin Mengd560c5c2015-06-07 11:33:14 +0800127
128 return 0;
129}