From: Jani Nikula <jani.nikula@linux.intel.com>
To: Karthik Poosa <karthik.poosa@intel.com>, intel-xe@lists.freedesktop.org
Cc: anshuman.gupta@intel.com, badal.nilawar@intel.com,
rodrigo.vivi@intel.com, lucas.demarchi@intel.com,
Karthik Poosa <karthik.poosa@intel.com>
Subject: Re: [PATCH v5 2/4] drm/xe/hwmon: Update xe_hwmon_get_reg to return struct xe_reg
Date: Thu, 04 Apr 2024 11:46:00 +0300 [thread overview]
Message-ID: <87plv5cy7r.fsf@intel.com> (raw)
In-Reply-To: <20240404035441.965590-3-karthik.poosa@intel.com>
On Thu, 04 Apr 2024, Karthik Poosa <karthik.poosa@intel.com> wrote:
> Return register address as struct xe_reg from xe_hwmon_get_reg
> instead of u32. (Lucas)
> Use XE_REG_IS_VALID() from caller to check returned xe_reg. (Badal)
> These changes are done to have abstracted usage of struct xe_reg.
>
> Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
> ---
> drivers/gpu/drm/xe/xe_hwmon.c | 47 +++++++++++++++++++----------------
> 1 file changed, 26 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> index 7e8caac838e0..2385f05d9504 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
> @@ -79,46 +79,46 @@ struct xe_hwmon {
> struct xe_hwmon_energy_info ei[CHANNEL_MAX];
> };
>
> -static u32 xe_hwmon_get_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg hwmon_reg, int channel)
> +static struct xe_reg xe_hwmon_get_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg hwmon_reg,
> + int channel)
> {
> struct xe_device *xe = gt_to_xe(hwmon->gt);
> - struct xe_reg reg = XE_REG(0);
>
> switch (hwmon_reg) {
> case REG_PKG_RAPL_LIMIT:
> if (xe->info.platform == XE_PVC && channel == CHANNEL_PKG)
> - reg = PVC_GT0_PACKAGE_RAPL_LIMIT;
> + return PVC_GT0_PACKAGE_RAPL_LIMIT;
> else if ((xe->info.platform == XE_DG2) && (channel == CHANNEL_PKG))
> - reg = PCU_CR_PACKAGE_RAPL_LIMIT;
> + return PCU_CR_PACKAGE_RAPL_LIMIT;
> break;
> case REG_PKG_POWER_SKU:
> if (xe->info.platform == XE_PVC && channel == CHANNEL_PKG)
> - reg = PVC_GT0_PACKAGE_POWER_SKU;
> + return PVC_GT0_PACKAGE_POWER_SKU;
> else if ((xe->info.platform == XE_DG2) && (channel == CHANNEL_PKG))
> - reg = PCU_CR_PACKAGE_POWER_SKU;
> + return PCU_CR_PACKAGE_POWER_SKU;
> break;
> case REG_PKG_POWER_SKU_UNIT:
> if (xe->info.platform == XE_PVC)
> - reg = PVC_GT0_PACKAGE_POWER_SKU_UNIT;
> + return PVC_GT0_PACKAGE_POWER_SKU_UNIT;
> else if (xe->info.platform == XE_DG2)
> - reg = PCU_CR_PACKAGE_POWER_SKU_UNIT;
> + return PCU_CR_PACKAGE_POWER_SKU_UNIT;
> break;
> case REG_GT_PERF_STATUS:
> if (xe->info.platform == XE_DG2 && channel == CHANNEL_PKG)
> - reg = GT_PERF_STATUS;
> + return GT_PERF_STATUS;
> break;
> case REG_PKG_ENERGY_STATUS:
> if (xe->info.platform == XE_PVC && channel == CHANNEL_PKG)
> - reg = PVC_GT0_PLATFORM_ENERGY_STATUS;
> + return PVC_GT0_PLATFORM_ENERGY_STATUS;
> else if ((xe->info.platform == XE_DG2) && (channel == CHANNEL_PKG))
> - reg = PCU_CR_PACKAGE_ENERGY_STATUS;
> + return PCU_CR_PACKAGE_ENERGY_STATUS;
> break;
> default:
> drm_warn(&xe->drm, "Unknown xe hwmon reg id: %d\n", hwmon_reg);
> break;
> }
>
> - return reg.raw;
> + return XE_REG(0);
You might want to look at i915_reg_defs.h, which abstracts away the
magic 0 as the invalid address, and provides type safety for the reg
validity checks via _Generic:
#define INVALID_MMIO_REG _MMIO(0)
#define i915_mmio_reg_offset(r) \
_Generic((r), i915_reg_t: (r).reg, i915_mcr_reg_t: (r).reg)
#define i915_mmio_reg_equal(a, b) (i915_mmio_reg_offset(a) == i915_mmio_reg_offset(b))
#define i915_mmio_reg_valid(r) (!i915_mmio_reg_equal(r, INVALID_MMIO_REG))
BR,
Jani.
> }
>
> static void xe_hwmon_process_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg hwmon_reg,
> @@ -127,9 +127,9 @@ static void xe_hwmon_process_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg hwmon
> {
> struct xe_reg reg;
>
> - reg.raw = xe_hwmon_get_reg(hwmon, hwmon_reg, channel);
> + reg = xe_hwmon_get_reg(hwmon, hwmon_reg, channel);
>
> - if (!reg.raw)
> + if (!XE_REG_IS_VALID(reg))
> return;
>
> switch (operation) {
> @@ -400,7 +400,7 @@ static umode_t xe_hwmon_attributes_visible(struct kobject *kobj,
>
> xe_pm_runtime_get(gt_to_xe(hwmon->gt));
>
> - ret = xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, index) ? attr->mode : 0;
> + ret = XE_REG_IS_VALID(xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, index)) ? attr->mode : 0;
>
> xe_pm_runtime_put(gt_to_xe(hwmon->gt));
>
> @@ -496,16 +496,19 @@ xe_hwmon_power_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
>
> switch (attr) {
> case hwmon_power_max:
> - return xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, channel) ? 0664 : 0;
> + return XE_REG_IS_VALID(xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT,
> + channel)) ? 0664 : 0;
> case hwmon_power_rated_max:
> - return xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU, channel) ? 0444 : 0;
> + return XE_REG_IS_VALID(xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU,
> + channel)) ? 0444 : 0;
> case hwmon_power_crit:
> if (channel == CHANNEL_PKG)
> return (xe_hwmon_pcode_read_i1(hwmon->gt, &uval) ||
> !(uval & POWER_SETUP_I1_WATTS)) ? 0 : 0644;
> break;
> case hwmon_power_label:
> - return xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU_UNIT, channel) ? 0444 : 0;
> + return XE_REG_IS_VALID(xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU_UNIT,
> + channel)) ? 0444 : 0;
> default:
> return 0;
> }
> @@ -588,7 +591,8 @@ xe_hwmon_in_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
> switch (attr) {
> case hwmon_in_input:
> case hwmon_in_label:
> - return xe_hwmon_get_reg(hwmon, REG_GT_PERF_STATUS, channel) ? 0444 : 0;
> + return XE_REG_IS_VALID(xe_hwmon_get_reg(hwmon, REG_GT_PERF_STATUS,
> + channel)) ? 0444 : 0;
> default:
> return 0;
> }
> @@ -612,7 +616,8 @@ xe_hwmon_energy_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
> switch (attr) {
> case hwmon_energy_input:
> case hwmon_energy_label:
> - return xe_hwmon_get_reg(hwmon, REG_PKG_ENERGY_STATUS, channel) ? 0444 : 0;
> + return XE_REG_IS_VALID(xe_hwmon_get_reg(hwmon, REG_PKG_ENERGY_STATUS,
> + channel)) ? 0444 : 0;
> default:
> return 0;
> }
> @@ -763,7 +768,7 @@ xe_hwmon_get_preregistration_info(struct xe_device *xe)
> * The contents of register PKG_POWER_SKU_UNIT do not change,
> * so read it once and store the shift values.
> */
> - if (xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU_UNIT, 0)) {
> + if (XE_REG_IS_VALID(xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU_UNIT, 0))) {
> xe_hwmon_process_reg(hwmon, REG_PKG_POWER_SKU_UNIT,
> REG_READ32, &val_sku_unit, 0, 0, 0);
> hwmon->scl_shift_power = REG_FIELD_GET(PKG_PWR_UNIT, val_sku_unit);
--
Jani Nikula, Intel
next prev parent reply other threads:[~2024-04-04 13:57 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-04 3:54 [PATCH v5 0/4] drm/xe/hwmon: Update xe hwmon with couple of fixes Karthik Poosa
2024-04-04 3:54 ` [PATCH v5 1/4] drm/xe: Define XE_REG_IS_VALID Karthik Poosa
2024-04-04 4:04 ` Nilawar, Badal
2024-04-04 4:16 ` Dixit, Ashutosh
2024-04-04 10:31 ` Riana Tauro
2024-04-04 16:07 ` Lucas De Marchi
2024-04-04 3:54 ` [PATCH v5 2/4] drm/xe/hwmon: Update xe_hwmon_get_reg to return struct xe_reg Karthik Poosa
2024-04-04 8:46 ` Jani Nikula [this message]
2024-04-04 9:54 ` Poosa, Karthik
2024-04-04 16:06 ` Lucas De Marchi
2024-04-04 3:54 ` [PATCH v5 3/4] drm/xe/hwmon: Update xe_hwmon_process_reg Karthik Poosa
2024-04-04 10:35 ` Riana Tauro
2024-04-04 10:52 ` Poosa, Karthik
2024-04-04 3:54 ` [PATCH v5 4/4] drm/xe/hwmon: Cast to output precision before multiplying operands Karthik Poosa
2024-04-04 11:48 ` Ghimiray, Himal Prasad
2024-04-04 4:48 ` ✓ CI.Patch_applied: success for drm/xe/hwmon: Update xe hwmon with couple of fixes (rev5) Patchwork
2024-04-04 4:48 ` ✗ CI.checkpatch: warning " Patchwork
2024-04-04 4:49 ` ✓ CI.KUnit: success " Patchwork
2024-04-04 5:00 ` ✓ CI.Build: " Patchwork
2024-04-04 5:04 ` ✓ CI.Hooks: " Patchwork
2024-04-04 5:10 ` ✓ CI.checksparse: " Patchwork
2024-04-04 5:48 ` ✓ CI.BAT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87plv5cy7r.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=anshuman.gupta@intel.com \
--cc=badal.nilawar@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=karthik.poosa@intel.com \
--cc=lucas.demarchi@intel.com \
--cc=rodrigo.vivi@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).