diff --git a/src/panfrost/lib/kmod/pan_kmod.h b/src/panfrost/lib/kmod/pan_kmod.h index d136fdd0d8f..da016078e59 100644 --- a/src/panfrost/lib/kmod/pan_kmod.h +++ b/src/panfrost/lib/kmod/pan_kmod.h @@ -109,6 +109,12 @@ enum pan_kmod_bo_flags { * supported by the GPU. */ PAN_KMOD_BO_FLAG_WB_MMAP = BITFIELD_BIT(6), + + /* Set by default when the device is IO coherent. We might want to + * make it optional at some point and pass a NON_COHERENT flag to + * the KMD to force non-coherent mappings on IO coherent setup. + */ + PAN_KMOD_BO_FLAG_IO_COHERENT = BITFIELD_BIT(7), }; /* Allowed group priority flags. */ @@ -223,6 +229,11 @@ struct pan_kmod_dev_props { /* Mask of BO flags supported by the KMD. */ uint32_t supported_bo_flags; + + /* GPU is IO coherent, meaning BOs can be created with WB_MMAP without + * requiring explicit CPU cache maintenance. + */ + bool is_io_coherent; }; /* Memory allocator for kmod internal allocations. */ diff --git a/src/panfrost/lib/kmod/pan_kmod_backend.h b/src/panfrost/lib/kmod/pan_kmod_backend.h index 11bccfc74ad..04ec699e3c9 100644 --- a/src/panfrost/lib/kmod/pan_kmod_backend.h +++ b/src/panfrost/lib/kmod/pan_kmod_backend.h @@ -78,6 +78,13 @@ pan_kmod_bo_init(struct pan_kmod_bo *bo, struct pan_kmod_dev *dev, struct pan_kmod_vm *exclusive_vm, uint64_t size, uint32_t flags, uint32_t handle) { + /* Set by default when the device is IO coherent. We might want to + * make it optional at some point and pass a NON_COHERENT flag to + * the KMD to force non-coherent mappings on IO coherent setup. + */ + if (dev->props.is_io_coherent) + flags |= PAN_KMOD_BO_FLAG_IO_COHERENT; + bo->dev = dev; bo->exclusive_vm = exclusive_vm; bo->size = size; diff --git a/src/panfrost/lib/kmod/panfrost_kmod.c b/src/panfrost/lib/kmod/panfrost_kmod.c index 7d554b679ae..049fbafab6f 100644 --- a/src/panfrost/lib/kmod/panfrost_kmod.c +++ b/src/panfrost/lib/kmod/panfrost_kmod.c @@ -201,8 +201,16 @@ panfrost_dev_query_props(struct panfrost_kmod_dev *panfrost_dev) props->supported_bo_flags = PAN_KMOD_BO_FLAG_EXECUTABLE | PAN_KMOD_BO_FLAG_ALLOC_ON_FAULT | PAN_KMOD_BO_FLAG_NO_MMAP; - if (pan_kmod_driver_version_at_least(&dev->driver, 1, 6)) + + if (pan_kmod_driver_version_at_least(&dev->driver, 1, 6)) { + uint32_t selected_coherency = + panfrost_query_raw(fd, DRM_PANFROST_PARAM_SELECTED_COHERENCY, true, + DRM_PANFROST_GPU_COHERENCY_NONE); + props->supported_bo_flags |= PAN_KMOD_BO_FLAG_WB_MMAP; + props->is_io_coherent = + selected_coherency != DRM_PANFROST_GPU_COHERENCY_NONE; + } } static struct pan_kmod_dev * diff --git a/src/panfrost/lib/kmod/panthor_kmod.c b/src/panfrost/lib/kmod/panthor_kmod.c index 3d9253c2f57..d11d1be4339 100644 --- a/src/panfrost/lib/kmod/panthor_kmod.c +++ b/src/panfrost/lib/kmod/panthor_kmod.c @@ -180,8 +180,11 @@ panthor_dev_query_props(struct panthor_kmod_dev *panthor_dev) if (pan_kmod_driver_version_at_least(&panthor_dev->base.driver, 1, 6)) props->timestamp_device_coherent = true; - if (pan_kmod_driver_version_at_least(&panthor_dev->base.driver, 1, 7)) + if (pan_kmod_driver_version_at_least(&panthor_dev->base.driver, 1, 7)) { + props->is_io_coherent = panthor_dev->props.gpu.selected_coherency != + DRM_PANTHOR_GPU_COHERENCY_NONE; props->supported_bo_flags |= PAN_KMOD_BO_FLAG_WB_MMAP; + } static_assert(sizeof(props->texture_features) == sizeof(panthor_dev->props.gpu.texture_features),