Commit 7558ab66 authored by Dave Airlie's avatar Dave Airlie

Merge branch 'drm-vmwgfx-next' of git://people.freedesktop.org/~syeh/repos_linux into drm-next

This series enables atomic mode set for vmwgfx.  A number of features and
larger fixes are also included.

* 'drm-vmwgfx-next' of git://people.freedesktop.org/~syeh/repos_linux: (22 commits)
  drm/vmwgfx: Properly check display/scanout surface size
  drm/vmwgfx: Support topology greater than texture size
  drm/vmwgfx: Define an overlaid handle_close ioctl.
  drm/vmwgfx: Re-implement the stream resource as a simple resource.
  drm/vmwgfx: Introduce a simple resource type
  drm/vmwgfx: Revert "drm/vmwgfx: Replace numeric parameter like 0444 with macro"
  drm/vmwgfx: Fix LDU X blank screen until mode change issue
  drm/vmwgfx: Skipping fbdev fb pinning for ldu
  drm/vmwgfx: Explicityly track screen target width and height
  drm/vmwgfx: Turn on DRIVER_ATOMIC flag
  drm/vmwgfx: Switch over to internal atomic API for SOU and LDU
  drm/vmwgfx: Switch over to internal atomic API for STDU
  drm/vmwgfx: Fixes to vmwgfx_fb
  drm/vmwgfx: Add and connect atomic state object check/commit
  drm/vmwgfx: Add and connect connector helper function
  drm/vmwgfx: Add and connect plane helper functions
  drm/vmwgfx: Add and connect CRTC helper functions
  drm/vmwgfx: Connector atomic state
  drm/vmwgfx: Plane atomic state
  drm/vmwgfx: CRTC atomic state
  ...
parents 8cd3ac52 28c95429
......@@ -8,6 +8,7 @@ vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o vmwgfx_drv.o \
vmwgfx_fence.o vmwgfx_dmabuf.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
vmwgfx_cotable.o vmwgfx_so.o vmwgfx_binding.o vmwgfx_msg.o \
vmwgfx_simple_resource.o vmwgfx_va.o
obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o
......@@ -246,13 +246,13 @@ static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
void *ptr);
MODULE_PARM_DESC(enable_fbdev, "Enable vmwgfx fbdev");
module_param_named(enable_fbdev, enable_fbdev, int, S_IRUSR | S_IWUSR);
module_param_named(enable_fbdev, enable_fbdev, int, 0600);
MODULE_PARM_DESC(force_dma_api, "Force using the DMA API for TTM pages");
module_param_named(force_dma_api, vmw_force_iommu, int, S_IRUSR | S_IWUSR);
module_param_named(force_dma_api, vmw_force_iommu, int, 0600);
MODULE_PARM_DESC(restrict_iommu, "Try to limit IOMMU usage for TTM pages");
module_param_named(restrict_iommu, vmw_restrict_iommu, int, S_IRUSR | S_IWUSR);
module_param_named(restrict_iommu, vmw_restrict_iommu, int, 0600);
MODULE_PARM_DESC(force_coherent, "Force coherent TTM pages");
module_param_named(force_coherent, vmw_force_coherent, int, S_IRUSR | S_IWUSR);
module_param_named(force_coherent, vmw_force_coherent, int, 0600);
MODULE_PARM_DESC(restrict_dma_mask, "Restrict DMA mask to 44 bits with IOMMU");
module_param_named(restrict_dma_mask, vmw_restrict_dma_mask, int, S_IRUSR | S_IWUSR);
MODULE_PARM_DESC(assume_16bpp, "Assume 16-bpp when filtering modes");
......@@ -650,6 +650,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
spin_lock_init(&dev_priv->waiter_lock);
spin_lock_init(&dev_priv->cap_lock);
spin_lock_init(&dev_priv->svga_lock);
spin_lock_init(&dev_priv->cursor_lock);
for (i = vmw_res_context; i < vmw_res_max; ++i) {
idr_init(&dev_priv->res_idr[i]);
......@@ -897,6 +898,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
goto out_no_fifo;
DRM_INFO("DX: %s\n", dev_priv->has_dx ? "yes." : "no.");
DRM_INFO("Atomic: %s\n",
(dev->driver->driver_features & DRIVER_ATOMIC) ? "yes" : "no");
snprintf(host_log, sizeof(host_log), "vmwgfx: %s-%s",
VMWGFX_REPO, VMWGFX_GIT_VERSION);
......@@ -1509,7 +1512,7 @@ static const struct file_operations vmwgfx_driver_fops = {
static struct drm_driver driver = {
.driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
DRIVER_MODESET | DRIVER_PRIME | DRIVER_RENDER,
DRIVER_MODESET | DRIVER_PRIME | DRIVER_RENDER | DRIVER_ATOMIC,
.load = vmw_driver_load,
.unload = vmw_driver_unload,
.lastclose = vmw_lastclose,
......
......@@ -153,7 +153,6 @@ enum vmw_cmdbuf_res_type {
struct vmw_cmdbuf_res_manager;
struct vmw_cursor_snooper {
struct drm_crtc *crtc;
size_t age;
uint32_t *image;
};
......@@ -415,6 +414,7 @@ struct vmw_private {
unsigned num_implicit;
struct vmw_framebuffer *implicit_fb;
struct mutex global_kms_state_mutex;
spinlock_t cursor_lock;
/*
* Context and surface management.
......
......@@ -434,7 +434,7 @@ static int vmw_fb_kms_detach(struct vmw_fb_par *par,
set.y = 0;
set.mode = NULL;
set.fb = NULL;
set.num_connectors = 1;
set.num_connectors = 0;
set.connectors = &par->con;
ret = drm_mode_set_config_internal(&set);
if (ret) {
......@@ -451,13 +451,15 @@ static int vmw_fb_kms_detach(struct vmw_fb_par *par,
}
if (par->vmw_bo && detach_bo) {
struct vmw_private *vmw_priv = par->vmw_priv;
if (par->bo_ptr) {
ttm_bo_kunmap(&par->map);
par->bo_ptr = NULL;
}
if (unref_bo)
vmw_dmabuf_unreference(&par->vmw_bo);
else
else if (vmw_priv->active_display_unit != vmw_du_legacy)
vmw_dmabuf_unpin(par->vmw_priv, par->vmw_bo, false);
}
......@@ -585,18 +587,25 @@ static int vmw_fb_set_par(struct fb_info *info)
/*
* Pin before mapping. Since we don't know in what placement
* to pin, call into KMS to do it for us.
* to pin, call into KMS to do it for us. LDU doesn't require
* additional pinning because set_config() would've pinned
* it already
*/
if (vmw_priv->active_display_unit != vmw_du_legacy) {
ret = vfb->pin(vfb);
if (ret) {
DRM_ERROR("Could not pin the fbdev framebuffer.\n");
DRM_ERROR("Could not pin the fbdev "
"framebuffer.\n");
goto out_unlock;
}
}
ret = ttm_bo_kmap(&par->vmw_bo->base, 0,
par->vmw_bo->base.num_pages, &par->map);
if (ret) {
if (vmw_priv->active_display_unit != vmw_du_legacy)
vfb->unpin(vfb);
DRM_ERROR("Could not map the fbdev framebuffer.\n");
goto out_unlock;
}
......@@ -822,7 +831,9 @@ int vmw_fb_off(struct vmw_private *vmw_priv)
flush_delayed_work(&par->local_work);
mutex_lock(&par->bo_mutex);
drm_modeset_lock_all(vmw_priv->dev);
(void) vmw_fb_kms_detach(par, true, false);
drm_modeset_unlock_all(vmw_priv->dev);
mutex_unlock(&par->bo_mutex);
return 0;
......
This diff is collapsed.
......@@ -33,6 +33,8 @@
#include <drm/drm_encoder.h>
#include "vmwgfx_drv.h"
/**
* struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
* function.
......@@ -125,20 +127,72 @@ struct vmw_framebuffer_dmabuf {
};
/*
* Basic cursor manipulation
static const uint32_t vmw_primary_plane_formats[] = {
DRM_FORMAT_XRGB1555,
DRM_FORMAT_RGB565,
DRM_FORMAT_RGB888,
DRM_FORMAT_XRGB8888,
DRM_FORMAT_ARGB8888,
};
static const uint32_t vmw_cursor_plane_formats[] = {
DRM_FORMAT_ARGB8888,
};
#define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
#define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
#define vmw_connector_state_to_vcs(x) \
container_of(x, struct vmw_connector_state, base)
/**
* Derived class for crtc state object
*
* @base DRM crtc object
*/
int vmw_cursor_update_image(struct vmw_private *dev_priv,
u32 *image, u32 width, u32 height,
u32 hotspotX, u32 hotspotY);
int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv,
struct vmw_dma_buffer *dmabuf,
u32 width, u32 height,
u32 hotspotX, u32 hotspotY);
void vmw_cursor_update_position(struct vmw_private *dev_priv,
bool show, int x, int y);
struct vmw_crtc_state {
struct drm_crtc_state base;
};
/**
* Derived class for plane state object
*
* @base DRM plane object
* @surf Display surface for STDU
* @dmabuf display dmabuf for SOU
* @content_fb_type Used by STDU.
* @dmabuf_size Size of the dmabuf, used by Screen Object Display Unit
* @pinned pin count for STDU display surface
*/
struct vmw_plane_state {
struct drm_plane_state base;
struct vmw_surface *surf;
struct vmw_dma_buffer *dmabuf;
int content_fb_type;
unsigned long dmabuf_size;
int pinned;
/* For CPU Blit */
struct ttm_bo_kmap_obj host_map, guest_map;
unsigned int cpp;
};
/**
* Derived class for connector state object
*
* @base DRM connector object
* @is_implicit connector property
*
*/
struct vmw_connector_state {
struct drm_connector_state base;
bool is_implicit;
};
/**
* Base class display unit.
*
......@@ -150,6 +204,8 @@ struct vmw_display_unit {
struct drm_crtc crtc;
struct drm_encoder encoder;
struct drm_connector connector;
struct drm_plane primary;
struct drm_plane cursor;
struct vmw_surface *cursor_surface;
struct vmw_dma_buffer *cursor_dmabuf;
......@@ -203,6 +259,18 @@ int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
uint32_t handle, uint32_t width, uint32_t height,
int32_t hot_x, int32_t hot_y);
int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
int vmw_du_connector_set_property(struct drm_connector *connector,
struct drm_property *property,
uint64_t val);
int vmw_du_connector_atomic_set_property(struct drm_connector *connector,
struct drm_connector_state *state,
struct drm_property *property,
uint64_t val);
int
vmw_du_connector_atomic_get_property(struct drm_connector *connector,
const struct drm_connector_state *state,
struct drm_property *property,
uint64_t *val);
int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
void vmw_du_connector_save(struct drm_connector *connector);
void vmw_du_connector_restore(struct drm_connector *connector);
......@@ -210,9 +278,6 @@ enum drm_connector_status
vmw_du_connector_detect(struct drm_connector *connector, bool force);
int vmw_du_connector_fill_modes(struct drm_connector *connector,
uint32_t max_width, uint32_t max_height);
int vmw_du_connector_set_property(struct drm_connector *connector,
struct drm_property *property,
uint64_t val);
int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
struct vmw_framebuffer *framebuffer,
const struct drm_clip_rect *clips,
......@@ -270,6 +335,55 @@ void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
bool immutable);
/* Universal Plane Helpers */
void vmw_du_primary_plane_destroy(struct drm_plane *plane);
void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
int vmw_du_cursor_plane_disable(struct drm_plane *plane);
int vmw_du_cursor_plane_update(struct drm_plane *plane,
struct drm_crtc *crtc,
struct drm_framebuffer *fb,
int crtc_x, int crtc_y,
unsigned int crtc_w,
unsigned int crtc_h,
uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h);
/* Atomic Helpers */
int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
struct drm_plane_state *state);
int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
struct drm_plane_state *state);
void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
struct drm_plane_state *old_state);
void vmw_du_cursor_plane_atomic_disable(struct drm_plane *plane,
struct drm_plane_state *old_state);
int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
struct drm_plane_state *new_state);
void vmw_du_plane_cleanup_fb(struct drm_plane *plane,
struct drm_plane_state *old_state);
void vmw_du_plane_reset(struct drm_plane *plane);
struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane);
void vmw_du_plane_destroy_state(struct drm_plane *plane,
struct drm_plane_state *state);
void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps,
bool unreference);
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
struct drm_crtc_state *state);
void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
struct drm_crtc_state *old_crtc_state);
void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
struct drm_crtc_state *old_crtc_state);
void vmw_du_crtc_reset(struct drm_crtc *crtc);
struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
struct drm_crtc_state *state);
void vmw_du_connector_reset(struct drm_connector *connector);
struct drm_connector_state *
vmw_du_connector_duplicate_state(struct drm_connector *connector);
void vmw_du_connector_destroy_state(struct drm_connector *connector,
struct drm_connector_state *state);
/*
* Legacy display unit functions - vmwgfx_ldu.c
......@@ -339,5 +453,6 @@ int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
bool to_surface,
bool interruptible);
int vmw_kms_set_config(struct drm_mode_set *set);
#endif
This diff is collapsed.
......@@ -45,31 +45,6 @@ struct vmw_bo_user_rep {
uint64_t map_handle;
};
struct vmw_stream {
struct vmw_resource res;
uint32_t stream_id;
};
struct vmw_user_stream {
struct ttm_base_object base;
struct vmw_stream stream;
};
static uint64_t vmw_user_stream_size;
static const struct vmw_res_func vmw_stream_func = {
.res_type = vmw_res_stream,
.needs_backup = false,
.may_evict = false,
.type_name = "video streams",
.backup_placement = NULL,
.create = NULL,
.destroy = NULL,
.bind = NULL,
.unbind = NULL
};
static inline struct vmw_dma_buffer *
vmw_dma_buffer(struct ttm_buffer_object *bo)
{
......@@ -259,24 +234,6 @@ void vmw_resource_activate(struct vmw_resource *res,
write_unlock(&dev_priv->resource_lock);
}
static struct vmw_resource *vmw_resource_lookup(struct vmw_private *dev_priv,
struct idr *idr, int id)
{
struct vmw_resource *res;
read_lock(&dev_priv->resource_lock);
res = idr_find(idr, id);
if (!res || !res->avail || !kref_get_unless_zero(&res->kref))
res = NULL;
read_unlock(&dev_priv->resource_lock);
if (unlikely(res == NULL))
return NULL;
return res;
}
/**
* vmw_user_resource_lookup_handle - lookup a struct resource from a
* TTM user-space handle and perform basic type checks
......@@ -776,217 +733,6 @@ int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
TTM_REF_USAGE, NULL);
}
/*
* Stream management
*/
static void vmw_stream_destroy(struct vmw_resource *res)
{
struct vmw_private *dev_priv = res->dev_priv;
struct vmw_stream *stream;
int ret;
DRM_INFO("%s: unref\n", __func__);
stream = container_of(res, struct vmw_stream, res);
ret = vmw_overlay_unref(dev_priv, stream->stream_id);
WARN_ON(ret != 0);
}
static int vmw_stream_init(struct vmw_private *dev_priv,
struct vmw_stream *stream,
void (*res_free) (struct vmw_resource *res))
{
struct vmw_resource *res = &stream->res;
int ret;
ret = vmw_resource_init(dev_priv, res, false, res_free,
&vmw_stream_func);
if (unlikely(ret != 0)) {
if (res_free == NULL)
kfree(stream);
else
res_free(&stream->res);
return ret;
}
ret = vmw_overlay_claim(dev_priv, &stream->stream_id);
if (ret) {
vmw_resource_unreference(&res);
return ret;
}
DRM_INFO("%s: claimed\n", __func__);
vmw_resource_activate(&stream->res, vmw_stream_destroy);
return 0;
}
static void vmw_user_stream_free(struct vmw_resource *res)
{
struct vmw_user_stream *stream =
container_of(res, struct vmw_user_stream, stream.res);
struct vmw_private *dev_priv = res->dev_priv;
ttm_base_object_kfree(stream, base);
ttm_mem_global_free(vmw_mem_glob(dev_priv),
vmw_user_stream_size);
}
/**
* This function is called when user space has no more references on the
* base object. It releases the base-object's reference on the resource object.
*/
static void vmw_user_stream_base_release(struct ttm_base_object **p_base)
{
struct ttm_base_object *base = *p_base;
struct vmw_user_stream *stream =
container_of(base, struct vmw_user_stream, base);
struct vmw_resource *res = &stream->stream.res;
*p_base = NULL;
vmw_resource_unreference(&res);
}
int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct vmw_private *dev_priv = vmw_priv(dev);
struct vmw_resource *res;
struct vmw_user_stream *stream;
struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data;
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
struct idr *idr = &dev_priv->res_idr[vmw_res_stream];
int ret = 0;
res = vmw_resource_lookup(dev_priv, idr, arg->stream_id);
if (unlikely(res == NULL))
return -EINVAL;
if (res->res_free != &vmw_user_stream_free) {
ret = -EINVAL;
goto out;
}
stream = container_of(res, struct vmw_user_stream, stream.res);
if (stream->base.tfile != tfile) {
ret = -EINVAL;
goto out;
}
ttm_ref_object_base_unref(tfile, stream->base.hash.key, TTM_REF_USAGE);
out:
vmw_resource_unreference(&res);
return ret;
}
int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct vmw_private *dev_priv = vmw_priv(dev);
struct vmw_user_stream *stream;
struct vmw_resource *res;
struct vmw_resource *tmp;
struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data;
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
int ret;
/*
* Approximate idr memory usage with 128 bytes. It will be limited
* by maximum number_of streams anyway?
*/
if (unlikely(vmw_user_stream_size == 0))
vmw_user_stream_size = ttm_round_pot(sizeof(*stream)) + 128;
ret = ttm_read_lock(&dev_priv->reservation_sem, true);
if (unlikely(ret != 0))
return ret;
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv),
vmw_user_stream_size,
false, true);
ttm_read_unlock(&dev_priv->reservation_sem);
if (unlikely(ret != 0)) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Out of graphics memory for stream"
" creation.\n");
goto out_ret;
}
stream = kmalloc(sizeof(*stream), GFP_KERNEL);
if (unlikely(stream == NULL)) {
ttm_mem_global_free(vmw_mem_glob(dev_priv),
vmw_user_stream_size);
ret = -ENOMEM;
goto out_ret;
}
res = &stream->stream.res;
stream->base.shareable = false;
stream->base.tfile = NULL;
/*
* From here on, the destructor takes over resource freeing.
*/
ret = vmw_stream_init(dev_priv, &stream->stream, vmw_user_stream_free);
if (unlikely(ret != 0))
goto out_ret;
tmp = vmw_resource_reference(res);
ret = ttm_base_object_init(tfile, &stream->base, false, VMW_RES_STREAM,
&vmw_user_stream_base_release, NULL);
if (unlikely(ret != 0)) {
vmw_resource_unreference(&tmp);
goto out_err;
}
arg->stream_id = res->id;
out_err:
vmw_resource_unreference(&res);
out_ret:
return ret;
}
int vmw_user_stream_lookup(struct vmw_private *dev_priv,
struct ttm_object_file *tfile,
uint32_t *inout_id, struct vmw_resource **out)
{
struct vmw_user_stream *stream;
struct vmw_resource *res;
int ret;
res = vmw_resource_lookup(dev_priv, &dev_priv->res_idr[vmw_res_stream],
*inout_id);
if (unlikely(res == NULL))
return -EINVAL;
if (res->res_free != &vmw_user_stream_free) {
ret = -EINVAL;
goto err_ref;
}
stream = container_of(res, struct vmw_user_stream, stream.res);
if (stream->base.tfile != tfile) {
ret = -EPERM;
goto err_ref;
}
*inout_id = stream->stream.stream_id;
*out = res;
return 0;
err_ref:
vmw_resource_unreference(&res);
return ret;
}
/**
* vmw_dumb_create - Create a dumb kms buffer
*
......
......@@ -30,6 +30,8 @@
#include "vmwgfx_drv.h"
#define VMW_IDA_ACC_SIZE 128
enum vmw_cmdbuf_res_state {
VMW_CMDBUF_RES_COMMITTED,
VMW_CMDBUF_RES_ADD,
......@@ -83,6 +85,35 @@ struct vmw_res_func {
enum vmw_cmdbuf_res_state state);
};
/**
* struct vmw_simple_resource_func - members and functions common for the
* simple resource helpers.
* @res_func: struct vmw_res_func as described above.
* @ttm_res_type: TTM resource type used for handle recognition.
* @size: Size of the simple resource information struct.
* @init: Initialize the simple resource information.
* @hw_destroy: A resource hw_destroy function.
* @set_arg_handle: Set the handle output argument of the ioctl create struct.
*/
struct vmw_simple_resource_func {
const struct vmw_res_func res_func;
int ttm_res_type;
size_t size;
int (*init)(struct vmw_resource *res, void *data);
void (*hw_destroy)(struct vmw_resource *res);
void (*set_arg_handle)(void *data, u32 handle);
};
/**
* struct vmw_simple_resource - Kernel only side simple resource
* @res: The resource we derive from.
* @func: The method and member virtual table.
*/
struct vmw_simple_resource {
struct vmw_resource res;
const struct vmw_simple_resource_func *func;
};
int vmw_resource_alloc_id(struct vmw_resource *res);
void vmw_resource_release_id(struct vmw_resource *res);
int vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res,
......@@ -91,4 +122,13 @@ int vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res,
const struct vmw_res_func *func);
void vmw_resource_activate(struct vmw_resource *res,
void (*hw_destroy) (struct vmw_resource *));
int
vmw_simple_resource_create_ioctl(struct drm_device *dev,
void *data,
struct drm_file *file_priv,
const struct vmw_simple_resource_func *func);
struct vmw_resource *
vmw_simple_resource_lookup(struct ttm_object_file *tfile,
uint32_t handle,
const struct vmw_simple_resource_func *func);
#endif
This diff is collapsed.
/**************************************************************************
*
* Copyright © 2016 VMware, Inc., Palo Alto, CA., USA
* All Rights Reserved.
*
* 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"
#include "vmwgfx_resource_priv.h"
/**
* struct vmw_user_simple_resource - User-space simple resource struct
*
* @base: The TTM base object implementing user-space visibility.
* @account_size: How much memory was accounted for this object.
* @simple: The embedded struct vmw_simple_resource.
*/
struct vmw_user_simple_resource {
struct ttm_base_object base;
size_t account_size;
struct vmw_simple_resource simple;
/*
* Nothing to be placed after @simple, since size of @simple is
* unknown.
*/
};
/**
* vmw_simple_resource_init - Initialize a simple resource object.
*
* @dev_priv: Pointer to a struct device private.
* @simple: The struct vmw_simple_resource to initialize.
* @data: Data passed to the information initialization function.
* @res_free: Function pointer to destroy the simple resource.
*
* Returns:
* 0 if succeeded.
* Negative error value if error, in which case the resource will have been
* freed.
*/
static int vmw_simple_resource_init(struct vmw_private *dev_priv,
struct vmw_simple_resource *simple,
void *data,
void (*res_free)(struct vmw_resource *res))
{
struct vmw_resource *res = &simple->res;
int ret;
ret = vmw_resource_init(dev_priv, res, false, res_free,
&simple->func->res_func);
if (ret) {
res_free(res);
return ret;
}
ret = simple->func->init(res, data);
if (ret) {
vmw_resource_unreference(&res);
return ret;
}
vmw_resource_activate(&simple->res, simple->func->hw_destroy);
return 0;
}
/**
* vmw_simple_resource_free - Free a simple resource object.
*
* @res: The struct vmw_resource member of the simple resource object.
*
* Frees memory and memory accounting for the object.
*/
static void vmw_simple_resource_free(struct vmw_resource *res)
{
struct vmw_user_simple_resource *usimple =
container_of(res, struct vmw_user_simple_resource,
simple.res);
struct vmw_private *dev_priv = res->dev_priv;
size_t size = usimple->account_size;
ttm_base_object_kfree(usimple, base);
ttm_mem_global_free(vmw_mem_glob(dev_priv), size);
}
/**
* vmw_simple_resource_base_release - TTM object release callback
*
* @p_base: The struct ttm_base_object member of the simple resource object.
*
* Called when the last reference to the embedded struct ttm_base_object is
* gone. Typically results in an object free, unless there are other
* references to the embedded struct vmw_resource.
*/
static void vmw_simple_resource_base_release(struct ttm_base_object **p_base)
{
struct ttm_base_object *base = *p_base;
struct vmw_user_simple_resource *usimple =
container_of(base, struct vmw_user_simple_resource, base);
struct vmw_resource *res = &usimple->simple.res;
*p_base = NULL;
vmw_resource_unreference(&res);
}
/**
* vmw_simple_resource_create_ioctl - Helper to set up an ioctl function to
* create a struct vmw_simple_resource.
*
* @dev: Pointer to a struct drm device.
* @data: Ioctl argument.
* @file_priv: Pointer to a struct drm_file identifying the caller.
* @func: Pointer to a struct vmw_simple_resource_func identifying the
* simple resource type.
*
* Returns:
* 0 if success,
* Negative error value on error.
*/
int
vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv,
const struct vmw_simple_resource_func *func)
{
struct vmw_private *dev_priv = vmw_priv(dev);
struct vmw_user_simple_resource *usimple;
struct vmw_resource *res;
struct vmw_resource *tmp;
struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
size_t alloc_size;
size_t account_size;
int ret;
alloc_size = offsetof(struct vmw_user_simple_resource, simple) +
func->size;
account_size = ttm_round_pot(alloc_size) + VMW_IDA_ACC_SIZE;
ret = ttm_read_lock(&dev_priv->reservation_sem, true);
if (ret)
return ret;
ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), account_size,
false, true);
ttm_read_unlock(&dev_priv->reservation_sem);
if (ret) {
if (ret != -ERESTARTSYS)
DRM_ERROR("Out of graphics memory for %s"
" creation.\n", func->res_func.type_name);
goto out_ret;
}
usimple = kzalloc(alloc_size, GFP_KERNEL);
if (!usimple) {
ttm_mem_global_free(vmw_mem_glob(dev_priv),
account_size);
ret = -ENOMEM;
goto out_ret;
}
usimple->simple.func = func;
usimple->account_size = account_size;
res = &usimple->simple.res;
usimple->base.shareable = false;
usimple->base.tfile = NULL;
/*
* From here on, the destructor takes over resource freeing.
*/
ret = vmw_simple_resource_init(dev_priv, &usimple->simple,
data, vmw_simple_resource_free);
if (ret)
goto out_ret;
tmp = vmw_resource_reference(res);
ret = ttm_base_object_init(tfile, &usimple->base, false,
func->ttm_res_type,
&vmw_simple_resource_base_release, NULL);
if (ret) {
vmw_resource_unreference(&tmp);
goto out_err;
}
func->set_arg_handle(data, usimple->base.hash.key);
out_err:
vmw_resource_unreference(&res);
out_ret:
return ret;
}
/**
* vmw_simple_resource_lookup - Look up a simple resource from its user-space
* handle.
*
* @tfile: struct ttm_object_file identifying the caller.
* @handle: The user-space handle.
* @func: The struct vmw_simple_resource_func identifying the simple resource
* type.
*
* Returns: Refcounted pointer to the embedded struct vmw_resource if
* successfule. Error pointer otherwise.
*/
struct vmw_resource *
vmw_simple_resource_lookup(struct ttm_object_file *tfile,
uint32_t handle,
const struct vmw_simple_resource_func *func)
{
struct vmw_user_simple_resource *usimple;
struct ttm_base_object *base;
struct vmw_resource *res;
base = ttm_base_object_lookup(tfile, handle);
if (!base) {
DRM_ERROR("Invalid %s handle 0x%08lx.\n",
func->res_func.type_name,
(unsigned long) handle);
return ERR_PTR(-ESRCH);
}
if (ttm_base_object_type(base) != func->ttm_res_type) {
ttm_base_object_unref(&base);
DRM_ERROR("Invalid type of %s handle 0x%08lx.\n",
func->res_func.type_name,
(unsigned long) handle);
return ERR_PTR(-EINVAL);
}
usimple = container_of(base, typeof(*usimple), base);
res = vmw_resource_reference(&usimple->simple.res);
ttm_base_object_unref(&base);
return res;
}
This diff is collapsed.
......@@ -814,7 +814,6 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
} else {
srf->snooper.image = NULL;
}
srf->snooper.crtc = NULL;
user_srf->prime.base.shareable = false;
user_srf->prime.base.tfile = NULL;
......@@ -1480,10 +1479,24 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,
*srf_out = NULL;
if (for_scanout) {
uint32_t max_width, max_height;
if (!svga3dsurface_is_screen_target_format(format)) {
DRM_ERROR("Invalid Screen Target surface format.");
return -EINVAL;
}
max_width = min(dev_priv->texture_max_width,
dev_priv->stdu_max_width);
max_height = min(dev_priv->texture_max_height,
dev_priv->stdu_max_height);
if (size.width > max_width || size.height > max_height) {
DRM_ERROR("%ux%u\n, exeeds max surface size %ux%u",
size.width, size.height,
max_width, max_height);
return -EINVAL;
}
} else {
const struct svga3d_surface_desc *desc;
......
/**************************************************************************
*
* Copyright © 2012-2016 VMware, Inc., Palo Alto, CA., USA
* All Rights Reserved.
*
* 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"
#include "vmwgfx_resource_priv.h"
/**
* struct vmw_stream - Overlay stream simple resource.
* @sres: The simple resource we derive from.
* @stream_id: The overlay stream id.
*/
struct vmw_stream {
struct vmw_simple_resource sres;
u32 stream_id;
};
/**
* vmw_stream - Typecast a struct vmw_resource to a struct vmw_stream.
* @res: Pointer to the struct vmw_resource.
*
* Returns: Returns a pointer to the struct vmw_stream.
*/
static struct vmw_stream *
vmw_stream(struct vmw_resource *res)
{
return container_of(res, struct vmw_stream, sres.res);
}
/***************************************************************************
* Simple resource callbacks for struct vmw_stream
**************************************************************************/
static void vmw_stream_hw_destroy(struct vmw_resource *res)
{
struct vmw_private *dev_priv = res->dev_priv;
struct vmw_stream *stream = vmw_stream(res);
int ret;
ret = vmw_overlay_unref(dev_priv, stream->stream_id);
WARN_ON_ONCE(ret != 0);
}
static int vmw_stream_init(struct vmw_resource *res, void *data)
{
struct vmw_stream *stream = vmw_stream(res);
return vmw_overlay_claim(res->dev_priv, &stream->stream_id);
}
static void vmw_stream_set_arg_handle(void *data, u32 handle)
{
struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data;
arg->stream_id = handle;
}
static const struct vmw_simple_resource_func va_stream_func = {
.res_func = {
.res_type = vmw_res_stream,
.needs_backup = false,
.may_evict = false,
.type_name = "overlay stream",
.backup_placement = NULL,
.create = NULL,
.destroy = NULL,
.bind = NULL,
.unbind = NULL
},
.ttm_res_type = VMW_RES_STREAM,
.size = sizeof(struct vmw_stream),
.init = vmw_stream_init,
.hw_destroy = vmw_stream_hw_destroy,
.set_arg_handle = vmw_stream_set_arg_handle,
};
/***************************************************************************
* End simple resource callbacks for struct vmw_stream
**************************************************************************/
/**
* vmw_stream_unref_ioctl - Ioctl to unreference a user-space handle to
* a struct vmw_stream.
* @dev: Pointer to the drm device.
* @data: The ioctl argument
* @file_priv: Pointer to a struct drm_file identifying the caller.
*
* Return:
* 0 if successful.
* Negative error value on failure.
*/
int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data;
return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile,
arg->stream_id, TTM_REF_USAGE);
}
/**
* vmw_stream_claim_ioctl - Ioctl to claim a struct vmw_stream overlay.
* @dev: Pointer to the drm device.
* @data: The ioctl argument
* @file_priv: Pointer to a struct drm_file identifying the caller.
*
* Return:
* 0 if successful.
* Negative error value on failure.
*/
int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
return vmw_simple_resource_create_ioctl(dev, data, file_priv,
&va_stream_func);
}
/**
* vmw_user_stream_lookup - Look up a struct vmw_user_stream from a handle.
* @dev_priv: Pointer to a struct vmw_private.
* @tfile: struct ttm_object_file identifying the caller.
* @inout_id: In: The user-space handle. Out: The stream id.
* @out: On output contains a refcounted pointer to the embedded
* struct vmw_resource.
*
* Return:
* 0 if successful.
* Negative error value on failure.
*/
int vmw_user_stream_lookup(struct vmw_private *dev_priv,
struct ttm_object_file *tfile,
uint32_t *inout_id, struct vmw_resource **out)
{
struct vmw_stream *stream;
struct vmw_resource *res =
vmw_simple_resource_lookup(tfile, *inout_id, &va_stream_func);
if (IS_ERR(res))
return PTR_ERR(res);
stream = vmw_stream(res);
*inout_id = stream->stream_id;
*out = res;
return 0;
}
......@@ -41,6 +41,7 @@ extern "C" {
#define DRM_VMW_GET_PARAM 0
#define DRM_VMW_ALLOC_DMABUF 1
#define DRM_VMW_UNREF_DMABUF 2
#define DRM_VMW_HANDLE_CLOSE 2
#define DRM_VMW_CURSOR_BYPASS 3
/* guarded by DRM_VMW_PARAM_NUM_STREAMS != 0*/
#define DRM_VMW_CONTROL_STREAM 4
......@@ -1092,6 +1093,29 @@ union drm_vmw_extended_context_arg {
struct drm_vmw_context_arg rep;
};
/*************************************************************************/
/*
* DRM_VMW_HANDLE_CLOSE - Close a user-space handle and release its
* underlying resource.
*
* Note that this ioctl is overlaid on the DRM_VMW_UNREF_DMABUF Ioctl.
* The ioctl arguments therefore need to be identical in layout.
*
*/
/**
* struct drm_vmw_handle_close_arg
*
* @handle: Handle to close.
*
* Argument to the DRM_VMW_HANDLE_CLOSE Ioctl.
*/
struct drm_vmw_handle_close_arg {
__u32 handle;
__u32 pad64;
};
#if defined(__cplusplus)
}
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment