drivers/gpu/drm/xe/xe_guc_id_mgr.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_guc_id_mgr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/xe/xe_guc_id_mgr.c- Extension
.c- Size
- 7328 bytes
- Lines
- 281
- 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/bitmap.hlinux/mutex.hdrm/drm_managed.hxe_assert.hxe_gt_printk.hxe_guc.hxe_guc_id_mgr.hxe_guc_types.htests/xe_guc_id_mgr_test.c
Detected Declarations
function __fini_idmfunction xe_guc_id_mgr_initfunction find_last_zero_areafunction for_each_clear_bitrangefunction idm_reserve_chunk_lockedfunction idm_release_chunk_lockedfunction xe_guc_id_mgr_reserve_lockedfunction xe_guc_id_mgr_release_lockedfunction xe_guc_id_mgr_reservefunction xe_guc_id_mgr_releasefunction idm_print_lockedfunction xe_guc_id_mgr_print
Annotated Snippet
if (weight) {
struct drm_printer p = xe_gt_info_printer(idm_to_gt(idm));
xe_gt_err(idm_to_gt(idm), "GUC ID manager unclean (%u/%u)\n",
weight, idm->total);
idm_print_locked(idm, &p, 1);
}
}
bitmap_free(idm->bitmap);
idm->bitmap = NULL;
idm->total = 0;
idm->used = 0;
mutex_unlock(idm_mutex(idm));
}
/**
* xe_guc_id_mgr_init() - Initialize GuC context ID Manager.
* @idm: the &xe_guc_id_mgr to initialize
* @limit: number of IDs to manage
*
* The bare-metal or PF driver can pass ~0 as &limit to indicate that all
* context IDs supported by the GuC firmware are available for use.
*
* Only VF drivers will have to provide explicit number of context IDs
* that they can use.
*
* Return: 0 on success or a negative error code on failure.
*/
int xe_guc_id_mgr_init(struct xe_guc_id_mgr *idm, unsigned int limit)
{
int ret;
idm_assert(idm, !idm->bitmap);
idm_assert(idm, !idm->total);
idm_assert(idm, !idm->used);
if (limit == ~0)
limit = GUC_ID_MAX;
else if (limit > GUC_ID_MAX)
return -ERANGE;
else if (!limit)
return -EINVAL;
idm->bitmap = bitmap_zalloc(limit, GFP_KERNEL);
if (!idm->bitmap)
return -ENOMEM;
idm->total = limit;
ret = drmm_add_action_or_reset(&idm_to_xe(idm)->drm, __fini_idm, idm);
if (ret)
return ret;
xe_gt_dbg(idm_to_gt(idm), "using %u GuC ID%s\n",
idm->total, str_plural(idm->total));
return 0;
}
static unsigned int find_last_zero_area(unsigned long *bitmap,
unsigned int total,
unsigned int count)
{
unsigned int found = total;
unsigned int rs, re, range;
for_each_clear_bitrange(rs, re, bitmap, total) {
range = re - rs;
if (range < count)
continue;
found = rs + (range - count);
}
return found;
}
static int idm_reserve_chunk_locked(struct xe_guc_id_mgr *idm,
unsigned int count, unsigned int retain)
{
int id;
idm_assert(idm, count);
lockdep_assert_held(idm_mutex(idm));
if (!idm->total)
return -ENODATA;
if (retain) {
/*
* For IDs reservations (used on PF for VFs) we want to make
* sure there will be at least 'retain' available for the PF
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/mutex.h`, `drm/drm_managed.h`, `xe_assert.h`, `xe_gt_printk.h`, `xe_guc.h`, `xe_guc_id_mgr.h`, `xe_guc_types.h`.
- Detected declarations: `function __fini_idm`, `function xe_guc_id_mgr_init`, `function find_last_zero_area`, `function for_each_clear_bitrange`, `function idm_reserve_chunk_locked`, `function idm_release_chunk_locked`, `function xe_guc_id_mgr_reserve_locked`, `function xe_guc_id_mgr_release_locked`, `function xe_guc_id_mgr_reserve`, `function xe_guc_id_mgr_release`.
- 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.