drivers/hwspinlock/sun6i_hwspinlock.c
Source file repositories/reference/linux-study-clean/drivers/hwspinlock/sun6i_hwspinlock.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwspinlock/sun6i_hwspinlock.c- Extension
.c- Size
- 5740 bytes
- Lines
- 211
- Domain
- Driver Families
- Bucket
- drivers/hwspinlock
- 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.
- 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/debugfs.hlinux/errno.hlinux/hwspinlock.hlinux/io.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/reset.hlinux/slab.hlinux/spinlock.hlinux/types.hhwspinlock_internal.h
Detected Declarations
struct sun6i_hwspinlock_datafunction hwlocks_supported_showfunction sun6i_hwspinlock_debugfs_initfunction sun6i_hwspinlock_debugfs_initfunction sun6i_hwspinlock_unlockfunction sun6i_hwspinlock_disablefunction sun6i_hwspinlock_probe
Annotated Snippet
struct sun6i_hwspinlock_data {
struct hwspinlock_device *bank;
struct reset_control *reset;
struct clk *ahb_clk;
struct dentry *debugfs;
int nlocks;
};
#ifdef CONFIG_DEBUG_FS
static int hwlocks_supported_show(struct seq_file *seqf, void *unused)
{
struct sun6i_hwspinlock_data *priv = seqf->private;
seq_printf(seqf, "%d\n", priv->nlocks);
return 0;
}
DEFINE_SHOW_ATTRIBUTE(hwlocks_supported);
static void sun6i_hwspinlock_debugfs_init(struct sun6i_hwspinlock_data *priv)
{
priv->debugfs = debugfs_create_dir(DRIVER_NAME, NULL);
debugfs_create_file("supported", 0444, priv->debugfs, priv, &hwlocks_supported_fops);
}
#else
static void sun6i_hwspinlock_debugfs_init(struct sun6i_hwspinlock_data *priv)
{
}
#endif
static int sun6i_hwspinlock_trylock(struct hwspinlock *lock)
{
void __iomem *lock_addr = lock->priv;
return (readl(lock_addr) == SPINLOCK_NOTTAKEN);
}
static void sun6i_hwspinlock_unlock(struct hwspinlock *lock)
{
void __iomem *lock_addr = lock->priv;
writel(SPINLOCK_NOTTAKEN, lock_addr);
}
static const struct hwspinlock_ops sun6i_hwspinlock_ops = {
.trylock = sun6i_hwspinlock_trylock,
.unlock = sun6i_hwspinlock_unlock,
};
static void sun6i_hwspinlock_disable(void *data)
{
struct sun6i_hwspinlock_data *priv = data;
debugfs_remove_recursive(priv->debugfs);
clk_disable_unprepare(priv->ahb_clk);
reset_control_assert(priv->reset);
}
static int sun6i_hwspinlock_probe(struct platform_device *pdev)
{
struct sun6i_hwspinlock_data *priv;
struct hwspinlock *hwlock;
void __iomem *io_base;
u32 num_banks;
int err, i;
io_base = devm_platform_ioremap_resource(pdev, SPINLOCK_BASE_ID);
if (IS_ERR(io_base))
return PTR_ERR(io_base);
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->ahb_clk = devm_clk_get(&pdev->dev, "ahb");
if (IS_ERR(priv->ahb_clk)) {
err = PTR_ERR(priv->ahb_clk);
dev_err(&pdev->dev, "unable to get AHB clock (%d)\n", err);
return err;
}
priv->reset = devm_reset_control_get(&pdev->dev, "ahb");
if (IS_ERR(priv->reset))
return dev_err_probe(&pdev->dev, PTR_ERR(priv->reset),
"unable to get reset control\n");
Annotation
- Immediate include surface: `linux/clk.h`, `linux/debugfs.h`, `linux/errno.h`, `linux/hwspinlock.h`, `linux/io.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct sun6i_hwspinlock_data`, `function hwlocks_supported_show`, `function sun6i_hwspinlock_debugfs_init`, `function sun6i_hwspinlock_debugfs_init`, `function sun6i_hwspinlock_unlock`, `function sun6i_hwspinlock_disable`, `function sun6i_hwspinlock_probe`.
- Atlas domain: Driver Families / drivers/hwspinlock.
- Implementation status: source 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.