mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-21 14:37:50 +00:00
lx_emul: implement __get_random_u32_below
The implementation was already part of the Zynq's sd_card driver and since other ARM drivers need it as well, promote it to the common shadow library. Issue genodelabs/genode-allwinner#21.
This commit is contained in:
parent
7109b80bbd
commit
c888fcbdd9
@ -39,18 +39,6 @@ int wait_for_random_bytes(void)
|
||||
|
||||
#include <linux/prandom.h>
|
||||
|
||||
u32 prandom_u32(void)
|
||||
{
|
||||
return lx_emul_random_gen_u32();
|
||||
}
|
||||
|
||||
|
||||
u32 __get_random_u32_below(u32 ceil)
|
||||
{
|
||||
return lx_emul_random_gen_u32();
|
||||
}
|
||||
|
||||
|
||||
u8 get_random_u8(void)
|
||||
{
|
||||
u8 ret;
|
||||
|
@ -60,3 +60,30 @@ bool rng_is_initialized(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
u32 __get_random_u32_below(u32 ceil)
|
||||
{
|
||||
/**
|
||||
* Returns a random number from the half-open interval [0, ceil)
|
||||
* with uniform distribution.
|
||||
*
|
||||
* The idea here is to split [0, 2^32) into #ceil bins. By dividing a random
|
||||
* number from the 32-bit interval, we can determine into which bin the number
|
||||
* fell.
|
||||
*/
|
||||
|
||||
/* determine divisor to determine bin number by dividing 2^32 by ceil */
|
||||
u32 div = 0x100000000ULL / ceil;
|
||||
|
||||
/**
|
||||
* In case the above division has a remainder, we will end up with an
|
||||
* additional (but smaller) bin at the end of the 32-bit interval. We'll
|
||||
* discard the result if the number fell into this bin and repeat.
|
||||
*/
|
||||
u32 result = ceil;
|
||||
while (result >= ceil)
|
||||
result = lx_emul_random_gen_u32() / div;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -22,14 +22,6 @@ void register_syscore_ops(struct syscore_ops * ops)
|
||||
}
|
||||
|
||||
|
||||
#include <linux/random.h>
|
||||
|
||||
u32 __get_random_u32_below(u32 ceil)
|
||||
{
|
||||
lx_emul_trace_and_stop(__func__);
|
||||
}
|
||||
|
||||
|
||||
#include <linux/interrupt.h>
|
||||
|
||||
DEFINE_STATIC_KEY_FALSE(force_irqthreads_key);
|
||||
|
@ -422,14 +422,6 @@ void pci_disable_msi(struct pci_dev *dev)
|
||||
}
|
||||
|
||||
|
||||
#include <linux/random.h>
|
||||
|
||||
u32 __get_random_u32_below(u32 ceil)
|
||||
{
|
||||
lx_emul_trace_and_stop(__func__);
|
||||
}
|
||||
|
||||
|
||||
#include <asm/smp.h>
|
||||
|
||||
DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
|
||||
|
@ -85,14 +85,6 @@ int __printk_ratelimit(const char * func)
|
||||
}
|
||||
|
||||
|
||||
#include <linux/prandom.h>
|
||||
|
||||
u32 prandom_u32(void)
|
||||
{
|
||||
lx_emul_trace_and_stop(__func__);
|
||||
}
|
||||
|
||||
|
||||
#include <linux/pci.h>
|
||||
|
||||
void pci_disable_device(struct pci_dev * dev)
|
||||
@ -101,14 +93,6 @@ void pci_disable_device(struct pci_dev * dev)
|
||||
}
|
||||
|
||||
|
||||
#include <linux/random.h>
|
||||
|
||||
u32 __get_random_u32_below(u32 ceil)
|
||||
{
|
||||
lx_emul_trace_and_stop(__func__);
|
||||
}
|
||||
|
||||
|
||||
#include <asm/smp.h>
|
||||
|
||||
DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
|
||||
|
@ -386,14 +386,6 @@ void ieee80211_free_led_names(struct ieee80211_local * local)
|
||||
pteval_t __default_kernel_pte_mask __read_mostly = ~0;
|
||||
|
||||
|
||||
#include <linux/random.h>
|
||||
|
||||
u32 __get_random_u32_below(u32 ceil)
|
||||
{
|
||||
lx_emul_trace_and_stop(__func__);
|
||||
}
|
||||
|
||||
|
||||
u16 get_random_u16(void)
|
||||
{
|
||||
lx_emul_trace_and_stop(__func__);
|
||||
|
Loading…
Reference in New Issue
Block a user