2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-11-18 00:14:45 +00:00
|
|
|
/*
|
2011-04-13 09:43:26 +00:00
|
|
|
* (C) Copyright 2008-2011
|
|
|
|
* Graeme Russ, <graeme.russ@gmail.com>
|
|
|
|
*
|
2002-11-18 00:14:45 +00:00
|
|
|
* (C) Copyright 2002
|
2011-08-04 16:45:45 +00:00
|
|
|
* Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
|
2003-06-27 21:31:46 +00:00
|
|
|
*
|
2002-11-18 00:14:45 +00:00
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Alex Zuepke <azu@sysgo.de>
|
|
|
|
*
|
2014-11-09 14:18:56 +00:00
|
|
|
* Part of this file is adapted from coreboot
|
|
|
|
* src/arch/x86/lib/cpu.c
|
2002-11-18 00:14:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2019-11-14 19:57:37 +00:00
|
|
|
#include <cpu_func.h>
|
2015-06-17 03:15:36 +00:00
|
|
|
#include <dm.h>
|
2014-10-10 14:21:55 +00:00
|
|
|
#include <errno.h>
|
2019-12-28 17:44:56 +00:00
|
|
|
#include <init.h>
|
2014-10-10 14:21:55 +00:00
|
|
|
#include <malloc.h>
|
2016-06-08 12:07:38 +00:00
|
|
|
#include <syscon.h>
|
2020-04-08 22:57:35 +00:00
|
|
|
#include <acpi/acpi_s3.h>
|
2020-04-08 22:57:36 +00:00
|
|
|
#include <acpi/acpi_table.h>
|
2018-07-19 04:42:15 +00:00
|
|
|
#include <asm/acpi.h>
|
2012-12-02 04:49:50 +00:00
|
|
|
#include <asm/control_regs.h>
|
2016-05-11 14:45:01 +00:00
|
|
|
#include <asm/coreboot_tables.h>
|
2014-10-10 14:21:55 +00:00
|
|
|
#include <asm/cpu.h>
|
2015-06-17 03:15:36 +00:00
|
|
|
#include <asm/lapic.h>
|
2016-03-12 05:07:11 +00:00
|
|
|
#include <asm/microcode.h>
|
2015-06-17 03:15:36 +00:00
|
|
|
#include <asm/mp.h>
|
2016-05-11 14:45:00 +00:00
|
|
|
#include <asm/mrccache.h>
|
2015-07-06 08:31:30 +00:00
|
|
|
#include <asm/msr.h>
|
|
|
|
#include <asm/mtrr.h>
|
2014-11-13 05:42:26 +00:00
|
|
|
#include <asm/post.h>
|
2011-02-12 04:11:30 +00:00
|
|
|
#include <asm/processor.h>
|
2011-02-12 04:11:32 +00:00
|
|
|
#include <asm/processor-flags.h>
|
2008-12-06 23:29:02 +00:00
|
|
|
#include <asm/interrupt.h>
|
2015-04-24 10:10:04 +00:00
|
|
|
#include <asm/tables.h>
|
2011-11-16 23:32:50 +00:00
|
|
|
#include <linux/compiler.h>
|
2002-11-18 00:14:45 +00:00
|
|
|
|
2014-11-09 14:18:56 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2019-12-07 04:41:51 +00:00
|
|
|
#ifndef CONFIG_TPL_BUILD
|
2014-11-09 14:18:56 +00:00
|
|
|
static const char *const x86_vendor_name[] = {
|
|
|
|
[X86_VENDOR_INTEL] = "Intel",
|
|
|
|
[X86_VENDOR_CYRIX] = "Cyrix",
|
|
|
|
[X86_VENDOR_AMD] = "AMD",
|
|
|
|
[X86_VENDOR_UMC] = "UMC",
|
|
|
|
[X86_VENDOR_NEXGEN] = "NexGen",
|
|
|
|
[X86_VENDOR_CENTAUR] = "Centaur",
|
|
|
|
[X86_VENDOR_RISE] = "Rise",
|
|
|
|
[X86_VENDOR_TRANSMETA] = "Transmeta",
|
|
|
|
[X86_VENDOR_NSC] = "NSC",
|
|
|
|
[X86_VENDOR_SIS] = "SiS",
|
|
|
|
};
|
2019-12-07 04:41:51 +00:00
|
|
|
#endif
|
2014-11-09 14:18:56 +00:00
|
|
|
|
2012-10-20 12:33:10 +00:00
|
|
|
int __weak x86_cleanup_before_linux(void)
|
|
|
|
{
|
2013-04-17 16:13:35 +00:00
|
|
|
#ifdef CONFIG_BOOTSTAGE_STASH
|
2015-03-03 00:04:37 +00:00
|
|
|
bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
|
2013-04-17 16:13:35 +00:00
|
|
|
CONFIG_BOOTSTAGE_STASH_SIZE);
|
|
|
|
#endif
|
|
|
|
|
2012-10-20 12:33:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-27 11:46:43 +00:00
|
|
|
int x86_init_cache(void)
|
|
|
|
{
|
|
|
|
enable_caches();
|
2011-02-12 04:11:35 +00:00
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-12-27 11:46:43 +00:00
|
|
|
int init_cache(void) __attribute__((weak, alias("x86_init_cache")));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
2011-11-08 02:33:13 +00:00
|
|
|
void flush_cache(unsigned long dummy1, unsigned long dummy2)
|
2002-11-18 00:14:45 +00:00
|
|
|
{
|
|
|
|
asm("wbinvd\n");
|
|
|
|
}
|
2008-12-06 23:29:02 +00:00
|
|
|
|
2012-12-02 04:49:50 +00:00
|
|
|
/* Define these functions to allow ehch-hcd to function */
|
|
|
|
void flush_dcache_range(unsigned long start, unsigned long stop)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void invalidate_dcache_range(unsigned long start, unsigned long stop)
|
|
|
|
{
|
|
|
|
}
|
2013-02-28 19:26:11 +00:00
|
|
|
|
|
|
|
void dcache_enable(void)
|
|
|
|
{
|
|
|
|
enable_caches();
|
|
|
|
}
|
|
|
|
|
|
|
|
void dcache_disable(void)
|
|
|
|
{
|
|
|
|
disable_caches();
|
|
|
|
}
|
|
|
|
|
|
|
|
void icache_enable(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void icache_disable(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int icache_status(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2014-10-10 14:21:52 +00:00
|
|
|
|
2019-12-07 04:41:51 +00:00
|
|
|
#ifndef CONFIG_TPL_BUILD
|
2014-11-09 14:18:56 +00:00
|
|
|
const char *cpu_vendor_name(int vendor)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
name = "<invalid cpu vendor>";
|
2017-11-20 18:45:56 +00:00
|
|
|
if (vendor < ARRAY_SIZE(x86_vendor_name) &&
|
|
|
|
x86_vendor_name[vendor])
|
2014-11-09 14:18:56 +00:00
|
|
|
name = x86_vendor_name[vendor];
|
2014-10-10 14:21:54 +00:00
|
|
|
|
2014-11-09 14:18:56 +00:00
|
|
|
return name;
|
2014-10-10 14:21:54 +00:00
|
|
|
}
|
2019-12-07 04:41:51 +00:00
|
|
|
#endif
|
2014-10-10 14:21:54 +00:00
|
|
|
|
2014-11-11 01:00:26 +00:00
|
|
|
char *cpu_get_name(char *name)
|
2014-10-10 14:21:54 +00:00
|
|
|
{
|
2014-11-11 01:00:26 +00:00
|
|
|
unsigned int *name_as_ints = (unsigned int *)name;
|
2014-11-09 14:18:56 +00:00
|
|
|
struct cpuid_result regs;
|
2014-11-11 01:00:26 +00:00
|
|
|
char *ptr;
|
2014-11-09 14:18:56 +00:00
|
|
|
int i;
|
2014-10-10 14:21:54 +00:00
|
|
|
|
2014-11-11 01:00:26 +00:00
|
|
|
/* This bit adds up to 48 bytes */
|
2014-11-09 14:18:56 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
regs = cpuid(0x80000002 + i);
|
|
|
|
name_as_ints[i * 4 + 0] = regs.eax;
|
|
|
|
name_as_ints[i * 4 + 1] = regs.ebx;
|
|
|
|
name_as_ints[i * 4 + 2] = regs.ecx;
|
|
|
|
name_as_ints[i * 4 + 3] = regs.edx;
|
|
|
|
}
|
2014-11-11 01:00:26 +00:00
|
|
|
name[CPU_MAX_NAME_LEN - 1] = '\0';
|
2014-10-10 14:21:54 +00:00
|
|
|
|
2014-11-09 14:18:56 +00:00
|
|
|
/* Skip leading spaces. */
|
2014-11-11 01:00:26 +00:00
|
|
|
ptr = name;
|
|
|
|
while (*ptr == ' ')
|
|
|
|
ptr++;
|
2014-11-09 14:18:56 +00:00
|
|
|
|
2014-11-11 01:00:26 +00:00
|
|
|
return ptr;
|
2014-10-10 14:21:54 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 01:00:26 +00:00
|
|
|
int default_print_cpuinfo(void)
|
2014-10-10 14:21:54 +00:00
|
|
|
{
|
2014-11-09 14:18:56 +00:00
|
|
|
printf("CPU: %s, vendor %s, device %xh\n",
|
|
|
|
cpu_has_64bit() ? "x86_64" : "x86",
|
|
|
|
cpu_vendor_name(gd->arch.x86_vendor), gd->arch.x86_device);
|
2014-10-10 14:21:54 +00:00
|
|
|
|
2017-04-21 14:24:32 +00:00
|
|
|
#ifdef CONFIG_HAVE_ACPI_RESUME
|
|
|
|
debug("ACPI previous sleep state: %s\n",
|
|
|
|
acpi_ss_string(gd->arch.prev_sleep_state));
|
|
|
|
#endif
|
|
|
|
|
2014-10-10 14:21:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-10-10 14:21:55 +00:00
|
|
|
|
2014-11-13 05:42:26 +00:00
|
|
|
void show_boot_progress(int val)
|
|
|
|
{
|
|
|
|
outb(val, POST_PORT);
|
|
|
|
}
|
2015-04-24 10:10:04 +00:00
|
|
|
|
2018-06-17 12:57:53 +00:00
|
|
|
#if !defined(CONFIG_SYS_COREBOOT) && !defined(CONFIG_EFI_STUB)
|
2016-05-11 14:44:56 +00:00
|
|
|
/*
|
|
|
|
* Implement a weak default function for boards that optionally
|
|
|
|
* need to clean up the system before jumping to the kernel.
|
|
|
|
*/
|
|
|
|
__weak void board_final_cleanup(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-24 10:10:04 +00:00
|
|
|
int last_stage_init(void)
|
|
|
|
{
|
2018-07-19 04:42:16 +00:00
|
|
|
struct acpi_fadt __maybe_unused *fadt;
|
|
|
|
|
2017-04-21 14:24:41 +00:00
|
|
|
board_final_cleanup();
|
|
|
|
|
2018-07-19 04:42:16 +00:00
|
|
|
#ifdef CONFIG_HAVE_ACPI_RESUME
|
|
|
|
fadt = acpi_find_fadt();
|
2017-04-21 14:24:37 +00:00
|
|
|
|
2018-07-19 04:42:16 +00:00
|
|
|
if (fadt && gd->arch.prev_sleep_state == ACPI_S3)
|
2017-04-21 14:24:44 +00:00
|
|
|
acpi_resume(fadt);
|
2017-04-21 14:24:37 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-24 10:10:04 +00:00
|
|
|
write_tables();
|
|
|
|
|
2018-07-19 04:42:16 +00:00
|
|
|
#ifdef CONFIG_GENERATE_ACPI_TABLE
|
|
|
|
fadt = acpi_find_fadt();
|
|
|
|
|
|
|
|
/* Don't touch ACPI hardware on HW reduced platforms */
|
|
|
|
if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
|
|
|
|
/*
|
|
|
|
* Other than waiting for OSPM to request us to switch to ACPI
|
|
|
|
* mode, do it by ourselves, since SMI will not be triggered.
|
|
|
|
*/
|
|
|
|
enter_acpi_mode(fadt->pm1a_cnt_blk);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-24 10:10:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-30 04:26:01 +00:00
|
|
|
|
2016-01-17 23:11:28 +00:00
|
|
|
static int x86_init_cpus(void)
|
2015-04-30 04:26:01 +00:00
|
|
|
{
|
2015-06-17 03:15:36 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
debug("Init additional CPUs\n");
|
|
|
|
x86_mp_init();
|
2015-07-22 08:21:12 +00:00
|
|
|
#else
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This causes the cpu-x86 driver to be probed.
|
|
|
|
* We don't check return value here as we want to allow boards
|
|
|
|
* which have not been converted to use cpu uclass driver to boot.
|
|
|
|
*/
|
|
|
|
uclass_first_device(UCLASS_CPU, &dev);
|
2015-06-17 03:15:36 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-30 04:26:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cpu_init_r(void)
|
|
|
|
{
|
2016-01-17 23:11:30 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!ll_boot_init())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = x86_init_cpus();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the northbridge, PCH and LPC if available. Note that these
|
|
|
|
* may have had some limited pre-relocation init if they were probed
|
|
|
|
* before relocation, but this is post relocation.
|
|
|
|
*/
|
|
|
|
uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
|
|
|
|
uclass_first_device(UCLASS_PCH, &dev);
|
|
|
|
uclass_first_device(UCLASS_LPC, &dev);
|
2015-08-04 18:34:00 +00:00
|
|
|
|
2016-06-08 12:07:38 +00:00
|
|
|
/* Set up pin control if available */
|
|
|
|
ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
|
|
|
|
debug("%s, pinctrl=%p, ret=%d\n", __func__, dev, ret);
|
|
|
|
|
2015-08-04 18:34:00 +00:00
|
|
|
return 0;
|
2015-04-30 04:26:01 +00:00
|
|
|
}
|
2016-05-11 14:45:00 +00:00
|
|
|
|
|
|
|
#ifndef CONFIG_EFI_STUB
|
|
|
|
int reserve_arch(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_ENABLE_MRC_CACHE
|
2016-05-11 14:45:01 +00:00
|
|
|
mrccache_reserve();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SEABIOS
|
|
|
|
high_table_reserve();
|
2016-05-11 14:45:00 +00:00
|
|
|
#endif
|
2016-05-11 14:45:01 +00:00
|
|
|
|
2017-04-21 14:24:47 +00:00
|
|
|
#ifdef CONFIG_HAVE_ACPI_RESUME
|
|
|
|
acpi_s3_reserve();
|
|
|
|
|
|
|
|
#ifdef CONFIG_HAVE_FSP
|
2017-04-21 14:24:39 +00:00
|
|
|
/*
|
|
|
|
* Save stack address to CMOS so that at next S3 boot,
|
|
|
|
* we can use it as the stack address for fsp_contiue()
|
|
|
|
*/
|
|
|
|
fsp_save_s3_stack();
|
2017-04-21 14:24:47 +00:00
|
|
|
#endif /* CONFIG_HAVE_FSP */
|
|
|
|
#endif /* CONFIG_HAVE_ACPI_RESUME */
|
2017-04-21 14:24:39 +00:00
|
|
|
|
2016-05-11 14:45:01 +00:00
|
|
|
return 0;
|
2016-05-11 14:45:00 +00:00
|
|
|
}
|
|
|
|
#endif
|