Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Copyright (C) 2004-2012 Cavium Networks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <asm/cop2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "octeon-crypto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)  * Enable access to Octeon's COP2 crypto hardware for kernel use. Wrap any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)  * crypto operations in calls to octeon_crypto_enable/disable in order to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)  * sure the state of COP2 isn't corrupted if userspace is also performing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)  * hardware crypto operations. Allocate the state parameter on the stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)  * Returns with preemption disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)  * @state: Pointer to state structure to store current COP2 state in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  * Returns: Flags to be passed to octeon_crypto_disable()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) unsigned long octeon_crypto_enable(struct octeon_cop2_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	status = read_c0_status();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	write_c0_status(status | ST0_CU2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	if (KSTK_STATUS(current) & ST0_CU2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		octeon_cop2_save(&(current->thread.cp2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 		KSTK_STATUS(current) &= ~ST0_CU2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		status &= ~ST0_CU2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	} else if (status & ST0_CU2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		octeon_cop2_save(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	return status & ST0_CU2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) EXPORT_SYMBOL_GPL(octeon_crypto_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)  * Disable access to Octeon's COP2 crypto hardware in the kernel. This must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)  * called after an octeon_crypto_enable() before any context switch or return to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)  * userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)  * @state:	Pointer to COP2 state to restore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)  * @flags:	Return value from octeon_crypto_enable()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) void octeon_crypto_disable(struct octeon_cop2_state *state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 			   unsigned long crypto_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	if (crypto_flags & ST0_CU2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 		octeon_cop2_restore(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		write_c0_status(read_c0_status() & ~ST0_CU2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) EXPORT_SYMBOL_GPL(octeon_crypto_disable);