igt: Add a helper function for mapping VC4 BOs.

v2: Use do_ioctl().

Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
Eric Anholt 2016-01-25 10:01:35 -08:00
parent 4880e13d04
commit b8badc2436
2 changed files with 19 additions and 0 deletions

View File

@ -25,6 +25,7 @@
#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>
@ -101,3 +102,20 @@ uint32_t igt_vc4_get_cleared_bo(int fd, size_t size, uint32_t clearval)
return create.handle;
}
void *
igt_vc4_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot)
{
struct drm_vc4_mmap_bo mmap_bo = {
.handle = handle,
};
void *ptr;
do_ioctl(fd, DRM_IOCTL_VC4_MMAP_BO, &mmap_bo);
ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_bo.offset);
if (ptr == MAP_FAILED)
return NULL;
else
return ptr;
}

View File

@ -25,5 +25,6 @@
#define IGT_VC4_H
uint32_t igt_vc4_get_cleared_bo(int fd, size_t size, uint32_t clearval);
void *igt_vc4_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot);
#endif /* IGT_VC4_H */