Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Derived from arch/powerpc/platforms/powernv/rng.c, which is:
0004  * Copyright 2013, Michael Ellerman, IBM Corporation.
0005  */
0006 
0007 #define pr_fmt(fmt) "microwatt-rng: " fmt
0008 
0009 #include <linux/kernel.h>
0010 #include <linux/smp.h>
0011 #include <asm/archrandom.h>
0012 #include <asm/cputable.h>
0013 #include <asm/machdep.h>
0014 #include "microwatt.h"
0015 
0016 #define DARN_ERR 0xFFFFFFFFFFFFFFFFul
0017 
0018 static int microwatt_get_random_darn(unsigned long *v)
0019 {
0020     unsigned long val;
0021 
0022     /* Using DARN with L=1 - 64-bit conditioned random number */
0023     asm volatile(PPC_DARN(%0, 1) : "=r"(val));
0024 
0025     if (val == DARN_ERR)
0026         return 0;
0027 
0028     *v = val;
0029 
0030     return 1;
0031 }
0032 
0033 void __init microwatt_rng_init(void)
0034 {
0035     unsigned long val;
0036     int i;
0037 
0038     for (i = 0; i < 10; i++) {
0039         if (microwatt_get_random_darn(&val)) {
0040             ppc_md.get_random_seed = microwatt_get_random_darn;
0041             return;
0042         }
0043     }
0044 }