Tarun Tuli | 537213a | 2023-03-29 13:18:43 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpi_device.h> |
| 4 | #include <baseboard/variants.h> |
| 5 | #include <console/console.h> |
| 6 | #include <device/pci_ops.h> |
| 7 | #include <soc/pci_devs.h> |
| 8 | |
| 9 | #include <drivers/intel/dptf/chip.h> |
| 10 | #include <intelblocks/power_limit.h> |
| 11 | |
| 12 | WEAK_DEV_PTR(dptf_policy); |
| 13 | |
Seunghwan Kim | 2cb8312 | 2024-03-25 08:57:09 +0900 | [diff] [blame^] | 14 | static struct soc_power_limits_config *get_soc_power_limit_config(void) |
| 15 | { |
| 16 | config_t *config = config_of_soc(); |
| 17 | size_t i; |
| 18 | struct device *sa = pcidev_path_on_root(SA_DEVFN_ROOT); |
| 19 | uint16_t sa_pci_id; |
| 20 | u8 tdp; |
| 21 | |
| 22 | if (!sa) |
| 23 | return NULL; |
| 24 | |
| 25 | sa_pci_id = pci_read_config16(sa, PCI_DEVICE_ID); |
| 26 | |
| 27 | tdp = get_cpu_tdp(); |
| 28 | |
| 29 | for (i = 0; i < ARRAY_SIZE(cpuid_to_adl); i++) { |
| 30 | if (sa_pci_id == cpuid_to_adl[i].cpu_id && |
| 31 | tdp == cpuid_to_adl[i].cpu_tdp) { |
| 32 | return &config->power_limits_config[cpuid_to_adl[i].limits]; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | return NULL; |
| 37 | } |
| 38 | |
Tarun Tuli | 537213a | 2023-03-29 13:18:43 +0000 | [diff] [blame] | 39 | void variant_update_power_limits(const struct cpu_power_limits *limits, size_t num_entries) |
| 40 | { |
| 41 | if (!num_entries) |
| 42 | return; |
| 43 | |
Seunghwan Kim | 2cb8312 | 2024-03-25 08:57:09 +0900 | [diff] [blame^] | 44 | struct soc_power_limits_config *soc_config = get_soc_power_limit_config(); |
| 45 | if (!soc_config) |
| 46 | return; |
| 47 | |
Tarun Tuli | 537213a | 2023-03-29 13:18:43 +0000 | [diff] [blame] | 48 | const struct device *policy_dev = DEV_PTR(dptf_policy); |
| 49 | if (!policy_dev) |
| 50 | return; |
| 51 | |
| 52 | struct drivers_intel_dptf_config *config = policy_dev->chip_info; |
| 53 | |
| 54 | uint16_t mchid = pci_s_read_config16(PCI_DEV(0, 0, 0), PCI_DEVICE_ID); |
| 55 | |
| 56 | u8 tdp = get_cpu_tdp(); |
| 57 | |
| 58 | for (size_t i = 0; i < num_entries; i++) { |
| 59 | if (mchid == limits[i].mchid && tdp == limits[i].cpu_tdp) { |
| 60 | struct dptf_power_limits *settings = &config->controls.power_limits; |
Tarun Tuli | 537213a | 2023-03-29 13:18:43 +0000 | [diff] [blame] | 61 | settings->pl1.min_power = limits[i].pl1_min_power; |
| 62 | settings->pl1.max_power = limits[i].pl1_max_power; |
| 63 | settings->pl2.min_power = limits[i].pl2_min_power; |
| 64 | settings->pl2.max_power = limits[i].pl2_max_power; |
| 65 | soc_config->tdp_pl4 = DIV_ROUND_UP(limits[i].pl4_power, |
Seunghwan Kim | 2cb8312 | 2024-03-25 08:57:09 +0900 | [diff] [blame^] | 66 | MILLIWATTS_TO_WATTS); |
Tarun Tuli | 537213a | 2023-03-29 13:18:43 +0000 | [diff] [blame] | 67 | printk(BIOS_INFO, "Overriding power limits PL1 (%u, %u) PL2 (%u, %u) PL4 (%u)\n", |
| 68 | limits[i].pl1_min_power, |
| 69 | limits[i].pl1_max_power, |
| 70 | limits[i].pl2_min_power, |
| 71 | limits[i].pl2_max_power, |
| 72 | limits[i].pl4_power); |
| 73 | } |
| 74 | } |
| 75 | } |