drivers/gpu/drm/i915/intel_wakeref.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/intel_wakeref.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/i915/intel_wakeref.c
Extension
.c
Size
5612 bytes
Lines
230
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (ret) {
			wakeref = xchg(&wf->wakeref, NULL);
			wake_up_var(&wf->wakeref);
			goto unlock;
		}

		smp_mb__before_atomic(); /* release wf->count */
	}

	atomic_inc(&wf->count);
	INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0);

unlock:
	mutex_unlock(&wf->mutex);
	if (unlikely(wakeref))
		intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref);

	return ret;
}

static void ____intel_wakeref_put_last(struct intel_wakeref *wf)
{
	intel_wakeref_t wakeref = NULL;

	INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0);
	if (unlikely(!atomic_dec_and_test(&wf->count)))
		goto unlock;

	/* ops->put() must reschedule its own release on error/deferral */
	if (likely(!wf->ops->put(wf))) {
		INTEL_WAKEREF_BUG_ON(!wf->wakeref);
		wakeref = xchg(&wf->wakeref, NULL);
		wake_up_var(&wf->wakeref);
	}

unlock:
	mutex_unlock(&wf->mutex);
	if (wakeref)
		intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref);
}

void __intel_wakeref_put_last(struct intel_wakeref *wf, unsigned long flags)
{
	INTEL_WAKEREF_BUG_ON(delayed_work_pending(&wf->work));

	/* Assume we are not in process context and so cannot sleep. */
	if (flags & INTEL_WAKEREF_PUT_ASYNC || !mutex_trylock(&wf->mutex)) {
		mod_delayed_work(wf->i915->unordered_wq, &wf->work,
				 FIELD_GET(INTEL_WAKEREF_PUT_DELAY_MASK, flags));
		return;
	}

	____intel_wakeref_put_last(wf);
}

static void __intel_wakeref_put_work(struct work_struct *wrk)
{
	struct intel_wakeref *wf = container_of(wrk, typeof(*wf), work.work);

	if (atomic_add_unless(&wf->count, -1, 1))
		return;

	mutex_lock(&wf->mutex);
	____intel_wakeref_put_last(wf);
}

void __intel_wakeref_init(struct intel_wakeref *wf,
			  struct drm_i915_private *i915,
			  const struct intel_wakeref_ops *ops,
			  struct intel_wakeref_lockclass *key,
			  const char *name)
{
	wf->i915 = i915;
	wf->ops = ops;

	__mutex_init(&wf->mutex, "wakeref.mutex", &key->mutex);
	atomic_set(&wf->count, 0);
	wf->wakeref = NULL;

	INIT_DELAYED_WORK(&wf->work, __intel_wakeref_put_work);
	lockdep_init_map(&wf->work.work.lockdep_map,
			 "wakeref.work", &key->work, 0);

#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_WAKEREF)
	if (!wf->debug.class)
		ref_tracker_dir_init(&wf->debug, INTEL_REFTRACK_DEAD_COUNT, "intel_wakeref");
#endif
}

int intel_wakeref_wait_for_idle(struct intel_wakeref *wf)

Annotation

Implementation Notes