~kris/9p

9hist

b59191ae10a965e9d6be556710e6bfed908c881f — David du Colombier 27 years ago 12bb386
Plan 9 from Bell Labs 1999-05-27
5 files changed, 214 insertions(+), 178 deletions(-)

M pc/devlml.c
M port/alloc.c
M port/devssl.c
M port/portfns.h
M port/qio.c
M pc/devlml.c => pc/devlml.c +25 -2
@@ 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; 

M port/alloc.c => port/alloc.c +184 -25
@@ 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);
}

M port/devssl.c => port/devssl.c +2 -2
@@ 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;
		}


M port/portfns.h => port/portfns.h +2 -0
@@ 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*);

M port/qio.c => port/qio.c +1 -149
@@ 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,46 56,14 @@ 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",


@@ 109,116 71,6 @@ ixsummary(void)
}

/*
 *  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
 */
void