shithub: riscv

Download patch

ref: 91994dc5d8ad4fbd4eb73f44855aafdb4bbbc3ba
parent: bd23963c8f359d0a3c802f7cd96b51b4d36b01ac
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Jul 2 17:12:40 EDT 2020

bcm64: handle 8GB of physical memory for raspberry pi4

widen and move the KMAP window to a new address so we can
handle the 8GB of physical memory of the new raspberry pi4.

the new memory map on pi4 uses the following 4 banks:

0x000000000	0x03e600000
0x040000000	0x0fc000000 <- soc.dramsize (only < 4GB)
0x100000000	0x180000000
0x180000000 0x200000000

--- a/sys/src/9/bcm64/mem.h
+++ b/sys/src/9/bcm64/mem.h
@@ -39,8 +39,10 @@
 #define STACKALIGN(sp)	((sp) & ~7)		/* bug: assure with alloc */
 #define TRAPFRAMESIZE	(38*8)
 
-#define KSEG0		(0xFFFFFFFE00000000ULL)
-#define KMAP		(0xFFFFFFFE00000000ULL)
+#define KSEG0		(0xFFFFFFFC00000000ULL)
+
+#define KMAP		(0xFFFFFFFC00000000ULL)
+#define KMAPEND		(0xFFFFFFFF00000000ULL)
 
 #define FRAMEBUFFER	(0xFFFFFFFFA0000000ULL|PTEWT)
 
--- a/sys/src/9/bcm64/mmu.c
+++ b/sys/src/9/bcm64/mmu.c
@@ -132,12 +132,13 @@
 	return nil;
 }
 
-/* KMAP maps all of ram (up to 4GB) */
 static void*
 kmapaddr(uintptr pa)
 {
 	if(pa < (uintptr)-KZERO)
 		return (void*)(pa + KZERO);
+	if(pa >= KMAPEND-KMAP)
+		panic("kmapaddr: pa=%#p pc=%#p", pa, getcallerpc(&pa));
 	return (void*)(pa + KMAP);
 }
 
@@ -275,12 +276,16 @@
 
 	pa = PGROUND((uintptr)end)-KZERO;
 	for(i=0; i<nelem(conf.mem); i++){
-		if(conf.mem[i].limit <= conf.mem[i].base
-		|| conf.mem[i].base >= PHYSDRAM + soc.dramsize){
-			conf.mem[i].base = conf.mem[i].limit = 0;
+		if(conf.mem[i].limit >= KMAPEND-KMAP)
+			conf.mem[i].limit = KMAPEND-KMAP;
+
+		if(conf.mem[i].limit <= conf.mem[i].base){
+			conf.mem[i].limit = conf.mem[i].base = 0;
 			continue;
 		}
-		if(conf.mem[i].limit > PHYSDRAM + soc.dramsize)
+
+		if(conf.mem[i].base < PHYSDRAM + soc.dramsize
+		&& conf.mem[i].limit > PHYSDRAM + soc.dramsize)
 			conf.mem[i].limit = PHYSDRAM + soc.dramsize;
 
 		/* take kernel out of allocatable space */