2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2004-2012 Cavium Networks
10 #include <linux/module.h>
11 #include <linux/interrupt.h>
13 #include "octeon-crypto.h"
16 * Enable access to Octeon's COP2 crypto hardware for kernel use. Wrap any
17 * crypto operations in calls to octeon_crypto_enable/disable in order to make
18 * sure the state of COP2 isn't corrupted if userspace is also performing
19 * hardware crypto operations. Allocate the state parameter on the stack.
20 * Preemption must be disabled to prevent context switches.
22 * @state: Pointer to state structure to store current COP2 state in.
24 * Returns: Flags to be passed to octeon_crypto_disable()
26 unsigned long octeon_crypto_enable(struct octeon_cop2_state *state)
31 local_irq_save(flags);
32 status = read_c0_status();
33 write_c0_status(status | ST0_CU2);
34 if (KSTK_STATUS(current) & ST0_CU2) {
35 octeon_cop2_save(&(current->thread.cp2));
36 KSTK_STATUS(current) &= ~ST0_CU2;
38 } else if (status & ST0_CU2) {
39 octeon_cop2_save(state);
41 local_irq_restore(flags);
42 return status & ST0_CU2;
44 EXPORT_SYMBOL_GPL(octeon_crypto_enable);
47 * Disable access to Octeon's COP2 crypto hardware in the kernel. This must be
48 * called after an octeon_crypto_enable() before any context switch or return to
51 * @state: Pointer to COP2 state to restore
52 * @flags: Return value from octeon_crypto_enable()
54 void octeon_crypto_disable(struct octeon_cop2_state *state,
55 unsigned long crypto_flags)
59 local_irq_save(flags);
60 if (crypto_flags & ST0_CU2)
61 octeon_cop2_restore(state);
63 write_c0_status(read_c0_status() & ~ST0_CU2);
64 local_irq_restore(flags);
66 EXPORT_SYMBOL_GPL(octeon_crypto_disable);