Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Lee Leahy | 47bd2d9 | 2016-07-24 18:12:16 -0700 | [diff] [blame] | 4 | * Copyright (C) 2015-2016 Intel Corp. |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 5 | * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.) |
| 6 | * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <arch/io.h> |
| 15 | #include <arch/cpu.h> |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 16 | #include <arch/symbols.h> |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 17 | #include <cbfs.h> |
Aaron Durbin | 2792868 | 2016-07-15 22:32:28 -0500 | [diff] [blame] | 18 | #include <cbmem.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 19 | #include <console/console.h> |
Furquan Shaikh | 5aea588 | 2016-07-30 18:10:05 -0700 | [diff] [blame] | 20 | #include <elog.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 21 | #include <fsp/api.h> |
| 22 | #include <fsp/util.h> |
| 23 | #include <memrange.h> |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 24 | #include <program_loading.h> |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 25 | #include <reset.h> |
| 26 | #include <romstage_handoff.h> |
| 27 | #include <soc/intel/common/mrc_cache.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 28 | #include <string.h> |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 29 | #include <symbols.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 30 | #include <timestamp.h> |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 31 | #include <vboot/vboot_common.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 32 | |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 33 | static void save_memory_training_data(bool s3wake, uint32_t fsp_version) |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 34 | { |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 35 | size_t mrc_data_size; |
| 36 | const void *mrc_data; |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 37 | |
| 38 | if (!IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS) || s3wake) |
| 39 | return; |
| 40 | |
| 41 | mrc_data = fsp_find_nv_storage_data(&mrc_data_size); |
| 42 | if (!mrc_data) { |
| 43 | printk(BIOS_ERR, "Couldn't find memory training data HOB.\n"); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * Save MRC Data to CBMEM. By always saving the data this forces |
| 49 | * a retrain after a trip through Chrome OS recovery path. The |
| 50 | * code which saves the data to flash doesn't write if the latest |
| 51 | * training data matches this one. |
| 52 | */ |
| 53 | if (mrc_cache_stash_data_with_version(mrc_data, mrc_data_size, |
| 54 | fsp_version) < 0) |
| 55 | printk(BIOS_ERR, "Failed to stash MRC data\n"); |
| 56 | } |
| 57 | |
Furquan Shaikh | af8ef2a | 2016-07-24 08:48:34 -0700 | [diff] [blame] | 58 | /* |
| 59 | * On every trip to recovery, newly generated MRC data is stored with this |
| 60 | * version since it is not expected to be a legit version. This ensures that on |
| 61 | * next normal boot, memory re-training occurs and new MRC data is stored. |
| 62 | */ |
| 63 | #define MRC_DEAD_VERSION (0xdeaddead) |
| 64 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 65 | static void do_fsp_post_memory_init(bool s3wake, uint32_t fsp_version) |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 66 | { |
| 67 | struct range_entry fsp_mem; |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 68 | struct romstage_handoff *handoff; |
| 69 | |
Lee Leahy | 52d0c68 | 2016-08-01 15:47:42 -0700 | [diff] [blame] | 70 | if (fsp_find_reserved_memory(&fsp_mem)) |
| 71 | die("Failed to find FSP_RESERVED_MEMORY_RESOURCE_HOB!\n"); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 72 | |
| 73 | /* initialize cbmem by adding FSP reserved memory first thing */ |
| 74 | if (!s3wake) { |
| 75 | cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY, |
| 76 | range_entry_size(&fsp_mem)); |
| 77 | } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY, |
| 78 | range_entry_size(&fsp_mem))) { |
| 79 | if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) { |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame^] | 80 | printk(BIOS_ERR, |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 81 | "Failed to recover CBMEM in S3 resume.\n"); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 82 | /* Failed S3 resume, reset to come up cleanly */ |
| 83 | hard_reset(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /* make sure FSP memory is reserved in cbmem */ |
| 88 | if (range_entry_base(&fsp_mem) != |
| 89 | (uintptr_t)cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY)) |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 90 | die("Failed to accommodate FSP reserved memory request!\n"); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 91 | |
| 92 | /* Now that CBMEM is up, save the list so ramstage can use it */ |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 93 | if (vboot_recovery_mode_enabled()) |
Furquan Shaikh | af8ef2a | 2016-07-24 08:48:34 -0700 | [diff] [blame] | 94 | fsp_version = MRC_DEAD_VERSION; |
| 95 | |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 96 | save_memory_training_data(s3wake, fsp_version); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 97 | |
| 98 | /* Create romstage handof information */ |
| 99 | handoff = romstage_handoff_find_or_add(); |
| 100 | if (handoff != NULL) |
| 101 | handoff->s3_resume = s3wake; |
| 102 | else |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame^] | 103 | printk(BIOS_SPEW, "Romstage handoff structure not added!\n"); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 106 | static void fsp_fill_mrc_cache(struct FSPM_ARCH_UPD *arch_upd, bool s3wake, |
| 107 | uint32_t fsp_version) |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 108 | { |
| 109 | const struct mrc_saved_data *mrc_cache; |
| 110 | |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 111 | arch_upd->NvsBufferPtr = NULL; |
| 112 | |
| 113 | if (!IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS)) |
| 114 | return; |
| 115 | |
Aaron Durbin | 98ea636 | 2016-07-18 11:31:53 -0500 | [diff] [blame] | 116 | /* Don't use saved training data when recovery mode is enabled. */ |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 117 | if (vboot_recovery_mode_enabled()) { |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame^] | 118 | printk(BIOS_SPEW, "Recovery mode. Not using MRC cache.\n"); |
Aaron Durbin | 98ea636 | 2016-07-18 11:31:53 -0500 | [diff] [blame] | 119 | return; |
| 120 | } |
| 121 | |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 122 | if (mrc_cache_get_current_with_version(&mrc_cache, fsp_version)) { |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame^] | 123 | printk(BIOS_SPEW, "MRC cache was not found\n"); |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 124 | return; |
| 125 | } |
| 126 | |
| 127 | /* MRC cache found */ |
| 128 | arch_upd->NvsBufferPtr = (void *)mrc_cache->data; |
| 129 | arch_upd->BootMode = s3wake ? |
| 130 | FSP_BOOT_ON_S3_RESUME: |
| 131 | FSP_BOOT_ASSUMING_NO_CONFIGURATION_CHANGES; |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame^] | 132 | printk(BIOS_SPEW, "MRC cache found, size %x bootmode:%d\n", |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 133 | mrc_cache->size, arch_upd->BootMode); |
| 134 | } |
| 135 | |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 136 | static enum cb_err check_region_overlap(const struct memranges *ranges, |
| 137 | const char *description, |
| 138 | uintptr_t begin, uintptr_t end) |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 139 | { |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 140 | const struct range_entry *r; |
| 141 | |
| 142 | memranges_each_entry(r, ranges) { |
| 143 | if (end <= range_entry_base(r)) |
| 144 | continue; |
| 145 | if (begin >= range_entry_end(r)) |
| 146 | continue; |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame^] | 147 | printk(BIOS_CRIT, "'%s' overlaps currently running program: " |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 148 | "[%p, %p)\n", description, (void *)begin, (void *)end); |
| 149 | return CB_ERR; |
| 150 | } |
| 151 | |
| 152 | return CB_SUCCESS; |
| 153 | } |
| 154 | |
| 155 | static enum cb_err fsp_fill_common_arch_params(struct FSPM_ARCH_UPD *arch_upd, |
| 156 | bool s3wake, uint32_t fsp_version, |
| 157 | const struct memranges *memmap) |
| 158 | { |
| 159 | uintptr_t stack_begin; |
| 160 | uintptr_t stack_end; |
| 161 | |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 162 | /* |
| 163 | * FSPM_UPD passed here is populated with default values provided by |
| 164 | * the blob itself. We let FSPM use top of CAR region of the size it |
| 165 | * requests. |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 166 | */ |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 167 | stack_end = (uintptr_t)_car_region_end; |
| 168 | stack_begin = stack_end - arch_upd->StackSize; |
| 169 | |
| 170 | if (check_region_overlap(memmap, "FSPM stack", stack_begin, |
| 171 | stack_end) != CB_SUCCESS) |
| 172 | return CB_ERR; |
| 173 | |
| 174 | arch_upd->StackBase = (void *)stack_begin; |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 175 | |
| 176 | arch_upd->BootMode = FSP_BOOT_WITH_FULL_CONFIGURATION; |
| 177 | |
Aaron Durbin | f0ec824 | 2016-07-18 11:24:36 -0500 | [diff] [blame] | 178 | fsp_fill_mrc_cache(arch_upd, s3wake, fsp_version); |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 179 | |
| 180 | return CB_SUCCESS; |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 181 | } |
| 182 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 183 | static void do_fsp_memory_init(struct fsp_header *hdr, bool s3wake, |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 184 | const struct memranges *memmap) |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 185 | { |
| 186 | enum fsp_status status; |
| 187 | fsp_memory_init_fn fsp_raminit; |
| 188 | struct FSPM_UPD fspm_upd, *upd; |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 189 | struct FSPM_ARCH_UPD *arch_upd; |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 190 | |
| 191 | post_code(0x34); |
| 192 | |
| 193 | upd = (struct FSPM_UPD *)(hdr->cfg_region_offset + hdr->image_base); |
| 194 | |
| 195 | if (upd->FspUpdHeader.Signature != FSPM_UPD_SIGNATURE) { |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 196 | die("Invalid FSPM signature!\n"); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* Copy the default values from the UPD area */ |
| 200 | memcpy(&fspm_upd, upd, sizeof(fspm_upd)); |
| 201 | |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 202 | arch_upd = &fspm_upd.FspmArchUpd; |
| 203 | |
Aaron Durbin | 2792868 | 2016-07-15 22:32:28 -0500 | [diff] [blame] | 204 | /* Reserve enough memory under TOLUD to save CBMEM header */ |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 205 | arch_upd->BootLoaderTolumSize = cbmem_overhead_size(); |
Aaron Durbin | 2792868 | 2016-07-15 22:32:28 -0500 | [diff] [blame] | 206 | |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 207 | /* Fill common settings on behalf of chipset. */ |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 208 | if (fsp_fill_common_arch_params(arch_upd, s3wake, hdr->fsp_revision, |
| 209 | memmap) != CB_SUCCESS) |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 210 | die("FSPM_ARCH_UPD not found!\n"); |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 211 | |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 212 | /* Give SoC and mainboard a chance to update the UPD */ |
| 213 | platform_fsp_memory_init_params_cb(&fspm_upd); |
| 214 | |
| 215 | /* Call FspMemoryInit */ |
| 216 | fsp_raminit = (void *)(hdr->image_base + hdr->memory_init_entry_offset); |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 217 | fsp_debug_before_memory_init(fsp_raminit, upd, &fspm_upd); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 218 | |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 219 | post_code(POST_FSP_MEMORY_INIT); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 220 | timestamp_add_now(TS_FSP_MEMORY_INIT_START); |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 221 | status = fsp_raminit(&fspm_upd, fsp_get_hob_list_ptr()); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 222 | post_code(POST_FSP_MEMORY_INIT); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 223 | timestamp_add_now(TS_FSP_MEMORY_INIT_END); |
| 224 | |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 225 | fsp_debug_after_memory_init(status); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 226 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 227 | /* Handle any errors returned by FspMemoryInit */ |
Aaron Durbin | f41f2aa | 2016-07-18 12:03:58 -0500 | [diff] [blame] | 228 | fsp_handle_reset(status); |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 229 | if (status != FSP_SUCCESS) { |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame^] | 230 | printk(BIOS_CRIT, "FspMemoryInit returned 0x%08x\n", status); |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 231 | die("FspMemoryInit returned an error!\n"); |
| 232 | } |
Aaron Durbin | f41f2aa | 2016-07-18 12:03:58 -0500 | [diff] [blame] | 233 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 234 | do_fsp_post_memory_init(s3wake, hdr->fsp_revision); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 237 | /* Load the binary into the memory specified by the info header. */ |
| 238 | static enum cb_err load_fspm_mem(struct fsp_header *hdr, |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 239 | const struct region_device *rdev, |
| 240 | const struct memranges *memmap) |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 241 | { |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 242 | uintptr_t fspm_begin; |
| 243 | uintptr_t fspm_end; |
| 244 | |
| 245 | if (fsp_validate_component(hdr, rdev) != CB_SUCCESS) |
| 246 | return CB_ERR; |
| 247 | |
| 248 | fspm_begin = hdr->image_base; |
| 249 | fspm_end = fspm_begin + hdr->image_size; |
| 250 | |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 251 | if (check_region_overlap(memmap, "FSPM", fspm_begin, fspm_end) != |
| 252 | CB_SUCCESS) |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 253 | return CB_ERR; |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 254 | |
| 255 | /* Load binary into memory at provided address. */ |
| 256 | if (rdev_readat(rdev, (void *)fspm_begin, 0, fspm_end - fspm_begin) < 0) |
| 257 | return CB_ERR; |
| 258 | |
| 259 | return CB_SUCCESS; |
| 260 | } |
| 261 | |
| 262 | /* Handle the case when FSPM is running XIP. */ |
| 263 | static enum cb_err load_fspm_xip(struct fsp_header *hdr, |
| 264 | const struct region_device *rdev) |
| 265 | { |
| 266 | void *base; |
| 267 | |
| 268 | if (fsp_validate_component(hdr, rdev) != CB_SUCCESS) |
| 269 | return CB_ERR; |
| 270 | |
| 271 | base = rdev_mmap_full(rdev); |
| 272 | if ((uintptr_t)base != hdr->image_base) { |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame^] | 273 | printk(BIOS_CRIT, "FSPM XIP base does not match: %p vs %p\n", |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 274 | (void *)(uintptr_t)hdr->image_base, base); |
| 275 | return CB_ERR; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * Since the component is XIP it's already in the address space. Thus, |
| 280 | * there's no need to rdev_munmap(). |
| 281 | */ |
| 282 | return CB_SUCCESS; |
| 283 | } |
| 284 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 285 | void fsp_memory_init(bool s3wake) |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 286 | { |
| 287 | struct fsp_header hdr; |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 288 | enum cb_err status; |
| 289 | struct cbfsf file_desc; |
| 290 | struct region_device file_data; |
| 291 | const char *name = CONFIG_FSP_M_CBFS; |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 292 | struct memranges memmap; |
| 293 | struct range_entry freeranges[2]; |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 294 | |
Furquan Shaikh | 5aea588 | 2016-07-30 18:10:05 -0700 | [diff] [blame] | 295 | if (IS_ENABLED(CONFIG_ELOG_BOOT_COUNT) && !s3wake) |
| 296 | boot_count_increment(); |
| 297 | |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 298 | if (cbfs_boot_locate(&file_desc, name, NULL)) { |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame^] | 299 | printk(BIOS_CRIT, "Could not locate %s in CBFS\n", name); |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 300 | die("FSPM not available!\n"); |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | cbfs_file_data(&file_data, &file_desc); |
| 304 | |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 305 | /* Build up memory map of romstage address space including CAR. */ |
| 306 | memranges_init_empty(&memmap, &freeranges[0], ARRAY_SIZE(freeranges)); |
| 307 | memranges_insert(&memmap, (uintptr_t)_car_region_start, |
| 308 | _car_relocatable_data_end - _car_region_start, 0); |
| 309 | memranges_insert(&memmap, (uintptr_t)_program, _program_size, 0); |
| 310 | |
Lee Leahy | 27cd96a | 2016-07-21 11:16:39 -0700 | [diff] [blame] | 311 | if (!IS_ENABLED(CONFIG_FSP_M_XIP)) |
Aaron Durbin | 02e504c | 2016-07-18 11:53:10 -0500 | [diff] [blame] | 312 | status = load_fspm_mem(&hdr, &file_data, &memmap); |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 313 | else |
| 314 | status = load_fspm_xip(&hdr, &file_data); |
| 315 | |
| 316 | if (status != CB_SUCCESS) { |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 317 | die("Loading FSPM failed!\n"); |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /* Signal that FSP component has been loaded. */ |
| 321 | prog_segment_loaded(hdr.image_base, hdr.image_size, SEG_FINAL); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 322 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 323 | do_fsp_memory_init(&hdr, s3wake, &memmap); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 324 | } |