Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Add support for installing modules that were loaded...



details:   https://anonhg.NetBSD.org/src/rev/c95ad1eea68a
branches:  trunk
changeset: 973135:c95ad1eea68a
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Jun 21 17:25:03 2020 +0000

description:
Add support for installing modules that were loaded by the bootloader.

diffstat:

 sys/arch/aarch64/aarch64/aarch64_machdep.c |   7 ++-
 sys/arch/arm/arm32/arm32_machdep.c         |   7 ++-
 sys/arch/arm/fdt/arm_fdt.c                 |  57 ++++++++++++++++++++++++++++-
 sys/arch/arm/fdt/arm_fdtvar.h              |   4 +-
 4 files changed, 68 insertions(+), 7 deletions(-)

diffs (156 lines):

diff -r 25d04ecf6ed3 -r c95ad1eea68a sys/arch/aarch64/aarch64/aarch64_machdep.c
--- a/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sun Jun 21 17:24:26 2020 +0000
+++ b/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sun Jun 21 17:25:03 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.42 2020/04/13 05:40:25 maxv Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.43 2020/06/21 17:25:03 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.42 2020/04/13 05:40:25 maxv Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.43 2020/06/21 17:25:03 jmcneill Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -530,6 +530,9 @@
 void
 module_init_md(void)
 {
+#ifdef FDT
+       arm_fdt_module_init();
+#endif
 }
 #endif /* MODULAR */
 
diff -r 25d04ecf6ed3 -r c95ad1eea68a sys/arch/arm/arm32/arm32_machdep.c
--- a/sys/arch/arm/arm32/arm32_machdep.c        Sun Jun 21 17:24:26 2020 +0000
+++ b/sys/arch/arm/arm32/arm32_machdep.c        Sun Jun 21 17:25:03 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm32_machdep.c,v 1.134 2020/06/20 15:45:22 skrll Exp $        */
+/*     $NetBSD: arm32_machdep.c,v 1.135 2020/06/21 17:25:03 jmcneill Exp $     */
 
 /*
  * Copyright (c) 1994-1998 Mark Brinicombe.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.134 2020/06/20 15:45:22 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.135 2020/06/21 17:25:03 jmcneill Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_arm_start.h"
@@ -687,6 +687,9 @@
 void
 module_init_md(void)
 {
+#ifdef FDT
+       arm_fdt_module_init();
+#endif
 }
 #endif /* MODULAR */
 
diff -r 25d04ecf6ed3 -r c95ad1eea68a sys/arch/arm/fdt/arm_fdt.c
--- a/sys/arch/arm/fdt/arm_fdt.c        Sun Jun 21 17:24:26 2020 +0000
+++ b/sys/arch/arm/fdt/arm_fdt.c        Sun Jun 21 17:25:03 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arm_fdt.c,v 1.10 2020/01/05 17:16:07 jmcneill Exp $ */
+/* $NetBSD: arm_fdt.c,v 1.11 2020/06/21 17:25:03 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,9 +27,10 @@
  */
 
 #include "opt_arm_timer.h"
+#include "opt_modular.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 1.10 2020/01/05 17:16:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm_fdt.c,v 1.11 2020/06/21 17:25:03 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -37,6 +38,9 @@
 #include <sys/device.h>
 #include <sys/kmem.h>
 #include <sys/bus.h>
+#include <sys/module.h>
+
+#include <uvm/uvm_extern.h>
 
 #include <dev/fdt/fdtvar.h>
 #include <dev/ofw/openfirm.h>
@@ -200,3 +204,52 @@
        _arm_fdt_timer_init();
 }
 #endif
+
+void
+arm_fdt_module_init(void)
+{
+#ifdef MODULAR
+       const int chosen = OF_finddevice("/chosen");
+       const char *module_name;
+       const uint64_t *data;
+       u_int index;
+       paddr_t pa;
+       vaddr_t va;
+       int len;
+
+       if (chosen == -1)
+               return;
+
+       data = fdtbus_get_prop(chosen, "netbsd,modules", &len);
+       if (data == NULL)
+               return;
+
+       for (index = 0; index < len / 16; index++, data += 2) {
+               module_name = fdtbus_get_string_index(chosen,
+                   "netbsd,module-names", index);
+               if (module_name == NULL)
+                       break;
+
+               const paddr_t startpa = (paddr_t)be64dec(data + 0);
+               const size_t size = (size_t)be64dec(data + 1);
+               const paddr_t endpa = round_page(startpa + size);
+
+               const vaddr_t startva = uvm_km_alloc(kernel_map, endpa - startpa,
+                   0, UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
+               if (startva == 0) {
+                       printf("ERROR: Cannot allocate VA for module %s\n",
+                           module_name);
+                       continue;
+               }
+
+               for (pa = startpa, va = startva;
+                    pa < endpa;
+                    pa += PAGE_SIZE, va += PAGE_SIZE) {
+                       pmap_kenter_pa(va, pa, VM_PROT_ALL, PMAP_WRITE_BACK);
+               }
+               pmap_update(pmap_kernel());
+
+               module_prime(module_name, (void *)(uintptr_t)startva, size);
+       }
+#endif /* !MODULAR */
+}
diff -r 25d04ecf6ed3 -r c95ad1eea68a sys/arch/arm/fdt/arm_fdtvar.h
--- a/sys/arch/arm/fdt/arm_fdtvar.h     Sun Jun 21 17:24:26 2020 +0000
+++ b/sys/arch/arm/fdt/arm_fdtvar.h     Sun Jun 21 17:25:03 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arm_fdtvar.h,v 1.16 2020/01/05 17:16:07 jmcneill Exp $ */
+/* $NetBSD: arm_fdtvar.h,v 1.17 2020/06/21 17:25:03 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -97,4 +97,6 @@
 
 void   arm_fdt_memory_dump(paddr_t);
 
+void   arm_fdt_module_init(void);
+
 #endif /* !_ARM_ARM_FDTVAR_H */



Home | Main Index | Thread Index | Old Index