blob: bddba3eddecdcb9942ffd911bd10e2ea8a588bd4 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass8ef07572014-11-12 22:42:07 -07002/*
3 * Copyright (c) 2014 Google, Inc
4 * (C) Copyright 2008
5 * Graeme Russ, graeme.russ@gmail.com.
6 *
7 * Some portions from coreboot src/mainboard/google/link/romstage.c
Simon Glass8e0df062014-11-12 22:42:23 -07008 * and src/cpu/intel/model_206ax/bootblock.c
Simon Glass8ef07572014-11-12 22:42:07 -07009 * Copyright (C) 2007-2010 coresystems GmbH
10 * Copyright (C) 2011 Google Inc.
Simon Glass8ef07572014-11-12 22:42:07 -070011 */
12
13#include <common.h>
Simon Glass30c7c432019-11-14 12:57:34 -070014#include <cpu_func.h>
Simon Glassaad78d22015-03-05 12:25:33 -070015#include <dm.h>
Simon Glass2b605152014-11-12 22:42:15 -070016#include <errno.h>
17#include <fdtdec.h>
Simon Glass691d7192020-05-10 11:40:02 -060018#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060019#include <log.h>
Simon Glass858361b2016-01-17 16:11:13 -070020#include <pch.h>
Simon Glass8ef07572014-11-12 22:42:07 -070021#include <asm/cpu.h>
Simon Glass50dd3da2016-03-11 22:06:58 -070022#include <asm/cpu_common.h>
Simon Glass401d1c42020-10-30 21:38:53 -060023#include <asm/global_data.h>
Simon Glass06d336c2016-03-11 22:06:55 -070024#include <asm/intel_regs.h>
Simon Glassf5fbbe92014-11-12 22:42:19 -070025#include <asm/io.h>
Simon Glass3eafce02014-11-12 22:42:27 -070026#include <asm/lapic.h>
Simon Glass7e4a6ae2016-03-16 07:44:36 -060027#include <asm/lpc_common.h>
Simon Glass9e665062016-03-11 22:06:54 -070028#include <asm/microcode.h>
Simon Glassf5fbbe92014-11-12 22:42:19 -070029#include <asm/msr.h>
30#include <asm/mtrr.h>
Simon Glass6e5b12b2014-11-12 22:42:13 -070031#include <asm/pci.h>
Simon Glass70a09c62014-11-12 22:42:10 -070032#include <asm/post.h>
Simon Glass8ef07572014-11-12 22:42:07 -070033#include <asm/processor.h>
Simon Glassf5fbbe92014-11-12 22:42:19 -070034#include <asm/arch/model_206ax.h>
Simon Glass2b605152014-11-12 22:42:15 -070035#include <asm/arch/pch.h>
Simon Glass8e0df062014-11-12 22:42:23 -070036#include <asm/arch/sandybridge.h>
Simon Glass8ef07572014-11-12 22:42:07 -070037
38DECLARE_GLOBAL_DATA_PTR;
39
Simon Glassf5fbbe92014-11-12 22:42:19 -070040static int set_flex_ratio_to_tdp_nominal(void)
41{
Simon Glassf5fbbe92014-11-12 22:42:19 -070042 /* Minimum CPU revision for configurable TDP support */
43 if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
44 return -EINVAL;
45
Simon Glass50dd3da2016-03-11 22:06:58 -070046 return cpu_set_flex_ratio_to_tdp_nominal();
Simon Glassf5fbbe92014-11-12 22:42:19 -070047}
48
Simon Glass8ef07572014-11-12 22:42:07 -070049int arch_cpu_init(void)
50{
Simon Glass161d2e42015-03-05 12:25:17 -070051 post_code(POST_CPU_INIT);
Simon Glass161d2e42015-03-05 12:25:17 -070052
53 return x86_cpu_init_f();
54}
55
56int arch_cpu_init_dm(void)
57{
Simon Glass6e5b12b2014-11-12 22:42:13 -070058 struct pci_controller *hose;
Simon Glass4acc83d2016-01-17 16:11:10 -070059 struct udevice *bus, *dev;
Simon Glass8ef07572014-11-12 22:42:07 -070060 int ret;
61
Simon Glassaad78d22015-03-05 12:25:33 -070062 post_code(0x70);
63 ret = uclass_get_device(UCLASS_PCI, 0, &bus);
64 post_code(0x71);
Simon Glass8ef07572014-11-12 22:42:07 -070065 if (ret)
66 return ret;
Simon Glassaad78d22015-03-05 12:25:33 -070067 post_code(0x72);
68 hose = dev_get_uclass_priv(bus);
Simon Glass8ef07572014-11-12 22:42:07 -070069
Simon Glassaad78d22015-03-05 12:25:33 -070070 /* TODO(sjg@chromium.org): Get rid of gd->hose */
71 gd->hose = hose;
Simon Glass6e5b12b2014-11-12 22:42:13 -070072
Simon Glass3f603cb2016-02-11 13:23:26 -070073 ret = uclass_first_device_err(UCLASS_LPC, &dev);
74 if (ret)
75 return ret;
Simon Glass4acc83d2016-01-17 16:11:10 -070076
Simon Glassf5fbbe92014-11-12 22:42:19 -070077 /*
78 * We should do as little as possible before the serial console is
79 * up. Perhaps this should move to later. Our next lot of init
Simon Glass76d1d022017-03-28 10:27:30 -060080 * happens in checkcpu() when we have a console
Simon Glassf5fbbe92014-11-12 22:42:19 -070081 */
82 ret = set_flex_ratio_to_tdp_nominal();
83 if (ret)
84 return ret;
85
Simon Glass8ef07572014-11-12 22:42:07 -070086 return 0;
87}
88
Simon Glass8e0df062014-11-12 22:42:23 -070089#define PCH_EHCI0_TEMP_BAR0 0xe8000000
90#define PCH_EHCI1_TEMP_BAR0 0xe8000400
91#define PCH_XHCI_TEMP_BAR0 0xe8001000
92
93/*
94 * Setup USB controller MMIO BAR to prevent the reference code from
95 * resetting the controller.
96 *
97 * The BAR will be re-assigned during device enumeration so these are only
98 * temporary.
99 *
100 * This is used to speed up the resume path.
101 */
Simon Glass5213f282016-01-17 16:11:46 -0700102static void enable_usb_bar(struct udevice *bus)
Simon Glass8e0df062014-11-12 22:42:23 -0700103{
104 pci_dev_t usb0 = PCH_EHCI1_DEV;
105 pci_dev_t usb1 = PCH_EHCI2_DEV;
106 pci_dev_t usb3 = PCH_XHCI_DEV;
Simon Glass5213f282016-01-17 16:11:46 -0700107 ulong cmd;
Simon Glass8e0df062014-11-12 22:42:23 -0700108
109 /* USB Controller 1 */
Simon Glass5213f282016-01-17 16:11:46 -0700110 pci_bus_write_config(bus, usb0, PCI_BASE_ADDRESS_0,
111 PCH_EHCI0_TEMP_BAR0, PCI_SIZE_32);
112 pci_bus_read_config(bus, usb0, PCI_COMMAND, &cmd, PCI_SIZE_32);
Simon Glass8e0df062014-11-12 22:42:23 -0700113 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
Simon Glass5213f282016-01-17 16:11:46 -0700114 pci_bus_write_config(bus, usb0, PCI_COMMAND, cmd, PCI_SIZE_32);
Simon Glass8e0df062014-11-12 22:42:23 -0700115
Simon Glass5213f282016-01-17 16:11:46 -0700116 /* USB Controller 2 */
117 pci_bus_write_config(bus, usb1, PCI_BASE_ADDRESS_0,
118 PCH_EHCI1_TEMP_BAR0, PCI_SIZE_32);
119 pci_bus_read_config(bus, usb1, PCI_COMMAND, &cmd, PCI_SIZE_32);
Simon Glass8e0df062014-11-12 22:42:23 -0700120 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
Simon Glass5213f282016-01-17 16:11:46 -0700121 pci_bus_write_config(bus, usb1, PCI_COMMAND, cmd, PCI_SIZE_32);
Simon Glass8e0df062014-11-12 22:42:23 -0700122
Simon Glass5213f282016-01-17 16:11:46 -0700123 /* USB3 Controller 1 */
124 pci_bus_write_config(bus, usb3, PCI_BASE_ADDRESS_0,
125 PCH_XHCI_TEMP_BAR0, PCI_SIZE_32);
126 pci_bus_read_config(bus, usb3, PCI_COMMAND, &cmd, PCI_SIZE_32);
Simon Glass8e0df062014-11-12 22:42:23 -0700127 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
Simon Glass5213f282016-01-17 16:11:46 -0700128 pci_bus_write_config(bus, usb3, PCI_COMMAND, cmd, PCI_SIZE_32);
Simon Glass8e0df062014-11-12 22:42:23 -0700129}
130
Simon Glass76d1d022017-03-28 10:27:30 -0600131int checkcpu(void)
Simon Glass8ef07572014-11-12 22:42:07 -0700132{
Simon Glass8e0df062014-11-12 22:42:23 -0700133 enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
Simon Glassf633efa2016-01-17 16:11:19 -0700134 struct udevice *dev, *lpc;
Simon Glass8e0df062014-11-12 22:42:23 -0700135 uint32_t pm1_cnt;
136 uint16_t pm1_sts;
Simon Glass94060ff2014-11-12 22:42:20 -0700137 int ret;
138
Simon Glass8e0df062014-11-12 22:42:23 -0700139 /* TODO: cmos_post_init() */
140 if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) {
141 debug("soft reset detected\n");
142 boot_mode = PEI_BOOT_SOFT_RESET;
143
144 /* System is not happy after keyboard reset... */
145 debug("Issuing CF9 warm reset\n");
Simon Glass5021c812015-04-28 20:11:30 -0600146 reset_cpu(0);
Simon Glass8e0df062014-11-12 22:42:23 -0700147 }
148
Simon Glass50dd3da2016-03-11 22:06:58 -0700149 ret = cpu_common_init();
Simon Glass4cc00f02016-07-25 18:58:59 -0600150 if (ret) {
151 debug("%s: cpu_common_init() failed\n", __func__);
Simon Glass858361b2016-01-17 16:11:13 -0700152 return ret;
Simon Glass4cc00f02016-07-25 18:58:59 -0600153 }
Simon Glass8e0df062014-11-12 22:42:23 -0700154
155 /* Check PM1_STS[15] to see if we are waking from Sx */
156 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
157
158 /* Read PM1_CNT[12:10] to determine which Sx state */
159 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
160
161 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
Simon Glass8e0df062014-11-12 22:42:23 -0700162 debug("Resume from S3 detected, but disabled.\n");
Simon Glass8e0df062014-11-12 22:42:23 -0700163 } else {
164 /*
165 * TODO: An indication of life might be possible here (e.g.
166 * keyboard light)
167 */
168 }
169 post_code(POST_EARLY_INIT);
170
171 /* Enable SPD ROMs and DDR-III DRAM */
Simon Glass3f603cb2016-02-11 13:23:26 -0700172 ret = uclass_first_device_err(UCLASS_I2C, &dev);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700173 if (ret) {
174 debug("%s: Failed to get I2C (ret=%d)\n", __func__, ret);
Simon Glass8e0df062014-11-12 22:42:23 -0700175 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700176 }
Simon Glass8e0df062014-11-12 22:42:23 -0700177
178 /* Prepare USB controller early in S3 resume */
Simon Glass50dd3da2016-03-11 22:06:58 -0700179 if (boot_mode == PEI_BOOT_RESUME) {
180 uclass_first_device(UCLASS_LPC, &lpc);
Simon Glass5213f282016-01-17 16:11:46 -0700181 enable_usb_bar(pci_get_controller(lpc->parent));
Simon Glass50dd3da2016-03-11 22:06:58 -0700182 }
Simon Glass8e0df062014-11-12 22:42:23 -0700183
184 gd->arch.pei_boot_mode = boot_mode;
185
Simon Glass76d1d022017-03-28 10:27:30 -0600186 return 0;
187}
188
189int print_cpuinfo(void)
190{
191 char processor_name[CPU_MAX_NAME_LEN];
192 const char *name;
193
Simon Glass8ef07572014-11-12 22:42:07 -0700194 /* Print processor name */
195 name = cpu_get_name(processor_name);
196 printf("CPU: %s\n", name);
197
Simon Glass8e0df062014-11-12 22:42:23 -0700198 post_code(POST_CPU_INFO);
199
Simon Glass8ef07572014-11-12 22:42:07 -0700200 return 0;
201}
Simon Glass7b952522015-10-18 19:51:27 -0600202
203void board_debug_uart_init(void)
204{
205 /* This enables the debug UART */
Simon Glassa827ba92019-08-31 21:23:18 -0600206 pci_x86_write_config(PCH_LPC_DEV, LPC_EN, COMA_LPC_EN, PCI_SIZE_16);
Simon Glass7b952522015-10-18 19:51:27 -0600207}