drivers/base/regmap/regmap-debugfs.c
Source file repositories/reference/linux-study-clean/drivers/base/regmap/regmap-debugfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/regmap/regmap-debugfs.c- Extension
.c- Size
- 17524 bytes
- Lines
- 705
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/slab.hlinux/mutex.hlinux/debugfs.hlinux/uaccess.hlinux/device.hlinux/list.hlinux/idr.hinternal.h
Detected Declarations
struct regmap_debugfs_nodefunction regmap_calc_reg_lenfunction regmap_name_read_filefunction regmap_debugfs_free_dump_cachefunction regmap_printablefunction regmap_debugfs_get_dump_startfunction regmap_calc_tot_lenfunction regmap_next_readable_regfunction list_for_each_entryfunction regmap_read_debugfsfunction regmap_map_read_filefunction regmap_map_write_filefunction regmap_range_read_filefunction regmap_reg_ranges_read_filefunction regmap_access_showfunction regmap_cache_only_write_filefunction regmap_cache_bypass_write_filefunction regmap_debugfs_initfunction regmap_debugfs_exitfunction list_for_each_entry_safefunction regmap_debugfs_initcall
Annotated Snippet
static const struct file_operations regmap_name_fops = {
.open = simple_open,
.read = regmap_name_read_file,
.llseek = default_llseek,
};
static void regmap_debugfs_free_dump_cache(struct regmap *map)
{
struct regmap_debugfs_off_cache *c;
while (!list_empty(&map->debugfs_off_cache)) {
c = list_first_entry(&map->debugfs_off_cache,
struct regmap_debugfs_off_cache,
list);
list_del(&c->list);
kfree(c);
}
}
static bool regmap_printable(struct regmap *map, unsigned int reg)
{
if (regmap_precious(map, reg))
return false;
if (!regmap_readable(map, reg) && !regmap_cached(map, reg))
return false;
return true;
}
/*
* Work out where the start offset maps into register numbers, bearing
* in mind that we suppress hidden registers.
*/
static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,
unsigned int base,
loff_t from,
loff_t *pos)
{
struct regmap_debugfs_off_cache *c = NULL;
loff_t p = 0;
unsigned int i, ret;
unsigned int fpos_offset;
unsigned int reg_offset;
/* Suppress the cache if we're using a subrange */
if (base)
return base;
/*
* If we don't have a cache build one so we don't have to do a
* linear scan each time.
*/
mutex_lock(&map->cache_lock);
i = base;
if (list_empty(&map->debugfs_off_cache)) {
for (; i <= map->max_register; i += map->reg_stride) {
/* Skip unprinted registers, closing off cache entry */
if (!regmap_printable(map, i)) {
if (c) {
c->max = p - 1;
c->max_reg = i - map->reg_stride;
list_add_tail(&c->list,
&map->debugfs_off_cache);
c = NULL;
}
continue;
}
/* No cache entry? Start a new one */
if (!c) {
c = kzalloc_obj(*c);
if (!c) {
regmap_debugfs_free_dump_cache(map);
mutex_unlock(&map->cache_lock);
return base;
}
c->min = p;
c->base_reg = i;
}
p += map->debugfs_tot_len;
}
}
/* Close the last entry off if we didn't scan beyond it */
if (c) {
c->max = p - 1;
c->max_reg = i - map->reg_stride;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/mutex.h`, `linux/debugfs.h`, `linux/uaccess.h`, `linux/device.h`, `linux/list.h`, `linux/idr.h`, `internal.h`.
- Detected declarations: `struct regmap_debugfs_node`, `function regmap_calc_reg_len`, `function regmap_name_read_file`, `function regmap_debugfs_free_dump_cache`, `function regmap_printable`, `function regmap_debugfs_get_dump_start`, `function regmap_calc_tot_len`, `function regmap_next_readable_reg`, `function list_for_each_entry`, `function regmap_read_debugfs`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: pattern 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.