drivers/gpu/drm/drm_gem_framebuffer_helper.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_gem_framebuffer_helper.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_gem_framebuffer_helper.c- Extension
.c- Size
- 18882 bytes
- Lines
- 623
- 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
linux/export.hlinux/slab.hlinux/module.hdrm/drm_damage_helper.hdrm/drm_drv.hdrm/drm_fourcc.hdrm/drm_framebuffer.hdrm/drm_gem.hdrm/drm_gem_framebuffer_helper.hdrm/drm_modeset_helper.hdrm/drm_print.hdrm_internal.h
Detected Declarations
function drm_gem_fb_createfunction drm_gem_fb_initfunction bufferfunction drm_gem_fb_create_handlefunction drm_gem_fb_init_with_funcsfunction drm_gem_fb_create_with_funcsfunction drm_gem_fb_createfunction drm_gem_fb_create_with_dirtyfunction drm_gem_fb_vunmapfunction drm_gem_fb_vmapfunction __drm_gem_fb_end_cpu_accessfunction drm_gem_fb_end_cpu_accessfunction drm_gem_fb_begin_cpu_accessfunction drm_gem_afbc_get_bppfunction drm_gem_afbc_min_sizefunction drm_gem_fb_afbc_initexport drm_gem_fb_get_objexport drm_gem_fb_destroyexport drm_gem_fb_create_handleexport drm_gem_fb_init_with_funcsexport drm_gem_fb_create_with_funcsexport drm_gem_fb_createexport drm_gem_fb_create_with_dirtyexport drm_gem_fb_vmapexport drm_gem_fb_vunmapexport drm_gem_fb_begin_cpu_accessexport drm_gem_fb_end_cpu_accessexport drm_gem_fb_afbc_init
Annotated Snippet
if (!objs[i]) {
drm_dbg_kms(dev, "Failed to lookup GEM object\n");
ret = -ENOENT;
goto err_gem_object_put;
}
min_size = (height - 1) * mode_cmd->pitches[i]
+ drm_format_info_min_pitch(info, i, width)
+ mode_cmd->offsets[i];
if (objs[i]->size < min_size) {
drm_dbg_kms(dev,
"GEM object size (%zu) smaller than minimum size (%u) for plane %d\n",
objs[i]->size, min_size, i);
drm_gem_object_put(objs[i]);
ret = -EINVAL;
goto err_gem_object_put;
}
}
ret = drm_gem_fb_init(dev, fb, info, mode_cmd, objs, i, funcs);
if (ret)
goto err_gem_object_put;
return 0;
err_gem_object_put:
while (i > 0) {
--i;
drm_gem_object_put(objs[i]);
}
return ret;
}
EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs);
/**
* drm_gem_fb_create_with_funcs() - Helper function for the
* &drm_mode_config_funcs.fb_create
* callback
* @dev: DRM device
* @file: DRM file that holds the GEM handle(s) backing the framebuffer
* @info: pixel format information
* @mode_cmd: Metadata from the userspace framebuffer creation request
* @funcs: vtable to be used for the new framebuffer object
*
* This function can be used to set &drm_framebuffer_funcs for drivers that need
* custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
* change &drm_framebuffer_funcs. The function does buffer size validation.
*
* Returns:
* Pointer to a &drm_framebuffer on success or an error pointer on failure.
*/
struct drm_framebuffer *
drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
const struct drm_format_info *info,
const struct drm_mode_fb_cmd2 *mode_cmd,
const struct drm_framebuffer_funcs *funcs)
{
struct drm_framebuffer *fb;
int ret;
fb = kzalloc_obj(*fb);
if (!fb)
return ERR_PTR(-ENOMEM);
ret = drm_gem_fb_init_with_funcs(dev, fb, file, info, mode_cmd, funcs);
if (ret) {
kfree(fb);
return ERR_PTR(ret);
}
return fb;
}
EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs);
static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
.destroy = drm_gem_fb_destroy,
.create_handle = drm_gem_fb_create_handle,
};
/**
* drm_gem_fb_create() - Helper function for the
* &drm_mode_config_funcs.fb_create callback
* @dev: DRM device
* @file: DRM file that holds the GEM handle(s) backing the framebuffer
* @info: pixel format information
* @mode_cmd: Metadata from the userspace framebuffer creation request
*
* This function creates a new framebuffer object described by
* &drm_mode_fb_cmd2. This description includes handles for the buffer(s)
Annotation
- Immediate include surface: `linux/export.h`, `linux/slab.h`, `linux/module.h`, `drm/drm_damage_helper.h`, `drm/drm_drv.h`, `drm/drm_fourcc.h`, `drm/drm_framebuffer.h`, `drm/drm_gem.h`.
- Detected declarations: `function drm_gem_fb_create`, `function drm_gem_fb_init`, `function buffer`, `function drm_gem_fb_create_handle`, `function drm_gem_fb_init_with_funcs`, `function drm_gem_fb_create_with_funcs`, `function drm_gem_fb_create`, `function drm_gem_fb_create_with_dirty`, `function drm_gem_fb_vunmap`, `function drm_gem_fb_vmap`.
- 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.