diff options
author | Steffen Trumtrar <s.trumtrar@pengutronix.de> | 2017-03-22 10:14:33 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-03-30 08:23:20 +0200 |
commit | 8eac8a6c657274e4741518ba37ecde324ffe4186 (patch) | |
tree | 62e1c88f5e3aa96840171ca5bf6d08ebfdf90c44 /include | |
parent | 441e9f5a72b245b671118f3e771eb129834a7a34 (diff) | |
download | barebox-8eac8a6c657274e4741518ba37ecde324ffe4186.tar.gz barebox-8eac8a6c657274e4741518ba37ecde324ffe4186.tar.xz |
drivers: add simple hw_random implementation
Add a simple hw_random implementation based on code from
Linux v4.5-rc5.
All the entropypool initialization stuff is left out and
the obsolete data_read/data_present calls are omitted.
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/hw_random.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h new file mode 100644 index 0000000000..bae442166c --- /dev/null +++ b/include/linux/hw_random.h @@ -0,0 +1,47 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef LINUX_HWRANDOM_H_ +#define LINUX_HWRANDOM_H_ + +#include <linux/list.h> + +/** + * struct hwrng - Hardware Random Number Generator driver + * @name: Unique RNG name. + * @init: Initialization callback (can be NULL). + * @read: New API. drivers can fill up to max bytes of data + * into the buffer. The buffer is aligned for any type. + */ +struct hwrng { + const char *name; + int (*init)(struct hwrng *rng); + int (*read)(struct hwrng *rng, void *data, size_t max, bool wait); + + struct list_head list; + + struct cdev cdev; + struct device_d *dev; + void *buf; +}; + +/* Register a new Hardware Random Number Generator driver. */ +int hwrng_register(struct device_d *dev, struct hwrng *rng); +int hwrng_get_data(struct hwrng *rng, void *buffer, size_t size, int wait); + +#ifdef CONFIG_HWRNG +struct hwrng *hwrng_get_first(void); +#else +static inline struct hwrng *hwrng_get_first(void) { return ERR_PTR(-ENODEV); }; +#endif + +#endif /* LINUX_HWRANDOM_H_ */ |