From ad42508424cee7dac9ff7dc81e63e33c8df9eaa9 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 21 Sep 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-09-21 --- pc/devfloppy.c | 84 ++++++++++++++++++++++++++++---------------------- pc/devhard.c | 2 +- pc/vga.c | 3 +- port/devsrv.c | 2 +- port/devwren.c | 2 +- power/devhs.c | 5 ++- 6 files changed, 57 insertions(+), 41 deletions(-) diff --git a/pc/devfloppy.c b/pc/devfloppy.c index 344c3ead2c63067e058fd52b054e17f7d665d8b5..f8b443d5b954e11541b487f51b04290f890be27b 100644 --- a/pc/devfloppy.c +++ b/pc/devfloppy.c @@ -110,7 +110,6 @@ struct Drive int dev; ulong lasttouched; /* time last touched */ - int motoron; /* motor is on */ int cyl; /* current cylinder */ int confused; /* needs to be recalibrated (or worse) */ @@ -137,12 +136,15 @@ struct Controller int confused; int intr; /* true if interrupt occured */ Rendez r; /* wait here for command termination */ + int motor; Rendez kr; /* for motor watcher */ }; Controller floppy; +#define MOTORBIT(i) (1<<((i)+4)) + /* * predeclared */ @@ -201,7 +203,7 @@ floppyreset(void) dp->dev = dp - floppy.d; dp->t = &floppytype[0]; /* default type */ floppydir[NFDIR*dp->dev].length = dp->t->cap; - dp->motoron = 1; + floppy.motor |= MOTORBIT(dp->dev); dp->cyl = -1; /* because we don't know */ motoroff(dp); } @@ -376,36 +378,6 @@ floppywrite(Chan *c, void *a, long n) return rv; } -/* - * start a floppy drive's motor. set an alarm for .75 second later to - * mark it as started (we get no interrupt to tell us). - * - * assume the caller qlocked the drive. - */ -static void -motoron(Drive *dp) -{ - int cmd; - - cmd = (1<<(dp->dev+4)) | Fintena | Fena | dp->dev; - outb(Fmotor, cmd); - tsleep(&dp->r, return0, 0, 750); - dp->motoron = 1; - dp->lasttouched = m->ticks; -} - -/* - * stop the floppy if it hasn't been used in 5 seconds - */ -static void -motoroff(Drive *dp) -{ - int cmd; - - cmd = Fintena | Fena | dp->dev; - outb(Fmotor, cmd); - dp->motoron = 0; -} static void floppykproc(void *a) { @@ -416,7 +388,8 @@ floppykproc(void *a) ; for(;;){ for(dp = floppy.d; dp < &floppy.d[conf.nfloppy]; dp++){ - if(dp->motoron && TK2SEC(m->ticks - dp->lasttouched) > 5 + if((floppy.motor&MOTORBIT(dp->dev)) + && TK2SEC(m->ticks - dp->lasttouched) > 5 && canqlock(dp)){ if(TK2SEC(m->ticks - dp->lasttouched) > 5) motoroff(dp); @@ -429,6 +402,46 @@ floppykproc(void *a) } } +static void +driveselect(Drive *dp) +{ + int cmd; + + cmd = floppy.motor | Fintena | Fena | dp->dev; + outb(Fmotor, cmd); +} + +/* + * start a floppy drive's motor. set an alarm for .75 second later to + * mark it as started (we get no interrupt to tell us). + * + * assume the caller qlocked the drive. + * + * this also selects the drive for subsequent operations + */ +static void +motoron(Drive *dp) +{ + int alreadyon; + + alreadyon = floppy.motor & MOTORBIT(dp->dev); + floppy.motor |= MOTORBIT(dp->dev); + driveselect(dp); + if(!alreadyon) + tsleep(&dp->r, return0, 0, 750); + dp->lasttouched = m->ticks; +} + +/* + * stop the floppy if it hasn't been used in 5 seconds + */ +static void +motoroff(Drive *dp) +{ + floppy.motor &= ~MOTORBIT(dp->dev); + driveselect(dp); +} + /* * send a byte to the floppy */ @@ -633,9 +646,9 @@ floppyrevive(void) outb(Fmotor, Fintena|Fena); spllo(); for(dp = floppy.d; dp < &floppy.d[conf.nfloppy]; dp++){ - dp->motoron = 0; dp->confused = 1; } + floppy.motor = 0; sleep(&floppy.r, interrupted, 0); floppy.confused = 0; } @@ -716,8 +729,7 @@ floppyxfer(Drive *dp, int cmd, void *a, long off, long n) */ if(floppy.confused || dp->confused) floppyrevive(); - if(!dp->motoron) - motoron(dp); + motoron(dp); /* * calculate new position and seek to it (dp->len may be trimmed) diff --git a/pc/devhard.c b/pc/devhard.c index 884ed9e4b6efdb3cf89c27cce62c02378fd2fc50..f10dff0b14507787cc2ff9cd040612612685b0a5 100644 --- a/pc/devhard.c +++ b/pc/devhard.c @@ -238,7 +238,7 @@ hardattach(char *spec) dp->online = 0; } - return devattach('h', spec); + return devattach('w', spec); } Chan* diff --git a/pc/vga.c b/pc/vga.c index 78df35888ddb0d59e776ada61f019b57dddf7266..088368ca937914771f593327762b06a6426cc0a0 100644 --- a/pc/vga.c +++ b/pc/vga.c @@ -165,7 +165,8 @@ screeninit(void) /* * swizzle the font longs. - * we do it here since the font is initialized with big endian longs. + * we do it here since the font is initialized with big + * endian longs. */ defont = &defont0; l = defont->bits->base; diff --git a/port/devsrv.c b/port/devsrv.c index 48116f7a75c7accb42e00f0907e6596167f350db..c0c70f719abe21bdad34b643c56effb6d2e152d9 100644 --- a/port/devsrv.c +++ b/port/devsrv.c @@ -181,6 +181,6 @@ srvwrite(Chan *c, void *va, long n, ulong offset) fd = strtoul(buf, 0, 0); fdtochan(fd, -1); /* error check only */ srv.chan[i] = u->p->fgrp->fd[fd]; - incref(u->p->fgrp->fd[fd]); + incref(srv.chan[i]); return n; } diff --git a/port/devwren.c b/port/devwren.c index 5e79ef6e5c4899a1f7d95cf20ae5a8ff277e08ef..14c02f151a3d07ff6962847736de0dab24019055 100644 --- a/port/devwren.c +++ b/port/devwren.c @@ -125,7 +125,7 @@ wrenattach(char *param) drive = wrendev(param); wrenpart(drive); - c = devattach('r', param); + c = devattach('w', param); c->dev = drive; return c; } diff --git a/power/devhs.c b/power/devhs.c index 0e890244385962e04bf33e09a3d7c0a564f7d8bb..b61e9d61fc3e4a848c9ce41f7e24d324e46145f7 100644 --- a/power/devhs.c +++ b/power/devhs.c @@ -45,6 +45,7 @@ struct Hsvme { uchar buf[1024]; /* bytes being collected */ uchar *wptr; /* pointer into buf */ int kstarted; /* true if kernel process started */ + int started; /* statistics */ @@ -124,6 +125,7 @@ hsvmerestart(Hsvme *hp) addr->csr = NORESET|IPL(Intlevel)|FORCEW|IENABLE|ALIVE; wbflush(); delay(1); + hp->started = 1; } /* @@ -164,7 +166,8 @@ hsvmeattach(char *spec) if(i >= Nhsvme) error(Ebadarg); hp = &hsvme[i]; - hsvmerestart(hp); + if(!hp->started) + hsvmerestart(hp); c = devattach('h', spec); c->dev = i;