xref: /openbmc/linux/drivers/gpu/drm/vc4/vc4_drv.h (revision 9cfc5c90)
1 /*
2  * Copyright (C) 2015 Broadcom
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8 
9 #include "drmP.h"
10 #include "drm_gem_cma_helper.h"
11 
12 struct vc4_dev {
13 	struct drm_device *dev;
14 
15 	struct vc4_hdmi *hdmi;
16 	struct vc4_hvs *hvs;
17 	struct vc4_crtc *crtc[3];
18 
19 	struct drm_fbdev_cma *fbdev;
20 };
21 
22 static inline struct vc4_dev *
23 to_vc4_dev(struct drm_device *dev)
24 {
25 	return (struct vc4_dev *)dev->dev_private;
26 }
27 
28 struct vc4_bo {
29 	struct drm_gem_cma_object base;
30 };
31 
32 static inline struct vc4_bo *
33 to_vc4_bo(struct drm_gem_object *bo)
34 {
35 	return (struct vc4_bo *)bo;
36 }
37 
38 struct vc4_hvs {
39 	struct platform_device *pdev;
40 	void __iomem *regs;
41 	void __iomem *dlist;
42 };
43 
44 struct vc4_plane {
45 	struct drm_plane base;
46 };
47 
48 static inline struct vc4_plane *
49 to_vc4_plane(struct drm_plane *plane)
50 {
51 	return (struct vc4_plane *)plane;
52 }
53 
54 enum vc4_encoder_type {
55 	VC4_ENCODER_TYPE_HDMI,
56 	VC4_ENCODER_TYPE_VEC,
57 	VC4_ENCODER_TYPE_DSI0,
58 	VC4_ENCODER_TYPE_DSI1,
59 	VC4_ENCODER_TYPE_SMI,
60 	VC4_ENCODER_TYPE_DPI,
61 };
62 
63 struct vc4_encoder {
64 	struct drm_encoder base;
65 	enum vc4_encoder_type type;
66 	u32 clock_select;
67 };
68 
69 static inline struct vc4_encoder *
70 to_vc4_encoder(struct drm_encoder *encoder)
71 {
72 	return container_of(encoder, struct vc4_encoder, base);
73 }
74 
75 #define HVS_READ(offset) readl(vc4->hvs->regs + offset)
76 #define HVS_WRITE(offset, val) writel(val, vc4->hvs->regs + offset)
77 
78 /**
79  * _wait_for - magic (register) wait macro
80  *
81  * Does the right thing for modeset paths when run under kdgb or similar atomic
82  * contexts. Note that it's important that we check the condition again after
83  * having timed out, since the timeout could be due to preemption or similar and
84  * we've never had a chance to check the condition before the timeout.
85  */
86 #define _wait_for(COND, MS, W) ({ \
87 	unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1;	\
88 	int ret__ = 0;							\
89 	while (!(COND)) {						\
90 		if (time_after(jiffies, timeout__)) {			\
91 			if (!(COND))					\
92 				ret__ = -ETIMEDOUT;			\
93 			break;						\
94 		}							\
95 		if (W && drm_can_sleep())  {				\
96 			msleep(W);					\
97 		} else {						\
98 			cpu_relax();					\
99 		}							\
100 	}								\
101 	ret__;								\
102 })
103 
104 #define wait_for(COND, MS) _wait_for(COND, MS, 1)
105 
106 /* vc4_bo.c */
107 void vc4_free_object(struct drm_gem_object *gem_obj);
108 struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size);
109 int vc4_dumb_create(struct drm_file *file_priv,
110 		    struct drm_device *dev,
111 		    struct drm_mode_create_dumb *args);
112 struct dma_buf *vc4_prime_export(struct drm_device *dev,
113 				 struct drm_gem_object *obj, int flags);
114 
115 /* vc4_crtc.c */
116 extern struct platform_driver vc4_crtc_driver;
117 int vc4_enable_vblank(struct drm_device *dev, unsigned int crtc_id);
118 void vc4_disable_vblank(struct drm_device *dev, unsigned int crtc_id);
119 void vc4_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file);
120 int vc4_crtc_debugfs_regs(struct seq_file *m, void *arg);
121 
122 /* vc4_debugfs.c */
123 int vc4_debugfs_init(struct drm_minor *minor);
124 void vc4_debugfs_cleanup(struct drm_minor *minor);
125 
126 /* vc4_drv.c */
127 void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
128 
129 /* vc4_hdmi.c */
130 extern struct platform_driver vc4_hdmi_driver;
131 int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused);
132 
133 /* vc4_hvs.c */
134 extern struct platform_driver vc4_hvs_driver;
135 void vc4_hvs_dump_state(struct drm_device *dev);
136 int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused);
137 
138 /* vc4_kms.c */
139 int vc4_kms_load(struct drm_device *dev);
140 
141 /* vc4_plane.c */
142 struct drm_plane *vc4_plane_init(struct drm_device *dev,
143 				 enum drm_plane_type type);
144 u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
145 u32 vc4_plane_dlist_size(struct drm_plane_state *state);
146