<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body ><div>Yeah, saw that too but was too ashamed... anyway it needs fixing. And apparently the docs are wrong on this anyway and 11 indicates 1333, while 0 or 1 is 800. Will post an updated one. </div><div><br></div><div><br></div>--<div>Jesse Barnes, Intel Open Source Technology Center</div> <br><br><br>-------- Original message --------<br>From: Kenneth Graunke <kenneth@whitecape.org> <br>Date: 05/01/2013 6:38 PM (GMT-08:00) <br>To: Ben Widawsky <ben@bwidawsk.net> <br>Cc: Jesse Barnes <jbarnes@virtuousgeek.org>,intel-gfx@lists.freedesktop.org <br>Subject: Re: [Intel-gfx] [PATCH 3/3] drm/i915: go back to switch for VLV mem freq detection <br> <br><br>On 05/01/2013 06:26 PM, Ben Widawsky wrote:<br>> On Wed, May 01, 2013 at 04:09:22PM -0700, Jesse Barnes wrote:<br>>> We need to catch the invalid case and override it.<br>>><br>>> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org><br><br>Jesse, it's actually worse than that:<br><br>Your parenthesis were off in the previous version, causing it to do the <br>multiplication by 266 before the bitwise-and:<br><br> 800 + ((266 * (val >> 6)) & 3)<br><br>This meant that you always got 800 or 802 Mhz.<br><br>Also, even when corrected, your previous formula would return 1332 Mhz <br>instead of 1333 Mhz, which is slightly off and doesn't work since you <br>use it in explicit switch statements.<br><br>It might be worth mentioning in the commit message.<br><br>>> ---<br>>> drivers/gpu/drm/i915/intel_pm.c | 16 +++++++++++++++-<br>>> 1 file changed, 15 insertions(+), 1 deletion(-)<br>>><br>>> diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c<br>>> index 0f4b46e..0a3b0b3 100644<br>>> --- a/drivers/gpu/drm/i915/intel_pm.c<br>>> +++ b/drivers/gpu/drm/i915/intel_pm.c<br>>> @@ -2902,7 +2902,21 @@ static void valleyview_enable_rps(struct drm_device *dev)<br>>> GEN7_RC_CTL_TO_MODE);<br>>><br>>> valleyview_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS, &val);<br>>> - dev_priv->mem_freq = 800 + (266 * (val >> 6) & 3);<br>>> + switch ((val >> 6) & 3) {<br>>> + case 0:<br>>> + dev_priv->mem_freq = 800;<br>>> + break;<br>>> + case 1:<br>>> + dev_priv->mem_freq = 1066;<br>>> + break;<br>>> + case 2:<br>>> + dev_priv->mem_freq = 1333;<br>>> + break;<br>>> + case 3:<br>>> + DRM_ERROR("invalid mem freq, assuming 800MHz\n");<br>>> + dev_priv->mem_freq = 800;<br>>> + break;<br>>> + }<br>>> DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq);<br>>><br>>> DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no");<br>><br>><br>> I guess it doesn't handle the last case, but:<br>> dev_priv->mem_freq = 800 + (266 * (val))) + val/2<br><br>Don't use this method. Presumably Ben meant (val >> 6) here, but even <br>with that fix this formula returns 1067 rather than 1066, which is wrong.<br><br>> or<br>><br>> u32 freqs[] = {800,1066,1333,800};<br>> dev_priv->mem_freq = freqs[(val >> 6) & 3];<br><br>I like this table based approach best. It's much more succinct than the <br>switch statement, and exact. Might be worth preserving the DRM_ERROR.<br><br>> Are two ways I would have used before making a switch block :P<br>><br>> Just a thought, but perhaps we don't want to enable RPS if we can't<br>> reliably figure out the memory freq. (case 3)<br>><br>> Reviewed-by: Ben Widawsky <ben@bwidawsk.net><br><br>For either the switch or Ben's table:<br>Reviewed-by: Kenneth Graunke <kenneth@whitecape.org><br><br>Incidentally, my Punit returns 3 here, but I believe the memory is <br>actually 1066. Not sure what the deal is.<br><br>--Ken<br><br></body>