diff options
author | Jakob Bornecrantz <jakob@vmware.com> | 2011-10-04 14:13:19 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2011-10-05 05:17:12 -0400 |
commit | 4084fb89e6b463686219a2369d1d35e6b78f785d (patch) | |
tree | 31dbf772059fa6c77f6701d98081d605829344e1 /drivers/gpu/drm | |
parent | 5deb65cf83ae5aaf4cdfdd85f0ab3117594d9b00 (diff) |
vmwgfx: Expand the command checker to cover screen object commands
Signed-off-by: Jakob Bornecrantz <jakob@vmware.com>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm')
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 77 |
1 files changed, 72 insertions, 5 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c index 542c852f8eb5..c98c3475a9f8 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | |||
@@ -450,6 +450,73 @@ static int vmw_cmd_tex_state(struct vmw_private *dev_priv, | |||
450 | return 0; | 450 | return 0; |
451 | } | 451 | } |
452 | 452 | ||
453 | static int vmw_cmd_check_define_gmrfb(struct vmw_private *dev_priv, | ||
454 | struct vmw_sw_context *sw_context, | ||
455 | void *buf) | ||
456 | { | ||
457 | struct vmw_dma_buffer *vmw_bo; | ||
458 | int ret; | ||
459 | |||
460 | struct { | ||
461 | uint32_t header; | ||
462 | SVGAFifoCmdDefineGMRFB body; | ||
463 | } *cmd = buf; | ||
464 | |||
465 | ret = vmw_translate_guest_ptr(dev_priv, sw_context, | ||
466 | &cmd->body.ptr, | ||
467 | &vmw_bo); | ||
468 | if (unlikely(ret != 0)) | ||
469 | return ret; | ||
470 | |||
471 | vmw_dmabuf_unreference(&vmw_bo); | ||
472 | |||
473 | return ret; | ||
474 | } | ||
475 | |||
476 | static int vmw_cmd_check_not_3d(struct vmw_private *dev_priv, | ||
477 | struct vmw_sw_context *sw_context, | ||
478 | void *buf, uint32_t *size) | ||
479 | { | ||
480 | uint32_t size_remaining = *size; | ||
481 | bool need_kernel = true; | ||
482 | uint32_t cmd_id; | ||
483 | |||
484 | cmd_id = le32_to_cpu(((uint32_t *)buf)[0]); | ||
485 | switch (cmd_id) { | ||
486 | case SVGA_CMD_UPDATE: | ||
487 | *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdUpdate); | ||
488 | need_kernel = false; | ||
489 | break; | ||
490 | case SVGA_CMD_DEFINE_GMRFB: | ||
491 | *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdDefineGMRFB); | ||
492 | break; | ||
493 | case SVGA_CMD_BLIT_GMRFB_TO_SCREEN: | ||
494 | *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdBlitGMRFBToScreen); | ||
495 | break; | ||
496 | case SVGA_CMD_BLIT_SCREEN_TO_GMRFB: | ||
497 | *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdBlitGMRFBToScreen); | ||
498 | break; | ||
499 | default: | ||
500 | DRM_ERROR("Unsupported SVGA command: %u.\n", cmd_id); | ||
501 | return -EINVAL; | ||
502 | } | ||
503 | |||
504 | if (*size > size_remaining) { | ||
505 | DRM_ERROR("Invalid SVGA command (size mismatch):" | ||
506 | " %u.\n", cmd_id); | ||
507 | return -EINVAL; | ||
508 | } | ||
509 | |||
510 | if (unlikely(need_kernel && !sw_context->kernel)) { | ||
511 | DRM_ERROR("Kernel only SVGA command: %u.\n", cmd_id); | ||
512 | return -EPERM; | ||
513 | } | ||
514 | |||
515 | if (cmd_id == SVGA_CMD_DEFINE_GMRFB) | ||
516 | return vmw_cmd_check_define_gmrfb(dev_priv, sw_context, buf); | ||
517 | |||
518 | return 0; | ||
519 | } | ||
453 | 520 | ||
454 | typedef int (*vmw_cmd_func) (struct vmw_private *, | 521 | typedef int (*vmw_cmd_func) (struct vmw_private *, |
455 | struct vmw_sw_context *, | 522 | struct vmw_sw_context *, |
@@ -502,11 +569,11 @@ static int vmw_cmd_check(struct vmw_private *dev_priv, | |||
502 | SVGA3dCmdHeader *header = (SVGA3dCmdHeader *) buf; | 569 | SVGA3dCmdHeader *header = (SVGA3dCmdHeader *) buf; |
503 | int ret; | 570 | int ret; |
504 | 571 | ||
505 | cmd_id = ((uint32_t *)buf)[0]; | 572 | cmd_id = le32_to_cpu(((uint32_t *)buf)[0]); |
506 | if (cmd_id == SVGA_CMD_UPDATE) { | 573 | /* Handle any none 3D commands */ |
507 | *size = 5 << 2; | 574 | if (unlikely(cmd_id < SVGA_CMD_MAX)) |
508 | return 0; | 575 | return vmw_cmd_check_not_3d(dev_priv, sw_context, buf, size); |
509 | } | 576 | |
510 | 577 | ||
511 | cmd_id = le32_to_cpu(header->id); | 578 | cmd_id = le32_to_cpu(header->id); |
512 | *size = le32_to_cpu(header->size) + sizeof(SVGA3dCmdHeader); | 579 | *size = le32_to_cpu(header->size) + sizeof(SVGA3dCmdHeader); |