| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/* |
| 3 |
* SHA-256 accelerated using the sparc64 sha256 opcodes |
| 4 |
* |
| 5 |
* Copyright (c) Jean-Luc Cooke <[email protected]> |
| 6 |
* Copyright (c) Andrew McDonald <[email protected]> |
| 7 |
* Copyright (c) 2002 James Morris <[email protected]> |
| 8 |
* SHA224 Support Copyright 2007 Intel Corporation <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <asm/elf.h> |
| 12 |
#include <asm/opcodes.h> |
| 13 |
#include <asm/pstate.h> |
| 14 |
|
| 15 |
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_sha256_opcodes); |
| 16 |
|
| 17 |
asmlinkage void sha256_sparc64_transform(struct sha256_block_state *state, |
| 18 |
const u8 *data, size_t nblocks); |
| 19 |
|
| 20 |
static void sha256_blocks(struct sha256_block_state *state, |
| 21 |
const u8 *data, size_t nblocks) |
| 22 |
{ |
| 23 |
if (static_branch_likely(&have_sha256_opcodes)) |
| 24 |
sha256_sparc64_transform(state, data, nblocks); |
| 25 |
else |
| 26 |
sha256_blocks_generic(state, data, nblocks); |
| 27 |
} |
| 28 |
|
| 29 |
#define sha256_mod_init_arch sha256_mod_init_arch |
| 30 |
static void sha256_mod_init_arch(void) |
| 31 |
{ |
| 32 |
unsigned long cfr; |
| 33 |
|
| 34 |
if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO)) |
| 35 |
return; |
| 36 |
|
| 37 |
__asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr)); |
| 38 |
if (!(cfr & CFR_SHA256)) |
| 39 |
return; |
| 40 |
|
| 41 |
static_branch_enable(&have_sha256_opcodes); |
| 42 |
pr_info("Using sparc64 sha256 opcode optimized SHA-256/SHA-224 implementation\n"); |
| 43 |
} |