blob: da7fcf10b7c0f5166ba89b13bfcae770d8e06708 [file] [log] [blame]
Andrey Petrovb4831462016-02-25 17:42:25 -08001/*
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 Rothebabfad2016-04-10 11:09:16 -060012 *
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 Petrovb4831462016-02-25 17:42:25 -080017 */
18
Aaron Durbineebe0e02016-03-18 11:19:38 -050019#include <arch/cpu.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070020#include <arch/early_variables.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080021#include <arch/io.h>
22#include <arch/symbols.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070023#include <assert.h>
Furquan Shaikhbae63832016-06-17 15:50:24 -070024#include <bootmode.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080025#include <cbfs.h>
26#include <cbmem.h>
27#include <console/console.h>
Andrey Petrovf748f832016-04-23 13:15:51 -070028#include <cpu/x86/mtrr.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080029#include <device/pci_def.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070030#include <device/resource.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080031#include <fsp/api.h>
32#include <fsp/util.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070033#include <soc/iomap.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080034#include <soc/northbridge.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070035#include <soc/pci_devs.h>
36#include <soc/pm.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080037#include <soc/romstage.h>
Furquan Shaikhbae63832016-06-17 15:50:24 -070038#include <soc/spi.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080039#include <soc/uart.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070040#include <string.h>
Alexandru Gagniuceaa0a172016-05-16 16:56:28 -070041#include <timestamp.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080042
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070043static struct chipset_power_state power_state CAR_GLOBAL;
44
Furquan Shaikhc6814092016-05-04 16:03:36 -070045/* 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 Petrovb4831462016-02-25 17:42:25 -080060/*
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 Petrovb4831462016-02-25 17:42:25 -080063 * - HPET is enabled because FSP wants to store a pointer to global data in the
64 * HPET comparator register
65 */
66static void soc_early_romstage_init(void)
67{
Andrey Petrovb4831462016-02-25 17:42:25 -080068 /* Set MCH base address and enable bit */
69 pci_write_config32(NB_DEV_ROOT, MCHBAR, MCH_BASE_ADDR | 1);
70
Andrey Petrovb4831462016-02-25 17:42:25 -080071 /* Enable decoding for HPET. Needed for FSP global pointer storage */
Furquan Shaikhc6814092016-05-04 16:03:36 -070072 pci_write_config8(P2SB_DEV, P2SB_HPTC, P2SB_HPTC_ADDRESS_SELECT_0 |
73 P2SB_HPTC_ADDRESS_ENABLE);
Andrey Petrovb4831462016-02-25 17:42:25 -080074}
75
76static void disable_watchdog(void)
77{
78 uint32_t reg;
Andrey Petrovb4831462016-02-25 17:42:25 -080079
80 /* Stop TCO timer */
Andrey Petrov664d5852016-05-15 22:12:35 -070081 reg = inl(ACPI_PMIO_BASE + TCO1_CNT);
82 reg |= TCO_TMR_HLT;
83 outl(reg, ACPI_PMIO_BASE + TCO1_CNT);
Andrey Petrovb4831462016-02-25 17:42:25 -080084}
85
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070086static 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}
100ROMSTAGE_CBMEM_INIT_HOOK(migrate_power_state);
101
Andrey Petrovb4831462016-02-25 17:42:25 -0800102asmlinkage void car_stage_entry(void)
103{
Aaron Durbineebe0e02016-03-18 11:19:38 -0500104 struct postcar_frame pcf;
Andrey Petrovf748f832016-04-23 13:15:51 -0700105 uintptr_t top_of_ram;
Aaron Durbinb4302502016-07-17 17:04:37 -0500106 bool s3wake;
Ravi Sarawadi2da008a2016-04-27 15:20:14 -0700107 struct chipset_power_state *ps = car_get_var_ptr(&power_state);
Andrey Petrovb4831462016-02-25 17:42:25 -0800108
Alexandru Gagniuceaa0a172016-05-16 16:56:28 -0700109 timestamp_add_now(TS_START_ROMSTAGE);
Andrey Petrovb4831462016-02-25 17:42:25 -0800110
Andrey Petrovb4831462016-02-25 17:42:25 -0800111 soc_early_romstage_init();
Aaron Durbin108cd0e2016-04-11 15:01:58 -0500112 disable_watchdog();
113
Alexandru Gagniuc766ba772016-05-16 16:52:54 -0700114 console_init();
115
Aaron Durbinb4302502016-07-17 17:04:37 -0500116 s3wake = fill_power_state(ps) == ACPI_S3;
Ravi Sarawadi2da008a2016-04-27 15:20:14 -0700117
Aaron Durbind04639b2016-07-17 23:23:59 -0500118 if (fsp_memory_init(s3wake) != FSP_SUCCESS) {
Andrey Petrovb4831462016-02-25 17:42:25 -0800119 die("FSP memory init failed. Giving up.");
120 }
121
Aaron Durbineebe0e02016-03-18 11:19:38 -0500122 if (postcar_frame_init(&pcf, 1*KiB))
123 die("Unable to initialize postcar frame.\n");
124
Andrey Petrovf748f832016-04-23 13:15:51 -0700125 /*
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 Durbineebe0e02016-03-18 11:19:38 -0500135 run_postcar_phase(&pcf);
Andrey Petrovb4831462016-02-25 17:42:25 -0800136}
137
138static 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
153void 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 Guvendikde4b09f2016-05-09 17:18:26 -0700159 mupd->FspmConfig.PreMemGpioTablePtr = (uintptr_t) NULL;
Andrey Petrov24a594f2016-06-28 17:37:09 -0700160
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 Petrovb4831462016-02-25 17:42:25 -0800168}
169
170__attribute__ ((weak))
171void mainboard_memory_init_params(struct FSPM_UPD *mupd)
172{
173 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
174}
Furquan Shaikhbae63832016-06-17 15:50:24 -0700175
176int 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}