drivers/base/regmap/regcache-flat.c
Source file repositories/reference/linux-study-clean/drivers/base/regmap/regcache-flat.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/regmap/regcache-flat.c- Extension
.c- Size
- 4167 bytes
- Lines
- 178
- Domain
- Driver Families
- Bucket
- drivers/base
- 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.
- 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/bitmap.hlinux/bitops.hlinux/device.hlinux/limits.hlinux/overflow.hlinux/seq_file.hlinux/slab.hinternal.h
Detected Declarations
struct regcache_flat_datafunction regcache_flat_get_indexfunction regcache_flat_initfunction regcache_flat_exitfunction regcache_flat_populatefunction regcache_flat_readfunction regcache_flat_sparse_readfunction regcache_flat_writefunction regcache_flat_drop
Annotated Snippet
struct regcache_flat_data {
unsigned long *valid;
unsigned int data[];
};
static int regcache_flat_init(struct regmap *map)
{
unsigned int cache_size;
struct regcache_flat_data *cache;
if (!map || map->reg_stride_order < 0 || !map->max_register_is_set)
return -EINVAL;
cache_size = regcache_flat_get_index(map, map->max_register) + 1;
cache = kzalloc_flex(*cache, data, cache_size, map->alloc_flags);
if (!cache)
return -ENOMEM;
cache->valid = bitmap_zalloc(cache_size, map->alloc_flags);
if (!cache->valid)
goto err_free;
map->cache = cache;
return 0;
err_free:
kfree(cache);
return -ENOMEM;
}
static int regcache_flat_exit(struct regmap *map)
{
struct regcache_flat_data *cache = map->cache;
if (cache)
bitmap_free(cache->valid);
kfree(cache);
map->cache = NULL;
return 0;
}
static int regcache_flat_populate(struct regmap *map)
{
struct regcache_flat_data *cache = map->cache;
unsigned int i;
for (i = 0; i < map->num_reg_defaults; i++) {
unsigned int reg = map->reg_defaults[i].reg;
unsigned int index = regcache_flat_get_index(map, reg);
cache->data[index] = map->reg_defaults[i].def;
__set_bit(index, cache->valid);
}
if (map->reg_default_cb) {
dev_dbg(map->dev,
"Populating regcache_flat using reg_default_cb callback\n");
for (i = 0; i <= map->max_register; i += map->reg_stride) {
unsigned int index = regcache_flat_get_index(map, i);
unsigned int value;
if (test_bit(index, cache->valid))
continue;
if (map->reg_default_cb(map->dev, i, &value))
continue;
cache->data[index] = value;
__set_bit(index, cache->valid);
}
}
return 0;
}
static int regcache_flat_read(struct regmap *map,
unsigned int reg, unsigned int *value)
{
struct regcache_flat_data *cache = map->cache;
unsigned int index = regcache_flat_get_index(map, reg);
/* legacy behavior: ignore validity, but warn the user */
if (unlikely(!test_bit(index, cache->valid)))
dev_warn_once(map->dev,
"using zero-initialized flat cache, this may cause unexpected behavior");
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/bitops.h`, `linux/device.h`, `linux/limits.h`, `linux/overflow.h`, `linux/seq_file.h`, `linux/slab.h`, `internal.h`.
- Detected declarations: `struct regcache_flat_data`, `function regcache_flat_get_index`, `function regcache_flat_init`, `function regcache_flat_exit`, `function regcache_flat_populate`, `function regcache_flat_read`, `function regcache_flat_sparse_read`, `function regcache_flat_write`, `function regcache_flat_drop`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: source implementation candidate.
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.