Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 4 | * Copyright (C) 2015 - 2017 Intel Corp. |
Mario Scheithauer | a39aede | 2017-11-06 16:47:27 +0100 | [diff] [blame] | 5 | * Copyright (C) 2017 Siemens AG |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 6 | * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.) |
| 7 | * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.) |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
Martin Roth | ebabfad | 2016-04-10 11:09:16 -0600 | [diff] [blame] | 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 18 | */ |
| 19 | |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 20 | #include <arch/acpi.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 21 | #include <bootstate.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 22 | #include <cbmem.h> |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 23 | #include <compiler.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 24 | #include <console/console.h> |
| 25 | #include <cpu/cpu.h> |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 26 | #include <cpu/x86/mp.h> |
Barnali Sarkar | 66fe0c4 | 2017-05-23 18:17:14 +0530 | [diff] [blame] | 27 | #include <cpu/x86/msr.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 28 | #include <device/device.h> |
| 29 | #include <device/pci.h> |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 30 | #include <intelblocks/acpi.h> |
Subrata Banik | f699c14 | 2018-06-08 17:57:37 +0530 | [diff] [blame] | 31 | #include <intelblocks/chip.h> |
Barnali Sarkar | e70142c | 2017-03-28 16:32:33 +0530 | [diff] [blame] | 32 | #include <intelblocks/fast_spi.h> |
Barnali Sarkar | 66fe0c4 | 2017-05-23 18:17:14 +0530 | [diff] [blame] | 33 | #include <intelblocks/msr.h> |
Subrata Banik | f699c14 | 2018-06-08 17:57:37 +0530 | [diff] [blame] | 34 | #include <intelblocks/p2sb.h> |
Duncan Laurie | 4c8fbc0 | 2018-03-26 02:19:58 -0700 | [diff] [blame] | 35 | #include <intelblocks/xdci.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 36 | #include <fsp/api.h> |
| 37 | #include <fsp/util.h> |
Duncan Laurie | bf713b0 | 2018-05-07 15:33:18 -0700 | [diff] [blame] | 38 | #include <intelblocks/acpi.h> |
Barnali Sarkar | 66fe0c4 | 2017-05-23 18:17:14 +0530 | [diff] [blame] | 39 | #include <intelblocks/cpulib.h> |
Bora Guvendik | 33117ec | 2017-04-10 15:49:02 -0700 | [diff] [blame] | 40 | #include <intelblocks/itss.h> |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 41 | #include <intelblocks/pmclib.h> |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 42 | #include <romstage_handoff.h> |
Andrey Petrov | e07e13d | 2016-03-18 14:43:00 -0700 | [diff] [blame] | 43 | #include <soc/iomap.h> |
Bora Guvendik | 33117ec | 2017-04-10 15:49:02 -0700 | [diff] [blame] | 44 | #include <soc/itss.h> |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 45 | #include <soc/intel/common/vbt.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 46 | #include <soc/nvs.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 47 | #include <soc/pci_devs.h> |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 48 | #include <spi-generic.h> |
Aaron Durbin | ac3e482 | 2017-06-14 13:21:00 -0500 | [diff] [blame] | 49 | #include <soc/cpu.h> |
Andrey Petrov | 3dbea29 | 2016-06-14 22:20:28 -0700 | [diff] [blame] | 50 | #include <soc/pm.h> |
Subrata Banik | 7952e28 | 2017-03-14 18:26:27 +0530 | [diff] [blame] | 51 | #include <soc/systemagent.h> |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 52 | #include <timer.h> |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 53 | |
| 54 | #include "chip.h" |
| 55 | |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 56 | #define DUAL_ROLE_CFG0 0x80d8 |
| 57 | #define SW_VBUS_VALID_MASK (1 << 24) |
| 58 | #define SW_IDPIN_EN_MASK (1 << 21) |
| 59 | #define SW_IDPIN_MASK (1 << 20) |
| 60 | #define SW_IDPIN_HOST (0 << 20) |
| 61 | #define DUAL_ROLE_CFG1 0x80dc |
| 62 | #define DRD_MODE_MASK (1 << 29) |
| 63 | #define DRD_MODE_HOST (1 << 29) |
| 64 | |
Duncan Laurie | bf713b0 | 2018-05-07 15:33:18 -0700 | [diff] [blame] | 65 | const char *soc_acpi_name(const struct device *dev) |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 66 | { |
| 67 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 68 | return "PCI0"; |
| 69 | |
Duncan Laurie | bf713b0 | 2018-05-07 15:33:18 -0700 | [diff] [blame] | 70 | if (dev->path.type == DEVICE_PATH_USB) { |
| 71 | switch (dev->path.usb.port_type) { |
| 72 | case 0: |
| 73 | /* Root Hub */ |
| 74 | return "RHUB"; |
| 75 | case 2: |
| 76 | /* USB2 ports */ |
| 77 | switch (dev->path.usb.port_id) { |
| 78 | case 0: return "HS01"; |
| 79 | case 1: return "HS02"; |
| 80 | case 2: return "HS03"; |
| 81 | case 3: return "HS04"; |
| 82 | case 4: return "HS05"; |
| 83 | case 5: return "HS06"; |
| 84 | case 6: return "HS07"; |
| 85 | case 7: return "HS08"; |
| 86 | } |
| 87 | break; |
| 88 | case 3: |
| 89 | /* USB3 ports */ |
| 90 | switch (dev->path.usb.port_id) { |
| 91 | case 0: return "SS01"; |
| 92 | case 1: return "SS02"; |
| 93 | case 2: return "SS03"; |
| 94 | case 3: return "SS04"; |
| 95 | case 4: return "SS05"; |
| 96 | case 5: return "SS06"; |
| 97 | } |
| 98 | break; |
| 99 | } |
| 100 | return NULL; |
| 101 | } |
| 102 | |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 103 | if (dev->path.type != DEVICE_PATH_PCI) |
| 104 | return NULL; |
| 105 | |
| 106 | switch (dev->path.pci.devfn) { |
| 107 | /* DSDT: acpi/northbridge.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 108 | case SA_DEVFN_ROOT: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 109 | return "MCHC"; |
| 110 | /* DSDT: acpi/lpc.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 111 | case PCH_DEVFN_LPC: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 112 | return "LPCB"; |
| 113 | /* DSDT: acpi/xhci.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 114 | case PCH_DEVFN_XHCI: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 115 | return "XHCI"; |
| 116 | /* DSDT: acpi/pch_hda.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 117 | case PCH_DEVFN_HDA: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 118 | return "HDAS"; |
| 119 | /* DSDT: acpi/lpss.asl */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 120 | case PCH_DEVFN_UART0: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 121 | return "URT1"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 122 | case PCH_DEVFN_UART1: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 123 | return "URT2"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 124 | case PCH_DEVFN_UART2: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 125 | return "URT3"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 126 | case PCH_DEVFN_UART3: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 127 | return "URT4"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 128 | case PCH_DEVFN_SPI0: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 129 | return "SPI1"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 130 | case PCH_DEVFN_SPI1: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 131 | return "SPI2"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 132 | case PCH_DEVFN_SPI2: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 133 | return "SPI3"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 134 | case PCH_DEVFN_PWM: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 135 | return "PWM"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 136 | case PCH_DEVFN_I2C0: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 137 | return "I2C0"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 138 | case PCH_DEVFN_I2C1: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 139 | return "I2C1"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 140 | case PCH_DEVFN_I2C2: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 141 | return "I2C2"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 142 | case PCH_DEVFN_I2C3: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 143 | return "I2C3"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 144 | case PCH_DEVFN_I2C4: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 145 | return "I2C4"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 146 | case PCH_DEVFN_I2C5: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 147 | return "I2C5"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 148 | case PCH_DEVFN_I2C6: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 149 | return "I2C6"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 150 | case PCH_DEVFN_I2C7: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 151 | return "I2C7"; |
| 152 | /* Storage */ |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 153 | case PCH_DEVFN_SDCARD: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 154 | return "SDCD"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 155 | case PCH_DEVFN_EMMC: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 156 | return "EMMC"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 157 | case PCH_DEVFN_SDIO: |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 158 | return "SDIO"; |
Vaibhav Shankar | ec9168f | 2016-09-16 14:20:53 -0700 | [diff] [blame] | 159 | /* PCIe */ |
Venkateswarlu Vinjamuri | f03c63e | 2018-04-12 10:13:43 -0700 | [diff] [blame] | 160 | case PCH_DEVFN_PCIE1: |
| 161 | return "RP03"; |
Venkateswarlu Vinjamuri | efeb690 | 2018-04-09 11:14:42 -0700 | [diff] [blame] | 162 | case PCH_DEVFN_PCIE5: |
Vaibhav Shankar | ec9168f | 2016-09-16 14:20:53 -0700 | [diff] [blame] | 163 | return "RP01"; |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | return NULL; |
| 167 | } |
| 168 | |
Elyes HAOUAS | 06e8315 | 2018-05-24 22:48:14 +0200 | [diff] [blame] | 169 | static void pci_domain_set_resources(struct device *dev) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 170 | { |
Lee Leahy | 1d20fe7 | 2017-03-09 09:50:28 -0800 | [diff] [blame] | 171 | assign_resources(dev->link_list); |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static struct device_operations pci_domain_ops = { |
| 175 | .read_resources = pci_domain_read_resources, |
| 176 | .set_resources = pci_domain_set_resources, |
| 177 | .enable_resources = NULL, |
| 178 | .init = NULL, |
| 179 | .scan_bus = pci_domain_scan_bus, |
Duncan Laurie | 02fcc88 | 2016-06-27 10:51:17 -0700 | [diff] [blame] | 180 | .acpi_name = &soc_acpi_name, |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | static struct device_operations cpu_bus_ops = { |
| 184 | .read_resources = DEVICE_NOOP, |
| 185 | .set_resources = DEVICE_NOOP, |
| 186 | .enable_resources = DEVICE_NOOP, |
Aaron Durbin | ac3e482 | 2017-06-14 13:21:00 -0500 | [diff] [blame] | 187 | .init = apollolake_init_cpus, |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 188 | .scan_bus = NULL, |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 189 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 190 | }; |
| 191 | |
Elyes HAOUAS | 06e8315 | 2018-05-24 22:48:14 +0200 | [diff] [blame] | 192 | static void enable_dev(struct device *dev) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 193 | { |
| 194 | /* Set the operations if it is a special bus type */ |
Lee Leahy | 4430f9f | 2017-03-09 10:00:30 -0800 | [diff] [blame] | 195 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 196 | dev->ops = &pci_domain_ops; |
Lee Leahy | 4430f9f | 2017-03-09 10:00:30 -0800 | [diff] [blame] | 197 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 198 | dev->ops = &cpu_bus_ops; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 201 | /* |
| 202 | * If the PCIe root port at function 0 is disabled, |
| 203 | * the PCIe root ports might be coalesced after FSP silicon init. |
| 204 | * The below function will swap the devfn of the first enabled device |
| 205 | * in devicetree and function 0 resides a pci device |
| 206 | * so that it won't confuse coreboot. |
| 207 | */ |
| 208 | static void pcie_update_device_tree(unsigned int devfn0, int num_funcs) |
| 209 | { |
Elyes HAOUAS | 06e8315 | 2018-05-24 22:48:14 +0200 | [diff] [blame] | 210 | struct device *func0; |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 211 | unsigned int devfn; |
| 212 | int i; |
| 213 | unsigned int inc = PCI_DEVFN(0, 1); |
| 214 | |
| 215 | func0 = dev_find_slot(0, devfn0); |
| 216 | if (func0 == NULL) |
| 217 | return; |
| 218 | |
| 219 | /* No more functions if function 0 is disabled. */ |
| 220 | if (pci_read_config32(func0, PCI_VENDOR_ID) == 0xffffffff) |
| 221 | return; |
| 222 | |
| 223 | devfn = devfn0 + inc; |
| 224 | |
| 225 | /* |
| 226 | * Increase funtion by 1. |
| 227 | * Then find first enabled device to replace func0 |
| 228 | * as that port was move to func0. |
| 229 | */ |
| 230 | for (i = 1; i < num_funcs; i++, devfn += inc) { |
Elyes HAOUAS | 06e8315 | 2018-05-24 22:48:14 +0200 | [diff] [blame] | 231 | struct device *dev = dev_find_slot(0, devfn); |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 232 | if (dev == NULL) |
| 233 | continue; |
| 234 | |
| 235 | if (!dev->enabled) |
| 236 | continue; |
| 237 | /* Found the first enabled device in given dev number */ |
| 238 | func0->path.pci.devfn = dev->path.pci.devfn; |
| 239 | dev->path.pci.devfn = devfn0; |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | static void pcie_override_devicetree_after_silicon_init(void) |
| 245 | { |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 246 | pcie_update_device_tree(PCH_DEVFN_PCIE1, 4); |
| 247 | pcie_update_device_tree(PCH_DEVFN_PCIE5, 2); |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 248 | } |
| 249 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 250 | /* Configure package power limits */ |
| 251 | static void set_power_limits(void) |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 252 | { |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 253 | static struct soc_intel_apollolake_config *cfg; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 254 | struct device *dev = SA_DEV_ROOT; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 255 | msr_t rapl_msr_reg, limit; |
| 256 | uint32_t power_unit; |
| 257 | uint32_t tdp, min_power, max_power; |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 258 | uint32_t pl2_val; |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 259 | |
Mario Scheithauer | 38b6100 | 2017-07-25 10:52:41 +0200 | [diff] [blame] | 260 | if (IS_ENABLED(CONFIG_APL_SKIP_SET_POWER_LIMITS)) { |
| 261 | printk(BIOS_INFO, "Skip the RAPL settings.\n"); |
| 262 | return; |
| 263 | } |
| 264 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 265 | if (!dev || !dev->chip_info) { |
| 266 | printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n"); |
| 267 | return; |
| 268 | } |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 269 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 270 | cfg = dev->chip_info; |
| 271 | |
| 272 | /* Get units */ |
| 273 | rapl_msr_reg = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 274 | power_unit = 1 << (rapl_msr_reg.lo & 0xf); |
| 275 | |
| 276 | /* Get power defaults for this SKU */ |
| 277 | rapl_msr_reg = rdmsr(MSR_PKG_POWER_SKU); |
| 278 | tdp = rapl_msr_reg.lo & PKG_POWER_LIMIT_MASK; |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 279 | pl2_val = rapl_msr_reg.hi & PKG_POWER_LIMIT_MASK; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 280 | min_power = (rapl_msr_reg.lo >> 16) & PKG_POWER_LIMIT_MASK; |
| 281 | max_power = rapl_msr_reg.hi & PKG_POWER_LIMIT_MASK; |
| 282 | |
| 283 | if (min_power > 0 && tdp < min_power) |
| 284 | tdp = min_power; |
| 285 | |
| 286 | if (max_power > 0 && tdp > max_power) |
| 287 | tdp = max_power; |
| 288 | |
| 289 | /* Set PL1 override value */ |
| 290 | tdp = (cfg->tdp_pl1_override_mw == 0) ? |
| 291 | tdp : (cfg->tdp_pl1_override_mw * power_unit) / 1000; |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 292 | /* Set PL2 override value */ |
| 293 | pl2_val = (cfg->tdp_pl2_override_mw == 0) ? |
| 294 | pl2_val : (cfg->tdp_pl2_override_mw * power_unit) / 1000; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 295 | |
| 296 | /* Set long term power limit to TDP */ |
| 297 | limit.lo = tdp & PKG_POWER_LIMIT_MASK; |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 298 | /* Set PL1 Pkg Power clamp bit */ |
| 299 | limit.lo |= PKG_POWER_LIMIT_CLAMP; |
| 300 | |
| 301 | limit.lo |= PKG_POWER_LIMIT_EN; |
| 302 | limit.lo |= (MB_POWER_LIMIT1_TIME_DEFAULT & |
| 303 | PKG_POWER_LIMIT_TIME_MASK) << PKG_POWER_LIMIT_TIME_SHIFT; |
| 304 | |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 305 | /* Set short term power limit PL2 */ |
| 306 | limit.hi = pl2_val & PKG_POWER_LIMIT_MASK; |
| 307 | limit.hi |= PKG_POWER_LIMIT_EN; |
| 308 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 309 | /* Program package power limits in RAPL MSR */ |
| 310 | wrmsr(MSR_PKG_POWER_LIMIT, limit); |
| 311 | printk(BIOS_INFO, "RAPL PL1 %d.%dW\n", tdp / power_unit, |
| 312 | 100 * (tdp % power_unit) / power_unit); |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 313 | printk(BIOS_INFO, "RAPL PL2 %d.%dW\n", pl2_val / power_unit, |
| 314 | 100 * (pl2_val % power_unit) / power_unit); |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 315 | |
Sumeet Pawnikar | 428f90a | 2016-12-02 18:14:19 +0530 | [diff] [blame] | 316 | /* Setting RAPL MMIO register for Power limits. |
| 317 | * RAPL driver is using MSR instead of MMIO. |
| 318 | * So, disabled LIMIT_EN bit for MMIO. */ |
Subrata Banik | 208587e | 2017-05-19 18:38:24 +0530 | [diff] [blame] | 319 | MCHBAR32(MCHBAR_RAPL_PPL) = limit.lo & ~PKG_POWER_LIMIT_EN; |
| 320 | MCHBAR32(MCHBAR_RAPL_PPL + 4) = limit.hi & ~PKG_POWER_LIMIT_EN; |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 321 | } |
| 322 | |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 323 | /* Overwrites the SCI IRQ if another IRQ number is given by device tree. */ |
| 324 | static void set_sci_irq(void) |
| 325 | { |
| 326 | static struct soc_intel_apollolake_config *cfg; |
| 327 | struct device *dev = SA_DEV_ROOT; |
| 328 | uint32_t scis; |
| 329 | |
| 330 | if (!dev || !dev->chip_info) { |
| 331 | printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n"); |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | cfg = dev->chip_info; |
| 336 | |
| 337 | /* Change only if a device tree entry exists. */ |
| 338 | if (cfg->sci_irq) { |
| 339 | scis = soc_read_sci_irq_select(); |
| 340 | scis &= ~SCI_IRQ_SEL; |
| 341 | scis |= (cfg->sci_irq << SCI_IRQ_ADJUST) & SCI_IRQ_SEL; |
| 342 | soc_write_sci_irq_select(scis); |
| 343 | } |
| 344 | } |
| 345 | |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 346 | static void soc_init(void *data) |
| 347 | { |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 348 | struct global_nvs_t *gnvs; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 349 | |
Aaron Durbin | 81d1e09 | 2016-07-13 01:49:10 -0500 | [diff] [blame] | 350 | /* Snapshot the current GPIO IRQ polarities. FSP is setting a |
| 351 | * default policy that doesn't honor boards' requirements. */ |
| 352 | itss_snapshot_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END); |
| 353 | |
Aaron Durbin | 6c191d8 | 2016-11-29 21:22:42 -0600 | [diff] [blame] | 354 | fsp_silicon_init(romstage_handoff_is_resume()); |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 355 | |
Aaron Durbin | 81d1e09 | 2016-07-13 01:49:10 -0500 | [diff] [blame] | 356 | /* Restore GPIO IRQ polarities back to previous settings. */ |
| 357 | itss_restore_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END); |
| 358 | |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 359 | /* override 'enabled' setting in device tree if needed */ |
| 360 | pcie_override_devicetree_after_silicon_init(); |
| 361 | |
Aaron Durbin | fadfc2e | 2016-07-01 16:36:03 -0500 | [diff] [blame] | 362 | /* |
| 363 | * Keep the P2SB device visible so it and the other devices are |
| 364 | * visible in coreboot for driver support and PCI resource allocation. |
| 365 | * There is a UPD setting for this, but it's more consistent to use |
| 366 | * hide and unhide symmetrically. |
| 367 | */ |
| 368 | p2sb_unhide(); |
| 369 | |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 370 | /* Allocate ACPI NVS in CBMEM */ |
| 371 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs)); |
Sumeet Pawnikar | 35240eb | 2016-08-23 11:20:20 +0530 | [diff] [blame] | 372 | |
Sumeet Pawnikar | a247d8e | 2016-09-27 23:18:35 +0530 | [diff] [blame] | 373 | /* Set RAPL MSR for Package power limits*/ |
| 374 | set_power_limits(); |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 375 | |
| 376 | /* |
| 377 | * FSP-S routes SCI to IRQ 9. With the help of this function you can |
| 378 | * select another IRQ for SCI. |
| 379 | */ |
| 380 | set_sci_irq(); |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 383 | static void soc_final(void *data) |
| 384 | { |
Andrey Petrov | 3dbea29 | 2016-06-14 22:20:28 -0700 | [diff] [blame] | 385 | /* Disable global reset, just in case */ |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 386 | pmc_global_reset_enable(0); |
Andrey Petrov | 3dbea29 | 2016-06-14 22:20:28 -0700 | [diff] [blame] | 387 | /* Make sure payload/OS can't trigger global reset */ |
Shaunak Saha | 93cdc8b | 2017-04-18 15:42:09 -0700 | [diff] [blame] | 388 | pmc_global_reset_lock(); |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Lee Leahy | bab8be2 | 2017-03-09 09:53:58 -0800 | [diff] [blame] | 391 | static void disable_dev(struct device *dev, FSP_S_CONFIG *silconfig) |
| 392 | { |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 393 | switch (dev->path.pci.devfn) { |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 394 | case PCH_DEVFN_ISH: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 395 | silconfig->IshEnable = 0; |
| 396 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 397 | case PCH_DEVFN_SATA: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 398 | silconfig->EnableSata = 0; |
| 399 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 400 | case PCH_DEVFN_PCIE5: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 401 | silconfig->PcieRootPortEn[0] = 0; |
| 402 | silconfig->PcieRpHotPlug[0] = 0; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 403 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 404 | case PCH_DEVFN_PCIE6: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 405 | silconfig->PcieRootPortEn[1] = 0; |
| 406 | silconfig->PcieRpHotPlug[1] = 0; |
| 407 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 408 | case PCH_DEVFN_PCIE1: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 409 | silconfig->PcieRootPortEn[2] = 0; |
| 410 | silconfig->PcieRpHotPlug[2] = 0; |
| 411 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 412 | case PCH_DEVFN_PCIE2: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 413 | silconfig->PcieRootPortEn[3] = 0; |
| 414 | silconfig->PcieRpHotPlug[3] = 0; |
| 415 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 416 | case PCH_DEVFN_PCIE3: |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 417 | silconfig->PcieRootPortEn[4] = 0; |
| 418 | silconfig->PcieRpHotPlug[4] = 0; |
| 419 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 420 | case PCH_DEVFN_PCIE4: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 421 | silconfig->PcieRootPortEn[5] = 0; |
Kane Chen | d779605 | 2016-07-11 12:17:13 +0800 | [diff] [blame] | 422 | silconfig->PcieRpHotPlug[5] = 0; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 423 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 424 | case PCH_DEVFN_XHCI: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 425 | silconfig->Usb30Mode = 0; |
| 426 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 427 | case PCH_DEVFN_XDCI: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 428 | silconfig->UsbOtg = 0; |
| 429 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 430 | case PCH_DEVFN_I2C0: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 431 | silconfig->I2c0Enable = 0; |
| 432 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 433 | case PCH_DEVFN_I2C1: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 434 | silconfig->I2c1Enable = 0; |
| 435 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 436 | case PCH_DEVFN_I2C2: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 437 | silconfig->I2c2Enable = 0; |
| 438 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 439 | case PCH_DEVFN_I2C3: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 440 | silconfig->I2c3Enable = 0; |
| 441 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 442 | case PCH_DEVFN_I2C4: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 443 | silconfig->I2c4Enable = 0; |
| 444 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 445 | case PCH_DEVFN_I2C5: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 446 | silconfig->I2c5Enable = 0; |
| 447 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 448 | case PCH_DEVFN_I2C6: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 449 | silconfig->I2c6Enable = 0; |
| 450 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 451 | case PCH_DEVFN_I2C7: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 452 | silconfig->I2c7Enable = 0; |
| 453 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 454 | case PCH_DEVFN_UART0: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 455 | silconfig->Hsuart0Enable = 0; |
| 456 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 457 | case PCH_DEVFN_UART1: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 458 | silconfig->Hsuart1Enable = 0; |
| 459 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 460 | case PCH_DEVFN_UART2: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 461 | silconfig->Hsuart2Enable = 0; |
| 462 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 463 | case PCH_DEVFN_UART3: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 464 | silconfig->Hsuart3Enable = 0; |
| 465 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 466 | case PCH_DEVFN_SPI0: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 467 | silconfig->Spi0Enable = 0; |
| 468 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 469 | case PCH_DEVFN_SPI1: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 470 | silconfig->Spi1Enable = 0; |
| 471 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 472 | case PCH_DEVFN_SPI2: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 473 | silconfig->Spi2Enable = 0; |
| 474 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 475 | case PCH_DEVFN_SDCARD: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 476 | silconfig->SdcardEnabled = 0; |
| 477 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 478 | case PCH_DEVFN_EMMC: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 479 | silconfig->eMMCEnabled = 0; |
| 480 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 481 | case PCH_DEVFN_SDIO: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 482 | silconfig->SdioEnabled = 0; |
| 483 | break; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 484 | case PCH_DEVFN_SMBUS: |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 485 | silconfig->SmbusEnable = 0; |
| 486 | break; |
| 487 | default: |
| 488 | printk(BIOS_WARNING, "PCI:%02x.%01x: Could not disable the device\n", |
| 489 | PCI_SLOT(dev->path.pci.devfn), |
| 490 | PCI_FUNC(dev->path.pci.devfn)); |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 495 | static void parse_devicetree(FSP_S_CONFIG *silconfig) |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 496 | { |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 497 | struct device *dev = SA_DEV_ROOT; |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 498 | |
| 499 | if (!dev) { |
| 500 | printk(BIOS_ERR, "Could not find root device\n"); |
| 501 | return; |
| 502 | } |
| 503 | /* Only disable bus 0 devices. */ |
| 504 | for (dev = dev->bus->children; dev; dev = dev->sibling) { |
| 505 | if (!dev->enabled) |
| 506 | disable_dev(dev, silconfig); |
| 507 | } |
| 508 | } |
| 509 | |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 510 | static void apl_fsp_silicon_init_params_cb(struct soc_intel_apollolake_config |
| 511 | *cfg, FSP_S_CONFIG *silconfig) |
| 512 | { |
| 513 | #if !IS_ENABLED(CONFIG_SOC_INTEL_GLK) /* GLK FSP does not have these |
| 514 | fields in FspsUpd.h yet */ |
| 515 | uint8_t port; |
| 516 | |
| 517 | for (port = 0; port < APOLLOLAKE_USB2_PORT_MAX; port++) { |
| 518 | if (cfg->usb2eye[port].Usb20PerPortTxPeHalf != 0) |
| 519 | silconfig->PortUsb20PerPortTxPeHalf[port] = |
| 520 | cfg->usb2eye[port].Usb20PerPortTxPeHalf; |
| 521 | |
| 522 | if (cfg->usb2eye[port].Usb20PerPortPeTxiSet != 0) |
| 523 | silconfig->PortUsb20PerPortPeTxiSet[port] = |
| 524 | cfg->usb2eye[port].Usb20PerPortPeTxiSet; |
| 525 | |
| 526 | if (cfg->usb2eye[port].Usb20PerPortTxiSet != 0) |
| 527 | silconfig->PortUsb20PerPortTxiSet[port] = |
| 528 | cfg->usb2eye[port].Usb20PerPortTxiSet; |
| 529 | |
| 530 | if (cfg->usb2eye[port].Usb20HsSkewSel != 0) |
| 531 | silconfig->PortUsb20HsSkewSel[port] = |
| 532 | cfg->usb2eye[port].Usb20HsSkewSel; |
| 533 | |
| 534 | if (cfg->usb2eye[port].Usb20IUsbTxEmphasisEn != 0) |
| 535 | silconfig->PortUsb20IUsbTxEmphasisEn[port] = |
| 536 | cfg->usb2eye[port].Usb20IUsbTxEmphasisEn; |
| 537 | |
| 538 | if (cfg->usb2eye[port].Usb20PerPortRXISet != 0) |
| 539 | silconfig->PortUsb20PerPortRXISet[port] = |
| 540 | cfg->usb2eye[port].Usb20PerPortRXISet; |
| 541 | |
| 542 | if (cfg->usb2eye[port].Usb20HsNpreDrvSel != 0) |
| 543 | silconfig->PortUsb20HsNpreDrvSel[port] = |
| 544 | cfg->usb2eye[port].Usb20HsNpreDrvSel; |
| 545 | } |
| 546 | #endif |
| 547 | } |
| 548 | |
| 549 | static void glk_fsp_silicon_init_params_cb( |
| 550 | struct soc_intel_apollolake_config *cfg, FSP_S_CONFIG *silconfig) |
| 551 | { |
Srinidhi N Kaushik | 5af546c | 2018-05-14 23:33:55 -0700 | [diff] [blame] | 552 | #if IS_ENABLED(CONFIG_SOC_INTEL_GLK) |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 553 | silconfig->Gmm = 0; |
Shamile Khan | c4276a3 | 2018-03-14 18:09:19 -0700 | [diff] [blame] | 554 | |
| 555 | /* On Geminilake, we need to override the default FSP PCIe de-emphasis |
| 556 | * settings using the device tree settings. This is because PCIe |
| 557 | * de-emphasis is enabled by default and Thunderpeak PCIe WiFi detection |
| 558 | * requires de-emphasis disabled. If we make this change common to both |
| 559 | * Apollolake and Geminilake, then we need to add mainboard device tree |
| 560 | * de-emphasis settings of 1 to Apollolake systems. |
| 561 | */ |
| 562 | memcpy(silconfig->PcieRpSelectableDeemphasis, |
| 563 | cfg->pcie_rp_deemphasis_enable, |
| 564 | sizeof(silconfig->PcieRpSelectableDeemphasis)); |
Srinidhi N Kaushik | 5af546c | 2018-05-14 23:33:55 -0700 | [diff] [blame] | 565 | /* |
| 566 | * FSP does not know what the clock requirements are for the |
| 567 | * device on SPI bus, hence it should not modify what coreboot |
| 568 | * has set up. Hence skipping in FSP. |
| 569 | */ |
| 570 | silconfig->SkipSpiPCP = 1; |
| 571 | #endif |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 574 | void __weak mainboard_devtree_update(struct device *dev) |
Kane Chen | 5bddcc4 | 2017-08-22 11:37:18 +0800 | [diff] [blame] | 575 | { |
| 576 | /* Override dev tree settings per board */ |
| 577 | } |
| 578 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 579 | void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 580 | { |
Lee Leahy | 1d20fe7 | 2017-03-09 09:50:28 -0800 | [diff] [blame] | 581 | FSP_S_CONFIG *silconfig = &silupd->FspsConfig; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 582 | static struct soc_intel_apollolake_config *cfg; |
| 583 | |
| 584 | /* Load VBT before devicetree-specific config. */ |
Patrick Georgi | 2257959 | 2017-10-06 17:36:09 +0200 | [diff] [blame] | 585 | silconfig->GraphicsConfigPtr = (uintptr_t)vbt_get(); |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 586 | |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 587 | struct device *dev = SA_DEV_ROOT; |
Andrey Petrov | 78461a9 | 2016-06-28 12:14:33 -0700 | [diff] [blame] | 588 | |
Patrick Georgi | 831d65d | 2016-04-14 11:53:48 +0200 | [diff] [blame] | 589 | if (!dev || !dev->chip_info) { |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 590 | printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n"); |
| 591 | return; |
| 592 | } |
| 593 | |
Kane Chen | 5bddcc4 | 2017-08-22 11:37:18 +0800 | [diff] [blame] | 594 | mainboard_devtree_update(dev); |
| 595 | |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 596 | cfg = dev->chip_info; |
| 597 | |
Jagadish Krishnamoorthy | b023e5e | 2016-06-22 18:32:17 -0700 | [diff] [blame] | 598 | /* Parse device tree and disable unused device*/ |
| 599 | parse_devicetree(silconfig); |
| 600 | |
Furquan Shaikh | 6d5e10c | 2018-03-14 19:57:16 -0700 | [diff] [blame] | 601 | memcpy(silconfig->PcieRpClkReqNumber, cfg->pcie_rp_clkreq_pin, |
| 602 | sizeof(silconfig->PcieRpClkReqNumber)); |
Andrey Petrov | e07e13d | 2016-03-18 14:43:00 -0700 | [diff] [blame] | 603 | |
Furquan Shaikh | 2cfc862 | 2018-03-14 21:43:04 -0700 | [diff] [blame] | 604 | memcpy(silconfig->PcieRpHotPlug, cfg->pcie_rp_hotplug_enable, |
| 605 | sizeof(silconfig->PcieRpHotPlug)); |
| 606 | |
Zhao, Lijian | 1b8ee0b | 2016-05-17 19:01:34 -0700 | [diff] [blame] | 607 | if (cfg->emmc_tx_cmd_cntl != 0) |
| 608 | silconfig->EmmcTxCmdCntl = cfg->emmc_tx_cmd_cntl; |
| 609 | if (cfg->emmc_tx_data_cntl1 != 0) |
| 610 | silconfig->EmmcTxDataCntl1 = cfg->emmc_tx_data_cntl1; |
| 611 | if (cfg->emmc_tx_data_cntl2 != 0) |
| 612 | silconfig->EmmcTxDataCntl2 = cfg->emmc_tx_data_cntl2; |
| 613 | if (cfg->emmc_rx_cmd_data_cntl1 != 0) |
| 614 | silconfig->EmmcRxCmdDataCntl1 = cfg->emmc_rx_cmd_data_cntl1; |
| 615 | if (cfg->emmc_rx_strobe_cntl != 0) |
| 616 | silconfig->EmmcRxStrobeCntl = cfg->emmc_rx_strobe_cntl; |
| 617 | if (cfg->emmc_rx_cmd_data_cntl2 != 0) |
| 618 | silconfig->EmmcRxCmdDataCntl2 = cfg->emmc_rx_cmd_data_cntl2; |
| 619 | |
Saurabh Satija | e46dbcc | 2016-05-03 15:15:31 -0700 | [diff] [blame] | 620 | silconfig->LPSS_S0ixEnable = cfg->lpss_s0ix_enable; |
| 621 | |
Lee Leahy | 07441b5 | 2017-03-09 10:59:25 -0800 | [diff] [blame] | 622 | /* Disable monitor mwait since it is broken due to a hardware bug |
Cole Nelson | f357c25 | 2017-05-16 11:38:59 -0700 | [diff] [blame] | 623 | * without a fix. Specific to Apollolake. |
Lee Leahy | 07441b5 | 2017-03-09 10:59:25 -0800 | [diff] [blame] | 624 | */ |
Cole Nelson | f357c25 | 2017-05-16 11:38:59 -0700 | [diff] [blame] | 625 | if (!IS_ENABLED(CONFIG_SOC_INTEL_GLK)) |
| 626 | silconfig->MonitorMwaitEnable = 0; |
Bora Guvendik | 60cc75d | 2016-07-25 14:44:51 -0700 | [diff] [blame] | 627 | |
Subrata Banik | f699c14 | 2018-06-08 17:57:37 +0530 | [diff] [blame] | 628 | silconfig->SkipMpInit = !chip_get_fsp_mp_init(); |
Venkateswarlu Vinjamuri | 1a5e32c | 2016-10-31 17:15:30 -0700 | [diff] [blame] | 629 | |
Furquan Shaikh | cad9b63 | 2016-06-20 16:08:42 -0700 | [diff] [blame] | 630 | /* Disable setting of EISS bit in FSP. */ |
| 631 | silconfig->SpiEiss = 0; |
Ravi Sarawadi | 3a21d0f | 2016-08-10 11:33:56 -0700 | [diff] [blame] | 632 | |
| 633 | /* Disable FSP from locking access to the RTC NVRAM */ |
| 634 | silconfig->RtcLock = 0; |
Venkateswarlu Vinjamuri | 88df48c | 2016-09-02 16:04:27 -0700 | [diff] [blame] | 635 | |
| 636 | /* Enable Audio clk gate and power gate */ |
| 637 | silconfig->HDAudioClkGate = cfg->hdaudio_clk_gate_enable; |
| 638 | silconfig->HDAudioPwrGate = cfg->hdaudio_pwr_gate_enable; |
| 639 | /* Bios config lockdown Audio clk and power gate */ |
| 640 | silconfig->BiosCfgLockDown = cfg->hdaudio_bios_config_lockdown; |
Hannah Williams | 3ff14a0 | 2017-05-05 16:30:22 -0700 | [diff] [blame] | 641 | if (IS_ENABLED(CONFIG_SOC_INTEL_GLK)) |
| 642 | glk_fsp_silicon_init_params_cb(cfg, silconfig); |
| 643 | else |
| 644 | apl_fsp_silicon_init_params_cb(cfg, silconfig); |
Duncan Laurie | 4c8fbc0 | 2018-03-26 02:19:58 -0700 | [diff] [blame] | 645 | |
| 646 | /* Enable xDCI controller if enabled in devicetree and allowed */ |
| 647 | dev = dev_find_slot(0, PCH_DEVFN_XDCI); |
| 648 | if (!xdci_can_enable()) |
| 649 | dev->enabled = 0; |
| 650 | silconfig->UsbOtg = dev->enabled; |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | struct chip_operations soc_intel_apollolake_ops = { |
| 654 | CHIP_NAME("Intel Apollolake SOC") |
| 655 | .enable_dev = &enable_dev, |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 656 | .init = &soc_init, |
| 657 | .final = &soc_final |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 658 | }; |
| 659 | |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 660 | static void drop_privilege_all(void) |
| 661 | { |
| 662 | /* Drop privilege level on all the CPUs */ |
Subrata Banik | 3337497 | 2018-04-24 13:45:30 +0530 | [diff] [blame] | 663 | if (mp_run_on_all_cpus(&cpu_enable_untrusted_mode, NULL, 1000) < 0) |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 664 | printk(BIOS_ERR, "failed to enable untrusted mode\n"); |
| 665 | } |
| 666 | |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 667 | static void configure_xhci_host_mode_port0(void) |
| 668 | { |
| 669 | uint32_t *cfg0; |
| 670 | uint32_t *cfg1; |
| 671 | const struct resource *res; |
| 672 | uint32_t reg; |
| 673 | struct stopwatch sw; |
| 674 | struct device *xhci_dev = PCH_DEV_XHCI; |
| 675 | |
| 676 | printk(BIOS_INFO, "Putting xHCI port 0 into host mode.\n"); |
| 677 | res = find_resource(xhci_dev, PCI_BASE_ADDRESS_0); |
| 678 | cfg0 = (void *)(uintptr_t)(res->base + DUAL_ROLE_CFG0); |
| 679 | cfg1 = (void *)(uintptr_t)(res->base + DUAL_ROLE_CFG1); |
| 680 | reg = read32(cfg0); |
John Zhao | db2f91b | 2018-08-21 15:02:54 -0700 | [diff] [blame] | 681 | if (!(reg & SW_IDPIN_EN_MASK)) |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 682 | return; |
| 683 | |
| 684 | reg &= ~(SW_IDPIN_MASK | SW_VBUS_VALID_MASK); |
| 685 | write32(cfg0, reg); |
| 686 | |
| 687 | stopwatch_init_msecs_expire(&sw, 10); |
| 688 | /* Wait for the host mode status bit. */ |
| 689 | while ((read32(cfg1) & DRD_MODE_MASK) != DRD_MODE_HOST) { |
| 690 | if (stopwatch_expired(&sw)) { |
| 691 | printk(BIOS_ERR, "Timed out waiting for host mode.\n"); |
| 692 | return; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | printk(BIOS_INFO, "xHCI port 0 host switch over took %lu ms\n", |
| 697 | stopwatch_duration_msecs(&sw)); |
| 698 | } |
| 699 | |
| 700 | static int check_xdci_enable(void) |
| 701 | { |
| 702 | struct device *dev = PCH_DEV_XDCI; |
| 703 | |
| 704 | return !!dev->enabled; |
| 705 | } |
| 706 | |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 707 | void platform_fsp_notify_status(enum fsp_notify_phase phase) |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 708 | { |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 709 | if (phase == END_OF_FIRMWARE) { |
| 710 | /* Hide the P2SB device to align with previous behavior. */ |
Aaron Durbin | fadfc2e | 2016-07-01 16:36:03 -0500 | [diff] [blame] | 711 | p2sb_hide(); |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 712 | /* |
| 713 | * As per guidelines BIOS is recommended to drop CPU privilege |
| 714 | * level to IA_UNTRUSTED. After that certain device registers |
| 715 | * and MSRs become inaccessible supposedly increasing system |
| 716 | * security. |
| 717 | */ |
| 718 | drop_privilege_all(); |
John Zhao | 7dff726 | 2018-07-30 13:54:25 -0700 | [diff] [blame] | 719 | |
| 720 | /* |
| 721 | * When USB OTG is set, GLK FSP enables xHCI SW ID pin and |
| 722 | * configures USB-C as device mode. Force USB-C into host mode. |
| 723 | */ |
| 724 | if (check_xdci_enable()) |
| 725 | configure_xhci_host_mode_port0(); |
Andrey Petrov | a697c19 | 2016-12-07 10:47:46 -0800 | [diff] [blame] | 726 | } |
Andrey Petrov | 70efecd | 2016-03-04 21:41:13 -0800 | [diff] [blame] | 727 | } |
| 728 | |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 729 | /* |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 730 | * spi_flash init() needs to run unconditionally on every boot (including |
| 731 | * resume) to allow write protect to be disabled for eventlog and nvram |
| 732 | * updates. This needs to be done as early as possible in ramstage. Thus, add a |
| 733 | * callback for entry into BS_PRE_DEVICE. |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 734 | */ |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 735 | static void spi_flash_init_cb(void *unused) |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 736 | { |
Barnali Sarkar | e70142c | 2017-03-28 16:32:33 +0530 | [diff] [blame] | 737 | fast_spi_init(); |
Furquan Shaikh | 6ac226d | 2016-06-15 17:13:20 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Furquan Shaikh | d6c5559 | 2016-11-21 12:41:20 -0800 | [diff] [blame] | 740 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, spi_flash_init_cb, NULL); |