PERFORCE change 153359 for review
Nathan Whitehorn
nwhitehorn at FreeBSD.org
Sat Nov 22 08:54:02 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=153359
Change 153359 by nwhitehorn at 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;
More information about the p4-projects
mailing list