Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 1 | #ifndef __DRM_GEM_CMA_HELPER_H__ |
| 2 | #define __DRM_GEM_CMA_HELPER_H__ |
| 3 | |
Shawn Guo | 740c22a | 2014-03-24 20:14:48 +0800 | [diff] [blame] | 4 | #include <drm/drmP.h> |
Daniel Vetter | d9fc941 | 2014-09-23 15:46:53 +0200 | [diff] [blame] | 5 | #include <drm/drm_gem.h> |
Shawn Guo | 740c22a | 2014-03-24 20:14:48 +0800 | [diff] [blame] | 6 | |
Thierry Reding | d7883f8 | 2014-11-03 13:56:55 +0100 | [diff] [blame] | 7 | /** |
| 8 | * struct drm_gem_cma_object - GEM object backed by CMA memory allocations |
| 9 | * @base: base GEM object |
| 10 | * @paddr: physical address of the backing memory |
| 11 | * @sgt: scatter/gather table for imported PRIME buffers |
| 12 | * @vaddr: kernel virtual address of the backing memory |
| 13 | */ |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 14 | struct drm_gem_cma_object { |
| 15 | struct drm_gem_object base; |
| 16 | dma_addr_t paddr; |
Laurent Pinchart | 71d7282 | 2013-02-17 01:57:30 +0100 | [diff] [blame] | 17 | struct sg_table *sgt; |
| 18 | |
| 19 | /* For objects with DMA memory allocated by GEM CMA */ |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 20 | void *vaddr; |
| 21 | }; |
| 22 | |
| 23 | static inline struct drm_gem_cma_object * |
| 24 | to_drm_gem_cma_obj(struct drm_gem_object *gem_obj) |
| 25 | { |
| 26 | return container_of(gem_obj, struct drm_gem_cma_object, base); |
| 27 | } |
| 28 | |
Thierry Reding | d7883f8 | 2014-11-03 13:56:55 +0100 | [diff] [blame] | 29 | /* free GEM object */ |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 30 | void drm_gem_cma_free_object(struct drm_gem_object *gem_obj); |
| 31 | |
Thierry Reding | d7883f8 | 2014-11-03 13:56:55 +0100 | [diff] [blame] | 32 | /* create memory region for DRM framebuffer */ |
Thierry Reding | 6d17829 | 2014-11-03 11:48:49 +0100 | [diff] [blame] | 33 | int drm_gem_cma_dumb_create_internal(struct drm_file *file_priv, |
| 34 | struct drm_device *drm, |
| 35 | struct drm_mode_create_dumb *args); |
| 36 | |
| 37 | /* create memory region for DRM framebuffer */ |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 38 | int drm_gem_cma_dumb_create(struct drm_file *file_priv, |
Thierry Reding | d7883f8 | 2014-11-03 13:56:55 +0100 | [diff] [blame] | 39 | struct drm_device *drm, |
| 40 | struct drm_mode_create_dumb *args); |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 41 | |
Thierry Reding | d7883f8 | 2014-11-03 13:56:55 +0100 | [diff] [blame] | 42 | /* map memory region for DRM framebuffer to user space */ |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 43 | int drm_gem_cma_dumb_map_offset(struct drm_file *file_priv, |
Thierry Reding | d7883f8 | 2014-11-03 13:56:55 +0100 | [diff] [blame] | 44 | struct drm_device *drm, u32 handle, |
| 45 | u64 *offset); |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 46 | |
Thierry Reding | d7883f8 | 2014-11-03 13:56:55 +0100 | [diff] [blame] | 47 | /* set vm_flags and we can change the VM attribute to other one at here */ |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 48 | int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma); |
| 49 | |
Thierry Reding | d7883f8 | 2014-11-03 13:56:55 +0100 | [diff] [blame] | 50 | /* allocate physical memory */ |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 51 | struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, |
Thierry Reding | d7883f8 | 2014-11-03 13:56:55 +0100 | [diff] [blame] | 52 | size_t size); |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 53 | |
| 54 | extern const struct vm_operations_struct drm_gem_cma_vm_ops; |
| 55 | |
Rob Clark | 6f64609 | 2012-12-10 10:46:43 -0600 | [diff] [blame] | 56 | #ifdef CONFIG_DEBUG_FS |
| 57 | void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m); |
| 58 | #endif |
| 59 | |
Joonyoung Shim | 78467dc | 2013-06-28 14:24:54 +0900 | [diff] [blame] | 60 | struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj); |
| 61 | struct drm_gem_object * |
Maarten Lankhorst | b5e9c1a | 2014-01-09 11:03:14 +0100 | [diff] [blame] | 62 | drm_gem_cma_prime_import_sg_table(struct drm_device *dev, |
| 63 | struct dma_buf_attachment *attach, |
Joonyoung Shim | 78467dc | 2013-06-28 14:24:54 +0900 | [diff] [blame] | 64 | struct sg_table *sgt); |
| 65 | int drm_gem_cma_prime_mmap(struct drm_gem_object *obj, |
| 66 | struct vm_area_struct *vma); |
| 67 | void *drm_gem_cma_prime_vmap(struct drm_gem_object *obj); |
| 68 | void drm_gem_cma_prime_vunmap(struct drm_gem_object *obj, void *vaddr); |
| 69 | |
Sascha Hauer | b9d4745 | 2012-06-27 15:30:18 +0200 | [diff] [blame] | 70 | #endif /* __DRM_GEM_CMA_HELPER_H__ */ |