2014-11-13 05:42:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Google, Inc
|
|
|
|
* (C) Copyright 2008
|
|
|
|
* Graeme Russ, graeme.russ@gmail.com.
|
|
|
|
*
|
|
|
|
* Some portions from coreboot src/mainboard/google/link/romstage.c
|
2014-11-13 05:42:23 +00:00
|
|
|
* and src/cpu/intel/model_206ax/bootblock.c
|
2014-11-13 05:42:07 +00:00
|
|
|
* Copyright (C) 2007-2010 coresystems GmbH
|
|
|
|
* Copyright (C) 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-03-05 19:25:33 +00:00
|
|
|
#include <dm.h>
|
2014-11-13 05:42:15 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fdtdec.h>
|
2016-01-17 23:11:13 +00:00
|
|
|
#include <pch.h>
|
2014-11-13 05:42:07 +00:00
|
|
|
#include <asm/cpu.h>
|
2014-11-13 05:42:19 +00:00
|
|
|
#include <asm/io.h>
|
2014-11-13 05:42:27 +00:00
|
|
|
#include <asm/lapic.h>
|
2014-11-13 05:42:19 +00:00
|
|
|
#include <asm/msr.h>
|
|
|
|
#include <asm/mtrr.h>
|
2014-11-13 05:42:13 +00:00
|
|
|
#include <asm/pci.h>
|
2014-11-13 05:42:10 +00:00
|
|
|
#include <asm/post.h>
|
2014-11-13 05:42:07 +00:00
|
|
|
#include <asm/processor.h>
|
2014-11-13 05:42:19 +00:00
|
|
|
#include <asm/arch/model_206ax.h>
|
2014-11-13 05:42:21 +00:00
|
|
|
#include <asm/arch/microcode.h>
|
2014-11-13 05:42:15 +00:00
|
|
|
#include <asm/arch/pch.h>
|
2014-11-13 05:42:23 +00:00
|
|
|
#include <asm/arch/sandybridge.h>
|
2014-11-13 05:42:07 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2014-11-13 05:42:19 +00:00
|
|
|
static int set_flex_ratio_to_tdp_nominal(void)
|
|
|
|
{
|
|
|
|
msr_t flex_ratio, msr;
|
|
|
|
u8 nominal_ratio;
|
|
|
|
|
|
|
|
/* Minimum CPU revision for configurable TDP support */
|
|
|
|
if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Check for Flex Ratio support */
|
|
|
|
flex_ratio = msr_read(MSR_FLEX_RATIO);
|
|
|
|
if (!(flex_ratio.lo & FLEX_RATIO_EN))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Check for >0 configurable TDPs */
|
|
|
|
msr = msr_read(MSR_PLATFORM_INFO);
|
|
|
|
if (((msr.hi >> 1) & 3) == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Use nominal TDP ratio for flex ratio */
|
|
|
|
msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
|
|
|
|
nominal_ratio = msr.lo & 0xff;
|
|
|
|
|
|
|
|
/* See if flex ratio is already set to nominal TDP ratio */
|
|
|
|
if (((flex_ratio.lo >> 8) & 0xff) == nominal_ratio)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Set flex ratio to nominal TDP ratio */
|
|
|
|
flex_ratio.lo &= ~0xff00;
|
|
|
|
flex_ratio.lo |= nominal_ratio << 8;
|
|
|
|
flex_ratio.lo |= FLEX_RATIO_LOCK;
|
|
|
|
msr_write(MSR_FLEX_RATIO, flex_ratio);
|
|
|
|
|
|
|
|
/* Set flex ratio in soft reset data register bits 11:6 */
|
|
|
|
clrsetbits_le32(RCB_REG(SOFT_RESET_DATA), 0x3f << 6,
|
|
|
|
(nominal_ratio & 0x3f) << 6);
|
|
|
|
|
|
|
|
/* Set soft reset control to use register value */
|
|
|
|
setbits_le32(RCB_REG(SOFT_RESET_CTRL), 1);
|
|
|
|
|
|
|
|
/* Issue warm reset, will be "CPU only" due to soft reset data */
|
|
|
|
outb(0x0, PORT_RESET);
|
2015-04-29 02:11:30 +00:00
|
|
|
outb(SYS_RST | RST_CPU, PORT_RESET);
|
2014-11-13 05:42:19 +00:00
|
|
|
cpu_hlt();
|
|
|
|
|
|
|
|
/* Not reached */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-11-13 05:42:07 +00:00
|
|
|
int arch_cpu_init(void)
|
2015-03-05 19:25:17 +00:00
|
|
|
{
|
|
|
|
post_code(POST_CPU_INIT);
|
|
|
|
|
|
|
|
return x86_cpu_init_f();
|
|
|
|
}
|
|
|
|
|
|
|
|
int arch_cpu_init_dm(void)
|
2014-11-13 05:42:07 +00:00
|
|
|
{
|
2014-11-13 05:42:13 +00:00
|
|
|
struct pci_controller *hose;
|
2016-01-17 23:11:10 +00:00
|
|
|
struct udevice *bus, *dev;
|
2014-11-13 05:42:07 +00:00
|
|
|
int ret;
|
|
|
|
|
2015-03-05 19:25:33 +00:00
|
|
|
post_code(0x70);
|
|
|
|
ret = uclass_get_device(UCLASS_PCI, 0, &bus);
|
|
|
|
post_code(0x71);
|
2014-11-13 05:42:07 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-03-05 19:25:33 +00:00
|
|
|
post_code(0x72);
|
|
|
|
hose = dev_get_uclass_priv(bus);
|
2014-11-13 05:42:07 +00:00
|
|
|
|
2015-03-05 19:25:33 +00:00
|
|
|
/* TODO(sjg@chromium.org): Get rid of gd->hose */
|
|
|
|
gd->hose = hose;
|
2014-11-13 05:42:13 +00:00
|
|
|
|
2016-01-17 23:11:10 +00:00
|
|
|
ret = uclass_first_device(UCLASS_LPC, &dev);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2014-11-13 05:42:19 +00:00
|
|
|
/*
|
|
|
|
* We should do as little as possible before the serial console is
|
|
|
|
* up. Perhaps this should move to later. Our next lot of init
|
|
|
|
* happens in print_cpuinfo() when we have a console
|
|
|
|
*/
|
|
|
|
ret = set_flex_ratio_to_tdp_nominal();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2014-11-13 05:42:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-13 05:42:23 +00:00
|
|
|
static int enable_smbus(void)
|
|
|
|
{
|
|
|
|
pci_dev_t dev;
|
|
|
|
uint16_t value;
|
|
|
|
|
|
|
|
/* Set the SMBus device statically. */
|
|
|
|
dev = PCI_BDF(0x0, 0x1f, 0x3);
|
|
|
|
|
|
|
|
/* Check to make sure we've got the right device. */
|
2015-03-05 19:25:15 +00:00
|
|
|
value = x86_pci_read_config16(dev, 0x0);
|
2014-11-13 05:42:23 +00:00
|
|
|
if (value != 0x8086) {
|
|
|
|
printf("SMBus controller not found\n");
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set SMBus I/O base. */
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config32(dev, SMB_BASE,
|
|
|
|
SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO);
|
2014-11-13 05:42:23 +00:00
|
|
|
|
|
|
|
/* Set SMBus enable. */
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config8(dev, HOSTC, HST_EN);
|
2014-11-13 05:42:23 +00:00
|
|
|
|
|
|
|
/* Set SMBus I/O space enable. */
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO);
|
2014-11-13 05:42:23 +00:00
|
|
|
|
|
|
|
/* Disable interrupt generation. */
|
|
|
|
outb(0, SMBUS_IO_BASE + SMBHSTCTL);
|
|
|
|
|
|
|
|
/* Clear any lingering errors, so transactions can run. */
|
|
|
|
outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
|
|
|
|
debug("SMBus controller enabled\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PCH_EHCI0_TEMP_BAR0 0xe8000000
|
|
|
|
#define PCH_EHCI1_TEMP_BAR0 0xe8000400
|
|
|
|
#define PCH_XHCI_TEMP_BAR0 0xe8001000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup USB controller MMIO BAR to prevent the reference code from
|
|
|
|
* resetting the controller.
|
|
|
|
*
|
|
|
|
* The BAR will be re-assigned during device enumeration so these are only
|
|
|
|
* temporary.
|
|
|
|
*
|
|
|
|
* This is used to speed up the resume path.
|
|
|
|
*/
|
|
|
|
static void enable_usb_bar(void)
|
|
|
|
{
|
|
|
|
pci_dev_t usb0 = PCH_EHCI1_DEV;
|
|
|
|
pci_dev_t usb1 = PCH_EHCI2_DEV;
|
|
|
|
pci_dev_t usb3 = PCH_XHCI_DEV;
|
|
|
|
u32 cmd;
|
|
|
|
|
|
|
|
/* USB Controller 1 */
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config32(usb0, PCI_BASE_ADDRESS_0,
|
|
|
|
PCH_EHCI0_TEMP_BAR0);
|
|
|
|
cmd = x86_pci_read_config32(usb0, PCI_COMMAND);
|
2014-11-13 05:42:23 +00:00
|
|
|
cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config32(usb0, PCI_COMMAND, cmd);
|
2014-11-13 05:42:23 +00:00
|
|
|
|
|
|
|
/* USB Controller 1 */
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config32(usb1, PCI_BASE_ADDRESS_0,
|
|
|
|
PCH_EHCI1_TEMP_BAR0);
|
|
|
|
cmd = x86_pci_read_config32(usb1, PCI_COMMAND);
|
2014-11-13 05:42:23 +00:00
|
|
|
cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config32(usb1, PCI_COMMAND, cmd);
|
2014-11-13 05:42:23 +00:00
|
|
|
|
|
|
|
/* USB3 Controller */
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config32(usb3, PCI_BASE_ADDRESS_0,
|
|
|
|
PCH_XHCI_TEMP_BAR0);
|
|
|
|
cmd = x86_pci_read_config32(usb3, PCI_COMMAND);
|
2014-11-13 05:42:23 +00:00
|
|
|
cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config32(usb3, PCI_COMMAND, cmd);
|
2014-11-13 05:42:23 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 05:42:20 +00:00
|
|
|
static int report_bist_failure(void)
|
|
|
|
{
|
|
|
|
if (gd->arch.bist != 0) {
|
2014-12-12 13:05:30 +00:00
|
|
|
post_code(POST_BIST_FAILURE);
|
2014-11-13 05:42:20 +00:00
|
|
|
printf("BIST failed: %08x\n", gd->arch.bist);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-13 05:42:07 +00:00
|
|
|
int print_cpuinfo(void)
|
|
|
|
{
|
2014-11-13 05:42:23 +00:00
|
|
|
enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
|
2014-11-13 05:42:07 +00:00
|
|
|
char processor_name[CPU_MAX_NAME_LEN];
|
2016-01-17 23:11:13 +00:00
|
|
|
struct udevice *dev;
|
2014-11-13 05:42:07 +00:00
|
|
|
const char *name;
|
2014-11-13 05:42:23 +00:00
|
|
|
uint32_t pm1_cnt;
|
|
|
|
uint16_t pm1_sts;
|
2014-11-13 05:42:20 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Halt if there was a built in self test failure */
|
|
|
|
ret = report_bist_failure();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-11-13 05:42:07 +00:00
|
|
|
|
2014-11-13 05:42:27 +00:00
|
|
|
enable_lapic();
|
|
|
|
|
2014-11-13 05:42:21 +00:00
|
|
|
ret = microcode_update_intel();
|
2015-01-01 23:18:14 +00:00
|
|
|
if (ret)
|
2014-11-13 05:42:21 +00:00
|
|
|
return ret;
|
|
|
|
|
2014-11-13 05:42:23 +00:00
|
|
|
/* Enable upper 128bytes of CMOS */
|
|
|
|
writel(1 << 2, RCB_REG(RC));
|
|
|
|
|
|
|
|
/* TODO: cmos_post_init() */
|
|
|
|
if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) {
|
|
|
|
debug("soft reset detected\n");
|
|
|
|
boot_mode = PEI_BOOT_SOFT_RESET;
|
|
|
|
|
|
|
|
/* System is not happy after keyboard reset... */
|
|
|
|
debug("Issuing CF9 warm reset\n");
|
2015-04-29 02:11:30 +00:00
|
|
|
reset_cpu(0);
|
2014-11-13 05:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Early chipset init required before RAM init can work */
|
2016-01-17 23:11:16 +00:00
|
|
|
uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
|
|
|
|
|
2016-01-17 23:11:13 +00:00
|
|
|
ret = uclass_first_device(UCLASS_PCH, &dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2014-11-13 05:42:23 +00:00
|
|
|
sandybridge_early_init(SANDYBRIDGE_MOBILE);
|
|
|
|
|
|
|
|
/* Check PM1_STS[15] to see if we are waking from Sx */
|
|
|
|
pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
|
|
|
|
|
|
|
|
/* Read PM1_CNT[12:10] to determine which Sx state */
|
|
|
|
pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
|
|
|
|
|
|
|
|
if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
|
|
|
|
debug("Resume from S3 detected, but disabled.\n");
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* TODO: An indication of life might be possible here (e.g.
|
|
|
|
* keyboard light)
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
post_code(POST_EARLY_INIT);
|
|
|
|
|
|
|
|
/* Enable SPD ROMs and DDR-III DRAM */
|
|
|
|
ret = enable_smbus();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Prepare USB controller early in S3 resume */
|
|
|
|
if (boot_mode == PEI_BOOT_RESUME)
|
|
|
|
enable_usb_bar();
|
|
|
|
|
|
|
|
gd->arch.pei_boot_mode = boot_mode;
|
|
|
|
|
|
|
|
/* TODO: Move this to the board or driver */
|
2015-03-05 19:25:15 +00:00
|
|
|
x86_pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE | 1);
|
|
|
|
x86_pci_write_config32(PCH_LPC_DEV, GPIO_CNTL, 0x10);
|
2014-11-13 05:42:23 +00:00
|
|
|
|
2014-11-13 05:42:07 +00:00
|
|
|
/* Print processor name */
|
|
|
|
name = cpu_get_name(processor_name);
|
|
|
|
printf("CPU: %s\n", name);
|
|
|
|
|
2014-11-13 05:42:23 +00:00
|
|
|
post_code(POST_CPU_INFO);
|
|
|
|
|
2014-11-13 05:42:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-10-19 01:51:27 +00:00
|
|
|
|
|
|
|
void board_debug_uart_init(void)
|
|
|
|
{
|
|
|
|
/* This enables the debug UART */
|
|
|
|
pci_x86_write_config(NULL, PCH_LPC_DEV, LPC_EN, COMA_LPC_EN,
|
|
|
|
PCI_SIZE_16);
|
|
|
|
}
|