Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Nov 2017 22:14:30 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r326213 - head/sys/powerpc/ofw
Message-ID:  <201711252214.vAPMEUNh064424@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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++) {



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