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

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


## diffname power/devhotrod.c 1990/1013
## diff -e /dev/null /n/bootesdump/1990/1013/sys/src/9/mips/devhotrod.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 Hotrod	Hotrod;
typedef struct Device	Device;

enum {
	Vmevec=		0xd2,		/* vme vector for interrupts */
	Intlevel=	5,		/* level to interrupt on */
	Nhotrod=	1,
};

/*
 *  the hotrod fiber interface responds to 1MB
 *  of either user or supervisor accesses at:
 *  	0x30000000 to 0x300FFFFF  in	A32 space
 *  and	  0xB00000 to   0xBFFFFF  in	A24 space
 */
struct Device {
	uchar	mem[1*1024*1024];
};
#define HOTROD		VMEA32SUP(Device, 0x30000000)

struct Hotrod {
	QLock;

	Device	*addr;
	int	vec;
	char	name[NAMELEN];
};

Hotrod hotrod[Nhotrod];

static void hotrodintr(int);

int
hotrodgen(Chan *c, Dirtab *tab, int ntab, int i, Dir *dp)
{
	if(i || c->dev>=Nhotrod)
		return -1;
	devdir(c, 0, hotrod[c->dev].name, sizeof(Device), 0666, dp);
	return 1;
}

/*
 *  reset all hotrod boards
 */
void
hotrodreset(void)
{
	int i;
	Hsvme *hp;

	for(i=0; i<Nhotrod; i++){
		hotrod[i].addr = HOTROD+i;
		hotrod[i].vec = Vmevec+i;
		sprint(hotrod[i].name, "hotrod%d", i);
		setvmevec(hotrod[i].vec, hotrodintr);
	}	
	wbflush();
	delay(20);
}

void
hotrodinit(void)
{
}

/*
 *  enable the device for interrupts, spec is the device number
 */
Chan*
hotrodattach(char *spec)
{
	int i;
	Chan *c;

	i = strtoul(spec, 0, 0);
	if(i >= Nhotrod)
		error(0, Ebadarg);

	c = devattach('H', spec);
	c->dev = i;
	c->qid = CHDIR;
	return c;
}

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

int	 
hotrodwalk(Chan *c, char *name)
{
	return devwalk(c, name, 0, 0, hotrodgen);
}

void	 
hotrodstat(Chan *c, char *dp)
{
	devstat(c, dp, 0, 0, hotrodgen);
}

Chan*
hotrodopen(Chan *c, int omode)
{
	if(c->qid == CHDIR){
		if(omode != OREAD)
			error(0, Eperm);
	}else
		streamopen(c, &hotrodinfo);
	c->mode = openmode(omode);
	c->flag |= COPEN;
	c->offset = 0;
	return c;
}

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

void	 
hotrodclose(Chan *c)
{
}

/*
 *  read the hotrod memory
 */
long	 
hotrodread(Chan *c, void *buf, long n)
{
	Hotrod *hp;
	Device *dp;

	hp = &hotrod[c->dev];
	dp = hp->addr;
	if(c->offset >= sizeof(dp->mem))
		return 0;
	if(c->offset+n > sizeof(dp->mem))
		n = sizeof(dp->mem) - c->offset;
	qlock(hp);
	memcpy(buf, &dp->mem[c->offset], n);
	qunlock(hp);
	return n;
}

/*
 *  write hotrod memory
 */
long	 
hotrodwrite(Chan *c, void *buf, long n)
{
	Hotrod *hp;
	Device *dp;

	hp = &hotrod[c->dev];
	dp = hp->addr;
	if(c->offset >= sizeof(dp->mem))
		return 0;
	if(c->offset+n > sizeof(dp->mem))
		n = sizeof(dp->mem) - c->offset;
	qlock(hp);
	memcpy(&dp->mem[c->offset], buf, n);
	qunlock(hp);
	return n;
}

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

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

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

void	 
hotroderrstr(Error *e, char *buf)
{
	rooterrstr(e, buf);
}

hotrodintr(int vec)
{
	Hotrod *hp;

	print("hotrod%d interrupt\n", vec - Vmevec);
	hp = &hotrod[vec - Vmevec];
	if(hp < hotrod || hp > &hotrod[Nhotrod]){
		print("bad hotrod vec\n");
		return;
	}
}
.
## diffname power/devhotrod.c 1990/1018
## diff -e /n/bootesdump/1990/1013/sys/src/9/mips/devhotrod.c /n/bootesdump/1990/1018/sys/src/9/mips/devhotrod.c
203a
static void
.
175c
	from = buf;
	to = &dp->mem[c->offset/sizeof(ulong)];
	end = to + (n/sizeof(ulong));
	while(to != end)
		*to++ = *from++;
.
173a

	/*
	 *  avoid memcpy to ensure VME 32-bit writes
	 */
.
167a
	/*
	 *  allow full word access only
	 */
	if((c->offset&(sizeof(ulong)-1)) || (n&(sizeof(ulong)-1)))
		error(0, Ebadarg);

.
166a
	ulong *from;
	ulong *to;
	ulong *end;
.
154c
	to = buf;
	from = &dp->mem[c->offset/sizeof(ulong)];
	end = to + (n/sizeof(ulong));
	while(to != end)
		*to++ = *from++;
.
152a

	/*
	 *  avoid memcpy to ensure VME 32-bit reads
	 */
.
146a
	if(c->qid&CHDIR)
		return devdirread(c, buf, n, 0, 0, hotrodgen);

	/*
	 *  allow full word access only
	 */
	if((c->offset&(sizeof(ulong)-1)) || (n&(sizeof(ulong)-1)))
		error(0, Ebadarg);

.
145a
	ulong *from;
	ulong *to;
	ulong *end;
.
119,120c
	}
.
59c
	Hotrod *hp;
.
29c
#define HOTROD		VMEA24SUP(Device, 0xB00000)
.
27c
	ulong	mem[1024*1024/sizeof(ulong)];
.
17c
	Nhotrod=	2,
.
## diffname power/devhotrod.c 1990/1020
## diff -e /n/bootesdump/1990/1018/sys/src/9/mips/devhotrod.c /n/bootesdump/1990/1020/sys/src/9/mips/devhotrod.c
173a
	}
.
172c
	while(to != end){
.
## diffname power/devhotrod.c 1990/1106
## diff -e /n/bootesdump/1990/1020/sys/src/9/mips/devhotrod.c /n/bootesdump/1990/1106/sys/src/9/mips/devhotrod.c
250a
	}
}

/*
 *  print hotrod processor messages on the console
 */
void
hotrodkproc(void *a)
{
	Hotrod	*hp = a;
	char	*p;

	hp->kprocstarted = 1;
	hp->pbuf.rptr = hp->pbuf.wptr = hp->pbuf.buf;
	hp->pbuf.lim = &hp->pbuf.buf[sizeof(hp->pbuf.buf)];

	for(;;){
		p = hp->pbuf.wptr;
		if(p != hp->pbuf.rptr){
			if(p > hp->pbuf.rptr){
				putstrn(hp->pbuf.rptr, p - hp->pbuf.rptr);
			} else {
				putstrn(hp->pbuf.rptr, hp->pbuf.lim - hp->pbuf.rptr);
				putstrn(hp->pbuf.buf, hp->pbuf.wptr - hp->pbuf.buf);
			}
			hp->pbuf.rptr = p;
		}
		tsleep(&(hp->r), return0, 0, 1000);
.
241c
void
.
115a
	Device *dp;
	Hotrod *hp;

	/*
	 *  Remind hotrod where the print buffer is.  The address we store
	 *  is the address of the printbuf in VME A32 space.
	 */
	hp = &hotrod[c->dev];
	dp = hp->addr;
	dp->mem[256*1024/sizeof(ulong)] = (((ulong)&hp->pbuf) - KZERO) | (SLAVE<<28);

.
88a
	hp = &hotrod[i];
	if(hp->kprocstarted == 0)
		kproc(hp->name, hotrodkproc, hp);

.
81a
	Hotrod *hp;
.
41c
void	hotrodintr(int);
void	hotrodkproc(void *a);
.
34,36c
	Device		*addr;		/* address of the device */
	int		vec;		/* vme interrupt vector */
	char		name[NAMELEN];	/* hot rod name */
	Printbuf	pbuf;		/* circular queue for hotrod print's */
	int		kprocstarted;
	Rendez		r;
.
20a
 *  circular 2 pointer queue for hotrod prnt's
 */
struct Printbuf {
	char	*rptr;
	char	*wptr;
	char	*lim;
	char	buf[4*1024];
};

/*
.
12a
typedef struct Printbuf	Printbuf;
.
## diffname power/devhotrod.c 1990/1110
## diff -e /n/bootesdump/1990/1106/sys/src/9/mips/devhotrod.c /n/bootesdump/1990/1110/sys/src/9/mips/devhotrod.c
145a
#endif
.
138a
#ifdef asdf
.
## diffname power/devhotrod.c 1990/11211
## diff -e /n/bootesdump/1990/1110/sys/src/9/mips/devhotrod.c /n/bootesdump/1990/11211/sys/src/9/mips/devhotrod.c
259,271c
	error(Eperm);
.
253c
	error(Eperm);
.
228c
		error(Ebadarg);
.
189c
		error(Ebadarg);
.
182c
	if(c->qid.path & CHDIR)
.
162c
	error(Eperm);
.
151c
			error(Eperm);
.
149c
	if(c->qid.path == CHDIR){
.
111c
	c->qid.path = CHDIR;
	c->qid.vers = 0;
.
103c
		error(Ebadarg);
.
63c
	devdir(c, (Qid){0,0}, hotrod[c->dev].name, sizeof(Device), 0666, dp);
.
## diffname power/devhotrod.c 1991/0209
## diff -e /n/bootesdump/1991/0201/sys/src/9/mips/devhotrod.c /n/bootesdump/1991/0209/sys/src/9/power/devhotrod.c
273,300d
224a
	if(c->qid.path != Qhotrod)
		error(Egreg);
.
183,184c
	if(c->qid.path != Qhotrod)
		error(Egreg);
.
168a
	Hotrod *hp;

	hp = &hotrod[c->dev];
	if(c->qid.path != CHDIR){
		u->khot.cmd = REBOOT;
		hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
		unlock(&hp->busy);
	}
.
152a
	}else if(c->qid.path == Qhotrod){
		hp = &hotrod[c->dev];
		if(!canlock(&hp->busy))
			error(Einuse);
		/*
		 * Clear communications region
		 */
		memset(hp->wq->msg, 0, sizeof(hp->wq->msg));
		hp->wq->i = 0;

		/*
		 * Issue reset
		 */
		hp->wi = 0;
		hp->ri = 0;
		u->khot.cmd = RESET;
		u->khot.param[0] = (ulong)&hp->rq;
		u->khot.param[1] = NhotQ;
		hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
.
140,149d
131c
	print("hotrodstat\n");
	error(Egreg);
.
125c
	if(c->qid.path != CHDIR)
		return 0;
	if(strncmp(name, "hotrod", 6) == 0){
		c->qid.path = Qhotrod;
		return 1;
	}
	return 0;
.
105,108d
76,80c
	for(hp=hotrod,i=0; i<Nhotrod; i++,hp++){
		hp->addr = HOTROD+i;
		/*
		 * Write queue is at end of hotrod memory
		 */
		hp->wq = (HotQ*)((ulong)hp->addr+2*0x40000-sizeof(HotQ));
		hp->vec = Vmevec+i;
		setvmevec(hp->vec, hotrodintr);
.
61,64c
print("hotsend send %d %lux %lux\n", m->cmd, m, m->param[0]);
	h->wq->msg[h->wi] = m;
	while(h->wq->msg[h->wi])
		;
print("hotsend done\n");
	h->wi++;
	if(h->wi >= NhotQ)
		h->wi = 0;
.
58,59c
/*
 * Commands
 */
enum{
	RESET=	0,	/* params: Q address, length of queue */
	REBOOT=	1,	/* params: none */
};

void
hotsend(Hotrod *h, Hotmsg *m)
.
56d
47,49c
	HotQ		*wq;		/* write this queue to send cmds */
	int		wi;		/* where to write next cmd */
	HotQ		rq;		/* read this queue to receive replies */
	int		ri;		/* where to read next response */
.
44a

struct Hotrod{
	QLock;
	Lock		busy;
.
42,43c
struct HotQ{
	ulong	i;			/* index into queue */
	Hotmsg	*msg[NhotQ];		/* pointer to command buffer */
	ulong	pad[3];			/* unused; for hotrod prints */
};
.
38c
	ulong	mem[0x100000/sizeof(ulong)];
.
35c
 *  and	  0xB00000 to   0xBFFFFF  in	A24 space.
 *  The second 0x40000 of this space is on-board SRAM.
.
22,32c
 *  The hotrod fiber interface responds to 1MB
.
18c
	Qdir=		0,		/* Qid's */
	Qhotrod=	1,
	NhotQ=		10,		/* size of communication queues */
	Nhotrod=	1,
.
13d
11a
typedef struct HotQ	HotQ;
.
## diffname power/devhotrod.c 1991/0212
## diff -e /n/bootesdump/1991/0209/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0212/sys/src/9/power/devhotrod.c
270,286c
	switch(c->qid.path){
	case 1:
		if(n > sizeof hp->buf)
			error(Egreg);
		if((((ulong)buf)&(KSEGM|3)) == KSEG0){
			/*
			 *  use supplied buffer, no need to lock for reply
			 */
			mp = &u->khot;
			qlock(hp);
			mp->cmd = WRITE;
			mp->param[0] = MP2VME(buf);
			mp->param[1] = n;
			hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
			qunlock(hp);
		}else{
			/*
			 *  use hotrod buffer.  lock the buffer till the reply
			 */
			mp = &u->uhot;
			qlock(&hp->buflock);
			qlock(hp);
			memcpy(hp->buf, buf, n);
			mp->cmd = WRITE;
			mp->param[0] = MP2VME(hp->buf);
			mp->param[1] = n;
			hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->uhot);
			qunlock(hp);
			qunlock(&hp->buflock);
		}
		return n;
	}
	error(Egreg);
	return 0;
.
261,268d
256,259c
	Hotmsg *mp;
.
245,246c
	error(Egreg);
	return 0;
.
229,243c
	switch(c->qid.path){
	case Qhotrod:
		if(n > sizeof hp->buf)
			error(Egreg);
		if((((ulong)buf)&(KSEGM|3)) == KSEG0){
			/*
			 *  use supplied buffer, no need to lock for reply
			 */
			mp = &u->khot;
			mp->param[2] = 0;	/* reply count */
			qlock(hp);
			mp->cmd = READ;
			mp->param[0] = MP2VME(buf);
			mp->param[1] = n;
			hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
			qunlock(hp);
			do
				n = mp->param[2];
			while(n == 0);
		}else{
			/*
			 *  use hotrod buffer.  lock the buffer till the reply
			 */
			mp = &u->uhot;
			mp->param[2] = 0;	/* reply count */
			qlock(&hp->buflock);
			qlock(hp);
			mp->cmd = READ;
			mp->param[0] = MP2VME(hp->buf);
			mp->param[1] = n;
			hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->uhot);
			qunlock(hp);
			do
				n = mp->param[2];
			while(n == 0);
			memcpy(buf, hp->buf, n);
			qunlock(&hp->buflock);
		}
		return n;
.
219,227d
214,217c
	Hotmsg *mp;
.
209a

.
208c
 * 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.
.
177,179c
		mp = &u->khot;
		mp->cmd = RESET;
		mp->param[0] = MP2VME(&hp->rq);
		mp->param[1] = NhotQ;
.
157a
	Hotmsg *mp;
.
71c
	h->wq->msg[h->wi] = (Hotmsg*)MP2VME(m);
.
64a
	READ=	2,	/* params: buffer, count, returned count */
	WRITE=	3,	/* params: buffer, count */
.
52a
	uchar		buf[MAXFDATA+100];
.
44a
	QLock		buflock;
.
7a
#include	"fcall.h"
.
## diffname power/devhotrod.c 1991/0214
## diff -e /n/bootesdump/1991/0212/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0214/sys/src/9/power/devhotrod.c
187a
		delay(1000);
		print("reset\n");
		/*
		 * Issue reset
		 */
		mp->cmd = TEST;
		hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
		print("ok1\n");
		delay(1000);
		print("ok2\n");
.
69a
	TEST=	7,	/* params: none */
.
## diffname power/devhotrod.c 1991/0215
## diff -e /n/bootesdump/1991/0214/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0215/sys/src/9/power/devhotrod.c
350a
	hp->addr->csr3 &= ~INT_VME;
.
346a
hp=&hotrod[0];
.
274a
			if(n == 0){
				print("devhotrod: give up\n");
				error(Egreg);
			}
.
272c
			while(n==0 && --l>0);
.
269a
			l = 100*1000*1000;
.
259c
			 *  use hotrod buffer.  lock the buffer until the reply
.
256c
			while(n==0 && --l>0);
			if(n == 0){
				print("devhotrod: give up\n");
				error(Egreg);
			}
.
253a
			l = 100*1000*000;
.
235a
	ulong l;
.
191,198d
189c
		delay(100);
.
162d
102a
setvmevec(0xFF, hotrodintr);
.
100c
		hp->wq = (HotQ*)(&hp->addr->hostrp);
.
78,79c
	do
		delay(1);
	while(h->wq->msg[h->wi]);
.
61a
#define	HOTROD	VMEA24SUP(Hot, 0xB00000);

.
48c
	Hot		*addr;		/* address of the device */
.
25,36d
21c
	NhotQ=		NRQ,		/* size of communication queues */
.
14d
10a
#include	"hrod.h"
.
## diffname power/devhotrod.c 1991/0219
## diff -e /n/bootesdump/1991/0215/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0219/sys/src/9/power/devhotrod.c
346c
	hp->addr->lcsr3 &= ~INT_VME;
.
341d
181a

		/*
		 * Issue test
		 */
		mp = &u->khot;
		mp->cmd = TEST;
		hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
		delay(100);
		print("tested\n");
.
94d
## diffname power/devhotrod.c 1991/0220
## diff -e /n/bootesdump/1991/0219/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0220/sys/src/9/power/devhotrod.c
347c
/*	print("hotrod%d interrupt\n", vec - Vmevec); /**/
.
325a
	print("hotrod write unk\n");
.
297a
		}
.
296c
		if(n > sizeof hp->buf){
			print("hotrod write bufsize\n");
.
279a
	print("hotrod read unk\n");
.
246c
			l = 100*1000*1000;
.
233a
		}
.
232c
		if(n > sizeof hp->buf){
			print("hotrod bufsize\n");
.
189a
#endif
.
181a
#ifdef asdf
.
71c
/* print("hotsend done\n"); /**/
.
66c
/* print("hotsend send %d %d %lux %lux\n", h->wi, m->cmd, m, m->param[0]); /**/
.
43c
	uchar		buf[MAXFDATA+MAXMSG];
.
## diffname power/devhotrod.c 1991/0222
## diff -e /n/bootesdump/1991/0220/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0222/sys/src/9/power/devhotrod.c
191d
182d
## diffname power/devhotrod.c 1991/0227
## diff -e /n/bootesdump/1991/0222/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0227/sys/src/9/power/devhotrod.c
186a
		mp->param[0] = MP2VME(testbuf);
		mp->param[1] = NTESTBUF;
.
149a
#define	NTESTBUF	256
ulong	testbuf[NTESTBUF];

.
## diffname power/devhotrod.c 1991/0302
## diff -e /n/bootesdump/1991/0227/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0302/sys/src/9/power/devhotrod.c
194a
#endif
.
184a
#ifdef asdf
.
## diffname power/devhotrod.c 1991/0303
## diff -e /n/bootesdump/1991/0302/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0303/sys/src/9/power/devhotrod.c
366a
}

void
mem(Hot *hot, ulong *buf, ulong size)
{
	long i, j, k, l;
	ulong *p, bit, u;
	int q;

goto part4;
	/* one bit */
	bit = 0;
	p = buf;
	for(i=0; i<size; i++,p++) {
		if(bit == 0)
			bit = 1;
		*p = bit;
		bit <<= 1;
	}
	bit = 0;
	p = buf;
	for(i=0; i<size; i++,p++) {
		if(bit == 0)
			bit = 1;
		if(*p != bit) {
			print("A: %lux is %lux sb %lux\n", p, *p, bit);
			hot->error++;
			delay(500);
		}
		bit <<= 1;
	}
	/* all but one bit */
	bit = 0;
	p = buf;
	for(i=0; i<size; i++,p++) {
		if(bit == 0)
			bit = 1;
		*p = ~bit;
		bit <<= 1;
	}
	bit = 0;
	p = buf;
	for(i=0; i<size; i++,p++) {
		if(bit == 0)
			bit = 1;
		if(*p != ~bit) {
			print("B: %lux is %lux sb %lux\n", p, *p, ~bit);
			hot->error++;
			delay(500);
		}
		bit <<= 1;
	}
	/* rand bit */
	bit = 0;
	p = buf;
	for(i=0; i<size; i++,p++) {
		if(bit == 0)
			bit = 1;
		*p = bit;
		bit += PRIME;
	}
	bit = 0;
	p = buf;
	for(i=0; i<size; i++,p++) {
		if(bit == 0)
			bit = 1;
		if(*p != bit) {
			print("C: %lux is %lux sb %lux\n", p, *p, bit);
			hot->error++;
			delay(500);
		}
		bit += PRIME;
	}
part4:
	/* address */
	p = buf;
	for(i=0; i<size; i++,p++)
		*p = i;
	for(j=0; j<200; j++) {
		p = buf;
		for(i=0; i<size; i++,p++) {
			u = *p;
			if(u != i+j) {
				print("D: %lux is %lux sb %lux (%lux)\n", p, u, i+j, *p);
			hot->error++;
				delay(500);
			}
			*p = i+j+1;
		}
	}
.
331a
			mp->param[2] = hotsum((ulong*)hp->buf, n, ENABCKSUM);
.
318a
			mp->param[2] = hotsum(buf, n, ENABCKSUM);
.
287c
		return m;
.
285a
			if(mp->param[2] != hotsum((ulong*)hp->buf, m, mp->param[2])){
				print("hotrod cksum err is %lux sb %lux\n",
					hotsum((ulong*)hp->buf, n, 1), mp->param[2]);
				qunlock(&hp->buflock);
				error(Eio);
			}
			memcpy(buf, hp->buf, m);
			qunlock(&hp->buflock);
.
278,283c
				m = mp->param[3];
			while(m==0 && --l>0);
			if(m==0 || m>n){
				print("devhotrod: count %ld %ld\n", m, n);
				qunlock(&hp->buflock);
.
268c
			mp->param[2] = 0;	/* checksum */
			mp->param[3] = 0;	/* reply count */
.
262a
			if(mp->param[2] != hotsum(buf, m, mp->param[2])){
				print("hotrod cksum err is %lux sb %lux\n",
					hotsum(buf, n, 1), mp->param[2]);
				error(Eio);
			}
.
257,260c
				m = mp->param[3];
			while(m==0 && --l>0);
			if(m==0 || m>n){
				print("devhotrod: count %ld %ld\n", m, n);
.
248c
			mp->param[2] = 0;	/* checksum */
			mp->param[3] = 0;	/* reply count */
.
234c
	ulong l, m;
.
222a
ulong
hotsum(ulong *p, int n, ulong doit)
{
	ulong sum;

	if(!doit)
		return 0;
	sum = 0;
	n = (n+sizeof(ulong)-1)/sizeof(ulong);
	while(--n >= 0)
		sum += *p++;
	return sum;
}

.
195c
		print("testing addr %lux size %ld\n", mp->param[0], mp->param[1]);
		for(;;){
			print("-");
			mem(hp->addr, &hp->addr->ram[(mp->param[0]-0x40000)/sizeof(ulong)], mp->param[1]);
		}
.
58,59c
	READ=	2,	/* params: buffer, count, sum, returned count */
	WRITE=	3,	/* params: buffer, count, sum */
.
12a
void	mem(Hot*, ulong*, ulong);

/*
 * If set, causes data transfers to have checksums
 */
#define	ENABCKSUM	1

.
## diffname power/devhotrod.c 1991/0304
## diff -e /n/bootesdump/1991/0303/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0304/sys/src/9/power/devhotrod.c
363c
			 *  use hotrod buffer.  lock the buffer until the reply
.
81a
	l = 0;
	while(*mp){
		delay(0);	/* just a subroutine call; stay off VME */
		if(++l > 1000*1000){
			l = 0;
			print("hotsend blocked\n");
		}
	}
.
74,78c
	mp = &h->wq->msg[h->wi];
	*mp = (Hotmsg*)MP2VME(m);
.
72a
	Hotmsg **mp;
	long l;

.
18c
#define	ENABCKSUM	0
.
## diffname power/devhotrod.c 1991/0306
## diff -e /n/bootesdump/1991/0304/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0306/sys/src/9/power/devhotrod.c
506a
#endif
.
417a
#ifdef	ENABMEMTEST
.
415c
	h->addr->lcsr3 &= ~INT_VME;
	hm = (Hotmsg*)VME2MP(h->rq[h->ri]);
	h->rq[h->ri] = 0;
	h->ri++;
	if(h->ri >= NRQ)
		h->ri = 0;
	hm->intr = 1;
	if(hm->abort)
		return;
	wakeup(&hm->r);
.
409,411c
	h = &hotrod[vec - Vmevec];
	if(h < hotrod || h > &hotrod[Nhotrod]){
.
407c
	Hotrod *h;
	Hotmsg *hm;
.
381c
			hotsend(hp, mp);
.
373c
			mp = &((User*)(u->p->upage->pa|KZERO))->uhot;
.
371c
			 * use hotrod buffer.  lock the buffer until the reply
.
367c
			hotsend(hp, mp);
.
361c
			mp = &((User*)(u->p->upage->pa|KZERO))->khot;
			if(mp->abort)	/* use reserved flush msg */
				mp = &((User*)(u->p->upage->pa|KZERO))->fhot;
.
359c
			 * use supplied buffer, no need to lock for reply
.
341,343d
314c
			mp->abort = 1;
			mp->intr = 0;
			hotsend(hp, mp);
.
306c
			mp = &((User*)(u->p->upage->pa|KZERO))->uhot;
.
304c
			 * use hotrod buffer. lock the buffer until the reply
.
301a
			if(!isflush)
				poperror();
.
292c
			}
.
289,290c
			if(isflush){		/* busy loop */
				l = 100*1000*1000;
				do
					m = mp->param[3];
				while(m==0 && --l>0);
			}else{
				if(waserror()){
					mp->abort = 1;
					nexterror();
				}
				sleep(&mp->r, hotmsgintr, mp);
.
287c
			mp->abort = isflush;
			mp->intr = 0;
			hotsend(hp, mp);
.
280c
			isflush = 0;
			mp = &((User*)(u->p->upage->pa|KZERO))->khot;
			if(mp->abort){	/* use reserved flush msg */
				mp = &((User*)(u->p->upage->pa|KZERO))->fhot;
				isflush = 1;
			}
.
267c
	ulong l, m, isflush;
.
255a
int
hotmsgintr(Hotmsg *hm)
{
	return hm->intr;
}

.
200c
#ifdef ENABMEMTEST
.
194,195c
		mp->param[0] = MP2VME(hp->rq);
		mp->param[1] = NRQ;
.
184,185c
		memset(hp->addr->hostrq, 0, NRQ*sizeof(ulong));
		hp->addr->hostrp = 0;
.
106d
80c
	if(h->wi >= NRQ)
.
77c
	mp = (Hotmsg**)&h->addr->hostrq[h->wi];
.
49d
47c
	ulong		rq[NRQ];	/* read this queue to receive replies */
.
45d
32,38d
28d
23c
enum{
.
21d
18c
#define	ENABCKSUM	1
.
13a
#endif
.
12a
/*
 * If defined, causes memory test to be run at device open
 */
#ifdef	ENABMEMTEST
.
## diffname power/devhotrod.c 1991/0307
## diff -e /n/bootesdump/1991/0306/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0307/sys/src/9/power/devhotrod.c
395c
			mp->cmd = Uwrite;
.
381c
			mp->cmd = Uwrite;
.
367,368c
	switch(c->qid.path & ~CHDIR){
	case Qdir:
		return devdirread(c, buf, n, hotroddir, NHOTRODDIR, devgen);

	case Qhotrod:
.
347a
{int i; for(i=0; i<8; i++) print("%lux\n", ((ulong*)buf)[i]); }
.
344a
				hp->addr->error++;
.
328c
			mp->cmd = Uread;
.
324c
			mp->param[2] = 0;	/* reply checksum */
.
314a
{int i; for(i=0; i<8; i++) print("%lux\n", ((ulong*)buf)[i]); }
.
312a
				hp->addr->error++;
.
288c
			mp->cmd = Uread;
.
285c
			mp->param[2] = 0;	/* reply checksum */
.
269c
	switch(c->qid.path & ~CHDIR){
	case Qdir:
		return devdirread(c, buf, n, hotroddir, NHOTRODDIR, devgen);

.
229c
		u->khot.cmd = Ureboot;
.
198c
		mp->cmd = Utest;
.
186c
		mp->cmd = Ureset;
.
158,160d
154,155c
	devstat(c, dp, hotroddir, NHOTRODDIR, devgen);
.
142,148c
	return devwalk(c, name, hotroddir, NHOTRODDIR, devgen);
.
103,104d
56,63d
34a
Dirtab hotroddir[]={
	"hotrod",	{Qhotrod},	0,	0600,
};

#define	NHOTRODDIR	(sizeof hotroddir/sizeof(Dirtab))

.
21c
 * If 1, ENABCKSUM causes data transfers to have checksums
.
17a
#define	NTESTBUF	256
ulong	testbuf[NTESTBUF];
.
14c
 * If defined, ENABMEMTEST causes memory test to be run at device open
.
## diffname power/devhotrod.c 1991/0316
## diff -e /n/bootesdump/1991/0307/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0316/sys/src/9/power/devhotrod.c
15a
#define	ENABMEMTEST
.
## diffname power/devhotrod.c 1991/0317
## diff -e /n/bootesdump/1991/0316/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0317/sys/src/9/power/devhotrod.c
16d
## diffname power/devhotrod.c 1991/0318
## diff -e /n/bootesdump/1991/0317/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0318/sys/src/9/power/devhotrod.c
392c
			memmove(hp->buf, buf, n);
.
345c
			memmove(buf, hp->buf, m);
.
## diffname power/devhotrod.c 1991/0326
## diff -e /n/bootesdump/1991/0318/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0326/sys/src/9/power/devhotrod.c
432,440c
	while(l = h->rq[h->ri]){	/* assign = */
		hm = (Hotmsg*)(VME2MP(l));
		h->rq[h->ri] = 0;
		h->ri++;
		if(h->ri >= NRQ)
			h->ri = 0;
		hm->intr = 1;
		if(hm->abort)
			print("abort wakeup\n");
		else
			wakeup(&hm->r);
	}
.
427c
	if(h<hotrod || h>&hotrod[Nhotrod]){
.
424a
	ulong l;
.
## diffname power/devhotrod.c 1991/0328
## diff -e /n/bootesdump/1991/0326/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0328/sys/src/9/power/devhotrod.c
195a
#endif
#ifdef ENABBUSTEST
		/*
		 * Issue test
		 */
		mp = &u->khot;
		mp->cmd = Ubus;
		hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
.
20a
/*
 * If defined, ENABBUSTEST causes bus error diagnostic to be run at device open
 */
#define	ENABBUSTEST
.
## diffname power/devhotrod.c 1991/0329
## diff -e /n/bootesdump/1991/0328/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0329/sys/src/9/power/devhotrod.c
24d
15a
#define	ENABMEMTEST
.
## diffname power/devhotrod.c 1991/0331
## diff -e /n/bootesdump/1991/0329/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0331/sys/src/9/power/devhotrod.c
29c
#define	ENABCKSUM	0
.
16d
## diffname power/devhotrod.c 1991/0401
## diff -e /n/bootesdump/1991/0331/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0401/sys/src/9/power/devhotrod.c
446c
		h->addr->replyq[h->ri] = 0;
.
444c
	while(l = h->addr->replyq[h->ri]){	/* assign = */
.
178,179d
168,169c
		memset(hp->addr->reqstq, 0, NRQ*sizeof(ulong));
		hp->addr->reqstp = 0;
		memset(hp->addr->replyq, 0, NRQ*sizeof(ulong));
		hp->addr->replyp = 0;
.
74c
	mp = (Hotmsg**)&h->addr->reqstq[h->wi];
.
53,54c
	int		ri;		/* where to read next reply */
.
## diffname power/devhotrod.c 1991/0402
## diff -e /n/bootesdump/1991/0401/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0402/sys/src/9/power/devhotrod.c
399a
			mp->wtype = ((char*)buf)[0];
.
385a
			mp->wtype = ((char*)buf)[0];
.
355a
			mp->abort = 0;
.
350c
					hotsum((ulong*)hp->buf, m, 1), mp->param[2]);
.
320c
			mp->abort = 0;
			if(isflush)
				u->khot.abort = 0;	/* flushed message's done too */
			else
.
316,317c
					hotsum(buf, m, 1), mp->param[2]);
				print("addr %lux\n", ((char*)buf)+m);
				{
					int i;
					ulong *p = buf;
					for(i=2; i<m/4; i++)
						if(p[i] != i-2)
							print("%d sb %d %lux %lux\n", p[i], i-2, p[i], &p[i]);
				}
.
280a
memset(buf, 0, n);
.
28c
#define	ENABCKSUM	1
.
## diffname power/devhotrod.c 1991/0403
## diff -e /n/bootesdump/1991/0402/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0403/sys/src/9/power/devhotrod.c
421,422c
			hmp = hotsend(hp, mp);
			hotwait(hmp);
.
415d
413c
			mp->wlen = n;
.
406,407c
			hmp = hotsend(hp, mp);
			hotwait(hmp);
.
401d
398c
			mp->wlen = n;
.
381c
	Hotmsg *mp, **hmp;
.
363d
347,348c
			hmp = hotsend(hp, mp);
			hotwait(hmp);
.
341d
325a
*/
.
317a
/*
.
303a
					if(*hmp && *hmp==mp)
						hotwait(hmp);
.
295,296c
			hmp = hotsend(hp, mp);
.
289d
281d
263c
	Hotmsg *mp, **hmp;
.
228c
		hmp = hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
		hotwait(hmp);
.
223a
	Hotmsg **hmp;
.
205c
		hmp = hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot, 0);
		hotwait(hmp);
.
191c
		hmp = hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
		hotwait(hmp);
.
179c
		hmp = hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
		hotwait(hmp);
.
155c
	Hotmsg *mp, **hmp;
.
85a
	return;
.
77a
	unlock(h);
	return mp;
}

void
hotwait(Hotmsg **mp)
{
	ulong l;

.
72c
	lock(h);
.
70d
66c

Hotmsg**
.
47c
	Lock;
.
28c
#define	ENABCKSUM	0
.
## diffname power/devhotrod.c 1991/0411
## diff -e /n/bootesdump/1991/0403/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0411/sys/src/9/power/devhotrod.c
392c
hotrodwrite(Chan *c, void *buf, long n, ulong offset)
.
275c
hotrodread(Chan *c, void *buf, long n, ulong offset)
.
## diffname power/devhotrod.c 1991/0419
## diff -e /n/bootesdump/1991/0411/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0419/sys/src/9/power/devhotrod.c
154a
Chan*
hotrodclwalk(Chan *c, char *name)
{
	return devclwalk(c, name);
}

.
## diffname power/devhotrod.c 1991/0427
## diff -e /n/bootesdump/1991/0419/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0427/sys/src/9/power/devhotrod.c
155,160d
## diffname power/devhotrod.c 1991/0723
## diff -e /n/bootesdump/1991/0427/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0723/sys/src/9/power/devhotrod.c
15a
#define	ENABMEMTEST
.
## diffname power/devhotrod.c 1991/0725
## diff -e /n/bootesdump/1991/0723/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0725/sys/src/9/power/devhotrod.c
207a
for(;;);
.
206a
		if(mp->param[0] == MP2VME(testbuf)){
			print("no way jose\n");
			unlock(&hp->busy);
			error(Egreg);
		}
			
.
## diffname power/devhotrod.c 1991/0727
## diff -e /n/bootesdump/1991/0725/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0727/sys/src/9/power/devhotrod.c
214d
79a
print("send 3\n"); delay(500);
.
75a
print("send 2\n"); delay(500);
.
74a
print("send 1 %lux\n", MP2VME(m)); delay(500);
.
29c
#define	ENABCKSUM	1
.
## diffname power/devhotrod.c 1991/0806
## diff -e /n/bootesdump/1991/0727/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0806/sys/src/9/power/devhotrod.c
228a
for(;;) ;
.
227c
		hmp = hotsend(hp, &((User*)(u->p->upage->pa|KZERO))->khot);
.
24a
#define	ENABBUSTEST
.
16d
## diffname power/devhotrod.c 1991/0808
## diff -e /n/bootesdump/1991/0806/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0808/sys/src/9/power/devhotrod.c
82d
77d
75d
29c
#define	ENABCKSUM	0
.
24d
## diffname power/devhotrod.c 1991/0817
## diff -e /n/bootesdump/1991/0808/sys/src/9/power/devhotrod.c /n/bootesdump/1991/0817/sys/src/9/power/devhotrod.c
28c
#define	ENABCKSUM	1
.
## diffname power/devhotrod.c 1991/1003
## diff -e /n/bootesdump/1991/0817/sys/src/9/power/devhotrod.c /n/bootesdump/1991/1003/sys/src/9/power/devhotrod.c
295c
			print("hotrod bufsize %d %d\n", n, sizeof hp->buf);
.
54c
	uchar		buf[MAXFDATA+MAXMSG+BITBOTCH];
.
0a
#define	BITBOTCH	256	/* remove with BIT3 */
.
## diffname power/devhotrod.c 1991/1011
## diff -e /n/bootesdump/1991/1003/sys/src/9/power/devhotrod.c /n/bootesdump/1991/1011/sys/src/9/power/devhotrod.c
29c
#define	ENABCKSUM	0
.
## diffname power/devhotrod.c 1991/1019
## diff -e /n/bootesdump/1991/1011/sys/src/9/power/devhotrod.c /n/bootesdump/1991/1019/sys/src/9/power/devhotrod.c
476c
	l = h->addr->lcsr3 & ~INT_VME;
	h->addr->lcsr3 = l;
	h->addr->lcsr3 = l;
.
## diffname power/devhotrod.c 1991/1216
## diff -e /n/bootesdump/1991/1019/sys/src/9/power/devhotrod.c /n/bootesdump/1991/1216/sys/src/9/power/devhotrod.c
460a
	USED(c, dp);
.
454a
	USED(c);
.
237a
	USED(c, name, omode, perm);
.
## diffname power/devhotrod.c 1991/1224
## diff -e /n/bootesdump/1991/1216/sys/src/9/power/devhotrod.c /n/bootesdump/1991/1224/sys/src/9/power/devhotrod.c
338c
				hp->addr->lcsr7 = 0xBEEF;
.
29c
#define	ENABCKSUM	1
.
## diffname power/devhotrod.c 1992/0104
## diff -e /n/bootesdump/1991/1224/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0104/sys/src/9/power/devhotrod.c
338a
{
	ulong *i, j, posn, nerr, val;

	i = buf;
	posn = -1;
	nerr = 0;
	for(j = 0; j < n/4; j++) {
		val = *i & 0xffff;
		if(posn == -1)
			posn = val+1;
		else if(posn != val) {
			print("error at offset %d %8lux != %8lux word=%8lux\n", 
						j, posn, val, *i);
			posn = -1;
			if(++nerr > 10) {
				print("too many\n");
				break;
			}
		}
		else
			posn++;
		i++;
	}
}
.
## diffname power/devhotrod.c 1992/0111
## diff -e /n/bootesdump/1992/0104/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0111/sys/src/9/power/devhotrod.c
7c
#include	"../port/error.h"
.
## diffname power/devhotrod.c 1992/0229
## diff -e /n/bootesdump/1992/0111/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0229/sys/src/9/power/devhotrod.c
519,610d
503,505d
494c
	Commrod *h;
.
427c
	Commrod *hp;
.
407d
365,374d
338,362d
286c
	Commrod *hp;
.
245c
	Commrod *hp;
.
165c
	Commrod *hp;
.
129c
	Commrod *hp;
.
106c
	Commrod *hp;
.
69c
hotsend(Commrod *h, Hotmsg *m)
.
62c
#define	HOTROD	VMEA24SUP(Comm, 0x10000);
.
58c
Commrod hotrod[Nhotrod];
.
51c
	Comm		*addr;		/* address of the device */
.
47c
struct Commrod
{
.
31c
typedef struct Commrod	Commrod;
.
29c
#define	ENABCKSUM	0
.
14,24d
12c
#include	"../../fs/cyc/comm.h"
.
## diffname power/devhotrod.c 1992/0301
## diff -e /n/bootesdump/1992/0229/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0301/sys/src/9/power/devhotrod.c
184,217d
## diffname power/devhotrod.c 1992/0306
## diff -e /n/bootesdump/1992/0301/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0306/sys/src/9/power/devhotrod.c
385c
			mp->param[2] = 0;
.
371c
			mp->param[2] = 0;
.
22c
enum
{
.
15,19d
## diffname power/devhotrod.c 1992/0317
## diff -e /n/bootesdump/1992/0306/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0317/sys/src/9/power/devhotrod.c
426,428c
		if(!hm->abort)
.
## diffname power/devhotrod.c 1992/0321
## diff -e /n/bootesdump/1992/0317/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0321/sys/src/9/power/devhotrod.c
3c
#include	"../port/lib.h"
.
## diffname power/devhotrod.c 1992/0428
## diff -e /n/bootesdump/1992/0321/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0428/sys/src/9/power/devhotrod.c
57a
int i;
.
## diffname power/devhotrod.c 1992/0508
## diff -e /n/bootesdump/1992/0428/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0508/sys/src/9/power/devhotrod.c
429a
	LEDOFF(LEDhotintr);
.
417a
		LEDOFF(LEDhotintr);
.
414a
	LEDON(LEDhotintr);
.
## diffname power/devhotrod.c 1992/0609
## diff -e /n/bootesdump/1992/0508/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0609/sys/src/9/power/devhotrod.c
432d
419d
415d
80c
			panic("hotsend blocked");
.
78c
		if(++l > 10*1000*1000){
.
## diffname power/devhotrod.c 1992/0612
## diff -e /n/bootesdump/1992/0609/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0612/sys/src/9/power/devhotrod.c
426a
		if(hm->param[3]==0 || hm->param[3] > 10000)
			print("hotrodintr count 0x%lux\n", hm->param[3]);
.
287c
				print("devhotrod: count 0x%lux 0x%lux\n", m, n);
.
275a
				print("isflush blocked\n");
.
264c
			mp->param[3] = 0xDEADBEEF;	/* reply count */
.
## diffname power/devhotrod.c 1992/0613 # deleted
## diff -e /n/bootesdump/1992/0612/sys/src/9/power/devhotrod.c /n/bootesdump/1992/0613/sys/src/9/power/devhotrod.c
1,433d

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].