[igt-dev] [PATCH i-g-t v31 13/40] lib/intel_bufops: Add init with handle and size function
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Mon Apr 12 10:31:20 UTC 2021
For some cases (fb with compression) fb size is bigger than calculated
intel_buf what lead to execbuf failure when allocator is used
along with EXEC_OBJECT_PINNED flag set for all objects.
We need to create intel_buf with size equal to fb so new function
in which we pass handle and size is required.
v2: add bo_size check to better protect input size (Jason)
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
Acked-by: Daniel Vetter <daniel.vetter at ffwll.ch>
---
lib/intel_bufops.c | 34 +++++++++++++++++++++++++++++++---
lib/intel_bufops.h | 7 +++++++
2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/lib/intel_bufops.c b/lib/intel_bufops.c
index eb5ac4dad..00be2bd04 100644
--- a/lib/intel_bufops.c
+++ b/lib/intel_bufops.c
@@ -708,7 +708,8 @@ static void __intel_buf_init(struct buf_ops *bops,
uint32_t handle,
struct intel_buf *buf,
int width, int height, int bpp, int alignment,
- uint32_t req_tiling, uint32_t compression)
+ uint32_t req_tiling, uint32_t compression,
+ uint64_t bo_size)
{
uint32_t tiling = req_tiling;
uint64_t size;
@@ -776,6 +777,11 @@ static void __intel_buf_init(struct buf_ops *bops,
size = buf->surface[0].stride * ALIGN(height, align_h);
}
+ if (bo_size > 0) {
+ igt_assert(bo_size >= size);
+ size = bo_size;
+ }
+
/* Store real bo size to avoid mistakes in calculating it again */
buf->size = size;
@@ -809,7 +815,7 @@ void intel_buf_init(struct buf_ops *bops,
uint32_t tiling, uint32_t compression)
{
__intel_buf_init(bops, 0, buf, width, height, bpp, alignment,
- tiling, compression);
+ tiling, compression, 0);
intel_buf_set_ownership(buf, true);
}
@@ -858,7 +864,7 @@ void intel_buf_init_using_handle(struct buf_ops *bops,
uint32_t req_tiling, uint32_t compression)
{
__intel_buf_init(bops, handle, buf, width, height, bpp, alignment,
- req_tiling, compression);
+ req_tiling, compression, 0);
}
/**
@@ -927,6 +933,28 @@ struct intel_buf *intel_buf_create_using_handle(struct buf_ops *bops,
return buf;
}
+struct intel_buf *intel_buf_create_using_handle_and_size(struct buf_ops *bops,
+ uint32_t handle,
+ int width, int height,
+ int bpp, int alignment,
+ uint32_t req_tiling,
+ uint32_t compression,
+ uint64_t size)
+{
+ struct intel_buf *buf;
+
+ igt_assert(bops);
+
+ buf = calloc(1, sizeof(*buf));
+ igt_assert(buf);
+
+ __intel_buf_init(bops, handle, buf, width, height, bpp, alignment,
+ req_tiling, compression, size);
+
+ return buf;
+}
+
+
/**
* intel_buf_destroy
* @buf: intel_buf
diff --git a/lib/intel_bufops.h b/lib/intel_bufops.h
index 5619fc6fa..54480bff6 100644
--- a/lib/intel_bufops.h
+++ b/lib/intel_bufops.h
@@ -139,6 +139,13 @@ struct intel_buf *intel_buf_create_using_handle(struct buf_ops *bops,
uint32_t req_tiling,
uint32_t compression);
+struct intel_buf *intel_buf_create_using_handle_and_size(struct buf_ops *bops,
+ uint32_t handle,
+ int width, int height,
+ int bpp, int alignment,
+ uint32_t req_tiling,
+ uint32_t compression,
+ uint64_t size);
void intel_buf_destroy(struct intel_buf *buf);
void *intel_buf_cpu_map(struct intel_buf *buf, bool write);
--
2.26.0
More information about the igt-dev
mailing list