drm/amdgpu: add new helper for in kernel allocations
Subsystems (2)
PATCH 1/6 drm/amdgpu: add new helper for in kernel allocations
From: Christian König <[email protected]>
We often allocate, pin and map things at the same time in the kernel.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 63 ++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 4 ++ 2 files changed, 67 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +63 -0
@@ -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,
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +4 -0
@@ -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);
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
PATCH 2/6 drm/amdgpu: pin shared GWS, GDS and OA resources
From: Christian König <[email protected]>
They can't move anyway, but just to be clean here.
--- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 21 +++++++++------------ drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 21 +++++++++------------ 2 files changed, 18 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +9 -12
@@ -4451,24 +4451,21 @@ static int gfx_v7_0_sw_init(void *handle) }/* reserve GDS, GWS and OA resource for gfx */ - r =amdgpu_bo_create (adev, adev->gds.mem.gfx_partition_size, -PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_GDS ,0 , -NULL ,NULL , &adev->gds.gds_gfx_bo); + r =amdgpu_bo_create_kernel (adev, adev->gds.mem.gfx_partition_size, +PAGE_SIZE ,AMDGPU_GEM_DOMAIN_GDS , + &adev->gds.gds_gfx_bo,NULL ,NULL );if (r)return r; - r =amdgpu_bo_create (adev, adev->gds.gws.gfx_partition_size, -PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_GWS ,0 , -NULL ,NULL , &adev->gds.gws_gfx_bo); + r =amdgpu_bo_create_kernel (adev, adev->gds.gws.gfx_partition_size, +PAGE_SIZE ,AMDGPU_GEM_DOMAIN_GWS , + &adev->gds.gws_gfx_bo,NULL ,NULL );if (r)return r; - r =amdgpu_bo_create (adev, adev->gds.oa.gfx_partition_size, -PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_OA ,0 , -NULL ,NULL , &adev->gds.oa_gfx_bo); + r =amdgpu_bo_create_kernel (adev, adev->gds.oa.gfx_partition_size, +PAGE_SIZE ,AMDGPU_GEM_DOMAIN_OA , + &adev->gds.oa_gfx_bo,NULL ,NULL );if (r)return r;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +9 -12
@@ -2075,24 +2075,21 @@ static int gfx_v8_0_sw_init(void *handle) }/* reserve GDS, GWS and OA resource for gfx */ - r =amdgpu_bo_create (adev, adev->gds.mem.gfx_partition_size, -PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_GDS ,0 ,NULL , -NULL , &adev->gds.gds_gfx_bo); + r =amdgpu_bo_create_kernel (adev, adev->gds.mem.gfx_partition_size, +PAGE_SIZE ,AMDGPU_GEM_DOMAIN_GDS , + &adev->gds.gds_gfx_bo,NULL ,NULL );if (r)return r; - r =amdgpu_bo_create (adev, adev->gds.gws.gfx_partition_size, -PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_GWS ,0 ,NULL , -NULL , &adev->gds.gws_gfx_bo); + r =amdgpu_bo_create_kernel (adev, adev->gds.gws.gfx_partition_size, +PAGE_SIZE ,AMDGPU_GEM_DOMAIN_GWS , + &adev->gds.gws_gfx_bo,NULL ,NULL );if (r)return r; - r =amdgpu_bo_create (adev, adev->gds.oa.gfx_partition_size, -PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_OA ,0 ,NULL , -NULL , &adev->gds.oa_gfx_bo); + r =amdgpu_bo_create_kernel (adev, adev->gds.oa.gfx_partition_size, +PAGE_SIZE ,AMDGPU_GEM_DOMAIN_OA , + &adev->gds.oa_gfx_bo,NULL ,NULL );if (r)return r;
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/6 drm/amdgpu: add more warning to amdgpu_bo_offset
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Warn when we try to get the address and the BO isn't locked or reserved.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 16 +--------------- 2 files changed, 19 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +18 -0
@@ -737,3 +737,21 @@ void amdgpu_bo_fence(struct amdgpu_bo *bo, struct fence *fence,else reservation_object_add_excl_fence (resv, fence); } + +/** +* amdgpu_bo_gpu_offset - return GPU offset of bo +* @bo: amdgpu object for which we query the offset +* +* Returns current GPU offset of the object. +* +* Note: object should either be pinned or reserved when calling this +* function, it might be useful to add check for this for debugging. +*/ +u64 amdgpu_bo_gpu_offset (struct amdgpu_bo *bo) +{ +WARN_ON_ONCE (bo->tbo.mem.mem_type ==TTM_PL_SYSTEM ); +WARN_ON_ONCE (!ww_mutex_is_locked (&bo->tbo.resv->lock) && + !bo->pin_count); + +return bo->tbo.offset; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -15
@@ -85,21 +85,6 @@ static inline void amdgpu_bo_unreserve(struct amdgpu_bo *bo)ttm_bo_unreserve (&bo->tbo); } -/** -* amdgpu_bo_gpu_offset - return GPU offset of bo -* @bo: amdgpu object for which we query the offset -* -* Returns current GPU offset of the object. -* -* Note: object should either be pinned or reserved when calling this -* function, it might be useful to add check for this for debugging. -*/ -static inline u64 amdgpu_bo_gpu_offset (struct amdgpu_bo *bo) -{ -WARN_ON_ONCE (bo->tbo.mem.mem_type ==TTM_PL_SYSTEM ); -return bo->tbo.offset; -} -static inline unsigned long amdgpu_bo_size (struct amdgpu_bo *bo) {return bo->tbo.num_pages <<PAGE_SHIFT ;
@@ -169,6 +154,7 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,int amdgpu_bo_fault_reserve_notify (struct ttm_buffer_object *bo);void amdgpu_bo_fence (struct amdgpu_bo *bo,struct fence *fence,bool shared); +u64 amdgpu_bo_gpu_offset (struct amdgpu_bo *bo);/* * sub allocation
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/6 drm/amdgpu: user amdgpu_bo_create_kernel for the UVD BO
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Saves us some code.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +3 -28
@@ -194,39 +194,14 @@ int amdgpu_uvd_sw_init(struct amdgpu_device *adev) bo_size =AMDGPU_GPU_PAGE_ALIGN (le32_to_cpu (hdr->ucode_size_bytes) +8 ) +AMDGPU_UVD_STACK_SIZE +AMDGPU_UVD_HEAP_SIZE +AMDGPU_UVD_SESSION_SIZE * adev->uvd.max_handles; - r =amdgpu_bo_create (adev, bo_size,PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_VRAM , -AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED , -NULL ,NULL , &adev->uvd.vcpu_bo); + r =amdgpu_bo_create_kernel (adev, bo_size,PAGE_SIZE , +AMDGPU_GEM_DOMAIN_VRAM , &adev->uvd.vcpu_bo, + &adev->uvd.gpu_addr, &adev->uvd.cpu_addr);if (r) {dev_err (adev->dev,"(%d) failed to allocate UVD bo\n" , r);return r; } - r =amdgpu_bo_reserve (adev->uvd.vcpu_bo, false); -if (r) { -amdgpu_bo_unref (&adev->uvd.vcpu_bo); -dev_err (adev->dev,"(%d) failed to reserve UVD bo\n" , r); -return r; - } - - r =amdgpu_bo_pin (adev->uvd.vcpu_bo,AMDGPU_GEM_DOMAIN_VRAM , - &adev->uvd.gpu_addr); -if (r) { -amdgpu_bo_unreserve (adev->uvd.vcpu_bo); -amdgpu_bo_unref (&adev->uvd.vcpu_bo); -dev_err (adev->dev,"(%d) UVD bo pin failed\n" , r); -return r; - } - - r =amdgpu_bo_kmap (adev->uvd.vcpu_bo, &adev->uvd.cpu_addr); -if (r) { -dev_err (adev->dev,"(%d) UVD map failed\n" , r); -return r; - } - -amdgpu_bo_unreserve (adev->uvd.vcpu_bo); - ring = &adev->uvd.ring; rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL ]; r = amd_sched_entity_init(&ring->sched, &adev->uvd.entity,
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/6 drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ih.c
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Saves us quite a bunch of code.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c +5 -22
@@ -40,32 +40,15 @@ static int amdgpu_ih_ring_alloc(struct amdgpu_device *adev)/* Allocate ring buffer */ if (adev->irq.ih.ring_obj ==NULL ) { - r =amdgpu_bo_create (adev, adev->irq.ih.ring_size, -PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_GTT ,0 , -NULL ,NULL , &adev->irq.ih.ring_obj); + r =amdgpu_bo_create_kernel (adev, adev->irq.ih.ring_size, +PAGE_SIZE ,AMDGPU_GEM_DOMAIN_GTT , + &adev->irq.ih.ring_obj, + &adev->irq.ih.gpu_addr, + (void **)&adev->irq.ih.ring);if (r) {DRM_ERROR ("amdgpu: failed to create ih ring buffer (%d).\n" , r);return r; } - r =amdgpu_bo_reserve (adev->irq.ih.ring_obj, false); -if (unlikely (r !=0 )) -return r; - r =amdgpu_bo_pin (adev->irq.ih.ring_obj, -AMDGPU_GEM_DOMAIN_GTT , - &adev->irq.ih.gpu_addr); -if (r) { -amdgpu_bo_unreserve (adev->irq.ih.ring_obj); -DRM_ERROR ("amdgpu: failed to pin ih ring buffer (%d).\n" , r); -return r; - } - r =amdgpu_bo_kmap (adev->irq.ih.ring_obj, - (void **)&adev->irq.ih.ring); -amdgpu_bo_unreserve (adev->irq.ih.ring_obj); -if (r) { -DRM_ERROR ("amdgpu: failed to map ih ring buffer (%d).\n" , r); -return r; - } }return 0 ; }
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/6 drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ring.c
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Saves us quite a bunch of code.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5 -22
@@ -222,33 +222,16 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,/* Allocate ring buffer */ if (ring->ring_obj ==NULL ) { - r =amdgpu_bo_create (adev, ring->ring_size,PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_GTT ,0 , -NULL ,NULL , &ring->ring_obj); + r =amdgpu_bo_create_kernel (adev, ring->ring_size,PAGE_SIZE , +AMDGPU_GEM_DOMAIN_GTT , + &ring->ring_obj, + &ring->gpu_addr, + (void **)&ring->ring);if (r) {dev_err (adev->dev,"(%d) ring create failed\n" , r);return r; } - r =amdgpu_bo_reserve (ring->ring_obj, false); -if (unlikely (r !=0 )) -return r; - r =amdgpu_bo_pin (ring->ring_obj,AMDGPU_GEM_DOMAIN_GTT , - &ring->gpu_addr); -if (r) { -amdgpu_bo_unreserve (ring->ring_obj); -dev_err (adev->dev,"(%d) ring pin failed\n" , r); -return r; - } - r =amdgpu_bo_kmap (ring->ring_obj, - (void **)&ring->ring); -memset ((void *)ring->ring,0 , ring->ring_size); - -amdgpu_bo_unreserve (ring->ring_obj); -if (r) { -dev_err (adev->dev,"(%d) ring map failed\n" , r); -return r; - } } ring->ptr_mask = (ring->ring_size /4 ) -1 ; ring->max_dw = max_dw;
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1469520017-8422-6-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Deucher, Alexander
Reviewed-by Alex DeucherRE: [PATCH 6/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ring.c
Quoted 8 lines
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Christian König
Sent: Tuesday, July 26, 2016 4:00 AM
To: [email protected]
Subject: [PATCH 6/6] drm/amdgpu: useamdgpu_bo_create_kernelinamdgpu_ring.c
Quoted 5 lines
From: Christian König <[email protected]>
Saves us quite a bunch of code.
Signed-off-by Christian König <[email protected]>
For the series:
Quoted 56 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 27 +++++---------------------(quoted diff) +0
-1- 1 file changed, 5 insertions(+), 22 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5
-23@@ -222,33 +222,16 @@ int amdgpu_ring_init(struct amdgpu_device *adev,struct amdgpu_ring *ring,/* Allocate ring buffer */ if (ring->ring_obj == NULL) { - r =amdgpu_bo_create (adev, ring->ring_size,PAGE_SIZE , true, -AMDGPU_GEM_DOMAIN_GTT ,0 , -NULL ,NULL , &ring->ring_obj); + r =amdgpu_bo_create_kernel (adev, ring->ring_size,PAGE_SIZE , +AMDGPU_GEM_DOMAIN_GTT , + &ring->ring_obj, + &ring->gpu_addr, + (void **)&ring->ring);if (r) {dev_err (adev->dev,"(%d) ring create failed\n" , r);return r; } - r =amdgpu_bo_reserve (ring->ring_obj, false); -if (unlikely (r !=0 )) -return r; - r =amdgpu_bo_pin (ring->ring_obj,AMDGPU_GEM_DOMAIN_GTT , - &ring->gpu_addr); -if (r) { -amdgpu_bo_unreserve (ring->ring_obj); -dev_err (adev->dev,"(%d) ring pin failed\n" , r); -return r; - } - r =amdgpu_bo_kmap (ring->ring_obj, - (void **)&ring->ring); -memset ((void *)ring->ring,0 , ring->ring_size); - -amdgpu_bo_unreserve (ring->ring_obj); -if (r) { -dev_err (adev->dev,"(%d) ring map failed\n" , r); -return r; - } } ring->ptr_mask = (ring->ring_size /4 ) -1 ; ring->max_dw = max_dw; --2.5.0
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
the set looks good to me, Reviewed-by: Chunming Zhou <[email protected]>
Quoted 89 lines · Christian König
From: Christian König <[email protected]>
We often allocate, pin and map things at the same time in the kernel.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 63 ++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 4 ++ 2 files changed, 67 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +63
-0@@ -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,drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h int amdgpu_bo_create_restricted(struct amdgpu_device *adev, · line 148
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +4
-0@@ -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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Edward O'Callaghan
Reviewed-byThis series is,
Quoted 90 lines · Christian König
From: Christian König <[email protected]>
We often allocate, pin and map things at the same time in the kernel.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 63 ++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 4 ++ 2 files changed, 67 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +63
-0@@ -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,drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h int amdgpu_bo_create_restricted(struct amdgpu_device *adev, · line 148
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +4
-0@@ -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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx