diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-02-14 02:44:19 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-02-14 02:44:19 +0100 |
commit | 6b2d1f0186f2e38a3b0cd6a19b5980dccb045c3c (patch) | |
tree | bba3d0a51c09b06ea36000c8123c1a2a6c44ade4 /sys/src/9 | |
parent | 48c5cf1f11fb6b8b620e5ed9269a528b5f6633f4 (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')
-rw-r--r-- | sys/src/9/zynq/etherzynq.c | 11 | ||||
-rw-r--r-- | sys/src/9/zynq/fns.h | 5 | ||||
-rw-r--r-- | sys/src/9/zynq/main.c | 3 | ||||
-rw-r--r-- | sys/src/9/zynq/mmu.c | 66 |
4 files changed, 47 insertions, 38 deletions
diff --git a/sys/src/9/zynq/etherzynq.c b/sys/src/9/zynq/etherzynq.c index 775d219f4..c24ded981 100644 --- a/sys/src/9/zynq/etherzynq.c +++ b/sys/src/9/zynq/etherzynq.c @@ -295,7 +295,6 @@ ethinit(Ether *edev) { Ctlr *c; int i; - uintptr rxrpa, txrpa; c = edev->ctlr; c->r[NET_CTRL] = 0; @@ -306,9 +305,9 @@ ethinit(Ether *edev) c->r[SPEC_ADDR1_BOT] = edev->ea[0] | edev->ea[1] << 8 | edev->ea[2] << 16 | edev->ea[3] << 24; c->r[SPEC_ADDR1_TOP] = edev->ea[4] | edev->ea[5] << 8; c->r[DMA_CFG] = TXCHKSUMEN | (Rbsz/64) << 16 | 1 << 10 | 3 << 8 | 0x10; - - rxrpa = ualloc(8 * RXRING, &c->rxr); - txrpa = ualloc(8 * TXRING, &c->txr); + + c->rxr = ucalloc(8 * RXRING); + c->txr = ucalloc(8 * TXRING); c->rxs = xspanalloc(4 * RXRING, 4, 0); c->txs = xspanalloc(4 * TXRING, 4, 0); for(i = 0; i < 2 * RXRING; ){ @@ -324,8 +323,8 @@ ethinit(Ether *edev) c->txr[i++] = 1<<31; } c->txr[2 * (TXRING - 1)] |= 1<<30; - c->r[RX_QBAR] = rxrpa; - c->r[TX_QBAR] = txrpa; + c->r[RX_QBAR] = PADDR(c->rxr); + c->r[TX_QBAR] = PADDR(c->txr); c->r[NET_CTRL] = MDEN | TXEN | RXEN; c->r[INTR_EN] = MGMTDONE | TXUNDER | RXCOMPL | RXUSED | RXOVER; diff --git a/sys/src/9/zynq/fns.h b/sys/src/9/zynq/fns.h index 962100aef..ce27a1c04 100644 --- a/sys/src/9/zynq/fns.h +++ b/sys/src/9/zynq/fns.h @@ -66,13 +66,10 @@ void clinvdse(void *, void *); void invaldln(void *); void cleandln(void *); void clinvdln(void *); -uintptr ualloc(ulong, void **); +void* ucalloc(ulong); void clean2pa(uintptr, uintptr); void inval2pa(uintptr, uintptr); void archinit(void); uintptr palookur(void *); void screeninit(void); int isaconfig(char*, int, ISAConf*); -void *ucalloc(usize); -void *ucallocalign(usize, int, int); -void ucfree(void *); diff --git a/sys/src/9/zynq/main.c b/sys/src/9/zynq/main.c index f8a103b11..994628293 100644 --- a/sys/src/9/zynq/main.c +++ b/sys/src/9/zynq/main.c @@ -380,11 +380,10 @@ mpinit(void) coherence(); cleandse((uchar*)KZERO, (uchar*)0xFFFFFFFF); - v = tmpmap(0xFFFFF000); + v = KADDR(0xFFFFF000); v[0xFF0/4] = PADDR(mpbootstrap); coherence(); cleandse(v, (uchar*)v+BY2PG); - tmpunmap(v); sendevent(); synccycles(); 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; } |