From 5edbf17e90973a2ac987c345e4a2d4021ee31cd7 Mon Sep 17 00:00:00 2001 From: Donald Robson Date: Wed, 3 May 2023 14:50:36 +0100 Subject: [PATCH] pvr: Move heap initialisation out of pvr_winsys_helper. This code will not be used by the new KMD, so it is being moved out of this shared code area. Signed-off-by: Donald Robson Reviewed-by: Frank Binns Part-of: --- .../vulkan/winsys/pvr_winsys_helper.c | 61 --------------- .../vulkan/winsys/pvr_winsys_helper.h | 9 --- .../vulkan/winsys/pvrsrvkm/pvr_srv.c | 77 +++++++++++++++++-- 3 files changed, 69 insertions(+), 78 deletions(-) diff --git a/src/imagination/vulkan/winsys/pvr_winsys_helper.c b/src/imagination/vulkan/winsys/pvr_winsys_helper.c index 5f6e234fc3f..5592ebba940 100644 --- a/src/imagination/vulkan/winsys/pvr_winsys_helper.c +++ b/src/imagination/vulkan/winsys/pvr_winsys_helper.c @@ -63,67 +63,6 @@ int pvr_winsys_helper_display_buffer_destroy(int master_fd, uint32_t handle) return drmIoctl(master_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &args); } -/* reserved_size can be 0 when no reserved area is needed. reserved_address must - * be 0 if reserved_size is 0. - */ -VkResult pvr_winsys_helper_winsys_heap_init( - struct pvr_winsys *const ws, - pvr_dev_addr_t base_address, - uint64_t size, - pvr_dev_addr_t reserved_address, - uint64_t reserved_size, - uint32_t log2_page_size, - const struct pvr_winsys_static_data_offsets *const static_data_offsets, - struct pvr_winsys_heap *const heap) -{ - const bool reserved_area_bottom_of_heap = reserved_address.addr == - base_address.addr; - const pvr_dev_addr_t vma_heap_begin_addr = - reserved_area_bottom_of_heap - ? PVR_DEV_ADDR_OFFSET(base_address, reserved_size) - : base_address; - const uint64_t vma_heap_size = size - reserved_size; - - assert(base_address.addr); - assert(reserved_size <= size); - - /* As per the reserved_base powervr-km uapi documentation the reserved - * region can only be at the beginning of the heap or at the end. - * reserved_address is 0 if there is no reserved region. - * pvrsrv-km doesn't explicitly provide this info and it's assumed that it's - * always at the beginning. - */ - assert(reserved_area_bottom_of_heap || - reserved_address.addr + reserved_size == base_address.addr + size || - (!reserved_address.addr && !reserved_size)); - - heap->ws = ws; - heap->base_addr = base_address; - heap->reserved_addr = reserved_address; - - heap->size = size; - heap->reserved_size = reserved_size; - - heap->page_size = 1 << log2_page_size; - heap->log2_page_size = log2_page_size; - - util_vma_heap_init(&heap->vma_heap, vma_heap_begin_addr.addr, vma_heap_size); - - heap->vma_heap.alloc_high = false; - - /* It's expected that the heap destroy function to be the last thing that's - * called, so we start the ref_count at 0. - */ - p_atomic_set(&heap->ref_count, 0); - - if (pthread_mutex_init(&heap->lock, NULL)) - return vk_error(NULL, VK_ERROR_INITIALIZATION_FAILED); - - heap->static_data_offsets = *static_data_offsets; - - return VK_SUCCESS; -} - bool pvr_winsys_helper_winsys_heap_finish(struct pvr_winsys_heap *const heap) { if (p_atomic_read(&heap->ref_count) != 0) diff --git a/src/imagination/vulkan/winsys/pvr_winsys_helper.h b/src/imagination/vulkan/winsys/pvr_winsys_helper.h index b27f803e1b6..aaa713699fd 100644 --- a/src/imagination/vulkan/winsys/pvr_winsys_helper.h +++ b/src/imagination/vulkan/winsys/pvr_winsys_helper.h @@ -45,15 +45,6 @@ int pvr_winsys_helper_display_buffer_create(int master_fd, uint32_t *const handle_out); int pvr_winsys_helper_display_buffer_destroy(int master_fd, uint32_t handle); -VkResult pvr_winsys_helper_winsys_heap_init( - struct pvr_winsys *const ws, - pvr_dev_addr_t base_address, - uint64_t size, - pvr_dev_addr_t reserved_address, - uint64_t reserved_size, - uint32_t log2_page_size, - const struct pvr_winsys_static_data_offsets *const static_data_offsets, - struct pvr_winsys_heap *const heap); bool pvr_winsys_helper_winsys_heap_finish(struct pvr_winsys_heap *const heap); bool pvr_winsys_helper_heap_alloc(struct pvr_winsys_heap *const heap, diff --git a/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.c b/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.c index 5f05464f087..6d752513164 100644 --- a/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.c +++ b/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.c @@ -53,6 +53,67 @@ /* Amount of space used to hold sync prim values (in bytes). */ #define PVR_SRV_SYNC_PRIM_VALUE_SIZE 4U +/* reserved_size can be 0 when no reserved region is needed. reserved_address + * must be 0 if reserved_size is 0. + */ +static VkResult pvr_winsys_heap_init( + struct pvr_winsys *const ws, + pvr_dev_addr_t base_address, + uint64_t size, + pvr_dev_addr_t reserved_address, + uint64_t reserved_size, + uint32_t log2_page_size, + const struct pvr_winsys_static_data_offsets *const static_data_offsets, + struct pvr_winsys_heap *const heap) +{ + const bool reserved_area_bottom_of_heap = reserved_address.addr == + base_address.addr; + const pvr_dev_addr_t vma_heap_begin_addr = + reserved_area_bottom_of_heap + ? PVR_DEV_ADDR_OFFSET(base_address, reserved_size) + : base_address; + const uint64_t vma_heap_size = size - reserved_size; + + assert(base_address.addr); + assert(reserved_size <= size); + + /* As per the reserved_base powervr-km uapi documentation the reserved + * region can only be at the beginning of the heap or at the end. + * reserved_address is 0 if there is no reserved region. + * pvrsrv-km doesn't explicitly provide this info and it's assumed that it's + * always at the beginning. + */ + assert(reserved_area_bottom_of_heap || + reserved_address.addr + reserved_size == base_address.addr + size || + (!reserved_address.addr && !reserved_size)); + + heap->ws = ws; + heap->base_addr = base_address; + heap->reserved_addr = reserved_address; + + heap->size = size; + heap->reserved_size = reserved_size; + + heap->page_size = 1 << log2_page_size; + heap->log2_page_size = log2_page_size; + + util_vma_heap_init(&heap->vma_heap, vma_heap_begin_addr.addr, vma_heap_size); + + heap->vma_heap.alloc_high = false; + + /* It's expected that the heap destroy function to be the last thing that's + * called, so we start the ref_count at 0. + */ + p_atomic_set(&heap->ref_count, 0); + + if (pthread_mutex_init(&heap->lock, NULL)) + return vk_error(NULL, VK_ERROR_INITIALIZATION_FAILED); + + heap->static_data_offsets = *static_data_offsets; + + return VK_SUCCESS; +} + /** * Maximum PB free list size supported by RGX and Services. * @@ -95,14 +156,14 @@ static VkResult pvr_srv_heap_init( if (result != VK_SUCCESS) return result; - result = pvr_winsys_helper_winsys_heap_init(&srv_ws->base, - base_address, - size, - base_address, - reserved_size, - log2_page_size, - static_data_offsets, - &srv_heap->base); + result = pvr_winsys_heap_init(&srv_ws->base, + base_address, + size, + base_address, + reserved_size, + log2_page_size, + static_data_offsets, + &srv_heap->base); if (result != VK_SUCCESS) return result;