[PATCH i-g-t 02/12] lib/intel_bufops: Fix mapping/unmapping for i915 and xe
Juha-Pekka Heikkila
juhapekka.heikkila at gmail.com
Mon Jun 3 07:31:35 UTC 2024
Reviewed-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
On 27.5.2024 10.33, Zbigniew Kempczyński wrote:
> It looks previously there was no user of intel-buf mapping code so
> missing xe path wasn't notice. Lets add xe path along with correct
> buffer size mapping.
>
> Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> Cc: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
> lib/intel_bufops.c | 39 ++++++++++++++++++++++++---------------
> 1 file changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/lib/intel_bufops.c b/lib/intel_bufops.c
> index 313c2665ae..b4ccf4c093 100644
> --- a/lib/intel_bufops.c
> +++ b/lib/intel_bufops.c
> @@ -1232,37 +1232,46 @@ void intel_buf_destroy(struct intel_buf *buf)
>
> void *intel_buf_cpu_map(struct intel_buf *buf, bool write)
> {
> - int i915 = buf_ops_get_fd(buf->bops);
> + int fd = 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);
> + if (is_xe_device(fd)) {
> + buf->ptr = xe_bo_map(fd, buf->handle, buf->bo_size);
> + } else {
> + buf->ptr = gem_mmap__cpu_coherent(fd, buf->handle, 0,
> + buf->bo_size,
> + write ? PROT_WRITE : PROT_READ);
> +
> + gem_set_domain(fd, 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);
> + int fd = 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);
> + if (is_xe_device(fd)) {
> + buf->ptr = xe_bo_map(fd, buf->handle, buf->bo_size);
> + } else {
> + buf->ptr = gem_mmap__device_coherent(fd, buf->handle, 0,
> + buf->bo_size,
> + write ? PROT_WRITE : PROT_READ);
>
> - gem_set_domain(i915, buf->handle,
> - I915_GEM_DOMAIN_WC,
> - write ? I915_GEM_DOMAIN_WC : 0);
> + gem_set_domain(fd, buf->handle,
> + I915_GEM_DOMAIN_WC,
> + write ? I915_GEM_DOMAIN_WC : 0);
> + }
>
> return buf->ptr;
> }
> @@ -1272,7 +1281,7 @@ void intel_buf_unmap(struct intel_buf *buf)
> igt_assert(buf);
> igt_assert(buf->ptr);
>
> - munmap(buf->ptr, buf->surface[0].size);
> + munmap(buf->ptr, buf->bo_size);
> buf->ptr = NULL;
> }
>
More information about the igt-dev
mailing list