drivers/char/hw_random/cctrng.c
Source file repositories/reference/linux-study-clean/drivers/char/hw_random/cctrng.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/hw_random/cctrng.c- Extension
.c- Size
- 17967 bytes
- Lines
- 664
- 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.
- 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.
- 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/kernel.hlinux/module.hlinux/clk.hlinux/hw_random.hlinux/io.hlinux/platform_device.hlinux/pm_runtime.hlinux/interrupt.hlinux/irqreturn.hlinux/workqueue.hlinux/circ_buf.hlinux/completion.hlinux/of.hlinux/bitfield.hlinux/fips.hcctrng.h
Detected Declarations
struct cctrng_drvdatafunction cc_iowritefunction cc_ioreadfunction cc_trng_pm_getfunction cc_trng_pm_put_suspendfunction cc_trng_pm_initfunction cc_trng_pm_gofunction cc_trng_pm_finifunction cc_trng_parse_sampling_ratiofunction cc_trng_change_roscfunction cc_trng_enable_rnd_sourcefunction circ_idx_incfunction circ_buf_spacefunction cctrng_readfunction cc_trng_hw_triggerfunction cc_trng_compwork_handlerfunction cc_isrfunction cc_trng_startwork_handlerfunction cctrng_probefunction cctrng_removefunction cctrng_suspendfunction cctrng_wait_for_reset_completionfunction cctrng_resume
Annotated Snippet
struct cctrng_drvdata {
struct platform_device *pdev;
void __iomem *cc_base;
struct clk *clk;
struct hwrng rng;
u32 active_rosc;
/* Sampling interval for each ring oscillator:
* count of ring oscillator cycles between consecutive bits sampling.
* Value of 0 indicates non-valid rosc
*/
u32 smpl_ratio[CC_TRNG_NUM_OF_ROSCS];
u32 data_buf[CCTRNG_DATA_BUF_WORDS];
struct circ_buf circ;
struct work_struct compwork;
struct work_struct startwork;
/* pending_hw - 1 when HW is pending, 0 when it is idle */
atomic_t pending_hw;
/* protects against multiple concurrent consumers of data_buf */
spinlock_t read_lock;
};
/* functions for write/read CC registers */
static inline void cc_iowrite(struct cctrng_drvdata *drvdata, u32 reg, u32 val)
{
iowrite32(val, (drvdata->cc_base + reg));
}
static inline u32 cc_ioread(struct cctrng_drvdata *drvdata, u32 reg)
{
return ioread32(drvdata->cc_base + reg);
}
static int cc_trng_pm_get(struct device *dev)
{
int rc = 0;
rc = pm_runtime_get_sync(dev);
/* pm_runtime_get_sync() can return 1 as a valid return code */
return (rc == 1 ? 0 : rc);
}
static void cc_trng_pm_put_suspend(struct device *dev)
{
int rc = 0;
rc = pm_runtime_put_autosuspend(dev);
if (rc)
dev_err(dev, "pm_runtime_put_autosuspend returned %x\n", rc);
}
static int cc_trng_pm_init(struct cctrng_drvdata *drvdata)
{
struct device *dev = &(drvdata->pdev->dev);
/* must be before the enabling to avoid redundant suspending */
pm_runtime_set_autosuspend_delay(dev, CC_TRNG_SUSPEND_TIMEOUT);
pm_runtime_use_autosuspend(dev);
/* set us as active - note we won't do PM ops until cc_trng_pm_go()! */
return pm_runtime_set_active(dev);
}
static void cc_trng_pm_go(struct cctrng_drvdata *drvdata)
{
struct device *dev = &(drvdata->pdev->dev);
/* enable the PM module*/
pm_runtime_enable(dev);
}
static void cc_trng_pm_fini(struct cctrng_drvdata *drvdata)
{
struct device *dev = &(drvdata->pdev->dev);
pm_runtime_disable(dev);
}
static inline int cc_trng_parse_sampling_ratio(struct cctrng_drvdata *drvdata)
{
struct device *dev = &(drvdata->pdev->dev);
struct device_node *np = drvdata->pdev->dev.of_node;
int rc;
int i;
/* ret will be set to 0 if at least one rosc has (sampling ratio > 0) */
int ret = -EINVAL;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/clk.h`, `linux/hw_random.h`, `linux/io.h`, `linux/platform_device.h`, `linux/pm_runtime.h`, `linux/interrupt.h`.
- Detected declarations: `struct cctrng_drvdata`, `function cc_iowrite`, `function cc_ioread`, `function cc_trng_pm_get`, `function cc_trng_pm_put_suspend`, `function cc_trng_pm_init`, `function cc_trng_pm_go`, `function cc_trng_pm_fini`, `function cc_trng_parse_sampling_ratio`, `function cc_trng_change_rosc`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: source 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.