Commit 2388bbd0 authored by Eric Anholt's avatar Eric Anholt

v3d: Add a helper library

Just a few little ioctl wrappers that v3d tests will use.

v2: Move the struct above the prototypes.
Signed-off-by: Eric Anholt's avatarEric Anholt <eric@anholt.net>
Acked-by: Petri Latvala <petri.latvala@intel.com> (v1)
parent bca19993
Pipeline #10089 passed with stages
in 2 minutes and 34 seconds
......@@ -107,6 +107,8 @@ lib_source_list = \
igt_syncobj.h \
igt_psr.c \
igt_psr.h \
igt_v3d.c \
igt_v3d.h \
$(NULL)
.PHONY: version.h.tmp
......
......@@ -202,6 +202,7 @@ static const struct module {
} modules[] = {
{ DRIVER_AMDGPU, "amdgpu" },
{ DRIVER_INTEL, "i915", modprobe_i915 },
{ DRIVER_V3D, "v3d" },
{ DRIVER_VC4, "vc4" },
{ DRIVER_VGEM, "vgem" },
{ DRIVER_VIRTIO, "virtio-gpu" },
......@@ -340,6 +341,8 @@ static const char *chipset_to_str(int chipset)
switch (chipset) {
case DRIVER_INTEL:
return "intel";
case DRIVER_V3D:
return "v3d";
case DRIVER_VC4:
return "vc4";
case DRIVER_VGEM:
......
......@@ -43,6 +43,7 @@
#define DRIVER_VGEM (1 << 2)
#define DRIVER_VIRTIO (1 << 3)
#define DRIVER_AMDGPU (1 << 4)
#define DRIVER_V3D (1 << 5)
/*
* Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system
* with vgem as well as a supported driver, you can end up with a
......
/*
* Copyright © 2016 Broadcom
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <assert.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include "drmtest.h"
#include "igt_aux.h"
#include "igt_core.h"
#include "igt_v3d.h"
#include "ioctl_wrappers.h"
#include "intel_reg.h"
#include "intel_chipset.h"
#include "v3d_drm.h"
#if NEW_CONTEXT_PARAM_NO_ERROR_CAPTURE_API
#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4
#endif
/**
* SECTION:igt_v3d
* @short_description: V3D support library
* @title: V3D
* @include: igt.h
*
* This library provides various auxiliary helper functions for writing V3D
* tests.
*/
struct v3d_bo *
igt_v3d_create_bo(int fd, size_t size)
{
struct v3d_bo *bo = calloc(1, sizeof(*bo));
struct drm_v3d_create_bo create = {
.size = size,
};
do_ioctl(fd, DRM_IOCTL_V3D_CREATE_BO, &create);
bo->handle = create.handle;
bo->offset = create.offset;
bo->size = size;
return bo;
}
void
igt_v3d_free_bo(int fd, struct v3d_bo *bo)
{
if (bo->map)
munmap(bo->map, bo->size);
gem_close(fd, bo->handle);
free(bo);
}
uint32_t
igt_v3d_get_bo_offset(int fd, uint32_t handle)
{
struct drm_v3d_get_bo_offset get = {
.handle = handle,
};
do_ioctl(fd, DRM_IOCTL_V3D_GET_BO_OFFSET, &get);
return get.offset;
}
uint32_t
igt_v3d_get_param(int fd, enum drm_v3d_param param)
{
struct drm_v3d_get_param get = {
.param = param,
};
do_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &get);
return get.value;
}
void *
igt_v3d_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot)
{
struct drm_v3d_mmap_bo mmap_bo = {
.handle = handle,
};
void *ptr;
do_ioctl(fd, DRM_IOCTL_V3D_MMAP_BO, &mmap_bo);
ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_bo.offset);
if (ptr == MAP_FAILED)
return NULL;
else
return ptr;
}
void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo)
{
bo->map = igt_v3d_mmap_bo(fd, bo->handle, bo->size,
PROT_READ | PROT_WRITE);
igt_assert(bo->map);
}
/*
* Copyright © 2016 Broadcom
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef IGT_V3D_H
#define IGT_V3D_H
#include "v3d_drm.h"
struct v3d_bo {
int handle;
uint32_t offset;
uint32_t size;
void *map;
};
struct v3d_bo *igt_v3d_create_bo(int fd, size_t size);
void igt_v3d_free_bo(int fd, struct v3d_bo *bo);
/* IOCTL wrappers */
uint32_t igt_v3d_get_bo_offset(int fd, uint32_t handle);
uint32_t igt_v3d_get_param(int fd, enum drm_v3d_param param);
void *igt_v3d_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot);
void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo);
#endif /* IGT_V3D_H */
......@@ -48,6 +48,7 @@ lib_sources = [
'igt_dummyload.c',
'uwildmat/uwildmat.c',
'igt_kmod.c',
'igt_v3d.c',
'igt_vc4.c',
'igt_psr.c',
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment