drivers/gpu/drm/panfrost/panfrost_gem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/panfrost/panfrost_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/panfrost/panfrost_gem.c- Extension
.c- Size
- 20320 bytes
- Lines
- 749
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/cleanup.hlinux/err.hlinux/slab.hlinux/dma-buf.hlinux/dma-mapping.hdrm/panfrost_drm.hdrm/drm_print.hpanfrost_device.hpanfrost_drv.hpanfrost_gem.hpanfrost_mmu.h
Detected Declarations
struct gem_size_totalsstruct flag_deffunction panfrost_gem_initfunction panfrost_gem_debugfs_bo_addfunction panfrost_gem_debugfs_bo_rmfunction panfrost_gem_debugfs_bo_addfunction panfrost_gem_mapping_getfunction panfrost_gem_teardown_mappingfunction panfrost_gem_mapping_releasefunction panfrost_gem_mapping_putfunction panfrost_gem_teardown_mappings_lockedfunction panfrost_gem_openfunction panfrost_gem_closefunction panfrost_gem_pinfunction panfrost_gem_statusfunction panfrost_gem_rssfunction panfrost_gem_prime_map_dma_buffunction panfrost_gem_prime_unmap_dma_buffunction panfrost_gem_prime_begin_cpu_accessfunction list_for_each_entryfunction panfrost_gem_prime_end_cpu_accessfunction panfrost_gem_prime_exportfunction panfrost_gem_prime_importfunction should_map_wcfunction panfrost_gem_createfunction panfrost_gem_prime_import_sg_tablefunction panfrost_gem_set_labelfunction scoped_guardfunction panfrost_gem_syncfunction for_each_sgtable_dma_sgfunction panfrost_gem_internal_set_labelfunction panfrost_gem_debugfs_print_flag_namesfunction panfrost_gem_debugfs_bo_printfunction scoped_guardfunction panfrost_gem_debugfs_print_bosfunction scoped_guard
Annotated Snippet
struct gem_size_totals {
size_t size;
size_t resident;
size_t reclaimable;
};
struct flag_def {
u32 flag;
const char *name;
};
static void panfrost_gem_debugfs_print_flag_names(struct seq_file *m)
{
int len;
int i;
static const struct flag_def gem_state_flags_names[] = {
{PANFROST_DEBUGFS_GEM_STATE_FLAG_IMPORTED, "imported"},
{PANFROST_DEBUGFS_GEM_STATE_FLAG_EXPORTED, "exported"},
{PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGED, "purged"},
{PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGEABLE, "purgeable"},
};
seq_puts(m, "GEM state flags: ");
for (i = 0, len = ARRAY_SIZE(gem_state_flags_names); i < len; i++) {
seq_printf(m, "%s (0x%x)%s", gem_state_flags_names[i].name,
gem_state_flags_names[i].flag, (i < len - 1) ? ", " : "\n\n");
}
}
static void panfrost_gem_debugfs_bo_print(struct panfrost_gem_object *bo,
struct seq_file *m,
struct gem_size_totals *totals)
{
unsigned int refcount = kref_read(&bo->base.base.refcount);
char creator_info[32] = {};
size_t resident_size;
u32 gem_state_flags = 0;
/* Skip BOs being destroyed. */
if (!refcount)
return;
resident_size = panfrost_gem_rss(&bo->base.base);
snprintf(creator_info, sizeof(creator_info),
"%s/%d", bo->debugfs.creator.process_name, bo->debugfs.creator.tgid);
seq_printf(m, "%-32s%-16d%-16d%-16zd%-16zd0x%-16lx",
creator_info,
bo->base.base.name,
refcount,
bo->base.base.size,
resident_size,
drm_vma_node_start(&bo->base.base.vma_node));
if (drm_gem_is_imported(&bo->base.base))
gem_state_flags |= PANFROST_DEBUGFS_GEM_STATE_FLAG_IMPORTED;
if (bo->base.base.dma_buf)
gem_state_flags |= PANFROST_DEBUGFS_GEM_STATE_FLAG_EXPORTED;
if (bo->base.madv < 0)
gem_state_flags |= PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGED;
else if (bo->base.madv > 0)
gem_state_flags |= PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGEABLE;
seq_printf(m, "0x%-10x", gem_state_flags);
scoped_guard(mutex, &bo->label.lock) {
seq_printf(m, "%s\n", bo->label.str ? : "");
}
totals->size += bo->base.base.size;
totals->resident += resident_size;
if (bo->base.madv > 0)
totals->reclaimable += resident_size;
}
void panfrost_gem_debugfs_print_bos(struct panfrost_device *pfdev,
struct seq_file *m)
{
struct gem_size_totals totals = {0};
struct panfrost_gem_object *bo;
panfrost_gem_debugfs_print_flag_names(m);
seq_puts(m, "created-by global-name refcount size resident-size file-offset state label\n");
seq_puts(m, "-----------------------------------------------------------------------------------------------------------------------------------\n");
scoped_guard(mutex, &pfdev->debugfs.gems_lock) {
list_for_each_entry(bo, &pfdev->debugfs.gems_list, debugfs.node) {
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/err.h`, `linux/slab.h`, `linux/dma-buf.h`, `linux/dma-mapping.h`, `drm/panfrost_drm.h`, `drm/drm_print.h`, `panfrost_device.h`.
- Detected declarations: `struct gem_size_totals`, `struct flag_def`, `function panfrost_gem_init`, `function panfrost_gem_debugfs_bo_add`, `function panfrost_gem_debugfs_bo_rm`, `function panfrost_gem_debugfs_bo_add`, `function panfrost_gem_mapping_get`, `function panfrost_gem_teardown_mapping`, `function panfrost_gem_mapping_release`, `function panfrost_gem_mapping_put`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.