Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 2 | |
| 3 | #include <arch/ioapic.h> |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 4 | #include <console/console.h> |
Marc Jones | 8b522db | 2020-10-12 11:58:46 -0600 | [diff] [blame] | 5 | #include <console/debug.h> |
Marc Jones | 64c6223 | 2021-04-06 14:09:30 -0600 | [diff] [blame] | 6 | #include <cpu/x86/mp.h> |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 7 | #include <device/pci.h> |
Marc Jones | 456b7ba | 2021-04-15 16:24:54 -0600 | [diff] [blame] | 8 | #include <device/pci_ids.h> |
Dinesh Gehlot | 6fecff2 | 2023-01-17 06:02:16 +0000 | [diff] [blame] | 9 | #include <gpio.h> |
Marc Jones | 81ef9c2 | 2021-01-21 10:53:47 -0700 | [diff] [blame] | 10 | #include <intelblocks/acpi.h> |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 11 | #include <intelblocks/lpc_lib.h> |
Andrey Petrov | 4e48ac0 | 2020-04-30 14:08:19 -0700 | [diff] [blame] | 12 | #include <intelblocks/p2sb.h> |
Jonathan Zhang | 3172f98 | 2020-05-28 17:53:48 -0700 | [diff] [blame] | 13 | #include <soc/acpi.h> |
Marc Jones | 1f50084 | 2020-10-15 14:32:51 -0600 | [diff] [blame] | 14 | #include <soc/chip_common.h> |
Arthur Heymans | 3d80253 | 2020-11-12 21:17:56 +0100 | [diff] [blame] | 15 | #include <soc/pch.h> |
Tim Chu | 13c4445 | 2022-11-25 10:31:00 +0000 | [diff] [blame] | 16 | #include <soc/soc_pch.h> |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 17 | #include <soc/ramstage.h> |
Arthur Heymans | 0f91e9c | 2020-10-16 13:15:50 +0200 | [diff] [blame] | 18 | #include <soc/p2sb.h> |
Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 19 | #include <soc/soc_util.h> |
Marc Jones | 5851f9d | 2020-11-02 15:30:10 -0700 | [diff] [blame] | 20 | #include <soc/util.h> |
Arthur Heymans | 0f91e9c | 2020-10-16 13:15:50 +0200 | [diff] [blame] | 21 | #include <soc/pci_devs.h> |
Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 22 | |
Marc Jones | b9365ef | 2020-10-11 15:00:36 -0600 | [diff] [blame] | 23 | /* UPD parameters to be initialized before SiliconInit */ |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 24 | void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd) |
| 25 | { |
Marc Jones | b9365ef | 2020-10-11 15:00:36 -0600 | [diff] [blame] | 26 | mainboard_silicon_init_params(silupd); |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Jonathan Zhang | 1ba42a9 | 2020-09-21 17:14:44 -0700 | [diff] [blame] | 29 | #if CONFIG(HAVE_ACPI_TABLES) |
Marc Jones | 81ef9c2 | 2021-01-21 10:53:47 -0700 | [diff] [blame] | 30 | const char *soc_acpi_name(const struct device *dev) |
Jonathan Zhang | 1ba42a9 | 2020-09-21 17:14:44 -0700 | [diff] [blame] | 31 | { |
| 32 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 33 | return "PC00"; |
| 34 | return NULL; |
| 35 | } |
| 36 | #endif |
| 37 | |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 38 | static struct device_operations pci_domain_ops = { |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 39 | .read_resources = iio_pci_domain_read_resources, |
| 40 | .set_resources = pci_domain_set_resources, |
| 41 | .scan_bus = iio_pci_domain_scan_bus, |
Jonathan Zhang | 1ba42a9 | 2020-09-21 17:14:44 -0700 | [diff] [blame] | 42 | #if CONFIG(HAVE_ACPI_TABLES) |
Jonathan Zhang | 3172f98 | 2020-05-28 17:53:48 -0700 | [diff] [blame] | 43 | .write_acpi_tables = &northbridge_write_acpi_tables, |
Jonathan Zhang | 1ba42a9 | 2020-09-21 17:14:44 -0700 | [diff] [blame] | 44 | .acpi_name = soc_acpi_name |
| 45 | #endif |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 48 | static struct device_operations cpu_bus_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 49 | .read_resources = noop_read_resources, |
| 50 | .set_resources = noop_set_resources, |
Arthur Heymans | 829e8e6 | 2023-01-30 19:09:34 +0100 | [diff] [blame] | 51 | .init = mp_cpu_bus_init, |
Jonathan Zhang | c110595 | 2020-06-03 15:55:28 -0700 | [diff] [blame] | 52 | .acpi_fill_ssdt = generate_cpu_entries, |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 55 | struct pci_operations soc_pci_ops = { |
| 56 | .set_subsystem = pci_dev_set_subsystem, |
| 57 | }; |
| 58 | |
Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 59 | static void chip_enable_dev(struct device *dev) |
| 60 | { |
| 61 | /* Set the operations if it is a special bus type */ |
| 62 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 63 | dev->ops = &pci_domain_ops; |
| 64 | attach_iio_stacks(dev); |
| 65 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 66 | dev->ops = &cpu_bus_ops; |
Michael Niewöhner | 8913b78 | 2020-12-11 22:13:44 +0100 | [diff] [blame] | 67 | } else if (dev->path.type == DEVICE_PATH_GPIO) { |
| 68 | block_gpio_enable(dev); |
Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Rocky Phagura | afefa50 | 2021-02-16 21:45:24 -0800 | [diff] [blame] | 72 | static void iio_write_mask(u16 bus, u16 dev, u8 func) |
| 73 | { |
| 74 | pci_devfn_t device = PCI_DEV(bus, dev, func); |
| 75 | u32 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG); |
| 76 | val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK); |
| 77 | pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val); |
| 78 | |
| 79 | val = pci_s_read_config32(device, RP_UNCERRMSK); |
| 80 | val |= (SURPRISE_DWN_ERR_MSK | UNSUPPORTED_REQ_ERR_MSK); |
| 81 | pci_s_write_config32(device, RP_UNCERRMSK, val); |
| 82 | } |
| 83 | |
| 84 | static void iio_dmi_en_masks(void) |
| 85 | { |
| 86 | pci_devfn_t device; |
| 87 | u32 val; |
| 88 | device = PCI_DEV(DMI_BUS_INDEX, DMI_DEV, DMI_FUNC); |
| 89 | val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG); |
| 90 | val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK); |
| 91 | pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val); |
| 92 | |
| 93 | val = pci_s_read_config32(device, DMI_UNCERRMSK); |
| 94 | val |= (ECRC_ERR | MLFRMD_TLP | RCV_BUF_OVRFLOW | FLOW_CNTR | POISON_TLP | DLL_PRT_ERR); |
| 95 | pci_s_write_config32(device, DMI_UNCERRMSK, val); |
| 96 | } |
| 97 | |
| 98 | static void iio_enable_masks(void) |
| 99 | { |
| 100 | struct iiostack_resource iio = {0}; |
| 101 | get_iiostack_info(&iio); |
| 102 | int i, k; |
| 103 | for (i = 0; i < iio.no_of_stacks; i++) { |
| 104 | const STACK_RES *st = &iio.res[i]; |
| 105 | if (st->BusBase > 0 && st->BusBase != 0xff) { |
| 106 | for (k = 0; k < DEVICES_PER_IIO_STACK; k++) { |
| 107 | printk(BIOS_DEBUG, "%s: bus:%x dev:%x func:%x\n", __func__, |
| 108 | st->BusBase, k, 0); |
| 109 | iio_write_mask(st->BusBase, k, 0); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | iio_dmi_en_masks(); |
| 114 | } |
Marc Jones | 4de7610 | 2021-03-12 14:36:48 -0700 | [diff] [blame] | 115 | |
| 116 | static void set_pcu_locks(void) |
| 117 | { |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 118 | for (uint32_t socket = 0; socket < CONFIG_MAX_SOCKET; ++socket) { |
| 119 | if (!soc_cpu_is_enabled(socket)) |
| 120 | continue; |
Marc Jones | 4de7610 | 2021-03-12 14:36:48 -0700 | [diff] [blame] | 121 | uint32_t bus = get_socket_stack_busno(socket, PCU_IIO_STACK); |
| 122 | |
| 123 | /* configure PCU_CR0_FUN csrs */ |
| 124 | const struct device *cr0_dev = PCU_DEV_CR0(bus); |
| 125 | pci_or_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS, P_STATE_LIMITS_LOCK); |
| 126 | pci_or_config32(cr0_dev, PCU_CR0_PACKAGE_RAPL_LIMIT_UPR, PKG_PWR_LIM_LOCK_UPR); |
Marc Jones | 4fad28f | 2021-04-01 14:47:52 -0600 | [diff] [blame] | 127 | pci_or_config32(cr0_dev, PCU_CR0_TURBO_ACTIVATION_RATIO, TURBO_ACTIVATION_RATIO_LOCK); |
| 128 | |
Marc Jones | 4de7610 | 2021-03-12 14:36:48 -0700 | [diff] [blame] | 129 | |
| 130 | /* configure PCU_CR1_FUN csrs */ |
| 131 | const struct device *cr1_dev = PCU_DEV_CR1(bus); |
| 132 | pci_or_config32(cr1_dev, PCU_CR1_SAPMCTL, SAPMCTL_LOCK_MASK); |
| 133 | |
| 134 | /* configure PCU_CR2_FUN csrs */ |
| 135 | const struct device *cr2_dev = PCU_DEV_CR2(bus); |
| 136 | pci_or_config32(cr2_dev, PCU_CR2_DRAM_PLANE_POWER_LIMIT, PP_PWR_LIM_LOCK); |
Marc Jones | 4fad28f | 2021-04-01 14:47:52 -0600 | [diff] [blame] | 137 | pci_or_config32(cr2_dev, PCU_CR2_DRAM_POWER_INFO_UPR, DRAM_POWER_INFO_LOCK_UPR); |
Marc Jones | 4de7610 | 2021-03-12 14:36:48 -0700 | [diff] [blame] | 138 | |
| 139 | /* configure PCU_CR3_FUN csrs */ |
| 140 | const struct device *cr3_dev = PCU_DEV_CR3(bus); |
| 141 | pci_or_config32(cr3_dev, PCU_CR3_CONFIG_TDP_CONTROL, TDP_LOCK); |
Marc Jones | 4fad28f | 2021-04-01 14:47:52 -0600 | [diff] [blame] | 142 | pci_or_config32(cr3_dev, PCU_CR3_FLEX_RATIO, OC_LOCK); |
Marc Jones | 4de7610 | 2021-03-12 14:36:48 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | } |
| 146 | |
Marc Jones | 456b7ba | 2021-04-15 16:24:54 -0600 | [diff] [blame] | 147 | static void set_imc_locks(void) |
| 148 | { |
| 149 | struct device *dev = 0; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 150 | while ((dev = dev_find_device(PCI_VID_INTEL, IMC_M2MEM_DEVID, dev))) |
Marc Jones | 456b7ba | 2021-04-15 16:24:54 -0600 | [diff] [blame] | 151 | pci_or_config32(dev, IMC_M2MEM_TIMEOUT, TIMEOUT_LOCK); |
| 152 | } |
| 153 | |
Marc Jones | b20d694 | 2021-04-15 16:25:49 -0600 | [diff] [blame] | 154 | static void set_upi_locks(void) |
| 155 | { |
| 156 | struct device *dev = 0; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 157 | while ((dev = dev_find_device(PCI_VID_INTEL, UPI_LL_CR_DEVID, dev))) |
Marc Jones | b20d694 | 2021-04-15 16:25:49 -0600 | [diff] [blame] | 158 | pci_or_config32(dev, UPI_LL_CR_KTIMISCMODLCK, KTIMISCMODLCK_LOCK); |
| 159 | } |
| 160 | |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 161 | static void chip_final(void *data) |
| 162 | { |
Arthur Heymans | 0f91e9c | 2020-10-16 13:15:50 +0200 | [diff] [blame] | 163 | /* Lock SBI */ |
| 164 | pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK); |
Arthur Heymans | 1918553 | 2020-10-27 17:40:22 +0100 | [diff] [blame] | 165 | |
| 166 | /* LOCK PAM */ |
| 167 | pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0); |
| 168 | |
Marc Jones | 4de7610 | 2021-03-12 14:36:48 -0700 | [diff] [blame] | 169 | set_pcu_locks(); |
Marc Jones | 456b7ba | 2021-04-15 16:24:54 -0600 | [diff] [blame] | 170 | set_imc_locks(); |
Marc Jones | b20d694 | 2021-04-15 16:25:49 -0600 | [diff] [blame] | 171 | set_upi_locks(); |
Marc Jones | 4de7610 | 2021-03-12 14:36:48 -0700 | [diff] [blame] | 172 | |
Andrey Petrov | 4e48ac0 | 2020-04-30 14:08:19 -0700 | [diff] [blame] | 173 | p2sb_hide(); |
Rocky Phagura | afefa50 | 2021-02-16 21:45:24 -0800 | [diff] [blame] | 174 | iio_enable_masks(); |
Jonathan Zhang | bea1980 | 2020-04-13 19:34:53 -0700 | [diff] [blame] | 175 | set_bios_init_completion(); |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static void chip_init(void *data) |
| 179 | { |
| 180 | printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n"); |
Kyösti Mälkki | cc93c6e | 2021-01-09 22:53:52 +0200 | [diff] [blame] | 181 | fsp_silicon_init(); |
Arthur Heymans | 3d80253 | 2020-11-12 21:17:56 +0100 | [diff] [blame] | 182 | override_hpet_ioapic_bdf(); |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 183 | pch_enable_ioapic(); |
Arthur Heymans | 8346307 | 2020-12-16 11:30:40 +0100 | [diff] [blame] | 184 | pch_lock_dmictl(); |
Andrey Petrov | 4e48ac0 | 2020-04-30 14:08:19 -0700 | [diff] [blame] | 185 | p2sb_unhide(); |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | struct chip_operations soc_intel_xeon_sp_cpx_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 189 | .name = "Intel Cooper Lake-SP", |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 190 | .enable_dev = chip_enable_dev, |
| 191 | .init = chip_init, |
Jonathan Zhang | 7919d61 | 2020-04-02 17:27:54 -0700 | [diff] [blame] | 192 | .final = chip_final, |
Andrey Petrov | 2e41075 | 2020-03-20 12:08:32 -0700 | [diff] [blame] | 193 | }; |