Lee Leahy | 102f625 | 2016-07-25 07:41:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Lee Leahy | 94b971a | 2017-03-06 08:59:23 -0800 | [diff] [blame] | 4 | * Copyright (C) 2016-2017 Intel Corp. |
Lee Leahy | 102f625 | 2016-07-25 07:41:54 -0700 | [diff] [blame] | 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. |
| 14 | */ |
| 15 | |
Kyösti Mälkki | 6e2d0c1 | 2019-06-28 10:08:51 +0300 | [diff] [blame] | 16 | #include <arch/cpu.h> |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame] | 17 | #include <arch/romstage.h> |
Arthur Heymans | 84e22e3 | 2019-05-25 09:57:27 +0200 | [diff] [blame] | 18 | #include <arch/symbols.h> |
Lee Leahy | 102f625 | 2016-07-25 07:41:54 -0700 | [diff] [blame] | 19 | #include <console/console.h> |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 20 | #include <cbmem.h> |
| 21 | #include "../chip.h" |
| 22 | #include <cpu/x86/cache.h> |
Lee Leahy | 102f625 | 2016-07-25 07:41:54 -0700 | [diff] [blame] | 23 | #include <fsp/util.h> |
Lee Leahy | 16bc9ba | 2017-04-01 20:33:58 -0700 | [diff] [blame] | 24 | #include <soc/iomap.h> |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 25 | #include <soc/pci_devs.h> |
| 26 | #include <soc/pm.h> |
Lee Leahy | 102f625 | 2016-07-25 07:41:54 -0700 | [diff] [blame] | 27 | #include <soc/romstage.h> |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 28 | #include <soc/reg_access.h> |
Lee Leahy | 16bc9ba | 2017-04-01 20:33:58 -0700 | [diff] [blame] | 29 | #include <soc/storage_test.h> |
Lee Leahy | 102f625 | 2016-07-25 07:41:54 -0700 | [diff] [blame] | 30 | |
Kyösti Mälkki | cd7a70f | 2019-08-17 20:51:08 +0300 | [diff] [blame] | 31 | static struct postcar_frame early_mtrrs; |
| 32 | |
Arthur Heymans | be291e8 | 2019-01-06 07:35:11 +0100 | [diff] [blame] | 33 | asmlinkage void car_stage_c_entry(void) |
Lee Leahy | 102f625 | 2016-07-25 07:41:54 -0700 | [diff] [blame] | 34 | { |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 35 | bool s3wake; |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 36 | |
Lee Leahy | 102f625 | 2016-07-25 07:41:54 -0700 | [diff] [blame] | 37 | post_code(0x20); |
| 38 | console_init(); |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 39 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 40 | if (CONFIG(STORAGE_TEST)) { |
Lee Leahy | 16bc9ba | 2017-04-01 20:33:58 -0700 | [diff] [blame] | 41 | uint32_t bar; |
Elyes HAOUAS | 6f01f43 | 2018-12-05 10:56:30 +0100 | [diff] [blame] | 42 | pci_devfn_t dev; |
Lee Leahy | 16bc9ba | 2017-04-01 20:33:58 -0700 | [diff] [blame] | 43 | uint32_t previous_bar; |
| 44 | uint16_t previous_command; |
| 45 | |
| 46 | /* Enable the SD/MMC controller and run the test. Restore |
| 47 | * the BAR and command registers upon completion. |
| 48 | */ |
| 49 | dev = PCI_DEV(0, SD_MMC_DEV, SD_MMC_FUNC); |
| 50 | bar = storage_test_init(dev, &previous_bar, &previous_command); |
| 51 | storage_test(bar, 1); |
| 52 | storage_test_complete(dev, previous_bar, previous_command); |
| 53 | } |
| 54 | |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 55 | /* Initialize DRAM */ |
| 56 | s3wake = fill_power_state() == ACPI_S3; |
| 57 | fsp_memory_init(s3wake); |
| 58 | |
| 59 | /* Disable the ROM shadow 0x000e0000 - 0x000fffff */ |
| 60 | disable_rom_shadow(); |
| 61 | |
| 62 | /* Initialize the PCIe bridges */ |
| 63 | pcie_init(); |
| 64 | |
Kyösti Mälkki | cd7a70f | 2019-08-17 20:51:08 +0300 | [diff] [blame] | 65 | prepare_and_run_postcar(&early_mtrrs); |
| 66 | /* We do not return here. */ |
| 67 | } |
| 68 | |
Arthur Heymans | 84e22e3 | 2019-05-25 09:57:27 +0200 | [diff] [blame] | 69 | static struct chipset_power_state power_state; |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 70 | |
| 71 | struct chipset_power_state *get_power_state(void) |
| 72 | { |
Arthur Heymans | 84e22e3 | 2019-05-25 09:57:27 +0200 | [diff] [blame] | 73 | return &power_state; |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | int fill_power_state(void) |
| 77 | { |
Arthur Heymans | 84e22e3 | 2019-05-25 09:57:27 +0200 | [diff] [blame] | 78 | power_state.prev_sleep_state = 0; |
| 79 | printk(BIOS_SPEW, "prev_sleep_state %d\n", |
| 80 | power_state.prev_sleep_state); |
| 81 | return power_state.prev_sleep_state; |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Andrey Petrov | f796c6e | 2016-11-18 14:57:51 -0800 | [diff] [blame] | 84 | void platform_fsp_memory_init_params_cb(FSPM_UPD *fspm_upd, uint32_t version) |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 85 | { |
Lee Leahy | 44ec92a | 2016-09-28 17:16:44 -0700 | [diff] [blame] | 86 | FSPM_ARCH_UPD *aupd; |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 87 | const struct soc_intel_quark_config *config; |
Lee Leahy | 70bb057 | 2017-03-13 16:37:20 -0700 | [diff] [blame] | 88 | void *rmu_data; |
| 89 | size_t rmu_data_len; |
Lee Leahy | 44ec92a | 2016-09-28 17:16:44 -0700 | [diff] [blame] | 90 | FSP_M_CONFIG *upd; |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 91 | |
| 92 | /* Clear SMI and wake events */ |
| 93 | clear_smi_and_wake_events(); |
| 94 | |
| 95 | /* Locate the RMU data file in flash */ |
Lee Leahy | 70bb057 | 2017-03-13 16:37:20 -0700 | [diff] [blame] | 96 | rmu_data = locate_rmu_file(&rmu_data_len); |
| 97 | if (!rmu_data) |
Keith Short | 1835bf0 | 2019-05-16 11:46:27 -0600 | [diff] [blame] | 98 | die_with_post_code(POST_INVALID_CBFS, |
| 99 | "Microcode file (rmu.bin) not found."); |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 100 | |
| 101 | /* Locate the configuration data from devicetree.cb */ |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame] | 102 | config = config_of_path(LPC_DEV_FUNC); |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 103 | |
| 104 | /* Update the architectural UPD values. */ |
| 105 | aupd = &fspm_upd->FspmArchUpd; |
| 106 | aupd->BootLoaderTolumSize = cbmem_overhead_size(); |
| 107 | aupd->StackBase = (void *)(CONFIG_FSP_ESRAM_LOC - aupd->StackSize); |
| 108 | aupd->BootMode = FSP_BOOT_WITH_FULL_CONFIGURATION; |
| 109 | |
| 110 | /* Display the ESRAM layout */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 111 | if (CONFIG(DISPLAY_ESRAM_LAYOUT)) { |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 112 | printk(BIOS_SPEW, "\nESRAM Layout:\n\n"); |
| 113 | printk(BIOS_SPEW, |
| 114 | "+-------------------+ 0x80080000 - ESRAM end\n"); |
| 115 | printk(BIOS_SPEW, "| FSP binary |\n"); |
| 116 | printk(BIOS_SPEW, |
| 117 | "+-------------------+ 0x%08x (CONFIG_FSP_ESRAM_LOC)\n", |
| 118 | CONFIG_FSP_ESRAM_LOC); |
| 119 | printk(BIOS_SPEW, "| FSP stack |\n"); |
| 120 | printk(BIOS_SPEW, "+-------------------+ 0x%p\n", |
| 121 | aupd->StackBase); |
| 122 | printk(BIOS_SPEW, "| |\n"); |
| 123 | printk(BIOS_SPEW, "+-------------------+ 0x%p\n", |
| 124 | _car_relocatable_data_end); |
| 125 | printk(BIOS_SPEW, "| coreboot data |\n"); |
| 126 | printk(BIOS_SPEW, "+-------------------+ 0x%p\n", |
| 127 | _car_stack_end); |
| 128 | printk(BIOS_SPEW, "| coreboot stack |\n"); |
| 129 | printk(BIOS_SPEW, |
| 130 | "+-------------------+ 0x80000000 - ESRAM start\n\n"); |
| 131 | } |
| 132 | |
| 133 | /* Update the UPD data for MemoryInit */ |
| 134 | upd = &fspm_upd->FspmConfig; |
| 135 | upd->AddrMode = config->AddrMode; |
| 136 | upd->ChanMask = config->ChanMask; |
| 137 | upd->ChanWidth = config->ChanWidth; |
| 138 | upd->DramDensity = config->DramDensity; |
| 139 | upd->DramRonVal = config->DramRonVal; |
| 140 | upd->DramRttNomVal = config->DramRttNomVal; |
| 141 | upd->DramRttWrVal = config->DramRttWrVal; |
| 142 | upd->DramSpeed = config->DramSpeed; |
| 143 | upd->DramType = config->DramType; |
| 144 | upd->DramWidth = config->DramWidth; |
| 145 | upd->EccScrubBlkSize = config->EccScrubBlkSize; |
| 146 | upd->EccScrubInterval = config->EccScrubInterval; |
| 147 | upd->Flags = config->Flags; |
| 148 | upd->FspReservedMemoryLength = config->FspReservedMemoryLength; |
| 149 | upd->RankMask = config->RankMask; |
Lee Leahy | 70bb057 | 2017-03-13 16:37:20 -0700 | [diff] [blame] | 150 | upd->RmuBaseAddress = (uintptr_t)rmu_data; |
| 151 | upd->RmuLength = rmu_data_len; |
Kyösti Mälkki | e613d70 | 2019-02-12 14:16:21 +0200 | [diff] [blame] | 152 | upd->SerialPortWriteChar = !!console_log_level(BIOS_SPEW) |
Lee Leahy | 5e07a7e | 2016-08-06 09:51:35 -0700 | [diff] [blame] | 153 | ? (uintptr_t)fsp_write_line : 0; |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 154 | upd->SmmTsegSize = CONFIG(HAVE_SMI_HANDLER) ? |
Lee Leahy | f26fc0f | 2016-07-25 10:14:07 -0700 | [diff] [blame] | 155 | config->SmmTsegSize : 0; |
| 156 | upd->SocRdOdtVal = config->SocRdOdtVal; |
| 157 | upd->SocWrRonVal = config->SocWrRonVal; |
| 158 | upd->SocWrSlewRate = config->SocWrSlewRate; |
| 159 | upd->SrInt = config->SrInt; |
| 160 | upd->SrTemp = config->SrTemp; |
| 161 | upd->tCL = config->tCL; |
| 162 | upd->tFAW = config->tFAW; |
| 163 | upd->tRAS = config->tRAS; |
| 164 | upd->tRRD = config->tRRD; |
| 165 | upd->tWTR = config->tWTR; |
| 166 | } |