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
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-11-18 00:14:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2015-06-17 03:15:36 +00:00
|
|
|
#include <dm.h>
|
2014-10-10 14:21:55 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <malloc.h>
|
2016-06-08 12:07:38 +00:00
|
|
|
#include <syscon.h>
|
2017-04-21 14:24:32 +00:00
|
|
|
#include <asm/acpi_s3.h>
|
2017-04-21 14:24:37 +00:00
|
|
|
#include <asm/acpi_table.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;
|
|
|
|
|
|
|
|
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",
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2010-06-28 20:00:46 +00:00
|
|
|
int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2002-11-18 00:14:45 +00:00
|
|
|
{
|
2011-11-08 02:33:13 +00:00
|
|
|
printf("resetting ...\n");
|
2011-04-13 09:43:26 +00:00
|
|
|
|
|
|
|
/* wait 50 ms */
|
|
|
|
udelay(50000);
|
2002-11-18 00:14:45 +00:00
|
|
|
disable_interrupts();
|
|
|
|
reset_cpu(0);
|
|
|
|
|
|
|
|
/*NOTREACHED*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-11-06 20:20:08 +00:00
|
|
|
__weak void reset_cpu(ulong addr)
|
2008-12-06 23:29:02 +00:00
|
|
|
{
|
2015-04-29 02:11:29 +00:00
|
|
|
/* Do a hard reset through the chipset's reset control register */
|
2016-03-12 05:06:59 +00:00
|
|
|
outb(SYS_RST | RST_CPU, IO_PORT_RESET);
|
2015-04-29 02:11:29 +00:00
|
|
|
for (;;)
|
|
|
|
cpu_hlt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void x86_full_reset(void)
|
|
|
|
{
|
2016-03-12 05:06:59 +00:00
|
|
|
outb(FULL_RST | SYS_RST | RST_CPU, IO_PORT_RESET);
|
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
|
|
|
|
2014-11-09 14:18:56 +00:00
|
|
|
const char *cpu_vendor_name(int vendor)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
name = "<invalid cpu vendor>";
|
|
|
|
if ((vendor < (ARRAY_SIZE(x86_vendor_name))) &&
|
|
|
|
(x86_vendor_name[vendor] != 0))
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
#ifndef CONFIG_SYS_COREBOOT
|
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)
|
|
|
|
{
|
2017-04-21 14:24:41 +00:00
|
|
|
board_final_cleanup();
|
|
|
|
|
2017-04-21 14:24:37 +00:00
|
|
|
#if CONFIG_HAVE_ACPI_RESUME
|
2017-04-21 14:24:44 +00:00
|
|
|
struct acpi_fadt *fadt = acpi_find_fadt();
|
2017-04-21 14:24:37 +00:00
|
|
|
|
2017-04-21 14:24:44 +00:00
|
|
|
if (fadt != NULL && gd->arch.prev_sleep_state == ACPI_S3)
|
|
|
|
acpi_resume(fadt);
|
2017-04-21 14:24:37 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-24 10:10:04 +00:00
|
|
|
write_tables();
|
|
|
|
|
|
|
|
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
|