xref: /openbmc/linux/drivers/gpu/drm/v3d/v3d_gem.c (revision a7dde1b7a5c9adf13d422240d02b812952660a35)
157692c94SEric Anholt // SPDX-License-Identifier: GPL-2.0+
257692c94SEric Anholt /* Copyright (C) 2014-2018 Broadcom */
357692c94SEric Anholt 
457692c94SEric Anholt #include <drm/drmP.h>
557692c94SEric Anholt #include <drm/drm_syncobj.h>
657692c94SEric Anholt #include <linux/module.h>
757692c94SEric Anholt #include <linux/platform_device.h>
857692c94SEric Anholt #include <linux/pm_runtime.h>
957692c94SEric Anholt #include <linux/device.h>
1057692c94SEric Anholt #include <linux/io.h>
1157692c94SEric Anholt #include <linux/sched/signal.h>
1257692c94SEric Anholt 
1357692c94SEric Anholt #include "uapi/drm/v3d_drm.h"
1457692c94SEric Anholt #include "v3d_drv.h"
1557692c94SEric Anholt #include "v3d_regs.h"
1657692c94SEric Anholt #include "v3d_trace.h"
1757692c94SEric Anholt 
1857692c94SEric Anholt static void
1957692c94SEric Anholt v3d_init_core(struct v3d_dev *v3d, int core)
2057692c94SEric Anholt {
2157692c94SEric Anholt 	/* Set OVRTMUOUT, which means that the texture sampler uniform
2257692c94SEric Anholt 	 * configuration's tmu output type field is used, instead of
2357692c94SEric Anholt 	 * using the hardware default behavior based on the texture
2457692c94SEric Anholt 	 * type.  If you want the default behavior, you can still put
2557692c94SEric Anholt 	 * "2" in the indirect texture state's output_type field.
2657692c94SEric Anholt 	 */
27*a7dde1b7SEric Anholt 	if (v3d->ver < 40)
2857692c94SEric Anholt 		V3D_CORE_WRITE(core, V3D_CTL_MISCCFG, V3D_MISCCFG_OVRTMUOUT);
2957692c94SEric Anholt 
3057692c94SEric Anholt 	/* Whenever we flush the L2T cache, we always want to flush
3157692c94SEric Anholt 	 * the whole thing.
3257692c94SEric Anholt 	 */
3357692c94SEric Anholt 	V3D_CORE_WRITE(core, V3D_CTL_L2TFLSTA, 0);
3457692c94SEric Anholt 	V3D_CORE_WRITE(core, V3D_CTL_L2TFLEND, ~0);
3557692c94SEric Anholt }
3657692c94SEric Anholt 
3757692c94SEric Anholt /* Sets invariant state for the HW. */
3857692c94SEric Anholt static void
3957692c94SEric Anholt v3d_init_hw_state(struct v3d_dev *v3d)
4057692c94SEric Anholt {
4157692c94SEric Anholt 	v3d_init_core(v3d, 0);
4257692c94SEric Anholt }
4357692c94SEric Anholt 
4457692c94SEric Anholt static void
4557692c94SEric Anholt v3d_idle_axi(struct v3d_dev *v3d, int core)
4657692c94SEric Anholt {
4757692c94SEric Anholt 	V3D_CORE_WRITE(core, V3D_GMP_CFG, V3D_GMP_CFG_STOP_REQ);
4857692c94SEric Anholt 
4957692c94SEric Anholt 	if (wait_for((V3D_CORE_READ(core, V3D_GMP_STATUS) &
5057692c94SEric Anholt 		      (V3D_GMP_STATUS_RD_COUNT_MASK |
5157692c94SEric Anholt 		       V3D_GMP_STATUS_WR_COUNT_MASK |
5257692c94SEric Anholt 		       V3D_GMP_STATUS_CFG_BUSY)) == 0, 100)) {
5357692c94SEric Anholt 		DRM_ERROR("Failed to wait for safe GMP shutdown\n");
5457692c94SEric Anholt 	}
5557692c94SEric Anholt }
5657692c94SEric Anholt 
5757692c94SEric Anholt static void
5857692c94SEric Anholt v3d_idle_gca(struct v3d_dev *v3d)
5957692c94SEric Anholt {
6057692c94SEric Anholt 	if (v3d->ver >= 41)
6157692c94SEric Anholt 		return;
6257692c94SEric Anholt 
6357692c94SEric Anholt 	V3D_GCA_WRITE(V3D_GCA_SAFE_SHUTDOWN, V3D_GCA_SAFE_SHUTDOWN_EN);
6457692c94SEric Anholt 
6557692c94SEric Anholt 	if (wait_for((V3D_GCA_READ(V3D_GCA_SAFE_SHUTDOWN_ACK) &
6657692c94SEric Anholt 		      V3D_GCA_SAFE_SHUTDOWN_ACK_ACKED) ==
6757692c94SEric Anholt 		     V3D_GCA_SAFE_SHUTDOWN_ACK_ACKED, 100)) {
6857692c94SEric Anholt 		DRM_ERROR("Failed to wait for safe GCA shutdown\n");
6957692c94SEric Anholt 	}
7057692c94SEric Anholt }
7157692c94SEric Anholt 
7257692c94SEric Anholt static void
7357692c94SEric Anholt v3d_reset_v3d(struct v3d_dev *v3d)
7457692c94SEric Anholt {
7557692c94SEric Anholt 	int version = V3D_BRIDGE_READ(V3D_TOP_GR_BRIDGE_REVISION);
7657692c94SEric Anholt 
7757692c94SEric Anholt 	if (V3D_GET_FIELD(version, V3D_TOP_GR_BRIDGE_MAJOR) == 2) {
7857692c94SEric Anholt 		V3D_BRIDGE_WRITE(V3D_TOP_GR_BRIDGE_SW_INIT_0,
7957692c94SEric Anholt 				 V3D_TOP_GR_BRIDGE_SW_INIT_0_V3D_CLK_108_SW_INIT);
8057692c94SEric Anholt 		V3D_BRIDGE_WRITE(V3D_TOP_GR_BRIDGE_SW_INIT_0, 0);
8157692c94SEric Anholt 
8257692c94SEric Anholt 		/* GFXH-1383: The SW_INIT may cause a stray write to address 0
8357692c94SEric Anholt 		 * of the unit, so reset it to its power-on value here.
8457692c94SEric Anholt 		 */
8557692c94SEric Anholt 		V3D_WRITE(V3D_HUB_AXICFG, V3D_HUB_AXICFG_MAX_LEN_MASK);
8657692c94SEric Anholt 	} else {
8757692c94SEric Anholt 		WARN_ON_ONCE(V3D_GET_FIELD(version,
8857692c94SEric Anholt 					   V3D_TOP_GR_BRIDGE_MAJOR) != 7);
8957692c94SEric Anholt 		V3D_BRIDGE_WRITE(V3D_TOP_GR_BRIDGE_SW_INIT_1,
9057692c94SEric Anholt 				 V3D_TOP_GR_BRIDGE_SW_INIT_1_V3D_CLK_108_SW_INIT);
9157692c94SEric Anholt 		V3D_BRIDGE_WRITE(V3D_TOP_GR_BRIDGE_SW_INIT_1, 0);
9257692c94SEric Anholt 	}
9357692c94SEric Anholt 
9457692c94SEric Anholt 	v3d_init_hw_state(v3d);
9557692c94SEric Anholt }
9657692c94SEric Anholt 
9757692c94SEric Anholt void
9857692c94SEric Anholt v3d_reset(struct v3d_dev *v3d)
9957692c94SEric Anholt {
10057692c94SEric Anholt 	struct drm_device *dev = &v3d->drm;
10157692c94SEric Anholt 
10257692c94SEric Anholt 	DRM_ERROR("Resetting GPU.\n");
10357692c94SEric Anholt 	trace_v3d_reset_begin(dev);
10457692c94SEric Anholt 
10557692c94SEric Anholt 	/* XXX: only needed for safe powerdown, not reset. */
10657692c94SEric Anholt 	if (false)
10757692c94SEric Anholt 		v3d_idle_axi(v3d, 0);
10857692c94SEric Anholt 
10957692c94SEric Anholt 	v3d_idle_gca(v3d);
11057692c94SEric Anholt 	v3d_reset_v3d(v3d);
11157692c94SEric Anholt 
11257692c94SEric Anholt 	v3d_mmu_set_page_table(v3d);
11357692c94SEric Anholt 	v3d_irq_reset(v3d);
11457692c94SEric Anholt 
11557692c94SEric Anholt 	trace_v3d_reset_end(dev);
11657692c94SEric Anholt }
11757692c94SEric Anholt 
11857692c94SEric Anholt static void
11957692c94SEric Anholt v3d_flush_l3(struct v3d_dev *v3d)
12057692c94SEric Anholt {
12157692c94SEric Anholt 	if (v3d->ver < 41) {
12257692c94SEric Anholt 		u32 gca_ctrl = V3D_GCA_READ(V3D_GCA_CACHE_CTRL);
12357692c94SEric Anholt 
12457692c94SEric Anholt 		V3D_GCA_WRITE(V3D_GCA_CACHE_CTRL,
12557692c94SEric Anholt 			      gca_ctrl | V3D_GCA_CACHE_CTRL_FLUSH);
12657692c94SEric Anholt 
12757692c94SEric Anholt 		if (v3d->ver < 33) {
12857692c94SEric Anholt 			V3D_GCA_WRITE(V3D_GCA_CACHE_CTRL,
12957692c94SEric Anholt 				      gca_ctrl & ~V3D_GCA_CACHE_CTRL_FLUSH);
13057692c94SEric Anholt 		}
13157692c94SEric Anholt 	}
13257692c94SEric Anholt }
13357692c94SEric Anholt 
1347b9d2fe4SEric Anholt /* Invalidates the (read-only) L2C cache.  This was the L2 cache for
1357b9d2fe4SEric Anholt  * uniforms and instructions on V3D 3.2.
1367b9d2fe4SEric Anholt  */
13757692c94SEric Anholt static void
1387b9d2fe4SEric Anholt v3d_invalidate_l2c(struct v3d_dev *v3d, int core)
13957692c94SEric Anholt {
1407b9d2fe4SEric Anholt 	if (v3d->ver > 32)
1417b9d2fe4SEric Anholt 		return;
1427b9d2fe4SEric Anholt 
14357692c94SEric Anholt 	V3D_CORE_WRITE(core, V3D_CTL_L2CACTL,
14457692c94SEric Anholt 		       V3D_L2CACTL_L2CCLR |
14557692c94SEric Anholt 		       V3D_L2CACTL_L2CENA);
14657692c94SEric Anholt }
14757692c94SEric Anholt 
14857692c94SEric Anholt /* Invalidates texture L2 cachelines */
14957692c94SEric Anholt static void
15057692c94SEric Anholt v3d_flush_l2t(struct v3d_dev *v3d, int core)
15157692c94SEric Anholt {
15251c1b6f9SEric Anholt 	/* While there is a busy bit (V3D_L2TCACTL_L2TFLS), we don't
15351c1b6f9SEric Anholt 	 * need to wait for completion before dispatching the job --
15451c1b6f9SEric Anholt 	 * L2T accesses will be stalled until the flush has completed.
15551c1b6f9SEric Anholt 	 */
15657692c94SEric Anholt 	V3D_CORE_WRITE(core, V3D_CTL_L2TCACTL,
15757692c94SEric Anholt 		       V3D_L2TCACTL_L2TFLS |
15857692c94SEric Anholt 		       V3D_SET_FIELD(V3D_L2TCACTL_FLM_FLUSH, V3D_L2TCACTL_FLM));
15957692c94SEric Anholt }
16057692c94SEric Anholt 
16157692c94SEric Anholt /* Invalidates the slice caches.  These are read-only caches. */
16257692c94SEric Anholt static void
16357692c94SEric Anholt v3d_invalidate_slices(struct v3d_dev *v3d, int core)
16457692c94SEric Anholt {
16557692c94SEric Anholt 	V3D_CORE_WRITE(core, V3D_CTL_SLCACTL,
16657692c94SEric Anholt 		       V3D_SET_FIELD(0xf, V3D_SLCACTL_TVCCS) |
16757692c94SEric Anholt 		       V3D_SET_FIELD(0xf, V3D_SLCACTL_TDCCS) |
16857692c94SEric Anholt 		       V3D_SET_FIELD(0xf, V3D_SLCACTL_UCC) |
16957692c94SEric Anholt 		       V3D_SET_FIELD(0xf, V3D_SLCACTL_ICC));
17057692c94SEric Anholt }
17157692c94SEric Anholt 
17257692c94SEric Anholt void
17357692c94SEric Anholt v3d_invalidate_caches(struct v3d_dev *v3d)
17457692c94SEric Anholt {
175aa5beec3SEric Anholt 	/* Invalidate the caches from the outside in.  That way if
176aa5beec3SEric Anholt 	 * another CL's concurrent use of nearby memory were to pull
177aa5beec3SEric Anholt 	 * an invalidated cacheline back in, we wouldn't leave stale
178aa5beec3SEric Anholt 	 * data in the inner cache.
179aa5beec3SEric Anholt 	 */
18057692c94SEric Anholt 	v3d_flush_l3(v3d);
1817b9d2fe4SEric Anholt 	v3d_invalidate_l2c(v3d, 0);
18257692c94SEric Anholt 	v3d_flush_l2t(v3d, 0);
183aa5beec3SEric Anholt 	v3d_invalidate_slices(v3d, 0);
18457692c94SEric Anholt }
18557692c94SEric Anholt 
18657692c94SEric Anholt static void
1871584f16cSEric Anholt v3d_attach_object_fences(struct v3d_bo **bos, int bo_count,
1881584f16cSEric Anholt 			 struct dma_fence *fence)
18957692c94SEric Anholt {
19057692c94SEric Anholt 	int i;
19157692c94SEric Anholt 
1921584f16cSEric Anholt 	for (i = 0; i < bo_count; i++) {
19357692c94SEric Anholt 		/* XXX: Use shared fences for read-only objects. */
1948d668309SRob Herring 		reservation_object_add_excl_fence(bos[i]->base.resv, fence);
19557692c94SEric Anholt 	}
19657692c94SEric Anholt }
19757692c94SEric Anholt 
19857692c94SEric Anholt static void
199e14a07fcSEric Anholt v3d_unlock_bo_reservations(struct v3d_bo **bos,
2001584f16cSEric Anholt 			   int bo_count,
20157692c94SEric Anholt 			   struct ww_acquire_ctx *acquire_ctx)
20257692c94SEric Anholt {
20357692c94SEric Anholt 	int i;
20457692c94SEric Anholt 
2051584f16cSEric Anholt 	for (i = 0; i < bo_count; i++)
2068d668309SRob Herring 		ww_mutex_unlock(&bos[i]->base.resv->lock);
20757692c94SEric Anholt 
20857692c94SEric Anholt 	ww_acquire_fini(acquire_ctx);
20957692c94SEric Anholt }
21057692c94SEric Anholt 
21157692c94SEric Anholt /* Takes the reservation lock on all the BOs being referenced, so that
21257692c94SEric Anholt  * at queue submit time we can update the reservations.
21357692c94SEric Anholt  *
21457692c94SEric Anholt  * We don't lock the RCL the tile alloc/state BOs, or overflow memory
21557692c94SEric Anholt  * (all of which are on exec->unref_list).  They're entirely private
21657692c94SEric Anholt  * to v3d, so we don't attach dma-buf fences to them.
21757692c94SEric Anholt  */
21857692c94SEric Anholt static int
219e14a07fcSEric Anholt v3d_lock_bo_reservations(struct v3d_bo **bos,
2201584f16cSEric Anholt 			 int bo_count,
22157692c94SEric Anholt 			 struct ww_acquire_ctx *acquire_ctx)
22257692c94SEric Anholt {
22357692c94SEric Anholt 	int contended_lock = -1;
22457692c94SEric Anholt 	int i, ret;
22557692c94SEric Anholt 
22657692c94SEric Anholt 	ww_acquire_init(acquire_ctx, &reservation_ww_class);
22757692c94SEric Anholt 
22857692c94SEric Anholt retry:
22957692c94SEric Anholt 	if (contended_lock != -1) {
2301584f16cSEric Anholt 		struct v3d_bo *bo = bos[contended_lock];
2318f1cd826SEric Anholt 
2328d668309SRob Herring 		ret = ww_mutex_lock_slow_interruptible(&bo->base.resv->lock,
23357692c94SEric Anholt 						       acquire_ctx);
23457692c94SEric Anholt 		if (ret) {
23557692c94SEric Anholt 			ww_acquire_done(acquire_ctx);
23657692c94SEric Anholt 			return ret;
23757692c94SEric Anholt 		}
23857692c94SEric Anholt 	}
23957692c94SEric Anholt 
2401584f16cSEric Anholt 	for (i = 0; i < bo_count; i++) {
24157692c94SEric Anholt 		if (i == contended_lock)
24257692c94SEric Anholt 			continue;
24357692c94SEric Anholt 
2448d668309SRob Herring 		ret = ww_mutex_lock_interruptible(&bos[i]->base.resv->lock,
2458f1cd826SEric Anholt 						  acquire_ctx);
24657692c94SEric Anholt 		if (ret) {
24757692c94SEric Anholt 			int j;
24857692c94SEric Anholt 
2498f1cd826SEric Anholt 			for (j = 0; j < i; j++)
2508d668309SRob Herring 				ww_mutex_unlock(&bos[j]->base.resv->lock);
25157692c94SEric Anholt 
25257692c94SEric Anholt 			if (contended_lock != -1 && contended_lock >= i) {
2531584f16cSEric Anholt 				struct v3d_bo *bo = bos[contended_lock];
25457692c94SEric Anholt 
2558d668309SRob Herring 				ww_mutex_unlock(&bo->base.resv->lock);
25657692c94SEric Anholt 			}
25757692c94SEric Anholt 
25857692c94SEric Anholt 			if (ret == -EDEADLK) {
25957692c94SEric Anholt 				contended_lock = i;
26057692c94SEric Anholt 				goto retry;
26157692c94SEric Anholt 			}
26257692c94SEric Anholt 
26357692c94SEric Anholt 			ww_acquire_done(acquire_ctx);
26457692c94SEric Anholt 			return ret;
26557692c94SEric Anholt 		}
26657692c94SEric Anholt 	}
26757692c94SEric Anholt 
26857692c94SEric Anholt 	ww_acquire_done(acquire_ctx);
26957692c94SEric Anholt 
27057692c94SEric Anholt 	/* Reserve space for our shared (read-only) fence references,
27157692c94SEric Anholt 	 * before we commit the CL to the hardware.
27257692c94SEric Anholt 	 */
2731584f16cSEric Anholt 	for (i = 0; i < bo_count; i++) {
2748d668309SRob Herring 		ret = reservation_object_reserve_shared(bos[i]->base.resv, 1);
27557692c94SEric Anholt 		if (ret) {
276e14a07fcSEric Anholt 			v3d_unlock_bo_reservations(bos, bo_count,
2771584f16cSEric Anholt 						   acquire_ctx);
27857692c94SEric Anholt 			return ret;
27957692c94SEric Anholt 		}
28057692c94SEric Anholt 	}
28157692c94SEric Anholt 
28257692c94SEric Anholt 	return 0;
28357692c94SEric Anholt }
28457692c94SEric Anholt 
28557692c94SEric Anholt /**
28657692c94SEric Anholt  * v3d_cl_lookup_bos() - Sets up exec->bo[] with the GEM objects
28757692c94SEric Anholt  * referenced by the job.
28857692c94SEric Anholt  * @dev: DRM device
28957692c94SEric Anholt  * @file_priv: DRM file for this fd
29057692c94SEric Anholt  * @exec: V3D job being set up
29157692c94SEric Anholt  *
29257692c94SEric Anholt  * The command validator needs to reference BOs by their index within
29357692c94SEric Anholt  * the submitted job's BO list.  This does the validation of the job's
29457692c94SEric Anholt  * BO list and reference counting for the lifetime of the job.
29557692c94SEric Anholt  *
29657692c94SEric Anholt  * Note that this function doesn't need to unreference the BOs on
29757692c94SEric Anholt  * failure, because that will happen at v3d_exec_cleanup() time.
29857692c94SEric Anholt  */
29957692c94SEric Anholt static int
30057692c94SEric Anholt v3d_cl_lookup_bos(struct drm_device *dev,
30157692c94SEric Anholt 		  struct drm_file *file_priv,
30257692c94SEric Anholt 		  struct drm_v3d_submit_cl *args,
30357692c94SEric Anholt 		  struct v3d_exec_info *exec)
30457692c94SEric Anholt {
30557692c94SEric Anholt 	u32 *handles;
30657692c94SEric Anholt 	int ret = 0;
30757692c94SEric Anholt 	int i;
30857692c94SEric Anholt 
30957692c94SEric Anholt 	exec->bo_count = args->bo_handle_count;
31057692c94SEric Anholt 
31157692c94SEric Anholt 	if (!exec->bo_count) {
31257692c94SEric Anholt 		/* See comment on bo_index for why we have to check
31357692c94SEric Anholt 		 * this.
31457692c94SEric Anholt 		 */
31557692c94SEric Anholt 		DRM_DEBUG("Rendering requires BOs\n");
31657692c94SEric Anholt 		return -EINVAL;
31757692c94SEric Anholt 	}
31857692c94SEric Anholt 
31957692c94SEric Anholt 	exec->bo = kvmalloc_array(exec->bo_count,
32057692c94SEric Anholt 				  sizeof(struct drm_gem_cma_object *),
32157692c94SEric Anholt 				  GFP_KERNEL | __GFP_ZERO);
32257692c94SEric Anholt 	if (!exec->bo) {
32357692c94SEric Anholt 		DRM_DEBUG("Failed to allocate validated BO pointers\n");
32457692c94SEric Anholt 		return -ENOMEM;
32557692c94SEric Anholt 	}
32657692c94SEric Anholt 
32757692c94SEric Anholt 	handles = kvmalloc_array(exec->bo_count, sizeof(u32), GFP_KERNEL);
32857692c94SEric Anholt 	if (!handles) {
32957692c94SEric Anholt 		ret = -ENOMEM;
33057692c94SEric Anholt 		DRM_DEBUG("Failed to allocate incoming GEM handles\n");
33157692c94SEric Anholt 		goto fail;
33257692c94SEric Anholt 	}
33357692c94SEric Anholt 
33457692c94SEric Anholt 	if (copy_from_user(handles,
33557692c94SEric Anholt 			   (void __user *)(uintptr_t)args->bo_handles,
33657692c94SEric Anholt 			   exec->bo_count * sizeof(u32))) {
33757692c94SEric Anholt 		ret = -EFAULT;
33857692c94SEric Anholt 		DRM_DEBUG("Failed to copy in GEM handles\n");
33957692c94SEric Anholt 		goto fail;
34057692c94SEric Anholt 	}
34157692c94SEric Anholt 
34257692c94SEric Anholt 	spin_lock(&file_priv->table_lock);
34357692c94SEric Anholt 	for (i = 0; i < exec->bo_count; i++) {
34457692c94SEric Anholt 		struct drm_gem_object *bo = idr_find(&file_priv->object_idr,
34557692c94SEric Anholt 						     handles[i]);
34657692c94SEric Anholt 		if (!bo) {
34757692c94SEric Anholt 			DRM_DEBUG("Failed to look up GEM BO %d: %d\n",
34857692c94SEric Anholt 				  i, handles[i]);
34957692c94SEric Anholt 			ret = -ENOENT;
35057692c94SEric Anholt 			spin_unlock(&file_priv->table_lock);
35157692c94SEric Anholt 			goto fail;
35257692c94SEric Anholt 		}
35357692c94SEric Anholt 		drm_gem_object_get(bo);
35457692c94SEric Anholt 		exec->bo[i] = to_v3d_bo(bo);
35557692c94SEric Anholt 	}
35657692c94SEric Anholt 	spin_unlock(&file_priv->table_lock);
35757692c94SEric Anholt 
35857692c94SEric Anholt fail:
35957692c94SEric Anholt 	kvfree(handles);
36057692c94SEric Anholt 	return ret;
36157692c94SEric Anholt }
36257692c94SEric Anholt 
36357692c94SEric Anholt static void
36457692c94SEric Anholt v3d_exec_cleanup(struct kref *ref)
36557692c94SEric Anholt {
36657692c94SEric Anholt 	struct v3d_exec_info *exec = container_of(ref, struct v3d_exec_info,
36757692c94SEric Anholt 						  refcount);
36857692c94SEric Anholt 	struct v3d_dev *v3d = exec->v3d;
36957692c94SEric Anholt 	unsigned int i;
37057692c94SEric Anholt 	struct v3d_bo *bo, *save;
37157692c94SEric Anholt 
37257692c94SEric Anholt 	dma_fence_put(exec->bin.in_fence);
37357692c94SEric Anholt 	dma_fence_put(exec->render.in_fence);
37457692c94SEric Anholt 
37557692c94SEric Anholt 	dma_fence_put(exec->bin.done_fence);
37657692c94SEric Anholt 	dma_fence_put(exec->render.done_fence);
37757692c94SEric Anholt 
37857692c94SEric Anholt 	dma_fence_put(exec->bin_done_fence);
37934c2c4f6SEric Anholt 	dma_fence_put(exec->render_done_fence);
38057692c94SEric Anholt 
38157692c94SEric Anholt 	for (i = 0; i < exec->bo_count; i++)
38257692c94SEric Anholt 		drm_gem_object_put_unlocked(&exec->bo[i]->base);
38357692c94SEric Anholt 	kvfree(exec->bo);
38457692c94SEric Anholt 
38557692c94SEric Anholt 	list_for_each_entry_safe(bo, save, &exec->unref_list, unref_head) {
38657692c94SEric Anholt 		drm_gem_object_put_unlocked(&bo->base);
38757692c94SEric Anholt 	}
38857692c94SEric Anholt 
38957692c94SEric Anholt 	pm_runtime_mark_last_busy(v3d->dev);
39057692c94SEric Anholt 	pm_runtime_put_autosuspend(v3d->dev);
39157692c94SEric Anholt 
39257692c94SEric Anholt 	kfree(exec);
39357692c94SEric Anholt }
39457692c94SEric Anholt 
39557692c94SEric Anholt void v3d_exec_put(struct v3d_exec_info *exec)
39657692c94SEric Anholt {
39757692c94SEric Anholt 	kref_put(&exec->refcount, v3d_exec_cleanup);
39857692c94SEric Anholt }
39957692c94SEric Anholt 
4001584f16cSEric Anholt static void
4011584f16cSEric Anholt v3d_tfu_job_cleanup(struct kref *ref)
4021584f16cSEric Anholt {
4031584f16cSEric Anholt 	struct v3d_tfu_job *job = container_of(ref, struct v3d_tfu_job,
4041584f16cSEric Anholt 					       refcount);
4051584f16cSEric Anholt 	struct v3d_dev *v3d = job->v3d;
4061584f16cSEric Anholt 	unsigned int i;
4071584f16cSEric Anholt 
4081584f16cSEric Anholt 	dma_fence_put(job->in_fence);
4091584f16cSEric Anholt 	dma_fence_put(job->done_fence);
4101584f16cSEric Anholt 
4111584f16cSEric Anholt 	for (i = 0; i < ARRAY_SIZE(job->bo); i++) {
4121584f16cSEric Anholt 		if (job->bo[i])
4131584f16cSEric Anholt 			drm_gem_object_put_unlocked(&job->bo[i]->base);
4141584f16cSEric Anholt 	}
4151584f16cSEric Anholt 
4161584f16cSEric Anholt 	pm_runtime_mark_last_busy(v3d->dev);
4171584f16cSEric Anholt 	pm_runtime_put_autosuspend(v3d->dev);
4181584f16cSEric Anholt 
4191584f16cSEric Anholt 	kfree(job);
4201584f16cSEric Anholt }
4211584f16cSEric Anholt 
4221584f16cSEric Anholt void v3d_tfu_job_put(struct v3d_tfu_job *job)
4231584f16cSEric Anholt {
4241584f16cSEric Anholt 	kref_put(&job->refcount, v3d_tfu_job_cleanup);
4251584f16cSEric Anholt }
4261584f16cSEric Anholt 
42757692c94SEric Anholt int
42857692c94SEric Anholt v3d_wait_bo_ioctl(struct drm_device *dev, void *data,
42957692c94SEric Anholt 		  struct drm_file *file_priv)
43057692c94SEric Anholt {
43157692c94SEric Anholt 	int ret;
43257692c94SEric Anholt 	struct drm_v3d_wait_bo *args = data;
43357692c94SEric Anholt 	ktime_t start = ktime_get();
43457692c94SEric Anholt 	u64 delta_ns;
43557692c94SEric Anholt 	unsigned long timeout_jiffies =
43657692c94SEric Anholt 		nsecs_to_jiffies_timeout(args->timeout_ns);
43757692c94SEric Anholt 
43857692c94SEric Anholt 	if (args->pad != 0)
43957692c94SEric Anholt 		return -EINVAL;
44057692c94SEric Anholt 
4418d668309SRob Herring 	ret = drm_gem_reservation_object_wait(file_priv, args->handle,
4428d668309SRob Herring 					      true, timeout_jiffies);
44357692c94SEric Anholt 
44457692c94SEric Anholt 	/* Decrement the user's timeout, in case we got interrupted
44557692c94SEric Anholt 	 * such that the ioctl will be restarted.
44657692c94SEric Anholt 	 */
44757692c94SEric Anholt 	delta_ns = ktime_to_ns(ktime_sub(ktime_get(), start));
44857692c94SEric Anholt 	if (delta_ns < args->timeout_ns)
44957692c94SEric Anholt 		args->timeout_ns -= delta_ns;
45057692c94SEric Anholt 	else
45157692c94SEric Anholt 		args->timeout_ns = 0;
45257692c94SEric Anholt 
45357692c94SEric Anholt 	/* Asked to wait beyond the jiffie/scheduler precision? */
45457692c94SEric Anholt 	if (ret == -ETIME && args->timeout_ns)
45557692c94SEric Anholt 		ret = -EAGAIN;
45657692c94SEric Anholt 
45757692c94SEric Anholt 	return ret;
45857692c94SEric Anholt }
45957692c94SEric Anholt 
46057692c94SEric Anholt /**
46157692c94SEric Anholt  * v3d_submit_cl_ioctl() - Submits a job (frame) to the V3D.
46257692c94SEric Anholt  * @dev: DRM device
46357692c94SEric Anholt  * @data: ioctl argument
46457692c94SEric Anholt  * @file_priv: DRM file for this fd
46557692c94SEric Anholt  *
46657692c94SEric Anholt  * This is the main entrypoint for userspace to submit a 3D frame to
46757692c94SEric Anholt  * the GPU.  Userspace provides the binner command list (if
46857692c94SEric Anholt  * applicable), and the kernel sets up the render command list to draw
46957692c94SEric Anholt  * to the framebuffer described in the ioctl, using the command lists
47057692c94SEric Anholt  * that the 3D engine's binner will produce.
47157692c94SEric Anholt  */
47257692c94SEric Anholt int
47357692c94SEric Anholt v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
47457692c94SEric Anholt 		    struct drm_file *file_priv)
47557692c94SEric Anholt {
47657692c94SEric Anholt 	struct v3d_dev *v3d = to_v3d_dev(dev);
47757692c94SEric Anholt 	struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
47857692c94SEric Anholt 	struct drm_v3d_submit_cl *args = data;
47957692c94SEric Anholt 	struct v3d_exec_info *exec;
48057692c94SEric Anholt 	struct ww_acquire_ctx acquire_ctx;
48157692c94SEric Anholt 	struct drm_syncobj *sync_out;
48257692c94SEric Anholt 	int ret = 0;
48357692c94SEric Anholt 
48455a9b748SEric Anholt 	trace_v3d_submit_cl_ioctl(&v3d->drm, args->rcl_start, args->rcl_end);
48555a9b748SEric Anholt 
48657692c94SEric Anholt 	if (args->pad != 0) {
48757692c94SEric Anholt 		DRM_INFO("pad must be zero: %d\n", args->pad);
48857692c94SEric Anholt 		return -EINVAL;
48957692c94SEric Anholt 	}
49057692c94SEric Anholt 
49157692c94SEric Anholt 	exec = kcalloc(1, sizeof(*exec), GFP_KERNEL);
49257692c94SEric Anholt 	if (!exec)
49357692c94SEric Anholt 		return -ENOMEM;
49457692c94SEric Anholt 
49557692c94SEric Anholt 	ret = pm_runtime_get_sync(v3d->dev);
49657692c94SEric Anholt 	if (ret < 0) {
49757692c94SEric Anholt 		kfree(exec);
49857692c94SEric Anholt 		return ret;
49957692c94SEric Anholt 	}
50057692c94SEric Anholt 
50157692c94SEric Anholt 	kref_init(&exec->refcount);
50257692c94SEric Anholt 
50357692c94SEric Anholt 	ret = drm_syncobj_find_fence(file_priv, args->in_sync_bcl,
504649fdce2SChunming Zhou 				     0, 0, &exec->bin.in_fence);
50557692c94SEric Anholt 	if (ret == -EINVAL)
50657692c94SEric Anholt 		goto fail;
50757692c94SEric Anholt 
50857692c94SEric Anholt 	ret = drm_syncobj_find_fence(file_priv, args->in_sync_rcl,
509649fdce2SChunming Zhou 				     0, 0, &exec->render.in_fence);
51057692c94SEric Anholt 	if (ret == -EINVAL)
51157692c94SEric Anholt 		goto fail;
51257692c94SEric Anholt 
51357692c94SEric Anholt 	exec->qma = args->qma;
51457692c94SEric Anholt 	exec->qms = args->qms;
51557692c94SEric Anholt 	exec->qts = args->qts;
51657692c94SEric Anholt 	exec->bin.exec = exec;
51757692c94SEric Anholt 	exec->bin.start = args->bcl_start;
51857692c94SEric Anholt 	exec->bin.end = args->bcl_end;
51957692c94SEric Anholt 	exec->render.exec = exec;
52057692c94SEric Anholt 	exec->render.start = args->rcl_start;
52157692c94SEric Anholt 	exec->render.end = args->rcl_end;
52257692c94SEric Anholt 	exec->v3d = v3d;
52357692c94SEric Anholt 	INIT_LIST_HEAD(&exec->unref_list);
52457692c94SEric Anholt 
52557692c94SEric Anholt 	ret = v3d_cl_lookup_bos(dev, file_priv, args, exec);
52657692c94SEric Anholt 	if (ret)
52757692c94SEric Anholt 		goto fail;
52857692c94SEric Anholt 
529e14a07fcSEric Anholt 	ret = v3d_lock_bo_reservations(exec->bo, exec->bo_count,
5301584f16cSEric Anholt 				       &acquire_ctx);
53157692c94SEric Anholt 	if (ret)
53257692c94SEric Anholt 		goto fail;
53357692c94SEric Anholt 
5347122b68bSEric Anholt 	mutex_lock(&v3d->sched_lock);
53557692c94SEric Anholt 	if (exec->bin.start != exec->bin.end) {
53657692c94SEric Anholt 		ret = drm_sched_job_init(&exec->bin.base,
53757692c94SEric Anholt 					 &v3d_priv->sched_entity[V3D_BIN],
53857692c94SEric Anholt 					 v3d_priv);
53957692c94SEric Anholt 		if (ret)
54057692c94SEric Anholt 			goto fail_unreserve;
54157692c94SEric Anholt 
54257692c94SEric Anholt 		exec->bin_done_fence =
54357692c94SEric Anholt 			dma_fence_get(&exec->bin.base.s_fence->finished);
54457692c94SEric Anholt 
54557692c94SEric Anholt 		kref_get(&exec->refcount); /* put by scheduler job completion */
54657692c94SEric Anholt 		drm_sched_entity_push_job(&exec->bin.base,
54757692c94SEric Anholt 					  &v3d_priv->sched_entity[V3D_BIN]);
54857692c94SEric Anholt 	}
54957692c94SEric Anholt 
55057692c94SEric Anholt 	ret = drm_sched_job_init(&exec->render.base,
55157692c94SEric Anholt 				 &v3d_priv->sched_entity[V3D_RENDER],
55257692c94SEric Anholt 				 v3d_priv);
55357692c94SEric Anholt 	if (ret)
55457692c94SEric Anholt 		goto fail_unreserve;
55557692c94SEric Anholt 
55634c2c4f6SEric Anholt 	exec->render_done_fence =
55734c2c4f6SEric Anholt 		dma_fence_get(&exec->render.base.s_fence->finished);
55834c2c4f6SEric Anholt 
55957692c94SEric Anholt 	kref_get(&exec->refcount); /* put by scheduler job completion */
56057692c94SEric Anholt 	drm_sched_entity_push_job(&exec->render.base,
56157692c94SEric Anholt 				  &v3d_priv->sched_entity[V3D_RENDER]);
5627122b68bSEric Anholt 	mutex_unlock(&v3d->sched_lock);
56357692c94SEric Anholt 
5641584f16cSEric Anholt 	v3d_attach_object_fences(exec->bo, exec->bo_count,
5651584f16cSEric Anholt 				 exec->render_done_fence);
56657692c94SEric Anholt 
567e14a07fcSEric Anholt 	v3d_unlock_bo_reservations(exec->bo, exec->bo_count, &acquire_ctx);
56857692c94SEric Anholt 
56957692c94SEric Anholt 	/* Update the return sync object for the */
57057692c94SEric Anholt 	sync_out = drm_syncobj_find(file_priv, args->out_sync);
57157692c94SEric Anholt 	if (sync_out) {
5720b258ed1SChristian König 		drm_syncobj_replace_fence(sync_out, exec->render_done_fence);
57357692c94SEric Anholt 		drm_syncobj_put(sync_out);
57457692c94SEric Anholt 	}
57557692c94SEric Anholt 
57657692c94SEric Anholt 	v3d_exec_put(exec);
57757692c94SEric Anholt 
57857692c94SEric Anholt 	return 0;
57957692c94SEric Anholt 
58057692c94SEric Anholt fail_unreserve:
5817122b68bSEric Anholt 	mutex_unlock(&v3d->sched_lock);
582e14a07fcSEric Anholt 	v3d_unlock_bo_reservations(exec->bo, exec->bo_count, &acquire_ctx);
58357692c94SEric Anholt fail:
58457692c94SEric Anholt 	v3d_exec_put(exec);
58557692c94SEric Anholt 
58657692c94SEric Anholt 	return ret;
58757692c94SEric Anholt }
58857692c94SEric Anholt 
5891584f16cSEric Anholt /**
5901584f16cSEric Anholt  * v3d_submit_tfu_ioctl() - Submits a TFU (texture formatting) job to the V3D.
5911584f16cSEric Anholt  * @dev: DRM device
5921584f16cSEric Anholt  * @data: ioctl argument
5931584f16cSEric Anholt  * @file_priv: DRM file for this fd
5941584f16cSEric Anholt  *
5951584f16cSEric Anholt  * Userspace provides the register setup for the TFU, which we don't
5961584f16cSEric Anholt  * need to validate since the TFU is behind the MMU.
5971584f16cSEric Anholt  */
5981584f16cSEric Anholt int
5991584f16cSEric Anholt v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
6001584f16cSEric Anholt 		     struct drm_file *file_priv)
6011584f16cSEric Anholt {
6021584f16cSEric Anholt 	struct v3d_dev *v3d = to_v3d_dev(dev);
6031584f16cSEric Anholt 	struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
6041584f16cSEric Anholt 	struct drm_v3d_submit_tfu *args = data;
6051584f16cSEric Anholt 	struct v3d_tfu_job *job;
6061584f16cSEric Anholt 	struct ww_acquire_ctx acquire_ctx;
6071584f16cSEric Anholt 	struct drm_syncobj *sync_out;
6081584f16cSEric Anholt 	struct dma_fence *sched_done_fence;
6091584f16cSEric Anholt 	int ret = 0;
6101584f16cSEric Anholt 	int bo_count;
6111584f16cSEric Anholt 
61255a9b748SEric Anholt 	trace_v3d_submit_tfu_ioctl(&v3d->drm, args->iia);
61355a9b748SEric Anholt 
6141584f16cSEric Anholt 	job = kcalloc(1, sizeof(*job), GFP_KERNEL);
6151584f16cSEric Anholt 	if (!job)
6161584f16cSEric Anholt 		return -ENOMEM;
6171584f16cSEric Anholt 
6181584f16cSEric Anholt 	ret = pm_runtime_get_sync(v3d->dev);
6191584f16cSEric Anholt 	if (ret < 0) {
6201584f16cSEric Anholt 		kfree(job);
6211584f16cSEric Anholt 		return ret;
6221584f16cSEric Anholt 	}
6231584f16cSEric Anholt 
6241584f16cSEric Anholt 	kref_init(&job->refcount);
6251584f16cSEric Anholt 
6261584f16cSEric Anholt 	ret = drm_syncobj_find_fence(file_priv, args->in_sync,
6271584f16cSEric Anholt 				     0, 0, &job->in_fence);
6281584f16cSEric Anholt 	if (ret == -EINVAL)
6291584f16cSEric Anholt 		goto fail;
6301584f16cSEric Anholt 
6311584f16cSEric Anholt 	job->args = *args;
6321584f16cSEric Anholt 	job->v3d = v3d;
6331584f16cSEric Anholt 
6341584f16cSEric Anholt 	spin_lock(&file_priv->table_lock);
6351584f16cSEric Anholt 	for (bo_count = 0; bo_count < ARRAY_SIZE(job->bo); bo_count++) {
6361584f16cSEric Anholt 		struct drm_gem_object *bo;
6371584f16cSEric Anholt 
6381584f16cSEric Anholt 		if (!args->bo_handles[bo_count])
6391584f16cSEric Anholt 			break;
6401584f16cSEric Anholt 
6411584f16cSEric Anholt 		bo = idr_find(&file_priv->object_idr,
6421584f16cSEric Anholt 			      args->bo_handles[bo_count]);
6431584f16cSEric Anholt 		if (!bo) {
6441584f16cSEric Anholt 			DRM_DEBUG("Failed to look up GEM BO %d: %d\n",
6451584f16cSEric Anholt 				  bo_count, args->bo_handles[bo_count]);
6461584f16cSEric Anholt 			ret = -ENOENT;
6471584f16cSEric Anholt 			spin_unlock(&file_priv->table_lock);
6481584f16cSEric Anholt 			goto fail;
6491584f16cSEric Anholt 		}
6501584f16cSEric Anholt 		drm_gem_object_get(bo);
6511584f16cSEric Anholt 		job->bo[bo_count] = to_v3d_bo(bo);
6521584f16cSEric Anholt 	}
6531584f16cSEric Anholt 	spin_unlock(&file_priv->table_lock);
6541584f16cSEric Anholt 
655e14a07fcSEric Anholt 	ret = v3d_lock_bo_reservations(job->bo, bo_count, &acquire_ctx);
6561584f16cSEric Anholt 	if (ret)
6571584f16cSEric Anholt 		goto fail;
6581584f16cSEric Anholt 
6591584f16cSEric Anholt 	mutex_lock(&v3d->sched_lock);
6601584f16cSEric Anholt 	ret = drm_sched_job_init(&job->base,
6611584f16cSEric Anholt 				 &v3d_priv->sched_entity[V3D_TFU],
6621584f16cSEric Anholt 				 v3d_priv);
6631584f16cSEric Anholt 	if (ret)
6641584f16cSEric Anholt 		goto fail_unreserve;
6651584f16cSEric Anholt 
6661584f16cSEric Anholt 	sched_done_fence = dma_fence_get(&job->base.s_fence->finished);
6671584f16cSEric Anholt 
6681584f16cSEric Anholt 	kref_get(&job->refcount); /* put by scheduler job completion */
6691584f16cSEric Anholt 	drm_sched_entity_push_job(&job->base, &v3d_priv->sched_entity[V3D_TFU]);
6701584f16cSEric Anholt 	mutex_unlock(&v3d->sched_lock);
6711584f16cSEric Anholt 
6721584f16cSEric Anholt 	v3d_attach_object_fences(job->bo, bo_count, sched_done_fence);
6731584f16cSEric Anholt 
674e14a07fcSEric Anholt 	v3d_unlock_bo_reservations(job->bo, bo_count, &acquire_ctx);
6751584f16cSEric Anholt 
6761584f16cSEric Anholt 	/* Update the return sync object */
6771584f16cSEric Anholt 	sync_out = drm_syncobj_find(file_priv, args->out_sync);
6781584f16cSEric Anholt 	if (sync_out) {
6792312f984SChristian König 		drm_syncobj_replace_fence(sync_out, sched_done_fence);
6801584f16cSEric Anholt 		drm_syncobj_put(sync_out);
6811584f16cSEric Anholt 	}
6821584f16cSEric Anholt 	dma_fence_put(sched_done_fence);
6831584f16cSEric Anholt 
6841584f16cSEric Anholt 	v3d_tfu_job_put(job);
6851584f16cSEric Anholt 
6861584f16cSEric Anholt 	return 0;
6871584f16cSEric Anholt 
6881584f16cSEric Anholt fail_unreserve:
6891584f16cSEric Anholt 	mutex_unlock(&v3d->sched_lock);
690e14a07fcSEric Anholt 	v3d_unlock_bo_reservations(job->bo, bo_count, &acquire_ctx);
6911584f16cSEric Anholt fail:
6921584f16cSEric Anholt 	v3d_tfu_job_put(job);
6931584f16cSEric Anholt 
6941584f16cSEric Anholt 	return ret;
6951584f16cSEric Anholt }
6961584f16cSEric Anholt 
69757692c94SEric Anholt int
69857692c94SEric Anholt v3d_gem_init(struct drm_device *dev)
69957692c94SEric Anholt {
70057692c94SEric Anholt 	struct v3d_dev *v3d = to_v3d_dev(dev);
70157692c94SEric Anholt 	u32 pt_size = 4096 * 1024;
70257692c94SEric Anholt 	int ret, i;
70357692c94SEric Anholt 
70457692c94SEric Anholt 	for (i = 0; i < V3D_MAX_QUEUES; i++)
70557692c94SEric Anholt 		v3d->queue[i].fence_context = dma_fence_context_alloc(1);
70657692c94SEric Anholt 
70757692c94SEric Anholt 	spin_lock_init(&v3d->mm_lock);
70857692c94SEric Anholt 	spin_lock_init(&v3d->job_lock);
70957692c94SEric Anholt 	mutex_init(&v3d->bo_lock);
71057692c94SEric Anholt 	mutex_init(&v3d->reset_lock);
7117122b68bSEric Anholt 	mutex_init(&v3d->sched_lock);
71257692c94SEric Anholt 
71357692c94SEric Anholt 	/* Note: We don't allocate address 0.  Various bits of HW
71457692c94SEric Anholt 	 * treat 0 as special, such as the occlusion query counters
71557692c94SEric Anholt 	 * where 0 means "disabled".
71657692c94SEric Anholt 	 */
71757692c94SEric Anholt 	drm_mm_init(&v3d->mm, 1, pt_size / sizeof(u32) - 1);
71857692c94SEric Anholt 
71957692c94SEric Anholt 	v3d->pt = dma_alloc_wc(v3d->dev, pt_size,
72057692c94SEric Anholt 			       &v3d->pt_paddr,
72157692c94SEric Anholt 			       GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO);
72257692c94SEric Anholt 	if (!v3d->pt) {
72357692c94SEric Anholt 		drm_mm_takedown(&v3d->mm);
72457692c94SEric Anholt 		dev_err(v3d->dev,
72557692c94SEric Anholt 			"Failed to allocate page tables. "
72657692c94SEric Anholt 			"Please ensure you have CMA enabled.\n");
72757692c94SEric Anholt 		return -ENOMEM;
72857692c94SEric Anholt 	}
72957692c94SEric Anholt 
73057692c94SEric Anholt 	v3d_init_hw_state(v3d);
73157692c94SEric Anholt 	v3d_mmu_set_page_table(v3d);
73257692c94SEric Anholt 
73357692c94SEric Anholt 	ret = v3d_sched_init(v3d);
73457692c94SEric Anholt 	if (ret) {
73557692c94SEric Anholt 		drm_mm_takedown(&v3d->mm);
73657692c94SEric Anholt 		dma_free_coherent(v3d->dev, 4096 * 1024, (void *)v3d->pt,
73757692c94SEric Anholt 				  v3d->pt_paddr);
73857692c94SEric Anholt 	}
73957692c94SEric Anholt 
74057692c94SEric Anholt 	return 0;
74157692c94SEric Anholt }
74257692c94SEric Anholt 
74357692c94SEric Anholt void
74457692c94SEric Anholt v3d_gem_destroy(struct drm_device *dev)
74557692c94SEric Anholt {
74657692c94SEric Anholt 	struct v3d_dev *v3d = to_v3d_dev(dev);
74757692c94SEric Anholt 
74857692c94SEric Anholt 	v3d_sched_fini(v3d);
74957692c94SEric Anholt 
75057692c94SEric Anholt 	/* Waiting for exec to finish would need to be done before
75157692c94SEric Anholt 	 * unregistering V3D.
75257692c94SEric Anholt 	 */
75314d1d190SEric Anholt 	WARN_ON(v3d->bin_job);
75414d1d190SEric Anholt 	WARN_ON(v3d->render_job);
75557692c94SEric Anholt 
75657692c94SEric Anholt 	drm_mm_takedown(&v3d->mm);
75757692c94SEric Anholt 
75857692c94SEric Anholt 	dma_free_coherent(v3d->dev, 4096 * 1024, (void *)v3d->pt, v3d->pt_paddr);
75957692c94SEric Anholt }
760