drivers/misc/sram.c
Source file repositories/reference/linux-study-clean/drivers/misc/sram.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/sram.c- Extension
.c- Size
- 11806 bytes
- Lines
- 465
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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/clk.hlinux/delay.hlinux/genalloc.hlinux/io.hlinux/list_sort.hlinux/of.hlinux/of_address.hlinux/platform_device.hlinux/regmap.hlinux/slab.hlinux/mfd/syscon.hsoc/at91/atmel-secumod.hsram.h
Detected Declarations
function Copyrightfunction sram_writefunction sram_add_poolfunction sram_add_exportfunction sram_add_partitionfunction sram_free_partitionsfunction sram_reserve_cmpfunction sram_reserve_regionsfunction atmel_securam_waitfunction sram_probefunction sram_removefunction sram_init
Annotated Snippet
if (IS_ERR(virt_base)) {
dev_err(sram->dev, "could not map SRAM at %pr\n", &block->res);
return PTR_ERR(virt_base);
}
part->base = virt_base;
} else {
part->base = sram->virt_base + block->start;
}
if (block->pool) {
ret = sram_add_pool(sram, block, start, part);
if (ret)
return ret;
}
if (block->export) {
ret = sram_add_export(sram, block, start, part);
if (ret)
return ret;
}
if (block->protect_exec) {
ret = sram_check_protect_exec(sram, block, part);
if (ret)
return ret;
ret = sram_add_pool(sram, block, start, part);
if (ret)
return ret;
sram_add_protect_exec(part);
}
sram->partitions++;
return 0;
}
static void sram_free_partitions(struct sram_dev *sram)
{
struct sram_partition *part;
if (!sram->partitions)
return;
part = &sram->partition[sram->partitions - 1];
for (; sram->partitions; sram->partitions--, part--) {
if (part->battr.size)
device_remove_bin_file(sram->dev, &part->battr);
if (part->pool &&
gen_pool_avail(part->pool) < gen_pool_size(part->pool))
dev_err(sram->dev, "removed pool while SRAM allocated\n");
}
}
static int sram_reserve_cmp(void *priv, const struct list_head *a,
const struct list_head *b)
{
const struct sram_reserve *ra = list_entry(a, struct sram_reserve, list);
const struct sram_reserve *rb = list_entry(b, struct sram_reserve, list);
return ra->start - rb->start;
}
static int sram_reserve_regions(struct sram_dev *sram, struct resource *res)
{
struct device_node *np = sram->dev->of_node, *child;
unsigned long size, cur_start, cur_size;
struct sram_reserve *rblocks, *block;
struct list_head reserve_list;
unsigned int nblocks, exports = 0;
const char *label;
int ret = 0;
INIT_LIST_HEAD(&reserve_list);
size = resource_size(res);
/*
* We need an additional block to mark the end of the memory region
* after the reserved blocks from the dt are processed.
*/
nblocks = (np) ? of_get_available_child_count(np) + 1 : 1;
rblocks = kzalloc_objs(*rblocks, nblocks);
if (!rblocks)
return -ENOMEM;
block = &rblocks[0];
for_each_available_child_of_node(np, child) {
struct resource child_res;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/genalloc.h`, `linux/io.h`, `linux/list_sort.h`, `linux/of.h`, `linux/of_address.h`, `linux/platform_device.h`.
- Detected declarations: `function Copyright`, `function sram_write`, `function sram_add_pool`, `function sram_add_export`, `function sram_add_partition`, `function sram_free_partitions`, `function sram_reserve_cmp`, `function sram_reserve_regions`, `function atmel_securam_wait`, `function sram_probe`.
- Atlas domain: Driver Families / drivers/misc.
- 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.