lib/drmtest: extract gem_mmap

Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Daniel Vetter
2012-01-10 18:41:46 +01:00
parent 7a6042e87e
commit 527cad1618
12 changed files with 28 additions and 164 deletions
+2 -20
View File
@@ -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 "