1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __MSM_DRV_H__
20#define __MSM_DRV_H__
21
22#include <linux/kernel.h>
23#include <linux/clk.h>
24#include <linux/cpufreq.h>
25#include <linux/module.h>
26#include <linux/component.h>
27#include <linux/platform_device.h>
28#include <linux/pm.h>
29#include <linux/pm_runtime.h>
30#include <linux/slab.h>
31#include <linux/list.h>
32#include <linux/iommu.h>
33#include <linux/types.h>
34#include <linux/of_graph.h>
35#include <linux/of_device.h>
36#include <asm/sizes.h>
37#include <linux/kthread.h>
38
39#include <drm/drmP.h>
40#include <drm/drm_atomic.h>
41#include <drm/drm_atomic_helper.h>
42#include <drm/drm_crtc_helper.h>
43#include <drm/drm_plane_helper.h>
44#include <drm/drm_fb_helper.h>
45#include <drm/msm_drm.h>
46#include <drm/drm_gem.h>
47
48struct msm_kms;
49struct msm_gpu;
50struct msm_mmu;
51struct msm_mdss;
52struct msm_rd_state;
53struct msm_perf_state;
54struct msm_gem_submit;
55struct msm_fence_context;
56struct msm_gem_address_space;
57struct msm_gem_vma;
58
59#define MAX_CRTCS 8
60#define MAX_PLANES 20
61#define MAX_ENCODERS 8
62#define MAX_BRIDGES 8
63#define MAX_CONNECTORS 8
64
65struct msm_file_private {
66 rwlock_t queuelock;
67 struct list_head submitqueues;
68 int queueid;
69};
70
71enum msm_mdp_plane_property {
72 PLANE_PROP_ZPOS,
73 PLANE_PROP_ALPHA,
74 PLANE_PROP_PREMULTIPLIED,
75 PLANE_PROP_MAX_NUM
76};
77
78struct msm_vblank_ctrl {
79 struct kthread_work work;
80 struct list_head event_list;
81 spinlock_t lock;
82};
83
84#define MSM_GPU_MAX_RINGS 4
85#define MAX_H_TILES_PER_DISPLAY 2
86
87
88
89
90
91
92
93
94enum msm_display_caps {
95 MSM_DISPLAY_CAP_VID_MODE = BIT(0),
96 MSM_DISPLAY_CAP_CMD_MODE = BIT(1),
97 MSM_DISPLAY_CAP_HOT_PLUG = BIT(2),
98 MSM_DISPLAY_CAP_EDID = BIT(3),
99};
100
101
102
103
104
105
106
107enum msm_event_wait {
108 MSM_ENC_COMMIT_DONE = 0,
109 MSM_ENC_TX_COMPLETE,
110 MSM_ENC_VBLANK,
111};
112
113
114
115
116
117
118
119struct msm_display_topology {
120 u32 num_lm;
121 u32 num_enc;
122 u32 num_intf;
123};
124
125
126
127
128
129
130
131
132
133
134
135struct msm_display_info {
136 int intf_type;
137 uint32_t capabilities;
138 uint32_t num_of_h_tiles;
139 uint32_t h_tile_instance[MAX_H_TILES_PER_DISPLAY];
140 bool is_te_using_watchdog_timer;
141};
142
143
144struct msm_drm_thread {
145 struct drm_device *dev;
146 struct task_struct *thread;
147 unsigned int crtc_id;
148 struct kthread_worker worker;
149};
150
151struct msm_drm_private {
152
153 struct drm_device *dev;
154
155 struct msm_kms *kms;
156
157
158 struct platform_device *gpu_pdev;
159
160
161 struct msm_mdss *mdss;
162
163
164
165
166 struct hdmi *hdmi;
167
168
169
170
171
172 struct msm_edp *edp;
173
174
175 struct msm_dsi *dsi[2];
176
177
178 struct msm_gpu *gpu;
179 struct msm_file_private *lastctx;
180
181 struct drm_fb_helper *fbdev;
182
183 struct msm_rd_state *rd;
184 struct msm_rd_state *hangrd;
185 struct msm_perf_state *perf;
186
187
188 struct list_head inactive_list;
189
190 struct workqueue_struct *wq;
191
192 unsigned int num_planes;
193 struct drm_plane *planes[MAX_PLANES];
194
195 unsigned int num_crtcs;
196 struct drm_crtc *crtcs[MAX_CRTCS];
197
198 struct msm_drm_thread disp_thread[MAX_CRTCS];
199 struct msm_drm_thread event_thread[MAX_CRTCS];
200
201 unsigned int num_encoders;
202 struct drm_encoder *encoders[MAX_ENCODERS];
203
204 unsigned int num_bridges;
205 struct drm_bridge *bridges[MAX_BRIDGES];
206
207 unsigned int num_connectors;
208 struct drm_connector *connectors[MAX_CONNECTORS];
209
210
211 struct drm_property *plane_property[PLANE_PROP_MAX_NUM];
212
213
214 struct {
215 unsigned long size;
216 dma_addr_t paddr;
217
218
219
220 struct drm_mm mm;
221 spinlock_t lock;
222 } vram;
223
224 struct notifier_block vmap_notifier;
225 struct shrinker shrinker;
226
227 struct msm_vblank_ctrl vblank_ctrl;
228 struct drm_atomic_state *pm_state;
229};
230
231struct msm_format {
232 uint32_t pixel_format;
233};
234
235int msm_atomic_prepare_fb(struct drm_plane *plane,
236 struct drm_plane_state *new_state);
237void msm_atomic_commit_tail(struct drm_atomic_state *state);
238struct drm_atomic_state *msm_atomic_state_alloc(struct drm_device *dev);
239void msm_atomic_state_clear(struct drm_atomic_state *state);
240void msm_atomic_state_free(struct drm_atomic_state *state);
241
242void msm_gem_unmap_vma(struct msm_gem_address_space *aspace,
243 struct msm_gem_vma *vma, struct sg_table *sgt);
244int msm_gem_map_vma(struct msm_gem_address_space *aspace,
245 struct msm_gem_vma *vma, struct sg_table *sgt, int npages);
246
247void msm_gem_address_space_put(struct msm_gem_address_space *aspace);
248
249struct msm_gem_address_space *
250msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain,
251 const char *name);
252
253int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu);
254void msm_unregister_mmu(struct drm_device *dev, struct msm_mmu *mmu);
255
256void msm_gem_submit_free(struct msm_gem_submit *submit);
257int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
258 struct drm_file *file);
259
260void msm_gem_shrinker_init(struct drm_device *dev);
261void msm_gem_shrinker_cleanup(struct drm_device *dev);
262
263int msm_gem_mmap_obj(struct drm_gem_object *obj,
264 struct vm_area_struct *vma);
265int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
266vm_fault_t msm_gem_fault(struct vm_fault *vmf);
267uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
268int msm_gem_get_iova(struct drm_gem_object *obj,
269 struct msm_gem_address_space *aspace, uint64_t *iova);
270uint64_t msm_gem_iova(struct drm_gem_object *obj,
271 struct msm_gem_address_space *aspace);
272struct page **msm_gem_get_pages(struct drm_gem_object *obj);
273void msm_gem_put_pages(struct drm_gem_object *obj);
274void msm_gem_put_iova(struct drm_gem_object *obj,
275 struct msm_gem_address_space *aspace);
276int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
277 struct drm_mode_create_dumb *args);
278int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
279 uint32_t handle, uint64_t *offset);
280struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj);
281void *msm_gem_prime_vmap(struct drm_gem_object *obj);
282void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
283int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
284struct reservation_object *msm_gem_prime_res_obj(struct drm_gem_object *obj);
285struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
286 struct dma_buf_attachment *attach, struct sg_table *sg);
287int msm_gem_prime_pin(struct drm_gem_object *obj);
288void msm_gem_prime_unpin(struct drm_gem_object *obj);
289void *msm_gem_get_vaddr(struct drm_gem_object *obj);
290void *msm_gem_get_vaddr_active(struct drm_gem_object *obj);
291void msm_gem_put_vaddr(struct drm_gem_object *obj);
292int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv);
293int msm_gem_sync_object(struct drm_gem_object *obj,
294 struct msm_fence_context *fctx, bool exclusive);
295void msm_gem_move_to_active(struct drm_gem_object *obj,
296 struct msm_gpu *gpu, bool exclusive, struct dma_fence *fence);
297void msm_gem_move_to_inactive(struct drm_gem_object *obj);
298int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout);
299int msm_gem_cpu_fini(struct drm_gem_object *obj);
300void msm_gem_free_object(struct drm_gem_object *obj);
301int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
302 uint32_t size, uint32_t flags, uint32_t *handle);
303struct drm_gem_object *msm_gem_new(struct drm_device *dev,
304 uint32_t size, uint32_t flags);
305struct drm_gem_object *msm_gem_new_locked(struct drm_device *dev,
306 uint32_t size, uint32_t flags);
307void *msm_gem_kernel_new(struct drm_device *dev, uint32_t size,
308 uint32_t flags, struct msm_gem_address_space *aspace,
309 struct drm_gem_object **bo, uint64_t *iova);
310void *msm_gem_kernel_new_locked(struct drm_device *dev, uint32_t size,
311 uint32_t flags, struct msm_gem_address_space *aspace,
312 struct drm_gem_object **bo, uint64_t *iova);
313struct drm_gem_object *msm_gem_import(struct drm_device *dev,
314 struct dma_buf *dmabuf, struct sg_table *sgt);
315
316int msm_framebuffer_prepare(struct drm_framebuffer *fb,
317 struct msm_gem_address_space *aspace);
318void msm_framebuffer_cleanup(struct drm_framebuffer *fb,
319 struct msm_gem_address_space *aspace);
320uint32_t msm_framebuffer_iova(struct drm_framebuffer *fb,
321 struct msm_gem_address_space *aspace, int plane);
322struct drm_gem_object *msm_framebuffer_bo(struct drm_framebuffer *fb, int plane);
323const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb);
324struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
325 struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd);
326struct drm_framebuffer * msm_alloc_stolen_fb(struct drm_device *dev,
327 int w, int h, int p, uint32_t format);
328
329struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev);
330void msm_fbdev_free(struct drm_device *dev);
331
332struct hdmi;
333int msm_hdmi_modeset_init(struct hdmi *hdmi, struct drm_device *dev,
334 struct drm_encoder *encoder);
335void __init msm_hdmi_register(void);
336void __exit msm_hdmi_unregister(void);
337
338struct msm_edp;
339void __init msm_edp_register(void);
340void __exit msm_edp_unregister(void);
341int msm_edp_modeset_init(struct msm_edp *edp, struct drm_device *dev,
342 struct drm_encoder *encoder);
343
344struct msm_dsi;
345#ifdef CONFIG_DRM_MSM_DSI
346void __init msm_dsi_register(void);
347void __exit msm_dsi_unregister(void);
348int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
349 struct drm_encoder *encoder);
350#else
351static inline void __init msm_dsi_register(void)
352{
353}
354static inline void __exit msm_dsi_unregister(void)
355{
356}
357static inline int msm_dsi_modeset_init(struct msm_dsi *msm_dsi,
358 struct drm_device *dev,
359 struct drm_encoder *encoder)
360{
361 return -EINVAL;
362}
363#endif
364
365void __init msm_mdp_register(void);
366void __exit msm_mdp_unregister(void);
367void __init msm_dpu_register(void);
368void __exit msm_dpu_unregister(void);
369
370#ifdef CONFIG_DEBUG_FS
371void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m);
372void msm_gem_describe_objects(struct list_head *list, struct seq_file *m);
373void msm_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m);
374int msm_debugfs_late_init(struct drm_device *dev);
375int msm_rd_debugfs_init(struct drm_minor *minor);
376void msm_rd_debugfs_cleanup(struct msm_drm_private *priv);
377void msm_rd_dump_submit(struct msm_rd_state *rd, struct msm_gem_submit *submit,
378 const char *fmt, ...);
379int msm_perf_debugfs_init(struct drm_minor *minor);
380void msm_perf_debugfs_cleanup(struct msm_drm_private *priv);
381#else
382static inline int msm_debugfs_late_init(struct drm_device *dev) { return 0; }
383static inline void msm_rd_dump_submit(struct msm_rd_state *rd, struct msm_gem_submit *submit,
384 const char *fmt, ...) {}
385static inline void msm_rd_debugfs_cleanup(struct msm_drm_private *priv) {}
386static inline void msm_perf_debugfs_cleanup(struct msm_drm_private *priv) {}
387#endif
388
389struct clk *msm_clk_get(struct platform_device *pdev, const char *name);
390int msm_clk_bulk_get(struct device *dev, struct clk_bulk_data **bulk);
391
392struct clk *msm_clk_bulk_get_clock(struct clk_bulk_data *bulk, int count,
393 const char *name);
394void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
395 const char *dbgname);
396void msm_writel(u32 data, void __iomem *addr);
397u32 msm_readl(const void __iomem *addr);
398
399struct msm_gpu_submitqueue;
400int msm_submitqueue_init(struct drm_device *drm, struct msm_file_private *ctx);
401struct msm_gpu_submitqueue *msm_submitqueue_get(struct msm_file_private *ctx,
402 u32 id);
403int msm_submitqueue_create(struct drm_device *drm, struct msm_file_private *ctx,
404 u32 prio, u32 flags, u32 *id);
405int msm_submitqueue_remove(struct msm_file_private *ctx, u32 id);
406void msm_submitqueue_close(struct msm_file_private *ctx);
407
408void msm_submitqueue_destroy(struct kref *kref);
409
410
411#define DBG(fmt, ...) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
412#define VERB(fmt, ...) if (0) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
413
414static inline int align_pitch(int width, int bpp)
415{
416 int bytespp = (bpp + 7) / 8;
417
418 return bytespp * ALIGN(width, 32);
419}
420
421
422#define INVALID_IDX(idx) ({BUG(); 0;})
423#define fui(x) ({BUG(); 0;})
424#define util_float_to_half(x) ({BUG(); 0;})
425
426
427#define FIELD(val, name) (((val) & name ## __MASK) >> name ## __SHIFT)
428
429
430#define COND(bool, val) ((bool) ? (val) : 0)
431
432static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
433{
434 ktime_t now = ktime_get();
435 unsigned long remaining_jiffies;
436
437 if (ktime_compare(*timeout, now) < 0) {
438 remaining_jiffies = 0;
439 } else {
440 ktime_t rem = ktime_sub(*timeout, now);
441 struct timespec ts = ktime_to_timespec(rem);
442 remaining_jiffies = timespec_to_jiffies(&ts);
443 }
444
445 return remaining_jiffies;
446}
447
448#endif
449