From 92226dc6c3a769c0ba107b002ae05aee907b14e2 Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Thu, 9 Dec 2021 12:16:39 +0100 Subject: [PATCH] soc/intel/{skylake/cannonlake}: Fix bug in vr_config The `cpu_get_power_max()` function returns the TDP in milliwatts, but the vr_config code interprets the value in watts. Divide the value by 1000 to fix this. This also fixes an integer overflow when `cpu_get_power_max()` returns a value greater than 65535 (UINT16_MAX). Change-Id: Ibe9e0db6762eee5cc363f8b371c8538eb92f6308 Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/60001 Tested-by: build bot (Jenkins) Reviewed-by: Arthur Heymans Reviewed-by: Felix Singer --- src/soc/intel/cannonlake/vr_config.c | 2 +- src/soc/intel/skylake/vr_config.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/soc/intel/cannonlake/vr_config.c b/src/soc/intel/cannonlake/vr_config.c index 744564bfa7..7ba73eac3f 100644 --- a/src/soc/intel/cannonlake/vr_config.c +++ b/src/soc/intel/cannonlake/vr_config.c @@ -619,7 +619,7 @@ void fill_vr_domain_config(void *params, FSP_S_CONFIG *vr_params = (FSP_S_CONFIG *)params; const struct vr_config *cfg; static uint16_t mch_id = 0, igd_id = 0; - const uint16_t tdp = cpu_get_power_max(); + const uint16_t tdp = cpu_get_power_max() / 1000; if (!mch_id) { struct device *dev = pcidev_path_on_root(SA_DEVFN_ROOT); diff --git a/src/soc/intel/skylake/vr_config.c b/src/soc/intel/skylake/vr_config.c index d72fa1fdc9..b807f54be3 100644 --- a/src/soc/intel/skylake/vr_config.c +++ b/src/soc/intel/skylake/vr_config.c @@ -62,7 +62,7 @@ static const struct vr_config default_configs[NUM_VR_DOMAINS] = { static uint16_t get_sku_icc_max(int domain) { - const uint16_t tdp = cpu_get_power_max(); + const uint16_t tdp = cpu_get_power_max() / 1000; static uint16_t mch_id = 0, igd_id = 0; if (!mch_id) {