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 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 22 | int checkcpu(void) |
| 23 | { |
| 24 | return 0; |
| 25 | } |
| 26 | |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 27 | int print_cpuinfo(void) |
| 28 | { |
| 29 | post_code(POST_CPU_INFO); |
| 30 | return default_print_cpuinfo(); |
| 31 | } |
| 32 | |
Simon Glass | fa91273 | 2015-08-10 07:05:07 -0600 | [diff] [blame] | 33 | int fsp_init_phase_pci(void) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 34 | { |
| 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 Glass | fa91273 | 2015-08-10 07:05:07 -0600 | [diff] [blame] | 40 | if (status) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 41 | debug("fail, error code %x\n", status); |
| 42 | else |
| 43 | debug("OK\n"); |
| 44 | |
Simon Glass | fa91273 | 2015-08-10 07:05:07 -0600 | [diff] [blame] | 45 | return status ? -EPERM : 0; |
| 46 | } |
| 47 | |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 48 | void 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 Glass | 3825229 | 2015-08-12 19:33:07 -0600 | [diff] [blame] | 55 | if (status) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 56 | debug("fail, error code %x\n", status); |
| 57 | else |
| 58 | debug("OK\n"); |
| 59 | |
| 60 | return; |
| 61 | } |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 62 | |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 63 | static __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 Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame^] | 83 | #ifdef CONFIG_HAVE_ACPI_RESUME |
| 84 | int 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 Glass | 295c423 | 2017-03-28 10:27:18 -0600 | [diff] [blame] | 109 | int arch_fsp_init(void) |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 110 | { |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 111 | void *nvs; |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame^] | 112 | int stack = CONFIG_FSP_TEMP_RAM_ADDR; |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 113 | int boot_mode = BOOT_FULL_CONFIG; |
| 114 | #ifdef CONFIG_HAVE_ACPI_RESUME |
| 115 | int prev_sleep_state = chipset_prev_sleep_state(); |
Bin Meng | ef61f77 | 2017-04-21 07:24:32 -0700 | [diff] [blame] | 116 | gd->arch.prev_sleep_state = prev_sleep_state; |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 117 | #endif |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 118 | |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 119 | if (!gd->arch.hob_list) { |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 120 | #ifdef CONFIG_ENABLE_MRC_CACHE |
| 121 | nvs = fsp_prepare_mrc_cache(); |
| 122 | #else |
| 123 | nvs = NULL; |
| 124 | #endif |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 125 | |
| 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 Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame^] | 141 | /* |
| 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 Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 146 | boot_mode = BOOT_ON_S3_RESUME; |
| 147 | } |
| 148 | #endif |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 149 | /* |
| 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 Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame^] | 154 | fsp_init(stack, boot_mode, nvs); |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 155 | } 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 ARIBAUD | 6cb4c46 | 2015-11-25 17:56:32 +0100 | [diff] [blame] | 159 | * 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 Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 161 | */ |
| 162 | gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN; |
| 163 | } |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 164 | |
| 165 | return 0; |
| 166 | } |