History

Merge tag 'drm-vc4-fixes-2016-02-17' of github.com:anholt/linux into drm-fixes

This pull request fixes GPU reset (which was disabled shortly after V3D integration due to build breakage) and waits for idle in the presence of signals (which X likes to do a lot). * tag 'drm-vc4-fixes-2016-02-17' of github.com:anholt/linux: drm/vc4: Use runtime PM to power cycle the device when the GPU hangs. drm/vc4: Enable runtime PM. drm/vc4: Fix spurious GPU resets due to BO reuse. drm/vc4: Drop error message on seqno wait timeouts. drm/vc4: Fix -ERESTARTSYS error return from BO waits. drm/vc4: Return an ERR_PTR from BO creation instead of NULL. drm/vc4: Fix the clear color for the first tile rendered. drm/vc4: Validate that WAIT_BO padding is cleared.

Dave Airlie committed 10 years ago

Commit 5441ea12 parents aaa7dd2 36cb6257 files · +118 −52Browse files

Unified · Split

7 files
  1. drivers/gpu/drm/vc4/vc4_bo.c +8 −8
  2. drivers/gpu/drm/vc4/vc4_drv.h +11 −2
  3. drivers/gpu/drm/vc4/vc4_gem.c +49 −16
  4. drivers/gpu/drm/vc4/vc4_irq.c +1 −1
  5. drivers/gpu/drm/vc4/vc4_render_cl.c +11 −11
  6. drivers/gpu/drm/vc4/vc4_v3d.c +36 −12
  7. drivers/gpu/drm/vc4/vc4_validate.c +2 −2
drivers/gpu/drm/vc4/vc4_bo.c+8−8
@@ -215,7 +215,7 @@ struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t unaligned_size, · 214 unmodified lines
215215 struct drm_gem_cma_object *cma_obj;
216216
217217 if (size == 0)
218− return NULL;
218+ return ERR_PTR(-EINVAL);
219219
220220 /* First, try to get a vc4_bo from the kernel BO cache. */
221221 if (from_cache) {
@@ -237,7 +237,7 @@ struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t unaligned_size, · 15 unmodified lines
237237 if (IS_ERR(cma_obj)) {
238238 DRM_ERROR("Failed to allocate from CMA:\n");
239239 vc4_bo_stats_dump(vc4);
240− return NULL;
240+ return ERR_PTR(-ENOMEM);
241241 }
242242 }
243243
@@ -259,8 +259,8 @@ int vc4_dumb_create(struct drm_file *file_priv, · 15 unmodified lines
259259 args->size = args->pitch * args->height;
260260
261261 bo = vc4_bo_create(dev, args->size, false);
262− if (!bo)
263− return -ENOMEM;
262+ if (IS_ERR(bo))
263+ return PTR_ERR(bo);
264264
265265 ret = drm_gem_handle_create(file_priv, &bo->base.base, &args->handle);
266266 drm_gem_object_unreference_unlocked(&bo->base.base);
@@ -443,8 +443,8 @@ int vc4_create_bo_ioctl(struct drm_device *dev, void *data, · 176 unmodified lines
443443 * get zeroed, and that might leak data between users.
444444 */
445445 bo = vc4_bo_create(dev, args->size, false);
446− if (!bo)
447− return -ENOMEM;
446+ if (IS_ERR(bo))
447+ return PTR_ERR(bo);
448448
449449 ret = drm_gem_handle_create(file_priv, &bo->base.base, &args->handle);
450450 drm_gem_object_unreference_unlocked(&bo->base.base);
@@ -496,8 +496,8 @@ vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data, · 45 unmodified lines
496496 }
497497
498498 bo = vc4_bo_create(dev, args->size, true);
499− if (!bo)
500− return -ENOMEM;
499+ if (IS_ERR(bo))
500+ return PTR_ERR(bo);
501501
502502 ret = copy_from_user(bo->base.vaddr,
503503 (void __user *)(uintptr_t)args->data,
drivers/gpu/drm/vc4/vc4_drv.h+11−2
@@ -91,8 +91,12 @@ struct vc4_dev { · 90 unmodified lines
9191 struct vc4_bo *overflow_mem;
9292 struct work_struct overflow_mem_work;
9393
94+ int power_refcount;
95+
96+ /* Mutex controlling the power refcount. */
97+ struct mutex power_lock;
98+
9499 struct {
95− uint32_t last_ct0ca, last_ct1ca;
96100 struct timer_list timer;
97101 struct work_struct reset_work;
98102 } hangcheck;
@@ -142,6 +146,7 @@ struct vc4_seqno_cb { · 43 unmodified lines
142146 };
143147
144148 struct vc4_v3d {
149+ struct vc4_dev *vc4;
145150 struct platform_device *pdev;
146151 void __iomem *regs;
147152 };
@@ -192,6 +197,11 @@ struct vc4_exec_info { · 44 unmodified lines
192197 /* Sequence number for this bin/render job. */
193198 uint64_t seqno;
194199
200+ /* Last current addresses the hardware was processing when the
201+ * hangcheck timer checked on us.
202+ */
203+ uint32_t last_ct0ca, last_ct1ca;
204+
195205 /* Kernel-space copy of the ioctl arguments */
196206 struct drm_vc4_submit_cl *args;
197207
@@ -434,7 +444,6 @@ void vc4_plane_async_set_fb(struct drm_plane *plane, · 236 unmodified lines
434444 extern struct platform_driver vc4_v3d_driver;
435445 int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused);
436446 int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused);
437−int vc4_v3d_set_power(struct vc4_dev *vc4, bool on);
438447
439448 /* vc4_validate.c */
440449 int
drivers/gpu/drm/vc4/vc4_gem.c+49−16
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323
2424 #include <linux/module.h>
2525 #include <linux/platform_device.h>
26+#include <linux/pm_runtime.h>
2627 #include <linux/device.h>
2728 #include <linux/io.h>
2829
@@ -228,8 +229,16 @@ vc4_reset(struct drm_device *dev) · 199 unmodified lines
228229 struct vc4_dev *vc4 = to_vc4_dev(dev);
229230
230231 DRM_INFO("Resetting GPU.\n");
231− vc4_v3d_set_power(vc4, false);
232− vc4_v3d_set_power(vc4, true);
232+
233+ mutex_lock(&vc4->power_lock);
234+ if (vc4->power_refcount) {
235+ /* Power the device off and back on the by dropping the
236+ * reference on runtime PM.
237+ */
238+ pm_runtime_put_sync_suspend(&vc4->v3d->pdev->dev);
239+ pm_runtime_get_sync(&vc4->v3d->pdev->dev);
240+ }
241+ mutex_unlock(&vc4->power_lock);
233242
234243 vc4_irq_reset(dev);
235244
@@ -257,10 +266,17 @@ vc4_hangcheck_elapsed(unsigned long data) · 21 unmodified lines
257266 struct drm_device *dev = (struct drm_device *)data;
258267 struct vc4_dev *vc4 = to_vc4_dev(dev);
259268 uint32_t ct0ca, ct1ca;
269+ unsigned long irqflags;
270+ struct vc4_exec_info *exec;
271+
272+ spin_lock_irqsave(&vc4->job_lock, irqflags);
273+ exec = vc4_first_job(vc4);
260274
261275 /* If idle, we can stop watching for hangs. */
262− if (list_empty(&vc4->job_list))
276+ if (!exec) {
277+ spin_unlock_irqrestore(&vc4->job_lock, irqflags);
263278 return;
279+ }
264280
265281 ct0ca = V3D_READ(V3D_CTNCA(0));
266282 ct1ca = V3D_READ(V3D_CTNCA(1));
@@ -268,14 +284,16 @@ vc4_hangcheck_elapsed(unsigned long data) · 1 unmodified line
268284 /* If we've made any progress in execution, rearm the timer
269285 * and wait.
270286 */
271− if (ct0ca != vc4->hangcheck.last_ct0ca ||
272− ct1ca != vc4->hangcheck.last_ct1ca) {
273− vc4->hangcheck.last_ct0ca = ct0ca;
274− vc4->hangcheck.last_ct1ca = ct1ca;
287+ if (ct0ca != exec->last_ct0ca || ct1ca != exec->last_ct1ca) {
288+ exec->last_ct0ca = ct0ca;
289+ exec->last_ct1ca = ct1ca;
290+ spin_unlock_irqrestore(&vc4->job_lock, irqflags);
275291 vc4_queue_hangcheck(dev);
276292 return;
277293 }
278294
295+ spin_unlock_irqrestore(&vc4->job_lock, irqflags);
296+
279297 /* We've gone too long with no progress, reset. This has to
280298 * be done from a work struct, since resetting can sleep and
281299 * this timer hook isn't allowed to.
@@ -340,12 +358,7 @@ vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno, uint64_t timeout_ns, · 58 unmodified lines
340358 finish_wait(&vc4->job_wait_queue, &wait);
341359 trace_vc4_wait_for_seqno_end(dev, seqno);
342360
343− if (ret && ret != -ERESTARTSYS) {
344− DRM_ERROR("timeout waiting for render thread idle\n");
345− return ret;
346− }
347−
348− return 0;
361+ return ret;
349362 }
350363
351364 static void
@@ -578,9 +591,9 @@ vc4_get_bcl(struct drm_device *dev, struct vc4_exec_info *exec) · 226 unmodified lines
578591 }
579592
580593 bo = vc4_bo_create(dev, exec_size, true);
581− if (!bo) {
594+ if (IS_ERR(bo)) {
582595 DRM_ERROR("Couldn't allocate BO for binning\n");
583− ret = -ENOMEM;
596+ ret = PTR_ERR(bo);
584597 goto fail;
585598 }
586599 exec->exec_bo = &bo->base;
@@ -617,6 +630,7 @@ fail: · 30 unmodified lines
617630 static void
618631 vc4_complete_exec(struct drm_device *dev, struct vc4_exec_info *exec)
619632 {
633+ struct vc4_dev *vc4 = to_vc4_dev(dev);
620634 unsigned i;
621635
622636 /* Need the struct lock for drm_gem_object_unreference(). */
@@ -635,6 +649,11 @@ vc4_complete_exec(struct drm_device *dev, struct vc4_exec_info *exec) · 12 unmodified lines
635649 }
636650 mutex_unlock(&dev->struct_mutex);
637651
652+ mutex_lock(&vc4->power_lock);
653+ if (--vc4->power_refcount == 0)
654+ pm_runtime_put(&vc4->v3d->pdev->dev);
655+ mutex_unlock(&vc4->power_lock);
656+
638657 kfree(exec);
639658 }
640659
@@ -746,6 +765,9 @@ vc4_wait_bo_ioctl(struct drm_device *dev, void *data, · 105 unmodified lines
746765 struct drm_gem_object *gem_obj;
747766 struct vc4_bo *bo;
748767
768+ if (args->pad != 0)
769+ return -EINVAL;
770+
749771 gem_obj = drm_gem_object_lookup(dev, file_priv, args->handle);
750772 if (!gem_obj) {
751773 DRM_ERROR("Failed to look up GEM BO %d\n", args->handle);
@@ -772,7 +794,7 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data, · 20 unmodified lines
772794 struct vc4_dev *vc4 = to_vc4_dev(dev);
773795 struct drm_vc4_submit_cl *args = data;
774796 struct vc4_exec_info *exec;
775− int ret;
797+ int ret = 0;
776798
777799 if ((args->flags & ~VC4_SUBMIT_CL_USE_CLEAR_COLOR) != 0) {
778800 DRM_ERROR("Unknown flags: 0x%02x\n", args->flags);
@@ -785,6 +807,15 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data, · 6 unmodified lines
785807 return -ENOMEM;
786808 }
787809
810+ mutex_lock(&vc4->power_lock);
811+ if (vc4->power_refcount++ == 0)
812+ ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
813+ mutex_unlock(&vc4->power_lock);
814+ if (ret < 0) {
815+ kfree(exec);
816+ return ret;
817+ }
818+
788819 exec->args = args;
789820 INIT_LIST_HEAD(&exec->unref_list);
790821
@@ -839,6 +870,8 @@ vc4_gem_init(struct drm_device *dev) · 48 unmodified lines
839870 (unsigned long)dev);
840871
841872 INIT_WORK(&vc4->job_done_work, vc4_job_done_work);
873+
874+ mutex_init(&vc4->power_lock);
842875 }
843876
844877 void
drivers/gpu/drm/vc4/vc4_irq.c+1−1
@@ -57,7 +57,7 @@ vc4_overflow_mem_work(struct work_struct *work) · 56 unmodified lines
5757 struct vc4_bo *bo;
5858
5959 bo = vc4_bo_create(dev, 256 * 1024, true);
60− if (!bo) {
60+ if (IS_ERR(bo)) {
6161 DRM_ERROR("Couldn't allocate binner overflow mem\n");
6262 return;
6363 }
drivers/gpu/drm/vc4/vc4_render_cl.c+11−11
@@ -316,20 +316,11 @@ static int vc4_create_rcl_bo(struct drm_device *dev, struct vc4_exec_info *exec, · 315 unmodified lines
316316 size += xtiles * ytiles * loop_body_size;
317317
318318 setup->rcl = &vc4_bo_create(dev, size, true)->base;
319− if (!setup->rcl)
320− return -ENOMEM;
319+ if (IS_ERR(setup->rcl))
320+ return PTR_ERR(setup->rcl);
321321 list_add_tail(&to_vc4_bo(&setup->rcl->base)->unref_head,
322322 &exec->unref_list);
323323
324− rcl_u8(setup, VC4_PACKET_TILE_RENDERING_MODE_CONFIG);
325− rcl_u32(setup,
326− (setup->color_write ? (setup->color_write->paddr +
327− args->color_write.offset) :
328− 0));
329− rcl_u16(setup, args->width);
330− rcl_u16(setup, args->height);
331− rcl_u16(setup, args->color_write.bits);
332−
333324 /* The tile buffer gets cleared when the previous tile is stored. If
334325 * the clear values changed between frames, then the tile buffer has
335326 * stale clear values in it, so we have to do a store in None mode (no
@@ -349,6 +340,15 @@ static int vc4_create_rcl_bo(struct drm_device *dev, struct vc4_exec_info *exec, · 13 unmodified lines
349340 rcl_u32(setup, 0); /* no address, since we're in None mode */
350341 }
351342
343+ rcl_u8(setup, VC4_PACKET_TILE_RENDERING_MODE_CONFIG);
344+ rcl_u32(setup,
345+ (setup->color_write ? (setup->color_write->paddr +
346+ args->color_write.offset) :
347+ 0));
348+ rcl_u16(setup, args->width);
349+ rcl_u16(setup, args->height);
350+ rcl_u16(setup, args->color_write.bits);
351+
352352 for (y = min_y_tile; y <= max_y_tile; y++) {
353353 for (x = min_x_tile; x <= max_x_tile; x++) {
354354 bool first = (x == min_x_tile && y == min_y_tile);
drivers/gpu/drm/vc4/vc4_v3d.c+36−12
@@ -17,6 +17,7 @@ · 16 unmodified lines
1717 */
1818
1919 #include "linux/component.h"
20+#include "linux/pm_runtime.h"
2021 #include "vc4_drv.h"
2122 #include "vc4_regs.h"
2223
@@ -144,18 +145,6 @@ int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused) · 121 unmodified lines
144145 }
145146 #endif /* CONFIG_DEBUG_FS */
146147
147−int
148−vc4_v3d_set_power(struct vc4_dev *vc4, bool on)
149−{
150− /* XXX: This interface is needed for GPU reset, and the way to
151− * do it is to turn our power domain off and back on. We
152− * can't just reset from within the driver, because the reset
153− * bits are in the power domain's register area, and get set
154− * during the poweron process.
155− */
156− return 0;
157−}
158−
159148 static void vc4_v3d_init_hw(struct drm_device *dev)
160149 {
161150 struct vc4_dev *vc4 = to_vc4_dev(dev);
@@ -167,6 +156,29 @@ static void vc4_v3d_init_hw(struct drm_device *dev) · 5 unmodified lines
167156 V3D_WRITE(V3D_VPMBASE, 0);
168157 }
169158
159+#ifdef CONFIG_PM
160+static int vc4_v3d_runtime_suspend(struct device *dev)
161+{
162+ struct vc4_v3d *v3d = dev_get_drvdata(dev);
163+ struct vc4_dev *vc4 = v3d->vc4;
164+
165+ vc4_irq_uninstall(vc4->dev);
166+
167+ return 0;
168+}
169+
170+static int vc4_v3d_runtime_resume(struct device *dev)
171+{
172+ struct vc4_v3d *v3d = dev_get_drvdata(dev);
173+ struct vc4_dev *vc4 = v3d->vc4;
174+
175+ vc4_v3d_init_hw(vc4->dev);
176+ vc4_irq_postinstall(vc4->dev);
177+
178+ return 0;
179+}
180+#endif
181+
170182 static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
171183 {
172184 struct platform_device *pdev = to_platform_device(dev);
@@ -179,6 +191,8 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data) · 6 unmodified lines
179191 if (!v3d)
180192 return -ENOMEM;
181193
194+ dev_set_drvdata(dev, v3d);
195+
182196 v3d->pdev = pdev;
183197
184198 v3d->regs = vc4_ioremap_regs(pdev, 0);
@@ -186,6 +200,7 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data) · 1 unmodified line
186200 return PTR_ERR(v3d->regs);
187201
188202 vc4->v3d = v3d;
203+ v3d->vc4 = vc4;
189204
190205 if (V3D_READ(V3D_IDENT0) != V3D_EXPECTED_IDENT0) {
191206 DRM_ERROR("V3D_IDENT0 read 0x%08x instead of 0x%08x\n",
@@ -207,6 +222,8 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data) · 15 unmodified lines
207222 return ret;
208223 }
209224
225+ pm_runtime_enable(dev);
226+
210227 return 0;
211228 }
212229
@@ -216,6 +233,8 @@ static void vc4_v3d_unbind(struct device *dev, struct device *master, · 3 unmodified lines
216233 struct drm_device *drm = dev_get_drvdata(master);
217234 struct vc4_dev *vc4 = to_vc4_dev(drm);
218235
236+ pm_runtime_disable(dev);
237+
219238 drm_irq_uninstall(drm);
220239
221240 /* Disable the binner's overflow memory address, so the next
@@ -228,6 +247,10 @@ static void vc4_v3d_unbind(struct device *dev, struct device *master, · 6 unmodified lines
228247 vc4->v3d = NULL;
229248 }
230249
250+static const struct dev_pm_ops vc4_v3d_pm_ops = {
251+ SET_RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume, NULL)
252+};
253+
231254 static const struct component_ops vc4_v3d_ops = {
232255 .bind = vc4_v3d_bind,
233256 .unbind = vc4_v3d_unbind,
@@ -255,5 +278,6 @@ struct platform_driver vc4_v3d_driver = { · 21 unmodified lines
255278 .driver = {
256279 .name = "vc4_v3d",
257280 .of_match_table = vc4_v3d_dt_match,
281+ .pm = &vc4_v3d_pm_ops,
258282 },
259283 };
drivers/gpu/drm/vc4/vc4_validate.c+2−2
@@ -401,8 +401,8 @@ validate_tile_binning_config(VALIDATE_ARGS) · 400 unmodified lines
401401 tile_bo = vc4_bo_create(dev, exec->tile_alloc_offset + tile_alloc_size,
402402 true);
403403 exec->tile_bo = &tile_bo->base;
404− if (!exec->tile_bo)
405− return -ENOMEM;
404+ if (IS_ERR(exec->tile_bo))
405+ return PTR_ERR(exec->tile_bo);
406406 list_add_tail(&tile_bo->unref_head, &exec->unref_list);
407407
408408 /* tile alloc address. */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t