From c2004a9373b089065b21882d5a1e935ac7fb2a50 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 13 Oct 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-10-13 --- gnot/devpipe.c | 6 +- port/devpipe.c | 6 +- port/fault.c | 2 +- port/page.c | 6 +- power/devhotrod.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++ power/fns.h | 2 +- power/io.h | 1 + power/main.c | 2 +- 8 files changed, 229 insertions(+), 10 deletions(-) create mode 100644 power/devhotrod.c diff --git a/gnot/devpipe.c b/gnot/devpipe.c index 02edfa3a0f7e2e1deba8def2e5b525febfc9385e..c213aeb57863341a463519e99372e9888b8d03bc 100644 --- a/gnot/devpipe.c +++ b/gnot/devpipe.c @@ -75,7 +75,8 @@ pipeattach(char *spec) } p = pipealloc.free; pipealloc.free = p->next; - p->ref = 1; + if(incref(p) != 1) + panic("pipeattach"); unlock(&pipealloc); c->qid = CHDIR|STREAMQID(2*(p - pipealloc.pipe), 0); @@ -89,7 +90,8 @@ pipeclone(Chan *c, Chan *nc) p = &pipealloc.pipe[STREAMID(c->qid)/2]; nc = devclone(c, nc); - incref(p); + if(incref(p) <= 1) + panic("pipeclone"); return nc; } diff --git a/port/devpipe.c b/port/devpipe.c index 02edfa3a0f7e2e1deba8def2e5b525febfc9385e..c213aeb57863341a463519e99372e9888b8d03bc 100644 --- a/port/devpipe.c +++ b/port/devpipe.c @@ -75,7 +75,8 @@ pipeattach(char *spec) } p = pipealloc.free; pipealloc.free = p->next; - p->ref = 1; + if(incref(p) != 1) + panic("pipeattach"); unlock(&pipealloc); c->qid = CHDIR|STREAMQID(2*(p - pipealloc.pipe), 0); @@ -89,7 +90,8 @@ pipeclone(Chan *c, Chan *nc) p = &pipealloc.pipe[STREAMID(c->qid)/2]; nc = devclone(c, nc); - incref(p); + if(incref(p) <= 1) + panic("pipeclone"); return nc; } diff --git a/port/fault.c b/port/fault.c index 7143eec772946034d3e5ba817d33aab6f2f7b5ba..a8954439ab9e95343b41a1e7252d73f2fb637f42 100644 --- a/port/fault.c +++ b/port/fault.c @@ -142,7 +142,7 @@ fault(Ureg *ur, int user, int code) /* * Add to mod list */ - pte = newmod(); + pte = newmod(o); o->nmod++; pte->proc = u->p; pte->page = opte->page; diff --git a/port/page.c b/port/page.c index 6a4828f6875615bab2b793a46d1f7b08e05fcd68..76f8a37b03da02d387322c352bcc46fcd8f472e9 100644 --- a/port/page.c +++ b/port/page.c @@ -382,7 +382,7 @@ o->nmod = 0; } PTE* -newmod(void) +newmod(Orig *o) { PTEA *pte; @@ -397,7 +397,7 @@ loop: unlock(&modalloc); print("no mods\n"); DEBUG(); -panic("mods"); +panic("mods %lux %d %d", o->va, o->npte, o->nmod); if(u == 0) panic("newmod"); u->p->state = Wakeme; @@ -423,7 +423,7 @@ forkmod(Seg *old, Seg *new, Proc *p) while(pte){ if(pte->page==0) panic("forkmod zero page"); if(pte->proc != u->p) panic("forkmod wrong page"); - npte = newmod(); + npte = newmod(o); o->nmod++; npte->proc = p; npte->page = pte->page; diff --git a/power/devhotrod.c b/power/devhotrod.c new file mode 100644 index 0000000000000000000000000000000000000000..85a9566b57b30d8603f571b6d855b36a630eba67 --- /dev/null +++ b/power/devhotrod.c @@ -0,0 +1,214 @@ +#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; +typedef struct Device Device; + +enum { + Vmevec= 0xd2, /* vme vector for interrupts */ + Intlevel= 5, /* level to interrupt on */ + Nhotrod= 1, +}; + +/* + * the hotrod fiber interface responds to 1MB + * of either user or supervisor accesses at: + * 0x30000000 to 0x300FFFFF in A32 space + * and 0xB00000 to 0xBFFFFF in A24 space + */ +struct Device { + uchar mem[1*1024*1024]; +}; +#define HOTROD VMEA32SUP(Device, 0x30000000) + +struct Hotrod { + QLock; + + Device *addr; + int vec; + char name[NAMELEN]; +}; + +Hotrod hotrod[Nhotrod]; + +static void hotrodintr(int); + +int +hotrodgen(Chan *c, Dirtab *tab, int ntab, int i, Dir *dp) +{ + if(i || c->dev>=Nhotrod) + return -1; + devdir(c, 0, hotrod[c->dev].name, sizeof(Device), 0666, dp); + return 1; +} + +/* + * reset all hotrod boards + */ +void +hotrodreset(void) +{ + int i; + Hsvme *hp; + + for(i=0; i= Nhotrod) + error(0, Ebadarg); + + c = devattach('H', spec); + c->dev = i; + c->qid = CHDIR; + return c; +} + +Chan* +hotrodclone(Chan *c, Chan *nc) +{ + return devclone(c, nc); +} + +int +hotrodwalk(Chan *c, char *name) +{ + return devwalk(c, name, 0, 0, hotrodgen); +} + +void +hotrodstat(Chan *c, char *dp) +{ + devstat(c, dp, 0, 0, hotrodgen); +} + +Chan* +hotrodopen(Chan *c, int omode) +{ + if(c->qid == CHDIR){ + if(omode != OREAD) + error(0, Eperm); + }else + streamopen(c, &hotrodinfo); + c->mode = openmode(omode); + c->flag |= COPEN; + c->offset = 0; + return c; +} + +void +hotrodcreate(Chan *c, char *name, int omode, ulong perm) +{ + error(0, Eperm); +} + +void +hotrodclose(Chan *c) +{ +} + +/* + * read the hotrod memory + */ +long +hotrodread(Chan *c, void *buf, long n) +{ + Hotrod *hp; + Device *dp; + + 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; + qlock(hp); + memcpy(buf, &dp->mem[c->offset], n); + qunlock(hp); + return n; +} + +/* + * write hotrod memory + */ +long +hotrodwrite(Chan *c, void *buf, long n) +{ + Hotrod *hp; + Device *dp; + + 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; + qlock(hp); + memcpy(&dp->mem[c->offset], buf, n); + qunlock(hp); + return n; +} + +void +hotrodremove(Chan *c) +{ + error(0, Eperm); +} + +void +hotrodwstat(Chan *c, char *dp) +{ + error(0, Eperm); +} + +void +hotroduserstr(Error *e, char *buf) +{ + consuserstr(e, buf); +} + +void +hotroderrstr(Error *e, char *buf) +{ + rooterrstr(e, buf); +} + +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; + } +} diff --git a/power/fns.h b/power/fns.h index eeee28c01d03295ca22cba99416b2e5ae09e5c45..41db55d7d12768b130d7f1b0c52ab710eee7e1f7 100644 --- a/power/fns.h +++ b/power/fns.h @@ -100,7 +100,7 @@ Chan *namec(char*, int, int, ulong); void nexterror(void); Alarm *newalarm(void); Chan *newchan(void); -PTE *newmod(void); +PTE *newmod(Orig*); Mount *newmount(void); Orig *neworig(ulong, ulong, int, Chan*); Page *newpage(int, Orig*, ulong); diff --git a/power/io.h b/power/io.h index 9946989d7cd543375000d353e96fd5413fe5cf9a..a9fad458e1d967305a3f7427e98f129409e10473 100644 --- a/power/io.h +++ b/power/io.h @@ -1,6 +1,7 @@ #define UNCACHED 0xA0000000 #define IO2(t,x) ((t *)(UNCACHED|0x17000000|(x))) #define VMEA24SUP(t, x) ((t *)(UNCACHED|0x13000000|(x))) +#define VMEA32SUP(t, x) ((t *)(UNCACHED|0x30000000|(x))) #define SYNCBUS(t,x) ((t *)(UNCACHED|0x1E000000|(x))) #define SBSEM SYNCBUS(ulong, 0) #define SBSEMTOP SYNCBUS(ulong, 0x400000) diff --git a/power/main.c b/power/main.c index cd6012bafb434585919841419d30dd62bb0af9af..3a4358f252897857e6299d487bb3deacaca97547 100644 --- a/power/main.c +++ b/power/main.c @@ -590,7 +590,7 @@ confinit(void) * set minimal default values */ conf.nmach = 2; - conf.nmod = 2000; + conf.nmod = 10000; conf.nalarm = 10000; conf.norig = 500; conf.nchan = 1000;