random: use lockless techniques in the interrupt path
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / random.h
CommitLineData
1da177e4
LT
1/*
2 * include/linux/random.h
3 *
4 * Include file for the random number generator.
5 */
6
7#ifndef _LINUX_RANDOM_H
8#define _LINUX_RANDOM_H
9
68622c61 10#include <linux/types.h>
1da177e4 11#include <linux/ioctl.h>
0ebb26e7 12#include <linux/irqnr.h>
1da177e4
LT
13
14/* ioctl()'s for the random number generator */
15
16/* Get the entropy count. */
17#define RNDGETENTCNT _IOR( 'R', 0x00, int )
18
19/* Add to (or subtract from) the entropy count. (Superuser only.) */
20#define RNDADDTOENTCNT _IOW( 'R', 0x01, int )
21
22/* Get the contents of the entropy pool. (Superuser only.) */
23#define RNDGETPOOL _IOR( 'R', 0x02, int [2] )
24
25/*
26 * Write bytes into the entropy pool and add to the entropy count.
27 * (Superuser only.)
28 */
29#define RNDADDENTROPY _IOW( 'R', 0x03, int [2] )
30
31/* Clear entropy count to 0. (Superuser only.) */
32#define RNDZAPENTCNT _IO( 'R', 0x04 )
33
34/* Clear the entropy pool and associated counters. (Superuser only.) */
35#define RNDCLEARPOOL _IO( 'R', 0x06 )
36
37struct rand_pool_info {
38 int entropy_count;
39 int buf_size;
40 __u32 buf[0];
41};
42
5960164f
JE
43struct rnd_state {
44 __u32 s1, s2, s3;
45};
46
1da177e4
LT
47/* Exported functions */
48
49#ifdef __KERNEL__
50
51extern void rand_initialize_irq(int irq);
52
53extern void add_input_randomness(unsigned int type, unsigned int code,
54 unsigned int value);
775f4b29 55extern void add_interrupt_randomness(int irq, int irq_flags);
1da177e4
LT
56
57extern void get_random_bytes(void *buf, int nbytes);
58void generate_random_uuid(unsigned char uuid_out[16]);
59
1da177e4 60#ifndef MODULE
54047320 61extern const struct file_operations random_fops, urandom_fops;
1da177e4
LT
62#endif
63
64unsigned int get_random_int(void);
65unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
66
aaa248f6
SH
67u32 random32(void);
68void srandom32(u32 seed);
69
5960164f
JE
70u32 prandom32(struct rnd_state *);
71
72/*
73 * Handle minimum values for seeds
74 */
75static inline u32 __seed(u32 x, u32 m)
76{
77 return (x < m) ? x + m : x;
78}
79
80/**
81 * prandom32_seed - set seed for prandom32().
82 * @state: pointer to state structure to receive the seed.
83 * @seed: arbitrary 64-bit value to use as a seed.
84 */
85static inline void prandom32_seed(struct rnd_state *state, u64 seed)
86{
87 u32 i = (seed >> 32) ^ (seed << 10) ^ seed;
88
89 state->s1 = __seed(i, 1);
90 state->s2 = __seed(i, 7);
91 state->s3 = __seed(i, 15);
92}
93
63d77173
PA
94#ifdef CONFIG_ARCH_RANDOM
95# include <asm/archrandom.h>
96#else
97static inline int arch_get_random_long(unsigned long *v)
98{
99 return 0;
100}
101static inline int arch_get_random_int(unsigned int *v)
102{
103 return 0;
104}
105#endif
106
1da177e4
LT
107#endif /* __KERNEL___ */
108
109#endif /* _LINUX_RANDOM_H */