Re: [PATCH 5/8] drm/amdgpu: Create context for usermode queue

2023-02-07 Thread Alex Deucher
On Tue, Feb 7, 2023 at 11:51 AM Alex Deucher  wrote:
>
> On Fri, Feb 3, 2023 at 4:54 PM Shashank Sharma  
> wrote:
> >
> > The FW expects us to allocate atleast one page as context space to
> > process gang, process, shadow, GDS and FW_space related work. This
> > patch creates some object for the same, and adds an IP specific
> > functions to do this.
> >
> > Cc: Alex Deucher 
> > Cc: Christian Koenig 
> > Signed-off-by: Shashank Sharma 
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  32 +
> >  .../amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c | 121 ++
> >  .../gpu/drm/amd/include/amdgpu_userqueue.h|  18 +++
> >  3 files changed, 171 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c 
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> > index 9f3490a91776..18281b3a51f1 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> > @@ -42,6 +42,28 @@ static struct amdgpu_usermode_queue
> >  return idr_find(_mgr->userq_idr, qid);
> >  }
> >
> > +static void
> > +amdgpu_userqueue_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
> > +   struct amdgpu_usermode_queue *queue)
> > +{
> > +uq_mgr->userq_mqd_funcs->ctx_destroy(uq_mgr, queue);
> > +}
> > +
> > +static int
> > +amdgpu_userqueue_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
> > +  struct amdgpu_usermode_queue *queue)
> > +{
> > +int r;
> > +
> > +r = uq_mgr->userq_mqd_funcs->ctx_create(uq_mgr, queue);
> > +if (r) {
> > +DRM_ERROR("Failed to create context space for queue\n");
> > +return r;
> > +}
> > +
> > +return 0;
> > +}
> > +
> >  static int
> >  amdgpu_userqueue_create_mqd(struct amdgpu_userq_mgr *uq_mgr, struct 
> > amdgpu_usermode_queue *queue)
> >  {
> > @@ -142,12 +164,21 @@ static int amdgpu_userqueue_create(struct drm_file 
> > *filp, union drm_amdgpu_userq
> >  goto free_qid;
> >  }
> >
> > +r = amdgpu_userqueue_create_ctx_space(uq_mgr, queue);
> > +if (r) {
> > +DRM_ERROR("Failed to create context space\n");
> > +goto free_mqd;
> > +}
> > +
> >  list_add_tail(>userq_node, _mgr->userq_list);
> >  args->out.q_id = queue->queue_id;
> >  args->out.flags = 0;
> >  mutex_unlock(_mgr->userq_mutex);
> >  return 0;
> >
> > +free_mqd:
> > +amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
> > +
> >  free_qid:
> >  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
> >
> > @@ -170,6 +201,7 @@ static void amdgpu_userqueue_destroy(struct drm_file 
> > *filp, int queue_id)
> >  }
> >
> >  mutex_lock(_mgr->userq_mutex);
> > +amdgpu_userqueue_destroy_ctx_space(uq_mgr, queue);
> >  amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
> >  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
> >  list_del(>userq_node);
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c 
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
> > index 57889729d635..687f90a587e3 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
> > @@ -120,6 +120,125 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct 
> > amdgpu_userq_mgr *uq_mgr, struct amdgpu_
> >
> >  }
> >
> > +static int amdgpu_userq_gfx_v11_ctx_create(struct amdgpu_userq_mgr *uq_mgr,
> > +   struct amdgpu_usermode_queue 
> > *queue)
> > +{
> > +int r;
> > +struct amdgpu_device *adev = uq_mgr->adev;
> > +struct amdgpu_userq_ctx *pctx = >proc_ctx;
> > +struct amdgpu_userq_ctx *gctx = >gang_ctx;
> > +struct amdgpu_userq_ctx *gdsctx = >gds_ctx;
> > +struct amdgpu_userq_ctx *fwctx = >fw_ctx;
> > +struct amdgpu_userq_ctx *sctx = >shadow_ctx;
> > +
> > +/*
> > + * The FW expects atleast one page space allocated for
> > + * process context related work, and one for gang context.
> > + */
> > +r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_PROC_CTX_SZ, PAGE_SIZE,
> > +AMDGPU_GEM_DOMAIN_VRAM,
> > +>obj,
> > +>gpu_addr,
> > +>cpu_ptr);
> > +if (r) {
> > +DRM_ERROR("Failed to allocate proc bo for userqueue (%d)", r);
> > +return r;
> > +}
> > +
> > +r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GANG_CTX_SZ, PAGE_SIZE,
> > +AMDGPU_GEM_DOMAIN_VRAM,
> > +>obj,
> > +>gpu_addr,
> > +>cpu_ptr);
> > +if (r) {
> > +DRM_ERROR("Failed to allocate gang bo for userqueue (%d)", r);
> > +goto err_gangctx;
> > +}
> > +
> > +r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GDS_CTX_SZ, PAGE_SIZE,
> > +

Re: [PATCH 5/8] drm/amdgpu: Create context for usermode queue

2023-02-07 Thread Alex Deucher
On Fri, Feb 3, 2023 at 4:54 PM Shashank Sharma  wrote:
>
> The FW expects us to allocate atleast one page as context space to
> process gang, process, shadow, GDS and FW_space related work. This
> patch creates some object for the same, and adds an IP specific
> functions to do this.
>
> Cc: Alex Deucher 
> Cc: Christian Koenig 
> Signed-off-by: Shashank Sharma 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  32 +
>  .../amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c | 121 ++
>  .../gpu/drm/amd/include/amdgpu_userqueue.h|  18 +++
>  3 files changed, 171 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> index 9f3490a91776..18281b3a51f1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> @@ -42,6 +42,28 @@ static struct amdgpu_usermode_queue
>  return idr_find(_mgr->userq_idr, qid);
>  }
>
> +static void
> +amdgpu_userqueue_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
> +   struct amdgpu_usermode_queue *queue)
> +{
> +uq_mgr->userq_mqd_funcs->ctx_destroy(uq_mgr, queue);
> +}
> +
> +static int
> +amdgpu_userqueue_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
> +  struct amdgpu_usermode_queue *queue)
> +{
> +int r;
> +
> +r = uq_mgr->userq_mqd_funcs->ctx_create(uq_mgr, queue);
> +if (r) {
> +DRM_ERROR("Failed to create context space for queue\n");
> +return r;
> +}
> +
> +return 0;
> +}
> +
>  static int
>  amdgpu_userqueue_create_mqd(struct amdgpu_userq_mgr *uq_mgr, struct 
> amdgpu_usermode_queue *queue)
>  {
> @@ -142,12 +164,21 @@ static int amdgpu_userqueue_create(struct drm_file 
> *filp, union drm_amdgpu_userq
>  goto free_qid;
>  }
>
> +r = amdgpu_userqueue_create_ctx_space(uq_mgr, queue);
> +if (r) {
> +DRM_ERROR("Failed to create context space\n");
> +goto free_mqd;
> +}
> +
>  list_add_tail(>userq_node, _mgr->userq_list);
>  args->out.q_id = queue->queue_id;
>  args->out.flags = 0;
>  mutex_unlock(_mgr->userq_mutex);
>  return 0;
>
> +free_mqd:
> +amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
> +
>  free_qid:
>  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
>
> @@ -170,6 +201,7 @@ static void amdgpu_userqueue_destroy(struct drm_file 
> *filp, int queue_id)
>  }
>
>  mutex_lock(_mgr->userq_mutex);
> +amdgpu_userqueue_destroy_ctx_space(uq_mgr, queue);
>  amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
>  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
>  list_del(>userq_node);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
> index 57889729d635..687f90a587e3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
> @@ -120,6 +120,125 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct 
> amdgpu_userq_mgr *uq_mgr, struct amdgpu_
>
>  }
>
> +static int amdgpu_userq_gfx_v11_ctx_create(struct amdgpu_userq_mgr *uq_mgr,
> +   struct amdgpu_usermode_queue 
> *queue)
> +{
> +int r;
> +struct amdgpu_device *adev = uq_mgr->adev;
> +struct amdgpu_userq_ctx *pctx = >proc_ctx;
> +struct amdgpu_userq_ctx *gctx = >gang_ctx;
> +struct amdgpu_userq_ctx *gdsctx = >gds_ctx;
> +struct amdgpu_userq_ctx *fwctx = >fw_ctx;
> +struct amdgpu_userq_ctx *sctx = >shadow_ctx;
> +
> +/*
> + * The FW expects atleast one page space allocated for
> + * process context related work, and one for gang context.
> + */
> +r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_PROC_CTX_SZ, PAGE_SIZE,
> +AMDGPU_GEM_DOMAIN_VRAM,
> +>obj,
> +>gpu_addr,
> +>cpu_ptr);
> +if (r) {
> +DRM_ERROR("Failed to allocate proc bo for userqueue (%d)", r);
> +return r;
> +}
> +
> +r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GANG_CTX_SZ, PAGE_SIZE,
> +AMDGPU_GEM_DOMAIN_VRAM,
> +>obj,
> +>gpu_addr,
> +>cpu_ptr);
> +if (r) {
> +DRM_ERROR("Failed to allocate gang bo for userqueue (%d)", r);
> +goto err_gangctx;
> +}
> +
> +r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GDS_CTX_SZ, PAGE_SIZE,
> +AMDGPU_GEM_DOMAIN_VRAM,
> +>obj,
> +>gpu_addr,
> +>cpu_ptr);
> +if (r) {
> +DRM_ERROR("Failed to allocate GDS bo for userqueue (%d)", r);
> +goto err_gdsctx;
> +}
> +
> +r = 

Re: [PATCH 5/8] drm/amdgpu: Create context for usermode queue

2023-02-07 Thread Shashank Sharma



On 07/02/2023 08:55, Christian König wrote:

Am 07.02.23 um 08:51 schrieb Shashank Sharma:


On 07/02/2023 08:14, Christian König wrote:

Am 03.02.23 um 22:54 schrieb Shashank Sharma:

The FW expects us to allocate atleast one page as context space to
process gang, process, shadow, GDS and FW_space related work. This
patch creates some object for the same, and adds an IP specific
functions to do this.

Cc: Alex Deucher 
Cc: Christian Koenig 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  32 +
  .../amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c | 121 
++

  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  18 +++
  3 files changed, 171 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c

index 9f3490a91776..18281b3a51f1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
@@ -42,6 +42,28 @@ static struct amdgpu_usermode_queue
  return idr_find(_mgr->userq_idr, qid);
  }
  +static void
+amdgpu_userqueue_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+   struct amdgpu_usermode_queue 
*queue)

+{
+    uq_mgr->userq_mqd_funcs->ctx_destroy(uq_mgr, queue);
+}
+
+static int
+amdgpu_userqueue_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+  struct amdgpu_usermode_queue 
*queue)

+{
+    int r;
+
+    r = uq_mgr->userq_mqd_funcs->ctx_create(uq_mgr, queue);
+    if (r) {
+    DRM_ERROR("Failed to create context space for queue\n");
+    return r;
+    }
+
+    return 0;
+}
+
  static int
  amdgpu_userqueue_create_mqd(struct amdgpu_userq_mgr *uq_mgr, 
struct amdgpu_usermode_queue *queue)

  {
@@ -142,12 +164,21 @@ static int amdgpu_userqueue_create(struct 
drm_file *filp, union drm_amdgpu_userq

  goto free_qid;
  }
  +    r = amdgpu_userqueue_create_ctx_space(uq_mgr, queue);
+    if (r) {
+    DRM_ERROR("Failed to create context space\n");
+    goto free_mqd;
+    }
+
  list_add_tail(>userq_node, _mgr->userq_list);
  args->out.q_id = queue->queue_id;
  args->out.flags = 0;
  mutex_unlock(_mgr->userq_mutex);
  return 0;
  +free_mqd:
+    amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
+
  free_qid:
  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
  @@ -170,6 +201,7 @@ static void amdgpu_userqueue_destroy(struct 
drm_file *filp, int queue_id)

  }
    mutex_lock(_mgr->userq_mutex);
+    amdgpu_userqueue_destroy_ctx_space(uq_mgr, queue);
  amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
  list_del(>userq_node);
diff --git 
a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c

index 57889729d635..687f90a587e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
@@ -120,6 +120,125 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct 
amdgpu_userq_mgr *uq_mgr, struct amdgpu_

    }
  +static int amdgpu_userq_gfx_v11_ctx_create(struct 
amdgpu_userq_mgr *uq_mgr,
+   struct 
amdgpu_usermode_queue *queue)

+{
+    int r;
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx *pctx = >proc_ctx;
+    struct amdgpu_userq_ctx *gctx = >gang_ctx;
+    struct amdgpu_userq_ctx *gdsctx = >gds_ctx;
+    struct amdgpu_userq_ctx *fwctx = >fw_ctx;
+    struct amdgpu_userq_ctx *sctx = >shadow_ctx;
+
+    /*
+ * The FW expects atleast one page space allocated for
+ * process context related work, and one for gang context.
+ */
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_PROC_CTX_SZ, 
PAGE_SIZE,

+    AMDGPU_GEM_DOMAIN_VRAM,
+    >obj,
+    >gpu_addr,
+    >cpu_ptr);


Again, don't use amdgpu_bo_create_kernel() for any of this.

Noted,



+    if (r) {
+    DRM_ERROR("Failed to allocate proc bo for userqueue (%d)", 
r);

+    return r;
+    }
+
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GANG_CTX_SZ, 
PAGE_SIZE,

+    AMDGPU_GEM_DOMAIN_VRAM,
+    >obj,
+    >gpu_addr,
+    >cpu_ptr);
+    if (r) {
+    DRM_ERROR("Failed to allocate gang bo for userqueue (%d)", 
r);

+    goto err_gangctx;
+    }
+
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GDS_CTX_SZ, 
PAGE_SIZE,

+    AMDGPU_GEM_DOMAIN_VRAM,
+    >obj,
+    >gpu_addr,
+    >cpu_ptr);
+    if (r) {
+    DRM_ERROR("Failed to allocate GDS bo for userqueue (%d)", r);
+    goto err_gdsctx;
+    }
+
+    r = 

Re: [PATCH 5/8] drm/amdgpu: Create context for usermode queue

2023-02-06 Thread Christian König

Am 07.02.23 um 08:51 schrieb Shashank Sharma:


On 07/02/2023 08:14, Christian König wrote:

Am 03.02.23 um 22:54 schrieb Shashank Sharma:

The FW expects us to allocate atleast one page as context space to
process gang, process, shadow, GDS and FW_space related work. This
patch creates some object for the same, and adds an IP specific
functions to do this.

Cc: Alex Deucher 
Cc: Christian Koenig 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  32 +
  .../amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c | 121 
++

  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  18 +++
  3 files changed, 171 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c

index 9f3490a91776..18281b3a51f1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
@@ -42,6 +42,28 @@ static struct amdgpu_usermode_queue
  return idr_find(_mgr->userq_idr, qid);
  }
  +static void
+amdgpu_userqueue_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+   struct amdgpu_usermode_queue 
*queue)

+{
+    uq_mgr->userq_mqd_funcs->ctx_destroy(uq_mgr, queue);
+}
+
+static int
+amdgpu_userqueue_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+  struct amdgpu_usermode_queue *queue)
+{
+    int r;
+
+    r = uq_mgr->userq_mqd_funcs->ctx_create(uq_mgr, queue);
+    if (r) {
+    DRM_ERROR("Failed to create context space for queue\n");
+    return r;
+    }
+
+    return 0;
+}
+
  static int
  amdgpu_userqueue_create_mqd(struct amdgpu_userq_mgr *uq_mgr, 
struct amdgpu_usermode_queue *queue)

  {
@@ -142,12 +164,21 @@ static int amdgpu_userqueue_create(struct 
drm_file *filp, union drm_amdgpu_userq

  goto free_qid;
  }
  +    r = amdgpu_userqueue_create_ctx_space(uq_mgr, queue);
+    if (r) {
+    DRM_ERROR("Failed to create context space\n");
+    goto free_mqd;
+    }
+
  list_add_tail(>userq_node, _mgr->userq_list);
  args->out.q_id = queue->queue_id;
  args->out.flags = 0;
  mutex_unlock(_mgr->userq_mutex);
  return 0;
  +free_mqd:
+    amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
+
  free_qid:
  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
  @@ -170,6 +201,7 @@ static void amdgpu_userqueue_destroy(struct 
drm_file *filp, int queue_id)

  }
    mutex_lock(_mgr->userq_mutex);
+    amdgpu_userqueue_destroy_ctx_space(uq_mgr, queue);
  amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
  list_del(>userq_node);
diff --git 
a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c

index 57889729d635..687f90a587e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
@@ -120,6 +120,125 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct 
amdgpu_userq_mgr *uq_mgr, struct amdgpu_

    }
  +static int amdgpu_userq_gfx_v11_ctx_create(struct 
amdgpu_userq_mgr *uq_mgr,
+   struct 
amdgpu_usermode_queue *queue)

+{
+    int r;
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx *pctx = >proc_ctx;
+    struct amdgpu_userq_ctx *gctx = >gang_ctx;
+    struct amdgpu_userq_ctx *gdsctx = >gds_ctx;
+    struct amdgpu_userq_ctx *fwctx = >fw_ctx;
+    struct amdgpu_userq_ctx *sctx = >shadow_ctx;
+
+    /*
+ * The FW expects atleast one page space allocated for
+ * process context related work, and one for gang context.
+ */
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_PROC_CTX_SZ, 
PAGE_SIZE,

+    AMDGPU_GEM_DOMAIN_VRAM,
+    >obj,
+    >gpu_addr,
+    >cpu_ptr);


Again, don't use amdgpu_bo_create_kernel() for any of this.

Noted,



+    if (r) {
+    DRM_ERROR("Failed to allocate proc bo for userqueue (%d)", r);
+    return r;
+    }
+
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GANG_CTX_SZ, 
PAGE_SIZE,

+    AMDGPU_GEM_DOMAIN_VRAM,
+    >obj,
+    >gpu_addr,
+    >cpu_ptr);
+    if (r) {
+    DRM_ERROR("Failed to allocate gang bo for userqueue (%d)", r);
+    goto err_gangctx;
+    }
+
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GDS_CTX_SZ, 
PAGE_SIZE,

+    AMDGPU_GEM_DOMAIN_VRAM,
+    >obj,
+    >gpu_addr,
+    >cpu_ptr);
+    if (r) {
+    DRM_ERROR("Failed to allocate GDS bo for userqueue (%d)", r);
+    goto err_gdsctx;
+    }
+
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_FW_CTX_SZ, 
PAGE_SIZE,

+  

Re: [PATCH 5/8] drm/amdgpu: Create context for usermode queue

2023-02-06 Thread Shashank Sharma



On 07/02/2023 08:14, Christian König wrote:

Am 03.02.23 um 22:54 schrieb Shashank Sharma:

The FW expects us to allocate atleast one page as context space to
process gang, process, shadow, GDS and FW_space related work. This
patch creates some object for the same, and adds an IP specific
functions to do this.

Cc: Alex Deucher 
Cc: Christian Koenig 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  32 +
  .../amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c | 121 ++
  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  18 +++
  3 files changed, 171 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c

index 9f3490a91776..18281b3a51f1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
@@ -42,6 +42,28 @@ static struct amdgpu_usermode_queue
  return idr_find(_mgr->userq_idr, qid);
  }
  +static void
+amdgpu_userqueue_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+   struct amdgpu_usermode_queue *queue)
+{
+    uq_mgr->userq_mqd_funcs->ctx_destroy(uq_mgr, queue);
+}
+
+static int
+amdgpu_userqueue_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+  struct amdgpu_usermode_queue *queue)
+{
+    int r;
+
+    r = uq_mgr->userq_mqd_funcs->ctx_create(uq_mgr, queue);
+    if (r) {
+    DRM_ERROR("Failed to create context space for queue\n");
+    return r;
+    }
+
+    return 0;
+}
+
  static int
  amdgpu_userqueue_create_mqd(struct amdgpu_userq_mgr *uq_mgr, struct 
amdgpu_usermode_queue *queue)

  {
@@ -142,12 +164,21 @@ static int amdgpu_userqueue_create(struct 
drm_file *filp, union drm_amdgpu_userq

  goto free_qid;
  }
  +    r = amdgpu_userqueue_create_ctx_space(uq_mgr, queue);
+    if (r) {
+    DRM_ERROR("Failed to create context space\n");
+    goto free_mqd;
+    }
+
  list_add_tail(>userq_node, _mgr->userq_list);
  args->out.q_id = queue->queue_id;
  args->out.flags = 0;
  mutex_unlock(_mgr->userq_mutex);
  return 0;
  +free_mqd:
+    amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
+
  free_qid:
  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
  @@ -170,6 +201,7 @@ static void amdgpu_userqueue_destroy(struct 
drm_file *filp, int queue_id)

  }
    mutex_lock(_mgr->userq_mutex);
+    amdgpu_userqueue_destroy_ctx_space(uq_mgr, queue);
  amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
  list_del(>userq_node);
diff --git 
a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c

index 57889729d635..687f90a587e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
@@ -120,6 +120,125 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct 
amdgpu_userq_mgr *uq_mgr, struct amdgpu_

    }
  +static int amdgpu_userq_gfx_v11_ctx_create(struct amdgpu_userq_mgr 
*uq_mgr,
+   struct 
amdgpu_usermode_queue *queue)

+{
+    int r;
+    struct amdgpu_device *adev = uq_mgr->adev;
+    struct amdgpu_userq_ctx *pctx = >proc_ctx;
+    struct amdgpu_userq_ctx *gctx = >gang_ctx;
+    struct amdgpu_userq_ctx *gdsctx = >gds_ctx;
+    struct amdgpu_userq_ctx *fwctx = >fw_ctx;
+    struct amdgpu_userq_ctx *sctx = >shadow_ctx;
+
+    /*
+ * The FW expects atleast one page space allocated for
+ * process context related work, and one for gang context.
+ */
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_PROC_CTX_SZ, 
PAGE_SIZE,

+    AMDGPU_GEM_DOMAIN_VRAM,
+    >obj,
+    >gpu_addr,
+    >cpu_ptr);


Again, don't use amdgpu_bo_create_kernel() for any of this.

Noted,



+    if (r) {
+    DRM_ERROR("Failed to allocate proc bo for userqueue (%d)", r);
+    return r;
+    }
+
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GANG_CTX_SZ, 
PAGE_SIZE,

+    AMDGPU_GEM_DOMAIN_VRAM,
+    >obj,
+    >gpu_addr,
+    >cpu_ptr);
+    if (r) {
+    DRM_ERROR("Failed to allocate gang bo for userqueue (%d)", r);
+    goto err_gangctx;
+    }
+
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GDS_CTX_SZ, 
PAGE_SIZE,

+    AMDGPU_GEM_DOMAIN_VRAM,
+    >obj,
+    >gpu_addr,
+    >cpu_ptr);
+    if (r) {
+    DRM_ERROR("Failed to allocate GDS bo for userqueue (%d)", r);
+    goto err_gdsctx;
+    }
+
+    r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_FW_CTX_SZ, 
PAGE_SIZE,

+    

Re: [PATCH 5/8] drm/amdgpu: Create context for usermode queue

2023-02-06 Thread Christian König

Am 03.02.23 um 22:54 schrieb Shashank Sharma:

The FW expects us to allocate atleast one page as context space to
process gang, process, shadow, GDS and FW_space related work. This
patch creates some object for the same, and adds an IP specific
functions to do this.

Cc: Alex Deucher 
Cc: Christian Koenig 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  32 +
  .../amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c | 121 ++
  .../gpu/drm/amd/include/amdgpu_userqueue.h|  18 +++
  3 files changed, 171 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
index 9f3490a91776..18281b3a51f1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
@@ -42,6 +42,28 @@ static struct amdgpu_usermode_queue
  return idr_find(_mgr->userq_idr, qid);
  }
  
+static void

+amdgpu_userqueue_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+   struct amdgpu_usermode_queue *queue)
+{
+uq_mgr->userq_mqd_funcs->ctx_destroy(uq_mgr, queue);
+}
+
+static int
+amdgpu_userqueue_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+  struct amdgpu_usermode_queue *queue)
+{
+int r;
+
+r = uq_mgr->userq_mqd_funcs->ctx_create(uq_mgr, queue);
+if (r) {
+DRM_ERROR("Failed to create context space for queue\n");
+return r;
+}
+
+return 0;
+}
+
  static int
  amdgpu_userqueue_create_mqd(struct amdgpu_userq_mgr *uq_mgr, struct 
amdgpu_usermode_queue *queue)
  {
@@ -142,12 +164,21 @@ static int amdgpu_userqueue_create(struct drm_file *filp, 
union drm_amdgpu_userq
  goto free_qid;
  }
  
+r = amdgpu_userqueue_create_ctx_space(uq_mgr, queue);

+if (r) {
+DRM_ERROR("Failed to create context space\n");
+goto free_mqd;
+}
+
  list_add_tail(>userq_node, _mgr->userq_list);
  args->out.q_id = queue->queue_id;
  args->out.flags = 0;
  mutex_unlock(_mgr->userq_mutex);
  return 0;
  
+free_mqd:

+amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
+
  free_qid:
  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
  
@@ -170,6 +201,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)

  }
  
  mutex_lock(_mgr->userq_mutex);

+amdgpu_userqueue_destroy_ctx_space(uq_mgr, queue);
  amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
  amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
  list_del(>userq_node);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
index 57889729d635..687f90a587e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
@@ -120,6 +120,125 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr 
*uq_mgr, struct amdgpu_
  
  }
  
+static int amdgpu_userq_gfx_v11_ctx_create(struct amdgpu_userq_mgr *uq_mgr,

+   struct amdgpu_usermode_queue *queue)
+{
+int r;
+struct amdgpu_device *adev = uq_mgr->adev;
+struct amdgpu_userq_ctx *pctx = >proc_ctx;
+struct amdgpu_userq_ctx *gctx = >gang_ctx;
+struct amdgpu_userq_ctx *gdsctx = >gds_ctx;
+struct amdgpu_userq_ctx *fwctx = >fw_ctx;
+struct amdgpu_userq_ctx *sctx = >shadow_ctx;
+
+/*
+ * The FW expects atleast one page space allocated for
+ * process context related work, and one for gang context.
+ */
+r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_PROC_CTX_SZ, PAGE_SIZE,
+AMDGPU_GEM_DOMAIN_VRAM,
+>obj,
+>gpu_addr,
+>cpu_ptr);


Again, don't use amdgpu_bo_create_kernel() for any of this.


+if (r) {
+DRM_ERROR("Failed to allocate proc bo for userqueue (%d)", r);
+return r;
+}
+
+r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GANG_CTX_SZ, PAGE_SIZE,
+AMDGPU_GEM_DOMAIN_VRAM,
+>obj,
+>gpu_addr,
+>cpu_ptr);
+if (r) {
+DRM_ERROR("Failed to allocate gang bo for userqueue (%d)", r);
+goto err_gangctx;
+}
+
+r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GDS_CTX_SZ, PAGE_SIZE,
+AMDGPU_GEM_DOMAIN_VRAM,
+>obj,
+>gpu_addr,
+>cpu_ptr);
+if (r) {
+DRM_ERROR("Failed to allocate GDS bo for userqueue (%d)", r);
+goto err_gdsctx;
+}
+
+r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_FW_CTX_SZ, PAGE_SIZE,
+AMDGPU_GEM_DOMAIN_VRAM,
+>obj,
+  

[PATCH 5/8] drm/amdgpu: Create context for usermode queue

2023-02-03 Thread Shashank Sharma
The FW expects us to allocate atleast one page as context space to
process gang, process, shadow, GDS and FW_space related work. This
patch creates some object for the same, and adds an IP specific
functions to do this.

Cc: Alex Deucher 
Cc: Christian Koenig 
Signed-off-by: Shashank Sharma 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c |  32 +
 .../amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c | 121 ++
 .../gpu/drm/amd/include/amdgpu_userqueue.h|  18 +++
 3 files changed, 171 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
index 9f3490a91776..18281b3a51f1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
@@ -42,6 +42,28 @@ static struct amdgpu_usermode_queue
 return idr_find(_mgr->userq_idr, qid);
 }
 
+static void
+amdgpu_userqueue_destroy_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+   struct amdgpu_usermode_queue *queue)
+{
+uq_mgr->userq_mqd_funcs->ctx_destroy(uq_mgr, queue);
+}
+
+static int
+amdgpu_userqueue_create_ctx_space(struct amdgpu_userq_mgr *uq_mgr,
+  struct amdgpu_usermode_queue *queue)
+{
+int r;
+
+r = uq_mgr->userq_mqd_funcs->ctx_create(uq_mgr, queue);
+if (r) {
+DRM_ERROR("Failed to create context space for queue\n");
+return r;
+}
+
+return 0;
+}
+
 static int
 amdgpu_userqueue_create_mqd(struct amdgpu_userq_mgr *uq_mgr, struct 
amdgpu_usermode_queue *queue)
 {
@@ -142,12 +164,21 @@ static int amdgpu_userqueue_create(struct drm_file *filp, 
union drm_amdgpu_userq
 goto free_qid;
 }
 
+r = amdgpu_userqueue_create_ctx_space(uq_mgr, queue);
+if (r) {
+DRM_ERROR("Failed to create context space\n");
+goto free_mqd;
+}
+
 list_add_tail(>userq_node, _mgr->userq_list);
 args->out.q_id = queue->queue_id;
 args->out.flags = 0;
 mutex_unlock(_mgr->userq_mutex);
 return 0;
 
+free_mqd:
+amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
+
 free_qid:
 amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
 
@@ -170,6 +201,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, 
int queue_id)
 }
 
 mutex_lock(_mgr->userq_mutex);
+amdgpu_userqueue_destroy_ctx_space(uq_mgr, queue);
 amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
 amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
 list_del(>userq_node);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
index 57889729d635..687f90a587e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_mqd_gfx_v11.c
@@ -120,6 +120,125 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr 
*uq_mgr, struct amdgpu_
 
 }
 
+static int amdgpu_userq_gfx_v11_ctx_create(struct amdgpu_userq_mgr *uq_mgr,
+   struct amdgpu_usermode_queue *queue)
+{
+int r;
+struct amdgpu_device *adev = uq_mgr->adev;
+struct amdgpu_userq_ctx *pctx = >proc_ctx;
+struct amdgpu_userq_ctx *gctx = >gang_ctx;
+struct amdgpu_userq_ctx *gdsctx = >gds_ctx;
+struct amdgpu_userq_ctx *fwctx = >fw_ctx;
+struct amdgpu_userq_ctx *sctx = >shadow_ctx;
+
+/*
+ * The FW expects atleast one page space allocated for
+ * process context related work, and one for gang context.
+ */
+r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_PROC_CTX_SZ, PAGE_SIZE,
+AMDGPU_GEM_DOMAIN_VRAM,
+>obj,
+>gpu_addr,
+>cpu_ptr);
+if (r) {
+DRM_ERROR("Failed to allocate proc bo for userqueue (%d)", r);
+return r;
+}
+
+r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GANG_CTX_SZ, PAGE_SIZE,
+AMDGPU_GEM_DOMAIN_VRAM,
+>obj,
+>gpu_addr,
+>cpu_ptr);
+if (r) {
+DRM_ERROR("Failed to allocate gang bo for userqueue (%d)", r);
+goto err_gangctx;
+}
+
+r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_GDS_CTX_SZ, PAGE_SIZE,
+AMDGPU_GEM_DOMAIN_VRAM,
+>obj,
+>gpu_addr,
+>cpu_ptr);
+if (r) {
+DRM_ERROR("Failed to allocate GDS bo for userqueue (%d)", r);
+goto err_gdsctx;
+}
+
+r = amdgpu_bo_create_kernel(adev, AMDGPU_USERQ_FW_CTX_SZ, PAGE_SIZE,
+AMDGPU_GEM_DOMAIN_VRAM,
+>obj,
+>gpu_addr,
+>cpu_ptr);
+if (r) {
+DRM_ERROR("Failed to allocate FW bo for userqueue