blob: 45fb39f9318680f884737525f57e4307cbea51b7 [file] [log] [blame]
Subrata Banik2871e0e2020-09-27 11:30:58 +05301/* 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>
Dinesh Gehlotd910fec2022-12-25 13:00:04 +00007#include <gpio.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +05308#include <intelblocks/acpi.h>
9#include <intelblocks/cfg.h>
MAULIK V VAGHELAed6f7e42022-02-22 19:59:42 +053010#include <intelblocks/cse.h>
Tim Wawrzynczak43607e42021-05-18 09:04:42 -060011#include <intelblocks/irq.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053012#include <intelblocks/itss.h>
13#include <intelblocks/pcie_rp.h>
Arthur Heymans08769c62022-05-09 14:33:15 +020014#include <intelblocks/systemagent.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053015#include <intelblocks/xdci.h>
Michał Żygowski9b0f1692022-05-05 13:21:01 +020016#include <soc/hsphy.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053017#include <soc/intel/common/vbt.h>
18#include <soc/itss.h>
Michał Żygowski16c76262022-11-23 14:43:17 +010019#include <soc/p2sb.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053020#include <soc/pci_devs.h>
Eric Laif8248f32020-12-31 11:43:29 +080021#include <soc/pcie.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053022#include <soc/ramstage.h>
23#include <soc/soc_chip.h>
24
Subrata Banik2871e0e2020-09-27 11:30:58 +053025#if CONFIG(HAVE_ACPI_TABLES)
26const char *soc_acpi_name(const struct device *dev)
27{
28 if (dev->path.type == DEVICE_PATH_DOMAIN)
29 return "PCI0";
30
31 if (dev->path.type == DEVICE_PATH_USB) {
32 switch (dev->path.usb.port_type) {
33 case 0:
34 /* Root Hub */
35 return "RHUB";
36 case 2:
37 /* USB2 ports */
38 switch (dev->path.usb.port_id) {
39 case 0: return "HS01";
40 case 1: return "HS02";
41 case 2: return "HS03";
42 case 3: return "HS04";
43 case 4: return "HS05";
44 case 5: return "HS06";
45 case 6: return "HS07";
46 case 7: return "HS08";
47 case 8: return "HS09";
48 case 9: return "HS10";
Michał Żygowski3f205a42022-04-15 18:17:46 +020049 case 10: return "HS11";
50 case 11: return "HS12";
51 case 12: return "HS13";
52 case 13: return "HS14";
Subrata Banik2871e0e2020-09-27 11:30:58 +053053 }
54 break;
55 case 3:
56 /* USB3 ports */
57 switch (dev->path.usb.port_id) {
58 case 0: return "SS01";
59 case 1: return "SS02";
60 case 2: return "SS03";
61 case 3: return "SS04";
Michał Żygowski3f205a42022-04-15 18:17:46 +020062 case 4: return "SS05";
63 case 5: return "SS06";
64 case 6: return "SS07";
65 case 7: return "SS08";
66 case 8: return "SS09";
67 case 9: return "SS10";
Subrata Banik2871e0e2020-09-27 11:30:58 +053068 }
69 break;
70 }
71 return NULL;
72 }
73 if (dev->path.type != DEVICE_PATH_PCI)
74 return NULL;
75
76 switch (dev->path.pci.devfn) {
77 case SA_DEVFN_ROOT: return "MCHC";
Michał Żygowski933a44b2022-04-15 18:15:44 +020078#if CONFIG(SOC_INTEL_ALDERLAKE_PCH_S)
79 case SA_DEVFN_CPU_PCIE1_0: return "PEG1";
80 case SA_DEVFN_CPU_PCIE1_1: return "PEG2";
81 case SA_DEVFN_CPU_PCIE6_0: return "PEG0";
82#else
Tim Wawrzynczakcf393362021-12-16 15:01:44 -070083 case SA_DEVFN_CPU_PCIE1_0: return "PEG2";
84 case SA_DEVFN_CPU_PCIE6_0: return "PEG0";
85 case SA_DEVFN_CPU_PCIE6_2: return "PEG1";
Michał Żygowski933a44b2022-04-15 18:15:44 +020086#endif
Wisley Chencd807212021-08-31 18:27:13 +060087 case SA_DEVFN_IGD: return "GFX0";
Subrata Banik2871e0e2020-09-27 11:30:58 +053088 case SA_DEVFN_TCSS_XHCI: return "TXHC";
89 case SA_DEVFN_TCSS_XDCI: return "TXDC";
90 case SA_DEVFN_TCSS_DMA0: return "TDM0";
91 case SA_DEVFN_TCSS_DMA1: return "TDM1";
92 case SA_DEVFN_TBT0: return "TRP0";
93 case SA_DEVFN_TBT1: return "TRP1";
94 case SA_DEVFN_TBT2: return "TRP2";
95 case SA_DEVFN_TBT3: return "TRP3";
96 case SA_DEVFN_IPU: return "IPU0";
Matt DeVillierecf2b422023-08-31 10:06:00 -050097 case SA_DEVFN_GNA: return "GNA";
CoolStard103a312023-02-09 22:43:35 -080098 case SA_DEVFN_DPTF: return "TCPU";
Subrata Banik2871e0e2020-09-27 11:30:58 +053099 case PCH_DEVFN_ISH: return "ISHB";
100 case PCH_DEVFN_XHCI: return "XHCI";
101 case PCH_DEVFN_I2C0: return "I2C0";
102 case PCH_DEVFN_I2C1: return "I2C1";
103 case PCH_DEVFN_I2C2: return "I2C2";
104 case PCH_DEVFN_I2C3: return "I2C3";
105 case PCH_DEVFN_I2C4: return "I2C4";
106 case PCH_DEVFN_I2C5: return "I2C5";
Varshit B Pandya339f0e72021-07-14 11:08:23 +0530107 case PCH_DEVFN_I2C6: return "I2C6";
108 case PCH_DEVFN_I2C7: return "I2C7";
Subrata Banik2871e0e2020-09-27 11:30:58 +0530109 case PCH_DEVFN_SATA: return "SATA";
110 case PCH_DEVFN_PCIE1: return "RP01";
111 case PCH_DEVFN_PCIE2: return "RP02";
112 case PCH_DEVFN_PCIE3: return "RP03";
113 case PCH_DEVFN_PCIE4: return "RP04";
114 case PCH_DEVFN_PCIE5: return "RP05";
115 case PCH_DEVFN_PCIE6: return "RP06";
116 case PCH_DEVFN_PCIE7: return "RP07";
117 case PCH_DEVFN_PCIE8: return "RP08";
118 case PCH_DEVFN_PCIE9: return "RP09";
119 case PCH_DEVFN_PCIE10: return "RP10";
120 case PCH_DEVFN_PCIE11: return "RP11";
121 case PCH_DEVFN_PCIE12: return "RP12";
Michał Żygowski933a44b2022-04-15 18:15:44 +0200122 case PCH_DEVFN_PCIE13: return "RP13";
123 case PCH_DEVFN_PCIE14: return "RP14";
124 case PCH_DEVFN_PCIE15: return "RP15";
125 case PCH_DEVFN_PCIE16: return "RP16";
126 case PCH_DEVFN_PCIE17: return "RP17";
127 case PCH_DEVFN_PCIE18: return "RP18";
128 case PCH_DEVFN_PCIE19: return "RP19";
129 case PCH_DEVFN_PCIE20: return "RP20";
130 case PCH_DEVFN_PCIE21: return "RP21";
131 case PCH_DEVFN_PCIE22: return "RP22";
132 case PCH_DEVFN_PCIE23: return "RP23";
133 case PCH_DEVFN_PCIE24: return "RP24";
134#if CONFIG(SOC_INTEL_ALDERLAKE_PCH_S)
135 /* Avoid conflicts with PCH-N eMMC */
136 case PCH_DEVFN_PCIE25: return "RP25";
137 case PCH_DEVFN_PCIE26: return "RP26";
138 case PCH_DEVFN_PCIE27: return "RP27";
139 case PCH_DEVFN_PCIE28: return "RP28";
140#endif
Subrata Banik2871e0e2020-09-27 11:30:58 +0530141 case PCH_DEVFN_PMC: return "PMC";
142 case PCH_DEVFN_UART0: return "UAR0";
143 case PCH_DEVFN_UART1: return "UAR1";
144 case PCH_DEVFN_UART2: return "UAR2";
145 case PCH_DEVFN_GSPI0: return "SPI0";
146 case PCH_DEVFN_GSPI1: return "SPI1";
147 case PCH_DEVFN_GSPI2: return "SPI2";
148 case PCH_DEVFN_GSPI3: return "SPI3";
149 /* Keeping ACPI device name coherent with ec.asl */
150 case PCH_DEVFN_ESPI: return "LPCB";
151 case PCH_DEVFN_HDA: return "HDAS";
152 case PCH_DEVFN_SMBUS: return "SBUS";
153 case PCH_DEVFN_GBE: return "GLAN";
Tarun Tulid8d52282022-05-03 20:34:32 +0000154 case PCH_DEVFN_SRAM: return "SRAM";
155 case PCH_DEVFN_SPI: return "FSPI";
156 case PCH_DEVFN_CSE: return "HEC1";
Krishna Prasad Bhata6d642f2022-01-16 23:16:24 +0530157#if CONFIG(SOC_INTEL_ALDERLAKE_PCH_N)
158 case PCH_DEVFN_EMMC: return "EMMC";
159#endif
Subrata Banik2871e0e2020-09-27 11:30:58 +0530160 }
161
162 return NULL;
163}
164#endif
165
Subrata Banik272ce9a2023-06-13 00:44:44 +0530166#if CONFIG(SOC_INTEL_STORE_ISH_FW_VERSION)
Subrata Banik9bb26902023-04-18 23:49:37 +0530167/*
168 * SoC override API to identify if ISH Firmware existed inside CSE FPT.
169 *
170 * SoC with UFS enabled would like to keep ISH enabled as well, hence
171 * identifying the UFS enabled device is enough to conclude that the ISH
172 * partition also is available.
173 */
174bool soc_is_ish_partition_enabled(void)
175{
176 struct device *ufs = pcidev_path_on_root(PCH_DEVFN_UFS);
177 uint16_t ufs_pci_id = ufs ? pci_read_config16(ufs, PCI_DEVICE_ID) : 0xFFFF;
178
179 if (ufs_pci_id == 0xFFFF)
180 return false;
181
182 return true;
183}
184#endif
185
Subrata Banik2871e0e2020-09-27 11:30:58 +0530186/* SoC routine to fill GPIO PM mask and value for GPIO_MISCCFG register */
187static void soc_fill_gpio_pm_configuration(void)
188{
189 uint8_t value[TOTAL_GPIO_COMM];
190 const config_t *config = config_of_soc();
191
192 if (config->gpio_override_pm)
Angel Pons0c0d4922021-04-05 13:02:45 +0200193 memcpy(value, config->gpio_pm, sizeof(value));
Subrata Banik2871e0e2020-09-27 11:30:58 +0530194 else
Angel Pons0c0d4922021-04-05 13:02:45 +0200195 memset(value, MISCCFG_GPIO_PM_CONFIG_BITS, sizeof(value));
Subrata Banik2871e0e2020-09-27 11:30:58 +0530196
197 gpio_pm_configure(value, TOTAL_GPIO_COMM);
198}
199
200void soc_init_pre_device(void *chip_info)
201{
Michał Żygowski9b0f1692022-05-05 13:21:01 +0200202 /* HSPHY FW needs to be loaded before FSP silicon init */
203 load_and_init_hsphy();
204
Subrata Banik2871e0e2020-09-27 11:30:58 +0530205 /* Perform silicon specific init. */
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200206 fsp_silicon_init();
Subrata Banik2871e0e2020-09-27 11:30:58 +0530207
208 /* Display FIRMWARE_VERSION_INFO_HOB */
209 fsp_display_fvi_version_hob();
210
Subrata Banik2871e0e2020-09-27 11:30:58 +0530211 soc_fill_gpio_pm_configuration();
212
213 /* Swap enabled PCI ports in device tree if needed. */
Eric Laif8248f32020-12-31 11:43:29 +0800214 pcie_rp_update_devicetree(get_pch_pcie_rp_table());
MAULIK V VAGHELA3e4f28f2022-01-21 14:17:53 +0530215
216 /* Swap enabled TBT root ports in device tree if needed. */
217 pcie_rp_update_devicetree(get_tbt_pcie_rp_table());
MAULIK V VAGHELAed6f7e42022-02-22 19:59:42 +0530218
219 /*
220 * Earlier when coreboot used to send EOP at late as possible caused
221 * issue of delayed response from CSE since CSE was busy loading payload.
222 * To resolve the issue, EOP should be sent earlier than current sequence
223 * in the boot sequence at BS_DEV_INIT.
224 * Intel CSE team recommends to send EOP close to FW init (between FSP-S exit and
225 * current boot sequence) to reduce message response time from CSE hence moving
226 * sending EOP to earlier stage.
227 */
Subrata Banikcda48b22023-04-09 08:07:11 +0000228 if (CONFIG(SOC_INTEL_CSE_SEND_EOP_EARLY) ||
229 CONFIG(SOC_INTEL_CSE_SEND_EOP_ASYNC)) {
MAULIK V VAGHELAed6f7e42022-02-22 19:59:42 +0530230 printk(BIOS_INFO, "Sending EOP early from SoC\n");
231 cse_send_end_of_post();
232 }
Subrata Banik2871e0e2020-09-27 11:30:58 +0530233}
234
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600235static void cpu_fill_ssdt(const struct device *dev)
236{
237 if (!generate_pin_irq_map())
Julius Wernere9665952022-01-21 17:06:20 -0800238 printk(BIOS_ERR, "Failed to generate ACPI _PRT table!\n");
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600239
240 generate_cpu_entries(dev);
241}
242
243static void cpu_set_north_irqs(struct device *dev)
244{
245 irq_program_non_pch();
246}
247
Subrata Banik2871e0e2020-09-27 11:30:58 +0530248static struct device_operations pci_domain_ops = {
249 .read_resources = &pci_domain_read_resources,
250 .set_resources = &pci_domain_set_resources,
Arthur Heymans0b0113f2023-08-31 17:09:28 +0200251 .scan_bus = &pci_host_bridge_scan_bus,
Subrata Banik2871e0e2020-09-27 11:30:58 +0530252#if CONFIG(HAVE_ACPI_TABLES)
253 .acpi_name = &soc_acpi_name,
Arthur Heymans08769c62022-05-09 14:33:15 +0200254 .acpi_fill_ssdt = ssdt_set_above_4g_pci,
Subrata Banik2871e0e2020-09-27 11:30:58 +0530255#endif
256};
257
258static struct device_operations cpu_bus_ops = {
259 .read_resources = noop_read_resources,
260 .set_resources = noop_set_resources,
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600261 .enable_resources = cpu_set_north_irqs,
Subrata Banik2871e0e2020-09-27 11:30:58 +0530262#if CONFIG(HAVE_ACPI_TABLES)
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600263 .acpi_fill_ssdt = cpu_fill_ssdt,
Subrata Banik2871e0e2020-09-27 11:30:58 +0530264#endif
265};
266
267static void soc_enable(struct device *dev)
268{
Michał Żygowski16c76262022-11-23 14:43:17 +0100269 struct device_operations *soc_p2sb_ops = (struct device_operations *)&p2sb_ops;
Subrata Banik2871e0e2020-09-27 11:30:58 +0530270 /*
271 * Set the operations if it is a special bus type or a hidden PCI
272 * device.
273 */
274 if (dev->path.type == DEVICE_PATH_DOMAIN)
275 dev->ops = &pci_domain_ops;
276 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
277 dev->ops = &cpu_bus_ops;
278 else if (dev->path.type == DEVICE_PATH_PCI &&
279 dev->path.pci.devfn == PCH_DEVFN_PMC)
280 dev->ops = &pmc_ops;
Michał Żygowski16c76262022-11-23 14:43:17 +0100281 else if (dev->path.type == DEVICE_PATH_PCI &&
282 dev->path.pci.devfn == PCH_DEVFN_P2SB)
283 dev->ops = soc_p2sb_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +0100284 else if (dev->path.type == DEVICE_PATH_GPIO)
285 block_gpio_enable(dev);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530286}
287
288struct chip_operations soc_intel_alderlake_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900289 .name = "Intel Alderlake",
Subrata Banik2871e0e2020-09-27 11:30:58 +0530290 .enable_dev = &soc_enable,
291 .init = &soc_init_pre_device,
292};