From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <intel-gfx-bounces@lists.freedesktop.org>
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 60B48C4332F
	for <intel-gfx@archiver.kernel.org>; Thu, 15 Dec 2022 18:44:30 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
	by gabe.freedesktop.org (Postfix) with ESMTP id CD9DF10E4DC;
	Thu, 15 Dec 2022 18:44:17 +0000 (UTC)
Received: from mga05.intel.com (mga05.intel.com [192.55.52.43])
 by gabe.freedesktop.org (Postfix) with ESMTPS id B178D10E4D3;
 Thu, 15 Dec 2022 18:44:13 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1671129853; x=1702665853;
 h=from:to:cc:subject:date:message-id:mime-version:
 content-transfer-encoding;
 bh=86vO0KLZMv7KO84HkROPRiSKu/hJwzd8f8pHk2y9gNQ=;
 b=XbqWLb97KBs2QcwES0EVof/WWHBlzJOhMwvK+MFfVnd8nA00l0zt/p32
 aPBWGrXHq+oQS88MR5vHRlup5iUX2zu4epbfE3QNImXq4JKbG5m+tJxcC
 zhg7hLwKOXRDphIiF++ePp02ovY61czIIkb6t7uukgl72TOXK1SLInKQp
 I2PjyNy3o6v/HCxrLKSiTFPjpLH13ES66FwOHSOcIoQBKSc3fBQ6TaYms
 tdgrZYJ+rnodnPhqiXqQ+cen16mRuaY5cQaP1nqZFX08lfiy5gCco3dpB
 NhT9QxUlQTtkkNQtGUf4ViOIdomtcKeVCzEiEDZlqERF84Zy4igR6A5HH A==;
X-IronPort-AV: E=McAfee;i="6500,9779,10562"; a="405028888"
X-IronPort-AV: E=Sophos;i="5.96,248,1665471600"; d="scan'208";a="405028888"
Received: from orsmga002.jf.intel.com ([10.7.209.21])
 by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 15 Dec 2022 10:44:13 -0800
X-IronPort-AV: E=McAfee;i="6500,9779,10562"; a="649537880"
X-IronPort-AV: E=Sophos;i="5.96,248,1665471600"; d="scan'208";a="649537880"
Received: from unerlige-ril.jf.intel.com ([10.165.21.138])
 by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 15 Dec 2022 10:44:12 -0800
From: Ashutosh Dixit <ashutosh.dixit@intel.com>
To: intel-gfx@lists.freedesktop.org
Date: Thu, 15 Dec 2022 10:44:09 -0800
Message-Id: <20221215184409.2467595-1-ashutosh.dixit@intel.com>
X-Mailer: git-send-email 2.38.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [Intel-gfx] [PATCH] drm/i915/hwmon: Display clamped PL1 limit
X-BeenThere: intel-gfx@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Intel graphics driver community testing & development
 <intel-gfx.lists.freedesktop.org>
List-Unsubscribe: <https://lists.freedesktop.org/mailman/options/intel-gfx>,
 <mailto:intel-gfx-request@lists.freedesktop.org?subject=unsubscribe>
List-Archive: <https://lists.freedesktop.org/archives/intel-gfx>
List-Post: <mailto:intel-gfx@lists.freedesktop.org>
List-Help: <mailto:intel-gfx-request@lists.freedesktop.org?subject=help>
List-Subscribe: <https://lists.freedesktop.org/mailman/listinfo/intel-gfx>,
 <mailto:intel-gfx-request@lists.freedesktop.org?subject=subscribe>
Cc: dri-devel@lists.freedesktop.org
Errors-To: intel-gfx-bounces@lists.freedesktop.org
Sender: "Intel-gfx" <intel-gfx-bounces@lists.freedesktop.org>

HW allows arbitrary PL1 limits to be set but silently clamps these values
to "typical but not guaranteed" min/max values in pkg_power_sku
register. Follow the same pattern for sysfs, allow arbitrary PL1 limits to
be set but display clamped values when read.

Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
---
 drivers/gpu/drm/i915/i915_hwmon.c        | 39 ++++++++++++++++++++----
 drivers/gpu/drm/i915/intel_mchbar_regs.h |  2 ++
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
index cca7a4350ec8f..1225bc432f0d5 100644
--- a/drivers/gpu/drm/i915/i915_hwmon.c
+++ b/drivers/gpu/drm/i915/i915_hwmon.c
@@ -359,6 +359,38 @@ hwm_power_is_visible(const struct hwm_drvdata *ddat, u32 attr, int chan)
 	}
 }
 
+/*
+ * HW allows arbitrary PL1 limits to be set but silently clamps these values to
+ * "typical but not guaranteed" min/max values in rg.pkg_power_sku. Follow the
+ * same pattern for sysfs, allow arbitrary PL1 limits to be set but display
+ * clamped values when read. Write/read I1 also follows the same pattern.
+ */
+static int
+hwm_power_max_read(struct hwm_drvdata *ddat, long *val)
+{
+	struct i915_hwmon *hwmon = ddat->hwmon;
+	intel_wakeref_t wakeref;
+	u64 r, min, max;
+
+	*val = hwm_field_read_and_scale(ddat,
+					hwmon->rg.pkg_rapl_limit,
+					PKG_PWR_LIM_1,
+					hwmon->scl_shift_power,
+					SF_POWER);
+
+	with_intel_runtime_pm(ddat->uncore->rpm, wakeref)
+		r = intel_uncore_read64(ddat->uncore, hwmon->rg.pkg_power_sku);
+	min = REG_FIELD_GET(PKG_MIN_PWR, r);
+	min = mul_u64_u32_shr(min, SF_POWER, hwmon->scl_shift_power);
+	max = REG_FIELD_GET(PKG_MAX_PWR, r);
+	max = mul_u64_u32_shr(max, SF_POWER, hwmon->scl_shift_power);
+
+	if (min && max)
+		*val = clamp_t(u64, *val, min, max);
+
+	return 0;
+}
+
 static int
 hwm_power_read(struct hwm_drvdata *ddat, u32 attr, int chan, long *val)
 {
@@ -368,12 +400,7 @@ hwm_power_read(struct hwm_drvdata *ddat, u32 attr, int chan, long *val)
 
 	switch (attr) {
 	case hwmon_power_max:
-		*val = hwm_field_read_and_scale(ddat,
-						hwmon->rg.pkg_rapl_limit,
-						PKG_PWR_LIM_1,
-						hwmon->scl_shift_power,
-						SF_POWER);
-		return 0;
+		return hwm_power_max_read(ddat, val);
 	case hwmon_power_rated_max:
 		*val = hwm_field_read_and_scale(ddat,
 						hwmon->rg.pkg_power_sku,
diff --git a/drivers/gpu/drm/i915/intel_mchbar_regs.h b/drivers/gpu/drm/i915/intel_mchbar_regs.h
index f93e9af43ac35..73900c098d591 100644
--- a/drivers/gpu/drm/i915/intel_mchbar_regs.h
+++ b/drivers/gpu/drm/i915/intel_mchbar_regs.h
@@ -194,6 +194,8 @@
  */
 #define PCU_PACKAGE_POWER_SKU			_MMIO(MCHBAR_MIRROR_BASE_SNB + 0x5930)
 #define   PKG_PKG_TDP				GENMASK_ULL(14, 0)
+#define   PKG_MIN_PWR				GENMASK_ULL(30, 16)
+#define   PKG_MAX_PWR				GENMASK_ULL(46, 32)
 #define   PKG_MAX_WIN				GENMASK_ULL(54, 48)
 #define     PKG_MAX_WIN_X			GENMASK_ULL(54, 53)
 #define     PKG_MAX_WIN_Y			GENMASK_ULL(52, 48)
-- 
2.38.0


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <intel-gfx-bounces@lists.freedesktop.org>
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 9928FC4332F
	for <intel-gfx@archiver.kernel.org>; Thu, 15 Dec 2022 18:48:39 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
	by gabe.freedesktop.org (Postfix) with ESMTP id 4633E10E4D3;
	Thu, 15 Dec 2022 18:48:32 +0000 (UTC)
Received: from mga04.intel.com (mga04.intel.com [192.55.52.120])
 by gabe.freedesktop.org (Postfix) with ESMTPS id CED7510E4D3;
 Thu, 15 Dec 2022 18:48:26 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1671130106; x=1702666106;
 h=from:to:cc:subject:in-reply-to:references:date:
 message-id:mime-version;
 bh=ogspCvicFhhzdkF7v9AuTncGKWm32X+u+8OosTh5eL4=;
 b=kGPtBf5XS/BKS+F9kzlOpKaSFhfF9V8B4vvJJjbbbeGzTze2Po8wmfyd
 CKoH2awW/zA06cJcbCigDDPUGzGGZDUQzrBVutizki5ryyNoG2ZvaOZuI
 ZN5OaNOSuajUg7U3n9VgyrPmPIOYaXBeEEtvbMU3f3OWmVhV0nITtqdOt
 LBasB82bpAdr0GL/ZnpIEctjAgQnbEnxoJGquqrDuSB6i2EsOnti5k/9/
 jlIRbknxdGOdPfqVMepdDXEnmffRT3Bzg3/9CQp8PEJmfT+ZF8C4qJbtU
 LA6PV+uuls7aXX22GQd+koKkqigoJoaDoGa5+qO9dz5M96BEm3Bq2xKNV w==;
X-IronPort-AV: E=McAfee;i="6500,9779,10562"; a="317470496"
X-IronPort-AV: E=Sophos;i="5.96,248,1665471600"; d="scan'208";a="317470496"
Received: from fmsmga006.fm.intel.com ([10.253.24.20])
 by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 15 Dec 2022 10:48:26 -0800
X-IronPort-AV: E=McAfee;i="6500,9779,10562"; a="894889082"
X-IronPort-AV: E=Sophos;i="5.96,248,1665471600"; d="scan'208";a="894889082"
Received: from popovaan-mobl2.ger.corp.intel.com (HELO localhost)
 ([10.252.59.139])
 by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 15 Dec 2022 10:48:24 -0800
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Ashutosh Dixit <ashutosh.dixit@intel.com>, intel-gfx@lists.freedesktop.org
In-Reply-To: <20221215184409.2467595-1-ashutosh.dixit@intel.com>
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
References: <20221215184409.2467595-1-ashutosh.dixit@intel.com>
Date: Thu, 15 Dec 2022 20:48:21 +0200
Message-ID: <87bko4v6yy.fsf@intel.com>
MIME-Version: 1.0
Content-Type: text/plain
Subject: Re: [Intel-gfx] [PATCH] drm/i915/hwmon: Display clamped PL1 limit
X-BeenThere: intel-gfx@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Intel graphics driver community testing & development
 <intel-gfx.lists.freedesktop.org>
List-Unsubscribe: <https://lists.freedesktop.org/mailman/options/intel-gfx>,
 <mailto:intel-gfx-request@lists.freedesktop.org?subject=unsubscribe>
List-Archive: <https://lists.freedesktop.org/archives/intel-gfx>
List-Post: <mailto:intel-gfx@lists.freedesktop.org>
List-Help: <mailto:intel-gfx-request@lists.freedesktop.org?subject=help>
List-Subscribe: <https://lists.freedesktop.org/mailman/listinfo/intel-gfx>,
 <mailto:intel-gfx-request@lists.freedesktop.org?subject=subscribe>
Cc: dri-devel@lists.freedesktop.org
Errors-To: intel-gfx-bounces@lists.freedesktop.org
Sender: "Intel-gfx" <intel-gfx-bounces@lists.freedesktop.org>

On Thu, 15 Dec 2022, Ashutosh Dixit <ashutosh.dixit@intel.com> wrote:
> HW allows arbitrary PL1 limits to be set but silently clamps these values
> to "typical but not guaranteed" min/max values in pkg_power_sku
> register. Follow the same pattern for sysfs, allow arbitrary PL1 limits to
> be set but display clamped values when read.

The commit message lacks the most important thing: why?


BR,
Jani.

>
> Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_hwmon.c        | 39 ++++++++++++++++++++----
>  drivers/gpu/drm/i915/intel_mchbar_regs.h |  2 ++
>  2 files changed, 35 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
> index cca7a4350ec8f..1225bc432f0d5 100644
> --- a/drivers/gpu/drm/i915/i915_hwmon.c
> +++ b/drivers/gpu/drm/i915/i915_hwmon.c
> @@ -359,6 +359,38 @@ hwm_power_is_visible(const struct hwm_drvdata *ddat, u32 attr, int chan)
>  	}
>  }
>  
> +/*
> + * HW allows arbitrary PL1 limits to be set but silently clamps these values to
> + * "typical but not guaranteed" min/max values in rg.pkg_power_sku. Follow the
> + * same pattern for sysfs, allow arbitrary PL1 limits to be set but display
> + * clamped values when read. Write/read I1 also follows the same pattern.
> + */
> +static int
> +hwm_power_max_read(struct hwm_drvdata *ddat, long *val)
> +{
> +	struct i915_hwmon *hwmon = ddat->hwmon;
> +	intel_wakeref_t wakeref;
> +	u64 r, min, max;
> +
> +	*val = hwm_field_read_and_scale(ddat,
> +					hwmon->rg.pkg_rapl_limit,
> +					PKG_PWR_LIM_1,
> +					hwmon->scl_shift_power,
> +					SF_POWER);
> +
> +	with_intel_runtime_pm(ddat->uncore->rpm, wakeref)
> +		r = intel_uncore_read64(ddat->uncore, hwmon->rg.pkg_power_sku);
> +	min = REG_FIELD_GET(PKG_MIN_PWR, r);
> +	min = mul_u64_u32_shr(min, SF_POWER, hwmon->scl_shift_power);
> +	max = REG_FIELD_GET(PKG_MAX_PWR, r);
> +	max = mul_u64_u32_shr(max, SF_POWER, hwmon->scl_shift_power);
> +
> +	if (min && max)
> +		*val = clamp_t(u64, *val, min, max);
> +
> +	return 0;
> +}
> +
>  static int
>  hwm_power_read(struct hwm_drvdata *ddat, u32 attr, int chan, long *val)
>  {
> @@ -368,12 +400,7 @@ hwm_power_read(struct hwm_drvdata *ddat, u32 attr, int chan, long *val)
>  
>  	switch (attr) {
>  	case hwmon_power_max:
> -		*val = hwm_field_read_and_scale(ddat,
> -						hwmon->rg.pkg_rapl_limit,
> -						PKG_PWR_LIM_1,
> -						hwmon->scl_shift_power,
> -						SF_POWER);
> -		return 0;
> +		return hwm_power_max_read(ddat, val);
>  	case hwmon_power_rated_max:
>  		*val = hwm_field_read_and_scale(ddat,
>  						hwmon->rg.pkg_power_sku,
> diff --git a/drivers/gpu/drm/i915/intel_mchbar_regs.h b/drivers/gpu/drm/i915/intel_mchbar_regs.h
> index f93e9af43ac35..73900c098d591 100644
> --- a/drivers/gpu/drm/i915/intel_mchbar_regs.h
> +++ b/drivers/gpu/drm/i915/intel_mchbar_regs.h
> @@ -194,6 +194,8 @@
>   */
>  #define PCU_PACKAGE_POWER_SKU			_MMIO(MCHBAR_MIRROR_BASE_SNB + 0x5930)
>  #define   PKG_PKG_TDP				GENMASK_ULL(14, 0)
> +#define   PKG_MIN_PWR				GENMASK_ULL(30, 16)
> +#define   PKG_MAX_PWR				GENMASK_ULL(46, 32)
>  #define   PKG_MAX_WIN				GENMASK_ULL(54, 48)
>  #define     PKG_MAX_WIN_X			GENMASK_ULL(54, 53)
>  #define     PKG_MAX_WIN_Y			GENMASK_ULL(52, 48)

-- 
Jani Nikula, Intel Open Source Graphics Center

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <intel-gfx-bounces@lists.freedesktop.org>
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 39D20C4332F
	for <intel-gfx@archiver.kernel.org>; Thu, 15 Dec 2022 19:17:38 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
	by gabe.freedesktop.org (Postfix) with ESMTP id 2D80810E513;
	Thu, 15 Dec 2022 19:17:36 +0000 (UTC)
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by gabe.freedesktop.org (Postfix) with ESMTPS id E7C4E10E513;
 Thu, 15 Dec 2022 19:17:32 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1671131852; x=1702667852;
 h=from:to:cc:subject:date:message-id:mime-version:
 content-transfer-encoding;
 bh=iou9Wrf5DCw6IIbHC+yc4W2bLgksXdyaZPYkluAot44=;
 b=Sbk70tqXuGqOX+SFnJpD299QkwWo5qDapWRACvzKXanY4qnTokCRtIxd
 XykIXcx8hmzNW3P0FyX52aLZjZxv6cSRR+Tc+TbB+/yFHnLRCwM2f6eK/
 MqiYwvdNUAd4Ge9NDhHg8TGJVGKHlOocQJbE4Zzwa+NVK1B2CaB/PE4Sj
 Xw+0QOdZ/AMkbB0s31WyxrR43h37AiHy6A0jSRpCHHdJjnf0QKlPdZWVZ
 gExlgDh/BTpvj3bPoG5m7zO044WzVWd3ZGvJ++HJoXGahT3m+jIE4RJ91
 xDl+dw5K2WYjy7lqpiQx3+n42pkPf5ZgbHNIGPeKTdC7AWd2qwnLu0u3Z Q==;
X-IronPort-AV: E=McAfee;i="6500,9779,10562"; a="306443436"
X-IronPort-AV: E=Sophos;i="5.96,248,1665471600"; d="scan'208";a="306443436"
Received: from fmsmga003.fm.intel.com ([10.253.24.29])
 by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 15 Dec 2022 11:17:31 -0800
X-IronPort-AV: E=McAfee;i="6500,9779,10562"; a="738265323"
X-IronPort-AV: E=Sophos;i="5.96,248,1665471600"; d="scan'208";a="738265323"
Received: from unerlige-ril.jf.intel.com ([10.165.21.138])
 by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 15 Dec 2022 11:17:31 -0800
From: Ashutosh Dixit <ashutosh.dixit@intel.com>
To: intel-gfx@lists.freedesktop.org
Date: Thu, 15 Dec 2022 11:17:27 -0800
Message-Id: <20221215191727.2468770-1-ashutosh.dixit@intel.com>
X-Mailer: git-send-email 2.38.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [Intel-gfx] [PATCH] drm/i915/hwmon: Display clamped PL1 limit
X-BeenThere: intel-gfx@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Intel graphics driver community testing & development
 <intel-gfx.lists.freedesktop.org>
List-Unsubscribe: <https://lists.freedesktop.org/mailman/options/intel-gfx>,
 <mailto:intel-gfx-request@lists.freedesktop.org?subject=unsubscribe>
List-Archive: <https://lists.freedesktop.org/archives/intel-gfx>
List-Post: <mailto:intel-gfx@lists.freedesktop.org>
List-Help: <mailto:intel-gfx-request@lists.freedesktop.org?subject=help>
List-Subscribe: <https://lists.freedesktop.org/mailman/listinfo/intel-gfx>,
 <mailto:intel-gfx-request@lists.freedesktop.org?subject=subscribe>
Cc: dri-devel@lists.freedesktop.org
Errors-To: intel-gfx-bounces@lists.freedesktop.org
Sender: "Intel-gfx" <intel-gfx-bounces@lists.freedesktop.org>

HW allows arbitrary PL1 limits to be set but silently clamps these values
to "typical but not guaranteed" min/max values in pkg_power_sku
register. Follow the same pattern for sysfs, allow arbitrary PL1 limits to
be set but display clamped values when read, so that users see PL1 limits
HW is likely using. Otherwise users think HW is using arbitrarily high/low
PL1 limits they might have set. The previous write/read I1 power1_crit
limit also follows the same clamping pattern.

v2: Explain "why" in commit message and include bug link (Jani Nikula)

Bug: https://gitlab.freedesktop.org/drm/intel/-/issues/7704
Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
---
 drivers/gpu/drm/i915/i915_hwmon.c        | 39 ++++++++++++++++++++----
 drivers/gpu/drm/i915/intel_mchbar_regs.h |  2 ++
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
index cca7a4350ec8f..1225bc432f0d5 100644
--- a/drivers/gpu/drm/i915/i915_hwmon.c
+++ b/drivers/gpu/drm/i915/i915_hwmon.c
@@ -359,6 +359,38 @@ hwm_power_is_visible(const struct hwm_drvdata *ddat, u32 attr, int chan)
 	}
 }
 
+/*
+ * HW allows arbitrary PL1 limits to be set but silently clamps these values to
+ * "typical but not guaranteed" min/max values in rg.pkg_power_sku. Follow the
+ * same pattern for sysfs, allow arbitrary PL1 limits to be set but display
+ * clamped values when read. Write/read I1 also follows the same pattern.
+ */
+static int
+hwm_power_max_read(struct hwm_drvdata *ddat, long *val)
+{
+	struct i915_hwmon *hwmon = ddat->hwmon;
+	intel_wakeref_t wakeref;
+	u64 r, min, max;
+
+	*val = hwm_field_read_and_scale(ddat,
+					hwmon->rg.pkg_rapl_limit,
+					PKG_PWR_LIM_1,
+					hwmon->scl_shift_power,
+					SF_POWER);
+
+	with_intel_runtime_pm(ddat->uncore->rpm, wakeref)
+		r = intel_uncore_read64(ddat->uncore, hwmon->rg.pkg_power_sku);
+	min = REG_FIELD_GET(PKG_MIN_PWR, r);
+	min = mul_u64_u32_shr(min, SF_POWER, hwmon->scl_shift_power);
+	max = REG_FIELD_GET(PKG_MAX_PWR, r);
+	max = mul_u64_u32_shr(max, SF_POWER, hwmon->scl_shift_power);
+
+	if (min && max)
+		*val = clamp_t(u64, *val, min, max);
+
+	return 0;
+}
+
 static int
 hwm_power_read(struct hwm_drvdata *ddat, u32 attr, int chan, long *val)
 {
@@ -368,12 +400,7 @@ hwm_power_read(struct hwm_drvdata *ddat, u32 attr, int chan, long *val)
 
 	switch (attr) {
 	case hwmon_power_max:
-		*val = hwm_field_read_and_scale(ddat,
-						hwmon->rg.pkg_rapl_limit,
-						PKG_PWR_LIM_1,
-						hwmon->scl_shift_power,
-						SF_POWER);
-		return 0;
+		return hwm_power_max_read(ddat, val);
 	case hwmon_power_rated_max:
 		*val = hwm_field_read_and_scale(ddat,
 						hwmon->rg.pkg_power_sku,
diff --git a/drivers/gpu/drm/i915/intel_mchbar_regs.h b/drivers/gpu/drm/i915/intel_mchbar_regs.h
index f93e9af43ac35..73900c098d591 100644
--- a/drivers/gpu/drm/i915/intel_mchbar_regs.h
+++ b/drivers/gpu/drm/i915/intel_mchbar_regs.h
@@ -194,6 +194,8 @@
  */
 #define PCU_PACKAGE_POWER_SKU			_MMIO(MCHBAR_MIRROR_BASE_SNB + 0x5930)
 #define   PKG_PKG_TDP				GENMASK_ULL(14, 0)
+#define   PKG_MIN_PWR				GENMASK_ULL(30, 16)
+#define   PKG_MAX_PWR				GENMASK_ULL(46, 32)
 #define   PKG_MAX_WIN				GENMASK_ULL(54, 48)
 #define     PKG_MAX_WIN_X			GENMASK_ULL(54, 53)
 #define     PKG_MAX_WIN_Y			GENMASK_ULL(52, 48)
-- 
2.38.0


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <intel-gfx-bounces@lists.freedesktop.org>
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 819D8C5479D
	for <intel-gfx@archiver.kernel.org>; Fri,  6 Jan 2023 10:17:14 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
	by gabe.freedesktop.org (Postfix) with ESMTP id 5BC9210E85B;
	Fri,  6 Jan 2023 10:17:12 +0000 (UTC)
Received: from mga04.intel.com (mga04.intel.com [192.55.52.120])
 by gabe.freedesktop.org (Postfix) with ESMTPS id 3BE2410E863;
 Fri,  6 Jan 2023 10:17:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1673000229; x=1704536229;
 h=message-id:date:subject:to:cc:references:from:
 in-reply-to:content-transfer-encoding:mime-version;
 bh=gd4HwFUU25NJHtunyI8OVMfW80jq9BxQgGzpDMX3jw4=;
 b=f4kifuowh3SFKDYis1kyCQE1h5oIAWdM6+S5K3/RmiXH+AnsAAvbYpJF
 vql8um6W8ddSihcx9t21qeMqFl+WHDl4fJCXnJKS92lXw2LepAnRwRNdW
 ad6qdi+tJI12qy2Q+WvjNygDdXwBWzU9bwhlLQdl2IbOoaWkOU34Iq3iG
 JIla25ejsuFLaONi0FDn1rR7WLeHLXogrN7XtqkPolGDxFDk0gylyy5r4
 G5fMr2v8vkJiAr8owojjI1ZOiO20AE+K+TxMVyfnkpJdnvUcJD0joQd+W
 XmJSqMke3Q4tyym4Rb2CLepYdx+RQpi9QlAJr8AbnoMES4/F9CWzLgSI0 g==;
X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="321154994"
X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="321154994"
Received: from fmsmga003.fm.intel.com ([10.253.24.29])
 by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 06 Jan 2023 02:17:08 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="744586471"
X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="744586471"
Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14])
 by FMSMGA003.fm.intel.com with ESMTP; 06 Jan 2023 02:17:07 -0800
Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by
 ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.1.2507.16; Fri, 6 Jan 2023 02:17:07 -0800
Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by
 ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.1.2507.16; Fri, 6 Jan 2023 02:17:06 -0800
Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by
 orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.1.2507.16 via Frontend Transport; Fri, 6 Jan 2023 02:17:06 -0800
Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.175)
 by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.1.2507.16; Fri, 6 Jan 2023 02:17:06 -0800
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=n7UA2cjRje/QUARjJcTWUiyXg5h0OFjf+31rjhfSNxM7hWYdndbumoiBu6pwyJQxiaTs+2TuqJXJ0cV+OF1SaYGaAw52AhBfbh+3MbsF7N6FG5Ez825w1mKFTHkpuGd79LMLWPJ3DXEJQECP+ju/aOxcq0FK+XWdeMd8QV47RrPJHLGJBaZvPpwLIjg6ZxZqSsRmO/7W6Sv3EgKz5V9DtBt4lR+qO0huEm8075EJBQgF05jCEESgE1yGLNiqbhYBXHUEXq/r8nFQpjZWkxCn9sKFw9+iti0H0mwFfjG2Rlb8WC4US3qHfdA7gJKbXrFrRLn5PEwfPs4kd1maSS60QA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=GOKDF+/L2ms6RLE7ykfO5wd6kImqBP38P55i+D/ekCs=;
 b=i0SgijZ/SP24KnngIk1BEMWNG39yy8hPzYcTA8++b9p8VyJMgCm8XZhgozU9wFKw01c7ZWLNmTFSf4HPRltffO5GOkK0mdS38DJi/wCWGF8ULVVaxJBy1wQrdxWxgyXCg+dQO39a9jMOhsbHlQYhyQZpI9/dAKiE/Va9vPS5Sxzd3YXpkoLZPik5pMHaOfJXZNa53M7/JskZBGmu01orGpRmG4k0/tfKfCEYkmQbXoremONwI8/X0u8mukppB58RUPUiTitqQPXpjxcPoUt6qo1DnJnmTyyafm2S+H1QVXHgmv3d1/cnOSfgw87NSrCAzSyqEi5MTo5CnLxMG7LurQ==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com;
 dkim=pass header.d=intel.com; arc=none
Authentication-Results: dkim=none (message not signed)
 header.d=none;dmarc=none action=none header.from=intel.com;
Received: from CY5PR11MB6211.namprd11.prod.outlook.com (2603:10b6:930:25::6)
 by SN7PR11MB6827.namprd11.prod.outlook.com (2603:10b6:806:2a2::20) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Fri, 6 Jan
 2023 10:17:05 +0000
Received: from CY5PR11MB6211.namprd11.prod.outlook.com
 ([fe80::1e74:3442:77ce:6ef]) by CY5PR11MB6211.namprd11.prod.outlook.com
 ([fe80::1e74:3442:77ce:6ef%8]) with mapi id 15.20.5944.019; Fri, 6 Jan 2023
 10:17:04 +0000
Message-ID: <7bd1bcb7-02c4-e828-7392-85a6e3fb8530@intel.com>
Date: Fri, 6 Jan 2023 15:46:54 +0530
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
 Firefox/102.0 Thunderbird/102.6.1
To: Ashutosh Dixit <ashutosh.dixit@intel.com>,
 <intel-gfx@lists.freedesktop.org>
References: <20221215191727.2468770-1-ashutosh.dixit@intel.com>
Content-Language: en-US
From: "Gupta, Anshuman" <anshuman.gupta@intel.com>
In-Reply-To: <20221215191727.2468770-1-ashutosh.dixit@intel.com>
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: 7bit
X-ClientProxiedBy: PN2PR01CA0015.INDPRD01.PROD.OUTLOOK.COM
 (2603:1096:c01:25::20) To CY5PR11MB6211.namprd11.prod.outlook.com
 (2603:10b6:930:25::6)
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: CY5PR11MB6211:EE_|SN7PR11MB6827:EE_
X-MS-Office365-Filtering-Correlation-Id: 43f84e29-9438-4189-2db8-08daefcf28a6
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info:  
X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:CY5PR11MB6211.namprd11.prod.outlook.com; PTR:; CAT:NONE;
 SFS:(13230022)(376002)(346002)(136003)(396003)(366004)(39860400002)(451199015)(5660300002)(8936002)(83380400001)(8676002)(66946007)(66476007)(4326008)(66556008)(316002)(41300700001)(2616005)(36756003)(82960400001)(38100700002)(86362001)(31696002)(2906002)(55236004)(6486002)(966005)(478600001)(53546011)(186003)(6512007)(26005)(6666004)(31686004)(6506007)(45980500001)(43740500002);
 DIR:OUT; SFP:1102; 
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RVhOenNXV2JUeDcyckpkYmNZanQ3dEg5OGhObE1XUXlzK1B0ME1pdG90ZWYw?=
 =?utf-8?B?QUlnRmZMVCtEaEQyUVhEZjVvek9IalhNTDNnZmg5YnhQQmVYWnd6dFBTWS9Q?=
 =?utf-8?B?bjlGNDZXVkU3RUZGOEwzWDAyWkVCa090a1FtNWFTVFNjT3U0dytiQWp6Mnc0?=
 =?utf-8?B?Y1UrcFY2V0VoejRwUitJd3M4WDA2d2hJSUtNaVRZMHk4Z08ya3loakh5WjAz?=
 =?utf-8?B?ZWNTbDl0VEV6REpJc0h0cnJVbkJXWGpZbE92bDZJMnN2ZXhIcjFuRXRhUW1X?=
 =?utf-8?B?YnE2RWdhUUM5RWp2bkJScSsreWxTdXVMS2U4OEFrckZNNnBhb3Y4UzFTVGVG?=
 =?utf-8?B?SDJtSktFYUlNYjFPamlvVkM3WVlKVGl4RnpVeTJVQm1NdzRwRm9icHNnVGdG?=
 =?utf-8?B?U3BrcHl6KzRDY0NmSU9kbTZXNlI2Vm9RYS9PTW1hTmppdUNBdVdaQlNVbHVQ?=
 =?utf-8?B?Qis4NUxPbk4rQU55S2xrdmNOWXFjM1dhNXowdy9Xc2FRVVRUTjNmS2NuazM2?=
 =?utf-8?B?dDh1L1djNmNRZUU1bm10anpxckpPc3c0ckpGTm55YjVxZUJiMTcvL1pLTExE?=
 =?utf-8?B?VnNxVFQzOUVyTC9TK1FJbXlDY3BDWmt4WCtwUVc0bWgvdWd1YXpRYi9kUk01?=
 =?utf-8?B?dDJpb1F3aElFVnh4TGRVOHcya2FXV0VRRVBjV3FKUmpSWGNzNVI3cnplaVBU?=
 =?utf-8?B?OUI0aWdIQm9MWHBYbnZHRDJUa3lTTkVsZFZCWUVxakVqc1dNUkZvZTRyRjUy?=
 =?utf-8?B?L1B2UFhwdVJoU3RLaWN6ZHRiOHdwNjhINlBCZGZ5NWlZdFNwOFNLOUx6R0dJ?=
 =?utf-8?B?cFdtUGxIb3VjTi9aQ2NyZHlwUmw2c3lFV3FCMk1iZmRZUzd6dTR5WHFGcTkx?=
 =?utf-8?B?ZDRsUm10RkZDd2tzVkVDejRHTmJ6aTJSc0QxOFNJL1Rid3NyOG9DSVdzVEk0?=
 =?utf-8?B?Zi8zWXNsZXFwbnh2MGhnNGNsYzcvTGNKN2JMbVdWVXY3ZmRRMkk4YzlhdzNl?=
 =?utf-8?B?TzF5cElxREs1Nnl3eHNVUmpCaVhENEhMSWxzaHdSd2U5cmc4dXFpemIvU25W?=
 =?utf-8?B?Zm9XL1FPMHpRQnl4UitZRzlEVVRLNkRKQUpSUFR5M005SldZOEJWK1M4anZK?=
 =?utf-8?B?WmVzbkZHbmJXLytTQzFkc28xTmRJUDQ3QWlzMHAwbk1xTUZObGtvVEovbncy?=
 =?utf-8?B?OTdHNnF1RzFSMmxNZk1Ra01INWhsVWpaZ0hJejZBU1ZNNFdacTU2bllQbmNO?=
 =?utf-8?B?ZEh0bmp0QUl6SGtpOUJGM2RaQkRQT09zcDFCbjA1NGIxN2JQZDhMZjVRa1RS?=
 =?utf-8?B?dTBzS1lEMWZQemNoMmFNY2xxVUxjVHg4blAwM1UySDBwOS9acjd3T08ycU4w?=
 =?utf-8?B?VnJPdEdLZGVkUGV1a2IrSURGZFB1U2U3K3FIaWFUZ1lYL1h5NHEwN29ZeVRH?=
 =?utf-8?B?MGZyMkNkN1c4cnZvMDVJZzd4VkVsT3I1T2Q3RWZQdE1ONHgxTFMvRGdLa1U4?=
 =?utf-8?B?bVBycUM3WGlLbUZBWTBucythbWwrQytxcVZVc1ZsRVdqcElpT3BoVGFZT3BU?=
 =?utf-8?B?eWcwU0xkaHV4ZkpnTms5R1pNY1pCL3hBYWNPcEZsTURXeDVtZkNPaFRaT1hn?=
 =?utf-8?B?QVRWWCtqK040d3NQd2EwRFRoQmFSYm03M2cwMThHdFBWSzZxK0dZS2F0Tnl3?=
 =?utf-8?B?SFA1TDB1ZWVCRTJOTXRjdUZKVHFnRlNCS205MDF2Y3FyazBQb3BPdHc1RDhZ?=
 =?utf-8?B?bkNSQzl4WXdDa3JEcFJBV2w5OXJrTjBsa1plNWEySmlMT3djOVZCZ1FPU0ho?=
 =?utf-8?B?ZFh6dnZUMUcycTVOVy9ZSmpkdlZ6SW9ubVAva1kvK3JSZTRFTTY5TUY0b01L?=
 =?utf-8?B?dWFpbkZGWmxwYS8zVXRQbnhiMXgvYTdoYTVHTW41NWRvMjAxVGlhUU9SSFJW?=
 =?utf-8?B?TGMrZjJsWDVHVDFNRnVtQis0WEkwU0k0ci9mWlBvRVY5M1RJWVZCYXlKbkRn?=
 =?utf-8?B?YTNMQjgxZWFEcjEvTjNkamdicEluNnR3ZlA0QklidERGcEdyT2pZSUgvTUV1?=
 =?utf-8?B?enVJNlFuMzNvMVdNZjN4T2hMUTZYS0RuNXNpalJ1R0xqQ1I3bGxuTHl1WDZv?=
 =?utf-8?B?UlZvMGxYUk1YbHJRcnB1ay9FcXA3eFJtejlEd3d0cjFsWG9SYVhZdDl3aWJp?=
 =?utf-8?B?akE9PQ==?=
X-MS-Exchange-CrossTenant-Network-Message-Id: 43f84e29-9438-4189-2db8-08daefcf28a6
X-MS-Exchange-CrossTenant-AuthSource: CY5PR11MB6211.namprd11.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2023 10:17:04.9167 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName: nKGYs94ybd2fpDGkYB/M6Uuwr4bSYqi6JuzCVUCBaPYBJutOkGLY2gZb3ZfdB2aIpV7nl/3smEsfVVM2UCm0IwWabc4kuO9P0UWdDR/PXco=
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR11MB6827
X-OriginatorOrg: intel.com
Subject: Re: [Intel-gfx] [PATCH] drm/i915/hwmon: Display clamped PL1 limit
X-BeenThere: intel-gfx@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Intel graphics driver community testing & development
 <intel-gfx.lists.freedesktop.org>
List-Unsubscribe: <https://lists.freedesktop.org/mailman/options/intel-gfx>,
 <mailto:intel-gfx-request@lists.freedesktop.org?subject=unsubscribe>
List-Archive: <https://lists.freedesktop.org/archives/intel-gfx>
List-Post: <mailto:intel-gfx@lists.freedesktop.org>
List-Help: <mailto:intel-gfx-request@lists.freedesktop.org?subject=help>
List-Subscribe: <https://lists.freedesktop.org/mailman/listinfo/intel-gfx>,
 <mailto:intel-gfx-request@lists.freedesktop.org?subject=subscribe>
Cc: dri-devel@lists.freedesktop.org
Errors-To: intel-gfx-bounces@lists.freedesktop.org
Sender: "Intel-gfx" <intel-gfx-bounces@lists.freedesktop.org>



On 12/16/2022 12:47 AM, Ashutosh Dixit wrote:
> HW allows arbitrary PL1 limits to be set but silently clamps these values
> to "typical but not guaranteed" min/max values in pkg_power_sku
> register. Follow the same pattern for sysfs, allow arbitrary PL1 limits to
> be set but display clamped values when read, so that users see PL1 limits
> HW is likely using. Otherwise users think HW is using arbitrarily high/low
> PL1 limits they might have set. The previous write/read I1 power1_crit
> limit also follows the same clamping pattern.
> 
> v2: Explain "why" in commit message and include bug link (Jani Nikula)
> 
> Bug: https://gitlab.freedesktop.org/drm/intel/-/issues/7704
> Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Looks good to me.
Reviewed-by: Anshuman Gupta <anshuman.gupta@intel.com>
> ---
>   drivers/gpu/drm/i915/i915_hwmon.c        | 39 ++++++++++++++++++++----
>   drivers/gpu/drm/i915/intel_mchbar_regs.h |  2 ++
>   2 files changed, 35 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
> index cca7a4350ec8f..1225bc432f0d5 100644
> --- a/drivers/gpu/drm/i915/i915_hwmon.c
> +++ b/drivers/gpu/drm/i915/i915_hwmon.c
> @@ -359,6 +359,38 @@ hwm_power_is_visible(const struct hwm_drvdata *ddat, u32 attr, int chan)
>   	}
>   }
>   
> +/*
> + * HW allows arbitrary PL1 limits to be set but silently clamps these values to
> + * "typical but not guaranteed" min/max values in rg.pkg_power_sku. Follow the
> + * same pattern for sysfs, allow arbitrary PL1 limits to be set but display
> + * clamped values when read. Write/read I1 also follows the same pattern.
> + */
> +static int
> +hwm_power_max_read(struct hwm_drvdata *ddat, long *val)
> +{
> +	struct i915_hwmon *hwmon = ddat->hwmon;
> +	intel_wakeref_t wakeref;
> +	u64 r, min, max;
> +
> +	*val = hwm_field_read_and_scale(ddat,
> +					hwmon->rg.pkg_rapl_limit,
> +					PKG_PWR_LIM_1,
> +					hwmon->scl_shift_power,
> +					SF_POWER);
> +
> +	with_intel_runtime_pm(ddat->uncore->rpm, wakeref)
> +		r = intel_uncore_read64(ddat->uncore, hwmon->rg.pkg_power_sku);
> +	min = REG_FIELD_GET(PKG_MIN_PWR, r);
> +	min = mul_u64_u32_shr(min, SF_POWER, hwmon->scl_shift_power);
> +	max = REG_FIELD_GET(PKG_MAX_PWR, r);
> +	max = mul_u64_u32_shr(max, SF_POWER, hwmon->scl_shift_power);
> +
> +	if (min && max)
> +		*val = clamp_t(u64, *val, min, max);
> +
> +	return 0;
> +}
> +
>   static int
>   hwm_power_read(struct hwm_drvdata *ddat, u32 attr, int chan, long *val)
>   {
> @@ -368,12 +400,7 @@ hwm_power_read(struct hwm_drvdata *ddat, u32 attr, int chan, long *val)
>   
>   	switch (attr) {
>   	case hwmon_power_max:
> -		*val = hwm_field_read_and_scale(ddat,
> -						hwmon->rg.pkg_rapl_limit,
> -						PKG_PWR_LIM_1,
> -						hwmon->scl_shift_power,
> -						SF_POWER);
> -		return 0;
> +		return hwm_power_max_read(ddat, val);
>   	case hwmon_power_rated_max:
>   		*val = hwm_field_read_and_scale(ddat,
>   						hwmon->rg.pkg_power_sku,
> diff --git a/drivers/gpu/drm/i915/intel_mchbar_regs.h b/drivers/gpu/drm/i915/intel_mchbar_regs.h
> index f93e9af43ac35..73900c098d591 100644
> --- a/drivers/gpu/drm/i915/intel_mchbar_regs.h
> +++ b/drivers/gpu/drm/i915/intel_mchbar_regs.h
> @@ -194,6 +194,8 @@
>    */
>   #define PCU_PACKAGE_POWER_SKU			_MMIO(MCHBAR_MIRROR_BASE_SNB + 0x5930)
>   #define   PKG_PKG_TDP				GENMASK_ULL(14, 0)
> +#define   PKG_MIN_PWR				GENMASK_ULL(30, 16)
> +#define   PKG_MAX_PWR				GENMASK_ULL(46, 32)
>   #define   PKG_MAX_WIN				GENMASK_ULL(54, 48)
>   #define     PKG_MAX_WIN_X			GENMASK_ULL(54, 53)
>   #define     PKG_MAX_WIN_Y			GENMASK_ULL(52, 48)

