drivers/gpu/drm/xe/xe_guard.h
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_guard.h
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/xe/xe_guard.h- Extension
.h- Size
- 3023 bytes
- Lines
- 120
- 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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/spinlock.h
Detected Declarations
struct xe_guardfunction xe_guard_initfunction xe_guard_armfunction xe_guard_disarmfunction xe_guard_mode_str
Annotated Snippet
struct xe_guard {
/**
* @counter: implements simple exclusive/lockdown logic:
* if == 0 then guard/feature is idle/not in use,
* if < 0 then feature is active and can't be locked-down,
* if > 0 then feature is lockded-down and can't be activated.
*/
int counter;
/** @name: the name of the guard (useful for debug) */
const char *name;
/** @owner: the info about the last owner of the guard (for debug) */
void *owner;
/** @lock: protects guard's data */
spinlock_t lock;
};
/**
* xe_guard_init() - Initialize the guard.
* @guard: the &xe_guard to init
* @name: name of the guard
*/
static inline void xe_guard_init(struct xe_guard *guard, const char *name)
{
spin_lock_init(&guard->lock);
guard->counter = 0;
guard->name = name;
}
/**
* xe_guard_arm() - Arm the guard for the exclusive/lockdown mode.
* @guard: the &xe_guard to arm
* @lockdown: arm for lockdown(true) or exclusive(false) mode
* @who: optional owner info (for debug only)
*
* Multiple lockdown requests are allowed.
* Only single exclusive access can be granted.
* Will fail if the guard is already in exclusive mode.
* On success, must call the xe_guard_disarm() to release.
*
* Return: 0 on success or a negative error code on failure.
*/
static inline int xe_guard_arm(struct xe_guard *guard, bool lockdown, void *who)
{
guard(spinlock)(&guard->lock);
if (lockdown) {
if (guard->counter < 0)
return -EBUSY;
guard->counter++;
} else {
if (guard->counter > 0)
return -EPERM;
if (guard->counter < 0)
return -EUSERS;
guard->counter--;
}
guard->owner = who;
return 0;
}
/**
* xe_guard_disarm() - Disarm the guard from exclusive/lockdown mode.
* @guard: the &xe_guard to disarm
* @lockdown: disarm from lockdown(true) or exclusive(false) mode
*
* Return: true if successfully disarmed or false in case of mismatch.
*/
static inline bool xe_guard_disarm(struct xe_guard *guard, bool lockdown)
{
guard(spinlock)(&guard->lock);
if (lockdown) {
if (guard->counter <= 0)
return false;
guard->counter--;
} else {
if (guard->counter != -1)
return false;
guard->counter++;
}
return true;
}
/**
* xe_guard_mode_str() - Convert guard mode into a string.
* @lockdown: flag used to select lockdown or exclusive mode
Annotation
- Immediate include surface: `linux/spinlock.h`.
- Detected declarations: `struct xe_guard`, `function xe_guard_init`, `function xe_guard_arm`, `function xe_guard_disarm`, `function xe_guard_mode_str`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.