diff options
author | Thomas Hellstrom <thellstrom@vmware.com> | 2013-11-28 03:28:30 -0500 |
---|---|---|
committer | Thomas Hellstrom <thellstrom@vmware.com> | 2013-12-04 15:03:50 -0500 |
commit | d69d51d73f9509dbb727e36a3a7ddac8b003ac6b (patch) | |
tree | 902daecf134df79a45ad5d9fabcbeba58b8da857 | |
parent | c6c1f325adc8a8e0cd06c6ad0ca232a6880a1783 (diff) |
drm/vmwgfx: Fix up and comment the dumb buffer implementation
Allocation was duplicating code. Comments were missing.
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c index efe2b74c5eb1..4381e270d032 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | |||
@@ -781,54 +781,55 @@ err_ref: | |||
781 | } | 781 | } |
782 | 782 | ||
783 | 783 | ||
784 | /** | ||
785 | * vmw_dumb_create - Create a dumb kms buffer | ||
786 | * | ||
787 | * @file_priv: Pointer to a struct drm_file identifying the caller. | ||
788 | * @dev: Pointer to the drm device. | ||
789 | * @args: Pointer to a struct drm_mode_create_dumb structure | ||
790 | * | ||
791 | * This is a driver callback for the core drm create_dumb functionality. | ||
792 | * Note that this is very similar to the vmw_dmabuf_alloc ioctl, except | ||
793 | * that the arguments have a different format. | ||
794 | */ | ||
784 | int vmw_dumb_create(struct drm_file *file_priv, | 795 | int vmw_dumb_create(struct drm_file *file_priv, |
785 | struct drm_device *dev, | 796 | struct drm_device *dev, |
786 | struct drm_mode_create_dumb *args) | 797 | struct drm_mode_create_dumb *args) |
787 | { | 798 | { |
788 | struct vmw_private *dev_priv = vmw_priv(dev); | 799 | struct vmw_private *dev_priv = vmw_priv(dev); |
789 | struct vmw_master *vmaster = vmw_master(file_priv->master); | 800 | struct vmw_master *vmaster = vmw_master(file_priv->master); |
790 | struct vmw_user_dma_buffer *vmw_user_bo; | 801 | struct vmw_dma_buffer *dma_buf; |
791 | struct ttm_buffer_object *tmp; | ||
792 | int ret; | 802 | int ret; |
793 | 803 | ||
794 | args->pitch = args->width * ((args->bpp + 7) / 8); | 804 | args->pitch = args->width * ((args->bpp + 7) / 8); |
795 | args->size = args->pitch * args->height; | 805 | args->size = args->pitch * args->height; |
796 | 806 | ||
797 | vmw_user_bo = kzalloc(sizeof(*vmw_user_bo), GFP_KERNEL); | ||
798 | if (vmw_user_bo == NULL) | ||
799 | return -ENOMEM; | ||
800 | |||
801 | ret = ttm_read_lock(&vmaster->lock, true); | 807 | ret = ttm_read_lock(&vmaster->lock, true); |
802 | if (ret != 0) { | 808 | if (unlikely(ret != 0)) |
803 | kfree(vmw_user_bo); | ||
804 | return ret; | 809 | return ret; |
805 | } | ||
806 | |||
807 | ret = vmw_dmabuf_init(dev_priv, &vmw_user_bo->dma, args->size, | ||
808 | &vmw_vram_sys_placement, true, | ||
809 | &vmw_user_dmabuf_destroy); | ||
810 | if (ret != 0) | ||
811 | goto out_no_dmabuf; | ||
812 | 810 | ||
813 | tmp = ttm_bo_reference(&vmw_user_bo->dma.base); | 811 | ret = vmw_user_dmabuf_alloc(dev_priv, vmw_fpriv(file_priv)->tfile, |
814 | ret = ttm_prime_object_init(vmw_fpriv(file_priv)->tfile, | 812 | args->size, false, &args->handle, |
815 | args->size, | 813 | &dma_buf); |
816 | &vmw_user_bo->prime, | ||
817 | false, | ||
818 | ttm_buffer_type, | ||
819 | &vmw_user_dmabuf_release, NULL); | ||
820 | if (unlikely(ret != 0)) | 814 | if (unlikely(ret != 0)) |
821 | goto out_no_base_object; | 815 | goto out_no_dmabuf; |
822 | |||
823 | args->handle = vmw_user_bo->prime.base.hash.key; | ||
824 | 816 | ||
825 | out_no_base_object: | 817 | vmw_dmabuf_unreference(&dma_buf); |
826 | ttm_bo_unref(&tmp); | ||
827 | out_no_dmabuf: | 818 | out_no_dmabuf: |
828 | ttm_read_unlock(&vmaster->lock); | 819 | ttm_read_unlock(&vmaster->lock); |
829 | return ret; | 820 | return ret; |
830 | } | 821 | } |
831 | 822 | ||
823 | /** | ||
824 | * vmw_dumb_map_offset - Return the address space offset of a dumb buffer | ||
825 | * | ||
826 | * @file_priv: Pointer to a struct drm_file identifying the caller. | ||
827 | * @dev: Pointer to the drm device. | ||
828 | * @handle: Handle identifying the dumb buffer. | ||
829 | * @offset: The address space offset returned. | ||
830 | * | ||
831 | * This is a driver callback for the core drm dumb_map_offset functionality. | ||
832 | */ | ||
832 | int vmw_dumb_map_offset(struct drm_file *file_priv, | 833 | int vmw_dumb_map_offset(struct drm_file *file_priv, |
833 | struct drm_device *dev, uint32_t handle, | 834 | struct drm_device *dev, uint32_t handle, |
834 | uint64_t *offset) | 835 | uint64_t *offset) |
@@ -846,6 +847,15 @@ int vmw_dumb_map_offset(struct drm_file *file_priv, | |||
846 | return 0; | 847 | return 0; |
847 | } | 848 | } |
848 | 849 | ||
850 | /** | ||
851 | * vmw_dumb_destroy - Destroy a dumb boffer | ||
852 | * | ||
853 | * @file_priv: Pointer to a struct drm_file identifying the caller. | ||
854 | * @dev: Pointer to the drm device. | ||
855 | * @handle: Handle identifying the dumb buffer. | ||
856 | * | ||
857 | * This is a driver callback for the core drm dumb_destroy functionality. | ||
858 | */ | ||
849 | int vmw_dumb_destroy(struct drm_file *file_priv, | 859 | int vmw_dumb_destroy(struct drm_file *file_priv, |
850 | struct drm_device *dev, | 860 | struct drm_device *dev, |
851 | uint32_t handle) | 861 | uint32_t handle) |