blob: 49b5ef1179b08f7257a37e05922011ad16d68d6f [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/* exynos_drm_gem.h
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Authoer: Inki Dae <inki.dae@samsung.com>
5 *
Inki Daed81aecb2012-12-18 02:30:17 +09006 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
Inki Dae1c248b72011-10-04 19:19:01 +090010 */
11
12#ifndef _EXYNOS_DRM_GEM_H_
13#define _EXYNOS_DRM_GEM_H_
14
Daniel Vetterd9fc9412014-09-23 15:46:53 +020015#include <drm/drm_gem.h>
16
Inki Dae1c248b72011-10-04 19:19:01 +090017#define to_exynos_gem_obj(x) container_of(x,\
18 struct exynos_drm_gem_obj, base)
19
Inki Daedcf9af82012-04-03 21:27:58 +090020#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
21
Inki Dae1c248b72011-10-04 19:19:01 +090022/*
Inki Dae2c871122011-11-12 15:23:32 +090023 * exynos drm gem buffer structure.
24 *
Carlo Caionea5d7ac302015-02-04 10:23:19 +010025 * @cookie: cookie returned by dma_alloc_attrs
Inki Dae2c871122011-11-12 15:23:32 +090026 * @kvaddr: kernel virtual address to allocated memory region.
27 * @dma_addr: bus address(accessed by dma) to allocated memory region.
28 * - this address could be physical address without IOMMU and
29 * device address with IOMMU.
Inki Dae4744ad22012-12-07 17:51:27 +090030 * @pages: Array of backing pages.
Inki Dae2c871122011-11-12 15:23:32 +090031 * @size: size of allocated memory region.
32 */
33struct exynos_drm_gem_buf {
Carlo Caionea5d7ac302015-02-04 10:23:19 +010034 void *cookie;
Inki Dae2c871122011-11-12 15:23:32 +090035 void __iomem *kvaddr;
36 dma_addr_t dma_addr;
Inki Dae0519f9a2012-10-20 07:53:42 -070037 struct dma_attrs dma_attrs;
Inki Dae4744ad22012-12-07 17:51:27 +090038 struct page **pages;
Inki Dae2c871122011-11-12 15:23:32 +090039 unsigned long size;
40};
41
42/*
Inki Dae1c248b72011-10-04 19:19:01 +090043 * exynos drm buffer structure.
44 *
45 * @base: a gem object.
46 * - a new handle to this gem object would be created
47 * by drm_gem_handle_create().
Inki Dae2c871122011-11-12 15:23:32 +090048 * @buffer: a pointer to exynos_drm_gem_buffer object.
49 * - contain the information to memory region allocated
50 * by user request or at framebuffer creation.
Inki Dae1c248b72011-10-04 19:19:01 +090051 * continuous memory region allocated by user request
52 * or at framebuffer creation.
Inki Dae3c52b882012-06-29 16:28:17 +090053 * @size: size requested from user, in bytes and this size is aligned
54 * in page unit.
Inki Dae2b358922012-03-16 18:47:05 +090055 * @flags: indicate memory type to allocated buffer and cache attruibute.
Inki Dae1c248b72011-10-04 19:19:01 +090056 *
Masanari Iidac6b78bc2013-10-24 16:02:57 +090057 * P.S. this object would be transferred to user as kms_bo.handle so
Inki Dae1c248b72011-10-04 19:19:01 +090058 * user can access the buffer through kms_bo.handle.
59 */
60struct exynos_drm_gem_obj {
Joonyoung Shimee5e7702011-12-13 14:20:23 +090061 struct drm_gem_object base;
62 struct exynos_drm_gem_buf *buffer;
Inki Dae2b358922012-03-16 18:47:05 +090063 unsigned long size;
64 unsigned int flags;
Inki Dae1c248b72011-10-04 19:19:01 +090065};
66
Inki Daeb2df26c2012-04-23 21:01:28 +090067struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
68
Joonyoung Shim23648392011-12-13 14:39:13 +090069/* destroy a buffer with gem object */
70void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
71
Inki Daeb2df26c2012-04-23 21:01:28 +090072/* create a private gem object and initialize it. */
73struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
74 unsigned long size);
75
Joonyoung Shim23648392011-12-13 14:39:13 +090076/* create a new buffer with gem object */
Inki Daef088d5a2011-11-12 14:51:23 +090077struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
Inki Dae2b358922012-03-16 18:47:05 +090078 unsigned int flags,
79 unsigned long size);
Inki Dae1c248b72011-10-04 19:19:01 +090080
81/*
82 * request gem object creation and buffer allocation as the size
83 * that it is calculated with framebuffer information such as width,
84 * height and bpp.
85 */
86int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
Joonyoung Shimee5e7702011-12-13 14:20:23 +090087 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +090088
Inki Daef0b1bda2012-03-16 18:47:06 +090089/*
90 * get dma address from gem handle and this function could be used for
91 * other drivers such as 2d/3d acceleration drivers.
92 * with this function call, gem object reference count would be increased.
93 */
Inki Daed87342c2012-11-03 21:53:24 -070094dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
Inki Daef0b1bda2012-03-16 18:47:06 +090095 unsigned int gem_handle,
Inki Daed87342c2012-11-03 21:53:24 -070096 struct drm_file *filp);
Inki Daef0b1bda2012-03-16 18:47:06 +090097
98/*
99 * put dma address from gem handle and this function could be used for
100 * other drivers such as 2d/3d acceleration drivers.
101 * with this function call, gem object reference count would be decreased.
102 */
103void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
104 unsigned int gem_handle,
Inki Daed87342c2012-11-03 21:53:24 -0700105 struct drm_file *filp);
Inki Daef0b1bda2012-03-16 18:47:06 +0900106
Inki Dae2a3098f2012-11-04 05:48:52 -0800107/* map user space allocated by malloc to pages. */
108int exynos_drm_gem_userptr_ioctl(struct drm_device *dev, void *data,
109 struct drm_file *file_priv);
110
Inki Dae40cd7e02012-05-04 15:51:17 +0900111/* get buffer information to memory region allocated by gem. */
112int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
113 struct drm_file *file_priv);
114
Inki Daea4f19aa2013-03-11 21:15:59 +0900115/* get buffer size to gem handle. */
116unsigned long exynos_drm_gem_get_size(struct drm_device *dev,
117 unsigned int gem_handle,
118 struct drm_file *file_priv);
119
Inki Dae1c248b72011-10-04 19:19:01 +0900120/* free gem object. */
121void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
122
123/* create memory region for drm framebuffer. */
124int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900125 struct drm_device *dev,
126 struct drm_mode_create_dumb *args);
Inki Dae1c248b72011-10-04 19:19:01 +0900127
128/* map memory region for drm framebuffer to user space. */
129int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900130 struct drm_device *dev, uint32_t handle,
131 uint64_t *offset);
Inki Dae1c248b72011-10-04 19:19:01 +0900132
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900133/* page fault handler and mmap fault address(virtual) to physical memory. */
134int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
135
136/* set vm_flags and we can change the vm attribute to other one at here. */
137int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
Inki Dae1c248b72011-10-04 19:19:01 +0900138
Inki Dae2a3098f2012-11-04 05:48:52 -0800139static inline int vma_is_io(struct vm_area_struct *vma)
140{
141 return !!(vma->vm_flags & (VM_IO | VM_PFNMAP));
142}
143
144/* get a copy of a virtual memory region. */
145struct vm_area_struct *exynos_gem_get_vma(struct vm_area_struct *vma);
146
147/* release a userspace virtual memory area. */
148void exynos_gem_put_vma(struct vm_area_struct *vma);
149
150/* get pages from user space. */
151int exynos_gem_get_pages_from_userptr(unsigned long start,
152 unsigned int npages,
153 struct page **pages,
154 struct vm_area_struct *vma);
155
156/* drop the reference to pages. */
157void exynos_gem_put_pages_to_userptr(struct page **pages,
158 unsigned int npages,
159 struct vm_area_struct *vma);
160
161/* map sgt with dma region. */
162int exynos_gem_map_sgt_with_dma(struct drm_device *drm_dev,
163 struct sg_table *sgt,
164 enum dma_data_direction dir);
165
166/* unmap sgt from dma region. */
167void exynos_gem_unmap_sgt_from_dma(struct drm_device *drm_dev,
168 struct sg_table *sgt,
169 enum dma_data_direction dir);
170
Inki Dae1c248b72011-10-04 19:19:01 +0900171#endif