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.
This commit is contained in:
cinap_lenrek 2015-02-14 02:44:19 +01:00
parent 48c5cf1f11
commit 6b2d1f0186
4 changed files with 48 additions and 39 deletions

View file

@ -295,7 +295,6 @@ ethinit(Ether *edev)
{ {
Ctlr *c; Ctlr *c;
int i; int i;
uintptr rxrpa, txrpa;
c = edev->ctlr; c = edev->ctlr;
c->r[NET_CTRL] = 0; 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_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[SPEC_ADDR1_TOP] = edev->ea[4] | edev->ea[5] << 8;
c->r[DMA_CFG] = TXCHKSUMEN | (Rbsz/64) << 16 | 1 << 10 | 3 << 8 | 0x10; c->r[DMA_CFG] = TXCHKSUMEN | (Rbsz/64) << 16 | 1 << 10 | 3 << 8 | 0x10;
rxrpa = ualloc(8 * RXRING, &c->rxr); c->rxr = ucalloc(8 * RXRING);
txrpa = ualloc(8 * TXRING, &c->txr); c->txr = ucalloc(8 * TXRING);
c->rxs = xspanalloc(4 * RXRING, 4, 0); c->rxs = xspanalloc(4 * RXRING, 4, 0);
c->txs = xspanalloc(4 * TXRING, 4, 0); c->txs = xspanalloc(4 * TXRING, 4, 0);
for(i = 0; i < 2 * RXRING; ){ for(i = 0; i < 2 * RXRING; ){
@ -324,8 +323,8 @@ ethinit(Ether *edev)
c->txr[i++] = 1<<31; c->txr[i++] = 1<<31;
} }
c->txr[2 * (TXRING - 1)] |= 1<<30; c->txr[2 * (TXRING - 1)] |= 1<<30;
c->r[RX_QBAR] = rxrpa; c->r[RX_QBAR] = PADDR(c->rxr);
c->r[TX_QBAR] = txrpa; c->r[TX_QBAR] = PADDR(c->txr);
c->r[NET_CTRL] = MDEN | TXEN | RXEN; c->r[NET_CTRL] = MDEN | TXEN | RXEN;
c->r[INTR_EN] = MGMTDONE | TXUNDER | RXCOMPL | RXUSED | RXOVER; c->r[INTR_EN] = MGMTDONE | TXUNDER | RXCOMPL | RXUSED | RXOVER;

View file

@ -66,13 +66,10 @@ void clinvdse(void *, void *);
void invaldln(void *); void invaldln(void *);
void cleandln(void *); void cleandln(void *);
void clinvdln(void *); void clinvdln(void *);
uintptr ualloc(ulong, void **); void* ucalloc(ulong);
void clean2pa(uintptr, uintptr); void clean2pa(uintptr, uintptr);
void inval2pa(uintptr, uintptr); void inval2pa(uintptr, uintptr);
void archinit(void); void archinit(void);
uintptr palookur(void *); uintptr palookur(void *);
void screeninit(void); void screeninit(void);
int isaconfig(char*, int, ISAConf*); int isaconfig(char*, int, ISAConf*);
void *ucalloc(usize);
void *ucallocalign(usize, int, int);
void ucfree(void *);

View file

@ -380,11 +380,10 @@ mpinit(void)
coherence(); coherence();
cleandse((uchar*)KZERO, (uchar*)0xFFFFFFFF); cleandse((uchar*)KZERO, (uchar*)0xFFFFFFFF);
v = tmpmap(0xFFFFF000); v = KADDR(0xFFFFF000);
v[0xFF0/4] = PADDR(mpbootstrap); v[0xFF0/4] = PADDR(mpbootstrap);
coherence(); coherence();
cleandse(v, (uchar*)v+BY2PG); cleandse(v, (uchar*)v+BY2PG);
tmpunmap(v);
sendevent(); sendevent();
synccycles(); synccycles();

View file

@ -6,6 +6,7 @@
#include "io.h" #include "io.h"
ulong *mpcore, *slcr; ulong *mpcore, *slcr;
uchar *ocm;
void void
mmuinit(void) mmuinit(void)
@ -19,6 +20,7 @@ mmuinit(void)
return; return;
mpcore = vmap(MPCORE_BASE, 0x2000); mpcore = vmap(MPCORE_BASE, 0x2000);
slcr = vmap(SLCR_BASE, 0x1000); slcr = vmap(SLCR_BASE, 0x1000);
ocm = vmap(OCM_BASE, -OCM_BASE);
} }
void void
@ -246,28 +248,36 @@ countpagerefs(ulong *, int)
print("countpagerefs\n"); print("countpagerefs\n");
} }
void *
kaddr(uintptr u)
{
if(u >= (uintptr)-KZERO)
panic("kaddr: pa=%#.8lux", u);
return (void *)(u + KZERO);
}
uintptr uintptr
paddr(void *v) paddr(void *v)
{ {
if((uintptr)v < KZERO) if((uintptr)v >= KZERO)
panic("paddr: va=%#.8lux", (uintptr) v); return (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;
}
void *
kaddr(uintptr u)
{
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 uintptr
cankaddr(uintptr u) cankaddr(uintptr u)
{ {
if(u >= (uintptr)-KZERO) if(u < (uintptr)-KZERO)
return 0; return -KZERO - u;
return -KZERO - u; if(u >= OCM_BASE)
return -u;
return 0;
} }
KMap * KMap *
@ -401,22 +411,26 @@ vmap(uintptr pa, ulong sz)
/* nasty things happen when there are cache entries for uncached memory /* nasty things happen when there are cache entries for uncached memory
so must make sure memory is not mapped ANYWHERE cached */ so must make sure memory is not mapped ANYWHERE cached */
uintptr void*
ualloc(ulong len, void **va) ucalloc(ulong len)
{ {
static uintptr free = OCM_BASE; static uchar *free = nil;
uintptr pa; static Lock l;
uchar *va;
if(len == 0) if(len == 0)
panic("ualloc: len == 0"); panic("ualloc: len == 0");
ilock(&l);
if(free == nil)
free = ocm + -OCM_BASE - BY2PG; /* last page is cpu1 bootstrap */
len = PGROUND(len); len = PGROUND(len);
if(free + len < OCM_BASE) free -= len;
if(free < ocm)
panic("ualloc: out of uncached memory"); panic("ualloc: out of uncached memory");
pa = free; va = free;
free += len; iunlock(&l);
if(va != nil){
*va = vmap(pa, len); invaldse(va, va + len);
invaldse(*va, (char *) *va + len); return (void*)va;
}
return pa;
} }