Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
| 5 | #include <fsp/api.h> |
| 6 | #include <fsp/util.h> |
| 7 | #include <intelblocks/acpi.h> |
| 8 | #include <intelblocks/cfg.h> |
MAULIK V VAGHELA | ed6f7e4 | 2022-02-22 19:59:42 +0530 | [diff] [blame] | 9 | #include <intelblocks/cse.h> |
Michael Niewöhner | 8913b78 | 2020-12-11 22:13:44 +0100 | [diff] [blame] | 10 | #include <intelblocks/gpio.h> |
Tim Wawrzynczak | 43607e4 | 2021-05-18 09:04:42 -0600 | [diff] [blame] | 11 | #include <intelblocks/irq.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 12 | #include <intelblocks/itss.h> |
| 13 | #include <intelblocks/pcie_rp.h> |
Arthur Heymans | 08769c6 | 2022-05-09 14:33:15 +0200 | [diff] [blame] | 14 | #include <intelblocks/systemagent.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 15 | #include <intelblocks/xdci.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 16 | #include <soc/intel/common/vbt.h> |
| 17 | #include <soc/itss.h> |
| 18 | #include <soc/pci_devs.h> |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 19 | #include <soc/pcie.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 20 | #include <soc/ramstage.h> |
| 21 | #include <soc/soc_chip.h> |
| 22 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 23 | #if CONFIG(HAVE_ACPI_TABLES) |
| 24 | const char *soc_acpi_name(const struct device *dev) |
| 25 | { |
| 26 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 27 | return "PCI0"; |
| 28 | |
| 29 | if (dev->path.type == DEVICE_PATH_USB) { |
| 30 | switch (dev->path.usb.port_type) { |
| 31 | case 0: |
| 32 | /* Root Hub */ |
| 33 | return "RHUB"; |
| 34 | case 2: |
| 35 | /* USB2 ports */ |
| 36 | switch (dev->path.usb.port_id) { |
| 37 | case 0: return "HS01"; |
| 38 | case 1: return "HS02"; |
| 39 | case 2: return "HS03"; |
| 40 | case 3: return "HS04"; |
| 41 | case 4: return "HS05"; |
| 42 | case 5: return "HS06"; |
| 43 | case 6: return "HS07"; |
| 44 | case 7: return "HS08"; |
| 45 | case 8: return "HS09"; |
| 46 | case 9: return "HS10"; |
Michał Żygowski | 3f205a4 | 2022-04-15 18:17:46 +0200 | [diff] [blame] | 47 | case 10: return "HS11"; |
| 48 | case 11: return "HS12"; |
| 49 | case 12: return "HS13"; |
| 50 | case 13: return "HS14"; |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 51 | } |
| 52 | break; |
| 53 | case 3: |
| 54 | /* USB3 ports */ |
| 55 | switch (dev->path.usb.port_id) { |
| 56 | case 0: return "SS01"; |
| 57 | case 1: return "SS02"; |
| 58 | case 2: return "SS03"; |
| 59 | case 3: return "SS04"; |
Michał Żygowski | 3f205a4 | 2022-04-15 18:17:46 +0200 | [diff] [blame] | 60 | case 4: return "SS05"; |
| 61 | case 5: return "SS06"; |
| 62 | case 6: return "SS07"; |
| 63 | case 7: return "SS08"; |
| 64 | case 8: return "SS09"; |
| 65 | case 9: return "SS10"; |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 66 | } |
| 67 | break; |
| 68 | } |
| 69 | return NULL; |
| 70 | } |
| 71 | if (dev->path.type != DEVICE_PATH_PCI) |
| 72 | return NULL; |
| 73 | |
| 74 | switch (dev->path.pci.devfn) { |
| 75 | case SA_DEVFN_ROOT: return "MCHC"; |
Michał Żygowski | 933a44b | 2022-04-15 18:15:44 +0200 | [diff] [blame] | 76 | #if CONFIG(SOC_INTEL_ALDERLAKE_PCH_S) |
| 77 | case SA_DEVFN_CPU_PCIE1_0: return "PEG1"; |
| 78 | case SA_DEVFN_CPU_PCIE1_1: return "PEG2"; |
| 79 | case SA_DEVFN_CPU_PCIE6_0: return "PEG0"; |
| 80 | #else |
Tim Wawrzynczak | cf39336 | 2021-12-16 15:01:44 -0700 | [diff] [blame] | 81 | case SA_DEVFN_CPU_PCIE1_0: return "PEG2"; |
| 82 | case SA_DEVFN_CPU_PCIE6_0: return "PEG0"; |
| 83 | case SA_DEVFN_CPU_PCIE6_2: return "PEG1"; |
Michał Żygowski | 933a44b | 2022-04-15 18:15:44 +0200 | [diff] [blame] | 84 | #endif |
Wisley Chen | cd80721 | 2021-08-31 18:27:13 +0600 | [diff] [blame] | 85 | case SA_DEVFN_IGD: return "GFX0"; |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 86 | case SA_DEVFN_TCSS_XHCI: return "TXHC"; |
| 87 | case SA_DEVFN_TCSS_XDCI: return "TXDC"; |
| 88 | case SA_DEVFN_TCSS_DMA0: return "TDM0"; |
| 89 | case SA_DEVFN_TCSS_DMA1: return "TDM1"; |
| 90 | case SA_DEVFN_TBT0: return "TRP0"; |
| 91 | case SA_DEVFN_TBT1: return "TRP1"; |
| 92 | case SA_DEVFN_TBT2: return "TRP2"; |
| 93 | case SA_DEVFN_TBT3: return "TRP3"; |
| 94 | case SA_DEVFN_IPU: return "IPU0"; |
Tarun Tuli | d8d5228 | 2022-05-03 20:34:32 +0000 | [diff] [blame] | 95 | case SA_DEVFN_DPTF: return "DPTF"; |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 96 | case PCH_DEVFN_ISH: return "ISHB"; |
| 97 | case PCH_DEVFN_XHCI: return "XHCI"; |
| 98 | case PCH_DEVFN_I2C0: return "I2C0"; |
| 99 | case PCH_DEVFN_I2C1: return "I2C1"; |
| 100 | case PCH_DEVFN_I2C2: return "I2C2"; |
| 101 | case PCH_DEVFN_I2C3: return "I2C3"; |
| 102 | case PCH_DEVFN_I2C4: return "I2C4"; |
| 103 | case PCH_DEVFN_I2C5: return "I2C5"; |
Varshit B Pandya | 339f0e7 | 2021-07-14 11:08:23 +0530 | [diff] [blame] | 104 | case PCH_DEVFN_I2C6: return "I2C6"; |
| 105 | case PCH_DEVFN_I2C7: return "I2C7"; |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 106 | case PCH_DEVFN_SATA: return "SATA"; |
| 107 | case PCH_DEVFN_PCIE1: return "RP01"; |
| 108 | case PCH_DEVFN_PCIE2: return "RP02"; |
| 109 | case PCH_DEVFN_PCIE3: return "RP03"; |
| 110 | case PCH_DEVFN_PCIE4: return "RP04"; |
| 111 | case PCH_DEVFN_PCIE5: return "RP05"; |
| 112 | case PCH_DEVFN_PCIE6: return "RP06"; |
| 113 | case PCH_DEVFN_PCIE7: return "RP07"; |
| 114 | case PCH_DEVFN_PCIE8: return "RP08"; |
| 115 | case PCH_DEVFN_PCIE9: return "RP09"; |
| 116 | case PCH_DEVFN_PCIE10: return "RP10"; |
| 117 | case PCH_DEVFN_PCIE11: return "RP11"; |
| 118 | case PCH_DEVFN_PCIE12: return "RP12"; |
Michał Żygowski | 933a44b | 2022-04-15 18:15:44 +0200 | [diff] [blame] | 119 | case PCH_DEVFN_PCIE13: return "RP13"; |
| 120 | case PCH_DEVFN_PCIE14: return "RP14"; |
| 121 | case PCH_DEVFN_PCIE15: return "RP15"; |
| 122 | case PCH_DEVFN_PCIE16: return "RP16"; |
| 123 | case PCH_DEVFN_PCIE17: return "RP17"; |
| 124 | case PCH_DEVFN_PCIE18: return "RP18"; |
| 125 | case PCH_DEVFN_PCIE19: return "RP19"; |
| 126 | case PCH_DEVFN_PCIE20: return "RP20"; |
| 127 | case PCH_DEVFN_PCIE21: return "RP21"; |
| 128 | case PCH_DEVFN_PCIE22: return "RP22"; |
| 129 | case PCH_DEVFN_PCIE23: return "RP23"; |
| 130 | case PCH_DEVFN_PCIE24: return "RP24"; |
| 131 | #if CONFIG(SOC_INTEL_ALDERLAKE_PCH_S) |
| 132 | /* Avoid conflicts with PCH-N eMMC */ |
| 133 | case PCH_DEVFN_PCIE25: return "RP25"; |
| 134 | case PCH_DEVFN_PCIE26: return "RP26"; |
| 135 | case PCH_DEVFN_PCIE27: return "RP27"; |
| 136 | case PCH_DEVFN_PCIE28: return "RP28"; |
| 137 | #endif |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 138 | case PCH_DEVFN_PMC: return "PMC"; |
| 139 | case PCH_DEVFN_UART0: return "UAR0"; |
| 140 | case PCH_DEVFN_UART1: return "UAR1"; |
| 141 | case PCH_DEVFN_UART2: return "UAR2"; |
| 142 | case PCH_DEVFN_GSPI0: return "SPI0"; |
| 143 | case PCH_DEVFN_GSPI1: return "SPI1"; |
| 144 | case PCH_DEVFN_GSPI2: return "SPI2"; |
| 145 | case PCH_DEVFN_GSPI3: return "SPI3"; |
| 146 | /* Keeping ACPI device name coherent with ec.asl */ |
| 147 | case PCH_DEVFN_ESPI: return "LPCB"; |
| 148 | case PCH_DEVFN_HDA: return "HDAS"; |
| 149 | case PCH_DEVFN_SMBUS: return "SBUS"; |
| 150 | case PCH_DEVFN_GBE: return "GLAN"; |
Tarun Tuli | d8d5228 | 2022-05-03 20:34:32 +0000 | [diff] [blame] | 151 | case PCH_DEVFN_SRAM: return "SRAM"; |
| 152 | case PCH_DEVFN_SPI: return "FSPI"; |
| 153 | case PCH_DEVFN_CSE: return "HEC1"; |
Krishna Prasad Bhat | a6d642f | 2022-01-16 23:16:24 +0530 | [diff] [blame] | 154 | #if CONFIG(SOC_INTEL_ALDERLAKE_PCH_N) |
| 155 | case PCH_DEVFN_EMMC: return "EMMC"; |
| 156 | #endif |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | return NULL; |
| 160 | } |
| 161 | #endif |
| 162 | |
| 163 | /* SoC routine to fill GPIO PM mask and value for GPIO_MISCCFG register */ |
| 164 | static void soc_fill_gpio_pm_configuration(void) |
| 165 | { |
| 166 | uint8_t value[TOTAL_GPIO_COMM]; |
| 167 | const config_t *config = config_of_soc(); |
| 168 | |
| 169 | if (config->gpio_override_pm) |
Angel Pons | 0c0d492 | 2021-04-05 13:02:45 +0200 | [diff] [blame] | 170 | memcpy(value, config->gpio_pm, sizeof(value)); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 171 | else |
Angel Pons | 0c0d492 | 2021-04-05 13:02:45 +0200 | [diff] [blame] | 172 | memset(value, MISCCFG_GPIO_PM_CONFIG_BITS, sizeof(value)); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 173 | |
| 174 | gpio_pm_configure(value, TOTAL_GPIO_COMM); |
| 175 | } |
| 176 | |
| 177 | void soc_init_pre_device(void *chip_info) |
| 178 | { |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 179 | /* Perform silicon specific init. */ |
Kyösti Mälkki | cc93c6e | 2021-01-09 22:53:52 +0200 | [diff] [blame] | 180 | fsp_silicon_init(); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 181 | |
| 182 | /* Display FIRMWARE_VERSION_INFO_HOB */ |
| 183 | fsp_display_fvi_version_hob(); |
| 184 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 185 | soc_fill_gpio_pm_configuration(); |
| 186 | |
| 187 | /* Swap enabled PCI ports in device tree if needed. */ |
Eric Lai | f8248f3 | 2020-12-31 11:43:29 +0800 | [diff] [blame] | 188 | pcie_rp_update_devicetree(get_pch_pcie_rp_table()); |
MAULIK V VAGHELA | 3e4f28f | 2022-01-21 14:17:53 +0530 | [diff] [blame] | 189 | |
| 190 | /* Swap enabled TBT root ports in device tree if needed. */ |
| 191 | pcie_rp_update_devicetree(get_tbt_pcie_rp_table()); |
MAULIK V VAGHELA | ed6f7e4 | 2022-02-22 19:59:42 +0530 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * Earlier when coreboot used to send EOP at late as possible caused |
| 195 | * issue of delayed response from CSE since CSE was busy loading payload. |
| 196 | * To resolve the issue, EOP should be sent earlier than current sequence |
| 197 | * in the boot sequence at BS_DEV_INIT. |
| 198 | * Intel CSE team recommends to send EOP close to FW init (between FSP-S exit and |
| 199 | * current boot sequence) to reduce message response time from CSE hence moving |
| 200 | * sending EOP to earlier stage. |
| 201 | */ |
| 202 | if (CONFIG(SOC_INTEL_CSE_SEND_EOP_EARLY)) { |
| 203 | printk(BIOS_INFO, "Sending EOP early from SoC\n"); |
| 204 | cse_send_end_of_post(); |
| 205 | } |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 206 | } |
| 207 | |
Tim Wawrzynczak | 43607e4 | 2021-05-18 09:04:42 -0600 | [diff] [blame] | 208 | static void cpu_fill_ssdt(const struct device *dev) |
| 209 | { |
| 210 | if (!generate_pin_irq_map()) |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 211 | printk(BIOS_ERR, "Failed to generate ACPI _PRT table!\n"); |
Tim Wawrzynczak | 43607e4 | 2021-05-18 09:04:42 -0600 | [diff] [blame] | 212 | |
| 213 | generate_cpu_entries(dev); |
| 214 | } |
| 215 | |
| 216 | static void cpu_set_north_irqs(struct device *dev) |
| 217 | { |
| 218 | irq_program_non_pch(); |
| 219 | } |
| 220 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 221 | static struct device_operations pci_domain_ops = { |
| 222 | .read_resources = &pci_domain_read_resources, |
| 223 | .set_resources = &pci_domain_set_resources, |
| 224 | .scan_bus = &pci_domain_scan_bus, |
| 225 | #if CONFIG(HAVE_ACPI_TABLES) |
| 226 | .acpi_name = &soc_acpi_name, |
Arthur Heymans | 08769c6 | 2022-05-09 14:33:15 +0200 | [diff] [blame] | 227 | .acpi_fill_ssdt = ssdt_set_above_4g_pci, |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 228 | #endif |
| 229 | }; |
| 230 | |
| 231 | static struct device_operations cpu_bus_ops = { |
| 232 | .read_resources = noop_read_resources, |
| 233 | .set_resources = noop_set_resources, |
Tim Wawrzynczak | 43607e4 | 2021-05-18 09:04:42 -0600 | [diff] [blame] | 234 | .enable_resources = cpu_set_north_irqs, |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 235 | #if CONFIG(HAVE_ACPI_TABLES) |
Tim Wawrzynczak | 43607e4 | 2021-05-18 09:04:42 -0600 | [diff] [blame] | 236 | .acpi_fill_ssdt = cpu_fill_ssdt, |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 237 | #endif |
| 238 | }; |
| 239 | |
| 240 | static void soc_enable(struct device *dev) |
| 241 | { |
| 242 | /* |
| 243 | * Set the operations if it is a special bus type or a hidden PCI |
| 244 | * device. |
| 245 | */ |
| 246 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 247 | dev->ops = &pci_domain_ops; |
| 248 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) |
| 249 | dev->ops = &cpu_bus_ops; |
| 250 | else if (dev->path.type == DEVICE_PATH_PCI && |
| 251 | dev->path.pci.devfn == PCH_DEVFN_PMC) |
| 252 | dev->ops = &pmc_ops; |
Michael Niewöhner | 8913b78 | 2020-12-11 22:13:44 +0100 | [diff] [blame] | 253 | else if (dev->path.type == DEVICE_PATH_GPIO) |
| 254 | block_gpio_enable(dev); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | struct chip_operations soc_intel_alderlake_ops = { |
| 258 | CHIP_NAME("Intel Alderlake") |
| 259 | .enable_dev = &soc_enable, |
| 260 | .init = &soc_init_pre_device, |
| 261 | }; |