From patchwork Fri Jun 14 04:25:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Golani, Mitulkumar Ajitkumar" X-Patchwork-Id: 13697864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 795C8C27C6E for ; Fri, 14 Jun 2024 04:26:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5534F10EC1B; Fri, 14 Jun 2024 04:26:01 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="mLxAbu0S"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id A21C310EC1D; Fri, 14 Jun 2024 04:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718339156; x=1749875156; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lrgk9n6nepoKyXCF6DFOP2mNFLE1mOcFS0wZHogcQMs=; b=mLxAbu0StNuZakrL2PdES8W/DrGDjQwbGyE6+whkizgRbyMC2o6qmN/l M3DYYVYJZiLahlrESxpEqVNMMiJ3Qfj0pr0kp6N0olTUNi9Sbu5/H4br1 2rnMoSF0h/Vc21RAz+h9Y8OCavMvL/q/N+E1JlxtHsiDWQnigrORBO37T 0NpWMODWd5azSxkMv11oZnz/bFHm+9GRitfBz8vdjXifLAyikEPsv+Ash 7DuIETxj7baer8qyFkufFfntyLQMd+cPr4D6Sl5AjhUjKqWRBx/ZUn1Ye ueE9q4SksiojTyE7cKagkOsqpHjsGvJu4m7pnPteEFq/MUw85TZzBt08P A==; X-CSE-ConnectionGUID: hlv7j4BMQ4ilvn7hfkK/Pw== X-CSE-MsgGUID: u8GmVvxSSJSPvRoN/iipEw== X-IronPort-AV: E=McAfee;i="6700,10204,11102"; a="37731526" X-IronPort-AV: E=Sophos;i="6.08,236,1712646000"; d="scan'208";a="37731526" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2024 21:25:54 -0700 X-CSE-ConnectionGUID: hI4hfTIvSCuqj5F8/MTLLQ== X-CSE-MsgGUID: 17UBm4znQmm8d9ojk9e2mg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,236,1712646000"; d="scan'208";a="40343373" Received: from mgolanimitul-x299-ud4-pro.iind.intel.com ([10.190.239.114]) by fmviesa008.fm.intel.com with ESMTP; 13 Jun 2024 21:25:51 -0700 From: Mitul Golani To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: mitulkumar.ajitkumar.golani@intel.com, ankit.k.nautiyal@intel.com, suraj.kandpal@intel.com, jani.nikula@linux.intel.com, sfr@canb.auug.org.au, lucas.demarchi@intel.com Subject: [PATCH v2 2/2] drm/i915/display: Update calculation to avoid overflow Date: Fri, 14 Jun 2024 09:55:58 +0530 Message-ID: <20240614042558.376983-3-mitulkumar.ajitkumar.golani@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614042558.376983-1-mitulkumar.ajitkumar.golani@intel.com> References: <20240614042558.376983-1-mitulkumar.ajitkumar.golani@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Update calculation to avoid overflow. -v2: Remove extra line from commit message.(Lucas) Fixes: 1676ecd303ac ("drm/i915: Compute CMRR and calculate vtotal") Cc: Mitul Golani Cc: Ankit Nautiyal Cc: Suraj Kandpal Cc: Jani Nikula Cc: Stephen Rothwell Signed-off-by: Mitul Golani Reviewed-by: Ankit Nautiyal --- drivers/gpu/drm/i915/display/intel_vrr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_vrr.c b/drivers/gpu/drm/i915/display/intel_vrr.c index eb5b62b54d32..6430da25957d 100644 --- a/drivers/gpu/drm/i915/display/intel_vrr.c +++ b/drivers/gpu/drm/i915/display/intel_vrr.c @@ -147,10 +147,11 @@ cmrr_get_vtotal(struct intel_crtc_state *crtc_state, bool video_mode_required) multiplier_n = 1000; } - crtc_state->cmrr.cmrr_n = - desired_refresh_rate * adjusted_mode->crtc_htotal * multiplier_n; - vtotal = (adjusted_mode->crtc_clock * 1000 * multiplier_n) / crtc_state->cmrr.cmrr_n; - adjusted_pixel_rate = adjusted_mode->crtc_clock * 1000 * multiplier_m; + crtc_state->cmrr.cmrr_n = mul_u32_u32(desired_refresh_rate * adjusted_mode->crtc_htotal, + multiplier_n); + vtotal = DIV_ROUND_UP_ULL(mul_u32_u32(adjusted_mode->crtc_clock * 1000, multiplier_n), + crtc_state->cmrr.cmrr_n); + adjusted_pixel_rate = mul_u32_u32(adjusted_mode->crtc_clock * 1000, multiplier_m); crtc_state->cmrr.cmrr_m = do_div(adjusted_pixel_rate, crtc_state->cmrr.cmrr_n); return vtotal;