ref: 4620f3da177f6d9f43ebde3e80cc1225d1e2f8d5
parent: adc608e8f12f5d236989ba00ca3adf240bdd268c
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Feb 13 21:44:19 EST 2015
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.
--- a/sys/src/9/zynq/etherzynq.c
+++ b/sys/src/9/zynq/etherzynq.c
@@ -295,7 +295,6 @@
{Ctlr *c;
int i;
- uintptr rxrpa, txrpa;
c = edev->ctlr;
c->r[NET_CTRL] = 0;
@@ -306,9 +305,9 @@
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 @@
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;
--- a/sys/src/9/zynq/fns.h
+++ b/sys/src/9/zynq/fns.h
@@ -66,7 +66,7 @@
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);
@@ -73,6 +73,3 @@
uintptr palookur(void *);
void screeninit(void);
int isaconfig(char*, int, ISAConf*);
-void *ucalloc(usize);
-void *ucallocalign(usize, int, int);
-void ucfree(void *);
--- a/sys/src/9/zynq/main.c
+++ b/sys/src/9/zynq/main.c
@@ -380,11 +380,10 @@
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();
--- 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 @@
return;
mpcore = vmap(MPCORE_BASE, 0x2000);
slcr = vmap(SLCR_BASE, 0x1000);
+ ocm = vmap(OCM_BASE, -OCM_BASE);
}
void
@@ -246,28 +248,36 @@
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 @@
/* 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;
}
--
⑨