diff options
author | Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> | 2020-09-11 10:07:18 +0200 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2020-09-16 14:14:54 +0100 |
commit | 3b2687ee148399e192cba971036fab4198b387fd (patch) | |
tree | b0292daef11e8d9bc67691ccd9bd75b11c06da37 /lib/intel_bufops.c | |
parent | 222051026b978ebbc0dc58db62d7a1f29728f95f (diff) |
lib/intel_bufops: add mapping on cpu / device
Simplify mapping intel_buf. To be extended with ref counting.
Add intel_buf dump function for easy dump buffer to the file.
Fixing returned type of bo size function.
Idempotency selftest is now skipped for default buf_ops creation
to avoid time consuming comparison of HW and SW tiled buffers
(this can be the problem for forked tests). Additional function
buf_ops_create_with_selftest() was added to allow perform
verification step where it is required.
Changing alignment from 4->2 (required for 16bpp render).
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/intel_bufops.c')
-rw-r--r-- | lib/intel_bufops.c | 126 |
1 files changed, 111 insertions, 15 deletions
diff --git a/lib/intel_bufops.c b/lib/intel_bufops.c index 2a48fb0c..49f59573 100644 --- a/lib/intel_bufops.c +++ b/lib/intel_bufops.c @@ -704,7 +704,7 @@ static void __intel_buf_init(struct buf_ops *bops, igt_assert(buf); igt_assert(width > 0 && height > 0); igt_assert(bpp == 8 || bpp == 16 || bpp == 32); - igt_assert(alignment % 4 == 0); + igt_assert(alignment >= 0); memset(buf, 0, sizeof(*buf)); @@ -757,7 +757,7 @@ static void __intel_buf_init(struct buf_ops *bops, buf->surface[0].stride = ALIGN(width * (bpp / 8), tile_width); } else { - buf->surface[0].stride = ALIGN(width * (bpp / 8), alignment ?: 4); + buf->surface[0].stride = ALIGN(width * (bpp / 8), alignment ?: 1); } buf->surface[0].size = buf->surface[0].stride * height; @@ -865,11 +865,69 @@ struct intel_buf *intel_buf_create(struct buf_ops *bops, void intel_buf_destroy(struct intel_buf *buf) { igt_assert(buf); + igt_assert(buf->ptr == NULL); intel_buf_close(buf->bops, buf); free(buf); } +void *intel_buf_cpu_map(struct intel_buf *buf, bool write) +{ + int i915 = buf_ops_get_fd(buf->bops); + + igt_assert(buf); + igt_assert(buf->ptr == NULL); /* already mapped */ + + buf->cpu_write = write; + buf->ptr = gem_mmap__cpu_coherent(i915, buf->handle, 0, + buf->surface[0].size, + write ? PROT_WRITE : PROT_READ); + + gem_set_domain(i915, buf->handle, + I915_GEM_DOMAIN_CPU, + write ? I915_GEM_DOMAIN_CPU : 0); + + return buf->ptr; +} + +void *intel_buf_device_map(struct intel_buf *buf, bool write) +{ + int i915 = buf_ops_get_fd(buf->bops); + + igt_assert(buf); + igt_assert(buf->ptr == NULL); /* already mapped */ + + buf->ptr = gem_mmap__device_coherent(i915, buf->handle, 0, + buf->surface[0].size, + write ? PROT_WRITE : PROT_READ); + + gem_set_domain(i915, buf->handle, + I915_GEM_DOMAIN_WC, + write ? I915_GEM_DOMAIN_WC : 0); + + return buf->ptr; +} + +void intel_buf_unmap(struct intel_buf *buf) +{ + igt_assert(buf); + igt_assert(buf->ptr); + + munmap(buf->ptr, buf->surface[0].size); + buf->ptr = NULL; +} + +void intel_buf_flush_and_unmap(struct intel_buf *buf) +{ + igt_assert(buf); + igt_assert(buf->ptr); + + if (buf->cpu_write) + gem_sw_finish(buf_ops_get_fd(buf->bops), buf->handle); + + intel_buf_unmap(buf); +} + void intel_buf_print(const struct intel_buf *buf) { igt_info("[name: %s]\n", buf->name); @@ -888,6 +946,21 @@ void intel_buf_print(const struct intel_buf *buf) from_user_pointer(buf->addr.offset), buf->addr.ctx); } +void intel_buf_dump(const struct intel_buf *buf, const char *filename) +{ + int i915 = buf_ops_get_fd(buf->bops); + uint64_t size = intel_buf_bo_size(buf); + FILE *out; + void *ptr; + + ptr = gem_mmap__device_coherent(i915, buf->handle, 0, size, PROT_READ); + out = fopen(filename, "wb"); + igt_assert(out); + fwrite(ptr, size, 1, out); + fclose(out); + munmap(ptr, size); +} + const char *intel_buf_set_name(struct intel_buf *buf, const char *name) { return strncpy(buf->name, name, INTEL_BUF_NAME_MAXSIZE); @@ -1066,7 +1139,7 @@ static void idempotency_selftest(struct buf_ops *bops, uint32_t tiling) buf_ops_set_software_tiling(bops, tiling, false); } -int intel_buf_bo_size(const struct intel_buf *buf) +uint32_t intel_buf_bo_size(const struct intel_buf *buf) { int offset = CCS_OFFSET(buf) ?: buf->surface[0].size; int ccs_size = @@ -1075,16 +1148,7 @@ int intel_buf_bo_size(const struct intel_buf *buf) return offset + ccs_size; } -/** - * buf_ops_create - * @fd: device filedescriptor - * - * Create buf_ops structure depending on fd-device capabilities. - * - * Returns: opaque pointer to buf_ops. - * - */ -struct buf_ops *buf_ops_create(int fd) +static struct buf_ops *__buf_ops_create(int fd, bool check_idempotency) { struct buf_ops *bops = calloc(1, sizeof(*bops)); uint32_t devid; @@ -1161,13 +1225,45 @@ struct buf_ops *buf_ops_create(int fd) bops->ys_to_linear = NULL; } - idempotency_selftest(bops, I915_TILING_X); - idempotency_selftest(bops, I915_TILING_Y); + if (check_idempotency) { + idempotency_selftest(bops, I915_TILING_X); + idempotency_selftest(bops, I915_TILING_Y); + } return bops; } /** + * buf_ops_create + * @fd: device filedescriptor + * + * Create buf_ops structure depending on fd-device capabilities. + * + * Returns: opaque pointer to buf_ops. + * + */ +struct buf_ops *buf_ops_create(int fd) +{ + return __buf_ops_create(fd, false); +} + +/** + * buf_ops_create_with_selftest + * @fd: device filedescriptor + * + * Create buf_ops structure depending on fd-device capabilities. + * Runs with idempotency selftest to verify software tiling gives same + * result like hardware tiling (gens with mappable gtt). + * + * Returns: opaque pointer to buf_ops. + * + */ +struct buf_ops *buf_ops_create_with_selftest(int fd) +{ + return __buf_ops_create(fd, true); +} + +/** * buf_ops_destroy * @bops: pointer to buf_ops * |