blob: 59f006634a12b71f026800af0f7b878876635091 [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>
7#include <intelblocks/acpi.h>
8#include <intelblocks/cfg.h>
MAULIK V VAGHELAed6f7e42022-02-22 19:59:42 +05309#include <intelblocks/cse.h>
Michael Niewöhner8913b782020-12-11 22:13:44 +010010#include <intelblocks/gpio.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>
14#include <intelblocks/xdci.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053015#include <soc/intel/common/vbt.h>
16#include <soc/itss.h>
17#include <soc/pci_devs.h>
Eric Laif8248f32020-12-31 11:43:29 +080018#include <soc/pcie.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053019#include <soc/ramstage.h>
20#include <soc/soc_chip.h>
21
Subrata Banik2871e0e2020-09-27 11:30:58 +053022#if CONFIG(HAVE_ACPI_TABLES)
23const char *soc_acpi_name(const struct device *dev)
24{
25 if (dev->path.type == DEVICE_PATH_DOMAIN)
26 return "PCI0";
27
28 if (dev->path.type == DEVICE_PATH_USB) {
29 switch (dev->path.usb.port_type) {
30 case 0:
31 /* Root Hub */
32 return "RHUB";
33 case 2:
34 /* USB2 ports */
35 switch (dev->path.usb.port_id) {
36 case 0: return "HS01";
37 case 1: return "HS02";
38 case 2: return "HS03";
39 case 3: return "HS04";
40 case 4: return "HS05";
41 case 5: return "HS06";
42 case 6: return "HS07";
43 case 7: return "HS08";
44 case 8: return "HS09";
45 case 9: return "HS10";
46 }
47 break;
48 case 3:
49 /* USB3 ports */
50 switch (dev->path.usb.port_id) {
51 case 0: return "SS01";
52 case 1: return "SS02";
53 case 2: return "SS03";
54 case 3: return "SS04";
55 }
56 break;
57 }
58 return NULL;
59 }
60 if (dev->path.type != DEVICE_PATH_PCI)
61 return NULL;
62
63 switch (dev->path.pci.devfn) {
64 case SA_DEVFN_ROOT: return "MCHC";
Tim Wawrzynczakcf393362021-12-16 15:01:44 -070065 case SA_DEVFN_CPU_PCIE1_0: return "PEG2";
66 case SA_DEVFN_CPU_PCIE6_0: return "PEG0";
67 case SA_DEVFN_CPU_PCIE6_2: return "PEG1";
Wisley Chencd807212021-08-31 18:27:13 +060068 case SA_DEVFN_IGD: return "GFX0";
Subrata Banik2871e0e2020-09-27 11:30:58 +053069 case SA_DEVFN_TCSS_XHCI: return "TXHC";
70 case SA_DEVFN_TCSS_XDCI: return "TXDC";
71 case SA_DEVFN_TCSS_DMA0: return "TDM0";
72 case SA_DEVFN_TCSS_DMA1: return "TDM1";
73 case SA_DEVFN_TBT0: return "TRP0";
74 case SA_DEVFN_TBT1: return "TRP1";
75 case SA_DEVFN_TBT2: return "TRP2";
76 case SA_DEVFN_TBT3: return "TRP3";
77 case SA_DEVFN_IPU: return "IPU0";
Tarun Tulid8d52282022-05-03 20:34:32 +000078 case SA_DEVFN_DPTF: return "DPTF";
Subrata Banik2871e0e2020-09-27 11:30:58 +053079 case PCH_DEVFN_ISH: return "ISHB";
80 case PCH_DEVFN_XHCI: return "XHCI";
81 case PCH_DEVFN_I2C0: return "I2C0";
82 case PCH_DEVFN_I2C1: return "I2C1";
83 case PCH_DEVFN_I2C2: return "I2C2";
84 case PCH_DEVFN_I2C3: return "I2C3";
85 case PCH_DEVFN_I2C4: return "I2C4";
86 case PCH_DEVFN_I2C5: return "I2C5";
Varshit B Pandya339f0e72021-07-14 11:08:23 +053087 case PCH_DEVFN_I2C6: return "I2C6";
88 case PCH_DEVFN_I2C7: return "I2C7";
Subrata Banik2871e0e2020-09-27 11:30:58 +053089 case PCH_DEVFN_SATA: return "SATA";
90 case PCH_DEVFN_PCIE1: return "RP01";
91 case PCH_DEVFN_PCIE2: return "RP02";
92 case PCH_DEVFN_PCIE3: return "RP03";
93 case PCH_DEVFN_PCIE4: return "RP04";
94 case PCH_DEVFN_PCIE5: return "RP05";
95 case PCH_DEVFN_PCIE6: return "RP06";
96 case PCH_DEVFN_PCIE7: return "RP07";
97 case PCH_DEVFN_PCIE8: return "RP08";
98 case PCH_DEVFN_PCIE9: return "RP09";
99 case PCH_DEVFN_PCIE10: return "RP10";
100 case PCH_DEVFN_PCIE11: return "RP11";
101 case PCH_DEVFN_PCIE12: return "RP12";
102 case PCH_DEVFN_PMC: return "PMC";
103 case PCH_DEVFN_UART0: return "UAR0";
104 case PCH_DEVFN_UART1: return "UAR1";
105 case PCH_DEVFN_UART2: return "UAR2";
106 case PCH_DEVFN_GSPI0: return "SPI0";
107 case PCH_DEVFN_GSPI1: return "SPI1";
108 case PCH_DEVFN_GSPI2: return "SPI2";
109 case PCH_DEVFN_GSPI3: return "SPI3";
110 /* Keeping ACPI device name coherent with ec.asl */
111 case PCH_DEVFN_ESPI: return "LPCB";
112 case PCH_DEVFN_HDA: return "HDAS";
113 case PCH_DEVFN_SMBUS: return "SBUS";
114 case PCH_DEVFN_GBE: return "GLAN";
Tarun Tulid8d52282022-05-03 20:34:32 +0000115 case PCH_DEVFN_SRAM: return "SRAM";
116 case PCH_DEVFN_SPI: return "FSPI";
117 case PCH_DEVFN_CSE: return "HEC1";
Krishna Prasad Bhata6d642f2022-01-16 23:16:24 +0530118#if CONFIG(SOC_INTEL_ALDERLAKE_PCH_N)
119 case PCH_DEVFN_EMMC: return "EMMC";
120#endif
Subrata Banik2871e0e2020-09-27 11:30:58 +0530121 }
122
123 return NULL;
124}
125#endif
126
127/* SoC routine to fill GPIO PM mask and value for GPIO_MISCCFG register */
128static void soc_fill_gpio_pm_configuration(void)
129{
130 uint8_t value[TOTAL_GPIO_COMM];
131 const config_t *config = config_of_soc();
132
133 if (config->gpio_override_pm)
Angel Pons0c0d4922021-04-05 13:02:45 +0200134 memcpy(value, config->gpio_pm, sizeof(value));
Subrata Banik2871e0e2020-09-27 11:30:58 +0530135 else
Angel Pons0c0d4922021-04-05 13:02:45 +0200136 memset(value, MISCCFG_GPIO_PM_CONFIG_BITS, sizeof(value));
Subrata Banik2871e0e2020-09-27 11:30:58 +0530137
138 gpio_pm_configure(value, TOTAL_GPIO_COMM);
139}
140
141void soc_init_pre_device(void *chip_info)
142{
Subrata Banik2871e0e2020-09-27 11:30:58 +0530143 /* Perform silicon specific init. */
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200144 fsp_silicon_init();
Subrata Banik2871e0e2020-09-27 11:30:58 +0530145
146 /* Display FIRMWARE_VERSION_INFO_HOB */
147 fsp_display_fvi_version_hob();
148
Subrata Banik2871e0e2020-09-27 11:30:58 +0530149 soc_fill_gpio_pm_configuration();
150
151 /* Swap enabled PCI ports in device tree if needed. */
Eric Laif8248f32020-12-31 11:43:29 +0800152 pcie_rp_update_devicetree(get_pch_pcie_rp_table());
MAULIK V VAGHELA3e4f28f2022-01-21 14:17:53 +0530153
154 /* Swap enabled TBT root ports in device tree if needed. */
155 pcie_rp_update_devicetree(get_tbt_pcie_rp_table());
MAULIK V VAGHELAed6f7e42022-02-22 19:59:42 +0530156
157 /*
158 * Earlier when coreboot used to send EOP at late as possible caused
159 * issue of delayed response from CSE since CSE was busy loading payload.
160 * To resolve the issue, EOP should be sent earlier than current sequence
161 * in the boot sequence at BS_DEV_INIT.
162 * Intel CSE team recommends to send EOP close to FW init (between FSP-S exit and
163 * current boot sequence) to reduce message response time from CSE hence moving
164 * sending EOP to earlier stage.
165 */
166 if (CONFIG(SOC_INTEL_CSE_SEND_EOP_EARLY)) {
167 printk(BIOS_INFO, "Sending EOP early from SoC\n");
168 cse_send_end_of_post();
169 }
Subrata Banik2871e0e2020-09-27 11:30:58 +0530170}
171
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600172static void cpu_fill_ssdt(const struct device *dev)
173{
174 if (!generate_pin_irq_map())
Julius Wernere9665952022-01-21 17:06:20 -0800175 printk(BIOS_ERR, "Failed to generate ACPI _PRT table!\n");
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600176
177 generate_cpu_entries(dev);
178}
179
180static void cpu_set_north_irqs(struct device *dev)
181{
182 irq_program_non_pch();
183}
184
Subrata Banik2871e0e2020-09-27 11:30:58 +0530185static struct device_operations pci_domain_ops = {
186 .read_resources = &pci_domain_read_resources,
187 .set_resources = &pci_domain_set_resources,
188 .scan_bus = &pci_domain_scan_bus,
189#if CONFIG(HAVE_ACPI_TABLES)
190 .acpi_name = &soc_acpi_name,
191#endif
192};
193
194static struct device_operations cpu_bus_ops = {
195 .read_resources = noop_read_resources,
196 .set_resources = noop_set_resources,
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600197 .enable_resources = cpu_set_north_irqs,
Subrata Banik2871e0e2020-09-27 11:30:58 +0530198#if CONFIG(HAVE_ACPI_TABLES)
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600199 .acpi_fill_ssdt = cpu_fill_ssdt,
Subrata Banik2871e0e2020-09-27 11:30:58 +0530200#endif
201};
202
203static void soc_enable(struct device *dev)
204{
205 /*
206 * Set the operations if it is a special bus type or a hidden PCI
207 * device.
208 */
209 if (dev->path.type == DEVICE_PATH_DOMAIN)
210 dev->ops = &pci_domain_ops;
211 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
212 dev->ops = &cpu_bus_ops;
213 else if (dev->path.type == DEVICE_PATH_PCI &&
214 dev->path.pci.devfn == PCH_DEVFN_PMC)
215 dev->ops = &pmc_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +0100216 else if (dev->path.type == DEVICE_PATH_GPIO)
217 block_gpio_enable(dev);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530218}
219
220struct chip_operations soc_intel_alderlake_ops = {
221 CHIP_NAME("Intel Alderlake")
222 .enable_dev = &soc_enable,
223 .init = &soc_init_pre_device,
224};