@@ -221,6 +221,9 @@ enum {
221221#define CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT 0x17
222222
223223static int intel_lr_context_pin (struct drm_i915_gem_request * rq );
224+ static void lrc_setup_hardware_status_page (struct intel_engine_cs * ring ,
225+ struct drm_i915_gem_object * default_ctx_obj );
226+
224227
225228/**
226229 * intel_sanitize_enable_execlists() - sanitize i915.enable_execlists
@@ -1020,39 +1023,54 @@ int logical_ring_flush_all_caches(struct drm_i915_gem_request *req)
10201023 return 0 ;
10211024}
10221025
1023- static int intel_lr_context_pin (struct drm_i915_gem_request * rq )
1026+ static int intel_lr_context_do_pin (struct intel_engine_cs * ring ,
1027+ struct drm_i915_gem_object * ctx_obj ,
1028+ struct intel_ringbuffer * ringbuf )
10241029{
1025- struct drm_i915_private * dev_priv = rq -> i915 ;
1026- struct intel_engine_cs * ring = rq -> ring ;
1027- struct drm_i915_gem_object * ctx_obj = rq -> ctx -> engine [ring -> id ].state ;
1028- struct intel_ringbuffer * ringbuf = rq -> ringbuf ;
1030+ struct drm_device * dev = ring -> dev ;
1031+ struct drm_i915_private * dev_priv = dev -> dev_private ;
10291032 int ret = 0 ;
10301033
10311034 WARN_ON (!mutex_is_locked (& ring -> dev -> struct_mutex ));
1032- if (rq -> ctx -> engine [ring -> id ].pin_count ++ == 0 ) {
1033- ret = i915_gem_obj_ggtt_pin (ctx_obj , GEN8_LR_CONTEXT_ALIGN ,
1034- PIN_OFFSET_BIAS | GUC_WOPCM_TOP );
1035- if (ret )
1036- goto reset_pin_count ;
1035+ ret = i915_gem_obj_ggtt_pin (ctx_obj , GEN8_LR_CONTEXT_ALIGN ,
1036+ PIN_OFFSET_BIAS | GUC_WOPCM_TOP );
1037+ if (ret )
1038+ return ret ;
10371039
1038- ret = intel_pin_and_map_ringbuffer_obj (ring -> dev , ringbuf );
1039- if (ret )
1040- goto unpin_ctx_obj ;
1040+ ret = intel_pin_and_map_ringbuffer_obj (ring -> dev , ringbuf );
1041+ if (ret )
1042+ goto unpin_ctx_obj ;
10411043
1042- ctx_obj -> dirty = true;
1044+ ctx_obj -> dirty = true;
10431045
1044- /* Invalidate GuC TLB. */
1045- if (i915 .enable_guc_submission )
1046- I915_WRITE (GEN8_GTCR , GEN8_GTCR_INVALIDATE );
1047- }
1046+ /* Invalidate GuC TLB. */
1047+ if (i915 .enable_guc_submission )
1048+ I915_WRITE (GEN8_GTCR , GEN8_GTCR_INVALIDATE );
10481049
10491050 return ret ;
10501051
10511052unpin_ctx_obj :
10521053 i915_gem_object_ggtt_unpin (ctx_obj );
1054+
1055+ return ret ;
1056+ }
1057+
1058+ static int intel_lr_context_pin (struct drm_i915_gem_request * rq )
1059+ {
1060+ int ret = 0 ;
1061+ struct intel_engine_cs * ring = rq -> ring ;
1062+ struct drm_i915_gem_object * ctx_obj = rq -> ctx -> engine [ring -> id ].state ;
1063+ struct intel_ringbuffer * ringbuf = rq -> ringbuf ;
1064+
1065+ if (rq -> ctx -> engine [ring -> id ].pin_count ++ == 0 ) {
1066+ ret = intel_lr_context_do_pin (ring , ctx_obj , ringbuf );
1067+ if (ret )
1068+ goto reset_pin_count ;
1069+ }
1070+ return ret ;
1071+
10531072reset_pin_count :
10541073 rq -> ctx -> engine [ring -> id ].pin_count = 0 ;
1055-
10561074 return ret ;
10571075}
10581076
@@ -1462,6 +1480,9 @@ static int gen8_init_common_ring(struct intel_engine_cs *ring)
14621480 struct drm_device * dev = ring -> dev ;
14631481 struct drm_i915_private * dev_priv = dev -> dev_private ;
14641482
1483+ lrc_setup_hardware_status_page (ring ,
1484+ ring -> default_context -> engine [ring -> id ].state );
1485+
14651486 I915_WRITE_IMR (ring , ~(ring -> irq_enable_mask | ring -> irq_keep_mask ));
14661487 I915_WRITE (RING_HWSTAM (ring -> mmio_base ), 0xffffffff );
14671488
@@ -1901,7 +1922,21 @@ static int logical_ring_init(struct drm_device *dev, struct intel_engine_cs *rin
19011922 if (ret )
19021923 return ret ;
19031924
1904- ret = intel_lr_context_deferred_create (ring -> default_context , ring );
1925+ ret = intel_lr_context_deferred_alloc (ring -> default_context , ring );
1926+ if (ret )
1927+ return ret ;
1928+
1929+ /* As this is the default context, always pin it */
1930+ ret = intel_lr_context_do_pin (
1931+ ring ,
1932+ ring -> default_context -> engine [ring -> id ].state ,
1933+ ring -> default_context -> engine [ring -> id ].ringbuf );
1934+ if (ret ) {
1935+ DRM_ERROR (
1936+ "Failed to pin and map ringbuffer %s: %d\n" ,
1937+ ring -> name , ret );
1938+ return ret ;
1939+ }
19051940
19061941 return ret ;
19071942}
@@ -2124,14 +2159,8 @@ int intel_logical_rings_init(struct drm_device *dev)
21242159 goto cleanup_vebox_ring ;
21252160 }
21262161
2127- ret = i915_gem_set_seqno (dev , ((u32 )~0 - 0x1000 ));
2128- if (ret )
2129- goto cleanup_bsd2_ring ;
2130-
21312162 return 0 ;
21322163
2133- cleanup_bsd2_ring :
2134- intel_logical_ring_cleanup (& dev_priv -> ring [VCS2 ]);
21352164cleanup_vebox_ring :
21362165 intel_logical_ring_cleanup (& dev_priv -> ring [VECS ]);
21372166cleanup_blt_ring :
@@ -2401,7 +2430,7 @@ static void lrc_setup_hardware_status_page(struct intel_engine_cs *ring,
24012430}
24022431
24032432/**
2404- * intel_lr_context_deferred_create () - create the LRC specific bits of a context
2433+ * intel_lr_context_deferred_alloc () - create the LRC specific bits of a context
24052434 * @ctx: LR context to create.
24062435 * @ring: engine to be used with the context.
24072436 *
@@ -2413,12 +2442,11 @@ static void lrc_setup_hardware_status_page(struct intel_engine_cs *ring,
24132442 *
24142443 * Return: non-zero on error.
24152444 */
2416- int intel_lr_context_deferred_create (struct intel_context * ctx ,
2445+
2446+ int intel_lr_context_deferred_alloc (struct intel_context * ctx ,
24172447 struct intel_engine_cs * ring )
24182448{
2419- const bool is_global_default_ctx = (ctx == ring -> default_context );
24202449 struct drm_device * dev = ring -> dev ;
2421- struct drm_i915_private * dev_priv = dev -> dev_private ;
24222450 struct drm_i915_gem_object * ctx_obj ;
24232451 uint32_t context_size ;
24242452 struct intel_ringbuffer * ringbuf ;
@@ -2438,82 +2466,50 @@ int intel_lr_context_deferred_create(struct intel_context *ctx,
24382466 return - ENOMEM ;
24392467 }
24402468
2441- if (is_global_default_ctx ) {
2442- ret = i915_gem_obj_ggtt_pin (ctx_obj , GEN8_LR_CONTEXT_ALIGN ,
2443- PIN_OFFSET_BIAS | GUC_WOPCM_TOP );
2444- if (ret ) {
2445- DRM_DEBUG_DRIVER ("Pin LRC backing obj failed: %d\n" ,
2446- ret );
2447- drm_gem_object_unreference (& ctx_obj -> base );
2448- return ret ;
2449- }
2450-
2451- /* Invalidate GuC TLB. */
2452- if (i915 .enable_guc_submission )
2453- I915_WRITE (GEN8_GTCR , GEN8_GTCR_INVALIDATE );
2454- }
2455-
24562469 ringbuf = intel_engine_create_ringbuffer (ring , 4 * PAGE_SIZE );
24572470 if (IS_ERR (ringbuf )) {
24582471 ret = PTR_ERR (ringbuf );
2459- goto error_unpin_ctx ;
2460- }
2461-
2462- if (is_global_default_ctx ) {
2463- ret = intel_pin_and_map_ringbuffer_obj (dev , ringbuf );
2464- if (ret ) {
2465- DRM_ERROR (
2466- "Failed to pin and map ringbuffer %s: %d\n" ,
2467- ring -> name , ret );
2468- goto error_ringbuf ;
2469- }
2472+ goto error_deref_obj ;
24702473 }
24712474
24722475 ret = populate_lr_context (ctx , ctx_obj , ring , ringbuf );
24732476 if (ret ) {
24742477 DRM_DEBUG_DRIVER ("Failed to populate LRC: %d\n" , ret );
2475- goto error ;
2478+ goto error_ringbuf ;
24762479 }
24772480
24782481 ctx -> engine [ring -> id ].ringbuf = ringbuf ;
24792482 ctx -> engine [ring -> id ].state = ctx_obj ;
24802483
2481- if (ctx == ring -> default_context )
2482- lrc_setup_hardware_status_page (ring , ctx_obj );
2483- else if (ring -> id == RCS && !ctx -> rcs_initialized ) {
2484- if (ring -> init_context ) {
2485- struct drm_i915_gem_request * req ;
2486-
2487- ret = i915_gem_request_alloc (ring , ctx , & req );
2488- if (ret )
2489- return ret ;
2484+ if (ctx != ring -> default_context && ring -> init_context ) {
2485+ struct drm_i915_gem_request * req ;
24902486
2491- ret = ring -> init_context (req );
2492- if (ret ) {
2493- DRM_ERROR ("ring init context: %d\n" , ret );
2494- i915_gem_request_cancel (req );
2495- ctx -> engine [ring -> id ].ringbuf = NULL ;
2496- ctx -> engine [ring -> id ].state = NULL ;
2497- goto error ;
2498- }
2499-
2500- i915_add_request_no_flush (req );
2487+ ret = i915_gem_request_alloc (ring ,
2488+ ctx , & req );
2489+ if (ret ) {
2490+ DRM_ERROR ("ring create req: %d\n" ,
2491+ ret );
2492+ i915_gem_request_cancel (req );
2493+ goto error_ringbuf ;
25012494 }
25022495
2503- ctx -> rcs_initialized = true;
2496+ ret = ring -> init_context (req );
2497+ if (ret ) {
2498+ DRM_ERROR ("ring init context: %d\n" ,
2499+ ret );
2500+ i915_gem_request_cancel (req );
2501+ goto error_ringbuf ;
2502+ }
2503+ i915_add_request_no_flush (req );
25042504 }
2505-
25062505 return 0 ;
25072506
2508- error :
2509- if (is_global_default_ctx )
2510- intel_unpin_ringbuffer_obj (ringbuf );
25112507error_ringbuf :
25122508 intel_ringbuffer_free (ringbuf );
2513- error_unpin_ctx :
2514- if (is_global_default_ctx )
2515- i915_gem_object_ggtt_unpin (ctx_obj );
2509+ error_deref_obj :
25162510 drm_gem_object_unreference (& ctx_obj -> base );
2511+ ctx -> engine [ring -> id ].ringbuf = NULL ;
2512+ ctx -> engine [ring -> id ].state = NULL ;
25172513 return ret ;
25182514}
25192515
0 commit comments