2018-05-07 06:16:26 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0 OR MIT
|
2009-12-10 07:19:58 +07:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2018-05-07 06:16:26 +07:00
|
|
|
* Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
|
2009-12-10 07:19:58 +07:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "vmwgfx_drv.h"
|
2012-10-03 00:01:07 +07:00
|
|
|
#include <drm/vmwgfx_drm.h>
|
2011-10-05 01:13:26 +07:00
|
|
|
#include "vmwgfx_kms.h"
|
2015-07-09 11:20:39 +07:00
|
|
|
#include "device_include/svga3d_caps.h"
|
2009-12-10 07:19:58 +07:00
|
|
|
|
2014-01-31 16:21:10 +07:00
|
|
|
struct svga_3d_compat_cap {
|
|
|
|
SVGA3dCapsRecordHeader header;
|
|
|
|
SVGA3dCapPair pairs[SVGA3D_DEVCAP_MAX];
|
|
|
|
};
|
|
|
|
|
2009-12-10 07:19:58 +07:00
|
|
|
int vmw_getparam_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
|
|
|
{
|
|
|
|
struct vmw_private *dev_priv = vmw_priv(dev);
|
|
|
|
struct drm_vmw_getparam_arg *param =
|
|
|
|
(struct drm_vmw_getparam_arg *)data;
|
2014-01-31 16:21:10 +07:00
|
|
|
struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
|
2009-12-10 07:19:58 +07:00
|
|
|
|
|
|
|
switch (param->param) {
|
|
|
|
case DRM_VMW_PARAM_NUM_STREAMS:
|
|
|
|
param->value = vmw_overlay_num_overlays(dev_priv);
|
|
|
|
break;
|
|
|
|
case DRM_VMW_PARAM_NUM_FREE_STREAMS:
|
|
|
|
param->value = vmw_overlay_num_free_overlays(dev_priv);
|
|
|
|
break;
|
|
|
|
case DRM_VMW_PARAM_3D:
|
2010-01-30 10:38:06 +07:00
|
|
|
param->value = vmw_fifo_have_3d(dev_priv) ? 1 : 0;
|
2009-12-10 07:19:58 +07:00
|
|
|
break;
|
2010-02-10 02:41:55 +07:00
|
|
|
case DRM_VMW_PARAM_HW_CAPS:
|
|
|
|
param->value = dev_priv->capabilities;
|
|
|
|
break;
|
2018-06-19 06:44:48 +07:00
|
|
|
case DRM_VMW_PARAM_HW_CAPS2:
|
|
|
|
param->value = dev_priv->capabilities2;
|
|
|
|
break;
|
2010-02-10 02:41:55 +07:00
|
|
|
case DRM_VMW_PARAM_FIFO_CAPS:
|
|
|
|
param->value = dev_priv->fifo.capabilities;
|
|
|
|
break;
|
2010-10-05 17:43:06 +07:00
|
|
|
case DRM_VMW_PARAM_MAX_FB_SIZE:
|
2012-11-21 16:32:36 +07:00
|
|
|
param->value = dev_priv->prim_bb_mem;
|
2010-10-05 17:43:06 +07:00
|
|
|
break;
|
2011-09-02 03:18:41 +07:00
|
|
|
case DRM_VMW_PARAM_FIFO_HW_VERSION:
|
|
|
|
{
|
2015-10-28 16:44:04 +07:00
|
|
|
u32 *fifo_mem = dev_priv->mmio_virt;
|
2011-11-28 19:19:08 +07:00
|
|
|
const struct vmw_fifo_state *fifo = &dev_priv->fifo;
|
2011-09-02 03:18:41 +07:00
|
|
|
|
2014-01-31 16:21:10 +07:00
|
|
|
if ((dev_priv->capabilities & SVGA_CAP_GBOBJECTS)) {
|
|
|
|
param->value = SVGA3D_HWVERSION_WS8_B1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-28 19:19:08 +07:00
|
|
|
param->value =
|
2015-10-28 16:44:04 +07:00
|
|
|
vmw_mmio_read(fifo_mem +
|
|
|
|
((fifo->capabilities &
|
|
|
|
SVGA_FIFO_CAP_3D_HWVERSION_REVISED) ?
|
|
|
|
SVGA_FIFO_3D_HWVERSION_REVISED :
|
|
|
|
SVGA_FIFO_3D_HWVERSION));
|
2011-09-02 03:18:41 +07:00
|
|
|
break;
|
|
|
|
}
|
2012-11-21 16:37:20 +07:00
|
|
|
case DRM_VMW_PARAM_MAX_SURF_MEMORY:
|
2014-01-31 16:21:10 +07:00
|
|
|
if ((dev_priv->capabilities & SVGA_CAP_GBOBJECTS) &&
|
|
|
|
!vmw_fp->gb_aware)
|
|
|
|
param->value = dev_priv->max_mob_pages * PAGE_SIZE / 2;
|
|
|
|
else
|
|
|
|
param->value = dev_priv->memory_size;
|
2012-11-21 16:37:20 +07:00
|
|
|
break;
|
|
|
|
case DRM_VMW_PARAM_3D_CAPS_SIZE:
|
2014-01-31 16:21:10 +07:00
|
|
|
if ((dev_priv->capabilities & SVGA_CAP_GBOBJECTS) &&
|
|
|
|
vmw_fp->gb_aware)
|
|
|
|
param->value = SVGA3D_DEVCAP_MAX * sizeof(uint32_t);
|
|
|
|
else if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS)
|
|
|
|
param->value = sizeof(struct svga_3d_compat_cap) +
|
|
|
|
sizeof(uint32_t);
|
2012-11-21 16:37:20 +07:00
|
|
|
else
|
|
|
|
param->value = (SVGA_FIFO_3D_CAPS_LAST -
|
2014-01-31 16:21:10 +07:00
|
|
|
SVGA_FIFO_3D_CAPS + 1) *
|
|
|
|
sizeof(uint32_t);
|
2012-11-21 16:37:20 +07:00
|
|
|
break;
|
2012-11-21 18:34:47 +07:00
|
|
|
case DRM_VMW_PARAM_MAX_MOB_MEMORY:
|
2014-01-31 16:21:10 +07:00
|
|
|
vmw_fp->gb_aware = true;
|
2012-11-21 18:34:47 +07:00
|
|
|
param->value = dev_priv->max_mob_pages * PAGE_SIZE;
|
|
|
|
break;
|
2014-02-12 18:07:38 +07:00
|
|
|
case DRM_VMW_PARAM_MAX_MOB_SIZE:
|
|
|
|
param->value = dev_priv->max_mob_size;
|
|
|
|
break;
|
2015-06-26 15:42:06 +07:00
|
|
|
case DRM_VMW_PARAM_SCREEN_TARGET:
|
|
|
|
param->value =
|
|
|
|
(dev_priv->active_display_unit == vmw_du_screen_target);
|
|
|
|
break;
|
2015-08-11 00:39:35 +07:00
|
|
|
case DRM_VMW_PARAM_DX:
|
|
|
|
param->value = dev_priv->has_dx;
|
|
|
|
break;
|
2018-06-21 05:09:43 +07:00
|
|
|
case DRM_VMW_PARAM_SM4_1:
|
|
|
|
param->value = dev_priv->has_sm4_1;
|
|
|
|
break;
|
2009-12-10 07:19:58 +07:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-09-02 03:18:41 +07:00
|
|
|
|
2015-10-26 18:42:31 +07:00
|
|
|
static u32 vmw_mask_multisample(unsigned int cap, u32 fmt_value)
|
|
|
|
{
|
2018-06-14 03:53:28 +07:00
|
|
|
/*
|
|
|
|
* A version of user-space exists which use MULTISAMPLE_MASKABLESAMPLES
|
|
|
|
* to check the sample count supported by virtual device. Since there
|
|
|
|
* never was support for multisample count for backing MOB return 0.
|
|
|
|
*/
|
|
|
|
if (cap == SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES)
|
2015-10-26 18:42:31 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return fmt_value;
|
|
|
|
}
|
|
|
|
|
2014-01-31 16:21:10 +07:00
|
|
|
static int vmw_fill_compat_cap(struct vmw_private *dev_priv, void *bounce,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
struct svga_3d_compat_cap *compat_cap =
|
|
|
|
(struct svga_3d_compat_cap *) bounce;
|
|
|
|
unsigned int i;
|
|
|
|
size_t pair_offset = offsetof(struct svga_3d_compat_cap, pairs);
|
|
|
|
unsigned int max_size;
|
|
|
|
|
|
|
|
if (size < pair_offset)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
max_size = (size - pair_offset) / sizeof(SVGA3dCapPair);
|
|
|
|
|
|
|
|
if (max_size > SVGA3D_DEVCAP_MAX)
|
|
|
|
max_size = SVGA3D_DEVCAP_MAX;
|
|
|
|
|
|
|
|
compat_cap->header.length =
|
|
|
|
(pair_offset + max_size * sizeof(SVGA3dCapPair)) / sizeof(u32);
|
|
|
|
compat_cap->header.type = SVGA3DCAPS_RECORD_DEVCAPS;
|
|
|
|
|
2015-01-14 17:33:39 +07:00
|
|
|
spin_lock(&dev_priv->cap_lock);
|
2014-01-31 16:21:10 +07:00
|
|
|
for (i = 0; i < max_size; ++i) {
|
|
|
|
vmw_write(dev_priv, SVGA_REG_DEV_CAP, i);
|
|
|
|
compat_cap->pairs[i][0] = i;
|
2015-10-26 18:42:31 +07:00
|
|
|
compat_cap->pairs[i][1] = vmw_mask_multisample
|
|
|
|
(i, vmw_read(dev_priv, SVGA_REG_DEV_CAP));
|
2014-01-31 16:21:10 +07:00
|
|
|
}
|
2015-01-14 17:33:39 +07:00
|
|
|
spin_unlock(&dev_priv->cap_lock);
|
2014-01-31 16:21:10 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-02 03:18:41 +07:00
|
|
|
|
|
|
|
int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
|
|
|
{
|
|
|
|
struct drm_vmw_get_3d_cap_arg *arg =
|
|
|
|
(struct drm_vmw_get_3d_cap_arg *) data;
|
|
|
|
struct vmw_private *dev_priv = vmw_priv(dev);
|
|
|
|
uint32_t size;
|
2015-10-28 16:44:04 +07:00
|
|
|
u32 *fifo_mem;
|
2011-09-02 03:18:41 +07:00
|
|
|
void __user *buffer = (void __user *)((unsigned long)(arg->buffer));
|
|
|
|
void *bounce;
|
|
|
|
int ret;
|
2012-11-21 16:37:20 +07:00
|
|
|
bool gb_objects = !!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS);
|
2014-01-31 16:21:10 +07:00
|
|
|
struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
|
2011-09-02 03:18:41 +07:00
|
|
|
|
2017-03-27 16:15:12 +07:00
|
|
|
if (unlikely(arg->pad64 != 0 || arg->max_size == 0)) {
|
2019-02-12 02:46:27 +07:00
|
|
|
VMW_DEBUG_USER("Illegal GET_3D_CAP argument.\n");
|
2011-09-02 03:18:41 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-01-31 16:21:10 +07:00
|
|
|
if (gb_objects && vmw_fp->gb_aware)
|
|
|
|
size = SVGA3D_DEVCAP_MAX * sizeof(uint32_t);
|
|
|
|
else if (gb_objects)
|
|
|
|
size = sizeof(struct svga_3d_compat_cap) + sizeof(uint32_t);
|
2012-11-21 16:37:20 +07:00
|
|
|
else
|
2014-01-31 16:21:10 +07:00
|
|
|
size = (SVGA_FIFO_3D_CAPS_LAST - SVGA_FIFO_3D_CAPS + 1) *
|
|
|
|
sizeof(uint32_t);
|
2011-09-02 03:18:41 +07:00
|
|
|
|
|
|
|
if (arg->max_size < size)
|
|
|
|
size = arg->max_size;
|
|
|
|
|
2014-01-31 16:21:10 +07:00
|
|
|
bounce = vzalloc(size);
|
2011-09-02 03:18:41 +07:00
|
|
|
if (unlikely(bounce == NULL)) {
|
|
|
|
DRM_ERROR("Failed to allocate bounce buffer for 3D caps.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2014-01-31 16:21:10 +07:00
|
|
|
if (gb_objects && vmw_fp->gb_aware) {
|
|
|
|
int i, num;
|
2012-11-21 16:37:20 +07:00
|
|
|
uint32_t *bounce32 = (uint32_t *) bounce;
|
|
|
|
|
2014-01-31 16:21:10 +07:00
|
|
|
num = size / sizeof(uint32_t);
|
2015-08-11 00:45:11 +07:00
|
|
|
if (num > SVGA3D_DEVCAP_MAX)
|
|
|
|
num = SVGA3D_DEVCAP_MAX;
|
2014-01-31 16:21:10 +07:00
|
|
|
|
2015-01-14 17:33:39 +07:00
|
|
|
spin_lock(&dev_priv->cap_lock);
|
2014-01-31 16:21:10 +07:00
|
|
|
for (i = 0; i < num; ++i) {
|
2012-11-21 16:37:20 +07:00
|
|
|
vmw_write(dev_priv, SVGA_REG_DEV_CAP, i);
|
2015-10-26 18:42:31 +07:00
|
|
|
*bounce32++ = vmw_mask_multisample
|
|
|
|
(i, vmw_read(dev_priv, SVGA_REG_DEV_CAP));
|
2012-11-21 16:37:20 +07:00
|
|
|
}
|
2015-01-14 17:33:39 +07:00
|
|
|
spin_unlock(&dev_priv->cap_lock);
|
2014-01-31 16:21:10 +07:00
|
|
|
} else if (gb_objects) {
|
|
|
|
ret = vmw_fill_compat_cap(dev_priv, bounce, size);
|
|
|
|
if (unlikely(ret != 0))
|
|
|
|
goto out_err;
|
2012-11-21 16:37:20 +07:00
|
|
|
} else {
|
|
|
|
fifo_mem = dev_priv->mmio_virt;
|
2015-10-28 16:44:04 +07:00
|
|
|
memcpy(bounce, &fifo_mem[SVGA_FIFO_3D_CAPS], size);
|
2012-11-21 16:37:20 +07:00
|
|
|
}
|
2011-09-02 03:18:41 +07:00
|
|
|
|
|
|
|
ret = copy_to_user(buffer, bounce, size);
|
2012-11-12 18:07:24 +07:00
|
|
|
if (ret)
|
|
|
|
ret = -EFAULT;
|
2014-01-31 16:21:10 +07:00
|
|
|
out_err:
|
2011-09-02 03:18:41 +07:00
|
|
|
vfree(bounce);
|
|
|
|
|
|
|
|
if (unlikely(ret != 0))
|
|
|
|
DRM_ERROR("Failed to report 3D caps info.\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2011-10-05 01:13:26 +07:00
|
|
|
|
|
|
|
int vmw_present_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
|
|
|
{
|
|
|
|
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
|
|
|
|
struct vmw_private *dev_priv = vmw_priv(dev);
|
|
|
|
struct drm_vmw_present_arg *arg =
|
|
|
|
(struct drm_vmw_present_arg *)data;
|
|
|
|
struct vmw_surface *surface;
|
|
|
|
struct drm_vmw_rect __user *clips_ptr;
|
|
|
|
struct drm_vmw_rect *clips = NULL;
|
2012-12-03 03:53:40 +07:00
|
|
|
struct drm_framebuffer *fb;
|
2011-10-05 01:13:26 +07:00
|
|
|
struct vmw_framebuffer *vfb;
|
2012-11-20 19:19:35 +07:00
|
|
|
struct vmw_resource *res;
|
2011-10-05 01:13:26 +07:00
|
|
|
uint32_t num_clips;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
num_clips = arg->num_clips;
|
2015-04-02 16:39:45 +07:00
|
|
|
clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
|
2011-10-05 01:13:26 +07:00
|
|
|
|
|
|
|
if (unlikely(num_clips == 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (clips_ptr == NULL) {
|
2019-02-12 02:46:27 +07:00
|
|
|
VMW_DEBUG_USER("Variable clips_ptr must be specified.\n");
|
2011-10-05 01:13:26 +07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_clips;
|
|
|
|
}
|
|
|
|
|
2011-11-30 04:08:00 +07:00
|
|
|
clips = kcalloc(num_clips, sizeof(*clips), GFP_KERNEL);
|
2011-10-05 01:13:26 +07:00
|
|
|
if (clips == NULL) {
|
|
|
|
DRM_ERROR("Failed to allocate clip rect list.\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_clips;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = copy_from_user(clips, clips_ptr, num_clips * sizeof(*clips));
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("Failed to copy clip rects from userspace.\n");
|
2011-10-18 13:09:19 +07:00
|
|
|
ret = -EFAULT;
|
2011-10-05 01:13:26 +07:00
|
|
|
goto out_no_copy;
|
|
|
|
}
|
|
|
|
|
2012-12-02 07:48:38 +07:00
|
|
|
drm_modeset_lock_all(dev);
|
2011-10-05 01:13:26 +07:00
|
|
|
|
2017-03-15 13:25:07 +07:00
|
|
|
fb = drm_framebuffer_lookup(dev, file_priv, arg->fb_id);
|
2012-12-03 03:53:40 +07:00
|
|
|
if (!fb) {
|
2019-02-12 02:46:27 +07:00
|
|
|
VMW_DEBUG_USER("Invalid framebuffer id.\n");
|
2013-10-17 17:35:06 +07:00
|
|
|
ret = -ENOENT;
|
2011-10-05 01:13:26 +07:00
|
|
|
goto out_no_fb;
|
|
|
|
}
|
2012-12-03 03:53:40 +07:00
|
|
|
vfb = vmw_framebuffer_to_vfb(fb);
|
2011-10-05 01:13:26 +07:00
|
|
|
|
2014-02-27 18:34:51 +07:00
|
|
|
ret = ttm_read_lock(&dev_priv->reservation_sem, true);
|
2011-10-05 01:13:26 +07:00
|
|
|
if (unlikely(ret != 0))
|
|
|
|
goto out_no_ttm_lock;
|
|
|
|
|
2012-11-20 19:19:35 +07:00
|
|
|
ret = vmw_user_resource_lookup_handle(dev_priv, tfile, arg->sid,
|
|
|
|
user_surface_converter,
|
|
|
|
&res);
|
2011-10-05 01:13:26 +07:00
|
|
|
if (ret)
|
|
|
|
goto out_no_surface;
|
|
|
|
|
2012-11-20 19:19:35 +07:00
|
|
|
surface = vmw_res_to_srf(res);
|
2011-10-05 01:13:26 +07:00
|
|
|
ret = vmw_kms_present(dev_priv, file_priv,
|
|
|
|
vfb, surface, arg->sid,
|
|
|
|
arg->dest_x, arg->dest_y,
|
|
|
|
clips, num_clips);
|
|
|
|
|
|
|
|
/* vmw_user_surface_lookup takes one ref so does new_fb */
|
|
|
|
vmw_surface_unreference(&surface);
|
|
|
|
|
|
|
|
out_no_surface:
|
2014-02-27 18:34:51 +07:00
|
|
|
ttm_read_unlock(&dev_priv->reservation_sem);
|
2011-10-05 01:13:26 +07:00
|
|
|
out_no_ttm_lock:
|
2018-03-12 06:33:13 +07:00
|
|
|
drm_framebuffer_put(fb);
|
2011-10-05 01:13:26 +07:00
|
|
|
out_no_fb:
|
2012-12-02 07:48:38 +07:00
|
|
|
drm_modeset_unlock_all(dev);
|
2011-10-05 01:13:26 +07:00
|
|
|
out_no_copy:
|
|
|
|
kfree(clips);
|
|
|
|
out_clips:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
|
|
|
{
|
|
|
|
struct vmw_private *dev_priv = vmw_priv(dev);
|
|
|
|
struct drm_vmw_present_readback_arg *arg =
|
|
|
|
(struct drm_vmw_present_readback_arg *)data;
|
|
|
|
struct drm_vmw_fence_rep __user *user_fence_rep =
|
|
|
|
(struct drm_vmw_fence_rep __user *)
|
|
|
|
(unsigned long)arg->fence_rep;
|
|
|
|
struct drm_vmw_rect __user *clips_ptr;
|
|
|
|
struct drm_vmw_rect *clips = NULL;
|
2012-12-03 03:53:40 +07:00
|
|
|
struct drm_framebuffer *fb;
|
2011-10-05 01:13:26 +07:00
|
|
|
struct vmw_framebuffer *vfb;
|
|
|
|
uint32_t num_clips;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
num_clips = arg->num_clips;
|
2015-04-02 16:39:45 +07:00
|
|
|
clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
|
2011-10-05 01:13:26 +07:00
|
|
|
|
|
|
|
if (unlikely(num_clips == 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (clips_ptr == NULL) {
|
2019-02-12 02:46:27 +07:00
|
|
|
VMW_DEBUG_USER("Argument clips_ptr must be specified.\n");
|
2011-10-05 01:13:26 +07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_clips;
|
|
|
|
}
|
|
|
|
|
2011-11-30 04:08:00 +07:00
|
|
|
clips = kcalloc(num_clips, sizeof(*clips), GFP_KERNEL);
|
2011-10-05 01:13:26 +07:00
|
|
|
if (clips == NULL) {
|
|
|
|
DRM_ERROR("Failed to allocate clip rect list.\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_clips;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = copy_from_user(clips, clips_ptr, num_clips * sizeof(*clips));
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("Failed to copy clip rects from userspace.\n");
|
2011-10-18 13:09:19 +07:00
|
|
|
ret = -EFAULT;
|
2011-10-05 01:13:26 +07:00
|
|
|
goto out_no_copy;
|
|
|
|
}
|
|
|
|
|
2012-12-02 07:48:38 +07:00
|
|
|
drm_modeset_lock_all(dev);
|
2011-10-05 01:13:26 +07:00
|
|
|
|
2017-03-15 13:25:07 +07:00
|
|
|
fb = drm_framebuffer_lookup(dev, file_priv, arg->fb_id);
|
2012-12-03 03:53:40 +07:00
|
|
|
if (!fb) {
|
2019-02-12 02:46:27 +07:00
|
|
|
VMW_DEBUG_USER("Invalid framebuffer id.\n");
|
2013-10-17 17:35:06 +07:00
|
|
|
ret = -ENOENT;
|
2011-10-05 01:13:26 +07:00
|
|
|
goto out_no_fb;
|
|
|
|
}
|
|
|
|
|
2012-12-03 03:53:40 +07:00
|
|
|
vfb = vmw_framebuffer_to_vfb(fb);
|
2018-06-19 20:02:16 +07:00
|
|
|
if (!vfb->bo) {
|
2019-02-12 02:46:27 +07:00
|
|
|
VMW_DEBUG_USER("Framebuffer not buffer backed.\n");
|
2011-10-05 01:13:26 +07:00
|
|
|
ret = -EINVAL;
|
2012-12-11 22:28:34 +07:00
|
|
|
goto out_no_ttm_lock;
|
2011-10-05 01:13:26 +07:00
|
|
|
}
|
|
|
|
|
2014-02-27 18:34:51 +07:00
|
|
|
ret = ttm_read_lock(&dev_priv->reservation_sem, true);
|
2011-10-05 01:13:26 +07:00
|
|
|
if (unlikely(ret != 0))
|
|
|
|
goto out_no_ttm_lock;
|
|
|
|
|
|
|
|
ret = vmw_kms_readback(dev_priv, file_priv,
|
|
|
|
vfb, user_fence_rep,
|
|
|
|
clips, num_clips);
|
|
|
|
|
2014-02-27 18:34:51 +07:00
|
|
|
ttm_read_unlock(&dev_priv->reservation_sem);
|
2011-10-05 01:13:26 +07:00
|
|
|
out_no_ttm_lock:
|
2018-03-12 06:33:13 +07:00
|
|
|
drm_framebuffer_put(fb);
|
2011-10-05 01:13:26 +07:00
|
|
|
out_no_fb:
|
2012-12-02 07:48:38 +07:00
|
|
|
drm_modeset_unlock_all(dev);
|
2011-10-05 01:13:26 +07:00
|
|
|
out_no_copy:
|
|
|
|
kfree(clips);
|
|
|
|
out_clips:
|
|
|
|
return ret;
|
|
|
|
}
|
2011-10-10 17:23:27 +07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vmw_fops_poll - wrapper around the drm_poll function
|
|
|
|
*
|
|
|
|
* @filp: See the linux fops poll documentation.
|
|
|
|
* @wait: See the linux fops poll documentation.
|
|
|
|
*
|
|
|
|
* Wrapper around the drm_poll function that makes sure the device is
|
|
|
|
* processing the fifo if drm_poll decides to wait.
|
|
|
|
*/
|
2017-07-03 17:39:46 +07:00
|
|
|
__poll_t vmw_fops_poll(struct file *filp, struct poll_table_struct *wait)
|
2011-10-10 17:23:27 +07:00
|
|
|
{
|
|
|
|
struct drm_file *file_priv = filp->private_data;
|
|
|
|
struct vmw_private *dev_priv =
|
|
|
|
vmw_priv(file_priv->minor->dev);
|
|
|
|
|
|
|
|
vmw_fifo_ping_host(dev_priv, SVGA_SYNC_GENERIC);
|
|
|
|
return drm_poll(filp, wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vmw_fops_read - wrapper around the drm_read function
|
|
|
|
*
|
|
|
|
* @filp: See the linux fops read documentation.
|
|
|
|
* @buffer: See the linux fops read documentation.
|
|
|
|
* @count: See the linux fops read documentation.
|
|
|
|
* offset: See the linux fops read documentation.
|
|
|
|
*
|
|
|
|
* Wrapper around the drm_read function that makes sure the device is
|
|
|
|
* processing the fifo if drm_read decides to wait.
|
|
|
|
*/
|
|
|
|
ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
|
|
|
|
size_t count, loff_t *offset)
|
|
|
|
{
|
|
|
|
struct drm_file *file_priv = filp->private_data;
|
|
|
|
struct vmw_private *dev_priv =
|
|
|
|
vmw_priv(file_priv->minor->dev);
|
|
|
|
|
|
|
|
vmw_fifo_ping_host(dev_priv, SVGA_SYNC_GENERIC);
|
|
|
|
return drm_read(filp, buffer, count, offset);
|
|
|
|
}
|