From 7519ca42b53201083ec763058dadd8fdb2050f80 Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Tue, 12 Jan 2021 01:21:24 +0100 Subject: nb/intel/sandybridge: Clarify command timing calculation Command timing is the absolute value of the most negative `pi_coding` value across all ranks, or zero if there are no negative values. Use the MAX() macro to ease proving that `cmd_delay` can never be negative, and then drop the always-false underflow check. The variable type for `cmd_delay` still needs to be signed because of the comparisons with `pi_coding`, which is a signed value. Using an unsigned type would result in undefined and also undesired behavior. Change-Id: I714d3cf57d0f62376a1107af63bcd761f952bc3a Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/49320 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- src/northbridge/intel/sandybridge/raminit_common.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/northbridge/intel') diff --git a/src/northbridge/intel/sandybridge/raminit_common.c b/src/northbridge/intel/sandybridge/raminit_common.c index f766867965..cef01316dc 100644 --- a/src/northbridge/intel/sandybridge/raminit_common.c +++ b/src/northbridge/intel/sandybridge/raminit_common.c @@ -938,16 +938,11 @@ void program_timings(ramctr_timing *ctrl, int channel) u32 clk_logic_dly = 0; /* - * Apply command delay if desired setting is negative. Find the - * most negative value: 'cmd_delay' will be the absolute value. + * Compute command timing as abs() of the most negative PI code + * across all ranks. Use zero if none of the values is negative. */ FOR_ALL_POPULATED_RANKS { - if (cmd_delay < -ctrl->timings[channel][slotrank].pi_coding) - cmd_delay = -ctrl->timings[channel][slotrank].pi_coding; - } - if (cmd_delay < 0) { - printk(BIOS_ERR, "C%d command delay underflow: %d\n", channel, cmd_delay); - cmd_delay = 0; + cmd_delay = MAX(cmd_delay, -ctrl->timings[channel][slotrank].pi_coding); } if (cmd_delay > CCC_MAX_PI) { printk(BIOS_ERR, "C%d command delay overflow: %d\n", channel, cmd_delay); -- cgit v1.2.3