Path: blob/master/arch/powerpc/platforms/microwatt/rng.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Derived from arch/powerpc/platforms/powernv/rng.c, which is:3* Copyright 2013, Michael Ellerman, IBM Corporation.4*/56#define pr_fmt(fmt) "microwatt-rng: " fmt78#include <linux/kernel.h>9#include <linux/smp.h>10#include <asm/archrandom.h>11#include <asm/cputable.h>12#include <asm/machdep.h>13#include "microwatt.h"1415#define DARN_ERR 0xFFFFFFFFFFFFFFFFul1617static int microwatt_get_random_darn(unsigned long *v)18{19unsigned long val;2021/* Using DARN with L=1 - 64-bit conditioned random number */22asm volatile(PPC_DARN(%0, 1) : "=r"(val));2324if (val == DARN_ERR)25return 0;2627*v = val;2829return 1;30}3132void __init microwatt_rng_init(void)33{34unsigned long val;35int i;3637for (i = 0; i < 10; i++) {38if (microwatt_get_random_darn(&val)) {39ppc_md.get_random_seed = microwatt_get_random_darn;40return;41}42}43}444546