xref: /linux/drivers/gpu/drm/exynos/exynos_drm_gem.h (revision 2364839a1aca677842b0dfd7ed0449acda3c3175)
11c248b7dSInki Dae /* exynos_drm_gem.h
21c248b7dSInki Dae  *
31c248b7dSInki Dae  * Copyright (c) 2011 Samsung Electronics Co., Ltd.
41c248b7dSInki Dae  * Authoer: Inki Dae <inki.dae@samsung.com>
51c248b7dSInki Dae  *
61c248b7dSInki Dae  * Permission is hereby granted, free of charge, to any person obtaining a
71c248b7dSInki Dae  * copy of this software and associated documentation files (the "Software"),
81c248b7dSInki Dae  * to deal in the Software without restriction, including without limitation
91c248b7dSInki Dae  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
101c248b7dSInki Dae  * and/or sell copies of the Software, and to permit persons to whom the
111c248b7dSInki Dae  * Software is furnished to do so, subject to the following conditions:
121c248b7dSInki Dae  *
131c248b7dSInki Dae  * The above copyright notice and this permission notice (including the next
141c248b7dSInki Dae  * paragraph) shall be included in all copies or substantial portions of the
151c248b7dSInki Dae  * Software.
161c248b7dSInki Dae  *
171c248b7dSInki Dae  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
181c248b7dSInki Dae  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
191c248b7dSInki Dae  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
201c248b7dSInki Dae  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
211c248b7dSInki Dae  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
221c248b7dSInki Dae  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
231c248b7dSInki Dae  * OTHER DEALINGS IN THE SOFTWARE.
241c248b7dSInki Dae  */
251c248b7dSInki Dae 
261c248b7dSInki Dae #ifndef _EXYNOS_DRM_GEM_H_
271c248b7dSInki Dae #define _EXYNOS_DRM_GEM_H_
281c248b7dSInki Dae 
291c248b7dSInki Dae #define to_exynos_gem_obj(x)	container_of(x,\
301c248b7dSInki Dae 			struct exynos_drm_gem_obj, base)
311c248b7dSInki Dae 
321c248b7dSInki Dae /*
332c871127SInki Dae  * exynos drm gem buffer structure.
342c871127SInki Dae  *
352c871127SInki Dae  * @kvaddr: kernel virtual address to allocated memory region.
362c871127SInki Dae  * @dma_addr: bus address(accessed by dma) to allocated memory region.
372c871127SInki Dae  *	- this address could be physical address without IOMMU and
382c871127SInki Dae  *	device address with IOMMU.
392c871127SInki Dae  * @size: size of allocated memory region.
402c871127SInki Dae  */
412c871127SInki Dae struct exynos_drm_gem_buf {
422c871127SInki Dae 	void __iomem		*kvaddr;
432c871127SInki Dae 	dma_addr_t		dma_addr;
442c871127SInki Dae 	unsigned long		size;
452c871127SInki Dae };
462c871127SInki Dae 
472c871127SInki Dae /*
481c248b7dSInki Dae  * exynos drm buffer structure.
491c248b7dSInki Dae  *
501c248b7dSInki Dae  * @base: a gem object.
511c248b7dSInki Dae  *	- a new handle to this gem object would be created
521c248b7dSInki Dae  *	by drm_gem_handle_create().
532c871127SInki Dae  * @buffer: a pointer to exynos_drm_gem_buffer object.
542c871127SInki Dae  *	- contain the information to memory region allocated
552c871127SInki Dae  *	by user request or at framebuffer creation.
561c248b7dSInki Dae  *	continuous memory region allocated by user request
571c248b7dSInki Dae  *	or at framebuffer creation.
581c248b7dSInki Dae  *
591c248b7dSInki Dae  * P.S. this object would be transfered to user as kms_bo.handle so
601c248b7dSInki Dae  *	user can access the buffer through kms_bo.handle.
611c248b7dSInki Dae  */
621c248b7dSInki Dae struct exynos_drm_gem_obj {
631c248b7dSInki Dae 	struct drm_gem_object		base;
642c871127SInki Dae 	struct exynos_drm_gem_buf	*buffer;
651c248b7dSInki Dae };
661c248b7dSInki Dae 
67*2364839aSJoonyoung Shim /* destroy a buffer with gem object */
68*2364839aSJoonyoung Shim void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
69*2364839aSJoonyoung Shim 
70*2364839aSJoonyoung Shim /* create a new buffer with gem object */
71f088d5a9SInki Dae struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
72ee5e770eSJoonyoung Shim 						 unsigned long size);
731c248b7dSInki Dae 
741c248b7dSInki Dae /*
751c248b7dSInki Dae  * request gem object creation and buffer allocation as the size
761c248b7dSInki Dae  * that it is calculated with framebuffer information such as width,
771c248b7dSInki Dae  * height and bpp.
781c248b7dSInki Dae  */
791c248b7dSInki Dae int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
801c248b7dSInki Dae 				struct drm_file *file_priv);
811c248b7dSInki Dae 
821c248b7dSInki Dae /* get buffer offset to map to user space. */
831c248b7dSInki Dae int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
841c248b7dSInki Dae 				    struct drm_file *file_priv);
851c248b7dSInki Dae 
86ee5e770eSJoonyoung Shim /*
87ee5e770eSJoonyoung Shim  * mmap the physically continuous memory that a gem object contains
88ee5e770eSJoonyoung Shim  * to user space.
89ee5e770eSJoonyoung Shim  */
90ee5e770eSJoonyoung Shim int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
911c248b7dSInki Dae 			      struct drm_file *file_priv);
921c248b7dSInki Dae 
931c248b7dSInki Dae /* initialize gem object. */
941c248b7dSInki Dae int exynos_drm_gem_init_object(struct drm_gem_object *obj);
951c248b7dSInki Dae 
961c248b7dSInki Dae /* free gem object. */
971c248b7dSInki Dae void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
981c248b7dSInki Dae 
991c248b7dSInki Dae /* create memory region for drm framebuffer. */
1001c248b7dSInki Dae int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
101ee5e770eSJoonyoung Shim 			       struct drm_device *dev,
102ee5e770eSJoonyoung Shim 			       struct drm_mode_create_dumb *args);
1031c248b7dSInki Dae 
1041c248b7dSInki Dae /* map memory region for drm framebuffer to user space. */
1051c248b7dSInki Dae int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
106ee5e770eSJoonyoung Shim 				   struct drm_device *dev, uint32_t handle,
107ee5e770eSJoonyoung Shim 				   uint64_t *offset);
1081c248b7dSInki Dae 
1091c248b7dSInki Dae /*
1101c248b7dSInki Dae  * destroy memory region allocated.
1111c248b7dSInki Dae  *	- a gem handle and physical memory region pointed by a gem object
1121c248b7dSInki Dae  *	would be released by drm_gem_handle_delete().
1131c248b7dSInki Dae  */
1141c248b7dSInki Dae int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
115ee5e770eSJoonyoung Shim 				struct drm_device *dev,
116ee5e770eSJoonyoung Shim 				unsigned int handle);
117ee5e770eSJoonyoung Shim 
118ee5e770eSJoonyoung Shim /* page fault handler and mmap fault address(virtual) to physical memory. */
119ee5e770eSJoonyoung Shim int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
120ee5e770eSJoonyoung Shim 
121ee5e770eSJoonyoung Shim /* set vm_flags and we can change the vm attribute to other one at here. */
122ee5e770eSJoonyoung Shim int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1231c248b7dSInki Dae 
1241c248b7dSInki Dae #endif
125