drivers/cache/starfive_starlink_cache.c
Source file repositories/reference/linux-study-clean/drivers/cache/starfive_starlink_cache.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cache/starfive_starlink_cache.c- Extension
.c- Size
- 4040 bytes
- Lines
- 131
- Domain
- Driver Families
- Bucket
- drivers/cache
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/cacheflush.hlinux/iopoll.hlinux/of_address.hasm/dma-noncoherent.h
Detected Declarations
function starlink_cache_flush_completefunction starlink_cache_dma_cache_wbackfunction starlink_cache_dma_cache_invalidatefunction starlink_cache_dma_cache_wback_invfunction starlink_cache_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Cache Management Operations for StarFive's Starlink cache controller
*
* Copyright (C) 2024 Shanghai StarFive Technology Co., Ltd.
*
* Author: Joshua Yeong <joshua.yeong@starfivetech.com>
*/
#include <linux/bitfield.h>
#include <linux/cacheflush.h>
#include <linux/iopoll.h>
#include <linux/of_address.h>
#include <asm/dma-noncoherent.h>
#define STARLINK_CACHE_FLUSH_START_ADDR 0x0
#define STARLINK_CACHE_FLUSH_END_ADDR 0x8
#define STARLINK_CACHE_FLUSH_CTL 0x10
#define STARLINK_CACHE_ALIGN 0x40
#define STARLINK_CACHE_ADDRESS_RANGE_MASK GENMASK(39, 0)
#define STARLINK_CACHE_FLUSH_CTL_MODE_MASK GENMASK(2, 1)
#define STARLINK_CACHE_FLUSH_CTL_ENABLE_MASK BIT(0)
#define STARLINK_CACHE_FLUSH_CTL_CLEAN_INVALIDATE 0
#define STARLINK_CACHE_FLUSH_CTL_MAKE_INVALIDATE 1
#define STARLINK_CACHE_FLUSH_CTL_CLEAN_SHARED 2
#define STARLINK_CACHE_FLUSH_POLL_DELAY_US 1
#define STARLINK_CACHE_FLUSH_TIMEOUT_US 5000000
static void __iomem *starlink_cache_base;
static void starlink_cache_flush_complete(void)
{
volatile void __iomem *ctl = starlink_cache_base + STARLINK_CACHE_FLUSH_CTL;
u64 v;
int ret;
ret = readq_poll_timeout_atomic(ctl, v, !(v & STARLINK_CACHE_FLUSH_CTL_ENABLE_MASK),
STARLINK_CACHE_FLUSH_POLL_DELAY_US,
STARLINK_CACHE_FLUSH_TIMEOUT_US);
if (ret)
WARN(1, "StarFive Starlink cache flush operation timeout\n");
}
static void starlink_cache_dma_cache_wback(phys_addr_t paddr, unsigned long size)
{
writeq(FIELD_PREP(STARLINK_CACHE_ADDRESS_RANGE_MASK, paddr),
starlink_cache_base + STARLINK_CACHE_FLUSH_START_ADDR);
writeq(FIELD_PREP(STARLINK_CACHE_ADDRESS_RANGE_MASK, paddr + size),
starlink_cache_base + STARLINK_CACHE_FLUSH_END_ADDR);
mb();
writeq(FIELD_PREP(STARLINK_CACHE_FLUSH_CTL_MODE_MASK,
STARLINK_CACHE_FLUSH_CTL_CLEAN_SHARED),
starlink_cache_base + STARLINK_CACHE_FLUSH_CTL);
starlink_cache_flush_complete();
}
static void starlink_cache_dma_cache_invalidate(phys_addr_t paddr, unsigned long size)
{
writeq(FIELD_PREP(STARLINK_CACHE_ADDRESS_RANGE_MASK, paddr),
starlink_cache_base + STARLINK_CACHE_FLUSH_START_ADDR);
writeq(FIELD_PREP(STARLINK_CACHE_ADDRESS_RANGE_MASK, paddr + size),
starlink_cache_base + STARLINK_CACHE_FLUSH_END_ADDR);
mb();
writeq(FIELD_PREP(STARLINK_CACHE_FLUSH_CTL_MODE_MASK,
STARLINK_CACHE_FLUSH_CTL_MAKE_INVALIDATE),
starlink_cache_base + STARLINK_CACHE_FLUSH_CTL);
starlink_cache_flush_complete();
}
static void starlink_cache_dma_cache_wback_inv(phys_addr_t paddr, unsigned long size)
{
writeq(FIELD_PREP(STARLINK_CACHE_ADDRESS_RANGE_MASK, paddr),
starlink_cache_base + STARLINK_CACHE_FLUSH_START_ADDR);
writeq(FIELD_PREP(STARLINK_CACHE_ADDRESS_RANGE_MASK, paddr + size),
starlink_cache_base + STARLINK_CACHE_FLUSH_END_ADDR);
mb();
writeq(FIELD_PREP(STARLINK_CACHE_FLUSH_CTL_MODE_MASK,
STARLINK_CACHE_FLUSH_CTL_CLEAN_INVALIDATE),
starlink_cache_base + STARLINK_CACHE_FLUSH_CTL);
starlink_cache_flush_complete();
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/cacheflush.h`, `linux/iopoll.h`, `linux/of_address.h`, `asm/dma-noncoherent.h`.
- Detected declarations: `function starlink_cache_flush_complete`, `function starlink_cache_dma_cache_wback`, `function starlink_cache_dma_cache_invalidate`, `function starlink_cache_dma_cache_wback_inv`, `function starlink_cache_init`.
- Atlas domain: Driver Families / drivers/cache.
- 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.