18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Kernel interface for the s390 arch_random_* functions 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright IBM Corp. 2017, 2022 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Author: Harald Freudenberger <freude@de.ibm.com> 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef _ASM_S390_ARCHRANDOM_H 128c2ecf20Sopenharmony_ci#define _ASM_S390_ARCHRANDOM_H 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_RANDOM 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/static_key.h> 178c2ecf20Sopenharmony_ci#include <linux/preempt.h> 188c2ecf20Sopenharmony_ci#include <linux/atomic.h> 198c2ecf20Sopenharmony_ci#include <asm/cpacf.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciDECLARE_STATIC_KEY_FALSE(s390_arch_random_available); 228c2ecf20Sopenharmony_ciextern atomic64_t s390_arch_random_counter; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic inline bool __must_check arch_get_random_long(unsigned long *v) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci return false; 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic inline bool __must_check arch_get_random_int(unsigned int *v) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci return false; 328c2ecf20Sopenharmony_ci} 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic inline bool __must_check arch_get_random_seed_long(unsigned long *v) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci if (static_branch_likely(&s390_arch_random_available) && 378c2ecf20Sopenharmony_ci in_task()) { 388c2ecf20Sopenharmony_ci cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v)); 398c2ecf20Sopenharmony_ci atomic64_add(sizeof(*v), &s390_arch_random_counter); 408c2ecf20Sopenharmony_ci return true; 418c2ecf20Sopenharmony_ci } 428c2ecf20Sopenharmony_ci return false; 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic inline bool __must_check arch_get_random_seed_int(unsigned int *v) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci if (static_branch_likely(&s390_arch_random_available) && 488c2ecf20Sopenharmony_ci in_task()) { 498c2ecf20Sopenharmony_ci cpacf_trng(NULL, 0, (u8 *)v, sizeof(*v)); 508c2ecf20Sopenharmony_ci atomic64_add(sizeof(*v), &s390_arch_random_counter); 518c2ecf20Sopenharmony_ci return true; 528c2ecf20Sopenharmony_ci } 538c2ecf20Sopenharmony_ci return false; 548c2ecf20Sopenharmony_ci} 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#endif /* CONFIG_ARCH_RANDOM */ 578c2ecf20Sopenharmony_ci#endif /* _ASM_S390_ARCHRANDOM_H */ 58