1 /* 2 * SPDX-License-Identifier: BSD-3-Clause 3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. 4 */ 5 6 #ifndef ENTROPY_H 7 #define ENTROPY_H 8 9 #include <arch.h> 10 #include <utils_def.h> 11 12 /* 13 * Write 8 bytes of random data in random. Returns true on success, false on 14 * failure. 15 */ arch_collect_entropy(uint64_t * random)16static inline bool arch_collect_entropy(uint64_t *random) 17 { 18 unsigned long rc; 19 uint64_t val; 20 21 asm volatile( 22 " mrs %[val], " __XSTRING(RNDR) "\n" 23 " str %[val], %[random_ptr]\n" 24 " cset %[rc], ne\n" /* RNDR sets NZCV to 0b0100 on failure */ 25 : [random_ptr] "=m" (*random), 26 [rc] "=r" (rc), 27 [val] "=r" (val) 28 : 29 : "cc" 30 ); 31 return (rc == 1); 32 } 33 34 #endif /* ENTROPY_H */ 35