AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David (Ming Qiang) Wu" <David.Wu3@amd.com>
To: <amd-gfx@lists.freedesktop.org>, <Christian.Koenig@amd.com>,
	<alexander.deucher@amd.com>
Cc: <leo.liu@amd.com>, <Boyuan.Zhang@amd.com>, <David.Wu3@amd.com>
Subject: [PATCH 08/14] drm/amdgpu/userq: change mes_userq_create_wptr_mapping() to be common
Date: Tue, 10 Feb 2026 16:47:23 -0500	[thread overview]
Message-ID: <20260210214729.80964-9-David.Wu3@amd.com> (raw)
In-Reply-To: <20260210214729.80964-1-David.Wu3@amd.com>

rename mes_userq_create_wptr_mapping() to common function so
it can be used by umsch as well. Also replace DRM_ERROR() with
dev_err().

Signed-off-by: David (Ming Qiang) Wu <David.Wu3@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c  | 87 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h  |  3 +
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 90 +---------------------
 3 files changed, 91 insertions(+), 89 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index dc9000b25be4..ebb0d8a9967f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -1572,3 +1572,90 @@ int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)
 
 	return r;
 }
+
+static int
+amdgpu_userq_map_gtt_bo_to_gart(struct amdgpu_device *adev, struct amdgpu_bo *bo)
+{
+	int ret;
+
+	ret = amdgpu_bo_reserve(bo, true);
+	if (ret) {
+		dev_err(adev->dev, "Failed to reserve bo. ret %d\n", ret);
+		goto err_reserve_bo_failed;
+	}
+
+	ret = amdgpu_ttm_alloc_gart(&bo->tbo);
+	if (ret) {
+		dev_err(adev->dev, "Failed to bind bo to GART. ret %d\n", ret);
+		goto err_map_bo_gart_failed;
+	}
+
+	amdgpu_bo_unreserve(bo);
+	bo = amdgpu_bo_ref(bo);
+
+	return 0;
+
+err_map_bo_gart_failed:
+	amdgpu_bo_unreserve(bo);
+err_reserve_bo_failed:
+	return ret;
+}
+
+int amdgpu_userq_create_wptr_mapping(struct amdgpu_userq_mgr *uq_mgr,
+			      struct amdgpu_usermode_queue *queue,
+			      uint64_t wptr)
+{
+	struct amdgpu_device *adev = uq_mgr->adev;
+	struct amdgpu_bo_va_mapping *wptr_mapping;
+	struct amdgpu_vm *wptr_vm;
+	struct amdgpu_userq_obj *wptr_obj = &queue->wptr_obj;
+	int ret;
+
+	wptr_vm = queue->vm;
+	ret = amdgpu_bo_reserve(wptr_vm->root.bo, false);
+	if (ret)
+		return ret;
+
+	wptr &= AMDGPU_GMC_HOLE_MASK;
+	wptr_mapping = amdgpu_vm_bo_lookup_mapping(wptr_vm, wptr >> PAGE_SHIFT);
+	amdgpu_bo_unreserve(wptr_vm->root.bo);
+	if (!wptr_mapping) {
+		dev_err(adev->dev, "Failed to lookup wptr bo\n");
+		return -EINVAL;
+	}
+
+	wptr_obj->obj = wptr_mapping->bo_va->base.bo;
+	if (wptr_obj->obj->tbo.base.size > PAGE_SIZE) {
+		dev_err(adev->dev, "Requested GART mapping for wptr bo larger than one page\n");
+		return -EINVAL;
+	}
+
+	ret = amdgpu_userq_map_gtt_bo_to_gart(adev, wptr_obj->obj);
+	if (ret) {
+		dev_err(adev->dev, "Failed to map wptr bo to GART\n");
+		return ret;
+	}
+
+	ret = amdgpu_bo_reserve(wptr_obj->obj, true);
+	if (ret) {
+		dev_err(adev->dev, "Failed to reserve wptr bo\n");
+		return ret;
+	}
+
+	/* TODO use eviction fence instead of pinning. */
+	ret = amdgpu_bo_pin(wptr_obj->obj, AMDGPU_GEM_DOMAIN_GTT);
+	if (ret) {
+		drm_file_err(uq_mgr->file, "[Usermode queues] Failed to pin wptr bo\n");
+		goto unresv_bo;
+	}
+
+	queue->wptr_obj.gpu_addr = amdgpu_bo_gpu_offset(wptr_obj->obj);
+	amdgpu_bo_unreserve(wptr_obj->obj);
+
+	return 0;
+
+unresv_bo:
+	amdgpu_bo_unreserve(wptr_obj->obj);
+	return ret;
+
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
index 4feeeaed20f9..758464203d98 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
@@ -159,4 +159,7 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,
 int amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev,
 				       struct amdgpu_bo_va_mapping *mapping,
 				       uint64_t saddr);
+int amdgpu_userq_create_wptr_mapping(struct amdgpu_userq_mgr *uq_mgr,
+				     struct amdgpu_usermode_queue *queue,
+				     uint64_t wptr);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index 9508709abd49..9c1a99f61472 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -30,94 +30,6 @@
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
 
-static int
-mes_userq_map_gtt_bo_to_gart(struct amdgpu_bo *bo)
-{
-	int ret;
-
-	ret = amdgpu_bo_reserve(bo, true);
-	if (ret) {
-		DRM_ERROR("Failed to reserve bo. ret %d\n", ret);
-		goto err_reserve_bo_failed;
-	}
-
-	ret = amdgpu_ttm_alloc_gart(&bo->tbo);
-	if (ret) {
-		DRM_ERROR("Failed to bind bo to GART. ret %d\n", ret);
-		goto err_map_bo_gart_failed;
-	}
-
-	amdgpu_bo_unreserve(bo);
-	bo = amdgpu_bo_ref(bo);
-
-	return 0;
-
-err_map_bo_gart_failed:
-	amdgpu_bo_unreserve(bo);
-err_reserve_bo_failed:
-	return ret;
-}
-
-static int
-mes_userq_create_wptr_mapping(struct amdgpu_device *adev,
-			      struct amdgpu_userq_mgr *uq_mgr,
-			      struct amdgpu_usermode_queue *queue,
-			      uint64_t wptr)
-{
-	struct amdgpu_bo_va_mapping *wptr_mapping;
-	struct amdgpu_vm *wptr_vm;
-	struct amdgpu_userq_obj *wptr_obj = &queue->wptr_obj;
-	int ret;
-
-	wptr_vm = queue->vm;
-	ret = amdgpu_bo_reserve(wptr_vm->root.bo, false);
-	if (ret)
-		return ret;
-
-	wptr &= AMDGPU_GMC_HOLE_MASK;
-	wptr_mapping = amdgpu_vm_bo_lookup_mapping(wptr_vm, wptr >> PAGE_SHIFT);
-	amdgpu_bo_unreserve(wptr_vm->root.bo);
-	if (!wptr_mapping) {
-		DRM_ERROR("Failed to lookup wptr bo\n");
-		return -EINVAL;
-	}
-
-	wptr_obj->obj = wptr_mapping->bo_va->base.bo;
-	if (wptr_obj->obj->tbo.base.size > PAGE_SIZE) {
-		DRM_ERROR("Requested GART mapping for wptr bo larger than one page\n");
-		return -EINVAL;
-	}
-
-	ret = mes_userq_map_gtt_bo_to_gart(wptr_obj->obj);
-	if (ret) {
-		DRM_ERROR("Failed to map wptr bo to GART\n");
-		return ret;
-	}
-
-	ret = amdgpu_bo_reserve(wptr_obj->obj, true);
-	if (ret) {
-		DRM_ERROR("Failed to reserve wptr bo\n");
-		return ret;
-	}
-
-	/* TODO use eviction fence instead of pinning. */
-	ret = amdgpu_bo_pin(wptr_obj->obj, AMDGPU_GEM_DOMAIN_GTT);
-	if (ret) {
-		drm_file_err(uq_mgr->file, "[Usermode queues] Failed to pin wptr bo\n");
-		goto unresv_bo;
-	}
-
-	queue->wptr_obj.gpu_addr = amdgpu_bo_gpu_offset(wptr_obj->obj);
-	amdgpu_bo_unreserve(wptr_obj->obj);
-
-	return 0;
-
-unresv_bo:
-	amdgpu_bo_unreserve(wptr_obj->obj);
-	return ret;
-
-}
-
 static int convert_to_mes_priority(int priority)
 {
 	switch (priority) {
@@ -413,7 +325,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 	}
 
 	/* FW expects WPTR BOs to be mapped into GART */
-	r = mes_userq_create_wptr_mapping(adev, uq_mgr, queue, userq_props->wptr_gpu_addr);
+	r = amdgpu_userq_create_wptr_mapping(uq_mgr, queue, userq_props->wptr_gpu_addr);
 	if (r) {
 		DRM_ERROR("Failed to create WPTR mapping\n");
 		goto free_ctx;
-- 
2.43.0


  parent reply	other threads:[~2026-02-10 21:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-10 21:47 [PATCH 00/14] user queue support for VCN 4.0.5 David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 01/14] amdgpu: add global aggregated doorbell bo David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 02/14] drm/amdgpu: add AMDGPU_GEM_GLOBAL_AGGREGATED_DOORBELL David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 03/14] drm/amdgpu/userq: add doorbell size for VCN and VPE David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 04/14] amdgpu/umsch: Update UMSCH interface and mqd structure David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 05/14] drm/amdgpu: use amdgpu_user_queue instead of amdgpu_umsch_mm David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 06/14] drm/amdgpu/vcn: changes when kernel queue is disabled David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 07/14] amdgpu/umsch: Add VCN IP init to umsch driver David (Ming Qiang) Wu
2026-02-10 21:47 ` David (Ming Qiang) Wu [this message]
2026-02-10 21:47 ` [PATCH 09/14] drm/amdgpu/userq: rework on amdgpu_userq_create_wptr_mapping David (Ming Qiang) Wu
2026-04-24 13:37   ` Alex Deucher
2026-04-27  8:44     ` Zhang, Jesse(Jie)
2026-02-10 21:47 ` [PATCH 10/14] drm/amdgpu/umsch: user queue support for vcn David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 11/14] drm/amdgpu: add AMDGPU_INFO_DOORBELL David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 12/14] drm/amdgpu/vcn: handle interrupt received from fw David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 13/14] drm/amdgpu/umsch: userq suspend and resume context David (Ming Qiang) Wu
2026-02-10 21:47 ` [PATCH 14/14] drm/amdgpu/vcn: handle the suspend context interrupt David (Ming Qiang) Wu
2026-02-18 15:37 ` [PATCH 00/14] user queue support for VCN 4.0.5 Saleemkhan
2026-02-18 18:13   ` Wu, David
2026-02-18 23:59     ` Saleemkhan
2026-02-19 18:00 ` David Wu
2026-04-17 15:22   ` Wu, David

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=20260210214729.80964-9-David.Wu3@amd.com \
    --to=david.wu3@amd.com \
    --cc=Boyuan.Zhang@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=leo.liu@amd.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