/* * Copyright 2013 Red Hat Inc. * * 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, sublicense, * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. * * Authors: Dave Airlie * Alon Levy
*/
#include <linux/pci.h> #include <linux/uaccess.h>
#include"qxl_drv.h" #include"qxl_object.h"
/* * TODO: allocating a new gem(in qxl_bo) for each request. * This is wasteful since bo's are page aligned.
*/ int qxl_alloc_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
{ struct qxl_device *qdev = to_qxl(dev); struct drm_qxl_alloc *qxl_alloc = data; int ret;
uint32_t handle;
u32 domain = QXL_GEM_DOMAIN_VRAM;
struct qxl_reloc_info { int type; struct qxl_bo *dst_bo;
uint32_t dst_offset; struct qxl_bo *src_bo; int src_offset;
};
/* * dst must be validated, i.e. whole bo on vram/surfacesram (right now all bo's * are on vram). * *(dst + dst_off) = qxl_bo_physical_address(src, src_off)
*/ staticvoid
apply_reloc(struct qxl_device *qdev, struct qxl_reloc_info *info)
{ void *reloc_page;
/* return holding the reference to this object */ staticint qxlhw_handle_to_bo(struct drm_file *file_priv, uint64_t handle, struct qxl_release *release, struct qxl_bo **qbo_p)
{ struct drm_gem_object *gobj; struct qxl_bo *qobj; int ret;
gobj = drm_gem_object_lookup(file_priv, handle); if (!gobj) return -EINVAL;
qobj = gem_to_qxl_bo(gobj);
ret = qxl_release_list_add(release, qobj);
drm_gem_object_put(gobj); if (ret) return ret;
*qbo_p = qobj; return 0;
}
/* * Usage of execbuffer: * Relocations need to take into account the full QXLDrawable size. * However, the command as passed from user space must *not* contain the initial * QXLReleaseInfo struct (first XXX bytes)
*/ staticint qxl_process_single_command(struct qxl_device *qdev, struct drm_qxl_command *cmd, struct drm_file *file_priv)
{ struct qxl_reloc_info *reloc_info; int release_type; struct qxl_release *release; struct qxl_bo *cmd_bo; void *fb_cmd; int i, ret; int unwritten;
switch (cmd->type) { case QXL_CMD_DRAW:
release_type = QXL_RELEASE_DRAWABLE; break; case QXL_CMD_SURFACE: case QXL_CMD_CURSOR: default:
DRM_DEBUG("Only draw commands in execbuffers\n"); return -EINVAL;
}
if (cmd->command_size > PAGE_SIZE - sizeof(union qxl_release_info)) return -EINVAL;
if (!access_ok(u64_to_user_ptr(cmd->command),
cmd->command_size)) return -EFAULT;
reloc_info = kmalloc_array(cmd->relocs_num, sizeof(struct qxl_reloc_info), GFP_KERNEL); if (!reloc_info) return -ENOMEM;
ret = qxl_alloc_release_reserved(qdev, sizeof(union qxl_release_info) +
cmd->command_size,
release_type,
&release,
&cmd_bo); if (ret) goto out_free_reloc;
qxl_bo_kunmap_atomic_page(qdev, cmd_bo, fb_cmd); if (unwritten) {
DRM_ERROR("got unwritten %d\n", unwritten);
ret = -EFAULT; goto out_free_release;
}
/* fill out reloc info structs */ for (i = 0; i < cmd->relocs_num; ++i) { struct drm_qxl_reloc reloc; struct drm_qxl_reloc __user *u = u64_to_user_ptr(cmd->relocs);
if (copy_from_user(&reloc, u + i, sizeof(reloc))) {
ret = -EFAULT; goto out_free_bos;
}
/* add the bos to the list of bos to validate -
need to validate first then process relocs? */ if (reloc.reloc_type != QXL_RELOC_TYPE_BO && reloc.reloc_type != QXL_RELOC_TYPE_SURF) {
DRM_DEBUG("unknown reloc type %d\n", reloc.reloc_type);
ret = -EINVAL; goto out_free_bos;
}
reloc_info[i].type = reloc.reloc_type;
if (reloc.dst_handle) {
ret = qxlhw_handle_to_bo(file_priv, reloc.dst_handle, release,
&reloc_info[i].dst_bo); if (ret) goto out_free_bos;
reloc_info[i].dst_offset = reloc.dst_offset;
} else {
reloc_info[i].dst_bo = cmd_bo;
reloc_info[i].dst_offset = reloc.dst_offset + release->release_offset;
}
/* reserve and validate the reloc dst bo */ if (reloc.reloc_type == QXL_RELOC_TYPE_BO || reloc.src_handle) {
ret = qxlhw_handle_to_bo(file_priv, reloc.src_handle, release,
&reloc_info[i].src_bo); if (ret) goto out_free_bos;
reloc_info[i].src_offset = reloc.src_offset;
} else {
reloc_info[i].src_bo = NULL;
reloc_info[i].src_offset = 0;
}
}
/* validate all buffers */
ret = qxl_release_reserve_list(release, false); if (ret) goto out_free_bos;
for (i = 0; i < cmd->relocs_num; ++i) { if (reloc_info[i].type == QXL_RELOC_TYPE_BO)
apply_reloc(qdev, &reloc_info[i]); elseif (reloc_info[i].type == QXL_RELOC_TYPE_SURF)
apply_surf_reloc(qdev, &reloc_info[i]);
}
qxl_release_fence_buffer_objects(release);
ret = qxl_push_command_ring_release(qdev, release, cmd->type, true);
if (update_area->left >= update_area->right ||
update_area->top >= update_area->bottom) return -EINVAL;
gobj = drm_gem_object_lookup(file, update_area->handle); if (gobj == NULL) return -ENOENT;
qobj = gem_to_qxl_bo(gobj);
ret = qxl_bo_reserve(qobj); if (ret) goto out;
if (!qobj->tbo.pin_count) {
qxl_ttm_placement_from_domain(qobj, qobj->type);
ret = ttm_bo_validate(&qobj->tbo, &qobj->placement, &ctx); if (unlikely(ret)) goto out;
}
ret = qxl_bo_check_id(qdev, qobj); if (ret) goto out2; if (!qobj->surface_id)
DRM_ERROR("got update area for surface with no id %d\n", update_area->handle);
ret = qxl_io_update_area(qdev, qobj, &area);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.