drivers/gpu/drm/drm_suballoc.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_suballoc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_suballoc.c- Extension
.c- Size
- 14992 bytes
- Lines
- 526
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
drm/drm_suballoc.hdrm/drm_print.hlinux/export.hlinux/slab.hlinux/sched.hlinux/wait.hlinux/dma-fence.h
Detected Declarations
function drm_suballoc_manager_initfunction drm_suballoc_manager_finifunction drm_suballoc_remove_lockedfunction drm_suballoc_try_freefunction drm_suballoc_hole_soffsetfunction drm_suballoc_hole_eoffsetfunction drm_suballoc_try_allocfunction __drm_suballoc_eventfunction drm_suballoc_eventfunction drm_suballoc_next_holefunction drm_suballoc_allocfunction drm_suballoc_insertfunction drm_suballoc_newfunction drm_suballoc_freefunction drm_suballoc_dump_debug_infoexport drm_suballoc_manager_initexport drm_suballoc_manager_finiexport drm_suballoc_allocexport drm_suballoc_insertexport drm_suballoc_newexport drm_suballoc_freeexport drm_suballoc_dump_debug_info
Annotated Snippet
if (!dma_fence_is_signaled(sa->fence)) {
fences[i] = sa->fence;
continue;
}
/* limit the number of tries each freelist gets */
if (tries[i] > 2)
continue;
tmp = sa->soffset;
if (tmp < soffset) {
/* wrap around, pretend it's after */
tmp += sa_manager->size;
}
tmp -= soffset;
if (tmp < best) {
/* this sa bo is the closest one */
best = tmp;
best_idx = i;
best_bo = sa;
}
}
if (best_bo) {
++tries[best_idx];
sa_manager->hole = best_bo->olist.prev;
/*
* We know that this one is signaled,
* so it's safe to remove it.
*/
drm_suballoc_remove_locked(best_bo);
return true;
}
return false;
}
/**
* drm_suballoc_alloc() - Allocate uninitialized suballoc object.
* @gfp: gfp flags used for memory allocation.
*
* Allocate memory for an uninitialized suballoc object. Intended usage is
* allocate memory for suballoc object outside of a reclaim tainted context
* and then be initialized at a later time in a reclaim tainted context.
*
* @drm_suballoc_free() should be used to release the memory if returned
* suballoc object is in uninitialized state.
*
* Return: a new uninitialized suballoc object, or an ERR_PTR(-ENOMEM).
*/
struct drm_suballoc *drm_suballoc_alloc(gfp_t gfp)
{
struct drm_suballoc *sa;
sa = kmalloc_obj(*sa, gfp);
if (!sa)
return ERR_PTR(-ENOMEM);
sa->manager = NULL;
return sa;
}
EXPORT_SYMBOL(drm_suballoc_alloc);
/**
* drm_suballoc_insert() - Initialize a suballocation and insert a hole.
* @sa_manager: pointer to the sa_manager
* @sa: The struct drm_suballoc.
* @size: number of bytes we want to suballocate.
* @intr: Whether to perform waits interruptible. This should typically
* always be true, unless the caller needs to propagate a
* non-interruptible context from above layers.
* @align: Alignment. Must not exceed the default manager alignment.
* If @align is zero, then the manager alignment is used.
*
* Try to make a suballocation on a pre-allocated suballoc object of size @size,
* which will be rounded up to the alignment specified in specified in
* drm_suballoc_manager_init().
*
* Return: zero on success, errno on failure.
*/
int drm_suballoc_insert(struct drm_suballoc_manager *sa_manager,
struct drm_suballoc *sa, size_t size,
bool intr, size_t align)
{
struct dma_fence *fences[DRM_SUBALLOC_MAX_QUEUES];
unsigned int tries[DRM_SUBALLOC_MAX_QUEUES];
unsigned int count;
int i, r;
Annotation
- Immediate include surface: `drm/drm_suballoc.h`, `drm/drm_print.h`, `linux/export.h`, `linux/slab.h`, `linux/sched.h`, `linux/wait.h`, `linux/dma-fence.h`.
- Detected declarations: `function drm_suballoc_manager_init`, `function drm_suballoc_manager_fini`, `function drm_suballoc_remove_locked`, `function drm_suballoc_try_free`, `function drm_suballoc_hole_soffset`, `function drm_suballoc_hole_eoffset`, `function drm_suballoc_try_alloc`, `function __drm_suballoc_event`, `function drm_suballoc_event`, `function drm_suballoc_next_hole`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration 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.