/** * vmw_stdu_bind_fb - Bind an fb to a defined screen target * * @dev_priv: Pointer to a device private struct. * @crtc: The crtc holding the screen target. * @mode: The mode currently used by the screen target. Must be non-NULL. * @new_fb: The new framebuffer to bind. Must be non-NULL. * * RETURNS: * 0 on success, error code on failure. */ static int vmw_stdu_bind_fb(struct vmw_private *dev_priv, struct drm_crtc *crtc, struct drm_display_mode *mode, struct drm_framebuffer *new_fb) { struct vmw_screen_target_display_unit *stdu = vmw_crtc_to_stdu(crtc); struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(new_fb); struct vmw_surface *new_display_srf = NULL; enum stdu_content_type new_content_type; struct vmw_framebuffer_surface *new_vfbs; int ret; WARN_ON_ONCE(!stdu->defined); new_vfbs = (vfb->dmabuf) ? NULL : vmw_framebuffer_to_vfbs(new_fb); if (new_vfbs && new_vfbs->surface->base_size.width == mode->hdisplay && new_vfbs->surface->base_size.height == mode->vdisplay) new_content_type = SAME_AS_DISPLAY; else if (vfb->dmabuf) new_content_type = SEPARATE_DMA; else new_content_type = SEPARATE_SURFACE; if (new_content_type != SAME_AS_DISPLAY && !stdu->display_srf) { struct vmw_surface content_srf; struct drm_vmw_size display_base_size = {0}; display_base_size.width = mode->hdisplay; display_base_size.height = mode->vdisplay; display_base_size.depth = 1; /* * If content buffer is a DMA buf, then we have to construct * surface info */ if (new_content_type == SEPARATE_DMA) { switch (new_fb->bits_per_pixel) { case 32: content_srf.format = SVGA3D_X8R8G8B8; break; case 16: content_srf.format = SVGA3D_R5G6B5; break; case 8: content_srf.format = SVGA3D_P8; break; default: DRM_ERROR("Invalid format\n"); return -EINVAL; } content_srf.flags = 0; content_srf.mip_levels[0] = 1; content_srf.multisample_count = 0; } else { content_srf = *new_vfbs->surface; } ret = vmw_surface_gb_priv_define(crtc->dev, 0, /* because kernel visible only */ content_srf.flags, content_srf.format, true, /* a scanout buffer */ content_srf.mip_levels[0], content_srf.multisample_count, 0, display_base_size, &new_display_srf); if (unlikely(ret != 0)) { DRM_ERROR("Could not allocate screen target surface.\n"); return ret; } } else if (new_content_type == SAME_AS_DISPLAY) { new_display_srf = vmw_surface_reference(new_vfbs->surface); } if (new_display_srf) { /* Pin new surface before flipping */ ret = vmw_resource_pin(&new_display_srf->res, false); if (ret) goto out_srf_unref; ret = vmw_stdu_bind_st(dev_priv, stdu, &new_display_srf->res); if (ret) goto out_srf_unpin; /* Unpin and unreference old surface */ vmw_stdu_unpin_display(stdu); /* Transfer the reference */ stdu->display_srf = new_display_srf; new_display_srf = NULL; } crtc->primary->fb = new_fb; stdu->content_fb_type = new_content_type; return 0; out_srf_unpin: vmw_resource_unpin(&new_display_srf->res); out_srf_unref: vmw_surface_unreference(&new_display_srf); return ret; }
/** * vmw_stdu_pin_display - pins the resource associated with the display surface * * @stdu: contains the display surface * * Since the display surface can either be a private surface allocated by us, * or it can point to the content surface, we use this function to not pin the * same resource twice. */ static int vmw_stdu_pin_display(struct vmw_screen_target_display_unit *stdu) { return vmw_resource_pin(&stdu->display_srf->res, false); }