minigbm: add clang-format and presubmit hooks
Running the presubmit.sh script will apply our rules to every file in the repo. Exclude gbm.h from the formatting requirements since this file was taken from other open-source projects, and diffing will be easier without our formatting rules. In addition, special case drivers where the order of includes matters. BUG=none TEST=Verified the following commands succeed: emerge-cyan minigbm/arc-cros-gralloc emerge-oak minigbm/arc-cros-gralloc emerge-veyron_minnie-cheets minigbm/arc-cros-gralloc emerge-peach_pi minigbm emerge-nyan_big minigbm emerge-jadeite minigbm Change-Id: I6ce93fb1930da254d13d5017766c17341870ccc9 Reviewed-on: https://chromium-review.googlesource.com/447319 Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
This commit is contained in:
parent
4c3aa42a52
commit
1b1d56ae40
32 changed files with 511 additions and 740 deletions
15
.clang-format
Normal file
15
.clang-format
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
# Copyright 2017 The Chromium OS Authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
|
# found in the LICENSE file.
|
||||||
|
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
AllowShortFunctionsOnASingleLine: None
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
ColumnLimit: 100
|
||||||
|
IndentWidth: 8
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Always
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
IndentCaseLabels: false
|
||||||
5
PRESUBMIT.cfg
Normal file
5
PRESUBMIT.cfg
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Copyright 2017 The Chromium OS Authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
|
# found in the LICENSE file.
|
||||||
|
[Hooks Scripts]
|
||||||
|
hook0 = ./presubmit.sh
|
||||||
159
amdgpu.c
159
amdgpu.c
|
|
@ -4,14 +4,14 @@
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
#ifdef DRV_AMDGPU
|
#ifdef DRV_AMDGPU
|
||||||
|
#include <amdgpu.h>
|
||||||
|
#include <amdgpu_drm.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
#include <amdgpu_drm.h>
|
|
||||||
#include <amdgpu.h>
|
|
||||||
|
|
||||||
#include "addrinterface.h"
|
#include "addrinterface.h"
|
||||||
#include "drv_priv.h"
|
#include "drv_priv.h"
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#define CIASICIDGFXENGINE_SOUTHERNISLAND 0x0000000A
|
#define CIASICIDGFXENGINE_SOUTHERNISLAND 0x0000000A
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
#define mmCC_RB_BACKEND_DISABLE 0x263d
|
#define mmCC_RB_BACKEND_DISABLE 0x263d
|
||||||
#define mmGB_TILE_MODE0 0x2644
|
#define mmGB_TILE_MODE0 0x2644
|
||||||
#define mmGB_MACROTILE_MODE0 0x2664
|
#define mmGB_MACROTILE_MODE0 0x2664
|
||||||
|
|
@ -38,15 +39,14 @@ enum {
|
||||||
FAMILY_PI,
|
FAMILY_PI,
|
||||||
FAMILY_LAST,
|
FAMILY_LAST,
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
const static uint32_t supported_formats[] = {
|
const static uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR8888,
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888
|
DRM_FORMAT_XRGB8888 };
|
||||||
};
|
|
||||||
|
|
||||||
static int amdgpu_set_metadata(int fd, uint32_t handle,
|
static int amdgpu_set_metadata(int fd, uint32_t handle, struct amdgpu_bo_metadata *info)
|
||||||
struct amdgpu_bo_metadata *info)
|
|
||||||
{
|
{
|
||||||
struct drm_amdgpu_gem_metadata args = {0};
|
struct drm_amdgpu_gem_metadata args = { 0 };
|
||||||
|
|
||||||
if (!info)
|
if (!info)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
@ -64,18 +64,16 @@ static int amdgpu_set_metadata(int fd, uint32_t handle,
|
||||||
memcpy(args.data.data, info->umd_metadata, info->size_metadata);
|
memcpy(args.data.data, info->umd_metadata, info->size_metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
return drmCommandWriteRead(fd, DRM_AMDGPU_GEM_METADATA, &args,
|
return drmCommandWriteRead(fd, DRM_AMDGPU_GEM_METADATA, &args, sizeof(args));
|
||||||
sizeof(args));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int amdgpu_read_mm_regs(int fd, unsigned dword_offset,
|
static int amdgpu_read_mm_regs(int fd, unsigned dword_offset, unsigned count, uint32_t instance,
|
||||||
unsigned count, uint32_t instance,
|
|
||||||
uint32_t flags, uint32_t *values)
|
uint32_t flags, uint32_t *values)
|
||||||
{
|
{
|
||||||
struct drm_amdgpu_info request;
|
struct drm_amdgpu_info request;
|
||||||
|
|
||||||
memset(&request, 0, sizeof(request));
|
memset(&request, 0, sizeof(request));
|
||||||
request.return_pointer = (uintptr_t) values;
|
request.return_pointer = (uintptr_t)values;
|
||||||
request.return_size = count * sizeof(uint32_t);
|
request.return_size = count * sizeof(uint32_t);
|
||||||
request.query = AMDGPU_INFO_READ_MMR_REG;
|
request.query = AMDGPU_INFO_READ_MMR_REG;
|
||||||
request.read_mmr_reg.dword_offset = dword_offset;
|
request.read_mmr_reg.dword_offset = dword_offset;
|
||||||
|
|
@ -83,8 +81,7 @@ static int amdgpu_read_mm_regs(int fd, unsigned dword_offset,
|
||||||
request.read_mmr_reg.instance = instance;
|
request.read_mmr_reg.instance = instance;
|
||||||
request.read_mmr_reg.flags = flags;
|
request.read_mmr_reg.flags = flags;
|
||||||
|
|
||||||
return drmCommandWrite(fd, DRM_AMDGPU_INFO, &request,
|
return drmCommandWrite(fd, DRM_AMDGPU_INFO, &request, sizeof(struct drm_amdgpu_info));
|
||||||
sizeof(struct drm_amdgpu_info));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int amdgpu_query_gpu(int fd, struct amdgpu_gpu_info *gpu_info)
|
static int amdgpu_query_gpu(int fd, struct amdgpu_gpu_info *gpu_info)
|
||||||
|
|
@ -95,19 +92,16 @@ static int amdgpu_query_gpu(int fd, struct amdgpu_gpu_info *gpu_info)
|
||||||
if (!gpu_info)
|
if (!gpu_info)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
instance = AMDGPU_INFO_MMR_SH_INDEX_MASK <<
|
instance = AMDGPU_INFO_MMR_SH_INDEX_MASK << AMDGPU_INFO_MMR_SH_INDEX_SHIFT;
|
||||||
AMDGPU_INFO_MMR_SH_INDEX_SHIFT;
|
|
||||||
|
|
||||||
ret = amdgpu_read_mm_regs(fd, mmCC_RB_BACKEND_DISABLE, 1, instance, 0,
|
ret = amdgpu_read_mm_regs(fd, mmCC_RB_BACKEND_DISABLE, 1, instance, 0,
|
||||||
&gpu_info->backend_disable[0]);
|
&gpu_info->backend_disable[0]);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
/* extract bitfield CC_RB_BACKEND_DISABLE.BACKEND_DISABLE */
|
/* extract bitfield CC_RB_BACKEND_DISABLE.BACKEND_DISABLE */
|
||||||
gpu_info->backend_disable[0] =
|
gpu_info->backend_disable[0] = (gpu_info->backend_disable[0] >> 16) & 0xff;
|
||||||
(gpu_info->backend_disable[0] >> 16) & 0xff;
|
|
||||||
|
|
||||||
ret = amdgpu_read_mm_regs(fd, mmGB_TILE_MODE0, 32, 0xffffffff, 0,
|
ret = amdgpu_read_mm_regs(fd, mmGB_TILE_MODE0, 32, 0xffffffff, 0, gpu_info->gb_tile_mode);
|
||||||
gpu_info->gb_tile_mode);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
@ -116,13 +110,11 @@ static int amdgpu_query_gpu(int fd, struct amdgpu_gpu_info *gpu_info)
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = amdgpu_read_mm_regs(fd, mmGB_ADDR_CONFIG, 1, 0xffffffff, 0,
|
ret = amdgpu_read_mm_regs(fd, mmGB_ADDR_CONFIG, 1, 0xffffffff, 0, &gpu_info->gb_addr_cfg);
|
||||||
&gpu_info->gb_addr_cfg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = amdgpu_read_mm_regs(fd, mmMC_ARB_RAMCFG, 1, 0xffffffff, 0,
|
ret = amdgpu_read_mm_regs(fd, mmMC_ARB_RAMCFG, 1, 0xffffffff, 0, &gpu_info->mc_arb_ramcfg);
|
||||||
&gpu_info->mc_arb_ramcfg);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
@ -140,22 +132,20 @@ static ADDR_E_RETURNCODE ADDR_API free_sys_mem(const ADDR_FREESYSMEM_INPUT *in)
|
||||||
return ADDR_OK;
|
return ADDR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int amdgpu_addrlib_compute(void *addrlib, uint32_t width,
|
static int amdgpu_addrlib_compute(void *addrlib, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t height, uint32_t format,
|
|
||||||
uint32_t usage, uint32_t *tiling_flags,
|
uint32_t usage, uint32_t *tiling_flags,
|
||||||
ADDR_COMPUTE_SURFACE_INFO_OUTPUT *addr_out)
|
ADDR_COMPUTE_SURFACE_INFO_OUTPUT *addr_out)
|
||||||
{
|
{
|
||||||
ADDR_COMPUTE_SURFACE_INFO_INPUT addr_surf_info_in = {0};
|
ADDR_COMPUTE_SURFACE_INFO_INPUT addr_surf_info_in = { 0 };
|
||||||
ADDR_TILEINFO addr_tile_info = {0};
|
ADDR_TILEINFO addr_tile_info = { 0 };
|
||||||
ADDR_TILEINFO addr_tile_info_out = {0};
|
ADDR_TILEINFO addr_tile_info_out = { 0 };
|
||||||
uint32_t bits_per_pixel;
|
uint32_t bits_per_pixel;
|
||||||
|
|
||||||
addr_surf_info_in.size = sizeof(ADDR_COMPUTE_SURFACE_INFO_INPUT);
|
addr_surf_info_in.size = sizeof(ADDR_COMPUTE_SURFACE_INFO_INPUT);
|
||||||
|
|
||||||
/* Set the requested tiling mode. */
|
/* Set the requested tiling mode. */
|
||||||
addr_surf_info_in.tileMode = ADDR_TM_2D_TILED_THIN1;
|
addr_surf_info_in.tileMode = ADDR_TM_2D_TILED_THIN1;
|
||||||
if (usage & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN |
|
if (usage & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
|
||||||
BO_USE_SW_WRITE_OFTEN))
|
|
||||||
addr_surf_info_in.tileMode = ADDR_TM_LINEAR_ALIGNED;
|
addr_surf_info_in.tileMode = ADDR_TM_LINEAR_ALIGNED;
|
||||||
else if (width <= 16 || height <= 16)
|
else if (width <= 16 || height <= 16)
|
||||||
addr_surf_info_in.tileMode = ADDR_TM_1D_TILED_THIN1;
|
addr_surf_info_in.tileMode = ADDR_TM_1D_TILED_THIN1;
|
||||||
|
|
@ -182,13 +172,12 @@ static int amdgpu_addrlib_compute(void *addrlib, uint32_t width,
|
||||||
addr_out->size = sizeof(ADDR_COMPUTE_SURFACE_INFO_OUTPUT);
|
addr_out->size = sizeof(ADDR_COMPUTE_SURFACE_INFO_OUTPUT);
|
||||||
addr_out->pTileInfo = &addr_tile_info_out;
|
addr_out->pTileInfo = &addr_tile_info_out;
|
||||||
|
|
||||||
if (AddrComputeSurfaceInfo(addrlib, &addr_surf_info_in,
|
if (AddrComputeSurfaceInfo(addrlib, &addr_surf_info_in, addr_out) != ADDR_OK)
|
||||||
addr_out) != ADDR_OK)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ADDR_CONVERT_TILEINFOTOHW_INPUT s_in = {0};
|
ADDR_CONVERT_TILEINFOTOHW_INPUT s_in = { 0 };
|
||||||
ADDR_CONVERT_TILEINFOTOHW_OUTPUT s_out = {0};
|
ADDR_CONVERT_TILEINFOTOHW_OUTPUT s_out = { 0 };
|
||||||
ADDR_TILEINFO s_tile_hw_info_out = {0};
|
ADDR_TILEINFO s_tile_hw_info_out = { 0 };
|
||||||
|
|
||||||
s_in.size = sizeof(ADDR_CONVERT_TILEINFOTOHW_INPUT);
|
s_in.size = sizeof(ADDR_CONVERT_TILEINFOTOHW_INPUT);
|
||||||
/* Convert from real value to HW value */
|
/* Convert from real value to HW value */
|
||||||
|
|
@ -212,16 +201,13 @@ static int amdgpu_addrlib_compute(void *addrlib, uint32_t width,
|
||||||
/* LINEAR_ALIGNED */
|
/* LINEAR_ALIGNED */
|
||||||
*tiling_flags |= AMDGPU_TILING_SET(ARRAY_MODE, 1);
|
*tiling_flags |= AMDGPU_TILING_SET(ARRAY_MODE, 1);
|
||||||
|
|
||||||
*tiling_flags |= AMDGPU_TILING_SET(BANK_WIDTH,
|
*tiling_flags |= AMDGPU_TILING_SET(BANK_WIDTH, drv_log_base2(addr_tile_info_out.bankWidth));
|
||||||
drv_log_base2(addr_tile_info_out.bankWidth));
|
*tiling_flags |=
|
||||||
*tiling_flags |= AMDGPU_TILING_SET(BANK_HEIGHT,
|
AMDGPU_TILING_SET(BANK_HEIGHT, drv_log_base2(addr_tile_info_out.bankHeight));
|
||||||
drv_log_base2(addr_tile_info_out.bankHeight));
|
*tiling_flags |= AMDGPU_TILING_SET(TILE_SPLIT, s_tile_hw_info_out.tileSplitBytes);
|
||||||
*tiling_flags |= AMDGPU_TILING_SET(TILE_SPLIT,
|
|
||||||
s_tile_hw_info_out.tileSplitBytes);
|
|
||||||
*tiling_flags |= AMDGPU_TILING_SET(MACRO_TILE_ASPECT,
|
*tiling_flags |= AMDGPU_TILING_SET(MACRO_TILE_ASPECT,
|
||||||
drv_log_base2(addr_tile_info_out.macroAspectRatio));
|
drv_log_base2(addr_tile_info_out.macroAspectRatio));
|
||||||
*tiling_flags |= AMDGPU_TILING_SET(PIPE_CONFIG,
|
*tiling_flags |= AMDGPU_TILING_SET(PIPE_CONFIG, s_tile_hw_info_out.pipeConfig);
|
||||||
s_tile_hw_info_out.pipeConfig);
|
|
||||||
*tiling_flags |= AMDGPU_TILING_SET(NUM_BANKS, s_tile_hw_info_out.banks);
|
*tiling_flags |= AMDGPU_TILING_SET(NUM_BANKS, s_tile_hw_info_out.banks);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -230,16 +216,16 @@ static int amdgpu_addrlib_compute(void *addrlib, uint32_t width,
|
||||||
static void *amdgpu_addrlib_init(int fd)
|
static void *amdgpu_addrlib_init(int fd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
ADDR_CREATE_INPUT addr_create_input = {0};
|
ADDR_CREATE_INPUT addr_create_input = { 0 };
|
||||||
ADDR_CREATE_OUTPUT addr_create_output = {0};
|
ADDR_CREATE_OUTPUT addr_create_output = { 0 };
|
||||||
ADDR_REGISTER_VALUE reg_value = {0};
|
ADDR_REGISTER_VALUE reg_value = { 0 };
|
||||||
ADDR_CREATE_FLAGS create_flags = { {0} };
|
ADDR_CREATE_FLAGS create_flags = { { 0 } };
|
||||||
ADDR_E_RETURNCODE addr_ret;
|
ADDR_E_RETURNCODE addr_ret;
|
||||||
|
|
||||||
addr_create_input.size = sizeof(ADDR_CREATE_INPUT);
|
addr_create_input.size = sizeof(ADDR_CREATE_INPUT);
|
||||||
addr_create_output.size = sizeof(ADDR_CREATE_OUTPUT);
|
addr_create_output.size = sizeof(ADDR_CREATE_OUTPUT);
|
||||||
|
|
||||||
struct amdgpu_gpu_info gpu_info = {0};
|
struct amdgpu_gpu_info gpu_info = { 0 };
|
||||||
|
|
||||||
ret = amdgpu_query_gpu(fd, &gpu_info);
|
ret = amdgpu_query_gpu(fd, &gpu_info);
|
||||||
|
|
||||||
|
|
@ -254,11 +240,10 @@ static void *amdgpu_addrlib_init(int fd)
|
||||||
|
|
||||||
reg_value.backendDisables = gpu_info.backend_disable[0];
|
reg_value.backendDisables = gpu_info.backend_disable[0];
|
||||||
reg_value.pTileConfig = gpu_info.gb_tile_mode;
|
reg_value.pTileConfig = gpu_info.gb_tile_mode;
|
||||||
reg_value.noOfEntries = sizeof(gpu_info.gb_tile_mode)
|
reg_value.noOfEntries = sizeof(gpu_info.gb_tile_mode) / sizeof(gpu_info.gb_tile_mode[0]);
|
||||||
/ sizeof(gpu_info.gb_tile_mode[0]);
|
|
||||||
reg_value.pMacroTileConfig = gpu_info.gb_macro_tile_mode;
|
reg_value.pMacroTileConfig = gpu_info.gb_macro_tile_mode;
|
||||||
reg_value.noOfMacroEntries = sizeof(gpu_info.gb_macro_tile_mode)
|
reg_value.noOfMacroEntries =
|
||||||
/ sizeof(gpu_info.gb_macro_tile_mode[0]);
|
sizeof(gpu_info.gb_macro_tile_mode) / sizeof(gpu_info.gb_macro_tile_mode[0]);
|
||||||
create_flags.value = 0;
|
create_flags.value = 0;
|
||||||
create_flags.useTileIndex = 1;
|
create_flags.useTileIndex = 1;
|
||||||
|
|
||||||
|
|
@ -298,25 +283,20 @@ static int amdgpu_init(struct driver *drv)
|
||||||
metadata.priority = 1;
|
metadata.priority = 1;
|
||||||
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, supported_formats,
|
ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
|
||||||
ARRAY_SIZE(supported_formats), &metadata,
|
|
||||||
flags);
|
flags);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
|
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
|
drv_modify_combination(drv, DRM_FORMAT_XBGR8888, &metadata, BO_USE_SCANOUT);
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
|
||||||
drv_modify_combination(drv, DRM_FORMAT_XBGR8888, &metadata,
|
|
||||||
BO_USE_SCANOUT);
|
|
||||||
|
|
||||||
metadata.tiling = ADDR_NON_DISPLAYABLE << 16 | ADDR_TM_LINEAR_ALIGNED;
|
metadata.tiling = ADDR_NON_DISPLAYABLE << 16 | ADDR_TM_LINEAR_ALIGNED;
|
||||||
metadata.priority = 2;
|
metadata.priority = 2;
|
||||||
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, supported_formats,
|
ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
|
||||||
ARRAY_SIZE(supported_formats), &metadata,
|
|
||||||
flags);
|
flags);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -328,24 +308,19 @@ static int amdgpu_init(struct driver *drv)
|
||||||
metadata.tiling = ADDR_DISPLAYABLE << 16 | ADDR_TM_2D_TILED_THIN1;
|
metadata.tiling = ADDR_DISPLAYABLE << 16 | ADDR_TM_2D_TILED_THIN1;
|
||||||
metadata.priority = 3;
|
metadata.priority = 3;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, supported_formats,
|
ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
|
||||||
ARRAY_SIZE(supported_formats), &metadata,
|
|
||||||
flags);
|
flags);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
|
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_SCANOUT);
|
||||||
BO_USE_SCANOUT);
|
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_SCANOUT);
|
||||||
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
|
drv_modify_combination(drv, DRM_FORMAT_XBGR8888, &metadata, BO_USE_SCANOUT);
|
||||||
BO_USE_SCANOUT);
|
|
||||||
drv_modify_combination(drv, DRM_FORMAT_XBGR8888, &metadata,
|
|
||||||
BO_USE_SCANOUT);
|
|
||||||
|
|
||||||
metadata.tiling = ADDR_NON_DISPLAYABLE << 16 | ADDR_TM_2D_TILED_THIN1;
|
metadata.tiling = ADDR_NON_DISPLAYABLE << 16 | ADDR_TM_2D_TILED_THIN1;
|
||||||
metadata.priority = 4;
|
metadata.priority = 4;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, supported_formats,
|
ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
|
||||||
ARRAY_SIZE(supported_formats), &metadata,
|
|
||||||
flags);
|
flags);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -359,31 +334,27 @@ static void amdgpu_close(struct driver *drv)
|
||||||
drv->priv = NULL;
|
drv->priv = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t usage)
|
uint32_t usage)
|
||||||
{
|
{
|
||||||
void *addrlib = bo->drv->priv;
|
void *addrlib = bo->drv->priv;
|
||||||
union drm_amdgpu_gem_create gem_create;
|
union drm_amdgpu_gem_create gem_create;
|
||||||
struct amdgpu_bo_metadata metadata = {0};
|
struct amdgpu_bo_metadata metadata = { 0 };
|
||||||
ADDR_COMPUTE_SURFACE_INFO_OUTPUT addr_out = {0};
|
ADDR_COMPUTE_SURFACE_INFO_OUTPUT addr_out = { 0 };
|
||||||
uint32_t tiling_flags = 0;
|
uint32_t tiling_flags = 0;
|
||||||
uint32_t gem_create_flags = 0;
|
uint32_t gem_create_flags = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (amdgpu_addrlib_compute(addrlib, width,
|
if (amdgpu_addrlib_compute(addrlib, width, height, format, usage, &tiling_flags,
|
||||||
height, format, usage,
|
|
||||||
&tiling_flags,
|
|
||||||
&addr_out) < 0)
|
&addr_out) < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
bo->tiling = tiling_flags;
|
bo->tiling = tiling_flags;
|
||||||
bo->offsets[0] = 0;
|
bo->offsets[0] = 0;
|
||||||
bo->sizes[0] = addr_out.surfSize;
|
bo->sizes[0] = addr_out.surfSize;
|
||||||
bo->strides[0] = addr_out.pixelPitch
|
bo->strides[0] = addr_out.pixelPitch * DIV_ROUND_UP(addr_out.pixelBits, 8);
|
||||||
* DIV_ROUND_UP(addr_out.pixelBits, 8);
|
if (usage & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN |
|
||||||
if (usage & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN |
|
BO_USE_SW_WRITE_RARELY | BO_USE_SW_READ_RARELY))
|
||||||
BO_USE_SW_WRITE_OFTEN | BO_USE_SW_WRITE_RARELY |
|
|
||||||
BO_USE_SW_READ_RARELY))
|
|
||||||
gem_create_flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
|
gem_create_flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
|
||||||
else
|
else
|
||||||
gem_create_flags |= AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
|
gem_create_flags |= AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
|
||||||
|
|
@ -396,8 +367,8 @@ static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
gem_create.in.domain_flags = gem_create_flags;
|
gem_create.in.domain_flags = gem_create_flags;
|
||||||
|
|
||||||
/* Allocate the buffer with the preferred heap. */
|
/* Allocate the buffer with the preferred heap. */
|
||||||
ret = drmCommandWriteRead(drv_get_fd(bo->drv), DRM_AMDGPU_GEM_CREATE,
|
ret = drmCommandWriteRead(drv_get_fd(bo->drv), DRM_AMDGPU_GEM_CREATE, &gem_create,
|
||||||
&gem_create, sizeof(gem_create));
|
sizeof(gem_create));
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -406,8 +377,7 @@ static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
|
|
||||||
metadata.tiling_info = tiling_flags;
|
metadata.tiling_info = tiling_flags;
|
||||||
|
|
||||||
ret = amdgpu_set_metadata(drv_get_fd(bo->drv),
|
ret = amdgpu_set_metadata(drv_get_fd(bo->drv), bo->handles[0].u32, &metadata);
|
||||||
bo->handles[0].u32, &metadata);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -427,8 +397,8 @@ static void *amdgpu_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
||||||
}
|
}
|
||||||
data->length = bo->sizes[0];
|
data->length = bo->sizes[0];
|
||||||
|
|
||||||
return mmap(0, bo->sizes[0], PROT_READ | PROT_WRITE, MAP_SHARED,
|
return mmap(0, bo->sizes[0], PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
|
||||||
bo->drv->fd, gem_map.out.addr_ptr);
|
gem_map.out.addr_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_amdgpu = {
|
struct backend backend_amdgpu = {
|
||||||
|
|
@ -442,4 +412,3 @@ struct backend backend_amdgpu = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
11
cirrus.c
11
cirrus.c
|
|
@ -8,18 +8,15 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
const static uint32_t supported_formats[] = {
|
const static uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB888,
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB888, DRM_FORMAT_XRGB8888
|
DRM_FORMAT_XRGB8888 };
|
||||||
};
|
|
||||||
|
|
||||||
static int cirrus_init(struct driver *drv)
|
static int cirrus_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_cirrus =
|
struct backend backend_cirrus = {
|
||||||
{
|
|
||||||
.name = "cirrus",
|
.name = "cirrus",
|
||||||
.init = cirrus_init,
|
.init = cirrus_init,
|
||||||
.bo_create = drv_dumb_bo_create,
|
.bo_create = drv_dumb_bo_create,
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
#include "cros_gralloc.h"
|
#include "cros_gralloc.h"
|
||||||
|
|
||||||
static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv,
|
static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv, int width, int height,
|
||||||
int width, int height,
|
|
||||||
int format, int usage)
|
int format, int usage)
|
||||||
{
|
{
|
||||||
uint64_t drv_usage;
|
uint64_t drv_usage;
|
||||||
|
|
@ -29,9 +28,8 @@ static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv,
|
||||||
if (!combo) {
|
if (!combo) {
|
||||||
cros_gralloc_error("Unsupported combination -- HAL format: %u, "
|
cros_gralloc_error("Unsupported combination -- HAL format: %u, "
|
||||||
"HAL flags: %u, drv_format: %4.4s, "
|
"HAL flags: %u, drv_format: %4.4s, "
|
||||||
"drv_flags: %llu", format, usage,
|
"drv_flags: %llu",
|
||||||
reinterpret_cast<char*>(&drv_format),
|
format, usage, reinterpret_cast<char *>(&drv_format), drv_usage);
|
||||||
drv_usage);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +83,7 @@ static struct cros_gralloc_handle *cros_gralloc_handle_from_bo(struct bo *bo)
|
||||||
|
|
||||||
mod = drv_bo_get_plane_format_modifier(bo, p);
|
mod = drv_bo_get_plane_format_modifier(bo, p);
|
||||||
hnd->format_modifiers[p] = static_cast<uint32_t>(mod >> 32);
|
hnd->format_modifiers[p] = static_cast<uint32_t>(mod >> 32);
|
||||||
hnd->format_modifiers[p+1] = static_cast<uint32_t>(mod);
|
hnd->format_modifiers[p + 1] = static_cast<uint32_t>(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
hnd->width = drv_bo_get_width(bo);
|
hnd->width = drv_bo_get_width(bo);
|
||||||
|
|
@ -98,10 +96,10 @@ static struct cros_gralloc_handle *cros_gralloc_handle_from_bo(struct bo *bo)
|
||||||
return hnd;
|
return hnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format,
|
static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format, int usage,
|
||||||
int usage, buffer_handle_t *handle, int *stride)
|
buffer_handle_t *handle, int *stride)
|
||||||
{
|
{
|
||||||
auto mod = (struct cros_gralloc_module *) dev->common.module;
|
auto mod = (struct cros_gralloc_module *)dev->common.module;
|
||||||
std::lock_guard<std::mutex> lock(mod->mutex);
|
std::lock_guard<std::mutex> lock(mod->mutex);
|
||||||
|
|
||||||
auto bo = cros_gralloc_bo_create(mod->drv, w, h, format, usage);
|
auto bo = cros_gralloc_bo_create(mod->drv, w, h, format, usage);
|
||||||
|
|
@ -127,8 +125,8 @@ static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format,
|
||||||
static int cros_gralloc_free(alloc_device_t *dev, buffer_handle_t handle)
|
static int cros_gralloc_free(alloc_device_t *dev, buffer_handle_t handle)
|
||||||
{
|
{
|
||||||
struct cros_gralloc_bo *bo;
|
struct cros_gralloc_bo *bo;
|
||||||
auto hnd = (struct cros_gralloc_handle *) handle;
|
auto hnd = (struct cros_gralloc_handle *)handle;
|
||||||
auto mod = (struct cros_gralloc_module *) dev->common.module;
|
auto mod = (struct cros_gralloc_module *)dev->common.module;
|
||||||
std::lock_guard<std::mutex> lock(mod->mutex);
|
std::lock_guard<std::mutex> lock(mod->mutex);
|
||||||
|
|
||||||
if (cros_gralloc_validate_handle(hnd)) {
|
if (cros_gralloc_validate_handle(hnd)) {
|
||||||
|
|
@ -151,8 +149,8 @@ static int cros_gralloc_free(alloc_device_t *dev, buffer_handle_t handle)
|
||||||
|
|
||||||
static int cros_gralloc_close(struct hw_device_t *dev)
|
static int cros_gralloc_close(struct hw_device_t *dev)
|
||||||
{
|
{
|
||||||
auto mod = (struct cros_gralloc_module *) dev->module;
|
auto mod = (struct cros_gralloc_module *)dev->module;
|
||||||
auto alloc = (struct alloc_device_t *) dev;
|
auto alloc = (struct alloc_device_t *)dev;
|
||||||
std::lock_guard<std::mutex> lock(mod->mutex);
|
std::lock_guard<std::mutex> lock(mod->mutex);
|
||||||
|
|
||||||
if (mod->drv) {
|
if (mod->drv) {
|
||||||
|
|
@ -168,10 +166,9 @@ static int cros_gralloc_close(struct hw_device_t *dev)
|
||||||
return CROS_GRALLOC_ERROR_NONE;
|
return CROS_GRALLOC_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cros_gralloc_open(const struct hw_module_t *mod, const char *name,
|
int cros_gralloc_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev)
|
||||||
struct hw_device_t **dev)
|
|
||||||
{
|
{
|
||||||
auto module = (struct cros_gralloc_module *) mod;
|
auto module = (struct cros_gralloc_module *)mod;
|
||||||
std::lock_guard<std::mutex> lock(module->mutex);
|
std::lock_guard<std::mutex> lock(module->mutex);
|
||||||
|
|
||||||
if (module->drv)
|
if (module->drv)
|
||||||
|
|
@ -194,7 +191,7 @@ int cros_gralloc_open(const struct hw_module_t *mod, const char *name,
|
||||||
alloc->free = cros_gralloc_free;
|
alloc->free = cros_gralloc_free;
|
||||||
alloc->common.tag = HARDWARE_DEVICE_TAG;
|
alloc->common.tag = HARDWARE_DEVICE_TAG;
|
||||||
alloc->common.version = 0;
|
alloc->common.version = 0;
|
||||||
alloc->common.module = (hw_module_t*) mod;
|
alloc->common.module = (hw_module_t *)mod;
|
||||||
alloc->common.close = cros_gralloc_close;
|
alloc->common.close = cros_gralloc_close;
|
||||||
|
|
||||||
*dev = &alloc->common;
|
*dev = &alloc->common;
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
#include "cros_gralloc_helpers.h"
|
#include "cros_gralloc_helpers.h"
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <unordered_set>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
struct cros_gralloc_bo {
|
struct cros_gralloc_bo {
|
||||||
struct bo *bo;
|
struct bo *bo;
|
||||||
|
|
@ -30,16 +30,14 @@ struct cros_gralloc_module {
|
||||||
gralloc_module_t base;
|
gralloc_module_t base;
|
||||||
struct driver *drv;
|
struct driver *drv;
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
std::unordered_map<cros_gralloc_handle*, handle_info> handles;
|
std::unordered_map<cros_gralloc_handle *, handle_info> handles;
|
||||||
std::unordered_map<uint32_t, cros_gralloc_bo*> buffers;
|
std::unordered_map<uint32_t, cros_gralloc_bo *> buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
int cros_gralloc_open(const struct hw_module_t *mod, const char *name,
|
int cros_gralloc_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev);
|
||||||
struct hw_device_t **dev);
|
|
||||||
|
|
||||||
int cros_gralloc_validate_reference(struct cros_gralloc_module *mod,
|
int cros_gralloc_validate_reference(struct cros_gralloc_module *mod,
|
||||||
struct cros_gralloc_handle *hnd,
|
struct cros_gralloc_handle *hnd, struct cros_gralloc_bo **obj);
|
||||||
struct cros_gralloc_bo **obj);
|
|
||||||
|
|
||||||
int cros_gralloc_decrement_reference_count(struct cros_gralloc_module *mod,
|
int cros_gralloc_decrement_reference_count(struct cros_gralloc_module *mod,
|
||||||
struct cros_gralloc_bo *obj);
|
struct cros_gralloc_bo *obj);
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
#ifndef CROS_GRALLOC_HANDLE_H
|
#ifndef CROS_GRALLOC_HANDLE_H
|
||||||
#define CROS_GRALLOC_HANDLE_H
|
#define CROS_GRALLOC_HANDLE_H
|
||||||
|
|
||||||
#include <cutils/native_handle.h>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cutils/native_handle.h>
|
||||||
|
|
||||||
#define DRV_MAX_PLANES 4
|
#define DRV_MAX_PLANES 4
|
||||||
|
|
||||||
|
|
@ -26,11 +26,11 @@ struct cros_gralloc_handle {
|
||||||
uint32_t format_modifiers[2 * DRV_MAX_PLANES];
|
uint32_t format_modifiers[2 * DRV_MAX_PLANES];
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint32_t format; /* DRM format */
|
uint32_t format; /* DRM format */
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
uint32_t pixel_stride;
|
uint32_t pixel_stride;
|
||||||
int32_t droid_format;
|
int32_t droid_format;
|
||||||
int32_t usage; /* Android usage. */
|
int32_t usage; /* Android usage. */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,12 @@ uint64_t cros_gralloc_convert_flags(int flags)
|
||||||
if (flags & GRALLOC_USAGE_HW_2D)
|
if (flags & GRALLOC_USAGE_HW_2D)
|
||||||
usage |= BO_USE_RENDERING;
|
usage |= BO_USE_RENDERING;
|
||||||
if (flags & GRALLOC_USAGE_HW_COMPOSER)
|
if (flags & GRALLOC_USAGE_HW_COMPOSER)
|
||||||
/* HWC wants to use display hardware, but can defer to OpenGL. */
|
/* HWC wants to use display hardware, but can defer to OpenGL. */
|
||||||
usage |= BO_USE_SCANOUT | BO_USE_RENDERING;
|
usage |= BO_USE_SCANOUT | BO_USE_RENDERING;
|
||||||
if (flags & GRALLOC_USAGE_HW_FB)
|
if (flags & GRALLOC_USAGE_HW_FB)
|
||||||
usage |= BO_USE_NONE;
|
usage |= BO_USE_NONE;
|
||||||
if (flags & GRALLOC_USAGE_EXTERNAL_DISP)
|
if (flags & GRALLOC_USAGE_EXTERNAL_DISP)
|
||||||
/* We're ignoring this flag until we decide what to with display link */
|
/* We're ignoring this flag until we decide what to with display link */
|
||||||
usage |= BO_USE_NONE;
|
usage |= BO_USE_NONE;
|
||||||
if (flags & GRALLOC_USAGE_PROTECTED)
|
if (flags & GRALLOC_USAGE_PROTECTED)
|
||||||
usage |= BO_USE_PROTECTED;
|
usage |= BO_USE_PROTECTED;
|
||||||
|
|
@ -86,8 +86,7 @@ uint32_t cros_gralloc_convert_format(int format)
|
||||||
return DRM_FORMAT_NONE;
|
return DRM_FORMAT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t cros_gralloc_query_rendernode(struct driver **drv,
|
static int32_t cros_gralloc_query_rendernode(struct driver **drv, const char *undesired)
|
||||||
const char *undesired)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Create a driver from rendernode while filtering out
|
* Create a driver from rendernode while filtering out
|
||||||
|
|
@ -154,8 +153,7 @@ int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd)
|
||||||
return CROS_GRALLOC_ERROR_NONE;
|
return CROS_GRALLOC_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cros_gralloc_log(const char *prefix, const char *file, int line,
|
void cros_gralloc_log(const char *prefix, const char *file, int line, const char *format, ...)
|
||||||
const char *format, ...)
|
|
||||||
{
|
{
|
||||||
char buf[50];
|
char buf[50];
|
||||||
snprintf(buf, sizeof(buf), "[%s:%s(%d)]", prefix, basename(file), line);
|
snprintf(buf, sizeof(buf), "[%s:%s(%d)]", prefix, basename(file), line);
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,14 @@ typedef enum {
|
||||||
* reserved for cases where no alternative to get same information (such as
|
* reserved for cases where no alternative to get same information (such as
|
||||||
* querying ANativeWindow) exists.
|
* querying ANativeWindow) exists.
|
||||||
*/
|
*/
|
||||||
|
// clang-format off
|
||||||
enum {
|
enum {
|
||||||
GRALLOC_DRM_GET_STRIDE,
|
GRALLOC_DRM_GET_STRIDE,
|
||||||
GRALLOC_DRM_GET_FORMAT,
|
GRALLOC_DRM_GET_FORMAT,
|
||||||
GRALLOC_DRM_GET_DIMENSIONS,
|
GRALLOC_DRM_GET_DIMENSIONS,
|
||||||
GRALLOC_DRM_GET_BACKING_STORE,
|
GRALLOC_DRM_GET_BACKING_STORE,
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
constexpr uint32_t cros_gralloc_magic(void)
|
constexpr uint32_t cros_gralloc_magic(void)
|
||||||
{
|
{
|
||||||
|
|
@ -74,14 +76,12 @@ int32_t cros_gralloc_rendernode_open(struct driver **drv);
|
||||||
int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd);
|
int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd);
|
||||||
|
|
||||||
/* Logging code adapted from bsdrm */
|
/* Logging code adapted from bsdrm */
|
||||||
__attribute__((format(printf, 4, 5)))
|
__attribute__((format(printf, 4, 5))) void cros_gralloc_log(const char *prefix, const char *file,
|
||||||
void cros_gralloc_log(const char *prefix, const char *file, int line,
|
int line, const char *format, ...);
|
||||||
const char *format, ...);
|
|
||||||
|
|
||||||
#define cros_gralloc_error(...) \
|
#define cros_gralloc_error(...) \
|
||||||
do { \
|
do { \
|
||||||
cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, \
|
cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, __LINE__, __VA_ARGS__); \
|
||||||
__LINE__, __VA_ARGS__); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
|
|
||||||
int cros_gralloc_validate_reference(struct cros_gralloc_module *mod,
|
int cros_gralloc_validate_reference(struct cros_gralloc_module *mod,
|
||||||
struct cros_gralloc_handle *hnd,
|
struct cros_gralloc_handle *hnd, struct cros_gralloc_bo **bo)
|
||||||
struct cros_gralloc_bo **bo)
|
|
||||||
{
|
{
|
||||||
if (!mod->handles.count(hnd))
|
if (!mod->handles.count(hnd))
|
||||||
return CROS_GRALLOC_ERROR_BAD_HANDLE;
|
return CROS_GRALLOC_ERROR_BAD_HANDLE;
|
||||||
|
|
@ -44,13 +43,13 @@ int cros_gralloc_decrement_reference_count(struct cros_gralloc_module *mod,
|
||||||
return CROS_GRALLOC_ERROR_NONE;
|
return CROS_GRALLOC_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cros_gralloc_register_buffer(struct gralloc_module_t const* module,
|
static int cros_gralloc_register_buffer(struct gralloc_module_t const *module,
|
||||||
buffer_handle_t handle)
|
buffer_handle_t handle)
|
||||||
{
|
{
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
struct cros_gralloc_bo *bo;
|
struct cros_gralloc_bo *bo;
|
||||||
auto hnd = (struct cros_gralloc_handle *) handle;
|
auto hnd = (struct cros_gralloc_handle *)handle;
|
||||||
auto mod = (struct cros_gralloc_module *) module;
|
auto mod = (struct cros_gralloc_module *)module;
|
||||||
std::lock_guard<std::mutex> lock(mod->mutex);
|
std::lock_guard<std::mutex> lock(mod->mutex);
|
||||||
|
|
||||||
if (cros_gralloc_validate_handle(hnd)) {
|
if (cros_gralloc_validate_handle(hnd)) {
|
||||||
|
|
@ -91,9 +90,9 @@ static int cros_gralloc_register_buffer(struct gralloc_module_t const* module,
|
||||||
data.strides[p] = hnd->strides[p];
|
data.strides[p] = hnd->strides[p];
|
||||||
data.offsets[p] = hnd->offsets[p];
|
data.offsets[p] = hnd->offsets[p];
|
||||||
data.sizes[p] = hnd->sizes[p];
|
data.sizes[p] = hnd->sizes[p];
|
||||||
data.format_modifiers[p] = static_cast<uint64_t>
|
data.format_modifiers[p] = static_cast<uint64_t>(hnd->format_modifiers[p])
|
||||||
(hnd->format_modifiers[p]) << 32;
|
<< 32;
|
||||||
data.format_modifiers[p] |= hnd->format_modifiers[p+1];
|
data.format_modifiers[p] |= hnd->format_modifiers[p + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
bo = new cros_gralloc_bo();
|
bo = new cros_gralloc_bo();
|
||||||
|
|
@ -116,12 +115,12 @@ static int cros_gralloc_register_buffer(struct gralloc_module_t const* module,
|
||||||
return CROS_GRALLOC_ERROR_NONE;
|
return CROS_GRALLOC_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cros_gralloc_unregister_buffer(struct gralloc_module_t const* module,
|
static int cros_gralloc_unregister_buffer(struct gralloc_module_t const *module,
|
||||||
buffer_handle_t handle)
|
buffer_handle_t handle)
|
||||||
{
|
{
|
||||||
struct cros_gralloc_bo *bo;
|
struct cros_gralloc_bo *bo;
|
||||||
auto hnd = (struct cros_gralloc_handle *) handle;
|
auto hnd = (struct cros_gralloc_handle *)handle;
|
||||||
auto mod = (struct cros_gralloc_module *) module;
|
auto mod = (struct cros_gralloc_module *)module;
|
||||||
std::lock_guard<std::mutex> lock(mod->mutex);
|
std::lock_guard<std::mutex> lock(mod->mutex);
|
||||||
|
|
||||||
if (cros_gralloc_validate_handle(hnd)) {
|
if (cros_gralloc_validate_handle(hnd)) {
|
||||||
|
|
@ -147,13 +146,12 @@ static int cros_gralloc_unregister_buffer(struct gralloc_module_t const* module,
|
||||||
return cros_gralloc_decrement_reference_count(mod, bo);
|
return cros_gralloc_decrement_reference_count(mod, bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cros_gralloc_lock(struct gralloc_module_t const* module,
|
static int cros_gralloc_lock(struct gralloc_module_t const *module, buffer_handle_t handle,
|
||||||
buffer_handle_t handle, int usage, int l, int t,
|
int usage, int l, int t, int w, int h, void **vaddr)
|
||||||
int w, int h, void** vaddr)
|
|
||||||
{
|
{
|
||||||
struct cros_gralloc_bo *bo;
|
struct cros_gralloc_bo *bo;
|
||||||
auto mod = (struct cros_gralloc_module *) module;
|
auto mod = (struct cros_gralloc_module *)module;
|
||||||
auto hnd = (struct cros_gralloc_handle *) handle;
|
auto hnd = (struct cros_gralloc_handle *)handle;
|
||||||
std::lock_guard<std::mutex> lock(mod->mutex);
|
std::lock_guard<std::mutex> lock(mod->mutex);
|
||||||
|
|
||||||
if (cros_gralloc_validate_handle(hnd)) {
|
if (cros_gralloc_validate_handle(hnd)) {
|
||||||
|
|
@ -177,8 +175,7 @@ static int cros_gralloc_lock(struct gralloc_module_t const* module,
|
||||||
*vaddr = bo->map_data->addr;
|
*vaddr = bo->map_data->addr;
|
||||||
} else {
|
} else {
|
||||||
*vaddr = drv_bo_map(bo->bo, 0, 0, drv_bo_get_width(bo->bo),
|
*vaddr = drv_bo_map(bo->bo, 0, 0, drv_bo_get_width(bo->bo),
|
||||||
drv_bo_get_height(bo->bo), 0,
|
drv_bo_get_height(bo->bo), 0, &bo->map_data, 0);
|
||||||
&bo->map_data, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*vaddr == MAP_FAILED) {
|
if (*vaddr == MAP_FAILED) {
|
||||||
|
|
@ -192,12 +189,11 @@ static int cros_gralloc_lock(struct gralloc_module_t const* module,
|
||||||
return CROS_GRALLOC_ERROR_NONE;
|
return CROS_GRALLOC_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cros_gralloc_unlock(struct gralloc_module_t const* module,
|
static int cros_gralloc_unlock(struct gralloc_module_t const *module, buffer_handle_t handle)
|
||||||
buffer_handle_t handle)
|
|
||||||
{
|
{
|
||||||
struct cros_gralloc_bo *bo;
|
struct cros_gralloc_bo *bo;
|
||||||
auto hnd = (struct cros_gralloc_handle *) handle;
|
auto hnd = (struct cros_gralloc_handle *)handle;
|
||||||
auto mod = (struct cros_gralloc_module *) module;
|
auto mod = (struct cros_gralloc_module *)module;
|
||||||
std::lock_guard<std::mutex> lock(mod->mutex);
|
std::lock_guard<std::mutex> lock(mod->mutex);
|
||||||
|
|
||||||
if (cros_gralloc_validate_handle(hnd)) {
|
if (cros_gralloc_validate_handle(hnd)) {
|
||||||
|
|
@ -218,8 +214,7 @@ static int cros_gralloc_unlock(struct gralloc_module_t const* module,
|
||||||
return CROS_GRALLOC_ERROR_NONE;
|
return CROS_GRALLOC_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cros_gralloc_perform(struct gralloc_module_t const* module,
|
static int cros_gralloc_perform(struct gralloc_module_t const *module, int op, ...)
|
||||||
int op, ... )
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
struct cros_gralloc_bo *bo;
|
struct cros_gralloc_bo *bo;
|
||||||
|
|
@ -227,7 +222,7 @@ static int cros_gralloc_perform(struct gralloc_module_t const* module,
|
||||||
uint64_t *out_store;
|
uint64_t *out_store;
|
||||||
buffer_handle_t handle;
|
buffer_handle_t handle;
|
||||||
uint32_t *out_width, *out_height, *out_stride;
|
uint32_t *out_width, *out_height, *out_stride;
|
||||||
auto mod = (struct cros_gralloc_module *) module;
|
auto mod = (struct cros_gralloc_module *)module;
|
||||||
std::lock_guard<std::mutex> lock(mod->mutex);
|
std::lock_guard<std::mutex> lock(mod->mutex);
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
|
|
@ -242,7 +237,7 @@ static int cros_gralloc_perform(struct gralloc_module_t const* module,
|
||||||
|
|
||||||
va_start(args, op);
|
va_start(args, op);
|
||||||
handle = va_arg(args, buffer_handle_t);
|
handle = va_arg(args, buffer_handle_t);
|
||||||
auto hnd = (struct cros_gralloc_handle *) handle;
|
auto hnd = (struct cros_gralloc_handle *)handle;
|
||||||
|
|
||||||
if (cros_gralloc_validate_handle(hnd)) {
|
if (cros_gralloc_validate_handle(hnd)) {
|
||||||
cros_gralloc_error("Invalid handle.");
|
cros_gralloc_error("Invalid handle.");
|
||||||
|
|
@ -282,16 +277,15 @@ static int cros_gralloc_perform(struct gralloc_module_t const* module,
|
||||||
return CROS_GRALLOC_ERROR_NONE;
|
return CROS_GRALLOC_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module,
|
static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const *module, buffer_handle_t handle,
|
||||||
buffer_handle_t handle, int usage, int l,
|
int usage, int l, int t, int w, int h,
|
||||||
int t, int w, int h,
|
|
||||||
struct android_ycbcr *ycbcr)
|
struct android_ycbcr *ycbcr)
|
||||||
{
|
{
|
||||||
uint8_t *addr = NULL;
|
uint8_t *addr = NULL;
|
||||||
size_t offsets[DRV_MAX_PLANES];
|
size_t offsets[DRV_MAX_PLANES];
|
||||||
struct cros_gralloc_bo *bo;
|
struct cros_gralloc_bo *bo;
|
||||||
auto hnd = (struct cros_gralloc_handle *) handle;
|
auto hnd = (struct cros_gralloc_handle *)handle;
|
||||||
auto mod = (struct cros_gralloc_module *) module;
|
auto mod = (struct cros_gralloc_module *)module;
|
||||||
std::lock_guard<std::mutex> lock(mod->mutex);
|
std::lock_guard<std::mutex> lock(mod->mutex);
|
||||||
|
|
||||||
if (cros_gralloc_validate_handle(hnd)) {
|
if (cros_gralloc_validate_handle(hnd)) {
|
||||||
|
|
@ -316,8 +310,7 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module,
|
||||||
vaddr = bo->map_data->addr;
|
vaddr = bo->map_data->addr;
|
||||||
} else {
|
} else {
|
||||||
vaddr = drv_bo_map(bo->bo, 0, 0, drv_bo_get_width(bo->bo),
|
vaddr = drv_bo_map(bo->bo, 0, 0, drv_bo_get_width(bo->bo),
|
||||||
drv_bo_get_height(bo->bo), 0,
|
drv_bo_get_height(bo->bo), 0, &bo->map_data, 0);
|
||||||
&bo->map_data, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vaddr == MAP_FAILED) {
|
if (vaddr == MAP_FAILED) {
|
||||||
|
|
@ -325,7 +318,7 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module,
|
||||||
return CROS_GRALLOC_ERROR_UNSUPPORTED;
|
return CROS_GRALLOC_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = static_cast<uint8_t*>(vaddr);
|
addr = static_cast<uint8_t *>(vaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t p = 0; p < drv_bo_get_num_planes(bo->bo); p++)
|
for (size_t p = 0; p < drv_bo_get_num_planes(bo->bo); p++)
|
||||||
|
|
@ -365,13 +358,13 @@ static int cros_gralloc_lock_ycbcr(struct gralloc_module_t const* module,
|
||||||
return CROS_GRALLOC_ERROR_NONE;
|
return CROS_GRALLOC_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct hw_module_methods_t cros_gralloc_module_methods = {
|
static struct hw_module_methods_t cros_gralloc_module_methods = {.open = cros_gralloc_open };
|
||||||
.open = cros_gralloc_open
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cros_gralloc_module HAL_MODULE_INFO_SYM = {
|
struct cros_gralloc_module HAL_MODULE_INFO_SYM = {
|
||||||
.base = {
|
.base =
|
||||||
.common = {
|
{
|
||||||
|
.common =
|
||||||
|
{
|
||||||
.tag = HARDWARE_MODULE_TAG,
|
.tag = HARDWARE_MODULE_TAG,
|
||||||
.module_api_version = GRALLOC_MODULE_API_VERSION_0_2,
|
.module_api_version = GRALLOC_MODULE_API_VERSION_0_2,
|
||||||
.hal_api_version = 0,
|
.hal_api_version = 0,
|
||||||
|
|
@ -379,14 +372,14 @@ struct cros_gralloc_module HAL_MODULE_INFO_SYM = {
|
||||||
.name = "CrOS Gralloc",
|
.name = "CrOS Gralloc",
|
||||||
.author = "Chrome OS",
|
.author = "Chrome OS",
|
||||||
.methods = &cros_gralloc_module_methods,
|
.methods = &cros_gralloc_module_methods,
|
||||||
},
|
},
|
||||||
.registerBuffer = cros_gralloc_register_buffer,
|
.registerBuffer = cros_gralloc_register_buffer,
|
||||||
.unregisterBuffer = cros_gralloc_unregister_buffer,
|
.unregisterBuffer = cros_gralloc_unregister_buffer,
|
||||||
.lock = cros_gralloc_lock,
|
.lock = cros_gralloc_lock,
|
||||||
.unlock = cros_gralloc_unlock,
|
.unlock = cros_gralloc_unlock,
|
||||||
.perform = cros_gralloc_perform,
|
.perform = cros_gralloc_perform,
|
||||||
.lock_ycbcr = cros_gralloc_lock_ycbcr,
|
.lock_ycbcr = cros_gralloc_lock_ycbcr,
|
||||||
},
|
},
|
||||||
|
|
||||||
.drv = NULL,
|
.drv = NULL,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
65
drv.c
65
drv.c
|
|
@ -64,8 +64,7 @@ static struct backend *drv_get_backend(int fd)
|
||||||
#ifdef DRV_AMDGPU
|
#ifdef DRV_AMDGPU
|
||||||
&backend_amdgpu,
|
&backend_amdgpu,
|
||||||
#endif
|
#endif
|
||||||
&backend_cirrus,
|
&backend_cirrus, &backend_evdi,
|
||||||
&backend_evdi,
|
|
||||||
#ifdef DRV_EXYNOS
|
#ifdef DRV_EXYNOS
|
||||||
&backend_exynos,
|
&backend_exynos,
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -90,11 +89,10 @@ static struct backend *drv_get_backend(int fd)
|
||||||
#ifdef DRV_VC4
|
#ifdef DRV_VC4
|
||||||
&backend_vc4,
|
&backend_vc4,
|
||||||
#endif
|
#endif
|
||||||
&backend_vgem,
|
&backend_vgem, &backend_virtio_gpu,
|
||||||
&backend_virtio_gpu,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for(i = 0; i < ARRAY_SIZE(backend_list); i++)
|
for (i = 0; i < ARRAY_SIZE(backend_list); i++)
|
||||||
if (!strcmp(drm_version->name, backend_list[i]->name)) {
|
if (!strcmp(drm_version->name, backend_list[i]->name)) {
|
||||||
drmFreeVersion(drm_version);
|
drmFreeVersion(drm_version);
|
||||||
return backend_list[i];
|
return backend_list[i];
|
||||||
|
|
@ -109,7 +107,7 @@ struct driver *drv_create(int fd)
|
||||||
struct driver *drv;
|
struct driver *drv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
drv = (struct driver *) calloc(1, sizeof(*drv));
|
drv = (struct driver *)calloc(1, sizeof(*drv));
|
||||||
|
|
||||||
if (!drv)
|
if (!drv)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -134,8 +132,8 @@ struct driver *drv_create(int fd)
|
||||||
/* Start with a power of 2 number of allocations. */
|
/* Start with a power of 2 number of allocations. */
|
||||||
drv->backend->combos.allocations = 2;
|
drv->backend->combos.allocations = 2;
|
||||||
drv->backend->combos.size = 0;
|
drv->backend->combos.size = 0;
|
||||||
drv->backend->combos.data = calloc(drv->backend->combos.allocations,
|
drv->backend->combos.data =
|
||||||
sizeof(struct combination));
|
calloc(drv->backend->combos.allocations, sizeof(struct combination));
|
||||||
if (!drv->backend->combos.data)
|
if (!drv->backend->combos.data)
|
||||||
goto free_map_table;
|
goto free_map_table;
|
||||||
|
|
||||||
|
|
@ -183,14 +181,12 @@ int drv_get_fd(struct driver *drv)
|
||||||
return drv->fd;
|
return drv->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *drv_get_name(struct driver *drv)
|
||||||
drv_get_name(struct driver *drv)
|
|
||||||
{
|
{
|
||||||
return drv->backend->name;
|
return drv->backend->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct combination *drv_get_combination(struct driver *drv, uint32_t format,
|
struct combination *drv_get_combination(struct driver *drv, uint32_t format, uint64_t usage)
|
||||||
uint64_t usage)
|
|
||||||
{
|
{
|
||||||
struct combination *curr, *best;
|
struct combination *curr, *best;
|
||||||
|
|
||||||
|
|
@ -202,20 +198,18 @@ struct combination *drv_get_combination(struct driver *drv, uint32_t format,
|
||||||
for (i = 0; i < drv->backend->combos.size; i++) {
|
for (i = 0; i < drv->backend->combos.size; i++) {
|
||||||
curr = &drv->backend->combos.data[i];
|
curr = &drv->backend->combos.data[i];
|
||||||
if ((format == curr->format) && usage == (curr->usage & usage))
|
if ((format == curr->format) && usage == (curr->usage & usage))
|
||||||
if (!best ||
|
if (!best || best->metadata.priority < curr->metadata.priority)
|
||||||
best->metadata.priority < curr->metadata.priority)
|
|
||||||
best = curr;
|
best = curr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height,
|
struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height, uint32_t format)
|
||||||
uint32_t format)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
struct bo *bo;
|
struct bo *bo;
|
||||||
bo = (struct bo *) calloc(1, sizeof(*bo));
|
bo = (struct bo *)calloc(1, sizeof(*bo));
|
||||||
|
|
||||||
if (!bo)
|
if (!bo)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -234,8 +228,8 @@ struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height,
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height,
|
struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint64_t flags)
|
uint64_t flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t plane;
|
size_t plane;
|
||||||
|
|
@ -263,10 +257,8 @@ struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height,
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bo *drv_bo_create_with_modifiers(struct driver *drv,
|
struct bo *drv_bo_create_with_modifiers(struct driver *drv, uint32_t width, uint32_t height,
|
||||||
uint32_t width, uint32_t height,
|
uint32_t format, const uint64_t *modifiers, uint32_t count)
|
||||||
uint32_t format,
|
|
||||||
const uint64_t *modifiers, uint32_t count)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t plane;
|
size_t plane;
|
||||||
|
|
@ -282,8 +274,7 @@ struct bo *drv_bo_create_with_modifiers(struct driver *drv,
|
||||||
if (!bo)
|
if (!bo)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ret = drv->backend->bo_create_with_modifiers(bo, width, height,
|
ret = drv->backend->bo_create_with_modifiers(bo, width, height, format, modifiers, count);
|
||||||
format, modifiers, count);
|
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
free(bo);
|
free(bo);
|
||||||
|
|
@ -300,7 +291,6 @@ struct bo *drv_bo_create_with_modifiers(struct driver *drv,
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void drv_bo_destroy(struct bo *bo)
|
void drv_bo_destroy(struct bo *bo)
|
||||||
{
|
{
|
||||||
size_t plane;
|
size_t plane;
|
||||||
|
|
@ -351,9 +341,8 @@ struct bo *drv_bo_import(struct driver *drv, struct drv_import_fd_data *data)
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width,
|
void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
|
||||||
uint32_t height, uint32_t flags, struct map_info **map_data,
|
uint32_t flags, struct map_info **map_data, size_t plane)
|
||||||
size_t plane)
|
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
uint8_t *addr;
|
uint8_t *addr;
|
||||||
|
|
@ -368,7 +357,7 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width,
|
||||||
pthread_mutex_lock(&bo->drv->driver_lock);
|
pthread_mutex_lock(&bo->drv->driver_lock);
|
||||||
|
|
||||||
if (!drmHashLookup(bo->drv->map_table, bo->handles[plane].u32, &ptr)) {
|
if (!drmHashLookup(bo->drv->map_table, bo->handles[plane].u32, &ptr)) {
|
||||||
data = (struct map_info *) ptr;
|
data = (struct map_info *)ptr;
|
||||||
data->refcount++;
|
data->refcount++;
|
||||||
goto success;
|
goto success;
|
||||||
}
|
}
|
||||||
|
|
@ -385,18 +374,17 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width,
|
||||||
data->refcount = 1;
|
data->refcount = 1;
|
||||||
data->addr = addr;
|
data->addr = addr;
|
||||||
data->handle = bo->handles[plane].u32;
|
data->handle = bo->handles[plane].u32;
|
||||||
drmHashInsert(bo->drv->map_table, bo->handles[plane].u32,
|
drmHashInsert(bo->drv->map_table, bo->handles[plane].u32, (void *)data);
|
||||||
(void *) data);
|
|
||||||
|
|
||||||
success:
|
success:
|
||||||
*map_data = data;
|
*map_data = data;
|
||||||
offset = drv_bo_get_plane_stride(bo, plane) * y;
|
offset = drv_bo_get_plane_stride(bo, plane) * y;
|
||||||
offset += drv_stride_from_format(bo->format, x, plane);
|
offset += drv_stride_from_format(bo->format, x, plane);
|
||||||
addr = (uint8_t *) data->addr;
|
addr = (uint8_t *)data->addr;
|
||||||
addr += drv_bo_get_plane_offset(bo, plane) + offset;
|
addr += drv_bo_get_plane_offset(bo, plane) + offset;
|
||||||
pthread_mutex_unlock(&bo->drv->driver_lock);
|
pthread_mutex_unlock(&bo->drv->driver_lock);
|
||||||
|
|
||||||
return (void *) addr;
|
return (void *)addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int drv_bo_unmap(struct bo *bo, struct map_info *data)
|
int drv_bo_unmap(struct bo *bo, struct map_info *data)
|
||||||
|
|
@ -457,11 +445,9 @@ int drv_bo_get_plane_fd(struct bo *bo, size_t plane)
|
||||||
int ret, fd;
|
int ret, fd;
|
||||||
assert(plane < bo->num_planes);
|
assert(plane < bo->num_planes);
|
||||||
|
|
||||||
ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32,
|
ret = drmPrimeHandleToFD(bo->drv->fd, bo->handles[plane].u32, DRM_CLOEXEC | DRM_RDWR, &fd);
|
||||||
DRM_CLOEXEC | DRM_RDWR, &fd);
|
|
||||||
|
|
||||||
return (ret) ? ret : fd;
|
return (ret) ? ret : fd;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t drv_bo_get_plane_offset(struct bo *bo, size_t plane)
|
uint32_t drv_bo_get_plane_offset(struct bo *bo, size_t plane)
|
||||||
|
|
@ -484,7 +470,7 @@ uint32_t drv_bo_get_plane_stride(struct bo *bo, size_t plane)
|
||||||
|
|
||||||
uint64_t drv_bo_get_plane_format_modifier(struct bo *bo, size_t plane)
|
uint64_t drv_bo_get_plane_format_modifier(struct bo *bo, size_t plane)
|
||||||
{
|
{
|
||||||
assert(plane < bo->num_planes);
|
assert(plane < bo->num_planes);
|
||||||
return bo->format_modifiers[plane];
|
return bo->format_modifiers[plane];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -563,8 +549,7 @@ size_t drv_num_planes_from_format(uint32_t format)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t drv_size_from_format(uint32_t format, uint32_t stride,
|
uint32_t drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height, size_t plane)
|
||||||
uint32_t height, size_t plane)
|
|
||||||
{
|
{
|
||||||
assert(plane < drv_num_planes_from_format(format));
|
assert(plane < drv_num_planes_from_format(format));
|
||||||
uint32_t vertical_subsampling;
|
uint32_t vertical_subsampling;
|
||||||
|
|
|
||||||
97
drv.h
97
drv.h
|
|
@ -16,6 +16,7 @@ extern "C" {
|
||||||
|
|
||||||
#define DRV_MAX_PLANES 4
|
#define DRV_MAX_PLANES 4
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
/* Use flags */
|
/* Use flags */
|
||||||
#define BO_USE_NONE 0
|
#define BO_USE_NONE 0
|
||||||
#define BO_USE_SCANOUT (1ull << 0)
|
#define BO_USE_SCANOUT (1ull << 0)
|
||||||
|
|
@ -52,6 +53,7 @@ extern "C" {
|
||||||
BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
|
BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
|
||||||
BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | \
|
BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | \
|
||||||
BO_USE_TEXTURE
|
BO_USE_TEXTURE
|
||||||
|
// clang-format on
|
||||||
struct driver;
|
struct driver;
|
||||||
struct bo;
|
struct bo;
|
||||||
struct combination;
|
struct combination;
|
||||||
|
|
@ -83,97 +85,64 @@ struct map_info {
|
||||||
void *priv;
|
void *priv;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct driver *
|
struct driver *drv_create(int fd);
|
||||||
drv_create(int fd);
|
|
||||||
|
|
||||||
void
|
void drv_destroy(struct driver *drv);
|
||||||
drv_destroy(struct driver *drv);
|
|
||||||
|
|
||||||
int
|
int drv_get_fd(struct driver *drv);
|
||||||
drv_get_fd(struct driver *drv);
|
|
||||||
|
|
||||||
const char *
|
const char *drv_get_name(struct driver *drv);
|
||||||
drv_get_name(struct driver *drv);
|
|
||||||
|
|
||||||
struct combination *
|
struct combination *drv_get_combination(struct driver *drv, uint32_t format, uint64_t usage);
|
||||||
drv_get_combination(struct driver *drv, uint32_t format, uint64_t usage);
|
|
||||||
|
|
||||||
struct bo *
|
struct bo *drv_bo_new(struct driver *drv, uint32_t width, uint32_t height, uint32_t format);
|
||||||
drv_bo_new(struct driver *drv, uint32_t width, uint32_t height,
|
|
||||||
uint32_t format);
|
|
||||||
|
|
||||||
struct bo *
|
struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, uint32_t format,
|
||||||
drv_bo_create(struct driver *drv, uint32_t width, uint32_t height,
|
uint64_t flags);
|
||||||
uint32_t format, uint64_t flags);
|
|
||||||
|
|
||||||
struct bo *
|
struct bo *drv_bo_create_with_modifiers(struct driver *drv, uint32_t width, uint32_t height,
|
||||||
drv_bo_create_with_modifiers(struct driver *drv,
|
uint32_t format, const uint64_t *modifiers, uint32_t count);
|
||||||
uint32_t width, uint32_t height,
|
|
||||||
uint32_t format,
|
|
||||||
const uint64_t *modifiers, uint32_t count);
|
|
||||||
|
|
||||||
void
|
void drv_bo_destroy(struct bo *bo);
|
||||||
drv_bo_destroy(struct bo *bo);
|
|
||||||
|
|
||||||
struct bo *
|
struct bo *drv_bo_import(struct driver *drv, struct drv_import_fd_data *data);
|
||||||
drv_bo_import(struct driver *drv, struct drv_import_fd_data *data);
|
|
||||||
|
|
||||||
void *
|
void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
|
||||||
drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width,
|
uint32_t flags, struct map_info **map_data, size_t plane);
|
||||||
uint32_t height, uint32_t flags, struct map_info **map_data,
|
|
||||||
size_t plane);
|
|
||||||
|
|
||||||
int
|
int drv_bo_unmap(struct bo *bo, struct map_info *map_data);
|
||||||
drv_bo_unmap(struct bo *bo, struct map_info *map_data);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_bo_get_width(struct bo *bo);
|
||||||
drv_bo_get_width(struct bo *bo);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_bo_get_height(struct bo *bo);
|
||||||
drv_bo_get_height(struct bo *bo);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_bo_get_stride_or_tiling(struct bo *bo);
|
||||||
drv_bo_get_stride_or_tiling(struct bo *bo);
|
|
||||||
|
|
||||||
size_t
|
size_t drv_bo_get_num_planes(struct bo *bo);
|
||||||
drv_bo_get_num_planes(struct bo *bo);
|
|
||||||
|
|
||||||
union bo_handle
|
union bo_handle drv_bo_get_plane_handle(struct bo *bo, size_t plane);
|
||||||
drv_bo_get_plane_handle(struct bo *bo, size_t plane);
|
|
||||||
|
|
||||||
int
|
int drv_bo_get_plane_fd(struct bo *bo, size_t plane);
|
||||||
drv_bo_get_plane_fd(struct bo *bo, size_t plane);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_bo_get_plane_offset(struct bo *bo, size_t plane);
|
||||||
drv_bo_get_plane_offset(struct bo *bo, size_t plane);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_bo_get_plane_size(struct bo *bo, size_t plane);
|
||||||
drv_bo_get_plane_size(struct bo *bo, size_t plane);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_bo_get_plane_stride(struct bo *bo, size_t plane);
|
||||||
drv_bo_get_plane_stride(struct bo *bo, size_t plane);
|
|
||||||
|
|
||||||
uint64_t
|
uint64_t drv_bo_get_plane_format_modifier(struct bo *bo, size_t plane);
|
||||||
drv_bo_get_plane_format_modifier(struct bo *bo, size_t plane);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_bo_get_format(struct bo *bo);
|
||||||
drv_bo_get_format(struct bo *bo);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_bo_get_stride_in_pixels(struct bo *bo);
|
||||||
drv_bo_get_stride_in_pixels(struct bo *bo);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_resolve_format(struct driver *drv, uint32_t format);
|
||||||
drv_resolve_format(struct driver *drv, uint32_t format);
|
|
||||||
|
|
||||||
size_t
|
size_t drv_num_planes_from_format(uint32_t format);
|
||||||
drv_num_planes_from_format(uint32_t format);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height, size_t plane);
|
||||||
drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height,
|
|
||||||
size_t plane);
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t drv_num_buffers_per_bo(struct bo *bo);
|
||||||
drv_num_buffers_per_bo(struct bo *bo);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
drv_priv.h
19
drv_priv.h
|
|
@ -14,8 +14,7 @@
|
||||||
|
|
||||||
#include "drv.h"
|
#include "drv.h"
|
||||||
|
|
||||||
struct bo
|
struct bo {
|
||||||
{
|
|
||||||
struct driver *drv;
|
struct driver *drv;
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
|
|
@ -64,21 +63,17 @@ struct combinations {
|
||||||
uint32_t allocations;
|
uint32_t allocations;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct backend
|
struct backend {
|
||||||
{
|
|
||||||
char *name;
|
char *name;
|
||||||
int (*init)(struct driver *drv);
|
int (*init)(struct driver *drv);
|
||||||
void (*close)(struct driver *drv);
|
void (*close)(struct driver *drv);
|
||||||
int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height,
|
int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t flags);
|
uint32_t flags);
|
||||||
int (*bo_create_with_modifiers)(struct bo *bo,
|
int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
uint32_t width, uint32_t height,
|
uint32_t format, const uint64_t *modifiers, uint32_t count);
|
||||||
uint32_t format,
|
|
||||||
const uint64_t *modifiers,
|
|
||||||
uint32_t count);
|
|
||||||
int (*bo_destroy)(struct bo *bo);
|
int (*bo_destroy)(struct bo *bo);
|
||||||
int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
|
int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
|
||||||
void* (*bo_map)(struct bo *bo, struct map_info *data, size_t plane);
|
void *(*bo_map)(struct bo *bo, struct map_info *data, size_t plane);
|
||||||
int (*bo_unmap)(struct bo *bo, struct map_info *data);
|
int (*bo_unmap)(struct bo *bo, struct map_info *data);
|
||||||
uint32_t (*resolve_format)(uint32_t format);
|
uint32_t (*resolve_format)(uint32_t format);
|
||||||
struct combinations combos;
|
struct combinations combos;
|
||||||
|
|
|
||||||
11
evdi.c
11
evdi.c
|
|
@ -8,18 +8,14 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
|
|
||||||
};
|
|
||||||
|
|
||||||
static int evdi_init(struct driver *drv)
|
static int evdi_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_evdi =
|
struct backend backend_evdi = {
|
||||||
{
|
|
||||||
.name = "evdi",
|
.name = "evdi",
|
||||||
.init = evdi_init,
|
.init = evdi_init,
|
||||||
.bo_create = drv_dumb_bo_create,
|
.bo_create = drv_dumb_bo_create,
|
||||||
|
|
@ -27,4 +23,3 @@ struct backend backend_evdi =
|
||||||
.bo_import = drv_prime_bo_import,
|
.bo_import = drv_prime_bo_import,
|
||||||
.bo_map = drv_dumb_bo_map,
|
.bo_map = drv_dumb_bo_map,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
29
exynos.c
29
exynos.c
|
|
@ -6,29 +6,29 @@
|
||||||
|
|
||||||
#ifdef DRV_EXYNOS
|
#ifdef DRV_EXYNOS
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
#include <exynos_drm.h>
|
#include <exynos_drm.h>
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
#include "drv_priv.h"
|
#include "drv_priv.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_NV12,
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_NV12, DRM_FORMAT_XRGB8888
|
DRM_FORMAT_XRGB8888 };
|
||||||
};
|
|
||||||
|
|
||||||
static int exynos_init(struct driver *drv)
|
static int exynos_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
size_t plane;
|
size_t plane;
|
||||||
|
|
||||||
|
|
@ -66,7 +66,8 @@ static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_EXYNOS_GEM_CREATE, &gem_create);
|
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_EXYNOS_GEM_CREATE, &gem_create);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "drv: DRM_IOCTL_EXYNOS_GEM_CREATE failed "
|
fprintf(stderr, "drv: DRM_IOCTL_EXYNOS_GEM_CREATE failed "
|
||||||
"(size=%zu)\n", size);
|
"(size=%zu)\n",
|
||||||
|
size);
|
||||||
goto cleanup_planes;
|
goto cleanup_planes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,16 +77,13 @@ static int exynos_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cleanup_planes:
|
cleanup_planes:
|
||||||
for ( ; plane != 0; plane--) {
|
for (; plane != 0; plane--) {
|
||||||
struct drm_gem_close gem_close;
|
struct drm_gem_close gem_close;
|
||||||
memset(&gem_close, 0, sizeof(gem_close));
|
memset(&gem_close, 0, sizeof(gem_close));
|
||||||
gem_close.handle = bo->handles[plane - 1].u32;
|
gem_close.handle = bo->handles[plane - 1].u32;
|
||||||
int gem_close_ret = drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE,
|
int gem_close_ret = drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
|
||||||
&gem_close);
|
|
||||||
if (gem_close_ret) {
|
if (gem_close_ret) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, "drv: DRM_IOCTL_GEM_CLOSE failed: %d\n", gem_close_ret);
|
||||||
"drv: DRM_IOCTL_GEM_CLOSE failed: %d\n",
|
|
||||||
gem_close_ret);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,8 +94,7 @@ cleanup_planes:
|
||||||
* Use dumb mapping with exynos even though a GEM buffer is created.
|
* Use dumb mapping with exynos even though a GEM buffer is created.
|
||||||
* libdrm does the same thing in exynos_drm.c
|
* libdrm does the same thing in exynos_drm.c
|
||||||
*/
|
*/
|
||||||
struct backend backend_exynos =
|
struct backend backend_exynos = {
|
||||||
{
|
|
||||||
.name = "exynos",
|
.name = "exynos",
|
||||||
.init = exynos_init,
|
.init = exynos_init,
|
||||||
.bo_create = exynos_bo_create,
|
.bo_create = exynos_bo_create,
|
||||||
|
|
|
||||||
134
gbm.c
134
gbm.c
|
|
@ -13,31 +13,26 @@
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
|
|
||||||
#include "drv.h"
|
#include "drv.h"
|
||||||
#include "gbm_priv.h"
|
|
||||||
#include "gbm_helpers.h"
|
#include "gbm_helpers.h"
|
||||||
|
#include "gbm_priv.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
PUBLIC int
|
PUBLIC int gbm_device_get_fd(struct gbm_device *gbm)
|
||||||
gbm_device_get_fd(struct gbm_device *gbm)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
return drv_get_fd(gbm->drv);
|
return drv_get_fd(gbm->drv);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC const char *
|
PUBLIC const char *gbm_device_get_backend_name(struct gbm_device *gbm)
|
||||||
gbm_device_get_backend_name(struct gbm_device *gbm)
|
|
||||||
{
|
{
|
||||||
return drv_get_name(gbm->drv);
|
return drv_get_name(gbm->drv);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC int
|
PUBLIC int gbm_device_is_format_supported(struct gbm_device *gbm, uint32_t format, uint32_t usage)
|
||||||
gbm_device_is_format_supported(struct gbm_device *gbm,
|
|
||||||
uint32_t format, uint32_t usage)
|
|
||||||
{
|
{
|
||||||
uint64_t drv_usage;
|
uint64_t drv_usage;
|
||||||
|
|
||||||
if (usage & GBM_BO_USE_CURSOR &&
|
if (usage & GBM_BO_USE_CURSOR && usage & GBM_BO_USE_RENDERING)
|
||||||
usage & GBM_BO_USE_RENDERING)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
drv_usage = gbm_convert_flags(usage);
|
drv_usage = gbm_convert_flags(usage);
|
||||||
|
|
@ -49,7 +44,7 @@ PUBLIC struct gbm_device *gbm_create_device(int fd)
|
||||||
{
|
{
|
||||||
struct gbm_device *gbm;
|
struct gbm_device *gbm;
|
||||||
|
|
||||||
gbm = (struct gbm_device*) malloc(sizeof(*gbm));
|
gbm = (struct gbm_device *)malloc(sizeof(*gbm));
|
||||||
|
|
||||||
if (!gbm)
|
if (!gbm)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -69,12 +64,10 @@ PUBLIC void gbm_device_destroy(struct gbm_device *gbm)
|
||||||
free(gbm);
|
free(gbm);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC struct gbm_surface *gbm_surface_create(struct gbm_device *gbm,
|
PUBLIC struct gbm_surface *gbm_surface_create(struct gbm_device *gbm, uint32_t width,
|
||||||
uint32_t width, uint32_t height,
|
uint32_t height, uint32_t format, uint32_t flags)
|
||||||
uint32_t format, uint32_t flags)
|
|
||||||
{
|
{
|
||||||
struct gbm_surface *surface =
|
struct gbm_surface *surface = (struct gbm_surface *)malloc(sizeof(*surface));
|
||||||
(struct gbm_surface*) malloc(sizeof(*surface));
|
|
||||||
|
|
||||||
if (!surface)
|
if (!surface)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -92,8 +85,7 @@ PUBLIC struct gbm_bo *gbm_surface_lock_front_buffer(struct gbm_surface *surface)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC void gbm_surface_release_buffer(struct gbm_surface *surface,
|
PUBLIC void gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_bo *bo)
|
||||||
struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +93,7 @@ static struct gbm_bo *gbm_bo_new(struct gbm_device *gbm, uint32_t format)
|
||||||
{
|
{
|
||||||
struct gbm_bo *bo;
|
struct gbm_bo *bo;
|
||||||
|
|
||||||
bo = (struct gbm_bo*) calloc(1, sizeof(*bo));
|
bo = (struct gbm_bo *)calloc(1, sizeof(*bo));
|
||||||
if (!bo)
|
if (!bo)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
@ -111,9 +103,8 @@ static struct gbm_bo *gbm_bo_new(struct gbm_device *gbm, uint32_t format)
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width,
|
PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width, uint32_t height,
|
||||||
uint32_t height, uint32_t format,
|
uint32_t format, uint32_t flags)
|
||||||
uint32_t flags)
|
|
||||||
{
|
{
|
||||||
struct gbm_bo *bo;
|
struct gbm_bo *bo;
|
||||||
|
|
||||||
|
|
@ -125,8 +116,7 @@ PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width,
|
||||||
if (!bo)
|
if (!bo)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
bo->bo = drv_bo_create(gbm->drv, width, height, format,
|
bo->bo = drv_bo_create(gbm->drv, width, height, format, gbm_convert_flags(flags));
|
||||||
gbm_convert_flags(flags));
|
|
||||||
|
|
||||||
if (!bo->bo) {
|
if (!bo->bo) {
|
||||||
free(bo);
|
free(bo);
|
||||||
|
|
@ -136,12 +126,9 @@ PUBLIC struct gbm_bo *gbm_bo_create(struct gbm_device *gbm, uint32_t width,
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC struct gbm_bo *gbm_bo_create_with_modifiers(struct gbm_device *gbm,
|
PUBLIC struct gbm_bo *gbm_bo_create_with_modifiers(struct gbm_device *gbm, uint32_t width,
|
||||||
uint32_t width,
|
uint32_t height, uint32_t format,
|
||||||
uint32_t height,
|
const uint64_t *modifiers, uint32_t count)
|
||||||
uint32_t format,
|
|
||||||
const uint64_t *modifiers,
|
|
||||||
uint32_t count)
|
|
||||||
{
|
{
|
||||||
struct gbm_bo *bo;
|
struct gbm_bo *bo;
|
||||||
|
|
||||||
|
|
@ -150,9 +137,7 @@ PUBLIC struct gbm_bo *gbm_bo_create_with_modifiers(struct gbm_device *gbm,
|
||||||
if (!bo)
|
if (!bo)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
bo->bo = drv_bo_create_with_modifiers(gbm->drv,
|
bo->bo = drv_bo_create_with_modifiers(gbm->drv, width, height, format, modifiers, count);
|
||||||
width, height, format,
|
|
||||||
modifiers, count);
|
|
||||||
|
|
||||||
if (!bo->bo) {
|
if (!bo->bo) {
|
||||||
free(bo);
|
free(bo);
|
||||||
|
|
@ -174,9 +159,8 @@ PUBLIC void gbm_bo_destroy(struct gbm_bo *bo)
|
||||||
free(bo);
|
free(bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC struct gbm_bo *
|
PUBLIC struct gbm_bo *gbm_bo_import(struct gbm_device *gbm, uint32_t type, void *buffer,
|
||||||
gbm_bo_import(struct gbm_device *gbm, uint32_t type,
|
uint32_t usage)
|
||||||
void *buffer, uint32_t usage)
|
|
||||||
{
|
{
|
||||||
struct gbm_bo *bo;
|
struct gbm_bo *bo;
|
||||||
struct drv_import_fd_data drv_data;
|
struct drv_import_fd_data drv_data;
|
||||||
|
|
@ -210,14 +194,10 @@ gbm_bo_import(struct gbm_device *gbm, uint32_t type,
|
||||||
drv_data.fds[i] = fd_planar_data->fds[i];
|
drv_data.fds[i] = fd_planar_data->fds[i];
|
||||||
drv_data.offsets[i] = fd_planar_data->offsets[i];
|
drv_data.offsets[i] = fd_planar_data->offsets[i];
|
||||||
drv_data.strides[i] = fd_planar_data->strides[i];
|
drv_data.strides[i] = fd_planar_data->strides[i];
|
||||||
drv_data.format_modifiers[i] =
|
drv_data.format_modifiers[i] = fd_planar_data->format_modifiers[i];
|
||||||
fd_planar_data->format_modifiers[i];
|
|
||||||
|
|
||||||
drv_data.sizes[i] = drv_size_from_format(
|
drv_data.sizes[i] = drv_size_from_format(
|
||||||
drv_data.format,
|
drv_data.format, drv_data.strides[i], drv_data.height, i);
|
||||||
drv_data.strides[i],
|
|
||||||
drv_data.height,
|
|
||||||
i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = num_planes; i < GBM_MAX_PLANES; i++)
|
for (i = num_planes; i < GBM_MAX_PLANES; i++)
|
||||||
|
|
@ -246,132 +226,110 @@ gbm_bo_import(struct gbm_device *gbm, uint32_t type,
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC void *
|
PUBLIC void *gbm_bo_map(struct gbm_bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
|
||||||
gbm_bo_map(struct gbm_bo *bo, uint32_t x, uint32_t y, uint32_t width,
|
uint32_t flags, uint32_t *stride, void **map_data, size_t plane)
|
||||||
uint32_t height, uint32_t flags, uint32_t *stride, void **map_data,
|
|
||||||
size_t plane)
|
|
||||||
{
|
{
|
||||||
if (!bo || width == 0 || height == 0 || !stride || !map_data)
|
if (!bo || width == 0 || height == 0 || !stride || !map_data)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*stride = gbm_bo_get_plane_stride(bo, plane);
|
*stride = gbm_bo_get_plane_stride(bo, plane);
|
||||||
return drv_bo_map(bo->bo, x, y, width, height, 0,
|
return drv_bo_map(bo->bo, x, y, width, height, 0, (struct map_info **)map_data, plane);
|
||||||
(struct map_info**)map_data, plane);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC void
|
PUBLIC void gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
|
||||||
gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
|
|
||||||
{
|
{
|
||||||
assert(bo);
|
assert(bo);
|
||||||
drv_bo_unmap(bo->bo, map_data);
|
drv_bo_unmap(bo->bo, map_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint32_t
|
PUBLIC uint32_t gbm_bo_get_width(struct gbm_bo *bo)
|
||||||
gbm_bo_get_width(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return drv_bo_get_width(bo->bo);
|
return drv_bo_get_width(bo->bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint32_t
|
PUBLIC uint32_t gbm_bo_get_height(struct gbm_bo *bo)
|
||||||
gbm_bo_get_height(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return drv_bo_get_height(bo->bo);
|
return drv_bo_get_height(bo->bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint32_t
|
PUBLIC uint32_t gbm_bo_get_stride(struct gbm_bo *bo)
|
||||||
gbm_bo_get_stride(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return gbm_bo_get_plane_stride(bo, 0);
|
return gbm_bo_get_plane_stride(bo, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint32_t
|
PUBLIC uint32_t gbm_bo_get_stride_or_tiling(struct gbm_bo *bo)
|
||||||
gbm_bo_get_stride_or_tiling(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return drv_bo_get_stride_or_tiling(bo->bo);
|
return drv_bo_get_stride_or_tiling(bo->bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint32_t
|
PUBLIC uint32_t gbm_bo_get_format(struct gbm_bo *bo)
|
||||||
gbm_bo_get_format(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return bo->gbm_format;
|
return bo->gbm_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint64_t
|
PUBLIC uint64_t gbm_bo_get_format_modifier(struct gbm_bo *bo)
|
||||||
gbm_bo_get_format_modifier(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return gbm_bo_get_plane_format_modifier(bo, 0);
|
return gbm_bo_get_plane_format_modifier(bo, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC struct gbm_device *
|
PUBLIC struct gbm_device *gbm_bo_get_device(struct gbm_bo *bo)
|
||||||
gbm_bo_get_device(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return bo->gbm;
|
return bo->gbm;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC union gbm_bo_handle
|
PUBLIC union gbm_bo_handle gbm_bo_get_handle(struct gbm_bo *bo)
|
||||||
gbm_bo_get_handle(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return gbm_bo_get_plane_handle(bo, 0);
|
return gbm_bo_get_plane_handle(bo, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC int
|
PUBLIC int gbm_bo_get_fd(struct gbm_bo *bo)
|
||||||
gbm_bo_get_fd(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return gbm_bo_get_plane_fd(bo, 0);
|
return gbm_bo_get_plane_fd(bo, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC size_t
|
PUBLIC size_t gbm_bo_get_num_planes(struct gbm_bo *bo)
|
||||||
gbm_bo_get_num_planes(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return drv_bo_get_num_planes(bo->bo);
|
return drv_bo_get_num_planes(bo->bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC union gbm_bo_handle
|
PUBLIC union gbm_bo_handle gbm_bo_get_plane_handle(struct gbm_bo *bo, size_t plane)
|
||||||
gbm_bo_get_plane_handle(struct gbm_bo *bo, size_t plane)
|
|
||||||
{
|
{
|
||||||
return (union gbm_bo_handle) drv_bo_get_plane_handle(bo->bo, plane).u64;
|
return (union gbm_bo_handle)drv_bo_get_plane_handle(bo->bo, plane).u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC int
|
PUBLIC int gbm_bo_get_plane_fd(struct gbm_bo *bo, size_t plane)
|
||||||
gbm_bo_get_plane_fd(struct gbm_bo *bo, size_t plane)
|
|
||||||
{
|
{
|
||||||
return drv_bo_get_plane_fd(bo->bo, plane);
|
return drv_bo_get_plane_fd(bo->bo, plane);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint32_t
|
PUBLIC uint32_t gbm_bo_get_plane_offset(struct gbm_bo *bo, size_t plane)
|
||||||
gbm_bo_get_plane_offset(struct gbm_bo *bo, size_t plane)
|
|
||||||
{
|
{
|
||||||
return drv_bo_get_plane_offset(bo->bo, plane);
|
return drv_bo_get_plane_offset(bo->bo, plane);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint32_t
|
PUBLIC uint32_t gbm_bo_get_plane_size(struct gbm_bo *bo, size_t plane)
|
||||||
gbm_bo_get_plane_size(struct gbm_bo *bo, size_t plane)
|
|
||||||
{
|
{
|
||||||
return drv_bo_get_plane_size(bo->bo, plane);
|
return drv_bo_get_plane_size(bo->bo, plane);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint32_t
|
PUBLIC uint32_t gbm_bo_get_plane_stride(struct gbm_bo *bo, size_t plane)
|
||||||
gbm_bo_get_plane_stride(struct gbm_bo *bo, size_t plane)
|
|
||||||
{
|
{
|
||||||
return drv_bo_get_plane_stride(bo->bo, plane);
|
return drv_bo_get_plane_stride(bo->bo, plane);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC uint64_t
|
PUBLIC uint64_t gbm_bo_get_plane_format_modifier(struct gbm_bo *bo, size_t plane)
|
||||||
gbm_bo_get_plane_format_modifier(struct gbm_bo *bo, size_t plane)
|
|
||||||
{
|
{
|
||||||
return drv_bo_get_plane_format_modifier(bo->bo, plane);
|
return drv_bo_get_plane_format_modifier(bo->bo, plane);
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC void
|
PUBLIC void gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
|
||||||
gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
|
void (*destroy_user_data)(struct gbm_bo *, void *))
|
||||||
void (*destroy_user_data)(struct gbm_bo *, void *))
|
|
||||||
{
|
{
|
||||||
bo->user_data = data;
|
bo->user_data = data;
|
||||||
bo->destroy_user_data = destroy_user_data;
|
bo->destroy_user_data = destroy_user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUBLIC void *
|
PUBLIC void *gbm_bo_get_user_data(struct gbm_bo *bo)
|
||||||
gbm_bo_get_user_data(struct gbm_bo *bo)
|
|
||||||
{
|
{
|
||||||
return bo->user_data;
|
return bo->user_data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
gbm_priv.h
11
gbm_priv.h
|
|
@ -8,23 +8,20 @@
|
||||||
#define GBM_PRIV_H
|
#define GBM_PRIV_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "drv.h"
|
#include "drv.h"
|
||||||
#include "gbm.h"
|
#include "gbm.h"
|
||||||
|
|
||||||
struct gbm_device
|
struct gbm_device {
|
||||||
{
|
|
||||||
struct driver *drv;
|
struct driver *drv;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gbm_surface
|
struct gbm_surface {
|
||||||
{
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gbm_bo
|
struct gbm_bo {
|
||||||
{
|
|
||||||
struct gbm_device *gbm;
|
struct gbm_device *gbm;
|
||||||
struct bo *bo;
|
struct bo *bo;
|
||||||
uint32_t gbm_format;
|
uint32_t gbm_format;
|
||||||
|
|
|
||||||
10
gma500.c
10
gma500.c
|
|
@ -8,18 +8,14 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_RGBX8888 };
|
||||||
DRM_FORMAT_RGBX8888
|
|
||||||
};
|
|
||||||
|
|
||||||
static int gma500_init(struct driver *drv)
|
static int gma500_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_gma500 =
|
struct backend backend_gma500 = {
|
||||||
{
|
|
||||||
.name = "gma500",
|
.name = "gma500",
|
||||||
.init = gma500_init,
|
.init = gma500_init,
|
||||||
.bo_create = drv_dumb_bo_create,
|
.bo_create = drv_dumb_bo_create,
|
||||||
|
|
|
||||||
97
helpers.c
97
helpers.c
|
|
@ -18,8 +18,8 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static uint32_t subsample_stride(uint32_t stride, uint32_t format,
|
static uint32_t subsample_stride(uint32_t stride, uint32_t format, size_t plane)
|
||||||
size_t plane) {
|
{
|
||||||
|
|
||||||
if (plane != 0) {
|
if (plane != 0) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
|
|
@ -105,8 +105,7 @@ static uint32_t bpp_from_format(uint32_t format, size_t plane)
|
||||||
|
|
||||||
uint32_t drv_bo_get_stride_in_pixels(struct bo *bo)
|
uint32_t drv_bo_get_stride_in_pixels(struct bo *bo)
|
||||||
{
|
{
|
||||||
uint32_t bytes_per_pixel = DIV_ROUND_UP(bpp_from_format(bo->format, 0),
|
uint32_t bytes_per_pixel = DIV_ROUND_UP(bpp_from_format(bo->format, 0), 8);
|
||||||
8);
|
|
||||||
return DIV_ROUND_UP(bo->strides[0], bytes_per_pixel);
|
return DIV_ROUND_UP(bo->strides[0], bytes_per_pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,15 +114,14 @@ uint32_t drv_bo_get_stride_in_pixels(struct bo *bo)
|
||||||
*/
|
*/
|
||||||
uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane)
|
uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane)
|
||||||
{
|
{
|
||||||
uint32_t stride = DIV_ROUND_UP(width * bpp_from_format(format, plane),
|
uint32_t stride = DIV_ROUND_UP(width * bpp_from_format(format, plane), 8);
|
||||||
8);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The stride of Android YV12 buffers is required to be aligned to 16 bytes
|
* The stride of Android YV12 buffers is required to be aligned to 16 bytes
|
||||||
* (see <system/graphics.h>).
|
* (see <system/graphics.h>).
|
||||||
*/
|
*/
|
||||||
if (format == DRM_FORMAT_YVU420_ANDROID)
|
if (format == DRM_FORMAT_YVU420_ANDROID)
|
||||||
stride = (plane == 0) ? ALIGN(stride, 32): ALIGN(stride, 16);
|
stride = (plane == 0) ? ALIGN(stride, 32) : ALIGN(stride, 16);
|
||||||
|
|
||||||
return stride;
|
return stride;
|
||||||
}
|
}
|
||||||
|
|
@ -133,8 +131,7 @@ uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane)
|
||||||
* the first plane, height and a format. This function assumes there is just
|
* the first plane, height and a format. This function assumes there is just
|
||||||
* one kernel buffer per buffer object.
|
* one kernel buffer per buffer object.
|
||||||
*/
|
*/
|
||||||
int drv_bo_from_format(struct bo *bo, uint32_t stride,
|
int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height, uint32_t format)
|
||||||
uint32_t aligned_height, uint32_t format)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
size_t p, num_planes;
|
size_t p, num_planes;
|
||||||
|
|
@ -146,19 +143,17 @@ int drv_bo_from_format(struct bo *bo, uint32_t stride,
|
||||||
|
|
||||||
for (p = 0; p < num_planes; p++) {
|
for (p = 0; p < num_planes; p++) {
|
||||||
bo->strides[p] = subsample_stride(stride, format, p);
|
bo->strides[p] = subsample_stride(stride, format, p);
|
||||||
bo->sizes[p] = drv_size_from_format(format, bo->strides[p],
|
bo->sizes[p] = drv_size_from_format(format, bo->strides[p], bo->height, p);
|
||||||
bo->height, p);
|
|
||||||
bo->offsets[p] = offset;
|
bo->offsets[p] = offset;
|
||||||
offset += bo->sizes[p];
|
offset += bo->sizes[p];
|
||||||
bo->total_size += drv_size_from_format(format, bo->strides[p],
|
bo->total_size += drv_size_from_format(format, bo->strides[p], aligned_height, p);
|
||||||
aligned_height, p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t plane;
|
size_t plane;
|
||||||
|
|
@ -208,7 +203,8 @@ int drv_dumb_bo_destroy(struct bo *bo)
|
||||||
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
|
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "drv: DRM_IOCTL_MODE_DESTROY_DUMB failed "
|
fprintf(stderr, "drv: DRM_IOCTL_MODE_DESTROY_DUMB failed "
|
||||||
"(handle=%x)\n", bo->handles[0].u32);
|
"(handle=%x)\n",
|
||||||
|
bo->handles[0].u32);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,7 +232,7 @@ int drv_gem_bo_destroy(struct bo *bo)
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "drv: DRM_IOCTL_GEM_CLOSE failed "
|
fprintf(stderr, "drv: DRM_IOCTL_GEM_CLOSE failed "
|
||||||
"(handle=%x) error %d\n",
|
"(handle=%x) error %d\n",
|
||||||
bo->handles[plane].u32, ret);
|
bo->handles[plane].u32, ret);
|
||||||
error = ret;
|
error = ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -254,12 +250,12 @@ int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data)
|
||||||
memset(&prime_handle, 0, sizeof(prime_handle));
|
memset(&prime_handle, 0, sizeof(prime_handle));
|
||||||
prime_handle.fd = data->fds[plane];
|
prime_handle.fd = data->fds[plane];
|
||||||
|
|
||||||
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE,
|
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &prime_handle);
|
||||||
&prime_handle);
|
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "drv: DRM_IOCTL_PRIME_FD_TO_HANDLE "
|
fprintf(stderr, "drv: DRM_IOCTL_PRIME_FD_TO_HANDLE "
|
||||||
"failed (fd=%u)\n", prime_handle.fd);
|
"failed (fd=%u)\n",
|
||||||
|
prime_handle.fd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Need to call GEM close on planes that were opened,
|
* Need to call GEM close on planes that were opened,
|
||||||
|
|
@ -303,43 +299,38 @@ void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
||||||
if (bo->handles[i].u32 == bo->handles[plane].u32)
|
if (bo->handles[i].u32 == bo->handles[plane].u32)
|
||||||
data->length += bo->sizes[i];
|
data->length += bo->sizes[i];
|
||||||
|
|
||||||
return mmap(0, data->length, PROT_READ | PROT_WRITE, MAP_SHARED,
|
return mmap(0, data->length, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
|
||||||
bo->drv->fd, map_dumb.offset);
|
map_dumb.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo,
|
uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo, size_t plane)
|
||||||
size_t plane)
|
|
||||||
{
|
{
|
||||||
void *count;
|
void *count;
|
||||||
uintptr_t num = 0;
|
uintptr_t num = 0;
|
||||||
|
|
||||||
if (!drmHashLookup(drv->buffer_table, bo->handles[plane].u32, &count))
|
if (!drmHashLookup(drv->buffer_table, bo->handles[plane].u32, &count))
|
||||||
num = (uintptr_t) (count);
|
num = (uintptr_t)(count);
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drv_increment_reference_count(struct driver *drv, struct bo *bo,
|
void drv_increment_reference_count(struct driver *drv, struct bo *bo, size_t plane)
|
||||||
size_t plane)
|
|
||||||
{
|
{
|
||||||
uintptr_t num = drv_get_reference_count(drv, bo, plane);
|
uintptr_t num = drv_get_reference_count(drv, bo, plane);
|
||||||
|
|
||||||
/* If a value isn't in the table, drmHashDelete is a no-op */
|
/* If a value isn't in the table, drmHashDelete is a no-op */
|
||||||
drmHashDelete(drv->buffer_table, bo->handles[plane].u32);
|
drmHashDelete(drv->buffer_table, bo->handles[plane].u32);
|
||||||
drmHashInsert(drv->buffer_table, bo->handles[plane].u32,
|
drmHashInsert(drv->buffer_table, bo->handles[plane].u32, (void *)(num + 1));
|
||||||
(void *) (num + 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drv_decrement_reference_count(struct driver *drv, struct bo *bo,
|
void drv_decrement_reference_count(struct driver *drv, struct bo *bo, size_t plane)
|
||||||
size_t plane)
|
|
||||||
{
|
{
|
||||||
uintptr_t num = drv_get_reference_count(drv, bo, plane);
|
uintptr_t num = drv_get_reference_count(drv, bo, plane);
|
||||||
|
|
||||||
drmHashDelete(drv->buffer_table, bo->handles[plane].u32);
|
drmHashDelete(drv->buffer_table, bo->handles[plane].u32);
|
||||||
|
|
||||||
if (num > 0)
|
if (num > 0)
|
||||||
drmHashInsert(drv->buffer_table, bo->handles[plane].u32,
|
drmHashInsert(drv->buffer_table, bo->handles[plane].u32, (void *)(num - 1));
|
||||||
(void *) (num - 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t drv_log_base2(uint32_t value)
|
uint32_t drv_log_base2(uint32_t value)
|
||||||
|
|
@ -352,15 +343,14 @@ uint32_t drv_log_base2(uint32_t value)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int drv_add_combination(struct driver *drv, uint32_t format,
|
int drv_add_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
|
||||||
struct format_metadata *metadata, uint64_t usage)
|
uint64_t usage)
|
||||||
{
|
{
|
||||||
struct combinations *combos = &drv->backend->combos;
|
struct combinations *combos = &drv->backend->combos;
|
||||||
if (combos->size >= combos->allocations) {
|
if (combos->size >= combos->allocations) {
|
||||||
struct combination *new_data;
|
struct combination *new_data;
|
||||||
combos->allocations *= 2;
|
combos->allocations *= 2;
|
||||||
new_data = realloc(combos->data, combos->allocations
|
new_data = realloc(combos->data, combos->allocations * sizeof(*combos->data));
|
||||||
* sizeof(*combos->data));
|
|
||||||
if (!new_data)
|
if (!new_data)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
|
@ -376,9 +366,8 @@ int drv_add_combination(struct driver *drv, uint32_t format,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int drv_add_combinations(struct driver *drv, const uint32_t *formats,
|
int drv_add_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats,
|
||||||
uint32_t num_formats, struct format_metadata *metadata,
|
struct format_metadata *metadata, uint64_t usage)
|
||||||
uint64_t usage)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
@ -391,16 +380,15 @@ int drv_add_combinations(struct driver *drv, const uint32_t *formats,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drv_modify_combination(struct driver *drv, uint32_t format,
|
void drv_modify_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
|
||||||
struct format_metadata *metadata, uint64_t usage)
|
uint64_t usage)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
struct combination *combo;
|
struct combination *combo;
|
||||||
/* Attempts to add the specified usage to an existing combination. */
|
/* Attempts to add the specified usage to an existing combination. */
|
||||||
for (i = 0; i < drv->backend->combos.size; i++) {
|
for (i = 0; i < drv->backend->combos.size; i++) {
|
||||||
combo = &drv->backend->combos.data[i];
|
combo = &drv->backend->combos.data[i];
|
||||||
if (combo->format == format &&
|
if (combo->format == format && combo->metadata.tiling == metadata->tiling &&
|
||||||
combo->metadata.tiling == metadata->tiling &&
|
|
||||||
combo->metadata.modifier == metadata->modifier)
|
combo->metadata.modifier == metadata->modifier)
|
||||||
combo->usage |= usage;
|
combo->usage |= usage;
|
||||||
}
|
}
|
||||||
|
|
@ -443,8 +431,7 @@ struct kms_item *drv_query_kms(struct driver *drv, uint32_t *num_items)
|
||||||
if (!plane)
|
if (!plane)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
props = drmModeObjectGetProperties(drv->fd, plane->plane_id,
|
props = drmModeObjectGetProperties(drv->fd, plane->plane_id, DRM_MODE_OBJECT_PLANE);
|
||||||
DRM_MODE_OBJECT_PLANE);
|
|
||||||
if (!props)
|
if (!props)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -485,8 +472,7 @@ struct kms_item *drv_query_kms(struct driver *drv, uint32_t *num_items)
|
||||||
if (!found && item_size >= allocations) {
|
if (!found && item_size >= allocations) {
|
||||||
struct kms_item *new_data = NULL;
|
struct kms_item *new_data = NULL;
|
||||||
allocations *= 2;
|
allocations *= 2;
|
||||||
new_data = realloc(items, allocations *
|
new_data = realloc(items, allocations * sizeof(*items));
|
||||||
sizeof(*items));
|
|
||||||
if (!new_data) {
|
if (!new_data) {
|
||||||
item_size = 0;
|
item_size = 0;
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -505,7 +491,6 @@ struct kms_item *drv_query_kms(struct driver *drv, uint32_t *num_items)
|
||||||
|
|
||||||
drmModeFreeObjectProperties(props);
|
drmModeFreeObjectProperties(props);
|
||||||
drmModeFreePlane(plane);
|
drmModeFreePlane(plane);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drmModeFreePlaneResources(resources);
|
drmModeFreePlaneResources(resources);
|
||||||
|
|
@ -519,8 +504,7 @@ out:
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
|
int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats)
|
||||||
uint32_t num_formats)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint32_t i, j, num_items;
|
uint32_t i, j, num_items;
|
||||||
|
|
@ -532,8 +516,7 @@ int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
|
||||||
metadata.priority = 1;
|
metadata.priority = 1;
|
||||||
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, formats, num_formats, &metadata,
|
ret = drv_add_combinations(drv, formats, num_formats, &metadata, BO_COMMON_USE_MASK);
|
||||||
BO_COMMON_USE_MASK);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
/*
|
/*
|
||||||
|
|
@ -543,10 +526,8 @@ int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
|
||||||
* kernel disregards the alpha component of ARGB unless it's an overlay
|
* kernel disregards the alpha component of ARGB unless it's an overlay
|
||||||
* plane.
|
* plane.
|
||||||
*/
|
*/
|
||||||
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
|
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
|
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
|
||||||
|
|
||||||
items = drv_query_kms(drv, &num_items);
|
items = drv_query_kms(drv, &num_items);
|
||||||
if (!items || !num_items)
|
if (!items || !num_items)
|
||||||
|
|
@ -557,8 +538,6 @@ int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
|
||||||
combo = &drv->backend->combos.data[j];
|
combo = &drv->backend->combos.data[j];
|
||||||
if (items[i].format == combo->format)
|
if (items[i].format == combo->format)
|
||||||
combo->usage |= BO_USE_SCANOUT;
|
combo->usage |= BO_USE_SCANOUT;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
32
helpers.h
32
helpers.h
|
|
@ -10,29 +10,23 @@
|
||||||
#include "drv.h"
|
#include "drv.h"
|
||||||
|
|
||||||
uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane);
|
uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane);
|
||||||
int drv_bo_from_format(struct bo *bo, uint32_t stride,
|
int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height, uint32_t format);
|
||||||
uint32_t aligned_height, uint32_t format);
|
int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
uint32_t flags);
|
||||||
uint32_t format, uint32_t flags);
|
|
||||||
int drv_dumb_bo_destroy(struct bo *bo);
|
int drv_dumb_bo_destroy(struct bo *bo);
|
||||||
int drv_gem_bo_destroy(struct bo *bo);
|
int drv_gem_bo_destroy(struct bo *bo);
|
||||||
int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data);
|
int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data);
|
||||||
void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane);
|
void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane);
|
||||||
uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo,
|
uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo, size_t plane);
|
||||||
size_t plane);
|
void drv_increment_reference_count(struct driver *drv, struct bo *bo, size_t plane);
|
||||||
void drv_increment_reference_count(struct driver *drv, struct bo *bo,
|
void drv_decrement_reference_count(struct driver *drv, struct bo *bo, size_t plane);
|
||||||
size_t plane);
|
|
||||||
void drv_decrement_reference_count(struct driver *drv, struct bo *bo,
|
|
||||||
size_t plane);
|
|
||||||
uint32_t drv_log_base2(uint32_t value);
|
uint32_t drv_log_base2(uint32_t value);
|
||||||
int drv_add_combination(struct driver *drv, uint32_t format,
|
int drv_add_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
|
||||||
struct format_metadata *metadata, uint64_t usage);
|
uint64_t usage);
|
||||||
int drv_add_combinations(struct driver *drv, const uint32_t *formats,
|
int drv_add_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats,
|
||||||
uint32_t num_formats, struct format_metadata *metadata,
|
struct format_metadata *metadata, uint64_t usage);
|
||||||
uint64_t usage);
|
void drv_modify_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
|
||||||
void drv_modify_combination(struct driver *drv, uint32_t format,
|
uint64_t usage);
|
||||||
struct format_metadata *metadata, uint64_t usage);
|
|
||||||
struct kms_item *drv_query_kms(struct driver *drv, uint32_t *num_items);
|
struct kms_item *drv_query_kms(struct driver *drv, uint32_t *num_items);
|
||||||
int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats,
|
int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats);
|
||||||
uint32_t num_formats);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
95
i915.c
95
i915.c
|
|
@ -17,35 +17,31 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t tileable_formats[] = {
|
static const uint32_t tileable_formats[] = { DRM_FORMAT_ARGB1555, DRM_FORMAT_ABGR8888,
|
||||||
DRM_FORMAT_ARGB1555, DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
|
DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565,
|
||||||
DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB1555,
|
DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB1555,
|
||||||
DRM_FORMAT_XRGB8888, DRM_FORMAT_UYVY, DRM_FORMAT_YUYV
|
DRM_FORMAT_XRGB8888, DRM_FORMAT_UYVY,
|
||||||
};
|
DRM_FORMAT_YUYV };
|
||||||
|
|
||||||
static const uint32_t linear_only_formats[] = {
|
static const uint32_t linear_only_formats[] = { DRM_FORMAT_GR88, DRM_FORMAT_R8, DRM_FORMAT_YVU420,
|
||||||
DRM_FORMAT_GR88, DRM_FORMAT_R8, DRM_FORMAT_YVU420,
|
DRM_FORMAT_YVU420_ANDROID };
|
||||||
DRM_FORMAT_YVU420_ANDROID
|
|
||||||
};
|
|
||||||
|
|
||||||
struct i915_device
|
struct i915_device {
|
||||||
{
|
|
||||||
int gen;
|
int gen;
|
||||||
drm_intel_bufmgr *mgr;
|
drm_intel_bufmgr *mgr;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct i915_bo
|
struct i915_bo {
|
||||||
{
|
|
||||||
drm_intel_bo *ibos[DRV_MAX_PLANES];
|
drm_intel_bo *ibos[DRV_MAX_PLANES];
|
||||||
};
|
};
|
||||||
|
|
||||||
static int get_gen(int device_id)
|
static int get_gen(int device_id)
|
||||||
{
|
{
|
||||||
const uint16_t gen3_ids[] = {0x2582, 0x2592, 0x2772, 0x27A2, 0x27AE,
|
const uint16_t gen3_ids[] = { 0x2582, 0x2592, 0x2772, 0x27A2, 0x27AE,
|
||||||
0x29C2, 0x29B2, 0x29D2, 0xA001, 0xA011};
|
0x29C2, 0x29B2, 0x29D2, 0xA001, 0xA011 };
|
||||||
unsigned i;
|
unsigned i;
|
||||||
for(i = 0; i < ARRAY_SIZE(gen3_ids); i++)
|
for (i = 0; i < ARRAY_SIZE(gen3_ids); i++)
|
||||||
if (gen3_ids[i] == device_id)
|
if (gen3_ids[i] == device_id)
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
|
|
@ -65,9 +61,9 @@ static int i915_add_kms_item(struct driver *drv, const struct kms_item *item)
|
||||||
combo = &drv->backend->combos.data[i];
|
combo = &drv->backend->combos.data[i];
|
||||||
if (combo->format == item->format) {
|
if (combo->format == item->format) {
|
||||||
if ((combo->metadata.tiling == I915_TILING_Y &&
|
if ((combo->metadata.tiling == I915_TILING_Y &&
|
||||||
item->modifier == I915_FORMAT_MOD_Y_TILED) ||
|
item->modifier == I915_FORMAT_MOD_Y_TILED) ||
|
||||||
(combo->metadata.tiling == I915_TILING_X &&
|
(combo->metadata.tiling == I915_TILING_X &&
|
||||||
item->modifier == I915_FORMAT_MOD_X_TILED)) {
|
item->modifier == I915_FORMAT_MOD_X_TILED)) {
|
||||||
combo->metadata.modifier = item->modifier;
|
combo->metadata.modifier = item->modifier;
|
||||||
combo->usage |= item->usage;
|
combo->usage |= item->usage;
|
||||||
} else if (combo->metadata.tiling != I915_TILING_Y) {
|
} else if (combo->metadata.tiling != I915_TILING_Y) {
|
||||||
|
|
@ -91,22 +87,18 @@ static int i915_add_combinations(struct driver *drv)
|
||||||
metadata.priority = 1;
|
metadata.priority = 1;
|
||||||
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, linear_only_formats,
|
ret = drv_add_combinations(drv, linear_only_formats, ARRAY_SIZE(linear_only_formats),
|
||||||
ARRAY_SIZE(linear_only_formats), &metadata,
|
&metadata, flags);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = drv_add_combinations(drv, tileable_formats, ARRAY_SIZE(tileable_formats), &metadata,
|
||||||
flags);
|
flags);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, tileable_formats,
|
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
ARRAY_SIZE(tileable_formats), &metadata,
|
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
flags);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
|
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
|
||||||
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
|
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
|
||||||
|
|
||||||
flags &= ~BO_USE_SW_WRITE_OFTEN;
|
flags &= ~BO_USE_SW_WRITE_OFTEN;
|
||||||
flags &= ~BO_USE_SW_READ_OFTEN;
|
flags &= ~BO_USE_SW_READ_OFTEN;
|
||||||
|
|
@ -115,8 +107,7 @@ static int i915_add_combinations(struct driver *drv)
|
||||||
metadata.tiling = I915_TILING_X;
|
metadata.tiling = I915_TILING_X;
|
||||||
metadata.priority = 2;
|
metadata.priority = 2;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, tileable_formats,
|
ret = drv_add_combinations(drv, tileable_formats, ARRAY_SIZE(tileable_formats), &metadata,
|
||||||
ARRAY_SIZE(tileable_formats), &metadata,
|
|
||||||
flags);
|
flags);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -124,9 +115,8 @@ static int i915_add_combinations(struct driver *drv)
|
||||||
metadata.tiling = I915_TILING_Y;
|
metadata.tiling = I915_TILING_Y;
|
||||||
metadata.priority = 3;
|
metadata.priority = 3;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, tileable_formats,
|
ret = drv_add_combinations(drv, tileable_formats, ARRAY_SIZE(tileable_formats), &metadata,
|
||||||
ARRAY_SIZE(tileable_formats), &metadata,
|
flags);
|
||||||
flags);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
@ -146,8 +136,8 @@ static int i915_add_combinations(struct driver *drv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int i915_align_dimensions(struct bo *bo, uint32_t tiling,
|
static int i915_align_dimensions(struct bo *bo, uint32_t tiling, uint32_t *stride,
|
||||||
uint32_t *stride, uint32_t *aligned_height)
|
uint32_t *aligned_height)
|
||||||
{
|
{
|
||||||
struct i915_device *i915 = bo->drv->priv;
|
struct i915_device *i915 = bo->drv->priv;
|
||||||
uint32_t horizontal_alignment = 4;
|
uint32_t horizontal_alignment = 4;
|
||||||
|
|
@ -168,7 +158,7 @@ static int i915_align_dimensions(struct bo *bo, uint32_t tiling,
|
||||||
if (i915->gen == 3) {
|
if (i915->gen == 3) {
|
||||||
horizontal_alignment = 512;
|
horizontal_alignment = 512;
|
||||||
vertical_alignment = 8;
|
vertical_alignment = 8;
|
||||||
} else {
|
} else {
|
||||||
horizontal_alignment = 128;
|
horizontal_alignment = 128;
|
||||||
vertical_alignment = 32;
|
vertical_alignment = 32;
|
||||||
}
|
}
|
||||||
|
|
@ -235,8 +225,8 @@ static void i915_close(struct driver *drv)
|
||||||
drv->priv = NULL;
|
drv->priv = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t plane;
|
size_t plane;
|
||||||
|
|
@ -248,8 +238,7 @@ static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
stride = drv_stride_from_format(format, width, 0);
|
stride = drv_stride_from_format(format, width, 0);
|
||||||
struct i915_device *i915_dev = (struct i915_device *)bo->drv->priv;
|
struct i915_device *i915_dev = (struct i915_device *)bo->drv->priv;
|
||||||
|
|
||||||
if (flags & (BO_USE_CURSOR | BO_USE_LINEAR |
|
if (flags & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
|
||||||
BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
|
|
||||||
tiling_mode = I915_TILING_NONE;
|
tiling_mode = I915_TILING_NONE;
|
||||||
else if (flags & BO_USE_SCANOUT)
|
else if (flags & BO_USE_SCANOUT)
|
||||||
tiling_mode = I915_TILING_X;
|
tiling_mode = I915_TILING_X;
|
||||||
|
|
@ -260,8 +249,7 @@ static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
* Align the Y plane to 128 bytes so the chroma planes would be aligned
|
* Align the Y plane to 128 bytes so the chroma planes would be aligned
|
||||||
* to 64 byte boundaries. This is an Intel HW requirement.
|
* to 64 byte boundaries. This is an Intel HW requirement.
|
||||||
*/
|
*/
|
||||||
if (format == DRM_FORMAT_YVU420 ||
|
if (format == DRM_FORMAT_YVU420 || format == DRM_FORMAT_YVU420_ANDROID) {
|
||||||
format == DRM_FORMAT_YVU420_ANDROID) {
|
|
||||||
stride = ALIGN(stride, 128);
|
stride = ALIGN(stride, 128);
|
||||||
tiling_mode = I915_TILING_NONE;
|
tiling_mode = I915_TILING_NONE;
|
||||||
}
|
}
|
||||||
|
|
@ -281,8 +269,7 @@ static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
|
|
||||||
bo->priv = i915_bo;
|
bo->priv = i915_bo;
|
||||||
|
|
||||||
i915_bo->ibos[0] = drm_intel_bo_alloc(i915_dev->mgr, name,
|
i915_bo->ibos[0] = drm_intel_bo_alloc(i915_dev->mgr, name, bo->total_size, 0);
|
||||||
bo->total_size, 0);
|
|
||||||
if (!i915_bo->ibos[0]) {
|
if (!i915_bo->ibos[0]) {
|
||||||
fprintf(stderr, "drv: drm_intel_bo_alloc failed");
|
fprintf(stderr, "drv: drm_intel_bo_alloc failed");
|
||||||
free(i915_bo);
|
free(i915_bo);
|
||||||
|
|
@ -300,12 +287,12 @@ static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
|
|
||||||
bo->tiling = tiling_mode;
|
bo->tiling = tiling_mode;
|
||||||
|
|
||||||
ret = drm_intel_bo_set_tiling(i915_bo->ibos[0], &bo->tiling,
|
ret = drm_intel_bo_set_tiling(i915_bo->ibos[0], &bo->tiling, bo->strides[0]);
|
||||||
bo->strides[0]);
|
|
||||||
|
|
||||||
if (ret || bo->tiling != tiling_mode) {
|
if (ret || bo->tiling != tiling_mode) {
|
||||||
fprintf(stderr, "drv: drm_intel_gem_bo_set_tiling failed "
|
fprintf(stderr, "drv: drm_intel_gem_bo_set_tiling failed "
|
||||||
"errno=%x, stride=%x\n", errno, bo->strides[0]);
|
"errno=%x, stride=%x\n",
|
||||||
|
errno, bo->strides[0]);
|
||||||
/* Calls i915 bo destroy. */
|
/* Calls i915 bo destroy. */
|
||||||
bo->drv->backend->bo_destroy(bo);
|
bo->drv->backend->bo_destroy(bo);
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
@ -350,8 +337,8 @@ static int i915_bo_import(struct bo *bo, struct drv_import_fd_data *data)
|
||||||
*/
|
*/
|
||||||
for (plane = 0; plane < bo->num_planes; plane++) {
|
for (plane = 0; plane < bo->num_planes; plane++) {
|
||||||
|
|
||||||
i915_bo->ibos[plane] = drm_intel_bo_gem_create_from_prime(i915_dev->mgr,
|
i915_bo->ibos[plane] = drm_intel_bo_gem_create_from_prime(
|
||||||
data->fds[plane], data->sizes[plane]);
|
i915_dev->mgr, data->fds[plane], data->sizes[plane]);
|
||||||
|
|
||||||
if (!i915_bo->ibos[plane]) {
|
if (!i915_bo->ibos[plane]) {
|
||||||
/*
|
/*
|
||||||
|
|
@ -369,8 +356,7 @@ static int i915_bo_import(struct bo *bo, struct drv_import_fd_data *data)
|
||||||
bo->handles[plane].u32 = i915_bo->ibos[plane]->handle;
|
bo->handles[plane].u32 = i915_bo->ibos[plane]->handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drm_intel_bo_get_tiling(i915_bo->ibos[0], &bo->tiling,
|
if (drm_intel_bo_get_tiling(i915_bo->ibos[0], &bo->tiling, &swizzling)) {
|
||||||
&swizzling)) {
|
|
||||||
fprintf(stderr, "drv: drm_intel_bo_get_tiling failed");
|
fprintf(stderr, "drv: drm_intel_bo_get_tiling failed");
|
||||||
i915_bo_destroy(bo);
|
i915_bo_destroy(bo);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
@ -426,8 +412,7 @@ static uint32_t i915_resolve_format(uint32_t format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_i915 =
|
struct backend backend_i915 = {
|
||||||
{
|
|
||||||
.name = "i915",
|
.name = "i915",
|
||||||
.init = i915_init,
|
.init = i915_init,
|
||||||
.close = i915_close,
|
.close = i915_close,
|
||||||
|
|
|
||||||
10
marvell.c
10
marvell.c
|
|
@ -10,18 +10,14 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
|
|
||||||
};
|
|
||||||
|
|
||||||
static int marvell_init(struct driver *drv)
|
static int marvell_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_marvell =
|
struct backend backend_marvell = {
|
||||||
{
|
|
||||||
.name = "marvell",
|
.name = "marvell",
|
||||||
.init = marvell_init,
|
.init = marvell_init,
|
||||||
.bo_create = drv_dumb_bo_create,
|
.bo_create = drv_dumb_bo_create,
|
||||||
|
|
|
||||||
30
mediatek.c
30
mediatek.c
|
|
@ -6,30 +6,30 @@
|
||||||
|
|
||||||
#ifdef DRV_MEDIATEK
|
#ifdef DRV_MEDIATEK
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
#include <mediatek_drm.h>
|
#include <mediatek_drm.h>
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
#include "drv_priv.h"
|
#include "drv_priv.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
|
||||||
DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565,
|
DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888,
|
||||||
DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888, DRM_FORMAT_YVU420,
|
DRM_FORMAT_XRGB8888, DRM_FORMAT_YVU420,
|
||||||
DRM_FORMAT_YVU420_ANDROID
|
DRM_FORMAT_YVU420_ANDROID };
|
||||||
};
|
|
||||||
|
|
||||||
static int mediatek_init(struct driver *drv)
|
static int mediatek_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t plane;
|
size_t plane;
|
||||||
|
|
@ -50,7 +50,8 @@ static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_CREATE, &gem_create);
|
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_CREATE, &gem_create);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "drv: DRM_IOCTL_MTK_GEM_CREATE failed "
|
fprintf(stderr, "drv: DRM_IOCTL_MTK_GEM_CREATE failed "
|
||||||
"(size=%llu)\n", gem_create.size);
|
"(size=%llu)\n",
|
||||||
|
gem_create.size);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,14 +71,14 @@ static void *mediatek_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
||||||
|
|
||||||
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_MAP_OFFSET, &gem_map);
|
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_MAP_OFFSET, &gem_map);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr,"drv: DRM_IOCTL_MTK_GEM_MAP_OFFSET failed\n");
|
fprintf(stderr, "drv: DRM_IOCTL_MTK_GEM_MAP_OFFSET failed\n");
|
||||||
return MAP_FAILED;
|
return MAP_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->length = bo->total_size;
|
data->length = bo->total_size;
|
||||||
|
|
||||||
return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
|
||||||
bo->drv->fd, gem_map.offset);
|
gem_map.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t mediatek_resolve_format(uint32_t format)
|
static uint32_t mediatek_resolve_format(uint32_t format)
|
||||||
|
|
@ -93,8 +94,7 @@ static uint32_t mediatek_resolve_format(uint32_t format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_mediatek =
|
struct backend backend_mediatek = {
|
||||||
{
|
|
||||||
.name = "mediatek",
|
.name = "mediatek",
|
||||||
.init = mediatek_init,
|
.init = mediatek_init,
|
||||||
.bo_create = mediatek_bo_create,
|
.bo_create = mediatek_bo_create,
|
||||||
|
|
|
||||||
10
nouveau.c
10
nouveau.c
|
|
@ -8,18 +8,14 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
|
|
||||||
};
|
|
||||||
|
|
||||||
static int nouveau_init(struct driver *drv)
|
static int nouveau_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_nouveau =
|
struct backend backend_nouveau = {
|
||||||
{
|
|
||||||
.name = "nouveau",
|
.name = "nouveau",
|
||||||
.init = nouveau_init,
|
.init = nouveau_init,
|
||||||
.bo_create = drv_dumb_bo_create,
|
.bo_create = drv_dumb_bo_create,
|
||||||
|
|
|
||||||
9
presubmit.sh
Executable file
9
presubmit.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Copyright 2017 The Chromium OS Authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
|
# found in the LICENSE file.
|
||||||
|
|
||||||
|
find \
|
||||||
|
'(' -name '*.[ch]' -or -name '*.cc' ')' \
|
||||||
|
-not -name 'gbm.h' \
|
||||||
|
-exec clang-format -style=file -i {} +
|
||||||
80
rockchip.c
80
rockchip.c
|
|
@ -7,25 +7,23 @@
|
||||||
#ifdef DRV_ROCKCHIP
|
#ifdef DRV_ROCKCHIP
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <rockchip_drm.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
#include <rockchip_drm.h>
|
|
||||||
|
|
||||||
#include "drv_priv.h"
|
#include "drv_priv.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
|
||||||
DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_NV12,
|
DRM_FORMAT_NV12, DRM_FORMAT_RGB565,
|
||||||
DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888,
|
DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888,
|
||||||
DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID
|
DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID };
|
||||||
};
|
|
||||||
|
|
||||||
static int afbc_bo_from_format(struct bo *bo, uint32_t width, uint32_t height,
|
static int afbc_bo_from_format(struct bo *bo, uint32_t width, uint32_t height, uint32_t format)
|
||||||
uint32_t format)
|
|
||||||
{
|
{
|
||||||
/* We've restricted ourselves to four bytes per pixel. */
|
/* We've restricted ourselves to four bytes per pixel. */
|
||||||
const uint32_t pixel_size = 4;
|
const uint32_t pixel_size = 4;
|
||||||
|
|
@ -55,10 +53,8 @@ static int afbc_bo_from_format(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
* alignement for the body plane. */
|
* alignement for the body plane. */
|
||||||
const uint32_t body_plane_alignment = 1024;
|
const uint32_t body_plane_alignment = 1024;
|
||||||
|
|
||||||
const uint32_t body_plane_offset =
|
const uint32_t body_plane_offset = ALIGN(header_plane_size, body_plane_alignment);
|
||||||
ALIGN(header_plane_size, body_plane_alignment);
|
const uint32_t total_size = body_plane_offset + body_plane_size;
|
||||||
const uint32_t total_size =
|
|
||||||
body_plane_offset + body_plane_size;
|
|
||||||
|
|
||||||
bo->strides[0] = width_in_blocks * block_width * pixel_size;
|
bo->strides[0] = width_in_blocks * block_width * pixel_size;
|
||||||
bo->sizes[0] = total_size;
|
bo->sizes[0] = total_size;
|
||||||
|
|
@ -82,16 +78,13 @@ static int rockchip_add_kms_item(struct driver *drv, const struct kms_item *item
|
||||||
for (i = 0; i < drv->backend->combos.size; i++) {
|
for (i = 0; i < drv->backend->combos.size; i++) {
|
||||||
combo = &drv->backend->combos.data[i];
|
combo = &drv->backend->combos.data[i];
|
||||||
if (combo->format == item->format) {
|
if (combo->format == item->format) {
|
||||||
if (item->modifier ==
|
if (item->modifier == DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC) {
|
||||||
DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC) {
|
flags = BO_USE_RENDERING | BO_USE_SCANOUT | BO_USE_TEXTURE;
|
||||||
flags = BO_USE_RENDERING | BO_USE_SCANOUT |
|
|
||||||
BO_USE_TEXTURE;
|
|
||||||
metadata.modifier = item->modifier;
|
metadata.modifier = item->modifier;
|
||||||
metadata.tiling = 0;
|
metadata.tiling = 0;
|
||||||
metadata.priority = 2;
|
metadata.priority = 2;
|
||||||
|
|
||||||
ret = drv_add_combination(drv, item[i].format,
|
ret = drv_add_combination(drv, item[i].format, &metadata, flags);
|
||||||
&metadata, flags);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -114,16 +107,13 @@ static int rockchip_init(struct driver *drv)
|
||||||
metadata.priority = 1;
|
metadata.priority = 1;
|
||||||
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, supported_formats,
|
ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
|
||||||
ARRAY_SIZE(supported_formats), &metadata,
|
|
||||||
BO_COMMON_USE_MASK);
|
BO_COMMON_USE_MASK);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
|
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
|
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
|
||||||
|
|
||||||
items = drv_query_kms(drv, &num_items);
|
items = drv_query_kms(drv, &num_items);
|
||||||
if (!items || !num_items)
|
if (!items || !num_items)
|
||||||
|
|
@ -152,10 +142,8 @@ static bool has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rockchip_bo_create_with_modifiers(struct bo *bo,
|
static int rockchip_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
uint32_t width, uint32_t height,
|
uint32_t format, const uint64_t *modifiers,
|
||||||
uint32_t format,
|
|
||||||
const uint64_t *modifiers,
|
|
||||||
uint32_t count)
|
uint32_t count)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -170,11 +158,9 @@ static int rockchip_bo_create_with_modifiers(struct bo *bo,
|
||||||
uint32_t aligned_height = DIV_ROUND_UP(h_mbs * 16 * 3, 2);
|
uint32_t aligned_height = DIV_ROUND_UP(h_mbs * 16 * 3, 2);
|
||||||
|
|
||||||
drv_bo_from_format(bo, aligned_width, height, format);
|
drv_bo_from_format(bo, aligned_width, height, format);
|
||||||
bo->total_size = bo->strides[0] * aligned_height
|
bo->total_size = bo->strides[0] * aligned_height + w_mbs * h_mbs * 128;
|
||||||
+ w_mbs * h_mbs * 128;
|
|
||||||
} else if (width <= 2560 &&
|
} else if (width <= 2560 &&
|
||||||
has_modifier(modifiers, count,
|
has_modifier(modifiers, count, DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC)) {
|
||||||
DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC)) {
|
|
||||||
/* If the caller has decided they can use AFBC, always
|
/* If the caller has decided they can use AFBC, always
|
||||||
* pick that */
|
* pick that */
|
||||||
afbc_bo_from_format(bo, width, height, format);
|
afbc_bo_from_format(bo, width, height, format);
|
||||||
|
|
@ -193,8 +179,7 @@ static int rockchip_bo_create_with_modifiers(struct bo *bo,
|
||||||
* luma plane to 128 bytes.
|
* luma plane to 128 bytes.
|
||||||
*/
|
*/
|
||||||
stride = drv_stride_from_format(format, width, 0);
|
stride = drv_stride_from_format(format, width, 0);
|
||||||
if (format == DRM_FORMAT_YVU420 ||
|
if (format == DRM_FORMAT_YVU420 || format == DRM_FORMAT_YVU420_ANDROID)
|
||||||
format == DRM_FORMAT_YVU420_ANDROID)
|
|
||||||
stride = ALIGN(stride, 128);
|
stride = ALIGN(stride, 128);
|
||||||
else
|
else
|
||||||
stride = ALIGN(stride, 64);
|
stride = ALIGN(stride, 64);
|
||||||
|
|
@ -205,12 +190,12 @@ static int rockchip_bo_create_with_modifiers(struct bo *bo,
|
||||||
memset(&gem_create, 0, sizeof(gem_create));
|
memset(&gem_create, 0, sizeof(gem_create));
|
||||||
gem_create.size = bo->total_size;
|
gem_create.size = bo->total_size;
|
||||||
|
|
||||||
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_CREATE,
|
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_CREATE, &gem_create);
|
||||||
&gem_create);
|
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_CREATE failed "
|
fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_CREATE failed "
|
||||||
"(size=%llu)\n", gem_create.size);
|
"(size=%llu)\n",
|
||||||
|
gem_create.size);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,13 +205,13 @@ static int rockchip_bo_create_with_modifiers(struct bo *bo,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
uint64_t modifiers[] = { DRM_FORMAT_MOD_NONE };
|
uint64_t modifiers[] = { DRM_FORMAT_MOD_NONE };
|
||||||
|
|
||||||
return rockchip_bo_create_with_modifiers(bo, width, height, format,
|
return rockchip_bo_create_with_modifiers(bo, width, height, format, modifiers,
|
||||||
modifiers, ARRAY_SIZE(modifiers));
|
ARRAY_SIZE(modifiers));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
||||||
|
|
@ -242,18 +227,16 @@ static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
||||||
memset(&gem_map, 0, sizeof(gem_map));
|
memset(&gem_map, 0, sizeof(gem_map));
|
||||||
gem_map.handle = bo->handles[0].u32;
|
gem_map.handle = bo->handles[0].u32;
|
||||||
|
|
||||||
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET,
|
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET, &gem_map);
|
||||||
&gem_map);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET failed\n");
|
||||||
"drv: DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET failed\n");
|
|
||||||
return MAP_FAILED;
|
return MAP_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->length = bo->total_size;
|
data->length = bo->total_size;
|
||||||
|
|
||||||
return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
|
||||||
bo->drv->fd, gem_map.offset);
|
gem_map.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t rockchip_resolve_format(uint32_t format)
|
static uint32_t rockchip_resolve_format(uint32_t format)
|
||||||
|
|
@ -269,8 +252,7 @@ static uint32_t rockchip_resolve_format(uint32_t format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_rockchip =
|
struct backend backend_rockchip = {
|
||||||
{
|
|
||||||
.name = "rockchip",
|
.name = "rockchip",
|
||||||
.init = rockchip_init,
|
.init = rockchip_init,
|
||||||
.bo_create = rockchip_bo_create,
|
.bo_create = rockchip_bo_create,
|
||||||
|
|
|
||||||
100
tegra.c
100
tegra.c
|
|
@ -9,8 +9,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <xf86drm.h>
|
|
||||||
#include <tegra_drm.h>
|
#include <tegra_drm.h>
|
||||||
|
#include <xf86drm.h>
|
||||||
|
|
||||||
#include "drv_priv.h"
|
#include "drv_priv.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
#define NV_DEFAULT_BLOCK_HEIGHT_LOG2 4
|
#define NV_DEFAULT_BLOCK_HEIGHT_LOG2 4
|
||||||
#define NV_PREFERRED_PAGE_SIZE (128 * 1024)
|
#define NV_PREFERRED_PAGE_SIZE (128 * 1024)
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
enum nv_mem_kind
|
enum nv_mem_kind
|
||||||
{
|
{
|
||||||
NV_MEM_KIND_PITCH = 0,
|
NV_MEM_KIND_PITCH = 0,
|
||||||
|
|
@ -37,15 +38,14 @@ enum tegra_map_type {
|
||||||
TEGRA_READ_TILED_BUFFER = 0,
|
TEGRA_READ_TILED_BUFFER = 0,
|
||||||
TEGRA_WRITE_TILED_BUFFER = 1,
|
TEGRA_WRITE_TILED_BUFFER = 1,
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
struct tegra_private_map_data {
|
struct tegra_private_map_data {
|
||||||
void *tiled;
|
void *tiled;
|
||||||
void *untiled;
|
void *untiled;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
|
|
||||||
};
|
|
||||||
|
|
||||||
static int compute_block_height_log2(int height)
|
static int compute_block_height_log2(int height)
|
||||||
{
|
{
|
||||||
|
|
@ -65,10 +65,9 @@ static int compute_block_height_log2(int height)
|
||||||
return block_height_log2;
|
return block_height_log2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compute_layout_blocklinear(int width, int height, int format,
|
static void compute_layout_blocklinear(int width, int height, int format, enum nv_mem_kind *kind,
|
||||||
enum nv_mem_kind *kind,
|
uint32_t *block_height_log2, uint32_t *stride,
|
||||||
uint32_t *block_height_log2,
|
uint32_t *size)
|
||||||
uint32_t *stride, uint32_t *size)
|
|
||||||
{
|
{
|
||||||
int pitch = drv_stride_from_format(format, width, 0);
|
int pitch = drv_stride_from_format(format, width, 0);
|
||||||
|
|
||||||
|
|
@ -78,8 +77,7 @@ static void compute_layout_blocklinear(int width, int height, int format,
|
||||||
/* Compute padded height. */
|
/* Compute padded height. */
|
||||||
*block_height_log2 = compute_block_height_log2(height);
|
*block_height_log2 = compute_block_height_log2(height);
|
||||||
int block_height = 1 << *block_height_log2;
|
int block_height = 1 << *block_height_log2;
|
||||||
int padded_height =
|
int padded_height = ALIGN(height, NV_BLOCKLINEAR_GOB_HEIGHT * block_height);
|
||||||
ALIGN(height, NV_BLOCKLINEAR_GOB_HEIGHT * block_height);
|
|
||||||
|
|
||||||
int bytes = pitch * padded_height;
|
int bytes = pitch * padded_height;
|
||||||
|
|
||||||
|
|
@ -94,16 +92,15 @@ static void compute_layout_blocklinear(int width, int height, int format,
|
||||||
*size = bytes;
|
*size = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compute_layout_linear(int width, int height, int format,
|
static void compute_layout_linear(int width, int height, int format, uint32_t *stride,
|
||||||
uint32_t *stride, uint32_t *size)
|
uint32_t *size)
|
||||||
{
|
{
|
||||||
*stride = ALIGN(drv_stride_from_format(format, width, 0), 64);
|
*stride = ALIGN(drv_stride_from_format(format, width, 0), 64);
|
||||||
*size = *stride * height;
|
*size = *stride * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transfer_tile(struct bo *bo, uint8_t *tiled, uint8_t *untiled,
|
static void transfer_tile(struct bo *bo, uint8_t *tiled, uint8_t *untiled, enum tegra_map_type type,
|
||||||
enum tegra_map_type type, uint32_t bytes_per_pixel,
|
uint32_t bytes_per_pixel, uint32_t gob_top, uint32_t gob_left,
|
||||||
uint32_t gob_top, uint32_t gob_left,
|
|
||||||
uint32_t gob_size_pixels)
|
uint32_t gob_size_pixels)
|
||||||
{
|
{
|
||||||
uint8_t *tmp;
|
uint8_t *tmp;
|
||||||
|
|
@ -129,11 +126,11 @@ static void transfer_tile(struct bo *bo, uint8_t *tiled, uint8_t *untiled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transfer_tiled_memory(struct bo *bo, uint8_t *tiled,
|
static void transfer_tiled_memory(struct bo *bo, uint8_t *tiled, uint8_t *untiled,
|
||||||
uint8_t *untiled, enum tegra_map_type type)
|
enum tegra_map_type type)
|
||||||
{
|
{
|
||||||
uint32_t gob_width, gob_height, gob_size_bytes, gob_size_pixels,
|
uint32_t gob_width, gob_height, gob_size_bytes, gob_size_pixels, gob_count_x, gob_count_y,
|
||||||
gob_count_x, gob_count_y, gob_top, gob_left;
|
gob_top, gob_left;
|
||||||
uint32_t i, j, offset;
|
uint32_t i, j, offset;
|
||||||
uint8_t *tmp;
|
uint8_t *tmp;
|
||||||
uint32_t bytes_per_pixel = drv_stride_from_format(bo->format, 1, 0);
|
uint32_t bytes_per_pixel = drv_stride_from_format(bo->format, 1, 0);
|
||||||
|
|
@ -143,11 +140,9 @@ static void transfer_tiled_memory(struct bo *bo, uint8_t *tiled,
|
||||||
* where 0 <= n <= 4.
|
* where 0 <= n <= 4.
|
||||||
*/
|
*/
|
||||||
gob_width = DIV_ROUND_UP(NV_BLOCKLINEAR_GOB_WIDTH, bytes_per_pixel);
|
gob_width = DIV_ROUND_UP(NV_BLOCKLINEAR_GOB_WIDTH, bytes_per_pixel);
|
||||||
gob_height = NV_BLOCKLINEAR_GOB_HEIGHT *
|
gob_height = NV_BLOCKLINEAR_GOB_HEIGHT * (1 << NV_DEFAULT_BLOCK_HEIGHT_LOG2);
|
||||||
(1 << NV_DEFAULT_BLOCK_HEIGHT_LOG2);
|
|
||||||
/* Calculate the height from maximum possible gob height */
|
/* Calculate the height from maximum possible gob height */
|
||||||
while (gob_height > NV_BLOCKLINEAR_GOB_HEIGHT
|
while (gob_height > NV_BLOCKLINEAR_GOB_HEIGHT && gob_height >= 2 * bo->height)
|
||||||
&& gob_height >= 2 * bo->height)
|
|
||||||
gob_height /= 2;
|
gob_height /= 2;
|
||||||
|
|
||||||
gob_size_bytes = gob_height * NV_BLOCKLINEAR_GOB_WIDTH;
|
gob_size_bytes = gob_height * NV_BLOCKLINEAR_GOB_WIDTH;
|
||||||
|
|
@ -163,8 +158,8 @@ static void transfer_tiled_memory(struct bo *bo, uint8_t *tiled,
|
||||||
tmp = tiled + offset;
|
tmp = tiled + offset;
|
||||||
gob_left = i * gob_width;
|
gob_left = i * gob_width;
|
||||||
|
|
||||||
transfer_tile(bo, tmp, untiled, type, bytes_per_pixel,
|
transfer_tile(bo, tmp, untiled, type, bytes_per_pixel, gob_top, gob_left,
|
||||||
gob_top, gob_left, gob_size_pixels);
|
gob_size_pixels);
|
||||||
|
|
||||||
offset += gob_size_bytes;
|
offset += gob_size_bytes;
|
||||||
}
|
}
|
||||||
|
|
@ -181,16 +176,13 @@ static int tegra_init(struct driver *drv)
|
||||||
metadata.priority = 1;
|
metadata.priority = 1;
|
||||||
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
metadata.modifier = DRM_FORMAT_MOD_NONE;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, supported_formats,
|
ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
|
||||||
ARRAY_SIZE(supported_formats), &metadata,
|
|
||||||
flags);
|
flags);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
|
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
|
||||||
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
|
|
||||||
BO_USE_CURSOR | BO_USE_SCANOUT);
|
|
||||||
|
|
||||||
flags &= ~BO_USE_SW_WRITE_OFTEN;
|
flags &= ~BO_USE_SW_WRITE_OFTEN;
|
||||||
flags &= ~BO_USE_SW_READ_OFTEN;
|
flags &= ~BO_USE_SW_READ_OFTEN;
|
||||||
|
|
@ -199,33 +191,29 @@ static int tegra_init(struct driver *drv)
|
||||||
metadata.tiling = NV_MEM_KIND_C32_2CRA;
|
metadata.tiling = NV_MEM_KIND_C32_2CRA;
|
||||||
metadata.priority = 2;
|
metadata.priority = 2;
|
||||||
|
|
||||||
ret = drv_add_combinations(drv, supported_formats,
|
ret = drv_add_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats), &metadata,
|
||||||
ARRAY_SIZE(supported_formats), &metadata,
|
|
||||||
flags);
|
flags);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata,
|
drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_SCANOUT);
|
||||||
BO_USE_SCANOUT);
|
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_SCANOUT);
|
||||||
drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata,
|
|
||||||
BO_USE_SCANOUT);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
uint32_t size, stride, block_height_log2 = 0;
|
uint32_t size, stride, block_height_log2 = 0;
|
||||||
enum nv_mem_kind kind = NV_MEM_KIND_PITCH;
|
enum nv_mem_kind kind = NV_MEM_KIND_PITCH;
|
||||||
struct drm_tegra_gem_create gem_create;
|
struct drm_tegra_gem_create gem_create;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (flags & (BO_USE_CURSOR | BO_USE_LINEAR |
|
if (flags & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
|
||||||
BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN))
|
|
||||||
compute_layout_linear(width, height, format, &stride, &size);
|
compute_layout_linear(width, height, format, &stride, &size);
|
||||||
else
|
else
|
||||||
compute_layout_blocklinear(width, height, format, &kind,
|
compute_layout_blocklinear(width, height, format, &kind, &block_height_log2,
|
||||||
&block_height_log2, &stride, &size);
|
&stride, &size);
|
||||||
|
|
||||||
memset(&gem_create, 0, sizeof(gem_create));
|
memset(&gem_create, 0, sizeof(gem_create));
|
||||||
gem_create.size = size;
|
gem_create.size = size;
|
||||||
|
|
@ -234,7 +222,8 @@ static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_TEGRA_GEM_CREATE, &gem_create);
|
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_TEGRA_GEM_CREATE, &gem_create);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "drv: DRM_IOCTL_TEGRA_GEM_CREATE failed "
|
fprintf(stderr, "drv: DRM_IOCTL_TEGRA_GEM_CREATE failed "
|
||||||
"(size=%zu)\n", size);
|
"(size=%zu)\n",
|
||||||
|
size);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -251,16 +240,15 @@ static int tegra_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
gem_tile.mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
|
gem_tile.mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
|
||||||
gem_tile.value = block_height_log2;
|
gem_tile.value = block_height_log2;
|
||||||
|
|
||||||
ret = drmCommandWriteRead(bo->drv->fd, DRM_TEGRA_GEM_SET_TILING,
|
ret = drmCommandWriteRead(bo->drv->fd, DRM_TEGRA_GEM_SET_TILING, &gem_tile,
|
||||||
&gem_tile, sizeof(gem_tile));
|
sizeof(gem_tile));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
drv_gem_bo_destroy(bo);
|
drv_gem_bo_destroy(bo);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encode blocklinear parameters for EGLImage creation. */
|
/* Encode blocklinear parameters for EGLImage creation. */
|
||||||
bo->tiling = (kind & 0xff) |
|
bo->tiling = (kind & 0xff) | ((block_height_log2 & 0xf) << 8);
|
||||||
((block_height_log2 & 0xf) << 8);
|
|
||||||
bo->format_modifiers[0] = fourcc_mod_code(NV, bo->tiling);
|
bo->format_modifiers[0] = fourcc_mod_code(NV, bo->tiling);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,15 +264,14 @@ static void *tegra_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
||||||
memset(&gem_map, 0, sizeof(gem_map));
|
memset(&gem_map, 0, sizeof(gem_map));
|
||||||
gem_map.handle = bo->handles[0].u32;
|
gem_map.handle = bo->handles[0].u32;
|
||||||
|
|
||||||
ret = drmCommandWriteRead(bo->drv->fd, DRM_TEGRA_GEM_MMAP, &gem_map,
|
ret = drmCommandWriteRead(bo->drv->fd, DRM_TEGRA_GEM_MMAP, &gem_map, sizeof(gem_map));
|
||||||
sizeof(gem_map));
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "drv: DRM_TEGRA_GEM_MMAP failed\n");
|
fprintf(stderr, "drv: DRM_TEGRA_GEM_MMAP failed\n");
|
||||||
return MAP_FAILED;
|
return MAP_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *addr = mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
void *addr = mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
|
||||||
bo->drv->fd, gem_map.offset);
|
gem_map.offset);
|
||||||
|
|
||||||
data->length = bo->total_size;
|
data->length = bo->total_size;
|
||||||
|
|
||||||
|
|
@ -293,8 +280,7 @@ static void *tegra_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
||||||
priv->untiled = calloc(1, bo->total_size);
|
priv->untiled = calloc(1, bo->total_size);
|
||||||
priv->tiled = addr;
|
priv->tiled = addr;
|
||||||
data->priv = priv;
|
data->priv = priv;
|
||||||
transfer_tiled_memory(bo, priv->tiled, priv->untiled,
|
transfer_tiled_memory(bo, priv->tiled, priv->untiled, TEGRA_READ_TILED_BUFFER);
|
||||||
TEGRA_READ_TILED_BUFFER);
|
|
||||||
addr = priv->untiled;
|
addr = priv->untiled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,8 +291,7 @@ static int tegra_bo_unmap(struct bo *bo, struct map_info *data)
|
||||||
{
|
{
|
||||||
if (data->priv) {
|
if (data->priv) {
|
||||||
struct tegra_private_map_data *priv = data->priv;
|
struct tegra_private_map_data *priv = data->priv;
|
||||||
transfer_tiled_memory(bo, priv->tiled, priv->untiled,
|
transfer_tiled_memory(bo, priv->tiled, priv->untiled, TEGRA_WRITE_TILED_BUFFER);
|
||||||
TEGRA_WRITE_TILED_BUFFER);
|
|
||||||
data->addr = priv->tiled;
|
data->addr = priv->tiled;
|
||||||
free(priv->untiled);
|
free(priv->untiled);
|
||||||
free(priv);
|
free(priv);
|
||||||
|
|
@ -316,8 +301,7 @@ static int tegra_bo_unmap(struct bo *bo, struct map_info *data)
|
||||||
return munmap(data->addr, data->length);
|
return munmap(data->addr, data->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_tegra =
|
struct backend backend_tegra = {
|
||||||
{
|
|
||||||
.name = "tegra",
|
.name = "tegra",
|
||||||
.init = tegra_init,
|
.init = tegra_init,
|
||||||
.bo_create = tegra_bo_create,
|
.bo_create = tegra_bo_create,
|
||||||
|
|
|
||||||
10
udl.c
10
udl.c
|
|
@ -8,18 +8,14 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
|
|
||||||
};
|
|
||||||
|
|
||||||
static int udl_init(struct driver *drv)
|
static int udl_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_udl =
|
struct backend backend_udl = {
|
||||||
{
|
|
||||||
.name = "udl",
|
.name = "udl",
|
||||||
.init = udl_init,
|
.init = udl_init,
|
||||||
.bo_create = drv_dumb_bo_create,
|
.bo_create = drv_dumb_bo_create,
|
||||||
|
|
|
||||||
6
util.h
6
util.h
|
|
@ -8,9 +8,9 @@
|
||||||
#define UTIL_H
|
#define UTIL_H
|
||||||
|
|
||||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||||
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*(A)))
|
#define ARRAY_SIZE(A) (sizeof(A) / sizeof(*(A)))
|
||||||
#define PUBLIC __attribute__((visibility("default")))
|
#define PUBLIC __attribute__((visibility("default")))
|
||||||
#define ALIGN(A, B) (((A) + (B) - 1) / (B) * (B))
|
#define ALIGN(A, B) (((A) + (B)-1) / (B) * (B))
|
||||||
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
25
vc4.c
25
vc4.c
|
|
@ -16,18 +16,16 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565,
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888
|
DRM_FORMAT_XRGB8888 };
|
||||||
};
|
|
||||||
|
|
||||||
static int vc4_init(struct driver *drv)
|
static int vc4_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vc4_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
static int vc4_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t plane;
|
size_t plane;
|
||||||
|
|
@ -48,7 +46,8 @@ static int vc4_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
||||||
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_VC4_CREATE_BO, &bo_create);
|
ret = drmIoctl(bo->drv->fd, DRM_IOCTL_VC4_CREATE_BO, &bo_create);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "drv: DRM_IOCTL_VC4_GEM_CREATE failed "
|
fprintf(stderr, "drv: DRM_IOCTL_VC4_GEM_CREATE failed "
|
||||||
"(size=%zu)\n", bo->total_size);
|
"(size=%zu)\n",
|
||||||
|
bo->total_size);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,8 +65,7 @@ static void *vc4_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
||||||
memset(&bo_map, 0, sizeof(bo_map));
|
memset(&bo_map, 0, sizeof(bo_map));
|
||||||
bo_map.handle = bo->handles[0].u32;
|
bo_map.handle = bo->handles[0].u32;
|
||||||
|
|
||||||
ret = drmCommandWriteRead(bo->drv->fd, DRM_VC4_MMAP_BO, &bo_map,
|
ret = drmCommandWriteRead(bo->drv->fd, DRM_VC4_MMAP_BO, &bo_map, sizeof(bo_map));
|
||||||
sizeof(bo_map));
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "drv: DRM_VC4_MMAP_BO failed\n");
|
fprintf(stderr, "drv: DRM_VC4_MMAP_BO failed\n");
|
||||||
return MAP_FAILED;
|
return MAP_FAILED;
|
||||||
|
|
@ -75,12 +73,11 @@ static void *vc4_bo_map(struct bo *bo, struct map_info *data, size_t plane)
|
||||||
|
|
||||||
data->length = bo->total_size;
|
data->length = bo->total_size;
|
||||||
|
|
||||||
return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
|
||||||
bo->drv->fd, bo_map.offset);
|
bo_map.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_vc4 =
|
struct backend backend_vc4 = {
|
||||||
{
|
|
||||||
.name = "vc4",
|
.name = "vc4",
|
||||||
.init = vc4_init,
|
.init = vc4_init,
|
||||||
.bo_create = vc4_bo_create,
|
.bo_create = vc4_bo_create,
|
||||||
|
|
|
||||||
20
vgem.c
20
vgem.c
|
|
@ -11,23 +11,19 @@
|
||||||
#define MESA_LLVMPIPE_TILE_ORDER 6
|
#define MESA_LLVMPIPE_TILE_ORDER 6
|
||||||
#define MESA_LLVMPIPE_TILE_SIZE (1 << MESA_LLVMPIPE_TILE_ORDER)
|
#define MESA_LLVMPIPE_TILE_SIZE (1 << MESA_LLVMPIPE_TILE_ORDER)
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565,
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
|
DRM_FORMAT_XRGB8888, DRM_FORMAT_YVU420_ANDROID };
|
||||||
DRM_FORMAT_YVU420_ANDROID
|
|
||||||
};
|
|
||||||
|
|
||||||
static int vgem_init(struct driver *drv)
|
static int vgem_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vgem_bo_create(struct bo *bo, uint32_t width, uint32_t height,
|
static int vgem_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
|
||||||
uint32_t format, uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
int ret = drv_dumb_bo_create(bo, ALIGN(width, MESA_LLVMPIPE_TILE_SIZE),
|
int ret = drv_dumb_bo_create(bo, ALIGN(width, MESA_LLVMPIPE_TILE_SIZE),
|
||||||
ALIGN(height, MESA_LLVMPIPE_TILE_SIZE),
|
ALIGN(height, MESA_LLVMPIPE_TILE_SIZE), format, flags);
|
||||||
format, flags);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,8 +40,7 @@ static uint32_t vgem_resolve_format(uint32_t format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_vgem =
|
struct backend backend_vgem = {
|
||||||
{
|
|
||||||
.name = "vgem",
|
.name = "vgem",
|
||||||
.init = vgem_init,
|
.init = vgem_init,
|
||||||
.bo_create = vgem_bo_create,
|
.bo_create = vgem_bo_create,
|
||||||
|
|
@ -54,4 +49,3 @@ struct backend backend_vgem =
|
||||||
.bo_map = drv_dumb_bo_map,
|
.bo_map = drv_dumb_bo_map,
|
||||||
.resolve_format = vgem_resolve_format,
|
.resolve_format = vgem_resolve_format,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
11
virtio_gpu.c
11
virtio_gpu.c
|
|
@ -8,18 +8,14 @@
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static const uint32_t supported_formats[] = {
|
static const uint32_t supported_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
|
||||||
DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888
|
|
||||||
};
|
|
||||||
|
|
||||||
static int virtio_gpu_init(struct driver *drv)
|
static int virtio_gpu_init(struct driver *drv)
|
||||||
{
|
{
|
||||||
return drv_add_linear_combinations(drv, supported_formats,
|
return drv_add_linear_combinations(drv, supported_formats, ARRAY_SIZE(supported_formats));
|
||||||
ARRAY_SIZE(supported_formats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct backend backend_virtio_gpu =
|
struct backend backend_virtio_gpu = {
|
||||||
{
|
|
||||||
.name = "virtio_gpu",
|
.name = "virtio_gpu",
|
||||||
.init = virtio_gpu_init,
|
.init = virtio_gpu_init,
|
||||||
.bo_create = drv_dumb_bo_create,
|
.bo_create = drv_dumb_bo_create,
|
||||||
|
|
@ -27,4 +23,3 @@ struct backend backend_virtio_gpu =
|
||||||
.bo_import = drv_prime_bo_import,
|
.bo_import = drv_prime_bo_import,
|
||||||
.bo_map = drv_dumb_bo_map,
|
.bo_map = drv_dumb_bo_map,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue