Path: blob/master/arch/mips/cavium-octeon/crypto/octeon-crypto.c
26535 views
/*1* This file is subject to the terms and conditions of the GNU General Public2* License. See the file "COPYING" in the main directory of this archive3* for more details.4*5* Copyright (C) 2004-2012 Cavium Networks6*/78#include <asm/cop2.h>9#include <asm/octeon/crypto.h>10#include <linux/export.h>11#include <linux/interrupt.h>12#include <linux/sched/task_stack.h>1314/**15* Enable access to Octeon's COP2 crypto hardware for kernel use. Wrap any16* crypto operations in calls to octeon_crypto_enable/disable in order to make17* sure the state of COP2 isn't corrupted if userspace is also performing18* hardware crypto operations. Allocate the state parameter on the stack.19* Returns with preemption disabled.20*21* @state: Pointer to state structure to store current COP2 state in.22*23* Returns: Flags to be passed to octeon_crypto_disable()24*/25unsigned long octeon_crypto_enable(struct octeon_cop2_state *state)26{27int status;28unsigned long flags;2930preempt_disable();31local_irq_save(flags);32status = read_c0_status();33write_c0_status(status | ST0_CU2);34if (KSTK_STATUS(current) & ST0_CU2) {35octeon_cop2_save(&(current->thread.cp2));36KSTK_STATUS(current) &= ~ST0_CU2;37status &= ~ST0_CU2;38} else if (status & ST0_CU2) {39octeon_cop2_save(state);40}41local_irq_restore(flags);42return status & ST0_CU2;43}44EXPORT_SYMBOL_GPL(octeon_crypto_enable);4546/**47* Disable access to Octeon's COP2 crypto hardware in the kernel. This must be48* called after an octeon_crypto_enable() before any context switch or return to49* userspace.50*51* @state: Pointer to COP2 state to restore52* @flags: Return value from octeon_crypto_enable()53*/54void octeon_crypto_disable(struct octeon_cop2_state *state,55unsigned long crypto_flags)56{57unsigned long flags;5859local_irq_save(flags);60if (crypto_flags & ST0_CU2)61octeon_cop2_restore(state);62else63write_c0_status(read_c0_status() & ~ST0_CU2);64local_irq_restore(flags);65preempt_enable();66}67EXPORT_SYMBOL_GPL(octeon_crypto_disable);686970