blob: 35ebac47dc2bacfec928d54001b6065aa9e75564 [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
15#define to_exynos_gem_obj(x) container_of(x,\
16 struct exynos_drm_gem_obj, base)
17
Inki Daedcf9af82012-04-03 21:27:58 +090018#define IS_NONCONTIG_BUFFER(f) (f & EXYNOS_BO_NONCONTIG)
19
Inki Dae1c248b72011-10-04 19:19:01 +090020/*
Inki Dae2c871122011-11-12 15:23:32 +090021 * exynos drm gem buffer structure.
22 *
23 * @kvaddr: kernel virtual address to allocated memory region.
Inki Dae2a3098f2012-11-04 05:48:52 -080024 * *userptr: user space address.
Inki Dae2c871122011-11-12 15:23:32 +090025 * @dma_addr: bus address(accessed by dma) to allocated memory region.
26 * - this address could be physical address without IOMMU and
27 * device address with IOMMU.
Inki Dae2a3098f2012-11-04 05:48:52 -080028 * @write: whether pages will be written to by the caller.
Inki Dae4744ad22012-12-07 17:51:27 +090029 * @pages: Array of backing pages.
Inki Dae2b358922012-03-16 18:47:05 +090030 * @sgt: sg table to transfer page data.
Inki Dae2c871122011-11-12 15:23:32 +090031 * @size: size of allocated memory region.
Inki Dae2a3098f2012-11-04 05:48:52 -080032 * @pfnmap: indicate whether memory region from userptr is mmaped with
33 * VM_PFNMAP or not.
Inki Dae2c871122011-11-12 15:23:32 +090034 */
35struct exynos_drm_gem_buf {
36 void __iomem *kvaddr;
Inki Dae2a3098f2012-11-04 05:48:52 -080037 unsigned long userptr;
Inki Dae2c871122011-11-12 15:23:32 +090038 dma_addr_t dma_addr;
Inki Dae0519f9a2012-10-20 07:53:42 -070039 struct dma_attrs dma_attrs;
Inki Dae2a3098f2012-11-04 05:48:52 -080040 unsigned int write;
Inki Dae4744ad22012-12-07 17:51:27 +090041 struct page **pages;
Inki Dae2b358922012-03-16 18:47:05 +090042 struct sg_table *sgt;
Inki Dae2c871122011-11-12 15:23:32 +090043 unsigned long size;
Inki Dae2a3098f2012-11-04 05:48:52 -080044 bool pfnmap;
Inki Dae2c871122011-11-12 15:23:32 +090045};
46
47/*
Inki Dae1c248b72011-10-04 19:19:01 +090048 * exynos drm buffer structure.
49 *
50 * @base: a gem object.
51 * - a new handle to this gem object would be created
52 * by drm_gem_handle_create().
Inki Dae2c871122011-11-12 15:23:32 +090053 * @buffer: a pointer to exynos_drm_gem_buffer object.
54 * - contain the information to memory region allocated
55 * by user request or at framebuffer creation.
Inki Dae1c248b72011-10-04 19:19:01 +090056 * continuous memory region allocated by user request
57 * or at framebuffer creation.
Inki Dae3c52b882012-06-29 16:28:17 +090058 * @size: size requested from user, in bytes and this size is aligned
59 * in page unit.
Inki Dae2a3098f2012-11-04 05:48:52 -080060 * @vma: a pointer to vm_area.
Inki Dae2b358922012-03-16 18:47:05 +090061 * @flags: indicate memory type to allocated buffer and cache attruibute.
Inki Dae1c248b72011-10-04 19:19:01 +090062 *
63 * P.S. this object would be transfered to user as kms_bo.handle so
64 * user can access the buffer through kms_bo.handle.
65 */
66struct exynos_drm_gem_obj {
Joonyoung Shimee5e7702011-12-13 14:20:23 +090067 struct drm_gem_object base;
68 struct exynos_drm_gem_buf *buffer;
Inki Dae2b358922012-03-16 18:47:05 +090069 unsigned long size;
Inki Dae2a3098f2012-11-04 05:48:52 -080070 struct vm_area_struct *vma;
Inki Dae2b358922012-03-16 18:47:05 +090071 unsigned int flags;
Inki Dae1c248b72011-10-04 19:19:01 +090072};
73
Inki Daeb2df26c2012-04-23 21:01:28 +090074struct page **exynos_gem_get_pages(struct drm_gem_object *obj, gfp_t gfpmask);
75
Joonyoung Shim23648392011-12-13 14:39:13 +090076/* destroy a buffer with gem object */
77void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
78
Inki Daeb2df26c2012-04-23 21:01:28 +090079/* create a private gem object and initialize it. */
80struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
81 unsigned long size);
82
Joonyoung Shim23648392011-12-13 14:39:13 +090083/* create a new buffer with gem object */
Inki Daef088d5a2011-11-12 14:51:23 +090084struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
Inki Dae2b358922012-03-16 18:47:05 +090085 unsigned int flags,
86 unsigned long size);
Inki Dae1c248b72011-10-04 19:19:01 +090087
88/*
89 * request gem object creation and buffer allocation as the size
90 * that it is calculated with framebuffer information such as width,
91 * height and bpp.
92 */
93int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
Joonyoung Shimee5e7702011-12-13 14:20:23 +090094 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +090095
Inki Daef0b1bda2012-03-16 18:47:06 +090096/*
97 * get dma address from gem handle and this function could be used for
98 * other drivers such as 2d/3d acceleration drivers.
99 * with this function call, gem object reference count would be increased.
100 */
Inki Daed87342c2012-11-03 21:53:24 -0700101dma_addr_t *exynos_drm_gem_get_dma_addr(struct drm_device *dev,
Inki Daef0b1bda2012-03-16 18:47:06 +0900102 unsigned int gem_handle,
Inki Daed87342c2012-11-03 21:53:24 -0700103 struct drm_file *filp);
Inki Daef0b1bda2012-03-16 18:47:06 +0900104
105/*
106 * put dma address from gem handle and this function could be used for
107 * other drivers such as 2d/3d acceleration drivers.
108 * with this function call, gem object reference count would be decreased.
109 */
110void exynos_drm_gem_put_dma_addr(struct drm_device *dev,
111 unsigned int gem_handle,
Inki Daed87342c2012-11-03 21:53:24 -0700112 struct drm_file *filp);
Inki Daef0b1bda2012-03-16 18:47:06 +0900113
Inki Dae1c248b72011-10-04 19:19:01 +0900114/* get buffer offset to map to user space. */
115int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900116 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +0900117
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900118/*
119 * mmap the physically continuous memory that a gem object contains
120 * to user space.
121 */
122int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
123 struct drm_file *file_priv);
Inki Dae1c248b72011-10-04 19:19:01 +0900124
Inki Dae2a3098f2012-11-04 05:48:52 -0800125/* map user space allocated by malloc to pages. */
126int exynos_drm_gem_userptr_ioctl(struct drm_device *dev, void *data,
127 struct drm_file *file_priv);
128
Inki Dae40cd7e02012-05-04 15:51:17 +0900129/* get buffer information to memory region allocated by gem. */
130int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
131 struct drm_file *file_priv);
132
Inki Dae1c248b72011-10-04 19:19:01 +0900133/* initialize gem object. */
134int exynos_drm_gem_init_object(struct drm_gem_object *obj);
135
136/* free gem object. */
137void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
138
139/* create memory region for drm framebuffer. */
140int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900141 struct drm_device *dev,
142 struct drm_mode_create_dumb *args);
Inki Dae1c248b72011-10-04 19:19:01 +0900143
144/* map memory region for drm framebuffer to user space. */
145int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900146 struct drm_device *dev, uint32_t handle,
147 uint64_t *offset);
Inki Dae1c248b72011-10-04 19:19:01 +0900148
149/*
150 * destroy memory region allocated.
151 * - a gem handle and physical memory region pointed by a gem object
152 * would be released by drm_gem_handle_delete().
153 */
154int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
Joonyoung Shimee5e7702011-12-13 14:20:23 +0900155 struct drm_device *dev,
156 unsigned int handle);
157
158/* page fault handler and mmap fault address(virtual) to physical memory. */
159int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
160
161/* set vm_flags and we can change the vm attribute to other one at here. */
162int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
Inki Dae1c248b72011-10-04 19:19:01 +0900163
Inki Dae2a3098f2012-11-04 05:48:52 -0800164static inline int vma_is_io(struct vm_area_struct *vma)
165{
166 return !!(vma->vm_flags & (VM_IO | VM_PFNMAP));
167}
168
169/* get a copy of a virtual memory region. */
170struct vm_area_struct *exynos_gem_get_vma(struct vm_area_struct *vma);
171
172/* release a userspace virtual memory area. */
173void exynos_gem_put_vma(struct vm_area_struct *vma);
174
175/* get pages from user space. */
176int exynos_gem_get_pages_from_userptr(unsigned long start,
177 unsigned int npages,
178 struct page **pages,
179 struct vm_area_struct *vma);
180
181/* drop the reference to pages. */
182void exynos_gem_put_pages_to_userptr(struct page **pages,
183 unsigned int npages,
184 struct vm_area_struct *vma);
185
186/* map sgt with dma region. */
187int exynos_gem_map_sgt_with_dma(struct drm_device *drm_dev,
188 struct sg_table *sgt,
189 enum dma_data_direction dir);
190
191/* unmap sgt from dma region. */
192void exynos_gem_unmap_sgt_from_dma(struct drm_device *drm_dev,
193 struct sg_table *sgt,
194 enum dma_data_direction dir);
195
Inki Dae1c248b72011-10-04 19:19:01 +0900196#endif