Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2015 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 16 | #include <arch/early_variables.h> |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 17 | #include <console/console.h> |
| 18 | #include <ec/google/chromeec/ec.h> |
| 19 | #include <fsp/car.h> |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 20 | #include <fsp/util.h> |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 21 | #include <program_loading.h> |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 22 | #include <soc/intel/common/util.h> |
| 23 | #include <timestamp.h> |
| 24 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 25 | FSP_INFO_HEADER *fih_car CAR_GLOBAL; |
| 26 | |
| 27 | /* Save FSP_INFO_HEADER for TempRamExit() call in assembly. */ |
| 28 | static inline void set_fih_car(FSP_INFO_HEADER *fih) |
| 29 | { |
| 30 | /* This variable is written in the raw form because it's only |
| 31 | * ever accessed in code that that has the cache-as-ram enabled. The |
| 32 | * assembly routine which tears down cache-as-ram utilizes this |
| 33 | * variable for determining where to find FSP. */ |
| 34 | fih_car = fih; |
| 35 | } |
| 36 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 37 | asmlinkage void *cache_as_ram_main(struct cache_as_ram_params *car_params) |
| 38 | { |
| 39 | /* Initialize timestamp book keeping only once. */ |
| 40 | timestamp_init(car_params->tsc); |
| 41 | |
| 42 | /* Call into pre-console init code then initialize console. */ |
| 43 | car_soc_pre_console_init(); |
| 44 | car_mainboard_pre_console_init(); |
| 45 | console_init(); |
| 46 | |
| 47 | printk(BIOS_DEBUG, "FSP TempRamInit successful\n"); |
| 48 | |
| 49 | printk(BIOS_SPEW, "bist: 0x%08x\n", car_params->bist); |
| 50 | printk(BIOS_SPEW, "tsc: 0x%016llx\n", car_params->tsc); |
| 51 | |
| 52 | if (car_params->bootloader_car_start != CONFIG_DCACHE_RAM_BASE || |
| 53 | car_params->bootloader_car_end != |
| 54 | (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE)) { |
| 55 | printk(BIOS_INFO, "CAR mismatch: %08x--%08x vs %08lx--%08lx\n", |
| 56 | CONFIG_DCACHE_RAM_BASE, |
| 57 | CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE, |
| 58 | (long)car_params->bootloader_car_start, |
| 59 | (long)car_params->bootloader_car_end); |
| 60 | } |
| 61 | |
| 62 | car_soc_post_console_init(); |
| 63 | car_mainboard_post_console_init(); |
| 64 | |
| 65 | /* Ensure the EC is in the right mode for recovery */ |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 66 | if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC) && |
| 67 | !IS_ENABLED(CONFIG_SEPARATE_VERSTAGE)) |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 68 | google_chromeec_early_init(); |
| 69 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 70 | set_fih_car(car_params->fih); |
| 71 | |
Elyes HAOUAS | 7753731 | 2016-07-30 15:37:26 +0200 | [diff] [blame^] | 72 | /* Return new stack value in RAM back to assembly stub. */ |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 73 | return cache_as_ram_stage_main(car_params->fih); |
| 74 | } |
| 75 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 76 | /* Entry point taken when romstage is called after a separate verstage. */ |
| 77 | asmlinkage void *romstage_after_verstage(void) |
| 78 | { |
| 79 | /* Need to locate the current FSP_INFO_HEADER. The cache-as-ram |
| 80 | * is still enabled. We can directly access work buffer here. */ |
| 81 | FSP_INFO_HEADER *fih; |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 82 | struct prog fsp = PROG_INIT(PROG_REFCODE, "fsp.bin"); |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 83 | |
| 84 | console_init(); |
| 85 | |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 86 | if (prog_locate(&fsp)) { |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 87 | fih = NULL; |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 88 | printk(BIOS_ERR, "Unable to locate %s\n", prog_name(&fsp)); |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 89 | } else |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 90 | /* This leaks a mapping which this code assumes is benign as |
| 91 | * the flash is memory mapped CPU's address space. */ |
| 92 | fih = find_fsp((uintptr_t)rdev_mmap_full(prog_rdev(&fsp))); |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 93 | |
| 94 | set_fih_car(fih); |
| 95 | |
Elyes HAOUAS | 7753731 | 2016-07-30 15:37:26 +0200 | [diff] [blame^] | 96 | /* Return new stack value in RAM back to assembly stub. */ |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 97 | return cache_as_ram_stage_main(fih); |
| 98 | } |
| 99 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 100 | asmlinkage void after_cache_as_ram(void *chipset_context) |
| 101 | { |
| 102 | timestamp_add_now(TS_FSP_TEMP_RAM_EXIT_END); |
| 103 | printk(BIOS_DEBUG, "FspTempRamExit returned successfully\n"); |
| 104 | soc_display_mtrrs(); |
| 105 | |
| 106 | after_cache_as_ram_stage(); |
| 107 | } |
| 108 | |
| 109 | void __attribute__((weak)) car_mainboard_pre_console_init(void) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | void __attribute__((weak)) car_soc_pre_console_init(void) |
| 114 | { |
| 115 | } |
| 116 | |
| 117 | void __attribute__((weak)) car_mainboard_post_console_init(void) |
| 118 | { |
| 119 | } |
| 120 | |
| 121 | void __attribute__((weak)) car_soc_post_console_init(void) |
| 122 | { |
| 123 | } |