Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/power/devbit.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname power/devbit.c 1990/0227
## diff -e /dev/null /n/bootesdump/1990/0227/sys/src/9/mips/devbit.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"errno.h"
#include	"devtab.h"

#include	"io.h"

typedef struct Bitmsg Bitmsg;
struct Bitmsg
{
	ulong	cmd;
	ulong	addr;
	ulong	count;
	ulong	result;
};

static struct
{
	QLock;
	int	open;
	Bitmsg	msg;
	char	buf[10*1024];
}bit;

#define	BITADDR	((Bitmsg**)(KZERO+0x7C))
#define	BITINTR	((char*)(UNCACHED|0x17c12001))

enum
{
	RESET,
	READ,
	WRITE,
};

void
bitsend(ulong cmd, void *addr, ulong count)
{
	bit.msg.cmd = cmd;
	bit.msg.addr = (ulong)addr;
	bit.msg.count = count;
	if(*BITADDR)
		panic("bitsend");
	*BITADDR = &bit.msg;
	wbflush();
	*BITINTR = 0x20;
}

void
bitsync(void)
{
	while(*BITADDR)
		;
}

void
bitreset(void)
{
	*BITADDR = 0;
	qlock(&bit);
	qunlock(&bit);
}

void
bitinit(void)
{
}

Chan*
bitattach(char *spec)
{
	return devattach('b', spec);
}

Chan*
bitclone(Chan *c, Chan *nc)
{
	return devclone(c, nc);
}

int	 
bitwalk(Chan *c, char *name)
{
	if(c->qid != CHDIR)
		return 0;
	if(strcmp(name, "bit") == 0){
		c->qid = 1;
		return 1;
	}
	return 0;
}

void	 
bitstat(Chan *c, char *dp)
{
	print("bitstat\n");
	error(0, Egreg);
}

Chan*
bitopen(Chan *c, int omode)
{
	if(c->qid!=1 || omode!=ORDWR)
		error(0, Eperm);
	qlock(&bit);
	if(bit.open){
		qunlock(&bit);
print("multiple bit open\n");
		error(0, Einuse);
	}
	bitsync();
	bitsend(RESET, 0, 0);
	bitsync();
	bit.open = 1;
	qunlock(&bit);
	c->mode = openmode(omode);
	c->flag |= COPEN;
	c->offset = 0;
	return c;
}

void	 
bitcreate(Chan *c, char *name, int omode, ulong perm)
{
	error(0, Eperm);
}

void	 
bitclose(Chan *c)
{
	qlock(&bit);
	bit.open = 0;
	qunlock(&bit);
}

/*
 * Read and write use physical addresses if they can, which they usually can.
 * Most I/O is from devmnt, which has local buffers.  Therefore just check
 * that buf is in KSEG0 and is at an even address.  The only killer is that
 * DMA counts from the bit device are mod 256, so devmnt must use oversize
 * buffers.
 */

long	 
bitread(Chan *c, void *buf, long n)
{
	switch(c->qid){
	case 1:
		if(n > sizeof bit.buf)
			error(0, Egreg);
		qlock(&bit);
		if((((ulong)buf)&(KSEGM|3)) == KSEG0){
			bitsend(READ, buf, n);
			bitsync();
		}else{
			bitsend(READ, bit.buf, n);
			bitsync();
			memcpy(buf, bit.buf, n);
		}
		n = bit.msg.result;
		qunlock(&bit);
		return n;
	}
	error(0, Egreg);
	return 0;
}

long	 
bitwrite(Chan *c, void *buf, long n)
{
	switch(c->qid){
	case 1:
		if(n > sizeof bit.buf)
			error(0, Egreg);
		qlock(&bit);
		if((((ulong)buf)&(KSEGM|3)) == KSEG0){
			bitsend(WRITE, buf, n);
			bitsync();
		}else{
			memcpy(bit.buf, buf, n);
			bitsend(WRITE, bit.buf, n);
			bitsync();
		}
		qunlock(&bit);
		return n;
	}
	error(0, Egreg);
	return 0;
}

void	 
bitremove(Chan *c)
{
	error(0, Eperm);
}

void	 
bitwstat(Chan *c, char *dp)
{
	error(0, Eperm);
}

void
bituserstr(Error *e, char *buf)
{
	consuserstr(e, buf);
}

void	 
biterrstr(Error *e, char *buf)
{
	rooterrstr(e, buf);
}
.
## diffname power/devbit.c 1990/0306
## diff -e /n/bootesdump/1990/0227/sys/src/9/mips/devbit.c /n/bootesdump/1990/0306/sys/src/9/mips/devbit.c
183,184c
			bitsend(bp, WRITE, bit.buf, n);
.
178,181c
		if((((ulong)buf)&(KSEGM|3)) == KSEG0)
			bitsend(bp, WRITE, buf, n);
		else{
.
172a
	Bitmsg *bp;

	bp = &((User*)(u->p->upage->pa|KZERO))->bit;
.
163a
		do
			n = bp->count;
		while(n == 0);
		if(docpy)
			memcpy(buf, bit.buf, n);
.
162d
154,160c
		if((((ulong)buf)&(KSEGM|3)) == KSEG0)
			bitsend(bp, READ, buf, n);
		else{
			bitsend(bp, READ, bit.buf, n);
			docpy = 1;
.
152a
		docpy = 0;
.
148a
	Bitmsg *bp;
	int docpy;

	bp = &((User*)(u->p->upage->pa|KZERO))->bit;
.
113,115c
	bitsend(bp, RESET, 0, 0);
.
104a
	Bitmsg *bp;

	bp = &((User*)(u->p->upage->pa|KZERO))->bit;
.
52,58d
48a
	do; while(*BITADDR);
.
46c
	*BITADDR = bp;
.
41,43c
	bp->cmd = cmd;
	bp->addr = (ulong)addr;
	bp->count = count;
.
39c
bitsend(Bitmsg *bp, ulong cmd, void *addr, ulong count)
.
24d
11,19d
## diffname power/devbit.c 1990/03081
## diff -e /n/bootesdump/1990/0306/sys/src/9/mips/devbit.c /n/bootesdump/1990/03081/sys/src/9/mips/devbit.c
171a
if(0 && n > 512){
	int i;
	char *cp=buf;
	for(i=15; i<n; i++)
		if(cp[i] != cp[i-1]){
			print("w %d %x %x\n", i, cp[i-1], cp[i]);
			break;
		}
}
.
155a
if(0 && n > 512){
	int i;
	char *cp=buf;
	for(i=9; i<n; i++)
		if(cp[i] != cp[i-1]){
			print("r %d %x %x\n", i, cp[i-1], cp[i]);
			break;
		}
}
.
151,153c
		do{
			n = bp->rcount;
			hang++;
		}while(n == 0);
.
137a
	bp->rcount = 0;
.
97d
44a
	*BITHOLD = 0;
.
39c
/* print("done\n");  /**/
.
37a
	do hold++; while(*BITHOLD);
.
34,35c
/* print("%d %lux %d ", cmd, addr, count); /**/
.
30a
	do wait++; while(*BITADDR);
.
27a
long	hold, wait, hang;

.
18a
#define	BITHOLD	((ulong*)(KZERO+0x78))
.
## diffname power/devbit.c 1990/0321
## diff -e /n/bootesdump/1990/03081/sys/src/9/mips/devbit.c /n/bootesdump/1990/0321/sys/src/9/mips/devbit.c
187,195d
162,170d
158,159c
		while(n == 0);
.
156c
		do
.
43d
41c
	do; while(*BITHOLD);
.
38d
34c
	do; while(*BITADDR);
.
29,30d
## diffname power/devbit.c 1990/0324 # deleted
## diff -e /n/bootesdump/1990/0321/sys/src/9/mips/devbit.c /n/bootesdump/1990/0324/sys/src/9/mips/devbit.c
1,209d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].