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