@@ -162,10 +162,52 @@ v3d_flush_l2t(struct v3d_dev *v3d, int core)
162162 /* While there is a busy bit (V3D_L2TCACTL_L2TFLS), we don't
163163 * need to wait for completion before dispatching the job --
164164 * L2T accesses will be stalled until the flush has completed.
165+ * However, we do need to make sure we don't try to trigger a
166+ * new flush while the L2_CLEAN queue is trying to
167+ * synchronously clean after a job.
165168 */
169+ mutex_lock (& v3d -> cache_clean_lock );
166170 V3D_CORE_WRITE (core , V3D_CTL_L2TCACTL ,
167171 V3D_L2TCACTL_L2TFLS |
168172 V3D_SET_FIELD (V3D_L2TCACTL_FLM_FLUSH , V3D_L2TCACTL_FLM ));
173+ mutex_unlock (& v3d -> cache_clean_lock );
174+ }
175+
176+ /* Cleans texture L1 and L2 cachelines (writing back dirty data).
177+ *
178+ * For cleaning, which happens from the CACHE_CLEAN queue after CSD has
179+ * executed, we need to make sure that the clean is done before
180+ * signaling job completion. So, we synchronously wait before
181+ * returning, and we make sure that L2 invalidates don't happen in the
182+ * meantime to confuse our are-we-done checks.
183+ */
184+ void
185+ v3d_clean_caches (struct v3d_dev * v3d )
186+ {
187+ struct drm_device * dev = & v3d -> drm ;
188+ int core = 0 ;
189+
190+ trace_v3d_cache_clean_begin (dev );
191+
192+ V3D_CORE_WRITE (core , V3D_CTL_L2TCACTL , V3D_L2TCACTL_TMUWCF );
193+ if (wait_for (!(V3D_CORE_READ (core , V3D_CTL_L2TCACTL ) &
194+ V3D_L2TCACTL_L2TFLS ), 100 )) {
195+ DRM_ERROR ("Timeout waiting for L1T write combiner flush\n" );
196+ }
197+
198+ mutex_lock (& v3d -> cache_clean_lock );
199+ V3D_CORE_WRITE (core , V3D_CTL_L2TCACTL ,
200+ V3D_L2TCACTL_L2TFLS |
201+ V3D_SET_FIELD (V3D_L2TCACTL_FLM_CLEAN , V3D_L2TCACTL_FLM ));
202+
203+ if (wait_for (!(V3D_CORE_READ (core , V3D_CTL_L2TCACTL ) &
204+ V3D_L2TCACTL_L2TFLS ), 100 )) {
205+ DRM_ERROR ("Timeout waiting for L2T clean\n" );
206+ }
207+
208+ mutex_unlock (& v3d -> cache_clean_lock );
209+
210+ trace_v3d_cache_clean_end (dev );
169211}
170212
171213/* Invalidates the slice caches. These are read-only caches. */
@@ -429,7 +471,8 @@ static void
429471v3d_attach_fences_and_unlock_reservation (struct drm_file * file_priv ,
430472 struct v3d_job * job ,
431473 struct ww_acquire_ctx * acquire_ctx ,
432- u32 out_sync )
474+ u32 out_sync ,
475+ struct dma_fence * done_fence )
433476{
434477 struct drm_syncobj * sync_out ;
435478 int i ;
@@ -445,7 +488,7 @@ v3d_attach_fences_and_unlock_reservation(struct drm_file *file_priv,
445488 /* Update the return sync object for the job */
446489 sync_out = drm_syncobj_find (file_priv , out_sync );
447490 if (sync_out ) {
448- drm_syncobj_replace_fence (sync_out , job -> done_fence );
491+ drm_syncobj_replace_fence (sync_out , done_fence );
449492 drm_syncobj_put (sync_out );
450493 }
451494}
@@ -541,8 +584,10 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
541584 mutex_unlock (& v3d -> sched_lock );
542585
543586 v3d_attach_fences_and_unlock_reservation (file_priv ,
544- & render -> base , & acquire_ctx ,
545- args -> out_sync );
587+ & render -> base ,
588+ & acquire_ctx ,
589+ args -> out_sync ,
590+ render -> base .done_fence );
546591
547592 if (bin )
548593 v3d_job_put (& bin -> base );
@@ -641,7 +686,8 @@ v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
641686
642687 v3d_attach_fences_and_unlock_reservation (file_priv ,
643688 & job -> base , & acquire_ctx ,
644- args -> out_sync );
689+ args -> out_sync ,
690+ job -> base .done_fence );
645691
646692 v3d_job_put (& job -> base );
647693
@@ -657,6 +703,105 @@ v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
657703 return ret ;
658704}
659705
706+ /**
707+ * v3d_submit_csd_ioctl() - Submits a CSD (texture formatting) job to the V3D.
708+ * @dev: DRM device
709+ * @data: ioctl argument
710+ * @file_priv: DRM file for this fd
711+ *
712+ * Userspace provides the register setup for the CSD, which we don't
713+ * need to validate since the CSD is behind the MMU.
714+ */
715+ int
716+ v3d_submit_csd_ioctl (struct drm_device * dev , void * data ,
717+ struct drm_file * file_priv )
718+ {
719+ struct v3d_dev * v3d = to_v3d_dev (dev );
720+ struct v3d_file_priv * v3d_priv = file_priv -> driver_priv ;
721+ struct drm_v3d_submit_csd * args = data ;
722+ struct v3d_csd_job * job ;
723+ struct v3d_job * clean_job ;
724+ struct ww_acquire_ctx acquire_ctx ;
725+ int ret ;
726+
727+ trace_v3d_submit_csd_ioctl (& v3d -> drm , args -> cfg [5 ], args -> cfg [6 ]);
728+
729+ if (!v3d_has_csd (v3d )) {
730+ DRM_DEBUG ("Attempting CSD submit on non-CSD hardware\n" );
731+ return - EINVAL ;
732+ }
733+
734+ job = kcalloc (1 , sizeof (* job ), GFP_KERNEL );
735+ if (!job )
736+ return - ENOMEM ;
737+
738+ ret = v3d_job_init (v3d , file_priv , & job -> base ,
739+ v3d_job_free , args -> in_sync );
740+ if (ret ) {
741+ kfree (job );
742+ return ret ;
743+ }
744+
745+ clean_job = kcalloc (1 , sizeof (* clean_job ), GFP_KERNEL );
746+ if (!clean_job ) {
747+ v3d_job_put (& job -> base );
748+ kfree (job );
749+ return - ENOMEM ;
750+ }
751+
752+ ret = v3d_job_init (v3d , file_priv , clean_job , v3d_job_free , 0 );
753+ if (ret ) {
754+ v3d_job_put (& job -> base );
755+ kfree (clean_job );
756+ return ret ;
757+ }
758+
759+ job -> args = * args ;
760+
761+ ret = v3d_lookup_bos (dev , file_priv , clean_job ,
762+ args -> bo_handles , args -> bo_handle_count );
763+ if (ret )
764+ goto fail ;
765+
766+ ret = v3d_lock_bo_reservations (clean_job -> base .bo ,
767+ clean_job -> base .bo_count ,
768+ & acquire_ctx );
769+ if (ret )
770+ goto fail ;
771+
772+ mutex_lock (& v3d -> sched_lock );
773+ ret = v3d_push_job (v3d_priv , & job -> base , V3D_CSD );
774+ if (ret )
775+ goto fail_unreserve ;
776+
777+ clean_job -> in_fence = dma_fence_get (job -> base .done_fence );
778+ ret = v3d_push_job (v3d_priv , clean_job , V3D_CACHE_CLEAN );
779+ if (ret )
780+ goto fail_unreserve ;
781+ mutex_unlock (& v3d -> sched_lock );
782+
783+ v3d_attach_fences_and_unlock_reservation (file_priv ,
784+ clean_job ,
785+ & acquire_ctx ,
786+ args -> out_sync ,
787+ clean_job -> done_fence );
788+
789+ v3d_job_put (& job -> base );
790+ v3d_job_put (clean_job );
791+
792+ return 0 ;
793+
794+ fail_unreserve :
795+ mutex_unlock (& v3d -> sched_lock );
796+ drm_gem_unlock_reservations (clean_job -> bo , clean_job -> bo_count ,
797+ & acquire_ctx );
798+ fail :
799+ v3d_job_put (& job -> base );
800+ v3d_job_put (clean_job );
801+
802+ return ret ;
803+ }
804+
660805int
661806v3d_gem_init (struct drm_device * dev )
662807{
@@ -672,6 +817,7 @@ v3d_gem_init(struct drm_device *dev)
672817 mutex_init (& v3d -> bo_lock );
673818 mutex_init (& v3d -> reset_lock );
674819 mutex_init (& v3d -> sched_lock );
820+ mutex_init (& v3d -> cache_clean_lock );
675821
676822 /* Note: We don't allocate address 0. Various bits of HW
677823 * treat 0 as special, such as the occlusion query counters
0 commit comments