Browse Source

Plan 9 from Bell Labs 2013-01-30

David du Colombier 11 years ago
parent
commit
ca0fa5ce3d

+ 0 - 2
sys/src/9/bcm/clock.c

@@ -97,7 +97,6 @@ clockinit(void)
 	tm = (Armtimer*)ARMTIMER;
 	tm->load = 0;
 	tm->ctl = TmrPrescale1|CntEnable|CntWidth32;
-	coherence();
 
 	tstart = tn->clo;
 	do{
@@ -172,7 +171,6 @@ armtimerset(int n)
 		tm->ctl &= ~(TmrEnable|TmrIntEnable);
 		tm->irq = 1;
 	}
-	coherence();
 }
 
 ulong

+ 42 - 35
sys/src/9/bcm/devusb.c

@@ -53,10 +53,10 @@ enum
 {
 	/* Qid numbers */
 	Qdir = 0,		/* #u */
-	Qusbdir,		/* #u/usb */
+	Qusbdir,			/* #u/usb */
 	Qctl,			/* #u/usb/ctl - control requests */
 
-	Qep0dir,		/* #u/usb/ep0.0 - endpoint 0 dir */
+	Qep0dir,			/* #u/usb/ep0.0 - endpoint 0 dir */
 	Qep0io,			/* #u/usb/ep0.0/data - endpoint 0 I/O */
 	Qep0ctl,		/* #u/usb/ep0.0/ctl - endpoint 0 ctl. */
 	Qep0dummy,		/* give 4 qids to each endpoint */
@@ -143,7 +143,7 @@ static Dirtab usbdir[] =
 char *usbmodename[] =
 {
 	[OREAD]	"r",
-	[OWRITE] "w",
+	[OWRITE]	"w",
 	[ORDWR]	"rw",
 };
 
@@ -237,7 +237,7 @@ name2mode(char *mode)
 static int
 qid2epidx(int q)
 {
-	q = (q - Qep0dir) / 4;
+	q = (q-Qep0dir)/4;
 	if(q < 0 || q >= epmax || eps[q] == nil)
 		return -1;
 	return q;
@@ -267,9 +267,10 @@ addhcitype(char* t, int (*r)(Hci*))
 static char*
 seprintep(char *s, char *se, Ep *ep, int all)
 {
+	static char* dsnames[] = { "config", "enabled", "detached", "reset" };
 	Udev *d;
-	int i, di;
-	static char *dsnames[] = { "config", "enabled", "detached", "reset" };
+	int i;
+	int di;
 
 	d = ep->dev;
 
@@ -346,7 +347,7 @@ epalloc(Hci *hp)
 	ep->hp = hp;
 	ep->maxpkt = 8;
 	ep->ntds = 1;
-	ep->samplesz = ep->pollival = ep->hz = 0;	/* make them void */
+	ep->samplesz = ep->pollival = ep->hz = 0; /* make them void */
 	qunlock(&epslck);
 	return ep;
 }
@@ -400,9 +401,10 @@ static void
 dumpeps(void)
 {
 	int i;
-	char *s, *e;
-	Ep *ep;
 	static char buf[512];
+	char *s;
+	char *e;
+	Ep *ep;
 
 	print("usb dump eps: epmax %d Neps %d (ref=1+ for dump):\n", epmax, Neps);
 	for(i = 0; i < epmax; i++){
@@ -518,6 +520,7 @@ newdevep(Ep *ep, int i, int tt, int mode)
 static int
 epdataperm(int mode)
 {
+
 	switch(mode){
 	case OREAD:
 		return 0440|DMEXCL;
@@ -533,11 +536,13 @@ epdataperm(int mode)
 static int
 usbgen(Chan *c, char *, Dirtab*, int, int s, Dir *dp)
 {
-	int mode, nb, perm;
-	char *se;
+	Qid q;
 	Dirtab *dir;
+	int perm;
+	char *se;
 	Ep *ep;
-	Qid q;
+	int nb;
+	int mode;
 
 	if(0)ddprint("usbgen q %#x s %d...", QID(c->qid), s);
 	if(s == DEVDOTDOT){
@@ -773,7 +778,8 @@ static ulong
 usbload(int speed, int maxpkt)
 {
 	enum{ Hostns = 1000, Hubns = 333 };
-	ulong l, bs;
+	ulong l;
+	ulong bs;
 
 	l = 0;
 	bs = 10UL * maxpkt;
@@ -791,14 +797,15 @@ usbload(int speed, int maxpkt)
 		print("usbload: bad speed %d\n", speed);
 		/* let it run */
 	}
-	return l / 1000UL;		/* in µs */
+	return l / 1000UL;	/* in µs */
 }
 
 static Chan*
 usbopen(Chan *c, int omode)
 {
-	int q, mode;
+	int q;
 	Ep *ep;
+	int mode;
 
 	mode = openmode(omode);
 	q = QID(c->qid);
@@ -845,7 +852,7 @@ usbopen(Chan *c, int omode)
 	c->mode = mode;
 	c->flag |= COPEN;
 	c->offset = 0;
-	c->aux = nil;		/* paranoia */
+	c->aux = nil;	/* paranoia */
 	return c;
 }
 
@@ -897,9 +904,12 @@ usbclose(Chan *c)
 static long
 ctlread(Chan *c, void *a, long n, vlong offset)
 {
-	int i, q;
-	char *s, *se, *us;
+	int q;
+	char *s;
+	char *us;
+	char *se;
 	Ep *ep;
+	int i;
 
 	q = QID(c->qid);
 	us = s = smalloc(READSTR);
@@ -916,8 +926,7 @@ ctlread(Chan *c, void *a, long n, vlong offset)
 					putep(ep);
 					nexterror();
 				}
-				s = seprint(s, se, "ep%d.%d ",
-					ep->dev->nb, ep->nb);
+				s = seprint(s, se, "ep%d.%d ", ep->dev->nb, ep->nb);
 				s = seprintep(s, se, ep, 0);
 				poperror();
 			}
@@ -932,8 +941,7 @@ ctlread(Chan *c, void *a, long n, vlong offset)
 			nexterror();
 		}
 		if(c->aux != nil){
-			/*
-			 * After a new endpoint request we read
+			/* After a new endpoint request we read
 			 * the new endpoint name back.
 			 */
 			strecpy(s, se, c->aux);
@@ -973,8 +981,10 @@ rhubread(Ep *ep, void *a, long n)
 static long
 rhubwrite(Ep *ep, void *a, long n)
 {
-	int cmd, feature, port;
 	uchar *s;
+	int cmd;
+	int feature;
+	int port;
 	Hci *hp;
 
 	if(ep->dev == nil || ep->dev->isroot == 0 || ep->nb != 0)
@@ -1003,7 +1013,6 @@ rhubwrite(Ep *ep, void *a, long n)
 		break;
 	default:
 		ep->rhrepl = 0;
-		break;
 	}
 	return n;
 }
@@ -1011,8 +1020,9 @@ rhubwrite(Ep *ep, void *a, long n)
 static long
 usbread(Chan *c, void *a, long n, vlong offset)
 {
-	int q, nr;
+	int q;
 	Ep *ep;
+	int nr;
 
 	q = QID(c->qid);
 
@@ -1042,10 +1052,9 @@ usbread(Chan *c, void *a, long n, vlong offset)
 			n = nr;
 			break;
 		}
-		/* else fall through */
+		/* else fall */
 	default:
-		ddeprint("\nusbread q %#x fid %d cnt %ld off %lld\n",
-			q, c->fid, n, offset);
+		ddeprint("\nusbread q %#x fid %d cnt %ld off %lld\n",q,c->fid,n,offset);
 		n = ep->hp->epread(ep, a, n);
 		break;
 	}
@@ -1063,7 +1072,7 @@ pow2(int n)
 static void
 setmaxpkt(Ep *ep, char* s)
 {
-	long spp;			/* samples per packet */
+	long spp;	/* samples per packet */
 
 	if(ep->dev->speed == Highspeed)
 		spp = (ep->hz * ep->pollival * ep->ntds + 7999) / 8000;
@@ -1081,7 +1090,7 @@ setmaxpkt(Ep *ep, char* s)
 }
 
 /*
- * Many endpoint ctls.  Simply update the portable representation
+ * Many endpoint ctls. simply update the portable representation
  * of the endpoint. The actual controller driver will look
  * at them to setup the endpoints as dictated.
  */
@@ -1140,8 +1149,7 @@ epctl(Ep *ep, Chan *c, void *a, long n)
 			nep->maxpkt = 64;	/* assume full speed */
 		nep->dev->hub = d->nb;
 		nep->dev->port = atoi(cb->f[2]);
-		/*
-		 * next read request will read
+		/* next read request will read
 		 * the name for the new endpoint
 		 */
 		l = sizeof(up->genbuf);
@@ -1404,10 +1412,9 @@ usbwrite(Chan *c, void *a, long n, vlong off)
 			n = nr;
 			break;
 		}
-		/* else fall through */
+		/* else fall */
 	default:
-		ddeprint("\nusbwrite q %#x fid %d cnt %ld off %lld\n",
-			q, c->fid, n, off);
+		ddeprint("\nusbwrite q %#x fid %d cnt %ld off %lld\n",q, c->fid, n, off);
 		ep->hp->epwrite(ep, a, n);
 	}
 	putep(ep);

+ 2 - 2
sys/src/9/bcm/dma.c

@@ -146,7 +146,7 @@ dmastart(int chan, int dev, int dir, void *src, void *dst, int len)
 		ctlr->regs = (u32int*)(DMAREGS + chan*Regsize);
 		ctlr->cb = xspanalloc(sizeof(Cb), Cbalign, 0);
 		assert(ctlr->cb != nil);
-		dmaregs[Enable] |= 1 << chan;
+		dmaregs[Enable] |= 1<<chan;
 		ctlr->regs[Cs] = Reset;
 		while(ctlr->regs[Cs] & Reset)
 			;
@@ -175,7 +175,7 @@ dmastart(int chan, int dev, int dir, void *src, void *dst, int len)
 		cb->destad = DMAADDR(dst);
 		break;
 	}
-	cb->ti = ti | dev << Permapshift | Inten;
+	cb->ti = ti | dev<<Permapshift | Inten;
 	cb->txfrlen = len;
 	cb->stride = 0;
 	cb->nextconbk = 0;

+ 2 - 2
sys/src/9/bcm/dwcotg.h

@@ -434,8 +434,8 @@ enum {
 		Episo		= 1<<18,
 		Epbulk		= 2<<18,
 		Epintr		= 3<<18,
-	Multicnt	= 0x3<<20,	/* transactions per μframe or retries */
-					/* per periodic split */
+	Multicnt	= 0x3<<20,	/* transactions per μframe */
+					/* or retries per periodic split */
 		OMulticnt	= 20,
 	Devaddr		= 0x7f<<22,	/* device address */
 		ODevaddr	= 22,

+ 9 - 8
sys/src/9/bcm/emmc.c

@@ -160,7 +160,7 @@ WR(int reg, u32int val)
 	u32int *r = (u32int*)EMMCREGS;
 
 	if(0)print("WR %2.2ux %ux\n", reg<<2, val);
-	microdelay(emmc.fastclock? 2: 20);
+	microdelay(emmc.fastclock? 2 : 20);
 	r[reg] = val;
 }
 
@@ -226,8 +226,8 @@ emmcenable(void)
 	int i;
 
 	r = (u32int*)EMMCREGS;
-	WR(Control1, clkdiv(emmc.extclk / Initfreq - 1) | DTO << Datatoshift |
-		Clkgendiv | Clken | Clkintlen);
+	WR(Control1, clkdiv(emmc.extclk/Initfreq - 1) |
+		DTO<<Datatoshift | Clkgendiv | Clken | Clkintlen);
 	for(i = 0; i < 1000; i++){
 		delay(1);
 		if(r[Control1] & Clkstable)
@@ -259,8 +259,8 @@ emmccmd(u32int cmd, u32int arg, u32int *resp)
 		while(r[Status] & Cmdinhibit)
 			;
 	}
-	if((c & Isdata || (c & Respmask) == Resp48busy) &&
-	    r[Status] & Datinhibit){
+	if((r[Status] & Datinhibit) &&
+	   ((c & Isdata) || (c & Respmask) == Resp48busy)){
 		print("emmccmd: need to reset Datinhibit intr %ux stat %ux\n",
 			r[Interrupt], r[Status]);
 		WR(Control1, r[Control1] | Srstdata);
@@ -325,8 +325,8 @@ emmccmd(u32int cmd, u32int arg, u32int *resp)
 	 */
 	if(cmd == MMCSelect){
 		delay(10);
-		WR(Control1, clkdiv(emmc.extclk / SDfreq - 1) |
-			DTO << Datatoshift | Clkgendiv | Clken | Clkintlen);
+		WR(Control1, clkdiv(emmc.extclk/SDfreq - 1) |
+			DTO<<Datatoshift | Clkgendiv | Clken | Clkintlen);
 		for(i = 0; i < 1000; i++){
 			delay(1);
 			if(r[Control1] & Clkstable)
@@ -338,7 +338,7 @@ emmccmd(u32int cmd, u32int arg, u32int *resp)
 	/*
 	 * If card bus width changes, change host bus width
 	 */
-	if(cmd == Setbuswidth)
+	if(cmd == Setbuswidth){
 		switch(arg){
 		case 0:
 			WR(Control0, r[Control0] & ~Dwidth4);
@@ -347,6 +347,7 @@ emmccmd(u32int cmd, u32int arg, u32int *resp)
 			WR(Control0, r[Control0] | Dwidth4);
 			break;
 		}
+	}
 	return 0;
 }
 

+ 1 - 1
sys/src/9/bcm/etherusb.c

@@ -197,7 +197,7 @@ transmitasix(Ctlr *ctlr, Block *b)
 	int n;
 
 	n = BLEN(b) & 0xFFFF;
-	n = 0xFFFF0000 & ~(n << 16) | n;
+	n |= ~n << 16;
 	padblock(b, 4);
 	PUT4(b->rp, n);
 	if(BLEN(b) % ctlr->maxpkt == 0){

+ 1 - 3
sys/src/9/bcm/mkfile

@@ -1,6 +1,6 @@
 CONF=pi
 CONFLIST=pi picpu pifat
-EXTRACOPIES=piestand lookout boundary # bovril
+EXTRACOPIES=
 
 loadaddr=0x80008000
 
@@ -130,8 +130,6 @@ reboot.h:D:	rebootcode.s arm.s arm.h mem.h
 	 xd -1x reboot.out |
 		sed -e '1,2d' -e 's/^[0-9a-f]+ //' -e 's/ ([0-9a-f][0-9a-f])/0x\1,/g'
 	 echo '};'} > reboot.h
-errstr.h:D:	../port/mkerrstr ../port/error.h
-	rc ../port/mkerrstr > errstr.h
 
 $CONF.clean:
 	rm -rf $p$CONF s$p$CONF errstr.h reboot.h $CONF.c boot$CONF.c

+ 2 - 1
sys/src/9/bcm/screen.c

@@ -299,7 +299,8 @@ screensize(void)
 
 	p = getconf("vgasize");
 	if(p == nil || getfields(p, f, nelem(f), 0, "x") != nelem(f) ||
-	    (width = atoi(f[0])) < 16 || (height = atoi(f[1])) <= 0 ||
+	    (width = atoi(f[0])) < 16 ||
+	    (height = atoi(f[1])) <= 0 ||
 	    (depth = atoi(f[2])) <= 0)
 		return -1;
 	xgscreen.r.max = Pt(width, height);

+ 5 - 4
sys/src/9/bcm/uartmini.c

@@ -85,7 +85,7 @@ gpiosel(uint pin, int func)
 	gp = (u32int*)GPIOREGS;
 	fsel = &gp[Fsel0 + pin/10];
 	off = (pin % 10) * 3;
-	*fsel = (*fsel & ~(FuncMask << off)) | func << off;
+	*fsel = (*fsel & ~(FuncMask<<off)) | func<<off;
 }
 
 void
@@ -111,7 +111,7 @@ gpioout(uint pin, int set)
 	int v;
 
 	gp = (u32int*)GPIOREGS;
-	v = set? Set0: Clr0;
+	v = set? Set0 : Clr0;
 	gp[v + pin/32] = 1 << (pin % 32);
 }
 
@@ -139,11 +139,12 @@ interrupt(Ureg*, void *arg)
 	if(ap[MuLsr] & TxRdy)
 		uartkick(uart);
 	if(ap[MuLsr] & RxRdy){
-		if(uart->console)
+		if(uart->console){
 			if(uart->opens == 1)
 				uart->putc = kbdcr2nl;
 			else
 				uart->putc = nil;
+		}
 		do{
 			uartrecv(uart, ap[MuIo] & 0xFF);
 		}while(ap[MuLsr] & RxRdy);
@@ -177,7 +178,7 @@ enable(Uart *uart, int ie)
 	ap[MuIir] = 6;
 	ap[MuLcr] = Bits8;
 	ap[MuCntl] = TxEn|RxEn;
-	ap[MuBaud] = 250000000 / (115200 * 8) - 1;
+	ap[MuBaud] = 250000000/(115200*8) - 1;
 	if(ie){
 		intrenable(IRQaux, interrupt, uart, 0, "uart");
 		ap[MuIer] = RxIen|TxIen;

+ 28 - 23
sys/src/9/bcm/usbdwc.c

@@ -77,7 +77,7 @@ chanalloc(Ep *ep)
 	bitmap = ctlr->chanbusy;
 	for(i = 0; i < ctlr->nchan; i++)
 		if((bitmap & (1<<i)) == 0){
-			ctlr->chanbusy = bitmap | 1 << i;
+			ctlr->chanbusy = bitmap | 1<<i;
 			qunlock(&ctlr->chanlock);
 			return &ctlr->regs->hchan[i];
 		}
@@ -95,7 +95,7 @@ chanrelease(Ep *ep, Hostchan *chan)
 	ctlr = ep->hp->aux;
 	i = chan - ctlr->regs->hchan;
 	qlock(&ctlr->chanlock);
-	ctlr->chanbusy &= ~(1 << i);
+	ctlr->chanbusy &= ~(1<<i);
 	qunlock(&ctlr->chanlock);
 }
 
@@ -138,7 +138,7 @@ chansetup(Hostchan *hc, Ep *ep)
 		hcc |= Lspddev;
 		/* fall through */
 	case Fullspeed:
-		hc->hcsplt = Spltena | POS_ALL | ep->dev->hub << OHubaddr |
+		hc->hcsplt = Spltena | POS_ALL | ep->dev->hub<<OHubaddr |
 			ep->dev->port;
 		break;
 	default:
@@ -168,7 +168,7 @@ sofwait(Ctlr *ctlr, int n)
 	do{
 		r->gintsts = Sofintr;
 		x = splfhi();
-		ctlr->sofchan |= 1 << n;
+		ctlr->sofchan |= 1<<n;
 		r->gintmsk |= Sofintr;
 		sleep(&ctlr->chanintr[n], sofdone, r);
 		splx(x);
@@ -196,7 +196,7 @@ chanwait(Ep *ep, Ctlr *ctlr, Hostchan *hc, int mask)
 	for(;;){
 restart:
 		x = splfhi();
-		r->haintmsk |= 1 << n;
+		r->haintmsk |= 1<<n;
 		hc->hcintmsk = mask;
 		sleep(&ctlr->chanintr[n], chandone, hc);
 		hc->hcintmsk = 0;
@@ -211,14 +211,15 @@ restart:
 			intr = hc->hcint;
 			if(intr & Chhltd){
 				if((ointr != Ack && ointr != (Ack|Xfercomp)) ||
-				    intr != (Ack|Chhltd|Xfercomp) ||
-				    (now - start) > 60)
+				   intr != (Ack|Chhltd|Xfercomp) ||
+				   (now - start) > 60)
 					dprint("await %x after %ld %x -> %x\n",
 						mask, now - start, ointr, intr);
 				return intr;
 			}
 			if((intr & mask) == 0){
-				dprint("ep%d.%d await %x intr %x -> %x\n",						ep->dev->nb, ep->nb, mask, ointr, intr);
+				dprint("ep%d.%d await %x intr %x -> %x\n",
+					ep->dev->nb, ep->nb, mask, ointr, intr);
 				goto restart;
 			}
 			now = fastticks(0);
@@ -248,7 +249,7 @@ chanintr(Ctlr *ctlr, int n)
 	int i;
 
 	hc = &ctlr->regs->hchan[n];
-	if(ctlr->debugchan & (1 << n))
+	if(ctlr->debugchan & (1<<n))
 		clog(nil, hc);
 	if((hc->hcsplt & Spltena) == 0)
 		return 0;
@@ -340,7 +341,7 @@ chanio(Ep *ep, Hostchan *hc, int dir, int pid, void *a, int len)
 		n = ROUND(len, ep->maxpkt);
 	else
 		n = len;
-	hc->hctsiz = n | npkt << OPktcnt | pid;
+	hc->hctsiz = n | npkt<<OPktcnt | pid;
 	hc->hcdma  = PADDR(a);
 
 	nleft = len;
@@ -407,31 +408,33 @@ chanio(Ep *ep, Hostchan *hc, int dir, int pid, void *a, int len)
 					hcdma, hc->hcdma, i, hc->hcint);
 		}
 		n = hc->hcdma - hcdma;
-		if(n == 0)
+		if(n == 0){
 			if((hc->hctsiz & Pktcnt) != (hctsiz & Pktcnt))
 				break;
 			else
 				continue;
+		}
 		if(dir == Epin && ep->ttype == Tbulk && n == nleft){
 			nt = (hctsiz & Xfersize) - (hc->hctsiz & Xfersize);
-			if(nt != n)
-				if(n == ((nt+3) & ~3))
+			if(nt != n){
+				if(n == ROUND(nt, 4))
 					n = nt;
 				else
-					print("usbotg: intr %8.8ux dma "
-						"%8.8ux-%8.8ux hctsiz "
-						"%8.8ux-%8.ux\n",
+					print("usbotg: intr %8.8ux "
+						"dma %8.8ux-%8.8ux "
+						"hctsiz %8.8ux-%8.ux\n",
 						i, hcdma, hc->hcdma, hctsiz,
 						hc->hctsiz);
+			}
 		}
 		if(n > nleft){
-			if(n != ((nleft+3) & ~3))
+			if(n != ROUND(nleft, 4))
 				dprint("too much: wanted %d got %d\n",
 					len, len - nleft + n);
 			n = nleft;
 		}
 		nleft -= n;
-		if(nleft == 0 || n % maxpkt != 0)
+		if(nleft == 0 || (n % maxpkt) != 0)
 			break;
 		if((i & Xfercomp) && ep->ttype != Tctl)
 			break;
@@ -479,7 +482,7 @@ eptrans(Ep *ep, int rw, void *a, long n)
 		}while(sofar < n && m == ep->maxpkt);
 		n = sofar;
 	}else{
-		n = chanio(ep, hc, rw == Read? Epin: Epout, ep->toggle[rw],
+		n = chanio(ep, hc, rw == Read? Epin : Epout, ep->toggle[rw],
 			a, n);
 		ep->toggle[rw] = hc->hctsiz & Pid;
 	}
@@ -602,7 +605,7 @@ init(Hci *hp)
 	tx = 0x100;
 	ptx = 0x200;
 	r->grxfsiz = rx;
-	r->gnptxfsiz = rx | tx << ODepth;
+	r->gnptxfsiz = rx | tx<<ODepth;
 	tsleep(&up->sleep, return0, 0, 1);
 	r->hptxfsiz = (rx + tx) | ptx << ODepth;
 	greset(r, Rxfflsh);
@@ -639,9 +642,11 @@ fiqintr(Ureg*, void *a)
 	if(intr & Hcintr){
 		haint = r->haint & r->haintmsk;
 		for(i = 0; haint; i++){
-			if(haint & 1 && chanintr(ctlr, i) == 0){
-				r->haintmsk &= ~(1 << i);
-				wakechan |= 1 << i;
+			if(haint & 1){
+				if(chanintr(ctlr, i) == 0){
+					r->haintmsk &= ~(1<<i);
+					wakechan |= 1<<i;
+				}
 			}
 			haint >>= 1;
 		}

+ 4 - 2
sys/src/9/bcm/vcore.c

@@ -139,7 +139,9 @@ vcreq(int tag, void *buf, int vallen, int rsplen)
 			return -1;
 		base = 0;
 	}
-	if(prop->req == RspOk && prop->tag == tag && prop->taglen & TagResp) {
+	if(prop->req == RspOk &&
+	   prop->tag == tag &&
+	   (prop->taglen&TagResp)) {
 		if((n = prop->taglen & ~TagResp) < rsplen)
 			rsplen = n;
 		memmove(buf, prop->data, rsplen);
@@ -212,7 +214,7 @@ setpower(int dev, int on)
 	u32int buf[2];
 
 	buf[0] = dev;
-	buf[1] = Powerwait | (on? 1: 0);
+	buf[1] = Powerwait | (on? 1 : 0);
 	vcreq(TagSetpower, buf, sizeof buf, sizeof buf);
 }
 

+ 1 - 518
sys/src/9/bcm/vfp3.c

@@ -1,518 +1 @@
-/*
- * VFPv2 or VFPv3 floating point unit
- */
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "ureg.h"
-#include "arm.h"
-
-/* subarchitecture code in m->havefp */
-enum {
-	VFPv2	= 2,
-	VFPv3	= 3,
-};
-
-/* fp control regs.  most are read-only */
-enum {
-	Fpsid =	0,
-	Fpscr =	1,			/* rw */
-	Mvfr1 =	6,
-	Mvfr0 =	7,
-	Fpexc =	8,			/* rw */
-	Fpinst= 9,			/* optional, for exceptions */
-	Fpinst2=10,
-};
-enum {
-	/* Fpexc bits */
-	Fpex =		1u << 31,
-	Fpenabled =	1 << 30,
-	Fpdex =		1 << 29,	/* defined synch exception */
-//	Fp2v =		1 << 28,	/* Fpinst2 reg is valid */
-//	Fpvv =		1 << 27,	/* if Fpdex, vecitr is valid */
-//	Fptfv = 	1 << 26,	/* trapped fault is valid */
-//	Fpvecitr =	MASK(3) << 8,
-	/* FSR bits appear here */
-	Fpmbc =		Fpdex,		/* bits exception handler must clear */
-
-	/* Fpscr bits; see u.h for more */
-	Stride =	MASK(2) << 20,
-	Len =		MASK(3) << 16,
-	Dn=		1 << 25,
-	Fz=		1 << 24,
-	/* trap exception enables (not allowed in vfp3) */
-	FPIDNRM =	1 << 15,	/* input denormal */
-	Alltraps = FPIDNRM | FPINEX | FPUNFL | FPOVFL | FPZDIV | FPINVAL,
-	/* pending exceptions */
-	FPAIDNRM =	1 << 7,		/* input denormal */
-	Allexc = FPAIDNRM | FPAINEX | FPAUNFL | FPAOVFL | FPAZDIV | FPAINVAL,
-	/* condition codes */
-	Allcc =		MASK(4) << 28,
-};
-enum {
-	/* CpCPaccess bits */
-	Cpaccnosimd =	1u << 31,
-	Cpaccd16 =	1 << 30,
-};
-
-static char *
-subarch(int impl, uint sa)
-{
-	static char *armarchs[] = {
-		"VFPv1 (unsupported)",
-		"VFPv2",
-		"VFPv3+ with common VFP subarch v2",
-		"VFPv3+ with null subarch",
-		"VFPv3+ with common VFP subarch v3",
-	};
-
-	if (impl != 'A' || sa >= nelem(armarchs))
-		return "GOK";
-	else
-		return armarchs[sa];
-}
-
-static char *
-implement(uchar impl)
-{
-	if (impl == 'A')
-		return "arm";
-	else
-		return "unknown";
-}
-
-static int
-havefp(void)
-{
-	int gotfp;
-	ulong acc, sid;
-
-	if (m->havefpvalid)
-		return m->havefp;
-
-	m->havefp = 0;
-	gotfp = 1 << CpFP | 1 << CpDFP;
-	cpwrsc(0, CpCONTROL, 0, CpCPaccess, MASK(28));
-	acc = cprdsc(0, CpCONTROL, 0, CpCPaccess);
-	if ((acc & (MASK(2) << (2*CpFP))) == 0) {
-		gotfp &= ~(1 << CpFP);
-		print("fpon: no single FP coprocessor\n");
-	}
-	if ((acc & (MASK(2) << (2*CpDFP))) == 0) {
-		gotfp &= ~(1 << CpDFP);
-		print("fpon: no double FP coprocessor\n");
-	}
-	if (!gotfp) {
-		print("fpon: no FP coprocessors\n");
-		m->havefpvalid = 1;
-		return 0;
-	}
-	m->fpon = 1;			/* don't panic */
-	sid = fprd(Fpsid);
-	m->fpon = 0;
-	switch((sid >> 16) & MASK(7)){
-	case 0:				/* VFPv1 */
-		break;
-	case 1:				/* VFPv2 */
-		m->havefp = VFPv2;
-		m->fpnregs = 16;
-		break;
-	default:			/* VFPv3 or later */
-		m->havefp = VFPv3;
-		m->fpnregs = (acc & Cpaccd16) ? 16 : 32;
-		break;
-	}
-	if (m->machno == 0)
-		print("fp: %d registers, %s simd\n", m->fpnregs,
-			(acc & Cpaccnosimd? " no": ""));
-	m->havefpvalid = 1;
-	return 1;
-}
-
-/*
- * these can be called to turn the fpu on or off for user procs,
- * not just at system start up or shutdown.
- */
-
-void
-fpoff(void)
-{
-	if (m->fpon) {
-		fpwr(Fpexc, 0);
-		m->fpon = 0;
-	}
-}
-
-void
-fpononly(void)
-{
-	if (!m->fpon && havefp()) {
-		/* enable fp.  must be first operation on the FPUs. */
-		fpwr(Fpexc, Fpenabled);
-		m->fpon = 1;
-	}
-}
-
-static void
-fpcfg(void)
-{
-	int impl;
-	ulong sid;
-	static int printed;
-
-	/* clear pending exceptions; no traps in vfp3; all v7 ops are scalar */
-	m->fpscr = Dn | Fz | FPRNR | (FPINVAL | FPZDIV | FPOVFL) & ~Alltraps;
-	fpwr(Fpscr, m->fpscr);
-	m->fpconfiged = 1;
-
-	if (printed)
-		return;
-	sid = fprd(Fpsid);
-	impl = sid >> 24;
-	print("fp: %s arch %s; rev %ld\n", implement(impl),
-		subarch(impl, (sid >> 16) & MASK(7)), sid & MASK(4));
-	printed = 1;
-}
-
-void
-fpinit(void)
-{
-	if (havefp()) {
-		fpononly();
-		fpcfg();
-	}
-}
-
-void
-fpon(void)
-{
-	if (havefp()) {
-	 	fpononly();
-		if (m->fpconfiged)
-			fpwr(Fpscr, (fprd(Fpscr) & Allcc) | m->fpscr);
-		else
-			fpcfg();	/* 1st time on this fpu; configure it */
-	}
-}
-
-void
-fpclear(void)
-{
-//	ulong scr;
-
-	fpon();
-//	scr = fprd(Fpscr);
-//	m->fpscr = scr & ~Allexc;
-//	fpwr(Fpscr, m->fpscr);
-
-	fpwr(Fpexc, fprd(Fpexc) & ~Fpmbc);
-}
-
-
-/*
- * Called when a note is about to be delivered to a
- * user process, usually at the end of a system call.
- * Note handlers are not allowed to use the FPU so
- * the state is marked (after saving if necessary) and
- * checked in the Device Not Available handler.
- */
-void
-fpunotify(Ureg*)
-{
-	if(up->fpstate == FPactive){
-		fpsave(&up->fpsave);
-		up->fpstate = FPinactive;
-	}
-	up->fpstate |= FPillegal;
-}
-
-/*
- * Called from sysnoted() via the machine-dependent
- * noted() routine.
- * Clear the flag set above in fpunotify().
- */
-void
-fpunoted(void)
-{
-	up->fpstate &= ~FPillegal;
-}
-
-/*
- * Called early in the non-interruptible path of
- * sysrfork() via the machine-dependent syscall() routine.
- * Save the state so that it can be easily copied
- * to the child process later.
- */
-void
-fpusysrfork(Ureg*)
-{
-	if(up->fpstate == FPactive){
-		fpsave(&up->fpsave);
-		up->fpstate = FPinactive;
-	}
-}
-
-/*
- * Called later in sysrfork() via the machine-dependent
- * sysrforkchild() routine.
- * Copy the parent FPU state to the child.
- */
-void
-fpusysrforkchild(Proc *p, Ureg *, Proc *up)
-{
-	/* don't penalize the child, it hasn't done FP in a note handler. */
-	p->fpstate = up->fpstate & ~FPillegal;
-}
-
-/* should only be called if p->fpstate == FPactive */
-void
-fpsave(FPsave *fps)
-{
-	int n;
-
-	fpon();
-	fps->control = fps->status = fprd(Fpscr);
-	assert(m->fpnregs);
-	for (n = 0; n < m->fpnregs; n++)
-		fpsavereg(n, (uvlong *)fps->regs[n]);
-	fpoff();
-}
-
-static void
-fprestore(Proc *p)
-{
-	int n;
-
-	fpon();
-	fpwr(Fpscr, p->fpsave.control);
-	m->fpscr = fprd(Fpscr) & ~Allcc;
-	assert(m->fpnregs);
-	for (n = 0; n < m->fpnregs; n++)
-		fprestreg(n, *(uvlong *)p->fpsave.regs[n]);
-}
-
-/*
- * Called from sched() and sleep() via the machine-dependent
- * procsave() routine.
- * About to go in to the scheduler.
- * If the process wasn't using the FPU
- * there's nothing to do.
- */
-void
-fpuprocsave(Proc *p)
-{
-	if(p->fpstate == FPactive){
-		if(p->state == Moribund)
-			fpclear();
-		else{
-			/*
-			 * Fpsave() stores without handling pending
-			 * unmasked exeptions. Postnote() can't be called
-			 * here as sleep() already has up->rlock, so
-			 * the handling of pending exceptions is delayed
-			 * until the process runs again and generates an
-			 * emulation fault to activate the FPU.
-			 */
-			fpsave(&p->fpsave);
-		}
-		p->fpstate = FPinactive;
-	}
-}
-
-/*
- * The process has been rescheduled and is about to run.
- * Nothing to do here right now. If the process tries to use
- * the FPU again it will cause a Device Not Available
- * exception and the state will then be restored.
- */
-void
-fpuprocrestore(Proc *)
-{
-}
-
-/*
- * Disable the FPU.
- * Called from sysexec() via sysprocsetup() to
- * set the FPU for the new process.
- */
-void
-fpusysprocsetup(Proc *p)
-{
-	p->fpstate = FPinit;
-	fpoff();
-}
-
-static void
-mathnote(void)
-{
-	ulong status;
-	char *msg, note[ERRMAX];
-
-	status = up->fpsave.status;
-
-	/*
-	 * Some attention should probably be paid here to the
-	 * exception masks and error summary.
-	 */
-	if (status & FPAINEX)
-		msg = "inexact";
-	else if (status & FPAOVFL)
-		msg = "overflow";
-	else if (status & FPAUNFL)
-		msg = "underflow";
-	else if (status & FPAZDIV)
-		msg = "divide by zero";
-	else if (status & FPAINVAL)
-		msg = "bad operation";
-	else
-		msg = "spurious";
-	snprint(note, sizeof note, "sys: fp: %s fppc=%#p status=%#lux",
-		msg, up->fpsave.pc, status);
-	postnote(up, 1, note, NDebug);
-}
-
-static void
-mathemu(Ureg *)
-{
-	if(m->havefp == VFPv3 && !(fprd(Fpexc) & (Fpex|Fpdex)))
-		iprint("mathemu: not an FP exception but an unknown FP opcode\n");
-	switch(up->fpstate){
-	case FPemu:
-		error("illegal instruction: VFP opcode in emulated mode");
-	case FPinit:
-		fpinit();
-		up->fpstate = FPactive;
-		break;
-	case FPinactive:
-		/*
-		 * Before restoring the state, check for any pending
-		 * exceptions.  There's no way to restore the state without
-		 * generating an unmasked exception.
-		 * More attention should probably be paid here to the
-		 * exception masks and error summary.
-		 */
-		if(up->fpsave.status & (FPAINEX|FPAUNFL|FPAOVFL|FPAZDIV|FPAINVAL)){
-			mathnote();
-			break;
-		}
-		fprestore(up);
-		up->fpstate = FPactive;
-		break;
-	case FPactive:
-		error("illegal instruction: bad vfp fpu opcode");
-		break;
-	}
-	fpclear();
-}
-
-void
-fpstuck(uintptr pc)
-{
-	if (m->fppc == pc && m->fppid == up->pid) {
-		m->fpcnt++;
-		if (m->fpcnt > 4)
-			panic("fpuemu: cpu%d stuck at pid %ld %s pc %#p "
-				"instr %#8.8lux", m->machno, up->pid, up->text,
-				pc, *(ulong *)pc);
-	} else {
-		m->fppid = up->pid;
-		m->fppc = pc;
-		m->fpcnt = 0;
-	}
-}
-
-enum {
-	N = 1<<31,
-	Z = 1<<30,
-	C = 1<<29,
-	V = 1<<28,
-	REGPC = 15,
-};
-
-static int
-condok(int cc, int c)
-{
-	switch(c){
-	case 0:	/* Z set */
-		return cc&Z;
-	case 1:	/* Z clear */
-		return (cc&Z) == 0;
-	case 2:	/* C set */
-		return cc&C;
-	case 3:	/* C clear */
-		return (cc&C) == 0;
-	case 4:	/* N set */
-		return cc&N;
-	case 5:	/* N clear */
-		return (cc&N) == 0;
-	case 6:	/* V set */
-		return cc&V;
-	case 7:	/* V clear */
-		return (cc&V) == 0;
-	case 8:	/* C set and Z clear */
-		return cc&C && (cc&Z) == 0;
-	case 9:	/* C clear or Z set */
-		return (cc&C) == 0 || cc&Z;
-	case 10:	/* N set and V set, or N clear and V clear */
-		return (~cc&(N|V))==0 || (cc&(N|V)) == 0;
-	case 11:	/* N set and V clear, or N clear and V set */
-		return (cc&(N|V))==N || (cc&(N|V))==V;
-	case 12:	/* Z clear, and either N set and V set or N clear and V clear */
-		return (cc&Z) == 0 && ((~cc&(N|V))==0 || (cc&(N|V))==0);
-	case 13:	/* Z set, or N set and V clear or N clear and V set */
-		return (cc&Z) || (cc&(N|V))==N || (cc&(N|V))==V;
-	case 14:	/* always */
-		return 1;
-	case 15:	/* never (reserved) */
-		return 0;
-	}
-	return 0;	/* not reached */
-}
-
-/* only called to deal with user-mode instruction faults */
-int
-fpuemu(Ureg* ureg)
-{
-	int s, nfp, cop, op;
-	uintptr pc;
-
-	if(waserror()){
-		postnote(up, 1, up->errstr, NDebug);
-		return 1;
-	}
-
-	if(up->fpstate & FPillegal)
-		error("floating point in note handler");
-
-	nfp = 0;
-	pc = ureg->pc;
-	validaddr(pc, 4, 0);
-	if(!condok(ureg->psr, *(ulong*)pc >> 28))
-		iprint("fpuemu: conditional instr shouldn't have got here\n");
-	op  = (*(ulong *)pc >> 24) & MASK(4);
-	cop = (*(ulong *)pc >>  8) & MASK(4);
-	if(m->fpon)
-		fpstuck(pc);		/* debugging; could move down 1 line */
-	if (ISFPAOP(cop, op)) {		/* old arm 7500 fpa opcode? */
-//		iprint("fpuemu: fpa instr %#8.8lux at %#p\n", *(ulong *)pc, pc);
-//		error("illegal instruction: old arm 7500 fpa opcode");
-		s = spllo();
-		if(waserror()){
-			splx(s);
-			nexterror();
-		}
-		nfp = fpiarm(ureg);	/* advances pc past emulated instr(s) */
-		if (nfp > 1)		/* could adjust this threshold */
-			m->fppc = m->fpcnt = 0;
-		splx(s);
-		poperror();
-	} else if (ISVFPOP(cop, op)) {	/* if vfp, fpu must be off */
-		mathemu(ureg);		/* enable fpu & retry */
-		nfp = 1;
-	}
-
-	poperror();
-	return nfp;
-}
+#include "../teg2/vfp3.c"

+ 6 - 6
sys/src/9/bcm/words

@@ -10,11 +10,12 @@ l1 I & D VIPT caches
 unified l2 PIPT cache 128K: 4-way?, 1024? sets, 32-byte lines, mostly for gpu
 (by default CPU doesn't see it)
 
-we arrange that device register accesses are uncached.
+we arrange that device register accesses are uncached and unbuffered
+(strongly ordered, in armv6/v7 terminology).
 
-256MB of dram at physical address 0, shared with gpu
+256MB or 512MB of dram at physical address 0, shared with gpu
 non-16550 uart for console
-	uart serial voltages are wrong (3.3v but rs232 is nominally 12v);
+	uart serial voltages are TTL (3.3v, not rs232 which is nominally 12v);
 	could use usb serial (ick).
 there's no real ethernet controller, so we have to use usb ether,
 and the usb controller is nastier than usual.
@@ -56,7 +57,7 @@ Booting from sd card:
 
 hex addr size	what
 ----
-0	 256MB	sdram, cached
+0	 256MB	sdram, cached (newer models have 512MB)
 00000000 64	exception vectors
 00000100 7936	boot ATAGs (inc. cmdline.txt)
 00002000 4K	Mach
@@ -95,8 +96,7 @@ hex addr size	what
 ----
 0	 512MB	user process address space
 7e000000 16M	i/o registers
-80000000 <=224M	kernel ram (reserve some for GPU)
-c0000000 256MB	kzero, mapped to 0
+80000000 <=224M	kzero, kernel ram (reserve some for GPU)
 ffff0000 4K	exception vectors
 
 Linux params at *R2 (default 0x100) are a sequence of ATAGs