blob: 099cb94e5d280969afdbae977f1250724e81d6ce [file] [log] [blame]
Simon Glass0b36ecd2014-11-12 22:42:07 -07001/*
2 * Copyright (c) 2014 Google, Inc
3 * (C) Copyright 2008
4 * Graeme Russ, graeme.russ@gmail.com.
5 *
6 * Some portions from coreboot src/mainboard/google/link/romstage.c
Simon Glass30580fc2014-11-12 22:42:23 -07007 * and src/cpu/intel/model_206ax/bootblock.c
Simon Glass0b36ecd2014-11-12 22:42:07 -07008 * Copyright (C) 2007-2010 coresystems GmbH
9 * Copyright (C) 2011 Google Inc.
10 *
11 * SPDX-License-Identifier: GPL-2.0
12 */
13
14#include <common.h>
Simon Glasse0e7b362015-03-05 12:25:33 -070015#include <dm.h>
Simon Glassdcfac352014-11-12 22:42:15 -070016#include <errno.h>
17#include <fdtdec.h>
Simon Glassa7b1d952016-01-17 16:11:13 -070018#include <pch.h>
Simon Glass0b36ecd2014-11-12 22:42:07 -070019#include <asm/cpu.h>
Simon Glass780ba482016-03-11 22:06:58 -070020#include <asm/cpu_common.h>
Simon Glass55357302016-03-11 22:06:55 -070021#include <asm/intel_regs.h>
Simon Glassf226c412014-11-12 22:42:19 -070022#include <asm/io.h>
Simon Glassd22f5c92014-11-12 22:42:27 -070023#include <asm/lapic.h>
Simon Glass9c852d72016-03-16 07:44:36 -060024#include <asm/lpc_common.h>
Simon Glass2df61882016-03-11 22:06:54 -070025#include <asm/microcode.h>
Simon Glassf226c412014-11-12 22:42:19 -070026#include <asm/msr.h>
27#include <asm/mtrr.h>
Simon Glass3274ae02014-11-12 22:42:13 -070028#include <asm/pci.h>
Simon Glass98f139b2014-11-12 22:42:10 -070029#include <asm/post.h>
Simon Glass0b36ecd2014-11-12 22:42:07 -070030#include <asm/processor.h>
Simon Glassf226c412014-11-12 22:42:19 -070031#include <asm/arch/model_206ax.h>
Simon Glassdcfac352014-11-12 22:42:15 -070032#include <asm/arch/pch.h>
Simon Glass30580fc2014-11-12 22:42:23 -070033#include <asm/arch/sandybridge.h>
Simon Glass0b36ecd2014-11-12 22:42:07 -070034
35DECLARE_GLOBAL_DATA_PTR;
36
Simon Glassf226c412014-11-12 22:42:19 -070037static int set_flex_ratio_to_tdp_nominal(void)
38{
Simon Glassf226c412014-11-12 22:42:19 -070039 /* Minimum CPU revision for configurable TDP support */
40 if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
41 return -EINVAL;
42
Simon Glass780ba482016-03-11 22:06:58 -070043 return cpu_set_flex_ratio_to_tdp_nominal();
Simon Glassf226c412014-11-12 22:42:19 -070044}
45
Simon Glass0b36ecd2014-11-12 22:42:07 -070046int arch_cpu_init(void)
47{
Simon Glass7567f462015-03-05 12:25:17 -070048 post_code(POST_CPU_INIT);
Simon Glass7567f462015-03-05 12:25:17 -070049
50 return x86_cpu_init_f();
51}
52
53int arch_cpu_init_dm(void)
54{
Simon Glass3274ae02014-11-12 22:42:13 -070055 struct pci_controller *hose;
Simon Glass044f1a02016-01-17 16:11:10 -070056 struct udevice *bus, *dev;
Simon Glass0b36ecd2014-11-12 22:42:07 -070057 int ret;
58
Simon Glasse0e7b362015-03-05 12:25:33 -070059 post_code(0x70);
60 ret = uclass_get_device(UCLASS_PCI, 0, &bus);
61 post_code(0x71);
Simon Glass0b36ecd2014-11-12 22:42:07 -070062 if (ret)
63 return ret;
Simon Glasse0e7b362015-03-05 12:25:33 -070064 post_code(0x72);
65 hose = dev_get_uclass_priv(bus);
Simon Glass0b36ecd2014-11-12 22:42:07 -070066
Simon Glasse0e7b362015-03-05 12:25:33 -070067 /* TODO(sjg@chromium.org): Get rid of gd->hose */
68 gd->hose = hose;
Simon Glass3274ae02014-11-12 22:42:13 -070069
Simon Glassc7298e72016-02-11 13:23:26 -070070 ret = uclass_first_device_err(UCLASS_LPC, &dev);
71 if (ret)
72 return ret;
Simon Glass044f1a02016-01-17 16:11:10 -070073
Simon Glassf226c412014-11-12 22:42:19 -070074 /*
75 * We should do as little as possible before the serial console is
76 * up. Perhaps this should move to later. Our next lot of init
Simon Glassee7c36f2017-03-28 10:27:30 -060077 * happens in checkcpu() when we have a console
Simon Glassf226c412014-11-12 22:42:19 -070078 */
79 ret = set_flex_ratio_to_tdp_nominal();
80 if (ret)
81 return ret;
82
Simon Glass0b36ecd2014-11-12 22:42:07 -070083 return 0;
84}
85
Simon Glass30580fc2014-11-12 22:42:23 -070086#define PCH_EHCI0_TEMP_BAR0 0xe8000000
87#define PCH_EHCI1_TEMP_BAR0 0xe8000400
88#define PCH_XHCI_TEMP_BAR0 0xe8001000
89
90/*
91 * Setup USB controller MMIO BAR to prevent the reference code from
92 * resetting the controller.
93 *
94 * The BAR will be re-assigned during device enumeration so these are only
95 * temporary.
96 *
97 * This is used to speed up the resume path.
98 */
Simon Glass18df7d02016-01-17 16:11:46 -070099static void enable_usb_bar(struct udevice *bus)
Simon Glass30580fc2014-11-12 22:42:23 -0700100{
101 pci_dev_t usb0 = PCH_EHCI1_DEV;
102 pci_dev_t usb1 = PCH_EHCI2_DEV;
103 pci_dev_t usb3 = PCH_XHCI_DEV;
Simon Glass18df7d02016-01-17 16:11:46 -0700104 ulong cmd;
Simon Glass30580fc2014-11-12 22:42:23 -0700105
106 /* USB Controller 1 */
Simon Glass18df7d02016-01-17 16:11:46 -0700107 pci_bus_write_config(bus, usb0, PCI_BASE_ADDRESS_0,
108 PCH_EHCI0_TEMP_BAR0, PCI_SIZE_32);
109 pci_bus_read_config(bus, usb0, PCI_COMMAND, &cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700110 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
Simon Glass18df7d02016-01-17 16:11:46 -0700111 pci_bus_write_config(bus, usb0, PCI_COMMAND, cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700112
Simon Glass18df7d02016-01-17 16:11:46 -0700113 /* USB Controller 2 */
114 pci_bus_write_config(bus, usb1, PCI_BASE_ADDRESS_0,
115 PCH_EHCI1_TEMP_BAR0, PCI_SIZE_32);
116 pci_bus_read_config(bus, usb1, PCI_COMMAND, &cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700117 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
Simon Glass18df7d02016-01-17 16:11:46 -0700118 pci_bus_write_config(bus, usb1, PCI_COMMAND, cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700119
Simon Glass18df7d02016-01-17 16:11:46 -0700120 /* USB3 Controller 1 */
121 pci_bus_write_config(bus, usb3, PCI_BASE_ADDRESS_0,
122 PCH_XHCI_TEMP_BAR0, PCI_SIZE_32);
123 pci_bus_read_config(bus, usb3, PCI_COMMAND, &cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700124 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
Simon Glass18df7d02016-01-17 16:11:46 -0700125 pci_bus_write_config(bus, usb3, PCI_COMMAND, cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700126}
127
Simon Glassee7c36f2017-03-28 10:27:30 -0600128int checkcpu(void)
Simon Glass0b36ecd2014-11-12 22:42:07 -0700129{
Simon Glass30580fc2014-11-12 22:42:23 -0700130 enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
Simon Glassb20cf042016-01-17 16:11:19 -0700131 struct udevice *dev, *lpc;
Simon Glass30580fc2014-11-12 22:42:23 -0700132 uint32_t pm1_cnt;
133 uint16_t pm1_sts;
Simon Glass367077a2014-11-12 22:42:20 -0700134 int ret;
135
Simon Glass30580fc2014-11-12 22:42:23 -0700136 /* TODO: cmos_post_init() */
137 if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) {
138 debug("soft reset detected\n");
139 boot_mode = PEI_BOOT_SOFT_RESET;
140
141 /* System is not happy after keyboard reset... */
142 debug("Issuing CF9 warm reset\n");
Simon Glass1375e9a2015-04-28 20:11:30 -0600143 reset_cpu(0);
Simon Glass30580fc2014-11-12 22:42:23 -0700144 }
145
Simon Glass780ba482016-03-11 22:06:58 -0700146 ret = cpu_common_init();
Simon Glassf7f56742016-07-25 18:58:59 -0600147 if (ret) {
148 debug("%s: cpu_common_init() failed\n", __func__);
Simon Glassa7b1d952016-01-17 16:11:13 -0700149 return ret;
Simon Glassf7f56742016-07-25 18:58:59 -0600150 }
Simon Glass30580fc2014-11-12 22:42:23 -0700151
152 /* Check PM1_STS[15] to see if we are waking from Sx */
153 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
154
155 /* Read PM1_CNT[12:10] to determine which Sx state */
156 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
157
158 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
Simon Glass30580fc2014-11-12 22:42:23 -0700159 debug("Resume from S3 detected, but disabled.\n");
Simon Glass30580fc2014-11-12 22:42:23 -0700160 } else {
161 /*
162 * TODO: An indication of life might be possible here (e.g.
163 * keyboard light)
164 */
165 }
166 post_code(POST_EARLY_INIT);
167
168 /* Enable SPD ROMs and DDR-III DRAM */
Simon Glassc7298e72016-02-11 13:23:26 -0700169 ret = uclass_first_device_err(UCLASS_I2C, &dev);
Simon Glasse5367962017-01-16 07:03:38 -0700170 if (ret) {
171 debug("%s: Failed to get I2C (ret=%d)\n", __func__, ret);
Simon Glass30580fc2014-11-12 22:42:23 -0700172 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700173 }
Simon Glass30580fc2014-11-12 22:42:23 -0700174
175 /* Prepare USB controller early in S3 resume */
Simon Glass780ba482016-03-11 22:06:58 -0700176 if (boot_mode == PEI_BOOT_RESUME) {
177 uclass_first_device(UCLASS_LPC, &lpc);
Simon Glass18df7d02016-01-17 16:11:46 -0700178 enable_usb_bar(pci_get_controller(lpc->parent));
Simon Glass780ba482016-03-11 22:06:58 -0700179 }
Simon Glass30580fc2014-11-12 22:42:23 -0700180
181 gd->arch.pei_boot_mode = boot_mode;
182
Simon Glassee7c36f2017-03-28 10:27:30 -0600183 return 0;
184}
185
186int print_cpuinfo(void)
187{
188 char processor_name[CPU_MAX_NAME_LEN];
189 const char *name;
190
Simon Glass0b36ecd2014-11-12 22:42:07 -0700191 /* Print processor name */
192 name = cpu_get_name(processor_name);
193 printf("CPU: %s\n", name);
194
Simon Glass30580fc2014-11-12 22:42:23 -0700195 post_code(POST_CPU_INFO);
196
Simon Glass0b36ecd2014-11-12 22:42:07 -0700197 return 0;
198}
Simon Glassf2dd4702015-10-18 19:51:27 -0600199
200void board_debug_uart_init(void)
201{
202 /* This enables the debug UART */
203 pci_x86_write_config(NULL, PCH_LPC_DEV, LPC_EN, COMA_LPC_EN,
204 PCI_SIZE_16);
205}