Commit aa67b22e authored by Daniel Vetter's avatar Daniel Vetter

lib/drmtest: extract gem_set_tiling

Way too much copy-pasting going on here.

Also fix a compiler warnings in gem_stress while fixup things up.
Signed-off-by: Daniel Vetter's avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 1be3fd7e
/*
* Copyright © 2007 Intel Corporation
* Copyright © 2007, 2011 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
......@@ -22,16 +22,21 @@
*
* Authors:
* Eric Anholt <eric@anholt.net>
* Daniel Vetter <daniel.vetter@ffwll.ch>
*
*/
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <string.h>
#include "drmtest.h"
#include "i915_drm.h"
#include "intel_chipset.h"
/* This file contains a bunch of wrapper functions to directly use gem ioctls.
* Mostly useful to write kernel tests. */
static int
is_intel(int fd)
{
......@@ -110,3 +115,22 @@ int drm_open_any_master(void)
fprintf(stderr, "Couldn't find an un-controlled DRM device\n");
abort();
}
void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride)
{
struct drm_i915_gem_set_tiling st;
int ret;
memset(&st, 0, sizeof(st));
do {
st.handle = handle;
st.tiling_mode = tiling;
st.stride = tiling ? stride : 0;
ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &st);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
assert(ret == 0);
assert(st.tiling_mode == tiling);
}
......@@ -35,3 +35,6 @@
int drm_open_any(void);
int drm_open_any_master(void);
void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride);
......@@ -98,20 +98,6 @@ static int gem_read(int fd,
return drmIoctl(fd, DRM_IOCTL_I915_GEM_PREAD, &pread);
}
static void gem_set_tiling(int fd, uint32_t handle, int tiling)
{
struct drm_i915_gem_set_tiling set_tiling;
int ret;
do {
set_tiling.handle = handle;
set_tiling.tiling_mode = tiling;
set_tiling.stride = 512;
ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
}
static void gem_close(int fd, uint32_t handle)
{
struct drm_gem_close close;
......@@ -165,7 +151,7 @@ int main(int argc, char **argv)
if (tiling != I915_TILING_NONE) {
printf("\nSetting tiling mode to %s\n",
tiling == I915_TILING_X ? "X" : "Y");
gem_set_tiling(fd, handle, tiling);
gem_set_tiling(fd, handle, tiling, 512);
}
if (tiling == I915_TILING_NONE) {
......
......@@ -188,14 +188,14 @@ void keep_gpu_busy(void)
busy_bo, 0, 4096, 0, 128);
}
static void set_to_cpu_domain(struct scratch_buf *buf, int write)
static void set_to_cpu_domain(struct scratch_buf *buf, int writing)
{
struct drm_i915_gem_set_domain set_domain;
int ret;
set_domain.handle = buf->bo->handle;
set_domain.read_domains = I915_GEM_DOMAIN_CPU;
if (write)
if (writing)
set_domain.write_domain = I915_GEM_DOMAIN_CPU;
else
set_domain.write_domain = 0;
......@@ -522,32 +522,6 @@ static void exchange_buf(void *array, unsigned i, unsigned j)
}
/* libdrm is too clever and prevents us from changing tiling of buffers already
* used in relocations. */
static void set_tiling(drm_intel_bo *bo, unsigned *tiling, unsigned stride)
{
struct drm_i915_gem_set_tiling set_tiling;
int ret;
memset(&set_tiling, 0, sizeof(set_tiling));
do {
/* set_tiling is slightly broken and overwrites the
* input on the error path, so we have to open code
* drmIoctl.
*/
set_tiling.handle = bo->handle;
set_tiling.tiling_mode = *tiling;
set_tiling.stride = tiling ? stride : 0;
ret = ioctl(drm_fd,
DRM_IOCTL_I915_GEM_SET_TILING,
&set_tiling);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
assert(ret != -1);
*tiling = set_tiling.tiling_mode;
}
static void init_set(unsigned set)
{
long int r;
......@@ -591,9 +565,9 @@ static void init_set(unsigned set)
sanitize_stride(&buffers[set][i]);
set_tiling(buffers[set][i].bo,
&buffers[set][i].tiling,
buffers[set][i].stride);
gem_set_tiling(drm_fd, buffers[set][i].bo->handle,
buffers[set][i].tiling,
buffers[set][i].stride);
if (options.trace_tile != -1 && i == options.trace_tile/options.tiles_per_buf)
printf("changing buffer %i containing tile %i: tiling %i, stride %i\n", i,
......@@ -857,11 +831,8 @@ static void init(void)
batch = intel_batchbuffer_alloc(bufmgr, devid);
busy_bo = drm_intel_bo_alloc(bufmgr, "tiled bo", BUSY_BUF_SIZE, 4096);
if (options.forced_tiling >= 0) {
tmp = options.forced_tiling;
set_tiling(busy_bo, &tmp, 4096);
assert(tmp == options.forced_tiling);
}
if (options.forced_tiling >= 0)
gem_set_tiling(drm_fd, busy_bo->handle, options.forced_tiling, 4096);
for (i = 0; i < num_buffers; i++) {
init_buffer(&buffers[0][i], options.scratch_buf_size);
......
......@@ -103,21 +103,6 @@ gem_read(int fd, uint32_t handle, int offset, int length, void *buf)
assert(ret == 0);
}
static void
gem_set_tiling(int fd, uint32_t handle, int tiling)
{
struct drm_i915_gem_set_tiling set_tiling;
int ret;
do {
set_tiling.handle = handle;
set_tiling.tiling_mode = tiling;
set_tiling.stride = WIDTH * sizeof(uint32_t);
ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
}
static void
gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle)
{
......@@ -142,7 +127,7 @@ create_bo(int fd)
int i;
handle = gem_create(fd, sizeof(linear));
gem_set_tiling(fd, handle, I915_TILING_X);
gem_set_tiling(fd, handle, I915_TILING_X, WIDTH * sizeof(uint32_t));
/* Fill the BO with dwords starting at start_val */
data = gem_mmap(fd, handle, sizeof(linear), PROT_READ | PROT_WRITE);
......
......@@ -122,21 +122,6 @@ gem_read(int fd, uint32_t handle, int offset, int length, void *buf)
assert(ret == 0);
}
static void
gem_set_tiling(int fd, uint32_t handle, int tiling)
{
struct drm_i915_gem_set_tiling set_tiling;
int ret;
do {
set_tiling.handle = handle;
set_tiling.tiling_mode = tiling;
set_tiling.stride = WIDTH * sizeof(uint32_t);
ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
}
static void
gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle)
{
......@@ -161,7 +146,7 @@ create_bo_and_fill(int fd)
int i;
handle = gem_create(fd, sizeof(linear));
gem_set_tiling(fd, handle, current_tiling_mode);
gem_set_tiling(fd, handle, current_tiling_mode, WIDTH * sizeof(uint32_t));
/* Fill the BO with dwords starting at start_val */
data = gem_mmap(fd, handle, sizeof(linear), PROT_READ | PROT_WRITE);
......@@ -178,7 +163,7 @@ create_bo(int fd)
uint32_t handle;
handle = gem_create(fd, sizeof(linear));
gem_set_tiling(fd, handle, current_tiling_mode);
gem_set_tiling(fd, handle, current_tiling_mode, WIDTH * sizeof(uint32_t));
return handle;
}
......
......@@ -484,22 +484,6 @@ static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
return ptr;
}
static void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride)
{
struct drm_i915_gem_set_tiling set_tiling;
int ret;
do {
set_tiling.handle = handle;
set_tiling.tiling_mode = tiling;
set_tiling.stride = stride;
ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
assert(ret == 0);
assert(set_tiling.tiling_mode == tiling);
}
static uint32_t
create_bo(int fd, uint32_t val, int tiling)
{
......
......@@ -373,22 +373,6 @@ static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
return ptr;
}
static void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride)
{
struct drm_i915_gem_set_tiling set_tiling;
int ret;
do {
set_tiling.handle = handle;
set_tiling.tiling_mode = tiling;
set_tiling.stride = stride;
ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
assert(ret == 0);
assert(set_tiling.tiling_mode == tiling);
}
static uint32_t
create_bo(int fd, uint32_t val, int tiling)
{
......
......@@ -360,22 +360,6 @@ static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
return ptr;
}
static void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride)
{
struct drm_i915_gem_set_tiling set_tiling;
int ret;
do {
set_tiling.handle = handle;
set_tiling.tiling_mode = tiling;
set_tiling.stride = stride;
ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
assert(ret == 0);
assert(set_tiling.tiling_mode == tiling);
}
static uint32_t
create_bo(int fd, uint32_t val)
{
......
......@@ -360,22 +360,6 @@ static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
return ptr;
}
static void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride)
{
struct drm_i915_gem_set_tiling set_tiling;
int ret;
do {
set_tiling.handle = handle;
set_tiling.tiling_mode = tiling;
set_tiling.stride = stride;
ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
assert(ret == 0);
assert(set_tiling.tiling_mode == tiling);
}
static uint32_t
create_bo(int fd, uint32_t val)
{
......
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