Skip to content

Commit 1556c17

Browse files
committed
accel/amdxdna: Add IOCTL parameter for resource data
Extend DRM_IOCTL_AMDXDNA_GET_INFO to include additional parameters that allow collection of resource data. Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> Link: https://patch.msgid.link/20251104062546.833771-2-lizhi.hou@amd.com
1 parent c48f1f4 commit 1556c17

5 files changed

Lines changed: 48 additions & 7 deletions

File tree

drivers/accel/amdxdna/aie2_ctx.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ int aie2_hwctx_init(struct amdxdna_hwctx *hwctx)
556556
struct drm_gpu_scheduler *sched;
557557
struct amdxdna_hwctx_priv *priv;
558558
struct amdxdna_gem_obj *heap;
559-
struct amdxdna_dev_hdl *ndev;
560559
int i, ret;
561560

562561
priv = kzalloc(sizeof(*hwctx->priv), GFP_KERNEL);
@@ -654,8 +653,6 @@ int aie2_hwctx_init(struct amdxdna_hwctx *hwctx)
654653
amdxdna_pm_suspend_put(xdna);
655654

656655
hwctx->status = HWCTX_STAT_INIT;
657-
ndev = xdna->dev_handle;
658-
ndev->hwctx_num++;
659656
init_waitqueue_head(&priv->job_free_wq);
660657

661658
XDNA_DBG(xdna, "hwctx %s init completed", hwctx->name);
@@ -688,13 +685,10 @@ int aie2_hwctx_init(struct amdxdna_hwctx *hwctx)
688685

689686
void aie2_hwctx_fini(struct amdxdna_hwctx *hwctx)
690687
{
691-
struct amdxdna_dev_hdl *ndev;
692688
struct amdxdna_dev *xdna;
693689
int idx;
694690

695691
xdna = hwctx->client->xdna;
696-
ndev = xdna->dev_handle;
697-
ndev->hwctx_num--;
698692

699693
XDNA_DBG(xdna, "%s sequence number %lld", hwctx->name, hwctx->priv->seq);
700694
drm_sched_entity_destroy(&hwctx->priv->entity);

drivers/accel/amdxdna/aie2_message.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ int aie2_create_context(struct amdxdna_dev_hdl *ndev, struct amdxdna_hwctx *hwct
235235
ret = -EINVAL;
236236
goto out_destroy_context;
237237
}
238+
ndev->hwctx_num++;
238239

239240
XDNA_DBG(xdna, "%s mailbox channel irq: %d, msix_id: %d",
240241
hwctx->name, ret, resp.msix_id);
@@ -269,6 +270,7 @@ int aie2_destroy_context(struct amdxdna_dev_hdl *ndev, struct amdxdna_hwctx *hwc
269270
hwctx->fw_ctx_id);
270271
hwctx->priv->mbox_chann = NULL;
271272
hwctx->fw_ctx_id = -1;
273+
ndev->hwctx_num--;
272274

273275
return ret;
274276
}

drivers/accel/amdxdna/aie2_pci.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,30 @@ static int aie2_get_hwctx_status(struct amdxdna_client *client,
838838
return 0;
839839
}
840840

841+
static int aie2_query_resource_info(struct amdxdna_client *client,
842+
struct amdxdna_drm_get_info *args)
843+
{
844+
struct amdxdna_drm_get_resource_info res_info;
845+
const struct amdxdna_dev_priv *priv;
846+
struct amdxdna_dev_hdl *ndev;
847+
struct amdxdna_dev *xdna;
848+
849+
xdna = client->xdna;
850+
ndev = xdna->dev_handle;
851+
priv = ndev->priv;
852+
853+
res_info.npu_clk_max = priv->dpm_clk_tbl[ndev->max_dpm_level].hclk;
854+
res_info.npu_tops_max = ndev->max_tops;
855+
res_info.npu_task_max = priv->hwctx_limit;
856+
res_info.npu_tops_curr = ndev->curr_tops;
857+
res_info.npu_task_curr = ndev->hwctx_num;
858+
859+
if (copy_to_user(u64_to_user_ptr(args->buffer), &res_info, sizeof(res_info)))
860+
return -EFAULT;
861+
862+
return 0;
863+
}
864+
841865
static int aie2_get_info(struct amdxdna_client *client, struct amdxdna_drm_get_info *args)
842866
{
843867
struct amdxdna_dev *xdna = client->xdna;
@@ -872,6 +896,9 @@ static int aie2_get_info(struct amdxdna_client *client, struct amdxdna_drm_get_i
872896
case DRM_AMDXDNA_GET_POWER_MODE:
873897
ret = aie2_get_power_mode(client, args);
874898
break;
899+
case DRM_AMDXDNA_QUERY_RESOURCE_INFO:
900+
ret = aie2_query_resource_info(client, args);
901+
break;
875902
default:
876903
XDNA_ERR(xdna, "Not supported request parameter %u", args->param);
877904
ret = -EOPNOTSUPP;

drivers/accel/amdxdna/amdxdna_pci_drv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ MODULE_FIRMWARE("amdnpu/17f0_20/npu.sbin");
2929
* 0.1: Support getting all hardware contexts by DRM_IOCTL_AMDXDNA_GET_ARRAY
3030
* 0.2: Support getting last error hardware error
3131
* 0.3: Support firmware debug buffer
32+
* 0.4: Support getting resource information
3233
*/
3334
#define AMDXDNA_DRIVER_MAJOR 0
34-
#define AMDXDNA_DRIVER_MINOR 3
35+
#define AMDXDNA_DRIVER_MINOR 4
3536

3637
/*
3738
* Bind the driver base on (vendor_id, device_id) pair and later use the

include/uapi/drm/amdxdna_accel.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,23 @@ enum amdxdna_drm_get_param {
442442
DRM_AMDXDNA_QUERY_HW_CONTEXTS,
443443
DRM_AMDXDNA_QUERY_FIRMWARE_VERSION = 8,
444444
DRM_AMDXDNA_GET_POWER_MODE,
445+
DRM_AMDXDNA_QUERY_RESOURCE_INFO = 12,
446+
};
447+
448+
/**
449+
* struct amdxdna_drm_get_resource_info - Get resource information
450+
*/
451+
struct amdxdna_drm_get_resource_info {
452+
/** @npu_clk_max: max H-Clocks */
453+
__u64 npu_clk_max;
454+
/** @npu_tops_max: max TOPs */
455+
__u64 npu_tops_max;
456+
/** @npu_task_max: max number of tasks */
457+
__u64 npu_task_max;
458+
/** @npu_tops_curr: current TOPs */
459+
__u64 npu_tops_curr;
460+
/** @npu_task_curr: current number of tasks */
461+
__u64 npu_task_curr;
445462
};
446463

447464
/**

0 commit comments

Comments
 (0)