drivers/char/hw_random/powernv-rng.c
Source file repositories/reference/linux-study-clean/drivers/char/hw_random/powernv-rng.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/hw_random/powernv-rng.c- Extension
.c- Size
- 1558 bytes
- Lines
- 72
- Domain
- Driver Families
- Bucket
- drivers/char
- 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/module.hlinux/mod_devicetable.hlinux/kernel.hlinux/platform_device.hlinux/random.hlinux/hw_random.hasm/archrandom.h
Detected Declarations
function powernv_rng_readfunction powernv_rng_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright 2013 Michael Ellerman, Guo Chao, IBM Corp.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/random.h>
#include <linux/hw_random.h>
#include <asm/archrandom.h>
static int powernv_rng_read(struct hwrng *rng, void *data, size_t max, bool wait)
{
unsigned long *buf;
int i, len;
/* We rely on rng_buffer_size() being >= sizeof(unsigned long) */
len = max / sizeof(unsigned long);
buf = (unsigned long *)data;
for (i = 0; i < len; i++)
pnv_get_random_long(buf++);
return len * sizeof(unsigned long);
}
static struct hwrng powernv_hwrng = {
.name = "powernv-rng",
.read = powernv_rng_read,
};
static int powernv_rng_probe(struct platform_device *pdev)
{
int rc;
rc = devm_hwrng_register(&pdev->dev, &powernv_hwrng);
if (rc) {
/* We only register one device, ignore any others */
if (rc == -EEXIST)
rc = -ENODEV;
return rc;
}
pr_info("Registered powernv hwrng.\n");
return 0;
}
static const struct of_device_id powernv_rng_match[] = {
{ .compatible = "ibm,power-rng",},
{},
};
MODULE_DEVICE_TABLE(of, powernv_rng_match);
static struct platform_driver powernv_rng_driver = {
.driver = {
.name = "powernv_rng",
.of_match_table = powernv_rng_match,
},
.probe = powernv_rng_probe,
};
module_platform_driver(powernv_rng_driver);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Bare metal HWRNG driver for POWER7+ and above");
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/kernel.h`, `linux/platform_device.h`, `linux/random.h`, `linux/hw_random.h`, `asm/archrandom.h`.
- Detected declarations: `function powernv_rng_read`, `function powernv_rng_probe`.
- Atlas domain: Driver Families / drivers/char.
- 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.