vmwgfx cleanups and modesetting changes
Subsystems (3)
cover vmwgfx cleanups and modesetting changes
A series of cleanups / reorganizations and modesetting changes that mostly target atomic state validation.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/15 drm/vmwgfx: Replace vmw_dma_buffer with vmw_buffer_object
Initially vmware buffer objects were only used as DMA buffers, so the name DMA buffer was a natural one. However, currently they are used also as dumb buffers and MOBs backing guest backed objects so renaming them to buffer objects is logical. Particularly since there is a dmabuf subsystem in the kernel where a dma buffer means something completely different.
This also renames user-space api structures and IOCTL names correspondingly, but the old names remain defined for now and the ABI hasn't changed.
There are a couple of minor style changes to make checkpatch happy.
---
drivers/gpu/drm/vmwgfx/Makefile | 4 +-
.../vmwgfx/{vmwgfx_dmabuf.c => vmwgfx_bo.c} | 58 ++--
drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 10 +-
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 10 +-
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 18 +-
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 129 ++++----
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 86 +++---
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c | 16 +-
drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c | 4 +-
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 203 +++++++------
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 58 ++--
drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 10 +-
drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c | 24 +-
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 280 +++++++++---------
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 100 +++----
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 22 +-
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 64 ++--
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 37 ++-
.../{vmwgfx_buffer.c => vmwgfx_ttm_buffer.c} | 2 +-
include/uapi/drm/vmwgfx_drm.h | 61 ++--
20 files changed, 589 insertions(+), 607 deletions(-)
rename drivers/gpu/drm/vmwgfx/{vmwgfx_dmabuf.c => vmwgfx_bo.c} (86%)
rename drivers/gpu/drm/vmwgfx/{vmwgfx_buffer.c => vmwgfx_ttm_buffer.c} (99%)drivers/gpu/drm/vmwgfx/Makefile +2 -2
@@ -1,9 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o vmwgfx_drv.o \ - vmwgfx_fb.o vmwgfx_ioctl.o vmwgfx_resource.o vmwgfx_buffer.o \ + vmwgfx_fb.o vmwgfx_ioctl.o vmwgfx_resource.o vmwgfx_ttm_buffer.o \ vmwgfx_fifo.o vmwgfx_irq.o vmwgfx_ldu.o vmwgfx_ttm_glue.o \ vmwgfx_overlay.o vmwgfx_marker.o vmwgfx_gmrid_manager.o \ - vmwgfx_fence.o vmwgfx_dmabuf.o vmwgfx_scrn.o vmwgfx_context.o \ + vmwgfx_fence.o vmwgfx_bo.o vmwgfx_scrn.o vmwgfx_context.o \ vmwgfx_surface.o vmwgfx_prime.o vmwgfx_mob.o vmwgfx_shader.o \ vmwgfx_cmdbuf_res.o vmwgfx_cmdbuf.o vmwgfx_stdu.o \ vmwgfx_cotable.o vmwgfx_so.o vmwgfx_binding.o vmwgfx_msg.o \
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c renamed from drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c +29 -29
145 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +5 -5
@@ -38,7 +38,7 @@ struct vmw_user_context {struct vmw_cmdbuf_res_manager *man;struct vmw_resource *cotables[SVGA_COTABLE_DX10_MAX ];spinlock_t cotable_lock; -struct vmw_dma_buffer *dx_query_mob; +struct vmw_buffer_object *dx_query_mob; };static void vmw_user_context_free (struct vmw_resource *res);
@@ -900,7 +900,7 @@ vmw_context_binding_state(struct vmw_resource *ctx)* specified in the parameter. 0 otherwise. */ int vmw_context_bind_dx_query (struct vmw_resource *ctx_res, -struct vmw_dma_buffer *mob) +struct vmw_buffer_object *mob) {struct vmw_user_context *uctx = container_of(ctx_res, struct vmw_user_context, res);
@@ -908,7 +908,7 @@ int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,if (mob ==NULL ) {if (uctx->dx_query_mob) { uctx->dx_query_mob->dx_query_ctx =NULL ; -vmw_dmabuf_unreference (&uctx->dx_query_mob); +vmw_bo_unreference (&uctx->dx_query_mob); uctx->dx_query_mob =NULL ; }
@@ -922,7 +922,7 @@ int vmw_context_bind_dx_query(struct vmw_resource *ctx_res, mob->dx_query_ctx = ctx_res;if (!uctx->dx_query_mob) - uctx->dx_query_mob =vmw_dmabuf_reference (mob); + uctx->dx_query_mob =vmw_bo_reference (mob);return 0 ; }
@@ -932,7 +932,7 @@ int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,* * @ctx_res: The context resource */ -struct vmw_dma_buffer * +struct vmw_buffer_object *vmw_context_get_dx_query_mob (struct vmw_resource *ctx_res) { struct vmw_user_context *uctx =
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +5 -5
@@ -390,7 +390,7 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)struct ttm_operation_ctx ctx = { false, false };struct vmw_private *dev_priv = res->dev_priv;struct vmw_cotable *vcotbl =vmw_cotable (res); -struct vmw_dma_buffer *buf, *old_buf = res->backup; +struct vmw_buffer_object *buf, *old_buf = res->backup;struct ttm_buffer_object *bo, *old_bo = &res->backup->base;size_t old_size = res->backup_size;size_t old_size_read_back = vcotbl->size_read_back;
@@ -415,8 +415,8 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)if (!buf)return -ENOMEM ; - ret =vmw_dmabuf_init (dev_priv, buf, new_size, &vmw_mob_ne_placement, - true, vmw_dmabuf_bo_free); + ret =vmw_bo_init (dev_priv, buf, new_size, &vmw_mob_ne_placement, + true, vmw_bo_bo_free);if (ret) {DRM_ERROR ("Failed initializing new cotable MOB.\n" );return ret;
@@ -482,7 +482,7 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)/* Let go of the old mob. */ list_del (&res->mob_head);list_add_tail (&res->mob_head, &buf->res_list); -vmw_dmabuf_unreference (&old_buf); +vmw_bo_unreference (&old_buf); res->id = vcotbl->type;return 0 ;
@@ -491,7 +491,7 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)ttm_bo_kunmap (&old_map); out_wait:ttm_bo_unreserve (bo); -vmw_dmabuf_unreference (&buf); +vmw_bo_unreference (&buf);return ret; }
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +9 -9
@@ -153,9 +153,9 @@static const struct drm_ioctl_desc vmw_ioctls[] = {VMW_IOCTL_DEF (VMW_GET_PARAM , vmw_getparam_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_ALLOC_DMABUF , vmw_dmabuf_alloc_ioctl, +VMW_IOCTL_DEF (VMW_ALLOC_DMABUF , vmw_bo_alloc_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_UNREF_DMABUF , vmw_dmabuf_unref_ioctl, +VMW_IOCTL_DEF (VMW_UNREF_DMABUF , vmw_bo_unref_ioctl,DRM_RENDER_ALLOW ), VMW_IOCTL_DEF(VMW_CURSOR_BYPASS, vmw_kms_cursor_bypass_ioctl,
@@ -219,7 +219,7 @@ static const struct drm_ioctl_desc vmw_ioctls[] = { vmw_gb_surface_reference_ioctl, DRM_AUTH | DRM_RENDER_ALLOW),VMW_IOCTL_DEF (VMW_SYNCCPU , - vmw_user_dmabuf_synccpu_ioctl, + vmw_user_bo_synccpu_ioctl,DRM_RENDER_ALLOW ), VMW_IOCTL_DEF(VMW_CREATE_EXTENDED_CONTEXT, vmw_extended_context_define_ioctl,
@@ -321,7 +321,7 @@ static void vmw_print_capabilities(uint32_t capabilities)static int vmw_dummy_query_bo_create (struct vmw_private *dev_priv) {int ret; -struct vmw_dma_buffer *vbo; +struct vmw_buffer_object *vbo;struct ttm_bo_kmap_obj map;volatile SVGA3dQueryResult *result;bool dummy;
@@ -335,9 +335,9 @@ static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)if (!vbo)return -ENOMEM ; - ret =vmw_dmabuf_init (dev_priv, vbo,PAGE_SIZE , - &vmw_sys_ne_placement, false, - &vmw_dmabuf_bo_free); + ret =vmw_bo_init (dev_priv, vbo,PAGE_SIZE , + &vmw_sys_ne_placement, false, + &vmw_bo_bo_free);if (unlikely (ret !=0 ))return ret;
@@ -358,7 +358,7 @@ static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)if (unlikely (ret !=0 )) {DRM_ERROR ("Dummy query buffer map failed.\n" ); -vmw_dmabuf_unreference (&vbo); +vmw_bo_unreference (&vbo); }else dev_priv->dummy_query_bo = vbo;
@@ -460,7 +460,7 @@ static void vmw_release_device_early(struct vmw_private *dev_priv)BUG_ON (dev_priv->pinned_bo !=NULL ); -vmw_dmabuf_unreference (&dev_priv->dummy_query_bo); +vmw_bo_unreference (&dev_priv->dummy_query_bo);if (dev_priv->cman)vmw_cmdbuf_remove_pool (dev_priv->cman);
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +65 -64
218 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +42 -44
313 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c +8 -8
@@ -42,7 +42,7 @@ struct vmw_fb_par {void *vmalloc;struct mutex bo_mutex; -struct vmw_dma_buffer *vmw_bo; +struct vmw_buffer_object *vmw_bo;unsigned bo_size;struct drm_framebuffer *set_fb;struct drm_display_mode *set_mode;
@@ -184,7 +184,7 @@ static void vmw_fb_dirty_flush(struct work_struct *work)struct drm_clip_rect clip;struct drm_framebuffer *cur_fb;u8 *src_ptr, *dst_ptr; -struct vmw_dma_buffer *vbo = par->vmw_bo; +struct vmw_buffer_object *vbo = par->vmw_bo;void *virtual;if (!READ_ONCE (par->dirty.active))
@@ -197,7 +197,7 @@ static void vmw_fb_dirty_flush(struct work_struct *work) (void )ttm_read_lock (&vmw_priv->reservation_sem, false); (void )ttm_bo_reserve (&vbo->base, false, false,NULL ); - virtual =vmw_dma_buffer_map_and_cache (vbo); + virtual =vmw_buffer_object_map_and_cache (vbo);if (!virtual) goto out_unreserve;
@@ -391,9 +391,9 @@ static void vmw_fb_imageblit(struct fb_info *info, const struct fb_image *image)*/ static int vmw_fb_create_bo (struct vmw_private *vmw_priv, -size_t size,struct vmw_dma_buffer **out) +size_t size,struct vmw_buffer_object **out) { -struct vmw_dma_buffer *vmw_bo; +struct vmw_buffer_object *vmw_bo;int ret; (void )ttm_write_lock (&vmw_priv->reservation_sem, false);
@@ -404,10 +404,10 @@ static int vmw_fb_create_bo(struct vmw_private *vmw_priv, goto err_unlock; } - ret =vmw_dmabuf_init (vmw_priv, vmw_bo, size, + ret =vmw_bo_init (vmw_priv, vmw_bo, size, &vmw_sys_placement, false, - &vmw_dmabuf_bo_free); + &vmw_bo_bo_free);if (unlikely (ret !=0 )) goto err_unlock;/* init frees the buffer on failure */
@@ -491,7 +491,7 @@ static int vmw_fb_kms_detach(struct vmw_fb_par *par, }if (par->vmw_bo && detach_bo && unref_bo) -vmw_dmabuf_unreference (&par->vmw_bo); +vmw_bo_unreference (&par->vmw_bo);return 0 ; }
drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c +2 -2
@@ -377,8 +377,8 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data, } vfb =vmw_framebuffer_to_vfb (fb); -if (!vfb->dmabuf) { -DRM_ERROR ("Framebuffer not dmabuf backed.\n" ); +if (!vfb->bo) { +DRM_ERROR ("Framebuffer not buffer backed.\n" ); ret = -EINVAL ; goto out_no_ttm_lock; }
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +101 -102
502 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +29 -29
136 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c +5 -5
@@ -547,11 +547,11 @@ int vmw_kms_ldu_close_display(struct vmw_private *dev_priv) } -int vmw_kms_ldu_do_dmabuf_dirty (struct vmw_private *dev_priv, -struct vmw_framebuffer *framebuffer, -unsigned flags,unsigned color, -struct drm_clip_rect *clips, -unsigned num_clips,int increment) +int vmw_kms_ldu_do_bo_dirty (struct vmw_private *dev_priv, +struct vmw_framebuffer *framebuffer, +unsigned int flags,unsigned int color, +struct drm_clip_rect *clips, +unsigned int num_clips,int increment) {size_t fifo_size;int i;
drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c +12 -12
@@ -38,7 +38,7 @@#define VMW_OVERLAY_CAP_MASK (SVGA_FIFO_CAP_VIDEO | SVGA_FIFO_CAP_ESCAPE)struct vmw_stream { -struct vmw_dma_buffer *buf; +struct vmw_buffer_object *buf;bool claimed;bool paused;struct drm_vmw_control_stream_arg saved;
@@ -94,7 +94,7 @@ static inline void fill_flush(struct vmw_escape_video_flush *cmd,* -ERESTARTSYS if interrupted by a signal. */ static int vmw_overlay_send_put (struct vmw_private *dev_priv, -struct vmw_dma_buffer *buf, +struct vmw_buffer_object *buf,struct drm_vmw_control_stream_arg *arg,bool interruptible) {
@@ -225,16 +225,16 @@ static int vmw_overlay_send_stop(struct vmw_private *dev_priv,* used with GMRs instead of being locked to vram. */ static int vmw_overlay_move_buffer (struct vmw_private *dev_priv, -struct vmw_dma_buffer *buf, +struct vmw_buffer_object *buf,bool pin,bool inter) {if (!pin) -return vmw_dmabuf_unpin (dev_priv, buf, inter); +return vmw_bo_unpin (dev_priv, buf, inter);if (dev_priv->active_display_unit == vmw_du_legacy) -return vmw_dmabuf_pin_in_vram (dev_priv, buf, inter); +return vmw_bo_pin_in_vram (dev_priv, buf, inter); -return vmw_dmabuf_pin_in_vram_or_gmr (dev_priv, buf, inter); +return vmw_bo_pin_in_vram_or_gmr (dev_priv, buf, inter); }/**
@@ -278,7 +278,7 @@ static int vmw_overlay_stop(struct vmw_private *dev_priv, }if (!pause) { -vmw_dmabuf_unreference (&stream->buf); +vmw_bo_unreference (&stream->buf); stream->paused = false; }else { stream->paused = true;
@@ -297,7 +297,7 @@ static int vmw_overlay_stop(struct vmw_private *dev_priv,* -ERESTARTSYS if interrupted. */ static int vmw_overlay_update_stream (struct vmw_private *dev_priv, -struct vmw_dma_buffer *buf, +struct vmw_buffer_object *buf,struct drm_vmw_control_stream_arg *arg,bool interruptible) {
@@ -347,7 +347,7 @@ static int vmw_overlay_update_stream(struct vmw_private *dev_priv, }if (stream->buf != buf) - stream->buf =vmw_dmabuf_reference (buf); + stream->buf =vmw_bo_reference (buf); stream->saved = *arg;/* stream is no longer stopped/paused */ stream->paused = false;
@@ -466,7 +466,7 @@ int vmw_overlay_ioctl(struct drm_device *dev, void *data,struct vmw_overlay *overlay = dev_priv->overlay_priv;struct drm_vmw_control_stream_arg *arg = (struct drm_vmw_control_stream_arg *)data; -struct vmw_dma_buffer *buf; +struct vmw_buffer_object *buf;struct vmw_resource *res;int ret;
@@ -484,13 +484,13 @@ int vmw_overlay_ioctl(struct drm_device *dev, void *data, goto out_unlock; } - ret =vmw_user_dmabuf_lookup (tfile, arg->handle, &buf,NULL ); + ret =vmw_user_bo_lookup (tfile, arg->handle, &buf,NULL );if (ret) goto out_unlock; ret =vmw_overlay_update_stream (dev_priv, buf, arg, true); -vmw_dmabuf_unreference (&buf); +vmw_bo_unreference (&buf); out_unlock:mutex_unlock (&overlay->mutex);
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +141 -139
694 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c +50 -50
259 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +11 -11
@@ -159,7 +159,7 @@ static int vmw_gb_shader_init(struct vmw_private *dev_priv,SVGA3dShaderType type, uint8_t num_input_sig, uint8_t num_output_sig, - struct vmw_dma_buffer *byte_code, + struct vmw_buffer_object *byte_code, void (*res_free) (struct vmw_resource *res)) { struct vmw_shader *shader = vmw_res_to_shader(res);
@@ -178,7 +178,7 @@ static int vmw_gb_shader_init(struct vmw_private *dev_priv, res->backup_size = size;if (byte_code) { - res->backup =vmw_dmabuf_reference (byte_code); + res->backup =vmw_bo_reference (byte_code); res->backup_offset = offset; } shader->size = size;
@@ -723,7 +723,7 @@ int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data, } static int vmw_user_shader_alloc(struct vmw_private *dev_priv, - struct vmw_dma_buffer *buffer, + struct vmw_buffer_object *buffer, size_t shader_size, size_t offset, SVGA3dShaderType shader_type,
@@ -801,7 +801,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv,static struct vmw_resource *vmw_shader_alloc (struct vmw_private *dev_priv, -struct vmw_dma_buffer *buffer, +struct vmw_buffer_object *buffer,size_t shader_size,size_t offset,SVGA3dShaderType shader_type)
@@ -862,12 +862,12 @@ static int vmw_shader_define(struct drm_device *dev, struct drm_file *file_priv, {struct vmw_private *dev_priv =vmw_priv (dev);struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; -struct vmw_dma_buffer *buffer =NULL ; +struct vmw_buffer_object *buffer =NULL ;SVGA3dShaderType shader_type;int ret;if (buffer_handle !=SVGA3D_INVALID_ID ) { - ret =vmw_user_dmabuf_lookup (tfile, buffer_handle, + ret =vmw_user_bo_lookup (tfile, buffer_handle, &buffer,NULL );if (unlikely (ret !=0 )) { DRM_ERROR("Could not find buffer for shader "
@@ -906,7 +906,7 @@ static int vmw_shader_define(struct drm_device *dev, struct drm_file *file_priv,ttm_read_unlock (&dev_priv->reservation_sem); out_bad_arg: -vmw_dmabuf_unreference (&buffer); +vmw_bo_unreference (&buffer);return ret; }
@@ -983,7 +983,7 @@ int vmw_compat_shader_add(struct vmw_private *dev_priv, struct list_head *list) {struct ttm_operation_ctx ctx = { false, true }; -struct vmw_dma_buffer *buf; +struct vmw_buffer_object *buf;struct ttm_bo_kmap_obj map;bool is_iomem;int ret;
@@ -997,8 +997,8 @@ int vmw_compat_shader_add(struct vmw_private *dev_priv,if (unlikely (!buf))return -ENOMEM ; - ret =vmw_dmabuf_init (dev_priv, buf, size, &vmw_sys_ne_placement, - true, vmw_dmabuf_bo_free); + ret =vmw_bo_init (dev_priv, buf, size, &vmw_sys_ne_placement, + true, vmw_bo_bo_free);if (unlikely (ret !=0 )) goto out;
@@ -1031,7 +1031,7 @@ int vmw_compat_shader_add(struct vmw_private *dev_priv, res, list);vmw_resource_unreference (&res); no_reserve: -vmw_dmabuf_unreference (&buf); +vmw_bo_unreference (&buf); out:return ret; }
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +32 -32
208 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +18 -19
@@ -842,12 +842,12 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,if (dev_priv->has_mob && req->shareable) {uint32_t backup_handle; - ret =vmw_user_dmabuf_alloc (dev_priv, tfile, - res->backup_size, - true, - &backup_handle, - &res->backup, - &user_srf->backup_base); + ret =vmw_user_bo_alloc (dev_priv, tfile, + res->backup_size, + true, + &backup_handle, + &res->backup, + &user_srf->backup_base);if (unlikely (ret !=0 )) {vmw_resource_unreference (&res); goto out_unlock;
@@ -1317,14 +1317,14 @@ int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,if (req->buffer_handle !=SVGA3D_INVALID_ID ) { - ret =vmw_user_dmabuf_lookup (tfile, req->buffer_handle, - &res->backup, - &user_srf->backup_base); + ret =vmw_user_bo_lookup (tfile, req->buffer_handle, + &res->backup, + &user_srf->backup_base);if (ret ==0 ) {if (res->backup->base.num_pages *PAGE_SIZE < res->backup_size) {DRM_ERROR ("Surface backup buffer is too small.\n" ); -vmw_dmabuf_unreference (&res->backup); +vmw_bo_unreference (&res->backup); ret = -EINVAL ; goto out_unlock; }else {
@@ -1332,13 +1332,13 @@ int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data, } } }else if (req->drm_surface_flags & drm_vmw_surface_flag_create_buffer) - ret =vmw_user_dmabuf_alloc (dev_priv, tfile, - res->backup_size, - req->drm_surface_flags & - drm_vmw_surface_flag_shareable, - &backup_handle, - &res->backup, - &user_srf->backup_base); + ret =vmw_user_bo_alloc (dev_priv, tfile, + res->backup_size, + req->drm_surface_flags & + drm_vmw_surface_flag_shareable, + &backup_handle, + &res->backup, + &user_srf->backup_base);if (unlikely (ret !=0 )) {vmw_resource_unreference (&res);
@@ -1414,8 +1414,7 @@ int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data, }mutex_lock (&dev_priv->cmdbuf_mutex);/* Protect res->backup */ - ret =vmw_user_dmabuf_reference (tfile, srf->res.backup, - &backup_handle); + ret =vmw_user_bo_reference (tfile, srf->res.backup, &backup_handle);mutex_unlock (&dev_priv->cmdbuf_mutex);if (unlikely (ret !=0 )) {
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c renamed from drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +1 -1
@@ -798,7 +798,7 @@ static int vmw_verify_access(struct ttm_buffer_object *bo, struct file *filp)struct ttm_object_file *tfile =vmw_fpriv ((struct drm_file *)filp->private_data)->tfile; -return vmw_user_dmabuf_verify_access (bo, tfile); +return vmw_user_bo_verify_access (bo, tfile); }static int vmw_ttm_io_mem_reserve (struct ttm_bo_device *bdev,struct ttm_mem_reg *mem)
include/uapi/drm/vmwgfx_drm.h +22 -39
68 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Part of the diff is not shown here. View the raw message.
PATCH 2/15 drm/vmwgfx: Move buffer object related code to vmwgfx_bo.c
In reply to Thomas HellstromIt makes more sense to have all the buffer object related code in a single file rather than splitting it up between the resource code and buffer object pinning utilities.
Place all buffer object related code in vmwgfx_bo.c. Fix up headers and export resource functionality when needed in the buffer object code.
--- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 816 ++++++++++++++++++++- drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 73 +- drivers/gpu/drm/vmwgfx/vmwgfx_fb.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_mob.c | 6 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 640 +--------------- drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 4 +- 11 files changed, 851 insertions(+), 708 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +780 -36
@@ -1,6 +1,6 @@/************************************************************************** * -* Copyright © 2011-2015 VMware, Inc., Palo Alto, CA., USA +* Copyright © 2011-2018 VMware, Inc., Palo Alto, CA., USA * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a
@@ -29,6 +29,51 @@#include <drm/drmP.h> #include "vmwgfx_drv.h" +#include "drm/ttm/ttm_object.h" + + +/** +* struct vmw_user_buffer_object - User-space-visible buffer object +* +* @prime: The prime object providing user visibility. +* @vbo: The struct vmw_buffer_object +*/ +struct vmw_user_buffer_object { +struct ttm_prime_object prime; +struct vmw_buffer_object vbo; +}; + + +/** +* vmw_buffer_object - Convert a struct ttm_buffer_object to a struct +* vmw_buffer_object. +* +* @bo: Pointer to the TTM buffer object. +* Return: Pointer to the struct vmw_buffer_object embedding the +* TTM buffer object. +*/ +static struct vmw_buffer_object * +vmw_buffer_object (struct ttm_buffer_object *bo) +{ + return container_of(bo, struct vmw_buffer_object, base); +} + + +/** +* vmw_user_buffer_object - Convert a struct ttm_buffer_object to a struct +* vmw_user_buffer_object. +* +* @bo: Pointer to the TTM buffer object. +* Return: Pointer to the struct vmw_buffer_object embedding the TTM buffer +* object. +*/ +static struct vmw_user_buffer_object * +vmw_user_buffer_object (struct ttm_buffer_object *bo) +{ +struct vmw_buffer_object *vmw_bo =vmw_buffer_object (bo); + + return container_of(vmw_bo, struct vmw_user_buffer_object, vbo); +}/**
@@ -38,9 +83,8 @@* @buf: DMA buffer to move. * @placement: The placement to pin it. * @interruptible: Use interruptible wait. -* -* Returns -* -ERESTARTSYS if interrupted by a signal. +* Return: Zero on success, Negative error code on failure. In particular +* -ERESTARTSYS if interrupted by a signal */ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv, struct vmw_buffer_object *buf,
@@ -78,6 +122,7 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,return ret; } +/** * vmw_bo_pin_in_vram_or_gmr - Move a buffer to vram or gmr. *
@@ -88,9 +133,8 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,* @buf: DMA buffer to move. * @pin: Pin buffer if true. * @interruptible: Use interruptible wait. -* -* Returns -* -ERESTARTSYS if interrupted by a signal. +* Return: Zero on success, Negative error code on failure. In particular +* -ERESTARTSYS if interrupted by a signal */ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv, struct vmw_buffer_object *buf,
@@ -133,6 +177,7 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,return ret; } +/** * vmw_bo_pin_in_vram - Move a buffer to vram. *
@@ -142,9 +187,8 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,* @dev_priv: Driver private. * @buf: DMA buffer to move. * @interruptible: Use interruptible wait. -* -* Returns -* -ERESTARTSYS if interrupted by a signal. +* Return: Zero on success, Negative error code on failure. In particular +* -ERESTARTSYS if interrupted by a signal */ int vmw_bo_pin_in_vram(struct vmw_private *dev_priv, struct vmw_buffer_object *buf,
@@ -154,6 +198,7 @@ int vmw_bo_pin_in_vram(struct vmw_private *dev_priv, interruptible); } +/** * vmw_bo_pin_in_start_of_vram - Move a buffer to start of vram. *
@@ -163,9 +208,8 @@ int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,* @dev_priv: Driver private. * @buf: DMA buffer to pin. * @interruptible: Use interruptible wait. -* -* Returns -* -ERESTARTSYS if interrupted by a signal. +* Return: Zero on success, Negative error code on failure. In particular +* -ERESTARTSYS if interrupted by a signal */ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv, struct vmw_buffer_object *buf,
@@ -225,6 +269,7 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,return ret; } +/** * vmw_bo_unpin - Unpin the buffer given buffer, does not move the buffer. *
@@ -233,9 +278,8 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,* @dev_priv: Driver private. * @buf: DMA buffer to unpin. * @interruptible: Use interruptible wait. -* -* Returns -* -ERESTARTSYS if interrupted by a signal. +* Return: Zero on success, Negative error code on failure. In particular +* -ERESTARTSYS if interrupted by a signal */ int vmw_bo_unpin(struct vmw_private *dev_priv, struct vmw_buffer_object *buf,
@@ -325,25 +369,8 @@ void vmw_bo_pin_reserved(struct vmw_buffer_object *vbo, bool pin) } -/* -* vmw_buffer_object_unmap - Tear down a cached buffer object map. -* -* @vbo: The buffer object whose map we are tearing down. -* -* This function tears down a cached map set up using -* vmw_buffer_object_map_and_cache(). -*/ -void vmw_buffer_object_unmap (struct vmw_buffer_object *vbo) -{ -if (vbo->map.bo ==NULL ) -return ; - -ttm_bo_kunmap (&vbo->map); -} - - -/* -* vmw_buffer_object_map_and_cache - Map a buffer object and cache the map +/** +* vmw_bo_map_and_cache - Map a buffer object and cache the map * * @vbo: The buffer object to map * Return: A kernel virtual address or NULL if mapping failed.
@@ -357,7 +384,7 @@ void vmw_buffer_object_unmap(struct vmw_buffer_object *vbo)* 3) Buffer object destruction * */ -void *vmw_buffer_object_map_and_cache (struct vmw_buffer_object *vbo) +void *vmw_bo_map_and_cache (struct vmw_buffer_object *vbo) {struct ttm_buffer_object *bo = &vbo->base;bool not_used;
@@ -374,3 +401,720 @@ void *vmw_buffer_object_map_and_cache(struct vmw_buffer_object *vbo)return ttm_kmap_obj_virtual (&vbo->map, ¬_used); } + + +/** +* vmw_bo_unmap - Tear down a cached buffer object map. +* +* @vbo: The buffer object whose map we are tearing down. +* +* This function tears down a cached map set up using +* vmw_buffer_object_map_and_cache(). +*/ +void vmw_bo_unmap (struct vmw_buffer_object *vbo) +{ +if (vbo->map.bo ==NULL ) +return ; + +ttm_bo_kunmap (&vbo->map); +} + + +/** +* vmw_bo_acc_size - Calculate the pinned memory usage of buffers +* +* @dev_priv: Pointer to a struct vmw_private identifying the device. +* @size: The requested buffer size. +* @user: Whether this is an ordinary dma buffer or a user dma buffer. +*/ +static size_t vmw_bo_acc_size (struct vmw_private *dev_priv,size_t size, +bool user) +{ +static size_t struct_size, user_struct_size; +size_t num_pages =PAGE_ALIGN (size) >>PAGE_SHIFT ; +size_t page_array_size =ttm_round_pot (num_pages *sizeof (void *)); + +if (unlikely (struct_size ==0 )) { +size_t backend_size =ttm_round_pot (vmw_tt_size); + + struct_size = backend_size + +ttm_round_pot (sizeof (struct vmw_buffer_object )); + user_struct_size = backend_size + +ttm_round_pot (sizeof (struct vmw_user_buffer_object )); + } + +if (dev_priv->map_mode == vmw_dma_alloc_coherent) + page_array_size += +ttm_round_pot (num_pages *sizeof (dma_addr_t)); + +return ((user) ? user_struct_size : struct_size) + + page_array_size; +} + + +/** +* vmw_bo_bo_free - vmw buffer object destructor +* +* @bo: Pointer to the embedded struct ttm_buffer_object +*/ +void vmw_bo_bo_free (struct ttm_buffer_object *bo) +{ +struct vmw_buffer_object *vmw_bo =vmw_buffer_object (bo); + +vmw_bo_unmap (vmw_bo); +kfree (vmw_bo); +} + + +/** +* vmw_user_bo_destroy - vmw buffer object destructor +* +* @bo: Pointer to the embedded struct ttm_buffer_object +*/ +static void vmw_user_bo_destroy (struct ttm_buffer_object *bo) +{ +struct vmw_user_buffer_object *vmw_user_bo =vmw_user_buffer_object (bo); + +vmw_bo_unmap (&vmw_user_bo->vbo); +ttm_prime_object_kfree (vmw_user_bo, prime); +} + + +/** +* vmw_bo_init - Initialize a vmw buffer object +* +* @dev_priv: Pointer to the device private struct +* @vmw_bo: Pointer to the struct vmw_buffer_object to initialize. +* @size: Buffer object size in bytes. +* @placement: Initial placement. +* @interruptible: Whether waits should be performed interruptible. +* @bo_free: The buffer object destructor. +* Returns: Zero on success, negative error code on error. +* +* Note that on error, the code will free the buffer object. +*/ +int vmw_bo_init (struct vmw_private *dev_priv, +struct vmw_buffer_object *vmw_bo, +size_t size,struct ttm_placement *placement, +bool interruptible, +void (*bo_free)(struct ttm_buffer_object *bo)) +{ +struct ttm_bo_device *bdev = &dev_priv->bdev; +size_t acc_size; +int ret; +bool user = (bo_free == &vmw_user_bo_destroy); + +WARN_ON_ONCE (!bo_free && (!user && (bo_free != vmw_bo_bo_free))); + + acc_size =vmw_bo_acc_size (dev_priv, size, user); +memset (vmw_bo,0 ,sizeof (*vmw_bo)); + +INIT_LIST_HEAD (&vmw_bo->res_list); + + ret =ttm_bo_init (bdev, &vmw_bo->base, size, + ttm_bo_type_device, placement, +0 , interruptible, acc_size, +NULL ,NULL , bo_free); +return ret; +} + + +/** +* vmw_user_bo_release - TTM reference base object release callback for +* vmw user buffer objects +* +* @p_base: The TTM base object pointer about to be unreferenced. +* +* Clears the TTM base object pointer and drops the reference the +* base object has on the underlying struct vmw_buffer_object. +*/ +static void vmw_user_bo_release (struct ttm_base_object **p_base) +{ +struct vmw_user_buffer_object *vmw_user_bo; +struct ttm_base_object *base = *p_base; +struct ttm_buffer_object *bo; + + *p_base =NULL ; + +if (unlikely (base ==NULL )) +return ; + + vmw_user_bo = container_of(base, struct vmw_user_buffer_object, + prime.base); + bo = &vmw_user_bo->vbo.base; +ttm_bo_unref (&bo); +} + + +/** +* vmw_user_bo_ref_obj-release - TTM synccpu reference object release callback +* for vmw user buffer objects +* +* @base: Pointer to the TTM base object +* @ref_type: Reference type of the reference reaching zero. +* +* Called when user-space drops its last synccpu reference on the buffer +* object, Either explicitly or as part of a cleanup file close. +*/ +static void vmw_user_bo_ref_obj_release (struct ttm_base_object *base, +enum ttm_ref_type ref_type) +{ +struct vmw_user_buffer_object *user_bo; + + user_bo = container_of(base, struct vmw_user_buffer_object, prime.base); + +switch (ref_type) { +case TTM_REF_SYNCCPU_WRITE : +ttm_bo_synccpu_write_release (&user_bo->vbo.base); +break ; +default : +WARN_ONCE (true,"Undefined buffer object reference release.\n" ); + } +} + + +/** +* vmw_user_bo_alloc - Allocate a user buffer object +* +* @dev_priv: Pointer to a struct device private. +* @tfile: Pointer to a struct ttm_object_file on which to register the user +* object. +* @size: Size of the buffer object. +* @shareable: Boolean whether the buffer is shareable with other open files. +* @handle: Pointer to where the handle value should be assigned. +* @p_vbo: Pointer to where the refcounted struct vmw_buffer_object pointer +* should be assigned. +* Return: Zero on success, negative error code on error. +*/ +int vmw_user_bo_alloc (struct vmw_private *dev_priv, +struct ttm_object_file *tfile, +uint32_t size, +bool shareable, +uint32_t *handle, +struct vmw_buffer_object **p_vbo, +struct ttm_base_object **p_base) +{ +struct vmw_user_buffer_object *user_bo; +struct ttm_buffer_object *tmp; +int ret; + + user_bo =kzalloc (sizeof (*user_bo),GFP_KERNEL ); +if (unlikely (!user_bo)) { +DRM_ERROR ("Failed to allocate a buffer.\n" ); +return -ENOMEM ; + } + + ret =vmw_bo_init (dev_priv, &user_bo->vbo, size, + (dev_priv->has_mob) ? + &vmw_sys_placement : + &vmw_vram_sys_placement, true, + &vmw_user_bo_destroy); +if (unlikely (ret !=0 )) +return ret; + + tmp =ttm_bo_reference (&user_bo->vbo.base); + ret =ttm_prime_object_init (tfile, + size, + &user_bo->prime, + shareable, + ttm_buffer_type, + &vmw_user_bo_release, + &vmw_user_bo_ref_obj_release); +if (unlikely (ret !=0 )) { +ttm_bo_unref (&tmp); + goto out_no_base_object; + } + + *p_vbo = &user_bo->vbo; +if (p_base) { + *p_base = &user_bo->prime.base; +kref_get (&(*p_base)->refcount); + } + *handle = user_bo->prime.base.hash.key; + +out_no_base_object: +return ret; +} + + +/** +* vmw_user_bo_verify_access - verify access permissions on this +* buffer object. +* +* @bo: Pointer to the buffer object being accessed +* @tfile: Identifying the caller. +*/ +int vmw_user_bo_verify_access (struct ttm_buffer_object *bo, +struct ttm_object_file *tfile) +{ +struct vmw_user_buffer_object *vmw_user_bo; + +if (unlikely (bo->destroy != vmw_user_bo_destroy)) +return -EPERM ; + + vmw_user_bo =vmw_user_buffer_object (bo); + +/* Check that the caller has opened the object. */ +if (likely (ttm_ref_object_exists (tfile, &vmw_user_bo->prime.base))) +return 0 ; + +DRM_ERROR ("Could not grant buffer access.\n" ); +return -EPERM ; +} + + +/** +* vmw_user_bo_synccpu_grab - Grab a struct vmw_user_buffer_object for cpu +* access, idling previous GPU operations on the buffer and optionally +* blocking it for further command submissions. +* +* @user_bo: Pointer to the buffer object being grabbed for CPU access +* @tfile: Identifying the caller. +* @flags: Flags indicating how the grab should be performed. +* Return: Zero on success, Negative error code on error. In particular, +* -EBUSY will be returned if a dontblock operation is requested and the +* buffer object is busy, and -ERESTARTSYS will be returned if a wait is +* interrupted by a signal. +* +* A blocking grab will be automatically released when @tfile is closed. +*/ +static int vmw_user_bo_synccpu_grab (struct vmw_user_buffer_object *user_bo, +struct ttm_object_file *tfile, +uint32_t flags) +{ +struct ttm_buffer_object *bo = &user_bo->vbo.base; +bool existed; +int ret; + +if (flags & drm_vmw_synccpu_allow_cs) { +bool nonblock = !!(flags & drm_vmw_synccpu_dontblock); +long lret; + + lret =reservation_object_wait_timeout_rcu + (bo->resv, true, true, + nonblock ?0 :MAX_SCHEDULE_TIMEOUT ); +if (!lret) +return -EBUSY ; +else if (lret <0 ) +return lret; +return 0 ; + } + + ret =ttm_bo_synccpu_write_grab + (bo, !!(flags & drm_vmw_synccpu_dontblock)); +if (unlikely (ret !=0 )) +return ret; + + ret =ttm_ref_object_add (tfile, &user_bo->prime.base, +TTM_REF_SYNCCPU_WRITE , &existed, false); +if (ret !=0 || existed) +ttm_bo_synccpu_write_release (&user_bo->vbo.base); + +return ret; +} + +/** +* vmw_user_bo_synccpu_release - Release a previous grab for CPU access, +* and unblock command submission on the buffer if blocked. +* +* @handle: Handle identifying the buffer object. +* @tfile: Identifying the caller. +* @flags: Flags indicating the type of release. +*/ +static int vmw_user_bo_synccpu_release (uint32_t handle, +struct ttm_object_file *tfile, +uint32_t flags) +{ +if (!(flags & drm_vmw_synccpu_allow_cs)) +return ttm_ref_object_base_unref (tfile, handle, +TTM_REF_SYNCCPU_WRITE ); + +return 0 ; +} + + +/** +* vmw_user_bo_synccpu_ioctl - ioctl function implementing the synccpu +* functionality. +* +* @dev: Identifies the drm device. +* @data: Pointer to the ioctl argument. +* @file_priv: Identifies the caller. +* Return: Zero on success, negative error code on error. +* +* This function checks the ioctl arguments for validity and calls the +* relevant synccpu functions. +*/ +int vmw_user_bo_synccpu_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_vmw_synccpu_arg *arg = + (struct drm_vmw_synccpu_arg *) data; +struct vmw_buffer_object *vbo; +struct vmw_user_buffer_object *user_bo; +struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct ttm_base_object *buffer_base; +int ret; + +if ((arg->flags & (drm_vmw_synccpu_read | drm_vmw_synccpu_write)) ==0 + || (arg->flags & ~(drm_vmw_synccpu_read | drm_vmw_synccpu_write | + drm_vmw_synccpu_dontblock | + drm_vmw_synccpu_allow_cs)) !=0 ) { +DRM_ERROR ("Illegal synccpu flags.\n" ); +return -EINVAL ; + } + +switch (arg->op) { +case drm_vmw_synccpu_grab: + ret =vmw_user_bo_lookup (tfile, arg->handle, &vbo, + &buffer_base); +if (unlikely (ret !=0 )) +return ret; + + user_bo = container_of(vbo, struct vmw_user_buffer_object, + vbo); + ret =vmw_user_bo_synccpu_grab (user_bo, tfile, arg->flags); +vmw_bo_unreference (&vbo); +ttm_base_object_unref (&buffer_base); +if (unlikely (ret !=0 && ret != -ERESTARTSYS && + ret != -EBUSY )) { +DRM_ERROR ("Failed synccpu grab on handle 0x%08x.\n" , + (unsigned int ) arg->handle); +return ret; + } +break ; +case drm_vmw_synccpu_release: + ret =vmw_user_bo_synccpu_release (arg->handle, tfile, + arg->flags); +if (unlikely (ret !=0 )) { +DRM_ERROR ("Failed synccpu release on handle 0x%08x.\n" , + (unsigned int ) arg->handle); +return ret; + } +break ; +default : +DRM_ERROR ("Invalid synccpu operation.\n" ); +return -EINVAL ; + } + +return 0 ; +} + + +/** +* vmw_bo_alloc_ioctl - ioctl function implementing the buffer object +* allocation functionality. +* +* @dev: Identifies the drm device. +* @data: Pointer to the ioctl argument. +* @file_priv: Identifies the caller. +* Return: Zero on success, negative error code on error. +* +* This function checks the ioctl arguments for validity and allocates a +* struct vmw_user_buffer_object bo. +*/ +int vmw_bo_alloc_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct vmw_private *dev_priv =vmw_priv (dev); +union drm_vmw_alloc_dmabuf_arg *arg = + (union drm_vmw_alloc_dmabuf_arg *)data; +struct drm_vmw_alloc_dmabuf_req *req = &arg->req; +struct drm_vmw_dmabuf_rep *rep = &arg->rep; +struct vmw_buffer_object *vbo; +uint32_t handle; +int ret; + + ret =ttm_read_lock (&dev_priv->reservation_sem, true); +if (unlikely (ret !=0 )) +return ret; + + ret =vmw_user_bo_alloc (dev_priv,vmw_fpriv (file_priv)->tfile, + req->size, false, &handle, &vbo, +NULL ); +if (unlikely (ret !=0 )) + goto out_no_bo; + + rep->handle = handle; + rep->map_handle =drm_vma_node_offset_addr (&vbo->base.vma_node); + rep->cur_gmr_id = handle; + rep->cur_gmr_offset =0 ; + +vmw_bo_unreference (&vbo); + +out_no_bo: +ttm_read_unlock (&dev_priv->reservation_sem); + +return ret; +} + + +/** +* vmw_bo_unref_ioctl - Generic handle close ioctl. +* +* @dev: Identifies the drm device. +* @data: Pointer to the ioctl argument. +* @file_priv: Identifies the caller. +* Return: Zero on success, negative error code on error. +* +* This function checks the ioctl arguments for validity and closes a +* handle to a TTM base object, optionally freeing the object. +*/ +int vmw_bo_unref_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_priv) +{ +struct drm_vmw_unref_dmabuf_arg *arg = + (struct drm_vmw_unref_dmabuf_arg *)data; + +return ttm_ref_object_base_unref (vmw_fpriv (file_priv)->tfile, + arg->handle, +TTM_REF_USAGE ); +} + + +/** +* vmw_user_bo_lookup - Look up a vmw user buffer object from a handle. +* +* @tfile: The TTM object file the handle is registered with. +* @handle: The user buffer object handle +* @out: Pointer to a where a pointer to the embedded +* struct vmw_buffer_object should be placed. +* @p_base: Pointer to where a pointer to the TTM base object should be +* placed, or NULL if no such pointer is required. +* Return: Zero on success, Negative error code on error. +* +* Both the output base object pointer and the vmw buffer object pointer +* will be refcounted. +*/ +int vmw_user_bo_lookup (struct ttm_object_file *tfile, +uint32_t handle,struct vmw_buffer_object **out, +struct ttm_base_object **p_base) +{ +struct vmw_user_buffer_object *vmw_user_bo; +struct ttm_base_object *base; + + base =ttm_base_object_lookup (tfile, handle); +if (unlikely (base ==NULL )) { +DRM_ERROR ("Invalid buffer object handle 0x%08lx.\n" , + (unsigned long )handle); +return -ESRCH ; + } + +if (unlikely (ttm_base_object_type (base) != ttm_buffer_type)) { +ttm_base_object_unref (&base); +DRM_ERROR ("Invalid buffer object handle 0x%08lx.\n" , + (unsigned long )handle); +return -EINVAL ; + } + + vmw_user_bo = container_of(base, struct vmw_user_buffer_object, + prime.base); + (void )ttm_bo_reference (&vmw_user_bo->vbo.base); +if (p_base) + *p_base = base; +else +ttm_base_object_unref (&base); + *out = &vmw_user_bo->vbo; + +return 0 ; +} + + +/** +* vmw_user_bo_reference - Open a handle to a vmw user buffer object. +* +* @tfile: The TTM object file to register the handle with. +* @vbo: The embedded vmw buffer object. +* @handle: Pointer to where the new handle should be placed. +* Return: Zero on success, Negative error code on error. +*/ +int vmw_user_bo_reference (struct ttm_object_file *tfile, +struct vmw_buffer_object *vbo, +uint32_t *handle) +{ +struct vmw_user_buffer_object *user_bo; + +if (vbo->base.destroy != vmw_user_bo_destroy) +return -EINVAL ; + + user_bo = container_of(vbo, struct vmw_user_buffer_object, vbo); + + *handle = user_bo->prime.base.hash.key; +return ttm_ref_object_add (tfile, &user_bo->prime.base, +TTM_REF_USAGE ,NULL , false); +} + + +/** +* vmw_bo_fence_single - Utility function to fence a single TTM buffer +* object without unreserving it. +* +* @bo: Pointer to the struct ttm_buffer_object to fence. +* @fence: Pointer to the fence. If NULL, this function will +* insert a fence into the command stream.. +* +* Contrary to the ttm_eu version of this function, it takes only +* a single buffer object instead of a list, and it also doesn't +* unreserve the buffer object, which needs to be done separately. +*/ +void vmw_bo_fence_single (struct ttm_buffer_object *bo, +struct vmw_fence_obj *fence) +{ +struct ttm_bo_device *bdev = bo->bdev; + +struct vmw_private *dev_priv = + container_of(bdev, struct vmw_private, bdev); + +if (fence ==NULL ) { +vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); +reservation_object_add_excl_fence (bo->resv, &fence->base); +dma_fence_put (&fence->base); + }else +reservation_object_add_excl_fence (bo->resv, &fence->base); +} + + +/** +* vmw_dumb_create - Create a dumb kms buffer +* +* @file_priv: Pointer to a struct drm_file identifying the caller. +* @dev: Pointer to the drm device. +* @args: Pointer to a struct drm_mode_create_dumb structure +* Return: Zero on success, negative error code on failure. +* +* This is a driver callback for the core drm create_dumb functionality. +* Note that this is very similar to the vmw_bo_alloc ioctl, except +* that the arguments have a different format. +*/ +int vmw_dumb_create (struct drm_file *file_priv, +struct drm_device *dev, +struct drm_mode_create_dumb *args) +{ +struct vmw_private *dev_priv =vmw_priv (dev); +struct vmw_buffer_object *vbo; +int ret; + + args->pitch = args->width * ((args->bpp +7 ) /8 ); + args->size = args->pitch * args->height; + + ret =ttm_read_lock (&dev_priv->reservation_sem, true); +if (unlikely (ret !=0 )) +return ret; + + ret =vmw_user_bo_alloc (dev_priv,vmw_fpriv (file_priv)->tfile, + args->size, false, &args->handle, + &vbo,NULL ); +if (unlikely (ret !=0 )) + goto out_no_bo; + +vmw_bo_unreference (&vbo); +out_no_bo: +ttm_read_unlock (&dev_priv->reservation_sem); +return ret; +} + + +/** +* vmw_dumb_map_offset - Return the address space offset of a dumb buffer +* +* @file_priv: Pointer to a struct drm_file identifying the caller. +* @dev: Pointer to the drm device. +* @handle: Handle identifying the dumb buffer. +* @offset: The address space offset returned. +* Return: Zero on success, negative error code on failure. +* +* This is a driver callback for the core drm dumb_map_offset functionality. +*/ +int vmw_dumb_map_offset (struct drm_file *file_priv, +struct drm_device *dev,uint32_t handle, +uint64_t *offset) +{ +struct ttm_object_file *tfile =vmw_fpriv (file_priv)->tfile; +struct vmw_buffer_object *out_buf; +int ret; + + ret =vmw_user_bo_lookup (tfile, handle, &out_buf,NULL ); +if (ret !=0 ) +return -EINVAL ; + + *offset =drm_vma_node_offset_addr (&out_buf->base.vma_node); +vmw_bo_unreference (&out_buf); +return 0 ; +} + + +/** +* vmw_dumb_destroy - Destroy a dumb boffer +* +* @file_priv: Pointer to a struct drm_file identifying the caller. +* @dev: Pointer to the drm device. +* @handle: Handle identifying the dumb buffer. +* Return: Zero on success, negative error code on failure. +* +* This is a driver callback for the core drm dumb_destroy functionality. +*/ +int vmw_dumb_destroy (struct drm_file *file_priv, +struct drm_device *dev, +uint32_t handle) +{ +return ttm_ref_object_base_unref (vmw_fpriv (file_priv)->tfile, + handle,TTM_REF_USAGE ); +} + + +/** +* vmw_bo_swap_notify - swapout notify callback. +* +* @bo: The buffer object to be swapped out. +*/ +void vmw_bo_swap_notify (struct ttm_buffer_object *bo) +{ +/* Is @bo embedded in a struct vmw_buffer_object? */ +if (bo->destroy != vmw_bo_bo_free && + bo->destroy != vmw_user_bo_destroy) +return ; + +/* Kill any cached kernel maps before swapout */ +vmw_bo_unmap (vmw_buffer_object (bo)); +} + + +/** +* vmw_bo_move_notify - TTM move_notify_callback +* +* @bo: The TTM buffer object about to move. +* @mem: The struct ttm_mem_reg indicating to what memory +* region the move is taking place. +* +* Detaches cached maps and device bindings that require that the +* buffer doesn't move. +*/ +void vmw_bo_move_notify (struct ttm_buffer_object *bo, +struct ttm_mem_reg *mem) +{ +struct vmw_buffer_object *vbo; + +if (mem ==NULL ) +return ; + +/* Make sure @bo is embedded in a struct vmw_buffer_object? */ +if (bo->destroy != vmw_bo_bo_free && + bo->destroy != vmw_user_bo_destroy) +return ; + + vbo = container_of(bo, struct vmw_buffer_object, base); + +/* +* Kill any cached kernel maps before move. An optimization could +* be to do this iff source or destination memory type is in VRAM. +*/ +vmw_bo_unmap (vbo); + +/* +* If we're moving a backup MOB out of MOB placement, then make sure we +* read back all resource content first, and unbind the MOB from +* the resource. +*/ +if (mem->mem_type !=VMW_PL_MOB ) +vmw_resource_unbind_list (vbo); +}
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +2 -2
@@ -424,7 +424,7 @@ static int vmw_gb_context_unbind(struct vmw_resource *res, (void )vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); -vmw_fence_single_bo (bo, fence); +vmw_bo_fence_single (bo, fence);if (likely (fence !=NULL ))vmw_fence_obj_unreference (&fence);
@@ -648,7 +648,7 @@ static int vmw_dx_context_unbind(struct vmw_resource *res, (void )vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); -vmw_fence_single_bo (bo, fence); +vmw_bo_fence_single (bo, fence);if (likely (fence !=NULL ))vmw_fence_obj_unreference (&fence);
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +2 -2
@@ -324,7 +324,7 @@ static int vmw_cotable_unbind(struct vmw_resource *res,vmw_dx_context_scrub_cotables (vcotbl->ctx, readback);mutex_unlock (&dev_priv->binding_mutex); (void )vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); -vmw_fence_single_bo (bo, fence); +vmw_bo_fence_single (bo, fence);if (likely (fence !=NULL ))vmw_fence_obj_unreference (&fence);
@@ -367,7 +367,7 @@ static int vmw_cotable_readback(struct vmw_resource *res) } (void )vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); -vmw_fence_single_bo (&res->backup->base, fence); +vmw_bo_fence_single (&res->backup->base, fence);vmw_fence_obj_unreference (&fence);return 0 ;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +35 -38
95 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c +1 -1
@@ -197,7 +197,7 @@ static void vmw_fb_dirty_flush(struct work_struct *work) (void )ttm_read_lock (&vmw_priv->reservation_sem, false); (void )ttm_bo_reserve (&vbo->base, false, false,NULL ); - virtual =vmw_buffer_object_map_and_cache (vbo); + virtual =vmw_bo_map_and_cache (vbo);if (!virtual) goto out_unreserve;
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +1 -1
@@ -2493,7 +2493,7 @@ void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv, ret =vmw_execbuf_fence_commands (file_priv, dev_priv, &fence, file_priv ? &handle :NULL );if (buf) -vmw_fence_single_bo (&buf->base, fence); +vmw_bo_fence_single (&buf->base, fence);if (file_priv) vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), ret, user_fence_rep, fence,
drivers/gpu/drm/vmwgfx/vmwgfx_mob.c +3 -3
@@ -225,7 +225,7 @@ static void vmw_takedown_otable_base(struct vmw_private *dev_priv, ret =ttm_bo_reserve (bo, false, true,NULL );BUG_ON (ret !=0 ); -vmw_fence_single_bo (bo,NULL ); +vmw_bo_fence_single (bo,NULL );ttm_bo_unreserve (bo); }
@@ -362,7 +362,7 @@ static void vmw_otable_batch_takedown(struct vmw_private *dev_priv, ret =ttm_bo_reserve (bo, false, true,NULL );BUG_ON (ret !=0 ); -vmw_fence_single_bo (bo,NULL ); +vmw_bo_fence_single (bo,NULL );ttm_bo_unreserve (bo);ttm_bo_unref (&batch->otable_bo);
@@ -620,7 +620,7 @@ void vmw_mob_unbind(struct vmw_private *dev_priv,vmw_fifo_commit (dev_priv,sizeof (*cmd)); }if (bo) { -vmw_fence_single_bo (bo,NULL ); +vmw_bo_fence_single (bo,NULL );ttm_bo_unreserve (bo); }vmw_fifo_resource_dec (dev_priv);
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +21 -619
683 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +2 -2
@@ -306,7 +306,7 @@ static int vmw_gb_shader_unbind(struct vmw_resource *res, (void )vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); -vmw_fence_single_bo (val_buf->bo, fence); +vmw_bo_fence_single (val_buf->bo, fence);if (likely (fence !=NULL ))vmw_fence_obj_unreference (&fence);
@@ -537,7 +537,7 @@ static int vmw_dx_shader_unbind(struct vmw_resource *res, (void )vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); -vmw_fence_single_bo (val_buf->bo, fence); +vmw_bo_fence_single (val_buf->bo, fence);if (likely (fence !=NULL ))vmw_fence_obj_unreference (&fence);
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +2 -2
@@ -468,7 +468,7 @@ static int vmw_legacy_srf_dma(struct vmw_resource *res, (void )vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); -vmw_fence_single_bo (val_buf->bo, fence); +vmw_bo_fence_single (val_buf->bo, fence);if (likely (fence !=NULL ))vmw_fence_obj_unreference (&fence);
@@ -1210,7 +1210,7 @@ static int vmw_gb_surface_unbind(struct vmw_resource *res, (void )vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); -vmw_fence_single_bo (val_buf->bo, fence); +vmw_bo_fence_single (val_buf->bo, fence);if (likely (fence !=NULL ))vmw_fence_obj_unreference (&fence);
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +2 -2
@@ -852,7 +852,7 @@ static void vmw_move_notify(struct ttm_buffer_object *bo,bool evict, struct ttm_mem_reg *mem) { -vmw_resource_move_notify (bo ,mem ); +vmw_bo_move_notify (bo ,mem );vmw_query_move_notify (bo, mem); }
@@ -864,7 +864,7 @@ static void vmw_move_notify(struct ttm_buffer_object *bo,*/ static void vmw_swap_notify (struct ttm_buffer_object *bo) { -vmw_resource_swap_notify (bo); +vmw_bo_swap_notify (bo); (void )ttm_bo_wait (bo, false, false); }
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/15 drm/vmwgfx: Optimize the buffer object swap_notify callback somewhat.
In reply to Thomas HellstromOnly try to unmap cached maps when the buffer is moved into or out from vram. Otherwise the underlying pages stay the same.
Also when unbinding resources from MOBs about to move, make sure we're really moving out of MOB memory.
--- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +6 -4
@@ -1105,16 +1105,18 @@ void vmw_bo_move_notify(struct ttm_buffer_object *bo, vbo = container_of(bo, struct vmw_buffer_object, base);/* -* Kill any cached kernel maps before move. An optimization could -* be to do this iff source or destination memory type is in VRAM. +* Kill any cached kernel maps before move to or from VRAM. +* With other types of moves, the underlying pages stay the same, +* and the map can be kept. */ -vmw_bo_unmap (vbo); +if (mem->mem_type ==TTM_PL_VRAM || bo->mem.mem_type ==TTM_PL_VRAM ) +vmw_bo_unmap (vbo);/* * If we're moving a backup MOB out of MOB placement, then make sure we * read back all resource content first, and unbind the MOB from * the resource. */ -if (mem->mem_type !=VMW_PL_MOB ) +if (mem->mem_type !=VMW_PL_MOB && bo->mem.mem_type ==VMW_PL_MOB )vmw_resource_unbind_list (vbo); }
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/15 drm/vmwgfx: Use blocking buffer object reserves when evicting resources
In reply to Thomas HellstromPreviously when evicting resources we were unconditionally calling ttm_eu_reserve_buffers with a NULL ww acquire context. That meant all buffer object reserves were done using trylock semantics. That makes sense when evicting during resource validation, because then there already are a number of buffers reserved and using waiting locks would cause lockdep errors.
That's not the case when unconditionally evicting all resources as part of driver takedown or hibernation, so in that code path, make sure we have a ww acquire context to get waiting lock buffer object reserve semantics.
--- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 29 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +19 -10
@@ -433,6 +433,7 @@ void vmw_resource_unreserve(struct vmw_resource *res,* for a resource and in that case, allocate * one, reserve and validate it. * +* @ticket: The ww aqcquire context to use, or NULL if trylocking. * @res: The resource for which to allocate a backup buffer. * @interruptible: Whether any sleeps during allocation should be * performed while interruptible.
@@ -440,7 +441,8 @@ void vmw_resource_unreserve(struct vmw_resource *res,* reserved and validated backup buffer. */ static int -vmw_resource_check_buffer (struct vmw_resource *res, +vmw_resource_check_buffer (struct ww_acquire_ctx *ticket, +struct vmw_resource *res,bool interruptible,struct ttm_validate_buffer *val_buf) {
@@ -459,7 +461,7 @@ vmw_resource_check_buffer(struct vmw_resource *res, val_buf->bo =ttm_bo_reference (&res->backup->base); val_buf->shared = false;list_add_tail (&val_buf->head, &val_list); - ret =ttm_eu_reserve_buffers (NULL , &val_list, interruptible,NULL ); + ret =ttm_eu_reserve_buffers (ticket, &val_list, interruptible,NULL );if (unlikely (ret !=0 )) goto out_no_reserve;
@@ -477,7 +479,7 @@ vmw_resource_check_buffer(struct vmw_resource *res,return 0 ; out_no_validate: -ttm_eu_backoff_reservation (NULL , &val_list); +ttm_eu_backoff_reservation (ticket, &val_list); out_no_reserve:ttm_bo_unref (&val_buf->bo);if (backup_dirty)
@@ -524,10 +526,12 @@ int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,* vmw_resource_backoff_reservation - Unreserve and unreference a * backup buffer *. +* @ticket: The ww acquire ctx used for reservation. * @val_buf: Backup buffer information. */ static void -vmw_resource_backoff_reservation (struct ttm_validate_buffer *val_buf) +vmw_resource_backoff_reservation (struct ww_acquire_ctx *ticket, +struct ttm_validate_buffer *val_buf) {struct list_head val_list;
@@ -536,7 +540,7 @@ vmw_resource_backoff_reservation(struct ttm_validate_buffer *val_buf)INIT_LIST_HEAD (&val_list);list_add_tail (&val_buf->head, &val_list); -ttm_eu_backoff_reservation (NULL , &val_list); +ttm_eu_backoff_reservation (ticket, &val_list);ttm_bo_unref (&val_buf->bo); }
@@ -544,10 +548,12 @@ vmw_resource_backoff_reservation(struct ttm_validate_buffer *val_buf)* vmw_resource_do_evict - Evict a resource, and transfer its data * to a backup buffer. * +* @ticket: The ww acquire ticket to use, or NULL if trylocking. * @res: The resource to evict. * @interruptible: Whether to wait interruptible. */ -static int vmw_resource_do_evict (struct vmw_resource *res,bool interruptible) +static int vmw_resource_do_evict (struct ww_acquire_ctx *ticket, +struct vmw_resource *res,bool interruptible) {struct ttm_validate_buffer val_buf;const struct vmw_res_func *func = res->func;
@@ -557,7 +563,7 @@ static int vmw_resource_do_evict(struct vmw_resource *res, bool interruptible) val_buf.bo =NULL ; val_buf.shared = false; - ret =vmw_resource_check_buffer (res, interruptible, &val_buf); + ret =vmw_resource_check_buffer (ticket, res, interruptible, &val_buf);if (unlikely (ret !=0 ))return ret;
@@ -572,7 +578,7 @@ static int vmw_resource_do_evict(struct vmw_resource *res, bool interruptible) res->backup_dirty = true; res->res_dirty = false; out_no_unbind: -vmw_resource_backoff_reservation (&val_buf); +vmw_resource_backoff_reservation (ticket, &val_buf);return ret; }
@@ -626,7 +632,8 @@ int vmw_resource_validate(struct vmw_resource *res)write_unlock (&dev_priv->resource_lock); - ret =vmw_resource_do_evict (evict_res, true); +/* Trylock backup buffers with a NULL ticket. */ + ret =vmw_resource_do_evict (NULL , evict_res, true);if (unlikely (ret !=0 )) {write_lock (&dev_priv->resource_lock);list_add_tail (&evict_res->lru_head, lru_list);
@@ -809,6 +816,7 @@ static void vmw_resource_evict_type(struct vmw_private *dev_priv,struct vmw_resource *evict_res;unsigned err_count =0 ;int ret; +struct ww_acquire_ctx ticket; do { write_lock(&dev_priv->resource_lock);
@@ -822,7 +830,8 @@ static void vmw_resource_evict_type(struct vmw_private *dev_priv,list_del_init (&evict_res->lru_head);write_unlock (&dev_priv->resource_lock); - ret =vmw_resource_do_evict (evict_res, false); +/* Wait lock backup buffers with a ticket. */ + ret =vmw_resource_do_evict (&ticket, evict_res, false);if (unlikely (ret !=0 )) {write_lock (&dev_priv->resource_lock);list_add_tail (&evict_res->lru_head, lru_list);
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/15 drm/vmwgfx: Fix atomic mode set check
In reply to Thomas HellstromFrom: Sinclair Yeh <[email protected]>
vmw_kms_atomic_check_modeset() is currently checking config using the legacy state, which is updated after a commit has happened.
This means vmw_kms_atomic_check_modeset() will reject an invalid config on the next update rather than the current one.
Fix this by using the new states for config checking
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 40 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +26 -14
@@ -1526,33 +1526,45 @@ static int vmw_kms_atomic_check_modeset(struct drm_device *dev, struct drm_atomic_state *state) { - struct drm_crtc_state *crtc_state; + struct drm_crtc_state *new_crtc_state; +struct drm_plane_state *new_plane_state; +struct drm_plane *plane;struct drm_crtc *crtc;struct vmw_private *dev_priv =vmw_priv (dev); -int i; +int i, ret, cpp =0 ; -for_each_new_crtc_in_state (state, crtc, crtc_state, i) { -unsigned long requested_bb_mem =0 ; + ret =drm_atomic_helper_check (dev, state); -if (dev_priv->active_display_unit == vmw_du_screen_target) { -struct drm_plane *plane = crtc->primary; -struct drm_plane_state *plane_state; +/* If this is not a STDU, then no more checking is necessary */ +if (ret || dev_priv->active_display_unit != vmw_du_screen_target) +return ret; - plane_state =drm_atomic_get_new_plane_state (state, plane); +for_each_new_plane_in_state (state, plane, new_plane_state, i) { +if (new_plane_state->fb) { +int current_cpp = new_plane_state->fb->pitches[0 ] / + new_plane_state->fb->width; -if (plane_state && plane_state->fb) { -int cpp = plane_state->fb->format->cpp[0 ]; +if (cpp ==0 ) + cpp = current_cpp; +else if (current_cpp != cpp) +return -EINVAL ; + } + } - requested_bb_mem += crtc->mode.hdisplay * cpp * - crtc->mode.vdisplay; - } +for_each_new_crtc_in_state (state, crtc, new_crtc_state, i) { +unsigned long requested_bb_mem =0 ; + +if (drm_atomic_crtc_needs_modeset (new_crtc_state)) { + requested_bb_mem += new_crtc_state->mode.hdisplay * + new_crtc_state->mode.vdisplay * + cpp;if (requested_bb_mem > dev_priv->prim_bb_mem)return -EINVAL ; } } -return drm_atomic_helper_check (dev, state); +return ret; } static const struct drm_mode_config_funcs vmw_kms_funcs = {
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 6/15 drm/vmwgfx: Perform topology validation during atomic modeset.
In reply to Thomas HellstromFrom: Deepak Rawat <[email protected]>
This patch adds display (primary) memory validation during modeset check. Display memory validation are applicable to both SOU and STDU, so allow both display unit to undergo this check.
Also added check for SVGA_CAP_NO_BB_RESTRICTION capability which lifts bounding box restriction for STDU.
--- .../gpu/drm/vmwgfx/device_include/svga_reg.h | 31 ++- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 184 ++++++++++++++---- 2 files changed, 177 insertions(+), 38 deletions(-)
drivers/gpu/drm/vmwgfx/device_include/svga_reg.h +29 -2
@@ -672,8 +672,34 @@ SVGASignedPoint;* SVGA_CAP_GBOBJECTS -- * Enable guest-backed objects and surfaces. * -* SVGA_CAP_CMD_BUFFERS_3 -- -* Enable support for command buffers in a mob. +* SVGA_CAP_DX -- +* Enable support for DX commands, and command buffers in a mob. +* +* SVGA_CAP_HP_CMD_QUEUE -- +* Enable support for the high priority command queue, and the +* ScreenCopy command. +* +* SVGA_CAP_NO_BB_RESTRICTION -- +* Allow ScreenTargets to be defined without regard to the 32-bpp +* bounding-box memory restrictions. ie: +* +* The summed memory usage of all screens (assuming they were defined as +* 32-bpp) must always be less than the value of the +* SVGA_REG_MAX_PRIMARY_MEM register. +* +* If this cap is not present, the 32-bpp bounding box around all screens +* must additionally be under the value of the SVGA_REG_MAX_PRIMARY_MEM +* register. +* +* If the cap is present, the bounding box restriction is lifted (and only +* the screen-sum limit applies). +* +* (Note that this is a slight lie... there is still a sanity limit on any +* dimension of the topology to be less than SVGA_SCREEN_ROOT_LIMIT, even +* when SVGA_CAP_NO_BB_RESTRICTION is present, but that should be +* large enough to express any possible topology without holes between +* monitors.) +* */ #define SVGA_CAP_NONE 0x00000000
@@ -699,6 +725,7 @@ SVGASignedPoint;#define SVGA_CAP_GBOBJECTS 0x08000000#define SVGA_CAP_DX 0x10000000#define SVGA_CAP_HP_CMD_QUEUE 0x20000000 +#define SVGA_CAP_NO_BB_RESTRICTION 0x40000000#define SVGA_CAP_CMD_RESERVED 0x80000000
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +148 -36
214 lines not on this page · raw message
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 7/15 drm/vmwgfx: Use modeset display memory validation for layout ioctl
In reply to Thomas HellstromFrom: Deepak Rawat <[email protected]>
Call the same display memory validation function which is used by modeset_check. This ensure consistency that kernel change preferred mode/topology only if supported.
Also change the internal function to use drm_rect instead of drm_vmw_rect.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 120 ++++++++++++---------------- 1 file changed, 51 insertions(+), 69 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +51 -69
@@ -1968,13 +1968,15 @@ void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe) { } - -/* -* Small shared kms functions. +/** +* vmw_du_update_layout - Update the display unit with topology from resolution +* plugin and generate DRM uevent +* @dev_priv: device private +* @num_rects: number of drm_rect in rects +* @rects: toplogy to update */ - -static int vmw_du_update_layout (struct vmw_private *dev_priv,unsigned num, -struct drm_vmw_rect *rects) +static int vmw_du_update_layout (struct vmw_private *dev_priv, +unsigned int num_rects,struct drm_rect *rects) {struct drm_device *dev = dev_priv->dev;struct vmw_display_unit *du;
@@ -1982,26 +1984,14 @@ static int vmw_du_update_layout(struct vmw_private *dev_priv, unsigned num,mutex_lock (&dev->mode_config.mutex); -#if 0 - { -unsigned int i; - -DRM_INFO ("%s: new layout " , __func__); -for (i =0 ; i < num; i++) -DRM_INFO ("(%i, %i %ux%u) " , rects[i].x, rects[i].y, - rects[i].w, rects[i].h); -DRM_INFO ("\n" ); - } -#endif -list_for_each_entry (con, &dev->mode_config.connector_list, head) { du =vmw_connector_to_du (con); -if (num > du->unit) { - du->pref_width = rects[du->unit].w; - du->pref_height = rects[du->unit].h; +if (num_rects > du->unit) { + du->pref_width =drm_rect_width (&rects[du->unit]); + du->pref_height =drm_rect_height (&rects[du->unit]); du->pref_active = true; - du->gui_x = rects[du->unit].x; - du->gui_y = rects[du->unit].y; + du->gui_x = rects[du->unit].x1; + du->gui_y = rects[du->unit].y1;drm_object_property_set_value (&con->base, dev->mode_config.suggested_x_property, du->gui_x);
@@ -2322,7 +2312,25 @@ vmw_du_connector_atomic_get_property(struct drm_connector *connector,return 0 ; } - +/** +* vmw_kms_update_layout_ioctl - Handler for DRM_VMW_UPDATE_LAYOUT ioctl +* @dev: drm device for the ioctl +* @data: data pointer for the ioctl +* @file_priv: drm file for the ioctl call +* +* Update preferred topology of display unit as per ioctl request. The topology +* is expressed as array of drm_vmw_rect. +* e.g. +* [0 0 640 480] [640 0 800 600] [0 480 640 480] +* +* NOTE: +* The x and y offset (upper left) in drm_vmw_rect cannot be less than 0. Beside +* device limit on topology, x + w and y + h (lower right) cannot be greater +* than INT_MAX. So topology beyond these limits will return with error. +* +* Returns: +* Zero on success, negative errno on failure. +*/ int vmw_kms_update_layout_ioctl (struct drm_device *dev,void *data,struct drm_file *file_priv) {
@@ -2331,15 +2339,12 @@ int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, (struct drm_vmw_update_layout_arg *)data;void __user *user_rects;struct drm_vmw_rect *rects; +struct drm_rect *drm_rects;unsigned rects_size; -int ret; -int i; -u64 total_pixels =0 ; -struct drm_mode_config *mode_config = &dev->mode_config; -struct drm_vmw_rect bounding_box = {0 }; +int ret, i;if (!arg->num_outputs) { -struct drm_vmw_rect def_rect = {0 ,0 ,800 ,600 }; +struct drm_rect def_rect = {0 ,0 ,800 ,600 };vmw_du_update_layout (dev_priv,1 , &def_rect);return 0 ; }
@@ -2358,52 +2363,29 @@ int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, goto out_free; } -for (i =0 ; i < arg->num_outputs; ++i) { -if (rects[i].x <0 || - rects[i].y <0 || - rects[i].x + rects[i].w > mode_config->max_width || - rects[i].y + rects[i].h > mode_config->max_height) { -DRM_ERROR ("Invalid GUI layout.\n" ); - ret = -EINVAL ; - goto out_free; - } - -/* -* bounding_box.w and bunding_box.h are used as -* lower-right coordinates -*/ -if (rects[i].x + rects[i].w > bounding_box.w) - bounding_box.w = rects[i].x + rects[i].w; - -if (rects[i].y + rects[i].h > bounding_box.h) - bounding_box.h = rects[i].y + rects[i].h; + drm_rects = (struct drm_rect *)rects; - total_pixels += (u64 ) rects[i].w * (u64 ) rects[i].h; - } +for (i =0 ; i < arg->num_outputs; i++) { +struct drm_vmw_rect curr_rect; -if (dev_priv->active_display_unit == vmw_du_screen_target) { -/* -* For Screen Targets, the limits for a toplogy are: -* 1. Bounding box (assuming 32bpp) must be < prim_bb_mem -* 2. Total pixels (assuming 32bpp) must be < prim_bb_mem -*/ -u64 bb_mem = (u64 ) bounding_box.w * bounding_box.h *4 ; -u64 pixel_mem = total_pixels *4 ; - -if (bb_mem > dev_priv->prim_bb_mem) { -DRM_ERROR ("Topology is beyond supported limits.\n" ); - ret = -EINVAL ; +/* Verify user-space for overflow as kernel use drm_rect */ +if ((rects[i].x + rects[i].w >INT_MAX ) || + (rects[i].y + rects[i].h >INT_MAX )) { + ret = -ERANGE ; goto out_free; } -if (pixel_mem > dev_priv->prim_bb_mem) { -DRM_ERROR ("Combined output size too large\n" ); - ret = -EINVAL ; - goto out_free; - } + curr_rect = rects[i]; + drm_rects[i].x1 = curr_rect.x; + drm_rects[i].y1 = curr_rect.y; + drm_rects[i].x2 = curr_rect.x + curr_rect.w; + drm_rects[i].y2 = curr_rect.y + curr_rect.h; } -vmw_du_update_layout (dev_priv, arg->num_outputs, rects); + ret =vmw_kms_check_display_memory (dev, arg->num_outputs, drm_rects); + +if (ret ==0 ) +vmw_du_update_layout (dev_priv, arg->num_outputs, drm_rects); out_free:kfree (rects);
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 8/15 drm/vmwgfx: Perform memory validations only when need full modeset.
In reply to Thomas HellstromFrom: Deepak Rawat <[email protected]>
For cases when full modeset is not requested like page-flip, skip memory validation as the topology is not changed.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +21 -2
@@ -1670,13 +1670,32 @@ static int vmw_kms_atomic_check_modeset(struct drm_device *dev, struct drm_atomic_state *state) { - int ret; + struct drm_crtc *crtc; +struct drm_crtc_state *crtc_state; +bool need_modeset = false; +int i, ret; ret =drm_atomic_helper_check (dev, state);if (ret)return ret; -return vmw_kms_check_topology (dev, state); +if (!state->allow_modeset) +return ret; + +/* +* Legacy path do not set allow_modeset properly like +* @drm_atomic_helper_update_plane, This will result in unnecessary call +* to vmw_kms_check_topology. So extra set of check. +*/ +for_each_new_crtc_in_state (state, crtc, crtc_state, i) { +if (drm_atomic_crtc_needs_modeset (crtc_state)) + need_modeset = true; + } + +if (need_modeset) +return vmw_kms_check_topology (dev, state); + +return ret; } static const struct drm_mode_config_funcs vmw_kms_funcs = {
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 9/15 drm/vmwgfx: Remove primary memory validation against mode while creating fb
In reply to Thomas HellstromFrom: Deepak Rawat <[email protected]>
This validation is not required because user-space will send create_fb request once the memory is allocated. This check should be performed during mode-setting.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +0 -13
@@ -1433,19 +1433,6 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,struct ttm_base_object *user_obj;int ret; -/** -* This code should be conditioned on Screen Objects not being used. -* If screen objects are used, we can allocate a GMR to hold the -* requested framebuffer. -*/ - -if (!vmw_kms_validate_mode_vram (dev_priv, - mode_cmd->pitches[0 ], - mode_cmd->height)) { -DRM_ERROR ("Requested mode exceed bounding box limit.\n" ); -return ERR_PTR (-ENOMEM ); - } -/* * Take a reference on the user object of the resource * backing the kms fb. This ensures that user-space handle
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 10/15 drm/vmwgfx: Use a mutex to protect gui positioning in vmw_display_unit
In reply to Thomas HellstromFrom: Deepak Rawat <[email protected]>
To avoid race condition between update_layout ioctl and modeset ioctl for access to gui_x/y positioning added a new mutex requested_layout_mutex.
Also used drm_for_each_connector_iter to iterate over connector list.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 9 +++++++ drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 38 ++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 11 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -0
@@ -644,6 +644,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)mutex_init (&dev_priv->cmdbuf_mutex);mutex_init (&dev_priv->release_mutex);mutex_init (&dev_priv->binding_mutex); +mutex_init (&dev_priv->requested_layout_mutex);mutex_init (&dev_priv->global_kms_state_mutex);rwlock_init (&dev_priv->resource_lock);ttm_lock_init (&dev_priv->reservation_sem);
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +9 -0
@@ -411,6 +411,15 @@ struct vmw_private {uint32_t num_displays; +/* +* Currently requested_layout_mutex is used to protect the gui +* positionig state in display unit. With that use case currently this +* mutex is only taken during layout ioctl and atomic check_modeset. +* Other display unit state can be protected with this mutex but that +* needs careful consideration. +*/ +struct mutex requested_layout_mutex; +/* * Framebuffer info. */
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +27 -11
@@ -1577,6 +1577,7 @@ static int vmw_kms_check_display_memory(struct drm_device *dev,static int vmw_kms_check_topology (struct drm_device *dev,struct drm_atomic_state *state) { +struct vmw_private *dev_priv =vmw_priv (dev);struct drm_crtc_state *old_crtc_state, *new_crtc_state;struct drm_rect *rects;struct drm_crtc *crtc;
@@ -1588,6 +1589,8 @@ static int vmw_kms_check_topology(struct drm_device *dev,if (!rects)return -ENOMEM ; +mutex_lock (&dev_priv->requested_layout_mutex); +drm_for_each_crtc (crtc, dev) {struct vmw_display_unit *du =vmw_crtc_to_du (crtc);struct drm_crtc_state *crtc_state = crtc->state;
@@ -1595,10 +1598,6 @@ static int vmw_kms_check_topology(struct drm_device *dev, i =drm_crtc_index (crtc);if (crtc_state && crtc_state->enable) { -/* -* There could be a race condition with update of gui_x/ -* gui_y. Those are protected by dev->mode_config.mutex. -*/ rects[i].x1 = du->gui_x; rects[i].y1 = du->gui_y; rects[i].x2 = du->gui_x + crtc_state->mode.hdisplay;
@@ -1636,6 +1635,7 @@ static int vmw_kms_check_topology(struct drm_device *dev, rects); clean: +mutex_unlock (&dev_priv->requested_layout_mutex);kfree (rects);return ret; }
@@ -1987,10 +1987,14 @@ static int vmw_du_update_layout(struct vmw_private *dev_priv,struct drm_device *dev = dev_priv->dev;struct vmw_display_unit *du;struct drm_connector *con; +struct drm_connector_list_iter conn_iter; -mutex_lock (&dev->mode_config.mutex); - -list_for_each_entry (con, &dev->mode_config.connector_list, head) { +/* +* Currently only gui_x/y is protected with requested_layout_mutex. +*/ +mutex_lock (&dev_priv->requested_layout_mutex); +drm_connector_list_iter_begin (dev, &conn_iter); +drm_for_each_connector_iter (con, &conn_iter) { du =vmw_connector_to_du (con);if (num_rects > du->unit) { du->pref_width =drm_rect_width (&rects[du->unit]);
@@ -1998,6 +2002,21 @@ static int vmw_du_update_layout(struct vmw_private *dev_priv, du->pref_active = true; du->gui_x = rects[du->unit].x1; du->gui_y = rects[du->unit].y1; + }else { + du->pref_width =800 ; + du->pref_height =600 ; + du->pref_active = false; + du->gui_x =0 ; + du->gui_y =0 ; + } + } +drm_connector_list_iter_end (&conn_iter); +mutex_unlock (&dev_priv->requested_layout_mutex); + +mutex_lock (&dev->mode_config.mutex); +list_for_each_entry (con, &dev->mode_config.connector_list, head) { + du =vmw_connector_to_du (con); +if (num_rects > du->unit) {drm_object_property_set_value (&con->base, dev->mode_config.suggested_x_property, du->gui_x);
@@ -2005,9 +2024,6 @@ static int vmw_du_update_layout(struct vmw_private *dev_priv, (&con->base, dev->mode_config.suggested_y_property, du->gui_y); }else { - du->pref_width =800 ; - du->pref_height =600 ; - du->pref_active = false;drm_object_property_set_value (&con->base, dev->mode_config.suggested_x_property,0 );
@@ -2017,8 +2033,8 @@ static int vmw_du_update_layout(struct vmw_private *dev_priv, } con->status =vmw_du_connector_detect (con, true); } -mutex_unlock (&dev->mode_config.mutex); +drm_sysfs_hotplug_event (dev);return 0 ;
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 11/15 drm/vmwgfx: Add gui_x/y to vmw_connector_state
In reply to Thomas HellstromFrom: Deepak Rawat <[email protected]>
As gui_x/y positioning is display unit is protected by requested_layout_mutex adding vmw_connector_state copy of the same and modeset commit will refer the state copy to sync with modeset_check state.
v2: Tested with CONFIG_PROVE_LOCKING enabled.
--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 37 +++++++++++++++++++-------- drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 18 +++++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 38 +++++++++++++++++----------- drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 29 +++++++++++++-------- 4 files changed, 86 insertions(+), 36 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +27 -10
@@ -1609,26 +1609,43 @@ static int vmw_kms_check_topology(struct drm_device *dev,for_each_oldnew_crtc_in_state (state, crtc, old_crtc_state, new_crtc_state, i) {struct vmw_display_unit *du =vmw_crtc_to_du (crtc); +struct drm_connector *connector; +struct drm_connector_state *conn_state; +struct vmw_connector_state *vmw_conn_state;if (!new_crtc_state->enable && old_crtc_state->enable) { rects[i].x1 =0 ; rects[i].y1 =0 ; rects[i].x2 =0 ; rects[i].y2 =0 ; +continue ; } -if (new_crtc_state->enable) { -/* If display unit is not active cannot enable CRTC */ -if (!du->pref_active) { - ret = -EINVAL ; - goto clean; - } +if (!du->pref_active) { + ret = -EINVAL ; + goto clean; + } - rects[i].x1 = du->gui_x; - rects[i].y1 = du->gui_y; - rects[i].x2 = du->gui_x + new_crtc_state->mode.hdisplay; - rects[i].y2 = du->gui_y + new_crtc_state->mode.vdisplay; +/* +* For vmwgfx each crtc has only one connector attached and it +* is not changed so don't really need to check the +* crtc->connector_mask and iterate over it. +*/ + connector = &du->connector; + conn_state =drm_atomic_get_connector_state (state, connector); +if (IS_ERR (conn_state)) { + ret =PTR_ERR (conn_state); + goto clean; } + + vmw_conn_state =vmw_connector_state_to_vcs (conn_state); + vmw_conn_state->gui_x = du->gui_x; + vmw_conn_state->gui_y = du->gui_y; + + rects[i].x1 = du->gui_x; + rects[i].y1 = du->gui_y; + rects[i].x2 = du->gui_x + new_crtc_state->mode.hdisplay; + rects[i].y2 = du->gui_y + new_crtc_state->mode.vdisplay; } ret = vmw_kms_check_display_memory(dev, dev->mode_config.num_crtc,
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +18 -0
@@ -192,6 +192,24 @@ struct vmw_connector_state {struct drm_connector_state base;bool is_implicit; + +/** +* @gui_x: +* +* vmwgfx connector property representing the x position of this display +* unit (connector is synonymous to display unit) in overall topology. +* This is what the device expect as xRoot while creating screen. +*/ +int gui_x; + +/** +* @gui_y: +* +* vmwgfx connector property representing the y position of this display +* unit (connector is synonymous to display unit) in overall topology. +* This is what the device expect as yRoot while creating screen. +*/ +int gui_y; };/**
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c +23 -15
@@ -109,7 +109,7 @@ static void vmw_sou_crtc_destroy(struct drm_crtc *crtc)*/ static int vmw_sou_fifo_create (struct vmw_private *dev_priv,struct vmw_screen_object_unit *sou, -uint32_t x,uint32_t y, +int x,int y,struct drm_display_mode *mode) {size_t fifo_size;
@@ -139,13 +139,8 @@ static int vmw_sou_fifo_create(struct vmw_private *dev_priv, (sou->base.unit ==0 ?SVGA_SCREEN_IS_PRIMARY :0 ); cmd->obj.size.width = mode->hdisplay; cmd->obj.size.height = mode->vdisplay; -if (sou->base.is_implicit) { - cmd->obj.root.x = x; - cmd->obj.root.y = y; - }else { - cmd->obj.root.x = sou->base.gui_x; - cmd->obj.root.y = sou->base.gui_y; - } + cmd->obj.root.x = x; + cmd->obj.root.y = y; sou->base.set_gui_x = cmd->obj.root.x; sou->base.set_gui_y = cmd->obj.root.y;
@@ -222,12 +217,11 @@ static void vmw_sou_crtc_mode_set_nofb(struct drm_crtc *crtc)struct vmw_plane_state *vps;int ret; - - sou =vmw_crtc_to_sou (crtc); + sou =vmw_crtc_to_sou (crtc); dev_priv =vmw_priv (crtc->dev); - ps = crtc->primary->state; - fb = ps->fb; - vps =vmw_plane_state_to_vps (ps); + ps = crtc->primary->state; + fb = ps->fb; + vps =vmw_plane_state_to_vps (ps); vfb = (fb) ?vmw_framebuffer_to_vfb (fb) :NULL ;
@@ -240,11 +234,25 @@ static void vmw_sou_crtc_mode_set_nofb(struct drm_crtc *crtc) }if (vfb) { +struct drm_connector_state *conn_state; +struct vmw_connector_state *vmw_conn_state; +int x, y; + sou->buffer = vps->bo; sou->buffer_size = vps->bo_size; - ret =vmw_sou_fifo_create (dev_priv, sou, crtc->x, crtc->y, - &crtc->mode); +if (sou->base.is_implicit) { + x = crtc->x; + y = crtc->y; + }else { + conn_state = sou->base.connector.state; + vmw_conn_state =vmw_connector_state_to_vcs (conn_state); + + x = vmw_conn_state->gui_x; + y = vmw_conn_state->gui_y; + } + + ret =vmw_sou_fifo_create (dev_priv, sou, x, y, &crtc->mode);if (ret)DRM_ERROR ("Failed to define Screen Object %dx%d\n" , crtc->x, crtc->y);
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +18 -11
@@ -178,13 +178,9 @@ static int vmw_stdu_define_st(struct vmw_private *dev_priv, cmd->body.height = mode->vdisplay; cmd->body.flags = (0 == cmd->body.stid) ?SVGA_STFLAG_PRIMARY :0 ; cmd->body.dpi =0 ; -if (stdu->base.is_implicit) { - cmd->body.xRoot = crtc_x; - cmd->body.yRoot = crtc_y; - }else { - cmd->body.xRoot = stdu->base.gui_x; - cmd->body.yRoot = stdu->base.gui_y; - } + cmd->body.xRoot = crtc_x; + cmd->body.yRoot = crtc_y; + stdu->base.set_gui_x = cmd->body.xRoot; stdu->base.set_gui_y = cmd->body.yRoot;
@@ -374,11 +370,14 @@ static void vmw_stdu_crtc_mode_set_nofb(struct drm_crtc *crtc) {struct vmw_private *dev_priv;struct vmw_screen_target_display_unit *stdu; -int ret; - +struct drm_connector_state *conn_state; +struct vmw_connector_state *vmw_conn_state; +int x, y, ret; - stdu =vmw_crtc_to_stdu (crtc); + stdu =vmw_crtc_to_stdu (crtc); dev_priv =vmw_priv (crtc->dev); + conn_state = stdu->base.connector.state; + vmw_conn_state =vmw_connector_state_to_vcs (conn_state);if (stdu->defined) { ret =vmw_stdu_bind_st (dev_priv, stdu,NULL );
@@ -397,8 +396,16 @@ static void vmw_stdu_crtc_mode_set_nofb(struct drm_crtc *crtc)if (!crtc->state->enable)return ; +if (stdu->base.is_implicit) { + x = crtc->x; + y = crtc->y; + }else { + x = vmw_conn_state->gui_x; + y = vmw_conn_state->gui_y; + } +vmw_svga_enable (dev_priv); - ret =vmw_stdu_define_st (dev_priv, stdu, &crtc->mode, crtc->x, crtc->y); + ret =vmw_stdu_define_st (dev_priv, stdu, &crtc->mode, x, y);if (ret) DRM_ERROR("Failed to define Screen Target of size %dx%d\n",
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 12/15 drm/vmwgfx: Improve on host message error messages
In reply to Thomas HellstromMake sure the error messages are a bit more descriptive, so that a log reader may understand what's gone wrong.
--- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +7 -6
@@ -234,7 +234,7 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg,if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 || (HIGH_WORD (ecx) &MESSAGE_STATUS_HB ) ==0 ) { -DRM_ERROR ("Failed to get reply size\n" ); +DRM_ERROR ("Failed to get reply size for host message.\n" );return -EINVAL ; }
@@ -245,7 +245,7 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg, reply_len = ebx; reply =kzalloc (reply_len +1 ,GFP_KERNEL );if (!reply) { -DRM_ERROR ("Cannot allocate memory for reply\n" ); +DRM_ERROR ("Cannot allocate memory for host message reply.\n" );return -ENOMEM ; }
@@ -338,7 +338,8 @@ int vmw_host_get_guestinfo(const char *guest_info_param, msg =kasprintf (GFP_KERNEL ,"info-get %s" , guest_info_param);if (!msg) { -DRM_ERROR ("Cannot allocate memory to get %s" , guest_info_param); +DRM_ERROR ("Cannot allocate memory to get guest info \"%s\"." , + guest_info_param);return -ENOMEM ; }
@@ -374,7 +375,7 @@ int vmw_host_get_guestinfo(const char *guest_info_param, out_open: *length =0 ;kfree (msg); -DRM_ERROR ("Failed to get %s" , guest_info_param); +DRM_ERROR ("Failed to get guest info \"%s\"." , guest_info_param);return -EINVAL ; }
@@ -403,7 +404,7 @@ int vmw_host_log(const char *log) msg =kasprintf (GFP_KERNEL ,"log %s" , log);if (!msg) { -DRM_ERROR ("Cannot allocate memory for log message\n" ); +DRM_ERROR ("Cannot allocate memory for host log message.\n" );return -ENOMEM ; }
@@ -422,7 +423,7 @@ int vmw_host_log(const char *log)vmw_close_channel (&channel); out_open:kfree (msg); -DRM_ERROR ("Failed to send log\n" ); +DRM_ERROR ("Failed to send host log message.\n" );return -EINVAL ; }
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 13/15 drm/vmwgfx: Reorganize the fence wait loop
In reply to Thomas HellstromReorganize the fence wait loop somewhat to make it look more like the examples in set_current_state() kerneldoc, and add some code comments.
Also if we're about to time out, make sure we check again whether the fence is actually signaled.
--- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 38 ++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +26 -12
@@ -175,7 +175,6 @@ static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout)struct vmw_private *dev_priv = fman->dev_priv;struct vmwgfx_wait_cb cb;long ret = timeout; -unsigned long irq_flags;if (likely (vmw_fence_obj_signaled (fence)))return timeout;
@@ -183,7 +182,7 @@ static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout)vmw_fifo_ping_host (dev_priv,SVGA_SYNC_GENERIC );vmw_seqno_waiter_add (dev_priv); -spin_lock_irqsave (f->lock, irq_flags); +spin_lock (f->lock);if (intr &&signal_pending (current)) { ret = -ERESTARTSYS ;
@@ -194,30 +193,45 @@ static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout) cb.task = current;list_add (&cb.base.node, &f->cb_list); -while (ret >0 ) { +for (;;) {__vmw_fences_update (fman); -if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &f->flags)) -break ; +/* +* 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 ); -spin_unlock_irqrestore (f->lock, irq_flags); - ret =schedule_timeout (ret); +if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &f->flags)) { +if (ret ==0 && timeout >0 ) + ret =1 ; +break ; + } -spin_lock_irqsave (f->lock, irq_flags); -if (ret >0 && intr &&signal_pending (current)) +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); -__set_current_state (TASK_RUNNING ); out: -spin_unlock_irqrestore (f->lock, irq_flags); +spin_unlock (f->lock);vmw_seqno_waiter_remove (dev_priv);
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 14/15 drm/vmwgfx: Fix host message module function declarations
In reply to Thomas HellstromMake the host message module function declarations similar to the other declarations in vmwgfx_drv.h and include the header in vmwgfx_msg.c
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 11 +++++------ drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 1 + 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +5 -6
@@ -1230,6 +1230,11 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst, u32 w, u32 h, struct vmw_diff_cpy *diff); +/* Host messaging -vmwgfx_msg.c: */ +int vmw_host_get_guestinfo (const char *guest_info_param, +char *buffer,size_t *length); +int vmw_host_log (const char *log); +/** * Inline helper functions */
@@ -1309,10 +1314,4 @@ static inline void vmw_mmio_write(u32 value, u32 *addr) {WRITE_ONCE (*addr, value); } - -/** -* Add vmw_msg module function -*/ -extern int vmw_host_log (const char *log); -#endif
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +1 -0
@@ -31,6 +31,7 @@#include <linux/frame.h> #include <asm/hypervisor.h> #include <drm/drmP.h> +#include "vmwgfx_drv.h" #include "vmwgfx_msg.h"
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 15/15 drm/vmwgfx: Remove an obsolete __le32 conversion
In reply to Thomas HellstromWe've long ago given up on enforcing the device format is always little endian, so remove a leftover conversion.
--- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +2 -2
@@ -1072,7 +1072,7 @@ static int vmw_gb_surface_create(struct vmw_resource *res) cmd2->header.size = cmd_len; cmd2->body.sid = srf->res.id; cmd2->body.surfaceFlags = srf->flags; - cmd2->body.format =cpu_to_le32 (srf->format); + cmd2->body.format = srf->format; cmd2->body.numMipLevels = srf->mip_levels[0 ]; cmd2->body.multisampleCount = srf->multisample_count; cmd2->body.autogenFilter = srf->autogen_filter;
@@ -1085,7 +1085,7 @@ static int vmw_gb_surface_create(struct vmw_resource *res) cmd->header.size = cmd_len; cmd->body.sid = srf->res.id; cmd->body.surfaceFlags = srf->flags; - cmd->body.format =cpu_to_le32 (srf->format); + cmd->body.format = srf->format; cmd->body.numMipLevels = srf->mip_levels[0 ]; cmd->body.multisampleCount = srf->multisample_count; cmd->body.autogenFilter = srf->autogen_filter;
Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH -next 05/15] drm/vmwgfx: Fix atomic mode set check
In reply to Thomas HellstromQuoted 54 lines · Thomas Hellstrom
From: Sinclair Yeh <[email protected]>
vmw_kms_atomic_check_modeset()is currently checking config using the legacy state, which is updated after a commit has happened.This means
vmw_kms_atomic_check_modeset()will reject an invalid config on the next update rather than the current one.Fix this by using the new states for config checking
Signed-off-by Sinclair Yeh <[email protected]>Reviewed-by Deepak Rawat <[email protected]>Signed-off-by Thomas Hellstrom <[email protected]>--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 40 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-)drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +13
-10@@ -1526,33 +1526,45 @@ static int vmw_kms_atomic_check_modeset(struct drm_device *dev, struct drm_atomic_state *state) { - struct drm_crtc_state *crtc_state; + struct drm_crtc_state *new_crtc_state; +struct drm_plane_state *new_plane_state; +struct drm_plane *plane;struct drm_crtc *crtc;struct vmw_private *dev_priv =vmw_priv (dev); -int i; +int i, ret, cpp =0 ; -for_each_new_crtc_in_state (state, crtc, crtc_state, i) { -unsigned long requested_bb_mem =0 ; + ret =drm_atomic_helper_check (dev, state); -if (dev_priv->active_display_unit == vmw_du_screen_target) { -struct drm_plane *plane = crtc->primary; -struct drm_plane_state *plane_state; +/* If this is not a STDU, then no more checking is necessary */ +if (ret || dev_priv->active_display_unit != vmw_du_screen_target) +return ret; - plane_state =drm_atomic_get_new_plane_state (state, plane); +for_each_new_plane_in_state (state, plane, new_plane_state, i) { +if (new_plane_state->fb) { +int current_cpp = new_plane_state->fb->pitches[0 ] / + new_plane_state->fb->width; -if (plane_state && plane_state->fb) { -int cpp = plane_state->fb->format->cpp[0 ]; +if (cpp ==0 )
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c static int · line 1554
Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +6
-3+ cpp = current_cpp; + else if (current_cpp != cpp) + return -EINVAL; + } + } - requested_bb_mem += crtc->mode.hdisplay * cpp * - crtc->mode.vdisplay; - } +for_each_new_crtc_in_state (state, crtc, new_crtc_state, i) {
Note that the above too loops only walk over the changed states (by default), not all planes/crtc. You either need to add them yourself (which kinda defeats the point of the per-plane/crtc locks for doing pageflips in parallel). Or you need to track things in a driver private structure (which you'll only grab on modesets) and just update the delta.
I didn't check the entire code to see whether this is a real problem for you, just wanted to point this out.
-Daniel
Quoted 24 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +7
-1+unsigned long requested_bb_mem =0 ; + +if (drm_atomic_crtc_needs_modeset (new_crtc_state)) { + requested_bb_mem += new_crtc_state->mode.hdisplay * + new_crtc_state->mode.vdisplay * + cpp;if (requested_bb_mem > dev_priv->prim_bb_mem)return -EINVAL ; } } -return drm_atomic_helper_check (dev, state); +return ret; }static const struct drm_mode_config_funcs vmw_kms_funcs = {Signature · 6 lines
2.18.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH -next 05/15] drm/vmwgfx: Fix atomic mode set check
Hi,
Quoted 71 lines · Daniel Vetter
Quoted 54 lines · Thomas Hellstrom
From: Sinclair Yeh <[email protected]>
vmw_kms_atomic_check_modeset()is currently checking config using the legacy state, which is updated after a commit has happened.This means
vmw_kms_atomic_check_modeset()will reject an invalid config on the next update rather than the current one.Fix this by using the new states for config checking
Signed-off-by Sinclair Yeh <[email protected]>Reviewed-by Deepak Rawat <[email protected]>Signed-off-by Thomas Hellstrom <[email protected]>--- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 40 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-)drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +13
-10@@ -1526,33 +1526,45 @@ static int vmw_kms_atomic_check_modeset(struct drm_device *dev, struct drm_atomic_state *state) { - struct drm_crtc_state *crtc_state; + struct drm_crtc_state *new_crtc_state; +struct drm_plane_state *new_plane_state; +struct drm_plane *plane;struct drm_crtc *crtc;struct vmw_private *dev_priv =vmw_priv (dev); -int i; +int i, ret, cpp =0 ; -for_each_new_crtc_in_state (state, crtc, crtc_state, i) { -unsigned long requested_bb_mem =0 ; + ret =drm_atomic_helper_check (dev, state); -if (dev_priv->active_display_unit == vmw_du_screen_target) { -struct drm_plane *plane = crtc->primary; -struct drm_plane_state *plane_state; +/* If this is not a STDU, then no more checking is necessary */ +if (ret || dev_priv->active_display_unit != vmw_du_screen_target) +return ret; - plane_state =drm_atomic_get_new_plane_state (state, plane); +for_each_new_plane_in_state (state, plane, new_plane_state, i) { +if (new_plane_state->fb) { +int current_cpp = new_plane_state->fb->pitches[0 ] / + new_plane_state->fb->width; -if (plane_state && plane_state->fb) { -int cpp = plane_state->fb->format->cpp[0 ]; +if (cpp ==0 )drivers/gpu/drm/vmwgfx/vmwgfx_kms.c static int · line 1554
Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +6
-3+ cpp = current_cpp; + else if (current_cpp != cpp) + return -EINVAL; + } + } - requested_bb_mem += crtc->mode.hdisplay * cpp * - crtc->mode.vdisplay; - } +for_each_new_crtc_in_state (state, crtc, new_crtc_state, i) {Note that the above too loops only walk over the changed states (by default), not all planes/crtc. You either need to add them yourself (which kinda defeats the point of the per-plane/crtc locks for doing pageflips in parallel). Or you need to track things in a driver private structure (which you'll only grab on modesets) and just update the delta.
Quoted 3 lines
I didn't check the entire code to see whether this is a real problem for you, just wanted to point this out.
-Daniel
Thanks for pointing this out. This is actually addressed in a later patch by Deepak which chooses the second alternative. We should perhaps have squashed these patches, but keeping track internally becomes easier this way.
/Thomas
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel