From 2c7d4f0dbbab45e726914a89ee9c279c18825119 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 16 Apr 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-04-16 --- pc/usbuhci.c | 49 ++++++++++++++++++++++++---------------------- port/chan.c | 5 +++-- port/devpnp.c | 6 +++--- port/devrealtime.c | 4 ++++ port/portclock.c | 8 -------- port/proc.c | 1 + port/taslock.c | 9 +++++++-- 7 files changed, 44 insertions(+), 38 deletions(-) diff --git a/pc/usbuhci.c b/pc/usbuhci.c index d47f0fd79cf30091dff74cbace3317fc8020b8d1..b287ff093d1cc951fcbf46534be192a3dd72a1e6 100644 --- a/pc/usbuhci.c +++ b/pc/usbuhci.c @@ -933,24 +933,6 @@ portinfo(Usbhost *uh, char *s, char *se) } } -static void -init(Usbhost* uh) -{ - Ctlr *ctlr; - - ctlr = uh->ctlr; - ilock(ctlr); - outl(ctlr->io+Flbaseadd, PCIWADDR(ctlr->frames)); - OUT(Frnum, 0); - OUT(Usbintr, 0xF); /* enable all interrupts */ - XPRINT("cmd 0x%x sofmod 0x%x\n", IN(Cmd), inb(ctlr->io+SOFMod)); - XPRINT("sc0 0x%x sc1 0x%x\n", IN(Portsc0), IN(Portsc1)); - if((IN(Cmd)&1)==0) - OUT(Cmd, 1); /* run */ -// pprint("at: c=%x s=%x c0=%x\n", IN(Cmd), IN(Status), IN(Portsc0)); - iunlock(ctlr); -} - static void cleaniso(Endpt *e, int frnum) { @@ -965,9 +947,8 @@ cleaniso(Endpt *e, int frnum) return; id = (e->x<<7)|(e->dev->x&0x7F); do { -//shut up! -// if (td->status & AnyError) -// iprint("usbisoerror 0x%lux\n", td->status); + if (td->status & AnyError) + XPRINT("usbisoerror 0x%lux\n", td->status); n = (td->status + 1) & 0x3ff; e->nbytes += n; if ((td->flags & IsoClean) == 0) @@ -1353,6 +1334,24 @@ XPRINT("qh %s: q=%p first=%p last=%p entries=%.8lux\n", return p-(uchar*)a; } +static void +init(Usbhost* uh) +{ + Ctlr *ctlr; + + ctlr = uh->ctlr; + ilock(ctlr); + outl(ctlr->io+Flbaseadd, PCIWADDR(ctlr->frames)); + OUT(Frnum, 0); + OUT(Usbintr, 0xF); /* enable all interrupts */ + XPRINT("cmd 0x%x sofmod 0x%x\n", IN(Cmd), inb(ctlr->io+SOFMod)); + XPRINT("sc0 0x%x sc1 0x%x\n", IN(Portsc0), IN(Portsc1)); + if((IN(Cmd)&1)==0) + OUT(Cmd, 1); /* run */ +// pprint("at: c=%x s=%x c0=%x\n", IN(Cmd), IN(Status), IN(Portsc0)); + iunlock(ctlr); +} + static void scanpci(void) { @@ -1407,6 +1406,7 @@ reset(Usbhost *uh) TD *t; ulong io; Ctlr *ctlr; + Pcidev *p; scanpci(); @@ -1425,10 +1425,13 @@ reset(Usbhost *uh) if(ctlr == nil) return -1; + p = ctlr->pcidev; + pcicfgw16(p, 0xc0, 0x2000); /* legacy support register: turn off lunacy mode */ + uh->ctlr = ctlr; uh->port = ctlr->io; - uh->irq = ctlr->pcidev->intl; - uh->tbdf = ctlr->pcidev->tbdf; + uh->irq = p->intl; + uh->tbdf = p->tbdf; io = ctlr->io; i = inb(io+SOFMod); diff --git a/port/chan.c b/port/chan.c index acabd12d5b95cfb5bc1555276c9f71a13cab0db0..41b72165970a89bbccefc87e5df6620366410f81 100644 --- a/port/chan.c +++ b/port/chan.c @@ -1114,9 +1114,10 @@ namec(char *aname, int amode, int omode, ulong perm) len = prefix+e.off[npath]; strcpy(tmperrbuf, up->errstr); if(len < ERRMAX/3 || (name=memrchr(aname, '/', len))==nil || name==aname) - snprint(up->errstr, ERRMAX, "\"%.*s\" %s", len, aname, tmperrbuf); + snprint(up->genbuf, sizeof up->genbuf, "%.*s", len, aname); else - snprint(up->errstr, ERRMAX, "\"...%.*s\" %s", (int)(len-(name-aname)), name, tmperrbuf); + snprint(up->genbuf, sizeof up->genbuf, "...%.*s", (int)(len-(name-aname)), name); + snprint(up->errstr, ERRMAX, "%#q %s", up->genbuf, tmperrbuf); nexterror(); } diff --git a/port/devpnp.c b/port/devpnp.c index d3fc3ac68ba55cca36e47aaeb55c39ff9540664b..af995a0f641cb48c9040dda6b5e8aface0d7a20f 100644 --- a/port/devpnp.c +++ b/port/devpnp.c @@ -549,10 +549,10 @@ pnpread(Chan *c, void *va, long n, vlong offset) p = pcimatchtbdf(tbdf); if(p == nil) error(Egreg); - if(offset > 128) + if(offset > 256) return 0; - if(n+offset > 128) - n = 128-offset; + if(n+offset > 256) + n = 256-offset; if(offset%4) error(Ebadarg); r = offset; diff --git a/port/devrealtime.c b/port/devrealtime.c index 830955ba694681be0b44372b166e544209dbb740..ba8028503999a0a01e16df8fe4f5127e06abc167 100644 --- a/port/devrealtime.c +++ b/port/devrealtime.c @@ -729,6 +729,8 @@ devrtwrite(Chan *c, void *va, long n, vlong) t->T += ticks; break; } + if (t->T < time2ticks(10000000/HZ)) + error("period too short"); }else if (strcmp(a, "D") == 0){ if (e=parsetime(&time, v)) error(e); @@ -767,6 +769,8 @@ devrtwrite(Chan *c, void *va, long n, vlong) t->C += ticks; break; } + if (t->C < time2ticks(10000000/HZ)) + error("cost too small"); }else if (strcmp(a, "resources") == 0){ if (v == nil) error("resources: value missing"); diff --git a/port/portclock.c b/port/portclock.c index 7172b6d35001dcb6710ce5f584e82101d7a1f80a..04761203c0c95772369e8ba907436a9ba74028a7 100644 --- a/port/portclock.c +++ b/port/portclock.c @@ -118,8 +118,6 @@ hzclock(Ureg *ur) checkalarms(); - m->inclockintr = 0; - if(up == 0 || up->state != Running) return; @@ -144,10 +142,6 @@ timerintr(Ureg *u, uvlong) uvlong when, now; int callhzclock; - if(m->inclockintr) - return; - m->inclockintr = 1; - intrcount[m->machno]++; callhzclock = 0; tt = &timers[m->machno]; @@ -160,7 +154,6 @@ timerintr(Ureg *u, uvlong) timerset(when); if(callhzclock) hzclock(u); - m->inclockintr = 0; return; } tt->head = t->next; @@ -178,7 +171,6 @@ timerintr(Ureg *u, uvlong) } } iunlock(tt); - m->inclockintr = 0; } uvlong hzperiod; diff --git a/port/proc.c b/port/proc.c index c0aa2e182c42eacdd79d4444b296c2482daf7c83..e6e17772508c7c12c027d7b3c2227a068b3a3a91 100644 --- a/port/proc.c +++ b/port/proc.c @@ -89,6 +89,7 @@ sched(void) { if(up){ if(up->state == Running && up->nlocks){ + up->delaysched = 1; delayedscheds++; return; } diff --git a/port/taslock.c b/port/taslock.c index 565fe10c0f73fb281a04b1f02c30684d1072724e..90262941514829af57150229bd5565dfdba03895 100644 --- a/port/taslock.c +++ b/port/taslock.c @@ -164,8 +164,13 @@ unlock(Lock *l) l->key = 0; coherence(); - if(up) - --up->nlocks; + /* give up the processor if ... */ + if(up && --up->nlocks == 0 /* we've closed the last nexted lock */ + && up->delaysched /* we delayed scheduling because of the lock */ + && up->state == Running){ /* we're in running state */ + up->delaysched = 0; + sched(); + } } void