[PATCH v4 06/12] drm/panthor: New function for FW section map flags

From: Ketil Johnsen

Date: Mon Oct 12 2026 - 09:03:57 EST


From: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>

This refactors the VM map flags for FW sections into a new function
called section_vm_map_flags().
This comes in handly for future handling of protected FW sections
(type CSF_FW_BINARY_IFACE_ENTRY_PROT).

Signed-off-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>
Co-developed-by: Ketil Johnsen <ketil.johnsen@xxxxxxx>
Signed-off-by: Ketil Johnsen <ketil.johnsen@xxxxxxx>

---

v4:
- First version of this change as a separate commit
---
drivers/gpu/drm/panthor/panthor_fw.c | 44 ++++++++++++++++------------
1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index e639ffeac7a32..7b8c90b19f4fe 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -543,6 +543,31 @@ panthor_fw_alloc_suspend_buf_mem(struct panthor_device *ptdev, size_t size)
"FW suspend buffer");
}

+static u32 section_vm_map_flags(const struct panthor_fw_section *section)
+{
+ u32 cache_mode = section->flags &
+ CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK;
+ u32 vm_map_flags = 0;
+
+ if (!(section->flags & CSF_FW_BINARY_IFACE_ENTRY_WR))
+ vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_READONLY;
+
+ if (!(section->flags & CSF_FW_BINARY_IFACE_ENTRY_EX))
+ vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC;
+
+ /* TODO: CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_*_COHERENT are mapped to
+ * non-cacheable for now. We might want to introduce a new
+ * IOMMU_xxx flag (or abuse IOMMU_MMIO, which maps to device
+ * memory and is currently not used by our driver) for
+ * AS_MEMATTR_AARCH64_SHARED memory, so we can take benefit
+ * of IO-coherent systems.
+ */
+ if (cache_mode != CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_CACHED)
+ vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED;
+
+ return vm_map_flags;
+}
+
static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
const struct firmware *fw,
struct panthor_fw_binary_iter *iter,
@@ -645,26 +670,9 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
}

if (section_size) {
- u32 cache_mode = hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK;
- u32 vm_map_flags = 0;
+ u32 vm_map_flags = section_vm_map_flags(section);
u64 va = hdr.va.start;

- if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_WR))
- vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_READONLY;
-
- if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_EX))
- vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC;
-
- /* TODO: CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_*_COHERENT are mapped to
- * non-cacheable for now. We might want to introduce a new
- * IOMMU_xxx flag (or abuse IOMMU_MMIO, which maps to device
- * memory and is currently not used by our driver) for
- * AS_MEMATTR_AARCH64_SHARED memory, so we can take benefit
- * of IO-coherent systems.
- */
- if (cache_mode != CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_CACHED)
- vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED;
-
section->mem = panthor_kernel_bo_create(ptdev, panthor_fw_vm(ptdev),
section_size,
DRM_PANTHOR_BO_NO_MMAP,
--
2.43.0