// SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * * Copyright (c) 2024 Broadcom. All Rights Reserved. The term * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * * 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. *
**************************************************************************/
/* * The worker can fall behind the vblank hrtimer, make sure we catch up.
*/ while (frame_start <= frame_end)
drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32);
}
if (WARN_ON(*vblank_time == vblank->time)) returntrue;
/* * To prevent races we roll the hrtimer forward before we do any * interrupt processing - this is how real hw works (the interrupt is * only generated after all the vblank registers are updated) and what * the vblank core expects. Therefore we need to always correct the * timestampe by one frame.
*/
*vblank_time -= du->vkms.period_ns;
if (vmw->vkms_enabled && du->vkms.surface != surf) {
WARN_ON(atomic_read(&du->vkms.atomic_lock) != VMW_VKMS_LOCK_MODESET); if (du->vkms.surface)
vmw_surface_unreference(&du->vkms.surface); if (surf)
du->vkms.surface = vmw_surface_reference(surf);
}
}
/** * vmw_vkms_lock_max_wait_ns - Return the max wait for the vkms lock * @du: The vmw_display_unit from which to grab the vblank timings * * Returns the maximum wait time used to acquire the vkms lock. By * default uses a time of a single frame and in case where vblank * was not initialized for the display unit 1/60th of a second.
*/ staticinline u64
vmw_vkms_lock_max_wait_ns(struct vmw_display_unit *du)
{
s64 nsecs = ktime_to_ns(du->vkms.period_ns);
return (nsecs > 0) ? nsecs : 16666666;
}
/** * vmw_vkms_modeset_lock - Protects access to crtc during modeset * @crtc: The crtc to lock for vkms * * This function prevents the VKMS timers/callbacks from being called * while a modeset operation is in process. We don't want the callbacks * e.g. the vblank simulator to be trying to access incomplete state * so we need to make sure they execute only when the modeset has * finished. * * Normally this would have been done with a spinlock but locking the * entire atomic modeset with vmwgfx is impossible because kms prepare * executes non-atomic ops (e.g. vmw_validation_prepare holds a mutex to * guard various bits of state). Which means that we need to synchronize * atomic context (the vblank handler) with the non-atomic entirity * of kms - so use an atomic_t to track which part of vkms has access * to the basic vkms state.
*/ void
vmw_vkms_modeset_lock(struct drm_crtc *crtc)
{ struct vmw_display_unit *du = vmw_crtc_to_du(crtc); const u64 nsecs_delay = 10; const u64 MAX_NSECS_DELAY = vmw_vkms_lock_max_wait_ns(du);
u64 total_delay = 0; int ret;
do {
ret = atomic_cmpxchg(&du->vkms.atomic_lock,
VMW_VKMS_LOCK_UNLOCKED,
VMW_VKMS_LOCK_MODESET); if (ret == VMW_VKMS_LOCK_UNLOCKED || total_delay >= MAX_NSECS_DELAY) break;
ndelay(nsecs_delay);
total_delay += nsecs_delay;
} while (1);
if (total_delay >= MAX_NSECS_DELAY) {
drm_warn(crtc->dev, "VKMS lock expired! total_delay = %lld, ret = %d, cur = %d\n",
total_delay, ret, atomic_read(&du->vkms.atomic_lock));
}
}
/** * vmw_vkms_modeset_lock_relaxed - Protects access to crtc during modeset * @crtc: The crtc to lock for vkms * * Much like vmw_vkms_modeset_lock except that when the crtc is currently * in a modeset it will return immediately. * * Returns true if actually locked vkms to modeset or false otherwise.
*/ bool
vmw_vkms_modeset_lock_relaxed(struct drm_crtc *crtc)
{ struct vmw_display_unit *du = vmw_crtc_to_du(crtc); const u64 nsecs_delay = 10; const u64 MAX_NSECS_DELAY = vmw_vkms_lock_max_wait_ns(du);
u64 total_delay = 0; int ret;
do {
ret = atomic_cmpxchg(&du->vkms.atomic_lock,
VMW_VKMS_LOCK_UNLOCKED,
VMW_VKMS_LOCK_MODESET); if (ret == VMW_VKMS_LOCK_UNLOCKED ||
ret == VMW_VKMS_LOCK_MODESET ||
total_delay >= MAX_NSECS_DELAY) break;
ndelay(nsecs_delay);
total_delay += nsecs_delay;
} while (1);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.