// SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * * Copyright 2009-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. *
**************************************************************************/ #include"vmwgfx_bo.h" #include"vmwgfx_drv.h"
/* * Overlay control
*/ struct vmw_overlay { /* * Each stream is a single overlay. In Xv these are called ports.
*/ struct mutex mutex; struct vmw_stream stream[VMW_MAX_NUM_STREAMS];
};
/* * Move a buffer to vram or gmr if @pin is set, else unpin the buffer. * * With the introduction of screen objects buffers could now be * used with GMRs instead of being locked to vram.
*/ staticint vmw_overlay_move_buffer(struct vmw_private *dev_priv, struct vmw_bo *buf, bool pin, bool inter)
{ if (!pin) return vmw_bo_unpin(dev_priv, buf, inter);
if (dev_priv->active_display_unit == vmw_du_legacy) return vmw_bo_pin_in_vram(dev_priv, buf, inter);
/* * Stop or pause a stream. * * If the stream is paused the no evict flag is removed from the buffer * but left in vram. This allows for instance mode_set to evict it * should it need to. * * The caller must hold the overlay lock. * * @stream_id which stream to stop/pause. * @pause true to pause, false to stop completely.
*/ staticint vmw_overlay_stop(struct vmw_private *dev_priv,
uint32_t stream_id, bool pause, bool interruptible)
{ struct vmw_overlay *overlay = dev_priv->overlay_priv; struct vmw_stream *stream = &overlay->stream[stream_id]; int ret;
/* no buffer attached the stream is completely stopped */ if (!stream->buf) return 0;
/* If the stream is paused this is already done */ if (!stream->paused) {
ret = vmw_overlay_send_stop(dev_priv, stream_id,
interruptible); if (ret) return ret;
/* We just remove the NO_EVICT flag so no -ENOMEM */
ret = vmw_overlay_move_buffer(dev_priv, stream->buf, false,
interruptible); if (interruptible && ret == -ERESTARTSYS) return ret; else
BUG_ON(ret != 0);
}
/* * Update a stream and send any put or stop fifo commands needed. * * The caller must hold the overlay lock. * * Returns * -ENOMEM if buffer doesn't fit in vram. * -ERESTARTSYS if interrupted.
*/ staticint vmw_overlay_update_stream(struct vmw_private *dev_priv, struct vmw_bo *buf, struct drm_vmw_control_stream_arg *arg, bool interruptible)
{ struct vmw_overlay *overlay = dev_priv->overlay_priv; struct vmw_stream *stream = &overlay->stream[arg->stream_id]; int ret = 0;
if (!buf) return -EINVAL;
DRM_DEBUG(" %s: old %p, new %p, %spaused\n", __func__,
stream->buf, buf, stream->paused ? "" : "not ");
if (stream->buf != buf) {
ret = vmw_overlay_stop(dev_priv, arg->stream_id, false, interruptible); if (ret) return ret;
} elseif (!stream->paused) { /* If the buffers match and not paused then just send * the put command, no need to do anything else.
*/
ret = vmw_overlay_send_put(dev_priv, buf, arg, interruptible); if (ret == 0)
stream->saved = *arg; else
BUG_ON(!interruptible);
return ret;
}
/* We don't start the old stream if we are interrupted. * Might return -ENOMEM if it can't fit the buffer in vram.
*/
ret = vmw_overlay_move_buffer(dev_priv, buf, true, interruptible); if (ret) return ret;
ret = vmw_overlay_send_put(dev_priv, buf, arg, interruptible); if (ret) { /* This one needs to happen no matter what. We only remove * the NO_EVICT flag so this is safe from -ENOMEM.
*/
BUG_ON(vmw_overlay_move_buffer(dev_priv, buf, false, false)
!= 0); return ret;
}
if (stream->buf != buf)
stream->buf = vmw_bo_reference(buf);
stream->saved = *arg; /* stream is no longer stopped/paused */
stream->paused = false;
return 0;
}
/* * Try to resume all paused streams. * * Used by the kms code after moving a new scanout buffer to vram. * * Takes the overlay lock.
*/ int vmw_overlay_resume_all(struct vmw_private *dev_priv)
{ struct vmw_overlay *overlay = dev_priv->overlay_priv; int i, ret;
if (!overlay) return 0;
mutex_lock(&overlay->mutex);
for (i = 0; i < VMW_MAX_NUM_STREAMS; i++) { struct vmw_stream *stream = &overlay->stream[i]; if (!stream->paused) continue;
ret = vmw_overlay_update_stream(dev_priv, stream->buf,
&stream->saved, false); if (ret != 0)
DRM_INFO("%s: *warning* failed to resume stream %i\n",
__func__, i);
}
mutex_unlock(&overlay->mutex);
return 0;
}
/* * Pauses all active streams. * * Used by the kms code when moving a new scanout buffer to vram. * * Takes the overlay lock.
*/ int vmw_overlay_pause_all(struct vmw_private *dev_priv)
{ struct vmw_overlay *overlay = dev_priv->overlay_priv; int i, ret;
if (!overlay) return 0;
mutex_lock(&overlay->mutex);
for (i = 0; i < VMW_MAX_NUM_STREAMS; i++) { if (overlay->stream[i].paused)
DRM_INFO("%s: *warning* stream %i already paused\n",
__func__, i);
ret = vmw_overlay_stop(dev_priv, i, true, false);
WARN_ON(ret != 0);
}
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.