drivers/gpu/drm/vc4/vc4_bo.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/vc4/vc4_bo.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/vc4/vc4_bo.c- Extension
.c- Size
- 28161 bytes
- Lines
- 1104
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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
linux/dma-buf.hdrm/drm_fourcc.hdrm/drm_print.hvc4_drv.h
Detected Declarations
function is_user_labelfunction vc4_bo_stats_printfunction vc4_bo_stats_debugfsfunction strcmpfunction vc4_bo_set_labelfunction bo_page_indexfunction vc4_bo_destroyfunction vc4_bo_remove_from_cachefunction vc4_bo_cache_purgefunction vc4_bo_add_to_purgeable_poolfunction vc4_bo_remove_from_purgeable_pool_lockedfunction vc4_bo_remove_from_purgeable_poolfunction vc4_bo_purgefunction vc4_bo_userspace_cache_purgefunction vc4_bo_dumb_createfunction vc4_bo_cache_free_oldfunction vc4_free_objectfunction vc4_bo_cache_time_workfunction vc4_bo_inc_usecntfunction vc4_bo_dec_usecntfunction vc4_bo_cache_time_timerfunction vc4_faultfunction vc4_gem_object_mmapfunction vc4_grab_bin_bofunction vc4_create_bo_ioctlfunction vc4_mmap_bo_ioctlfunction vc4_create_shader_bo_ioctlfunction vc4_set_tiling_ioctlfunction vc4_get_tiling_ioctlfunction vc4_bo_debugfs_initfunction vc4_bo_cache_initfunction vc4_bo_cache_destroyfunction vc4_label_bo_ioctl
Annotated Snippet
if (!vc4->bo_labels[i].name) {
free_slot = i;
} else if (strcmp(vc4->bo_labels[i].name, name) == 0) {
kfree(name);
return i;
}
}
if (free_slot != -1) {
WARN_ON(vc4->bo_labels[free_slot].num_allocated != 0);
vc4->bo_labels[free_slot].name = name;
return free_slot;
} else {
u32 new_label_count = vc4->num_labels + 1;
struct vc4_label *new_labels =
krealloc(vc4->bo_labels,
new_label_count * sizeof(*new_labels),
GFP_KERNEL);
if (!new_labels) {
kfree(name);
return -1;
}
free_slot = vc4->num_labels;
vc4->bo_labels = new_labels;
vc4->num_labels = new_label_count;
vc4->bo_labels[free_slot].name = name;
vc4->bo_labels[free_slot].num_allocated = 0;
vc4->bo_labels[free_slot].size_allocated = 0;
return free_slot;
}
}
static void vc4_bo_set_label(struct drm_gem_object *gem_obj, int label)
{
struct vc4_bo *bo = to_vc4_bo(gem_obj);
struct vc4_dev *vc4 = to_vc4_dev(gem_obj->dev);
lockdep_assert_held(&vc4->bo_lock);
if (label != -1) {
vc4->bo_labels[label].num_allocated++;
vc4->bo_labels[label].size_allocated += gem_obj->size;
}
vc4->bo_labels[bo->label].num_allocated--;
vc4->bo_labels[bo->label].size_allocated -= gem_obj->size;
if (vc4->bo_labels[bo->label].num_allocated == 0 &&
is_user_label(bo->label)) {
/* Free user BO label slots on last unreference.
* Slots are just where we track the stats for a given
* name, and once a name is unused we can reuse that
* slot.
*/
kfree(vc4->bo_labels[bo->label].name);
vc4->bo_labels[bo->label].name = NULL;
}
bo->label = label;
}
static uint32_t bo_page_index(size_t size)
{
return (size / PAGE_SIZE) - 1;
}
static void vc4_bo_destroy(struct vc4_bo *bo)
{
struct drm_gem_object *obj = &bo->base.base;
struct vc4_dev *vc4 = to_vc4_dev(obj->dev);
lockdep_assert_held(&vc4->bo_lock);
vc4_bo_set_label(obj, -1);
if (bo->validated_shader) {
kfree(bo->validated_shader->uniform_addr_offsets);
kfree(bo->validated_shader->texture_samples);
kfree(bo->validated_shader);
bo->validated_shader = NULL;
}
mutex_destroy(&bo->madv_lock);
drm_gem_dma_free(&bo->base);
}
Annotation
- Immediate include surface: `linux/dma-buf.h`, `drm/drm_fourcc.h`, `drm/drm_print.h`, `vc4_drv.h`.
- Detected declarations: `function is_user_label`, `function vc4_bo_stats_print`, `function vc4_bo_stats_debugfs`, `function strcmp`, `function vc4_bo_set_label`, `function bo_page_index`, `function vc4_bo_destroy`, `function vc4_bo_remove_from_cache`, `function vc4_bo_cache_purge`, `function vc4_bo_add_to_purgeable_pool`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.