accel/ivpu: Update for -next 2024-01-04
Subsystems (4)
cover accel/ivpu: Update for -next 2024-01-04
Various driver updates:
- Fixes for driver crashes caused by unbind
- Fixes for driver crashes during reset/recovery
- Deprecated DRM_IVPU_PARAM_CONTEXT_PRIORITY
- Improved support for 40xx
- Improved diagnostic messages
- ivpu_job.c refactor
Grzegorz Trzebiatowski (1):
accel/ivpu: New job status for jobs aborted by the driver
Jacek Lawrynowicz (8):
accel/ivpu: Fix potential infinite loops in IRQ handlers accel/ivpu: Fix for missing lock around drm_gem_shmem_vmap() accel/ivpu: Free buffer sgt on unbind
accel/ivpu: Disable buffer sharing among VPU contexts accel/ivpu: Improve buffer object debug logs accel/ivpu: Fix dev open/close races with unbind accel/ivpu: Refactor ivpu_submit_ioctl() accel/ivpu: Improve recovery and reset support
Krystian Pradzynski (2):
accel/ivpu/40xx: Enable D0i3 message feature accel/ivpu/40xx: Stop passing SKU boot parameters to FW
Wachowski, Karol (5):
accel/ivpu: Dump MMU events in case of VPU boot timeout accel/ivpu: Call diagnose failure in ivpu_mmu_cmdq_sync() accel/ivpu: Add debug prints for MMU map/unmap operations accel/ivpu: Remove deprecated DRM_IVPU_PARAM_CONTEXT_PRIORITY accel/ivpu: Add diagnostic messages when VPU fails to boot or suspend
drivers/accel/ivpu/ivpu_debugfs.c | 20 +++- drivers/accel/ivpu/ivpu_drv.c | 127 +++++++++++--------- drivers/accel/ivpu/ivpu_drv.h | 5 +- drivers/accel/ivpu/ivpu_fw.c | 1 - drivers/accel/ivpu/ivpu_gem.c | 142 +++++++++------------- drivers/accel/ivpu/ivpu_gem.h | 3 +- drivers/accel/ivpu/ivpu_hw_37xx.c | 14 +-- drivers/accel/ivpu/ivpu_hw_40xx.c | 13 +-- drivers/accel/ivpu/ivpu_ipc.c | 12 +- drivers/accel/ivpu/ivpu_job.c | 162 ++++++++++++-------------- drivers/accel/ivpu/ivpu_job.h | 3 +- drivers/accel/ivpu/ivpu_mmu.c | 29 +++-- drivers/accel/ivpu/ivpu_mmu.h | 1 + drivers/accel/ivpu/ivpu_mmu_context.c | 9 ++ drivers/accel/ivpu/ivpu_pm.c | 52 ++++++--- drivers/accel/ivpu/ivpu_pm.h | 6 +- include/uapi/drm/ivpu_accel.h | 22 +++- 17 files changed, 327 insertions(+), 294 deletions(-)
--
2.43.0
PATCH 1/16 accel/ivpu: Dump MMU events in case of VPU boot timeout
From: "Wachowski, Karol" <[email protected]>
Add ivpu_mmu_evtq_dump() function that dumps existing MMU events from MMU event queue. Call this function if VPU boot failed.
Previously MMU events were only checked in interrupt handler, but if VPU failed to boot due to MMU faults, those faults were missed because of interrupts not yet being enabled. This will allow checking potential fault reason of VPU not booting.
--- drivers/accel/ivpu/ivpu_drv.c | 1 + drivers/accel/ivpu/ivpu_mmu.c | 8 ++++++++ drivers/accel/ivpu/ivpu_mmu.h | 1 + 3 files changed, 10 insertions(+)
drivers/accel/ivpu/ivpu_drv.c +1 -0
@@ -369,6 +369,7 @@ int ivpu_boot(struct ivpu_device *vdev) ret =ivpu_wait_for_ready (vdev);if (ret) {ivpu_err (vdev,"Failed to boot the firmware: %d\n" , ret); +ivpu_mmu_evtq_dump (vdev);return ret; }
drivers/accel/ivpu/ivpu_mmu.c +8 -0
@@ -905,6 +905,14 @@ void ivpu_mmu_irq_evtq_handler(struct ivpu_device *vdev)ivpu_pm_schedule_recovery (vdev); } +void ivpu_mmu_evtq_dump (struct ivpu_device *vdev) +{ +u32 *event; + +while ((event =ivpu_mmu_get_event (vdev)) !=NULL ) +ivpu_mmu_dump_event (vdev, event); +} +void ivpu_mmu_irq_gerr_handler (struct ivpu_device *vdev) {u32 gerror_val, gerrorn_val, active;
drivers/accel/ivpu/ivpu_mmu.h +1 -0
@@ -46,5 +46,6 @@ int ivpu_mmu_invalidate_tlb(struct ivpu_device *vdev, u16 ssid);void ivpu_mmu_irq_evtq_handler (struct ivpu_device *vdev);void ivpu_mmu_irq_gerr_handler (struct ivpu_device *vdev); +void ivpu_mmu_evtq_dump (struct ivpu_device *vdev);#endif /* __IVPU_MMU_H__ */
Signature · 1 line
2.43.0
Re: [PATCH 01/16] accel/ivpu: Dump MMU events in case of VPU boot timeout
Quoted 5 lines · Jacek Lawrynowicz
From: "Wachowski, Karol" <[email protected]>
Add
ivpu_mmu_evtq_dump()function that dumps existing MMU events from MMU event queue. Call this function if VPU boot failed.
Quoted 7 lines
Previously MMU events were only checked in interrupt handler, but if VPU failed to boot due to MMU faults, those faults were missed because of interrupts not yet being enabled. This will allow checking potential fault reason of VPU not booting.
Signed-off-by Wachowski, Karol <[email protected]>Signed-off-by Jacek Lawrynowicz <[email protected]>
PATCH 2/16 accel/ivpu: Call diagnose failure in ivpu_mmu_cmdq_sync()
In reply to Jacek LawrynowiczFrom: "Wachowski, Karol" <[email protected]>
Check for possible failure reasons in the buttress.
Some errors (like external abort) should have corresponding buttress errors registers set indicating the real reason of failure.
--- drivers/accel/ivpu/ivpu_mmu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/accel/ivpu/ivpu_mmu.c +2 -0
@@ -7,6 +7,7 @@#include <linux/highmem.h> #include "ivpu_drv.h" +#include "ivpu_hw.h" #include "ivpu_hw_reg_io.h" #include "ivpu_mmu.h" #include "ivpu_mmu_context.h"
@@ -518,6 +519,7 @@ static int ivpu_mmu_cmdq_sync(struct ivpu_device *vdev)ivpu_err (vdev,"Timed out waiting for MMU consumer: %d, error: %s\n" , ret,ivpu_mmu_cmdq_err_to_str (err)); +ivpu_hw_diagnose_failure (vdev); }return ret;
Signature · 1 line
2.43.0
PATCH 3/16 accel/ivpu: Fix potential infinite loops in IRQ handlers
In reply to Jacek LawrynowiczLimit number of iterations in ivpu_mmu_irq_evtq_handler() and ivpu_ipc_irq_handler().
--- drivers/accel/ivpu/ivpu_ipc.c | 6 ++++++ drivers/accel/ivpu/ivpu_mmu.c | 21 +++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-)
drivers/accel/ivpu/ivpu_ipc.c +6 -0
@@ -389,12 +389,18 @@ void ivpu_ipc_irq_handler(struct ivpu_device *vdev, bool *wake_thread)unsigned long flags;bool dispatched;u32 vpu_addr; +int msg_count =0 ;/* * Driver needs to purge all messages from IPC FIFO to clear IPC interrupt. * Without purge IPC FIFO to 0 next IPC interrupts won't be generated. */ while (ivpu_hw_reg_ipc_rx_count_get (vdev)) { +if (++msg_count >IPC_MAX_RX_MSG ) { +ivpu_pm_schedule_recovery (vdev); +return ; + } + vpu_addr =ivpu_hw_reg_ipc_rx_addr_get (vdev);if (vpu_addr ==REG_IO_ERROR ) {ivpu_err_ratelimited (vdev,"Failed to read IPC rx addr register\n" );
drivers/accel/ivpu/ivpu_mmu.c +13 -8
@@ -236,6 +236,8 @@#define IVPU_MMU_CERROR_ABT 0x2#define IVPU_MMU_CERROR_ATC_INV_SYNC 0x3 +#define IVPU_MMU_MAX_EVENT_COUNT 100 +static const char *ivpu_mmu_event_to_str (u32 cmd) {switch (cmd) {
@@ -887,7 +889,7 @@ static u32 *ivpu_mmu_get_event(struct ivpu_device *vdev)void ivpu_mmu_irq_evtq_handler (struct ivpu_device *vdev) { -bool schedule_recovery = false; +int event_count =0 ;u32 *event;u32 ssid;
@@ -895,16 +897,19 @@ void ivpu_mmu_irq_evtq_handler(struct ivpu_device *vdev)while ((event =ivpu_mmu_get_event (vdev)) !=NULL ) {ivpu_mmu_dump_event (vdev, event); +if (++event_count >IVPU_MMU_MAX_EVENT_COUNT ) { +ivpu_pm_schedule_recovery (vdev); +return ; + } ssid =FIELD_GET (IVPU_MMU_EVT_SSID_MASK , event[0 ]); -if (ssid ==IVPU_GLOBAL_CONTEXT_MMU_SSID ) - schedule_recovery = true; -else -ivpu_mmu_user_context_mark_invalid (vdev, ssid); - } +if (ssid ==IVPU_GLOBAL_CONTEXT_MMU_SSID ) { +ivpu_pm_schedule_recovery (vdev); +return ; + } -if (schedule_recovery) -ivpu_pm_schedule_recovery (vdev); +ivpu_mmu_user_context_mark_invalid (vdev, ssid); + } }void ivpu_mmu_evtq_dump (struct ivpu_device *vdev)
Signature · 1 line
2.43.0
PATCH 4/16 accel/ivpu: Add debug prints for MMU map/unmap operations
In reply to Jacek LawrynowiczFrom: "Wachowski, Karol" <[email protected]>
It is common need to be able to see IOVA/physical to VPU addresses mappings. Especially when debugging different kind of memory related issues. Lack of such logs forces user to modify and recompile KMD manually.
This commit adds those logs under MMU debug mask which can be turned on dynamically with module param during KMD load.
--- drivers/accel/ivpu/ivpu_drv.h | 1 + drivers/accel/ivpu/ivpu_mmu_context.c | 9 +++++++++ 2 files changed, 10 insertions(+)
drivers/accel/ivpu/ivpu_drv.h +1 -0
@@ -56,6 +56,7 @@#define IVPU_DBG_JSM BIT(10)#define IVPU_DBG_KREF BIT(11)#define IVPU_DBG_RPM BIT(12) +#define IVPU_DBG_MMU_MAP BIT(13)#define ivpu_err (vdev, fmt, ...) \ drm_err(&(vdev)->drm, "%s(): " fmt, __func__, ##__VA_ARGS__)
drivers/accel/ivpu/ivpu_mmu_context.c +9 -0
@@ -355,6 +355,9 @@ ivpu_mmu_context_map_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,dma_addr_t dma_addr =sg_dma_address (sg) - sg->offset;size_t size =sg_dma_len (sg) + sg->offset; +ivpu_dbg (vdev,MMU_MAP ,"Map ctx: %u dma_addr: 0x%llx vpu_addr: 0x%llx size: %lu\n" , + ctx->id, dma_addr, vpu_addr, size); + ret =ivpu_mmu_context_map_pages (vdev, ctx, vpu_addr, dma_addr, size, prot);if (ret) {ivpu_err (vdev,"Failed to map context pages\n" );
@@ -366,6 +369,7 @@ ivpu_mmu_context_map_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,/* Ensure page table modifications are flushed from wc buffers to memory */ wmb (); +mutex_unlock (&ctx->lock); ret =ivpu_mmu_invalidate_tlb (vdev, ctx->id);
@@ -388,14 +392,19 @@ ivpu_mmu_context_unmap_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctmutex_lock (&ctx->lock);for_each_sgtable_dma_sg (sgt, sg, i) { +dma_addr_t dma_addr =sg_dma_address (sg) - sg->offset;size_t size =sg_dma_len (sg) + sg->offset; +ivpu_dbg (vdev,MMU_MAP ,"Unmap ctx: %u dma_addr: 0x%llx vpu_addr: 0x%llx size: %lu\n" , + ctx->id, dma_addr, vpu_addr, size); +ivpu_mmu_context_unmap_pages (ctx, vpu_addr, size); vpu_addr += size; }/* Ensure page table modifications are flushed from wc buffers to memory */ wmb (); +mutex_unlock (&ctx->lock); ret =ivpu_mmu_invalidate_tlb (vdev, ctx->id);
Signature · 1 line
2.43.0
PATCH 5/16 accel/ivpu/40xx: Enable D0i3 message feature
In reply to Jacek LawrynowiczFrom: Krystian Pradzynski <[email protected]>
All recent 40xx firmware already supports D0i3 entry message.
--- drivers/accel/ivpu/ivpu_fw.c | 1 - 1 file changed, 1 deletion(-)
drivers/accel/ivpu/ivpu_fw.c +0 -1
@@ -222,7 +222,6 @@ ivpu_fw_init_wa(struct ivpu_device *vdev)const struct vpu_firmware_header *fw_hdr = (const void *)vdev->fw->file->data;if (IVPU_FW_CHECK_API_VER_LT (vdev, fw_hdr,BOOT ,3 ,17 ) || - (ivpu_hw_gen (vdev) >IVPU_HW_37XX ) || (ivpu_test_mode &IVPU_TEST_MODE_D0I3_MSG_DISABLE )) vdev->wa.disable_d0i3_msg = true;
Signature · 1 line
2.43.0
PATCH 6/16 accel/ivpu: Fix for missing lock around drm_gem_shmem_vmap()
In reply to Jacek Lawrynowiczdrm_gem_shmem_vmap/vunmap requires dma resv lock to be held. This was missed during conversion to shmem helper.
--- drivers/accel/ivpu/ivpu_gem.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/accel/ivpu/ivpu_gem.c +5 -0
@@ -361,7 +361,9 @@ ivpu_bo_alloc_internal(struct ivpu_device *vdev, u64 vpu_addr, u64 size, u32 flaif (ret) goto err_put; +dma_resv_lock (bo->base.base.resv,NULL ); ret =drm_gem_shmem_vmap (&bo->base, &map); +dma_resv_unlock (bo->base.base.resv);if (ret) goto err_put;
@@ -376,7 +378,10 @@ void ivpu_bo_free_internal(struct ivpu_bo *bo) {struct iosys_map map =IOSYS_MAP_INIT_VADDR (bo->base.vaddr); +dma_resv_lock (bo->base.base.resv,NULL );drm_gem_shmem_vunmap (&bo->base, &map); +dma_resv_unlock (bo->base.base.resv); +drm_gem_object_put (&bo->base.base); }
Signature · 1 line
2.43.0
PATCH 7/16 accel/ivpu: Free buffer sgt on unbind
In reply to Jacek LawrynowiczCall dma_unmap() on all buffers before to VPU is unbinded to avoid "device driver has pending DMA allocations while released from device" warning when DMA-API debug is enabled.
--- drivers/accel/ivpu/ivpu_gem.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/accel/ivpu/ivpu_gem.c +12 -2
@@ -112,8 +112,6 @@ static void ivpu_bo_unbind_locked(struct ivpu_bo *bo)ivpu_dbg_bo (vdev, bo,"unbind" ); -/* TODO: dma_unmap */ -if (bo->mmu_mapped) {drm_WARN_ON (&vdev->drm, !bo->ctx);drm_WARN_ON (&vdev->drm, !bo->vpu_addr);
@@ -127,6 +125,18 @@ static void ivpu_bo_unbind_locked(struct ivpu_bo *bo) bo->vpu_addr =0 ; bo->ctx =NULL ; } + +if (bo->base.base.import_attach) +return ; + +dma_resv_lock (bo->base.base.resv,NULL ); +if (bo->base.sgt) { +dma_unmap_sgtable (vdev->drm.dev, bo->base.sgt,DMA_BIDIRECTIONAL ,0 ); +sg_free_table (bo->base.sgt); +kfree (bo->base.sgt); + bo->base.sgt =NULL ; + } +dma_resv_unlock (bo->base.base.resv); }static void ivpu_bo_unbind (struct ivpu_bo *bo)
Signature · 1 line
2.43.0
PATCH 8/16 accel/ivpu: Disable buffer sharing among VPU contexts
In reply to Jacek LawrynowiczThis was not supported properly. A buffer was imported to another VPU context as a separate buffer object with duplicated sgt. Both exported and imported buffers could be DMA mapped causing a double mapping on the same device.
Imported buffer from another VPU context will now have just reference increased and there will be a single sgt fixing above problem but buffers still can't be shared among VPU contexts because each context have its own MMU mapping and ivpu_bo supports only single MMU mapping.
The solution would be to use a mapping list as in panfrost or etnaviv drivers and it will be implemented in future if required.
--- drivers/accel/ivpu/ivpu_gem.c | 44 +++++------------------------------ 1 file changed, 6 insertions(+), 38 deletions(-)
drivers/accel/ivpu/ivpu_gem.c +6 -38
@@ -222,6 +222,12 @@ static int ivpu_bo_open(struct drm_gem_object *obj, struct drm_file *file)struct ivpu_bo *bo =to_ivpu_bo (obj);struct ivpu_addr_range *range; +if (bo->ctx) { +ivpu_warn (vdev,"Can't add BO (vpu_addr 0x%llx) to ctx %u: already in ctx %u\n" , + bo->vpu_addr, file_priv->ctx.id, bo->ctx->id); +return -EALREADY ; + } +if (bo->flags &DRM_IVPU_BO_SHAVE_MEM ) range = &vdev->hw->ranges.shave;else if (bo->flags &DRM_IVPU_BO_DMA_MEM )
@@ -252,47 +258,9 @@ static void ivpu_bo_free(struct drm_gem_object *obj)drm_gem_shmem_free (&bo->base); } -static const struct dma_buf_ops ivpu_bo_dmabuf_ops = { - .cache_sgt_mapping = true, - .attach = drm_gem_map_attach, - .detach = drm_gem_map_detach, - .map_dma_buf = drm_gem_map_dma_buf, - .unmap_dma_buf = drm_gem_unmap_dma_buf, - .release = drm_gem_dmabuf_release, - .mmap = drm_gem_dmabuf_mmap, - .vmap = drm_gem_dmabuf_vmap, - .vunmap = drm_gem_dmabuf_vunmap, -}; - -static struct dma_buf *ivpu_bo_export (struct drm_gem_object *obj,int flags) -{ -struct drm_device *dev = obj->dev; -struct dma_buf_export_info exp_info = { - .exp_name =KBUILD_MODNAME , - .owner = dev->driver->fops->owner, - .ops = &ivpu_bo_dmabuf_ops, - .size = obj->size, - .flags = flags, - .priv = obj, - .resv = obj->resv, - }; -void *sgt; - -/* -* Make sure that pages are allocated and dma-mapped before exporting the bo. -* DMA-mapping is required if the bo will be imported to the same device. -*/ - sgt =drm_gem_shmem_get_pages_sgt (to_drm_gem_shmem_obj (obj)); -if (IS_ERR (sgt)) -return sgt; - -return drm_gem_dmabuf_export (dev, &exp_info); -} -static const struct drm_gem_object_funcs ivpu_gem_funcs = { .free = ivpu_bo_free, .open = ivpu_bo_open, - .export = ivpu_bo_export, .print_info = drm_gem_shmem_object_print_info, .pin = drm_gem_shmem_object_pin, .unpin = drm_gem_shmem_object_unpin,
Signature · 1 line
2.43.0
PATCH 9/16 accel/ivpu: Improve buffer object debug logs
In reply to Jacek LawrynowiczMake debug logs more readable and consistent:
- don't print handle as it is not always available for all buffers
- use hashed ivpu_bo ptr as main buffer identifier
- remove unused fields from ivpu_bo_print_info()
--- drivers/accel/ivpu/ivpu_gem.c | 72 +++++++++++------------------------ drivers/accel/ivpu/ivpu_gem.h | 1 - 2 files changed, 23 insertions(+), 50 deletions(-)
drivers/accel/ivpu/ivpu_gem.c +23 -49
@@ -24,14 +24,11 @@ static const struct drm_gem_object_funcs ivpu_gem_funcs;static inline void ivpu_dbg_bo (struct ivpu_device *vdev,struct ivpu_bo *bo,const char *action) { -if (bo->ctx) -ivpu_dbg (vdev,BO ,"%6s: size %zu has_pages %d dma_mapped %d handle %u ctx %d vpu_addr 0x%llx mmu_mapped %d\n" , - action,ivpu_bo_size (bo), (bool )bo->base.pages, (bool )bo->base.sgt, - bo->handle, bo->ctx->id, bo->vpu_addr, bo->mmu_mapped); -else -ivpu_dbg (vdev,BO ,"%6s: size %zu has_pages %d dma_mapped %d handle %u (not added to context)\n" , - action,ivpu_bo_size (bo), (bool )bo->base.pages, (bool )bo->base.sgt, - bo->handle); +ivpu_dbg (vdev,BO , +"%6s: bo %8p vpu_addr %9llx size %8zu ctx %d has_pages %d dma_mapped %d mmu_mapped %d wc %d imported %d\n" , + action, bo, bo->vpu_addr,ivpu_bo_size (bo), bo->ctx ? bo->ctx->id :0 , + (bool )bo->base.pages, (bool )bo->base.sgt, bo->mmu_mapped, bo->base.map_wc, + (bool )bo->base.base.import_attach); }/*
@@ -49,12 +46,7 @@ int __must_check ivpu_bo_pin(struct ivpu_bo *bo)mutex_lock (&bo->lock);ivpu_dbg_bo (vdev, bo,"pin" ); - -if (!bo->ctx) { -ivpu_err (vdev,"vpu_addr not allocated for BO %d\n" , bo->handle); - ret = -EINVAL ; - goto unlock; - } +drm_WARN_ON (&vdev->drm, !bo->ctx);if (!bo->mmu_mapped) {struct sg_table *sgt =drm_gem_shmem_get_pages_sgt (&bo->base);
@@ -108,9 +100,7 @@ static void ivpu_bo_unbind_locked(struct ivpu_bo *bo) {struct ivpu_device *vdev =ivpu_bo_to_vdev (bo); -lockdep_assert_held (&bo->lock); - -ivpu_dbg_bo (vdev, bo,"unbind" ); +lockdep_assert (lockdep_is_held (&bo->lock) || !kref_read (&bo->base.base.refcount));if (bo->mmu_mapped) {drm_WARN_ON (&vdev->drm, !bo->ctx);
@@ -122,7 +112,6 @@ static void ivpu_bo_unbind_locked(struct ivpu_bo *bo)if (bo->ctx) {ivpu_mmu_context_remove_node (bo->ctx, &bo->mm_node); - bo->vpu_addr =0 ; bo->ctx =NULL ; }
@@ -139,13 +128,6 @@ static void ivpu_bo_unbind_locked(struct ivpu_bo *bo)dma_resv_unlock (bo->base.base.resv); } -static void ivpu_bo_unbind (struct ivpu_bo *bo) -{ -mutex_lock (&bo->lock); -ivpu_bo_unbind_locked (bo); -mutex_unlock (&bo->lock); -} -void ivpu_bo_remove_all_bos_from_context (struct ivpu_device *vdev,struct ivpu_mmu_context *ctx) {struct ivpu_bo *bo;
@@ -156,8 +138,10 @@ void ivpu_bo_remove_all_bos_from_context(struct ivpu_device *vdev, struct ivpu_mmutex_lock (&vdev->bo_list_lock);list_for_each_entry (bo, &vdev->bo_list, bo_list_node) {mutex_lock (&bo->lock); -if (bo->ctx == ctx) +if (bo->ctx == ctx) { +ivpu_dbg_bo (vdev, bo,"unbind" );ivpu_bo_unbind_locked (bo); + }mutex_unlock (&bo->lock); }mutex_unlock (&vdev->bo_list_lock);
@@ -209,9 +193,6 @@ ivpu_bo_create(struct ivpu_device *vdev, u64 size, u32 flags)list_add_tail (&bo->bo_list_node, &vdev->bo_list);mutex_unlock (&vdev->bo_list_lock); -ivpu_dbg (vdev,BO ,"create: vpu_addr 0x%llx size %zu flags 0x%x\n" , - bo->vpu_addr, bo->base.base.size, flags); -return bo; }
@@ -243,15 +224,15 @@ static void ivpu_bo_free(struct drm_gem_object *obj)struct ivpu_device *vdev =to_ivpu_device (obj->dev);struct ivpu_bo *bo =to_ivpu_bo (obj); +ivpu_dbg_bo (vdev, bo,"free" ); +mutex_lock (&vdev->bo_list_lock);list_del (&bo->bo_list_node);mutex_unlock (&vdev->bo_list_lock);drm_WARN_ON (&vdev->drm, !dma_resv_test_signaled (obj->resv,DMA_RESV_USAGE_READ )); -ivpu_dbg_bo (vdev, bo,"free" ); - -ivpu_bo_unbind (bo); +ivpu_bo_unbind_locked (bo);mutex_destroy (&bo->lock);drm_WARN_ON (obj->dev, bo->base.pages_use_count >1 );
@@ -293,11 +274,9 @@ int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *fireturn PTR_ERR (bo); } - ret =drm_gem_handle_create (file, &bo->base.base, &bo->handle); -if (!ret) { + ret =drm_gem_handle_create (file, &bo->base.base, &args->handle); +if (!ret) args->vpu_addr = bo->vpu_addr; - args->handle = bo->handle; - }drm_gem_object_put (&bo->base.base);
@@ -415,19 +394,11 @@ int ivpu_bo_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filestatic void ivpu_bo_print_info (struct ivpu_bo *bo,struct drm_printer *p) { -unsigned long dma_refcount =0 ; -mutex_lock (&bo->lock); -if (bo->base.base.dma_buf && bo->base.base.dma_buf->file) - dma_refcount =atomic_long_read (&bo->base.base.dma_buf->file->f_count); - -drm_printf (p,"%-3u %-6d 0x%-12llx %-10lu 0x%-8x %-4u %-8lu" , - bo->ctx->id, bo->handle, bo->vpu_addr, bo->base.base.size, - bo->flags,kref_read (&bo->base.base.refcount), dma_refcount); - -if (bo->base.base.import_attach) -drm_printf (p," imported" ); +drm_printf (p,"%-9p %-3u 0x%-12llx %-10lu 0x%-8x %-4u" , + bo, bo->ctx->id, bo->vpu_addr, bo->base.base.size, + bo->flags,kref_read (&bo->base.base.refcount));if (bo->base.pages)drm_printf (p," has_pages" );
@@ -435,6 +406,9 @@ static void ivpu_bo_print_info(struct ivpu_bo *bo, struct drm_printer *p)if (bo->mmu_mapped)drm_printf (p," mmu_mapped" ); +if (bo->base.base.import_attach) +drm_printf (p," imported" ); +drm_printf (p,"\n" );mutex_unlock (&bo->lock);
@@ -445,8 +419,8 @@ void ivpu_bo_list(struct drm_device *dev, struct drm_printer *p)struct ivpu_device *vdev =to_ivpu_device (dev);struct ivpu_bo *bo; -drm_printf (p,"%-3s %-6s %-14s %-10s %-10s %-4s %-8s %s\n" , -"ctx" ,"handle" ,"vpu_addr" ,"size" ,"flags" ,"refs" ,"dma_refs" ,"attribs" ); +drm_printf (p,"%-9s %-3s %-14s %-10s %-10s %-4s %s\n" , +"bo" ,"ctx" ,"vpu_addr" ,"size" ,"flags" ,"refs" ,"attribs" );mutex_lock (&vdev->bo_list_lock);list_for_each_entry (bo, &vdev->bo_list, bo_list_node)
drivers/accel/ivpu/ivpu_gem.h +0 -1
@@ -19,7 +19,6 @@ struct ivpu_bo {struct mutex lock;/* Protects: ctx, mmu_mapped, vpu_addr */ u64 vpu_addr; -u32 handle;u32 flags;u32 job_status;/* Valid only for command buffer */ bool mmu_mapped;
Signature · 1 line
2.43.0
PATCH 10/16 accel/ivpu/40xx: Stop passing SKU boot parameters to FW
In reply to Jacek LawrynowiczFrom: Krystian Pradzynski <[email protected]>
This parameter was never used by the 40xx FW.
--- drivers/accel/ivpu/ivpu_hw_40xx.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/accel/ivpu/ivpu_hw_40xx.c +0 -5
@@ -704,7 +704,6 @@ static int ivpu_hw_40xx_info_init(struct ivpu_device *vdev) {struct ivpu_hw_info *hw = vdev->hw;u32 tile_disable; -u32 tile_enable;u32 fuse; fuse =REGB_RD32 (VPU_40XX_BUTTRESS_TILE_FUSE );
@@ -725,10 +724,6 @@ static int ivpu_hw_40xx_info_init(struct ivpu_device *vdev)else ivpu_dbg (vdev,MISC ,"Fuse: All %d tiles enabled\n" ,TILE_MAX_NUM ); - tile_enable = (~tile_disable) &TILE_MAX_MASK ; - - hw->sku =REG_SET_FLD_NUM (SKU ,HW_ID ,LNL_HW_ID , hw->sku); - hw->sku =REG_SET_FLD_NUM (SKU ,TILE , tile_enable, hw->sku); hw->tile_fuse = tile_disable; hw->pll.profiling_freq =PLL_PROFILING_FREQ_DEFAULT ;
Signature · 1 line
2.43.0
PATCH 11/16 accel/ivpu: Remove deprecated DRM_IVPU_PARAM_CONTEXT_PRIORITY
In reply to Jacek LawrynowiczFrom: "Wachowski, Karol" <[email protected]>
DRM_IVPU_PARAM_CONTEXT_PRIORITY has been deprecated because it has been replaced with DRM_IVPU_JOB_PRIORITY levels set with submit IOCTL and was unused anyway.
--- drivers/accel/ivpu/ivpu_drv.c | 11 ----------- drivers/accel/ivpu/ivpu_drv.h | 1 - drivers/accel/ivpu/ivpu_job.c | 3 +++ include/uapi/drm/ivpu_accel.h | 21 ++++++++++++++++++++- 4 files changed, 23 insertions(+), 13 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +0 -11
@@ -176,9 +176,6 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_fcase DRM_IVPU_PARAM_CONTEXT_BASE_ADDRESS : args->value = vdev->hw->ranges.user.start;break ; -case DRM_IVPU_PARAM_CONTEXT_PRIORITY : - args->value = file_priv->priority; -break ;case DRM_IVPU_PARAM_CONTEXT_ID : args->value = file_priv->ctx.id;break ;
@@ -218,17 +215,10 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_fstatic int ivpu_set_param_ioctl (struct drm_device *dev,void *data,struct drm_file *file) { -struct ivpu_file_priv *file_priv = file->driver_priv;struct drm_ivpu_param *args = data;int ret =0 ;switch (args->param) { -case DRM_IVPU_PARAM_CONTEXT_PRIORITY : -if (args->value <=DRM_IVPU_CONTEXT_PRIORITY_REALTIME ) - file_priv->priority = args->value; -else - ret = -EINVAL ; -break ;default : ret = -EINVAL ; }
@@ -257,7 +247,6 @@ static int ivpu_open(struct drm_device *dev, struct drm_file *file) } file_priv->vdev = vdev; - file_priv->priority =DRM_IVPU_CONTEXT_PRIORITY_NORMAL ;kref_init (&file_priv->ref);mutex_init (&file_priv->lock);
drivers/accel/ivpu/ivpu_drv.h +0 -1
@@ -146,7 +146,6 @@ struct ivpu_file_priv {struct mutex lock;/* Protects cmdq */ struct ivpu_cmdq *cmdq[IVPU_NUM_ENGINES ];struct ivpu_mmu_context ctx; -u32 priority;bool has_mmu_faults; };
drivers/accel/ivpu/ivpu_job.c +3 -0
@@ -488,6 +488,9 @@ int ivpu_submit_ioctl(struct drm_device *dev, void *data, struct drm_file *file)if (params->engine >DRM_IVPU_ENGINE_COPY )return -EINVAL ; +if (params->priority >DRM_IVPU_JOB_PRIORITY_REALTIME ) +return -EINVAL ; +if (params->buffer_count ==0 || params->buffer_count >JOB_MAX_BUFFER_COUNT )return -EINVAL ;
include/uapi/drm/ivpu_accel.h +20 -1
@@ -13,7 +13,7 @@ extern "C" {#endif #define DRM_IVPU_DRIVER_MAJOR 1 -#define DRM_IVPU_DRIVER_MINOR 0 +#define DRM_IVPU_DRIVER_MINOR 1#define DRM_IVPU_GET_PARAM 0x00#define DRM_IVPU_SET_PARAM 0x01
@@ -64,11 +64,18 @@ extern "C" {#define DRM_IVPU_PLATFORM_TYPE_SILICON 0 +/* Deprecated - to be removed */ #define DRM_IVPU_CONTEXT_PRIORITY_IDLE 0#define DRM_IVPU_CONTEXT_PRIORITY_NORMAL 1#define DRM_IVPU_CONTEXT_PRIORITY_FOCUS 2#define DRM_IVPU_CONTEXT_PRIORITY_REALTIME 3 +#define DRM_IVPU_JOB_PRIORITY_DEFAULT 0 +#define DRM_IVPU_JOB_PRIORITY_IDLE 1 +#define DRM_IVPU_JOB_PRIORITY_NORMAL 2 +#define DRM_IVPU_JOB_PRIORITY_FOCUS 3 +#define DRM_IVPU_JOB_PRIORITY_REALTIME 4 +/** * DRM_IVPU_CAP_METRIC_STREAMER *
@@ -286,6 +293,18 @@ struct drm_ivpu_submit {* to be executed. The offset has to be 8-byte aligned. */ __u32 commands_offset; + +/** +* @priority: +* +* Priority to be set for related job command queue, can be one of the following: +* %DRM_IVPU_JOB_PRIORITY_DEFAULT +* %DRM_IVPU_JOB_PRIORITY_IDLE +* %DRM_IVPU_JOB_PRIORITY_NORMAL +* %DRM_IVPU_JOB_PRIORITY_FOCUS +* %DRM_IVPU_JOB_PRIORITY_REALTIME +*/ +__u32 priority; };/* drm_ivpu_bo_wait job status codes */
Signature · 1 line
2.43.0
PATCH 12/16 accel/ivpu: Add diagnostic messages when VPU fails to boot or suspend
In reply to Jacek LawrynowiczFrom: "Wachowski, Karol" <[email protected]>
Make boot/suspend failure debugging easier by dumping FW logs and error registers.
--- drivers/accel/ivpu/ivpu_drv.c | 5 +++-- drivers/accel/ivpu/ivpu_pm.c | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +3 -2
@@ -17,6 +17,7 @@#include "ivpu_debugfs.h" #include "ivpu_drv.h" #include "ivpu_fw.h" +#include "ivpu_fw_log.h" #include "ivpu_gem.h" #include "ivpu_hw.h" #include "ivpu_ipc.h"
@@ -329,8 +330,6 @@ static int ivpu_wait_for_ready(struct ivpu_device *vdev)if (!ret)ivpu_dbg (vdev,PM ,"VPU ready message received successfully\n" ); -else -ivpu_hw_diagnose_failure (vdev);return ret; }
@@ -358,7 +357,9 @@ int ivpu_boot(struct ivpu_device *vdev) ret =ivpu_wait_for_ready (vdev);if (ret) {ivpu_err (vdev,"Failed to boot the firmware: %d\n" , ret); +ivpu_hw_diagnose_failure (vdev);ivpu_mmu_evtq_dump (vdev); +ivpu_fw_log_dump (vdev);return ret; }
drivers/accel/ivpu/ivpu_pm.c +3 -1
@@ -13,6 +13,7 @@#include "ivpu_drv.h" #include "ivpu_hw.h" #include "ivpu_fw.h" +#include "ivpu_fw_log.h" #include "ivpu_ipc.h" #include "ivpu_job.h" #include "ivpu_jsm_msg.h"
@@ -247,7 +248,8 @@ int ivpu_pm_runtime_suspend_cb(struct device *dev)ivpu_err (vdev,"Failed to set suspend VPU: %d\n" , ret);if (!hw_is_idle) { -ivpu_warn (vdev,"VPU failed to enter idle, force suspended.\n" ); +ivpu_err (vdev,"VPU failed to enter idle, force suspended.\n" ); +ivpu_fw_log_dump (vdev);ivpu_pm_prepare_cold_boot (vdev); }else {ivpu_pm_prepare_warm_boot (vdev);
Signature · 1 line
2.43.0
PATCH 13/16 accel/ivpu: Fix dev open/close races with unbind
In reply to Jacek Lawrynowicz - Add context_list_lock to synchronize user context addition/removal
- Add ivpu_file_priv->bound to indicate if context is bound to a device
- Use drm_dev_enter() to prevent unbinding the device during ivpu_open()
- Mark all user contexts as not bound when the device is removed
--- drivers/accel/ivpu/ivpu_drv.c | 110 +++++++++++++++++++++------------- drivers/accel/ivpu/ivpu_drv.h | 3 +- drivers/accel/ivpu/ivpu_gem.c | 9 ++- drivers/accel/ivpu/ivpu_gem.h | 2 +- drivers/accel/ivpu/ivpu_job.c | 16 ++--- drivers/accel/ivpu/ivpu_job.h | 2 +- 6 files changed, 85 insertions(+), 57 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +68 -42
@@ -6,6 +6,7 @@#include <linux/firmware.h> #include <linux/module.h> #include <linux/pci.h> +#include <linux/pm_runtime.h> #include <drm/drm_accel.h> #include <drm/drm_file.h>
@@ -66,22 +67,20 @@ struct ivpu_file_priv *ivpu_file_priv_get(struct ivpu_file_priv *file_priv)return file_priv; } -struct ivpu_file_priv *ivpu_file_priv_get_by_ctx_id (struct ivpu_device *vdev,unsigned long id) +static void file_priv_unbind (struct ivpu_device *vdev,struct ivpu_file_priv *file_priv) { -struct ivpu_file_priv *file_priv; - -xa_lock_irq (&vdev->context_xa); - file_priv =xa_load (&vdev->context_xa, id); -/* file_priv may still be in context_xa during file_priv_release() */ -if (file_priv && !kref_get_unless_zero (&file_priv->ref)) - file_priv =NULL ; -xa_unlock_irq (&vdev->context_xa); - -if (file_priv) -ivpu_dbg (vdev,KREF ,"file_priv get by id: ctx %u refcount %u\n" , - file_priv->ctx.id,kref_read (&file_priv->ref)); - -return file_priv; +mutex_lock (&file_priv->lock); +if (file_priv->bound) { +ivpu_dbg (vdev,FILE ,"file_priv unbind: ctx %u\n" , file_priv->ctx.id); + +ivpu_cmdq_release_all_locked (file_priv); +ivpu_jsm_context_release (vdev, file_priv->ctx.id); +ivpu_bo_unbind_all_bos_from_context (vdev, &file_priv->ctx); +ivpu_mmu_user_context_fini (vdev, &file_priv->ctx); + file_priv->bound = false; +drm_WARN_ON (&vdev->drm, !xa_erase_irq (&vdev->context_xa, file_priv->ctx.id)); + } +mutex_unlock (&file_priv->lock); }static void file_priv_release (struct kref *ref)
@@ -89,13 +88,15 @@ static void file_priv_release(struct kref *ref) struct ivpu_file_priv *file_priv = container_of(ref, struct ivpu_file_priv, ref);struct ivpu_device *vdev = file_priv->vdev; -ivpu_dbg (vdev,FILE ,"file_priv release: ctx %u\n" , file_priv->ctx.id); +ivpu_dbg (vdev,FILE ,"file_priv release: ctx %u bound %d\n" , + file_priv->ctx.id, (bool )file_priv->bound); + +pm_runtime_get_sync (vdev->drm.dev); +mutex_lock (&vdev->context_list_lock); +file_priv_unbind (vdev, file_priv); +mutex_unlock (&vdev->context_list_lock); +pm_runtime_put_autosuspend (vdev->drm.dev); -ivpu_cmdq_release_all (file_priv); -ivpu_jsm_context_release (vdev, file_priv->ctx.id); -ivpu_bo_remove_all_bos_from_context (vdev, &file_priv->ctx); -ivpu_mmu_user_context_fini (vdev, &file_priv->ctx); -drm_WARN_ON (&vdev->drm,xa_erase_irq (&vdev->context_xa, file_priv->ctx.id) != file_priv);mutex_destroy (&file_priv->lock);kfree (file_priv); }
@@ -232,49 +233,54 @@ static int ivpu_open(struct drm_device *dev, struct drm_file *file)struct ivpu_device *vdev =to_ivpu_device (dev);struct ivpu_file_priv *file_priv;u32 ctx_id; -void *old; -int ret; +int idx, ret; - ret =xa_alloc_irq (&vdev->context_xa, &ctx_id,NULL , vdev->context_xa_limit,GFP_KERNEL ); -if (ret) { -ivpu_err (vdev,"Failed to allocate context id: %d\n" , ret); -return ret; - } +if (!drm_dev_enter (dev, &idx)) +return -ENODEV ; file_priv =kzalloc (sizeof (*file_priv),GFP_KERNEL );if (!file_priv) { +ivpu_err (vdev,"Failed to allocate file_priv\n" ); ret = -ENOMEM ; - goto err_xa_erase; + goto err_dev_exit; } file_priv->vdev = vdev; + file_priv->bound = true;kref_init (&file_priv->ref);mutex_init (&file_priv->lock); +mutex_lock (&vdev->context_list_lock); + + ret =xa_alloc_irq (&vdev->context_xa, &ctx_id, file_priv, + vdev->context_xa_limit,GFP_KERNEL ); +if (ret) { +ivpu_err (vdev,"Failed to allocate context id: %d\n" , ret); + goto err_unlock; + } + ret =ivpu_mmu_user_context_init (vdev, &file_priv->ctx, ctx_id);if (ret) - goto err_mutex_destroy; + goto err_xa_erase; - old =xa_store_irq (&vdev->context_xa, ctx_id, file_priv,GFP_KERNEL ); -if (xa_is_err (old)) { - ret =xa_err (old); -ivpu_err (vdev,"Failed to store context %u: %d\n" , ctx_id, ret); - goto err_ctx_fini; - } +mutex_unlock (&vdev->context_list_lock); +drm_dev_exit (idx); + + file->driver_priv = file_priv;ivpu_dbg (vdev,FILE ,"file_priv create: ctx %u process %s pid %d\n" , ctx_id, current->comm,task_pid_nr (current)); - file->driver_priv = file_priv;return 0 ; -err_ctx_fini: -ivpu_mmu_user_context_fini (vdev, &file_priv->ctx); -err_mutex_destroy: -mutex_destroy (&file_priv->lock); -kfree (file_priv); err_xa_erase:xa_erase_irq (&vdev->context_xa, ctx_id); +err_unlock: +mutex_unlock (&vdev->context_list_lock); +mutex_destroy (&file_priv->lock); +kfree (file_priv); +err_dev_exit: +drm_dev_exit (idx);return ret; }
@@ -531,6 +537,10 @@ static int ivpu_dev_init(struct ivpu_device *vdev)lockdep_set_class (&vdev->submitted_jobs_xa.xa_lock, &submitted_jobs_xa_lock_class_key);INIT_LIST_HEAD (&vdev->bo_list); + ret =drmm_mutex_init (&vdev->drm, &vdev->context_list_lock); +if (ret) + goto err_xa_destroy; + ret =drmm_mutex_init (&vdev->drm, &vdev->bo_list_lock);if (ret) goto err_xa_destroy;
@@ -602,14 +612,30 @@ static int ivpu_dev_init(struct ivpu_device *vdev)return ret; } +static void ivpu_bo_unbind_all_user_contexts (struct ivpu_device *vdev) +{ +struct ivpu_file_priv *file_priv; +unsigned long ctx_id; + +mutex_lock (&vdev->context_list_lock); + +xa_for_each (&vdev->context_xa, ctx_id, file_priv) +file_priv_unbind (vdev, file_priv); + +mutex_unlock (&vdev->context_list_lock); +} +static void ivpu_dev_fini (struct ivpu_device *vdev) {ivpu_pm_disable (vdev);ivpu_shutdown (vdev);if (IVPU_WA (d3hot_after_power_off))pci_set_power_state (to_pci_dev (vdev->drm.dev), PCI_D3hot); + +ivpu_jobs_abort_all (vdev);ivpu_job_done_consumer_fini (vdev);ivpu_pm_cancel_recovery (vdev); +ivpu_bo_unbind_all_user_contexts (vdev);ivpu_ipc_fini (vdev);ivpu_fw_fini (vdev);
drivers/accel/ivpu/ivpu_drv.h +2 -1
@@ -115,6 +115,7 @@ struct ivpu_device {struct ivpu_mmu_context gctx;struct ivpu_mmu_context rctx; +struct mutex context_list_lock;/* Protects user context addition/removal */ struct xarray context_xa;struct xa_limit context_xa_limit;
@@ -147,6 +148,7 @@ struct ivpu_file_priv {struct ivpu_cmdq *cmdq[IVPU_NUM_ENGINES ];struct ivpu_mmu_context ctx;bool has_mmu_faults; +bool bound; };extern int ivpu_dbg_mask;
@@ -162,7 +164,6 @@ extern bool ivpu_disable_mmu_cont_pages;extern int ivpu_test_mode;struct ivpu_file_priv *ivpu_file_priv_get (struct ivpu_file_priv *file_priv); -struct ivpu_file_priv *ivpu_file_priv_get_by_ctx_id (struct ivpu_device *vdev,unsigned long id);void ivpu_file_priv_put (struct ivpu_file_priv **link);int ivpu_boot (struct ivpu_device *vdev);
drivers/accel/ivpu/ivpu_gem.c +7 -2
@@ -77,7 +77,10 @@ ivpu_bo_alloc_vpu_addr(struct ivpu_bo *bo, struct ivpu_mmu_context *ctx, const struct ivpu_addr_range *range) {struct ivpu_device *vdev =ivpu_bo_to_vdev (bo); -int ret; +int idx, ret; + +if (!drm_dev_enter (&vdev->drm, &idx)) +return -ENODEV ;mutex_lock (&bo->lock);
@@ -93,6 +96,8 @@ ivpu_bo_alloc_vpu_addr(struct ivpu_bo *bo, struct ivpu_mmu_context *ctx,mutex_unlock (&bo->lock); +drm_dev_exit (idx); +return ret; }
@@ -128,7 +133,7 @@ static void ivpu_bo_unbind_locked(struct ivpu_bo *bo)dma_resv_unlock (bo->base.base.resv); } -void ivpu_bo_remove_all_bos_from_context (struct ivpu_device *vdev,struct ivpu_mmu_context *ctx) +void ivpu_bo_unbind_all_bos_from_context (struct ivpu_device *vdev,struct ivpu_mmu_context *ctx) {struct ivpu_bo *bo;
drivers/accel/ivpu/ivpu_gem.h +1 -1
@@ -25,7 +25,7 @@ struct ivpu_bo { };int ivpu_bo_pin (struct ivpu_bo *bo); -void ivpu_bo_remove_all_bos_from_context (struct ivpu_device *vdev,struct ivpu_mmu_context *ctx); +void ivpu_bo_unbind_all_bos_from_context (struct ivpu_device *vdev,struct ivpu_mmu_context *ctx);struct drm_gem_object *ivpu_gem_create_object (struct drm_device *dev,size_t size);struct ivpu_bo *ivpu_bo_alloc_internal (struct ivpu_device *vdev,u64 vpu_addr,u64 size,u32 flags);
drivers/accel/ivpu/ivpu_job.c +6 -10
@@ -112,16 +112,14 @@ static void ivpu_cmdq_release_locked(struct ivpu_file_priv *file_priv, u16 engin } } -void ivpu_cmdq_release_all (struct ivpu_file_priv *file_priv) +void ivpu_cmdq_release_all_locked (struct ivpu_file_priv *file_priv) {int i; -mutex_lock (&file_priv->lock); +lockdep_assert_held (&file_priv->lock);for (i =0 ; i <IVPU_NUM_ENGINES ; i++)ivpu_cmdq_release_locked (file_priv, i); - -mutex_unlock (&file_priv->lock); }/*
@@ -161,15 +159,13 @@ void ivpu_cmdq_reset_all_contexts(struct ivpu_device *vdev)struct ivpu_file_priv *file_priv;unsigned long ctx_id; -xa_for_each (&vdev->context_xa, ctx_id, file_priv) { - file_priv =ivpu_file_priv_get_by_ctx_id (vdev, ctx_id); -if (!file_priv) -continue ; +mutex_lock (&vdev->context_list_lock); +xa_for_each (&vdev->context_xa, ctx_id, file_priv)ivpu_cmdq_reset_all (file_priv); -ivpu_file_priv_put (&file_priv); - } +mutex_unlock (&vdev->context_list_lock); + }static int ivpu_cmdq_push_job (struct ivpu_cmdq *cmdq,struct ivpu_job *job)
drivers/accel/ivpu/ivpu_job.h +1 -1
@@ -56,7 +56,7 @@ struct ivpu_job {int ivpu_submit_ioctl (struct drm_device *dev,void *data,struct drm_file *file); -void ivpu_cmdq_release_all (struct ivpu_file_priv *file_priv); +void ivpu_cmdq_release_all_locked (struct ivpu_file_priv *file_priv);void ivpu_cmdq_reset_all_contexts (struct ivpu_device *vdev);void ivpu_job_done_consumer_init (struct ivpu_device *vdev);
Signature · 1 line
2.43.0
PATCH 14/16 accel/ivpu: Refactor ivpu_submit_ioctl()
In reply to Jacek Lawrynowicz- Wake up the device as late as possible
- Remove job reference counting in order to simplify the code
- Don't put jobs that are not fully submitted on submitted_jobs_xa in order to avoid potential races with reset/recovery
- Split job_destroy/rpm_put which is needed for TDR refactor
--- drivers/accel/ivpu/ivpu_job.c | 139 +++++++++++++++------------------- drivers/accel/ivpu/ivpu_job.h | 1 - 2 files changed, 62 insertions(+), 78 deletions(-)
drivers/accel/ivpu/ivpu_job.c +62 -77
@@ -125,7 +125,7 @@ void ivpu_cmdq_release_all_locked(struct ivpu_file_priv *file_priv)/* * Mark the doorbell as unregistered and reset job queue pointers. * This function needs to be called when the VPU hardware is restarted -* and FW looses job queue state. The next time job queue is used it +* and FW loses job queue state. The next time job queue is used it * will be registered again. */ static void ivpu_cmdq_reset_locked (struct ivpu_file_priv *file_priv,u16 engine)
@@ -239,60 +239,32 @@ static struct dma_fence *ivpu_fence_create(struct ivpu_device *vdev)return &fence->base; } -static void job_get (struct ivpu_job *job,struct ivpu_job **link) +static void ivpu_job_destroy (struct ivpu_job *job) {struct ivpu_device *vdev = job->vdev; - -kref_get (&job->ref); - *link = job; - -ivpu_dbg (vdev,KREF ,"Job get: id %u refcount %u\n" , job->job_id,kref_read (&job->ref)); -} - -static void job_release (struct kref *ref) -{ - struct ivpu_job *job = container_of(ref, struct ivpu_job, ref); -struct ivpu_device *vdev = job->vdev;u32 i; +ivpu_dbg (vdev,JOB ,"Job destroyed: id %3u ctx %2d engine %d" , + job->job_id, job->file_priv->ctx.id, job->engine_idx); +for (i =0 ; i < job->bo_count; i++)if (job->bos[i])drm_gem_object_put (&job->bos[i]->base.base);dma_fence_put (job->done_fence);ivpu_file_priv_put (&job->file_priv); - -ivpu_dbg (vdev,KREF ,"Job released: id %u\n" , job->job_id);kfree (job); - -/* Allow the VPU to get suspended, must be called after ivpu_file_priv_put() */ -ivpu_rpm_put (vdev); -} - -static void job_put (struct ivpu_job *job) -{ -struct ivpu_device *vdev = job->vdev; - -ivpu_dbg (vdev,KREF ,"Job put: id %u refcount %u\n" , job->job_id,kref_read (&job->ref)); -kref_put (&job->ref, job_release); }static struct ivpu_job * -ivpu_create_job (struct ivpu_file_priv *file_priv,u32 engine_idx,u32 bo_count) +ivpu_job_create (struct ivpu_file_priv *file_priv,u32 engine_idx,u32 bo_count) {struct ivpu_device *vdev = file_priv->vdev;struct ivpu_job *job; -int ret; - - ret =ivpu_rpm_get (vdev); -if (ret <0 ) -return NULL ; job =kzalloc (struct_size (job, bos, bo_count),GFP_KERNEL );if (!job) - goto err_rpm_put; - -kref_init (&job->ref); +return NULL ; job->vdev = vdev; job->engine_idx = engine_idx;
@@ -306,17 +278,14 @@ ivpu_create_job(struct ivpu_file_priv *file_priv, u32 engine_idx, u32 bo_count) job->file_priv =ivpu_file_priv_get (file_priv);ivpu_dbg (vdev,JOB ,"Job created: ctx %2d engine %d" , file_priv->ctx.id, job->engine_idx); -return job; err_free_job:kfree (job); -err_rpm_put: -ivpu_rpm_put (vdev);return NULL ; } -static int ivpu_job_done (struct ivpu_device *vdev,u32 job_id,u32 job_status) +static int ivpu_job_signal_and_destroy (struct ivpu_device *vdev,u32 job_id,u32 job_status) {struct ivpu_job *job;
@@ -333,9 +302,10 @@ static int ivpu_job_done(struct ivpu_device *vdev, u32 job_id, u32 job_status)ivpu_dbg (vdev,JOB ,"Job complete: id %3u ctx %2d engine %d status 0x%x\n" , job->job_id, job->file_priv->ctx.id, job->engine_idx, job_status); +ivpu_job_destroy (job);ivpu_stop_job_timeout_detection (vdev); -job_put (job); +ivpu_rpm_put (vdev);return 0 ; }
@@ -345,10 +315,10 @@ void ivpu_jobs_abort_all(struct ivpu_device *vdev)unsigned long id;xa_for_each (&vdev->submitted_jobs_xa, id, job) -ivpu_job_done (vdev, id,VPU_JSM_STATUS_ABORTED ); +ivpu_job_signal_and_destroy (vdev, id,VPU_JSM_STATUS_ABORTED ); } -static int ivpu_direct_job_submission (struct ivpu_job *job) +static int ivpu_job_submit (struct ivpu_job *job) {struct ivpu_file_priv *file_priv = job->file_priv;struct ivpu_device *vdev = job->vdev;
@@ -356,53 +326,65 @@ static int ivpu_direct_job_submission(struct ivpu_job *job)struct ivpu_cmdq *cmdq;int ret; + ret =ivpu_rpm_get (vdev); +if (ret <0 ) +return ret; +mutex_lock (&file_priv->lock); cmdq =ivpu_cmdq_acquire (job->file_priv, job->engine_idx);if (!cmdq) { -ivpu_warn (vdev,"Failed get job queue, ctx %d engine %d\n" , - file_priv->ctx.id, job->engine_idx); +ivpu_warn_ratelimited (vdev,"Failed get job queue, ctx %d engine %d\n" , + file_priv->ctx.id, job->engine_idx); ret = -EINVAL ; - goto err_unlock; + goto err_unlock_file_priv; } job_id_range.min =FIELD_PREP (JOB_ID_CONTEXT_MASK , (file_priv->ctx.id -1 )); job_id_range.max = job_id_range.min |JOB_ID_JOB_MASK ; -job_get (job, &job); - ret =xa_alloc (&vdev->submitted_jobs_xa, &job->job_id, job, job_id_range,GFP_KERNEL ); +xa_lock (&vdev->submitted_jobs_xa); + ret =__xa_alloc (&vdev->submitted_jobs_xa, &job->job_id, job, job_id_range,GFP_KERNEL );if (ret) { -ivpu_warn_ratelimited (vdev,"Failed to allocate job id: %d\n" , ret); - goto err_job_put; +ivpu_dbg (vdev,JOB ,"Too many active jobs in ctx %d\n" , + file_priv->ctx.id); + ret = -EBUSY ; + goto err_unlock_submitted_jobs_xa; } ret =ivpu_cmdq_push_job (cmdq, job);if (ret) - goto err_xa_erase; + goto err_erase_xa;ivpu_start_job_timeout_detection (vdev); -ivpu_dbg (vdev,JOB ,"Job submitted: id %3u addr 0x%llx ctx %2d engine %d next %d\n" , - job->job_id, job->cmd_buf_vpu_addr, file_priv->ctx.id, - job->engine_idx, cmdq->jobq->header.tail); - -if (ivpu_test_mode &IVPU_TEST_MODE_NULL_HW ) { -ivpu_job_done (vdev, job->job_id,VPU_JSM_STATUS_SUCCESS ); +if (unlikely (ivpu_test_mode &IVPU_TEST_MODE_NULL_HW )) { cmdq->jobq->header.head = cmdq->jobq->header.tail;wmb ();/* Flush WC buffer for jobq header */ }else {ivpu_cmdq_ring_db (vdev, cmdq); } +ivpu_dbg (vdev,JOB ,"Job submitted: id %3u ctx %2d engine %d addr 0x%llx next %d\n" , + job->job_id, file_priv->ctx.id, job->engine_idx, + job->cmd_buf_vpu_addr, cmdq->jobq->header.tail); + +xa_unlock (&vdev->submitted_jobs_xa); +mutex_unlock (&file_priv->lock); + +if (unlikely (ivpu_test_mode &IVPU_TEST_MODE_NULL_HW )) +ivpu_job_signal_and_destroy (vdev, job->job_id,VPU_JSM_STATUS_SUCCESS ); +return 0 ; -err_xa_erase: -xa_erase (&vdev->submitted_jobs_xa, job->job_id); -err_job_put: -job_put (job); -err_unlock: +err_erase_xa: +__xa_erase (&vdev->submitted_jobs_xa, job->job_id); +err_unlock_submitted_jobs_xa: +xa_unlock (&vdev->submitted_jobs_xa); +err_unlock_file_priv:mutex_unlock (&file_priv->lock); +ivpu_rpm_put (vdev);return ret; }
@@ -508,44 +490,47 @@ int ivpu_submit_ioctl(struct drm_device *dev, void *data, struct drm_file *file) params->buffer_count * sizeof(u32));if (ret) { ret = -EFAULT ; - goto free_handles; + goto err_free_handles; }if (!drm_dev_enter (&vdev->drm, &idx)) { ret = -ENODEV ; - goto free_handles; + goto err_free_handles; }ivpu_dbg (vdev,JOB ,"Submit ioctl: ctx %u buf_count %u\n" , file_priv->ctx.id, params->buffer_count); - job =ivpu_create_job (file_priv, params->engine, params->buffer_count); + job =ivpu_job_create (file_priv, params->engine, params->buffer_count);if (!job) {ivpu_err (vdev,"Failed to create job\n" ); ret = -ENOMEM ; - goto dev_exit; + goto err_exit_dev; } ret =ivpu_job_prepare_bos_for_submit (file, job, buf_handles, params->buffer_count, params->commands_offset);if (ret) { -ivpu_err (vdev,"Failed to prepare job, ret %d\n" , ret); - goto job_put; +ivpu_err (vdev,"Failed to prepare job: %d\n" , ret); + goto err_destroy_job; } - ret =ivpu_direct_job_submission (job); -if (ret) { -dma_fence_signal (job->done_fence); -ivpu_err (vdev,"Failed to submit job to the HW, ret %d\n" , ret); - } + ret =ivpu_job_submit (job); +if (ret) + goto err_signal_fence; -job_put: -job_put (job); -dev_exit:drm_dev_exit (idx); -free_handles:kfree (buf_handles); +return ret; +err_signal_fence: +dma_fence_signal (job->done_fence); +err_destroy_job: +ivpu_job_destroy (job); +err_exit_dev: +drm_dev_exit (idx); +err_free_handles: +kfree (buf_handles);return ret; }
@@ -567,7 +552,7 @@ ivpu_job_done_callback(struct ivpu_device *vdev, struct ivpu_ipc_hdr *ipc_hdr, } payload = (struct vpu_ipc_msg_payload_job_done *)&jsm_msg->payload; - ret =ivpu_job_done (vdev, payload->job_id, payload->job_status); + ret =ivpu_job_signal_and_destroy (vdev, payload->job_id, payload->job_status);if (!ret && !xa_empty (&vdev->submitted_jobs_xa))ivpu_start_job_timeout_detection (vdev); }
drivers/accel/ivpu/ivpu_job.h +0 -1
@@ -43,7 +43,6 @@ struct ivpu_cmdq {will update the job status */ struct ivpu_job { -struct kref ref;struct ivpu_device *vdev;struct ivpu_file_priv *file_priv;struct dma_fence *done_fence;
Signature · 1 line
2.43.0
PATCH 15/16 accel/ivpu: Improve recovery and reset support
In reply to Jacek Lawrynowicz - Synchronize job submission with reset/recovery using reset_lock
- Always print recovery reason and call diagnose_failure()
- Prevent immediate autosuspend after reset/recovery
--- drivers/accel/ivpu/ivpu_debugfs.c | 20 ++++++++++--- drivers/accel/ivpu/ivpu_hw_37xx.c | 14 +++------ drivers/accel/ivpu/ivpu_hw_40xx.c | 8 +++--- drivers/accel/ivpu/ivpu_ipc.c | 8 ++---- drivers/accel/ivpu/ivpu_job.c | 2 ++ drivers/accel/ivpu/ivpu_mmu.c | 4 +-- drivers/accel/ivpu/ivpu_pm.c | 48 ++++++++++++++++++++----------- drivers/accel/ivpu/ivpu_pm.h | 6 ++-- 8 files changed, 67 insertions(+), 43 deletions(-)
drivers/accel/ivpu/ivpu_debugfs.c +16 -4
@@ -102,7 +102,7 @@ static int reset_pending_show(struct seq_file *s, void *v) {struct ivpu_device *vdev =seq_to_ivpu (s); -seq_printf (s,"%d\n" ,atomic_read (&vdev->pm->in_reset)); +seq_printf (s,"%d\n" ,atomic_read (&vdev->pm->reset_pending));return 0 ; }
@@ -130,7 +130,9 @@ dvfs_mode_fops_write(struct file *file, const char __user *user_buf, size_t size fw->dvfs_mode = dvfs_mode; -ivpu_pm_schedule_recovery (vdev); + ret =pci_try_reset_function (to_pci_dev (vdev->drm.dev)); +if (ret) +return ret;return size; }
@@ -190,7 +192,10 @@ fw_profiling_freq_fops_write(struct file *file, const char __user *user_buf,return ret;ivpu_hw_profiling_freq_drive (vdev, enable); -ivpu_pm_schedule_recovery (vdev); + + ret =pci_try_reset_function (to_pci_dev (vdev->drm.dev)); +if (ret) +return ret;return size; }
@@ -301,11 +306,18 @@ static ssize_t ivpu_force_recovery_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos) { struct ivpu_device *vdev = file->private_data; +int ret;if (!size)return -EINVAL ; -ivpu_pm_schedule_recovery (vdev); + ret =ivpu_rpm_get (vdev); +if (ret) +return ret; + +ivpu_pm_trigger_recovery (vdev,"debugfs" ); +flush_work (&vdev->pm->recovery_work); +ivpu_rpm_put (vdev);return size; }
drivers/accel/ivpu/ivpu_hw_37xx.c +4 -10
@@ -869,24 +869,18 @@ static void ivpu_hw_37xx_irq_disable(struct ivpu_device *vdev)static void ivpu_hw_37xx_irq_wdt_nce_handler (struct ivpu_device *vdev) { -ivpu_err_ratelimited (vdev,"WDT NCE irq\n" ); - -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"WDT NCE IRQ" ); }static void ivpu_hw_37xx_irq_wdt_mss_handler (struct ivpu_device *vdev) { -ivpu_err_ratelimited (vdev,"WDT MSS irq\n" ); -ivpu_hw_wdt_disable (vdev); -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"WDT MSS IRQ" ); }static void ivpu_hw_37xx_irq_noc_firewall_handler (struct ivpu_device *vdev) { -ivpu_err_ratelimited (vdev,"NOC Firewall irq\n" ); - -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"NOC Firewall IRQ" ); }/* Handler for IRQs from VPU core (irqV) */
@@ -964,7 +958,7 @@ static bool ivpu_hw_37xx_irqb_handler(struct ivpu_device *vdev, int irq)REGB_WR32 (VPU_37XX_BUTTRESS_INTERRUPT_STAT , status);if (schedule_recovery) -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"Buttress IRQ" );return true; }
drivers/accel/ivpu/ivpu_hw_40xx.c +4 -4
@@ -1027,18 +1027,18 @@ static void ivpu_hw_40xx_irq_disable(struct ivpu_device *vdev)static void ivpu_hw_40xx_irq_wdt_nce_handler (struct ivpu_device *vdev) {/* TODO: For LNN hang consider engine reset instead of full recovery */ -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"WDT NCE IRQ" ); }static void ivpu_hw_40xx_irq_wdt_mss_handler (struct ivpu_device *vdev) {ivpu_hw_wdt_disable (vdev); -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"WDT MSS IRQ" ); }static void ivpu_hw_40xx_irq_noc_firewall_handler (struct ivpu_device *vdev) { -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"NOC Firewall IRQ" ); }/* Handler for IRQs from VPU core (irqV) */
@@ -1132,7 +1132,7 @@ static bool ivpu_hw_40xx_irqb_handler(struct ivpu_device *vdev, int irq)REGB_WR32 (VPU_40XX_BUTTRESS_INTERRUPT_STAT , status);if (schedule_recovery) -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"Buttress IRQ" );return true; }
drivers/accel/ivpu/ivpu_ipc.c +3 -5
@@ -343,10 +343,8 @@ int ivpu_ipc_send_receive_active(struct ivpu_device *vdev, struct vpu_jsm_msg *r hb_ret =ivpu_ipc_send_receive_internal (vdev, &hb_req,VPU_JSM_MSG_QUERY_ENGINE_HB_DONE , &hb_resp,VPU_IPC_CHAN_ASYNC_CMD , vdev->timeout.jsm); -if (hb_ret == -ETIMEDOUT ) { -ivpu_hw_diagnose_failure (vdev); -ivpu_pm_schedule_recovery (vdev); - } +if (hb_ret == -ETIMEDOUT ) +ivpu_pm_trigger_recovery (vdev,"IPC timeout" );return ret; }
@@ -397,7 +395,7 @@ void ivpu_ipc_irq_handler(struct ivpu_device *vdev, bool *wake_thread)*/ while (ivpu_hw_reg_ipc_rx_count_get (vdev)) {if (++msg_count >IPC_MAX_RX_MSG ) { -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"IPC msg limit" );return ; }
drivers/accel/ivpu/ivpu_job.c +2 -0
@@ -515,7 +515,9 @@ int ivpu_submit_ioctl(struct drm_device *dev, void *data, struct drm_file *file) goto err_destroy_job; } +down_read (&vdev->pm->reset_lock); ret =ivpu_job_submit (job); +up_read (&vdev->pm->reset_lock);if (ret) goto err_signal_fence;
drivers/accel/ivpu/ivpu_mmu.c +2 -2
@@ -898,13 +898,13 @@ void ivpu_mmu_irq_evtq_handler(struct ivpu_device *vdev)while ((event =ivpu_mmu_get_event (vdev)) !=NULL ) {ivpu_mmu_dump_event (vdev, event);if (++event_count >IVPU_MMU_MAX_EVENT_COUNT ) { -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"MMU event limit" );return ; } ssid =FIELD_GET (IVPU_MMU_EVT_SSID_MASK , event[0 ]);if (ssid ==IVPU_GLOBAL_CONTEXT_MMU_SSID ) { -ivpu_pm_schedule_recovery (vdev); +ivpu_pm_trigger_recovery (vdev,"MMU event" );return ; }
drivers/accel/ivpu/ivpu_pm.c +32 -16
104 lines not on this page · raw message
drivers/accel/ivpu/ivpu_pm.h +4 -2
@@ -6,6 +6,7 @@#ifndef __IVPU_PM_H__#define __IVPU_PM_H__ +#include <linux/rwsem.h> #include <linux/types.h> struct ivpu_device ;
@@ -14,8 +15,9 @@ struct ivpu_pm_info {struct ivpu_device *vdev;struct delayed_work job_timeout_work;struct work_struct recovery_work; -atomic_t in_reset; +struct rw_semaphore reset_lock;atomic_t reset_counter; +atomic_t reset_pending;bool is_warmboot;u32 suspend_reschedule_counter; };
@@ -37,7 +39,7 @@ int __must_check ivpu_rpm_get(struct ivpu_device *vdev);int __must_check ivpu_rpm_get_if_active (struct ivpu_device *vdev);void ivpu_rpm_put (struct ivpu_device *vdev); -void ivpu_pm_schedule_recovery (struct ivpu_device *vdev); +void ivpu_pm_trigger_recovery (struct ivpu_device *vdev,const char *reason);void ivpu_start_job_timeout_detection (struct ivpu_device *vdev);void ivpu_stop_job_timeout_detection (struct ivpu_device *vdev);
Signature · 1 line
2.43.0
PATCH 16/16 accel/ivpu: New job status for jobs aborted by the driver
In reply to Jacek LawrynowiczFrom: Grzegorz Trzebiatowski <[email protected]>
Add DRM_IVPU_JOB_STATUS_ABORTED to indicate that the job was aborted by the driver due to e.g. TDR or user context MMU faults.
This will help UMD and tests distinguish if job was aborted by the FW or the driver.
--- drivers/accel/ivpu/ivpu_job.c | 4 ++-- include/uapi/drm/ivpu_accel.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/accel/ivpu/ivpu_job.c +2 -2
@@ -294,7 +294,7 @@ static int ivpu_job_signal_and_destroy(struct ivpu_device *vdev, u32 job_id, u32return -ENOENT ;if (job->file_priv->has_mmu_faults) - job_status =VPU_JSM_STATUS_ABORTED ; + job_status =DRM_IVPU_JOB_STATUS_ABORTED ; job->bos[CMD_BUF_IDX ]->job_status = job_status;dma_fence_signal (job->done_fence);
@@ -315,7 +315,7 @@ void ivpu_jobs_abort_all(struct ivpu_device *vdev)unsigned long id;xa_for_each (&vdev->submitted_jobs_xa, id, job) -ivpu_job_signal_and_destroy (vdev, id,VPU_JSM_STATUS_ABORTED ); +ivpu_job_signal_and_destroy (vdev, id,DRM_IVPU_JOB_STATUS_ABORTED ); }static int ivpu_job_submit (struct ivpu_job *job)
include/uapi/drm/ivpu_accel.h +1 -0
@@ -309,6 +309,7 @@ struct drm_ivpu_submit {/* drm_ivpu_bo_wait job status codes */ #define DRM_IVPU_JOB_STATUS_SUCCESS 0 +#define DRM_IVPU_JOB_STATUS_ABORTED 256/** * struct drm_ivpu_bo_wait - Wait for BO to become inactive
Signature · 1 line
2.43.0