drivers/base/regmap/regmap-ram.c
Source file repositories/reference/linux-study-clean/drivers/base/regmap/regmap-ram.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/regmap/regmap-ram.c- Extension
.c- Size
- 1949 bytes
- Lines
- 92
- Domain
- Driver Families
- Bucket
- drivers/base
- 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.
- 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/clk.hlinux/err.hlinux/io.hlinux/module.hlinux/regmap.hlinux/slab.hlinux/swab.hinternal.h
Detected Declarations
function regmap_ram_writefunction regmap_ram_readfunction regmap_ram_free_contextexport __regmap_init_ram
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
//
// Register map access API - Memory region
//
// This is intended for testing only
//
// Copyright (c) 2023, Arm Ltd
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/swab.h>
#include "internal.h"
static int regmap_ram_write(void *context, unsigned int reg, unsigned int val)
{
struct regmap_ram_data *data = context;
data->vals[reg] = val;
data->written[reg] = true;
return 0;
}
static int regmap_ram_read(void *context, unsigned int reg, unsigned int *val)
{
struct regmap_ram_data *data = context;
*val = data->vals[reg];
data->read[reg] = true;
return 0;
}
static void regmap_ram_free_context(void *context)
{
struct regmap_ram_data *data = context;
kfree(data->vals);
kfree(data->read);
kfree(data->written);
kfree(data);
}
static const struct regmap_bus regmap_ram = {
.fast_io = true,
.reg_write = regmap_ram_write,
.reg_read = regmap_ram_read,
.free_context = regmap_ram_free_context,
};
struct regmap *__regmap_init_ram(struct device *dev,
const struct regmap_config *config,
struct regmap_ram_data *data,
struct lock_class_key *lock_key,
const char *lock_name)
{
struct regmap *map;
if (!config->max_register) {
pr_crit("No max_register specified for RAM regmap\n");
return ERR_PTR(-EINVAL);
}
data->read = kzalloc_objs(bool, config->max_register + 1);
if (!data->read)
return ERR_PTR(-ENOMEM);
data->written = kzalloc_objs(bool, config->max_register + 1);
if (!data->written) {
kfree(data->read);
return ERR_PTR(-ENOMEM);
}
map = __regmap_init(dev, ®map_ram, data, config,
lock_key, lock_name);
if (IS_ERR(map)) {
kfree(data->read);
kfree(data->written);
}
return map;
}
EXPORT_SYMBOL_GPL(__regmap_init_ram);
MODULE_DESCRIPTION("Register map access API - Memory region");
Annotation
- Immediate include surface: `linux/clk.h`, `linux/err.h`, `linux/io.h`, `linux/module.h`, `linux/regmap.h`, `linux/slab.h`, `linux/swab.h`, `internal.h`.
- Detected declarations: `function regmap_ram_write`, `function regmap_ram_read`, `function regmap_ram_free_context`, `export __regmap_init_ram`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: integration 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.