blob: 3397bb83eaf1191bc7a5cffdab3bf216fb10e174 [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
Simon Glassee7c36f2017-03-28 10:27:30 -060022int checkcpu(void)
23{
24 return 0;
25}
26
Simon Glass509805b2015-01-27 22:13:39 -070027int print_cpuinfo(void)
28{
29 post_code(POST_CPU_INFO);
30 return default_print_cpuinfo();
31}
32
Simon Glassfa912732015-08-10 07:05:07 -060033int fsp_init_phase_pci(void)
Simon Glass509805b2015-01-27 22:13:39 -070034{
35 u32 status;
36
37 /* call into FspNotify */
38 debug("Calling into FSP (notify phase INIT_PHASE_PCI): ");
39 status = fsp_notify(NULL, INIT_PHASE_PCI);
Simon Glassfa912732015-08-10 07:05:07 -060040 if (status)
Simon Glass509805b2015-01-27 22:13:39 -070041 debug("fail, error code %x\n", status);
42 else
43 debug("OK\n");
44
Simon Glassfa912732015-08-10 07:05:07 -060045 return status ? -EPERM : 0;
46}
47
Simon Glass509805b2015-01-27 22:13:39 -070048void board_final_cleanup(void)
49{
50 u32 status;
51
52 /* call into FspNotify */
53 debug("Calling into FSP (notify phase INIT_PHASE_BOOT): ");
54 status = fsp_notify(NULL, INIT_PHASE_BOOT);
Simon Glass38252292015-08-12 19:33:07 -060055 if (status)
Simon Glass509805b2015-01-27 22:13:39 -070056 debug("fail, error code %x\n", status);
57 else
58 debug("OK\n");
59
60 return;
61}
Bin Mengd560c5c2015-06-07 11:33:14 +080062
Bin Meng07793c082015-10-11 21:37:42 -070063static __maybe_unused void *fsp_prepare_mrc_cache(void)
64{
65 struct mrc_data_container *cache;
66 struct mrc_region entry;
67 int ret;
68
69 ret = mrccache_get_region(NULL, &entry);
70 if (ret)
71 return NULL;
72
73 cache = mrccache_find_current(&entry);
74 if (!cache)
75 return NULL;
76
77 debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
78 cache->data, cache->data_size, cache->checksum);
79
80 return cache->data;
81}
82
Bin Mengcf200302017-04-21 07:24:39 -070083#ifdef CONFIG_HAVE_ACPI_RESUME
84int fsp_save_s3_stack(void)
85{
86 struct udevice *dev;
87 int ret;
88
89 if (gd->arch.prev_sleep_state == ACPI_S3)
90 return 0;
91
92 ret = uclass_get_device(UCLASS_RTC, 0, &dev);
93 if (ret) {
94 debug("Cannot find RTC: err=%d\n", ret);
95 return -ENODEV;
96 }
97
98 /* Save the stack address to CMOS */
99 ret = rtc_write32(dev, CMOS_FSP_STACK_ADDR, gd->start_addr_sp);
100 if (ret) {
101 debug("Save stack address to CMOS: err=%d\n", ret);
102 return -EIO;
103 }
104
105 return 0;
106}
107#endif
108
Simon Glass295c4232017-03-28 10:27:18 -0600109int arch_fsp_init(void)
Bin Mengd560c5c2015-06-07 11:33:14 +0800110{
Bin Meng07793c082015-10-11 21:37:42 -0700111 void *nvs;
Bin Mengcf200302017-04-21 07:24:39 -0700112 int stack = CONFIG_FSP_TEMP_RAM_ADDR;
Bin Mengacb4bf92017-04-21 07:24:31 -0700113 int boot_mode = BOOT_FULL_CONFIG;
114#ifdef CONFIG_HAVE_ACPI_RESUME
115 int prev_sleep_state = chipset_prev_sleep_state();
Bin Mengef61f772017-04-21 07:24:32 -0700116 gd->arch.prev_sleep_state = prev_sleep_state;
Bin Mengacb4bf92017-04-21 07:24:31 -0700117#endif
Bin Meng07793c082015-10-11 21:37:42 -0700118
Bin Meng12440cd2015-08-20 06:40:19 -0700119 if (!gd->arch.hob_list) {
Bin Meng07793c082015-10-11 21:37:42 -0700120#ifdef CONFIG_ENABLE_MRC_CACHE
121 nvs = fsp_prepare_mrc_cache();
122#else
123 nvs = NULL;
124#endif
Bin Mengacb4bf92017-04-21 07:24:31 -0700125
126#ifdef CONFIG_HAVE_ACPI_RESUME
127 if (prev_sleep_state == ACPI_S3) {
128 if (nvs == NULL) {
129 /* If waking from S3 and no cache then */
130 debug("No MRC cache found in S3 resume path\n");
131 post_code(POST_RESUME_FAILURE);
132 /* Clear Sleep Type */
133 chipset_clear_sleep_state();
134 /* Reboot */
135 debug("Rebooting..\n");
136 reset_cpu(0);
137 /* Should not reach here.. */
138 panic("Reboot System");
139 }
140
Bin Mengcf200302017-04-21 07:24:39 -0700141 /*
142 * DM is not avaiable yet at this point, hence call
143 * CMOS access library which does not depend on DM.
144 */
145 stack = cmos_read32(CMOS_FSP_STACK_ADDR);
Bin Mengacb4bf92017-04-21 07:24:31 -0700146 boot_mode = BOOT_ON_S3_RESUME;
147 }
148#endif
Bin Meng12440cd2015-08-20 06:40:19 -0700149 /*
150 * The first time we enter here, call fsp_init().
151 * Note the execution does not return to this function,
152 * instead it jumps to fsp_continue().
153 */
Bin Mengcf200302017-04-21 07:24:39 -0700154 fsp_init(stack, boot_mode, nvs);
Bin Meng12440cd2015-08-20 06:40:19 -0700155 } else {
156 /*
157 * The second time we enter here, adjust the size of malloc()
158 * pool before relocation. Given gd->malloc_base was adjusted
Albert ARIBAUD6cb4c462015-11-25 17:56:32 +0100159 * after the call to board_init_f_init_reserve() in arch/x86/
160 * cpu/start.S, we should fix up gd->malloc_limit here.
Bin Meng12440cd2015-08-20 06:40:19 -0700161 */
162 gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
163 }
Bin Mengd560c5c2015-06-07 11:33:14 +0800164
165 return 0;
166}