Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2015 Intel Corp. |
| 5 | * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.) |
| 6 | * (Written by Andrey Petrov <andrey.petrov@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. |
Martin Roth | ebabfad | 2016-04-10 11:09:16 -0600 | [diff] [blame] | 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 17 | */ |
| 18 | |
Aaron Durbin | eebe0e0 | 2016-03-18 11:19:38 -0500 | [diff] [blame] | 19 | #include <arch/cpu.h> |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 20 | #include <arch/early_variables.h> |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 21 | #include <arch/io.h> |
| 22 | #include <arch/symbols.h> |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 23 | #include <assert.h> |
Furquan Shaikh | bae6383 | 2016-06-17 15:50:24 -0700 | [diff] [blame] | 24 | #include <bootmode.h> |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 25 | #include <cbfs.h> |
| 26 | #include <cbmem.h> |
| 27 | #include <console/console.h> |
Andrey Petrov | f748f83 | 2016-04-23 13:15:51 -0700 | [diff] [blame] | 28 | #include <cpu/x86/mtrr.h> |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 29 | #include <device/pci_def.h> |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 30 | #include <device/resource.h> |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 31 | #include <fsp/api.h> |
| 32 | #include <fsp/util.h> |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 33 | #include <soc/iomap.h> |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 34 | #include <soc/northbridge.h> |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 35 | #include <soc/pci_devs.h> |
| 36 | #include <soc/pm.h> |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 37 | #include <soc/romstage.h> |
Furquan Shaikh | bae6383 | 2016-06-17 15:50:24 -0700 | [diff] [blame] | 38 | #include <soc/spi.h> |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 39 | #include <soc/uart.h> |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 40 | #include <string.h> |
Alexandru Gagniuc | eaa0a17 | 2016-05-16 16:56:28 -0700 | [diff] [blame] | 41 | #include <timestamp.h> |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 42 | |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 43 | static struct chipset_power_state power_state CAR_GLOBAL; |
| 44 | |
Furquan Shaikh | c681409 | 2016-05-04 16:03:36 -0700 | [diff] [blame] | 45 | /* High Performance Event Timer Configuration */ |
| 46 | #define P2SB_HPTC 0x60 |
| 47 | #define P2SB_HPTC_ADDRESS_ENABLE (1 << 7) |
| 48 | /* |
| 49 | * ADDRESS_SELECT ENCODING_RANGE |
| 50 | * 0 0xFED0 0000 - 0xFED0 03FF |
| 51 | * 1 0xFED0 1000 - 0xFED0 13FF |
| 52 | * 2 0xFED0 2000 - 0xFED0 23FF |
| 53 | * 3 0xFED0 3000 - 0xFED0 33FF |
| 54 | */ |
| 55 | #define P2SB_HPTC_ADDRESS_SELECT_0 (0 << 0) |
| 56 | #define P2SB_HPTC_ADDRESS_SELECT_1 (1 << 0) |
| 57 | #define P2SB_HPTC_ADDRESS_SELECT_2 (2 << 0) |
| 58 | #define P2SB_HPTC_ADDRESS_SELECT_3 (3 << 0) |
| 59 | |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 60 | /* |
| 61 | * Enables several BARs and devices which are needed for memory init |
| 62 | * - MCH_BASE_ADDR is needed in order to talk to the memory controller |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 63 | * - HPET is enabled because FSP wants to store a pointer to global data in the |
| 64 | * HPET comparator register |
| 65 | */ |
| 66 | static void soc_early_romstage_init(void) |
| 67 | { |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 68 | /* Set MCH base address and enable bit */ |
| 69 | pci_write_config32(NB_DEV_ROOT, MCHBAR, MCH_BASE_ADDR | 1); |
| 70 | |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 71 | /* Enable decoding for HPET. Needed for FSP global pointer storage */ |
Furquan Shaikh | c681409 | 2016-05-04 16:03:36 -0700 | [diff] [blame] | 72 | pci_write_config8(P2SB_DEV, P2SB_HPTC, P2SB_HPTC_ADDRESS_SELECT_0 | |
| 73 | P2SB_HPTC_ADDRESS_ENABLE); |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static void disable_watchdog(void) |
| 77 | { |
| 78 | uint32_t reg; |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 79 | |
| 80 | /* Stop TCO timer */ |
Andrey Petrov | 664d585 | 2016-05-15 22:12:35 -0700 | [diff] [blame] | 81 | reg = inl(ACPI_PMIO_BASE + TCO1_CNT); |
| 82 | reg |= TCO_TMR_HLT; |
| 83 | outl(reg, ACPI_PMIO_BASE + TCO1_CNT); |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 86 | static void migrate_power_state(int is_recovery) |
| 87 | { |
| 88 | struct chipset_power_state *ps_cbmem; |
| 89 | struct chipset_power_state *ps_car; |
| 90 | |
| 91 | ps_car = car_get_var_ptr(&power_state); |
| 92 | ps_cbmem = cbmem_add(CBMEM_ID_POWER_STATE, sizeof(*ps_cbmem)); |
| 93 | |
| 94 | if (ps_cbmem == NULL) { |
| 95 | printk(BIOS_DEBUG, "Unable to add power state to cbmem!\n"); |
| 96 | return; |
| 97 | } |
| 98 | memcpy(ps_cbmem, ps_car, sizeof(*ps_cbmem)); |
| 99 | } |
| 100 | ROMSTAGE_CBMEM_INIT_HOOK(migrate_power_state); |
| 101 | |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 102 | asmlinkage void car_stage_entry(void) |
| 103 | { |
Aaron Durbin | eebe0e0 | 2016-03-18 11:19:38 -0500 | [diff] [blame] | 104 | struct postcar_frame pcf; |
Andrey Petrov | f748f83 | 2016-04-23 13:15:51 -0700 | [diff] [blame] | 105 | uintptr_t top_of_ram; |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 106 | bool s3wake; |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 107 | struct chipset_power_state *ps = car_get_var_ptr(&power_state); |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 108 | |
Alexandru Gagniuc | eaa0a17 | 2016-05-16 16:56:28 -0700 | [diff] [blame] | 109 | timestamp_add_now(TS_START_ROMSTAGE); |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 110 | |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 111 | soc_early_romstage_init(); |
Aaron Durbin | 108cd0e | 2016-04-11 15:01:58 -0500 | [diff] [blame] | 112 | disable_watchdog(); |
| 113 | |
Alexandru Gagniuc | 766ba77 | 2016-05-16 16:52:54 -0700 | [diff] [blame] | 114 | console_init(); |
| 115 | |
Aaron Durbin | b430250 | 2016-07-17 17:04:37 -0500 | [diff] [blame] | 116 | s3wake = fill_power_state(ps) == ACPI_S3; |
Ravi Sarawadi | 2da008a | 2016-04-27 15:20:14 -0700 | [diff] [blame] | 117 | |
Aaron Durbin | d04639b | 2016-07-17 23:23:59 -0500 | [diff] [blame] | 118 | if (fsp_memory_init(s3wake) != FSP_SUCCESS) { |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 119 | die("FSP memory init failed. Giving up."); |
| 120 | } |
| 121 | |
Aaron Durbin | eebe0e0 | 2016-03-18 11:19:38 -0500 | [diff] [blame] | 122 | if (postcar_frame_init(&pcf, 1*KiB)) |
| 123 | die("Unable to initialize postcar frame.\n"); |
| 124 | |
Andrey Petrov | f748f83 | 2016-04-23 13:15:51 -0700 | [diff] [blame] | 125 | /* |
| 126 | * We need to make sure ramstage will be run cached. At this point exact |
| 127 | * location of ramstage in cbmem is not known. Instruct postcar to cache |
| 128 | * 16 megs under cbmem top which is a safe bet to cover ramstage. |
| 129 | */ |
| 130 | top_of_ram = (uintptr_t) cbmem_top(); |
| 131 | /* cbmem_top() needs to be at least 16 MiB aligned */ |
| 132 | assert(ALIGN_DOWN(top_of_ram, 16*MiB) == top_of_ram); |
| 133 | postcar_frame_add_mtrr(&pcf, top_of_ram - 16*MiB, 16*MiB, MTRR_TYPE_WRBACK); |
| 134 | |
Aaron Durbin | eebe0e0 | 2016-03-18 11:19:38 -0500 | [diff] [blame] | 135 | run_postcar_phase(&pcf); |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void fill_console_params(struct FSPM_UPD *mupd) |
| 139 | { |
| 140 | if (IS_ENABLED(CONFIG_CONSOLE_SERIAL)) { |
| 141 | mupd->FspmConfig.SerialDebugPortDevice = CONFIG_UART_FOR_CONSOLE; |
| 142 | /* use MMIO port type */ |
| 143 | mupd->FspmConfig.SerialDebugPortType = 2; |
| 144 | /* use 4 byte register stride */ |
| 145 | mupd->FspmConfig.SerialDebugPortStrideSize = 2; |
| 146 | /* used only for port type set to external */ |
| 147 | mupd->FspmConfig.SerialDebugPortAddress = 0; |
| 148 | } else { |
| 149 | mupd->FspmConfig.SerialDebugPortType = 0; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void platform_fsp_memory_init_params_cb(struct FSPM_UPD *mupd) |
| 154 | { |
| 155 | fill_console_params(mupd); |
| 156 | mainboard_memory_init_params(mupd); |
| 157 | |
| 158 | /* Do NOT let FSP do any GPIO pad configuration */ |
Bora Guvendik | de4b09f | 2016-05-09 17:18:26 -0700 | [diff] [blame] | 159 | mupd->FspmConfig.PreMemGpioTablePtr = (uintptr_t) NULL; |
Andrey Petrov | 24a594f | 2016-06-28 17:37:09 -0700 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * Tell CSE we do not need to use Ring Buffer Protocol (RBP) to fetch |
| 163 | * firmware for us if we are using memory-mapped SPI. This lets CSE |
| 164 | * state machine transition to next boot state, so that it can function |
| 165 | * as designed. |
| 166 | */ |
| 167 | mupd->FspmConfig.SkipCseRbp = IS_ENABLED(CONFIG_SPI_FLASH_MEMORY_MAPPED); |
Andrey Petrov | b483146 | 2016-02-25 17:42:25 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | __attribute__ ((weak)) |
| 171 | void mainboard_memory_init_params(struct FSPM_UPD *mupd) |
| 172 | { |
| 173 | printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__); |
| 174 | } |
Furquan Shaikh | bae6383 | 2016-06-17 15:50:24 -0700 | [diff] [blame] | 175 | |
| 176 | int get_sw_write_protect_state(void) |
| 177 | { |
| 178 | uint8_t status; |
| 179 | |
| 180 | /* Return unprotected status if status read fails. */ |
| 181 | return spi_read_status(&status) ? 0 : !!(status & 0x80); |
| 182 | } |