All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Sujaritha Sundaresan <sujaritha.sundaresan@intel.com>
Cc: intel-xe@lists.freedesktop.org, vivi.rodrigo@intel.com
Subject: Re: [Intel-xe] [RFC 4/4] drm/xe: Add vram frequency sysfs attributes
Date: Fri, 17 Nov 2023 16:43:55 -0500	[thread overview]
Message-ID: <ZVfem1m9puMhHcJM@intel.com> (raw)
In-Reply-To: <20231116143043.908412-5-sujaritha.sundaresan@intel.com>

On Thu, Nov 16, 2023 at 08:00:43PM +0530, Sujaritha Sundaresan wrote:
> Add vram rp0/n frequency sysfs attribuites under
> /device/../tile<n>/memory/freq/vram_rp0/n_freq


The ideal scenario is that our xe_freq is generic enough to be used
under gt, tile or vram/memory...

> 
> Signed-off-by: Sujaritha Sundaresan <sujaritha.sundaresan@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_pcode_api.h  |  8 ++++
>  drivers/gpu/drm/xe/xe_tile_sysfs.c | 77 ++++++++++++++++++++++++++++--
>  2 files changed, 81 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_pcode_api.h b/drivers/gpu/drm/xe/xe_pcode_api.h
> index 5935cfe30204..c003a423562c 100644
> --- a/drivers/gpu/drm/xe/xe_pcode_api.h
> +++ b/drivers/gpu/drm/xe/xe_pcode_api.h
> @@ -42,6 +42,14 @@
>  #define	    POWER_SETUP_I1_SHIFT		6	/* 10.6 fixed point format */
>  #define	    POWER_SETUP_I1_DATA_MASK		REG_GENMASK(15, 0)
>  
> +#define   XEHP_PCODE_FREQUENCY_CONFIG			0x6e	/* xehp, pvc */
> +/* XEHP_PCODE_FREQUENCY_CONFIG sub-commands (param1) */
> +#define     PCODE_MBOX_FC_SC_READ_FUSED_P0		0x0
> +#define     PCODE_MBOX_FC_SC_READ_FUSED_PN		0x1
> +/* PCODE_MBOX_DOMAIN_* - mailbox domain IDs */
> +/* XEHP_PCODE_FREQUENCY_CONFIG param2 */
> +#define     PCODE_MBOX_DOMAIN_HBM			0x2
> +
>  struct pcode_err_decode {
>  	int errno;
>  	const char *str;
> diff --git a/drivers/gpu/drm/xe/xe_tile_sysfs.c b/drivers/gpu/drm/xe/xe_tile_sysfs.c
> index d61c6fb1df40..2a6a515f48e8 100644
> --- a/drivers/gpu/drm/xe/xe_tile_sysfs.c
> +++ b/drivers/gpu/drm/xe/xe_tile_sysfs.c
> @@ -7,9 +7,15 @@
>  #include <linux/sysfs.h>
>  #include <drm/drm_managed.h>
>  
> +#include "xe_gt.h"
> +#include "xe_gt_sysfs.h"
> +#include "xe_pcode.h"
> +#include "xe_pcode_api.h"
>  #include "xe_tile.h"
>  #include "xe_tile_sysfs.h"
>  
> +#define GT_FREQUENCY_MULTIPLIER	50
> +
>  static void xe_tile_sysfs_kobj_release(struct kobject *kobj)
>  {
>  	kfree(kobj);
> @@ -34,6 +40,58 @@ static DEVICE_ATTR_RO(physical_vram_size_bytes);
>  static const struct attribute *physical_memsize_attr =
>  	&dev_attr_physical_vram_size_bytes.attr;
>  
> +static ssize_t vram_rp0_freq_show(struct device *dev, struct device_attribute *attr,
> +				  char *buff)
> +{
> +	struct kobject *kobj = &dev->kobj;
> +	struct xe_gt *gt = kobj_to_gt(kobj);
> +	u32 val, mbox;
> +	int err;
> +
> +	mbox = REG_FIELD_PREP(PCODE_MB_COMMAND, XEHP_PCODE_FREQUENCY_CONFIG)
> +		| REG_FIELD_PREP(PCODE_MB_PARAM1, PCODE_MBOX_FC_SC_READ_FUSED_P0)
> +		| REG_FIELD_PREP(PCODE_MB_PARAM2, PCODE_MBOX_DOMAIN_HBM);
> +
> +	err = xe_pcode_read(gt, mbox, &val, NULL);
> +	if (err)
> +		return err;
> +
> +	/* data_out - Fused P0 for domain ID in units of 50 MHz */
> +	val *= GT_FREQUENCY_MULTIPLIER;
> +
> +	return sysfs_emit(buff, "%u\n", val);
> +}
> +static DEVICE_ATTR_RO(vram_rp0_freq);
> +
> +static ssize_t vram_rpn_freq_show(struct device *dev, struct device_attribute *attr,
> +				  char *buff)
> +{
> +	struct kobject *kobj = &dev->kobj;
> +	struct xe_gt *gt = kobj_to_gt(kobj);
> +	u32 val, mbox;
> +	int err;
> +
> +	mbox = REG_FIELD_PREP(PCODE_MB_COMMAND, XEHP_PCODE_FREQUENCY_CONFIG)
> +		| REG_FIELD_PREP(PCODE_MB_PARAM1, PCODE_MBOX_FC_SC_READ_FUSED_PN)
> +		| REG_FIELD_PREP(PCODE_MB_PARAM2, PCODE_MBOX_DOMAIN_HBM);
> +
> +	err = xe_pcode_read(gt, mbox, &val, NULL);
> +	if (err)
> +		return err;
> +
> +	/* data_out - Fused Pn for domain ID in units of 50 MHz */
> +	val *= GT_FREQUENCY_MULTIPLIER;
> +
> +	return sysfs_emit(buff, "%u\n", val);
> +}
> +static DEVICE_ATTR_RO(vram_rpn_freq);
> +
> +static const struct attribute *vram_freq_attrs[] = {
> +	&dev_attr_vram_rp0_freq.attr,
> +	&dev_attr_vram_rpn_freq.attr,
> +	NULL
> +};
> +
>  static void tile_sysfs_fini(struct drm_device *drm, void *arg)
>  {
>  	struct xe_tile *tile = arg;
> @@ -46,7 +104,8 @@ void xe_tile_sysfs_init(struct xe_tile *tile)
>  	struct xe_device *xe = tile_to_xe(tile);
>  	struct device *dev = xe->drm.dev;
>  	struct kobj_tile *kt;
> -	struct kobject *kobj;
> +	struct kobject *kobj1, *kobj2;
> +
>  	int err;
>  
>  	kt = kzalloc(sizeof(*kt), GFP_KERNEL);
> @@ -65,17 +124,27 @@ void xe_tile_sysfs_init(struct xe_tile *tile)
>  
>  	tile->sysfs = &kt->base;
>  
> -	kobj = kobject_create_and_add("memory", tile->sysfs);
> -	if (!kobj) {
> +	kobj1 = kobject_create_and_add("memory", tile->sysfs);
> +	if (!kobj1) {
>  		drm_warn(&xe->drm, "%s failed, err: %d\n", __func__, -ENOMEM);
>  		return;
>  	}
>  
>  	if (IS_DGFX(xe) && xe->info.platform != XE_DG1 &&
> -	    sysfs_create_file(kobj, physical_memsize_attr))
> +	    sysfs_create_file(kobj1, physical_memsize_attr))
>  		drm_warn(&xe->drm,
>  			 "Sysfs creation to read addr_range per tile failed\n");
>  
> +	kobj2 = kobject_create_and_add("freq", kobj1);
> +	if (xe->info.platform == XE_PVC) {
> +	err = sysfs_create_files(kobj2, vram_freq_attrs);
> +		if (err) {
> +			kobject_put(&kt->base);
> +			drm_warn(&xe->drm, "failed to register vram freq sysfs, err: %d\n", err);
> +			return;
> +		}
> +	}
> +
>  	err = drmm_add_action_or_reset(&xe->drm, tile_sysfs_fini, tile);
>  	if (err) {
>  		drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
> -- 
> 2.25.1
> 

  reply	other threads:[~2023-11-17 21:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-16 14:30 [Intel-xe] [RFC 0/4] Adding new frequency sysfs attributes Sujaritha Sundaresan
2023-11-16 14:20 ` [Intel-xe] ✗ CI.Patch_applied: failure for " Patchwork
2023-11-16 14:30 ` [Intel-xe] [RFC 1/4] drm/xe: Moving and renaming existing " Sujaritha Sundaresan
2023-11-21  4:12   ` Dixit, Ashutosh
2023-11-21  4:50   ` Riana Tauro
2023-11-21  4:58     ` Dixit, Ashutosh
2023-11-22  8:25       ` Sundaresan, Sujaritha
2023-11-22 14:32         ` Gupta, Anshuman
2023-11-16 14:30 ` [Intel-xe] [RFC 2/4] drm/xe: Add memory directory for vram attributes Sujaritha Sundaresan
2023-11-17 21:37   ` Rodrigo Vivi
2023-11-18  1:25     ` Welty, Brian
2023-11-22  8:36       ` Sundaresan, Sujaritha
2023-11-22  8:37       ` Sundaresan, Sujaritha
2023-11-16 14:30 ` [Intel-xe] [RFC 3/4] drm/xe: Add throttle reasons sysfs attributes Sujaritha Sundaresan
2023-11-17 21:41   ` Rodrigo Vivi
2023-11-20  3:33     ` Sundaresan, Sujaritha
2023-11-22  8:33     ` Sundaresan, Sujaritha
2023-11-16 14:30 ` [Intel-xe] [RFC 4/4] drm/xe: Add vram frequency " Sujaritha Sundaresan
2023-11-17 21:43   ` Rodrigo Vivi [this message]
2023-11-18  2:24 ` [Intel-xe] ✓ CI.Patch_applied: success for Adding new " Patchwork
2023-11-18  2:24 ` [Intel-xe] ✗ CI.checkpatch: warning " Patchwork
2023-11-18  2:25 ` [Intel-xe] ✓ CI.KUnit: success " Patchwork
2023-11-18  2:32 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-11-18  2:33 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-11-18  2:34 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-11-18  3:12 ` [Intel-xe] ✗ CI.BAT: failure " 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=ZVfem1m9puMhHcJM@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sujaritha.sundaresan@intel.com \
    --cc=vivi.rodrigo@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.