svn commit: r326213 - head/sys/powerpc/ofw

Nathan Whitehorn nwhitehorn at FreeBSD.org
Sat Nov 25 22:14:31 UTC 2017


Author: nwhitehorn
Date: Sat Nov 25 22:14:30 2017
New Revision: 326213
URL: https://svnweb.freebsd.org/changeset/base/326213

Log:
  When booting from an FDT, make sure the FDT itself isn't included the range
  of available memory. Boot loaders are supposed to add a reserved entry for
  it, but not all do.
  
  MFC after:	2 weeks

Modified:
  head/sys/powerpc/ofw/ofw_machdep.c

Modified: head/sys/powerpc/ofw/ofw_machdep.c
==============================================================================
--- head/sys/powerpc/ofw/ofw_machdep.c	Sat Nov 25 22:13:19 2017	(r326212)
+++ head/sys/powerpc/ofw/ofw_machdep.c	Sat Nov 25 22:14:30 2017	(r326213)
@@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$");
 #include <machine/ofw_machdep.h>
 #include <machine/trap.h>
 
+#include <contrib/libfdt/libfdt.h>
+
 static void	*fdt;
 int		ofw_real_mode;
 
@@ -233,8 +235,17 @@ excise_fdt_reserved(struct mem_region *avail, int asz)
 	fdtmapsize = OF_getprop(chosen, "fdtmemreserv", fdtmap, sizeof(fdtmap));
 
 	for (j = 0; j < fdtmapsize/sizeof(fdtmap[0]); j++) {
-		fdtmap[j].address = be64toh(fdtmap[j].address);
-		fdtmap[j].size = be64toh(fdtmap[j].size);
+		fdtmap[j].address = be64toh(fdtmap[j].address) & ~PAGE_MASK;
+		fdtmap[j].size = round_page(be64toh(fdtmap[j].size));
+	}
+
+	KASSERT(j*sizeof(fdtmap[0]) < sizeof(fdtmap),
+	    ("Exceeded number of FDT reservations"));
+	/* Add a virtual entry for the FDT itself */
+	if (fdt != NULL) {
+		fdtmap[j].address = (vm_offset_t)fdt & ~PAGE_MASK;
+		fdtmap[j].size = round_page(fdt_totalsize(fdt));
+		fdtmapsize += sizeof(fdtmap[0]);
 	}
 
 	for (i = 0; i < asz; i++) {


More information about the svn-src-head mailing list