blob: 05691a38d2e8b8c3c547d6fe23be990609e25770 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass0b36ecd2014-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 Glass30580fc2014-11-12 22:42:23 -07008 * and src/cpu/intel/model_206ax/bootblock.c
Simon Glass0b36ecd2014-11-12 22:42:07 -07009 * Copyright (C) 2007-2010 coresystems GmbH
10 * Copyright (C) 2011 Google Inc.
Simon Glass0b36ecd2014-11-12 22:42:07 -070011 */
12
Simon Glass1fa70f82019-11-14 12:57:34 -070013#include <cpu_func.h>
Simon Glasse0e7b362015-03-05 12:25:33 -070014#include <dm.h>
Simon Glassdcfac352014-11-12 22:42:15 -070015#include <errno.h>
Simon Glassfc557362022-03-04 08:43:05 -070016#include <event.h>
Simon Glassdcfac352014-11-12 22:42:15 -070017#include <fdtdec.h>
Simon Glass97589732020-05-10 11:40:02 -060018#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060019#include <log.h>
Simon Glassa7b1d952016-01-17 16:11:13 -070020#include <pch.h>
Simon Glass0b36ecd2014-11-12 22:42:07 -070021#include <asm/cpu.h>
Simon Glass780ba482016-03-11 22:06:58 -070022#include <asm/cpu_common.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060023#include <asm/global_data.h>
Simon Glass55357302016-03-11 22:06:55 -070024#include <asm/intel_regs.h>
Simon Glassf226c412014-11-12 22:42:19 -070025#include <asm/io.h>
Simon Glassd22f5c92014-11-12 22:42:27 -070026#include <asm/lapic.h>
Simon Glass9c852d72016-03-16 07:44:36 -060027#include <asm/lpc_common.h>
Simon Glass2df61882016-03-11 22:06:54 -070028#include <asm/microcode.h>
Simon Glassf226c412014-11-12 22:42:19 -070029#include <asm/msr.h>
30#include <asm/mtrr.h>
Simon Glass3274ae02014-11-12 22:42:13 -070031#include <asm/pci.h>
Simon Glass98f139b2014-11-12 22:42:10 -070032#include <asm/post.h>
Simon Glass0b36ecd2014-11-12 22:42:07 -070033#include <asm/processor.h>
Simon Glassf226c412014-11-12 22:42:19 -070034#include <asm/arch/model_206ax.h>
Simon Glassdcfac352014-11-12 22:42:15 -070035#include <asm/arch/pch.h>
Simon Glass30580fc2014-11-12 22:42:23 -070036#include <asm/arch/sandybridge.h>
Simon Glass0b36ecd2014-11-12 22:42:07 -070037
38DECLARE_GLOBAL_DATA_PTR;
39
Simon Glassf226c412014-11-12 22:42:19 -070040static int set_flex_ratio_to_tdp_nominal(void)
41{
Simon Glassf226c412014-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 Glass780ba482016-03-11 22:06:58 -070046 return cpu_set_flex_ratio_to_tdp_nominal();
Simon Glassf226c412014-11-12 22:42:19 -070047}
48
Simon Glass0b36ecd2014-11-12 22:42:07 -070049int arch_cpu_init(void)
50{
Simon Glass7567f462015-03-05 12:25:17 -070051 post_code(POST_CPU_INIT);
Simon Glass7567f462015-03-05 12:25:17 -070052
53 return x86_cpu_init_f();
54}
55
Simon Glassb8357c12023-08-21 21:16:56 -060056static int ivybridge_cpu_init(void)
Simon Glass7567f462015-03-05 12:25:17 -070057{
Simon Glass044f1a02016-01-17 16:11:10 -070058 struct udevice *bus, *dev;
Simon Glass0b36ecd2014-11-12 22:42:07 -070059 int ret;
60
Simon Glasse0e7b362015-03-05 12:25:33 -070061 post_code(0x70);
62 ret = uclass_get_device(UCLASS_PCI, 0, &bus);
63 post_code(0x71);
Simon Glass0b36ecd2014-11-12 22:42:07 -070064 if (ret)
65 return ret;
Simon Glasse0e7b362015-03-05 12:25:33 -070066 post_code(0x72);
Simon Glass3274ae02014-11-12 22:42:13 -070067
Simon Glassc7298e72016-02-11 13:23:26 -070068 ret = uclass_first_device_err(UCLASS_LPC, &dev);
69 if (ret)
70 return ret;
Simon Glass044f1a02016-01-17 16:11:10 -070071
Simon Glassf226c412014-11-12 22:42:19 -070072 /*
73 * We should do as little as possible before the serial console is
74 * up. Perhaps this should move to later. Our next lot of init
Simon Glassee7c36f2017-03-28 10:27:30 -060075 * happens in checkcpu() when we have a console
Simon Glassf226c412014-11-12 22:42:19 -070076 */
77 ret = set_flex_ratio_to_tdp_nominal();
78 if (ret)
79 return ret;
80
Simon Glass0b36ecd2014-11-12 22:42:07 -070081 return 0;
82}
Simon Glassb8357c12023-08-21 21:16:56 -060083EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, ivybridge_cpu_init);
Simon Glass0b36ecd2014-11-12 22:42:07 -070084
Simon Glass30580fc2014-11-12 22:42:23 -070085#define PCH_EHCI0_TEMP_BAR0 0xe8000000
86#define PCH_EHCI1_TEMP_BAR0 0xe8000400
87#define PCH_XHCI_TEMP_BAR0 0xe8001000
88
89/*
90 * Setup USB controller MMIO BAR to prevent the reference code from
91 * resetting the controller.
92 *
93 * The BAR will be re-assigned during device enumeration so these are only
94 * temporary.
95 *
96 * This is used to speed up the resume path.
97 */
Simon Glass18df7d02016-01-17 16:11:46 -070098static void enable_usb_bar(struct udevice *bus)
Simon Glass30580fc2014-11-12 22:42:23 -070099{
100 pci_dev_t usb0 = PCH_EHCI1_DEV;
101 pci_dev_t usb1 = PCH_EHCI2_DEV;
102 pci_dev_t usb3 = PCH_XHCI_DEV;
Simon Glass18df7d02016-01-17 16:11:46 -0700103 ulong cmd;
Simon Glass30580fc2014-11-12 22:42:23 -0700104
105 /* USB Controller 1 */
Simon Glass18df7d02016-01-17 16:11:46 -0700106 pci_bus_write_config(bus, usb0, PCI_BASE_ADDRESS_0,
107 PCH_EHCI0_TEMP_BAR0, PCI_SIZE_32);
108 pci_bus_read_config(bus, usb0, PCI_COMMAND, &cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700109 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
Simon Glass18df7d02016-01-17 16:11:46 -0700110 pci_bus_write_config(bus, usb0, PCI_COMMAND, cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700111
Simon Glass18df7d02016-01-17 16:11:46 -0700112 /* USB Controller 2 */
113 pci_bus_write_config(bus, usb1, PCI_BASE_ADDRESS_0,
114 PCH_EHCI1_TEMP_BAR0, PCI_SIZE_32);
115 pci_bus_read_config(bus, usb1, PCI_COMMAND, &cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700116 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
Simon Glass18df7d02016-01-17 16:11:46 -0700117 pci_bus_write_config(bus, usb1, PCI_COMMAND, cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700118
Simon Glass18df7d02016-01-17 16:11:46 -0700119 /* USB3 Controller 1 */
120 pci_bus_write_config(bus, usb3, PCI_BASE_ADDRESS_0,
121 PCH_XHCI_TEMP_BAR0, PCI_SIZE_32);
122 pci_bus_read_config(bus, usb3, PCI_COMMAND, &cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700123 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
Simon Glass18df7d02016-01-17 16:11:46 -0700124 pci_bus_write_config(bus, usb3, PCI_COMMAND, cmd, PCI_SIZE_32);
Simon Glass30580fc2014-11-12 22:42:23 -0700125}
126
Simon Glassee7c36f2017-03-28 10:27:30 -0600127int checkcpu(void)
Simon Glass0b36ecd2014-11-12 22:42:07 -0700128{
Simon Glass30580fc2014-11-12 22:42:23 -0700129 enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
Simon Glassb20cf042016-01-17 16:11:19 -0700130 struct udevice *dev, *lpc;
Simon Glass30580fc2014-11-12 22:42:23 -0700131 uint32_t pm1_cnt;
132 uint16_t pm1_sts;
Simon Glass367077a2014-11-12 22:42:20 -0700133 int ret;
134
Simon Glass30580fc2014-11-12 22:42:23 -0700135 /* TODO: cmos_post_init() */
136 if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) {
137 debug("soft reset detected\n");
138 boot_mode = PEI_BOOT_SOFT_RESET;
139
140 /* System is not happy after keyboard reset... */
141 debug("Issuing CF9 warm reset\n");
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100142 reset_cpu();
Simon Glass30580fc2014-11-12 22:42:23 -0700143 }
144
Simon Glass780ba482016-03-11 22:06:58 -0700145 ret = cpu_common_init();
Simon Glassf7f56742016-07-25 18:58:59 -0600146 if (ret) {
147 debug("%s: cpu_common_init() failed\n", __func__);
Simon Glassa7b1d952016-01-17 16:11:13 -0700148 return ret;
Simon Glassf7f56742016-07-25 18:58:59 -0600149 }
Simon Glass30580fc2014-11-12 22:42:23 -0700150
151 /* Check PM1_STS[15] to see if we are waking from Sx */
152 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
153
154 /* Read PM1_CNT[12:10] to determine which Sx state */
155 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
156
157 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
Simon Glass30580fc2014-11-12 22:42:23 -0700158 debug("Resume from S3 detected, but disabled.\n");
Simon Glass30580fc2014-11-12 22:42:23 -0700159 } else {
160 /*
161 * TODO: An indication of life might be possible here (e.g.
162 * keyboard light)
163 */
164 }
165 post_code(POST_EARLY_INIT);
166
167 /* Enable SPD ROMs and DDR-III DRAM */
Simon Glassc7298e72016-02-11 13:23:26 -0700168 ret = uclass_first_device_err(UCLASS_I2C, &dev);
Simon Glasse5367962017-01-16 07:03:38 -0700169 if (ret) {
170 debug("%s: Failed to get I2C (ret=%d)\n", __func__, ret);
Simon Glass30580fc2014-11-12 22:42:23 -0700171 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700172 }
Simon Glass30580fc2014-11-12 22:42:23 -0700173
174 /* Prepare USB controller early in S3 resume */
Simon Glass780ba482016-03-11 22:06:58 -0700175 if (boot_mode == PEI_BOOT_RESUME) {
176 uclass_first_device(UCLASS_LPC, &lpc);
Simon Glass18df7d02016-01-17 16:11:46 -0700177 enable_usb_bar(pci_get_controller(lpc->parent));
Simon Glass780ba482016-03-11 22:06:58 -0700178 }
Simon Glass30580fc2014-11-12 22:42:23 -0700179
180 gd->arch.pei_boot_mode = boot_mode;
181
Simon Glassee7c36f2017-03-28 10:27:30 -0600182 return 0;
183}
184
185int print_cpuinfo(void)
186{
187 char processor_name[CPU_MAX_NAME_LEN];
188 const char *name;
189
Simon Glass0b36ecd2014-11-12 22:42:07 -0700190 /* Print processor name */
191 name = cpu_get_name(processor_name);
192 printf("CPU: %s\n", name);
193
Simon Glass30580fc2014-11-12 22:42:23 -0700194 post_code(POST_CPU_INFO);
195
Simon Glass0b36ecd2014-11-12 22:42:07 -0700196 return 0;
197}
Simon Glassf2dd4702015-10-18 19:51:27 -0600198
199void board_debug_uart_init(void)
200{
201 /* This enables the debug UART */
Simon Glassa5464582019-08-31 21:23:18 -0600202 pci_x86_write_config(PCH_LPC_DEV, LPC_EN, COMA_LPC_EN, PCI_SIZE_16);
Simon Glassf2dd4702015-10-18 19:51:27 -0600203}