1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
7 #include <linux/dma-buf.h>
9 #include <drm/drm_prime.h>
14 struct sg_table
*msm_gem_prime_get_sg_table(struct drm_gem_object
*obj
)
16 struct msm_gem_object
*msm_obj
= to_msm_bo(obj
);
17 int npages
= obj
->size
>> PAGE_SHIFT
;
19 if (WARN_ON(!msm_obj
->pages
)) /* should have already pinned! */
22 return drm_prime_pages_to_sg(obj
->dev
, msm_obj
->pages
, npages
);
25 int msm_gem_prime_vmap(struct drm_gem_object
*obj
, struct dma_buf_map
*map
)
29 vaddr
= msm_gem_get_vaddr(obj
);
31 return PTR_ERR(vaddr
);
32 dma_buf_map_set_vaddr(map
, vaddr
);
37 void msm_gem_prime_vunmap(struct drm_gem_object
*obj
, struct dma_buf_map
*map
)
39 msm_gem_put_vaddr(obj
);
42 int msm_gem_prime_mmap(struct drm_gem_object
*obj
, struct vm_area_struct
*vma
)
46 ret
= drm_gem_mmap_obj(obj
, obj
->size
, vma
);
50 return msm_gem_mmap_obj(vma
->vm_private_data
, vma
);
53 struct drm_gem_object
*msm_gem_prime_import_sg_table(struct drm_device
*dev
,
54 struct dma_buf_attachment
*attach
, struct sg_table
*sg
)
56 return msm_gem_import(dev
, attach
->dmabuf
, sg
);
59 int msm_gem_prime_pin(struct drm_gem_object
*obj
)
61 if (!obj
->import_attach
)
62 msm_gem_get_pages(obj
);
66 void msm_gem_prime_unpin(struct drm_gem_object
*obj
)
68 if (!obj
->import_attach
)
69 msm_gem_put_pages(obj
);