47 static void vmw_resource_to_validate_list(
struct vmw_sw_context *sw_context,
72 static int vmw_bo_to_validate_list(
struct vmw_sw_context *sw_context,
83 DRM_ERROR(
"Max number of DMA buffers per submission"
88 val_buf = &sw_context->
val_bufs[val_node];
91 val_buf->
bo = ttm_bo_reference(bo);
101 *p_val_node = val_node;
125 DRM_ERROR(
"Could not find or use context %u\n",
126 (
unsigned)
cmd->cid);
133 vmw_resource_to_validate_list(sw_context, &ctx);
138 static int vmw_cmd_sid_check(
struct vmw_private *dev_priv,
159 DRM_ERROR(
"Could ot find or use surface 0x%08x "
162 (
unsigned long) sid);
169 DRM_ERROR(
"Could not validate surface.\n");
170 vmw_surface_unreference(&srf);
180 vmw_resource_to_validate_list(sw_context, &res);
186 static int vmw_cmd_set_render_target_check(
struct vmw_private *dev_priv,
196 ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
201 ret = vmw_cmd_sid_check(dev_priv, sw_context, &
cmd->body.target.sid);
205 static int vmw_cmd_surface_copy_check(
struct vmw_private *dev_priv,
216 ret = vmw_cmd_sid_check(dev_priv, sw_context, &
cmd->body.src.sid);
219 return vmw_cmd_sid_check(dev_priv, sw_context, &
cmd->body.dest.sid);
222 static int vmw_cmd_stretch_blt_check(
struct vmw_private *dev_priv,
233 ret = vmw_cmd_sid_check(dev_priv, sw_context, &
cmd->body.src.sid);
236 return vmw_cmd_sid_check(dev_priv, sw_context, &
cmd->body.dest.sid);
239 static int vmw_cmd_blt_surf_screen_check(
struct vmw_private *dev_priv,
251 DRM_ERROR(
"Kernel only SVGA3d command: %u.\n",
cmd->header.id);
255 return vmw_cmd_sid_check(dev_priv, sw_context, &
cmd->body.srcImage.sid);
258 static int vmw_cmd_present_check(
struct vmw_private *dev_priv,
271 DRM_ERROR(
"Kernel only SVGA3d command: %u.\n",
cmd->header.id);
275 return vmw_cmd_sid_check(dev_priv, sw_context, &
cmd->body.sid);
294 static int vmw_query_bo_switch_prepare(
struct vmw_private *dev_priv,
300 bool add_cid =
false;
306 DRM_ERROR(
"Query buffer too large.\n");
314 ret = vmw_bo_to_validate_list(sw_context,
323 ret = vmw_bo_to_validate_list(sw_context,
347 ret = vmw_bo_to_validate_list(sw_context,
376 static void vmw_query_bo_switch_commit(
struct vmw_private *dev_priv,
397 DRM_ERROR(
"Out of fifo space for dummy query.\n");
431 static void vmw_query_switch_backoff(
struct vmw_sw_context *sw_context)
440 static int vmw_translate_guest_ptr(
struct vmw_private *dev_priv,
453 DRM_ERROR(
"Could not find or use GMR region.\n");
459 DRM_ERROR(
"Max number relocations per submission"
477 vmw_dmabuf_unreference(&vmw_bo);
482 static int vmw_cmd_end_query(
struct vmw_private *dev_priv,
487 struct vmw_query_cmd {
494 ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
498 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
504 ret = vmw_query_bo_switch_prepare(dev_priv,
cmd->q.cid,
505 &vmw_bo->
base, sw_context);
507 vmw_dmabuf_unreference(&vmw_bo);
511 static int vmw_cmd_wait_query(
struct vmw_private *dev_priv,
516 struct vmw_query_cmd {
524 ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
528 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
534 vmw_dmabuf_unreference(&vmw_bo);
548 static int vmw_cmd_dma(
struct vmw_private *dev_priv,
563 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
571 cmd->dma.host.sid, &srf);
573 DRM_ERROR(
"could not find surface\n");
580 DRM_ERROR(
"Culd not validate surface.\n");
581 goto out_no_validate;
587 cmd->dma.host.sid = srf->
res.id;
590 vmw_dmabuf_unreference(&vmw_bo);
593 vmw_resource_to_validate_list(sw_context, &res);
598 vmw_surface_unreference(&srf);
600 vmw_dmabuf_unreference(&vmw_bo);
604 static int vmw_cmd_draw(
struct vmw_private *dev_priv,
608 struct vmw_draw_cmd {
613 (
unsigned long)header +
sizeof(*cmd));
619 ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
624 maxnum = (header->
size -
sizeof(
cmd->body)) /
sizeof(*decl);
627 DRM_ERROR(
"Illegal number of vertex declarations.\n");
631 for (i = 0; i <
cmd->body.numVertexDecls; ++
i, ++decl) {
632 ret = vmw_cmd_sid_check(dev_priv, sw_context,
638 maxnum = (header->
size -
sizeof(
cmd->body) -
639 cmd->body.numVertexDecls *
sizeof(*decl)) /
sizeof(*range);
641 DRM_ERROR(
"Illegal number of index ranges.\n");
646 for (i = 0; i <
cmd->body.numRanges; ++
i, ++
range) {
647 ret = vmw_cmd_sid_check(dev_priv, sw_context,
656 static int vmw_cmd_tex_state(
struct vmw_private *dev_priv,
660 struct vmw_tex_state_cmd {
666 ((
unsigned long) header + header->
size +
sizeof(header));
668 ((
unsigned long) header +
sizeof(
struct vmw_tex_state_cmd));
671 ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
675 for (; cur_state < last_state; ++cur_state) {
679 ret = vmw_cmd_sid_check(dev_priv, sw_context,
688 static int vmw_cmd_check_define_gmrfb(
struct vmw_private *dev_priv,
700 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
706 vmw_dmabuf_unreference(&vmw_bo);
711 static int vmw_cmd_check_not_3d(
struct vmw_private *dev_priv,
733 DRM_ERROR(
"Unsupported SVGA command: %u.\n", cmd_id);
737 if (*size > size_remaining) {
738 DRM_ERROR(
"Invalid SVGA command (size mismatch):"
744 DRM_ERROR(
"Kernel only SVGA command: %u.\n", cmd_id);
749 return vmw_cmd_check_define_gmrfb(dev_priv, sw_context, buf);
758 #define VMW_CMD_DEF(cmd, func) \
759 [cmd - SVGA_3D_CMD_BASE] = func
773 &vmw_cmd_set_render_target_check),
793 &vmw_cmd_blt_surf_screen_check)
796 static int vmw_cmd_check(
struct vmw_private *dev_priv,
808 return vmw_cmd_check_not_3d(dev_priv, sw_context, buf, size);
815 if (
unlikely(*size > size_remaining))
821 ret = vmw_cmd_funcs[cmd_id](dev_priv, sw_context, header);
827 DRM_ERROR(
"Illegal / Invalid SVGA3D command: %d\n",
832 static int vmw_cmd_check_all(
struct vmw_private *dev_priv,
840 while (cur_size > 0) {
842 ret = vmw_cmd_check(dev_priv, sw_context, buf, &size);
845 buf = (
void *)((
unsigned long) buf +
size);
850 DRM_ERROR(
"Command verifier out of sync.\n");
857 static void vmw_free_relocations(
struct vmw_sw_context *sw_context)
862 static void vmw_apply_relocations(
struct vmw_sw_context *sw_context)
870 reloc = &sw_context->
relocs[
i];
879 vmw_free_relocations(sw_context);
882 static void vmw_clear_validations(
struct vmw_sw_context *sw_context)
910 static int vmw_validate_single_buffer(
struct vmw_private *dev_priv,
941 DRM_INFO(
"Falling through to VRAM.\n");
947 static int vmw_validate_buffers(
struct vmw_private *dev_priv,
954 ret = vmw_validate_single_buffer(dev_priv, entry->
bo);
961 static int vmw_resize_cmd_bounce(
struct vmw_sw_context *sw_context,
982 DRM_ERROR(
"Failed to allocate command bounce buffer.\n");
1008 bool synced =
false;
1015 DRM_ERROR(
"Fence submission error. Syncing.\n");
1019 if (p_handle !=
NULL)
1029 if (
unlikely(ret != 0 && !synced)) {
1069 if (user_fence_rep ==
NULL)
1072 memset(&fence_rep, 0,
sizeof(fence_rep));
1078 fence_rep.
handle = fence_handle;
1099 DRM_ERROR(
"Fence copy error. Syncing.\n");
1108 void __user *user_commands,
1109 void *kernel_commands,
1125 if (kernel_commands ==
NULL) {
1126 sw_context->
kernel =
false;
1128 ret = vmw_resize_cmd_bounce(sw_context, command_size);
1134 user_commands, command_size);
1138 DRM_ERROR(
"Failed copying commands.\n");
1143 sw_context->
kernel =
true;
1159 ret = vmw_cmd_check_all(dev_priv, sw_context, kernel_commands,
1168 ret = vmw_validate_buffers(dev_priv, sw_context);
1172 vmw_apply_relocations(sw_context);
1184 DRM_ERROR(
"Failed reserving fifo space for commands.\n");
1189 memcpy(cmd, kernel_commands, command_size);
1192 vmw_query_bo_switch_commit(dev_priv, sw_context);
1195 (user_fence_rep) ? &handle :
NULL);
1203 DRM_ERROR(
"Fence submission error. Syncing.\n");
1208 vmw_clear_validations(sw_context);
1210 user_fence_rep, fence, handle);
1216 }
else if (
likely(fence != NULL)) {
1224 vmw_free_relocations(sw_context);
1226 vmw_query_switch_backoff(sw_context);
1228 vmw_clear_validations(sw_context);
1243 static void vmw_execbuf_unpin_panic(
struct vmw_private *dev_priv)
1245 DRM_ERROR(
"Can't unpin query buffer. Trying to recover.\n");
1276 bool only_on_cid_match,
uint32_t cid)
1288 if (only_on_cid_match && cid != dev_priv->
query_cid)
1291 INIT_LIST_HEAD(&validate_list);
1295 pinned_val.
bo = ttm_bo_reference(dev_priv->
pinned_bo);
1307 vmw_execbuf_unpin_panic(dev_priv);
1308 goto out_no_reserve;
1313 vmw_execbuf_unpin_panic(dev_priv);
1343 struct drm_file *file_priv)
1358 DRM_ERROR(
"Incorrect execbuf version.\n");
1359 DRM_ERROR(
"You're running outdated experimental "
1360 "vmwgfx user-space drivers.");