mirror of
https://gitlab.freedesktop.org/mesa/vulkan-wsi-layer.git
synced 2025-12-19 23:50:07 +01:00
Remove ion wsialloc implementation
Signed-off-by: Alex Bates <alex.bates@arm.com> Change-Id: Iecfb86ecefc0cfba2796b9dca6b105392a3b3f73
This commit is contained in:
parent
6b3cc197ab
commit
575cf49d95
3 changed files with 6 additions and 208 deletions
|
|
@ -72,7 +72,7 @@ option(BUILD_WSI_HEADLESS "Build with support for VK_EXT_headless_surface" ON)
|
|||
option(BUILD_WSI_WAYLAND "Build with support for VK_KHR_wayland_surface" OFF)
|
||||
option(BUILD_WSI_DISPLAY "Build with support for VK_KHR_display" OFF)
|
||||
|
||||
set(SELECT_EXTERNAL_ALLOCATOR "none" CACHE STRING "Select an external system allocator (none, ion, dma_buf_heaps)")
|
||||
set(SELECT_EXTERNAL_ALLOCATOR "none" CACHE STRING "Select an external system allocator (none, dma_buf_heaps)")
|
||||
set(EXTERNAL_WSIALLOC_LIBRARY "" CACHE STRING "External implementation of the wsialloc interface to use")
|
||||
set(WSIALLOC_MEMORY_HEAP_NAME "linux,cma" CACHE STRING "Heap name used by the dma_buf_heaps allocator")
|
||||
|
||||
|
|
@ -113,15 +113,7 @@ if(NOT SELECT_EXTERNAL_ALLOCATOR STREQUAL "none" AND EXTERNAL_WSIALLOC_LIBRARY S
|
|||
add_library(wsialloc STATIC)
|
||||
set_target_properties(wsialloc PROPERTIES C_STANDARD 99)
|
||||
|
||||
if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "ion")
|
||||
target_sources(wsialloc PRIVATE util/wsialloc/wsialloc_ion.c util/wsialloc/wsialloc_helpers.c)
|
||||
target_link_libraries(wsialloc drm_utils)
|
||||
if(DEFINED KERNEL_HEADER_DIR)
|
||||
target_include_directories(wsialloc PRIVATE "${KERNEL_HEADER_DIR}")
|
||||
else()
|
||||
message(FATAL_ERROR "KERNEL_HEADER_DIR must be defined as the directory that includes the kernel headers.")
|
||||
endif()
|
||||
elseif(SELECT_EXTERNAL_ALLOCATOR STREQUAL "dma_buf_heaps")
|
||||
if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "dma_buf_heaps")
|
||||
target_sources(wsialloc PRIVATE util/wsialloc/wsialloc_dma_buf_heaps.c util/wsialloc/wsialloc_helpers.c)
|
||||
target_link_libraries(wsialloc drm_utils)
|
||||
if(DEFINED KERNEL_HEADER_DIR)
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ make -C build
|
|||
|
||||
In order to build with Wayland support the `BUILD_WSI_WAYLAND` build option
|
||||
must be used, the `SELECT_EXTERNAL_ALLOCATOR` option has to be set to
|
||||
a graphics memory allocator (currently only ion and dma_buf_heaps are supported) and
|
||||
a graphics memory allocator (currently only dma_buf_heaps is supported) and
|
||||
the `KERNEL_HEADER_DIR` option must be defined as the directory that includes the kernel headers.
|
||||
source.
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ source.
|
|||
cmake . -DVULKAN_CXX_INCLUDE="path/to/vulkan-header" \
|
||||
-DBUILD_WSI_HEADLESS=0 \
|
||||
-DBUILD_WSI_WAYLAND=1 \
|
||||
-DSELECT_EXTERNAL_ALLOCATOR=ion \
|
||||
-DSELECT_EXTERNAL_ALLOCATOR=dma_buf_heaps \
|
||||
-DKERNEL_HEADER_DIR="path/to/linux-kernel-headers"
|
||||
```
|
||||
|
||||
|
|
@ -138,9 +138,9 @@ also responsible for selecting a suitable format that can be
|
|||
efficiently shared between the different devices in the system, e.g. GPU,
|
||||
display. It is therefore an important point of integration. It is expected
|
||||
that each system will need a tailored implementation, although the layer
|
||||
provides a generic ion and dma_buf_heaps implementations that may work in
|
||||
provides a generic dma_buf_heaps implementation that may work in
|
||||
systems that support linear formats. This is selected by
|
||||
the `-DSELECT_EXTERNAL_ALLOCATOR=ion` option, as shown above.
|
||||
the `-DSELECT_EXTERNAL_ALLOCATOR=dma_buf_heaps` option, as shown above.
|
||||
|
||||
### Wayland support with FIFO presentation mode
|
||||
|
||||
|
|
|
|||
|
|
@ -1,194 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017-2024 Arm Limited.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "wsialloc.h"
|
||||
#include "wsialloc_helpers.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <ion.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* @brief Version of the wsialloc interface we are implementing in this file.
|
||||
*
|
||||
* This should only be increased when this implementation is updated to match newer versions of wsialloc.h.
|
||||
*/
|
||||
#define WSIALLOC_IMPLEMENTATION_VERSION 3
|
||||
|
||||
/* Ensure we are implementing the wsialloc version matching the wsialloc.h header we are using. */
|
||||
#if WSIALLOC_IMPLEMENTATION_VERSION != WSIALLOC_INTERFACE_VERSION
|
||||
#error "Version mismatch between wsialloc implementation and interface version"
|
||||
#endif
|
||||
|
||||
const uint32_t WSIALLOC_IMPLEMENTATION_VERSION_SYMBOL = WSIALLOC_IMPLEMENTATION_VERSION;
|
||||
|
||||
struct wsialloc_allocator
|
||||
{
|
||||
/* File descriptor of /dev/ion. */
|
||||
int fd;
|
||||
/* Allocator heap id. */
|
||||
uint32_t alloc_heap_id;
|
||||
/* Protected allocator heap id */
|
||||
uint32_t protected_alloc_heap_id;
|
||||
bool protected_heap_exists;
|
||||
};
|
||||
|
||||
static int find_alloc_heap_id(int fd)
|
||||
{
|
||||
assert(fd != -1);
|
||||
|
||||
struct ion_heap_data heaps[ION_NUM_HEAP_IDS];
|
||||
struct ion_heap_query query = {
|
||||
.cnt = ION_NUM_HEAP_IDS,
|
||||
.heaps = (uint64_t)(uintptr_t)heaps,
|
||||
};
|
||||
|
||||
int ret = ioctl(fd, ION_IOC_HEAP_QUERY, &query);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
int alloc_heap_id = -1;
|
||||
for (uint32_t i = 0; i < query.cnt; ++i)
|
||||
{
|
||||
if (ION_HEAP_TYPE_DMA == heaps[i].type)
|
||||
{
|
||||
alloc_heap_id = heaps[i].heap_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return alloc_heap_id;
|
||||
}
|
||||
|
||||
static int allocate(int fd, size_t size, uint32_t heap_id)
|
||||
{
|
||||
assert(size > 0);
|
||||
assert(fd != -1);
|
||||
|
||||
struct ion_allocation_data alloc = {
|
||||
.len = size,
|
||||
.heap_id_mask = 1u << heap_id,
|
||||
.flags = 0,
|
||||
};
|
||||
int ret = ioctl(fd, ION_IOC_ALLOC, &alloc);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
return alloc.fd;
|
||||
}
|
||||
|
||||
wsialloc_error wsialloc_new(wsialloc_allocator **allocator)
|
||||
{
|
||||
assert(allocator != NULL);
|
||||
wsialloc_allocator *ion = malloc(sizeof(wsialloc_allocator));
|
||||
if (NULL == ion)
|
||||
{
|
||||
wsialloc_delete(ion);
|
||||
return WSIALLOC_ERROR_NO_RESOURCE;
|
||||
}
|
||||
|
||||
ion->fd = open("/dev/ion", O_RDONLY);
|
||||
if (ion->fd < 0)
|
||||
{
|
||||
wsialloc_delete(ion);
|
||||
return WSIALLOC_ERROR_NO_RESOURCE;
|
||||
}
|
||||
|
||||
ion->alloc_heap_id = find_alloc_heap_id(ion->fd);
|
||||
if (ion->alloc_heap_id < 0)
|
||||
{
|
||||
wsialloc_delete(ion);
|
||||
return WSIALLOC_ERROR_NO_RESOURCE;
|
||||
}
|
||||
|
||||
ion->protected_heap_exists = false;
|
||||
*allocator = ion;
|
||||
return WSIALLOC_ERROR_NONE;
|
||||
}
|
||||
|
||||
void wsialloc_delete(wsialloc_allocator *allocator)
|
||||
{
|
||||
assert(allocator != NULL);
|
||||
if (NULL == allocator)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (allocator->fd >= 0)
|
||||
{
|
||||
close(allocator->fd);
|
||||
allocator->fd = -1;
|
||||
}
|
||||
|
||||
free(allocator);
|
||||
}
|
||||
|
||||
static int ion_allocate(const wsialloc_allocator *allocator, const wsialloc_allocate_info *info, uint64_t size)
|
||||
{
|
||||
assert(allocator != NULL);
|
||||
assert(info != NULL);
|
||||
assert(allocator->fd != -1);
|
||||
assert(size > 0);
|
||||
|
||||
/* The only error that can be encountered on allocations is lack of resources. Other parameter validation and
|
||||
* support checks are done on format selection. */
|
||||
uint32_t alloc_heap_id = allocator->alloc_heap_id;
|
||||
if (info->flags & WSIALLOC_ALLOCATE_PROTECTED)
|
||||
{
|
||||
/* Exit if we don't support allocating protected memory. */
|
||||
if (!allocator->protected_heap_exists)
|
||||
{
|
||||
assert(false);
|
||||
return -1;
|
||||
}
|
||||
alloc_heap_id = allocator->protected_alloc_heap_id;
|
||||
}
|
||||
|
||||
return allocate(allocator->fd, size, alloc_heap_id);
|
||||
}
|
||||
|
||||
wsialloc_error wsialloc_alloc(wsialloc_allocator *allocator, const wsialloc_allocate_info *info,
|
||||
wsialloc_allocate_result *result)
|
||||
{
|
||||
if ((info->flags & WSIALLOC_ALLOCATE_PROTECTED) && (!allocator->protected_heap_exists))
|
||||
{
|
||||
return WSIALLOC_ERROR_NO_RESOURCE;
|
||||
}
|
||||
|
||||
return wsiallocp_alloc(allocator, ion_allocate, info, result);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue