blob: 7862dfe246836bc15409746a4e971bb0d25922ab [file] [log] [blame]
Tarun Tuli537213a2023-03-29 13:18:43 +00001/* 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
12WEAK_DEV_PTR(dptf_policy);
13
Seunghwan Kim2cb83122024-03-25 08:57:09 +090014static 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 Tuli537213a2023-03-29 13:18:43 +000039void variant_update_power_limits(const struct cpu_power_limits *limits, size_t num_entries)
40{
41 if (!num_entries)
42 return;
43
Seunghwan Kim2cb83122024-03-25 08:57:09 +090044 struct soc_power_limits_config *soc_config = get_soc_power_limit_config();
45 if (!soc_config)
46 return;
47
Tarun Tuli537213a2023-03-29 13:18:43 +000048 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 Tuli537213a2023-03-29 13:18:43 +000061 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 Kim2cb83122024-03-25 08:57:09 +090066 MILLIWATTS_TO_WATTS);
Tarun Tuli537213a2023-03-29 13:18:43 +000067 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}