drm/panfrost, panthor: Cached maps and explicit flushing
Subsystems (5)
Boris Brezillon
maintainerv8 cover drm/panfrost, panthor: Cached maps and explicit flushing
This series implements cached maps and explicit flushing for both panfrost and panthor.
The PanVK MR to use this lives here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36385
This version moves away from the code sharing proposed at the drm_prime/gem_shmem level and hand-roll a bunch of things that could potentially be shared. The goal here is to take the path of least resistance and discuss this controversial code-sharing topic in a follow-up MR. Dropping driver maintainers Cc-ed on v7 since they should now be aware that we changed gears and hand-rolled our own thing in pan{thor,frost}.
Changes in v2:
- Expose the coherency so userspace can know when it should skip cache maintenance
- Hook things up at drm_gem_object_funcs level to dma-buf cpu_prep hooks can be implemented generically
- Revisit the semantics of the flags passed to gem_sync()
- Add BO_QUERY_INFO ioctls to query BO flags on imported objects and let the UMD know when cache maintenance is needed on those
Changes in v3:
- New patch to fix panthor_gpu_coherency_set()
- No other major changes, check each patch changelog for more details
Changes in v4:
- Two trivial fixes, check each patch changelog for more details
Changes in v5:
- Add a way to overload dma_buf_ops while still relying on the drm_prime boilerplate
- Add default shmem implementation for dma_buf_ops::{begin,end}_cpu_access()
- Provide custom dma_buf_ops to deal with CPU cache flushes around CPU accesses when the BO is CPU-cacheable
- Go back to a version of drm_gem_shmem_sync() that only deals with cache maintenance, and adjust the semantics to make it clear this is the only thing it cares about
- Adjust the BO_SYNC ioctls according to the new drm_gem_shmem_sync() semantics
Changes in v6:
- No major changes, check the changelog in each patch for more details
Changes in v7:
- Drop the drm_prime/gem_shmem helpers and duplicate the logic in panthor/panfrost
Changes in v8:
- Fix a double struct field assignment and collect R-b tags
Boris Brezillon (8):
drm/panthor: Provide a custom dma_buf implementation drm/panthor: Fix panthor_gpu_coherency_set() drm/panthor: Expose the selected coherency protocol to the UMD drm/panthor: Add a PANTHOR_BO_SYNC ioctl
drm/panthor: Add an ioctl to query BO flags drm/panfrost: Provide a custom dma_buf implementation drm/panfrost: Expose the selected coherency protocol to the UMD drm/panfrost: Add an ioctl to query BO flags
Faith Ekstrand (4):
drm/panthor: Bump the driver version to 1.7 drm/panfrost: Add a PANFROST_SYNC_BO ioctl drm/panfrost: Add flag to map GEM object Write-Back Cacheable drm/panfrost: Bump the driver version to 1.6
Loïc Molinari (1):
drm/panthor: Add flag to map GEM object Write-Back Cacheable
drivers/gpu/drm/panfrost/panfrost_device.h | 1 + drivers/gpu/drm/panfrost/panfrost_drv.c | 101 ++++++++- drivers/gpu/drm/panfrost/panfrost_gem.c | 239 ++++++++++++++++++++ drivers/gpu/drm/panfrost/panfrost_gem.h | 10 + drivers/gpu/drm/panfrost/panfrost_gpu.c | 26 ++- drivers/gpu/drm/panfrost/panfrost_regs.h | 10 +- drivers/gpu/drm/panthor/panthor_device.c | 10 +- drivers/gpu/drm/panthor/panthor_drv.c | 79 ++++++- drivers/gpu/drm/panthor/panthor_gem.c | 240 ++++++++++++++++++++- drivers/gpu/drm/panthor/panthor_gem.h | 6 + drivers/gpu/drm/panthor/panthor_gpu.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 18 +- include/uapi/drm/panfrost_drm.h | 76 ++++++- include/uapi/drm/panthor_drm.h | 157 +++++++++++++- 14 files changed, 953 insertions(+), 22 deletions(-)
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 1/13 drm/panthor: Provide a custom dma_buf implementation
Before we introduce cached CPU mappings, we want a dma_buf implementation satisfying synchronization requests around CPU accesses coming from a dma_buf exported by our driver. Let's provide our own implementation relying on the default gem_shmem_prime helpers designed for that purpose.
v5:
- New patch
v6:
- Collect R-b
v7:
- Hand-roll the dma_buf sync/import logic (was previously done by generic prime/shmem helpers)
v8:
- No changes
--- drivers/gpu/drm/panthor/panthor_drv.c | 1 + drivers/gpu/drm/panthor/panthor_gem.c | 118 +++++++++++++++++++++++++- drivers/gpu/drm/panthor/panthor_gem.h | 4 + 3 files changed, 122 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
@@ -1622,6 +1622,7 @@ static const struct drm_driver panthor_drm_driver = { .gem_create_object = panthor_gem_create_object, .gem_prime_import_sg_table = drm_gem_shmem_prime_import_sg_table, + .gem_prime_import = panthor_gem_prime_import,#ifdef CONFIG_DEBUG_FS .debugfs_init = panthor_debugfs_init,#endif
drivers/gpu/drm/panthor/panthor_gem.c +117 -1
131 lines not on this page · raw message
drivers/gpu/drm/panthor/panthor_gem.h +4 -0
@@ -147,6 +147,10 @@ panthor_gem_create_with_handle(struct drm_file *file,void panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label);void panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label); +struct drm_gem_object * +panthor_gem_prime_import (struct drm_device *dev, +struct dma_buf *dma_buf); +static inline u64 panthor_kernel_bo_gpuva (struct panthor_kernel_bo *bo) {
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 2/13 drm/panthor: Fix panthor_gpu_coherency_set()
In reply to Boris BrezillonGPU_COHERENCY_PROTOCOL takes one of GPU_COHERENCY_xx not BIT(GPU_COHERENCY_xx).
v3:
- New commit
v4:
- Add Steve's R-b
v5:
- No changes
v6:
- No changes
v7:
- No changes
v8:
- No changes
--- drivers/gpu/drm/panthor/panthor_gpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_gpu.c +1 -1
@@ -51,7 +51,7 @@ struct panthor_gpu {static void panthor_gpu_coherency_set (struct panthor_device *ptdev) {gpu_write (ptdev,GPU_COHERENCY_PROTOCOL , - ptdev->coherent ?GPU_COHERENCY_PROT_BIT (ACE_LITE ) :GPU_COHERENCY_NONE ); + ptdev->coherent ?GPU_COHERENCY_ACE_LITE :GPU_COHERENCY_NONE ); }static void panthor_gpu_l2_config_set (struct panthor_device *ptdev)
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 3/13 drm/panthor: Expose the selected coherency protocol to the UMD
In reply to Boris BrezillonIf we want to be able to skip CPU cache maintenance operations on CPU-cached mappings, the UMD needs to know the kind of coherency in place. Add a field to drm_panthor_gpu_info to do that. We can re-use a padding field for that since this object is write-only from the KMD perspective, and the UMD should just ignore it.
v2:
- New commit
v3:
- Make coherency protocol a real enum, not a bitmask
- Add BUILD_BUG_ON()s to make sure the values in panthor_regs.h and those exposed through the uAPI match
v4:
- Add Steve's R-b
v5:
- No changes
v6:
- No changes
v7:
- Fix kernel doc
v8:
- No changes
--- drivers/gpu/drm/panthor/panthor_device.c | 10 +++++- drivers/gpu/drm/panthor/panthor_gpu.c | 2 +- include/uapi/drm/panthor_drm.h | 39 ++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-)
drivers/gpu/drm/panthor/panthor_device.c +9 -1
@@ -27,6 +27,12 @@static int panthor_gpu_coherency_init (struct panthor_device *ptdev) { +BUILD_BUG_ON (GPU_COHERENCY_NONE !=DRM_PANTHOR_GPU_COHERENCY_NONE ); +BUILD_BUG_ON (GPU_COHERENCY_ACE_LITE !=DRM_PANTHOR_GPU_COHERENCY_ACE_LITE ); +BUILD_BUG_ON (GPU_COHERENCY_ACE !=DRM_PANTHOR_GPU_COHERENCY_ACE ); + +/* Start with no coherency, and update it if the device is flagged coherent. */ + ptdev->gpu_info.selected_coherency =GPU_COHERENCY_NONE ; ptdev->coherent =device_get_dma_attr (ptdev->base.dev) ==DEV_DMA_COHERENT ;if (!ptdev->coherent)
@@ -36,8 +42,10 @@ static int panthor_gpu_coherency_init(struct panthor_device *ptdev)* ACE protocol has never been supported for command stream frontend GPUs. */ if ((gpu_read (ptdev,GPU_COHERENCY_FEATURES ) & -GPU_COHERENCY_PROT_BIT (ACE_LITE ))) +GPU_COHERENCY_PROT_BIT (ACE_LITE ))) { + ptdev->gpu_info.selected_coherency =GPU_COHERENCY_ACE_LITE ;return 0 ; + }drm_err (&ptdev->base,"Coherency not supported by the device" );return -ENOTSUPP ;
drivers/gpu/drm/panthor/panthor_gpu.c +1 -1
@@ -51,7 +51,7 @@ struct panthor_gpu {static void panthor_gpu_coherency_set (struct panthor_device *ptdev) {gpu_write (ptdev,GPU_COHERENCY_PROTOCOL , - ptdev->coherent ?GPU_COHERENCY_ACE_LITE :GPU_COHERENCY_NONE ); + ptdev->gpu_info.selected_coherency); }static void panthor_gpu_l2_config_set (struct panthor_device *ptdev)
include/uapi/drm/panthor_drm.h +36 -3
@@ -245,6 +245,26 @@ enum drm_panthor_dev_query_type { DRM_PANTHOR_DEV_QUERY_GROUP_PRIORITIES_INFO, }; +/** +* enum drm_panthor_gpu_coherency: Type of GPU coherency +*/ +enum drm_panthor_gpu_coherency { +/** +* @DRM_PANTHOR_GPU_COHERENCY_ACE_LITE: ACE Lite coherency. +*/ +DRM_PANTHOR_GPU_COHERENCY_ACE_LITE =0 , + +/** +* @DRM_PANTHOR_GPU_COHERENCY_ACE: ACE coherency. +*/ +DRM_PANTHOR_GPU_COHERENCY_ACE =1 , + +/** +* @DRM_PANTHOR_GPU_COHERENCY_NONE: No coherency. +*/ +DRM_PANTHOR_GPU_COHERENCY_NONE =31 , +}; +/** * struct drm_panthor_gpu_info - GPU information *
@@ -301,7 +321,16 @@ struct drm_panthor_gpu_info {*/ __u32 thread_max_barrier_size; -/** @coherency_features: Coherency features. */ +/** +* @coherency_features: Coherency features. +* +* Combination of drm_panthor_gpu_coherency flags. +* +* Note that this is just what the coherency protocols supported by the +* GPU, but the actual coherency in place depends on the SoC +* integration and is reflected by +* drm_panthor_gpu_info::selected_coherency. +*/ __u32 coherency_features;/** @texture_features: Texture features. */
@@ -310,8 +339,12 @@ struct drm_panthor_gpu_info {/** @as_present: Bitmask encoding the number of address-space exposed by the MMU. */ __u32 as_present; -/** @pad0: MBZ. */ -__u32 pad0; +/** +* @select_coherency: Coherency selected for this device. +* +* One of drm_panthor_gpu_coherency. +*/ +__u32 selected_coherency;/** @shader_present: Bitmask encoding the shader cores exposed by the GPU. */ __u64 shader_present;
Signature · 1 line
2.51.1
Re: [PATCH v8 03/13] drm/panthor: Expose the selected coherency protocol to the UMD
Quoted 133 lines · Boris Brezillon
If we want to be able to skip CPU cache maintenance operations on CPU-cached mappings, the UMD needs to know the kind of coherency in place. Add a field to
drm_panthor_gpu_infoto do that. We can re-use a padding field for that since this object is write-only from the KMD perspective, and the UMD should just ignore it.v2:
- New commitv3:
- Make coherency protocol a real enum, not a bitmask
- Add BUILD_BUG_ON()s to make sure the values inpanthor_regs.hand those exposed through the uAPI matchv4:
- Add Steve's R-bv5:
- No changesv6:
- No changesv7:
- Fix kernel docv8:
- No changesSigned-off-by Boris Brezillon <[email protected]>Reviewed-by Steven Price <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.c | 10 +++++- drivers/gpu/drm/panthor/panthor_gpu.c | 2 +- include/uapi/drm/panthor_drm.h | 39 ++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-)drivers/gpu/drm/panthor/panthor_device.c +9
-1@@ -27,6 +27,12 @@static int panthor_gpu_coherency_init (struct panthor_device *ptdev) { +BUILD_BUG_ON (GPU_COHERENCY_NONE !=DRM_PANTHOR_GPU_COHERENCY_NONE ); +BUILD_BUG_ON (GPU_COHERENCY_ACE_LITE !=DRM_PANTHOR_GPU_COHERENCY_ACE_LITE ); +BUILD_BUG_ON (GPU_COHERENCY_ACE !=DRM_PANTHOR_GPU_COHERENCY_ACE ); + +/* Start with no coherency, and update it if the device is flagged coherent. */ + ptdev->gpu_info.selected_coherency =GPU_COHERENCY_NONE ; ptdev->coherent =device_get_dma_attr (ptdev->base.dev) ==DEV_DMA_COHERENT ;if (!ptdev->coherent)@@ -36,8 +42,10 @@ static int panthor_gpu_coherency_init(struct panthor_device *ptdev)* ACE protocol has never been supported for command stream frontend GPUs. */ if ((gpu_read (ptdev,GPU_COHERENCY_FEATURES ) & -GPU_COHERENCY_PROT_BIT (ACE_LITE ))) +GPU_COHERENCY_PROT_BIT (ACE_LITE ))) { + ptdev->gpu_info.selected_coherency =GPU_COHERENCY_ACE_LITE ;return 0 ; + }drm_err (&ptdev->base,"Coherency not supported by the device" );return -ENOTSUPP ;drivers/gpu/drm/panthor/panthor_gpu.c +1
-1@@ -51,7 +51,7 @@ struct panthor_gpu {static void panthor_gpu_coherency_set (struct panthor_device *ptdev) {gpu_write (ptdev,GPU_COHERENCY_PROTOCOL , - ptdev->coherent ?GPU_COHERENCY_ACE_LITE :GPU_COHERENCY_NONE ); + ptdev->gpu_info.selected_coherency); }static void panthor_gpu_l2_config_set (struct panthor_device *ptdev)include/uapi/drm/panthor_drm.h +30
-2@@ -245,6 +245,26 @@ enum drm_panthor_dev_query_type { DRM_PANTHOR_DEV_QUERY_GROUP_PRIORITIES_INFO, }; +/** +* enum drm_panthor_gpu_coherency: Type of GPU coherency +*/ +enum drm_panthor_gpu_coherency { +/** +* @DRM_PANTHOR_GPU_COHERENCY_ACE_LITE: ACE Lite coherency. +*/ +DRM_PANTHOR_GPU_COHERENCY_ACE_LITE =0 , + +/** +* @DRM_PANTHOR_GPU_COHERENCY_ACE: ACE coherency. +*/ +DRM_PANTHOR_GPU_COHERENCY_ACE =1 , + +/** +* @DRM_PANTHOR_GPU_COHERENCY_NONE: No coherency. +*/ +DRM_PANTHOR_GPU_COHERENCY_NONE =31 , +}; +/** * struct drm_panthor_gpu_info - GPU information * @@ -301,7 +321,16 @@ struct drm_panthor_gpu_info {*/ __u32 thread_max_barrier_size; -/** @coherency_features: Coherency features. */ +/** +* @coherency_features: Coherency features. +* +* Combination of drm_panthor_gpu_coherency flags. +* +* Note that this is just what the coherency protocols supported by the +* GPU, but the actual coherency in place depends on the SoC +* integration and is reflected by +* drm_panthor_gpu_info::selected_coherency. +*/ __u32 coherency_features;/** @texture_features: Texture features. */ @@ -310,8 +339,12 @@ struct drm_panthor_gpu_info {/** @as_present: Bitmask encoding the number of address-space exposed by the MMU. */ __u32 as_present; -/** @pad0: MBZ. */
include/uapi/drm/panthor_drm.h struct drm_panthor_gpu_info { · line 350
Quoted 10 lines
include/uapi/drm/panthor_drm.h +6
-1-__u32 pad0; +/** +* @select_coherency: Coherency selected for this device. +* +* One of drm_panthor_gpu_coherency. +*/ +__u32 selected_coherency;/** @shader_present: Bitmask encoding the shader cores exposed by the GPU. */ __u64 shader_present;
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Boris Brezillon
maintainerPATCH v8 4/13 drm/panthor: Add a PANTHOR_BO_SYNC ioctl
In reply to Boris BrezillonThis will be used by the UMD to synchronize CPU-cached mappings when the UMD can't do it directly (no usermode cache maintenance instruction on Arm32).
v2:
- Change the flags so they better match the drm_gem_shmem_sync() semantics
v3:
- Add Steve's R-b
v4:
- No changes
v5:
- Drop Steve's R-b (the semantics changes call for a new review)
v6:
- Drop ret initialization in panthor_ioctl_bo_sync()
- Bail out early in panthor_ioctl_bo_sync() if ops.count is zero
- Drop unused PANTHOR_BO_SYNC_OP_FLAGS definition
v7:
- Hand-roll the sync logic (was previously provided by gem_shmem)
v8:
- Collect R-b
--- drivers/gpu/drm/panthor/panthor_drv.c | 41 ++++++++++++- drivers/gpu/drm/panthor/panthor_gem.c | 85 +++++++++++++++++++++++++++ drivers/gpu/drm/panthor/panthor_gem.h | 2 + include/uapi/drm/panthor_drm.h | 52 ++++++++++++++++ 4 files changed, 179 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_drv.c +40 -1
@@ -177,7 +177,8 @@ panthor_get_uobj_array(const struct drm_panthor_obj_array *in, u32 min_stride, PANTHOR_UOBJ_DECL(struct drm_panthor_sync_op, timeline_value), \PANTHOR_UOBJ_DECL (struct drm_panthor_queue_submit , syncs), \PANTHOR_UOBJ_DECL (struct drm_panthor_queue_create , ringbuf_size), \ - PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs)) +PANTHOR_UOBJ_DECL (struct drm_panthor_vm_bind_op , syncs), \ + PANTHOR_UOBJ_DECL(struct drm_panthor_bo_sync_op, size))/** * PANTHOR_UOBJ_SET() - Copy a kernel object to a user object.
@@ -1396,6 +1397,43 @@ static int panthor_ioctl_set_user_mmio_offset(struct drm_device *ddev,return 0 ; } +static int panthor_ioctl_bo_sync (struct drm_device *ddev,void *data, +struct drm_file *file) +{ +struct drm_panthor_bo_sync *args = data; +struct drm_panthor_bo_sync_op *ops; +struct drm_gem_object *obj; +int ret; + +if (!args->ops.count) +return 0 ; + + ret =PANTHOR_UOBJ_GET_ARRAY (ops, &args->ops); +if (ret) +return ret; + +for (u32 i =0 ; i < args->ops.count; i++) { + obj =drm_gem_object_lookup (file, ops[i].handle); +if (!obj) { + ret = -ENOENT ; + goto err_ops; + } + + ret =panthor_gem_sync (obj, ops[i].type, ops[i].offset, + ops[i].size); + +drm_gem_object_put (obj); + +if (ret) + goto err_ops; + } + +err_ops: +kvfree (ops); + +return ret; +} +static int panthor_open (struct drm_device *ddev,struct drm_file *file) {
@@ -1470,6 +1508,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {PANTHOR_IOCTL (GROUP_SUBMIT , group_submit,DRM_RENDER_ALLOW ),PANTHOR_IOCTL (BO_SET_LABEL , bo_set_label,DRM_RENDER_ALLOW ),PANTHOR_IOCTL (SET_USER_MMIO_OFFSET , set_user_mmio_offset,DRM_RENDER_ALLOW ), + PANTHOR_IOCTL(BO_SYNC, bo_sync, DRM_RENDER_ALLOW), };static int panthor_mmap (struct file *filp,struct vm_area_struct *vma)
drivers/gpu/drm/panthor/panthor_gem.c +85 -0
91 lines not on this page · raw message
drivers/gpu/drm/panthor/panthor_gem.h +2 -0
@@ -146,6 +146,8 @@ panthor_gem_create_with_handle(struct drm_file *file,void panthor_gem_bo_set_label (struct drm_gem_object *obj,const char *label);void panthor_gem_kernel_bo_set_label (struct panthor_kernel_bo *bo,const char *label); +int panthor_gem_sync (struct drm_gem_object *obj, +u32 type,u64 offset,u64 size);struct drm_gem_object * panthor_gem_prime_import(struct drm_device *dev,
include/uapi/drm/panthor_drm.h +52 -0
70 lines not on this page · raw message
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 5/13 drm/panthor: Add an ioctl to query BO flags
In reply to Boris BrezillonThis is useful when importing BOs, so we can know about cacheability and flush the caches when needed.
We can also know when the buffer comes from a different subsystem and take proper actions (avoid CPU mappings, or do kernel-based syncs instead of userland cache flushes).
v2:
- New commit
v3:
- Add Steve's R-b
v4:
- No changes
v5:
- No changes
v6:
- No changes
v7:
- No changes
v8:
- No changes
--- drivers/gpu/drm/panthor/panthor_drv.c | 24 +++++++++++ include/uapi/drm/panthor_drm.h | 57 +++++++++++++++++++++++++++ 2 files changed, 81 insertions(+)
drivers/gpu/drm/panthor/panthor_drv.c +24 -0
@@ -1434,6 +1434,29 @@ static int panthor_ioctl_bo_sync(struct drm_device *ddev, void *data,return ret; } +static int panthor_ioctl_bo_query_info (struct drm_device *ddev,void *data, +struct drm_file *file) +{ +struct drm_panthor_bo_query_info *args = data; +struct panthor_gem_object *bo; +struct drm_gem_object *obj; + + obj =drm_gem_object_lookup (file, args->handle); +if (!obj) +return -ENOENT ; + + bo =to_panthor_bo (obj); + args->pad =0 ; + args->create_flags = bo->flags; + + args->extra_flags =0 ; +if (drm_gem_is_imported (&bo->base.base)) + args->extra_flags |=DRM_PANTHOR_BO_IS_IMPORTED ; + +drm_gem_object_put (obj); +return 0 ; +} +static int panthor_open (struct drm_device *ddev,struct drm_file *file) {
@@ -1509,6 +1532,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {PANTHOR_IOCTL (BO_SET_LABEL , bo_set_label,DRM_RENDER_ALLOW ),PANTHOR_IOCTL (SET_USER_MMIO_OFFSET , set_user_mmio_offset,DRM_RENDER_ALLOW ),PANTHOR_IOCTL (BO_SYNC , bo_sync,DRM_RENDER_ALLOW ), + PANTHOR_IOCTL(BO_QUERY_INFO, bo_query_info, DRM_RENDER_ALLOW), };static int panthor_mmap (struct file *filp,struct vm_area_struct *vma)
include/uapi/drm/panthor_drm.h +57 -0
75 lines not on this page · raw message
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 6/13 drm/panthor: Add flag to map GEM object Write-Back Cacheable
In reply to Boris BrezillonFrom: Loïc Molinari <[email protected]>
Will be used by the UMD to optimize CPU accesses to buffers that are frequently read by the CPU, or on which the access pattern makes non-cacheable mappings inefficient.
Mapping buffers CPU-cached implies taking care of the CPU cache maintenance in the UMD, unless the GPU is IO coherent.
v2:
- Add more to the commit message
- Tweak the doc
- Make sure we sync the section of the BO pointing to the CS syncobj before we read its seqno
v3:
- Fix formatting/spelling issues
v4:
- Add Steve's R-b
v5:
- Drop Steve's R-b (changes in the ioctl semantics requiring new review)
v6:
- Fix the uAPI doc
- Fix inverted logic in some comment
v7:
- No changes
v8:
- Collect R-b
--- drivers/gpu/drm/panthor/panthor_drv.c | 7 ++++- drivers/gpu/drm/panthor/panthor_gem.c | 37 +++++++++++++++++++++++-- drivers/gpu/drm/panthor/panthor_sched.c | 18 ++++++++++-- include/uapi/drm/panthor_drm.h | 9 ++++++ 4 files changed, 66 insertions(+), 5 deletions(-)
drivers/gpu/drm/panthor/panthor_drv.c +6 -1
@@ -902,7 +902,8 @@ static int panthor_ioctl_vm_destroy(struct drm_device *ddev, void *data,return panthor_vm_pool_destroy_vm (pfile->vms, args->id); } -#define PANTHOR_BO_FLAGS DRM_PANTHOR_BO_NO_MMAP +#define PANTHOR_BO_FLAGS (DRM_PANTHOR_BO_NO_MMAP | \ + DRM_PANTHOR_BO_WB_MMAP)static int panthor_ioctl_bo_create (struct drm_device *ddev,void *data,struct drm_file *file)
@@ -921,6 +922,10 @@ static int panthor_ioctl_bo_create(struct drm_device *ddev, void *data, goto out_dev_exit; } +if ((args->flags &DRM_PANTHOR_BO_NO_MMAP ) && + (args->flags &DRM_PANTHOR_BO_WB_MMAP )) +return -EINVAL ; +if (args->exclusive_vm_id) { vm =panthor_vm_pool_get_vm (pfile->vms, args->exclusive_vm_id);if (!vm) {
drivers/gpu/drm/panthor/panthor_gem.c +35 -2
@@ -59,6 +59,39 @@ static void panthor_gem_debugfs_set_usage_flags(struct panthor_gem_object *bo, ustatic void panthor_gem_debugfs_bo_init (struct panthor_gem_object *bo) {}#endif +static bool +should_map_wc (struct panthor_gem_object *bo,struct panthor_vm *exclusive_vm) +{ + struct panthor_device *ptdev = container_of(bo->base.base.dev, struct panthor_device, base); + +/* We can't do uncached mappings if the device is coherent, +* because the zeroing done by the shmem layer at page allocation +* time happens on a cached mapping which isn't CPU-flushed (at least +* not on Arm64 where the flush is deferred to PTE setup time, and +* only done conditionally based on the mapping permissions). We can't +* rely on dma_map_sgtable()/dma_sync_sgtable_for_xxx() either to flush +* those, because they are NOPed if dma_dev_coherent() returns true. +* +* FIXME: Note that this problem is going to pop up again when we +* decide to support mapping buffers with the NO_MMAP flag as +* non-shareable (AKA buffers accessed only by the GPU), because we +* need the same CPU flush to happen after page allocation, otherwise +* there's a risk of data leak or late corruption caused by a dirty +* cacheline being evicted. At this point we'll need a way to force +* CPU cache maintenance regardless of whether the device is coherent +* or not. +*/ +if (ptdev->coherent) +return false; + +/* Cached mappings are explicitly requested, so no write-combine. */ +if (bo->flags &DRM_PANTHOR_BO_WB_MMAP ) +return false; + +/* The default is write-combine. */ +return true; +} +static void panthor_gem_free_object (struct drm_gem_object *obj) {struct panthor_gem_object *bo =to_panthor_bo (obj);
@@ -145,6 +178,7 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm, bo =to_panthor_bo (&obj->base); kbo->obj = &obj->base; bo->flags = bo_flags; + bo->base.map_wc =should_map_wc (bo, vm); bo->exclusive_vm_root_gem =panthor_vm_root_gem (vm);drm_gem_object_get (bo->exclusive_vm_root_gem); bo->base.base.resv = bo->exclusive_vm_root_gem->resv;
@@ -345,7 +379,6 @@ static const struct drm_gem_object_funcs panthor_gem_funcs = {*/ struct drm_gem_object *panthor_gem_create_object (struct drm_device *ddev,size_t size) { - struct panthor_device *ptdev = container_of(ddev, struct panthor_device, base);struct panthor_gem_object *obj; obj =kzalloc (sizeof (*obj),GFP_KERNEL );
@@ -353,7 +386,6 @@ struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_treturn ERR_PTR (-ENOMEM ); obj->base.base.funcs = &panthor_gem_funcs; - obj->base.map_wc = !ptdev->coherent;mutex_init (&obj->label.lock);panthor_gem_debugfs_bo_init (obj);
@@ -388,6 +420,7 @@ panthor_gem_create_with_handle(struct drm_file *file, bo =to_panthor_bo (&shmem->base); bo->flags = flags; + bo->base.map_wc =should_map_wc (bo, exclusive_vm);if (exclusive_vm) { bo->exclusive_vm_root_gem =panthor_vm_root_gem (exclusive_vm);
drivers/gpu/drm/panthor/panthor_sched.c +16 -2
@@ -863,8 +863,11 @@ panthor_queue_get_syncwait_obj(struct panthor_group *group, struct panthor_queuestruct iosys_map map;int ret; -if (queue->syncwait.kmap) -return queue->syncwait.kmap + queue->syncwait.offset; +if (queue->syncwait.kmap) { + bo =container_of (queue->syncwait.obj, + struct panthor_gem_object, base.base); + goto out_sync; + } bo = panthor_vm_get_bo_for_va(group->vm, queue->syncwait.gpu_va,
@@ -881,6 +884,17 @@ panthor_queue_get_syncwait_obj(struct panthor_group *group, struct panthor_queueif (drm_WARN_ON (&ptdev->base, !queue->syncwait.kmap)) goto err_put_syncwait_obj; +out_sync: +/* Make sure the CPU caches are invalidated before the seqno is read. +* drm_gem_shmem_sync() is a NOP if map_wc=true, so no need to check +* it here. +*/ +panthor_gem_sync (&bo->base.base, queue->syncwait.offset, + queue->syncwait.sync64 ? +sizeof (struct panthor_syncobj_64b ) : +sizeof (struct panthor_syncobj_32b ), +DRM_PANTHOR_BO_SYNC_CPU_CACHE_FLUSH_AND_INVALIDATE ); +return queue->syncwait.kmap + queue->syncwait.offset; err_put_syncwait_obj:
include/uapi/drm/panthor_drm.h +9 -0
@@ -681,6 +681,15 @@ struct drm_panthor_vm_get_state {enum drm_panthor_bo_flags {/** @DRM_PANTHOR_BO_NO_MMAP: The buffer object will never be CPU-mapped in userspace. */ DRM_PANTHOR_BO_NO_MMAP = (1 <<0 ), + +/** +* @DRM_PANTHOR_BO_WB_MMAP: Force "Write-Back Cacheable" CPU mapping. +* +* CPU map the buffer object in userspace by forcing the "Write-Back +* Cacheable" cacheability attribute. The mapping otherwise uses the +* "Non-Cacheable" attribute if the GPU is not IO coherent. +*/ +DRM_PANTHOR_BO_WB_MMAP = (1 <<1 ), };/**
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 7/13 drm/panthor: Bump the driver version to 1.7
In reply to Boris BrezillonFrom: Faith Ekstrand <[email protected]>
Bump the driver version to reflect the new cached-CPU mapping capability.
v2:
- Quickly describe what the new version exposes in the commit message
v3:
- Add Steve's R-b
v4:
- No changes
v5:
- No changes
v6:
- No changes
v7:
- No changes
v8:
- Bump to 1.7 (1.6 was picked in the meantime)
--- drivers/gpu/drm/panthor/panthor_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_drv.c +5 -1
@@ -1673,6 +1673,10 @@ static void panthor_debugfs_init(struct drm_minor *minor)* - 1.4 - adds DRM_IOCTL_PANTHOR_BO_SET_LABEL ioctl * - 1.5 - adds DRM_PANTHOR_SET_USER_MMIO_OFFSET ioctl * - 1.6 - enables GLB_COUNTER_EN +* - 1.7 - adds DRM_PANTHOR_BO_WB_MMAP flag +* - adds DRM_IOCTL_PANTHOR_BO_SYNC ioctl +* - adds DRM_IOCTL_PANTHOR_BO_QUERY_INFO ioctl +* - adds drm_panthor_gpu_info::selected_coherency */ static const struct drm_driver panthor_drm_driver = { .driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
@@ -1686,7 +1690,7 @@ static const struct drm_driver panthor_drm_driver = { .name = "panthor", .desc = "Panthor DRM driver", .major = 1, - .minor = 6, + .minor = 7, .gem_create_object = panthor_gem_create_object, .gem_prime_import_sg_table = drm_gem_shmem_prime_import_sg_table,
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 8/13 drm/panfrost: Provide a custom dma_buf implementation
In reply to Boris BrezillonBefore we introduce cached CPU mappings, we want a dma_buf implementation satisfying synchronization requests around CPU accesses coming from a dma_buf exported by our driver. Let's provide our own implementation relying on the default gem_shmem_prime helpers designed for that purpose.
v5:
- New patch
v6:
- Collect R-b
v7:
- Hand-roll our own dma_buf boilerplate
v8:
- No changes
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 1 + drivers/gpu/drm/panfrost/panfrost_gem.c | 123 ++++++++++++++++++++++++ drivers/gpu/drm/panfrost/panfrost_gem.h | 3 + 3 files changed, 127 insertions(+)
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -0
@@ -852,6 +852,7 @@ static const struct drm_driver panfrost_drm_driver = { .minor = 5, .gem_create_object = panfrost_gem_create_object, + .gem_prime_import = panfrost_gem_prime_import, .gem_prime_import_sg_table = panfrost_gem_prime_import_sg_table, #ifdef CONFIG_DEBUG_FS .debugfs_init = panfrost_debugfs_init,
drivers/gpu/drm/panfrost/panfrost_gem.c +123 -0
135 lines not on this page · raw message
drivers/gpu/drm/panfrost/panfrost_gem.h +3 -0
@@ -130,6 +130,9 @@ struct drm_gem_object * panfrost_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sgt); +struct drm_gem_object * +panfrost_gem_prime_import (struct drm_device *dev, +struct dma_buf *dma_buf);struct panfrost_gem_object *panfrost_gem_create (struct drm_device *dev,size_t size,u32 flags);
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 9/13 drm/panfrost: Expose the selected coherency protocol to the UMD
In reply to Boris BrezillonWill be needed if we want to skip CPU cache maintenance operations when the GPU can snoop CPU caches.
v2:
- New commit
v3:
- Fix the coherency values (enum instead of bitmask)
v4:
- Fix init/test on coherency_features
v5:
- No changes
v6:
- Collect R-b
v7:
- No changes
v8:
- No changes
--- drivers/gpu/drm/panfrost/panfrost_device.h | 1 + drivers/gpu/drm/panfrost/panfrost_drv.c | 1 + drivers/gpu/drm/panfrost/panfrost_gpu.c | 26 +++++++++++++++++++--- drivers/gpu/drm/panfrost/panfrost_regs.h | 10 +++++++-- include/uapi/drm/panfrost_drm.h | 7 ++++++ 5 files changed, 40 insertions(+), 5 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.h +1 -0
@@ -79,6 +79,7 @@ struct panfrost_features {u32 thread_max_workgroup_sz;u32 thread_max_barrier_sz;u32 coherency_features; +u32 selected_coherency;u32 afbc_features;u32 texture_features[4 ];u32 js_features[16 ];
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -0
@@ -95,6 +95,7 @@ static int panfrost_ioctl_get_param(struct drm_device *ddev, void *data, structPANFROST_FEATURE_ARRAY (JS_FEATURES , js_features,15 );PANFROST_FEATURE (NR_CORE_GROUPS , nr_core_groups);PANFROST_FEATURE (THREAD_TLS_ALLOC , thread_tls_alloc); +PANFROST_FEATURE (SELECTED_COHERENCY , selected_coherency);case DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP : ret =panfrost_ioctl_query_timestamp (pfdev, ¶m->value);
drivers/gpu/drm/panfrost/panfrost_gpu.c +23 -3
@@ -159,8 +159,8 @@ static void panfrost_gpu_init_quirks(struct panfrost_device *pfdev) pfdev->features.revision >= 0x2000) quirks |=JM_MAX_JOB_THROTTLE_LIMIT <<JM_JOB_THROTTLE_LIMIT_SHIFT ; else if (panfrost_model_eq(pfdev, 0x6000) && - pfdev->features.coherency_features == COHERENCY_ACE) - quirks |= (COHERENCY_ACE_LITE | COHERENCY_ACE) << + pfdev->features.coherency_features == BIT(COHERENCY_ACE)) + quirks |= (BIT(COHERENCY_ACE_LITE) | BIT(COHERENCY_ACE)) << JM_FORCE_COHERENCY_FEATURES_SHIFT; if (panfrost_has_hw_feature(pfdev, HW_FEATURE_IDVS_GROUP_SIZE))
@@ -263,7 +263,27 @@ static int panfrost_gpu_init_features(struct panfrost_device *pfdev) pfdev->features.max_threads =gpu_read (pfdev,GPU_THREAD_MAX_THREADS ); pfdev->features.thread_max_workgroup_sz =gpu_read (pfdev,GPU_THREAD_MAX_WORKGROUP_SIZE ); pfdev->features.thread_max_barrier_sz =gpu_read (pfdev,GPU_THREAD_MAX_BARRIER_SIZE ); - pfdev->features.coherency_features =gpu_read (pfdev,GPU_COHERENCY_FEATURES ); + +if (panfrost_has_hw_feature (pfdev,HW_FEATURE_COHERENCY_REG )) + pfdev->features.coherency_features =gpu_read (pfdev,GPU_COHERENCY_FEATURES ); +else + pfdev->features.coherency_features =BIT (COHERENCY_ACE_LITE ); + +BUILD_BUG_ON (COHERENCY_ACE_LITE !=DRM_PANFROST_GPU_COHERENCY_ACE_LITE ); +BUILD_BUG_ON (COHERENCY_ACE !=DRM_PANFROST_GPU_COHERENCY_ACE ); +BUILD_BUG_ON (COHERENCY_NONE !=DRM_PANFROST_GPU_COHERENCY_NONE ); + +if (!pfdev->coherent) { + pfdev->features.selected_coherency =COHERENCY_NONE ; + }else if (pfdev->features.coherency_features &BIT (COHERENCY_ACE )) { + pfdev->features.selected_coherency =COHERENCY_ACE ; + }else if (pfdev->features.coherency_features &BIT (COHERENCY_ACE_LITE )) { + pfdev->features.selected_coherency =COHERENCY_ACE_LITE ; + }else { +drm_WARN (&pfdev->base, true,"No known coherency protocol supported" ); + pfdev->features.selected_coherency =COHERENCY_NONE ; + } + pfdev->features.afbc_features =gpu_read (pfdev,GPU_AFBC_FEATURES );for (i =0 ; i <4 ; i++) pfdev->features.texture_features[i] =gpu_read (pfdev,GPU_TEXTURE_FEATURES (i));
drivers/gpu/drm/panfrost/panfrost_regs.h +8 -2
@@ -102,9 +102,15 @@#define GPU_L2_PRESENT_LO 0x120/* (RO) Level 2 cache present bitmap, low word */ #define GPU_L2_PRESENT_HI 0x124/* (RO) Level 2 cache present bitmap, high word */ +/* GPU_COHERENCY_FEATURES is a bitmask of BIT(COHERENCY_xxx) values encoding the +* set of supported coherency protocols. GPU_COHERENCY_ENABLE is passed a +* COHERENCY_xxx value. +*/ #define GPU_COHERENCY_FEATURES 0x300/* (RO) Coherency features present */ -#define COHERENCY_ACE_LITE BIT(0) -#define COHERENCY_ACE BIT(1) +#define GPU_COHERENCY_ENABLE 0x304/* (RW) Coherency protocol selection */ +#define COHERENCY_ACE_LITE 0 +#define COHERENCY_ACE 1 +#define COHERENCY_NONE 31#define GPU_STACK_PRESENT_LO 0xE00/* (RO) Core stack present bitmap, low word */ #define GPU_STACK_PRESENT_HI 0xE04/* (RO) Core stack present bitmap, high word */
include/uapi/drm/panfrost_drm.h +7 -0
@@ -228,6 +228,13 @@ enum drm_panfrost_param {DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP ,DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP_FREQUENCY ,DRM_PANFROST_PARAM_ALLOWED_JM_CTX_PRIORITIES , + DRM_PANFROST_PARAM_SELECTED_COHERENCY, +}; + +enum drm_panfrost_gpu_coherency { +DRM_PANFROST_GPU_COHERENCY_ACE_LITE =0 , +DRM_PANFROST_GPU_COHERENCY_ACE =1 , +DRM_PANFROST_GPU_COHERENCY_NONE =31 , }; struct drm_panfrost_get_param {
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 10/13 drm/panfrost: Add a PANFROST_SYNC_BO ioctl
In reply to Boris BrezillonFrom: Faith Ekstrand <[email protected]>
This will be used by the UMD to synchronize CPU-cached mappings when the UMD can't do it directly (no usermode cache maintenance instruction on Arm32).
v2:
- Add more to the commit message
- Change the flags to better match the drm_gem_shmem_sync semantics
v3:
- Add Steve's R-b
v4:
- No changes
v5:
- Drop Steve's R-b (semantics changes requiring a new review)
v6:
- Bail out early in panfrost_ioctl_sync_bo() if op_count is zero
v7:
- Hand-roll our own bo_sync() helper
v8:
- Collect R-b
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 51 +++++++++++++++ drivers/gpu/drm/panfrost/panfrost_gem.c | 84 +++++++++++++++++++++++++ drivers/gpu/drm/panfrost/panfrost_gem.h | 2 + include/uapi/drm/panfrost_drm.h | 45 +++++++++++++ 4 files changed, 182 insertions(+)
drivers/gpu/drm/panfrost/panfrost_drv.c +51 -0
@@ -580,6 +580,56 @@ static int panfrost_ioctl_jm_ctx_destroy(struct drm_device *dev, void *data,return panfrost_jm_ctx_destroy (file, args->handle); } +static int panfrost_ioctl_sync_bo (struct drm_device *ddev,void *data, +struct drm_file *file) +{ +struct drm_panfrost_sync_bo *args = data; +struct drm_panfrost_bo_sync_op *ops; +struct drm_gem_object *obj; +int ret; +u32 i; + +if (args->pad) +return -EINVAL ; + +if (!args->op_count) +return 0 ; + + ops =kvmalloc_array (args->op_count,sizeof (*ops),GFP_KERNEL ); +if (!ops) { +DRM_DEBUG ("Failed to allocate incoming BO sync ops array\n" ); +return -ENOMEM ; + } + +if (copy_from_user (ops, (void __user *)(uintptr_t )args->ops, + args->op_count *sizeof (*ops))) { +DRM_DEBUG ("Failed to copy in BO sync ops\n" ); + ret = -EFAULT ; + goto err_ops; + } + +for (i =0 ; i < args->op_count; i++) { + obj =drm_gem_object_lookup (file, ops[i].handle); +if (!obj) { + ret = -ENOENT ; + goto err_ops; + } + + ret =panfrost_gem_sync (obj, ops[i].type, + ops[i].offset, ops[i].size); + +drm_gem_object_put (obj); + +if (ret) + goto err_ops; + } + +err_ops: +kvfree (ops); + +return ret; +} +int panfrost_unstable_ioctl_check (void ) {if (!unstable_ioctls)
@@ -649,6 +699,7 @@ static const struct drm_ioctl_desc panfrost_drm_driver_ioctls[] = {PANFROST_IOCTL (SET_LABEL_BO , set_label_bo,DRM_RENDER_ALLOW ),PANFROST_IOCTL (JM_CTX_CREATE , jm_ctx_create,DRM_RENDER_ALLOW ),PANFROST_IOCTL (JM_CTX_DESTROY , jm_ctx_destroy,DRM_RENDER_ALLOW ), + PANFROST_IOCTL(SYNC_BO, sync_bo, DRM_RENDER_ALLOW), }; static void panfrost_gpu_show_fdinfo(struct panfrost_device *pfdev,
drivers/gpu/drm/panfrost/panfrost_gem.c +84 -0
90 lines not on this page · raw message
drivers/gpu/drm/panfrost/panfrost_gem.h +2 -0
@@ -151,6 +151,8 @@ int panfrost_gem_shrinker_init(struct drm_device *dev);void panfrost_gem_shrinker_cleanup (struct drm_device *dev);void panfrost_gem_set_label (struct drm_gem_object *obj,const char *label); +int panfrost_gem_sync (struct drm_gem_object *obj,u32 type, +u32 offset,u32 size);void panfrost_gem_internal_set_label (struct drm_gem_object *obj,const char *label);#ifdef CONFIG_DEBUG_FS
include/uapi/drm/panfrost_drm.h +45 -0
63 lines not on this page · raw message
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 11/13 drm/panfrost: Add an ioctl to query BO flags
In reply to Boris BrezillonThis is useful when importing BOs, so we can know about cacheability and flush the caches when needed.
v2:
- New commit
v3:
- Add Steve's R-b
v4:
- No changes
v5:
- No changes
v6:
- No changes
v7:
- No changes
v8:
- No changes
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 33 +++++++++++++++++++++++++ include/uapi/drm/panfrost_drm.h | 19 ++++++++++++++ 2 files changed, 52 insertions(+)
drivers/gpu/drm/panfrost/panfrost_drv.c +33 -0
@@ -630,6 +630,38 @@ static int panfrost_ioctl_sync_bo(struct drm_device *ddev, void *data,return ret; } +static int panfrost_ioctl_query_bo_info (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_panfrost_query_bo_info *args = data; +struct drm_gem_object *gem_obj; +struct panfrost_gem_object *bo; + + gem_obj =drm_gem_object_lookup (file_priv, args->handle); +if (!gem_obj) { +DRM_DEBUG ("Failed to look up GEM BO %d\n" , args->handle); +return -ENOENT ; + } + + bo =to_panfrost_bo (gem_obj); + args->pad =0 ; + args->create_flags =0 ; + args->extra_flags =0 ; + +if (drm_gem_is_imported (gem_obj)) { + args->extra_flags |=DRM_PANFROST_BO_IS_IMPORTED ; + }else { +if (bo->noexec) + args->create_flags |=PANFROST_BO_NOEXEC ; + +if (bo->is_heap) + args->create_flags |=PANFROST_BO_HEAP ; + } + +drm_gem_object_put (gem_obj); +return 0 ; +} +int panfrost_unstable_ioctl_check (void ) {if (!unstable_ioctls)
@@ -700,6 +732,7 @@ static const struct drm_ioctl_desc panfrost_drm_driver_ioctls[] = {PANFROST_IOCTL (JM_CTX_CREATE , jm_ctx_create,DRM_RENDER_ALLOW ),PANFROST_IOCTL (JM_CTX_DESTROY , jm_ctx_destroy,DRM_RENDER_ALLOW ),PANFROST_IOCTL (SYNC_BO , sync_bo,DRM_RENDER_ALLOW ), + PANFROST_IOCTL(QUERY_BO_INFO, query_bo_info, DRM_RENDER_ALLOW), }; static void panfrost_gpu_show_fdinfo(struct panfrost_device *pfdev,
include/uapi/drm/panfrost_drm.h +19 -0
@@ -25,6 +25,7 @@ extern "C" {#define DRM_PANFROST_JM_CTX_CREATE 0x0a#define DRM_PANFROST_JM_CTX_DESTROY 0x0b#define DRM_PANFROST_SYNC_BO 0x0c +#define DRM_PANFROST_QUERY_BO_INFO 0x0d#define DRM_IOCTL_PANFROST_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_SUBMIT, struct drm_panfrost_submit)#define DRM_IOCTL_PANFROST_WAIT_BO DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_WAIT_BO, struct drm_panfrost_wait_bo)
@@ -37,6 +38,7 @@ extern "C" {#define DRM_IOCTL_PANFROST_JM_CTX_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_JM_CTX_CREATE, struct drm_panfrost_jm_ctx_create)#define DRM_IOCTL_PANFROST_JM_CTX_DESTROY DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_JM_CTX_DESTROY, struct drm_panfrost_jm_ctx_destroy)#define DRM_IOCTL_PANFROST_SYNC_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_SYNC_BO, struct drm_panfrost_sync_bo) +#define DRM_IOCTL_PANFROST_QUERY_BO_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_QUERY_BO_INFO, struct drm_panfrost_query_bo_info)/* * Unstable ioctl(s): only exposed when the unsafe unstable_ioctls module
@@ -353,6 +355,23 @@ struct drm_panfrost_sync_bo {__u32 pad; }; +/** BO comes from a different subsystem. */ +#define DRM_PANFROST_BO_IS_IMPORTED (1 << 0) + +struct drm_panfrost_query_bo_info { +/** Handle of the object being queried. */ +__u32 handle; + +/** Extra flags that are not coming from the BO_CREATE ioctl(). */ +__u32 extra_flags; + +/** Flags passed at creation time. */ +__u32 create_flags; + +/** Will be zero on return. */ +__u32 pad; +}; +/* Definitions for coredump decoding in user space */ #define PANFROSTDUMP_MAJOR 1#define PANFROSTDUMP_MINOR 0
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 12/13 drm/panfrost: Add flag to map GEM object Write-Back Cacheable
In reply to Boris BrezillonFrom: Faith Ekstrand <[email protected]>
Will be used by the UMD to optimize CPU accesses to buffers that are frequently read by the CPU, or on which the access pattern makes non-cacheable mappings inefficient.
Mapping buffers CPU-cached implies taking care of the CPU cache maintenance in the UMD, unless the GPU is IO coherent.
v2:
- Add more to the commit message
v3:
- No changes
v4:
- Fix the map_wc test in panfrost_ioctl_query_bo_info()
v5:
- Drop Steve's R-b (enough has changed to justify a new review)
v6:
- Collect R-b
v7:
- No changes
v8:
- Fix double drm_gem_object_funcs::export assignment
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 10 ++++++-- drivers/gpu/drm/panfrost/panfrost_gem.c | 32 +++++++++++++++++++++++++ drivers/gpu/drm/panfrost/panfrost_gem.h | 5 ++++ include/uapi/drm/panfrost_drm.h | 5 +++- 4 files changed, 49 insertions(+), 3 deletions(-)
drivers/gpu/drm/panfrost/panfrost_drv.c +8 -2
@@ -126,6 +126,10 @@ static int panfrost_ioctl_get_param(struct drm_device *ddev, void *data, structreturn 0 ; } +#define PANFROST_BO_FLAGS (PANFROST_BO_NOEXEC | \ + PANFROST_BO_HEAP | \ + PANFROST_BO_WB_MMAP) +static int panfrost_ioctl_create_bo (struct drm_device *dev,void *data,struct drm_file *file) {
@@ -135,8 +139,7 @@ static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data,struct panfrost_gem_mapping *mapping;int ret; -if (!args->size || args->pad || - (args->flags & ~(PANFROST_BO_NOEXEC |PANFROST_BO_HEAP ))) +if (!args->size || args->pad || (args->flags & ~PANFROST_BO_FLAGS ))return -EINVAL ;/* Heaps should never be executable */
@@ -656,6 +659,9 @@ static int panfrost_ioctl_query_bo_info(struct drm_device *dev, void *data,if (bo->is_heap) args->create_flags |=PANFROST_BO_HEAP ; + +if (!bo->base.map_wc) + args->create_flags |=PANFROST_BO_WB_MMAP ; }drm_gem_object_put (gem_obj);
drivers/gpu/drm/panfrost/panfrost_gem.c +32 -0
@@ -426,12 +426,42 @@ struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_treturn &obj->base.base; } +static bool +should_map_wc (struct panfrost_gem_object *bo) +{ +struct panfrost_device *pfdev =to_panfrost_device (bo->base.base.dev); + +/* We can't do uncached mappings if the device is coherent, +* because the zeroing done by the shmem layer at page allocation +* time happens on a cached mapping which isn't CPU-flushed (at least +* not on Arm64 where the flush is deferred to PTE setup time, and +* only done conditionally based on the mapping permissions). We can't +* rely on dma_map_sgtable()/dma_sync_sgtable_for_xxx() either to flush +* those, because they are NOPed if dma_dev_coherent() returns true. +*/ +if (pfdev->coherent) +return false; + +/* Cached mappings are explicitly requested, so no write-combine. */ +if (bo->wb_mmap) +return false; + +/* The default is write-combine. */ +return true; +} +struct panfrost_gem_object *panfrost_gem_create (struct drm_device *dev,size_t size,u32 flags) {struct drm_gem_shmem_object *shmem;struct panfrost_gem_object *bo; +/* The heap buffer is not supposed to be CPU-visible, so don't allow +* WB_MMAP on those. +*/ +if ((flags &PANFROST_BO_HEAP ) && (flags &PANFROST_BO_WB_MMAP )) +return ERR_PTR (-EINVAL ); +/* Round up heap allocations to 2MB to keep fault handling simple */ if (flags &PANFROST_BO_HEAP ) size =roundup (size,SZ_2M );
@@ -443,6 +473,8 @@ panfrost_gem_create(struct drm_device *dev, size_t size, u32 flags) bo =to_panfrost_bo (&shmem->base); bo->noexec = !!(flags &PANFROST_BO_NOEXEC ); bo->is_heap = !!(flags &PANFROST_BO_HEAP ); + bo->wb_mmap = !!(flags &PANFROST_BO_WB_MMAP ); + bo->base.map_wc =should_map_wc (bo);return bo; }
drivers/gpu/drm/panfrost/panfrost_gem.h +5 -0
@@ -98,6 +98,11 @@ struct panfrost_gem_object { bool noexec :1; bool is_heap :1; +/* On coherent devices, this reflects the creation flags, not the true +* cacheability attribute of the mapping. +*/ + bool wb_mmap :1; +#ifdef CONFIG_DEBUG_FS struct panfrost_gem_debugfs debugfs;#endif
include/uapi/drm/panfrost_drm.h +4 -1
@@ -124,9 +124,12 @@ struct drm_panfrost_wait_bo {__s64 timeout_ns; }; -/* Valid flags to pass to drm_panfrost_create_bo */ +/* Valid flags to pass to drm_panfrost_create_bo. +* PANFROST_BO_WB_MMAP can't be set if PANFROST_BO_HEAP is. +*/ #define PANFROST_BO_NOEXEC 1#define PANFROST_BO_HEAP 2 +#define PANFROST_BO_WB_MMAP 4/** * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.
Signature · 1 line
2.51.1
Boris Brezillon
maintainerPATCH v8 13/13 drm/panfrost: Bump the driver version to 1.6
In reply to Boris BrezillonFrom: Faith Ekstrand <[email protected]>
Bump the driver version to reflect the new cached-CPU mapping capability.
v2:
- Quickly describe what the new version exposes in the commit message
v3:
- Add Steve's R-b
v4:
- No changes
v5:
- No changes
v6:
- No changes
v7:
- No changes
v8:
- No changes
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_drv.c +4 -1
@@ -928,6 +928,9 @@ static void panfrost_debugfs_init(struct drm_minor *minor)* - 1.4 - adds SET_LABEL_BO * - 1.5 - adds JM_CTX_{CREATE,DESTROY} ioctls and extend SUBMIT to allow * context creation with configurable priorities/affinity +* - 1.6 - adds PANFROST_BO_MAP_WB, PANFROST_IOCTL_SYNC_BO, +* PANFROST_IOCTL_QUERY_BO_INFO and +* DRM_PANFROST_PARAM_SELECTED_COHERENCY */ static const struct drm_driver panfrost_drm_driver = { .driver_features =DRIVER_RENDER |DRIVER_GEM |DRIVER_SYNCOBJ ,
@@ -940,7 +943,7 @@ static const struct drm_driver panfrost_drm_driver = { .name = "panfrost", .desc = "panfrost DRM", .major = 1, - .minor = 5, + .minor = 6, .gem_create_object = panfrost_gem_create_object, .gem_prime_import = panfrost_gem_prime_import,
Signature · 1 line
2.51.1
Re: [PATCH v8 00/13] drm/panfrost,panthor: Cached maps and explicit flushing
In reply to Boris BrezillonQuoted 64 lines · On Mon, 8 Dec 2025 11:08:27 +0100 Boris Brezillon…
This series implements cached maps and explicit flushing for both panfrost and panthor.
The PanVK MR to use this lives here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36385
This version moves away from the code sharing proposed at the drm_prime/gem_shmem level and hand-roll a bunch of things that could potentially be shared. The goal here is to take the path of least resistance and discuss this controversial code-sharing topic in a follow-up MR. Dropping driver maintainers Cc-ed on v7 since they should now be aware that we changed gears and hand-rolled our own thing in pan{thor,frost}.
Changes in v2:
- Expose the coherency so userspace can know when it should skip cache maintenance
- Hook things up atdrm_gem_object_funcslevel to dma-bufcpu_prephooks can be implemented generically
- Revisit the semantics of the flags passed togem_sync()
- AddBO_QUERY_INFOioctls to query BO flags on imported objects and let the UMD know when cache maintenance is needed on thoseChanges in v3:
- New patch to fixpanthor_gpu_coherency_set()
- No other major changes, check each patch changelog for more detailsChanges in v4:
- Two trivial fixes, check each patch changelog for more detailsChanges in v5:
- Add a way to overloaddma_buf_opswhile still relying on thedrm_primeboilerplate
- Add default shmem implementation for dma_buf_ops::{begin,end}_cpu_access()
- Provide customdma_buf_opsto deal with CPU cache flushes around CPU accesses when the BO is CPU-cacheable
- Go back to a version ofdrm_gem_shmem_sync()that only deals with cache maintenance, and adjust the semantics to make it clear this is the only thing it cares about
- Adjust theBO_SYNCioctls according to the newdrm_gem_shmem_sync()semanticsChanges in v6:
- No major changes, check the changelog in each patch for more detailsChanges in v7:
- Drop the drm_prime/gem_shmem helpers and duplicate the logic in panthor/panfrostChanges in v8:
- Fix a double struct field assignment and collect R-b tagsBoris Brezillon (8):
drm/panthor: Provide a customdma_bufimplementation drm/panthor: Fixpanthor_gpu_coherency_set()drm/panthor: Expose the selected coherency protocol to the UMD drm/panthor: Add aPANTHOR_BO_SYNCioctl
drm/panthor: Add an ioctl to query BO flags drm/panfrost: Provide a customdma_bufimplementation drm/panfrost: Expose the selected coherency protocol to the UMD drm/panfrost: Add an ioctl to query BO flags
Quoted 8 lines
Faith Ekstrand (4):
drm/panthor: Bump the driver version to 1.7 drm/panfrost: Add aPANFROST_SYNC_BOioctl drm/panfrost: Add flag to map GEM object Write-Back Cacheable drm/panfrost: Bump the driver version to 1.6Loïc Molinari (1):
drm/panthor: Add flag to map GEM object Write-Back Cacheable
Queued to drm-misc-next.
Quoted 17 lines
drivers/gpu/drm/panfrost/panfrost_device.h | 1 + drivers/gpu/drm/panfrost/panfrost_drv.c | 101 ++++++++- drivers/gpu/drm/panfrost/panfrost_gem.c | 239 ++++++++++++++++++++ drivers/gpu/drm/panfrost/panfrost_gem.h | 10 + drivers/gpu/drm/panfrost/panfrost_gpu.c | 26 ++- drivers/gpu/drm/panfrost/panfrost_regs.h | 10 +- drivers/gpu/drm/panthor/panthor_device.c | 10 +- drivers/gpu/drm/panthor/panthor_drv.c | 79 ++++++- drivers/gpu/drm/panthor/panthor_gem.c | 240 ++++++++++++++++++++- drivers/gpu/drm/panthor/panthor_gem.h | 6 + drivers/gpu/drm/panthor/panthor_gpu.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 18 +- include/uapi/drm/panfrost_drm.h | 76 ++++++- include/uapi/drm/panthor_drm.h | 157 +++++++++++++- 14 files changed, 953 insertions(+), 22 deletions(-)