Skip to content

Commit

Permalink
arm64: add support for kernel mode NEON
Browse files Browse the repository at this point in the history
Add <asm/neon.h> containing kernel_neon_begin/kernel_neon_end function
declarations and corresponding definitions in fpsimd.c

These are needed to wrap uses of NEON in kernel mode. The names are
identical to the ones used in arm/ so code using intrinsics or
vectorized by GCC can be shared between arm and arm64.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
  • Loading branch information
Ard Biesheuvel authored and Catalin Marinas committed Aug 20, 2013
1 parent 178cd9c commit 4cfb361
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arch/arm64/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ config SWIOTLB
config IOMMU_HELPER
def_bool SWIOTLB

config KERNEL_MODE_NEON
def_bool y

source "init/Kconfig"

source "kernel/Kconfig.freezer"
Expand Down
14 changes: 14 additions & 0 deletions arch/arm64/include/asm/neon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* linux/arch/arm64/include/asm/neon.h
*
* Copyright (C) 2013 Linaro Ltd <ard.biesheuvel@linaro.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

#define cpu_has_neon() (1)

void kernel_neon_begin(void);
void kernel_neon_end(void);
28 changes: 28 additions & 0 deletions arch/arm64/kernel/fpsimd.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/signal.h>
#include <linux/hardirq.h>

#include <asm/fpsimd.h>
#include <asm/cputype.h>
Expand Down Expand Up @@ -83,6 +84,33 @@ void fpsimd_flush_thread(void)
fpsimd_load_state(&current->thread.fpsimd_state);
}

#ifdef CONFIG_KERNEL_MODE_NEON

/*
* Kernel-side NEON support functions
*/
void kernel_neon_begin(void)
{
/* Avoid using the NEON in interrupt context */
BUG_ON(in_interrupt());
preempt_disable();

if (current->mm)
fpsimd_save_state(&current->thread.fpsimd_state);
}
EXPORT_SYMBOL(kernel_neon_begin);

void kernel_neon_end(void)
{
if (current->mm)
fpsimd_load_state(&current->thread.fpsimd_state);

preempt_enable();
}
EXPORT_SYMBOL(kernel_neon_end);

#endif /* CONFIG_KERNEL_MODE_NEON */

/*
* FP/SIMD support code initialisation.
*/
Expand Down

0 comments on commit 4cfb361

Please sign in to comment.