Skip to content

Commit

Permalink
powerpc/microwatt: wire up rng during setup_arch()
Browse files Browse the repository at this point in the history
The platform's RNG must be available before random_init() in order to be
useful for initial seeding, which in turn means that it needs to be
called from setup_arch(), rather than from an init call. Fortunately,
each platform already has a setup_arch function pointer, which means
it's easy to wire this up. This commit also removes some noisy log
messages that don't add much.

Fixes: c25769f ("powerpc/microwatt: Add support for hardware random number generator")
Cc: stable@vger.kernel.org # v5.14+
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220611151015.548325-2-Jason@zx2c4.com
  • Loading branch information
Jason A. Donenfeld authored and Michael Ellerman committed Jun 18, 2022
1 parent 6cf06c1 commit 20a9689
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions arch/powerpc/platforms/microwatt/microwatt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _MICROWATT_H
#define _MICROWATT_H

void microwatt_rng_init(void);

#endif /* _MICROWATT_H */
10 changes: 3 additions & 7 deletions arch/powerpc/platforms/microwatt/rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <asm/archrandom.h>
#include <asm/cputable.h>
#include <asm/machdep.h>
#include "microwatt.h"

#define DARN_ERR 0xFFFFFFFFFFFFFFFFul

Expand All @@ -29,20 +30,15 @@ static int microwatt_get_random_darn(unsigned long *v)
return 1;
}

static __init int rng_init(void)
void __init microwatt_rng_init(void)
{
unsigned long val;
int i;

for (i = 0; i < 10; i++) {
if (microwatt_get_random_darn(&val)) {
ppc_md.get_random_seed = microwatt_get_random_darn;
return 0;
return;
}
}

pr_warn("Unable to use DARN for get_random_seed()\n");

return -EIO;
}
machine_subsys_initcall(, rng_init);
8 changes: 8 additions & 0 deletions arch/powerpc/platforms/microwatt/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <asm/xics.h>
#include <asm/udbg.h>

#include "microwatt.h"

static void __init microwatt_init_IRQ(void)
{
xics_init();
Expand All @@ -32,10 +34,16 @@ static int __init microwatt_populate(void)
}
machine_arch_initcall(microwatt, microwatt_populate);

static void __init microwatt_setup_arch(void)
{
microwatt_rng_init();
}

define_machine(microwatt) {
.name = "microwatt",
.probe = microwatt_probe,
.init_IRQ = microwatt_init_IRQ,
.setup_arch = microwatt_setup_arch,
.progress = udbg_progress,
.calibrate_decr = generic_calibrate_decr,
};

0 comments on commit 20a9689

Please sign in to comment.