afc94da40bc0550390458ef29d9dd8b3733fd307
[openwrt/staging/dangole.git] /
1 From 7140cf0d83c10f93ca8212edb17697baf9cafb45 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Mon, 1 Apr 2019 11:35:59 -0700
4 Subject: [PATCH] drm/vc4: Disable V3D interactions if the v3d
5 component didn't probe.
6
7 Commit ffc26740714962e3e8801dca7ef32b636b3781db upstream.
8
9 One might want to use the VC4 display stack without using Mesa.
10 Similar to the debugfs fixes for not having all of the possible
11 display bits enabled, make sure you can't oops in vc4 if v3d isn't
12 enabled.
13
14 v2: Fix matching against other v3d variants (review by Paul), don't
15 forget to set irq_enabled so that the vblank uapi works
16 v3: Use -ENODEV instead of -EINVAL on Paul's suggestion.
17
18 Signed-off-by: Eric Anholt <eric@anholt.net>
19 Link: https://patchwork.freedesktop.org/patch/msgid/20190401183559.3823-2-eric@anholt.net
20 Reviewed-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
21 ---
22 drivers/gpu/drm/vc4/vc4_drv.c | 10 ++++++++++
23 drivers/gpu/drm/vc4/vc4_drv.h | 1 +
24 drivers/gpu/drm/vc4/vc4_gem.c | 10 ++++++++++
25 drivers/gpu/drm/vc4/vc4_irq.c | 9 +++++++++
26 drivers/gpu/drm/vc4/vc4_perfmon.c | 18 ++++++++++++++++++
27 drivers/gpu/drm/vc4/vc4_v3d.c | 2 +-
28 6 files changed, 49 insertions(+), 1 deletion(-)
29
30 --- a/drivers/gpu/drm/vc4/vc4_drv.c
31 +++ b/drivers/gpu/drm/vc4/vc4_drv.c
32 @@ -71,6 +71,9 @@ static int vc4_get_param_ioctl(struct dr
33 if (args->pad != 0)
34 return -EINVAL;
35
36 + if (!vc4->v3d)
37 + return -ENODEV;
38 +
39 switch (args->param) {
40 case DRM_VC4_PARAM_V3D_IDENT0:
41 ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
42 @@ -271,6 +274,7 @@ static int vc4_drm_bind(struct device *d
43 struct platform_device *pdev = to_platform_device(dev);
44 struct drm_device *drm;
45 struct vc4_dev *vc4;
46 + struct device_node *node;
47 int ret = 0;
48
49 dev->coherent_dma_mask = DMA_BIT_MASK(32);
50 @@ -279,6 +283,12 @@ static int vc4_drm_bind(struct device *d
51 if (!vc4)
52 return -ENOMEM;
53
54 + /* If VC4 V3D is missing, don't advertise render nodes. */
55 + node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
56 + if (!node || !of_device_is_available(node))
57 + vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
58 + of_node_put(node);
59 +
60 drm = drm_dev_alloc(&vc4_drm_driver, dev);
61 if (IS_ERR(drm))
62 return PTR_ERR(drm);
63 --- a/drivers/gpu/drm/vc4/vc4_drv.h
64 +++ b/drivers/gpu/drm/vc4/vc4_drv.h
65 @@ -787,6 +787,7 @@ void vc4_plane_async_set_fb(struct drm_p
66
67 /* vc4_v3d.c */
68 extern struct platform_driver vc4_v3d_driver;
69 +extern const struct of_device_id vc4_v3d_dt_match[];
70 int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused);
71 int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused);
72 int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
73 --- a/drivers/gpu/drm/vc4/vc4_gem.c
74 +++ b/drivers/gpu/drm/vc4/vc4_gem.c
75 @@ -74,6 +74,11 @@ vc4_get_hang_state_ioctl(struct drm_devi
76 u32 i;
77 int ret = 0;
78
79 + if (!vc4->v3d) {
80 + DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n");
81 + return -ENODEV;
82 + }
83 +
84 spin_lock_irqsave(&vc4->job_lock, irqflags);
85 kernel_state = vc4->hang_state;
86 if (!kernel_state) {
87 @@ -1124,6 +1129,11 @@ vc4_submit_cl_ioctl(struct drm_device *d
88 struct dma_fence *in_fence;
89 int ret = 0;
90
91 + if (!vc4->v3d) {
92 + DRM_DEBUG("VC4_SUBMIT_CL with no VC4 V3D probed\n");
93 + return -ENODEV;
94 + }
95 +
96 if ((args->flags & ~(VC4_SUBMIT_CL_USE_CLEAR_COLOR |
97 VC4_SUBMIT_CL_FIXED_RCL_ORDER |
98 VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X |
99 --- a/drivers/gpu/drm/vc4/vc4_irq.c
100 +++ b/drivers/gpu/drm/vc4/vc4_irq.c
101 @@ -229,6 +229,9 @@ vc4_irq_preinstall(struct drm_device *de
102 {
103 struct vc4_dev *vc4 = to_vc4_dev(dev);
104
105 + if (!vc4->v3d)
106 + return;
107 +
108 init_waitqueue_head(&vc4->job_wait_queue);
109 INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
110
111 @@ -243,6 +246,9 @@ vc4_irq_postinstall(struct drm_device *d
112 {
113 struct vc4_dev *vc4 = to_vc4_dev(dev);
114
115 + if (!vc4->v3d)
116 + return 0;
117 +
118 /* Enable both the render done and out of memory interrupts. */
119 V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS);
120
121 @@ -254,6 +260,9 @@ vc4_irq_uninstall(struct drm_device *dev
122 {
123 struct vc4_dev *vc4 = to_vc4_dev(dev);
124
125 + if (!vc4->v3d)
126 + return;
127 +
128 /* Disable sending interrupts for our driver's IRQs. */
129 V3D_WRITE(V3D_INTDIS, V3D_DRIVER_IRQS);
130
131 --- a/drivers/gpu/drm/vc4/vc4_perfmon.c
132 +++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
133 @@ -100,12 +100,18 @@ void vc4_perfmon_close_file(struct vc4_f
134 int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
135 struct drm_file *file_priv)
136 {
137 + struct vc4_dev *vc4 = to_vc4_dev(dev);
138 struct vc4_file *vc4file = file_priv->driver_priv;
139 struct drm_vc4_perfmon_create *req = data;
140 struct vc4_perfmon *perfmon;
141 unsigned int i;
142 int ret;
143
144 + if (!vc4->v3d) {
145 + DRM_DEBUG("Creating perfmon no VC4 V3D probed\n");
146 + return -ENODEV;
147 + }
148 +
149 /* Number of monitored counters cannot exceed HW limits. */
150 if (req->ncounters > DRM_VC4_MAX_PERF_COUNTERS ||
151 !req->ncounters)
152 @@ -146,10 +152,16 @@ int vc4_perfmon_create_ioctl(struct drm_
153 int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
154 struct drm_file *file_priv)
155 {
156 + struct vc4_dev *vc4 = to_vc4_dev(dev);
157 struct vc4_file *vc4file = file_priv->driver_priv;
158 struct drm_vc4_perfmon_destroy *req = data;
159 struct vc4_perfmon *perfmon;
160
161 + if (!vc4->v3d) {
162 + DRM_DEBUG("Destroying perfmon no VC4 V3D probed\n");
163 + return -ENODEV;
164 + }
165 +
166 mutex_lock(&vc4file->perfmon.lock);
167 perfmon = idr_remove(&vc4file->perfmon.idr, req->id);
168 mutex_unlock(&vc4file->perfmon.lock);
169 @@ -164,11 +176,17 @@ int vc4_perfmon_destroy_ioctl(struct drm
170 int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
171 struct drm_file *file_priv)
172 {
173 + struct vc4_dev *vc4 = to_vc4_dev(dev);
174 struct vc4_file *vc4file = file_priv->driver_priv;
175 struct drm_vc4_perfmon_get_values *req = data;
176 struct vc4_perfmon *perfmon;
177 int ret;
178
179 + if (!vc4->v3d) {
180 + DRM_DEBUG("Getting perfmon no VC4 V3D probed\n");
181 + return -ENODEV;
182 + }
183 +
184 mutex_lock(&vc4file->perfmon.lock);
185 perfmon = idr_find(&vc4file->perfmon.idr, req->id);
186 vc4_perfmon_get(perfmon);
187 --- a/drivers/gpu/drm/vc4/vc4_v3d.c
188 +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
189 @@ -452,7 +452,7 @@ static int vc4_v3d_dev_remove(struct pla
190 return 0;
191 }
192
193 -static const struct of_device_id vc4_v3d_dt_match[] = {
194 +const struct of_device_id vc4_v3d_dt_match[] = {
195 { .compatible = "brcm,bcm2835-v3d" },
196 { .compatible = "brcm,cygnus-v3d" },
197 { .compatible = "brcm,vc4-v3d" },