2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-01-16 14:03:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Google, Inc
|
|
|
|
*/
|
|
|
|
|
2023-07-16 03:39:11 +00:00
|
|
|
#define LOG_CATEGORY LOGC_BOOT
|
|
|
|
|
2017-01-16 14:03:56 +00:00
|
|
|
#include <common.h>
|
2019-11-14 19:57:37 +00:00
|
|
|
#include <cpu_func.h>
|
2017-01-16 14:03:56 +00:00
|
|
|
#include <debug_uart.h>
|
2019-10-21 03:37:49 +00:00
|
|
|
#include <dm.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <image.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2019-11-14 19:57:41 +00:00
|
|
|
#include <irq_func.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2019-05-02 16:52:12 +00:00
|
|
|
#include <malloc.h>
|
2017-01-16 14:03:56 +00:00
|
|
|
#include <spl.h>
|
2019-10-21 03:37:49 +00:00
|
|
|
#include <syscon.h>
|
2023-07-16 03:39:01 +00:00
|
|
|
#include <vesa.h>
|
2017-01-16 14:03:56 +00:00
|
|
|
#include <asm/cpu.h>
|
2019-10-21 03:37:49 +00:00
|
|
|
#include <asm/cpu_common.h>
|
2022-03-04 15:43:05 +00:00
|
|
|
#include <asm/fsp2/fsp_api.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2023-07-16 03:38:36 +00:00
|
|
|
#include <asm/mp.h>
|
2019-05-02 16:52:12 +00:00
|
|
|
#include <asm/mrccache.h>
|
2017-01-16 14:03:56 +00:00
|
|
|
#include <asm/mtrr.h>
|
2019-10-21 03:37:49 +00:00
|
|
|
#include <asm/pci.h>
|
2017-01-16 14:03:56 +00:00
|
|
|
#include <asm/processor.h>
|
2023-07-30 17:16:01 +00:00
|
|
|
#include <asm/qemu.h>
|
2019-09-25 14:11:39 +00:00
|
|
|
#include <asm/spl.h>
|
2017-01-16 14:03:56 +00:00
|
|
|
#include <asm-generic/sections.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2022-03-04 15:43:05 +00:00
|
|
|
__weak int fsp_setup_pinctrl(void *ctx, struct event *event)
|
2017-01-18 11:32:53 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-21 03:37:49 +00:00
|
|
|
#ifdef CONFIG_TPL
|
|
|
|
|
|
|
|
static int set_max_freq(void)
|
|
|
|
{
|
|
|
|
if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
|
|
|
|
/*
|
|
|
|
* Burst Mode has been factory-configured as disabled and is not
|
|
|
|
* available in this physical processor package
|
|
|
|
*/
|
|
|
|
debug("Burst Mode is factory-disabled\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable burst mode */
|
|
|
|
cpu_set_burst_mode(true);
|
|
|
|
|
|
|
|
/* Enable speed step */
|
|
|
|
cpu_set_eist(true);
|
|
|
|
|
|
|
|
/* Set P-State ratio */
|
|
|
|
cpu_set_p_state_to_turbo_ratio();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-16 14:03:56 +00:00
|
|
|
static int x86_spl_init(void)
|
|
|
|
{
|
2023-07-16 03:39:13 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
|
2019-05-02 16:52:12 +00:00
|
|
|
#ifndef CONFIG_TPL
|
2017-01-16 14:03:56 +00:00
|
|
|
/*
|
|
|
|
* TODO(sjg@chromium.org): We use this area of RAM for the stack
|
|
|
|
* and global_data in SPL. Once U-Boot starts up and releocates it
|
|
|
|
* is not needed. We could make this a CONFIG option or perhaps
|
2022-10-21 00:22:39 +00:00
|
|
|
* place it immediately below CONFIG_TEXT_BASE.
|
2017-01-16 14:03:56 +00:00
|
|
|
*/
|
2020-05-01 03:21:42 +00:00
|
|
|
__maybe_unused char *ptr = (char *)0x110000;
|
2019-10-21 03:37:49 +00:00
|
|
|
#else
|
|
|
|
struct udevice *punit;
|
2019-05-02 16:52:12 +00:00
|
|
|
#endif
|
2017-01-16 14:03:56 +00:00
|
|
|
int ret;
|
|
|
|
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("x86 spl starting\n");
|
2019-10-21 03:37:55 +00:00
|
|
|
if (IS_ENABLED(TPL))
|
|
|
|
ret = x86_cpu_reinit_f();
|
|
|
|
else
|
|
|
|
ret = x86_cpu_init_f();
|
2017-01-16 14:03:56 +00:00
|
|
|
ret = spl_init();
|
|
|
|
if (ret) {
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("spl_init() failed (err=%d)\n", ret);
|
2017-01-16 14:03:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = arch_cpu_init();
|
|
|
|
if (ret) {
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("arch_cpu_init() failed (err=%d)\n", ret);
|
2017-01-16 14:03:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2019-05-02 16:52:12 +00:00
|
|
|
#ifndef CONFIG_TPL
|
2022-03-04 15:43:05 +00:00
|
|
|
ret = fsp_setup_pinctrl(NULL, NULL);
|
2017-01-16 14:03:56 +00:00
|
|
|
if (ret) {
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("fsp_setup_pinctrl() failed (err=%d)\n", ret);
|
2017-01-16 14:03:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2019-05-02 16:52:12 +00:00
|
|
|
#endif
|
2023-07-16 03:39:00 +00:00
|
|
|
/*
|
|
|
|
* spl_board_init() below sets up the console if enabled. If it isn't,
|
|
|
|
* do it here. We cannot call this twice since it results in a double
|
|
|
|
* banner and CI tests fail.
|
|
|
|
*/
|
|
|
|
if (!IS_ENABLED(CONFIG_SPL_BOARD_INIT))
|
|
|
|
preloader_console_init();
|
2021-03-15 05:11:18 +00:00
|
|
|
#if !defined(CONFIG_TPL) && !CONFIG_IS_ENABLED(CPU)
|
2017-01-16 14:03:56 +00:00
|
|
|
ret = print_cpuinfo();
|
|
|
|
if (ret) {
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("print_cpuinfo() failed (err=%d)\n", ret);
|
2017-01-16 14:03:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2019-05-02 16:52:12 +00:00
|
|
|
#endif
|
2023-07-16 03:39:13 +00:00
|
|
|
/* probe the LPC so we get the GPIO_BASE set up correctly */
|
|
|
|
ret = uclass_first_device_err(UCLASS_LPC, &dev);
|
|
|
|
if (ret && ret != -ENODEV) {
|
|
|
|
log_debug("lpc probe failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-01-16 14:03:56 +00:00
|
|
|
ret = dram_init();
|
|
|
|
if (ret) {
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("dram_init() failed (err=%d)\n", ret);
|
2017-01-16 14:03:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("mrc\n");
|
2019-05-02 16:52:12 +00:00
|
|
|
if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
|
|
|
|
ret = mrccache_spl_save();
|
|
|
|
if (ret)
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("Failed to write to mrccache (err=%d)\n",
|
|
|
|
ret);
|
2019-05-02 16:52:12 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 03:21:42 +00:00
|
|
|
#ifndef CONFIG_SYS_COREBOOT
|
2023-05-04 22:50:54 +00:00
|
|
|
debug("BSS clear from %lx to %lx len %lx\n", (ulong)&__bss_start,
|
|
|
|
(ulong)&__bss_end, (ulong)&__bss_end - (ulong)&__bss_start);
|
2017-01-16 14:03:56 +00:00
|
|
|
memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
|
2021-01-24 17:06:10 +00:00
|
|
|
# ifndef CONFIG_TPL
|
2017-01-16 14:03:56 +00:00
|
|
|
|
|
|
|
/* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
|
|
|
|
ret = interrupt_init();
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: interrupt_init() failed\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The stack grows down from ptr. Put the global data at ptr. This
|
|
|
|
* will only be used for SPL. Once SPL loads U-Boot proper it will
|
|
|
|
* set up its own stack.
|
|
|
|
*/
|
|
|
|
gd->new_gd = (struct global_data *)ptr;
|
|
|
|
memcpy(gd->new_gd, gd, sizeof(*gd));
|
2023-07-16 03:39:05 +00:00
|
|
|
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("logging\n");
|
2023-07-16 03:39:05 +00:00
|
|
|
/*
|
|
|
|
* Make sure logging is disabled when we switch, since the log system
|
|
|
|
* list head will move
|
|
|
|
*/
|
|
|
|
gd->new_gd->flags &= ~GD_FLG_LOG_READY;
|
2017-01-16 14:03:56 +00:00
|
|
|
arch_setup_gd(gd->new_gd);
|
|
|
|
gd->start_addr_sp = (ulong)ptr;
|
|
|
|
|
2023-07-16 03:39:05 +00:00
|
|
|
/* start up logging again, with the new list-head location */
|
|
|
|
ret = log_init();
|
|
|
|
if (ret) {
|
|
|
|
log_debug("Log setup failed (err=%d)\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-07-16 03:38:36 +00:00
|
|
|
if (_LOG_DEBUG) {
|
|
|
|
ret = mtrr_list(mtrr_get_var_count(), MP_SELECT_BSP);
|
|
|
|
if (ret)
|
|
|
|
printf("mtrr_list failed\n");
|
|
|
|
}
|
|
|
|
|
2017-01-16 14:03:56 +00:00
|
|
|
/* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
|
|
|
|
ret = mtrr_add_request(MTRR_TYPE_WRBACK,
|
|
|
|
(1ULL << 32) - CONFIG_XIP_ROM_SIZE,
|
|
|
|
CONFIG_XIP_ROM_SIZE);
|
|
|
|
if (ret) {
|
2019-05-02 16:52:12 +00:00
|
|
|
debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
|
2017-01-16 14:03:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2020-05-01 03:21:42 +00:00
|
|
|
# else
|
2019-10-21 03:37:49 +00:00
|
|
|
ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
|
|
|
|
if (ret)
|
|
|
|
debug("Could not find PUNIT (err=%d)\n", ret);
|
|
|
|
|
|
|
|
ret = set_max_freq();
|
|
|
|
if (ret)
|
|
|
|
debug("Failed to set CPU frequency (err=%d)\n", ret);
|
2020-05-01 03:21:42 +00:00
|
|
|
# endif
|
2019-05-02 16:52:12 +00:00
|
|
|
#endif
|
2023-07-16 03:39:11 +00:00
|
|
|
log_debug("done\n");
|
2017-01-16 14:03:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void board_init_f(ulong flags)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = x86_spl_init();
|
|
|
|
if (ret) {
|
2020-05-27 12:58:48 +00:00
|
|
|
printf("x86_spl_init: error %d\n", ret);
|
|
|
|
hang();
|
2017-01-16 14:03:56 +00:00
|
|
|
}
|
2020-05-01 03:21:42 +00:00
|
|
|
#if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT)
|
2019-05-02 16:52:12 +00:00
|
|
|
gd->bd = malloc(sizeof(*gd->bd));
|
|
|
|
if (!gd->bd) {
|
|
|
|
printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
board_init_r(gd, 0);
|
|
|
|
#else
|
2017-01-16 14:03:56 +00:00
|
|
|
/* Uninit CAR and jump to board_init_f_r() */
|
|
|
|
board_init_f_r_trampoline(gd->start_addr_sp);
|
2019-05-02 16:52:12 +00:00
|
|
|
#endif
|
2017-01-16 14:03:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void board_init_f_r(void)
|
|
|
|
{
|
2023-05-04 22:50:57 +00:00
|
|
|
mtrr_commit(false);
|
|
|
|
init_cache();
|
2017-01-16 14:03:56 +00:00
|
|
|
gd->flags &= ~GD_FLG_SERIAL_READY;
|
|
|
|
debug("cache status %d\n", dcache_status());
|
|
|
|
board_init_r(gd, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 spl_boot_device(void)
|
|
|
|
{
|
2019-09-25 14:11:39 +00:00
|
|
|
return BOOT_DEVICE_SPI_MMAP;
|
2017-01-16 14:03:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int spl_start_uboot(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void spl_board_announce_boot_device(void)
|
|
|
|
{
|
|
|
|
printf("SPI flash");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spl_board_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
|
|
|
{
|
|
|
|
spl_image->size = CONFIG_SYS_MONITOR_LEN;
|
2022-10-21 00:22:39 +00:00
|
|
|
spl_image->entry_point = CONFIG_TEXT_BASE;
|
|
|
|
spl_image->load_addr = CONFIG_TEXT_BASE;
|
2017-01-16 14:03:56 +00:00
|
|
|
spl_image->os = IH_OS_U_BOOT;
|
|
|
|
spl_image->name = "U-Boot";
|
|
|
|
|
2020-05-01 03:21:41 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) {
|
2023-05-04 22:50:55 +00:00
|
|
|
/* Copy U-Boot from ROM */
|
|
|
|
memcpy((void *)spl_image->load_addr,
|
|
|
|
(void *)spl_get_image_pos(), spl_get_image_size());
|
2020-05-01 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 14:03:56 +00:00
|
|
|
debug("Loading to %lx\n", spl_image->load_addr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-09-25 14:11:39 +00:00
|
|
|
SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
|
2017-01-16 14:03:56 +00:00
|
|
|
|
|
|
|
int spl_spi_load_image(void)
|
|
|
|
{
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2019-05-02 16:52:12 +00:00
|
|
|
#ifdef CONFIG_X86_RUN_64BIT
|
2017-01-16 14:03:56 +00:00
|
|
|
void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
|
|
|
|
ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
|
|
|
|
debug("ret=%d\n", ret);
|
2019-09-25 14:11:38 +00:00
|
|
|
hang();
|
2017-01-16 14:03:56 +00:00
|
|
|
}
|
2019-05-02 16:52:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void spl_board_init(void)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_TPL
|
|
|
|
preloader_console_init();
|
|
|
|
#endif
|
2023-07-30 17:16:01 +00:00
|
|
|
if (IS_ENABLED(CONFIG_QEMU))
|
|
|
|
qemu_chipset_init();
|
2023-07-16 03:39:01 +00:00
|
|
|
|
|
|
|
if (CONFIG_IS_ENABLED(VIDEO)) {
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
/* Set up PCI video in SPL if required */
|
|
|
|
uclass_first_device_err(UCLASS_PCI, &dev);
|
|
|
|
uclass_first_device_err(UCLASS_VIDEO, &dev);
|
|
|
|
}
|
2019-05-02 16:52:12 +00:00
|
|
|
}
|