From b59191ae10a965e9d6be556710e6bfed908c881f Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 27 May 1999 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1999-05-27 --- pc/devlml.c | 27 ++++++- port/alloc.c | 209 +++++++++++++++++++++++++++++++++++++++++++------ port/devssl.c | 4 +- port/portfns.h | 2 + port/qio.c | 150 +---------------------------------- 5 files changed, 214 insertions(+), 178 deletions(-) diff --git a/pc/devlml.c b/pc/devlml.c index 06819221c445ec4e34587d171500871c719da8cf..45c16c0442c3aa8b8f04b9189b48f0a89141d842 100644 --- a/pc/devlml.c +++ b/pc/devlml.c @@ -264,8 +264,11 @@ lmlreset(void) { Physseg segbuf; Physseg segreg; + Physseg seggrab; ulong regpa; ulong cdsize; + ulong *grabpa; + ulong grablen; int i; pcidev = pcimatch(nil, PCI_VENDOR_ZORAN, PCI_DEVICE_ZORAN_36067); @@ -279,8 +282,17 @@ lmlreset(void) return; } + grablen = (720 * 480 * 2 * 2 + BY2PG - 1) & ~(BY2PG - 1); + grabpa = (ulong *)xspanalloc(grablen, BY2PG, 0); + if (grabpa == nil) { + print("devlml: xspanalloc(%lux, %ux, 0)\n", grablen, BY2PG); + return; + } + *grabpa = PADDR(grabpa); + print("Installing Motion JPEG driver %s\n", MJPG_VERSION); - print("Buffer at 0x%.8lux, size 0x%.8lux\n", codeData, cdsize); + print("MJPG buffer at 0x%.8lux, size 0x%.8lux\n", codeData, cdsize); + print("Grab buffer at 0x%.8lux, size 0x%.8lux\n", grabpa, grablen); // Get access to DMA memory buffer memset(codeData, 0xAA, sizeof(CodeData)); @@ -327,7 +339,18 @@ lmlreset(void) segreg.pa = (ulong)regpa; segreg.size = pcidev->mem[0].size; if (addphysseg(&segreg) == -1) { - print("lml: physsegment: lmlmjpg\n"); + print("lml: physsegment: lmlregs\n"); + return; + } + + memset(&seggrab, 0, sizeof(seggrab)); + seggrab.attr = SG_PHYSICAL; + seggrab.name = smalloc(NAMELEN); + snprint(seggrab.name, NAMELEN, "lmlgrab"); + seggrab.pa = (ulong)PADDR(grabpa); + seggrab.size = grablen; + if (addphysseg(&seggrab) == -1) { + print("lml: physsegment: lmlgrab\n"); return; } return; diff --git a/port/alloc.c b/port/alloc.c index 676b33512a101abbab08f281eb7e0971324c8287..773d530e64ddcf2345668b479ea1baf7e737b8dc 100644 --- a/port/alloc.c +++ b/port/alloc.c @@ -360,6 +360,15 @@ poolread(char *va, int count, ulong offset) return n; } +static void +tagwithpc(void *v, ulong pc) +{ + Bhdr *h; + + D2B(h, v); + B2T(h)->pad = pc; +} + void* malloc(ulong size) { @@ -368,11 +377,8 @@ malloc(ulong size) v = poolalloc(mainmem, size); if(v != nil) memset(v, 0, size); -if(v != nil){ -Bhdr *h; -D2B(h, v); -B2T(h)->pad = getcallerpc(&size); -} + if(v != nil) + tagwithpc(v, getcallerpc(&size)); return v; } @@ -388,11 +394,7 @@ smalloc(ulong size) tsleep(&up->sleep, return0, 0, 100); } memset(v, 0, size); -{ -Bhdr *h; -D2B(h, v); -B2T(h)->pad = getcallerpc(&size); -} + tagwithpc(v, getcallerpc(&size)); return v; } @@ -404,23 +406,16 @@ mallocz(ulong size, int clr) v = poolalloc(mainmem, size); if(clr && v != nil) memset(v, 0, size); -if(v != nil){ -Bhdr *h; -D2B(h, v); -B2T(h)->pad = getcallerpc(&size); -} + if(v != nil) + tagwithpc(v, getcallerpc(&size)); return v; } void free(void *v) { - Bhdr *b; - - if(v != nil) { - D2B(b, v); + if(v != nil) poolfree(mainmem, v); - } } void* @@ -444,11 +439,8 @@ realloc(void *v, ulong size) memmove(nv, v, osize); free(v); } -{ -Bhdr *h; -D2B(h, nv); -B2T(h)->pad = getcallerpc(&size); -} + if(nv != nil) + tagwithpc(nv, getcallerpc(&v)); return nv; } @@ -635,3 +627,170 @@ recur(Bhdr *t) return 0; return recur(t->right) && recur(t->left); } + +enum +{ + Hdrspc = 64, /* leave room for high-level headers */ + Bdead = 0x51494F42, /* "QIOB" */ +}; + +struct +{ + Lock; + ulong bytes; +} ialloc; + +/* + * allocate blocks, round the data base upt to a multiple of BLOCKALIGN. + */ +Block* +allocb(int size) +{ + Block *b; + ulong addr; + int n; + + n = sizeof(Block) + size; + b = poolalloc(mainmem, n+Hdrspc); + if(b == 0) + exhausted("Blocks"); + memset(b, 0, sizeof(Block)); + + /* align start of data portion by rounding up */ + addr = (ulong)b; + addr = ROUND(addr + sizeof(Block), BLOCKALIGN); + b->base = (uchar*)addr; + + /* align end of data portion by rounding down */ + b->lim = ((uchar*)b) + msize(b); + addr = (ulong)(b->lim); + addr = addr & ~(BLOCKALIGN-1); + b->lim = (uchar*)addr; + + /* leave sluff at beginning for added headers */ + b->rp = b->lim - ROUND(size, BLOCKALIGN); + if(b->rp < b->base) + panic("allocb"); + b->wp = b->rp; + tagwithpc(b, getcallerpc(&size)); + + return b; +} + +/* + * interrupt time allocation + */ +Block* +iallocb(int size) +{ + Block *b; + ulong addr; + int n; + + if(ialloc.bytes > conf.ialloc){ + print("iallocb: limited %lud/%lud\n", + ialloc.bytes, conf.ialloc); + return 0; + } + + n = sizeof(Block) + size; + b = poolalloc(mainmem, n+Hdrspc); + if(b == 0){ + print("iallocb: no memory %lud/%lud\n", + ialloc.bytes, conf.ialloc); + return nil; + } + memset(b, 0, sizeof(Block)); + + /* align start of data portion by rounding up */ + addr = (ulong)b; + addr = ROUND(addr + sizeof(Block), BLOCKALIGN); + b->base = (uchar*)addr; + + /* align end of data portion by rounding down */ + b->lim = ((uchar*)b) + msize(b); + addr = (ulong)(b->lim); + addr = addr & ~(BLOCKALIGN-1); + b->lim = (uchar*)addr; + + /* leave sluff at beginning for added headers */ + b->rp = b->lim - ROUND(size, BLOCKALIGN); + if(b->rp < b->base) + panic("allocb"); + b->wp = b->rp; + + b->flag = BINTR; + + ilock(&ialloc); + ialloc.bytes += b->lim - b->base; + iunlock(&ialloc); + tagwithpc(b, getcallerpc(&size)); + + return b; +} + +void +freeb(Block *b) +{ + void *dead = (void*)Bdead; + + if(b == nil) + return; + + /* + * drivers which perform non cache coherent DMA manage their own buffer + * pool of uncached buffers and provide their own free routine. + */ + if(b->free) { + b->free(b); + return; + } + if(b->flag & BINTR) { + ilock(&ialloc); + ialloc.bytes -= b->lim - b->base; + iunlock(&ialloc); + } + + /* poison the block in case someone is still holding onto it */ + b->next = dead; + b->rp = dead; + b->wp = dead; + b->lim = dead; + b->base = dead; + + poolfree(mainmem, b); +} + +void +checkb(Block *b, char *msg) +{ + void *dead = (void*)Bdead; + + if(b == dead) + panic("checkb b %s %lux", msg, b); + if(b->base == dead || b->lim == dead || b->next == dead + || b->rp == dead || b->wp == dead){ + print("checkb: base 0x%8.8luX lim 0x%8.8luX next 0x%8.8luX\n", + b->base, b->lim, b->next); + print("checkb: rp 0x%8.8luX wp 0x%8.8luX\n", b->rp, b->wp); + panic("checkb dead: %s\n", msg); + } + + if(b->base > b->lim) + panic("checkb 0 %s %lux %lux", msg, b->base, b->lim); + if(b->rp < b->base) + panic("checkb 1 %s %lux %lux", msg, b->base, b->rp); + if(b->wp < b->base) + panic("checkb 2 %s %lux %lux", msg, b->base, b->wp); + if(b->rp > b->lim) + panic("checkb 3 %s %lux %lux", msg, b->rp, b->lim); + if(b->wp > b->lim) + panic("checkb 4 %s %lux %lux", msg, b->wp, b->lim); + +} + +void +iallocsummary(void) +{ + print("ialloc %lud/%lud\n", ialloc.bytes, conf.ialloc); +} diff --git a/port/devssl.c b/port/devssl.c index 5f4d72899afee4aacec699617a741f09917911e3..6f9fdff782c52c2b3de3e3a5256e08f2a5f73a24 100644 --- a/port/devssl.c +++ b/port/devssl.c @@ -992,9 +992,9 @@ sslwrite(Chan *c, void *a, long n, vlong off) if(s.s->c == 0) error("must set fd before algorithm"); + s.s->state = Sclear; + s.s->maxpad = s.s->max = (1<<15) - s.s->diglen - 1; if(strcmp(p, "clear") == 0){ - s.s->state = Sclear; - s.s->maxpad = s.s->max = (1<<15) - s.s->diglen - 1; goto out; } diff --git a/port/portfns.h b/port/portfns.h index a0dbb62d7ee7830686b7996449a2287525b9fca6..95ee514d8757a07378de73f34939741a9fd1795f 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -32,6 +32,7 @@ void chandevreset(void); void chanfree(Chan*); void chanrec(Mnt*); void checkalarms(void); +void checkb(Block*, char*); void cinit(void); Chan* cclone(Chan*, Chan*); void cclose(Chan*); @@ -115,6 +116,7 @@ long hostdomainwrite(char*, int); long hostownerwrite(char*, int); void iallocinit(void); Block* iallocb(int); +void iallocsumary(void); long ibrk(ulong, int); void ilock(Lock*); void iunlock(Lock*); diff --git a/port/qio.c b/port/qio.c index b7d9c66fe7440c635f1d04269a76d34a57d5fef5..a59af31b0cd831dee93c10b5f3d2d408b261f6ab 100644 --- a/port/qio.c +++ b/port/qio.c @@ -5,12 +5,6 @@ #include "fns.h" #include "../port/error.h" -struct -{ - Lock; - ulong bytes; -} ialloc; - static ulong padblockcnt; static ulong concatblockcnt; static ulong pullupblockcnt; @@ -62,162 +56,20 @@ enum Qclosed = (1<<2), Qflow = (1<<3), - Hdrspc = 64, /* leave room for high-level headers */ - - Bdead = 0x51494F42, /* "QIOB" */ - Maxatomic = 32*1024, }; -void -checkb(Block *b, char *msg) -{ - void *dead = (void*)Bdead; - - if(b == dead) - panic("checkb b %s %lux", msg, b); - if(b->base == dead || b->lim == dead || b->next == dead - || b->rp == dead || b->wp == dead){ - print("checkb: base 0x%8.8luX lim 0x%8.8luX next 0x%8.8luX\n", - b->base, b->lim, b->next); - print("checkb: rp 0x%8.8luX wp 0x%8.8luX\n", b->rp, b->wp); - panic("checkb dead: %s\n", msg); - } - - if(b->base > b->lim) - panic("checkb 0 %s %lux %lux", msg, b->base, b->lim); - if(b->rp < b->base) - panic("checkb 1 %s %lux %lux", msg, b->base, b->rp); - if(b->wp < b->base) - panic("checkb 2 %s %lux %lux", msg, b->base, b->wp); - if(b->rp > b->lim) - panic("checkb 3 %s %lux %lux", msg, b->rp, b->lim); - if(b->wp > b->lim) - panic("checkb 4 %s %lux %lux", msg, b->wp, b->lim); - -} - void ixsummary(void) { debugging ^= 1; - print("ialloc %lud/%lud %d\n", ialloc.bytes, conf.ialloc, debugging); + iallocsummary(); print("pad %lud, concat %lud, pullup %lud, copy %lud\n", padblockcnt, concatblockcnt, pullupblockcnt, copyblockcnt); print("consume %lud, produce %lud, qcopy %lud\n", consumecnt, producecnt, qcopycnt); } -/* - * allocate blocks (round data base address to 64 bit boundary). - * if mallocz gives us more than we asked for, leave room at the front - * for header. - */ -Block* -allocb(int size) -{ - Block *b; - ulong addr; - int n; - - n = sizeof(Block) + size; - b = mallocz(n+Hdrspc, 0); - if(b == 0) - exhausted("Blocks"); - memset(b, 0, sizeof(Block)); - - /* align start of data portion by rounding up */ - addr = (ulong)b; - addr = ROUND(addr + sizeof(Block), BLOCKALIGN); - b->base = (uchar*)addr; - - /* align end of data portion by rounding down */ - b->lim = ((uchar*)b) + msize(b); - addr = (ulong)(b->lim); - addr = addr & ~(BLOCKALIGN-1); - b->lim = (uchar*)addr; - - /* leave sluff at beginning for added headers */ - b->rp = b->lim - ROUND(size, BLOCKALIGN); - if(b->rp < b->base) - panic("allocb"); - b->wp = b->rp; - - return b; -} - -/* - * interrupt time allocation - */ -Block* -iallocb(int size) -{ - Block *b; - ulong addr; - int n; - - if(ialloc.bytes > conf.ialloc){ - print("iallocb: limited %lud/%lud\n", - ialloc.bytes, conf.ialloc); - return 0; - } - - n = sizeof(Block) + size + (BY2V-1); - b = mallocz(n+Hdrspc, 0); - if(b == nil){ - print("iallocb: no memory %lud/%lud\n", - ialloc.bytes, conf.ialloc); - return nil; - } - memset(b, 0, sizeof(Block)); - - addr = (ulong)b; - addr = ROUND(addr + sizeof(Block), BY2V); - b->base = (uchar*)addr; - b->lim = ((uchar*)b) + msize(b); - b->rp = b->base; - n = b->lim - b->base - size; - b->rp += n & ~(BY2V-1); - b->wp = b->rp; - - b->flag = BINTR; - - ilock(&ialloc); - ialloc.bytes += b->lim - b->base; - iunlock(&ialloc); - - return b; -} - -void -freeb(Block *b) -{ - void *dead = (void*)Bdead; - - /* - * drivers which perform non cache coherent DMA manage their own buffer - * pool of uncached buffers and provide their own free routine. - */ - if(b->free) { - b->free(b); - return; - } - if(b->flag & BINTR) { - ilock(&ialloc); - ialloc.bytes -= b->lim - b->base; - iunlock(&ialloc); - } - - /* poison the block in case someone is still holding onto it */ - b->next = dead; - b->rp = dead; - b->wp = dead; - b->lim = dead; - b->base = dead; - - free(b); -} - /* * free a list of blocks */