diff options
Diffstat (limited to 'drivers/char/hw_random/via-rng.c')
-rw-r--r-- | drivers/char/hw_random/via-rng.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c index ec435cb25c4f..868e39fd42e4 100644 --- a/drivers/char/hw_random/via-rng.c +++ b/drivers/char/hw_random/via-rng.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
29 | #include <linux/hw_random.h> | 29 | #include <linux/hw_random.h> |
30 | #include <linux/delay.h> | ||
30 | #include <asm/io.h> | 31 | #include <asm/io.h> |
31 | #include <asm/msr.h> | 32 | #include <asm/msr.h> |
32 | #include <asm/cpufeature.h> | 33 | #include <asm/cpufeature.h> |
@@ -77,10 +78,11 @@ static inline u32 xstore(u32 *addr, u32 edx_in) | |||
77 | return eax_out; | 78 | return eax_out; |
78 | } | 79 | } |
79 | 80 | ||
80 | static int via_rng_data_present(struct hwrng *rng) | 81 | static int via_rng_data_present(struct hwrng *rng, int wait) |
81 | { | 82 | { |
82 | u32 bytes_out; | 83 | u32 bytes_out; |
83 | u32 *via_rng_datum = (u32 *)(&rng->priv); | 84 | u32 *via_rng_datum = (u32 *)(&rng->priv); |
85 | int i; | ||
84 | 86 | ||
85 | /* We choose the recommended 1-byte-per-instruction RNG rate, | 87 | /* We choose the recommended 1-byte-per-instruction RNG rate, |
86 | * for greater randomness at the expense of speed. Larger | 88 | * for greater randomness at the expense of speed. Larger |
@@ -95,12 +97,15 @@ static int via_rng_data_present(struct hwrng *rng) | |||
95 | * completes. | 97 | * completes. |
96 | */ | 98 | */ |
97 | 99 | ||
98 | *via_rng_datum = 0; /* paranoia, not really necessary */ | 100 | for (i = 0; i < 20; i++) { |
99 | bytes_out = xstore(via_rng_datum, VIA_RNG_CHUNK_1); | 101 | *via_rng_datum = 0; /* paranoia, not really necessary */ |
100 | bytes_out &= VIA_XSTORE_CNT_MASK; | 102 | bytes_out = xstore(via_rng_datum, VIA_RNG_CHUNK_1); |
101 | if (bytes_out == 0) | 103 | bytes_out &= VIA_XSTORE_CNT_MASK; |
102 | return 0; | 104 | if (bytes_out || !wait) |
103 | return 1; | 105 | break; |
106 | udelay(10); | ||
107 | } | ||
108 | return bytes_out ? 1 : 0; | ||
104 | } | 109 | } |
105 | 110 | ||
106 | static int via_rng_data_read(struct hwrng *rng, u32 *data) | 111 | static int via_rng_data_read(struct hwrng *rng, u32 *data) |