blob: eacf55410588ddada909480e093024b6a375c9e7 [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 */
Lee Leahy4430f9f2017-03-09 10:00:30 -0800157 if (dev->path.type == DEVICE_PATH_DOMAIN)
Andrey Petrov70efecd2016-03-04 21:41:13 -0800158 dev->ops = &pci_domain_ops;
Lee Leahy4430f9f2017-03-09 10:00:30 -0800159 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Andrey Petrov70efecd2016-03-04 21:41:13 -0800160 dev->ops = &cpu_bus_ops;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800161}
162
Kane Chend7796052016-07-11 12:17:13 +0800163/*
164 * If the PCIe root port at function 0 is disabled,
165 * the PCIe root ports might be coalesced after FSP silicon init.
166 * The below function will swap the devfn of the first enabled device
167 * in devicetree and function 0 resides a pci device
168 * so that it won't confuse coreboot.
169 */
170static void pcie_update_device_tree(unsigned int devfn0, int num_funcs)
171{
172 device_t func0;
173 unsigned int devfn;
174 int i;
175 unsigned int inc = PCI_DEVFN(0, 1);
176
177 func0 = dev_find_slot(0, devfn0);
178 if (func0 == NULL)
179 return;
180
181 /* No more functions if function 0 is disabled. */
182 if (pci_read_config32(func0, PCI_VENDOR_ID) == 0xffffffff)
183 return;
184
185 devfn = devfn0 + inc;
186
187 /*
188 * Increase funtion by 1.
189 * Then find first enabled device to replace func0
190 * as that port was move to func0.
191 */
192 for (i = 1; i < num_funcs; i++, devfn += inc) {
193 device_t dev = dev_find_slot(0, devfn);
194 if (dev == NULL)
195 continue;
196
197 if (!dev->enabled)
198 continue;
199 /* Found the first enabled device in given dev number */
200 func0->path.pci.devfn = dev->path.pci.devfn;
201 dev->path.pci.devfn = devfn0;
202 break;
203 }
204}
205
206static void pcie_override_devicetree_after_silicon_init(void)
207{
208 pcie_update_device_tree(PCIEA0_DEVFN, 4);
209 pcie_update_device_tree(PCIEB0_DEVFN, 2);
210}
211
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530212/* Configure package power limits */
213static void set_power_limits(void)
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530214{
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530215 static struct soc_intel_apollolake_config *cfg;
216 struct device *dev = NB_DEV_ROOT;
217 msr_t rapl_msr_reg, limit;
218 uint32_t power_unit;
219 uint32_t tdp, min_power, max_power;
Sumeet Pawnikar428f90a2016-12-02 18:14:19 +0530220 uint32_t pl2_val;
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530221 uint32_t *rapl_mmio_reg;
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530222
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530223 if (!dev || !dev->chip_info) {
224 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
225 return;
226 }
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530227
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530228 cfg = dev->chip_info;
229
230 /* Get units */
231 rapl_msr_reg = rdmsr(MSR_PKG_POWER_SKU_UNIT);
232 power_unit = 1 << (rapl_msr_reg.lo & 0xf);
233
234 /* Get power defaults for this SKU */
235 rapl_msr_reg = rdmsr(MSR_PKG_POWER_SKU);
236 tdp = rapl_msr_reg.lo & PKG_POWER_LIMIT_MASK;
Sumeet Pawnikar428f90a2016-12-02 18:14:19 +0530237 pl2_val = rapl_msr_reg.hi & PKG_POWER_LIMIT_MASK;
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530238 min_power = (rapl_msr_reg.lo >> 16) & PKG_POWER_LIMIT_MASK;
239 max_power = rapl_msr_reg.hi & PKG_POWER_LIMIT_MASK;
240
241 if (min_power > 0 && tdp < min_power)
242 tdp = min_power;
243
244 if (max_power > 0 && tdp > max_power)
245 tdp = max_power;
246
247 /* Set PL1 override value */
248 tdp = (cfg->tdp_pl1_override_mw == 0) ?
249 tdp : (cfg->tdp_pl1_override_mw * power_unit) / 1000;
Sumeet Pawnikar428f90a2016-12-02 18:14:19 +0530250 /* Set PL2 override value */
251 pl2_val = (cfg->tdp_pl2_override_mw == 0) ?
252 pl2_val : (cfg->tdp_pl2_override_mw * power_unit) / 1000;
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530253
254 /* Set long term power limit to TDP */
255 limit.lo = tdp & PKG_POWER_LIMIT_MASK;
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530256 /* Set PL1 Pkg Power clamp bit */
257 limit.lo |= PKG_POWER_LIMIT_CLAMP;
258
259 limit.lo |= PKG_POWER_LIMIT_EN;
260 limit.lo |= (MB_POWER_LIMIT1_TIME_DEFAULT &
261 PKG_POWER_LIMIT_TIME_MASK) << PKG_POWER_LIMIT_TIME_SHIFT;
262
Sumeet Pawnikar428f90a2016-12-02 18:14:19 +0530263 /* Set short term power limit PL2 */
264 limit.hi = pl2_val & PKG_POWER_LIMIT_MASK;
265 limit.hi |= PKG_POWER_LIMIT_EN;
266
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530267 /* Program package power limits in RAPL MSR */
268 wrmsr(MSR_PKG_POWER_LIMIT, limit);
269 printk(BIOS_INFO, "RAPL PL1 %d.%dW\n", tdp / power_unit,
270 100 * (tdp % power_unit) / power_unit);
Sumeet Pawnikar428f90a2016-12-02 18:14:19 +0530271 printk(BIOS_INFO, "RAPL PL2 %d.%dW\n", pl2_val / power_unit,
272 100 * (pl2_val % power_unit) / power_unit);
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530273
274 /* Get the MMIO address */
275 rapl_mmio_reg = (void *)(uintptr_t) (MCH_BASE_ADDR + MCHBAR_RAPL_PPL);
Sumeet Pawnikar428f90a2016-12-02 18:14:19 +0530276
277 /* Setting RAPL MMIO register for Power limits.
278 * RAPL driver is using MSR instead of MMIO.
279 * So, disabled LIMIT_EN bit for MMIO. */
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530280 write32(rapl_mmio_reg, limit.lo & ~(PKG_POWER_LIMIT_EN));
Sumeet Pawnikar428f90a2016-12-02 18:14:19 +0530281 write32(rapl_mmio_reg + 1, limit.hi & ~(PKG_POWER_LIMIT_EN));
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530282}
283
Andrey Petrov70efecd2016-03-04 21:41:13 -0800284static void soc_init(void *data)
285{
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700286 struct global_nvs_t *gnvs;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800287
Andrey Petrov868679f2016-05-12 19:11:48 -0700288 /* Save VBT info and mapping */
Abhay Kumarec2947f2016-07-14 18:43:54 -0700289 vbt = vbt_get(&vbt_rdev);
Andrey Petrov868679f2016-05-12 19:11:48 -0700290
Aaron Durbin81d1e092016-07-13 01:49:10 -0500291 /* Snapshot the current GPIO IRQ polarities. FSP is setting a
292 * default policy that doesn't honor boards' requirements. */
293 itss_snapshot_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END);
294
Aaron Durbin6c191d82016-11-29 21:22:42 -0600295 fsp_silicon_init(romstage_handoff_is_resume());
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700296
Aaron Durbin81d1e092016-07-13 01:49:10 -0500297 /* Restore GPIO IRQ polarities back to previous settings. */
298 itss_restore_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END);
299
Kane Chend7796052016-07-11 12:17:13 +0800300 /* override 'enabled' setting in device tree if needed */
301 pcie_override_devicetree_after_silicon_init();
302
Aaron Durbinfadfc2e2016-07-01 16:36:03 -0500303 /*
304 * Keep the P2SB device visible so it and the other devices are
305 * visible in coreboot for driver support and PCI resource allocation.
306 * There is a UPD setting for this, but it's more consistent to use
307 * hide and unhide symmetrically.
308 */
309 p2sb_unhide();
310
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700311 /* Allocate ACPI NVS in CBMEM */
312 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Sumeet Pawnikar35240eb2016-08-23 11:20:20 +0530313
Sumeet Pawnikara247d8e2016-09-27 23:18:35 +0530314 /* Set RAPL MSR for Package power limits*/
315 set_power_limits();
Andrey Petrov70efecd2016-03-04 21:41:13 -0800316}
317
Andrey Petrov868679f2016-05-12 19:11:48 -0700318static void soc_final(void *data)
319{
320 if (vbt)
321 rdev_munmap(&vbt_rdev, vbt);
Andrey Petrov3dbea292016-06-14 22:20:28 -0700322
323 /* Disable global reset, just in case */
324 global_reset_enable(0);
325 /* Make sure payload/OS can't trigger global reset */
326 global_reset_lock();
Andrey Petrov868679f2016-05-12 19:11:48 -0700327}
328
Lee Leahybab8be22017-03-09 09:53:58 -0800329static void disable_dev(struct device *dev, FSP_S_CONFIG *silconfig)
330{
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700331 switch (dev->path.pci.devfn) {
332 case ISH_DEVFN:
333 silconfig->IshEnable = 0;
334 break;
335 case SATA_DEVFN:
336 silconfig->EnableSata = 0;
337 break;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700338 case PCIEB0_DEVFN:
Kane Chend7796052016-07-11 12:17:13 +0800339 silconfig->PcieRootPortEn[0] = 0;
340 silconfig->PcieRpHotPlug[0] = 0;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700341 break;
342 case PCIEB1_DEVFN:
Kane Chend7796052016-07-11 12:17:13 +0800343 silconfig->PcieRootPortEn[1] = 0;
344 silconfig->PcieRpHotPlug[1] = 0;
345 break;
346 case PCIEA0_DEVFN:
347 silconfig->PcieRootPortEn[2] = 0;
348 silconfig->PcieRpHotPlug[2] = 0;
349 break;
350 case PCIEA1_DEVFN:
351 silconfig->PcieRootPortEn[3] = 0;
352 silconfig->PcieRpHotPlug[3] = 0;
353 break;
354 case PCIEA2_DEVFN:
355 silconfig->PcieRootPortEn[4] = 0;
356 silconfig->PcieRpHotPlug[4] = 0;
357 break;
358 case PCIEA3_DEVFN:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700359 silconfig->PcieRootPortEn[5] = 0;
Kane Chend7796052016-07-11 12:17:13 +0800360 silconfig->PcieRpHotPlug[5] = 0;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700361 break;
362 case XHCI_DEVFN:
363 silconfig->Usb30Mode = 0;
364 break;
365 case XDCI_DEVFN:
366 silconfig->UsbOtg = 0;
367 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700368 case LPSS_DEVFN_I2C0:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700369 silconfig->I2c0Enable = 0;
370 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700371 case LPSS_DEVFN_I2C1:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700372 silconfig->I2c1Enable = 0;
373 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700374 case LPSS_DEVFN_I2C2:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700375 silconfig->I2c2Enable = 0;
376 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700377 case LPSS_DEVFN_I2C3:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700378 silconfig->I2c3Enable = 0;
379 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700380 case LPSS_DEVFN_I2C4:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700381 silconfig->I2c4Enable = 0;
382 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700383 case LPSS_DEVFN_I2C5:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700384 silconfig->I2c5Enable = 0;
385 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700386 case LPSS_DEVFN_I2C6:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700387 silconfig->I2c6Enable = 0;
388 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700389 case LPSS_DEVFN_I2C7:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700390 silconfig->I2c7Enable = 0;
391 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700392 case LPSS_DEVFN_UART0:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700393 silconfig->Hsuart0Enable = 0;
394 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700395 case LPSS_DEVFN_UART1:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700396 silconfig->Hsuart1Enable = 0;
397 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700398 case LPSS_DEVFN_UART2:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700399 silconfig->Hsuart2Enable = 0;
400 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700401 case LPSS_DEVFN_UART3:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700402 silconfig->Hsuart3Enable = 0;
403 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700404 case LPSS_DEVFN_SPI0:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700405 silconfig->Spi0Enable = 0;
406 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700407 case LPSS_DEVFN_SPI1:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700408 silconfig->Spi1Enable = 0;
409 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700410 case LPSS_DEVFN_SPI2:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700411 silconfig->Spi2Enable = 0;
412 break;
413 case SDCARD_DEVFN:
414 silconfig->SdcardEnabled = 0;
415 break;
416 case EMMC_DEVFN:
417 silconfig->eMMCEnabled = 0;
418 break;
419 case SDIO_DEVFN:
420 silconfig->SdioEnabled = 0;
421 break;
422 case SMBUS_DEVFN:
423 silconfig->SmbusEnable = 0;
424 break;
425 default:
426 printk(BIOS_WARNING, "PCI:%02x.%01x: Could not disable the device\n",
427 PCI_SLOT(dev->path.pci.devfn),
428 PCI_FUNC(dev->path.pci.devfn));
429 break;
430 }
431}
432
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700433static void parse_devicetree(FSP_S_CONFIG *silconfig)
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700434{
Andrey Petrov78461a92016-06-28 12:14:33 -0700435 struct device *dev = NB_DEV_ROOT;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700436
437 if (!dev) {
438 printk(BIOS_ERR, "Could not find root device\n");
439 return;
440 }
441 /* Only disable bus 0 devices. */
442 for (dev = dev->bus->children; dev; dev = dev->sibling) {
443 if (!dev->enabled)
444 disable_dev(dev, silconfig);
445 }
446}
447
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700448void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd)
Andrey Petrov70efecd2016-03-04 21:41:13 -0800449{
Lee Leahy1d20fe72017-03-09 09:50:28 -0800450 FSP_S_CONFIG *silconfig = &silupd->FspsConfig;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800451 static struct soc_intel_apollolake_config *cfg;
Kane Chen9d490da2017-01-11 12:53:58 +0800452 uint8_t port;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800453
454 /* Load VBT before devicetree-specific config. */
Andrey Petrov868679f2016-05-12 19:11:48 -0700455 silconfig->GraphicsConfigPtr = (uintptr_t)vbt;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800456
Andrey Petrov78461a92016-06-28 12:14:33 -0700457 struct device *dev = NB_DEV_ROOT;
458
Patrick Georgi831d65d2016-04-14 11:53:48 +0200459 if (!dev || !dev->chip_info) {
Andrey Petrov70efecd2016-03-04 21:41:13 -0800460 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
461 return;
462 }
463
464 cfg = dev->chip_info;
465
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700466 /* Parse device tree and disable unused device*/
467 parse_devicetree(silconfig);
468
Andrey Petrov70efecd2016-03-04 21:41:13 -0800469 silconfig->PcieRpClkReqNumber[0] = cfg->pcie_rp0_clkreq_pin;
470 silconfig->PcieRpClkReqNumber[1] = cfg->pcie_rp1_clkreq_pin;
471 silconfig->PcieRpClkReqNumber[2] = cfg->pcie_rp2_clkreq_pin;
472 silconfig->PcieRpClkReqNumber[3] = cfg->pcie_rp3_clkreq_pin;
473 silconfig->PcieRpClkReqNumber[4] = cfg->pcie_rp4_clkreq_pin;
474 silconfig->PcieRpClkReqNumber[5] = cfg->pcie_rp5_clkreq_pin;
Andrey Petrove07e13d2016-03-18 14:43:00 -0700475
Zhao, Lijian1b8ee0b2016-05-17 19:01:34 -0700476 if (cfg->emmc_tx_cmd_cntl != 0)
477 silconfig->EmmcTxCmdCntl = cfg->emmc_tx_cmd_cntl;
478 if (cfg->emmc_tx_data_cntl1 != 0)
479 silconfig->EmmcTxDataCntl1 = cfg->emmc_tx_data_cntl1;
480 if (cfg->emmc_tx_data_cntl2 != 0)
481 silconfig->EmmcTxDataCntl2 = cfg->emmc_tx_data_cntl2;
482 if (cfg->emmc_rx_cmd_data_cntl1 != 0)
483 silconfig->EmmcRxCmdDataCntl1 = cfg->emmc_rx_cmd_data_cntl1;
484 if (cfg->emmc_rx_strobe_cntl != 0)
485 silconfig->EmmcRxStrobeCntl = cfg->emmc_rx_strobe_cntl;
486 if (cfg->emmc_rx_cmd_data_cntl2 != 0)
487 silconfig->EmmcRxCmdDataCntl2 = cfg->emmc_rx_cmd_data_cntl2;
488
Saurabh Satijae46dbcc2016-05-03 15:15:31 -0700489 silconfig->LPSS_S0ixEnable = cfg->lpss_s0ix_enable;
490
Bora Guvendik60cc75d2016-07-25 14:44:51 -0700491 /* Disable monitor mwait since it is broken due to a hardware bug without a fix */
492 silconfig->MonitorMwaitEnable = 0;
493
Venkateswarlu Vinjamuri1a5e32c2016-10-31 17:15:30 -0700494 silconfig->SkipMpInit = 1;
495
Furquan Shaikhcad9b632016-06-20 16:08:42 -0700496 /* Disable setting of EISS bit in FSP. */
497 silconfig->SpiEiss = 0;
Ravi Sarawadi3a21d0f2016-08-10 11:33:56 -0700498
499 /* Disable FSP from locking access to the RTC NVRAM */
500 silconfig->RtcLock = 0;
Venkateswarlu Vinjamuri88df48c2016-09-02 16:04:27 -0700501
502 /* Enable Audio clk gate and power gate */
503 silconfig->HDAudioClkGate = cfg->hdaudio_clk_gate_enable;
504 silconfig->HDAudioPwrGate = cfg->hdaudio_pwr_gate_enable;
505 /* Bios config lockdown Audio clk and power gate */
506 silconfig->BiosCfgLockDown = cfg->hdaudio_bios_config_lockdown;
507
Kane Chen9d490da2017-01-11 12:53:58 +0800508 /* USB2 eye diagram settings per port */
509 for (port = 0; port < APOLLOLAKE_USB2_PORT_MAX; port++) {
510 if (cfg->usb2eye[port].Usb20PerPortTxPeHalf != 0)
511 silconfig->PortUsb20PerPortTxPeHalf[port] =
512 cfg->usb2eye[port].Usb20PerPortTxPeHalf;
513
514 if (cfg->usb2eye[port].Usb20PerPortPeTxiSet != 0)
515 silconfig->PortUsb20PerPortPeTxiSet[port] =
516 cfg->usb2eye[port].Usb20PerPortPeTxiSet;
517
518 if (cfg->usb2eye[port].Usb20PerPortTxiSet != 0)
519 silconfig->PortUsb20PerPortTxiSet[port] =
520 cfg->usb2eye[port].Usb20PerPortTxiSet;
521
522 if (cfg->usb2eye[port].Usb20HsSkewSel != 0)
523 silconfig->PortUsb20HsSkewSel[port] =
524 cfg->usb2eye[port].Usb20HsSkewSel;
525
526 if (cfg->usb2eye[port].Usb20IUsbTxEmphasisEn != 0)
527 silconfig->PortUsb20IUsbTxEmphasisEn[port] =
528 cfg->usb2eye[port].Usb20IUsbTxEmphasisEn;
529
530 if (cfg->usb2eye[port].Usb20PerPortRXISet != 0)
531 silconfig->PortUsb20PerPortRXISet[port] =
532 cfg->usb2eye[port].Usb20PerPortRXISet;
533
534 if (cfg->usb2eye[port].Usb20HsNpreDrvSel != 0)
535 silconfig->PortUsb20HsNpreDrvSel[port] =
536 cfg->usb2eye[port].Usb20HsNpreDrvSel;
537 }
538
Andrey Petrov70efecd2016-03-04 21:41:13 -0800539}
540
541struct chip_operations soc_intel_apollolake_ops = {
542 CHIP_NAME("Intel Apollolake SOC")
543 .enable_dev = &enable_dev,
Andrey Petrov868679f2016-05-12 19:11:48 -0700544 .init = &soc_init,
545 .final = &soc_final
Andrey Petrov70efecd2016-03-04 21:41:13 -0800546};
547
Andrey Petrova697c192016-12-07 10:47:46 -0800548static void drop_privilege_all(void)
549{
550 /* Drop privilege level on all the CPUs */
551 if (mp_run_on_all_cpus(&enable_untrusted_mode, 1000) < 0)
552 printk(BIOS_ERR, "failed to enable untrusted mode\n");
553}
554
Lee Leahy806fa242016-08-01 13:55:02 -0700555void platform_fsp_notify_status(enum fsp_notify_phase phase)
Andrey Petrov70efecd2016-03-04 21:41:13 -0800556{
Andrey Petrova697c192016-12-07 10:47:46 -0800557 if (phase == END_OF_FIRMWARE) {
558 /* Hide the P2SB device to align with previous behavior. */
Aaron Durbinfadfc2e2016-07-01 16:36:03 -0500559 p2sb_hide();
Andrey Petrova697c192016-12-07 10:47:46 -0800560 /*
561 * As per guidelines BIOS is recommended to drop CPU privilege
562 * level to IA_UNTRUSTED. After that certain device registers
563 * and MSRs become inaccessible supposedly increasing system
564 * security.
565 */
566 drop_privilege_all();
567 }
Andrey Petrov70efecd2016-03-04 21:41:13 -0800568}
569
Furquan Shaikh6ac226d2016-06-15 17:13:20 -0700570/*
Furquan Shaikhd6c55592016-11-21 12:41:20 -0800571 * spi_flash init() needs to run unconditionally on every boot (including
572 * resume) to allow write protect to be disabled for eventlog and nvram
573 * updates. This needs to be done as early as possible in ramstage. Thus, add a
574 * callback for entry into BS_PRE_DEVICE.
Furquan Shaikh6ac226d2016-06-15 17:13:20 -0700575 */
Furquan Shaikhd6c55592016-11-21 12:41:20 -0800576static void spi_flash_init_cb(void *unused)
Furquan Shaikh6ac226d2016-06-15 17:13:20 -0700577{
Furquan Shaikhd6c55592016-11-21 12:41:20 -0800578 spi_flash_init();
Furquan Shaikh6ac226d2016-06-15 17:13:20 -0700579}
580
Furquan Shaikhd6c55592016-11-21 12:41:20 -0800581BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, spi_flash_init_cb, NULL);