Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
Martin Roth | ebabfad | 2016-04-10 11:09:16 -0600 | [diff] [blame] | 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 16 | #include <arch/acpi.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 17 | #include <bootstate.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 18 | #include <cbmem.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 19 | #include <console/console.h> |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 20 | #include <cpu/x86/mp.h> |
Barnali Sarkar | 66fe0c4 | 2017-05-23 18:17:14 +0530 | [diff] [blame] | 21 | #include <cpu/x86/msr.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 22 | #include <device/mmio.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 25 | #include <device/pci_ops.h> |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 26 | #include <intelblocks/acpi.h> |
Kyösti Mälkki | 32d47eb | 2019-09-28 00:00:30 +0300 | [diff] [blame] | 27 | #include <intelblocks/cfg.h> |
Barnali Sarkar | e70142c | 2017-03-28 16:32:33 +0530 | [diff] [blame] | 28 | #include <intelblocks/fast_spi.h> |
Barnali Sarkar | 66fe0c4 | 2017-05-23 18:17:14 +0530 | [diff] [blame] | 29 | #include <intelblocks/msr.h> |
Subrata Banik | f699c14 | 2018-06-08 17:57:37 +0530 | [diff] [blame] | 30 | #include <intelblocks/p2sb.h> |
Duncan Laurie | 4c8fbc0 | 2018-03-26 02:19:58 -0700 | [diff] [blame] | 31 | #include <intelblocks/xdci.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 32 | #include <fsp/api.h> |
| 33 | #include <fsp/util.h> |
Barnali Sarkar | 66fe0c4 | 2017-05-23 18:17:14 +0530 | [diff] [blame] | 34 | #include <intelblocks/cpulib.h> |
Bora Guvendik | 33117ec | 2017-04-10 15:49:02 -0700 | [diff] [blame] | 35 | #include <intelblocks/itss.h> |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 36 | #include <intelblocks/pmclib.h> |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 37 | #include <romstage_handoff.h> |
Furquan Shaikh | d2c2f83 | 2018-11-07 10:24:31 -0800 | [diff] [blame] | 38 | #include <soc/cpu.h> |
| 39 | #include <soc/heci.h> |
| 40 | #include <soc/intel/common/vbt.h> |
Andrey Petrov | e07e13d | 2016-03-18 14:43:00 -0700 | [diff] [blame] | 41 | #include <soc/iomap.h> |
Bora Guvendik | 33117ec | 2017-04-10 15:49:02 -0700 | [diff] [blame] | 42 | #include <soc/itss.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 43 | #include <soc/nvs.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 44 | #include <soc/pci_devs.h> |
Andrey Petrov | 3dbea29 | 2016-06-14 22:20:28 -0700 | [diff] [blame] | 45 | #include <soc/pm.h> |
Subrata Banik | 7952e28 | 2017-03-14 18:26:27 +0530 | [diff] [blame] | 46 | #include <soc/systemagent.h> |
Furquan Shaikh | d2c2f83 | 2018-11-07 10:24:31 -0800 | [diff] [blame] | 47 | #include <spi-generic.h> |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 48 | #include <timer.h> |
Felix Singer | e59ae10 | 2019-05-02 13:57:57 +0200 | [diff] [blame] | 49 | #include <soc/ramstage.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 50 | |
| 51 | #include "chip.h" |
| 52 | |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 53 | #define DUAL_ROLE_CFG0 0x80d8 |
| 54 | #define SW_VBUS_VALID_MASK (1 << 24) |
| 55 | #define SW_IDPIN_EN_MASK (1 << 21) |
| 56 | #define SW_IDPIN_MASK (1 << 20) |
| 57 | #define SW_IDPIN_HOST (0 << 20) |
| 58 | #define DUAL_ROLE_CFG1 0x80dc |
| 59 | #define DRD_MODE_MASK (1 << 29) |
| 60 | #define DRD_MODE_HOST (1 << 29) |
| 61 | |
John Zhao | 57aa8b6 | 2019-01-14 09:15:50 -0800 | [diff] [blame] | 62 | #define CFG_XHCLKGTEN 0x8650 |
| 63 | /* Naking USB2.0 EPs for Backbone Clock Gating and PLL Shutdown */ |
| 64 | #define NUEFBCGPS (1 << 28) |
| 65 | /* SRAM Power Gate Enable */ |
| 66 | #define SRAMPGTEN (1 << 27) |
| 67 | /* SS Link PLL Shutdown Enable */ |
| 68 | #define SSLSE (1 << 26) |
| 69 | /* USB2 PLL Shutdown Enable */ |
| 70 | #define USB2PLLSE (1 << 25) |
| 71 | /* IOSF Sideband Trunk Clock Gating Enable */ |
| 72 | #define IOSFSTCGE (1 << 24) |
| 73 | /* BIT[23:20] HS Backbone PXP Trunk Clock Gate Enable */ |
| 74 | #define HSTCGE (1 << 23 | 1 << 22) |
| 75 | /* BIT[19:16] SS Backbone PXP Trunk Clock Gate Enable */ |
| 76 | #define SSTCGE (1 << 19 | 1 << 18 | 1 << 17) |
| 77 | /* XHC Ignore_EU3S */ |
| 78 | #define XHCIGEU3S (1 << 15) |
| 79 | /* XHC Frame Timer Clock Shutdown Enable */ |
| 80 | #define XHCFTCLKSE (1 << 14) |
| 81 | /* XHC Backbone PXP Trunk Clock Gate In Presence of ISOCH EP */ |
| 82 | #define XHCBBTCGIPISO (1 << 13) |
| 83 | /* XHC HS Backbone PXP Trunk Clock Gate U2 non RWE */ |
| 84 | #define XHCHSTCGU2NRWE (1 << 12) |
| 85 | /* BIT[11:10] XHC USB2 PLL Shutdown Lx Enable */ |
| 86 | #define XHCUSB2PLLSDLE (1 << 11 | 1 << 10) |
| 87 | /* BIT[9:8] HS Backbone PXP PLL Shutdown Ux Enable */ |
| 88 | #define HSUXDMIPLLSE (1 << 9) |
| 89 | /* BIT[7:5] SS Backbone PXP PLL shutdown Ux Enable */ |
| 90 | #define SSPLLSUE (1 << 6) |
| 91 | /* XHC Backbone Local Clock Gating Enable */ |
| 92 | #define XHCBLCGE (1 << 4) |
| 93 | /* HS Link Trunk Clock Gating Enable */ |
| 94 | #define HSLTCGE (1 << 3) |
| 95 | /* SS Link Trunk Clock Gating Enable */ |
| 96 | #define SSLTCGE (1 << 2) |
| 97 | /* IOSF Backbone Trunk Clock Gating Enable */ |
| 98 | #define IOSFBTCGE (1 << 1) |
| 99 | /* IOSF Gasket Backbone Local Clock Gating Enable */ |
| 100 | #define IOSFGBLCGE (1 << 0) |
| 101 | |
Duncan Laurie | bf713b0 | 2018-05-07 15:33:18 -0700 | [diff] [blame] | 102 | const char *soc_acpi_name(const struct device *dev) |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 103 | { |
| 104 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 105 | return "PCI0"; |
| 106 | |
Duncan Laurie | bf713b0 | 2018-05-07 15:33:18 -0700 | [diff] [blame] | 107 | if (dev->path.type == DEVICE_PATH_USB) { |
| 108 | switch (dev->path.usb.port_type) { |
| 109 | case 0: |
| 110 | /* Root Hub */ |
| 111 | return "RHUB"; |
| 112 | case 2: |
| 113 | /* USB2 ports */ |
| 114 | switch (dev->path.usb.port_id) { |
| 115 | case 0: return "HS01"; |
| 116 | case 1: return "HS02"; |
| 117 | case 2: return "HS03"; |
| 118 | case 3: return "HS04"; |
| 119 | case 4: return "HS05"; |
| 120 | case 5: return "HS06"; |
| 121 | case 6: return "HS07"; |
| 122 | case 7: return "HS08"; |
Furquan Shaikh | ad62b9a | 2019-01-30 22:47:17 -0800 | [diff] [blame] | 123 | case 8: |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 124 | if (CONFIG(SOC_INTEL_GLK)) |
Furquan Shaikh | ad62b9a | 2019-01-30 22:47:17 -0800 | [diff] [blame] | 125 | return "HS09"; |
Duncan Laurie | bf713b0 | 2018-05-07 15:33:18 -0700 | [diff] [blame] | 126 | } |
| 127 | break; |
| 128 | case 3: |
| 129 | /* USB3 ports */ |
| 130 | switch (dev->path.usb.port_id) { |
| 131 | case 0: return "SS01"; |
| 132 | case 1: return "SS02"; |
| 133 | case 2: return "SS03"; |
| 134 | case 3: return "SS04"; |
| 135 | case 4: return "SS05"; |
| 136 | case 5: return "SS06"; |
| 137 | } |
| 138 | break; |
| 139 | } |
| 140 | return NULL; |
| 141 | } |
| 142 | |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 143 | if (dev->path.type != DEVICE_PATH_PCI) |
| 144 | return NULL; |
| 145 | |
| 146 | switch (dev->path.pci.devfn) { |
| 147 | /* DSDT: acpi/northbridge.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 148 | case SA_DEVFN_ROOT: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 149 | return "MCHC"; |
| 150 | /* DSDT: acpi/lpc.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 151 | case PCH_DEVFN_LPC: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 152 | return "LPCB"; |
| 153 | /* DSDT: acpi/xhci.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 154 | case PCH_DEVFN_XHCI: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 155 | return "XHCI"; |
| 156 | /* DSDT: acpi/pch_hda.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 157 | case PCH_DEVFN_HDA: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 158 | return "HDAS"; |
| 159 | /* DSDT: acpi/lpss.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 160 | case PCH_DEVFN_UART0: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 161 | return "URT1"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 162 | case PCH_DEVFN_UART1: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 163 | return "URT2"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 164 | case PCH_DEVFN_UART2: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 165 | return "URT3"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 166 | case PCH_DEVFN_UART3: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 167 | return "URT4"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 168 | case PCH_DEVFN_SPI0: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 169 | return "SPI1"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 170 | case PCH_DEVFN_SPI1: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 171 | return "SPI2"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 172 | case PCH_DEVFN_SPI2: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 173 | return "SPI3"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 174 | case PCH_DEVFN_PWM: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 175 | return "PWM"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 176 | case PCH_DEVFN_I2C0: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 177 | return "I2C0"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 178 | case PCH_DEVFN_I2C1: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 179 | return "I2C1"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 180 | case PCH_DEVFN_I2C2: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 181 | return "I2C2"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 182 | case PCH_DEVFN_I2C3: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 183 | return "I2C3"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 184 | case PCH_DEVFN_I2C4: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 185 | return "I2C4"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 186 | case PCH_DEVFN_I2C5: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 187 | return "I2C5"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 188 | case PCH_DEVFN_I2C6: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 189 | return "I2C6"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 190 | case PCH_DEVFN_I2C7: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 191 | return "I2C7"; |
| 192 | /* Storage */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 193 | case PCH_DEVFN_SDCARD: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 194 | return "SDCD"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 195 | case PCH_DEVFN_EMMC: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 196 | return "EMMC"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 197 | case PCH_DEVFN_SDIO: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 198 | return "SDIO"; |
Vaibhav Shankar | ec9168f | 2016-09-16 14:20:53 -0700 | [diff] [blame] | 199 | /* PCIe */ |
Venkateswarlu Vinjamuri | f03c63e | 2018-04-12 10:13:43 -0700 | [diff] [blame] | 200 | case PCH_DEVFN_PCIE1: |
| 201 | return "RP03"; |
Venkateswarlu Vinjamuri | efeb690 | 2018-04-09 11:14:42 -0700 | [diff] [blame] | 202 | case PCH_DEVFN_PCIE5: |
Vaibhav Shankar | ec9168f | 2016-09-16 14:20:53 -0700 | [diff] [blame] | 203 | return "RP01"; |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | return NULL; |
| 207 | } |
| 208 | |
Elyes HAOUAS | 06e8315 | 2018-05-24 22:48:14 +0200 | [diff] [blame] | 209 | static void pci_domain_set_resources(struct device *dev) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 210 | { |
Lee Leahy | 1d20fe7 | 2017-03-09 09:50:28 -0800 | [diff] [blame] | 211 | assign_resources(dev->link_list); |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static struct device_operations pci_domain_ops = { |
| 215 | .read_resources = pci_domain_read_resources, |
| 216 | .set_resources = pci_domain_set_resources, |
| 217 | .enable_resources = NULL, |
| 218 | .init = NULL, |
| 219 | .scan_bus = pci_domain_scan_bus, |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 220 | .acpi_name = &soc_acpi_name, |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | static struct device_operations cpu_bus_ops = { |
| 224 | .read_resources = DEVICE_NOOP, |
| 225 | .set_resources = DEVICE_NOOP, |
| 226 | .enable_resources = DEVICE_NOOP, |
Aaron Durbin | ac3e482 | 2017-06-14 13:21:00 -0500 | [diff] [blame] | 227 | .init = apollolake_init_cpus, |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 228 | .scan_bus = NULL, |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 229 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 230 | }; |
| 231 | |
Elyes HAOUAS | 06e8315 | 2018-05-24 22:48:14 +0200 | [diff] [blame] | 232 | static void enable_dev(struct device *dev) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 233 | { |
| 234 | /* Set the operations if it is a special bus type */ |
Lee Leahy | 4430f9f | 2017-03-09 10:00:30 -0800 | [diff] [blame] | 235 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 236 | dev->ops = &pci_domain_ops; |
Lee Leahy | 4430f9f | 2017-03-09 10:00:30 -0800 | [diff] [blame] | 237 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 238 | dev->ops = &cpu_bus_ops; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 241 | /* |
| 242 | * If the PCIe root port at function 0 is disabled, |
| 243 | * the PCIe root ports might be coalesced after FSP silicon init. |
| 244 | * The below function will swap the devfn of the first enabled device |
| 245 | * in devicetree and function 0 resides a pci device |
| 246 | * so that it won't confuse coreboot. |
| 247 | */ |
| 248 | static void pcie_update_device_tree(unsigned int devfn0, int num_funcs) |
| 249 | { |
Elyes HAOUAS | 06e8315 | 2018-05-24 22:48:14 +0200 | [diff] [blame] | 250 | struct device *func0; |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 251 | unsigned int devfn; |
| 252 | int i; |
| 253 | unsigned int inc = PCI_DEVFN(0, 1); |
| 254 | |
Kyösti Mälkki | 903b40a | 2019-07-03 07:25:59 +0300 | [diff] [blame] | 255 | func0 = pcidev_path_on_root(devfn0); |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 256 | if (func0 == NULL) |
| 257 | return; |
| 258 | |
| 259 | /* No more functions if function 0 is disabled. */ |
| 260 | if (pci_read_config32(func0, PCI_VENDOR_ID) == 0xffffffff) |
| 261 | return; |
| 262 | |
| 263 | devfn = devfn0 + inc; |
| 264 | |
| 265 | /* |
Elyes HAOUAS | 0f82c12 | 2019-12-04 19:23:50 +0100 | [diff] [blame] | 266 | * Increase function by 1. |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 267 | * Then find first enabled device to replace func0 |
| 268 | * as that port was move to func0. |
| 269 | */ |
| 270 | for (i = 1; i < num_funcs; i++, devfn += inc) { |
Kyösti Mälkki | 903b40a | 2019-07-03 07:25:59 +0300 | [diff] [blame] | 271 | struct device *dev = pcidev_path_on_root(devfn); |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 272 | if (dev == NULL) |
| 273 | continue; |
| 274 | |
| 275 | if (!dev->enabled) |
| 276 | continue; |
| 277 | /* Found the first enabled device in given dev number */ |
| 278 | func0->path.pci.devfn = dev->path.pci.devfn; |
| 279 | dev->path.pci.devfn = devfn0; |
| 280 | break; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | static void pcie_override_devicetree_after_silicon_init(void) |
| 285 | { |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 286 | pcie_update_device_tree(PCH_DEVFN_PCIE1, 4); |
| 287 | pcie_update_device_tree(PCH_DEVFN_PCIE5, 2); |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 288 | } |
| 289 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 290 | /* Configure package power limits */ |
| 291 | static void set_power_limits(void) |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 292 | { |
Kyösti Mälkki | 4af4e7f | 2019-07-14 05:50:20 +0300 | [diff] [blame] | 293 | struct soc_intel_apollolake_config *cfg; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 294 | msr_t rapl_msr_reg, limit; |
| 295 | uint32_t power_unit; |
| 296 | uint32_t tdp, min_power, max_power; |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 297 | uint32_t pl2_val; |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 298 | |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 299 | cfg = config_of_soc(); |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 300 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 301 | if (CONFIG(APL_SKIP_SET_POWER_LIMITS)) { |
Mario Scheithauer | 38b6100 | 2017-07-25 10:52:41 +0200 | [diff] [blame] | 302 | printk(BIOS_INFO, "Skip the RAPL settings.\n"); |
| 303 | return; |
| 304 | } |
| 305 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 306 | /* Get units */ |
| 307 | rapl_msr_reg = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 308 | power_unit = 1 << (rapl_msr_reg.lo & 0xf); |
| 309 | |
| 310 | /* Get power defaults for this SKU */ |
| 311 | rapl_msr_reg = rdmsr(MSR_PKG_POWER_SKU); |
| 312 | tdp = rapl_msr_reg.lo & PKG_POWER_LIMIT_MASK; |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 313 | pl2_val = rapl_msr_reg.hi & PKG_POWER_LIMIT_MASK; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 314 | min_power = (rapl_msr_reg.lo >> 16) & PKG_POWER_LIMIT_MASK; |
| 315 | max_power = rapl_msr_reg.hi & PKG_POWER_LIMIT_MASK; |
| 316 | |
| 317 | if (min_power > 0 && tdp < min_power) |
| 318 | tdp = min_power; |
| 319 | |
| 320 | if (max_power > 0 && tdp > max_power) |
| 321 | tdp = max_power; |
| 322 | |
| 323 | /* Set PL1 override value */ |
| 324 | tdp = (cfg->tdp_pl1_override_mw == 0) ? |
| 325 | tdp : (cfg->tdp_pl1_override_mw * power_unit) / 1000; |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 326 | /* Set PL2 override value */ |
| 327 | pl2_val = (cfg->tdp_pl2_override_mw == 0) ? |
| 328 | pl2_val : (cfg->tdp_pl2_override_mw * power_unit) / 1000; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 329 | |
| 330 | /* Set long term power limit to TDP */ |
| 331 | limit.lo = tdp & PKG_POWER_LIMIT_MASK; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 332 | /* Set PL1 Pkg Power clamp bit */ |
| 333 | limit.lo |= PKG_POWER_LIMIT_CLAMP; |
| 334 | |
| 335 | limit.lo |= PKG_POWER_LIMIT_EN; |
| 336 | limit.lo |= (MB_POWER_LIMIT1_TIME_DEFAULT & |
| 337 | PKG_POWER_LIMIT_TIME_MASK) << PKG_POWER_LIMIT_TIME_SHIFT; |
| 338 | |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 339 | /* Set short term power limit PL2 */ |
| 340 | limit.hi = pl2_val & PKG_POWER_LIMIT_MASK; |
| 341 | limit.hi |= PKG_POWER_LIMIT_EN; |
| 342 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 343 | /* Program package power limits in RAPL MSR */ |
| 344 | wrmsr(MSR_PKG_POWER_LIMIT, limit); |
| 345 | printk(BIOS_INFO, "RAPL PL1 %d.%dW\n", tdp / power_unit, |
| 346 | 100 * (tdp % power_unit) / power_unit); |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 347 | printk(BIOS_INFO, "RAPL PL2 %d.%dW\n", pl2_val / power_unit, |
| 348 | 100 * (pl2_val % power_unit) / power_unit); |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 349 | |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 350 | /* Setting RAPL MMIO register for Power limits. |
| 351 | * RAPL driver is using MSR instead of MMIO. |
| 352 | * So, disabled LIMIT_EN bit for MMIO. */ |
Subrata Banik | 208587e | 2017-05-19 18:38:24 +0530 | [diff] [blame] | 353 | MCHBAR32(MCHBAR_RAPL_PPL) = limit.lo & ~PKG_POWER_LIMIT_EN; |
| 354 | MCHBAR32(MCHBAR_RAPL_PPL + 4) = limit.hi & ~PKG_POWER_LIMIT_EN; |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 355 | } |
| 356 | |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 357 | /* Overwrites the SCI IRQ if another IRQ number is given by device tree. */ |
| 358 | static void set_sci_irq(void) |
| 359 | { |
Kyösti Mälkki | 4af4e7f | 2019-07-14 05:50:20 +0300 | [diff] [blame] | 360 | struct soc_intel_apollolake_config *cfg; |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 361 | uint32_t scis; |
| 362 | |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 363 | cfg = config_of_soc(); |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 364 | |
| 365 | /* Change only if a device tree entry exists. */ |
| 366 | if (cfg->sci_irq) { |
| 367 | scis = soc_read_sci_irq_select(); |
| 368 | scis &= ~SCI_IRQ_SEL; |
| 369 | scis |= (cfg->sci_irq << SCI_IRQ_ADJUST) & SCI_IRQ_SEL; |
| 370 | soc_write_sci_irq_select(scis); |
| 371 | } |
| 372 | } |
| 373 | |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 374 | static void soc_init(void *data) |
| 375 | { |
Aaron Durbin | 81d1e09 | 2016-07-13 01:49:10 -0500 | [diff] [blame] | 376 | /* Snapshot the current GPIO IRQ polarities. FSP is setting a |
| 377 | * default policy that doesn't honor boards' requirements. */ |
| 378 | itss_snapshot_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END); |
| 379 | |
Karthikeyan Ramasubramanian | 6629b4b | 2019-05-01 10:22:22 -0600 | [diff] [blame] | 380 | /* |
| 381 | * Clear the GPI interrupt status and enable registers. These |
| 382 | * registers do not get reset to default state when booting from S5. |
| 383 | */ |
| 384 | gpi_clear_int_cfg(); |
| 385 | |
Aaron Durbin | 6c191d8 | 2016-11-29 21:22:42 -0600 | [diff] [blame] | 386 | fsp_silicon_init(romstage_handoff_is_resume()); |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 387 | |
Aaron Durbin | 81d1e09 | 2016-07-13 01:49:10 -0500 | [diff] [blame] | 388 | /* Restore GPIO IRQ polarities back to previous settings. */ |
| 389 | itss_restore_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END); |
| 390 | |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 391 | /* override 'enabled' setting in device tree if needed */ |
| 392 | pcie_override_devicetree_after_silicon_init(); |
| 393 | |
Aaron Durbin | fadfc2e | 2016-07-01 16:36:03 -0500 | [diff] [blame] | 394 | /* |
| 395 | * Keep the P2SB device visible so it and the other devices are |
| 396 | * visible in coreboot for driver support and PCI resource allocation. |
| 397 | * There is a UPD setting for this, but it's more consistent to use |
| 398 | * hide and unhide symmetrically. |
| 399 | */ |
| 400 | p2sb_unhide(); |
| 401 | |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 402 | /* Allocate ACPI NVS in CBMEM */ |
John Zhao | 5744884 | 2019-05-20 16:10:16 -0700 | [diff] [blame] | 403 | cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(struct global_nvs_t)); |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 404 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 405 | /* Set RAPL MSR for Package power limits*/ |
| 406 | set_power_limits(); |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 407 | |
| 408 | /* |
| 409 | * FSP-S routes SCI to IRQ 9. With the help of this function you can |
| 410 | * select another IRQ for SCI. |
| 411 | */ |
| 412 | set_sci_irq(); |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 415 | static void soc_final(void *data) |
| 416 | { |
Andrey Petrov | 3dbea29 | 2016-06-14 22:20:28 -0700 | [diff] [blame] | 417 | /* Make sure payload/OS can't trigger global reset */ |
Michael Niewöhner | 1c6ea92 | 2019-11-02 12:20:53 +0100 | [diff] [blame] | 418 | pmc_global_reset_disable_and_lock(); |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Lee Leahy | bab8be2 | 2017-03-09 09:53:58 -0800 | [diff] [blame] | 421 | static void disable_dev(struct device *dev, FSP_S_CONFIG *silconfig) |
| 422 | { |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 423 | switch (dev->path.pci.devfn) { |
Maxim Polyakov | 7b98e3e | 2020-02-16 11:51:57 +0300 | [diff] [blame] | 424 | case PCH_DEVFN_NPK: |
| 425 | /* |
| 426 | * Disable this device in the parse_devicetree_setting() function |
| 427 | * in romstage.c |
| 428 | */ |
| 429 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 430 | case PCH_DEVFN_ISH: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 431 | silconfig->IshEnable = 0; |
| 432 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 433 | case PCH_DEVFN_SATA: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 434 | silconfig->EnableSata = 0; |
| 435 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 436 | case PCH_DEVFN_PCIE5: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 437 | silconfig->PcieRootPortEn[0] = 0; |
| 438 | silconfig->PcieRpHotPlug[0] = 0; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 439 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 440 | case PCH_DEVFN_PCIE6: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 441 | silconfig->PcieRootPortEn[1] = 0; |
| 442 | silconfig->PcieRpHotPlug[1] = 0; |
| 443 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 444 | case PCH_DEVFN_PCIE1: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 445 | silconfig->PcieRootPortEn[2] = 0; |
| 446 | silconfig->PcieRpHotPlug[2] = 0; |
| 447 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 448 | case PCH_DEVFN_PCIE2: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 449 | silconfig->PcieRootPortEn[3] = 0; |
| 450 | silconfig->PcieRpHotPlug[3] = 0; |
| 451 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 452 | case PCH_DEVFN_PCIE3: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 453 | silconfig->PcieRootPortEn[4] = 0; |
| 454 | silconfig->PcieRpHotPlug[4] = 0; |
| 455 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 456 | case PCH_DEVFN_PCIE4: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 457 | silconfig->PcieRootPortEn[5] = 0; |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 458 | silconfig->PcieRpHotPlug[5] = 0; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 459 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 460 | case PCH_DEVFN_XHCI: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 461 | silconfig->Usb30Mode = 0; |
| 462 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 463 | case PCH_DEVFN_XDCI: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 464 | silconfig->UsbOtg = 0; |
| 465 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 466 | case PCH_DEVFN_I2C0: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 467 | silconfig->I2c0Enable = 0; |
| 468 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 469 | case PCH_DEVFN_I2C1: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 470 | silconfig->I2c1Enable = 0; |
| 471 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 472 | case PCH_DEVFN_I2C2: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 473 | silconfig->I2c2Enable = 0; |
| 474 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 475 | case PCH_DEVFN_I2C3: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 476 | silconfig->I2c3Enable = 0; |
| 477 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 478 | case PCH_DEVFN_I2C4: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 479 | silconfig->I2c4Enable = 0; |
| 480 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 481 | case PCH_DEVFN_I2C5: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 482 | silconfig->I2c5Enable = 0; |
| 483 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 484 | case PCH_DEVFN_I2C6: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 485 | silconfig->I2c6Enable = 0; |
| 486 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 487 | case PCH_DEVFN_I2C7: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 488 | silconfig->I2c7Enable = 0; |
| 489 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 490 | case PCH_DEVFN_UART0: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 491 | silconfig->Hsuart0Enable = 0; |
| 492 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 493 | case PCH_DEVFN_UART1: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 494 | silconfig->Hsuart1Enable = 0; |
| 495 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 496 | case PCH_DEVFN_UART2: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 497 | silconfig->Hsuart2Enable = 0; |
| 498 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 499 | case PCH_DEVFN_UART3: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 500 | silconfig->Hsuart3Enable = 0; |
| 501 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 502 | case PCH_DEVFN_SPI0: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 503 | silconfig->Spi0Enable = 0; |
| 504 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 505 | case PCH_DEVFN_SPI1: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 506 | silconfig->Spi1Enable = 0; |
| 507 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 508 | case PCH_DEVFN_SPI2: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 509 | silconfig->Spi2Enable = 0; |
| 510 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 511 | case PCH_DEVFN_SDCARD: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 512 | silconfig->SdcardEnabled = 0; |
| 513 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 514 | case PCH_DEVFN_EMMC: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 515 | silconfig->eMMCEnabled = 0; |
| 516 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 517 | case PCH_DEVFN_SDIO: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 518 | silconfig->SdioEnabled = 0; |
| 519 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 520 | case PCH_DEVFN_SMBUS: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 521 | silconfig->SmbusEnable = 0; |
| 522 | break; |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 523 | #if !CONFIG(SOC_INTEL_GLK) |
Werner Zeh | de3ace0 | 2019-01-15 08:03:43 +0100 | [diff] [blame] | 524 | case SA_DEVFN_IPU: |
| 525 | silconfig->IpuEn = 0; |
| 526 | break; |
| 527 | #endif |
Nico Huber | 4074ce0 | 2019-01-31 16:45:04 +0100 | [diff] [blame] | 528 | case PCH_DEVFN_HDA: |
| 529 | silconfig->HdaEnable = 0; |
| 530 | break; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 531 | default: |
| 532 | printk(BIOS_WARNING, "PCI:%02x.%01x: Could not disable the device\n", |
| 533 | PCI_SLOT(dev->path.pci.devfn), |
| 534 | PCI_FUNC(dev->path.pci.devfn)); |
| 535 | break; |
| 536 | } |
| 537 | } |
| 538 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 539 | static void parse_devicetree(FSP_S_CONFIG *silconfig) |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 540 | { |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 541 | struct device *dev = pcidev_path_on_root(SA_DEVFN_ROOT); |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 542 | |
| 543 | if (!dev) { |
| 544 | printk(BIOS_ERR, "Could not find root device\n"); |
| 545 | return; |
| 546 | } |
| 547 | /* Only disable bus 0 devices. */ |
| 548 | for (dev = dev->bus->children; dev; dev = dev->sibling) { |
| 549 | if (!dev->enabled) |
| 550 | disable_dev(dev, silconfig); |
| 551 | } |
| 552 | } |
| 553 | |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 554 | static void apl_fsp_silicon_init_params_cb(struct soc_intel_apollolake_config |
| 555 | *cfg, FSP_S_CONFIG *silconfig) |
| 556 | { |
Maxim Polyakov | 6704049 | 2020-02-16 11:51:57 +0300 | [diff] [blame] | 557 | #if !CONFIG(SOC_INTEL_GLK) /* GLK FSP does not have these fields in FspsUpd.h yet */ |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 558 | uint8_t port; |
| 559 | |
| 560 | for (port = 0; port < APOLLOLAKE_USB2_PORT_MAX; port++) { |
Maxim Polyakov | 6704049 | 2020-02-16 11:51:57 +0300 | [diff] [blame] | 561 | if (cfg->usb_config_override) { |
| 562 | if (!cfg->usb2_port[port].enable) |
| 563 | continue; |
| 564 | |
| 565 | silconfig->PortUsb20Enable[port] = 1; |
| 566 | silconfig->PortUs20bOverCurrentPin[port] = cfg->usb2_port[port].oc_pin; |
| 567 | } |
| 568 | |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 569 | if (cfg->usb2eye[port].Usb20PerPortTxPeHalf != 0) |
| 570 | silconfig->PortUsb20PerPortTxPeHalf[port] = |
| 571 | cfg->usb2eye[port].Usb20PerPortTxPeHalf; |
| 572 | |
| 573 | if (cfg->usb2eye[port].Usb20PerPortPeTxiSet != 0) |
| 574 | silconfig->PortUsb20PerPortPeTxiSet[port] = |
| 575 | cfg->usb2eye[port].Usb20PerPortPeTxiSet; |
| 576 | |
| 577 | if (cfg->usb2eye[port].Usb20PerPortTxiSet != 0) |
| 578 | silconfig->PortUsb20PerPortTxiSet[port] = |
| 579 | cfg->usb2eye[port].Usb20PerPortTxiSet; |
| 580 | |
| 581 | if (cfg->usb2eye[port].Usb20HsSkewSel != 0) |
| 582 | silconfig->PortUsb20HsSkewSel[port] = |
| 583 | cfg->usb2eye[port].Usb20HsSkewSel; |
| 584 | |
| 585 | if (cfg->usb2eye[port].Usb20IUsbTxEmphasisEn != 0) |
| 586 | silconfig->PortUsb20IUsbTxEmphasisEn[port] = |
| 587 | cfg->usb2eye[port].Usb20IUsbTxEmphasisEn; |
| 588 | |
| 589 | if (cfg->usb2eye[port].Usb20PerPortRXISet != 0) |
| 590 | silconfig->PortUsb20PerPortRXISet[port] = |
| 591 | cfg->usb2eye[port].Usb20PerPortRXISet; |
| 592 | |
| 593 | if (cfg->usb2eye[port].Usb20HsNpreDrvSel != 0) |
| 594 | silconfig->PortUsb20HsNpreDrvSel[port] = |
| 595 | cfg->usb2eye[port].Usb20HsNpreDrvSel; |
| 596 | } |
Maxim Polyakov | 6704049 | 2020-02-16 11:51:57 +0300 | [diff] [blame] | 597 | |
| 598 | if (cfg->usb_config_override) { |
| 599 | for (port = 0; port < APOLLOLAKE_USB3_PORT_MAX; port++) { |
| 600 | if (!cfg->usb3_port[port].enable) |
| 601 | continue; |
| 602 | |
| 603 | silconfig->PortUsb30Enable[port] = 1; |
| 604 | silconfig->PortUs30bOverCurrentPin[port] = cfg->usb3_port[port].oc_pin; |
| 605 | } |
| 606 | } |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 607 | #endif |
| 608 | } |
| 609 | |
| 610 | static void glk_fsp_silicon_init_params_cb( |
| 611 | struct soc_intel_apollolake_config *cfg, FSP_S_CONFIG *silconfig) |
| 612 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 613 | #if CONFIG(SOC_INTEL_GLK) |
Seunghwan Kim | f7fd9b1 | 2019-01-24 16:17:44 +0900 | [diff] [blame] | 614 | uint8_t port; |
Franklin He | 117a660 | 2020-03-16 12:31:01 +1100 | [diff] [blame^] | 615 | struct device *dev; |
Seunghwan Kim | f7fd9b1 | 2019-01-24 16:17:44 +0900 | [diff] [blame] | 616 | |
| 617 | for (port = 0; port < APOLLOLAKE_USB2_PORT_MAX; port++) { |
| 618 | if (!cfg->usb2eye[port].Usb20OverrideEn) |
| 619 | continue; |
| 620 | |
| 621 | silconfig->Usb2AfePehalfbit[port] = |
| 622 | cfg->usb2eye[port].Usb20PerPortTxPeHalf; |
| 623 | silconfig->Usb2AfePetxiset[port] = |
| 624 | cfg->usb2eye[port].Usb20PerPortPeTxiSet; |
| 625 | silconfig->Usb2AfeTxiset[port] = |
| 626 | cfg->usb2eye[port].Usb20PerPortTxiSet; |
| 627 | silconfig->Usb2AfePredeemp[port] = |
| 628 | cfg->usb2eye[port].Usb20IUsbTxEmphasisEn; |
| 629 | } |
| 630 | |
Franklin He | 117a660 | 2020-03-16 12:31:01 +1100 | [diff] [blame^] | 631 | dev = pcidev_path_on_root(SA_GLK_DEVFN_GMM); |
| 632 | silconfig->Gmm = dev ? dev->enabled : 0; |
Shamile Khan | c4276a3 | 2018-03-14 18:09:19 -0700 | [diff] [blame] | 633 | |
| 634 | /* On Geminilake, we need to override the default FSP PCIe de-emphasis |
| 635 | * settings using the device tree settings. This is because PCIe |
| 636 | * de-emphasis is enabled by default and Thunderpeak PCIe WiFi detection |
| 637 | * requires de-emphasis disabled. If we make this change common to both |
| 638 | * Apollolake and Geminilake, then we need to add mainboard device tree |
| 639 | * de-emphasis settings of 1 to Apollolake systems. |
| 640 | */ |
| 641 | memcpy(silconfig->PcieRpSelectableDeemphasis, |
| 642 | cfg->pcie_rp_deemphasis_enable, |
| 643 | sizeof(silconfig->PcieRpSelectableDeemphasis)); |
Srinidhi N Kaushik | 5af546c | 2018-05-14 23:33:55 -0700 | [diff] [blame] | 644 | /* |
| 645 | * FSP does not know what the clock requirements are for the |
| 646 | * device on SPI bus, hence it should not modify what coreboot |
| 647 | * has set up. Hence skipping in FSP. |
| 648 | */ |
| 649 | silconfig->SkipSpiPCP = 1; |
John Zhao | e673e5c | 2018-10-30 15:12:11 -0700 | [diff] [blame] | 650 | |
| 651 | /* |
| 652 | * FSP provides UPD interface to execute IPC command. In order to |
| 653 | * improve boot performance, configure PmicPmcIpcCtrl for PMC to program |
| 654 | * PMIC PCH_PWROK delay. |
John Zhao | 91600a3 | 2019-01-10 12:13:38 -0800 | [diff] [blame] | 655 | */ |
John Zhao | e673e5c | 2018-10-30 15:12:11 -0700 | [diff] [blame] | 656 | silconfig->PmicPmcIpcCtrl = cfg->PmicPmcIpcCtrl; |
John Zhao | 91600a3 | 2019-01-10 12:13:38 -0800 | [diff] [blame] | 657 | |
| 658 | /* |
| 659 | * Options to disable XHCI Link Compliance Mode. |
| 660 | */ |
| 661 | silconfig->DisableComplianceMode = cfg->DisableComplianceMode; |
John Zhao | 9a4beb4 | 2019-01-28 16:04:35 -0800 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * Options to change USB3 ModPhy setting for Integrated Filter value. |
| 665 | */ |
| 666 | silconfig->ModPhyIfValue = cfg->ModPhyIfValue; |
| 667 | |
| 668 | /* |
| 669 | * Options to bump USB3 LDO voltage with 40mv. |
| 670 | */ |
| 671 | silconfig->ModPhyVoltageBump = cfg->ModPhyVoltageBump; |
| 672 | |
| 673 | /* |
| 674 | * Options to adjust PMIC Vdd2 voltage. |
| 675 | */ |
| 676 | silconfig->PmicVdd2Voltage = cfg->PmicVdd2Voltage; |
Srinidhi N Kaushik | 5af546c | 2018-05-14 23:33:55 -0700 | [diff] [blame] | 677 | #endif |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 680 | void __weak mainboard_devtree_update(struct device *dev) |
Kane Chen | 5bddcc4 | 2017-08-22 11:37:18 +0800 | [diff] [blame] | 681 | { |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame] | 682 | /* Override dev tree settings per board */ |
Kane Chen | 5bddcc4 | 2017-08-22 11:37:18 +0800 | [diff] [blame] | 683 | } |
| 684 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 685 | void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 686 | { |
Lee Leahy | 1d20fe7 | 2017-03-09 09:50:28 -0800 | [diff] [blame] | 687 | FSP_S_CONFIG *silconfig = &silupd->FspsConfig; |
Kyösti Mälkki | 4af4e7f | 2019-07-14 05:50:20 +0300 | [diff] [blame] | 688 | struct soc_intel_apollolake_config *cfg; |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 689 | struct device *dev; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 690 | |
| 691 | /* Load VBT before devicetree-specific config. */ |
Patrick Georgi | 2257959 | 2017-10-06 17:36:09 +0200 | [diff] [blame] | 692 | silconfig->GraphicsConfigPtr = (uintptr_t)vbt_get(); |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 693 | |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 694 | dev = pcidev_path_on_root(SA_DEVFN_ROOT); |
| 695 | cfg = config_of(dev); |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 696 | |
Kane Chen | 5bddcc4 | 2017-08-22 11:37:18 +0800 | [diff] [blame] | 697 | mainboard_devtree_update(dev); |
| 698 | |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 699 | /* Parse device tree and disable unused device*/ |
| 700 | parse_devicetree(silconfig); |
| 701 | |
Furquan Shaikh | 6d5e10c | 2018-03-14 19:57:16 -0700 | [diff] [blame] | 702 | memcpy(silconfig->PcieRpClkReqNumber, cfg->pcie_rp_clkreq_pin, |
| 703 | sizeof(silconfig->PcieRpClkReqNumber)); |
Andrey Petrov | e07e13d | 2016-03-18 14:43:00 -0700 | [diff] [blame] | 704 | |
Furquan Shaikh | 2cfc862 | 2018-03-14 21:43:04 -0700 | [diff] [blame] | 705 | memcpy(silconfig->PcieRpHotPlug, cfg->pcie_rp_hotplug_enable, |
| 706 | sizeof(silconfig->PcieRpHotPlug)); |
| 707 | |
Nico Huber | 8885529 | 2018-11-27 15:13:22 +0100 | [diff] [blame] | 708 | switch (cfg->serirq_mode) { |
| 709 | case SERIRQ_QUIET: |
| 710 | silconfig->SirqEnable = 1; |
| 711 | silconfig->SirqMode = 0; |
| 712 | break; |
| 713 | case SERIRQ_CONTINUOUS: |
| 714 | silconfig->SirqEnable = 1; |
| 715 | silconfig->SirqMode = 1; |
| 716 | break; |
| 717 | case SERIRQ_OFF: |
| 718 | default: |
| 719 | silconfig->SirqEnable = 0; |
| 720 | break; |
| 721 | } |
| 722 | |
Zhao, Lijian | 1b8ee0b | 2016-05-17 19:01:34 -0700 | [diff] [blame] | 723 | if (cfg->emmc_tx_cmd_cntl != 0) |
| 724 | silconfig->EmmcTxCmdCntl = cfg->emmc_tx_cmd_cntl; |
| 725 | if (cfg->emmc_tx_data_cntl1 != 0) |
| 726 | silconfig->EmmcTxDataCntl1 = cfg->emmc_tx_data_cntl1; |
| 727 | if (cfg->emmc_tx_data_cntl2 != 0) |
| 728 | silconfig->EmmcTxDataCntl2 = cfg->emmc_tx_data_cntl2; |
| 729 | if (cfg->emmc_rx_cmd_data_cntl1 != 0) |
| 730 | silconfig->EmmcRxCmdDataCntl1 = cfg->emmc_rx_cmd_data_cntl1; |
| 731 | if (cfg->emmc_rx_strobe_cntl != 0) |
| 732 | silconfig->EmmcRxStrobeCntl = cfg->emmc_rx_strobe_cntl; |
| 733 | if (cfg->emmc_rx_cmd_data_cntl2 != 0) |
| 734 | silconfig->EmmcRxCmdDataCntl2 = cfg->emmc_rx_cmd_data_cntl2; |
Mario Scheithauer | 9116eb6 | 2018-08-23 11:39:19 +0200 | [diff] [blame] | 735 | if (cfg->emmc_host_max_speed != 0) |
| 736 | silconfig->eMMCHostMaxSpeed = cfg->emmc_host_max_speed; |
Zhao, Lijian | 1b8ee0b | 2016-05-17 19:01:34 -0700 | [diff] [blame] | 737 | |
Saurabh Satija | e46dbcc | 2016-05-03 15:15:31 -0700 | [diff] [blame] | 738 | silconfig->LPSS_S0ixEnable = cfg->lpss_s0ix_enable; |
| 739 | |
Lee Leahy | 07441b5 | 2017-03-09 10:59:25 -0800 | [diff] [blame] | 740 | /* Disable monitor mwait since it is broken due to a hardware bug |
Cole Nelson | f357c25 | 2017-05-16 11:38:59 -0700 | [diff] [blame] | 741 | * without a fix. Specific to Apollolake. |
Lee Leahy | 07441b5 | 2017-03-09 10:59:25 -0800 | [diff] [blame] | 742 | */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 743 | if (!CONFIG(SOC_INTEL_GLK)) |
Cole Nelson | f357c25 | 2017-05-16 11:38:59 -0700 | [diff] [blame] | 744 | silconfig->MonitorMwaitEnable = 0; |
Bora Guvendik | 60cc75d | 2016-07-25 14:44:51 -0700 | [diff] [blame] | 745 | |
Subrata Banik | cf32fd1 | 2018-12-19 18:02:17 +0530 | [diff] [blame] | 746 | silconfig->SkipMpInit = !CONFIG_USE_INTEL_FSP_MP_INIT; |
Venkateswarlu Vinjamuri | 1a5e32c | 2016-10-31 17:15:30 -0700 | [diff] [blame] | 747 | |
Furquan Shaikh | cad9b63 | 2016-06-20 16:08:42 -0700 | [diff] [blame] | 748 | /* Disable setting of EISS bit in FSP. */ |
| 749 | silconfig->SpiEiss = 0; |
Ravi Sarawadi | 3a21d0f | 2016-08-10 11:33:56 -0700 | [diff] [blame] | 750 | |
| 751 | /* Disable FSP from locking access to the RTC NVRAM */ |
| 752 | silconfig->RtcLock = 0; |
Venkateswarlu Vinjamuri | 88df48c | 2016-09-02 16:04:27 -0700 | [diff] [blame] | 753 | |
| 754 | /* Enable Audio clk gate and power gate */ |
| 755 | silconfig->HDAudioClkGate = cfg->hdaudio_clk_gate_enable; |
| 756 | silconfig->HDAudioPwrGate = cfg->hdaudio_pwr_gate_enable; |
Elyes HAOUAS | 6dc9d03 | 2020-02-16 16:22:52 +0100 | [diff] [blame] | 757 | /* BIOS config lockdown Audio clk and power gate */ |
Venkateswarlu Vinjamuri | 88df48c | 2016-09-02 16:04:27 -0700 | [diff] [blame] | 758 | silconfig->BiosCfgLockDown = cfg->hdaudio_bios_config_lockdown; |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 759 | if (CONFIG(SOC_INTEL_GLK)) |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 760 | glk_fsp_silicon_init_params_cb(cfg, silconfig); |
| 761 | else |
| 762 | apl_fsp_silicon_init_params_cb(cfg, silconfig); |
Duncan Laurie | 4c8fbc0 | 2018-03-26 02:19:58 -0700 | [diff] [blame] | 763 | |
| 764 | /* Enable xDCI controller if enabled in devicetree and allowed */ |
Kyösti Mälkki | 903b40a | 2019-07-03 07:25:59 +0300 | [diff] [blame] | 765 | dev = pcidev_path_on_root(PCH_DEVFN_XDCI); |
Duncan Laurie | 4c8fbc0 | 2018-03-26 02:19:58 -0700 | [diff] [blame] | 766 | if (!xdci_can_enable()) |
| 767 | dev->enabled = 0; |
| 768 | silconfig->UsbOtg = dev->enabled; |
Werner Zeh | 279afdc | 2019-02-01 12:32:51 +0100 | [diff] [blame] | 769 | |
| 770 | /* Set VTD feature according to devicetree */ |
| 771 | silconfig->VtdEnable = cfg->enable_vtd; |
Felix Singer | e59ae10 | 2019-05-02 13:57:57 +0200 | [diff] [blame] | 772 | |
Michael Niewöhner | 9b8d28f | 2019-10-26 10:44:33 +0200 | [diff] [blame] | 773 | dev = pcidev_path_on_root(SA_DEVFN_IGD); |
| 774 | if (CONFIG(RUN_FSP_GOP) && dev && dev->enabled) |
| 775 | silconfig->PeiGraphicsPeimInit = 1; |
| 776 | else |
| 777 | silconfig->PeiGraphicsPeimInit = 0; |
| 778 | |
Felix Singer | e59ae10 | 2019-05-02 13:57:57 +0200 | [diff] [blame] | 779 | mainboard_silicon_init_params(silconfig); |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | struct chip_operations soc_intel_apollolake_ops = { |
| 783 | CHIP_NAME("Intel Apollolake SOC") |
John Zhao | 57aa8b6 | 2019-01-14 09:15:50 -0800 | [diff] [blame] | 784 | .enable_dev = &enable_dev, |
| 785 | .init = &soc_init, |
| 786 | .final = &soc_final |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 787 | }; |
| 788 | |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 789 | static void drop_privilege_all(void) |
| 790 | { |
| 791 | /* Drop privilege level on all the CPUs */ |
Patrick Rudolph | 5ec97ce | 2019-07-26 14:47:32 +0200 | [diff] [blame] | 792 | if (mp_run_on_all_cpus(&cpu_enable_untrusted_mode, NULL) < 0) |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 793 | printk(BIOS_ERR, "failed to enable untrusted mode\n"); |
| 794 | } |
| 795 | |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 796 | static void configure_xhci_host_mode_port0(void) |
| 797 | { |
| 798 | uint32_t *cfg0; |
| 799 | uint32_t *cfg1; |
| 800 | const struct resource *res; |
| 801 | uint32_t reg; |
| 802 | struct stopwatch sw; |
| 803 | struct device *xhci_dev = PCH_DEV_XHCI; |
| 804 | |
| 805 | printk(BIOS_INFO, "Putting xHCI port 0 into host mode.\n"); |
| 806 | res = find_resource(xhci_dev, PCI_BASE_ADDRESS_0); |
| 807 | cfg0 = (void *)(uintptr_t)(res->base + DUAL_ROLE_CFG0); |
| 808 | cfg1 = (void *)(uintptr_t)(res->base + DUAL_ROLE_CFG1); |
| 809 | reg = read32(cfg0); |
John Zhao | db2f91b | 2018-08-21 15:02:54 -0700 | [diff] [blame] | 810 | if (!(reg & SW_IDPIN_EN_MASK)) |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 811 | return; |
| 812 | |
| 813 | reg &= ~(SW_IDPIN_MASK | SW_VBUS_VALID_MASK); |
| 814 | write32(cfg0, reg); |
| 815 | |
| 816 | stopwatch_init_msecs_expire(&sw, 10); |
| 817 | /* Wait for the host mode status bit. */ |
| 818 | while ((read32(cfg1) & DRD_MODE_MASK) != DRD_MODE_HOST) { |
| 819 | if (stopwatch_expired(&sw)) { |
| 820 | printk(BIOS_ERR, "Timed out waiting for host mode.\n"); |
| 821 | return; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | printk(BIOS_INFO, "xHCI port 0 host switch over took %lu ms\n", |
| 826 | stopwatch_duration_msecs(&sw)); |
| 827 | } |
| 828 | |
| 829 | static int check_xdci_enable(void) |
| 830 | { |
| 831 | struct device *dev = PCH_DEV_XDCI; |
| 832 | |
| 833 | return !!dev->enabled; |
| 834 | } |
| 835 | |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 836 | void platform_fsp_notify_status(enum fsp_notify_phase phase) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 837 | { |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 838 | if (phase == END_OF_FIRMWARE) { |
Furquan Shaikh | d2c2f83 | 2018-11-07 10:24:31 -0800 | [diff] [blame] | 839 | |
| 840 | /* |
| 841 | * Before hiding P2SB device and dropping privilege level, |
| 842 | * dump CSE status and disable HECI1 interface. |
| 843 | */ |
| 844 | heci_cse_lockdown(); |
| 845 | |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 846 | /* Hide the P2SB device to align with previous behavior. */ |
Aaron Durbin | fadfc2e | 2016-07-01 16:36:03 -0500 | [diff] [blame] | 847 | p2sb_hide(); |
Furquan Shaikh | d2c2f83 | 2018-11-07 10:24:31 -0800 | [diff] [blame] | 848 | |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 849 | /* |
| 850 | * As per guidelines BIOS is recommended to drop CPU privilege |
| 851 | * level to IA_UNTRUSTED. After that certain device registers |
| 852 | * and MSRs become inaccessible supposedly increasing system |
| 853 | * security. |
| 854 | */ |
| 855 | drop_privilege_all(); |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 856 | |
| 857 | /* |
| 858 | * When USB OTG is set, GLK FSP enables xHCI SW ID pin and |
| 859 | * configures USB-C as device mode. Force USB-C into host mode. |
| 860 | */ |
| 861 | if (check_xdci_enable()) |
| 862 | configure_xhci_host_mode_port0(); |
John Zhao | 57aa8b6 | 2019-01-14 09:15:50 -0800 | [diff] [blame] | 863 | |
| 864 | /* |
| 865 | * Override GLK xhci clock gating register(XHCLKGTEN) to |
Elyes HAOUAS | 44f558e | 2020-02-24 13:26:04 +0100 | [diff] [blame] | 866 | * mitigate USB device suspend and resume failure. |
John Zhao | 57aa8b6 | 2019-01-14 09:15:50 -0800 | [diff] [blame] | 867 | */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 868 | if (CONFIG(SOC_INTEL_GLK)) { |
John Zhao | 57aa8b6 | 2019-01-14 09:15:50 -0800 | [diff] [blame] | 869 | uint32_t *cfg; |
| 870 | const struct resource *res; |
| 871 | uint32_t reg; |
| 872 | struct device *xhci_dev = PCH_DEV_XHCI; |
| 873 | |
| 874 | res = find_resource(xhci_dev, PCI_BASE_ADDRESS_0); |
| 875 | cfg = (void *)(uintptr_t)(res->base + CFG_XHCLKGTEN); |
| 876 | reg = SRAMPGTEN | SSLSE | USB2PLLSE | IOSFSTCGE | |
| 877 | HSTCGE | HSUXDMIPLLSE | SSTCGE | XHCFTCLKSE | |
| 878 | XHCBBTCGIPISO | XHCUSB2PLLSDLE | SSPLLSUE | |
| 879 | XHCBLCGE | HSLTCGE | SSLTCGE | IOSFBTCGE | |
| 880 | IOSFGBLCGE; |
| 881 | write32(cfg, reg); |
| 882 | } |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 883 | } |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 884 | } |
| 885 | |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 886 | /* |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 887 | * spi_flash init() needs to run unconditionally on every boot (including |
| 888 | * resume) to allow write protect to be disabled for eventlog and nvram |
| 889 | * updates. This needs to be done as early as possible in ramstage. Thus, add a |
| 890 | * callback for entry into BS_PRE_DEVICE. |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 891 | */ |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 892 | static void spi_flash_init_cb(void *unused) |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 893 | { |
Barnali Sarkar | e70142c | 2017-03-28 16:32:33 +0530 | [diff] [blame] | 894 | fast_spi_init(); |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Felix Singer | e59ae10 | 2019-05-02 13:57:57 +0200 | [diff] [blame] | 897 | __weak |
| 898 | void mainboard_silicon_init_params(FSP_S_CONFIG *silconfig) |
| 899 | { |
| 900 | printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__); |
| 901 | } |
| 902 | |
Wim Vervoorn | d137150 | 2019-12-17 14:10:16 +0100 | [diff] [blame] | 903 | /* Handle FSP logo params */ |
| 904 | const struct cbmem_entry *soc_load_logo(FSPS_UPD *supd) |
| 905 | { |
| 906 | return fsp_load_logo(&supd->FspsConfig.LogoPtr, &supd->FspsConfig.LogoSize); |
| 907 | } |
| 908 | |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 909 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, spi_flash_init_cb, NULL); |