mirror of
				https://github.com/tiagovignatti/intel-gpu-tools.git
				synced 2025-11-04 03:58:27 +00:00 
			
		
		
		
	lib/drmtest: extract gem_mmap
Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
		
							parent
							
								
									7a6042e87e
								
							
						
					
					
						commit
						527cad1618
					
				@ -30,6 +30,7 @@
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <sys/ioctl.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
#include "drmtest.h"
 | 
			
		||||
#include "i915_drm.h"
 | 
			
		||||
#include "intel_chipset.h"
 | 
			
		||||
@ -202,3 +203,19 @@ uint32_t gem_create(int fd, int size)
 | 
			
		||||
	return create.handle;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt mmap_arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
 | 
			
		||||
	mmap_arg.handle = handle;
 | 
			
		||||
	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 | 
			
		||||
	if (ptr == MAP_FAILED)
 | 
			
		||||
		ptr = NULL;
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -45,3 +45,4 @@ void gem_set_domain(int fd, uint32_t handle,
 | 
			
		||||
		    uint32_t read_domains, uint32_t write_domain);
 | 
			
		||||
void gem_sync(int fd, uint32_t handle);
 | 
			
		||||
uint32_t gem_create(int fd, int size);
 | 
			
		||||
void *gem_mmap(int fd, uint32_t handle, int size, int prot);
 | 
			
		||||
 | 
			
		||||
@ -60,18 +60,9 @@
 | 
			
		||||
static void *
 | 
			
		||||
mmap_bo(int fd, uint32_t handle)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
	int ret;
 | 
			
		||||
 | 
			
		||||
	memset(&arg, 0, sizeof(arg));
 | 
			
		||||
 | 
			
		||||
	arg.handle = handle;
 | 
			
		||||
	ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &arg);
 | 
			
		||||
	assert(ret == 0);
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, 4096, PROT_READ | PROT_WRITE,
 | 
			
		||||
		   MAP_SHARED, fd, arg.offset);
 | 
			
		||||
	ptr = gem_mmap(fd, handle, 4096, PROT_READ | PROT_WRITE);
 | 
			
		||||
	assert(ptr != MAP_FAILED);
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
 | 
			
		||||
@ -45,22 +45,6 @@
 | 
			
		||||
 | 
			
		||||
#define OBJECT_SIZE 16384
 | 
			
		||||
 | 
			
		||||
static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt mmap_arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
 | 
			
		||||
	mmap_arg.handle = handle;
 | 
			
		||||
	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 | 
			
		||||
	if (ptr == MAP_FAILED)
 | 
			
		||||
		ptr = NULL;
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static double elapsed(const struct timeval *start,
 | 
			
		||||
		      const struct timeval *end,
 | 
			
		||||
		      int loop)
 | 
			
		||||
 | 
			
		||||
@ -50,18 +50,9 @@ static void set_domain(int fd, uint32_t handle)
 | 
			
		||||
static void *
 | 
			
		||||
mmap_bo(int fd, uint32_t handle)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
	int ret;
 | 
			
		||||
 | 
			
		||||
	memset(&arg, 0, sizeof(arg));
 | 
			
		||||
 | 
			
		||||
	arg.handle = handle;
 | 
			
		||||
	ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &arg);
 | 
			
		||||
	assert(ret == 0);
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,
 | 
			
		||||
		   MAP_SHARED, fd, arg.offset);
 | 
			
		||||
	ptr = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
 | 
			
		||||
	assert(ptr != MAP_FAILED);
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
 | 
			
		||||
@ -61,22 +61,6 @@ static int tile_width;
 | 
			
		||||
static int tile_height;
 | 
			
		||||
static int tile_size;
 | 
			
		||||
 | 
			
		||||
static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt mmap_arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
 | 
			
		||||
	mmap_arg.handle = handle;
 | 
			
		||||
	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 | 
			
		||||
	if (ptr == MAP_FAILED)
 | 
			
		||||
		ptr = NULL;
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@ -67,22 +67,6 @@ static uint32_t current_tiling_mode;
 | 
			
		||||
 | 
			
		||||
#define PAGE_SIZE 4096
 | 
			
		||||
 | 
			
		||||
static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt mmap_arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
 | 
			
		||||
	mmap_arg.handle = handle;
 | 
			
		||||
	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 | 
			
		||||
	if (ptr == MAP_FAILED)
 | 
			
		||||
		ptr = NULL;
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@ -428,26 +428,6 @@ retry:
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt mmap_arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
 | 
			
		||||
	mmap_arg.handle = handle;
 | 
			
		||||
	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg)) {
 | 
			
		||||
		assert(0);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 | 
			
		||||
	if (ptr == MAP_FAILED) {
 | 
			
		||||
		assert(0);
 | 
			
		||||
		ptr = NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint32_t
 | 
			
		||||
create_bo(int fd, uint32_t val, int tiling)
 | 
			
		||||
{
 | 
			
		||||
@ -460,6 +440,7 @@ create_bo(int fd, uint32_t val, int tiling)
 | 
			
		||||
 | 
			
		||||
	/* Fill the BO with dwords starting at val */
 | 
			
		||||
	v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ | PROT_WRITE);
 | 
			
		||||
	assert(v);
 | 
			
		||||
	for (i = 0; i < WIDTH*HEIGHT; i++)
 | 
			
		||||
		v[i] = val++;
 | 
			
		||||
	munmap(v, WIDTH*HEIGHT*4);
 | 
			
		||||
@ -474,6 +455,7 @@ check_bo(int fd, uint32_t handle, uint32_t val)
 | 
			
		||||
	int i;
 | 
			
		||||
 | 
			
		||||
	v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
 | 
			
		||||
	assert(v);
 | 
			
		||||
	for (i = 0; i < WIDTH*HEIGHT; i++) {
 | 
			
		||||
		if (v[i] != val) {
 | 
			
		||||
			fprintf(stderr, "Expected 0x%08x, found 0x%08x "
 | 
			
		||||
 | 
			
		||||
@ -317,26 +317,6 @@ copy(int fd,
 | 
			
		||||
	gem_close(fd, handle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt mmap_arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
 | 
			
		||||
	mmap_arg.handle = handle;
 | 
			
		||||
	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg)) {
 | 
			
		||||
		assert(0);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 | 
			
		||||
	if (ptr == MAP_FAILED) {
 | 
			
		||||
		assert(0);
 | 
			
		||||
		ptr = NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint32_t
 | 
			
		||||
create_bo(int fd, uint32_t val, int tiling)
 | 
			
		||||
{
 | 
			
		||||
@ -349,6 +329,7 @@ create_bo(int fd, uint32_t val, int tiling)
 | 
			
		||||
 | 
			
		||||
	/* Fill the BO with dwords starting at val */
 | 
			
		||||
	v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ | PROT_WRITE);
 | 
			
		||||
	assert(v);
 | 
			
		||||
	for (i = 0; i < WIDTH*HEIGHT; i++)
 | 
			
		||||
		v[i] = val++;
 | 
			
		||||
	munmap(v, WIDTH*HEIGHT*4);
 | 
			
		||||
@ -363,6 +344,7 @@ check_bo(int fd, uint32_t handle, uint32_t val)
 | 
			
		||||
	int i;
 | 
			
		||||
 | 
			
		||||
	v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
 | 
			
		||||
	assert(v);
 | 
			
		||||
	for (i = 0; i < WIDTH*HEIGHT; i++) {
 | 
			
		||||
		if (v[i] != val) {
 | 
			
		||||
			fprintf(stderr, "Expected 0x%08x, found 0x%08x "
 | 
			
		||||
 | 
			
		||||
@ -304,26 +304,6 @@ copy(int fd, uint32_t dst, uint32_t src)
 | 
			
		||||
	gem_close(fd, handle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt mmap_arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
 | 
			
		||||
	mmap_arg.handle = handle;
 | 
			
		||||
	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg)) {
 | 
			
		||||
		assert(0);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 | 
			
		||||
	if (ptr == MAP_FAILED) {
 | 
			
		||||
		assert(0);
 | 
			
		||||
		ptr = NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint32_t
 | 
			
		||||
create_bo(int fd, uint32_t val)
 | 
			
		||||
{
 | 
			
		||||
@ -336,6 +316,7 @@ create_bo(int fd, uint32_t val)
 | 
			
		||||
 | 
			
		||||
	/* Fill the BO with dwords starting at val */
 | 
			
		||||
	v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ | PROT_WRITE);
 | 
			
		||||
	assert(v);
 | 
			
		||||
	for (i = 0; i < WIDTH*HEIGHT; i++)
 | 
			
		||||
		v[i] = val++;
 | 
			
		||||
	munmap(v, WIDTH*HEIGHT*4);
 | 
			
		||||
@ -350,6 +331,7 @@ check_bo(int fd, uint32_t handle, uint32_t val)
 | 
			
		||||
	int i;
 | 
			
		||||
 | 
			
		||||
	v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
 | 
			
		||||
	assert(v);
 | 
			
		||||
	for (i = 0; i < WIDTH*HEIGHT; i++) {
 | 
			
		||||
		if (v[i] != val) {
 | 
			
		||||
			fprintf(stderr, "Expected 0x%08x, found 0x%08x "
 | 
			
		||||
 | 
			
		||||
@ -304,26 +304,6 @@ copy(int fd, uint32_t dst, uint32_t src)
 | 
			
		||||
	gem_close(fd, handle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt mmap_arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
 | 
			
		||||
	mmap_arg.handle = handle;
 | 
			
		||||
	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg)) {
 | 
			
		||||
		assert(0);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 | 
			
		||||
	if (ptr == MAP_FAILED) {
 | 
			
		||||
		assert(0);
 | 
			
		||||
		ptr = NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint32_t
 | 
			
		||||
create_bo(int fd, uint32_t val)
 | 
			
		||||
{
 | 
			
		||||
@ -336,6 +316,7 @@ create_bo(int fd, uint32_t val)
 | 
			
		||||
 | 
			
		||||
	/* Fill the BO with dwords starting at val */
 | 
			
		||||
	v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ | PROT_WRITE);
 | 
			
		||||
	assert(v);
 | 
			
		||||
	for (i = 0; i < WIDTH*HEIGHT; i++)
 | 
			
		||||
		v[i] = val++;
 | 
			
		||||
	munmap(v, WIDTH*HEIGHT*4);
 | 
			
		||||
@ -350,6 +331,7 @@ check_bo(int fd, uint32_t handle, uint32_t val)
 | 
			
		||||
	int i;
 | 
			
		||||
 | 
			
		||||
	v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
 | 
			
		||||
	assert(v);
 | 
			
		||||
	for (i = 0; i < WIDTH*HEIGHT; i++) {
 | 
			
		||||
		if (v[i] != val) {
 | 
			
		||||
			fprintf(stderr, "Expected 0x%08x, found 0x%08x "
 | 
			
		||||
 | 
			
		||||
@ -384,22 +384,6 @@ static void connector_find_preferred_mode(struct connector *c)
 | 
			
		||||
	c->connector = connector;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
 | 
			
		||||
{
 | 
			
		||||
	struct drm_i915_gem_mmap_gtt mmap_arg;
 | 
			
		||||
	void *ptr;
 | 
			
		||||
 | 
			
		||||
	mmap_arg.handle = handle;
 | 
			
		||||
	if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 | 
			
		||||
	if (ptr == MAP_FAILED)
 | 
			
		||||
		ptr = NULL;
 | 
			
		||||
 | 
			
		||||
	return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static cairo_surface_t *
 | 
			
		||||
allocate_surface(int fd, int width, int height, uint32_t depth,
 | 
			
		||||
		 uint32_t *handle, int tiled)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user