drivers/gpu/drm/drm_vma_manager.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_vma_manager.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_vma_manager.c- Extension
.c- Size
- 13667 bytes
- Lines
- 423
- 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.
- 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
linux/export.hlinux/mm.hlinux/module.hlinux/rbtree.hlinux/slab.hlinux/spinlock.hlinux/types.hdrm/drm_mm.hdrm/drm_vma_manager.h
Detected Declarations
function Copyrightfunction drm_vma_offset_manager_destroyfunction drm_vma_offset_addfunction drm_vma_offset_removefunction vma_node_allowfunction drm_vma_offset_removefunction drm_vma_offset_removefunction drm_vma_node_allowfunction drm_vma_node_is_allowedexport drm_vma_offset_manager_initexport drm_vma_offset_manager_destroyexport drm_vma_offset_lookup_lockedexport drm_vma_offset_addexport drm_vma_offset_removeexport drm_vma_node_allowexport drm_vma_node_allow_onceexport drm_vma_node_revokeexport drm_vma_node_is_allowed
Annotated Snippet
if (start >= offset) {
iter = iter->rb_right;
best = node;
if (start == offset)
break;
} else {
iter = iter->rb_left;
}
}
/* verify that the node spans the requested area */
if (best) {
offset = best->start + best->size;
if (offset < start + pages)
best = NULL;
}
if (!best)
return NULL;
return container_of(best, struct drm_vma_offset_node, vm_node);
}
EXPORT_SYMBOL(drm_vma_offset_lookup_locked);
/**
* drm_vma_offset_add() - Add offset node to manager
* @mgr: Manager object
* @node: Node to be added
* @pages: Allocation size visible to user-space (in number of pages)
*
* Add a node to the offset-manager. If the node was already added, this does
* nothing and return 0. @pages is the size of the object given in number of
* pages.
* After this call succeeds, you can access the offset of the node until it
* is removed again.
*
* If this call fails, it is safe to retry the operation or call
* drm_vma_offset_remove(), anyway. However, no cleanup is required in that
* case.
*
* @pages is not required to be the same size as the underlying memory object
* that you want to map. It only limits the size that user-space can map into
* their address space.
*
* RETURNS:
* 0 on success, negative error code on failure.
*/
int drm_vma_offset_add(struct drm_vma_offset_manager *mgr,
struct drm_vma_offset_node *node, unsigned long pages)
{
int ret = 0;
write_lock(&mgr->vm_lock);
if (!drm_mm_node_allocated(&node->vm_node))
ret = drm_mm_insert_node(&mgr->vm_addr_space_mm,
&node->vm_node, pages);
write_unlock(&mgr->vm_lock);
return ret;
}
EXPORT_SYMBOL(drm_vma_offset_add);
/**
* drm_vma_offset_remove() - Remove offset node from manager
* @mgr: Manager object
* @node: Node to be removed
*
* Remove a node from the offset manager. If the node wasn't added before, this
* does nothing. After this call returns, the offset and size will be 0 until a
* new offset is allocated via drm_vma_offset_add() again. Helper functions like
* drm_vma_node_start() and drm_vma_node_offset_addr() will return 0 if no
* offset is allocated.
*/
void drm_vma_offset_remove(struct drm_vma_offset_manager *mgr,
struct drm_vma_offset_node *node)
{
write_lock(&mgr->vm_lock);
if (drm_mm_node_allocated(&node->vm_node)) {
drm_mm_remove_node(&node->vm_node);
memset(&node->vm_node, 0, sizeof(node->vm_node));
}
write_unlock(&mgr->vm_lock);
}
EXPORT_SYMBOL(drm_vma_offset_remove);
static int vma_node_allow(struct drm_vma_offset_node *node,
Annotation
- Immediate include surface: `linux/export.h`, `linux/mm.h`, `linux/module.h`, `linux/rbtree.h`, `linux/slab.h`, `linux/spinlock.h`, `linux/types.h`, `drm/drm_mm.h`.
- Detected declarations: `function Copyright`, `function drm_vma_offset_manager_destroy`, `function drm_vma_offset_add`, `function drm_vma_offset_remove`, `function vma_node_allow`, `function drm_vma_offset_remove`, `function drm_vma_offset_remove`, `function drm_vma_node_allow`, `function drm_vma_node_is_allowed`, `export drm_vma_offset_manager_init`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration implementation candidate.
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.