blob: 4a060af6628091e9da83be714ee791d4b7542e8e [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>
Michael Niewöhner8913b782020-12-11 22:13:44 +01009#include <intelblocks/gpio.h>
Tim Wawrzynczak43607e42021-05-18 09:04:42 -060010#include <intelblocks/irq.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053011#include <intelblocks/itss.h>
12#include <intelblocks/pcie_rp.h>
13#include <intelblocks/xdci.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053014#include <soc/intel/common/vbt.h>
15#include <soc/itss.h>
16#include <soc/pci_devs.h>
Eric Laif8248f32020-12-31 11:43:29 +080017#include <soc/pcie.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053018#include <soc/ramstage.h>
19#include <soc/soc_chip.h>
20
Subrata Banik2871e0e2020-09-27 11:30:58 +053021#if CONFIG(HAVE_ACPI_TABLES)
22const char *soc_acpi_name(const struct device *dev)
23{
24 if (dev->path.type == DEVICE_PATH_DOMAIN)
25 return "PCI0";
26
27 if (dev->path.type == DEVICE_PATH_USB) {
28 switch (dev->path.usb.port_type) {
29 case 0:
30 /* Root Hub */
31 return "RHUB";
32 case 2:
33 /* USB2 ports */
34 switch (dev->path.usb.port_id) {
35 case 0: return "HS01";
36 case 1: return "HS02";
37 case 2: return "HS03";
38 case 3: return "HS04";
39 case 4: return "HS05";
40 case 5: return "HS06";
41 case 6: return "HS07";
42 case 7: return "HS08";
43 case 8: return "HS09";
44 case 9: return "HS10";
45 }
46 break;
47 case 3:
48 /* USB3 ports */
49 switch (dev->path.usb.port_id) {
50 case 0: return "SS01";
51 case 1: return "SS02";
52 case 2: return "SS03";
53 case 3: return "SS04";
54 }
55 break;
56 }
57 return NULL;
58 }
59 if (dev->path.type != DEVICE_PATH_PCI)
60 return NULL;
61
62 switch (dev->path.pci.devfn) {
63 case SA_DEVFN_ROOT: return "MCHC";
64 case SA_DEVFN_TCSS_XHCI: return "TXHC";
65 case SA_DEVFN_TCSS_XDCI: return "TXDC";
66 case SA_DEVFN_TCSS_DMA0: return "TDM0";
67 case SA_DEVFN_TCSS_DMA1: return "TDM1";
68 case SA_DEVFN_TBT0: return "TRP0";
69 case SA_DEVFN_TBT1: return "TRP1";
70 case SA_DEVFN_TBT2: return "TRP2";
71 case SA_DEVFN_TBT3: return "TRP3";
72 case SA_DEVFN_IPU: return "IPU0";
73 case PCH_DEVFN_ISH: return "ISHB";
74 case PCH_DEVFN_XHCI: return "XHCI";
75 case PCH_DEVFN_I2C0: return "I2C0";
76 case PCH_DEVFN_I2C1: return "I2C1";
77 case PCH_DEVFN_I2C2: return "I2C2";
78 case PCH_DEVFN_I2C3: return "I2C3";
79 case PCH_DEVFN_I2C4: return "I2C4";
80 case PCH_DEVFN_I2C5: return "I2C5";
Varshit B Pandya339f0e72021-07-14 11:08:23 +053081 case PCH_DEVFN_I2C6: return "I2C6";
82 case PCH_DEVFN_I2C7: return "I2C7";
Subrata Banik2871e0e2020-09-27 11:30:58 +053083 case PCH_DEVFN_SATA: return "SATA";
84 case PCH_DEVFN_PCIE1: return "RP01";
85 case PCH_DEVFN_PCIE2: return "RP02";
86 case PCH_DEVFN_PCIE3: return "RP03";
87 case PCH_DEVFN_PCIE4: return "RP04";
88 case PCH_DEVFN_PCIE5: return "RP05";
89 case PCH_DEVFN_PCIE6: return "RP06";
90 case PCH_DEVFN_PCIE7: return "RP07";
91 case PCH_DEVFN_PCIE8: return "RP08";
92 case PCH_DEVFN_PCIE9: return "RP09";
93 case PCH_DEVFN_PCIE10: return "RP10";
94 case PCH_DEVFN_PCIE11: return "RP11";
95 case PCH_DEVFN_PCIE12: return "RP12";
96 case PCH_DEVFN_PMC: return "PMC";
97 case PCH_DEVFN_UART0: return "UAR0";
98 case PCH_DEVFN_UART1: return "UAR1";
99 case PCH_DEVFN_UART2: return "UAR2";
100 case PCH_DEVFN_GSPI0: return "SPI0";
101 case PCH_DEVFN_GSPI1: return "SPI1";
102 case PCH_DEVFN_GSPI2: return "SPI2";
103 case PCH_DEVFN_GSPI3: return "SPI3";
104 /* Keeping ACPI device name coherent with ec.asl */
105 case PCH_DEVFN_ESPI: return "LPCB";
106 case PCH_DEVFN_HDA: return "HDAS";
107 case PCH_DEVFN_SMBUS: return "SBUS";
108 case PCH_DEVFN_GBE: return "GLAN";
109 }
110
111 return NULL;
112}
113#endif
114
115/* SoC routine to fill GPIO PM mask and value for GPIO_MISCCFG register */
116static void soc_fill_gpio_pm_configuration(void)
117{
118 uint8_t value[TOTAL_GPIO_COMM];
119 const config_t *config = config_of_soc();
120
121 if (config->gpio_override_pm)
Angel Pons0c0d4922021-04-05 13:02:45 +0200122 memcpy(value, config->gpio_pm, sizeof(value));
Subrata Banik2871e0e2020-09-27 11:30:58 +0530123 else
Angel Pons0c0d4922021-04-05 13:02:45 +0200124 memset(value, MISCCFG_GPIO_PM_CONFIG_BITS, sizeof(value));
Subrata Banik2871e0e2020-09-27 11:30:58 +0530125
126 gpio_pm_configure(value, TOTAL_GPIO_COMM);
127}
128
129void soc_init_pre_device(void *chip_info)
130{
Subrata Banik2871e0e2020-09-27 11:30:58 +0530131 /* Perform silicon specific init. */
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200132 fsp_silicon_init();
Subrata Banik2871e0e2020-09-27 11:30:58 +0530133
134 /* Display FIRMWARE_VERSION_INFO_HOB */
135 fsp_display_fvi_version_hob();
136
Subrata Banik2871e0e2020-09-27 11:30:58 +0530137 soc_fill_gpio_pm_configuration();
138
139 /* Swap enabled PCI ports in device tree if needed. */
Eric Laif8248f32020-12-31 11:43:29 +0800140 pcie_rp_update_devicetree(get_pch_pcie_rp_table());
Subrata Banik2871e0e2020-09-27 11:30:58 +0530141}
142
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600143static void cpu_fill_ssdt(const struct device *dev)
144{
145 if (!generate_pin_irq_map())
146 printk(BIOS_ERR, "ERROR: Failed to generate ACPI _PRT table!\n");
147
148 generate_cpu_entries(dev);
149}
150
151static void cpu_set_north_irqs(struct device *dev)
152{
153 irq_program_non_pch();
154}
155
Subrata Banik2871e0e2020-09-27 11:30:58 +0530156static struct device_operations pci_domain_ops = {
157 .read_resources = &pci_domain_read_resources,
158 .set_resources = &pci_domain_set_resources,
159 .scan_bus = &pci_domain_scan_bus,
160#if CONFIG(HAVE_ACPI_TABLES)
161 .acpi_name = &soc_acpi_name,
162#endif
163};
164
165static struct device_operations cpu_bus_ops = {
166 .read_resources = noop_read_resources,
167 .set_resources = noop_set_resources,
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600168 .enable_resources = cpu_set_north_irqs,
Subrata Banik2871e0e2020-09-27 11:30:58 +0530169#if CONFIG(HAVE_ACPI_TABLES)
Tim Wawrzynczak43607e42021-05-18 09:04:42 -0600170 .acpi_fill_ssdt = cpu_fill_ssdt,
Subrata Banik2871e0e2020-09-27 11:30:58 +0530171#endif
172};
173
174static void soc_enable(struct device *dev)
175{
176 /*
177 * Set the operations if it is a special bus type or a hidden PCI
178 * device.
179 */
180 if (dev->path.type == DEVICE_PATH_DOMAIN)
181 dev->ops = &pci_domain_ops;
182 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
183 dev->ops = &cpu_bus_ops;
184 else if (dev->path.type == DEVICE_PATH_PCI &&
185 dev->path.pci.devfn == PCH_DEVFN_PMC)
186 dev->ops = &pmc_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +0100187 else if (dev->path.type == DEVICE_PATH_GPIO)
188 block_gpio_enable(dev);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530189}
190
191struct chip_operations soc_intel_alderlake_ops = {
192 CHIP_NAME("Intel Alderlake")
193 .enable_dev = &soc_enable,
194 .init = &soc_init_pre_device,
195};