blob: 036c126d45671a1f6a348722ae7f863ba4febe76 [file] [log] [blame]
Ravi Sarawadi91ffac82022-05-07 16:37:09 -07001/* 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 Gehlot166c75c72023-01-03 05:26:19 +00007#include <gpio.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -07008#include <intelblocks/acpi.h>
9#include <intelblocks/cfg.h>
Subrata Banikad42d9c2023-04-19 18:30:53 +053010#include <intelblocks/cse.h>
Kapil Porwalcca3c902022-12-19 23:57:15 +053011#include <intelblocks/irq.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070012#include <intelblocks/itss.h>
John Zhao54a03e42022-08-03 20:07:03 -070013#include <intelblocks/p2sb.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070014#include <intelblocks/pcie_rp.h>
15#include <intelblocks/systemagent.h>
John Zhao54a03e42022-08-03 20:07:03 -070016#include <intelblocks/tcss.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070017#include <intelblocks/xdci.h>
18#include <soc/intel/common/vbt.h>
John Zhao54a03e42022-08-03 20:07:03 -070019#include <soc/iomap.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070020#include <soc/itss.h>
21#include <soc/p2sb.h>
22#include <soc/pci_devs.h>
23#include <soc/pcie.h>
24#include <soc/ramstage.h>
25#include <soc/soc_chip.h>
John Zhao54a03e42022-08-03 20:07:03 -070026#include <soc/tcss.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070027
28#if CONFIG(HAVE_ACPI_TABLES)
29const char *soc_acpi_name(const struct device *dev)
30{
31 if (dev->path.type == DEVICE_PATH_DOMAIN)
32 return "PCI0";
33
34 if (dev->path.type == DEVICE_PATH_USB) {
35 switch (dev->path.usb.port_type) {
36 case 0:
37 /* Root Hub */
38 return "RHUB";
39 case 2:
40 /* USB2 ports */
41 switch (dev->path.usb.port_id) {
42 case 0: return "HS01";
43 case 1: return "HS02";
44 case 2: return "HS03";
45 case 3: return "HS04";
46 case 4: return "HS05";
47 case 5: return "HS06";
48 case 6: return "HS07";
49 case 7: return "HS08";
50 case 8: return "HS09";
51 case 9: return "HS10";
52 }
53 break;
54 case 3:
55 /* USB3 ports */
56 switch (dev->path.usb.port_id) {
57 case 0: return "SS01";
58 case 1: return "SS02";
59 case 2: return "SS03";
60 case 3: return "SS04";
61 }
62 break;
63 }
64 printk(BIOS_DEBUG, "dev->path.type=%x\n", dev->path.usb.port_type);
65 return NULL;
66 }
67 if (dev->path.type != DEVICE_PATH_PCI) {
68 printk(BIOS_DEBUG, "dev->path.type=%x\n", dev->path.type);
69 return NULL;
70 }
71
72 switch (dev->path.pci.devfn) {
73 case PCI_DEVFN_ROOT: return "MCHC";
Won Chungede55642023-05-16 17:11:21 +000074 case PCI_DEVFN_IGD: return "GFX0";
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070075 case PCI_DEVFN_TCSS_XHCI: return "TXHC";
76 case PCI_DEVFN_TCSS_XDCI: return "TXDC";
77 case PCI_DEVFN_TCSS_DMA0: return "TDM0";
78 case PCI_DEVFN_TCSS_DMA1: return "TDM1";
79 case PCI_DEVFN_TBT0: return "TRP0";
80 case PCI_DEVFN_TBT1: return "TRP1";
81 case PCI_DEVFN_TBT2: return "TRP2";
82 case PCI_DEVFN_TBT3: return "TRP3";
83 case PCI_DEVFN_IPU: return "IPU0";
84 case PCI_DEVFN_ISH: return "ISHB";
85 case PCI_DEVFN_XHCI: return "XHCI";
86 case PCI_DEVFN_I2C0: return "I2C0";
87 case PCI_DEVFN_I2C1: return "I2C1";
88 case PCI_DEVFN_I2C2: return "I2C2";
89 case PCI_DEVFN_I2C3: return "I2C3";
90 case PCI_DEVFN_I2C4: return "I2C4";
91 case PCI_DEVFN_I2C5: return "I2C5";
92 case PCI_DEVFN_SATA: return "SATA";
93 case PCI_DEVFN_PCIE1: return "RP01";
94 case PCI_DEVFN_PCIE2: return "RP02";
95 case PCI_DEVFN_PCIE3: return "RP03";
96 case PCI_DEVFN_PCIE4: return "RP04";
97 case PCI_DEVFN_PCIE5: return "RP05";
98 case PCI_DEVFN_PCIE6: return "RP06";
99 case PCI_DEVFN_PCIE7: return "RP07";
100 case PCI_DEVFN_PCIE8: return "RP08";
101 case PCI_DEVFN_PCIE9: return "RP09";
102 case PCI_DEVFN_PCIE10: return "RP10";
103 case PCI_DEVFN_PCIE11: return "RP11";
104 case PCI_DEVFN_PCIE12: return "RP12";
105 case PCI_DEVFN_PMC: return "PMC";
106 case PCI_DEVFN_UART0: return "UAR0";
107 case PCI_DEVFN_UART1: return "UAR1";
108 case PCI_DEVFN_UART2: return "UAR2";
109 case PCI_DEVFN_GSPI0: return "SPI0";
110 case PCI_DEVFN_GSPI1: return "SPI1";
Angel Ponsc7c746c2022-07-16 12:37:38 +0200111 case PCI_DEVFN_GSPI2: return "SPI2";
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700112 /* Keeping ACPI device name coherent with ec.asl */
113 case PCI_DEVFN_ESPI: return "LPCB";
114 case PCI_DEVFN_HDA: return "HDAS";
115 case PCI_DEVFN_SMBUS: return "SBUS";
116 case PCI_DEVFN_GBE: return "GLAN";
117 }
Subrata Banike70bc422023-02-17 03:18:50 +0530118 printk(BIOS_DEBUG, "Missing ACPI Name for PCI: 00:%02x.%01x\n",
119 PCI_SLOT(dev->path.pci.devfn), PCI_FUNC(dev->path.pci.devfn));
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700120 return NULL;
121}
122#endif
123
124/* SoC routine to fill GPIO PM mask and value for GPIO_MISCCFG register */
125static void soc_fill_gpio_pm_configuration(void)
126{
127 uint8_t value[TOTAL_GPIO_COMM];
128 const config_t *config = config_of_soc();
129
130 if (config->gpio_override_pm)
131 memcpy(value, config->gpio_pm, sizeof(value));
132 else
133 memset(value, MISCCFG_GPIO_PM_CONFIG_BITS, sizeof(value));
134
135 gpio_pm_configure(value, TOTAL_GPIO_COMM);
136}
137
138void soc_init_pre_device(void *chip_info)
139{
John Zhao54a03e42022-08-03 20:07:03 -0700140 config_t *config = config_of_soc();
141
142 /* Validate TBT image authentication */
143 config->tbt_authentication = ioe_p2sb_sbi_read(PID_IOM,
144 IOM_CSME_IMR_TBT_STATUS) & TBT_VALID_AUTHENTICATION;
145
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700146 /* Perform silicon specific init. */
147 fsp_silicon_init();
148
149 /* Display FIRMWARE_VERSION_INFO_HOB */
150 fsp_display_fvi_version_hob();
151
152 soc_fill_gpio_pm_configuration();
153
154 /* Swap enabled PCI ports in device tree if needed. */
155 pcie_rp_update_devicetree(get_pcie_rp_table());
Subrata Banikad42d9c2023-04-19 18:30:53 +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 *
163 * Intel CSE team recommends to send EOP close to FW init (between FSP-S
164 * exit and current boot sequence) to reduce message response time from
165 * CSE hence moving sending EOP to earlier stage.
166 */
167 if (CONFIG(SOC_INTEL_CSE_SEND_EOP_EARLY) ||
168 CONFIG(SOC_INTEL_CSE_SEND_EOP_ASYNC)) {
169 printk(BIOS_INFO, "Sending EOP early from SoC\n");
170 cse_send_end_of_post();
171 }
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700172}
173
Kapil Porwalcca3c902022-12-19 23:57:15 +0530174static void cpu_fill_ssdt(const struct device *dev)
175{
176 if (!generate_pin_irq_map())
177 printk(BIOS_ERR, "Failed to generate ACPI _PRT table!\n");
178
179 generate_cpu_entries(dev);
180}
181
182static void cpu_set_north_irqs(struct device *dev)
183{
184 irq_program_non_pch();
185}
186
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700187static struct device_operations pci_domain_ops = {
188 .read_resources = &pci_domain_read_resources,
189 .set_resources = &pci_domain_set_resources,
190 .scan_bus = &pci_domain_scan_bus,
191#if CONFIG(HAVE_ACPI_TABLES)
192 .acpi_name = &soc_acpi_name,
193 .acpi_fill_ssdt = ssdt_set_above_4g_pci,
194#endif
195};
196
197static struct device_operations cpu_bus_ops = {
198 .read_resources = noop_read_resources,
199 .set_resources = noop_set_resources,
Kapil Porwalcca3c902022-12-19 23:57:15 +0530200 .enable_resources = cpu_set_north_irqs,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700201#if CONFIG(HAVE_ACPI_TABLES)
Kapil Porwalcca3c902022-12-19 23:57:15 +0530202 .acpi_fill_ssdt = cpu_fill_ssdt,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700203#endif
204};
205
206static void soc_enable(struct device *dev)
207{
208 /*
209 * Set the operations if it is a special bus type or a hidden PCI
210 * device.
211 */
212 if (dev->path.type == DEVICE_PATH_DOMAIN)
213 dev->ops = &pci_domain_ops;
214 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
215 dev->ops = &cpu_bus_ops;
216 else if (dev->path.type == DEVICE_PATH_PCI &&
217 dev->path.pci.devfn == PCI_DEVFN_PMC)
218 dev->ops = &pmc_ops;
219 else if (dev->path.type == DEVICE_PATH_PCI &&
Subrata Banik4ed30ca2022-10-27 15:44:54 +0530220 dev->path.pci.devfn == PCI_DEVFN_P2SB)
221 dev->ops = &soc_p2sb_ops;
222 else if (dev->path.type == DEVICE_PATH_PCI &&
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700223 dev->path.pci.devfn == PCI_DEVFN_IOE_P2SB)
224 dev->ops = &ioe_p2sb_ops;
225 else if (dev->path.type == DEVICE_PATH_GPIO)
226 block_gpio_enable(dev);
227}
228
229struct chip_operations soc_intel_meteorlake_ops = {
230 CHIP_NAME("Intel Meteorlake")
231 .enable_dev = &soc_enable,
232 .init = &soc_init_pre_device,
233};