drm/etnaviv: call correct function when trying to vmap a DMABUF
[linux-2.6-block.git] / drivers / gpu / drm / etnaviv / etnaviv_drv.h
CommitLineData
a8c21a54
T
1/*
2 * Copyright (C) 2015 Etnaviv Project
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __ETNAVIV_DRV_H__
18#define __ETNAVIV_DRV_H__
19
20#include <linux/kernel.h>
21#include <linux/clk.h>
22#include <linux/cpufreq.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
25#include <linux/pm.h>
26#include <linux/pm_runtime.h>
27#include <linux/slab.h>
28#include <linux/list.h>
29#include <linux/iommu.h>
30#include <linux/types.h>
31#include <linux/sizes.h>
32
33#include <drm/drmP.h>
34#include <drm/drm_crtc_helper.h>
35#include <drm/drm_fb_helper.h>
36#include <drm/drm_gem.h>
37#include <drm/etnaviv_drm.h>
38
39struct etnaviv_cmdbuf;
40struct etnaviv_gpu;
41struct etnaviv_mmu;
42struct etnaviv_gem_object;
43struct etnaviv_gem_submit;
44
45struct etnaviv_file_private {
46 /* currently we don't do anything useful with this.. but when
47 * per-context address spaces are supported we'd keep track of
48 * the context's page-tables here.
49 */
50 int dummy;
51};
52
53struct etnaviv_drm_private {
54 int num_gpus;
55 struct etnaviv_gpu *gpu[ETNA_MAX_PIPES];
56
57 /* list of GEM objects: */
58 struct mutex gem_lock;
59 struct list_head gem_list;
60
61 struct workqueue_struct *wq;
62};
63
64static inline void etnaviv_queue_work(struct drm_device *dev,
65 struct work_struct *w)
66{
67 struct etnaviv_drm_private *priv = dev->dev_private;
68
69 queue_work(priv->wq, w);
70}
71
72int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
73 struct drm_file *file);
74
75int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma);
76int etnaviv_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
77int etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset);
78int etnaviv_gem_get_iova(struct etnaviv_gpu *gpu,
79 struct drm_gem_object *obj, u32 *iova);
80void etnaviv_gem_put_iova(struct etnaviv_gpu *gpu, struct drm_gem_object *obj);
81struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj);
82void *etnaviv_gem_prime_vmap(struct drm_gem_object *obj);
83void etnaviv_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
84struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev,
85 struct dma_buf_attachment *attach, struct sg_table *sg);
86int etnaviv_gem_prime_pin(struct drm_gem_object *obj);
87void etnaviv_gem_prime_unpin(struct drm_gem_object *obj);
ce3088fd 88void *etnaviv_gem_vmap(struct drm_gem_object *obj);
a8c21a54
T
89int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
90 struct timespec *timeout);
91int etnaviv_gem_cpu_fini(struct drm_gem_object *obj);
92void etnaviv_gem_free_object(struct drm_gem_object *obj);
93int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
94 u32 size, u32 flags, u32 *handle);
95struct drm_gem_object *etnaviv_gem_new_locked(struct drm_device *dev,
96 u32 size, u32 flags);
97struct drm_gem_object *etnaviv_gem_new(struct drm_device *dev,
98 u32 size, u32 flags);
99int etnaviv_gem_new_userptr(struct drm_device *dev, struct drm_file *file,
100 uintptr_t ptr, u32 size, u32 flags, u32 *handle);
101u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu);
102void etnaviv_buffer_end(struct etnaviv_gpu *gpu);
103void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event,
104 struct etnaviv_cmdbuf *cmdbuf);
105void etnaviv_validate_init(void);
106bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu,
107 u32 *stream, unsigned int size,
108 struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size);
109
110#ifdef CONFIG_DEBUG_FS
111void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv,
112 struct seq_file *m);
113#endif
114
115void __iomem *etnaviv_ioremap(struct platform_device *pdev, const char *name,
116 const char *dbgname);
117void etnaviv_writel(u32 data, void __iomem *addr);
118u32 etnaviv_readl(const void __iomem *addr);
119
120#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
121#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
122
123/*
124 * Return the storage size of a structure with a variable length array.
125 * The array is nelem elements of elem_size, where the base structure
126 * is defined by base. If the size overflows size_t, return zero.
127 */
128static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
129{
130 if (elem_size && nelem > (SIZE_MAX - base) / elem_size)
131 return 0;
132 return base + nelem * elem_size;
133}
134
135/* returns true if fence a comes after fence b */
136static inline bool fence_after(u32 a, u32 b)
137{
138 return (s32)(a - b) > 0;
139}
140
141static inline bool fence_after_eq(u32 a, u32 b)
142{
143 return (s32)(a - b) >= 0;
144}
145
146static inline unsigned long etnaviv_timeout_to_jiffies(
147 const struct timespec *timeout)
148{
149 unsigned long timeout_jiffies = timespec_to_jiffies(timeout);
150 unsigned long start_jiffies = jiffies;
151 unsigned long remaining_jiffies;
152
153 if (time_after(start_jiffies, timeout_jiffies))
154 remaining_jiffies = 0;
155 else
156 remaining_jiffies = timeout_jiffies - start_jiffies;
157
158 return remaining_jiffies;
159}
160
161#endif /* __ETNAVIV_DRV_H__ */