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> |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 18 | #include <cpu/x86/mtrr.h> |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 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 <timestamp.h> |
| 23 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 24 | FSP_INFO_HEADER *fih_car CAR_GLOBAL; |
| 25 | |
| 26 | /* Save FSP_INFO_HEADER for TempRamExit() call in assembly. */ |
| 27 | static inline void set_fih_car(FSP_INFO_HEADER *fih) |
| 28 | { |
| 29 | /* This variable is written in the raw form because it's only |
| 30 | * ever accessed in code that that has the cache-as-ram enabled. The |
| 31 | * assembly routine which tears down cache-as-ram utilizes this |
| 32 | * variable for determining where to find FSP. */ |
| 33 | fih_car = fih; |
| 34 | } |
| 35 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 36 | asmlinkage void *cache_as_ram_main(struct cache_as_ram_params *car_params) |
| 37 | { |
Arthur Heymans | 61b22cb | 2019-01-08 23:25:04 +0100 | [diff] [blame] | 38 | int i; |
| 39 | const int num_guards = 4; |
| 40 | const u32 stack_guard = 0xdeadbeef; |
| 41 | u32 *stack_base; |
Arthur Heymans | ec3c8b5 | 2019-01-12 11:44:08 +0100 | [diff] [blame] | 42 | void *ram_stack; |
Arthur Heymans | 61b22cb | 2019-01-08 23:25:04 +0100 | [diff] [blame] | 43 | u32 size; |
| 44 | |
| 45 | /* Size of unallocated CAR. */ |
| 46 | size = _car_region_end - _car_relocatable_data_end; |
| 47 | size = ALIGN_DOWN(size, 16); |
| 48 | |
| 49 | stack_base = (u32 *) (_car_region_end - size); |
| 50 | |
| 51 | for (i = 0; i < num_guards; i++) |
| 52 | stack_base[i] = stack_guard; |
| 53 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 54 | /* Initialize timestamp book keeping only once. */ |
| 55 | timestamp_init(car_params->tsc); |
| 56 | |
| 57 | /* Call into pre-console init code then initialize console. */ |
| 58 | car_soc_pre_console_init(); |
| 59 | car_mainboard_pre_console_init(); |
| 60 | console_init(); |
| 61 | |
| 62 | printk(BIOS_DEBUG, "FSP TempRamInit successful\n"); |
| 63 | |
| 64 | printk(BIOS_SPEW, "bist: 0x%08x\n", car_params->bist); |
| 65 | printk(BIOS_SPEW, "tsc: 0x%016llx\n", car_params->tsc); |
| 66 | |
Arthur Heymans | e124fa5 | 2019-01-12 11:48:37 +0100 | [diff] [blame^] | 67 | display_mtrrs(); |
| 68 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 69 | if (car_params->bootloader_car_start != CONFIG_DCACHE_RAM_BASE || |
| 70 | car_params->bootloader_car_end != |
| 71 | (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE)) { |
| 72 | printk(BIOS_INFO, "CAR mismatch: %08x--%08x vs %08lx--%08lx\n", |
| 73 | CONFIG_DCACHE_RAM_BASE, |
| 74 | CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE, |
| 75 | (long)car_params->bootloader_car_start, |
| 76 | (long)car_params->bootloader_car_end); |
| 77 | } |
| 78 | |
| 79 | car_soc_post_console_init(); |
| 80 | car_mainboard_post_console_init(); |
| 81 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 82 | set_fih_car(car_params->fih); |
| 83 | |
Arthur Heymans | ec3c8b5 | 2019-01-12 11:44:08 +0100 | [diff] [blame] | 84 | /* Return new stack value in RAM back to assembly stub. */ |
| 85 | ram_stack = cache_as_ram_stage_main(car_params->fih); |
| 86 | |
Arthur Heymans | 61b22cb | 2019-01-08 23:25:04 +0100 | [diff] [blame] | 87 | /* Check the stack. */ |
| 88 | for (i = 0; i < num_guards; i++) { |
| 89 | if (stack_base[i] == stack_guard) |
| 90 | continue; |
| 91 | printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); |
| 92 | } |
| 93 | |
Arthur Heymans | ec3c8b5 | 2019-01-12 11:44:08 +0100 | [diff] [blame] | 94 | return ram_stack; |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 97 | /* Entry point taken when romstage is called after a separate verstage. */ |
Teo Boon Tiong | d8e34b2 | 2016-12-28 18:56:26 +0800 | [diff] [blame] | 98 | asmlinkage void *romstage_c_entry(void) |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 99 | { |
| 100 | /* Need to locate the current FSP_INFO_HEADER. The cache-as-ram |
| 101 | * is still enabled. We can directly access work buffer here. */ |
| 102 | FSP_INFO_HEADER *fih; |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 103 | struct prog fsp = PROG_INIT(PROG_REFCODE, "fsp.bin"); |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 104 | |
| 105 | console_init(); |
| 106 | |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 107 | if (prog_locate(&fsp)) { |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 108 | fih = NULL; |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 109 | printk(BIOS_ERR, "Unable to locate %s\n", prog_name(&fsp)); |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 110 | } else |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 111 | /* This leaks a mapping which this code assumes is benign as |
| 112 | * the flash is memory mapped CPU's address space. */ |
| 113 | fih = find_fsp((uintptr_t)rdev_mmap_full(prog_rdev(&fsp))); |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 114 | |
| 115 | set_fih_car(fih); |
| 116 | |
Elyes HAOUAS | 7753731 | 2016-07-30 15:37:26 +0200 | [diff] [blame] | 117 | /* Return new stack value in RAM back to assembly stub. */ |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 118 | return cache_as_ram_stage_main(fih); |
| 119 | } |
| 120 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 121 | asmlinkage void after_cache_as_ram(void *chipset_context) |
| 122 | { |
| 123 | timestamp_add_now(TS_FSP_TEMP_RAM_EXIT_END); |
| 124 | printk(BIOS_DEBUG, "FspTempRamExit returned successfully\n"); |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 125 | display_mtrrs(); |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 126 | |
| 127 | after_cache_as_ram_stage(); |
| 128 | } |
| 129 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 130 | void __weak car_mainboard_pre_console_init(void) |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 131 | { |
| 132 | } |
| 133 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 134 | void __weak car_soc_pre_console_init(void) |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 135 | { |
| 136 | } |
| 137 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 138 | void __weak car_mainboard_post_console_init(void) |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 139 | { |
| 140 | } |
| 141 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 142 | void __weak car_soc_post_console_init(void) |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 143 | { |
| 144 | } |