diff options
Diffstat (limited to 'drivers/gpu/drm/vmwgfx')
-rw-r--r-- | drivers/gpu/drm/vmwgfx/Kconfig | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 24 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 19 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 29 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 510 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_fence.h | 21 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 11 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_irq.c | 61 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 15 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 2 |
12 files changed, 141 insertions, 556 deletions
diff --git a/drivers/gpu/drm/vmwgfx/Kconfig b/drivers/gpu/drm/vmwgfx/Kconfig index 6c3c2922ae8b..aab646b91ca9 100644 --- a/drivers/gpu/drm/vmwgfx/Kconfig +++ b/drivers/gpu/drm/vmwgfx/Kconfig @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 config DRM_VMWGFX tristate "DRM driver for VMware Virtual GPU" - depends on DRM && PCI && MMU + depends on DRM && PCI depends on (X86 && HYPERVISOR_GUEST) || ARM64 select DRM_CLIENT_SELECTION select DRM_TTM diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c index dd4ca6a9c690..8fe02131a6c4 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c @@ -544,7 +544,7 @@ int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno) cmd_fence = (struct svga_fifo_cmd_fence *) fm; cmd_fence->fence = *seqno; vmw_cmd_commit_flush(dev_priv, bytes); - vmw_update_seqno(dev_priv); + vmw_fences_update(dev_priv->fman); out_err: return ret; diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c index 0695a342b1ef..8ff958d119be 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c @@ -440,8 +440,10 @@ static int vmw_device_init(struct vmw_private *dev_priv) vmw_write(dev_priv, SVGA_REG_CONFIG_DONE, 1); } - dev_priv->last_read_seqno = vmw_fence_read(dev_priv); - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno); + u32 seqno = vmw_fence_read(dev_priv); + + atomic_set(&dev_priv->last_read_seqno, seqno); + atomic_set(&dev_priv->marker_seq, seqno); return 0; } @@ -454,7 +456,7 @@ static void vmw_device_fini(struct vmw_private *vmw) while (vmw_read(vmw, SVGA_REG_BUSY) != 0) ; - vmw->last_read_seqno = vmw_fence_read(vmw); + atomic_set(&vmw->last_read_seqno, vmw_fence_read(vmw)); vmw_write(vmw, SVGA_REG_CONFIG_DONE, vmw->config_done_state); @@ -713,7 +715,7 @@ static int vmw_setup_pci_resources(struct vmw_private *dev, pci_set_master(pdev); - ret = pci_request_regions(pdev, "vmwgfx probe"); + ret = pcim_request_all_regions(pdev, "vmwgfx probe"); if (ret) return ret; @@ -733,7 +735,6 @@ static int vmw_setup_pci_resources(struct vmw_private *dev, if (!dev->rmmio) { drm_err(&dev->drm, "Failed mapping registers mmio memory.\n"); - pci_release_regions(pdev); return -ENOMEM; } } else if (pci_id == VMWGFX_PCI_ID_SVGA2) { @@ -749,16 +750,14 @@ static int vmw_setup_pci_resources(struct vmw_private *dev, dev->fifo_mem = devm_memremap(dev->drm.dev, fifo_start, fifo_size, - MEMREMAP_WB); + MEMREMAP_WB | MEMREMAP_DEC); if (IS_ERR(dev->fifo_mem)) { drm_err(&dev->drm, "Failed mapping FIFO memory.\n"); - pci_release_regions(pdev); return PTR_ERR(dev->fifo_mem); } } else { - pci_release_regions(pdev); return -EINVAL; } @@ -836,7 +835,6 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id) int ret; enum vmw_res_type i; bool refuse_dma = false; - struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); vmw_sw_context_init(dev_priv); @@ -852,7 +850,7 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id) return ret; ret = vmw_detect_version(dev_priv); if (ret) - goto out_no_pci_or_version; + return ret; for (i = vmw_res_context; i < vmw_res_max; ++i) { @@ -1152,15 +1150,13 @@ out_err0: if (dev_priv->ctx.staged_bindings) vmw_binding_state_free(dev_priv->ctx.staged_bindings); -out_no_pci_or_version: - pci_release_regions(pdev); + return ret; } static void vmw_driver_unload(struct drm_device *dev) { struct vmw_private *dev_priv = vmw_priv(dev); - struct pci_dev *pdev = to_pci_dev(dev->dev); enum vmw_res_type i; unregister_pm_notifier(&dev_priv->pm_nb); @@ -1196,8 +1192,6 @@ static void vmw_driver_unload(struct drm_device *dev) idr_destroy(&dev_priv->res_idr[i]); vmw_mksstat_remove_all(dev_priv); - - pci_release_regions(pdev); } static void vmw_postclose(struct drm_device *dev, diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index 594af8eb04c6..eda5b6f8f4c4 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h @@ -522,7 +522,7 @@ struct vmw_private { int cmdbuf_waiters; /* Protected by waiter_lock */ int error_waiters; /* Protected by waiter_lock */ int fifo_queue_waiters; /* Protected by waiter_lock */ - uint32_t last_read_seqno; + atomic_t last_read_seqno; struct vmw_fence_manager *fman; uint32_t irq_mask; /* Updates protected by waiter_lock */ @@ -1006,15 +1006,14 @@ extern int vmw_fallback_wait(struct vmw_private *dev_priv, uint32_t seqno, bool interruptible, unsigned long timeout); -extern void vmw_update_seqno(struct vmw_private *dev_priv); -extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv); -extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv); -extern void vmw_goal_waiter_add(struct vmw_private *dev_priv); -extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv); -extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag, - int *waiter_count); -extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv, - u32 flag, int *waiter_count); +bool vmw_seqno_waiter_add(struct vmw_private *dev_priv); +bool vmw_seqno_waiter_remove(struct vmw_private *dev_priv); +bool vmw_goal_waiter_add(struct vmw_private *dev_priv); +bool vmw_goal_waiter_remove(struct vmw_private *dev_priv); +bool vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag, + int *waiter_count); +bool vmw_generic_waiter_remove(struct vmw_private *dev_priv, + u32 flag, int *waiter_count); /** * Kernel modesetting - vmwgfx_kms.c diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c index e831e324e737..819704ac675d 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c @@ -3878,8 +3878,7 @@ vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv, fence_rep.handle = fence_handle; fence_rep.seqno = fence->base.seqno; - vmw_update_seqno(dev_priv); - fence_rep.passed_seqno = dev_priv->last_read_seqno; + fence_rep.passed_seqno = vmw_fences_update(dev_priv->fman); } /* @@ -4068,23 +4067,6 @@ static int vmw_execbuf_tie_context(struct vmw_private *dev_priv, return 0; } -/* - * DMA fence callback to remove a seqno_waiter - */ -struct seqno_waiter_rm_context { - struct dma_fence_cb base; - struct vmw_private *dev_priv; -}; - -static void seqno_waiter_rm_cb(struct dma_fence *f, struct dma_fence_cb *cb) -{ - struct seqno_waiter_rm_context *ctx = - container_of(cb, struct seqno_waiter_rm_context, base); - - vmw_seqno_waiter_remove(ctx->dev_priv); - kfree(ctx); -} - int vmw_execbuf_process(struct drm_file *file_priv, struct vmw_private *dev_priv, void __user *user_commands, void *kernel_commands, @@ -4265,15 +4247,6 @@ int vmw_execbuf_process(struct drm_file *file_priv, } else { /* Link the fence with the FD created earlier */ fd_install(out_fence_fd, sync_file->file); - struct seqno_waiter_rm_context *ctx = - kmalloc(sizeof(*ctx), GFP_KERNEL); - ctx->dev_priv = dev_priv; - vmw_seqno_waiter_add(dev_priv); - if (dma_fence_add_callback(&fence->base, &ctx->base, - seqno_waiter_rm_cb) < 0) { - vmw_seqno_waiter_remove(dev_priv); - kfree(ctx); - } } } diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c index 588d50ababf6..c2294abbe753 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c @@ -1,32 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * - * Copyright 2011-2023 VMware, Inc., Palo Alto, CA., USA - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. + * Copyright (c) 2009-2025 Broadcom. All Rights Reserved. The term + * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * **************************************************************************/ -#include <linux/sched/signal.h> - #include "vmwgfx_drv.h" #define VMW_FENCE_WRAP (1 << 31) @@ -35,14 +14,7 @@ struct vmw_fence_manager { struct vmw_private *dev_priv; spinlock_t lock; struct list_head fence_list; - struct work_struct work; bool fifo_down; - struct list_head cleanup_list; - uint32_t pending_actions[VMW_ACTION_MAX]; - struct mutex goal_irq_mutex; - bool goal_irq_on; /* Protected by @goal_irq_mutex */ - bool seqno_valid; /* Protected by @lock, and may not be set to true - without the @goal_irq_mutex held. */ u64 ctx; }; @@ -52,12 +24,10 @@ struct vmw_user_fence { }; /** - * struct vmw_event_fence_action - fence action that delivers a drm event. + * struct vmw_event_fence_action - fence callback that delivers a DRM event. * - * @action: A struct vmw_fence_action to hook up to a fence. + * @base: For use with dma_fence_add_callback(...) * @event: A pointer to the pending event. - * @fence: A referenced pointer to the fence to keep it alive while @action - * hangs on it. * @dev: Pointer to a struct drm_device so we can access the event stuff. * @tv_sec: If non-null, the variable pointed to will be assigned * current time tv_sec val when the fence signals. @@ -65,10 +35,9 @@ struct vmw_user_fence { * be assigned the current time tv_usec val when the fence signals. */ struct vmw_event_fence_action { - struct vmw_fence_action action; + struct dma_fence_cb base; struct drm_pending_event *event; - struct vmw_fence_obj *fence; struct drm_device *dev; uint32_t *tv_sec; @@ -81,44 +50,6 @@ fman_from_fence(struct vmw_fence_obj *fence) return container_of(fence->base.lock, struct vmw_fence_manager, lock); } -static u32 vmw_fence_goal_read(struct vmw_private *vmw) -{ - if ((vmw->capabilities2 & SVGA_CAP2_EXTRA_REGS) != 0) - return vmw_read(vmw, SVGA_REG_FENCE_GOAL); - else - return vmw_fifo_mem_read(vmw, SVGA_FIFO_FENCE_GOAL); -} - -static void vmw_fence_goal_write(struct vmw_private *vmw, u32 value) -{ - if ((vmw->capabilities2 & SVGA_CAP2_EXTRA_REGS) != 0) - vmw_write(vmw, SVGA_REG_FENCE_GOAL, value); - else - vmw_fifo_mem_write(vmw, SVGA_FIFO_FENCE_GOAL, value); -} - -/* - * Note on fencing subsystem usage of irqs: - * Typically the vmw_fences_update function is called - * - * a) When a new fence seqno has been submitted by the fifo code. - * b) On-demand when we have waiters. Sleeping waiters will switch on the - * ANY_FENCE irq and call vmw_fences_update function each time an ANY_FENCE - * irq is received. When the last fence waiter is gone, that IRQ is masked - * away. - * - * In situations where there are no waiters and we don't submit any new fences, - * fence objects may not be signaled. This is perfectly OK, since there are - * no consumers of the signaled data, but that is NOT ok when there are fence - * actions attached to a fence. The fencing subsystem then makes use of the - * FENCE_GOAL irq and sets the fence goal seqno to that of the next fence - * which has an action attached, and each time vmw_fences_update is called, - * the subsystem makes sure the fence goal seqno is updated. - * - * The fence goal seqno irq is on as long as there are unsignaled fence - * objects with actions attached to them. - */ - static void vmw_fence_obj_destroy(struct dma_fence *f) { struct vmw_fence_obj *fence = @@ -126,8 +57,21 @@ static void vmw_fence_obj_destroy(struct dma_fence *f) struct vmw_fence_manager *fman = fman_from_fence(fence); if (!list_empty(&fence->head)) { + /* The fence manager still has an implicit reference to this + * fence via the fence list if head is set. Because the lock is + * required to be held when the fence manager updates the fence + * list either the fence will have been removed after we get + * the lock below or we can safely remove it and the fence + * manager will never see it. This implies the fence is being + * deleted without being signaled which is dubious but valid + * if there are no callbacks. The dma_fence code that calls + * this hook will warn about deleted unsignaled with callbacks + * so no need to warn again here. + */ spin_lock(&fman->lock); list_del_init(&fence->head); + if (fence->waiter_added) + vmw_seqno_waiter_remove(fman->dev_priv); spin_unlock(&fman->lock); } fence->destroy(fence); @@ -143,165 +87,46 @@ static const char *vmw_fence_get_timeline_name(struct dma_fence *f) return "svga"; } +/* When we toggle signaling for the SVGA device there is a race period from + * the time we first read the fence seqno to the time we enable interrupts. + * If we miss the interrupt for a fence during this period its likely the driver + * will stall. As a result we need to re-read the seqno after interrupts are + * enabled. If interrupts were already enabled we just increment the number of + * seqno waiters. + */ static bool vmw_fence_enable_signaling(struct dma_fence *f) { + u32 seqno; struct vmw_fence_obj *fence = container_of(f, struct vmw_fence_obj, base); struct vmw_fence_manager *fman = fman_from_fence(fence); struct vmw_private *dev_priv = fman->dev_priv; - - u32 seqno = vmw_fence_read(dev_priv); - if (seqno - fence->base.seqno < VMW_FENCE_WRAP) +check_for_race: + seqno = vmw_fence_read(dev_priv); + if (seqno - fence->base.seqno < VMW_FENCE_WRAP) { + if (fence->waiter_added) { + vmw_seqno_waiter_remove(dev_priv); + fence->waiter_added = false; + } return false; - + } else if (!fence->waiter_added) { + fence->waiter_added = true; + if (vmw_seqno_waiter_add(dev_priv)) + goto check_for_race; + } return true; } -struct vmwgfx_wait_cb { - struct dma_fence_cb base; - struct task_struct *task; -}; - -static void -vmwgfx_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb) -{ - struct vmwgfx_wait_cb *wait = - container_of(cb, struct vmwgfx_wait_cb, base); - - wake_up_process(wait->task); -} - -static void __vmw_fences_update(struct vmw_fence_manager *fman); - -static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout) -{ - struct vmw_fence_obj *fence = - container_of(f, struct vmw_fence_obj, base); - - struct vmw_fence_manager *fman = fman_from_fence(fence); - struct vmw_private *dev_priv = fman->dev_priv; - struct vmwgfx_wait_cb cb; - long ret = timeout; - - if (likely(vmw_fence_obj_signaled(fence))) - return timeout; - - vmw_seqno_waiter_add(dev_priv); - - spin_lock(f->lock); - - if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &f->flags)) - goto out; - - if (intr && signal_pending(current)) { - ret = -ERESTARTSYS; - goto out; - } - - cb.base.func = vmwgfx_wait_cb; - cb.task = current; - list_add(&cb.base.node, &f->cb_list); - - for (;;) { - __vmw_fences_update(fman); - - /* - * We can use the barrier free __set_current_state() since - * DMA_FENCE_FLAG_SIGNALED_BIT + wakeup is protected by the - * fence spinlock. - */ - if (intr) - __set_current_state(TASK_INTERRUPTIBLE); - else - __set_current_state(TASK_UNINTERRUPTIBLE); - - if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &f->flags)) { - if (ret == 0 && timeout > 0) - ret = 1; - break; - } - - if (intr && signal_pending(current)) { - ret = -ERESTARTSYS; - break; - } - - if (ret == 0) - break; - - spin_unlock(f->lock); - - ret = schedule_timeout(ret); - - spin_lock(f->lock); - } - __set_current_state(TASK_RUNNING); - if (!list_empty(&cb.base.node)) - list_del(&cb.base.node); - -out: - spin_unlock(f->lock); - - vmw_seqno_waiter_remove(dev_priv); - - return ret; -} +static u32 __vmw_fences_update(struct vmw_fence_manager *fman); static const struct dma_fence_ops vmw_fence_ops = { .get_driver_name = vmw_fence_get_driver_name, .get_timeline_name = vmw_fence_get_timeline_name, .enable_signaling = vmw_fence_enable_signaling, - .wait = vmw_fence_wait, .release = vmw_fence_obj_destroy, }; -/* - * Execute signal actions on fences recently signaled. - * This is done from a workqueue so we don't have to execute - * signal actions from atomic context. - */ - -static void vmw_fence_work_func(struct work_struct *work) -{ - struct vmw_fence_manager *fman = - container_of(work, struct vmw_fence_manager, work); - struct list_head list; - struct vmw_fence_action *action, *next_action; - bool seqno_valid; - - do { - INIT_LIST_HEAD(&list); - mutex_lock(&fman->goal_irq_mutex); - - spin_lock(&fman->lock); - list_splice_init(&fman->cleanup_list, &list); - seqno_valid = fman->seqno_valid; - spin_unlock(&fman->lock); - - if (!seqno_valid && fman->goal_irq_on) { - fman->goal_irq_on = false; - vmw_goal_waiter_remove(fman->dev_priv); - } - mutex_unlock(&fman->goal_irq_mutex); - - if (list_empty(&list)) - return; - - /* - * At this point, only we should be able to manipulate the - * list heads of the actions we have on the private list. - * hence fman::lock not held. - */ - - list_for_each_entry_safe(action, next_action, &list, head) { - list_del_init(&action->head); - if (action->cleanup) - action->cleanup(action); - } - } while (1); -} - struct vmw_fence_manager *vmw_fence_manager_init(struct vmw_private *dev_priv) { struct vmw_fence_manager *fman = kzalloc(sizeof(*fman), GFP_KERNEL); @@ -312,10 +137,7 @@ struct vmw_fence_manager *vmw_fence_manager_init(struct vmw_private *dev_priv) fman->dev_priv = dev_priv; spin_lock_init(&fman->lock); INIT_LIST_HEAD(&fman->fence_list); - INIT_LIST_HEAD(&fman->cleanup_list); - INIT_WORK(&fman->work, &vmw_fence_work_func); fman->fifo_down = true; - mutex_init(&fman->goal_irq_mutex); fman->ctx = dma_fence_context_alloc(1); return fman; @@ -325,11 +147,8 @@ void vmw_fence_manager_takedown(struct vmw_fence_manager *fman) { bool lists_empty; - (void) cancel_work_sync(&fman->work); - spin_lock(&fman->lock); - lists_empty = list_empty(&fman->fence_list) && - list_empty(&fman->cleanup_list); + lists_empty = list_empty(&fman->fence_list); spin_unlock(&fman->lock); BUG_ON(!lists_empty); @@ -344,7 +163,6 @@ static int vmw_fence_obj_init(struct vmw_fence_manager *fman, dma_fence_init(&fence->base, &vmw_fence_ops, &fman->lock, fman->ctx, seqno); - INIT_LIST_HEAD(&fence->seq_passed_actions); fence->destroy = destroy; spin_lock(&fman->lock); @@ -352,6 +170,11 @@ static int vmw_fence_obj_init(struct vmw_fence_manager *fman, ret = -EBUSY; goto out_unlock; } + /* This creates an implicit reference to the fence from the fence + * manager. It will be dropped when the fence is signaled which is + * expected to happen before deletion. The dtor has code to catch + * the rare deletion before signaling case. + */ list_add_tail(&fence->head, &fman->fence_list); out_unlock: @@ -360,148 +183,35 @@ out_unlock: } -static void vmw_fences_perform_actions(struct vmw_fence_manager *fman, - struct list_head *list) -{ - struct vmw_fence_action *action, *next_action; - - list_for_each_entry_safe(action, next_action, list, head) { - list_del_init(&action->head); - fman->pending_actions[action->type]--; - if (action->seq_passed != NULL) - action->seq_passed(action); - - /* - * Add the cleanup action to the cleanup list so that - * it will be performed by a worker task. - */ - - list_add_tail(&action->head, &fman->cleanup_list); - } -} - -/** - * vmw_fence_goal_new_locked - Figure out a new device fence goal - * seqno if needed. - * - * @fman: Pointer to a fence manager. - * @passed_seqno: The seqno the device currently signals as passed. - * - * This function should be called with the fence manager lock held. - * It is typically called when we have a new passed_seqno, and - * we might need to update the fence goal. It checks to see whether - * the current fence goal has already passed, and, in that case, - * scans through all unsignaled fences to get the next fence object with an - * action attached, and sets the seqno of that fence as a new fence goal. - * - * returns true if the device goal seqno was updated. False otherwise. - */ -static bool vmw_fence_goal_new_locked(struct vmw_fence_manager *fman, - u32 passed_seqno) -{ - u32 goal_seqno; - struct vmw_fence_obj *fence, *next_fence; - - if (likely(!fman->seqno_valid)) - return false; - - goal_seqno = vmw_fence_goal_read(fman->dev_priv); - if (likely(passed_seqno - goal_seqno >= VMW_FENCE_WRAP)) - return false; - - fman->seqno_valid = false; - list_for_each_entry_safe(fence, next_fence, &fman->fence_list, head) { - if (!list_empty(&fence->seq_passed_actions)) { - fman->seqno_valid = true; - vmw_fence_goal_write(fman->dev_priv, - fence->base.seqno); - break; - } - } - - return true; -} - - -/** - * vmw_fence_goal_check_locked - Replace the device fence goal seqno if - * needed. - * - * @fence: Pointer to a struct vmw_fence_obj the seqno of which should be - * considered as a device fence goal. - * - * This function should be called with the fence manager lock held. - * It is typically called when an action has been attached to a fence to - * check whether the seqno of that fence should be used for a fence - * goal interrupt. This is typically needed if the current fence goal is - * invalid, or has a higher seqno than that of the current fence object. - * - * returns true if the device goal seqno was updated. False otherwise. - */ -static bool vmw_fence_goal_check_locked(struct vmw_fence_obj *fence) -{ - struct vmw_fence_manager *fman = fman_from_fence(fence); - u32 goal_seqno; - - if (dma_fence_is_signaled_locked(&fence->base)) - return false; - - goal_seqno = vmw_fence_goal_read(fman->dev_priv); - if (likely(fman->seqno_valid && - goal_seqno - fence->base.seqno < VMW_FENCE_WRAP)) - return false; - - vmw_fence_goal_write(fman->dev_priv, fence->base.seqno); - fman->seqno_valid = true; - - return true; -} - -static void __vmw_fences_update(struct vmw_fence_manager *fman) +static u32 __vmw_fences_update(struct vmw_fence_manager *fman) { struct vmw_fence_obj *fence, *next_fence; - struct list_head action_list; - bool needs_rerun; - uint32_t seqno, new_seqno; + const bool cookie = dma_fence_begin_signalling(); + const u32 seqno = vmw_fence_read(fman->dev_priv); - seqno = vmw_fence_read(fman->dev_priv); -rerun: list_for_each_entry_safe(fence, next_fence, &fman->fence_list, head) { if (seqno - fence->base.seqno < VMW_FENCE_WRAP) { list_del_init(&fence->head); + if (fence->waiter_added) { + vmw_seqno_waiter_remove(fman->dev_priv); + fence->waiter_added = false; + } dma_fence_signal_locked(&fence->base); - INIT_LIST_HEAD(&action_list); - list_splice_init(&fence->seq_passed_actions, - &action_list); - vmw_fences_perform_actions(fman, &action_list); } else break; } - - /* - * Rerun if the fence goal seqno was updated, and the - * hardware might have raced with that update, so that - * we missed a fence_goal irq. - */ - - needs_rerun = vmw_fence_goal_new_locked(fman, seqno); - if (unlikely(needs_rerun)) { - new_seqno = vmw_fence_read(fman->dev_priv); - if (new_seqno != seqno) { - seqno = new_seqno; - goto rerun; - } - } - - if (!list_empty(&fman->cleanup_list)) - (void) schedule_work(&fman->work); + dma_fence_end_signalling(cookie); + atomic_set_release(&fman->dev_priv->last_read_seqno, seqno); + return seqno; } -void vmw_fences_update(struct vmw_fence_manager *fman) +u32 vmw_fences_update(struct vmw_fence_manager *fman) { + u32 seqno; spin_lock(&fman->lock); - __vmw_fences_update(fman); + seqno = __vmw_fences_update(fman); spin_unlock(&fman->lock); + return seqno; } bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence) @@ -539,14 +249,13 @@ int vmw_fence_create(struct vmw_fence_manager *fman, struct vmw_fence_obj **p_fence) { struct vmw_fence_obj *fence; - int ret; + int ret; fence = kzalloc(sizeof(*fence), GFP_KERNEL); if (unlikely(!fence)) return -ENOMEM; - ret = vmw_fence_obj_init(fman, fence, seqno, - vmw_fence_destroy); + ret = vmw_fence_obj_init(fman, fence, seqno, vmw_fence_destroy); if (unlikely(ret != 0)) goto out_err_init; @@ -638,7 +347,6 @@ out_no_object: void vmw_fence_fifo_down(struct vmw_fence_manager *fman) { - struct list_head action_list; int ret; /* @@ -661,10 +369,6 @@ void vmw_fence_fifo_down(struct vmw_fence_manager *fman) if (unlikely(ret != 0)) { list_del_init(&fence->head); dma_fence_signal(&fence->base); - INIT_LIST_HEAD(&action_list); - list_splice_init(&fence->seq_passed_actions, - &action_list); - vmw_fences_perform_actions(fman, &action_list); } BUG_ON(!list_empty(&fence->head)); @@ -778,7 +482,6 @@ int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data, (struct drm_vmw_fence_signaled_arg *) data; struct ttm_base_object *base; struct vmw_fence_obj *fence; - struct vmw_fence_manager *fman; struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; struct vmw_private *dev_priv = vmw_priv(dev); @@ -787,14 +490,11 @@ int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data, return PTR_ERR(base); fence = &(container_of(base, struct vmw_user_fence, base)->fence); - fman = fman_from_fence(fence); arg->signaled = vmw_fence_obj_signaled(fence); arg->signaled_flags = arg->flags; - spin_lock(&fman->lock); - arg->passed_seqno = dev_priv->last_read_seqno; - spin_unlock(&fman->lock); + arg->passed_seqno = atomic_read_acquire(&dev_priv->last_read_seqno); ttm_base_object_unref(&base); @@ -822,10 +522,11 @@ int vmw_fence_obj_unref_ioctl(struct drm_device *dev, void *data, * attached has passed. It queues the event on the submitter's event list. * This function is always called from atomic context. */ -static void vmw_event_fence_action_seq_passed(struct vmw_fence_action *action) +static void vmw_event_fence_action_seq_passed(struct dma_fence *f, + struct dma_fence_cb *cb) { struct vmw_event_fence_action *eaction = - container_of(action, struct vmw_event_fence_action, action); + container_of(cb, struct vmw_event_fence_action, base); struct drm_device *dev = eaction->dev; struct drm_pending_event *event = eaction->event; @@ -837,7 +538,7 @@ static void vmw_event_fence_action_seq_passed(struct vmw_fence_action *action) if (likely(eaction->tv_sec != NULL)) { struct timespec64 ts; - ktime_get_ts64(&ts); + ktime_to_timespec64(f->timestamp); /* monotonic time, so no y2038 overflow */ *eaction->tv_sec = ts.tv_sec; *eaction->tv_usec = ts.tv_nsec / NSEC_PER_USEC; @@ -846,75 +547,10 @@ static void vmw_event_fence_action_seq_passed(struct vmw_fence_action *action) drm_send_event_locked(dev, eaction->event); eaction->event = NULL; spin_unlock_irq(&dev->event_lock); -} - -/** - * vmw_event_fence_action_cleanup - * - * @action: The struct vmw_fence_action embedded in a struct - * vmw_event_fence_action. - * - * This function is the struct vmw_fence_action destructor. It's typically - * called from a workqueue. - */ -static void vmw_event_fence_action_cleanup(struct vmw_fence_action *action) -{ - struct vmw_event_fence_action *eaction = - container_of(action, struct vmw_event_fence_action, action); - - vmw_fence_obj_unreference(&eaction->fence); + dma_fence_put(f); kfree(eaction); } - -/** - * vmw_fence_obj_add_action - Add an action to a fence object. - * - * @fence: The fence object. - * @action: The action to add. - * - * Note that the action callbacks may be executed before this function - * returns. - */ -static void vmw_fence_obj_add_action(struct vmw_fence_obj *fence, - struct vmw_fence_action *action) -{ - struct vmw_fence_manager *fman = fman_from_fence(fence); - bool run_update = false; - - mutex_lock(&fman->goal_irq_mutex); - spin_lock(&fman->lock); - - fman->pending_actions[action->type]++; - if (dma_fence_is_signaled_locked(&fence->base)) { - struct list_head action_list; - - INIT_LIST_HEAD(&action_list); - list_add_tail(&action->head, &action_list); - vmw_fences_perform_actions(fman, &action_list); - } else { - list_add_tail(&action->head, &fence->seq_passed_actions); - - /* - * This function may set fman::seqno_valid, so it must - * be run with the goal_irq_mutex held. - */ - run_update = vmw_fence_goal_check_locked(fence); - } - - spin_unlock(&fman->lock); - - if (run_update) { - if (!fman->goal_irq_on) { - fman->goal_irq_on = true; - vmw_goal_waiter_add(fman->dev_priv); - } - vmw_fences_update(fman); - } - mutex_unlock(&fman->goal_irq_mutex); - -} - /** * vmw_event_fence_action_queue - Post an event for sending when a fence * object seqno has passed. @@ -949,18 +585,14 @@ int vmw_event_fence_action_queue(struct drm_file *file_priv, return -ENOMEM; eaction->event = event; - - eaction->action.seq_passed = vmw_event_fence_action_seq_passed; - eaction->action.cleanup = vmw_event_fence_action_cleanup; - eaction->action.type = VMW_ACTION_EVENT; - - eaction->fence = vmw_fence_obj_reference(fence); eaction->dev = &fman->dev_priv->drm; eaction->tv_sec = tv_sec; eaction->tv_usec = tv_usec; - vmw_fence_obj_add_action(fence, &eaction->action); - + vmw_fence_obj_reference(fence); // Dropped in CB + if (dma_fence_add_callback(&fence->base, &eaction->base, + vmw_event_fence_action_seq_passed) < 0) + vmw_event_fence_action_seq_passed(&fence->base, &eaction->base); return 0; } diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.h b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.h index a7eee579c76a..e897cccae1ae 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.h @@ -39,27 +39,10 @@ struct drm_pending_event; struct vmw_private; struct vmw_fence_manager; -/** - * - * - */ -enum vmw_action_type { - VMW_ACTION_EVENT = 0, - VMW_ACTION_MAX -}; - -struct vmw_fence_action { - struct list_head head; - enum vmw_action_type type; - void (*seq_passed) (struct vmw_fence_action *action); - void (*cleanup) (struct vmw_fence_action *action); -}; - struct vmw_fence_obj { struct dma_fence base; - + bool waiter_added; struct list_head head; - struct list_head seq_passed_actions; void (*destroy)(struct vmw_fence_obj *fence); }; @@ -86,7 +69,7 @@ vmw_fence_obj_reference(struct vmw_fence_obj *fence) return fence; } -extern void vmw_fences_update(struct vmw_fence_manager *fman); +u32 vmw_fences_update(struct vmw_fence_manager *fman); extern bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence); diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c index c55382167c1b..eedf1fe60be7 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c @@ -85,10 +85,10 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map) int ret; if (drm_gem_is_imported(obj)) { - ret = dma_buf_vmap(obj->dma_buf, map); + ret = dma_buf_vmap(obj->import_attach->dmabuf, map); if (!ret) { if (drm_WARN_ON(obj->dev, map->is_iomem)) { - dma_buf_vunmap(obj->dma_buf, map); + dma_buf_vunmap(obj->import_attach->dmabuf, map); return -EIO; } } @@ -102,7 +102,7 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map) static void vmw_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map) { if (drm_gem_is_imported(obj)) - dma_buf_vunmap(obj->dma_buf, map); + dma_buf_vunmap(obj->import_attach->dmabuf, map); else drm_gem_ttm_vunmap(obj, map); } @@ -284,11 +284,10 @@ static void vmw_bo_print_info(int id, struct vmw_bo *bo, struct seq_file *m) seq_printf(m, "\t\t0x%08x: %12zu bytes %s, type = %s", id, bo->tbo.base.size, placement, type); - seq_printf(m, ", priority = %u, pin_count = %u, GEM refs = %d, TTM refs = %d", + seq_printf(m, ", priority = %u, pin_count = %u, GEM refs = %d", bo->tbo.priority, bo->tbo.pin_count, - kref_read(&bo->tbo.base.refcount), - kref_read(&bo->tbo.kref)); + kref_read(&bo->tbo.base.refcount)); seq_puts(m, "\n"); } diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c index 086e69a130d4..05773eb394d3 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c @@ -123,26 +123,17 @@ static bool vmw_fifo_idle(struct vmw_private *dev_priv, uint32_t seqno) return (vmw_read(dev_priv, SVGA_REG_BUSY) == 0); } -void vmw_update_seqno(struct vmw_private *dev_priv) -{ - uint32_t seqno = vmw_fence_read(dev_priv); - - if (dev_priv->last_read_seqno != seqno) { - dev_priv->last_read_seqno = seqno; - vmw_fences_update(dev_priv->fman); - } -} - bool vmw_seqno_passed(struct vmw_private *dev_priv, uint32_t seqno) { bool ret; + u32 last_read_seqno = atomic_read_acquire(&dev_priv->last_read_seqno); - if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP)) + if (last_read_seqno - seqno < VMW_FENCE_WRAP) return true; - vmw_update_seqno(dev_priv); - if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP)) + last_read_seqno = vmw_fences_update(dev_priv->fman); + if (last_read_seqno - seqno < VMW_FENCE_WRAP) return true; if (!vmw_has_fences(dev_priv) && vmw_fifo_idle(dev_priv, seqno)) @@ -239,51 +230,59 @@ out_err: return ret; } -void vmw_generic_waiter_add(struct vmw_private *dev_priv, +bool vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag, int *waiter_count) { - spin_lock_bh(&dev_priv->waiter_lock); + bool hw_programmed = false; + + spin_lock(&dev_priv->waiter_lock); if ((*waiter_count)++ == 0) { vmw_irq_status_write(dev_priv, flag); dev_priv->irq_mask |= flag; vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask); + hw_programmed = true; } - spin_unlock_bh(&dev_priv->waiter_lock); + spin_unlock(&dev_priv->waiter_lock); + return hw_programmed; } -void vmw_generic_waiter_remove(struct vmw_private *dev_priv, +bool vmw_generic_waiter_remove(struct vmw_private *dev_priv, u32 flag, int *waiter_count) { - spin_lock_bh(&dev_priv->waiter_lock); + bool hw_programmed = false; + + spin_lock(&dev_priv->waiter_lock); if (--(*waiter_count) == 0) { dev_priv->irq_mask &= ~flag; vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask); + hw_programmed = true; } - spin_unlock_bh(&dev_priv->waiter_lock); + spin_unlock(&dev_priv->waiter_lock); + return hw_programmed; } -void vmw_seqno_waiter_add(struct vmw_private *dev_priv) +bool vmw_seqno_waiter_add(struct vmw_private *dev_priv) { - vmw_generic_waiter_add(dev_priv, SVGA_IRQFLAG_ANY_FENCE, - &dev_priv->fence_queue_waiters); + return vmw_generic_waiter_add(dev_priv, SVGA_IRQFLAG_ANY_FENCE, + &dev_priv->fence_queue_waiters); } -void vmw_seqno_waiter_remove(struct vmw_private *dev_priv) +bool vmw_seqno_waiter_remove(struct vmw_private *dev_priv) { - vmw_generic_waiter_remove(dev_priv, SVGA_IRQFLAG_ANY_FENCE, - &dev_priv->fence_queue_waiters); + return vmw_generic_waiter_remove(dev_priv, SVGA_IRQFLAG_ANY_FENCE, + &dev_priv->fence_queue_waiters); } -void vmw_goal_waiter_add(struct vmw_private *dev_priv) +bool vmw_goal_waiter_add(struct vmw_private *dev_priv) { - vmw_generic_waiter_add(dev_priv, vmw_irqflag_fence_goal(dev_priv), - &dev_priv->goal_queue_waiters); + return vmw_generic_waiter_add(dev_priv, vmw_irqflag_fence_goal(dev_priv), + &dev_priv->goal_queue_waiters); } -void vmw_goal_waiter_remove(struct vmw_private *dev_priv) +bool vmw_goal_waiter_remove(struct vmw_private *dev_priv) { - vmw_generic_waiter_remove(dev_priv, vmw_irqflag_fence_goal(dev_priv), - &dev_priv->goal_queue_waiters); + return vmw_generic_waiter_remove(dev_priv, vmw_irqflag_fence_goal(dev_priv), + &dev_priv->goal_queue_waiters); } static void vmw_irq_preinstall(struct drm_device *dev) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c index 05b1c54a070c..54ea1b513950 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c @@ -500,6 +500,7 @@ static const struct drm_framebuffer_funcs vmw_framebuffer_surface_funcs = { static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv, struct vmw_user_object *uo, struct vmw_framebuffer **out, + const struct drm_format_info *info, const struct drm_mode_fb_cmd2 *mode_cmd) @@ -548,7 +549,7 @@ static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv, goto out_err1; } - drm_helper_mode_fill_fb_struct(dev, &vfbs->base.base, mode_cmd); + drm_helper_mode_fill_fb_struct(dev, &vfbs->base.base, info, mode_cmd); memcpy(&vfbs->uo, uo, sizeof(vfbs->uo)); vmw_user_object_ref(&vfbs->uo); @@ -602,6 +603,7 @@ static const struct drm_framebuffer_funcs vmw_framebuffer_bo_funcs = { static int vmw_kms_new_framebuffer_bo(struct vmw_private *dev_priv, struct vmw_bo *bo, struct vmw_framebuffer **out, + const struct drm_format_info *info, const struct drm_mode_fb_cmd2 *mode_cmd) @@ -634,7 +636,7 @@ static int vmw_kms_new_framebuffer_bo(struct vmw_private *dev_priv, } vfbd->base.base.obj[0] = &bo->tbo.base; - drm_helper_mode_fill_fb_struct(dev, &vfbd->base.base, mode_cmd); + drm_helper_mode_fill_fb_struct(dev, &vfbd->base.base, info, mode_cmd); vfbd->base.bo = true; vfbd->buffer = vmw_bo_reference(bo); *out = &vfbd->base; @@ -679,11 +681,13 @@ vmw_kms_srf_ok(struct vmw_private *dev_priv, uint32_t width, uint32_t height) * @dev_priv: Pointer to device private struct. * @uo: Pointer to user object to wrap the kms framebuffer around. * Either the buffer or surface inside the user object must be NULL. + * @info: pixel format information. * @mode_cmd: Frame-buffer metadata. */ struct vmw_framebuffer * vmw_kms_new_framebuffer(struct vmw_private *dev_priv, struct vmw_user_object *uo, + const struct drm_format_info *info, const struct drm_mode_fb_cmd2 *mode_cmd) { struct vmw_framebuffer *vfb = NULL; @@ -692,10 +696,10 @@ vmw_kms_new_framebuffer(struct vmw_private *dev_priv, /* Create the new framebuffer depending one what we have */ if (vmw_user_object_surface(uo)) { ret = vmw_kms_new_framebuffer_surface(dev_priv, uo, &vfb, - mode_cmd); + info, mode_cmd); } else if (uo->buffer) { ret = vmw_kms_new_framebuffer_bo(dev_priv, uo->buffer, &vfb, - mode_cmd); + info, mode_cmd); } else { BUG(); } @@ -712,6 +716,7 @@ vmw_kms_new_framebuffer(struct vmw_private *dev_priv, static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev, struct drm_file *file_priv, + const struct drm_format_info *info, const struct drm_mode_fb_cmd2 *mode_cmd) { struct vmw_private *dev_priv = vmw_priv(dev); @@ -741,7 +746,7 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev, } - vfb = vmw_kms_new_framebuffer(dev_priv, &uo, mode_cmd); + vfb = vmw_kms_new_framebuffer(dev_priv, &uo, info, mode_cmd); if (IS_ERR(vfb)) { ret = PTR_ERR(vfb); goto err_out; diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h index 511e29cdb987..445471fe9be6 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h @@ -399,6 +399,7 @@ int vmw_kms_readback(struct vmw_private *dev_priv, struct vmw_framebuffer * vmw_kms_new_framebuffer(struct vmw_private *dev_priv, struct vmw_user_object *uo, + const struct drm_format_info *info, const struct drm_mode_fb_cmd2 *mode_cmd); void vmw_guess_mode_timing(struct drm_display_mode *mode); void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv); diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c index 7fb1c88bcc47..69dfe69ce0f8 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c @@ -896,7 +896,7 @@ int vmw_compat_shader_add(struct vmw_private *dev_priv, .busy_domain = VMW_BO_DOMAIN_SYS, .bo_type = ttm_bo_type_device, .size = size, - .pin = true, + .pin = false, .keep_resv = true, }; |