eec645b2b3b2800730bcf942acd11c6391f4dad9
[openwrt/staging/blogic.git] /
1 From f69f2b1354e0a548d2cb6dfdc07d37efb426eee0 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Wed, 20 Feb 2019 13:03:41 -0800
4 Subject: [PATCH 575/806] drm/vc4: Disable V3D interactions if the v3d
5 component didn't probe.
6
7 One might want to use the VC4 display stack without using Mesa.
8 Similar to the debugfs fixes for not having all of the possible
9 display bits enabled, make sure you can't oops in vc4 if v3d isn't
10 enabled.
11
12 Signed-off-by: Eric Anholt <eric@anholt.net>
13 ---
14 drivers/gpu/drm/vc4/vc4_drv.c | 11 +++++++++++
15 drivers/gpu/drm/vc4/vc4_gem.c | 10 ++++++++++
16 drivers/gpu/drm/vc4/vc4_irq.c | 9 +++++++++
17 drivers/gpu/drm/vc4/vc4_perfmon.c | 18 ++++++++++++++++++
18 4 files changed, 48 insertions(+)
19
20 --- a/drivers/gpu/drm/vc4/vc4_drv.c
21 +++ b/drivers/gpu/drm/vc4/vc4_drv.c
22 @@ -71,6 +71,9 @@ static int vc4_get_param_ioctl(struct dr
23 if (args->pad != 0)
24 return -EINVAL;
25
26 + if (!vc4->v3d)
27 + return -EINVAL;
28 +
29 switch (args->param) {
30 case DRM_VC4_PARAM_V3D_IDENT0:
31 ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
32 @@ -271,6 +274,7 @@ static int vc4_drm_bind(struct device *d
33 struct platform_device *pdev = to_platform_device(dev);
34 struct drm_device *drm;
35 struct vc4_dev *vc4;
36 + struct device_node *node;
37 int ret = 0;
38
39 dev->coherent_dma_mask = DMA_BIT_MASK(32);
40 @@ -279,6 +283,13 @@ static int vc4_drm_bind(struct device *d
41 if (!vc4)
42 return -ENOMEM;
43
44 + /* If VC4 V3D is missing, don't advertise render nodes. */
45 + node = of_find_compatible_node(NULL, NULL, "brcm,bcm2835-v3d");
46 + if (node)
47 + of_node_put(node);
48 + else
49 + vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
50 +
51 drm = drm_dev_alloc(&vc4_drm_driver, dev);
52 if (IS_ERR(drm))
53 return PTR_ERR(drm);
54 --- a/drivers/gpu/drm/vc4/vc4_gem.c
55 +++ b/drivers/gpu/drm/vc4/vc4_gem.c
56 @@ -74,6 +74,11 @@ vc4_get_hang_state_ioctl(struct drm_devi
57 u32 i;
58 int ret = 0;
59
60 + if (!vc4->v3d) {
61 + DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n");
62 + return -EINVAL;
63 + }
64 +
65 spin_lock_irqsave(&vc4->job_lock, irqflags);
66 kernel_state = vc4->hang_state;
67 if (!kernel_state) {
68 @@ -1124,6 +1129,11 @@ vc4_submit_cl_ioctl(struct drm_device *d
69 struct dma_fence *in_fence;
70 int ret = 0;
71
72 + if (!vc4->v3d) {
73 + DRM_DEBUG("VC4_SUBMIT_CL with no VC4 V3D probed\n");
74 + return -EINVAL;
75 + }
76 +
77 if ((args->flags & ~(VC4_SUBMIT_CL_USE_CLEAR_COLOR |
78 VC4_SUBMIT_CL_FIXED_RCL_ORDER |
79 VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X |
80 --- a/drivers/gpu/drm/vc4/vc4_irq.c
81 +++ b/drivers/gpu/drm/vc4/vc4_irq.c
82 @@ -229,6 +229,9 @@ vc4_irq_preinstall(struct drm_device *de
83 {
84 struct vc4_dev *vc4 = to_vc4_dev(dev);
85
86 + if (!vc4->v3d)
87 + return;
88 +
89 init_waitqueue_head(&vc4->job_wait_queue);
90 INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
91
92 @@ -243,6 +246,9 @@ vc4_irq_postinstall(struct drm_device *d
93 {
94 struct vc4_dev *vc4 = to_vc4_dev(dev);
95
96 + if (!vc4->v3d)
97 + return 0;
98 +
99 /* Enable both the render done and out of memory interrupts. */
100 V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS);
101
102 @@ -254,6 +260,9 @@ vc4_irq_uninstall(struct drm_device *dev
103 {
104 struct vc4_dev *vc4 = to_vc4_dev(dev);
105
106 + if (!vc4->v3d)
107 + return;
108 +
109 /* Disable sending interrupts for our driver's IRQs. */
110 V3D_WRITE(V3D_INTDIS, V3D_DRIVER_IRQS);
111
112 --- a/drivers/gpu/drm/vc4/vc4_perfmon.c
113 +++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
114 @@ -100,12 +100,18 @@ void vc4_perfmon_close_file(struct vc4_f
115 int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
116 struct drm_file *file_priv)
117 {
118 + struct vc4_dev *vc4 = to_vc4_dev(dev);
119 struct vc4_file *vc4file = file_priv->driver_priv;
120 struct drm_vc4_perfmon_create *req = data;
121 struct vc4_perfmon *perfmon;
122 unsigned int i;
123 int ret;
124
125 + if (!vc4->v3d) {
126 + DRM_DEBUG("Creating perfmon no VC4 V3D probed\n");
127 + return -EINVAL;
128 + }
129 +
130 /* Number of monitored counters cannot exceed HW limits. */
131 if (req->ncounters > DRM_VC4_MAX_PERF_COUNTERS ||
132 !req->ncounters)
133 @@ -146,10 +152,16 @@ int vc4_perfmon_create_ioctl(struct drm_
134 int vc4_perfmon_destroy_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_destroy *req = data;
140 struct vc4_perfmon *perfmon;
141
142 + if (!vc4->v3d) {
143 + DRM_DEBUG("Destroying perfmon no VC4 V3D probed\n");
144 + return -EINVAL;
145 + }
146 +
147 mutex_lock(&vc4file->perfmon.lock);
148 perfmon = idr_remove(&vc4file->perfmon.idr, req->id);
149 mutex_unlock(&vc4file->perfmon.lock);
150 @@ -164,11 +176,17 @@ int vc4_perfmon_destroy_ioctl(struct drm
151 int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
152 struct drm_file *file_priv)
153 {
154 + struct vc4_dev *vc4 = to_vc4_dev(dev);
155 struct vc4_file *vc4file = file_priv->driver_priv;
156 struct drm_vc4_perfmon_get_values *req = data;
157 struct vc4_perfmon *perfmon;
158 int ret;
159
160 + if (!vc4->v3d) {
161 + DRM_DEBUG("Getting perfmon no VC4 V3D probed\n");
162 + return -EINVAL;
163 + }
164 +
165 mutex_lock(&vc4file->perfmon.lock);
166 perfmon = idr_find(&vc4file->perfmon.idr, req->id);
167 vc4_perfmon_get(perfmon);