Subject: port-sun3/6540: sun3x MACHINE_NEW_NONCONTIG and UVM fix
To: None <gnats-bugs@gnats.netbsd.org>
From: None <tsutsui@ceres.dti.ne.jp>
List: netbsd-bugs
Date: 12/06/1998 23:41:20
>Number:         6540
>Category:       port-sun3
>Synopsis:       sun3x MACHINE_NEW_NONCONTIG and UVM fix
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec  6 06:50:01 1998
>Last-Modified:
>Originator:     Izumi Tsutsui
>Organization:
Izumi Tsutsui Himeji City Japan
>Release:        NetBSD-current supped on 981204
>Environment:
NetBSD chariot 1.3I NetBSD 1.3I (CHARIOT) #57: Sat Dec  5 23:44:15 JST 1998    tsutsui@chariot:/usr/src/sys/arch/sun3/compile/CHARIOT sun3

>Description:
sun3x kernel with MACHINE_NEW_NONCONTIG does not work currently.
It may hung during boot, cause unexpected core dump,
or cannot get PROM prompt after halt. UVM requires
MACHINE_NEW_NONCONTIG, so sun3x cannot switch to UVM.

Comments in sun3x/pmap.c say that a few pages in the last
memory bank are reserved for PROM, but pmap_page_upload() which
is used on MACHINE_NEW_NONCONTIG does not take care about it.
That may cause the problem.

>How-To-Repeat:
Make sun3x kernel with #define MACHINE_NEW_NONCONTIG in vmparam3x.h
and boot it.

>Fix:
Preserve the memory reserved for PROM in sun3x/pmap.c.
I'm not sure my fix is appropriate, but my kernel with UVM
and MACHINE_NEW_NONCONTIG seems to work fine.

--- sys/arch/sun3/sun3x/machdep.c.orig	Wed Nov 25 21:20:49 1998
+++ sys/arch/sun3/sun3x/machdep.c	Sat Dec  5 12:43:56 1998
@@ -125,6 +125,8 @@
 #endif
 
 int	physmem;
+int	totalphysmem;
+int	resvmem;
 int	fputype;
 caddr_t	msgbufaddr;
 
@@ -306,8 +308,9 @@
 	identifycpu();
 	initfpu();	/* also prints FPU type */
 
-	size = ptoa(physmem);
-	printf("real  mem = %dK (0x%lx)\n", (size >> 10), size);
+	size = ptoa(totalphysmem);
+	printf("real  mem = %ldK (0x%lx), %ldK reserved for PROM\n",
+	       (size >> 10), size, (ptoa(resvmem) >> 10));
 
 	/*
 	 * Find out how much space we need, allocate it,
@@ -435,7 +438,7 @@
 #else
 	size = ptoa(cnt.v_free_count);
 #endif
-	printf("avail mem = %dK (0x%lx)\n", (size >> 10), size);
+	printf("avail mem = %ldK (0x%lx)\n", (size >> 10), size);
 	printf("using %d buffers containing %d bytes of memory\n",
 		   nbuf, bufpages * CLBYTES);
 
--- sys/arch/sun3/sun3x/pmap.c.orig	Wed Jul  8 20:10:32 1998
+++ sys/arch/sun3/sun3x/pmap.c	Sat Dec  5 12:43:56 1998
@@ -146,6 +146,8 @@
 /* XXX - What headers declare these? */
 extern struct pcb *curpcb;
 extern int physmem;
+extern int totalphysmem;
+extern int resvmem;
 
 extern void copypage __P((const void*, void*));
 extern void zeropage __P((void*));
@@ -581,8 +583,6 @@
  ** - functions required by the Mach VM Pmap interface, with MACHINE_CONTIG
  **   defined.
  **/
-#ifdef INCLUDED_IN_PMAP_H
-void   pmap_bootstrap __P((void));
 void  *pmap_bootstrap_alloc __P((int));
 void   pmap_enter __P((pmap_t, vm_offset_t, vm_offset_t, vm_prot_t, boolean_t));
 pmap_t pmap_create __P((vm_size_t));
@@ -593,8 +593,10 @@
 void   pmap_clear_modify __P((vm_offset_t));
 vm_offset_t pmap_extract __P((pmap_t, vm_offset_t));
 int    pmap_page_index __P((vm_offset_t));
+#if !defined(MACHINE_NEW_NONCONTIG)
 u_int  pmap_free_pages __P((void));
-#endif /* INCLUDED_IN_PMAP_H */
+boolean_t   pmap_next_page __P((vm_offset_t *));
+#endif /* MACHINE_NEW_NONCONTIG */
 void pmap_pinit __P((pmap_t));
 void pmap_release __P((pmap_t));
 
@@ -677,15 +679,6 @@
 		membank = membank->next;
 	}
 
-	/*
-	 * XXX The last bank of memory should be reduced to exclude the
-	 * physical pages needed by the PROM monitor from being used
-	 * in the VM system.  XXX - See below - Fix!
-	 */
-	pmap_membank->pmem_start = membank->address;
-	pmap_membank->pmem_end = membank->address + membank->size;
-	pmap_membank->pmem_next = NULL;
-
 #if 0	/* XXX - Need to integrate this! */
 	/*
 	 * The last few pages of physical memory are "owned" by
@@ -701,7 +694,20 @@
 #endif	/* XXX */
 
 	total_phys_mem += membank->size;	/* XXX see above */
-	physmem = btoc(total_phys_mem);
+	totalphysmem = btoc(total_phys_mem);
+	physmem = btoc(*romVectorPtr->memoryAvail);
+	resvmem = btoc(total_phys_mem - *romVectorPtr->memoryAvail);
+
+	/*
+	 * XXX The last bank of memory should be reduced to exclude the
+	 * physical pages needed by the PROM monitor from being used
+	 * in the VM system.  XXX - See below - Fix!
+	 */
+	pmap_membank->pmem_start = membank->address;
+	pmap_membank->pmem_end = membank->address + membank->size -
+		(total_phys_mem - *romVectorPtr->memoryAvail);
+	pmap_membank->pmem_end = m68k_trunc_page(pmap_membank->pmem_end);
+	pmap_membank->pmem_next = NULL;
 
 	/*
 	 * Avail_end is set to the first byte of physical memory
@@ -710,9 +716,7 @@
 	 *
 	 * XXX - The setting of avail_end is a temporary ROM saving hack.
 	 */
-	avail_end = pmap_membank->pmem_end -
-		(total_phys_mem - *romVectorPtr->memoryAvail);
-	avail_end = m68k_trunc_page(avail_end);
+	avail_end = pmap_membank->pmem_end;
 
 	/*
 	 * First allocate enough kernel MMU tables to map all
@@ -3755,10 +3759,6 @@
 	vm_offset_t *pa;
 {
 	static struct pmap_physmem_struct *curbank = avail_mem;
-
-	/* XXX - temporary ROM saving hack. */
-	if (avail_next >= avail_end)
-		return FALSE;
 
 	if (avail_next >= curbank->pmem_end)
 		if (curbank->pmem_next == NULL)
--- sys/arch/sun3/include/vmparam3x.h.orig	Wed Jul  8 20:10:27 1998
+++ sys/arch/sun3/include/vmparam3x.h	Sat Dec  5 12:46:28 1998
@@ -106,10 +106,6 @@
 #define VM_KMEM_SIZE		(NKMEMCLUSTERS*CLBYTES)
 #define VM_PHYS_SIZE		(USRIOSIZE*CLBYTES)
 
-#if 1	/* XXX */
-#define MACHINE_NONCONTIG	/* VM <=> pmap interface modifier */
-#else	/* XXX */
-/* XXX - This does not work correctly yet... */
 #define MACHINE_NEW_NONCONTIG	/* VM <=> pmap interface modifier */
 
 #define VM_PHYSSEG_MAX		4
@@ -122,4 +118,3 @@
 struct pmap_physseg {
 	/* NULL */
 };
-#endif	/* XXX */
>Audit-Trail:
>Unformatted: