Module Name:    src
Committed By:   macallan
Date:           Sun May 12 13:42:39 UTC 2013

Modified Files:
        src/sys/arch/powerpc/powerpc: ofw_machdep.c

Log Message:
cleanup mem_regions:
- use different variables for / and /memory nodes
- remove redundant OF_finddevice("/")
- assume 32bit addresses/sizes in "available" on Apple hardware


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/powerpc/powerpc/ofw_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/powerpc/ofw_machdep.c
diff -u src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.22 src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.23
--- src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.22	Thu Apr 11 19:55:10 2013
+++ src/sys/arch/powerpc/powerpc/ofw_machdep.c	Sun May 12 13:42:39 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_machdep.c,v 1.22 2013/04/11 19:55:10 macallan Exp $	*/
+/*	$NetBSD: ofw_machdep.c,v 1.23 2013/05/12 13:42:39 macallan Exp $	*/
 
 /*
  * Copyright (C) 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.22 2013/04/11 19:55:10 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.23 2013/05/12 13:42:39 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -69,31 +69,29 @@ static struct mem_region OFmem[OFMEM_REG
 void
 mem_regions(struct mem_region **memp, struct mem_region **availp)
 {
-	int phandle, i, cnt, regcnt, acells, scells;
+	const char *macrisc[] = {"MacRISC", "MacRISC2", "MacRISC4", NULL};
+	int hroot, hmem, i, cnt, regcnt, acells, scells;
 	int numregs;
 	uint32_t regs[OFMEM_REGIONS * 4]; /* 2 values + 2 for 64bit */
 
 	DPRINTF("calling mem_regions\n");
 	/* determine acell size */
-	if ((phandle = OF_finddevice("/")) == -1)
+	if ((hroot = OF_finddevice("/")) == -1)
 		goto error;
-	cnt = OF_getprop(phandle, "#address-cells", &acells, sizeof(int));
+	cnt = OF_getprop(hroot, "#address-cells", &acells, sizeof(int));
 	if (cnt <= 0)
 		acells = 1;
 
 	/* determine scell size */
-	if ((phandle = OF_finddevice("/")) == -1)
-		goto error;
-	cnt = OF_getprop(phandle, "#size-cells", &scells, sizeof(int));
+	cnt = OF_getprop(hroot, "#size-cells", &scells, sizeof(int));
 	if (cnt <= 0)
 		scells = 1;
 
 	/* Get memory */
-	if ((phandle = OF_finddevice("/memory")) == -1)
-		goto error;
-
 	memset(regs, 0, sizeof(regs));
-	regcnt = OF_getprop(phandle, "reg", regs,
+	if ((hmem = OF_finddevice("/memory")) == -1)
+		goto error;
+	regcnt = OF_getprop(hmem, "reg", regs,
 	    sizeof(regs[0]) * OFMEM_REGIONS * 4);
 	if (regcnt <= 0)
 		goto error;
@@ -142,7 +140,7 @@ mem_regions(struct mem_region **memp, st
 
 	/* now do the same thing again, for the available counts */
 	memset(regs, 0, sizeof(regs));
-	regcnt = OF_getprop(phandle, "available", regs,
+	regcnt = OF_getprop(hmem, "available", regs,
 	    sizeof(regs[0]) * OFMEM_REGIONS * 4);
 	if (regcnt <= 0)
 		goto error;
@@ -150,15 +148,15 @@ mem_regions(struct mem_region **memp, st
 	DPRINTF("%08x %08x %08x %08x\n", regs[0], regs[1], regs[2], regs[3]);
 
 	/*
-	 * some(?) G5s have messed up 'available' properties which don't obey
-	 * #address-cells. Try to detect this here.
-	 * XXX this needs a better test
+	 * according to comments in FreeBSD all Apple OF has 32bit values in
+	 * "available", no matter what the cell sizes are
 	 */
-	if (((regcnt >> 2) % (acells + scells)) != 0) {
-		aprint_normal("messed up 'available' property detected\n");
+	if (of_compatible(hroot, macrisc) != -1) {
+		DPRINTF("this appears to be a mac...\n");
 		acells = 1;
+		scells = 1;
 	}
-	
+		
 	/* how many mem regions did we get? */
 	numregs = regcnt / (sizeof(uint32_t) * (acells + scells));
 	DPRINTF("regcnt=%d num=%d acell=%d scell=%d\n",
@@ -189,7 +187,7 @@ mem_regions(struct mem_region **memp, st
 #ifndef _LP64
 		if (addr > 0xFFFFFFFF || size > 0xFFFFFFFF ||
 			(addr + size) > 0xFFFFFFFF) {
-			aprint_error("Base addr of %llx or size of %llx too"
+			aprint_verbose("Base addr of %llx or size of %llx too"
 			    " large for 32 bit OS. Skipping.", addr, size);
 			continue;
 		}

Reply via email to