Merge tag 'ecryptfs-4.15-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / etnaviv / etnaviv_drv.h
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/types.h>
30 #include <linux/sizes.h>
31
32 #include <drm/drmP.h>
33 #include <drm/drm_crtc_helper.h>
34 #include <drm/drm_fb_helper.h>
35 #include <drm/drm_gem.h>
36 #include <drm/etnaviv_drm.h>
37
38 struct etnaviv_cmdbuf;
39 struct etnaviv_gpu;
40 struct etnaviv_mmu;
41 struct etnaviv_gem_object;
42 struct etnaviv_gem_submit;
43
44 struct etnaviv_file_private {
45         /* currently we don't do anything useful with this.. but when
46          * per-context address spaces are supported we'd keep track of
47          * the context's page-tables here.
48          */
49         int dummy;
50 };
51
52 struct etnaviv_drm_private {
53         int num_gpus;
54         struct etnaviv_gpu *gpu[ETNA_MAX_PIPES];
55
56         /* list of GEM objects: */
57         struct mutex gem_lock;
58         struct list_head gem_list;
59
60         struct workqueue_struct *wq;
61 };
62
63 static inline void etnaviv_queue_work(struct drm_device *dev,
64         struct work_struct *w)
65 {
66         struct etnaviv_drm_private *priv = dev->dev_private;
67
68         queue_work(priv->wq, w);
69 }
70
71 int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
72                 struct drm_file *file);
73
74 int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma);
75 int etnaviv_gem_fault(struct vm_fault *vmf);
76 int etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset);
77 struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj);
78 void *etnaviv_gem_prime_vmap(struct drm_gem_object *obj);
79 void etnaviv_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
80 int etnaviv_gem_prime_mmap(struct drm_gem_object *obj,
81                            struct vm_area_struct *vma);
82 struct reservation_object *etnaviv_gem_prime_res_obj(struct drm_gem_object *obj);
83 struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev,
84         struct dma_buf_attachment *attach, struct sg_table *sg);
85 int etnaviv_gem_prime_pin(struct drm_gem_object *obj);
86 void etnaviv_gem_prime_unpin(struct drm_gem_object *obj);
87 void *etnaviv_gem_vmap(struct drm_gem_object *obj);
88 int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
89                 struct timespec *timeout);
90 int etnaviv_gem_cpu_fini(struct drm_gem_object *obj);
91 void etnaviv_gem_free_object(struct drm_gem_object *obj);
92 int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
93                 u32 size, u32 flags, u32 *handle);
94 int etnaviv_gem_new_userptr(struct drm_device *dev, struct drm_file *file,
95         uintptr_t ptr, u32 size, u32 flags, u32 *handle);
96 u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu);
97 u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe_addr);
98 void etnaviv_buffer_end(struct etnaviv_gpu *gpu);
99 void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event);
100 void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event,
101         struct etnaviv_cmdbuf *cmdbuf);
102 void etnaviv_validate_init(void);
103 bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu,
104         u32 *stream, unsigned int size,
105         struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size);
106
107 #ifdef CONFIG_DEBUG_FS
108 void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv,
109         struct seq_file *m);
110 #endif
111
112 void __iomem *etnaviv_ioremap(struct platform_device *pdev, const char *name,
113                 const char *dbgname);
114 void etnaviv_writel(u32 data, void __iomem *addr);
115 u32 etnaviv_readl(const void __iomem *addr);
116
117 #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
118 #define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
119
120 /*
121  * Return the storage size of a structure with a variable length array.
122  * The array is nelem elements of elem_size, where the base structure
123  * is defined by base.  If the size overflows size_t, return zero.
124  */
125 static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
126 {
127         if (elem_size && nelem > (SIZE_MAX - base) / elem_size)
128                 return 0;
129         return base + nelem * elem_size;
130 }
131
132 /* returns true if fence a comes after fence b */
133 static inline bool fence_after(u32 a, u32 b)
134 {
135         return (s32)(a - b) > 0;
136 }
137
138 static inline bool fence_after_eq(u32 a, u32 b)
139 {
140         return (s32)(a - b) >= 0;
141 }
142
143 static inline unsigned long etnaviv_timeout_to_jiffies(
144         const struct timespec *timeout)
145 {
146         unsigned long timeout_jiffies = timespec_to_jiffies(timeout);
147         unsigned long start_jiffies = jiffies;
148         unsigned long remaining_jiffies;
149
150         if (time_after(start_jiffies, timeout_jiffies))
151                 remaining_jiffies = 0;
152         else
153                 remaining_jiffies = timeout_jiffies - start_jiffies;
154
155         return remaining_jiffies;
156 }
157
158 #endif /* __ETNAVIV_DRV_H__ */