drivers/base/regmap/regcache-rbtree.c
Source file repositories/reference/linux-study-clean/drivers/base/regmap/regcache-rbtree.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/regmap/regcache-rbtree.c- Extension
.c- Size
- 13943 bytes
- Lines
- 560
- 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/debugfs.hlinux/device.hlinux/rbtree.hlinux/seq_file.hlinux/slab.hinternal.h
Detected Declarations
struct regcache_rbtree_nodestruct regcache_rbtree_ctxfunction regcache_rbtree_get_base_top_regfunction regcache_rbtree_get_registerfunction regcache_rbtree_set_registerfunction regcache_rbtree_insertfunction rbtree_showfunction rbtree_debugfs_initfunction regcache_rbtree_initfunction regcache_rbtree_exitfunction regcache_rbtree_populatefunction regcache_rbtree_readfunction regcache_rbtree_insert_to_blockfunction regcache_rbtree_node_allocfunction regcache_rbtree_writefunction regcache_rbtree_syncfunction regcache_rbtree_drop
Annotated Snippet
struct regcache_rbtree_node {
/* block of adjacent registers */
void *block;
/* Which registers are present */
unsigned long *cache_present;
/* base register handled by this block */
unsigned int base_reg;
/* number of registers available in the block */
unsigned int blklen;
/* the actual rbtree node holding this block */
struct rb_node node;
};
struct regcache_rbtree_ctx {
struct rb_root root;
struct regcache_rbtree_node *cached_rbnode;
};
static inline void regcache_rbtree_get_base_top_reg(
struct regmap *map,
struct regcache_rbtree_node *rbnode,
unsigned int *base, unsigned int *top)
{
*base = rbnode->base_reg;
*top = rbnode->base_reg + ((rbnode->blklen - 1) * map->reg_stride);
}
static unsigned int regcache_rbtree_get_register(struct regmap *map,
struct regcache_rbtree_node *rbnode, unsigned int idx)
{
return regcache_get_val(map, rbnode->block, idx);
}
static void regcache_rbtree_set_register(struct regmap *map,
struct regcache_rbtree_node *rbnode,
unsigned int idx, unsigned int val)
{
set_bit(idx, rbnode->cache_present);
regcache_set_val(map, rbnode->block, idx, val);
}
static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,
unsigned int reg)
{
struct regcache_rbtree_ctx *rbtree_ctx = map->cache;
struct rb_node *node;
struct regcache_rbtree_node *rbnode;
unsigned int base_reg, top_reg;
rbnode = rbtree_ctx->cached_rbnode;
if (rbnode) {
regcache_rbtree_get_base_top_reg(map, rbnode, &base_reg,
&top_reg);
if (reg >= base_reg && reg <= top_reg)
return rbnode;
}
node = rbtree_ctx->root.rb_node;
while (node) {
rbnode = rb_entry(node, struct regcache_rbtree_node, node);
regcache_rbtree_get_base_top_reg(map, rbnode, &base_reg,
&top_reg);
if (reg >= base_reg && reg <= top_reg) {
rbtree_ctx->cached_rbnode = rbnode;
return rbnode;
} else if (reg > top_reg) {
node = node->rb_right;
} else if (reg < base_reg) {
node = node->rb_left;
}
}
return NULL;
}
static int regcache_rbtree_insert(struct regmap *map, struct rb_root *root,
struct regcache_rbtree_node *rbnode)
{
struct rb_node **new, *parent;
struct regcache_rbtree_node *rbnode_tmp;
unsigned int base_reg_tmp, top_reg_tmp;
unsigned int base_reg;
parent = NULL;
new = &root->rb_node;
while (*new) {
rbnode_tmp = rb_entry(*new, struct regcache_rbtree_node, node);
/* base and top registers of the current rbnode */
regcache_rbtree_get_base_top_reg(map, rbnode_tmp, &base_reg_tmp,
&top_reg_tmp);
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/device.h`, `linux/rbtree.h`, `linux/seq_file.h`, `linux/slab.h`, `internal.h`.
- Detected declarations: `struct regcache_rbtree_node`, `struct regcache_rbtree_ctx`, `function regcache_rbtree_get_base_top_reg`, `function regcache_rbtree_get_register`, `function regcache_rbtree_set_register`, `function regcache_rbtree_insert`, `function rbtree_show`, `function rbtree_debugfs_init`, `function regcache_rbtree_init`, `function regcache_rbtree_exit`.
- 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.