@@ -556,9 +556,150 @@ set_proto_ctx_engines_bond(struct i915_user_extension __user *base, void *data)
556556 return 0 ;
557557}
558558
559+ static int
560+ set_proto_ctx_engines_parallel_submit (struct i915_user_extension __user * base ,
561+ void * data )
562+ {
563+ struct i915_context_engines_parallel_submit __user * ext =
564+ container_of_user (base , typeof (* ext ), base );
565+ const struct set_proto_ctx_engines * set = data ;
566+ struct drm_i915_private * i915 = set -> i915 ;
567+ u64 flags ;
568+ int err = 0 , n , i , j ;
569+ u16 slot , width , num_siblings ;
570+ struct intel_engine_cs * * siblings = NULL ;
571+ intel_engine_mask_t prev_mask ;
572+
573+ /* Disabling for now */
574+ return - ENODEV ;
575+
576+ /* FIXME: This is NIY for execlists */
577+ if (!(intel_uc_uses_guc_submission (& i915 -> gt .uc )))
578+ return - ENODEV ;
579+
580+ if (get_user (slot , & ext -> engine_index ))
581+ return - EFAULT ;
582+
583+ if (get_user (width , & ext -> width ))
584+ return - EFAULT ;
585+
586+ if (get_user (num_siblings , & ext -> num_siblings ))
587+ return - EFAULT ;
588+
589+ if (slot >= set -> num_engines ) {
590+ drm_dbg (& i915 -> drm , "Invalid placement value, %d >= %d\n" ,
591+ slot , set -> num_engines );
592+ return - EINVAL ;
593+ }
594+
595+ if (set -> engines [slot ].type != I915_GEM_ENGINE_TYPE_INVALID ) {
596+ drm_dbg (& i915 -> drm ,
597+ "Invalid placement[%d], already occupied\n" , slot );
598+ return - EINVAL ;
599+ }
600+
601+ if (get_user (flags , & ext -> flags ))
602+ return - EFAULT ;
603+
604+ if (flags ) {
605+ drm_dbg (& i915 -> drm , "Unknown flags 0x%02llx" , flags );
606+ return - EINVAL ;
607+ }
608+
609+ for (n = 0 ; n < ARRAY_SIZE (ext -> mbz64 ); n ++ ) {
610+ err = check_user_mbz (& ext -> mbz64 [n ]);
611+ if (err )
612+ return err ;
613+ }
614+
615+ if (width < 2 ) {
616+ drm_dbg (& i915 -> drm , "Width (%d) < 2\n" , width );
617+ return - EINVAL ;
618+ }
619+
620+ if (num_siblings < 1 ) {
621+ drm_dbg (& i915 -> drm , "Number siblings (%d) < 1\n" ,
622+ num_siblings );
623+ return - EINVAL ;
624+ }
625+
626+ siblings = kmalloc_array (num_siblings * width ,
627+ sizeof (* siblings ),
628+ GFP_KERNEL );
629+ if (!siblings )
630+ return - ENOMEM ;
631+
632+ /* Create contexts / engines */
633+ for (i = 0 ; i < width ; ++ i ) {
634+ intel_engine_mask_t current_mask = 0 ;
635+ struct i915_engine_class_instance prev_engine ;
636+
637+ for (j = 0 ; j < num_siblings ; ++ j ) {
638+ struct i915_engine_class_instance ci ;
639+
640+ n = i * num_siblings + j ;
641+ if (copy_from_user (& ci , & ext -> engines [n ], sizeof (ci ))) {
642+ err = - EFAULT ;
643+ goto out_err ;
644+ }
645+
646+ siblings [n ] =
647+ intel_engine_lookup_user (i915 , ci .engine_class ,
648+ ci .engine_instance );
649+ if (!siblings [n ]) {
650+ drm_dbg (& i915 -> drm ,
651+ "Invalid sibling[%d]: { class:%d, inst:%d }\n" ,
652+ n , ci .engine_class , ci .engine_instance );
653+ err = - EINVAL ;
654+ goto out_err ;
655+ }
656+
657+ if (n ) {
658+ if (prev_engine .engine_class !=
659+ ci .engine_class ) {
660+ drm_dbg (& i915 -> drm ,
661+ "Mismatched class %d, %d\n" ,
662+ prev_engine .engine_class ,
663+ ci .engine_class );
664+ err = - EINVAL ;
665+ goto out_err ;
666+ }
667+ }
668+
669+ prev_engine = ci ;
670+ current_mask |= siblings [n ]-> logical_mask ;
671+ }
672+
673+ if (i > 0 ) {
674+ if (current_mask != prev_mask << 1 ) {
675+ drm_dbg (& i915 -> drm ,
676+ "Non contiguous logical mask 0x%x, 0x%x\n" ,
677+ prev_mask , current_mask );
678+ err = - EINVAL ;
679+ goto out_err ;
680+ }
681+ }
682+ prev_mask = current_mask ;
683+ }
684+
685+ set -> engines [slot ].type = I915_GEM_ENGINE_TYPE_PARALLEL ;
686+ set -> engines [slot ].num_siblings = num_siblings ;
687+ set -> engines [slot ].width = width ;
688+ set -> engines [slot ].siblings = siblings ;
689+
690+ return 0 ;
691+
692+ out_err :
693+ kfree (siblings );
694+
695+ return err ;
696+ }
697+
559698static const i915_user_extension_fn set_proto_ctx_engines_extensions [] = {
560699 [I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE ] = set_proto_ctx_engines_balance ,
561700 [I915_CONTEXT_ENGINES_EXT_BOND ] = set_proto_ctx_engines_bond ,
701+ [I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT ] =
702+ set_proto_ctx_engines_parallel_submit ,
562703};
563704
564705static int set_proto_ctx_engines (struct drm_i915_file_private * fpriv ,
@@ -794,6 +935,7 @@ static int intel_context_set_gem(struct intel_context *ce,
794935 GEM_BUG_ON (rcu_access_pointer (ce -> gem_context ));
795936 RCU_INIT_POINTER (ce -> gem_context , ctx );
796937
938+ GEM_BUG_ON (intel_context_is_pinned (ce ));
797939 ce -> ring_size = SZ_16K ;
798940
799941 i915_vm_put (ce -> vm );
@@ -818,6 +960,25 @@ static int intel_context_set_gem(struct intel_context *ce,
818960 return ret ;
819961}
820962
963+ static void __unpin_engines (struct i915_gem_engines * e , unsigned int count )
964+ {
965+ while (count -- ) {
966+ struct intel_context * ce = e -> engines [count ], * child ;
967+
968+ if (!ce || !test_bit (CONTEXT_PERMA_PIN , & ce -> flags ))
969+ continue ;
970+
971+ for_each_child (ce , child )
972+ intel_context_unpin (child );
973+ intel_context_unpin (ce );
974+ }
975+ }
976+
977+ static void unpin_engines (struct i915_gem_engines * e )
978+ {
979+ __unpin_engines (e , e -> num_engines );
980+ }
981+
821982static void __free_engines (struct i915_gem_engines * e , unsigned int count )
822983{
823984 while (count -- ) {
@@ -933,6 +1094,40 @@ static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx,
9331094 return err ;
9341095}
9351096
1097+ static int perma_pin_contexts (struct intel_context * ce )
1098+ {
1099+ struct intel_context * child ;
1100+ int i = 0 , j = 0 , ret ;
1101+
1102+ GEM_BUG_ON (!intel_context_is_parent (ce ));
1103+
1104+ ret = intel_context_pin (ce );
1105+ if (unlikely (ret ))
1106+ return ret ;
1107+
1108+ for_each_child (ce , child ) {
1109+ ret = intel_context_pin (child );
1110+ if (unlikely (ret ))
1111+ goto unwind ;
1112+ ++ i ;
1113+ }
1114+
1115+ set_bit (CONTEXT_PERMA_PIN , & ce -> flags );
1116+
1117+ return 0 ;
1118+
1119+ unwind :
1120+ intel_context_unpin (ce );
1121+ for_each_child (ce , child ) {
1122+ if (j ++ < i )
1123+ intel_context_unpin (child );
1124+ else
1125+ break ;
1126+ }
1127+
1128+ return ret ;
1129+ }
1130+
9361131static struct i915_gem_engines * user_engines (struct i915_gem_context * ctx ,
9371132 unsigned int num_engines ,
9381133 struct i915_gem_proto_engine * pe )
@@ -946,7 +1141,7 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
9461141 e -> num_engines = num_engines ;
9471142
9481143 for (n = 0 ; n < num_engines ; n ++ ) {
949- struct intel_context * ce ;
1144+ struct intel_context * ce , * child ;
9501145 int ret ;
9511146
9521147 switch (pe [n ].type ) {
@@ -956,7 +1151,13 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
9561151
9571152 case I915_GEM_ENGINE_TYPE_BALANCED :
9581153 ce = intel_engine_create_virtual (pe [n ].siblings ,
959- pe [n ].num_siblings );
1154+ pe [n ].num_siblings , 0 );
1155+ break ;
1156+
1157+ case I915_GEM_ENGINE_TYPE_PARALLEL :
1158+ ce = intel_engine_create_parallel (pe [n ].siblings ,
1159+ pe [n ].num_siblings ,
1160+ pe [n ].width );
9601161 break ;
9611162
9621163 case I915_GEM_ENGINE_TYPE_INVALID :
@@ -977,6 +1178,30 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
9771178 err = ERR_PTR (ret );
9781179 goto free_engines ;
9791180 }
1181+ for_each_child (ce , child ) {
1182+ ret = intel_context_set_gem (child , ctx , pe -> sseu );
1183+ if (ret ) {
1184+ err = ERR_PTR (ret );
1185+ goto free_engines ;
1186+ }
1187+ }
1188+
1189+ /*
1190+ * XXX: Must be done after calling intel_context_set_gem as that
1191+ * function changes the ring size. The ring is allocated when
1192+ * the context is pinned. If the ring size is changed after
1193+ * allocation we have a mismatch of the ring size and will cause
1194+ * the context to hang. Presumably with a bit of reordering we
1195+ * could move the perma-pin step to the backend function
1196+ * intel_engine_create_parallel.
1197+ */
1198+ if (pe [n ].type == I915_GEM_ENGINE_TYPE_PARALLEL ) {
1199+ ret = perma_pin_contexts (ce );
1200+ if (ret ) {
1201+ err = ERR_PTR (ret );
1202+ goto free_engines ;
1203+ }
1204+ }
9801205 }
9811206
9821207 return e ;
@@ -1219,6 +1444,7 @@ static void context_close(struct i915_gem_context *ctx)
12191444
12201445 /* Flush any concurrent set_engines() */
12211446 mutex_lock (& ctx -> engines_mutex );
1447+ unpin_engines (__context_engines_static (ctx ));
12221448 engines_idle_release (ctx , rcu_replace_pointer (ctx -> engines , NULL , 1 ));
12231449 i915_gem_context_set_closed (ctx );
12241450 mutex_unlock (& ctx -> engines_mutex );
0 commit comments