1*02b35babSEric Biggers /* SPDX-License-Identifier: GPL-2.0-only */ 2*02b35babSEric Biggers /* 3*02b35babSEric Biggers * SHA-512 accelerated using the sparc64 sha512 opcodes 4*02b35babSEric Biggers * 5*02b35babSEric Biggers * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com> 6*02b35babSEric Biggers * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> 7*02b35babSEric Biggers * Copyright (c) 2003 Kyle McMartin <kyle@debian.org> 8*02b35babSEric Biggers */ 9*02b35babSEric Biggers 10*02b35babSEric Biggers #include <asm/elf.h> 11*02b35babSEric Biggers #include <asm/opcodes.h> 12*02b35babSEric Biggers #include <asm/pstate.h> 13*02b35babSEric Biggers 14*02b35babSEric Biggers static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_sha512_opcodes); 15*02b35babSEric Biggers 16*02b35babSEric Biggers asmlinkage void sha512_sparc64_transform(struct sha512_block_state *state, 17*02b35babSEric Biggers const u8 *data, size_t nblocks); 18*02b35babSEric Biggers 19*02b35babSEric Biggers static void sha512_blocks(struct sha512_block_state *state, 20*02b35babSEric Biggers const u8 *data, size_t nblocks) 21*02b35babSEric Biggers { 22*02b35babSEric Biggers if (static_branch_likely(&have_sha512_opcodes)) 23*02b35babSEric Biggers sha512_sparc64_transform(state, data, nblocks); 24*02b35babSEric Biggers else 25*02b35babSEric Biggers sha512_blocks_generic(state, data, nblocks); 26*02b35babSEric Biggers } 27*02b35babSEric Biggers 28*02b35babSEric Biggers #define sha512_mod_init_arch sha512_mod_init_arch 29*02b35babSEric Biggers static inline void sha512_mod_init_arch(void) 30*02b35babSEric Biggers { 31*02b35babSEric Biggers unsigned long cfr; 32*02b35babSEric Biggers 33*02b35babSEric Biggers if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO)) 34*02b35babSEric Biggers return; 35*02b35babSEric Biggers 36*02b35babSEric Biggers __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr)); 37*02b35babSEric Biggers if (!(cfr & CFR_SHA512)) 38*02b35babSEric Biggers return; 39*02b35babSEric Biggers 40*02b35babSEric Biggers static_branch_enable(&have_sha512_opcodes); 41*02b35babSEric Biggers pr_info("Using sparc64 sha512 opcode optimized SHA-512/SHA-384 implementation\n"); 42*02b35babSEric Biggers } 43