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 32*dcf9af82SInki Dae #define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG) 33*dcf9af82SInki Dae 341c248b7dSInki Dae /* 352c871127SInki Dae * exynos drm gem buffer structure. 362c871127SInki Dae * 372c871127SInki Dae * @kvaddr: kernel virtual address to allocated memory region. 382c871127SInki Dae * @dma_addr: bus address(accessed by dma) to allocated memory region. 392c871127SInki Dae * - this address could be physical address without IOMMU and 402c871127SInki Dae * device address with IOMMU. 412b35892eSInki Dae * @sgt: sg table to transfer page data. 422b35892eSInki Dae * @pages: contain all pages to allocated memory region. 432c871127SInki Dae * @size: size of allocated memory region. 442c871127SInki Dae */ 452c871127SInki Dae struct exynos_drm_gem_buf { 462c871127SInki Dae void __iomem *kvaddr; 472c871127SInki Dae dma_addr_t dma_addr; 482b35892eSInki Dae struct sg_table *sgt; 492b35892eSInki Dae struct page **pages; 502c871127SInki Dae unsigned long size; 512c871127SInki Dae }; 522c871127SInki Dae 532c871127SInki Dae /* 541c248b7dSInki Dae * exynos drm buffer structure. 551c248b7dSInki Dae * 561c248b7dSInki Dae * @base: a gem object. 571c248b7dSInki Dae * - a new handle to this gem object would be created 581c248b7dSInki Dae * by drm_gem_handle_create(). 592c871127SInki Dae * @buffer: a pointer to exynos_drm_gem_buffer object. 602c871127SInki Dae * - contain the information to memory region allocated 612c871127SInki Dae * by user request or at framebuffer creation. 621c248b7dSInki Dae * continuous memory region allocated by user request 631c248b7dSInki Dae * or at framebuffer creation. 642b35892eSInki Dae * @size: total memory size to physically non-continuous memory region. 652b35892eSInki Dae * @flags: indicate memory type to allocated buffer and cache attruibute. 661c248b7dSInki Dae * 671c248b7dSInki Dae * P.S. this object would be transfered to user as kms_bo.handle so 681c248b7dSInki Dae * user can access the buffer through kms_bo.handle. 691c248b7dSInki Dae */ 701c248b7dSInki Dae struct exynos_drm_gem_obj { 711c248b7dSInki Dae struct drm_gem_object base; 722c871127SInki Dae struct exynos_drm_gem_buf *buffer; 732b35892eSInki Dae unsigned long size; 742b35892eSInki Dae unsigned int flags; 751c248b7dSInki Dae }; 761c248b7dSInki Dae 772364839aSJoonyoung Shim /* destroy a buffer with gem object */ 782364839aSJoonyoung Shim void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj); 792364839aSJoonyoung Shim 802364839aSJoonyoung Shim /* create a new buffer with gem object */ 81f088d5a9SInki Dae struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev, 822b35892eSInki Dae unsigned int flags, 83ee5e770eSJoonyoung Shim unsigned long size); 841c248b7dSInki Dae 851c248b7dSInki Dae /* 861c248b7dSInki Dae * request gem object creation and buffer allocation as the size 871c248b7dSInki Dae * that it is calculated with framebuffer information such as width, 881c248b7dSInki Dae * height and bpp. 891c248b7dSInki Dae */ 901c248b7dSInki Dae int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data, 911c248b7dSInki Dae struct drm_file *file_priv); 921c248b7dSInki Dae 93f0b1bda7SInki Dae /* 94f0b1bda7SInki Dae * get dma address from gem handle and this function could be used for 95f0b1bda7SInki Dae * other drivers such as 2d/3d acceleration drivers. 96f0b1bda7SInki Dae * with this function call, gem object reference count would be increased. 97f0b1bda7SInki Dae */ 98f0b1bda7SInki Dae void *exynos_drm_gem_get_dma_addr(struct drm_device *dev, 99f0b1bda7SInki Dae unsigned int gem_handle, 100f0b1bda7SInki Dae struct drm_file *file_priv); 101f0b1bda7SInki Dae 102f0b1bda7SInki Dae /* 103f0b1bda7SInki Dae * put dma address from gem handle and this function could be used for 104f0b1bda7SInki Dae * other drivers such as 2d/3d acceleration drivers. 105f0b1bda7SInki Dae * with this function call, gem object reference count would be decreased. 106f0b1bda7SInki Dae */ 107f0b1bda7SInki Dae void exynos_drm_gem_put_dma_addr(struct drm_device *dev, 108f0b1bda7SInki Dae unsigned int gem_handle, 109f0b1bda7SInki Dae struct drm_file *file_priv); 110f0b1bda7SInki Dae 1111c248b7dSInki Dae /* get buffer offset to map to user space. */ 1121c248b7dSInki Dae int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data, 1131c248b7dSInki Dae struct drm_file *file_priv); 1141c248b7dSInki Dae 115ee5e770eSJoonyoung Shim /* 116ee5e770eSJoonyoung Shim * mmap the physically continuous memory that a gem object contains 117ee5e770eSJoonyoung Shim * to user space. 118ee5e770eSJoonyoung Shim */ 119ee5e770eSJoonyoung Shim int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data, 1201c248b7dSInki Dae struct drm_file *file_priv); 1211c248b7dSInki Dae 1221c248b7dSInki Dae /* initialize gem object. */ 1231c248b7dSInki Dae int exynos_drm_gem_init_object(struct drm_gem_object *obj); 1241c248b7dSInki Dae 1251c248b7dSInki Dae /* free gem object. */ 1261c248b7dSInki Dae void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj); 1271c248b7dSInki Dae 1281c248b7dSInki Dae /* create memory region for drm framebuffer. */ 1291c248b7dSInki Dae int exynos_drm_gem_dumb_create(struct drm_file *file_priv, 130ee5e770eSJoonyoung Shim struct drm_device *dev, 131ee5e770eSJoonyoung Shim struct drm_mode_create_dumb *args); 1321c248b7dSInki Dae 1331c248b7dSInki Dae /* map memory region for drm framebuffer to user space. */ 1341c248b7dSInki Dae int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv, 135ee5e770eSJoonyoung Shim struct drm_device *dev, uint32_t handle, 136ee5e770eSJoonyoung Shim uint64_t *offset); 1371c248b7dSInki Dae 1381c248b7dSInki Dae /* 1391c248b7dSInki Dae * destroy memory region allocated. 1401c248b7dSInki Dae * - a gem handle and physical memory region pointed by a gem object 1411c248b7dSInki Dae * would be released by drm_gem_handle_delete(). 1421c248b7dSInki Dae */ 1431c248b7dSInki Dae int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv, 144ee5e770eSJoonyoung Shim struct drm_device *dev, 145ee5e770eSJoonyoung Shim unsigned int handle); 146ee5e770eSJoonyoung Shim 147ee5e770eSJoonyoung Shim /* page fault handler and mmap fault address(virtual) to physical memory. */ 148ee5e770eSJoonyoung Shim int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf); 149ee5e770eSJoonyoung Shim 150ee5e770eSJoonyoung Shim /* set vm_flags and we can change the vm attribute to other one at here. */ 151ee5e770eSJoonyoung Shim int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); 1521c248b7dSInki Dae 1531c248b7dSInki Dae #endif 154