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 * Returns with preemption disabled.
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
)
32 local_irq_save(flags
);
33 status
= read_c0_status();
34 write_c0_status(status
| ST0_CU2
);
35 if (KSTK_STATUS(current
) & ST0_CU2
) {
36 octeon_cop2_save(&(current
->thread
.cp2
));
37 KSTK_STATUS(current
) &= ~ST0_CU2
;
39 } else if (status
& ST0_CU2
) {
40 octeon_cop2_save(state
);
42 local_irq_restore(flags
);
43 return status
& ST0_CU2
;
45 EXPORT_SYMBOL_GPL(octeon_crypto_enable
);
48 * Disable access to Octeon's COP2 crypto hardware in the kernel. This must be
49 * called after an octeon_crypto_enable() before any context switch or return to
52 * @state: Pointer to COP2 state to restore
53 * @flags: Return value from octeon_crypto_enable()
55 void octeon_crypto_disable(struct octeon_cop2_state
*state
,
56 unsigned long crypto_flags
)
60 local_irq_save(flags
);
61 if (crypto_flags
& ST0_CU2
)
62 octeon_cop2_restore(state
);
64 write_c0_status(read_c0_status() & ~ST0_CU2
);
65 local_irq_restore(flags
);
68 EXPORT_SYMBOL_GPL(octeon_crypto_disable
);