Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 2 | /* |
| 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 Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 8 | * and src/cpu/intel/model_206ax/bootblock.c |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 9 | * Copyright (C) 2007-2010 coresystems GmbH |
| 10 | * Copyright (C) 2011 Google Inc. |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
Simon Glass | 1fa70f8 | 2019-11-14 12:57:34 -0700 | [diff] [blame] | 13 | #include <cpu_func.h> |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 14 | #include <dm.h> |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 15 | #include <errno.h> |
Simon Glass | fc55736 | 2022-03-04 08:43:05 -0700 | [diff] [blame] | 16 | #include <event.h> |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 17 | #include <fdtdec.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 18 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 19 | #include <log.h> |
Simon Glass | a7b1d95 | 2016-01-17 16:11:13 -0700 | [diff] [blame] | 20 | #include <pch.h> |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 21 | #include <asm/cpu.h> |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 22 | #include <asm/cpu_common.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 23 | #include <asm/global_data.h> |
Simon Glass | 5535730 | 2016-03-11 22:06:55 -0700 | [diff] [blame] | 24 | #include <asm/intel_regs.h> |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 25 | #include <asm/io.h> |
Simon Glass | d22f5c9 | 2014-11-12 22:42:27 -0700 | [diff] [blame] | 26 | #include <asm/lapic.h> |
Simon Glass | 9c852d7 | 2016-03-16 07:44:36 -0600 | [diff] [blame] | 27 | #include <asm/lpc_common.h> |
Simon Glass | 2df6188 | 2016-03-11 22:06:54 -0700 | [diff] [blame] | 28 | #include <asm/microcode.h> |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 29 | #include <asm/msr.h> |
| 30 | #include <asm/mtrr.h> |
Simon Glass | 3274ae0 | 2014-11-12 22:42:13 -0700 | [diff] [blame] | 31 | #include <asm/pci.h> |
Simon Glass | 98f139b | 2014-11-12 22:42:10 -0700 | [diff] [blame] | 32 | #include <asm/post.h> |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 33 | #include <asm/processor.h> |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 34 | #include <asm/arch/model_206ax.h> |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 35 | #include <asm/arch/pch.h> |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 36 | #include <asm/arch/sandybridge.h> |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 37 | |
| 38 | DECLARE_GLOBAL_DATA_PTR; |
| 39 | |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 40 | static int set_flex_ratio_to_tdp_nominal(void) |
| 41 | { |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 42 | /* Minimum CPU revision for configurable TDP support */ |
| 43 | if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID) |
| 44 | return -EINVAL; |
| 45 | |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 46 | return cpu_set_flex_ratio_to_tdp_nominal(); |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 49 | int arch_cpu_init(void) |
| 50 | { |
Simon Glass | 7567f46 | 2015-03-05 12:25:17 -0700 | [diff] [blame] | 51 | post_code(POST_CPU_INIT); |
Simon Glass | 7567f46 | 2015-03-05 12:25:17 -0700 | [diff] [blame] | 52 | |
| 53 | return x86_cpu_init_f(); |
| 54 | } |
| 55 | |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 56 | static int ivybridge_cpu_init(void) |
Simon Glass | 7567f46 | 2015-03-05 12:25:17 -0700 | [diff] [blame] | 57 | { |
Simon Glass | 3274ae0 | 2014-11-12 22:42:13 -0700 | [diff] [blame] | 58 | struct pci_controller *hose; |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 59 | struct udevice *bus, *dev; |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 60 | int ret; |
| 61 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 62 | post_code(0x70); |
| 63 | ret = uclass_get_device(UCLASS_PCI, 0, &bus); |
| 64 | post_code(0x71); |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 65 | if (ret) |
| 66 | return ret; |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 67 | post_code(0x72); |
| 68 | hose = dev_get_uclass_priv(bus); |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 69 | |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 70 | /* TODO(sjg@chromium.org): Get rid of gd->hose */ |
| 71 | gd->hose = hose; |
Simon Glass | 3274ae0 | 2014-11-12 22:42:13 -0700 | [diff] [blame] | 72 | |
Simon Glass | c7298e7 | 2016-02-11 13:23:26 -0700 | [diff] [blame] | 73 | ret = uclass_first_device_err(UCLASS_LPC, &dev); |
| 74 | if (ret) |
| 75 | return ret; |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 76 | |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 77 | /* |
| 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 Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 80 | * happens in checkcpu() when we have a console |
Simon Glass | f226c41 | 2014-11-12 22:42:19 -0700 | [diff] [blame] | 81 | */ |
| 82 | ret = set_flex_ratio_to_tdp_nominal(); |
| 83 | if (ret) |
| 84 | return ret; |
| 85 | |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 86 | return 0; |
| 87 | } |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 88 | EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, ivybridge_cpu_init); |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 89 | |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 90 | #define PCH_EHCI0_TEMP_BAR0 0xe8000000 |
| 91 | #define PCH_EHCI1_TEMP_BAR0 0xe8000400 |
| 92 | #define PCH_XHCI_TEMP_BAR0 0xe8001000 |
| 93 | |
| 94 | /* |
| 95 | * Setup USB controller MMIO BAR to prevent the reference code from |
| 96 | * resetting the controller. |
| 97 | * |
| 98 | * The BAR will be re-assigned during device enumeration so these are only |
| 99 | * temporary. |
| 100 | * |
| 101 | * This is used to speed up the resume path. |
| 102 | */ |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 103 | static void enable_usb_bar(struct udevice *bus) |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 104 | { |
| 105 | pci_dev_t usb0 = PCH_EHCI1_DEV; |
| 106 | pci_dev_t usb1 = PCH_EHCI2_DEV; |
| 107 | pci_dev_t usb3 = PCH_XHCI_DEV; |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 108 | ulong cmd; |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 109 | |
| 110 | /* USB Controller 1 */ |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 111 | pci_bus_write_config(bus, usb0, PCI_BASE_ADDRESS_0, |
| 112 | PCH_EHCI0_TEMP_BAR0, PCI_SIZE_32); |
| 113 | pci_bus_read_config(bus, usb0, PCI_COMMAND, &cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 114 | cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 115 | pci_bus_write_config(bus, usb0, PCI_COMMAND, cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 116 | |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 117 | /* USB Controller 2 */ |
| 118 | pci_bus_write_config(bus, usb1, PCI_BASE_ADDRESS_0, |
| 119 | PCH_EHCI1_TEMP_BAR0, PCI_SIZE_32); |
| 120 | pci_bus_read_config(bus, usb1, PCI_COMMAND, &cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 121 | cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 122 | pci_bus_write_config(bus, usb1, PCI_COMMAND, cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 123 | |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 124 | /* USB3 Controller 1 */ |
| 125 | pci_bus_write_config(bus, usb3, PCI_BASE_ADDRESS_0, |
| 126 | PCH_XHCI_TEMP_BAR0, PCI_SIZE_32); |
| 127 | pci_bus_read_config(bus, usb3, PCI_COMMAND, &cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 128 | cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 129 | pci_bus_write_config(bus, usb3, PCI_COMMAND, cmd, PCI_SIZE_32); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 132 | int checkcpu(void) |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 133 | { |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 134 | enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE; |
Simon Glass | b20cf04 | 2016-01-17 16:11:19 -0700 | [diff] [blame] | 135 | struct udevice *dev, *lpc; |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 136 | uint32_t pm1_cnt; |
| 137 | uint16_t pm1_sts; |
Simon Glass | 367077a | 2014-11-12 22:42:20 -0700 | [diff] [blame] | 138 | int ret; |
| 139 | |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 140 | /* TODO: cmos_post_init() */ |
| 141 | if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) { |
| 142 | debug("soft reset detected\n"); |
| 143 | boot_mode = PEI_BOOT_SOFT_RESET; |
| 144 | |
| 145 | /* System is not happy after keyboard reset... */ |
| 146 | debug("Issuing CF9 warm reset\n"); |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 147 | reset_cpu(); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 150 | ret = cpu_common_init(); |
Simon Glass | f7f5674 | 2016-07-25 18:58:59 -0600 | [diff] [blame] | 151 | if (ret) { |
| 152 | debug("%s: cpu_common_init() failed\n", __func__); |
Simon Glass | a7b1d95 | 2016-01-17 16:11:13 -0700 | [diff] [blame] | 153 | return ret; |
Simon Glass | f7f5674 | 2016-07-25 18:58:59 -0600 | [diff] [blame] | 154 | } |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 155 | |
| 156 | /* Check PM1_STS[15] to see if we are waking from Sx */ |
| 157 | pm1_sts = inw(DEFAULT_PMBASE + PM1_STS); |
| 158 | |
| 159 | /* Read PM1_CNT[12:10] to determine which Sx state */ |
| 160 | pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT); |
| 161 | |
| 162 | if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) { |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 163 | debug("Resume from S3 detected, but disabled.\n"); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 164 | } else { |
| 165 | /* |
| 166 | * TODO: An indication of life might be possible here (e.g. |
| 167 | * keyboard light) |
| 168 | */ |
| 169 | } |
| 170 | post_code(POST_EARLY_INIT); |
| 171 | |
| 172 | /* Enable SPD ROMs and DDR-III DRAM */ |
Simon Glass | c7298e7 | 2016-02-11 13:23:26 -0700 | [diff] [blame] | 173 | ret = uclass_first_device_err(UCLASS_I2C, &dev); |
Simon Glass | e536796 | 2017-01-16 07:03:38 -0700 | [diff] [blame] | 174 | if (ret) { |
| 175 | debug("%s: Failed to get I2C (ret=%d)\n", __func__, ret); |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 176 | return ret; |
Simon Glass | e536796 | 2017-01-16 07:03:38 -0700 | [diff] [blame] | 177 | } |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 178 | |
| 179 | /* Prepare USB controller early in S3 resume */ |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 180 | if (boot_mode == PEI_BOOT_RESUME) { |
| 181 | uclass_first_device(UCLASS_LPC, &lpc); |
Simon Glass | 18df7d0 | 2016-01-17 16:11:46 -0700 | [diff] [blame] | 182 | enable_usb_bar(pci_get_controller(lpc->parent)); |
Simon Glass | 780ba48 | 2016-03-11 22:06:58 -0700 | [diff] [blame] | 183 | } |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 184 | |
| 185 | gd->arch.pei_boot_mode = boot_mode; |
| 186 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | int print_cpuinfo(void) |
| 191 | { |
| 192 | char processor_name[CPU_MAX_NAME_LEN]; |
| 193 | const char *name; |
| 194 | |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 195 | /* Print processor name */ |
| 196 | name = cpu_get_name(processor_name); |
| 197 | printf("CPU: %s\n", name); |
| 198 | |
Simon Glass | 30580fc | 2014-11-12 22:42:23 -0700 | [diff] [blame] | 199 | post_code(POST_CPU_INFO); |
| 200 | |
Simon Glass | 0b36ecd | 2014-11-12 22:42:07 -0700 | [diff] [blame] | 201 | return 0; |
| 202 | } |
Simon Glass | f2dd470 | 2015-10-18 19:51:27 -0600 | [diff] [blame] | 203 | |
| 204 | void board_debug_uart_init(void) |
| 205 | { |
| 206 | /* This enables the debug UART */ |
Simon Glass | a546458 | 2019-08-31 21:23:18 -0600 | [diff] [blame] | 207 | pci_x86_write_config(PCH_LPC_DEV, LPC_EN, COMA_LPC_EN, PCI_SIZE_16); |
Simon Glass | f2dd470 | 2015-10-18 19:51:27 -0600 | [diff] [blame] | 208 | } |