All of lore.kernel.org
 help / color / mirror / Atom feed
From: zhoucm1 <david1.zhou-5C7GfCeVMHo@public.gmane.org>
To: "Christian König"
	<deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations
Date: Tue, 26 Jul 2016 16:11:46 +0800	[thread overview]
Message-ID: <57971B42.7070803@amd.com> (raw)
In-Reply-To: <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>

the set looks good to me, Reviewed-by: Chunming Zhou <david1.zhou@amd.com>

On 2016年07月26日 16:00, Christian König wrote:
> From: Christian König <christian.koenig@amd.com>
>
> We often allocate, pin and map things at the same time in the kernel.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 63 ++++++++++++++++++++++++++++++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  4 ++
>   2 files changed, 67 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 6f0873c..9357358 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -211,6 +211,69 @@ static void amdgpu_fill_placement_to_bo(struct amdgpu_bo *bo,
>   	bo->placement.busy_placement = bo->placements;
>   }
>   
> +/**
> + * amdgpu_bo_create_kernel - create BO for kernel use
> + *
> + * @adev: amdgpu device object
> + * @size: size for the new BO
> + * @align: alignment for the new BO
> + * @domain: where to place it
> + * @bo_ptr: resulting BO
> + * @gpu_addr: GPU addr of the pinned BO
> + * @cpu_addr: optional CPU address mapping
> + *
> + * Allocates and pins a BO for kernel internal use.
> + *
> + * Returns 0 on success, negative error code otherwise.
> + */
> +int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
> +			    unsigned long size, int align,
> +			    u32 domain, struct amdgpu_bo **bo_ptr,
> +			    u64 *gpu_addr, void **cpu_addr)
> +{
> +	int r;
> +
> +	r = amdgpu_bo_create(adev, size, align, true, domain,
> +			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
> +			     NULL, NULL, bo_ptr);
> +	if (r) {
> +		dev_err(adev->dev, "(%d) failed to allocate kernel bo\n", r);
> +		return r;
> +	}
> +
> +	r = amdgpu_bo_reserve(*bo_ptr, false);
> +	if (r) {
> +		dev_err(adev->dev, "(%d) failed to reserve kernel bo\n", r);
> +		goto error_free;
> +	}
> +
> +	r = amdgpu_bo_pin(*bo_ptr, domain, gpu_addr);
> +	if (r) {
> +		dev_err(adev->dev, "(%d) kernel bo pin failed\n", r);
> +		goto error_unreserve;
> +	}
> +
> +	if (cpu_addr) {
> +		r = amdgpu_bo_kmap(*bo_ptr, cpu_addr);
> +		if (r) {
> +			dev_err(adev->dev, "(%d) kernel bo map failed\n", r);
> +			goto error_unreserve;
> +		}
> +	}
> +
> +	amdgpu_bo_unreserve(*bo_ptr);
> +
> +	return 0;
> +
> +error_unreserve:
> +	amdgpu_bo_unreserve(*bo_ptr);
> +
> +error_free:
> +	amdgpu_bo_unref(bo_ptr);
> +
> +	return r;
> +}
> +
>   int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
>   				unsigned long size, int byte_align,
>   				bool kernel, u32 domain, u64 flags,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index bdb01d9..ae188a8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -139,6 +139,10 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
>   				struct ttm_placement *placement,
>   			        struct reservation_object *resv,
>   				struct amdgpu_bo **bo_ptr);
> +int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
> +			    unsigned long size, int align,
> +			    u32 domain, struct amdgpu_bo **bo_ptr,
> +			    u64 *gpu_addr, void **cpu_addr);
>   int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);
>   void amdgpu_bo_kunmap(struct amdgpu_bo *bo);
>   struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo);

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

  parent reply	other threads:[~2016-07-26  8:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-26  8:00 [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations Christian König
     [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2016-07-26  8:00   ` [PATCH 2/6] drm/amdgpu: pin shared GWS, GDS and OA resources Christian König
2016-07-26  8:00   ` [PATCH 3/6] drm/amdgpu: add more warning to amdgpu_bo_offset Christian König
2016-07-26  8:00   ` [PATCH 4/6] drm/amdgpu: user amdgpu_bo_create_kernel for the UVD BO Christian König
2016-07-26  8:00   ` [PATCH 5/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ih.c Christian König
2016-07-26  8:00   ` [PATCH 6/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ring.c Christian König
     [not found]     ` <1469520017-8422-6-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2016-07-28  3:56       ` Deucher, Alexander
2016-07-26  8:11   ` zhoucm1 [this message]
2016-07-26 23:54   ` [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations Edward O'Callaghan

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=57971B42.7070803@amd.com \
    --to=david1.zhou-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org \
    /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.