| plan 9 kernel history: overview | file list | diff list |
1992/0808/gnot/devport.c (diff list | history)
| gnot/devport.c on 1991/0110 | ||
| 1991/0110 | #include "u.h" | |
| 1992/0321 | #include "../port/lib.h" | |
| 1991/0110 | #include "mem.h" #include "dat.h" #include "fns.h" #include "io.h" | |
| 1992/0111 | #include "../port/error.h" | |
| 1991/0110 | #include "devtab.h" | |
| 1992/0225 | #define ROMADDR 0x40000000 #define ROMSIZE ((256*1024)/8) | |
| 1992/0621 | #define P_oper(sel, inst) (P_qlock(sel), inst, P_qunlock(sel)) #define P_qlock(sel) (sel >= 0 ? (qlock(&portpage), \ PORTSELECT = portpage.select = sel) : -1) #define P_qunlock(sel) (sel >= 0 ? (qunlock(&portpage),0) : -1) #define P_read(sel, addr, val, type) P_oper(sel, val = *(type *)(PORT+addr)) #define P_write(sel, addr, val, type) P_oper(sel, *(type *)(PORT+addr) = val) enum { | |
| 1991/0110 | Qdir, Qdata, | |
| 1992/0225 | Qrom | |
| 1991/0110 | }; Dirtab portdir[]={ | |
| 1991/1112 | "data", {Qdata}, 0, 0666, | |
| 1992/0225 | "rom", {Qrom}, ROMSIZE, 0444, | |
| 1991/0110 | }; #define NPORT (sizeof portdir/sizeof(Dirtab)) | |
| 1992/0621 | #define Nportservice 8 static int (*portservice[Nportservice])(void); | |
| 1992/0808 | Portpage portpage; | |
| 1992/0621 | static Lock intrlock; | |
| 1991/0110 | int portprobe(char *what, int select, int addr, int rw, long val) { int time; if (!conf.portispaged) return 0; P_qlock(select); switch (rw) { case -1: | |
| 1992/0621 | val = *(uchar *)(PORT+addr); break; | |
| 1991/0110 | case -2: | |
| 1992/0621 | val = *(ushort *)(PORT+addr); break; | |
| 1991/0110 | case -4: | |
| 1992/0621 | val = *(long *)(PORT+addr); break; | |
| 1991/0110 | case 1: | |
| 1992/0621 | *(uchar *)(PORT+addr) = val; break; | |
| 1991/0110 | case 2: | |
| 1992/0621 | *(ushort *)(PORT+addr) = val; break; | |
| 1991/0110 | case 4: | |
| 1992/0621 | *(long *)(PORT+addr) = val; break; | |
| 1991/0110 | default: panic("portprobe"); } time = PORTSELECT & 0x1f; P_qunlock(select); if (what) { print("%s at %d, %d", what, select, addr); print("%s", time & 0x10 ? " -- NOT FOUND\n" : "\n"); } if (time & 0x10) return -1; return val; } void portreset(void) { portpage.select = -1; lock(&portpage); unlock(&portpage); } void portinit(void) | |
| 1992/0621 | { } | |
| 1991/0110 | Chan * portattach(char *param) { return devattach('x', param); } Chan * portclone(Chan *c, Chan *nc) { return devclone(c, nc); } int portwalk(Chan *c, char *name) { return devwalk(c, name, portdir, NPORT, devgen); } void portstat(Chan *c, char *db) { devstat(c, db, portdir, NPORT, devgen); } Chan * portopen(Chan *c, int omode) { return devopen(c, omode, portdir, NPORT, devgen); } void portcreate(Chan *c, char *name, int omode, ulong perm) { | |
| 1992/0711 | USED(c, name, omode, perm); | |
| 1991/0110 | error(Eperm); } void portclose(Chan *c) | |
| 1992/0621 | { | |
| 1992/0711 | USED(c); | |
| 1992/0621 | } | |
| 1991/0110 | long | |
| 1991/0411 | portread(Chan *c, char *a, long n, ulong offset) | |
| 1991/0110 | { long s, k; if (n == 0) return 0; switch ((int)(c->qid.path & ~CHDIR)) { case Qdir: return devdirread(c, a, n, portdir, NPORT, devgen); case Qdata: | |
| 1991/0411 | if (!conf.portispaged || (s = offset >> PORTSHIFT) > 0xff) | |
| 1991/0110 | s = -1; | |
| 1991/0411 | k = offset % PORTSIZE; | |
| 1991/0110 | P_qlock(s); switch ((int)n) { case 1: *a = PORT[k]; break; case 2: *(short *)a = *(short *)(PORT+k); break; case 4: *(long *)a = *(long *)(PORT+k); break; default: P_qunlock(s); error(Ebadarg); } P_qunlock(s); | |
| 1992/0225 | break; case Qrom: if(offset >= ROMSIZE) return 0; if(offset+n > ROMSIZE) n = ROMSIZE - offset; memmove(a, ((char*)ROMADDR)+offset, n); return n; | |
| 1991/0110 | break; default: panic("portread"); } return n; } long | |
| 1991/0411 | portwrite(Chan *c, char *a, long n, ulong offset) | |
| 1991/0110 | { long s, k; if (n == 0) return 0; switch ((int)c->qid.path) { case Qdata: | |
| 1991/0411 | if (!conf.portispaged || (s = offset >> PORTSHIFT) > 0xff) | |
| 1991/0110 | s = -1; | |
| 1991/0411 | k = offset % PORTSIZE; | |
| 1991/0110 | P_qlock(s); switch ((int)n) { case 1: PORT[k] = *a; break; case 2: | |
| 1992/0621 | *(short *)(PORT+k) = *(short *)a; break; | |
| 1991/0110 | case 4: | |
| 1992/0621 | *(long *)(PORT+k) = *(long *)a; break; | |
| 1991/0110 | default: P_qunlock(s); error(Ebadarg); } P_qunlock(s); break; default: panic("portwrite"); } return n; } void portremove(Chan *c) { | |
| 1992/0621 | USED(c); | |
| 1991/0110 | error(Eperm); } void portwstat(Chan *c, char *dp) { | |
| 1992/0621 | USED(c, dp); | |
| 1991/0110 | error(Eperm); } void addportintr(int (*f)(void)) { int s = splhi(); int (**p)(void); | |
| 1992/0621 | ||
| 1991/0110 | lock(&intrlock); for (p=portservice; *p; p++) if (*p == f) goto out; if (p >= &portservice[Nportservice-1]) panic("addportintr"); *p = f; out: unlock(&intrlock); splx(s); } void devportintr(void) { | |
| 1992/0621 | int (**p)(void); int i = 0; | |
| 1991/0110 | for (p=portservice; *p; p++) i |= (**p)(); | |
| 1992/0621 | ||
| 1991/0110 | if (!i) /*putstring("spurious portintr\n");*/ panic("portintr"); if (portpage.select >= 0) PORTSELECT = portpage.select; } | |