changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > plan9front / sys/src/9/bcm64/mmu.c

revision 7239: c0e23a8829f7
parent 7238: 9fe2319844b6
child 7244: 2e8af1bf191d
     1.1--- a/sys/src/9/bcm64/mmu.c
     1.2+++ b/sys/src/9/bcm64/mmu.c
     1.3@@ -12,6 +12,9 @@ mmu0init(uintptr *l1)
     1.4 
     1.5 	/* 0 identity map */
     1.6 	pe = PHYSDRAM + soc.dramsize;
     1.7+	if(pe > (uintptr)-KZERO)
     1.8+		pe = (uintptr)-KZERO;
     1.9+
    1.10 	for(pa = PHYSDRAM; pa < pe; pa += PGLSZ(1))
    1.11 		l1[PTL1X(pa, 1)] = pa | PTEVALID | PTEBLOCK | PTEWRITE | PTEAF
    1.12 			 | PTEKERNEL | PTESH(SHARE_INNER);
    1.13@@ -52,6 +55,8 @@ mmu0clear(uintptr *l1)
    1.14 	uintptr va, pa, pe;
    1.15 
    1.16 	pe = PHYSDRAM + soc.dramsize;
    1.17+	if(pe > (uintptr)-KZERO)
    1.18+		pe = (uintptr)-KZERO;
    1.19 
    1.20 	for(pa = PHYSDRAM, va = KZERO; pa < pe; pa += PGLSZ(1), va += PGLSZ(1)){
    1.21 		if(PTL1X(pa, 1) != PTL1X(va, 1))
    1.22@@ -78,6 +83,8 @@ mmuidmap(uintptr *l1)
    1.23 	flushtlb();
    1.24 
    1.25 	pe = PHYSDRAM + soc.dramsize;
    1.26+	if(pe > (uintptr)-KZERO)
    1.27+		pe = (uintptr)-KZERO;
    1.28 
    1.29 	for(pa = PHYSDRAM, va = KZERO; pa < pe; pa += PGLSZ(1), va += PGLSZ(1)){
    1.30 		if(PTL1X(pa, 1) != PTL1X(va, 1))
    1.31@@ -189,33 +196,18 @@ mmuwalk(uintptr va, int level)
    1.32 			pte &= ~(0xFFFFULL<<48 | BY2PG-1);
    1.33 			table = KADDR(pte);
    1.34 		} else {
    1.35-			if(i < 2){
    1.36-				pg = up->mmufree;
    1.37-				if(pg == nil)
    1.38-					return nil;
    1.39-				up->mmufree = pg->next;
    1.40-				switch(i){
    1.41-				case 0:
    1.42-					pg->va = va & -PGLSZ(1);
    1.43-					if((pg->next = up->mmul1) == nil)
    1.44-						up->mmul1tail = pg;
    1.45-					up->mmul1 = pg;
    1.46-					break;
    1.47-				case 1:
    1.48-					pg->va = va & -PGLSZ(2);
    1.49-					if((pg->next = up->mmul2) == nil)
    1.50-						up->mmul2tail = pg;
    1.51-					up->mmul2 = pg;
    1.52-					break;
    1.53-				}
    1.54-				memset(KADDR(pg->pa), 0, BY2PG);
    1.55-				coherence();
    1.56-				table[x] = pg->pa | PTEVALID | PTETABLE;
    1.57-				table = KADDR(pg->pa);
    1.58-			} else {
    1.59-				table[x] = PADDR(&m->mmul1[L1TABLEX(va, 2)]) | PTEVALID | PTETABLE;
    1.60-				table = &m->mmul1[L1TABLEX(va, 2)];
    1.61-			}
    1.62+			pg = up->mmufree;
    1.63+			if(pg == nil)
    1.64+				return nil;
    1.65+			up->mmufree = pg->next;
    1.66+			pg->va = va & -PGLSZ(i+1);
    1.67+			if((pg->next = up->mmuhead[i+1]) == nil)
    1.68+				up->mmutail[i+1] = pg;
    1.69+			up->mmuhead[i+1] = pg;
    1.70+			memset(KADDR(pg->pa), 0, BY2PG);
    1.71+			coherence();
    1.72+			table[x] = pg->pa | PTEVALID | PTETABLE;
    1.73+			table = KADDR(pg->pa);
    1.74 		}
    1.75 		x = PTLX(va, (uintptr)i);
    1.76 	}
    1.77@@ -318,20 +310,16 @@ putmmu(uintptr va, uintptr pa, Page *pg)
    1.78 static void
    1.79 mmufree(Proc *p)
    1.80 {
    1.81+	int i;
    1.82+
    1.83 	freeasid(p);
    1.84 
    1.85-	if(p->mmul1 == nil){
    1.86-		assert(p->mmul2 == nil);
    1.87-		return;
    1.88-	}
    1.89-	p->mmul1tail->next = p->mmufree;
    1.90-	p->mmufree = p->mmul1;
    1.91-	p->mmul1 = p->mmul1tail = nil;
    1.92-
    1.93-	if(PTLEVELS > 2){
    1.94-		p->mmul2tail->next = p->mmufree;
    1.95-		p->mmufree = p->mmul2;
    1.96-		p->mmul2 = p->mmul2tail = nil;
    1.97+	for(i=1; i<PTLEVELS; i++){
    1.98+		if(p->mmuhead[i] == nil)
    1.99+			break;
   1.100+		p->mmutail[i]->next = p->mmufree;
   1.101+		p->mmufree = p->mmuhead[i];
   1.102+		p->mmuhead[i] = p->mmutail[i] = nil;
   1.103 	}
   1.104 }
   1.105 
   1.106@@ -354,19 +342,9 @@ mmuswitch(Proc *p)
   1.107 		p->newtlb = 0;
   1.108 	}
   1.109 
   1.110-	if(PTLEVELS == 2){
   1.111-		for(t = p->mmul1; t != nil; t = t->next){
   1.112-			va = t->va;
   1.113-			m->mmul1[PTL1X(va, 1)] = t->pa | PTEVALID | PTETABLE;
   1.114-		}
   1.115-	} else {
   1.116-		for(t = p->mmul2; t != nil; t = t->next){
   1.117-			va = t->va;
   1.118-			m->mmul1[PTL1X(va, 2)] = t->pa | PTEVALID | PTETABLE;
   1.119-			if(PTLEVELS > 3)
   1.120-				m->mmul1[PTL1X(va, 3)] = PADDR(&m->mmul1[L1TABLEX(va, 2)]) |
   1.121-					PTEVALID | PTETABLE;
   1.122-		}
   1.123+	for(t = p->mmuhead[PTLEVELS-1]; t != nil; t = t->next){
   1.124+		va = t->va;
   1.125+		m->mmul1[PTL1X(va, PTLEVELS-1)] = t->pa | PTEVALID | PTETABLE;
   1.126 	}
   1.127 
   1.128 	if(allocasid(p))