plan 9 kernel history: overview | file list | diff list

1991/0209/power/devhotrod.c (diff list | history)

power/devhotrod.c on 1990/1013
1990/1013    
#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; 
1991/0209    
typedef struct HotQ	HotQ; 
1990/1013    
typedef struct Device	Device; 
 
enum { 
	Vmevec=		0xd2,		/* vme vector for interrupts */ 
	Intlevel=	5,		/* level to interrupt on */ 
1991/0209    
	Qdir=		0,		/* Qid's */ 
	Qhotrod=	1, 
	NhotQ=		10,		/* size of communication queues */ 
	Nhotrod=	1, 
1990/1013    
}; 
 
/* 
1991/0209    
 *  The hotrod fiber interface responds to 1MB 
1990/1013    
 *  of either user or supervisor accesses at: 
 *  	0x30000000 to 0x300FFFFF  in	A32 space 
1991/0209    
 *  and	  0xB00000 to   0xBFFFFF  in	A24 space. 
 *  The second 0x40000 of this space is on-board SRAM. 
1990/1013    
 */ 
struct Device { 
1991/0209    
	ulong	mem[0x100000/sizeof(ulong)]; 
1990/1013    
}; 
1990/1018    
#define HOTROD		VMEA24SUP(Device, 0xB00000) 
1990/1013    
 
1991/0209    
struct HotQ{ 
	ulong	i;			/* index into queue */ 
	Hotmsg	*msg[NhotQ];		/* pointer to command buffer */ 
	ulong	pad[3];			/* unused; for hotrod prints */ 
}; 
1990/1013    
 
1991/0209    
 
struct Hotrod{ 
	QLock; 
	Lock		busy; 
1990/1106    
	Device		*addr;		/* address of the device */ 
	int		vec;		/* vme interrupt vector */ 
1991/0209    
	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 */ 
1990/1106    
	Rendez		r; 
1990/1013    
}; 
 
Hotrod hotrod[Nhotrod]; 
 
1990/1106    
void	hotrodintr(int); 
1990/1013    
 
1991/0209    
/* 
 * Commands 
 */ 
enum{ 
	RESET=	0,	/* params: Q address, length of queue */ 
	REBOOT=	1,	/* params: none */ 
}; 
 
void 
hotsend(Hotrod *h, Hotmsg *m) 
1990/1013    
{ 
1991/0209    
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; 
1990/1013    
} 
 
/* 
 *  reset all hotrod boards 
 */ 
void 
hotrodreset(void) 
{ 
	int i; 
1990/1018    
	Hotrod *hp; 
1990/1013    
 
1991/0209    
	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); 
1990/1013    
	}	 
	wbflush(); 
	delay(20); 
} 
 
void 
hotrodinit(void) 
{ 
} 
 
/* 
 *  enable the device for interrupts, spec is the device number 
 */ 
Chan* 
hotrodattach(char *spec) 
{ 
1990/1106    
	Hotrod *hp; 
1990/1013    
	int i; 
	Chan *c; 
 
	i = strtoul(spec, 0, 0); 
	if(i >= Nhotrod) 
1990/11211    
		error(Ebadarg); 
1990/1013    
 
	c = devattach('H', spec); 
	c->dev = i; 
1990/11211    
	c->qid.path = CHDIR; 
	c->qid.vers = 0; 
1990/1013    
	return c; 
} 
 
Chan* 
hotrodclone(Chan *c, Chan *nc) 
{ 
	return devclone(c, nc); 
} 
 
int	  
hotrodwalk(Chan *c, char *name) 
{ 
1991/0209    
	if(c->qid.path != CHDIR) 
		return 0; 
	if(strncmp(name, "hotrod", 6) == 0){ 
		c->qid.path = Qhotrod; 
		return 1; 
	} 
	return 0; 
1990/1013    
} 
 
void	  
hotrodstat(Chan *c, char *dp) 
{ 
1991/0209    
	print("hotrodstat\n"); 
	error(Egreg); 
1990/1013    
} 
 
Chan* 
hotrodopen(Chan *c, int omode) 
{ 
1990/1106    
	Device *dp; 
	Hotrod *hp; 
 
1990/11211    
	if(c->qid.path == CHDIR){ 
1990/1013    
		if(omode != OREAD) 
1990/11211    
			error(Eperm); 
1991/0209    
	}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); 
1990/1018    
	} 
1990/1013    
	c->mode = openmode(omode); 
	c->flag |= COPEN; 
	c->offset = 0; 
	return c; 
} 
 
void	  
hotrodcreate(Chan *c, char *name, int omode, ulong perm) 
{ 
1990/11211    
	error(Eperm); 
1990/1013    
} 
 
void	  
hotrodclose(Chan *c) 
{ 
1991/0209    
	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); 
	} 
1990/1013    
} 
 
/* 
 *  read the hotrod memory 
 */ 
long	  
hotrodread(Chan *c, void *buf, long n) 
{ 
	Hotrod *hp; 
	Device *dp; 
1990/1018    
	ulong *from; 
	ulong *to; 
	ulong *end; 
1990/1013    
 
1991/0209    
	if(c->qid.path != Qhotrod) 
		error(Egreg); 
1990/1018    
 
	/* 
	 *  allow full word access only 
	 */ 
	if((c->offset&(sizeof(ulong)-1)) || (n&(sizeof(ulong)-1))) 
1990/11211    
		error(Ebadarg); 
1990/1018    
 
1990/1013    
	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; 
1990/1018    
 
	/* 
	 *  avoid memcpy to ensure VME 32-bit reads 
	 */ 
1990/1013    
	qlock(hp); 
1990/1018    
	to = buf; 
	from = &dp->mem[c->offset/sizeof(ulong)]; 
	end = to + (n/sizeof(ulong)); 
1990/1020    
	while(to != end){ 
1990/1018    
		*to++ = *from++; 
1990/1020    
	} 
1990/1013    
	qunlock(hp); 
	return n; 
} 
 
/* 
 *  write hotrod memory 
 */ 
long	  
hotrodwrite(Chan *c, void *buf, long n) 
{ 
	Hotrod *hp; 
	Device *dp; 
1990/1018    
	ulong *from; 
	ulong *to; 
	ulong *end; 
1990/1013    
 
1991/0209    
	if(c->qid.path != Qhotrod) 
		error(Egreg); 
1990/1018    
	/* 
	 *  allow full word access only 
	 */ 
	if((c->offset&(sizeof(ulong)-1)) || (n&(sizeof(ulong)-1))) 
1990/11211    
		error(Ebadarg); 
1990/1018    
 
1990/1013    
	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; 
1990/1018    
 
	/* 
	 *  avoid memcpy to ensure VME 32-bit writes 
	 */ 
1990/1013    
	qlock(hp); 
1990/1018    
	from = buf; 
	to = &dp->mem[c->offset/sizeof(ulong)]; 
	end = to + (n/sizeof(ulong)); 
	while(to != end) 
		*to++ = *from++; 
1990/1013    
	qunlock(hp); 
	return n; 
} 
 
void	  
hotrodremove(Chan *c) 
{ 
1990/11211    
	error(Eperm); 
1990/1013    
} 
 
void	  
hotrodwstat(Chan *c, char *dp) 
{ 
1990/11211    
	error(Eperm); 
1990/1013    
} 
 
1990/1106    
void 
1990/1013    
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; 
	} 
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)