From owner-p4-projects@FreeBSD.ORG  Sat Nov 22 16:54:02 2008
Return-Path: <owner-p4-projects@FreeBSD.ORG>
Delivered-To: p4-projects@freebsd.org
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 8F37B1065674; Sat, 22 Nov 2008 16:54:02 +0000 (UTC)
Delivered-To: perforce@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 537731065673
	for <perforce@freebsd.org>; Sat, 22 Nov 2008 16:54:02 +0000 (UTC)
	(envelope-from nwhitehorn@freebsd.org)
Received: from repoman.freebsd.org (repoman.freebsd.org
	[IPv6:2001:4f8:fff6::29])
	by mx1.freebsd.org (Postfix) with ESMTP id 430688FC0A
	for <perforce@freebsd.org>; Sat, 22 Nov 2008 16:54:02 +0000 (UTC)
	(envelope-from nwhitehorn@freebsd.org)
Received: from repoman.freebsd.org (localhost [127.0.0.1])
	by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id mAMGs2jk063632
	for <perforce@freebsd.org>; Sat, 22 Nov 2008 16:54:02 GMT
	(envelope-from nwhitehorn@freebsd.org)
Received: (from perforce@localhost)
	by repoman.freebsd.org (8.14.3/8.14.3/Submit) id mAMGs2YR063630
	for perforce@freebsd.org; Sat, 22 Nov 2008 16:54:02 GMT
	(envelope-from nwhitehorn@freebsd.org)
Date: Sat, 22 Nov 2008 16:54:02 GMT
Message-Id: <200811221654.mAMGs2YR063630@repoman.freebsd.org>
X-Authentication-Warning: repoman.freebsd.org: perforce set sender to
	nwhitehorn@freebsd.org using -f
From: Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To: Perforce Change Reviews <perforce@freebsd.org>
Cc: 
Subject: PERFORCE change 153359 for review
X-BeenThere: p4-projects@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: p4 projects tree changes <p4-projects.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/p4-projects>,
	<mailto:p4-projects-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/p4-projects>
List-Post: <mailto:p4-projects@freebsd.org>
List-Help: <mailto:p4-projects-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/p4-projects>,
	<mailto:p4-projects-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sat, 22 Nov 2008 16:54:02 -0000

http://perforce.freebsd.org/chv.cgi?CH=153359

Change 153359 by nwhitehorn@nwhitehorn_trantor on 2008/11/22 16:53:09

	Another try to get this code to work in a reasonable way. This time,
	it allocates a 256 byte static buffer and then swaps it for a full page
	allocated with contigmalloc() once the VM is up. Still not optimal,
	but better. Mambo still can't boot SMP due to some memory corruption
	thing: there is a "stack overflow detected" panic.

Affected files ...

.. //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_real.c#4 edit

Differences ...

==== //depot/projects/ppc-g5/sys/powerpc/ofw/ofw_real.c#4 (text+ko) ====

@@ -146,6 +146,8 @@
 };
 OFW_DEF(ofw_real);
 
+MALLOC_DEFINE(M_OFWREAL, "ofwreal", "Open Firmware Real Mode Bounce Page");
+
 static int (*openfirmware)(void *);
 
 static vm_offset_t	of_bounce_phys;
@@ -158,9 +160,16 @@
  * We need a statically allocated bounce buffer to handle the case when
  * there are Open Firmware calls after the MMU has been enabled but before
  * the VM has been initialized to the point that we can allocate memory.
- * Make it 4K and 8 byte aligned.
+ * Make it 256 bytes and 8 byte aligned and hope for the best.
+ *
+ * After the VM is up, allocate more memory.
  */
-static uint64_t		of_bounce_buffer[512];
+static uint64_t		of_static_bounce_buffer[32];
+
+static void ofw_real_bounce_alloc(void *);
+
+SYSINIT(ofw_real_bounce_alloc, SI_SUB_VM, SI_ORDER_ANY, 
+    ofw_real_bounce_alloc, NULL);
 
 static void
 ofw_real_start(void)
@@ -175,6 +184,31 @@
 	mtx_unlock(&of_bounce_mtx);
 }
 
+static void
+ofw_real_bounce_alloc(void *junk)
+{
+	/*
+	 * Check that ofw_real is actually in use before allocating wads 
+	 * of memory. Do this by checking if our mutex has been set up.
+	 */
+	if (!mtx_initialized(&of_bounce_mtx))
+		return;
+
+	/*
+	 * Allocate a page of contiguous, wired physical memory that can
+	 * fit into a 32-bit address space.
+	 */
+
+	mtx_lock(&of_bounce_mtx);
+
+	of_bounce_virt = contigmalloc(PAGE_SIZE, M_OFWREAL, 0,
+			     0, BUS_SPACE_MAXADDR_32BIT, PAGE_SIZE, PAGE_SIZE);
+	of_bounce_phys = vtophys(of_bounce_virt);
+	of_bounce_size = PAGE_SIZE;
+
+	mtx_unlock(&of_bounce_mtx);
+}
+
 static cell_t
 ofw_real_map(const void *buf, size_t len)
 {
@@ -186,10 +220,10 @@
 		if (!pmap_bootstrapped)
 			return (cell_t)buf;
 
-		of_bounce_virt = (caddr_t)of_bounce_buffer;
-		of_bounce_size = sizeof(of_bounce_buffer);
+		of_bounce_virt = (caddr_t)of_static_bounce_buffer;
+		of_bounce_size = sizeof(of_static_bounce_buffer);
 
-		of_bounce_phys = vtophys(of_bounce_buffer);
+		of_bounce_phys = vtophys(of_static_bounce_buffer);
 	}
 
 	/*
@@ -198,8 +232,10 @@
 	 */
 	of_bounce_offset += of_bounce_offset % sizeof(register_t);
 
-	if (of_bounce_offset + len > of_bounce_size)
+	if (of_bounce_offset + len > of_bounce_size) {
+		panic("Oversize Open Firmware call!");
 		return 0;
+	}
 
 	memcpy(of_bounce_virt + of_bounce_offset, buf, len);
 	phys = of_bounce_phys + of_bounce_offset;