]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/msm/msm_drv.h
drm/msm: add support for non-IOMMU systems
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / msm / msm_drv.h
CommitLineData
c8afe684
RC
1/*
2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __MSM_DRV_H__
19#define __MSM_DRV_H__
20
21#include <linux/kernel.h>
22#include <linux/clk.h>
23#include <linux/cpufreq.h>
24#include <linux/module.h>
25#include <linux/platform_device.h>
26#include <linux/pm.h>
27#include <linux/pm_runtime.h>
28#include <linux/slab.h>
29#include <linux/list.h>
30#include <linux/iommu.h>
31#include <linux/types.h>
32#include <asm/sizes.h>
33
3083894f
RC
34
35#if defined(CONFIG_COMPILE_TEST) && !defined(CONFIG_ARCH_MSM)
36/* stubs we need for compile-test: */
37static inline struct device *msm_iommu_get_ctx(const char *ctx_name)
38{
39 return NULL;
40}
41#endif
42
c8afe684
RC
43#ifndef CONFIG_OF
44#include <mach/board.h>
45#include <mach/socinfo.h>
46#include <mach/iommu_domains.h>
47#endif
48
49#include <drm/drmP.h>
50#include <drm/drm_crtc_helper.h>
51#include <drm/drm_fb_helper.h>
7198e6b0 52#include <drm/msm_drm.h>
c8afe684
RC
53
54struct msm_kms;
7198e6b0 55struct msm_gpu;
871d812a 56struct msm_mmu;
c8afe684 57
7198e6b0
RC
58#define NUM_DOMAINS 2 /* one for KMS, then one per gpu core (?) */
59
60struct msm_file_private {
61 /* currently we don't do anything useful with this.. but when
62 * per-context address spaces are supported we'd keep track of
63 * the context's page-tables here.
64 */
65 int dummy;
66};
c8afe684
RC
67
68struct msm_drm_private {
69
70 struct msm_kms *kms;
71
7198e6b0
RC
72 /* when we have more than one 'msm_gpu' these need to be an array: */
73 struct msm_gpu *gpu;
74 struct msm_file_private *lastctx;
75
c8afe684
RC
76 struct drm_fb_helper *fbdev;
77
7198e6b0
RC
78 uint32_t next_fence, completed_fence;
79 wait_queue_head_t fence_event;
80
c8afe684
RC
81 /* list of GEM objects: */
82 struct list_head inactive_list;
83
84 struct workqueue_struct *wq;
85
edd4fc63
RC
86 /* callbacks deferred until bo is inactive: */
87 struct list_head fence_cbs;
88
871d812a
RC
89 /* registered MMUs: */
90 unsigned int num_mmus;
91 struct msm_mmu *mmus[NUM_DOMAINS];
c8afe684 92
a8623918
RC
93 unsigned int num_planes;
94 struct drm_plane *planes[8];
95
c8afe684
RC
96 unsigned int num_crtcs;
97 struct drm_crtc *crtcs[8];
98
99 unsigned int num_encoders;
100 struct drm_encoder *encoders[8];
101
a3376e3e
RC
102 unsigned int num_bridges;
103 struct drm_bridge *bridges[8];
104
c8afe684
RC
105 unsigned int num_connectors;
106 struct drm_connector *connectors[8];
871d812a
RC
107
108 /* VRAM carveout, used when no IOMMU: */
109 struct {
110 unsigned long size;
111 dma_addr_t paddr;
112 /* NOTE: mm managed at the page level, size is in # of pages
113 * and position mm_node->start is in # of pages:
114 */
115 struct drm_mm mm;
116 } vram;
c8afe684
RC
117};
118
119struct msm_format {
120 uint32_t pixel_format;
121};
122
edd4fc63
RC
123/* callback from wq once fence has passed: */
124struct msm_fence_cb {
125 struct work_struct work;
126 uint32_t fence;
127 void (*func)(struct msm_fence_cb *cb);
128};
129
130void __msm_fence_worker(struct work_struct *work);
131
132#define INIT_FENCE_CB(_cb, _func) do { \
133 INIT_WORK(&(_cb)->work, __msm_fence_worker); \
134 (_cb)->func = _func; \
135 } while (0)
136
c8afe684
RC
137/* As there are different display controller blocks depending on the
138 * snapdragon version, the kms support is split out and the appropriate
139 * implementation is loaded at runtime. The kms module is responsible
140 * for constructing the appropriate planes/crtcs/encoders/connectors.
141 */
142struct msm_kms_funcs {
143 /* hw initialization: */
144 int (*hw_init)(struct msm_kms *kms);
145 /* irq handling: */
146 void (*irq_preinstall)(struct msm_kms *kms);
147 int (*irq_postinstall)(struct msm_kms *kms);
148 void (*irq_uninstall)(struct msm_kms *kms);
149 irqreturn_t (*irq)(struct msm_kms *kms);
150 int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
151 void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
152 /* misc: */
153 const struct msm_format *(*get_format)(struct msm_kms *kms, uint32_t format);
154 long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
155 struct drm_encoder *encoder);
156 /* cleanup: */
157 void (*preclose)(struct msm_kms *kms, struct drm_file *file);
158 void (*destroy)(struct msm_kms *kms);
159};
160
161struct msm_kms {
162 const struct msm_kms_funcs *funcs;
163};
164
165struct msm_kms *mdp4_kms_init(struct drm_device *dev);
166
871d812a 167int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu);
c8afe684 168
7198e6b0
RC
169int msm_wait_fence_interruptable(struct drm_device *dev, uint32_t fence,
170 struct timespec *timeout);
171void msm_update_fence(struct drm_device *dev, uint32_t fence);
172
173int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
174 struct drm_file *file);
175
c8afe684
RC
176int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
177int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
178uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
179int msm_gem_get_iova_locked(struct drm_gem_object *obj, int id,
180 uint32_t *iova);
181int msm_gem_get_iova(struct drm_gem_object *obj, int id, uint32_t *iova);
05b84911
RC
182struct page **msm_gem_get_pages(struct drm_gem_object *obj);
183void msm_gem_put_pages(struct drm_gem_object *obj);
c8afe684
RC
184void msm_gem_put_iova(struct drm_gem_object *obj, int id);
185int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
186 struct drm_mode_create_dumb *args);
c8afe684
RC
187int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
188 uint32_t handle, uint64_t *offset);
05b84911
RC
189struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj);
190void *msm_gem_prime_vmap(struct drm_gem_object *obj);
191void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
192struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
193 size_t size, struct sg_table *sg);
194int msm_gem_prime_pin(struct drm_gem_object *obj);
195void msm_gem_prime_unpin(struct drm_gem_object *obj);
c8afe684
RC
196void *msm_gem_vaddr_locked(struct drm_gem_object *obj);
197void *msm_gem_vaddr(struct drm_gem_object *obj);
edd4fc63
RC
198int msm_gem_queue_inactive_cb(struct drm_gem_object *obj,
199 struct msm_fence_cb *cb);
7198e6b0 200void msm_gem_move_to_active(struct drm_gem_object *obj,
bf6811f3 201 struct msm_gpu *gpu, bool write, uint32_t fence);
7198e6b0
RC
202void msm_gem_move_to_inactive(struct drm_gem_object *obj);
203int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op,
204 struct timespec *timeout);
205int msm_gem_cpu_fini(struct drm_gem_object *obj);
c8afe684
RC
206void msm_gem_free_object(struct drm_gem_object *obj);
207int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
208 uint32_t size, uint32_t flags, uint32_t *handle);
209struct drm_gem_object *msm_gem_new(struct drm_device *dev,
210 uint32_t size, uint32_t flags);
05b84911
RC
211struct drm_gem_object *msm_gem_import(struct drm_device *dev,
212 uint32_t size, struct sg_table *sgt);
c8afe684
RC
213
214struct drm_gem_object *msm_framebuffer_bo(struct drm_framebuffer *fb, int plane);
215const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb);
216struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
217 struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos);
218struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
219 struct drm_file *file, struct drm_mode_fb_cmd2 *mode_cmd);
220
221struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev);
222
a3376e3e 223int hdmi_init(struct drm_device *dev, struct drm_encoder *encoder);
c8afe684
RC
224void __init hdmi_register(void);
225void __exit hdmi_unregister(void);
226
227#ifdef CONFIG_DEBUG_FS
228void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m);
229void msm_gem_describe_objects(struct list_head *list, struct seq_file *m);
230void msm_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m);
231#endif
232
233void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
234 const char *dbgname);
235void msm_writel(u32 data, void __iomem *addr);
236u32 msm_readl(const void __iomem *addr);
237
238#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
239#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
240
f816f272
RC
241static inline bool fence_completed(struct drm_device *dev, uint32_t fence)
242{
243 struct msm_drm_private *priv = dev->dev_private;
244 return priv->completed_fence >= fence;
245}
246
c8afe684
RC
247static inline int align_pitch(int width, int bpp)
248{
249 int bytespp = (bpp + 7) / 8;
250 /* adreno needs pitch aligned to 32 pixels: */
251 return bytespp * ALIGN(width, 32);
252}
253
254/* for the generated headers: */
255#define INVALID_IDX(idx) ({BUG(); 0;})
7198e6b0
RC
256#define fui(x) ({BUG(); 0;})
257#define util_float_to_half(x) ({BUG(); 0;})
258
c8afe684
RC
259
260#define FIELD(val, name) (((val) & name ## __MASK) >> name ## __SHIFT)
261
262/* for conditionally setting boolean flag(s): */
263#define COND(bool, val) ((bool) ? (val) : 0)
264
c8afe684
RC
265
266#endif /* __MSM_DRV_H__ */