drivers/gpu/drm/drm_pagemap_util.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_pagemap_util.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_pagemap_util.c- Extension
.c- Size
- 16832 bytes
- Lines
- 565
- 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/slab.hdrm/drm_drv.hdrm/drm_managed.hdrm/drm_pagemap.hdrm/drm_pagemap_util.hdrm/drm_print.h
Detected Declarations
struct drm_pagemap_cachestruct drm_pagemap_shrinkerstruct drm_pagemap_ownerfunction drm_pagemap_cache_finifunction drm_pagemap_cache_create_devmfunction drm_pagemap_cache_lock_lookupfunction drm_pagemap_cache_unlock_lookupfunction drm_pagemap_get_from_cachefunction drm_pagemap_cache_set_pagemapfunction drm_pagemap_shrinker_cancelfunction drm_pagemap_shrinker_might_lockfunction drm_pagemap_shrinker_addfunction drm_pagemap_shrinker_countfunction drm_pagemap_shrinker_scanfunction drm_pagemap_shrinker_finifunction drm_pagemap_shrinker_create_devmfunction drm_pagemap_owner_releasefunction drm_pagemap_release_ownerfunction drm_pagemap_acquire_ownerexport drm_pagemap_cache_create_devmexport drm_pagemap_cache_lock_lookupexport drm_pagemap_cache_unlock_lookupexport drm_pagemap_get_from_cacheexport drm_pagemap_cache_set_pagemapexport drm_pagemap_get_from_cache_if_activeexport drm_pagemap_shrinker_create_devmexport drm_pagemap_release_ownerexport drm_pagemap_acquire_owner
Annotated Snippet
struct drm_pagemap_cache {
/** @lookup_mutex: Mutex making the lookup process atomic */
struct mutex lookup_mutex;
/** @lock: Lock protecting the @dpagemap pointer */
spinlock_t lock;
/** @shrinker: Pointer to the shrinker used for this cache. Immutable. */
struct drm_pagemap_shrinker *shrinker;
/** @dpagemap: Non-refcounted pointer to the drm_pagemap */
struct drm_pagemap *dpagemap;
/**
* @queued: Signals when an inactive drm_pagemap has been put on
* @shrinker's list.
*/
struct completion queued;
};
/**
* struct drm_pagemap_shrinker - Shrinker to remove unused pagemaps
*/
struct drm_pagemap_shrinker {
/** @drm: Pointer to the drm device. */
struct drm_device *drm;
/** @lock: Spinlock to protect the @dpagemaps list. */
spinlock_t lock;
/** @dpagemaps: List of unused dpagemaps. */
struct list_head dpagemaps;
/** @num_dpagemaps: Number of unused dpagemaps in @dpagemaps. */
atomic_t num_dpagemaps;
/** @shrink: Pointer to the struct shrinker. */
struct shrinker *shrink;
};
static bool drm_pagemap_shrinker_cancel(struct drm_pagemap *dpagemap);
static void drm_pagemap_cache_fini(void *arg)
{
struct drm_pagemap_cache *cache = arg;
struct drm_pagemap *dpagemap;
drm_dbg(cache->shrinker->drm, "Destroying dpagemap cache.\n");
spin_lock(&cache->lock);
dpagemap = cache->dpagemap;
cache->dpagemap = NULL;
if (dpagemap && !drm_pagemap_shrinker_cancel(dpagemap))
dpagemap = NULL;
spin_unlock(&cache->lock);
if (dpagemap)
drm_pagemap_destroy(dpagemap, false);
mutex_destroy(&cache->lookup_mutex);
kfree(cache);
}
/**
* drm_pagemap_cache_create_devm() - Create a drm_pagemap_cache
* @shrinker: Pointer to a struct drm_pagemap_shrinker.
*
* Create a device-managed drm_pagemap cache. The cache is automatically
* destroyed on struct device removal, at which point any *inactive*
* drm_pagemap's are destroyed.
*
* Return: Pointer to a struct drm_pagemap_cache on success. Error pointer
* on failure.
*/
struct drm_pagemap_cache *drm_pagemap_cache_create_devm(struct drm_pagemap_shrinker *shrinker)
{
struct drm_pagemap_cache *cache = kzalloc_obj(*cache);
int err;
if (!cache)
return ERR_PTR(-ENOMEM);
mutex_init(&cache->lookup_mutex);
spin_lock_init(&cache->lock);
cache->shrinker = shrinker;
init_completion(&cache->queued);
err = devm_add_action_or_reset(shrinker->drm->dev, drm_pagemap_cache_fini, cache);
if (err)
return ERR_PTR(err);
return cache;
}
EXPORT_SYMBOL(drm_pagemap_cache_create_devm);
/**
* DOC: Cache lookup
*
* Cache lookup should be done under a locked mutex, so that a
* failed drm_pagemap_get_from_cache() and a following
Annotation
- Immediate include surface: `linux/slab.h`, `drm/drm_drv.h`, `drm/drm_managed.h`, `drm/drm_pagemap.h`, `drm/drm_pagemap_util.h`, `drm/drm_print.h`.
- Detected declarations: `struct drm_pagemap_cache`, `struct drm_pagemap_shrinker`, `struct drm_pagemap_owner`, `function drm_pagemap_cache_fini`, `function drm_pagemap_cache_create_devm`, `function drm_pagemap_cache_lock_lookup`, `function drm_pagemap_cache_unlock_lookup`, `function drm_pagemap_get_from_cache`, `function drm_pagemap_cache_set_pagemap`, `function drm_pagemap_shrinker_cancel`.
- 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.