@@ -554,6 +554,81 @@ int gem_madvise(int fd, uint32_t handle, int state)
return madv.retained;
}
+
+int gem_linear_blt(uint32_t *batch,
+ uint32_t src,
+ uint32_t dst,
+ uint32_t length,
+ struct drm_i915_gem_relocation_entry *reloc)
+{
+ uint32_t *b = batch;
+ int height = length / (16 * 1024);
+
+ assert(height <= 1<<16);
+
+ if (height) {
+ b[0] = XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA | XY_SRC_COPY_BLT_WRITE_RGB;
+ b[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (16*1024);
+ b[2] = 0;
+ b[3] = height << 16 | (4*1024);
+ b[4] = 0;
+ reloc->offset = (b-batch+4) * sizeof(uint32_t);
+ reloc->delta = 0;
+ reloc->target_handle = dst;
+ reloc->read_domains = I915_GEM_DOMAIN_RENDER;
+ reloc->write_domain = I915_GEM_DOMAIN_RENDER;
+ reloc->presumed_offset = 0;
+ reloc++;
+
+ b[5] = 0;
+ b[6] = 16*1024;
+ b[7] = 0;
+ reloc->offset = (b-batch+7) * sizeof(uint32_t);
+ reloc->delta = 0;
+ reloc->target_handle = src;
+ reloc->read_domains = I915_GEM_DOMAIN_RENDER;
+ reloc->write_domain = 0;
+ reloc->presumed_offset = 0;
+ reloc++;
+
+ b += 8;
+ length -= height * 16*1024;
+ }
+
+ if (length) {
+ b[0] = XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA | XY_SRC_COPY_BLT_WRITE_RGB;
+ b[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (16*1024);
+ b[2] = height << 16;
+ b[3] = (1+height) << 16 | (length / 4);
+ b[4] = 0;
+ reloc->offset = (b-batch+4) * sizeof(uint32_t);
+ reloc->delta = 0;
+ reloc->target_handle = dst;
+ reloc->read_domains = I915_GEM_DOMAIN_RENDER;
+ reloc->write_domain = I915_GEM_DOMAIN_RENDER;
+ reloc->presumed_offset = 0;
+ reloc++;
+
+ b[5] = height << 16;
+ b[6] = 16*1024;
+ b[7] = 0;
+ reloc->offset = (b-batch+7) * sizeof(uint32_t);
+ reloc->delta = 0;
+ reloc->target_handle = src;
+ reloc->read_domains = I915_GEM_DOMAIN_RENDER;
+ reloc->write_domain = 0;
+ reloc->presumed_offset = 0;
+ reloc++;
+
+ b += 8;
+ }
+
+ b[0] = MI_BATCH_BUFFER_END;
+ b[1] = 0;
+
+ return (b+2 - batch) * sizeof(uint32_t);
+}
+
/* prime */
int prime_handle_to_fd(int fd, uint32_t handle)
{
@@ -36,6 +36,7 @@
#include "xf86drm.h"
#include "xf86drmMode.h"
#include "intel_batchbuffer.h"
+#include "i915_drm.h"
drm_intel_bo * gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd,
const char *name, uint32_t handle);
@@ -72,6 +73,10 @@ uint64_t gem_aperture_size(int fd);
uint64_t gem_mappable_aperture_size(void);
int gem_madvise(int fd, uint32_t handle, int state);
+int gem_linear_blt(uint32_t *batch, uint32_t src,
+ uint32_t dst, uint32_t length,
+ struct drm_i915_gem_relocation_entry *reloc);
+
/* feature test helpers */
bool gem_uses_aliasing_ppgtt(int fd);
int gem_available_fences(int fd);
@@ -46,94 +46,14 @@
#define OBJECT_SIZE 16384
-#define COPY_BLT_CMD (2<<29|0x53<<22|0x6)
-#define BLT_WRITE_ALPHA (1<<21)
-#define BLT_WRITE_RGB (1<<20)
-#define BLT_SRC_TILED (1<<15)
-#define BLT_DST_TILED (1<<11)
-
-static int gem_linear_blt(uint32_t *batch,
- uint32_t src,
- uint32_t dst,
- uint32_t length,
- struct drm_i915_gem_relocation_entry *reloc)
-{
- uint32_t *b = batch;
- int height = length / (16 * 1024);
-
- assert(height <= 1<<16);
-
- if (height) {
- b[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
- b[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (16*1024);
- b[2] = 0;
- b[3] = height << 16 | (4*1024);
- b[4] = 0;
- reloc->offset = (b-batch+4) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = dst;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = I915_GEM_DOMAIN_RENDER;
- reloc->presumed_offset = 0;
- reloc++;
-
- b[5] = 0;
- b[6] = 16*1024;
- b[7] = 0;
- reloc->offset = (b-batch+7) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = src;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = 0;
- reloc->presumed_offset = 0;
- reloc++;
-
- b += 8;
- length -= height * 16*1024;
- }
-
- if (length) {
- b[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
- b[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (16*1024);
- b[2] = height << 16;
- b[3] = (1+height) << 16 | (length / 4);
- b[4] = 0;
- reloc->offset = (b-batch+4) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = dst;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = I915_GEM_DOMAIN_RENDER;
- reloc->presumed_offset = 0;
- reloc++;
-
- b[5] = height << 16;
- b[6] = 16*1024;
- b[7] = 0;
- reloc->offset = (b-batch+7) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = src;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = 0;
- reloc->presumed_offset = 0;
- reloc++;
-
- b += 8;
- }
-
- b[0] = MI_BATCH_BUFFER_END;
- b[1] = 0;
-
- return (b+2 - batch) * sizeof(uint32_t);
-}
-
static int gem_exec(int fd, struct drm_i915_gem_execbuffer2 *execbuf, int loops)
{
int ret = 0;
while (loops-- && ret == 0) {
ret = drmIoctl(fd,
- DRM_IOCTL_I915_GEM_EXECBUFFER2,
- execbuf);
+ DRM_IOCTL_I915_GEM_EXECBUFFER2,
+ execbuf);
}
return ret;
@@ -51,93 +51,13 @@
#define OBJECT_SIZE 16384
-#define COPY_BLT_CMD (2<<29|0x53<<22|0x6)
-#define BLT_WRITE_ALPHA (1<<21)
-#define BLT_WRITE_RGB (1<<20)
-#define BLT_SRC_TILED (1<<15)
-#define BLT_DST_TILED (1<<11)
-
-static int gem_linear_blt(uint32_t *batch,
- uint32_t src,
- uint32_t dst,
- uint32_t length,
- struct drm_i915_gem_relocation_entry *reloc)
-{
- uint32_t *b = batch;
- int height = length / (16 * 1024);
-
- assert(height <= 1<<16);
-
- if (height) {
- b[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
- b[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (16*1024);
- b[2] = 0;
- b[3] = height << 16 | (4*1024);
- b[4] = 0;
- reloc->offset = (b-batch+4) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = dst;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = I915_GEM_DOMAIN_RENDER;
- reloc->presumed_offset = 0;
- reloc++;
-
- b[5] = 0;
- b[6] = 16*1024;
- b[7] = 0;
- reloc->offset = (b-batch+7) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = src;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = 0;
- reloc->presumed_offset = 0;
- reloc++;
-
- b += 8;
- length -= height * 16*1024;
- }
-
- if (length) {
- b[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
- b[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (16*1024);
- b[2] = height << 16;
- b[3] = (1+height) << 16 | (length / 4);
- b[4] = 0;
- reloc->offset = (b-batch+4) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = dst;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = I915_GEM_DOMAIN_RENDER;
- reloc->presumed_offset = 0;
- reloc++;
-
- b[5] = height << 16;
- b[6] = 16*1024;
- b[7] = 0;
- reloc->offset = (b-batch+7) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = src;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = 0;
- reloc->presumed_offset = 0;
- reloc++;
-
- b += 8;
- }
-
- b[0] = MI_BATCH_BUFFER_END;
- b[1] = 0;
-
- return (b+2 - batch) * sizeof(uint32_t);
-}
-
static void gem_exec(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
{
int ret;
ret = drmIoctl(fd,
- DRM_IOCTL_I915_GEM_EXECBUFFER2,
- execbuf);
+ DRM_IOCTL_I915_GEM_EXECBUFFER2,
+ execbuf);
assert(ret == 0);
}
@@ -42,10 +42,6 @@
#include "intel_chipset.h"
#include "intel_gpu_tools.h"
-#define COPY_BLT_CMD (2<<29|0x53<<22|0x6)
-#define BLT_WRITE_ALPHA (1<<21)
-#define BLT_WRITE_RGB (1<<20)
-
static void exec(int fd, uint32_t handle, uint32_t offset)
{
struct drm_i915_gem_execbuffer2 execbuf;
@@ -84,46 +80,6 @@ static void exec(int fd, uint32_t handle, uint32_t offset)
assert(gem_exec[0].offset == offset);
}
-static int gem_linear_blt(uint32_t *batch,
- uint32_t src,
- uint32_t dst,
- uint32_t length,
- struct drm_i915_gem_relocation_entry *reloc)
-{
- uint32_t *b = batch;
-
- b[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
- b[1] = 0x66 << 16 | 1 << 25 | 1 << 24 | (4*1024);
- b[2] = 0;
- b[3] = (length / (4*1024)) << 16 | 1024;
- b[4] = 0;
- reloc->offset = (b-batch+4) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = dst;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = I915_GEM_DOMAIN_RENDER;
- reloc->presumed_offset = 0;
- reloc++;
-
- b[5] = 0;
- b[6] = 4*1024;
- b[7] = 0;
- reloc->offset = (b-batch+7) * sizeof(uint32_t);
- reloc->delta = 0;
- reloc->target_handle = src;
- reloc->read_domains = I915_GEM_DOMAIN_RENDER;
- reloc->write_domain = 0;
- reloc->presumed_offset = 0;
- reloc++;
-
- b += 8;
-
- b[0] = MI_BATCH_BUFFER_END;
- b[1] = 0;
-
- return (b+2 - batch) * sizeof(uint32_t);
-}
-
static void make_busy(int fd, uint32_t handle)
{
struct drm_i915_gem_execbuffer2 execbuf;
@@ -131,9 +87,10 @@ static void make_busy(int fd, uint32_t handle)
struct drm_i915_gem_relocation_entry reloc[2];
uint32_t batch[20];
uint32_t tmp;
- int count;
+ int count, len;
tmp = gem_create(fd, 1024*1024);
+ len = gem_linear_blt(batch, tmp, tmp, 1024*1024, reloc);
obj[0].handle = tmp;
obj[0].relocation_count = 0;
@@ -145,7 +102,7 @@ static void make_busy(int fd, uint32_t handle)
obj[0].rsvd2 = 0;
obj[1].handle = handle;
- obj[1].relocation_count = 2;
+ obj[1].relocation_count = len > 40 ? 4 : 2;
obj[1].relocs_ptr = (uintptr_t) reloc;
obj[1].alignment = 0;
obj[1].offset = 0;
@@ -156,7 +113,7 @@ static void make_busy(int fd, uint32_t handle)
execbuf.buffers_ptr = (uintptr_t)obj;
execbuf.buffer_count = 2;
execbuf.batch_start_offset = 0;
- execbuf.batch_len = gem_linear_blt(batch, tmp, tmp, 1024*1024,reloc);
+ execbuf.batch_len = len;
execbuf.cliprects_ptr = 0;
execbuf.num_cliprects = 0;
execbuf.DR1 = 0;
Several test functions will call gem_linear_blt(), so move this function to drm_test.c. Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.com> --- lib/drmtest.c | 75 ++++++++++++++++++++++++++++++++++++ lib/drmtest.h | 5 +++ tests/gem_exec_blt.c | 84 +---------------------------------------- tests/gem_exec_faulting_reloc.c | 84 +---------------------------------------- tests/gem_pin.c | 51 ++----------------------- 5 files changed, 88 insertions(+), 211 deletions(-)