vmwgfx: Refactor kms code to use vmw_user_lookup_handle helper

Signed-off-by: Jakob Bornecrantz <jakob@vmware.com>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Jakob Bornecrantz 2011-11-28 13:19:12 +01:00 committed by Dave Airlie
parent 551a6697d0
commit e7ac9211f2

View File

@ -147,24 +147,21 @@ int vmw_du_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
return -EINVAL; return -EINVAL;
if (handle) { if (handle) {
ret = vmw_user_surface_lookup_handle(dev_priv, tfile, ret = vmw_user_lookup_handle(dev_priv, tfile,
handle, &surface); handle, &surface, &dmabuf);
if (!ret) { if (ret) {
if (!surface->snooper.image) { DRM_ERROR("failed to find surface or dmabuf: %i\n", ret);
DRM_ERROR("surface not suitable for cursor\n"); return -EINVAL;
vmw_surface_unreference(&surface);
return -EINVAL;
}
} else {
ret = vmw_user_dmabuf_lookup(tfile,
handle, &dmabuf);
if (ret) {
DRM_ERROR("failed to find surface or dmabuf: %i\n", ret);
return -EINVAL;
}
} }
} }
/* need to do this before taking down old image */
if (surface && !surface->snooper.image) {
DRM_ERROR("surface not suitable for cursor\n");
vmw_surface_unreference(&surface);
return -EINVAL;
}
/* takedown old cursor */ /* takedown old cursor */
if (du->cursor_surface) { if (du->cursor_surface) {
du->cursor_surface->snooper.crtc = NULL; du->cursor_surface->snooper.crtc = NULL;
@ -568,6 +565,10 @@ static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv,
* Sanity checks. * Sanity checks.
*/ */
/* Surface must be marked as a scanout. */
if (unlikely(!surface->scanout))
return -EINVAL;
if (unlikely(surface->mip_levels[0] != 1 || if (unlikely(surface->mip_levels[0] != 1 ||
surface->num_sizes != 1 || surface->num_sizes != 1 ||
surface->sizes[0].width < mode_cmd->width || surface->sizes[0].width < mode_cmd->width ||
@ -1045,46 +1046,29 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
/** /* returns either a dmabuf or surface */
* End conditioned code. ret = vmw_user_lookup_handle(dev_priv, tfile,
*/ mode_cmd->handle,
&surface, &bo);
ret = vmw_user_surface_lookup_handle(dev_priv, tfile,
mode_cmd->handle, &surface);
if (ret) if (ret)
goto try_dmabuf; goto err_out;
if (!surface->scanout) /* Create the new framebuffer depending one what we got back */
goto err_not_scanout; if (bo)
ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, bo, &vfb,
mode_cmd);
else if (surface)
ret = vmw_kms_new_framebuffer_surface(dev_priv, file_priv,
surface, &vfb, mode_cmd);
else
BUG();
ret = vmw_kms_new_framebuffer_surface(dev_priv, file_priv, surface, err_out:
&vfb, mode_cmd); /* vmw_user_lookup_handle takes one ref so does new_fb */
if (bo)
/* vmw_user_surface_lookup takes one ref so does new_fb */ vmw_dmabuf_unreference(&bo);
vmw_surface_unreference(&surface); if (surface)
vmw_surface_unreference(&surface);
if (ret) {
DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret);
ttm_base_object_unref(&user_obj);
return ERR_PTR(ret);
} else
vfb->user_obj = user_obj;
return &vfb->base;
try_dmabuf:
DRM_INFO("%s: trying buffer\n", __func__);
ret = vmw_user_dmabuf_lookup(tfile, mode_cmd->handle, &bo);
if (ret) {
DRM_ERROR("failed to find buffer: %i\n", ret);
return ERR_PTR(-ENOENT);
}
ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, bo, &vfb,
mode_cmd);
/* vmw_user_dmabuf_lookup takes one ref so does new_fb */
vmw_dmabuf_unreference(&bo);
if (ret) { if (ret) {
DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret); DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret);
@ -1094,14 +1078,6 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
vfb->user_obj = user_obj; vfb->user_obj = user_obj;
return &vfb->base; return &vfb->base;
err_not_scanout:
DRM_ERROR("surface not marked as scanout\n");
/* vmw_user_surface_lookup takes one ref */
vmw_surface_unreference(&surface);
ttm_base_object_unref(&user_obj);
return ERR_PTR(-EINVAL);
} }
static struct drm_mode_config_funcs vmw_kms_funcs = { static struct drm_mode_config_funcs vmw_kms_funcs = {