Merge tag 'perf-tools-fixes-for-v6.9-2024-04-19' of git://git.kernel.org/pub/scm...
[linux-2.6-block.git] / include / linux / hw_random.h
CommitLineData
844dd05f
MB
1/*
2 Hardware Random Number Generator
3
4f4cfa6c 4 Please read Documentation/admin-guide/hw_random.rst for details on use.
844dd05f
MB
5
6 ----------------------------------------------------------
7 This software may be used and distributed according to the terms
8 of the GNU General Public License, incorporated herein by reference.
9
10 */
11
12#ifndef LINUX_HWRANDOM_H_
13#define LINUX_HWRANDOM_H_
844dd05f 14
77584ee5 15#include <linux/completion.h>
844dd05f
MB
16#include <linux/types.h>
17#include <linux/list.h>
3a2c0ba5 18#include <linux/kref.h>
844dd05f
MB
19
20/**
21 * struct hwrng - Hardware Random Number Generator driver
22 * @name: Unique RNG name.
23 * @init: Initialization callback (can be NULL).
24 * @cleanup: Cleanup callback (can be NULL).
25 * @data_present: Callback to determine if data is available
26 * on the RNG. If NULL, it is assumed that
9996508b 27 * there is always data available. *OBSOLETE*
844dd05f
MB
28 * @data_read: Read data from the RNG device.
29 * Returns the number of lower random bytes in "data".
988acec9 30 * Must not be NULL. *OBSOLETE*
9996508b 31 * @read: New API. drivers can fill up to max bytes of data
ed0bd721 32 * into the buffer. The buffer is aligned for any type
ed424bb3 33 * and max is a multiple of 4 and >= 32 bytes.
844dd05f 34 * @priv: Private data, for use by the RNG driver.
0f734e6e 35 * @quality: Estimation of true entropy in RNG's bitstream
fae29f13 36 * (in bits of entropy per 1024 bits of input;
16bdbae3 37 * valid values: 1 to 1024, or 0 for maximum).
844dd05f
MB
38 */
39struct hwrng {
40 const char *name;
41 int (*init)(struct hwrng *rng);
42 void (*cleanup)(struct hwrng *rng);
984e976f 43 int (*data_present)(struct hwrng *rng, int wait);
844dd05f 44 int (*data_read)(struct hwrng *rng, u32 *data);
9996508b 45 int (*read)(struct hwrng *rng, void *data, size_t max, bool wait);
844dd05f 46 unsigned long priv;
0f734e6e 47 unsigned short quality;
844dd05f
MB
48
49 /* internal. */
50 struct list_head list;
3a2c0ba5 51 struct kref ref;
77584ee5 52 struct completion cleanup_done;
36cb6494 53 struct completion dying;
844dd05f
MB
54};
55
4d9b519c
DT
56struct device;
57
844dd05f
MB
58/** Register a new Hardware Random Number Generator driver. */
59extern int hwrng_register(struct hwrng *rng);
4d9b519c 60extern int devm_hwrng_register(struct device *dev, struct hwrng *rng);
844dd05f 61/** Unregister a Hardware Random Number Generator driver. */
b844eba2 62extern void hwrng_unregister(struct hwrng *rng);
4d9b519c 63extern void devm_hwrng_unregister(struct device *dve, struct hwrng *rng);
844dd05f 64
36cb6494 65extern long hwrng_msleep(struct hwrng *rng, unsigned int msecs);
b58a3600 66extern long hwrng_yield(struct hwrng *rng);
36cb6494 67
844dd05f 68#endif /* LINUX_HWRANDOM_H_ */