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> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 12 | #include <rtc.h> |
Simon Glass | 5046109 | 2020-04-08 16:57:35 -0600 | [diff] [blame] | 13 | #include <acpi/acpi_s3.h> |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 14 | #include <asm/cmos_layout.h> |
| 15 | #include <asm/early_cmos.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 17 | #include <asm/io.h> |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 18 | #include <asm/mrccache.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 19 | #include <asm/post.h> |
| 20 | #include <asm/processor.h> |
Simon Glass | 6c34fc1 | 2019-09-25 08:00:11 -0600 | [diff] [blame] | 21 | #include <asm/fsp1/fsp_support.h> |
Simon Glass | 509805b | 2015-01-27 22:13:39 -0700 | [diff] [blame] | 22 | |
Simon Glass | daa93d9 | 2015-07-31 09:31:31 -0600 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Simon Glass | 9de1027 | 2019-12-06 21:42:10 -0700 | [diff] [blame] | 25 | static void *fsp_prepare_mrc_cache(void) |
| 26 | { |
| 27 | struct mrc_data_container *cache; |
| 28 | struct mrc_region entry; |
| 29 | int ret; |
| 30 | |
| 31 | ret = mrccache_get_region(MRC_TYPE_NORMAL, NULL, &entry); |
| 32 | if (ret) |
| 33 | return NULL; |
| 34 | |
| 35 | cache = mrccache_find_current(&entry); |
| 36 | if (!cache) |
| 37 | return NULL; |
| 38 | |
| 39 | debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__, |
| 40 | cache->data, cache->data_size, cache->checksum); |
| 41 | |
| 42 | return cache->data; |
| 43 | } |
| 44 | |
Simon Glass | 295c423 | 2017-03-28 10:27:18 -0600 | [diff] [blame] | 45 | int arch_fsp_init(void) |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 46 | { |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 47 | void *nvs; |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 48 | int stack = CONFIG_FSP_TEMP_RAM_ADDR; |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 49 | int boot_mode = BOOT_FULL_CONFIG; |
Simon Glass | e6ad202 | 2020-07-09 18:43:16 -0600 | [diff] [blame] | 50 | int prev_sleep_state; |
| 51 | |
| 52 | if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) { |
| 53 | prev_sleep_state = chipset_prev_sleep_state(); |
| 54 | gd->arch.prev_sleep_state = prev_sleep_state; |
| 55 | } |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 56 | |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 57 | if (!gd->arch.hob_list) { |
Simon Glass | f755a45 | 2019-09-25 08:11:27 -0600 | [diff] [blame] | 58 | if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) |
| 59 | nvs = fsp_prepare_mrc_cache(); |
| 60 | else |
| 61 | nvs = NULL; |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 62 | |
Simon Glass | e6ad202 | 2020-07-09 18:43:16 -0600 | [diff] [blame] | 63 | if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) && |
| 64 | prev_sleep_state == ACPI_S3) { |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 65 | if (nvs == NULL) { |
| 66 | /* If waking from S3 and no cache then */ |
| 67 | debug("No MRC cache found in S3 resume path\n"); |
| 68 | post_code(POST_RESUME_FAILURE); |
| 69 | /* Clear Sleep Type */ |
| 70 | chipset_clear_sleep_state(); |
| 71 | /* Reboot */ |
| 72 | debug("Rebooting..\n"); |
Bin Meng | 6e57714 | 2018-07-19 03:07:32 -0700 | [diff] [blame] | 73 | outb(SYS_RST | RST_CPU, IO_PORT_RESET); |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 74 | /* Should not reach here.. */ |
| 75 | panic("Reboot System"); |
| 76 | } |
| 77 | |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 78 | /* |
Vagrant Cascadian | 973c099 | 2019-05-03 14:28:37 -0800 | [diff] [blame] | 79 | * DM is not available yet at this point, hence call |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 80 | * CMOS access library which does not depend on DM. |
| 81 | */ |
| 82 | stack = cmos_read32(CMOS_FSP_STACK_ADDR); |
Bin Meng | acb4bf9 | 2017-04-21 07:24:31 -0700 | [diff] [blame] | 83 | boot_mode = BOOT_ON_S3_RESUME; |
| 84 | } |
Simon Glass | e6ad202 | 2020-07-09 18:43:16 -0600 | [diff] [blame] | 85 | |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 86 | /* |
| 87 | * The first time we enter here, call fsp_init(). |
| 88 | * Note the execution does not return to this function, |
| 89 | * instead it jumps to fsp_continue(). |
| 90 | */ |
Bin Meng | cf20030 | 2017-04-21 07:24:39 -0700 | [diff] [blame] | 91 | fsp_init(stack, boot_mode, nvs); |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 92 | } else { |
| 93 | /* |
| 94 | * The second time we enter here, adjust the size of malloc() |
| 95 | * pool before relocation. Given gd->malloc_base was adjusted |
Albert ARIBAUD | 6cb4c46 | 2015-11-25 17:56:32 +0100 | [diff] [blame] | 96 | * after the call to board_init_f_init_reserve() in arch/x86/ |
| 97 | * cpu/start.S, we should fix up gd->malloc_limit here. |
Bin Meng | 12440cd | 2015-08-20 06:40:19 -0700 | [diff] [blame] | 98 | */ |
| 99 | gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN; |
| 100 | } |
Bin Meng | d560c5c | 2015-06-07 11:33:14 +0800 | [diff] [blame] | 101 | |
| 102 | return 0; |
| 103 | } |