drivers/gpu/drm/i915/intel_wakeref.h

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

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/i915/intel_wakeref.h
Extension
.h
Size
8686 bytes
Lines
352
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

struct intel_wakeref_ops {
	int (*get)(struct intel_wakeref *wf);
	int (*put)(struct intel_wakeref *wf);
};

struct intel_wakeref {
	atomic_t count;
	struct mutex mutex;

	intel_wakeref_t wakeref;

	struct drm_i915_private *i915;
	const struct intel_wakeref_ops *ops;

	struct delayed_work work;

#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_WAKEREF)
	struct ref_tracker_dir debug;
#endif
};

struct intel_wakeref_lockclass {
	struct lock_class_key mutex;
	struct lock_class_key work;
};

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);
#define intel_wakeref_init(wf, i915, ops, name) do {			\
	static struct intel_wakeref_lockclass __key;			\
									\
	__intel_wakeref_init((wf), (i915), (ops), &__key, name);	\
} while (0)

int __intel_wakeref_get_first(struct intel_wakeref *wf);
void __intel_wakeref_put_last(struct intel_wakeref *wf, unsigned long flags);

/**
 * intel_wakeref_get: Acquire the wakeref
 * @wf: the wakeref
 *
 * Acquire a hold on the wakeref. The first user to do so, will acquire
 * the runtime pm wakeref and then call the intel_wakeref_ops->get()
 * underneath the wakeref mutex.
 *
 * Note that intel_wakeref_ops->get() is allowed to fail, in which case
 * the runtime-pm wakeref will be released and the acquisition unwound,
 * and an error reported.
 *
 * Returns: 0 if the wakeref was acquired successfully, or a negative error
 * code otherwise.
 */
static inline int
intel_wakeref_get(struct intel_wakeref *wf)
{
	might_sleep();
	if (unlikely(!atomic_inc_not_zero(&wf->count)))
		return __intel_wakeref_get_first(wf);

	return 0;
}

/**
 * __intel_wakeref_get: Acquire the wakeref, again
 * @wf: the wakeref
 *
 * Increment the wakeref counter, only valid if it is already held by
 * the caller.
 *
 * See intel_wakeref_get().
 */
static inline void
__intel_wakeref_get(struct intel_wakeref *wf)
{
	INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0);
	atomic_inc(&wf->count);
}

/**
 * intel_wakeref_get_if_active: Acquire the wakeref
 * @wf: the wakeref
 *
 * Acquire a hold on the wakeref, but only if the wakeref is already
 * active.
 *
 * Returns: true if the wakeref was acquired, false otherwise.
 */

Annotation

Implementation Notes