From 280b8b5c8b1efe7bc9562061d851e50c4e2a2b19 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 18 Nov 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-11-18 --- gnot/devpipe.c | 47 +++++++++++++++++++------------------------ gnot/stream.c | 20 ++++++++++--------- port/devcons.c | 9 +++++++++ port/devdk.c | 3 ++- port/devpipe.c | 47 +++++++++++++++++++------------------------ port/stream.c | 54 +++++++++++++++++++++++++------------------------- power/dat.h | 2 +- power/fns.h | 1 + power/main.c | 35 ++++++++++++++++++++------------ 9 files changed, 113 insertions(+), 105 deletions(-) diff --git a/gnot/devpipe.c b/gnot/devpipe.c index 404d4a51544bef7ba639d4cf433201137f3c7016..246f3c238eea057f1a93696cbf8c245072829138 100644 --- a/gnot/devpipe.c +++ b/gnot/devpipe.c @@ -178,7 +178,7 @@ pipeopen(Chan *c, int omode) * pointer from the other stream. */ if(streamenter(local)<0) - panic("pipeattach"); + panic("pipeopen"); } unlock(p); poperror(); @@ -207,44 +207,30 @@ pipewstat(Chan *c, char *db) error(0, Eperm); } -void -pipeexit(Pipe *p) -{ - if(decref(p) < 0) - panic("pipeexit"); - if(p->ref == 0){ - lock(&pipealloc); - p->next = pipealloc.free; - pipealloc.free = p; - unlock(&pipealloc); - } -} - void pipeclose(Chan *c) { - Stream *remote; - Stream *local; Pipe *p; p = &pipealloc.pipe[STREAMID(c->qid)/2]; - lock(p); - if(waserror()){ - unlock(p); - nexterror(); - } /* * take care of associated streams */ - if(local = c->stream){ - remote = (Stream *)c->stream->devq->ptr; + if(c->stream) streamclose(c); /* close this stream */ - streamexit(remote, 0); /* release stream for other half of pipe */ + + /* + * free the structure + */ + if(decref(p) == 0){ + lock(&pipealloc); + p->next = pipealloc.free; + pipealloc.free = p; + unlock(&pipealloc); } - unlock(p); - poperror(); - pipeexit(p); + if(p->ref < 0) + panic("pipeexit"); } long @@ -315,6 +301,7 @@ static void pipestclose(Queue *q) { Block *bp; + Stream *remote; /* * point to the bit-bucket and let any in-progress @@ -330,4 +317,10 @@ pipestclose(Queue *q) bp = allocb(0); bp->type = M_HANGUP; PUTNEXT(q, bp); + + /* + * release stream for other half of pipe + */ + remote = RD(q)->ptr; + streamexit(remote, 0); } diff --git a/gnot/stream.c b/gnot/stream.c index bcd0ff9ad5e969ab136567f77b7bf8cb4b6d6417..3db78b07c8ef86fec7c830f0ff71247e0e9188c8 100644 --- a/gnot/stream.c +++ b/gnot/stream.c @@ -810,9 +810,9 @@ streamclose1(Stream *s) if(!waserror()){ if(q->info->close) (*q->info->close)(q->other); - WR(q)->put = nullput; + poperror(); } - poperror(); + WR(q)->put = nullput; /* * this may be 2 streams joined device end to device end @@ -820,14 +820,14 @@ streamclose1(Stream *s) if(q == s->devq->other) break; } - } - /* - * ascend the stream flushing the queues - */ - for(q = s->devq; q; q = nq){ - nq = q->next; - flushq(q); + /* + * ascend the stream flushing the queues + */ + for(q = s->devq; q; q = nq){ + nq = q->next; + flushq(q); + } } s->opens--; @@ -1013,6 +1013,8 @@ streamread(Chan *c, void *vbuf, long n) * hangup -- send an M_HANGUP up the stream * push ldname -- push the line discipline named ldname * pop -- pop a line discipline + * + * This routing is entrered with s->wrlock'ed and must unlock. */ static long streamctlwrite(Chan *c, void *a, long n) diff --git a/port/devcons.c b/port/devcons.c index 1db49ce118d081d958ffe2c6c03aa8fb369ae947..09e9a6c5d27917067770174bf775065b08e31e97 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -311,6 +311,7 @@ enum{ Qppid, Qtime, Quser, + Qvmereset, }; Dirtab consdir[]={ @@ -324,6 +325,7 @@ Dirtab consdir[]={ "ppid", Qppid, 12, 0600, "time", Qtime, 12, 0600, "user", Quser, 0, 0600, + "vmereset", Qvmereset, 0, 0600, }; #define NCONS (sizeof consdir/sizeof(Dirtab)) @@ -579,6 +581,13 @@ conswrite(Chan *c, void *va, long n) case Qnull: break; + + case Qvmereset: + if(strcmp(u->p->pgrp->user, "bootes") != 0) + error(0, Eperm); + vmereset(); + break; + default: error(0, Egreg); } diff --git a/port/devdk.c b/port/devdk.c index dc3721909326f35e658fe70833032ddc7837db05..3f7c97799280e23b04355a1f03216971bb65ec43 100644 --- a/port/devdk.c +++ b/port/devdk.c @@ -6,7 +6,7 @@ #include "io.h" #include "errno.h" -#define DPRINT if(0) /*kprint*/ +#define DPRINT if(0) print #define NOW (MACHP(0)->ticks) @@ -1668,6 +1668,7 @@ dktimer(void *a) /* * send keep alive */ + DPRINT("keep alive\n"); dkmesg(c, T_ALIVE, D_CONTINUE, 0, 0); /* diff --git a/port/devpipe.c b/port/devpipe.c index 404d4a51544bef7ba639d4cf433201137f3c7016..246f3c238eea057f1a93696cbf8c245072829138 100644 --- a/port/devpipe.c +++ b/port/devpipe.c @@ -178,7 +178,7 @@ pipeopen(Chan *c, int omode) * pointer from the other stream. */ if(streamenter(local)<0) - panic("pipeattach"); + panic("pipeopen"); } unlock(p); poperror(); @@ -207,44 +207,30 @@ pipewstat(Chan *c, char *db) error(0, Eperm); } -void -pipeexit(Pipe *p) -{ - if(decref(p) < 0) - panic("pipeexit"); - if(p->ref == 0){ - lock(&pipealloc); - p->next = pipealloc.free; - pipealloc.free = p; - unlock(&pipealloc); - } -} - void pipeclose(Chan *c) { - Stream *remote; - Stream *local; Pipe *p; p = &pipealloc.pipe[STREAMID(c->qid)/2]; - lock(p); - if(waserror()){ - unlock(p); - nexterror(); - } /* * take care of associated streams */ - if(local = c->stream){ - remote = (Stream *)c->stream->devq->ptr; + if(c->stream) streamclose(c); /* close this stream */ - streamexit(remote, 0); /* release stream for other half of pipe */ + + /* + * free the structure + */ + if(decref(p) == 0){ + lock(&pipealloc); + p->next = pipealloc.free; + pipealloc.free = p; + unlock(&pipealloc); } - unlock(p); - poperror(); - pipeexit(p); + if(p->ref < 0) + panic("pipeexit"); } long @@ -315,6 +301,7 @@ static void pipestclose(Queue *q) { Block *bp; + Stream *remote; /* * point to the bit-bucket and let any in-progress @@ -330,4 +317,10 @@ pipestclose(Queue *q) bp = allocb(0); bp->type = M_HANGUP; PUTNEXT(q, bp); + + /* + * release stream for other half of pipe + */ + remote = RD(q)->ptr; + streamexit(remote, 0); } diff --git a/port/stream.c b/port/stream.c index 2a30050163ed89b43ee33d6dfa3b540fda29765d..3db78b07c8ef86fec7c830f0ff71247e0e9188c8 100644 --- a/port/stream.c +++ b/port/stream.c @@ -652,10 +652,10 @@ streamnew(ushort type, ushort dev, ushort id, Qinfo *qi, int noopen) */ for(s = slist; s < &slist[conf.nstream]; s++) { if(s->inuse == 0){ - if(canlock(s)){ + if(canqlock(s)){ if(s->inuse == 0) break; - unlock(s); + qunlock(s); } } } @@ -664,7 +664,7 @@ streamnew(ushort type, ushort dev, ushort id, Qinfo *qi, int noopen) error(0, Enostream); } if(waserror()){ - unlock(s); + qunlock(s); streamclose1(s); nexterror(); } @@ -697,7 +697,7 @@ streamnew(ushort type, ushort dev, ushort id, Qinfo *qi, int noopen) if(qi->open) (*qi->open)(RD(s->devq), s); - unlock(s); + qunlock(s); poperror(); return s; } @@ -717,17 +717,17 @@ streamopen(Chan *c, Qinfo *qi) for(s = slist; s < &slist[conf.nstream]; s++) { if(s->inuse && s->type == c->type && s->dev == c->dev && s->id == STREAMID(c->qid)){ - lock(s); + qlock(s); if(s->inuse && s->type == c->type && s->dev == c->dev && s->id == STREAMID(c->qid)){ s->inuse++; s->opens++; c->stream = s; - unlock(s); + qunlock(s); return; } - unlock(s); + qunlock(s); } } @@ -744,13 +744,13 @@ streamopen(Chan *c, Qinfo *qi) int streamenter(Stream *s) { - lock(s); + qlock(s); if(s->opens == 0){ - unlock(s); + qunlock(s); return -1; } s->inuse++; - unlock(s); + qunlock(s); return 0; } @@ -767,7 +767,7 @@ streamexit(Stream *s, int locked) char *name; if(!locked) - lock(s); + qlock(s); if(s->inuse == 1){ if(s->opens != 0) panic("streamexit %d %s\n", s->opens, s->devq->info->name); @@ -784,7 +784,7 @@ streamexit(Stream *s, int locked) s->inuse--; rv = s->inuse; if(!locked) - unlock(s); + qunlock(s); return rv; } @@ -801,24 +801,24 @@ streamclose1(Stream *s) /* * decrement the reference count */ - lock(s); + qlock(s); if(s->opens == 1){ - if(!waserror()){ - /* - * descend the stream closing the queues - */ - for(q = s->procq; q; q = q->next){ + /* + * descend the stream closing the queues + */ + for(q = s->procq; q; q = q->next){ + if(!waserror()){ if(q->info->close) (*q->info->close)(q->other); - WR(q)->put = nullput; - - /* - * this may be 2 streams joined device end to device end - */ - if(q == s->devq->other) - break; + poperror(); } - poperror(); + WR(q)->put = nullput; + + /* + * this may be 2 streams joined device end to device end + */ + if(q == s->devq->other) + break; } /* @@ -835,7 +835,7 @@ streamclose1(Stream *s) * leave it and free it */ streamexit(s, 1); - unlock(s); + qunlock(s); } void streamclose(Chan *c) diff --git a/power/dat.h b/power/dat.h index 6025e00e02b7552c6a4c11623f1a0f4c698fe009..70dab74aa12174f1fc52ad22e93d9a9d72fd72e8 100644 --- a/power/dat.h +++ b/power/dat.h @@ -454,7 +454,7 @@ struct Queue { * a stream head */ struct Stream { - Lock; /* structure lock */ + QLock; /* structure lock */ short inuse; /* number of processes in stream */ short opens; /* number of processes with stream open */ ushort hread; /* number of reads after hangup */ diff --git a/power/fns.h b/power/fns.h index 974a5114b4e6e5ebb5c001fd73cf67c7ccae786a..71b4a9ab2ec1fca671f7d94a6357413563a86d3c 100644 --- a/power/fns.h +++ b/power/fns.h @@ -198,6 +198,7 @@ void validaddr(ulong, ulong, int); void vecinit(void); void vector80(void); void* vmemchr(void*, int, int); +void vmereset(void); void wakeme(Alarm*); void wakeup(Rendez*); void wbflush(void); diff --git a/power/main.c b/power/main.c index 5704b698d575229ac380d9369bdab301388f9efe..485172b528def86694c1c29456500ebe4af2bd5d 100644 --- a/power/main.c +++ b/power/main.c @@ -102,6 +102,25 @@ vecinit(void) *p++ = *q++; } +/* + * reset the vme bus + */ +void +vmereset(void) +{ + long i; + int noforce; + + if(ioid >= IO3R1) + noforce = 1; + else + noforce = 0; + MODEREG->resetforce = (1<<1) | noforce; + for(i=0; i<1000000; i++) + ; + MODEREG->resetforce = noforce; +} + /* * We have to program both the IO2 board to generate interrupts * and the SBCC on CPU 0 to accept them. @@ -110,25 +129,15 @@ void ioboardinit(void) { long i; - int noforce; int maxlevel; ioid = *IOID; - if(ioid >= IO3R1){ + if(ioid >= IO3R1) maxlevel = 11; - noforce = 1; - } else { + else maxlevel = 8; - noforce = 0; - } - /* - * reset VME bus (MODEREG is on the IO2) - */ - MODEREG->resetforce = (1<<1) | noforce; - for(i=0; i<1000000; i++) - ; - MODEREG->resetforce = noforce; + vmereset(); MODEREG->masterslave = (SLAVE<<4) | MASTER; /*