static int qxl_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) { struct drm_device *dev = crtc->dev; struct qxl_device *qdev = dev->dev_private; struct qxl_crtc *qcrtc = to_qxl_crtc(crtc); struct drm_gem_object *obj; struct qxl_cursor *cursor; struct qxl_cursor_cmd *cmd; struct qxl_bo *cursor_bo, *user_bo; struct qxl_release *release; void *user_ptr; int size = 64*64*4; int ret = 0; if (!handle) { qxl_hide_cursor(qdev); return 0; } obj = drm_gem_object_lookup(crtc->dev, file_priv, handle); if (!obj) { DRM_ERROR("cannot find cursor object\n"); return -ENOENT; } user_bo = gem_to_qxl_bo(obj); ret = qxl_bo_reserve(user_bo, false); if (ret) goto out_unref; ret = qxl_bo_pin(user_bo, QXL_GEM_DOMAIN_CPU, NULL); if (ret) goto out_unreserve; ret = qxl_bo_kmap(user_bo, &user_ptr); if (ret) goto out_unpin; ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd), QXL_RELEASE_CURSOR_CMD, &release, NULL); if (ret) goto out_kunmap; ret = qxl_alloc_bo_reserved(qdev, sizeof(struct qxl_cursor) + size, &cursor_bo); if (ret) goto out_free_release; ret = qxl_bo_kmap(cursor_bo, (void **)&cursor); if (ret) goto out_free_bo; cursor->header.unique = 0; cursor->header.type = SPICE_CURSOR_TYPE_ALPHA; cursor->header.width = 64; cursor->header.height = 64; cursor->header.hot_spot_x = hot_x; cursor->header.hot_spot_y = hot_y; cursor->data_size = size; cursor->chunk.next_chunk = 0; cursor->chunk.prev_chunk = 0; cursor->chunk.data_size = size; memcpy(cursor->chunk.data, user_ptr, size); qxl_bo_kunmap(cursor_bo); /* finish with the userspace bo */ qxl_bo_kunmap(user_bo); qxl_bo_unpin(user_bo); qxl_bo_unreserve(user_bo); drm_gem_object_unreference_unlocked(obj); cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release); cmd->type = QXL_CURSOR_SET; cmd->u.set.position.x = qcrtc->cur_x; cmd->u.set.position.y = qcrtc->cur_y; cmd->u.set.shape = qxl_bo_physical_address(qdev, cursor_bo, 0); qxl_release_add_res(qdev, release, cursor_bo); cmd->u.set.visible = 1; qxl_release_unmap(qdev, release, &cmd->release_info); qxl_fence_releaseable(qdev, release); qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); qxl_release_unreserve(qdev, release); qxl_bo_unreserve(cursor_bo); qxl_bo_unref(&cursor_bo); return ret; out_free_bo: qxl_bo_unref(&cursor_bo); out_free_release: qxl_release_unreserve(qdev, release); qxl_release_free(qdev, release); out_kunmap: qxl_bo_kunmap(user_bo); out_unpin: qxl_bo_unpin(user_bo); out_unreserve: qxl_bo_unreserve(user_bo); out_unref: drm_gem_object_unreference_unlocked(obj); return ret; }
/* * 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) */ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct qxl_device *qdev = dev->dev_private; struct drm_qxl_execbuffer *execbuffer = data; struct drm_qxl_command user_cmd; int cmd_num; struct qxl_bo *reloc_src_bo; struct qxl_bo *reloc_dst_bo; struct drm_qxl_reloc reloc; void *fb_cmd; int i, ret; struct qxl_reloc_list reloc_list; int unwritten; uint32_t reloc_dst_offset; INIT_LIST_HEAD(&reloc_list.bos); for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) { struct qxl_release *release; struct qxl_bo *cmd_bo; int release_type; struct drm_qxl_command *commands = (struct drm_qxl_command *)execbuffer->commands; if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num], sizeof(user_cmd))) return -EFAULT; switch (user_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; break; } if (user_cmd.command_size > PAGE_SIZE - sizeof(union qxl_release_info)) return -EINVAL; ret = qxl_alloc_release_reserved(qdev, sizeof(union qxl_release_info) + user_cmd.command_size, release_type, &release, &cmd_bo); if (ret) return ret; /* TODO copy slow path code from i915 */ fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE)); unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void *)(unsigned long)user_cmd.command, user_cmd.command_size); qxl_bo_kunmap_atomic_page(qdev, cmd_bo, fb_cmd); if (unwritten) { DRM_ERROR("got unwritten %d\n", unwritten); qxl_release_unreserve(qdev, release); qxl_release_free(qdev, release); return -EFAULT; } for (i = 0 ; i < user_cmd.relocs_num; ++i) { if (DRM_COPY_FROM_USER(&reloc, &((struct drm_qxl_reloc *)user_cmd.relocs)[i], sizeof(reloc))) { qxl_bo_list_unreserve(&reloc_list, true); qxl_release_unreserve(qdev, release); qxl_release_free(qdev, release); return -EFAULT; } /* add the bos to the list of bos to validate - need to validate first then process relocs? */ if (reloc.dst_handle) { reloc_dst_bo = qxlhw_handle_to_bo(qdev, file_priv, reloc.dst_handle, &reloc_list); if (!reloc_dst_bo) { qxl_bo_list_unreserve(&reloc_list, true); qxl_release_unreserve(qdev, release); qxl_release_free(qdev, release); return -EINVAL; } reloc_dst_offset = 0; } else { reloc_dst_bo = cmd_bo; reloc_dst_offset = release->release_offset; } /* reserve and validate the reloc dst bo */ if (reloc.reloc_type == QXL_RELOC_TYPE_BO || reloc.src_handle > 0) { reloc_src_bo = qxlhw_handle_to_bo(qdev, file_priv, reloc.src_handle, &reloc_list); if (!reloc_src_bo) { if (reloc_dst_bo != cmd_bo) drm_gem_object_unreference_unlocked(&reloc_dst_bo->gem_base); qxl_bo_list_unreserve(&reloc_list, true); qxl_release_unreserve(qdev, release); qxl_release_free(qdev, release); return -EINVAL; } } else reloc_src_bo = NULL; if (reloc.reloc_type == QXL_RELOC_TYPE_BO) { apply_reloc(qdev, reloc_dst_bo, reloc_dst_offset + reloc.dst_offset, reloc_src_bo, reloc.src_offset); } else if (reloc.reloc_type == QXL_RELOC_TYPE_SURF) { apply_surf_reloc(qdev, reloc_dst_bo, reloc_dst_offset + reloc.dst_offset, reloc_src_bo); } else { DRM_ERROR("unknown reloc type %d\n", reloc.reloc_type); return -EINVAL; } if (reloc_src_bo && reloc_src_bo != cmd_bo) { qxl_release_add_res(qdev, release, reloc_src_bo); drm_gem_object_unreference_unlocked(&reloc_src_bo->gem_base); } if (reloc_dst_bo != cmd_bo) drm_gem_object_unreference_unlocked(&reloc_dst_bo->gem_base); } qxl_fence_releaseable(qdev, release); ret = qxl_push_command_ring_release(qdev, release, user_cmd.type, true); if (ret == -ERESTARTSYS) { qxl_release_unreserve(qdev, release); qxl_release_free(qdev, release); qxl_bo_list_unreserve(&reloc_list, true); return ret; } qxl_release_unreserve(qdev, release); } qxl_bo_list_unreserve(&reloc_list, 0); return 0; }