Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 8 | #include <errno.h> |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 9 | #include <rtc.h> |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 10 | #include <asm/acpi_s3.h> |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 11 | #include <asm/cmos_layout.h> |
| 12 | #include <asm/early_cmos.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 13 | #include <asm/io.h> |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 14 | #include <asm/mrccache.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 15 | #include <asm/post.h> |
| 16 | #include <asm/processor.h> |
| 17 | #include <asm/fsp/fsp_support.h> |
| 18 | |
Simon Glass | daa93d9 | 2015-07-31 09:31:31 -0600 | [diff] [blame] | 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 21 | int checkcpu(void) |
| 22 | { |
| 23 | return 0; |
| 24 | } |
| 25 | |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 26 | int print_cpuinfo(void) |
| 27 | { |
| 28 | post_code(POST_CPU_INFO); |
| 29 | return default_print_cpuinfo(); |
| 30 | } |
| 31 | |
Simon Glass | fa91273 | 2015-08-10 07:05:07 -0600 | [diff] [blame] | 32 | int fsp_init_phase_pci(void) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 33 | { |
| 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 Glass | fa91273 | 2015-08-10 07:05:07 -0600 | [diff] [blame] | 39 | if (status) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 40 | debug("fail, error code %x\n", status); |
| 41 | else |
| 42 | debug("OK\n"); |
| 43 | |
Simon Glass | fa91273 | 2015-08-10 07:05:07 -0600 | [diff] [blame] | 44 | return status ? -EPERM : 0; |
| 45 | } |
| 46 | |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 47 | void 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 Glass | 3825229 | 2015-08-12 19:33:07 -0600 | [diff] [blame] | 54 | if (status) |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 55 | debug("fail, error code %x\n", status); |
| 56 | else |
| 57 | debug("OK\n"); |
| 58 | |
| 59 | return; |
| 60 | } |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 61 | |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 62 | static __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 Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 82 | #ifdef CONFIG_HAVE_ACPI_RESUME |
| 83 | int 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 Glass | 295c423 | 2017-03-28 10:27:18 -0600 | [diff] [blame] | 108 | int arch_fsp_init(void) |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 109 | { |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 110 | void *nvs; |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 111 | int stack = CONFIG_FSP_TEMP_RAM_ADDR; |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 112 | int boot_mode = BOOT_FULL_CONFIG; |
| 113 | #ifdef CONFIG_HAVE_ACPI_RESUME |
| 114 | int prev_sleep_state = chipset_prev_sleep_state(); |
Bin Meng | ef61f77 | 2017-04-21 07:24:32 -0700 | [diff] [blame] | 115 | gd->arch.prev_sleep_state = prev_sleep_state; |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 116 | #endif |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 117 | |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 118 | if (!gd->arch.hob_list) { |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 119 | #ifdef CONFIG_ENABLE_MRC_CACHE |
| 120 | nvs = fsp_prepare_mrc_cache(); |
| 121 | #else |
| 122 | nvs = NULL; |
| 123 | #endif |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 124 | |
| 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 Meng | 6e57714 | 2018-07-19 03:07:32 -0700 | [diff] [blame^] | 135 | outb(SYS_RST | RST_CPU, IO_PORT_RESET); |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 136 | /* Should not reach here.. */ |
| 137 | panic("Reboot System"); |
| 138 | } |
| 139 | |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 140 | /* |
| 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 Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 145 | boot_mode = BOOT_ON_S3_RESUME; |
| 146 | } |
| 147 | #endif |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 148 | /* |
| 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 Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 153 | fsp_init(stack, boot_mode, nvs); |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 154 | } 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 ARIBAUD | 6cb4c46 | 2015-11-25 17:56:32 +0100 | [diff] [blame] | 158 | * 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 Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 160 | */ |
| 161 | gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN; |
| 162 | } |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 163 | |
| 164 | return 0; |
| 165 | } |