blob: 345d7c4446d20f747e381d48e2c5a13a2ab61529 [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>
24#include <device/device.h>
25#include <device/pci.h>
26#include <fsp/api.h>
27#include <fsp/util.h>
Andrey Petrove07e13d2016-03-18 14:43:00 -070028#include <soc/iomap.h>
Andrey Petrov70efecd2016-03-04 21:41:13 -080029#include <soc/cpu.h>
Andrey Petrov868679f2016-05-12 19:11:48 -070030#include <soc/intel/common/vbt.h>
Aaron Durbin81d1e092016-07-13 01:49:10 -050031#include <soc/itss.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070032#include <soc/nvs.h>
Andrey Petrov70efecd2016-03-04 21:41:13 -080033#include <soc/pci_devs.h>
Furquan Shaikh6ac226d2016-06-15 17:13:20 -070034#include <spi-generic.h>
Andrey Petrov3dbea292016-06-14 22:20:28 -070035#include <soc/pm.h>
Aaron Durbinfadfc2e2016-07-01 16:36:03 -050036#include <soc/p2sb.h>
Andrey Petrov70efecd2016-03-04 21:41:13 -080037
38#include "chip.h"
39
Andrey Petrov868679f2016-05-12 19:11:48 -070040static void *vbt;
41static struct region_device vbt_rdev;
42
Duncan Laurie02fcc882016-06-27 10:51:17 -070043static const char *soc_acpi_name(struct device *dev)
44{
45 if (dev->path.type == DEVICE_PATH_DOMAIN)
46 return "PCI0";
47
48 if (dev->path.type != DEVICE_PATH_PCI)
49 return NULL;
50
51 switch (dev->path.pci.devfn) {
52 /* DSDT: acpi/northbridge.asl */
53 case NB_DEVFN:
54 return "MCHC";
55 /* DSDT: acpi/lpc.asl */
56 case LPC_DEVFN:
57 return "LPCB";
58 /* DSDT: acpi/xhci.asl */
59 case XHCI_DEVFN:
60 return "XHCI";
61 /* DSDT: acpi/pch_hda.asl */
62 case HDA_DEVFN:
63 return "HDAS";
64 /* DSDT: acpi/lpss.asl */
65 case LPSS_DEVFN_UART0:
66 return "URT1";
67 case LPSS_DEVFN_UART1:
68 return "URT2";
69 case LPSS_DEVFN_UART2:
70 return "URT3";
71 case LPSS_DEVFN_UART3:
72 return "URT4";
73 case LPSS_DEVFN_SPI0:
74 return "SPI1";
75 case LPSS_DEVFN_SPI1:
76 return "SPI2";
77 case LPSS_DEVFN_SPI2:
78 return "SPI3";
79 case LPSS_DEVFN_PWM:
80 return "PWM";
81 case LPSS_DEVFN_I2C0:
82 return "I2C0";
83 case LPSS_DEVFN_I2C1:
84 return "I2C1";
85 case LPSS_DEVFN_I2C2:
86 return "I2C2";
87 case LPSS_DEVFN_I2C3:
88 return "I2C3";
89 case LPSS_DEVFN_I2C4:
90 return "I2C4";
91 case LPSS_DEVFN_I2C5:
92 return "I2C5";
93 case LPSS_DEVFN_I2C6:
94 return "I2C6";
95 case LPSS_DEVFN_I2C7:
96 return "I2C7";
97 /* Storage */
98 case SDCARD_DEVFN:
99 return "SDCD";
100 case EMMC_DEVFN:
101 return "EMMC";
102 case SDIO_DEVFN:
103 return "SDIO";
104 }
105
106 return NULL;
107}
108
Andrey Petrov70efecd2016-03-04 21:41:13 -0800109static void pci_domain_set_resources(device_t dev)
110{
111 assign_resources(dev->link_list);
112}
113
114static struct device_operations pci_domain_ops = {
115 .read_resources = pci_domain_read_resources,
116 .set_resources = pci_domain_set_resources,
117 .enable_resources = NULL,
118 .init = NULL,
119 .scan_bus = pci_domain_scan_bus,
120 .ops_pci_bus = pci_bus_default_ops,
Duncan Laurie02fcc882016-06-27 10:51:17 -0700121 .acpi_name = &soc_acpi_name,
Andrey Petrov70efecd2016-03-04 21:41:13 -0800122};
123
124static struct device_operations cpu_bus_ops = {
125 .read_resources = DEVICE_NOOP,
126 .set_resources = DEVICE_NOOP,
127 .enable_resources = DEVICE_NOOP,
128 .init = apollolake_init_cpus,
129 .scan_bus = NULL,
Hannah Williams0f61da82016-04-18 13:47:08 -0700130 .acpi_fill_ssdt_generator = generate_cpu_entries,
Andrey Petrov70efecd2016-03-04 21:41:13 -0800131};
132
133static void enable_dev(device_t dev)
134{
135 /* Set the operations if it is a special bus type */
136 if (dev->path.type == DEVICE_PATH_DOMAIN) {
137 dev->ops = &pci_domain_ops;
138 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
139 dev->ops = &cpu_bus_ops;
140 }
141}
142
Kane Chend7796052016-07-11 12:17:13 +0800143/*
144 * If the PCIe root port at function 0 is disabled,
145 * the PCIe root ports might be coalesced after FSP silicon init.
146 * The below function will swap the devfn of the first enabled device
147 * in devicetree and function 0 resides a pci device
148 * so that it won't confuse coreboot.
149 */
150static void pcie_update_device_tree(unsigned int devfn0, int num_funcs)
151{
152 device_t func0;
153 unsigned int devfn;
154 int i;
155 unsigned int inc = PCI_DEVFN(0, 1);
156
157 func0 = dev_find_slot(0, devfn0);
158 if (func0 == NULL)
159 return;
160
161 /* No more functions if function 0 is disabled. */
162 if (pci_read_config32(func0, PCI_VENDOR_ID) == 0xffffffff)
163 return;
164
165 devfn = devfn0 + inc;
166
167 /*
168 * Increase funtion by 1.
169 * Then find first enabled device to replace func0
170 * as that port was move to func0.
171 */
172 for (i = 1; i < num_funcs; i++, devfn += inc) {
173 device_t dev = dev_find_slot(0, devfn);
174 if (dev == NULL)
175 continue;
176
177 if (!dev->enabled)
178 continue;
179 /* Found the first enabled device in given dev number */
180 func0->path.pci.devfn = dev->path.pci.devfn;
181 dev->path.pci.devfn = devfn0;
182 break;
183 }
184}
185
186static void pcie_override_devicetree_after_silicon_init(void)
187{
188 pcie_update_device_tree(PCIEA0_DEVFN, 4);
189 pcie_update_device_tree(PCIEB0_DEVFN, 2);
190}
191
Andrey Petrov70efecd2016-03-04 21:41:13 -0800192static void soc_init(void *data)
193{
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700194 struct global_nvs_t *gnvs;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800195
Andrey Petrov868679f2016-05-12 19:11:48 -0700196 /* Save VBT info and mapping */
Abhay Kumarec2947f2016-07-14 18:43:54 -0700197 vbt = vbt_get(&vbt_rdev);
Andrey Petrov868679f2016-05-12 19:11:48 -0700198
Aaron Durbin81d1e092016-07-13 01:49:10 -0500199 /* Snapshot the current GPIO IRQ polarities. FSP is setting a
200 * default policy that doesn't honor boards' requirements. */
201 itss_snapshot_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END);
202
Lee Leahy9671faa2016-07-24 18:18:52 -0700203 fsp_silicon_init();
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700204
Aaron Durbin81d1e092016-07-13 01:49:10 -0500205 /* Restore GPIO IRQ polarities back to previous settings. */
206 itss_restore_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END);
207
Kane Chend7796052016-07-11 12:17:13 +0800208 /* override 'enabled' setting in device tree if needed */
209 pcie_override_devicetree_after_silicon_init();
210
Aaron Durbinfadfc2e2016-07-01 16:36:03 -0500211 /*
212 * Keep the P2SB device visible so it and the other devices are
213 * visible in coreboot for driver support and PCI resource allocation.
214 * There is a UPD setting for this, but it's more consistent to use
215 * hide and unhide symmetrically.
216 */
217 p2sb_unhide();
218
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700219 /* Allocate ACPI NVS in CBMEM */
220 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Andrey Petrov70efecd2016-03-04 21:41:13 -0800221}
222
Andrey Petrov868679f2016-05-12 19:11:48 -0700223static void soc_final(void *data)
224{
225 if (vbt)
226 rdev_munmap(&vbt_rdev, vbt);
Andrey Petrov3dbea292016-06-14 22:20:28 -0700227
228 /* Disable global reset, just in case */
229 global_reset_enable(0);
230 /* Make sure payload/OS can't trigger global reset */
231 global_reset_lock();
Andrey Petrov868679f2016-05-12 19:11:48 -0700232}
233
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700234static void disable_dev(struct device *dev, struct FSP_S_CONFIG *silconfig) {
235
236 switch (dev->path.pci.devfn) {
237 case ISH_DEVFN:
238 silconfig->IshEnable = 0;
239 break;
240 case SATA_DEVFN:
241 silconfig->EnableSata = 0;
242 break;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700243 case PCIEB0_DEVFN:
Kane Chend7796052016-07-11 12:17:13 +0800244 silconfig->PcieRootPortEn[0] = 0;
245 silconfig->PcieRpHotPlug[0] = 0;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700246 break;
247 case PCIEB1_DEVFN:
Kane Chend7796052016-07-11 12:17:13 +0800248 silconfig->PcieRootPortEn[1] = 0;
249 silconfig->PcieRpHotPlug[1] = 0;
250 break;
251 case PCIEA0_DEVFN:
252 silconfig->PcieRootPortEn[2] = 0;
253 silconfig->PcieRpHotPlug[2] = 0;
254 break;
255 case PCIEA1_DEVFN:
256 silconfig->PcieRootPortEn[3] = 0;
257 silconfig->PcieRpHotPlug[3] = 0;
258 break;
259 case PCIEA2_DEVFN:
260 silconfig->PcieRootPortEn[4] = 0;
261 silconfig->PcieRpHotPlug[4] = 0;
262 break;
263 case PCIEA3_DEVFN:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700264 silconfig->PcieRootPortEn[5] = 0;
Kane Chend7796052016-07-11 12:17:13 +0800265 silconfig->PcieRpHotPlug[5] = 0;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700266 break;
267 case XHCI_DEVFN:
268 silconfig->Usb30Mode = 0;
269 break;
270 case XDCI_DEVFN:
271 silconfig->UsbOtg = 0;
272 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700273 case LPSS_DEVFN_I2C0:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700274 silconfig->I2c0Enable = 0;
275 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700276 case LPSS_DEVFN_I2C1:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700277 silconfig->I2c1Enable = 0;
278 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700279 case LPSS_DEVFN_I2C2:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700280 silconfig->I2c2Enable = 0;
281 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700282 case LPSS_DEVFN_I2C3:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700283 silconfig->I2c3Enable = 0;
284 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700285 case LPSS_DEVFN_I2C4:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700286 silconfig->I2c4Enable = 0;
287 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700288 case LPSS_DEVFN_I2C5:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700289 silconfig->I2c5Enable = 0;
290 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700291 case LPSS_DEVFN_I2C6:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700292 silconfig->I2c6Enable = 0;
293 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700294 case LPSS_DEVFN_I2C7:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700295 silconfig->I2c7Enable = 0;
296 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700297 case LPSS_DEVFN_UART0:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700298 silconfig->Hsuart0Enable = 0;
299 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700300 case LPSS_DEVFN_UART1:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700301 silconfig->Hsuart1Enable = 0;
302 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700303 case LPSS_DEVFN_UART2:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700304 silconfig->Hsuart2Enable = 0;
305 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700306 case LPSS_DEVFN_UART3:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700307 silconfig->Hsuart3Enable = 0;
308 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700309 case LPSS_DEVFN_SPI0:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700310 silconfig->Spi0Enable = 0;
311 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700312 case LPSS_DEVFN_SPI1:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700313 silconfig->Spi1Enable = 0;
314 break;
Andrey Petrov78461a92016-06-28 12:14:33 -0700315 case LPSS_DEVFN_SPI2:
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700316 silconfig->Spi2Enable = 0;
317 break;
318 case SDCARD_DEVFN:
319 silconfig->SdcardEnabled = 0;
320 break;
321 case EMMC_DEVFN:
322 silconfig->eMMCEnabled = 0;
323 break;
324 case SDIO_DEVFN:
325 silconfig->SdioEnabled = 0;
326 break;
327 case SMBUS_DEVFN:
328 silconfig->SmbusEnable = 0;
329 break;
330 default:
331 printk(BIOS_WARNING, "PCI:%02x.%01x: Could not disable the device\n",
332 PCI_SLOT(dev->path.pci.devfn),
333 PCI_FUNC(dev->path.pci.devfn));
334 break;
335 }
336}
337
338static void parse_devicetree(struct FSP_S_CONFIG *silconfig)
339{
Andrey Petrov78461a92016-06-28 12:14:33 -0700340 struct device *dev = NB_DEV_ROOT;
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700341
342 if (!dev) {
343 printk(BIOS_ERR, "Could not find root device\n");
344 return;
345 }
346 /* Only disable bus 0 devices. */
347 for (dev = dev->bus->children; dev; dev = dev->sibling) {
348 if (!dev->enabled)
349 disable_dev(dev, silconfig);
350 }
351}
352
Andrey Petrov70efecd2016-03-04 21:41:13 -0800353void platform_fsp_silicon_init_params_cb(struct FSPS_UPD *silupd)
354{
355 struct FSP_S_CONFIG *silconfig = &silupd->FspsConfig;
356 static struct soc_intel_apollolake_config *cfg;
357
358 /* Load VBT before devicetree-specific config. */
Andrey Petrov868679f2016-05-12 19:11:48 -0700359 silconfig->GraphicsConfigPtr = (uintptr_t)vbt;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800360
Andrey Petrov78461a92016-06-28 12:14:33 -0700361 struct device *dev = NB_DEV_ROOT;
362
Patrick Georgi831d65d2016-04-14 11:53:48 +0200363 if (!dev || !dev->chip_info) {
Andrey Petrov70efecd2016-03-04 21:41:13 -0800364 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
365 return;
366 }
367
368 cfg = dev->chip_info;
369
Jagadish Krishnamoorthyb023e5e2016-06-22 18:32:17 -0700370 /* Parse device tree and disable unused device*/
371 parse_devicetree(silconfig);
372
Andrey Petrov70efecd2016-03-04 21:41:13 -0800373 silconfig->PcieRpClkReqNumber[0] = cfg->pcie_rp0_clkreq_pin;
374 silconfig->PcieRpClkReqNumber[1] = cfg->pcie_rp1_clkreq_pin;
375 silconfig->PcieRpClkReqNumber[2] = cfg->pcie_rp2_clkreq_pin;
376 silconfig->PcieRpClkReqNumber[3] = cfg->pcie_rp3_clkreq_pin;
377 silconfig->PcieRpClkReqNumber[4] = cfg->pcie_rp4_clkreq_pin;
378 silconfig->PcieRpClkReqNumber[5] = cfg->pcie_rp5_clkreq_pin;
Andrey Petrove07e13d2016-03-18 14:43:00 -0700379
Zhao, Lijian1b8ee0b2016-05-17 19:01:34 -0700380 if (cfg->emmc_tx_cmd_cntl != 0)
381 silconfig->EmmcTxCmdCntl = cfg->emmc_tx_cmd_cntl;
382 if (cfg->emmc_tx_data_cntl1 != 0)
383 silconfig->EmmcTxDataCntl1 = cfg->emmc_tx_data_cntl1;
384 if (cfg->emmc_tx_data_cntl2 != 0)
385 silconfig->EmmcTxDataCntl2 = cfg->emmc_tx_data_cntl2;
386 if (cfg->emmc_rx_cmd_data_cntl1 != 0)
387 silconfig->EmmcRxCmdDataCntl1 = cfg->emmc_rx_cmd_data_cntl1;
388 if (cfg->emmc_rx_strobe_cntl != 0)
389 silconfig->EmmcRxStrobeCntl = cfg->emmc_rx_strobe_cntl;
390 if (cfg->emmc_rx_cmd_data_cntl2 != 0)
391 silconfig->EmmcRxCmdDataCntl2 = cfg->emmc_rx_cmd_data_cntl2;
392
Saurabh Satijae46dbcc2016-05-03 15:15:31 -0700393 silconfig->LPSS_S0ixEnable = cfg->lpss_s0ix_enable;
394
Bora Guvendik60cc75d2016-07-25 14:44:51 -0700395 /* Disable monitor mwait since it is broken due to a hardware bug without a fix */
396 silconfig->MonitorMwaitEnable = 0;
397
Furquan Shaikhcad9b632016-06-20 16:08:42 -0700398 /* Disable setting of EISS bit in FSP. */
399 silconfig->SpiEiss = 0;
Andrey Petrov70efecd2016-03-04 21:41:13 -0800400}
401
402struct chip_operations soc_intel_apollolake_ops = {
403 CHIP_NAME("Intel Apollolake SOC")
404 .enable_dev = &enable_dev,
Andrey Petrov868679f2016-05-12 19:11:48 -0700405 .init = &soc_init,
406 .final = &soc_final
Andrey Petrov70efecd2016-03-04 21:41:13 -0800407};
408
Lee Leahy806fa242016-08-01 13:55:02 -0700409void platform_fsp_notify_status(enum fsp_notify_phase phase)
Andrey Petrov70efecd2016-03-04 21:41:13 -0800410{
Lee Leahy806fa242016-08-01 13:55:02 -0700411 /* Hide the P2SB device to align with previous behavior. */
412 if (phase == END_OF_FIRMWARE)
Aaron Durbinfadfc2e2016-07-01 16:36:03 -0500413 p2sb_hide();
Andrey Petrov70efecd2016-03-04 21:41:13 -0800414}
415
Furquan Shaikh6ac226d2016-06-15 17:13:20 -0700416/*
417 * spi_init() needs to run unconditionally on every boot (including resume) to
418 * allow write protect to be disabled for eventlog and nvram updates. This needs
419 * to be done as early as possible in ramstage. Thus, add a callback for entry
420 * into BS_PRE_DEVICE.
421 */
422static void spi_init_cb(void *unused)
423{
424 spi_init();
425}
426
427BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, spi_init_cb, NULL);