summaryrefslogtreecommitdiff
path: root/sys/src/9/zynq/mmu.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-02-14 02:44:19 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2015-02-14 02:44:19 +0100
commit6b2d1f0186f2e38a3b0cd6a19b5980dccb045c3c (patch)
treebba3d0a51c09b06ea36000c8123c1a2a6c44ade4 /sys/src/9/zynq/mmu.c
parent48c5cf1f11fb6b8b620e5ed9269a528b5f6633f4 (diff)
zynq: do fixed mapping for ocm memory on boot and make kaddr() and paddr() work with it
map the whole ocm memory on boot so we can translate physical to virtual addresses and back for uncached memory using KADDR() and PADDR(). replace ualloc() with ucalloc() returning virtual address. physical address can be acquired with PADDR() now. as ocm is now always mapped, use KADDR() instead of tmpmap() for mp bootstrap.
Diffstat (limited to 'sys/src/9/zynq/mmu.c')
-rw-r--r--sys/src/9/zynq/mmu.c66
1 files changed, 40 insertions, 26 deletions
diff --git a/sys/src/9/zynq/mmu.c b/sys/src/9/zynq/mmu.c
index 66816225f..14f915759 100644
--- a/sys/src/9/zynq/mmu.c
+++ b/sys/src/9/zynq/mmu.c
@@ -6,6 +6,7 @@
#include "io.h"
ulong *mpcore, *slcr;
+uchar *ocm;
void
mmuinit(void)
@@ -19,6 +20,7 @@ mmuinit(void)
return;
mpcore = vmap(MPCORE_BASE, 0x2000);
slcr = vmap(SLCR_BASE, 0x1000);
+ ocm = vmap(OCM_BASE, -OCM_BASE);
}
void
@@ -246,28 +248,36 @@ countpagerefs(ulong *, int)
print("countpagerefs\n");
}
-void *
-kaddr(uintptr u)
+uintptr
+paddr(void *v)
{
- if(u >= (uintptr)-KZERO)
- panic("kaddr: pa=%#.8lux", u);
- return (void *)(u + KZERO);
+ if((uintptr)v >= KZERO)
+ return (uintptr)v-KZERO;
+ if((uintptr)v >= VMAP)
+ return ((uintptr)v & (BY2PG-1)) | PPN(((ulong*)VMAPL2)[(uintptr)v-VMAP >> PGSHIFT]);
+ panic("paddr: va=%#p pc=%#p", v, getcallerpc(&v));
+ return 0;
}
-uintptr
-paddr(void *v)
+void *
+kaddr(uintptr u)
{
- if((uintptr)v < KZERO)
- panic("paddr: va=%#.8lux", (uintptr) v);
- return (uintptr)v - KZERO;
+ if(u < (uintptr)-KZERO)
+ return (void *)(u + KZERO);
+ if(u >= OCM_BASE)
+ return (void *)(ocm + (u - OCM_BASE));
+ panic("kaddr: pa=%#p pc=%#p", u, getcallerpc(&u));
+ return nil;
}
uintptr
cankaddr(uintptr u)
{
- if(u >= (uintptr)-KZERO)
- return 0;
- return -KZERO - u;
+ if(u < (uintptr)-KZERO)
+ return -KZERO - u;
+ if(u >= OCM_BASE)
+ return -u;
+ return 0;
}
KMap *
@@ -401,22 +411,26 @@ vmap(uintptr pa, ulong sz)
/* nasty things happen when there are cache entries for uncached memory
so must make sure memory is not mapped ANYWHERE cached */
-uintptr
-ualloc(ulong len, void **va)
+void*
+ucalloc(ulong len)
{
- static uintptr free = OCM_BASE;
- uintptr pa;
-
+ static uchar *free = nil;
+ static Lock l;
+ uchar *va;
+
if(len == 0)
panic("ualloc: len == 0");
+
+ ilock(&l);
+ if(free == nil)
+ free = ocm + -OCM_BASE - BY2PG; /* last page is cpu1 bootstrap */
len = PGROUND(len);
- if(free + len < OCM_BASE)
+ free -= len;
+ if(free < ocm)
panic("ualloc: out of uncached memory");
- pa = free;
- free += len;
- if(va != nil){
- *va = vmap(pa, len);
- invaldse(*va, (char *) *va + len);
- }
- return pa;
+ va = free;
+ iunlock(&l);
+
+ invaldse(va, va + len);
+ return (void*)va;
}