blob: 041b16d413d0f5b49a6b46c6984f972021f97e5f [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>
7#include <intelblocks/acpi.h>
8#include <intelblocks/cfg.h>
9#include <intelblocks/gpio.h>
10#include <intelblocks/itss.h>
John Zhao54a03e42022-08-03 20:07:03 -070011#include <intelblocks/p2sb.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070012#include <intelblocks/pcie_rp.h>
13#include <intelblocks/systemagent.h>
John Zhao54a03e42022-08-03 20:07:03 -070014#include <intelblocks/tcss.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070015#include <intelblocks/xdci.h>
16#include <soc/intel/common/vbt.h>
John Zhao54a03e42022-08-03 20:07:03 -070017#include <soc/iomap.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070018#include <soc/itss.h>
19#include <soc/p2sb.h>
20#include <soc/pci_devs.h>
21#include <soc/pcie.h>
22#include <soc/ramstage.h>
23#include <soc/soc_chip.h>
John Zhao54a03e42022-08-03 20:07:03 -070024#include <soc/tcss.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070025
26#if CONFIG(HAVE_ACPI_TABLES)
27const char *soc_acpi_name(const struct device *dev)
28{
29 if (dev->path.type == DEVICE_PATH_DOMAIN)
30 return "PCI0";
31
32 if (dev->path.type == DEVICE_PATH_USB) {
33 switch (dev->path.usb.port_type) {
34 case 0:
35 /* Root Hub */
36 return "RHUB";
37 case 2:
38 /* USB2 ports */
39 switch (dev->path.usb.port_id) {
40 case 0: return "HS01";
41 case 1: return "HS02";
42 case 2: return "HS03";
43 case 3: return "HS04";
44 case 4: return "HS05";
45 case 5: return "HS06";
46 case 6: return "HS07";
47 case 7: return "HS08";
48 case 8: return "HS09";
49 case 9: return "HS10";
50 }
51 break;
52 case 3:
53 /* USB3 ports */
54 switch (dev->path.usb.port_id) {
55 case 0: return "SS01";
56 case 1: return "SS02";
57 case 2: return "SS03";
58 case 3: return "SS04";
59 }
60 break;
61 }
62 printk(BIOS_DEBUG, "dev->path.type=%x\n", dev->path.usb.port_type);
63 return NULL;
64 }
65 if (dev->path.type != DEVICE_PATH_PCI) {
66 printk(BIOS_DEBUG, "dev->path.type=%x\n", dev->path.type);
67 return NULL;
68 }
69
70 switch (dev->path.pci.devfn) {
71 case PCI_DEVFN_ROOT: return "MCHC";
72 case PCI_DEVFN_TCSS_XHCI: return "TXHC";
73 case PCI_DEVFN_TCSS_XDCI: return "TXDC";
74 case PCI_DEVFN_TCSS_DMA0: return "TDM0";
75 case PCI_DEVFN_TCSS_DMA1: return "TDM1";
76 case PCI_DEVFN_TBT0: return "TRP0";
77 case PCI_DEVFN_TBT1: return "TRP1";
78 case PCI_DEVFN_TBT2: return "TRP2";
79 case PCI_DEVFN_TBT3: return "TRP3";
80 case PCI_DEVFN_IPU: return "IPU0";
81 case PCI_DEVFN_ISH: return "ISHB";
82 case PCI_DEVFN_XHCI: return "XHCI";
83 case PCI_DEVFN_I2C0: return "I2C0";
84 case PCI_DEVFN_I2C1: return "I2C1";
85 case PCI_DEVFN_I2C2: return "I2C2";
86 case PCI_DEVFN_I2C3: return "I2C3";
87 case PCI_DEVFN_I2C4: return "I2C4";
88 case PCI_DEVFN_I2C5: return "I2C5";
89 case PCI_DEVFN_SATA: return "SATA";
90 case PCI_DEVFN_PCIE1: return "RP01";
91 case PCI_DEVFN_PCIE2: return "RP02";
92 case PCI_DEVFN_PCIE3: return "RP03";
93 case PCI_DEVFN_PCIE4: return "RP04";
94 case PCI_DEVFN_PCIE5: return "RP05";
95 case PCI_DEVFN_PCIE6: return "RP06";
96 case PCI_DEVFN_PCIE7: return "RP07";
97 case PCI_DEVFN_PCIE8: return "RP08";
98 case PCI_DEVFN_PCIE9: return "RP09";
99 case PCI_DEVFN_PCIE10: return "RP10";
100 case PCI_DEVFN_PCIE11: return "RP11";
101 case PCI_DEVFN_PCIE12: return "RP12";
102 case PCI_DEVFN_PMC: return "PMC";
103 case PCI_DEVFN_UART0: return "UAR0";
104 case PCI_DEVFN_UART1: return "UAR1";
105 case PCI_DEVFN_UART2: return "UAR2";
106 case PCI_DEVFN_GSPI0: return "SPI0";
107 case PCI_DEVFN_GSPI1: return "SPI1";
Angel Ponsc7c746c2022-07-16 12:37:38 +0200108 case PCI_DEVFN_GSPI2: return "SPI2";
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700109 /* Keeping ACPI device name coherent with ec.asl */
110 case PCI_DEVFN_ESPI: return "LPCB";
111 case PCI_DEVFN_HDA: return "HDAS";
112 case PCI_DEVFN_SMBUS: return "SBUS";
113 case PCI_DEVFN_GBE: return "GLAN";
114 }
115 printk(BIOS_DEBUG, "dev->path.devfn=%x\n", dev->path.pci.devfn);
116 return NULL;
117}
118#endif
119
120/* SoC routine to fill GPIO PM mask and value for GPIO_MISCCFG register */
121static void soc_fill_gpio_pm_configuration(void)
122{
123 uint8_t value[TOTAL_GPIO_COMM];
124 const config_t *config = config_of_soc();
125
126 if (config->gpio_override_pm)
127 memcpy(value, config->gpio_pm, sizeof(value));
128 else
129 memset(value, MISCCFG_GPIO_PM_CONFIG_BITS, sizeof(value));
130
131 gpio_pm_configure(value, TOTAL_GPIO_COMM);
132}
133
134void soc_init_pre_device(void *chip_info)
135{
John Zhao54a03e42022-08-03 20:07:03 -0700136 config_t *config = config_of_soc();
137
138 /* Validate TBT image authentication */
139 config->tbt_authentication = ioe_p2sb_sbi_read(PID_IOM,
140 IOM_CSME_IMR_TBT_STATUS) & TBT_VALID_AUTHENTICATION;
141
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700142 /* Perform silicon specific init. */
143 fsp_silicon_init();
144
145 /* Display FIRMWARE_VERSION_INFO_HOB */
146 fsp_display_fvi_version_hob();
147
148 soc_fill_gpio_pm_configuration();
149
150 /* Swap enabled PCI ports in device tree if needed. */
151 pcie_rp_update_devicetree(get_pcie_rp_table());
152}
153
154static struct device_operations pci_domain_ops = {
155 .read_resources = &pci_domain_read_resources,
156 .set_resources = &pci_domain_set_resources,
157 .scan_bus = &pci_domain_scan_bus,
158#if CONFIG(HAVE_ACPI_TABLES)
159 .acpi_name = &soc_acpi_name,
160 .acpi_fill_ssdt = ssdt_set_above_4g_pci,
161#endif
162};
163
164static struct device_operations cpu_bus_ops = {
165 .read_resources = noop_read_resources,
166 .set_resources = noop_set_resources,
167#if CONFIG(HAVE_ACPI_TABLES)
168 .acpi_fill_ssdt = generate_cpu_entries,
169#endif
170};
171
172static void soc_enable(struct device *dev)
173{
174 /*
175 * Set the operations if it is a special bus type or a hidden PCI
176 * device.
177 */
178 if (dev->path.type == DEVICE_PATH_DOMAIN)
179 dev->ops = &pci_domain_ops;
180 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
181 dev->ops = &cpu_bus_ops;
182 else if (dev->path.type == DEVICE_PATH_PCI &&
183 dev->path.pci.devfn == PCI_DEVFN_PMC)
184 dev->ops = &pmc_ops;
185 else if (dev->path.type == DEVICE_PATH_PCI &&
Subrata Banik4ed30ca2022-10-27 15:44:54 +0530186 dev->path.pci.devfn == PCI_DEVFN_P2SB)
187 dev->ops = &soc_p2sb_ops;
188 else if (dev->path.type == DEVICE_PATH_PCI &&
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700189 dev->path.pci.devfn == PCI_DEVFN_IOE_P2SB)
190 dev->ops = &ioe_p2sb_ops;
191 else if (dev->path.type == DEVICE_PATH_GPIO)
192 block_gpio_enable(dev);
193}
194
195struct chip_operations soc_intel_meteorlake_ops = {
196 CHIP_NAME("Intel Meteorlake")
197 .enable_dev = &soc_enable,
198 .init = &soc_init_pre_device,
199};