Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2015 Intel Corp. |
| 5 | * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.) |
| 6 | * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
Martin Roth | ebabfad | 2016-04-10 11:09:16 -0600 | [diff] [blame] | 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 17 | */ |
| 18 | |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 19 | #include <arch/acpi.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 20 | #include <bootstate.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 21 | #include <cbmem.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 22 | #include <console/console.h> |
| 23 | #include <cpu/cpu.h> |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 24 | #include <cpu/x86/mp.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 25 | #include <device/device.h> |
| 26 | #include <device/pci.h> |
| 27 | #include <fsp/api.h> |
| 28 | #include <fsp/util.h> |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 29 | #include <romstage_handoff.h> |
Andrey Petrov | e07e13d | 2016-03-18 14:43:00 -0700 | [diff] [blame] | 30 | #include <soc/iomap.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 31 | #include <soc/cpu.h> |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 32 | #include <soc/flash_ctrlr.h> |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 33 | #include <soc/intel/common/vbt.h> |
Aaron Durbin | 81d1e09 | 2016-07-13 01:49:10 -0500 | [diff] [blame] | 34 | #include <soc/itss.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 35 | #include <soc/nvs.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 36 | #include <soc/pci_devs.h> |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 37 | #include <spi-generic.h> |
Andrey Petrov | 3dbea29 | 2016-06-14 22:20:28 -0700 | [diff] [blame] | 38 | #include <soc/pm.h> |
Aaron Durbin | fadfc2e | 2016-07-01 16:36:03 -0500 | [diff] [blame] | 39 | #include <soc/p2sb.h> |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 40 | #include <soc/northbridge.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 41 | |
| 42 | #include "chip.h" |
| 43 | |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 44 | static void *vbt; |
| 45 | static struct region_device vbt_rdev; |
| 46 | |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 47 | static const char *soc_acpi_name(struct device *dev) |
| 48 | { |
| 49 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 50 | return "PCI0"; |
| 51 | |
| 52 | if (dev->path.type != DEVICE_PATH_PCI) |
| 53 | return NULL; |
| 54 | |
| 55 | switch (dev->path.pci.devfn) { |
| 56 | /* DSDT: acpi/northbridge.asl */ |
| 57 | case NB_DEVFN: |
| 58 | return "MCHC"; |
| 59 | /* DSDT: acpi/lpc.asl */ |
| 60 | case LPC_DEVFN: |
| 61 | return "LPCB"; |
| 62 | /* DSDT: acpi/xhci.asl */ |
| 63 | case XHCI_DEVFN: |
| 64 | return "XHCI"; |
| 65 | /* DSDT: acpi/pch_hda.asl */ |
| 66 | case HDA_DEVFN: |
| 67 | return "HDAS"; |
| 68 | /* DSDT: acpi/lpss.asl */ |
| 69 | case LPSS_DEVFN_UART0: |
| 70 | return "URT1"; |
| 71 | case LPSS_DEVFN_UART1: |
| 72 | return "URT2"; |
| 73 | case LPSS_DEVFN_UART2: |
| 74 | return "URT3"; |
| 75 | case LPSS_DEVFN_UART3: |
| 76 | return "URT4"; |
| 77 | case LPSS_DEVFN_SPI0: |
| 78 | return "SPI1"; |
| 79 | case LPSS_DEVFN_SPI1: |
| 80 | return "SPI2"; |
| 81 | case LPSS_DEVFN_SPI2: |
| 82 | return "SPI3"; |
| 83 | case LPSS_DEVFN_PWM: |
| 84 | return "PWM"; |
| 85 | case LPSS_DEVFN_I2C0: |
| 86 | return "I2C0"; |
| 87 | case LPSS_DEVFN_I2C1: |
| 88 | return "I2C1"; |
| 89 | case LPSS_DEVFN_I2C2: |
| 90 | return "I2C2"; |
| 91 | case LPSS_DEVFN_I2C3: |
| 92 | return "I2C3"; |
| 93 | case LPSS_DEVFN_I2C4: |
| 94 | return "I2C4"; |
| 95 | case LPSS_DEVFN_I2C5: |
| 96 | return "I2C5"; |
| 97 | case LPSS_DEVFN_I2C6: |
| 98 | return "I2C6"; |
| 99 | case LPSS_DEVFN_I2C7: |
| 100 | return "I2C7"; |
| 101 | /* Storage */ |
| 102 | case SDCARD_DEVFN: |
| 103 | return "SDCD"; |
| 104 | case EMMC_DEVFN: |
| 105 | return "EMMC"; |
| 106 | case SDIO_DEVFN: |
| 107 | return "SDIO"; |
Vaibhav Shankar | ec9168f | 2016-09-16 14:20:53 -0700 | [diff] [blame] | 108 | /* PCIe */ |
| 109 | case PCIEB0_DEVFN: |
| 110 | return "RP01"; |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | return NULL; |
| 114 | } |
| 115 | |
Venkateswarlu Vinjamuri | 6dd7b40 | 2017-02-24 15:37:30 -0800 | [diff] [blame] | 116 | static void pci_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 117 | { |
| 118 | if (!vendor || !device) |
| 119 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 120 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 121 | else |
| 122 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 123 | (device << 16) | vendor); |
| 124 | } |
| 125 | |
| 126 | struct pci_operations soc_pci_ops = { |
| 127 | .set_subsystem = &pci_set_subsystem |
| 128 | }; |
| 129 | |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 130 | static void pci_domain_set_resources(device_t dev) |
| 131 | { |
| 132 | assign_resources(dev->link_list); |
| 133 | } |
| 134 | |
| 135 | static struct device_operations pci_domain_ops = { |
| 136 | .read_resources = pci_domain_read_resources, |
| 137 | .set_resources = pci_domain_set_resources, |
| 138 | .enable_resources = NULL, |
| 139 | .init = NULL, |
| 140 | .scan_bus = pci_domain_scan_bus, |
| 141 | .ops_pci_bus = pci_bus_default_ops, |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 142 | .acpi_name = &soc_acpi_name, |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | static struct device_operations cpu_bus_ops = { |
| 146 | .read_resources = DEVICE_NOOP, |
| 147 | .set_resources = DEVICE_NOOP, |
| 148 | .enable_resources = DEVICE_NOOP, |
| 149 | .init = apollolake_init_cpus, |
| 150 | .scan_bus = NULL, |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 151 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | static void enable_dev(device_t dev) |
| 155 | { |
| 156 | /* Set the operations if it is a special bus type */ |
| 157 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 158 | dev->ops = &pci_domain_ops; |
| 159 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 160 | dev->ops = &cpu_bus_ops; |
| 161 | } |
| 162 | } |
| 163 | |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 164 | /* |
| 165 | * If the PCIe root port at function 0 is disabled, |
| 166 | * the PCIe root ports might be coalesced after FSP silicon init. |
| 167 | * The below function will swap the devfn of the first enabled device |
| 168 | * in devicetree and function 0 resides a pci device |
| 169 | * so that it won't confuse coreboot. |
| 170 | */ |
| 171 | static void pcie_update_device_tree(unsigned int devfn0, int num_funcs) |
| 172 | { |
| 173 | device_t func0; |
| 174 | unsigned int devfn; |
| 175 | int i; |
| 176 | unsigned int inc = PCI_DEVFN(0, 1); |
| 177 | |
| 178 | func0 = dev_find_slot(0, devfn0); |
| 179 | if (func0 == NULL) |
| 180 | return; |
| 181 | |
| 182 | /* No more functions if function 0 is disabled. */ |
| 183 | if (pci_read_config32(func0, PCI_VENDOR_ID) == 0xffffffff) |
| 184 | return; |
| 185 | |
| 186 | devfn = devfn0 + inc; |
| 187 | |
| 188 | /* |
| 189 | * Increase funtion by 1. |
| 190 | * Then find first enabled device to replace func0 |
| 191 | * as that port was move to func0. |
| 192 | */ |
| 193 | for (i = 1; i < num_funcs; i++, devfn += inc) { |
| 194 | device_t dev = dev_find_slot(0, devfn); |
| 195 | if (dev == NULL) |
| 196 | continue; |
| 197 | |
| 198 | if (!dev->enabled) |
| 199 | continue; |
| 200 | /* Found the first enabled device in given dev number */ |
| 201 | func0->path.pci.devfn = dev->path.pci.devfn; |
| 202 | dev->path.pci.devfn = devfn0; |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | static void pcie_override_devicetree_after_silicon_init(void) |
| 208 | { |
| 209 | pcie_update_device_tree(PCIEA0_DEVFN, 4); |
| 210 | pcie_update_device_tree(PCIEB0_DEVFN, 2); |
| 211 | } |
| 212 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 213 | /* Configure package power limits */ |
| 214 | static void set_power_limits(void) |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 215 | { |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 216 | static struct soc_intel_apollolake_config *cfg; |
| 217 | struct device *dev = NB_DEV_ROOT; |
| 218 | msr_t rapl_msr_reg, limit; |
| 219 | uint32_t power_unit; |
| 220 | uint32_t tdp, min_power, max_power; |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 221 | uint32_t pl2_val; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 222 | uint32_t *rapl_mmio_reg; |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 223 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 224 | if (!dev || !dev->chip_info) { |
| 225 | printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n"); |
| 226 | return; |
| 227 | } |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 228 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 229 | cfg = dev->chip_info; |
| 230 | |
| 231 | /* Get units */ |
| 232 | rapl_msr_reg = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 233 | power_unit = 1 << (rapl_msr_reg.lo & 0xf); |
| 234 | |
| 235 | /* Get power defaults for this SKU */ |
| 236 | rapl_msr_reg = rdmsr(MSR_PKG_POWER_SKU); |
| 237 | tdp = rapl_msr_reg.lo & PKG_POWER_LIMIT_MASK; |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 238 | pl2_val = rapl_msr_reg.hi & PKG_POWER_LIMIT_MASK; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 239 | min_power = (rapl_msr_reg.lo >> 16) & PKG_POWER_LIMIT_MASK; |
| 240 | max_power = rapl_msr_reg.hi & PKG_POWER_LIMIT_MASK; |
| 241 | |
| 242 | if (min_power > 0 && tdp < min_power) |
| 243 | tdp = min_power; |
| 244 | |
| 245 | if (max_power > 0 && tdp > max_power) |
| 246 | tdp = max_power; |
| 247 | |
| 248 | /* Set PL1 override value */ |
| 249 | tdp = (cfg->tdp_pl1_override_mw == 0) ? |
| 250 | tdp : (cfg->tdp_pl1_override_mw * power_unit) / 1000; |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 251 | /* Set PL2 override value */ |
| 252 | pl2_val = (cfg->tdp_pl2_override_mw == 0) ? |
| 253 | pl2_val : (cfg->tdp_pl2_override_mw * power_unit) / 1000; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 254 | |
| 255 | /* Set long term power limit to TDP */ |
| 256 | limit.lo = tdp & PKG_POWER_LIMIT_MASK; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 257 | /* Set PL1 Pkg Power clamp bit */ |
| 258 | limit.lo |= PKG_POWER_LIMIT_CLAMP; |
| 259 | |
| 260 | limit.lo |= PKG_POWER_LIMIT_EN; |
| 261 | limit.lo |= (MB_POWER_LIMIT1_TIME_DEFAULT & |
| 262 | PKG_POWER_LIMIT_TIME_MASK) << PKG_POWER_LIMIT_TIME_SHIFT; |
| 263 | |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 264 | /* Set short term power limit PL2 */ |
| 265 | limit.hi = pl2_val & PKG_POWER_LIMIT_MASK; |
| 266 | limit.hi |= PKG_POWER_LIMIT_EN; |
| 267 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 268 | /* Program package power limits in RAPL MSR */ |
| 269 | wrmsr(MSR_PKG_POWER_LIMIT, limit); |
| 270 | printk(BIOS_INFO, "RAPL PL1 %d.%dW\n", tdp / power_unit, |
| 271 | 100 * (tdp % power_unit) / power_unit); |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 272 | printk(BIOS_INFO, "RAPL PL2 %d.%dW\n", pl2_val / power_unit, |
| 273 | 100 * (pl2_val % power_unit) / power_unit); |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 274 | |
| 275 | /* Get the MMIO address */ |
| 276 | rapl_mmio_reg = (void *)(uintptr_t) (MCH_BASE_ADDR + MCHBAR_RAPL_PPL); |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 277 | |
| 278 | /* Setting RAPL MMIO register for Power limits. |
| 279 | * RAPL driver is using MSR instead of MMIO. |
| 280 | * So, disabled LIMIT_EN bit for MMIO. */ |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 281 | write32(rapl_mmio_reg, limit.lo & ~(PKG_POWER_LIMIT_EN)); |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 282 | write32(rapl_mmio_reg + 1, limit.hi & ~(PKG_POWER_LIMIT_EN)); |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 283 | } |
| 284 | |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 285 | static void soc_init(void *data) |
| 286 | { |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 287 | struct global_nvs_t *gnvs; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 288 | |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 289 | /* Save VBT info and mapping */ |
Abhay Kumar | ec2947f | 2016-07-14 18:43:54 -0700 | [diff] [blame] | 290 | vbt = vbt_get(&vbt_rdev); |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 291 | |
Aaron Durbin | 81d1e09 | 2016-07-13 01:49:10 -0500 | [diff] [blame] | 292 | /* Snapshot the current GPIO IRQ polarities. FSP is setting a |
| 293 | * default policy that doesn't honor boards' requirements. */ |
| 294 | itss_snapshot_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END); |
| 295 | |
Aaron Durbin | 6c191d8 | 2016-11-29 21:22:42 -0600 | [diff] [blame] | 296 | fsp_silicon_init(romstage_handoff_is_resume()); |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 297 | |
Aaron Durbin | 81d1e09 | 2016-07-13 01:49:10 -0500 | [diff] [blame] | 298 | /* Restore GPIO IRQ polarities back to previous settings. */ |
| 299 | itss_restore_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END); |
| 300 | |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 301 | /* override 'enabled' setting in device tree if needed */ |
| 302 | pcie_override_devicetree_after_silicon_init(); |
| 303 | |
Aaron Durbin | fadfc2e | 2016-07-01 16:36:03 -0500 | [diff] [blame] | 304 | /* |
| 305 | * Keep the P2SB device visible so it and the other devices are |
| 306 | * visible in coreboot for driver support and PCI resource allocation. |
| 307 | * There is a UPD setting for this, but it's more consistent to use |
| 308 | * hide and unhide symmetrically. |
| 309 | */ |
| 310 | p2sb_unhide(); |
| 311 | |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 312 | /* Allocate ACPI NVS in CBMEM */ |
| 313 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs)); |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 314 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 315 | /* Set RAPL MSR for Package power limits*/ |
| 316 | set_power_limits(); |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 319 | static void soc_final(void *data) |
| 320 | { |
| 321 | if (vbt) |
| 322 | rdev_munmap(&vbt_rdev, vbt); |
Andrey Petrov | 3dbea29 | 2016-06-14 22:20:28 -0700 | [diff] [blame] | 323 | |
| 324 | /* Disable global reset, just in case */ |
| 325 | global_reset_enable(0); |
| 326 | /* Make sure payload/OS can't trigger global reset */ |
| 327 | global_reset_lock(); |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 330 | static void disable_dev(struct device *dev, FSP_S_CONFIG *silconfig) { |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 331 | |
| 332 | switch (dev->path.pci.devfn) { |
| 333 | case ISH_DEVFN: |
| 334 | silconfig->IshEnable = 0; |
| 335 | break; |
| 336 | case SATA_DEVFN: |
| 337 | silconfig->EnableSata = 0; |
| 338 | break; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 339 | case PCIEB0_DEVFN: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 340 | silconfig->PcieRootPortEn[0] = 0; |
| 341 | silconfig->PcieRpHotPlug[0] = 0; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 342 | break; |
| 343 | case PCIEB1_DEVFN: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 344 | silconfig->PcieRootPortEn[1] = 0; |
| 345 | silconfig->PcieRpHotPlug[1] = 0; |
| 346 | break; |
| 347 | case PCIEA0_DEVFN: |
| 348 | silconfig->PcieRootPortEn[2] = 0; |
| 349 | silconfig->PcieRpHotPlug[2] = 0; |
| 350 | break; |
| 351 | case PCIEA1_DEVFN: |
| 352 | silconfig->PcieRootPortEn[3] = 0; |
| 353 | silconfig->PcieRpHotPlug[3] = 0; |
| 354 | break; |
| 355 | case PCIEA2_DEVFN: |
| 356 | silconfig->PcieRootPortEn[4] = 0; |
| 357 | silconfig->PcieRpHotPlug[4] = 0; |
| 358 | break; |
| 359 | case PCIEA3_DEVFN: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 360 | silconfig->PcieRootPortEn[5] = 0; |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 361 | silconfig->PcieRpHotPlug[5] = 0; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 362 | break; |
| 363 | case XHCI_DEVFN: |
| 364 | silconfig->Usb30Mode = 0; |
| 365 | break; |
| 366 | case XDCI_DEVFN: |
| 367 | silconfig->UsbOtg = 0; |
| 368 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 369 | case LPSS_DEVFN_I2C0: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 370 | silconfig->I2c0Enable = 0; |
| 371 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 372 | case LPSS_DEVFN_I2C1: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 373 | silconfig->I2c1Enable = 0; |
| 374 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 375 | case LPSS_DEVFN_I2C2: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 376 | silconfig->I2c2Enable = 0; |
| 377 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 378 | case LPSS_DEVFN_I2C3: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 379 | silconfig->I2c3Enable = 0; |
| 380 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 381 | case LPSS_DEVFN_I2C4: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 382 | silconfig->I2c4Enable = 0; |
| 383 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 384 | case LPSS_DEVFN_I2C5: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 385 | silconfig->I2c5Enable = 0; |
| 386 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 387 | case LPSS_DEVFN_I2C6: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 388 | silconfig->I2c6Enable = 0; |
| 389 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 390 | case LPSS_DEVFN_I2C7: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 391 | silconfig->I2c7Enable = 0; |
| 392 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 393 | case LPSS_DEVFN_UART0: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 394 | silconfig->Hsuart0Enable = 0; |
| 395 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 396 | case LPSS_DEVFN_UART1: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 397 | silconfig->Hsuart1Enable = 0; |
| 398 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 399 | case LPSS_DEVFN_UART2: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 400 | silconfig->Hsuart2Enable = 0; |
| 401 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 402 | case LPSS_DEVFN_UART3: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 403 | silconfig->Hsuart3Enable = 0; |
| 404 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 405 | case LPSS_DEVFN_SPI0: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 406 | silconfig->Spi0Enable = 0; |
| 407 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 408 | case LPSS_DEVFN_SPI1: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 409 | silconfig->Spi1Enable = 0; |
| 410 | break; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 411 | case LPSS_DEVFN_SPI2: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 412 | silconfig->Spi2Enable = 0; |
| 413 | break; |
| 414 | case SDCARD_DEVFN: |
| 415 | silconfig->SdcardEnabled = 0; |
| 416 | break; |
| 417 | case EMMC_DEVFN: |
| 418 | silconfig->eMMCEnabled = 0; |
| 419 | break; |
| 420 | case SDIO_DEVFN: |
| 421 | silconfig->SdioEnabled = 0; |
| 422 | break; |
| 423 | case SMBUS_DEVFN: |
| 424 | silconfig->SmbusEnable = 0; |
| 425 | break; |
| 426 | default: |
| 427 | printk(BIOS_WARNING, "PCI:%02x.%01x: Could not disable the device\n", |
| 428 | PCI_SLOT(dev->path.pci.devfn), |
| 429 | PCI_FUNC(dev->path.pci.devfn)); |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 434 | static void parse_devicetree(FSP_S_CONFIG *silconfig) |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 435 | { |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 436 | struct device *dev = NB_DEV_ROOT; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 437 | |
| 438 | if (!dev) { |
| 439 | printk(BIOS_ERR, "Could not find root device\n"); |
| 440 | return; |
| 441 | } |
| 442 | /* Only disable bus 0 devices. */ |
| 443 | for (dev = dev->bus->children; dev; dev = dev->sibling) { |
| 444 | if (!dev->enabled) |
| 445 | disable_dev(dev, silconfig); |
| 446 | } |
| 447 | } |
| 448 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 449 | void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 450 | { |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 451 | FSP_S_CONFIG *silconfig = &silupd->FspsConfig; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 452 | static struct soc_intel_apollolake_config *cfg; |
Kane Chen | 9d490da | 2017-01-11 12:53:58 +0800 | [diff] [blame] | 453 | uint8_t port; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 454 | |
| 455 | /* Load VBT before devicetree-specific config. */ |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 456 | silconfig->GraphicsConfigPtr = (uintptr_t)vbt; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 457 | |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 458 | struct device *dev = NB_DEV_ROOT; |
| 459 | |
Patrick Georgi | 831d65d | 2016-04-14 11:53:48 +0200 | [diff] [blame] | 460 | if (!dev || !dev->chip_info) { |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 461 | printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n"); |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | cfg = dev->chip_info; |
| 466 | |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 467 | /* Parse device tree and disable unused device*/ |
| 468 | parse_devicetree(silconfig); |
| 469 | |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 470 | silconfig->PcieRpClkReqNumber[0] = cfg->pcie_rp0_clkreq_pin; |
| 471 | silconfig->PcieRpClkReqNumber[1] = cfg->pcie_rp1_clkreq_pin; |
| 472 | silconfig->PcieRpClkReqNumber[2] = cfg->pcie_rp2_clkreq_pin; |
| 473 | silconfig->PcieRpClkReqNumber[3] = cfg->pcie_rp3_clkreq_pin; |
| 474 | silconfig->PcieRpClkReqNumber[4] = cfg->pcie_rp4_clkreq_pin; |
| 475 | silconfig->PcieRpClkReqNumber[5] = cfg->pcie_rp5_clkreq_pin; |
Andrey Petrov | e07e13d | 2016-03-18 14:43:00 -0700 | [diff] [blame] | 476 | |
Zhao, Lijian | 1b8ee0b | 2016-05-17 19:01:34 -0700 | [diff] [blame] | 477 | if (cfg->emmc_tx_cmd_cntl != 0) |
| 478 | silconfig->EmmcTxCmdCntl = cfg->emmc_tx_cmd_cntl; |
| 479 | if (cfg->emmc_tx_data_cntl1 != 0) |
| 480 | silconfig->EmmcTxDataCntl1 = cfg->emmc_tx_data_cntl1; |
| 481 | if (cfg->emmc_tx_data_cntl2 != 0) |
| 482 | silconfig->EmmcTxDataCntl2 = cfg->emmc_tx_data_cntl2; |
| 483 | if (cfg->emmc_rx_cmd_data_cntl1 != 0) |
| 484 | silconfig->EmmcRxCmdDataCntl1 = cfg->emmc_rx_cmd_data_cntl1; |
| 485 | if (cfg->emmc_rx_strobe_cntl != 0) |
| 486 | silconfig->EmmcRxStrobeCntl = cfg->emmc_rx_strobe_cntl; |
| 487 | if (cfg->emmc_rx_cmd_data_cntl2 != 0) |
| 488 | silconfig->EmmcRxCmdDataCntl2 = cfg->emmc_rx_cmd_data_cntl2; |
| 489 | |
Saurabh Satija | e46dbcc | 2016-05-03 15:15:31 -0700 | [diff] [blame] | 490 | silconfig->LPSS_S0ixEnable = cfg->lpss_s0ix_enable; |
| 491 | |
Bora Guvendik | 60cc75d | 2016-07-25 14:44:51 -0700 | [diff] [blame] | 492 | /* Disable monitor mwait since it is broken due to a hardware bug without a fix */ |
| 493 | silconfig->MonitorMwaitEnable = 0; |
| 494 | |
Venkateswarlu Vinjamuri | 1a5e32c | 2016-10-31 17:15:30 -0700 | [diff] [blame] | 495 | silconfig->SkipMpInit = 1; |
| 496 | |
Furquan Shaikh | cad9b63 | 2016-06-20 16:08:42 -0700 | [diff] [blame] | 497 | /* Disable setting of EISS bit in FSP. */ |
| 498 | silconfig->SpiEiss = 0; |
Ravi Sarawadi | 3a21d0f | 2016-08-10 11:33:56 -0700 | [diff] [blame] | 499 | |
| 500 | /* Disable FSP from locking access to the RTC NVRAM */ |
| 501 | silconfig->RtcLock = 0; |
Venkateswarlu Vinjamuri | 88df48c | 2016-09-02 16:04:27 -0700 | [diff] [blame] | 502 | |
| 503 | /* Enable Audio clk gate and power gate */ |
| 504 | silconfig->HDAudioClkGate = cfg->hdaudio_clk_gate_enable; |
| 505 | silconfig->HDAudioPwrGate = cfg->hdaudio_pwr_gate_enable; |
| 506 | /* Bios config lockdown Audio clk and power gate */ |
| 507 | silconfig->BiosCfgLockDown = cfg->hdaudio_bios_config_lockdown; |
| 508 | |
Kane Chen | 9d490da | 2017-01-11 12:53:58 +0800 | [diff] [blame] | 509 | /* USB2 eye diagram settings per port */ |
| 510 | for (port = 0; port < APOLLOLAKE_USB2_PORT_MAX; port++) { |
| 511 | if (cfg->usb2eye[port].Usb20PerPortTxPeHalf != 0) |
| 512 | silconfig->PortUsb20PerPortTxPeHalf[port] = |
| 513 | cfg->usb2eye[port].Usb20PerPortTxPeHalf; |
| 514 | |
| 515 | if (cfg->usb2eye[port].Usb20PerPortPeTxiSet != 0) |
| 516 | silconfig->PortUsb20PerPortPeTxiSet[port] = |
| 517 | cfg->usb2eye[port].Usb20PerPortPeTxiSet; |
| 518 | |
| 519 | if (cfg->usb2eye[port].Usb20PerPortTxiSet != 0) |
| 520 | silconfig->PortUsb20PerPortTxiSet[port] = |
| 521 | cfg->usb2eye[port].Usb20PerPortTxiSet; |
| 522 | |
| 523 | if (cfg->usb2eye[port].Usb20HsSkewSel != 0) |
| 524 | silconfig->PortUsb20HsSkewSel[port] = |
| 525 | cfg->usb2eye[port].Usb20HsSkewSel; |
| 526 | |
| 527 | if (cfg->usb2eye[port].Usb20IUsbTxEmphasisEn != 0) |
| 528 | silconfig->PortUsb20IUsbTxEmphasisEn[port] = |
| 529 | cfg->usb2eye[port].Usb20IUsbTxEmphasisEn; |
| 530 | |
| 531 | if (cfg->usb2eye[port].Usb20PerPortRXISet != 0) |
| 532 | silconfig->PortUsb20PerPortRXISet[port] = |
| 533 | cfg->usb2eye[port].Usb20PerPortRXISet; |
| 534 | |
| 535 | if (cfg->usb2eye[port].Usb20HsNpreDrvSel != 0) |
| 536 | silconfig->PortUsb20HsNpreDrvSel[port] = |
| 537 | cfg->usb2eye[port].Usb20HsNpreDrvSel; |
| 538 | } |
| 539 | |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | struct chip_operations soc_intel_apollolake_ops = { |
| 543 | CHIP_NAME("Intel Apollolake SOC") |
| 544 | .enable_dev = &enable_dev, |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 545 | .init = &soc_init, |
| 546 | .final = &soc_final |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 547 | }; |
| 548 | |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 549 | static void drop_privilege_all(void) |
| 550 | { |
| 551 | /* Drop privilege level on all the CPUs */ |
| 552 | if (mp_run_on_all_cpus(&enable_untrusted_mode, 1000) < 0) |
| 553 | printk(BIOS_ERR, "failed to enable untrusted mode\n"); |
| 554 | } |
| 555 | |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 556 | void platform_fsp_notify_status(enum fsp_notify_phase phase) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 557 | { |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 558 | if (phase == END_OF_FIRMWARE) { |
| 559 | /* Hide the P2SB device to align with previous behavior. */ |
Aaron Durbin | fadfc2e | 2016-07-01 16:36:03 -0500 | [diff] [blame] | 560 | p2sb_hide(); |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 561 | /* |
| 562 | * As per guidelines BIOS is recommended to drop CPU privilege |
| 563 | * level to IA_UNTRUSTED. After that certain device registers |
| 564 | * and MSRs become inaccessible supposedly increasing system |
| 565 | * security. |
| 566 | */ |
| 567 | drop_privilege_all(); |
| 568 | } |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 569 | } |
| 570 | |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 571 | /* |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 572 | * spi_flash init() needs to run unconditionally on every boot (including |
| 573 | * resume) to allow write protect to be disabled for eventlog and nvram |
| 574 | * updates. This needs to be done as early as possible in ramstage. Thus, add a |
| 575 | * callback for entry into BS_PRE_DEVICE. |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 576 | */ |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 577 | static void spi_flash_init_cb(void *unused) |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 578 | { |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 579 | spi_flash_init(); |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 582 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, spi_flash_init_cb, NULL); |