drivers/char/hw_random/octeon-rng.c
Source file repositories/reference/linux-study-clean/drivers/char/hw_random/octeon-rng.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/hw_random/octeon-rng.c- Extension
.c- Size
- 2744 bytes
- Lines
- 119
- 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.
- 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/module.hlinux/platform_device.hlinux/device.hlinux/hw_random.hlinux/io.hlinux/gfp.hasm/octeon/octeon.hasm/octeon/cvmx-rnm-defs.h
Detected Declarations
struct octeon_rngfunction octeon_rng_initfunction octeon_rng_cleanupfunction octeon_rng_data_readfunction octeon_rng_probe
Annotated Snippet
struct octeon_rng {
struct hwrng ops;
void __iomem *control_status;
void __iomem *result;
};
static int octeon_rng_init(struct hwrng *rng)
{
union cvmx_rnm_ctl_status ctl;
struct octeon_rng *p = container_of(rng, struct octeon_rng, ops);
ctl.u64 = 0;
ctl.s.ent_en = 1; /* Enable the entropy source. */
ctl.s.rng_en = 1; /* Enable the RNG hardware. */
cvmx_write_csr((unsigned long)p->control_status, ctl.u64);
return 0;
}
static void octeon_rng_cleanup(struct hwrng *rng)
{
union cvmx_rnm_ctl_status ctl;
struct octeon_rng *p = container_of(rng, struct octeon_rng, ops);
ctl.u64 = 0;
/* Disable everything. */
cvmx_write_csr((unsigned long)p->control_status, ctl.u64);
}
static int octeon_rng_data_read(struct hwrng *rng, u32 *data)
{
struct octeon_rng *p = container_of(rng, struct octeon_rng, ops);
*data = cvmx_read64_uint32((unsigned long)p->result);
return sizeof(u32);
}
static int octeon_rng_probe(struct platform_device *pdev)
{
struct resource *res_ports;
struct resource *res_result;
struct octeon_rng *rng;
int ret;
struct hwrng ops = {
.name = "octeon",
.init = octeon_rng_init,
.cleanup = octeon_rng_cleanup,
.data_read = octeon_rng_data_read
};
rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
if (!rng)
return -ENOMEM;
res_ports = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res_ports)
return -ENOENT;
res_result = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (!res_result)
return -ENOENT;
rng->control_status = devm_ioremap(&pdev->dev,
res_ports->start,
sizeof(u64));
if (!rng->control_status)
return -ENOENT;
rng->result = devm_ioremap(&pdev->dev,
res_result->start,
sizeof(u64));
if (!rng->result)
return -ENOENT;
rng->ops = ops;
platform_set_drvdata(pdev, &rng->ops);
ret = devm_hwrng_register(&pdev->dev, &rng->ops);
if (ret)
return -ENOENT;
dev_info(&pdev->dev, "Octeon Random Number Generator\n");
return 0;
}
static struct platform_driver octeon_rng_driver = {
.driver = {
.name = "octeon_rng",
},
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_device.h`, `linux/device.h`, `linux/hw_random.h`, `linux/io.h`, `linux/gfp.h`, `asm/octeon/octeon.h`, `asm/octeon/cvmx-rnm-defs.h`.
- Detected declarations: `struct octeon_rng`, `function octeon_rng_init`, `function octeon_rng_cleanup`, `function octeon_rng_data_read`, `function octeon_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.