summaryrefslogtreecommitdiffstats
path: root/include/linux/hw_random.h
blob: ff6d3bb58285480e14b4c386670adbaba6608492 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * 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>
#include <driver.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 *dev;
	void *buf;
	unsigned long priv;
};

/* Register a new Hardware Random Number Generator driver. */
int hwrng_register(struct device *dev, struct hwrng *rng);

#ifdef CONFIG_HWRNG
struct hwrng *hwrng_get_first(void);
int hwrng_get_data(struct hwrng *rng, void *buffer, size_t size, int wait);
#else
static inline struct hwrng *hwrng_get_first(void) { return ERR_PTR(-ENODEV); };
static inline int hwrng_get_data(struct hwrng *rng, void *buffer, size_t size, int wait)
{
	return -ENODEV;
}
#endif

void hwrng_unregister(struct hwrng *rng);

static inline long hwrng_yield(struct hwrng *rng)
{
	return 0;
}

#endif /* LINUX_HWRANDOM_H_ */