@@ -570,11 +570,10 @@ static __poll_t xe_oa_poll(struct file *file, poll_table *wait)
570
570
return ret ;
571
571
}
572
572
573
- static int xe_oa_submit_bb (struct xe_oa_stream * stream , struct xe_bb * bb )
573
+ static struct dma_fence * xe_oa_submit_bb (struct xe_oa_stream * stream , struct xe_bb * bb )
574
574
{
575
575
struct xe_sched_job * job ;
576
576
struct dma_fence * fence ;
577
- long timeout ;
578
577
int err = 0 ;
579
578
580
579
/* Kernel configuration is issued on stream->k_exec_q, not stream->exec_q */
@@ -588,14 +587,9 @@ static int xe_oa_submit_bb(struct xe_oa_stream *stream, struct xe_bb *bb)
588
587
fence = dma_fence_get (& job -> drm .s_fence -> finished );
589
588
xe_sched_job_push (job );
590
589
591
- timeout = dma_fence_wait_timeout (fence , false, HZ );
592
- dma_fence_put (fence );
593
- if (timeout < 0 )
594
- err = timeout ;
595
- else if (!timeout )
596
- err = - ETIME ;
590
+ return fence ;
597
591
exit :
598
- return err ;
592
+ return ERR_PTR ( err ) ;
599
593
}
600
594
601
595
static void write_cs_mi_lri (struct xe_bb * bb , const struct xe_oa_reg * reg_data , u32 n_regs )
@@ -659,6 +653,7 @@ static void xe_oa_store_flex(struct xe_oa_stream *stream, struct xe_lrc *lrc,
659
653
static int xe_oa_modify_ctx_image (struct xe_oa_stream * stream , struct xe_lrc * lrc ,
660
654
const struct flex * flex , u32 count )
661
655
{
656
+ struct dma_fence * fence ;
662
657
struct xe_bb * bb ;
663
658
int err ;
664
659
@@ -670,14 +665,24 @@ static int xe_oa_modify_ctx_image(struct xe_oa_stream *stream, struct xe_lrc *lr
670
665
671
666
xe_oa_store_flex (stream , lrc , bb , flex , count );
672
667
673
- err = xe_oa_submit_bb (stream , bb );
668
+ fence = xe_oa_submit_bb (stream , bb );
669
+ if (IS_ERR (fence )) {
670
+ err = PTR_ERR (fence );
671
+ goto free_bb ;
672
+ }
673
+ xe_bb_free (bb , fence );
674
+ dma_fence_put (fence );
675
+
676
+ return 0 ;
677
+ free_bb :
674
678
xe_bb_free (bb , NULL );
675
679
exit :
676
680
return err ;
677
681
}
678
682
679
683
static int xe_oa_load_with_lri (struct xe_oa_stream * stream , struct xe_oa_reg * reg_lri )
680
684
{
685
+ struct dma_fence * fence ;
681
686
struct xe_bb * bb ;
682
687
int err ;
683
688
@@ -689,7 +694,16 @@ static int xe_oa_load_with_lri(struct xe_oa_stream *stream, struct xe_oa_reg *re
689
694
690
695
write_cs_mi_lri (bb , reg_lri , 1 );
691
696
692
- err = xe_oa_submit_bb (stream , bb );
697
+ fence = xe_oa_submit_bb (stream , bb );
698
+ if (IS_ERR (fence )) {
699
+ err = PTR_ERR (fence );
700
+ goto free_bb ;
701
+ }
702
+ xe_bb_free (bb , fence );
703
+ dma_fence_put (fence );
704
+
705
+ return 0 ;
706
+ free_bb :
693
707
xe_bb_free (bb , NULL );
694
708
exit :
695
709
return err ;
@@ -919,15 +933,32 @@ static int xe_oa_emit_oa_config(struct xe_oa_stream *stream, struct xe_oa_config
919
933
{
920
934
#define NOA_PROGRAM_ADDITIONAL_DELAY_US 500
921
935
struct xe_oa_config_bo * oa_bo ;
922
- int err , us = NOA_PROGRAM_ADDITIONAL_DELAY_US ;
936
+ int err = 0 , us = NOA_PROGRAM_ADDITIONAL_DELAY_US ;
937
+ struct dma_fence * fence ;
938
+ long timeout ;
923
939
940
+ /* Emit OA configuration batch */
924
941
oa_bo = xe_oa_alloc_config_buffer (stream , config );
925
942
if (IS_ERR (oa_bo )) {
926
943
err = PTR_ERR (oa_bo );
927
944
goto exit ;
928
945
}
929
946
930
- err = xe_oa_submit_bb (stream , oa_bo -> bb );
947
+ fence = xe_oa_submit_bb (stream , oa_bo -> bb );
948
+ if (IS_ERR (fence )) {
949
+ err = PTR_ERR (fence );
950
+ goto exit ;
951
+ }
952
+
953
+ /* Wait till all previous batches have executed */
954
+ timeout = dma_fence_wait_timeout (fence , false, 5 * HZ );
955
+ dma_fence_put (fence );
956
+ if (timeout < 0 )
957
+ err = timeout ;
958
+ else if (!timeout )
959
+ err = - ETIME ;
960
+ if (err )
961
+ drm_dbg (& stream -> oa -> xe -> drm , "dma_fence_wait_timeout err %d\n" , err );
931
962
932
963
/* Additional empirical delay needed for NOA programming after registers are written */
933
964
usleep_range (us , 2 * us );
0 commit comments