Skip to content

Commit dcdf1bb

Browse files
lucacoelhohogander
authored andcommitted
drm/i915: handle uncore spinlock when not available
The uncore code may not always be available (e.g. when we build the display code with Xe), so we can't always rely on having the uncore's spinlock. To handle this, split the spin_lock/unlock_irqsave/restore() into spin_lock/unlock() followed by a call to local_irq_save/restore() and create wrapper functions for locking and unlocking the uncore's spinlock. In these functions, we have a condition check and only actually try to lock/unlock the spinlock when I915 is defined, and thus uncore is available. This keeps the ifdefs contained in these new functions and all such logic inside the display code. Cc: Tvrtko Ursulin <tvrto.ursulin@intel.com> Cc: Jani Nikula <jani.nikula@intel.com> Cc: Ville Syrjala <ville.syrjala@linux.intel.com> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Signed-off-by: Luca Coelho <luciano.coelho@intel.com> Reviewed-by: Jouni Högander <jouni.hogander@intel.com> Signed-off-by: Jouni Högander <jouni.hogander@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20231201100032.1367589-1-luciano.coelho@intel.com
1 parent 01a39f1 commit dcdf1bb

1 file changed

Lines changed: 41 additions & 10 deletions

File tree

drivers/gpu/drm/i915/display/intel_vblank.c

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,32 @@ int intel_crtc_scanline_to_hw(struct intel_crtc *crtc, int scanline)
265265
return (scanline + vtotal - crtc->scanline_offset) % vtotal;
266266
}
267267

268+
/*
269+
* The uncore version of the spin lock functions is used to decide
270+
* whether we need to lock the uncore lock or not. This is only
271+
* needed in i915, not in Xe.
272+
*
273+
* This lock in i915 is needed because some old platforms (at least
274+
* IVB and possibly HSW as well), which are not supported in Xe, need
275+
* all register accesses to the same cacheline to be serialized,
276+
* otherwise they may hang.
277+
*/
278+
static void intel_vblank_section_enter(struct drm_i915_private *i915)
279+
__acquires(i915->uncore.lock)
280+
{
281+
#ifdef I915
282+
spin_lock(&i915->uncore.lock);
283+
#endif
284+
}
285+
286+
static void intel_vblank_section_exit(struct drm_i915_private *i915)
287+
__releases(i915->uncore.lock)
288+
{
289+
#ifdef I915
290+
spin_unlock(&i915->uncore.lock);
291+
#endif
292+
}
293+
268294
static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
269295
bool in_vblank_irq,
270296
int *vpos, int *hpos,
@@ -302,11 +328,12 @@ static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
302328
}
303329

304330
/*
305-
* Lock uncore.lock, as we will do multiple timing critical raw
306-
* register reads, potentially with preemption disabled, so the
307-
* following code must not block on uncore.lock.
331+
* Enter vblank critical section, as we will do multiple
332+
* timing critical raw register reads, potentially with
333+
* preemption disabled, so the following code must not block.
308334
*/
309-
spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
335+
local_irq_save(irqflags);
336+
intel_vblank_section_enter(dev_priv);
310337

311338
/* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
312339

@@ -374,7 +401,8 @@ static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
374401

375402
/* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
376403

377-
spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
404+
intel_vblank_section_exit(dev_priv);
405+
local_irq_restore(irqflags);
378406

379407
/*
380408
* While in vblank, position will be negative
@@ -412,9 +440,13 @@ int intel_get_crtc_scanline(struct intel_crtc *crtc)
412440
unsigned long irqflags;
413441
int position;
414442

415-
spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
443+
local_irq_save(irqflags);
444+
intel_vblank_section_enter(dev_priv);
445+
416446
position = __intel_get_crtc_scanline(crtc);
417-
spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
447+
448+
intel_vblank_section_exit(dev_priv);
449+
local_irq_restore(irqflags);
418450

419451
return position;
420452
}
@@ -537,7 +569,7 @@ void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state,
537569
* Need to audit everything to make sure it's safe.
538570
*/
539571
spin_lock_irqsave(&i915->drm.vblank_time_lock, irqflags);
540-
spin_lock(&i915->uncore.lock);
572+
intel_vblank_section_enter(i915);
541573

542574
drm_calc_timestamping_constants(&crtc->base, &adjusted_mode);
543575

@@ -546,7 +578,6 @@ void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state,
546578
crtc->mode_flags = mode_flags;
547579

548580
crtc->scanline_offset = intel_crtc_scanline_offset(crtc_state);
549-
550-
spin_unlock(&i915->uncore.lock);
581+
intel_vblank_section_exit(i915);
551582
spin_unlock_irqrestore(&i915->drm.vblank_time_lock, irqflags);
552583
}

0 commit comments

Comments
 (0)