git: a6a481eaa2e0 - main - arm: Add fpu_kern_alloc_ctx()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Mon, 11 Dec 2023 14:16:35 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=a6a481eaa2e0f02e24b874f1a08bb494a68972c0

commit a6a481eaa2e0f02e24b874f1a08bb494a68972c0
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-12-11 14:07:55 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-12-11 14:07:55 +0000

    arm: Add fpu_kern_alloc_ctx()
    
    This enables the use of some out-of-tree crypto libraries on arm.
    No functional change intended, there are no callers of this function in
    the tree currently.
    
    Reviewed by:    andrew
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   Stormshield
    Differential Revision:  https://reviews.freebsd.org/D42969
---
 sys/arm/arm/vfp.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/sys/arm/arm/vfp.c b/sys/arm/arm/vfp.c
index a4be235e1e01..f2979d4a2b27 100644
--- a/sys/arm/arm/vfp.c
+++ b/sys/arm/arm/vfp.c
@@ -30,10 +30,10 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/kernel.h>
 #include <sys/limits.h>
+#include <sys/malloc.h>
 #include <sys/proc.h>
-#include <sys/imgact_elf.h>
-#include <sys/kernel.h>
 
 #include <machine/armreg.h>
 #include <machine/elf.h>
@@ -52,6 +52,9 @@ static struct undefined_handler vfp10_uh, vfp11_uh;
 /* If true the VFP unit has 32 double registers, otherwise it has 16 */
 static int is_d32;
 
+static MALLOC_DEFINE(M_FPUKERN_CTX, "fpukern_ctx",
+    "Kernel contexts for VFP state");
+
 struct fpu_kern_ctx {
 	struct vfp_state	*prev;
 #define	FPU_KERN_CTX_DUMMY	0x01	/* avoided save for the kern thread */
@@ -407,6 +410,21 @@ vfp_save_state(struct thread *td, struct pcb *pcb)
 	critical_exit();
 }
 
+struct fpu_kern_ctx *
+fpu_kern_alloc_ctx(u_int flags)
+{
+	return (malloc(sizeof(struct fpu_kern_ctx), M_FPUKERN_CTX,
+	    ((flags & FPU_KERN_NOWAIT) ? M_NOWAIT : M_WAITOK) | M_ZERO));
+}
+
+void
+fpu_kern_free_ctx(struct fpu_kern_ctx *ctx)
+{
+	KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) == 0, ("freeing in-use ctx"));
+
+	free(ctx, M_FPUKERN_CTX);
+}
+
 void
 fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags)
 {