drivers/gpu/drm/drm_framebuffer.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_framebuffer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_framebuffer.c- Extension
.c- Size
- 34616 bytes
- Lines
- 1239
- 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.
- 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/export.hlinux/uaccess.hdrm/drm_atomic.hdrm/drm_atomic_uapi.hdrm/drm_auth.hdrm/drm_debugfs.hdrm/drm_drv.hdrm/drm_file.hdrm/drm_fourcc.hdrm/drm_framebuffer.hdrm/drm_gem.hdrm/drm_print.hdrm/drm_util.hdrm_crtc_internal.hdrm_internal.h
Detected Declarations
struct drm_mode_rmfb_workfunction Copyrightfunction drm_mode_addfbfunction drm_mode_addfb_ioctlfunction framebuffer_checkfunction drm_internal_framebuffer_createfunction drm_mode_addfb2function drm_mode_addfb2_ioctlfunction drm_mode_rmfb_work_fnfunction drm_mode_closefbfunction drm_mode_rmfbfunction drm_mode_rmfb_ioctlfunction drm_mode_closefb_ioctlfunction drm_mode_getfbfunction drm_mode_getfb2_ioctlfunction handlesfunction drm_mode_dirtyfb_ioctlfunction drm_fb_releasefunction drm_framebuffer_freefunction drm_framebuffer_initfunction drm_framebuffer_putfunction drm_framebuffer_cleanupfunction atomic_remove_fbfunction drm_for_each_planefunction legacy_remove_fbfunction drm_for_each_planefunction drm_framebuffer_removefunction drm_framebuffer_print_infofunction drm_framebuffer_infofunction drm_framebuffer_debugfs_initexport drm_framebuffer_initexport drm_framebuffer_lookupexport drm_framebuffer_unregister_privateexport drm_framebuffer_cleanupexport drm_framebuffer_remove
Annotated Snippet
struct drm_mode_rmfb_work {
struct work_struct work;
struct list_head fbs;
};
static void drm_mode_rmfb_work_fn(struct work_struct *w)
{
struct drm_mode_rmfb_work *arg = container_of(w, typeof(*arg), work);
while (!list_empty(&arg->fbs)) {
struct drm_framebuffer *fb =
list_first_entry(&arg->fbs, typeof(*fb), filp_head);
drm_dbg_kms(fb->dev,
"Removing [FB:%d] from all active usage due to RMFB ioctl\n",
fb->base.id);
list_del_init(&fb->filp_head);
drm_framebuffer_remove(fb);
}
}
static int drm_mode_closefb(struct drm_framebuffer *fb,
struct drm_file *file_priv)
{
struct drm_framebuffer *fbl;
bool found = false;
mutex_lock(&file_priv->fbs_lock);
list_for_each_entry(fbl, &file_priv->fbs, filp_head)
if (fb == fbl)
found = true;
if (!found) {
mutex_unlock(&file_priv->fbs_lock);
return -ENOENT;
}
list_del_init(&fb->filp_head);
mutex_unlock(&file_priv->fbs_lock);
/* Drop the reference that was stored in the fbs list */
drm_framebuffer_put(fb);
return 0;
}
/**
* drm_mode_rmfb - remove an FB from the configuration
* @dev: drm device
* @fb_id: id of framebuffer to remove
* @file_priv: drm file
*
* Remove the specified FB.
*
* Called by the user via ioctl, or by an in-kernel client.
*
* Returns:
* Zero on success, negative errno on failure.
*/
int drm_mode_rmfb(struct drm_device *dev, u32 fb_id,
struct drm_file *file_priv)
{
struct drm_framebuffer *fb;
int ret;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EOPNOTSUPP;
fb = drm_framebuffer_lookup(dev, file_priv, fb_id);
if (!fb)
return -ENOENT;
ret = drm_mode_closefb(fb, file_priv);
if (ret != 0) {
drm_framebuffer_put(fb);
return ret;
}
/*
* drm_framebuffer_remove may fail with -EINTR on pending signals,
* so run this in a separate stack as there's no way to correctly
* handle this after the fb is already removed from the lookup table.
*/
if (drm_framebuffer_read_refcount(fb) > 1) {
struct drm_mode_rmfb_work arg;
INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
INIT_LIST_HEAD(&arg.fbs);
drm_WARN_ON(dev, !list_empty(&fb->filp_head));
list_add_tail(&fb->filp_head, &arg.fbs);
Annotation
- Immediate include surface: `linux/export.h`, `linux/uaccess.h`, `drm/drm_atomic.h`, `drm/drm_atomic_uapi.h`, `drm/drm_auth.h`, `drm/drm_debugfs.h`, `drm/drm_drv.h`, `drm/drm_file.h`.
- Detected declarations: `struct drm_mode_rmfb_work`, `function Copyright`, `function drm_mode_addfb`, `function drm_mode_addfb_ioctl`, `function framebuffer_check`, `function drm_internal_framebuffer_create`, `function drm_mode_addfb2`, `function drm_mode_addfb2_ioctl`, `function drm_mode_rmfb_work_fn`, `function drm_mode_closefb`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration 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.