Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 May 2020 19:50:27 +0000 (UTC)
From:      Mitchell Horne <mhorne@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r360703 - in stable/12/sys: arm/arm arm/include arm64/arm64 conf kern sys
Message-ID:  <202005061950.046JoRrA042224@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mhorne
Date: Wed May  6 19:50:27 2020
New Revision: 360703
URL: https://svnweb.freebsd.org/changeset/base/360703

Log:
  MFC r360082:
  
  Convert arm's physmem interface to MI code

Added:
  stable/12/sys/kern/subr_physmem.c
     - copied, changed from r360702, stable/12/sys/arm/arm/physmem.c
  stable/12/sys/sys/physmem.h
     - copied unchanged from r360082, head/sys/sys/physmem.h
Deleted:
  stable/12/sys/arm/arm/physmem.c
  stable/12/sys/arm/include/physmem.h
Modified:
  stable/12/sys/arm/arm/machdep.c
  stable/12/sys/arm/arm/machdep_boot.c
  stable/12/sys/arm/arm/mp_machdep.c
  stable/12/sys/arm/arm/pmap-v6.c
  stable/12/sys/arm/include/md_var.h
  stable/12/sys/arm64/arm64/machdep.c
  stable/12/sys/arm64/arm64/pmap.c
  stable/12/sys/conf/files.arm
  stable/12/sys/conf/files.arm64
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/arm/arm/machdep.c
==============================================================================
--- stable/12/sys/arm/arm/machdep.c	Wed May  6 19:10:39 2020	(r360702)
+++ stable/12/sys/arm/arm/machdep.c	Wed May  6 19:50:27 2020	(r360703)
@@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/linker.h>
 #include <sys/msgbuf.h>
+#include <sys/physmem.h>
 #include <sys/reboot.h>
 #include <sys/rwlock.h>
 #include <sys/sched.h>
@@ -82,7 +83,6 @@ __FBSDID("$FreeBSD$");
 #include <machine/machdep.h>
 #include <machine/metadata.h>
 #include <machine/pcb.h>
-#include <machine/physmem.h>
 #include <machine/platform.h>
 #include <machine/sysarch.h>
 #include <machine/undefined.h>
@@ -122,6 +122,9 @@ uint32_t cpu_reset_address = 0;
 int cold = 1;
 vm_offset_t vector_page;
 
+/* The address at which the kernel was loaded.  Set early in initarm(). */
+vm_paddr_t arm_physmem_kernaddr;
+
 int (*_arm_memcpy)(void *, void *, int, int) = NULL;
 int (*_arm_bzero)(void *, int, int) = NULL;
 int _min_memcpy_size = 0;
@@ -159,7 +162,6 @@ static void *delay_arg;
 #endif
 
 struct kva_md_info kmi;
-
 /*
  * arm32_vector_init:
  *
@@ -236,7 +238,7 @@ cpu_startup(void *dummy)
 	    (uintmax_t)arm32_ptob(vm_free_count()),
 	    (uintmax_t)arm32_ptob(vm_free_count()) / mbyte);
 	if (bootverbose) {
-		arm_physmem_print_tables();
+		physmem_print_tables();
 		devmap_print_table();
 	}
 
@@ -868,11 +870,11 @@ initarm(struct arm_boot_params *abp)
 	/* Grab physical memory regions information from device tree. */
 	if (fdt_get_mem_regions(mem_regions, &mem_regions_sz, &memsize) != 0)
 		panic("Cannot get physical memory regions");
-	arm_physmem_hardware_regions(mem_regions, mem_regions_sz);
+	physmem_hardware_regions(mem_regions, mem_regions_sz);
 
 	/* Grab reserved memory regions information from device tree. */
 	if (fdt_get_reserved_regions(mem_regions, &mem_regions_sz) == 0)
-		arm_physmem_exclude_regions(mem_regions, mem_regions_sz,
+		physmem_exclude_regions(mem_regions, mem_regions_sz,
 		    EXFLAG_NODUMP | EXFLAG_NOALLOC);
 
 	/* Platform-specific initialisation */
@@ -1079,9 +1081,9 @@ initarm(struct arm_boot_params *abp)
 	 *
 	 * Prepare the list of physical memory available to the vm subsystem.
 	 */
-	arm_physmem_exclude_region(abp->abp_physaddr,
+	physmem_exclude_region(abp->abp_physaddr,
 	    (virtual_avail - KERNVIRTADDR), EXFLAG_NOALLOC);
-	arm_physmem_init_kernel_globals();
+	physmem_init_kernel_globals();
 
 	init_param2(physmem);
 	dbg_monitor_init();
@@ -1147,11 +1149,11 @@ initarm(struct arm_boot_params *abp)
 		if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,NULL) != 0)
 			panic("Cannot get physical memory regions");
 	}
-	arm_physmem_hardware_regions(mem_regions, mem_regions_sz);
+	physmem_hardware_regions(mem_regions, mem_regions_sz);
 
 	/* Grab reserved memory regions information from device tree. */
 	if (fdt_get_reserved_regions(mem_regions, &mem_regions_sz) == 0)
-		arm_physmem_exclude_regions(mem_regions, mem_regions_sz,
+		physmem_exclude_regions(mem_regions, mem_regions_sz,
 		    EXFLAG_NODUMP | EXFLAG_NOALLOC);
 
 	/*
@@ -1286,9 +1288,9 @@ initarm(struct arm_boot_params *abp)
 	 *
 	 * Prepare the list of physical memory available to the vm subsystem.
 	 */
-	arm_physmem_exclude_region(abp->abp_physaddr,
+	physmem_exclude_region(abp->abp_physaddr,
 		pmap_preboot_get_pages(0) - abp->abp_physaddr, EXFLAG_NOALLOC);
-	arm_physmem_init_kernel_globals();
+	physmem_init_kernel_globals();
 
 	init_param2(physmem);
 	/* Init message buffer. */

Modified: stable/12/sys/arm/arm/machdep_boot.c
==============================================================================
--- stable/12/sys/arm/arm/machdep_boot.c	Wed May  6 19:10:39 2020	(r360702)
+++ stable/12/sys/arm/arm/machdep_boot.c	Wed May  6 19:50:27 2020	(r360703)
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/systm.h>
 #include <sys/ctype.h>
 #include <sys/linker.h>
+#include <sys/physmem.h>
 #include <sys/reboot.h>
 #include <sys/sysctl.h>
 #if defined(LINUX_BOOT_ABI)
@@ -46,7 +47,6 @@ __FBSDID("$FreeBSD$");
 #include <machine/cpu.h>
 #include <machine/machdep.h>
 #include <machine/metadata.h>
-#include <machine/physmem.h>
 #include <machine/vmparam.h>	/* For KERNVIRTADDR */
 
 #ifdef FDT
@@ -227,7 +227,7 @@ linux_parse_boot_param(struct arm_boot_params *abp)
 		case ATAG_CORE:
 			break;
 		case ATAG_MEM:
-			arm_physmem_hardware_region(walker->u.tag_mem.start,
+			physmem_hardware_region(walker->u.tag_mem.start,
 			    walker->u.tag_mem.size);
 			break;
 		case ATAG_INITRD2:

Modified: stable/12/sys/arm/arm/mp_machdep.c
==============================================================================
--- stable/12/sys/arm/arm/mp_machdep.c	Wed May  6 19:10:39 2020	(r360702)
+++ stable/12/sys/arm/arm/mp_machdep.c	Wed May  6 19:50:27 2020	(r360703)
@@ -53,7 +53,6 @@ __FBSDID("$FreeBSD$");
 #include <machine/debug_monitor.h>
 #include <machine/smp.h>
 #include <machine/pcb.h>
-#include <machine/physmem.h>
 #include <machine/intr.h>
 #include <machine/vmparam.h>
 #ifdef VFP

Modified: stable/12/sys/arm/arm/pmap-v6.c
==============================================================================
--- stable/12/sys/arm/arm/pmap-v6.c	Wed May  6 19:10:39 2020	(r360702)
+++ stable/12/sys/arm/arm/pmap-v6.c	Wed May  6 19:50:27 2020	(r360703)
@@ -117,8 +117,6 @@ __FBSDID("$FreeBSD$");
 #include <ddb/ddb.h>
 #endif
 
-#include <machine/physmem.h>
-
 #include <vm/vm.h>
 #include <vm/uma.h>
 #include <vm/pmap.h>

Modified: stable/12/sys/arm/include/md_var.h
==============================================================================
--- stable/12/sys/arm/include/md_var.h	Wed May  6 19:10:39 2020	(r360702)
+++ stable/12/sys/arm/include/md_var.h	Wed May  6 19:50:27 2020	(r360703)
@@ -42,6 +42,7 @@ extern uint32_t *vm_page_dump;
 extern int vm_page_dump_size;
 extern u_long elf_hwcap;
 extern u_long elf_hwcap2;
+extern vm_paddr_t arm_physmem_kernaddr;
 
 extern int (*_arm_memcpy)(void *, void *, int, int);
 extern int (*_arm_bzero)(void *, int, int);

Modified: stable/12/sys/arm64/arm64/machdep.c
==============================================================================
--- stable/12/sys/arm64/arm64/machdep.c	Wed May  6 19:10:39 2020	(r360702)
+++ stable/12/sys/arm64/arm64/machdep.c	Wed May  6 19:50:27 2020	(r360703)
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/linker.h>
 #include <sys/msgbuf.h>
 #include <sys/pcpu.h>
+#include <sys/physmem.h>
 #include <sys/proc.h>
 #include <sys/ptrace.h>
 #include <sys/reboot.h>
@@ -80,8 +81,6 @@ __FBSDID("$FreeBSD$");
 #include <machine/undefined.h>
 #include <machine/vmparam.h>
 
-#include <arm/include/physmem.h>
-
 #ifdef VFP
 #include <machine/vfp.h>
 #endif
@@ -764,7 +763,7 @@ exclude_efi_map_entry(struct efi_md *p)
 		 */
 		break;
 	default:
-		arm_physmem_exclude_region(p->md_phys, p->md_pages * PAGE_SIZE,
+		physmem_exclude_region(p->md_phys, p->md_pages * PAGE_SIZE,
 		    EXFLAG_NOALLOC);
 	}
 }
@@ -795,7 +794,7 @@ add_efi_map_entry(struct efi_md *p)
 		/*
 		 * We're allowed to use any entry with these types.
 		 */
-		arm_physmem_hardware_region(p->md_phys,
+		physmem_hardware_region(p->md_phys,
 		    p->md_pages * PAGE_SIZE);
 		break;
 	}
@@ -1029,10 +1028,10 @@ initarm(struct arm64_bootparams *abp)
 		if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,
 		    NULL) != 0)
 			panic("Cannot get physical memory regions");
-		arm_physmem_hardware_regions(mem_regions, mem_regions_sz);
+		physmem_hardware_regions(mem_regions, mem_regions_sz);
 	}
 	if (fdt_get_reserved_mem(mem_regions, &mem_regions_sz) == 0)
-		arm_physmem_exclude_regions(mem_regions, mem_regions_sz,
+		physmem_exclude_regions(mem_regions, mem_regions_sz,
 		    EXFLAG_NODUMP | EXFLAG_NOALLOC);
 #endif
 
@@ -1040,7 +1039,7 @@ initarm(struct arm64_bootparams *abp)
 	efifb = (struct efi_fb *)preload_search_info(kmdp,
 	    MODINFO_METADATA | MODINFOMD_EFI_FB);
 	if (efifb != NULL)
-		arm_physmem_exclude_region(efifb->fb_addr, efifb->fb_size,
+		physmem_exclude_region(efifb->fb_addr, efifb->fb_size,
 		    EXFLAG_NOALLOC);
 
 	/* Set the pcpu data, this is needed by pmap_bootstrap */
@@ -1069,7 +1068,7 @@ initarm(struct arm64_bootparams *abp)
 	/* Exclude entries neexed in teh DMAP region, but not phys_avail */
 	if (efihdr != NULL)
 		exclude_efi_map_entries(efihdr);
-	arm_physmem_init_kernel_globals();
+	physmem_init_kernel_globals();
 
 	devmap_bootstrap(0, NULL);
 
@@ -1096,7 +1095,7 @@ initarm(struct arm64_bootparams *abp)
 
 	if (boothowto & RB_VERBOSE) {
 		print_efi_map_entries(efihdr);
-		arm_physmem_print_tables();
+		physmem_print_tables();
 	}
 
 	early_boot = 0;

Modified: stable/12/sys/arm64/arm64/pmap.c
==============================================================================
--- stable/12/sys/arm64/arm64/pmap.c	Wed May  6 19:10:39 2020	(r360702)
+++ stable/12/sys/arm64/arm64/pmap.c	Wed May  6 19:50:27 2020	(r360703)
@@ -118,6 +118,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/mman.h>
 #include <sys/msgbuf.h>
 #include <sys/mutex.h>
+#include <sys/physmem.h>
 #include <sys/proc.h>
 #include <sys/rwlock.h>
 #include <sys/sbuf.h>
@@ -147,8 +148,6 @@ __FBSDID("$FreeBSD$");
 #include <machine/md_var.h>
 #include <machine/pcb.h>
 
-#include <arm/include/physmem.h>
-
 #define	NL0PG		(PAGE_SIZE/(sizeof (pd_entry_t)))
 #define	NL1PG		(PAGE_SIZE/(sizeof (pd_entry_t)))
 #define	NL2PG		(PAGE_SIZE/(sizeof (pd_entry_t)))
@@ -801,7 +800,7 @@ pmap_bootstrap(vm_offset_t l0pt, vm_offset_t l1pt, vm_
 	/* Assume the address we were loaded to is a valid physical address */
 	min_pa = KERNBASE - kern_delta;
 
-	physmap_idx = arm_physmem_avail(physmap, nitems(physmap));
+	physmap_idx = physmem_avail(physmap, nitems(physmap));
 	physmap_idx /= 2;
 
 	/*
@@ -882,7 +881,7 @@ pmap_bootstrap(vm_offset_t l0pt, vm_offset_t l1pt, vm_
 
 	pa = pmap_early_vtophys(l1pt, freemempos);
 
-	arm_physmem_exclude_region(start_pa, pa - start_pa, EXFLAG_NOALLOC);
+	physmem_exclude_region(start_pa, pa - start_pa, EXFLAG_NOALLOC);
 
 	cpu_tlb_flushID();
 }

Modified: stable/12/sys/conf/files.arm
==============================================================================
--- stable/12/sys/conf/files.arm	Wed May  6 19:10:39 2020	(r360702)
+++ stable/12/sys/conf/files.arm	Wed May  6 19:50:27 2020	(r360703)
@@ -59,7 +59,6 @@ arm/arm/mp_machdep.c		optional	smp
 arm/arm/mpcore_timer.c		optional	mpcore_timer
 arm/arm/nexus.c			standard
 arm/arm/ofw_machdep.c		optional	fdt
-arm/arm/physmem.c		standard
 arm/arm/pl190.c			optional	pl190
 arm/arm/pl310.c			optional	pl310
 arm/arm/platform.c		optional	platform
@@ -128,6 +127,7 @@ kern/msi_if.m			optional	intrng
 kern/pic_if.m			optional	intrng
 kern/subr_busdma_bufalloc.c	standard
 kern/subr_devmap.c		standard
+kern/subr_physmem.c		standard
 kern/subr_sfbuf.c		standard
 libkern/arm/aeabi_unwind.c	standard
 libkern/arm/divsi3.S		standard

Modified: stable/12/sys/conf/files.arm64
==============================================================================
--- stable/12/sys/conf/files.arm64	Wed May  6 19:10:39 2020	(r360702)
+++ stable/12/sys/conf/files.arm64	Wed May  6 19:50:27 2020	(r360703)
@@ -79,7 +79,6 @@ arm/arm/gic.c			standard
 arm/arm/gic_acpi.c		optional	acpi
 arm/arm/gic_fdt.c		optional	fdt
 arm/arm/pmu.c			standard
-arm/arm/physmem.c		standard
 arm/broadcom/bcm2835/bcm2835_audio.c		optional sound vchiq fdt \
 	compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq"
 arm/broadcom/bcm2835/bcm2835_bsc.c		optional bcm2835_bsc fdt
@@ -263,6 +262,7 @@ kern/msi_if.m			optional	intrng
 kern/pic_if.m			optional	intrng
 kern/subr_devmap.c		standard
 kern/subr_intr.c		optional	intrng
+kern/subr_physmem.c		standard
 libkern/bcmp.c			standard
 libkern/ffs.c			standard
 libkern/ffsl.c			standard

Copied and modified: stable/12/sys/kern/subr_physmem.c (from r360702, stable/12/sys/arm/arm/physmem.c)
==============================================================================
--- stable/12/sys/arm/arm/physmem.c	Wed May  6 19:10:39 2020	(r360702, copy source)
+++ stable/12/sys/kern/subr_physmem.c	Wed May  6 19:50:27 2020	(r360703)
@@ -38,9 +38,9 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/physmem.h>
 #include <vm/vm.h>
 #include <machine/md_var.h>
-#include <arm/include/physmem.h>
 
 /*
  * These structures are used internally to keep track of regions of physical
@@ -59,10 +59,8 @@ __FBSDID("$FreeBSD$");
 
 #if defined(__arm__)
 #define	MAX_PHYS_ADDR	0xFFFFFFFFull
-#define	pm_btop(x)	arm32_btop(x)
-#elif defined(__aarch64__)
+#elif defined(__aarch64__) || defined(__riscv)
 #define	MAX_PHYS_ADDR	0xFFFFFFFFFFFFFFFFull
-#define	pm_btop(x)	arm64_btop(x)
 #endif
 
 struct region {
@@ -110,9 +108,6 @@ vm_paddr_t dump_avail[MAX_AVAIL_ENTRIES + 2]; /* of ze
 long realmem;
 long Maxmem;
 
-/* The address at which the kernel was loaded.  Set early in initarm(). */
-vm_paddr_t arm_physmem_kernaddr;
-
 /*
  * Print the contents of the physical and excluded region tables using the
  * provided printf-like output function (which will be either printf or
@@ -159,7 +154,7 @@ physmem_dump_tables(int (*prfunc)(const char *, ...))
  * Print the contents of the static mapping table.  Used for bootverbose.
  */
 void
-arm_physmem_print_tables(void)
+physmem_print_tables(void)
 {
 
 	physmem_dump_tables(printf);
@@ -188,7 +183,7 @@ regions_to_avail(vm_paddr_t *avail, uint32_t exflags, 
 	for (hwi = 0, hwp = hwregions; hwi < hwcnt; ++hwi, ++hwp) {
 		start = hwp->addr;
 		end   = hwp->size + start;
-		totalmem += pm_btop((vm_offset_t)(end - start));
+		totalmem += atop((vm_offset_t)(end - start));
 		for (exi = 0, exp = exregions; exi < excnt; ++exi, ++exp) {
 			/*
 			 * If the excluded region does not match given flags,
@@ -236,8 +231,7 @@ regions_to_avail(vm_paddr_t *avail, uint32_t exflags, 
 					avail[acnt++] = (vm_paddr_t)start;
 					avail[acnt++] = (vm_paddr_t)xstart;
 				}
-				availmem +=
-				    pm_btop((vm_offset_t)(xstart - start));
+				availmem += atop((vm_offset_t)(xstart - start));
 				start = xend;
 				continue;
 			}
@@ -262,7 +256,7 @@ regions_to_avail(vm_paddr_t *avail, uint32_t exflags, 
 				avail[acnt++] = (vm_paddr_t)start;
 				avail[acnt++] = (vm_paddr_t)end;
 			}
-			availmem += pm_btop((vm_offset_t)(end - start));
+			availmem += atop((vm_offset_t)(end - start));
 		}
 		if (acnt >= maxavail)
 			panic("Not enough space in the dump/phys_avail arrays");
@@ -316,7 +310,7 @@ insert_region(struct region *regions, size_t rcnt, vm_
  * Add a hardware memory region.
  */
 void
-arm_physmem_hardware_region(uint64_t pa, uint64_t sz)
+physmem_hardware_region(uint64_t pa, uint64_t sz)
 {
 	vm_offset_t adj;
 
@@ -368,7 +362,7 @@ arm_physmem_hardware_region(uint64_t pa, uint64_t sz)
  * Add an exclusion region.
  */
 void
-arm_physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t exflags)
+physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t exflags)
 {
 	vm_offset_t adj;
 
@@ -387,7 +381,7 @@ arm_physmem_exclude_region(vm_paddr_t pa, vm_size_t sz
 }
 
 size_t
-arm_physmem_avail(vm_paddr_t *avail, size_t maxavail)
+physmem_avail(vm_paddr_t *avail, size_t maxavail)
 {
 
 	return (regions_to_avail(avail, EXFLAG_NOALLOC, maxavail, NULL, NULL));
@@ -403,7 +397,7 @@ arm_physmem_avail(vm_paddr_t *avail, size_t maxavail)
  * last page of physical memory in the system.
  */
 void
-arm_physmem_init_kernel_globals(void)
+physmem_init_kernel_globals(void)
 {
 	size_t nextidx;
 
@@ -426,4 +420,3 @@ DB_SHOW_COMMAND(physmem, db_show_physmem)
 }
 
 #endif /* DDB */
-

Copied: stable/12/sys/sys/physmem.h (from r360082, head/sys/sys/physmem.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/sys/physmem.h	Wed May  6 19:50:27 2020	(r360703, copy of r360082, head/sys/sys/physmem.h)
@@ -0,0 +1,88 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2014 Ian Lepore <ian@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef	_SYS_PHYSMEM_H_
+#define	_SYS_PHYSMEM_H_
+
+/*
+ * Routines to help configure physical ram.
+ *
+ * Multiple regions of contiguous physical ram can be added (in any order).
+ *
+ * Multiple regions of physical ram that should be excluded from crash dumps, or
+ * memory allocation, or both, can be added (in any order).
+ *
+ * After all early kernel init is done and it's time to configure all
+ * remainining non-excluded physical ram for use by other parts of the kernel,
+ * physmem_init_kernel_globals() processes the hardware regions and
+ * exclusion regions to generate the global dump_avail and phys_avail arrays
+ * that communicate physical ram configuration to other parts of the kernel.
+ */
+
+#define	EXFLAG_NODUMP	0x01
+#define	EXFLAG_NOALLOC	0x02
+
+void physmem_hardware_region(uint64_t pa, uint64_t sz);
+void physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t flags);
+size_t physmem_avail(vm_paddr_t *avail, size_t maxavail);
+void physmem_init_kernel_globals(void);
+void physmem_print_tables(void);
+
+/*
+ * Convenience routines for FDT.
+ */
+
+#ifdef FDT
+
+#include <machine/ofw_machdep.h>
+
+static inline void
+physmem_hardware_regions(struct mem_region * mrptr, int mrcount)
+{
+	while (mrcount--) {
+		physmem_hardware_region(mrptr->mr_start, mrptr->mr_size);
+		++mrptr;
+	}
+}
+
+static inline void
+physmem_exclude_regions(struct mem_region * mrptr, int mrcount,
+    uint32_t exflags)
+{
+	while (mrcount--) {
+		physmem_exclude_region(mrptr->mr_start, mrptr->mr_size,
+		    exflags);
+		++mrptr;
+	}
+}
+
+#endif /* FDT */
+
+#endif /* !_SYS_PHYSMEM_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005061950.046JoRrA042224>