drivers/cache/sifive_ccache.c
Source file repositories/reference/linux-study-clean/drivers/cache/sifive_ccache.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cache/sifive_ccache.c- Extension
.c- Size
- 9647 bytes
- Lines
- 355
- Domain
- Driver Families
- Bucket
- drivers/cache
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/align.hlinux/debugfs.hlinux/interrupt.hlinux/of_irq.hlinux/of_address.hlinux/device.hlinux/bitfield.hlinux/platform_device.hlinux/property.hasm/cacheflush.hasm/cacheinfo.hasm/dma-noncoherent.hsoc/sifive/sifive_ccache.h
Detected Declarations
function ccache_writefunction setup_sifive_debugfunction ccache_config_readfunction register_sifive_ccache_error_notifierfunction unregister_sifive_ccache_error_notifierfunction ccache_flush_rangefunction ccache_largest_wayenabledfunction number_of_ways_enabled_showfunction ccache_int_handlerfunction sifive_ccache_probefunction sifive_ccache_initexport register_sifive_ccache_error_notifierexport unregister_sifive_ccache_error_notifier
Annotated Snippet
static const struct file_operations ccache_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.write = ccache_write
};
static void setup_sifive_debug(void)
{
sifive_test = debugfs_create_dir("sifive_ccache_cache", NULL);
debugfs_create_file("sifive_debug_inject_error", 0200,
sifive_test, NULL, &ccache_fops);
}
#endif
static void ccache_config_read(void)
{
u32 cfg;
cfg = readl(ccache_base + SIFIVE_CCACHE_CONFIG);
pr_info("%llu banks, %llu ways, sets/bank=%llu, bytes/block=%llu\n",
FIELD_GET(SIFIVE_CCACHE_CONFIG_BANK_MASK, cfg),
FIELD_GET(SIFIVE_CCACHE_CONFIG_WAYS_MASK, cfg),
BIT_ULL(FIELD_GET(SIFIVE_CCACHE_CONFIG_SETS_MASK, cfg)),
BIT_ULL(FIELD_GET(SIFIVE_CCACHE_CONFIG_BLKS_MASK, cfg)));
cfg = readl(ccache_base + SIFIVE_CCACHE_WAYENABLE);
pr_info("Index of the largest way enabled: %u\n", cfg);
}
static const struct of_device_id sifive_ccache_ids[] = {
{ .compatible = "eswin,eic7700-l3-cache",
.data = (void *)(QUIRK_NONSTANDARD_CACHE_OPS) },
{ .compatible = "sifive,fu540-c000-ccache" },
{ .compatible = "sifive,fu740-c000-ccache" },
{ .compatible = "starfive,jh7100-ccache",
.data = (void *)(QUIRK_NONSTANDARD_CACHE_OPS | QUIRK_BROKEN_DATA_UNCORR) },
{ .compatible = "starfive,jh7110-ccache",
.data = (void *)(QUIRK_NONSTANDARD_CACHE_OPS) },
{ .compatible = "sifive,ccache0" },
{ /* end of table */ }
};
static ATOMIC_NOTIFIER_HEAD(ccache_err_chain);
int register_sifive_ccache_error_notifier(struct notifier_block *nb)
{
return atomic_notifier_chain_register(&ccache_err_chain, nb);
}
EXPORT_SYMBOL_GPL(register_sifive_ccache_error_notifier);
int unregister_sifive_ccache_error_notifier(struct notifier_block *nb)
{
return atomic_notifier_chain_unregister(&ccache_err_chain, nb);
}
EXPORT_SYMBOL_GPL(unregister_sifive_ccache_error_notifier);
#ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS
static void ccache_flush_range(phys_addr_t start, size_t len)
{
phys_addr_t end = start + len;
phys_addr_t line;
if (!len)
return;
mb(); /* complete earlier memory accesses before the cache flush */
for (line = ALIGN_DOWN(start, SIFIVE_CCACHE_LINE_SIZE); line < end;
line += SIFIVE_CCACHE_LINE_SIZE) {
#ifdef CONFIG_32BIT
writel_relaxed(line >> 4, ccache_base + SIFIVE_CCACHE_FLUSH32);
#else
writeq_relaxed(line, ccache_base + SIFIVE_CCACHE_FLUSH64);
#endif
}
mb(); /* issue later memory accesses after the cache flush */
}
static const struct riscv_nonstd_cache_ops ccache_mgmt_ops __initconst = {
.wback = &ccache_flush_range,
.inv = &ccache_flush_range,
.wback_inv = &ccache_flush_range,
};
#endif /* CONFIG_RISCV_NONSTANDARD_CACHE_OPS */
static int ccache_largest_wayenabled(void)
{
return readl(ccache_base + SIFIVE_CCACHE_WAYENABLE) & 0xFF;
}
Annotation
- Immediate include surface: `linux/align.h`, `linux/debugfs.h`, `linux/interrupt.h`, `linux/of_irq.h`, `linux/of_address.h`, `linux/device.h`, `linux/bitfield.h`, `linux/platform_device.h`.
- Detected declarations: `function ccache_write`, `function setup_sifive_debug`, `function ccache_config_read`, `function register_sifive_ccache_error_notifier`, `function unregister_sifive_ccache_error_notifier`, `function ccache_flush_range`, `function ccache_largest_wayenabled`, `function number_of_ways_enabled_show`, `function ccache_int_handler`, `function sifive_ccache_probe`.
- Atlas domain: Driver Families / drivers/cache.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.