diff options
author | Kalamarz, Lukasz <lukasz.kalamarz@intel.com> | 2018-04-24 10:32:12 +0200 |
---|---|---|
committer | MichaĆ Winiarski <michal.winiarski@intel.com> | 2018-04-24 13:11:18 +0200 |
commit | e5e8dafc991ee922ec159491c680caff0cfe9235 (patch) | |
tree | 496aaa79dd03fbbf8f4fba918be3a66f4c62feee /lib/intel_batchbuffer.c | |
parent | 25c75f879c43d7456960d656b69b4f10adca187d (diff) |
lib/intel_batchbuffer: Move batch functions from media/render/gpgpu libs
Batch functions were copy/pasted across several libs.
With moving it into intel_batchbuffer lib test can now be
easly maintained without worrying that we forgot to modify
older version of lib.
v2: Added documentation into lib and rebased patch
v3: Fixed typos and rebased patch
v4: Fixed documentation issues
v5: Rename, clean up of leftovers from previous version
and documentation polishing
v6: Fixing assert
Signed-off-by: Lukasz Kalamarz <lukasz.kalamarz@intel.com>
Cc: Katarzyna Dec <katarzyna.dec@intel.com>
Cc: Radoslaw Szwichtenberg <radoslaw.szwichtenberg@intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Reviewed-by: Katarzyna Dec <katarzyna.dec@intel.com>
Diffstat (limited to 'lib/intel_batchbuffer.c')
-rw-r--r-- | lib/intel_batchbuffer.c | 80 |
1 files changed, 72 insertions, 8 deletions
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c index 53ddae24..f87e6bed 100644 --- a/lib/intel_batchbuffer.c +++ b/lib/intel_batchbuffer.c @@ -66,6 +66,61 @@ */ /** + * intel_batchbuffer_align: + * @batch: batchbuffer object + * @align: value in bytes to which we want to align + * + * Aligns the current in-batch offset to the given value. + * + * Returns: Batchbuffer offset aligned to the given value. + */ +uint32_t +intel_batchbuffer_align(struct intel_batchbuffer *batch, uint32_t align) +{ + uint32_t offset = batch->ptr - batch->buffer; + + offset = ALIGN(offset, align); + batch->ptr = batch->buffer + offset; + return offset; +} + +/** + * intel_batchbuffer_subdata_alloc: + * @batch: batchbuffer object + * @size: amount of bytes need to allocate + * @align: value in bytes to which we want to align + * + * Verify if sufficient @size within @batch is available to deny overflow. + * Then allocate @size bytes within @batch. + * + * Returns: Offset within @batch between allocated subdata and base of @batch. + */ +void * +intel_batchbuffer_subdata_alloc(struct intel_batchbuffer *batch, uint32_t size, + uint32_t align) +{ + uint32_t offset = intel_batchbuffer_align(batch, align); + + igt_assert(size <= intel_batchbuffer_space(batch)); + + batch->ptr += size; + return memset(batch->buffer + offset, 0, size); +} + +/** + * intel_batchbuffer_subdata_offset: + * @batch: batchbuffer object + * @ptr: pointer to given data + * + * Returns: Offset within @batch between @ptr and base of @batch. + */ +uint32_t +intel_batchbuffer_subdata_offset(struct intel_batchbuffer *batch, void *ptr) +{ + return (uint8_t *)ptr - batch->buffer; +} + +/** * intel_batchbuffer_reset: * @batch: batchbuffer object * @@ -288,22 +343,31 @@ intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch, } /** - * intel_batchbuffer_data: + * intel_batchbuffer_copy_data: * @batch: batchbuffer object * @data: pointer to the data to write into the batchbuffer * @bytes: number of bytes to write into the batchbuffer + * @align: value in bytes to which we want to align * * This transfers the given @data into the batchbuffer. Note that the length - * must be DWORD aligned, i.e. multiples of 32bits. + * must be DWORD aligned, i.e. multiples of 32bits. The caller must + * confirm that there is enough space in the batch for the data to be + * copied. + * + * Returns: Offset of copied data. */ -void -intel_batchbuffer_data(struct intel_batchbuffer *batch, - const void *data, unsigned int bytes) +uint32_t +intel_batchbuffer_copy_data(struct intel_batchbuffer *batch, + const void *data, unsigned int bytes, + uint32_t align) { + uint32_t *subdata; + igt_assert((bytes & 3) == 0); - intel_batchbuffer_require_space(batch, bytes); - memcpy(batch->ptr, data, bytes); - batch->ptr += bytes; + subdata = intel_batchbuffer_subdata_alloc(batch, bytes, align); + memcpy(subdata, data, bytes); + + return intel_batchbuffer_subdata_offset(batch, subdata); } /** |