blob: d5ed1d5631287fde641bf46d429d2bcca9fd6720 [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>
Bin Mengcf200302017-04-21 07:24:39 -07009#include <rtc.h>
Bin Mengacb4bf92017-04-21 07:24:31 -070010#include <asm/acpi_s3.h>
Bin Mengcf200302017-04-21 07:24:39 -070011#include <asm/cmos_layout.h>
12#include <asm/early_cmos.h>
Simon Glass509805b2015-01-27 22:13:39 -070013#include <asm/io.h>
Bin Meng07793c082015-10-11 21:37:42 -070014#include <asm/mrccache.h>
Simon Glass509805b2015-01-27 22:13:39 -070015#include <asm/post.h>
16#include <asm/processor.h>
17#include <asm/fsp/fsp_support.h>
18
Simon Glassdaa93d92015-07-31 09:31:31 -060019DECLARE_GLOBAL_DATA_PTR;
20
Simon Glassee7c36f2017-03-28 10:27:30 -060021int checkcpu(void)
22{
23 return 0;
24}
25
Simon Glass509805b2015-01-27 22:13:39 -070026int print_cpuinfo(void)
27{
28 post_code(POST_CPU_INFO);
29 return default_print_cpuinfo();
30}
31
Simon Glassfa912732015-08-10 07:05:07 -060032int fsp_init_phase_pci(void)
Simon Glass509805b2015-01-27 22:13:39 -070033{
34 u32 status;
35
36 /* call into FspNotify */
37 debug("Calling into FSP (notify phase INIT_PHASE_PCI): ");
38 status = fsp_notify(NULL, INIT_PHASE_PCI);
Simon Glassfa912732015-08-10 07:05:07 -060039 if (status)
Simon Glass509805b2015-01-27 22:13:39 -070040 debug("fail, error code %x\n", status);
41 else
42 debug("OK\n");
43
Simon Glassfa912732015-08-10 07:05:07 -060044 return status ? -EPERM : 0;
45}
46
Simon Glass509805b2015-01-27 22:13:39 -070047void board_final_cleanup(void)
48{
49 u32 status;
50
51 /* call into FspNotify */
52 debug("Calling into FSP (notify phase INIT_PHASE_BOOT): ");
53 status = fsp_notify(NULL, INIT_PHASE_BOOT);
Simon Glass38252292015-08-12 19:33:07 -060054 if (status)
Simon Glass509805b2015-01-27 22:13:39 -070055 debug("fail, error code %x\n", status);
56 else
57 debug("OK\n");
58
59 return;
60}
Bin Mengd560c5c2015-06-07 11:33:14 +080061
Bin Meng07793c082015-10-11 21:37:42 -070062static __maybe_unused void *fsp_prepare_mrc_cache(void)
63{
64 struct mrc_data_container *cache;
65 struct mrc_region entry;
66 int ret;
67
68 ret = mrccache_get_region(NULL, &entry);
69 if (ret)
70 return NULL;
71
72 cache = mrccache_find_current(&entry);
73 if (!cache)
74 return NULL;
75
76 debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
77 cache->data, cache->data_size, cache->checksum);
78
79 return cache->data;
80}
81
Bin Mengcf200302017-04-21 07:24:39 -070082#ifdef CONFIG_HAVE_ACPI_RESUME
83int fsp_save_s3_stack(void)
84{
85 struct udevice *dev;
86 int ret;
87
88 if (gd->arch.prev_sleep_state == ACPI_S3)
89 return 0;
90
91 ret = uclass_get_device(UCLASS_RTC, 0, &dev);
92 if (ret) {
93 debug("Cannot find RTC: err=%d\n", ret);
94 return -ENODEV;
95 }
96
97 /* Save the stack address to CMOS */
98 ret = rtc_write32(dev, CMOS_FSP_STACK_ADDR, gd->start_addr_sp);
99 if (ret) {
100 debug("Save stack address to CMOS: err=%d\n", ret);
101 return -EIO;
102 }
103
104 return 0;
105}
106#endif
107
Simon Glass295c4232017-03-28 10:27:18 -0600108int arch_fsp_init(void)
Bin Mengd560c5c2015-06-07 11:33:14 +0800109{
Bin Meng07793c082015-10-11 21:37:42 -0700110 void *nvs;
Bin Mengcf200302017-04-21 07:24:39 -0700111 int stack = CONFIG_FSP_TEMP_RAM_ADDR;
Bin Mengacb4bf92017-04-21 07:24:31 -0700112 int boot_mode = BOOT_FULL_CONFIG;
113#ifdef CONFIG_HAVE_ACPI_RESUME
114 int prev_sleep_state = chipset_prev_sleep_state();
Bin Mengef61f772017-04-21 07:24:32 -0700115 gd->arch.prev_sleep_state = prev_sleep_state;
Bin Mengacb4bf92017-04-21 07:24:31 -0700116#endif
Bin Meng07793c082015-10-11 21:37:42 -0700117
Bin Meng12440cd2015-08-20 06:40:19 -0700118 if (!gd->arch.hob_list) {
Bin Meng07793c082015-10-11 21:37:42 -0700119#ifdef CONFIG_ENABLE_MRC_CACHE
120 nvs = fsp_prepare_mrc_cache();
121#else
122 nvs = NULL;
123#endif
Bin Mengacb4bf92017-04-21 07:24:31 -0700124
125#ifdef CONFIG_HAVE_ACPI_RESUME
126 if (prev_sleep_state == ACPI_S3) {
127 if (nvs == NULL) {
128 /* If waking from S3 and no cache then */
129 debug("No MRC cache found in S3 resume path\n");
130 post_code(POST_RESUME_FAILURE);
131 /* Clear Sleep Type */
132 chipset_clear_sleep_state();
133 /* Reboot */
134 debug("Rebooting..\n");
Bin Meng6e577142018-07-19 03:07:32 -0700135 outb(SYS_RST | RST_CPU, IO_PORT_RESET);
Bin Mengacb4bf92017-04-21 07:24:31 -0700136 /* Should not reach here.. */
137 panic("Reboot System");
138 }
139
Bin Mengcf200302017-04-21 07:24:39 -0700140 /*
141 * DM is not avaiable yet at this point, hence call
142 * CMOS access library which does not depend on DM.
143 */
144 stack = cmos_read32(CMOS_FSP_STACK_ADDR);
Bin Mengacb4bf92017-04-21 07:24:31 -0700145 boot_mode = BOOT_ON_S3_RESUME;
146 }
147#endif
Bin Meng12440cd2015-08-20 06:40:19 -0700148 /*
149 * The first time we enter here, call fsp_init().
150 * Note the execution does not return to this function,
151 * instead it jumps to fsp_continue().
152 */
Bin Mengcf200302017-04-21 07:24:39 -0700153 fsp_init(stack, boot_mode, nvs);
Bin Meng12440cd2015-08-20 06:40:19 -0700154 } else {
155 /*
156 * The second time we enter here, adjust the size of malloc()
157 * pool before relocation. Given gd->malloc_base was adjusted
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +0100158 * after the call to board_init_f_init_reserve() in arch/x86/
159 * cpu/start.S, we should fix up gd->malloc_limit here.
Bin Meng12440cd2015-08-20 06:40:19 -0700160 */
161 gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
162 }
Bin Mengd560c5c2015-06-07 11:33:14 +0800163
164 return 0;
165}