Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 1 | /* |
| 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 Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 9 | #include <errno.h> |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 10 | #include <rtc.h> |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 11 | #include <asm/acpi_s3.h> |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 12 | #include <asm/cmos_layout.h> |
| 13 | #include <asm/early_cmos.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 14 | #include <asm/io.h> |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 15 | #include <asm/mrccache.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 16 | #include <asm/post.h> |
| 17 | #include <asm/processor.h> |
| 18 | #include <asm/fsp/fsp_support.h> |
| 19 | |
Simon Glass | daa93d9 | 2015-07-31 09:31:31 -0600 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Bin Meng | b032e3f | 2017-08-15 22:38:31 -0700 | [diff] [blame^] | 22 | extern void ich_spi_config_opcode(struct udevice *dev); |
| 23 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 24 | int checkcpu(void) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 29 | int print_cpuinfo(void) |
| 30 | { |
| 31 | post_code(POST_CPU_INFO); |
| 32 | return default_print_cpuinfo(); |
| 33 | } |
| 34 | |
Simon Glass | fa91273 | 2015-08-10 07:05:07 -0600 | [diff] [blame] | 35 | int fsp_init_phase_pci(void) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 36 | { |
| 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 Glass | fa91273 | 2015-08-10 07:05:07 -0600 | [diff] [blame] | 42 | if (status) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 43 | debug("fail, error code %x\n", status); |
| 44 | else |
| 45 | debug("OK\n"); |
| 46 | |
Simon Glass | fa91273 | 2015-08-10 07:05:07 -0600 | [diff] [blame] | 47 | return status ? -EPERM : 0; |
| 48 | } |
| 49 | |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 50 | void board_final_cleanup(void) |
| 51 | { |
| 52 | u32 status; |
| 53 | |
Bin Meng | b032e3f | 2017-08-15 22:38:31 -0700 | [diff] [blame^] | 54 | #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 Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 76 | /* call into FspNotify */ |
| 77 | debug("Calling into FSP (notify phase INIT_PHASE_BOOT): "); |
| 78 | status = fsp_notify(NULL, INIT_PHASE_BOOT); |
Simon Glass | 3825229 | 2015-08-12 19:33:07 -0600 | [diff] [blame] | 79 | if (status) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 80 | debug("fail, error code %x\n", status); |
| 81 | else |
| 82 | debug("OK\n"); |
| 83 | |
| 84 | return; |
| 85 | } |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 86 | |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 87 | static __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 Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 107 | #ifdef CONFIG_HAVE_ACPI_RESUME |
| 108 | int 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 Glass | 295c423 | 2017-03-28 10:27:18 -0600 | [diff] [blame] | 133 | int arch_fsp_init(void) |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 134 | { |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 135 | void *nvs; |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 136 | int stack = CONFIG_FSP_TEMP_RAM_ADDR; |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 137 | int boot_mode = BOOT_FULL_CONFIG; |
| 138 | #ifdef CONFIG_HAVE_ACPI_RESUME |
| 139 | int prev_sleep_state = chipset_prev_sleep_state(); |
Bin Meng | ef61f77 | 2017-04-21 07:24:32 -0700 | [diff] [blame] | 140 | gd->arch.prev_sleep_state = prev_sleep_state; |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 141 | #endif |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 142 | |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 143 | if (!gd->arch.hob_list) { |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 144 | #ifdef CONFIG_ENABLE_MRC_CACHE |
| 145 | nvs = fsp_prepare_mrc_cache(); |
| 146 | #else |
| 147 | nvs = NULL; |
| 148 | #endif |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 149 | |
| 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 Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 165 | /* |
| 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 Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 170 | boot_mode = BOOT_ON_S3_RESUME; |
| 171 | } |
| 172 | #endif |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 173 | /* |
| 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 Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 178 | fsp_init(stack, boot_mode, nvs); |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 179 | } 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 ARIBAUD | 6cb4c46 | 2015-11-25 17:56:32 +0100 | [diff] [blame] | 183 | * 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 Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 185 | */ |
| 186 | gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN; |
| 187 | } |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 188 | |
| 189 | return 0; |
| 190 | } |