blob: 9ac047e142e2c84903b5ecf3c060a19be494de8e [file] [log] [blame]
Andrey Petrov70efecd2016-03-04 21:41:13 -08001/*
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 Rothebabfad2016-04-10 11:09:16 -060012 *
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 Petrov70efecd2016-03-04 21:41:13 -080017 */
18
Hannah Williams0f61da82016-04-18 13:47:08 -070019#include <arch/acpi.h>
Andrey Petrov70efecd2016-03-04 21:41:13 -080020#include <bootstate.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070021#include <cbmem.h>
Andrey Petrov70efecd2016-03-04 21:41:13 -080022#include <console/console.h>
23#include <cpu/cpu.h>
Andrey Petrova697c192016-12-07 10:47:46 -080024#include <cpu/x86/mp.h>
Andrey Petrov70efecd2016-03-04 21:41:13 -080025#include <device/device.h>
26#include <device/pci.h>
27#include <fsp/api.h>
28#include <fsp/util.h>
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080029#include <romstage_handoff.h>
Andrey Petrove07e13d2016-03-18 14:43:00 -070030#include <soc/iomap.h>
Andrey Petrov70efecd2016-03-04 21:41:13 -080031#include <soc/cpu.h>
Furquan Shaikhd6c55592016-11-21 12:41:20 -080032#include <soc/flash_ctrlr.h>
Andrey Petrov868679f2016-05-12 19:11:48 -070033#include <soc/intel/common/vbt.h>
Aaron Durbin81d1e092016-07-13 01:49:10 -050034#include <soc/itss.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070035#include <soc/nvs.h>
Andrey Petrov70efecd2016-03-04 21:41:13 -080036#include <soc/pci_devs.h>
Furquan Shaikh6ac226d2016-06-15 17:13:20 -070037#include <spi-generic.h>
Andrey Petrov3dbea292016-06-14 22:20:28 -070038#include <soc/pm.h>
Aaron Durbinfadfc2e2016-07-01 16:36:03 -050039#include <soc/p2sb.h>
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +053040#include <soc/northbridge.h>
Andrey Petrov70efecd2016-03-04 21:41:13 -080041
42#include "chip.h"
43
Andrey Petrov868679f2016-05-12 19:11:48 -070044static void *vbt;
45static struct region_device vbt_rdev;
46
Duncan Laurie02fcc882016-06-27 10:51:17 -070047static 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 Shankarec9168f2016-09-16 14:20:53 -0700108 /* PCIe */
109 case PCIEB0_DEVFN:
110 return "RP01";
Duncan Laurie02fcc882016-06-27 10:51:17 -0700111 }
112
113 return NULL;
114}
115
Venkateswarlu Vinjamuri6dd7b402017-02-24 15:37:30 -0800116static 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
126struct pci_operations soc_pci_ops = {
127 .set_subsystem = &pci_set_subsystem
128};
129
Andrey Petrov70efecd2016-03-04 21:41:13 -0800130static void pci_domain_set_resources(device_t dev)
131{
Lee Leahy1d20fe72017-03-09 09:50:28 -0800132 assign_resources(dev->link_list);
Andrey Petrov70efecd2016-03-04 21:41:13 -0800133}
134
135static 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 Laurie02fcc882016-06-27 10:51:17 -0700142 .acpi_name = &soc_acpi_name,
Andrey Petrov70efecd2016-03-04 21:41:13 -0800143};
144
145static 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 Williams0f61da82016-04-18 13:47:08 -0700151 .acpi_fill_ssdt_generator = generate_cpu_entries,
Andrey Petrov70efecd2016-03-04 21:41:13 -0800152};
153
154static 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 Chend7796052016-07-11 12:17:13 +0800164/*
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 */
171static 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
207static 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 Pawnikara247d8e2016-09-27 23:18:35 +0530213/* Configure package power limits */
214static void set_power_limits(void)
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530215{
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530216 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 Pawnikar428f90a2016-12-02 18:14:19 +0530221 uint32_t pl2_val;
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530222 uint32_t *rapl_mmio_reg;
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530223
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530224 if (!dev || !dev->chip_info) {
225 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
226 return;
227 }
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530228
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530229 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 Pawnikar428f90a2016-12-02 18:14:19 +0530238 pl2_val = rapl_msr_reg.hi & PKG_POWER_LIMIT_MASK;
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530239 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 Pawnikar428f90a2016-12-02 18:14:19 +0530251 /* 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 Pawnikara247d8e2016-09-27 23:18:35 +0530254
255 /* Set long term power limit to TDP */
256 limit.lo = tdp & PKG_POWER_LIMIT_MASK;
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530257 /* 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 Pawnikar428f90a2016-12-02 18:14:19 +0530264 /* Set short term power limit PL2 */
265 limit.hi = pl2_val & PKG_POWER_LIMIT_MASK;
266 limit.hi |= PKG_POWER_LIMIT_EN;
267
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530268 /* 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 Pawnikar428f90a2016-12-02 18:14:19 +0530272 printk(BIOS_INFO, "RAPL PL2 %d.%dW\n", pl2_val / power_unit,
273 100 * (pl2_val % power_unit) / power_unit);
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530274
275 /* Get the MMIO address */
276 rapl_mmio_reg = (void *)(uintptr_t) (MCH_BASE_ADDR + MCHBAR_RAPL_PPL);
Sumeet Pawnikar428f90a2016-12-02 18:14:19 +0530277
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 Pawnikara247d8e2016-09-27 23:18:35 +0530281 write32(rapl_mmio_reg, limit.lo & ~(PKG_POWER_LIMIT_EN));
Sumeet Pawnikar428f90a2016-12-02 18:14:19 +0530282 write32(rapl_mmio_reg + 1, limit.hi & ~(PKG_POWER_LIMIT_EN));
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530283}
284
Andrey Petrov70efecd2016-03-04 21:41:13 -0800285static void soc_init(void *data)
286{
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700287 struct global_nvs_t *gnvs;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800288
Andrey Petrov868679f2016-05-12 19:11:48 -0700289 /* Save VBT info and mapping */
Abhay Kumarec2947f2016-07-14 18:43:54 -0700290 vbt = vbt_get(&vbt_rdev);
Andrey Petrov868679f2016-05-12 19:11:48 -0700291
Aaron Durbin81d1e092016-07-13 01:49:10 -0500292 /* 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 Durbin6c191d82016-11-29 21:22:42 -0600296 fsp_silicon_init(romstage_handoff_is_resume());
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700297
Aaron Durbin81d1e092016-07-13 01:49:10 -0500298 /* Restore GPIO IRQ polarities back to previous settings. */
299 itss_restore_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END);
300
Kane Chend7796052016-07-11 12:17:13 +0800301 /* override 'enabled' setting in device tree if needed */
302 pcie_override_devicetree_after_silicon_init();
303
Aaron Durbinfadfc2e2016-07-01 16:36:03 -0500304 /*
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 Zhao1bd0c0c2016-04-19 18:04:21 -0700312 /* Allocate ACPI NVS in CBMEM */
313 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530314
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530315 /* Set RAPL MSR for Package power limits*/
316 set_power_limits();
Andrey Petrov70efecd2016-03-04 21:41:13 -0800317}
318
Andrey Petrov868679f2016-05-12 19:11:48 -0700319static void soc_final(void *data)
320{
321 if (vbt)
322 rdev_munmap(&vbt_rdev, vbt);
Andrey Petrov3dbea292016-06-14 22:20:28 -0700323
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 Petrov868679f2016-05-12 19:11:48 -0700328}
329
Lee Leahybab8be22017-03-09 09:53:58 -0800330static void disable_dev(struct device *dev, FSP_S_CONFIG *silconfig)
331{
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700332 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 Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700339 case PCIEB0_DEVFN:
Kane Chend7796052016-07-11 12:17:13 +0800340 silconfig->PcieRootPortEn[0] = 0;
341 silconfig->PcieRpHotPlug[0] = 0;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700342 break;
343 case PCIEB1_DEVFN:
Kane Chend7796052016-07-11 12:17:13 +0800344 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 Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700360 silconfig->PcieRootPortEn[5] = 0;
Kane Chend7796052016-07-11 12:17:13 +0800361 silconfig->PcieRpHotPlug[5] = 0;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700362 break;
363 case XHCI_DEVFN:
364 silconfig->Usb30Mode = 0;
365 break;
366 case XDCI_DEVFN:
367 silconfig->UsbOtg = 0;
368 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700369 case LPSS_DEVFN_I2C0:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700370 silconfig->I2c0Enable = 0;
371 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700372 case LPSS_DEVFN_I2C1:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700373 silconfig->I2c1Enable = 0;
374 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700375 case LPSS_DEVFN_I2C2:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700376 silconfig->I2c2Enable = 0;
377 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700378 case LPSS_DEVFN_I2C3:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700379 silconfig->I2c3Enable = 0;
380 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700381 case LPSS_DEVFN_I2C4:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700382 silconfig->I2c4Enable = 0;
383 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700384 case LPSS_DEVFN_I2C5:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700385 silconfig->I2c5Enable = 0;
386 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700387 case LPSS_DEVFN_I2C6:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700388 silconfig->I2c6Enable = 0;
389 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700390 case LPSS_DEVFN_I2C7:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700391 silconfig->I2c7Enable = 0;
392 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700393 case LPSS_DEVFN_UART0:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700394 silconfig->Hsuart0Enable = 0;
395 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700396 case LPSS_DEVFN_UART1:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700397 silconfig->Hsuart1Enable = 0;
398 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700399 case LPSS_DEVFN_UART2:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700400 silconfig->Hsuart2Enable = 0;
401 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700402 case LPSS_DEVFN_UART3:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700403 silconfig->Hsuart3Enable = 0;
404 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700405 case LPSS_DEVFN_SPI0:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700406 silconfig->Spi0Enable = 0;
407 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700408 case LPSS_DEVFN_SPI1:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700409 silconfig->Spi1Enable = 0;
410 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700411 case LPSS_DEVFN_SPI2:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700412 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 Breitensteinc31ba0e2016-07-27 17:34:45 -0700434static void parse_devicetree(FSP_S_CONFIG *silconfig)
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700435{
Andrey Petrov78461a92016-06-28 12:14:33 -0700436 struct device *dev = NB_DEV_ROOT;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700437
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 Breitensteinc31ba0e2016-07-27 17:34:45 -0700449void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd)
Andrey Petrov70efecd2016-03-04 21:41:13 -0800450{
Lee Leahy1d20fe72017-03-09 09:50:28 -0800451 FSP_S_CONFIG *silconfig = &silupd->FspsConfig;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800452 static struct soc_intel_apollolake_config *cfg;
Kane Chen9d490da2017-01-11 12:53:58 +0800453 uint8_t port;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800454
455 /* Load VBT before devicetree-specific config. */
Andrey Petrov868679f2016-05-12 19:11:48 -0700456 silconfig->GraphicsConfigPtr = (uintptr_t)vbt;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800457
Andrey Petrov78461a92016-06-28 12:14:33 -0700458 struct device *dev = NB_DEV_ROOT;
459
Patrick Georgi831d65d2016-04-14 11:53:48 +0200460 if (!dev || !dev->chip_info) {
Andrey Petrov70efecd2016-03-04 21:41:13 -0800461 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
462 return;
463 }
464
465 cfg = dev->chip_info;
466
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700467 /* Parse device tree and disable unused device*/
468 parse_devicetree(silconfig);
469
Andrey Petrov70efecd2016-03-04 21:41:13 -0800470 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 Petrove07e13d2016-03-18 14:43:00 -0700476
Zhao, Lijian1b8ee0b2016-05-17 19:01:34 -0700477 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 Satijae46dbcc2016-05-03 15:15:31 -0700490 silconfig->LPSS_S0ixEnable = cfg->lpss_s0ix_enable;
491
Bora Guvendik60cc75d2016-07-25 14:44:51 -0700492 /* Disable monitor mwait since it is broken due to a hardware bug without a fix */
493 silconfig->MonitorMwaitEnable = 0;
494
Venkateswarlu Vinjamuri1a5e32c2016-10-31 17:15:30 -0700495 silconfig->SkipMpInit = 1;
496
Furquan Shaikhcad9b632016-06-20 16:08:42 -0700497 /* Disable setting of EISS bit in FSP. */
498 silconfig->SpiEiss = 0;
Ravi Sarawadi3a21d0f2016-08-10 11:33:56 -0700499
500 /* Disable FSP from locking access to the RTC NVRAM */
501 silconfig->RtcLock = 0;
Venkateswarlu Vinjamuri88df48c2016-09-02 16:04:27 -0700502
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 Chen9d490da2017-01-11 12:53:58 +0800509 /* 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 Petrov70efecd2016-03-04 21:41:13 -0800540}
541
542struct chip_operations soc_intel_apollolake_ops = {
543 CHIP_NAME("Intel Apollolake SOC")
544 .enable_dev = &enable_dev,
Andrey Petrov868679f2016-05-12 19:11:48 -0700545 .init = &soc_init,
546 .final = &soc_final
Andrey Petrov70efecd2016-03-04 21:41:13 -0800547};
548
Andrey Petrova697c192016-12-07 10:47:46 -0800549static 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 Leahy806fa242016-08-01 13:55:02 -0700556void platform_fsp_notify_status(enum fsp_notify_phase phase)
Andrey Petrov70efecd2016-03-04 21:41:13 -0800557{
Andrey Petrova697c192016-12-07 10:47:46 -0800558 if (phase == END_OF_FIRMWARE) {
559 /* Hide the P2SB device to align with previous behavior. */
Aaron Durbinfadfc2e2016-07-01 16:36:03 -0500560 p2sb_hide();
Andrey Petrova697c192016-12-07 10:47:46 -0800561 /*
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 Petrov70efecd2016-03-04 21:41:13 -0800569}
570
Furquan Shaikh6ac226d2016-06-15 17:13:20 -0700571/*
Furquan Shaikhd6c55592016-11-21 12:41:20 -0800572 * 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 Shaikh6ac226d2016-06-15 17:13:20 -0700576 */
Furquan Shaikhd6c55592016-11-21 12:41:20 -0800577static void spi_flash_init_cb(void *unused)
Furquan Shaikh6ac226d2016-06-15 17:13:20 -0700578{
Furquan Shaikhd6c55592016-11-21 12:41:20 -0800579 spi_flash_init();
Furquan Shaikh6ac226d2016-06-15 17:13:20 -0700580}
581
Furquan Shaikhd6c55592016-11-21 12:41:20 -0800582BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, spi_flash_init_cb, NULL);