blob: 1714d13228e375cc59b0a45aa4d618a8d08f26a3 [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>
Bin Mengcf200302017-04-21 07:24:39 -07008#include <dm.h>
Simon Glass509805b2015-01-27 22:13:39 -07009#include <errno.h>
Bin Mengcf200302017-04-21 07:24:39 -070010#include <rtc.h>
Bin Mengacb4bf92017-04-21 07:24:31 -070011#include <asm/acpi_s3.h>
Bin Mengcf200302017-04-21 07:24:39 -070012#include <asm/cmos_layout.h>
13#include <asm/early_cmos.h>
Simon Glass509805b2015-01-27 22:13:39 -070014#include <asm/io.h>
Bin Meng07793c082015-10-11 21:37:42 -070015#include <asm/mrccache.h>
Simon Glass509805b2015-01-27 22:13:39 -070016#include <asm/post.h>
17#include <asm/processor.h>
18#include <asm/fsp/fsp_support.h>
19
Simon Glassdaa93d92015-07-31 09:31:31 -060020DECLARE_GLOBAL_DATA_PTR;
21
Bin Mengb032e3f2017-08-15 22:38:31 -070022extern void ich_spi_config_opcode(struct udevice *dev);
23
Simon Glassee7c36f2017-03-28 10:27:30 -060024int checkcpu(void)
25{
26 return 0;
27}
28
Simon Glass509805b2015-01-27 22:13:39 -070029int print_cpuinfo(void)
30{
31 post_code(POST_CPU_INFO);
32 return default_print_cpuinfo();
33}
34
Simon Glassfa912732015-08-10 07:05:07 -060035int fsp_init_phase_pci(void)
Simon Glass509805b2015-01-27 22:13:39 -070036{
37 u32 status;
38
39 /* call into FspNotify */
40 debug("Calling into FSP (notify phase INIT_PHASE_PCI): ");
41 status = fsp_notify(NULL, INIT_PHASE_PCI);
Simon Glassfa912732015-08-10 07:05:07 -060042 if (status)
Simon Glass509805b2015-01-27 22:13:39 -070043 debug("fail, error code %x\n", status);
44 else
45 debug("OK\n");
46
Simon Glassfa912732015-08-10 07:05:07 -060047 return status ? -EPERM : 0;
48}
49
Simon Glass509805b2015-01-27 22:13:39 -070050void board_final_cleanup(void)
51{
52 u32 status;
53
Bin Mengb032e3f2017-08-15 22:38:31 -070054#ifdef CONFIG_FSP_LOCKDOWN_SPI
55 struct udevice *dev;
56
57 /*
58 * Some Intel FSP (like Braswell) does SPI lock-down during the call
59 * to fsp_notify(INIT_PHASE_BOOT). But before SPI lock-down is done,
60 * it's bootloader's responsibility to configure the SPI controller's
61 * opcode registers properly otherwise SPI controller driver doesn't
62 * know how to communicate with the SPI flash device.
63 *
64 * Note we cannot do such configuration elsewhere (eg: during the SPI
65 * controller driver's probe() routine), because:
66 *
67 * 1). U-Boot SPI controller driver does not set the lock-down bit
68 * 2). Any SPI transfer will corrupt the contents of these registers
69 *
70 * Hence we have to do it right here before SPI lock-down bit is set.
71 */
72 if (!uclass_first_device_err(UCLASS_SPI, &dev))
73 ich_spi_config_opcode(dev);
74#endif
75
Simon Glass509805b2015-01-27 22:13:39 -070076 /* call into FspNotify */
77 debug("Calling into FSP (notify phase INIT_PHASE_BOOT): ");
78 status = fsp_notify(NULL, INIT_PHASE_BOOT);
Simon Glass38252292015-08-12 19:33:07 -060079 if (status)
Simon Glass509805b2015-01-27 22:13:39 -070080 debug("fail, error code %x\n", status);
81 else
82 debug("OK\n");
83
84 return;
85}
Bin Mengd560c5c2015-06-07 11:33:14 +080086
Bin Meng07793c082015-10-11 21:37:42 -070087static __maybe_unused void *fsp_prepare_mrc_cache(void)
88{
89 struct mrc_data_container *cache;
90 struct mrc_region entry;
91 int ret;
92
93 ret = mrccache_get_region(NULL, &entry);
94 if (ret)
95 return NULL;
96
97 cache = mrccache_find_current(&entry);
98 if (!cache)
99 return NULL;
100
101 debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
102 cache->data, cache->data_size, cache->checksum);
103
104 return cache->data;
105}
106
Bin Mengcf200302017-04-21 07:24:39 -0700107#ifdef CONFIG_HAVE_ACPI_RESUME
108int fsp_save_s3_stack(void)
109{
110 struct udevice *dev;
111 int ret;
112
113 if (gd->arch.prev_sleep_state == ACPI_S3)
114 return 0;
115
116 ret = uclass_get_device(UCLASS_RTC, 0, &dev);
117 if (ret) {
118 debug("Cannot find RTC: err=%d\n", ret);
119 return -ENODEV;
120 }
121
122 /* Save the stack address to CMOS */
123 ret = rtc_write32(dev, CMOS_FSP_STACK_ADDR, gd->start_addr_sp);
124 if (ret) {
125 debug("Save stack address to CMOS: err=%d\n", ret);
126 return -EIO;
127 }
128
129 return 0;
130}
131#endif
132
Simon Glass295c4232017-03-28 10:27:18 -0600133int arch_fsp_init(void)
Bin Mengd560c5c2015-06-07 11:33:14 +0800134{
Bin Meng07793c082015-10-11 21:37:42 -0700135 void *nvs;
Bin Mengcf200302017-04-21 07:24:39 -0700136 int stack = CONFIG_FSP_TEMP_RAM_ADDR;
Bin Mengacb4bf92017-04-21 07:24:31 -0700137 int boot_mode = BOOT_FULL_CONFIG;
138#ifdef CONFIG_HAVE_ACPI_RESUME
139 int prev_sleep_state = chipset_prev_sleep_state();
Bin Mengef61f772017-04-21 07:24:32 -0700140 gd->arch.prev_sleep_state = prev_sleep_state;
Bin Mengacb4bf92017-04-21 07:24:31 -0700141#endif
Bin Meng07793c082015-10-11 21:37:42 -0700142
Bin Meng12440cd2015-08-20 06:40:19 -0700143 if (!gd->arch.hob_list) {
Bin Meng07793c082015-10-11 21:37:42 -0700144#ifdef CONFIG_ENABLE_MRC_CACHE
145 nvs = fsp_prepare_mrc_cache();
146#else
147 nvs = NULL;
148#endif
Bin Mengacb4bf92017-04-21 07:24:31 -0700149
150#ifdef CONFIG_HAVE_ACPI_RESUME
151 if (prev_sleep_state == ACPI_S3) {
152 if (nvs == NULL) {
153 /* If waking from S3 and no cache then */
154 debug("No MRC cache found in S3 resume path\n");
155 post_code(POST_RESUME_FAILURE);
156 /* Clear Sleep Type */
157 chipset_clear_sleep_state();
158 /* Reboot */
159 debug("Rebooting..\n");
160 reset_cpu(0);
161 /* Should not reach here.. */
162 panic("Reboot System");
163 }
164
Bin Mengcf200302017-04-21 07:24:39 -0700165 /*
166 * DM is not avaiable yet at this point, hence call
167 * CMOS access library which does not depend on DM.
168 */
169 stack = cmos_read32(CMOS_FSP_STACK_ADDR);
Bin Mengacb4bf92017-04-21 07:24:31 -0700170 boot_mode = BOOT_ON_S3_RESUME;
171 }
172#endif
Bin Meng12440cd2015-08-20 06:40:19 -0700173 /*
174 * The first time we enter here, call fsp_init().
175 * Note the execution does not return to this function,
176 * instead it jumps to fsp_continue().
177 */
Bin Mengcf200302017-04-21 07:24:39 -0700178 fsp_init(stack, boot_mode, nvs);
Bin Meng12440cd2015-08-20 06:40:19 -0700179 } else {
180 /*
181 * The second time we enter here, adjust the size of malloc()
182 * pool before relocation. Given gd->malloc_base was adjusted
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +0100183 * after the call to board_init_f_init_reserve() in arch/x86/
184 * cpu/start.S, we should fix up gd->malloc_limit here.
Bin Meng12440cd2015-08-20 06:40:19 -0700185 */
186 gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
187 }
Bin Mengd560c5c2015-06-07 11:33:14 +0800188
189 return 0;
190}