AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com>, alexander.deucher@amd.com
Cc: Harry Wentland <harry.wentland@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amd/display: Implement functions to let DC allocate GPU memory
Date: Wed, 20 Jan 2021 11:26:16 +0100	[thread overview]
Message-ID: <fab8baec-78fa-d816-3e05-ad94215c83f2@gmail.com> (raw)
In-Reply-To: <20210119204030.2794877-1-Bhawanpreet.Lakha@amd.com>

Am 19.01.21 um 21:40 schrieb Bhawanpreet Lakha:
> From: Harry Wentland <harry.wentland@amd.com>
>
> [Why]
> DC needs to communicate with PM FW through GPU memory. In order
> to do so we need to be able to allocate memory from within DC.
>
> [How]
> Call amdgpu_bo_create_kernel to allocate GPU memory and use a
> list in amdgpu_display_manager to track our allocations so we
> can clean them up later.

Well that looks like classic mid-layering to me with a horrible 
implementation of the free function.

Christian.

>
> Signed-off-by: Harry Wentland <harry.wentland@amd.com>
> ---
>   .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  2 +
>   .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  9 +++++
>   .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 40 +++++++++++++++++--
>   3 files changed, 48 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index e490fc2486f7..83ec92a69cba 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -1017,6 +1017,8 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
>   
>   	init_data.soc_bounding_box = adev->dm.soc_bounding_box;
>   
> +	INIT_LIST_HEAD(&adev->dm.da_list);
> +
>   	/* Display Core create. */
>   	adev->dm.dc = dc_create(&init_data);
>   
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
> index 38bc0f88b29c..49137924a855 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
> @@ -130,6 +130,13 @@ struct amdgpu_dm_backlight_caps {
>   	bool aux_support;
>   };
>   
> +struct dal_allocation {
> +	struct list_head list;
> +	struct amdgpu_bo *bo;
> +	void *cpu_ptr;
> +	u64 gpu_addr;
> +};
> +
>   /**
>    * struct amdgpu_display_manager - Central amdgpu display manager device
>    *
> @@ -350,6 +357,8 @@ struct amdgpu_display_manager {
>   	 */
>   	struct amdgpu_encoder mst_encoders[AMDGPU_DM_MAX_CRTC];
>   	bool force_timing_sync;
> +
> +	struct list_head da_list;
>   };
>   
>   enum dsc_clock_force_state {
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
> index 3244a6ea7a65..5dc426e6e785 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
> @@ -652,8 +652,31 @@ void *dm_helpers_allocate_gpu_mem(
>   		size_t size,
>   		long long *addr)
>   {
> -	// TODO
> -	return NULL;
> +	struct amdgpu_device *adev = ctx->driver_context;
> +	struct dal_allocation *da;
> +	u32 domain = (type == DC_MEM_ALLOC_TYPE_GART) ?
> +		AMDGPU_GEM_DOMAIN_GTT : AMDGPU_GEM_DOMAIN_VRAM;
> +	int ret;
> +
> +	da = kzalloc(sizeof(struct dal_allocation), GFP_KERNEL);
> +	if (!da)
> +		return NULL;
> +
> +	ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
> +				      domain, &da->bo,
> +				      &da->gpu_addr, &da->cpu_ptr);
> +
> +	*addr = da->gpu_addr;
> +
> +	if (ret) {
> +		kfree(da);
> +		return NULL;
> +	}
> +
> +	/* add da to list in dm */
> +	list_add(&da->list, &adev->dm.da_list);
> +
> +	return da->cpu_ptr;
>   }
>   
>   void dm_helpers_free_gpu_mem(
> @@ -661,5 +684,16 @@ void dm_helpers_free_gpu_mem(
>   		enum dc_gpu_mem_alloc_type type,
>   		void *pvMem)
>   {
> -	// TODO
> +	struct amdgpu_device *adev = ctx->driver_context;
> +	struct dal_allocation *da;
> +
> +	/* walk the da list in DM */
> +	list_for_each_entry(da, &adev->dm.da_list, list) {
> +		if (pvMem == da->cpu_ptr) {
> +			amdgpu_bo_free_kernel(&da->bo, &da->gpu_addr, &da->cpu_ptr);
> +			list_del(&da->list);
> +			kfree(da);
> +			break;
> +		}
> +	}
>   }

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2021-01-20 10:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-19 20:40 [PATCH] drm/amd/display: Implement functions to let DC allocate GPU memory Bhawanpreet Lakha
2021-01-19 22:10 ` Kazlauskas, Nicholas
2021-01-20  1:53 ` Chen, Guchun
2021-01-20 10:26 ` Christian König [this message]
2021-01-20 14:16   ` Kazlauskas, Nicholas
2021-01-20 14:45     ` Christian König

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=fab8baec-78fa-d816-3e05-ad94215c83f2@gmail.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=Bhawanpreet.Lakha@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=harry.wentland@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