Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/gnot/devport.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname gnot/devport.c 1991/0110
## diff -e /dev/null /n/bootesdump/1991/0110/sys/src/9/68020/devport.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"
#include	"errno.h"

#include	"devtab.h"

#include	"port.h"

enum {
	Qdir,
	Qdata,
};

Dirtab portdir[]={
	"data",		{Qdata},	0,	0600,
};

#define	NPORT	(sizeof portdir/sizeof(Dirtab))

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:
		val = *(uchar *)(PORT+addr); break;
	case -2:
		val = *(ushort *)(PORT+addr); break;
	case -4:
		val = *(long *)(PORT+addr); break;
	case 1:
		*(uchar *)(PORT+addr) = val; break;
	case 2:
		*(ushort *)(PORT+addr) = val; break;
	case 4:
		*(long *)(PORT+addr) = val; break;
	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)
{}

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)
{
	error(Eperm);
}

void
portclose(Chan *c)
{}

long
portread(Chan *c, char *a, long n)
{
	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:
		if (!conf.portispaged || (s = c->offset >> PORTSHIFT) > 0xff)
			s = -1;
		k = c->offset % PORTSIZE;
		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);
		break;
	default:
		panic("portread");
	}
	return n;
}

long
portwrite(Chan *c, char *a, long n)
{
	long s, k;
	if (n == 0)
		return 0;
	switch ((int)c->qid.path) {
	case Qdata:
		if (!conf.portispaged || (s = c->offset >> PORTSHIFT) > 0xff)
			s = -1;
		k = c->offset % PORTSIZE;
		P_qlock(s);
		switch ((int)n) {
		case 1:
			PORT[k] = *a; break;
		case 2:
			*(short *)(PORT+k) = *(short *)a; break;
		case 4:
			*(long *)(PORT+k) = *(long *)a; break;
		default:
			P_qunlock(s);
			error(Ebadarg);
		}
		P_qunlock(s);
		break;
	default:
		panic("portwrite");
	}
	return n;
}

void
portremove(Chan *c)
{
	error(Eperm);
}

void
portwstat(Chan *c, char *dp)
{
	error(Eperm);
}

#define	Nportservice	8
int	(*portservice[Nportservice])(void);

Portpage portpage;

Lock	intrlock;

void
addportintr(int (*f)(void))
{
	int s = splhi();
	int (**p)(void);
	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)
{
	int (**p)(void); int i = 0;
	for (p=portservice; *p; p++)
		i |= (**p)();
	if (!i)
		/*putstring("spurious portintr\n");*/
		panic("portintr");
	if (portpage.select >= 0)
		PORTSELECT = portpage.select;

}
.
## diffname gnot/devport.c 1991/0115
## diff -e /n/bootesdump/1991/0110/sys/src/9/68020/devport.c /n/bootesdump/1991/0115/sys/src/9/68020/devport.c
11,12d
## diffname gnot/devport.c 1991/0411
## diff -e /n/bootesdump/1991/0201/sys/src/9/68020/devport.c /n/bootesdump/1991/0411/sys/src/9/gnot/devport.c
151c
		k = offset % PORTSIZE;
.
149c
		if (!conf.portispaged || (s = offset >> PORTSHIFT) > 0xff)
.
142c
portwrite(Chan *c, char *a, long n, ulong offset)
.
120c
		k = offset % PORTSIZE;
.
118c
		if (!conf.portispaged || (s = offset >> PORTSHIFT) > 0xff)
.
109c
portread(Chan *c, char *a, long n, ulong offset)
.
## diffname gnot/devport.c 1991/0419
## diff -e /n/bootesdump/1991/0411/sys/src/9/gnot/devport.c /n/bootesdump/1991/0419/sys/src/9/gnot/devport.c
85a
Chan*
portclwalk(Chan *c, char *name)
{
	return devclwalk(c, name);
}

.
## diffname gnot/devport.c 1991/0427
## diff -e /n/bootesdump/1991/0419/sys/src/9/gnot/devport.c /n/bootesdump/1991/0427/sys/src/9/gnot/devport.c
86,91d
## diffname gnot/devport.c 1991/1112
## diff -e /n/bootesdump/1991/0427/sys/src/9/gnot/devport.c /n/bootesdump/1991/1112/sys/src/9/gnot/devport.c
17c
	"data",		{Qdata},	0,	0666,
.
## diffname gnot/devport.c 1992/0111
## diff -e /n/bootesdump/1991/1112/sys/src/9/gnot/devport.c /n/bootesdump/1992/0111/sys/src/9/gnot/devport.c
7c
#include	"../port/error.h"
.
## diffname gnot/devport.c 1992/0225
## diff -e /n/bootesdump/1992/0111/sys/src/9/gnot/devport.c /n/bootesdump/1992/0225/sys/src/9/gnot/devport.c
133a
		break;
	case Qrom:
		if(offset >= ROMSIZE)
			return 0;
		if(offset+n > ROMSIZE)
			n = ROMSIZE - offset;
		memmove(a, ((char*)ROMADDR)+offset, n);
		return n;
.
17a
	"rom",		{Qrom},	ROMSIZE,	0444,
.
13a
	Qrom
.
10a
#define	ROMADDR	0x40000000
#define	ROMSIZE	((256*1024)/8)

.
## diffname gnot/devport.c 1992/0321
## diff -e /n/bootesdump/1992/0225/sys/src/9/gnot/devport.c /n/bootesdump/1992/0321/sys/src/9/gnot/devport.c
2c
#include	"../port/lib.h"
.
## diffname gnot/devport.c 1992/0621
## diff -e /n/bootesdump/1992/0321/sys/src/9/gnot/devport.c /n/bootesdump/1992/0621/sys/src/9/gnot/devport.c
232d
226a

.
224c
	int (**p)(void);
	int i = 0;

.
208a

.
197,203d
193a
	USED(c, dp);
.
187a
	USED(c);
.
172c
			*(long *)(PORT+k) = *(long *)a;
			break;
.
170c
			*(short *)(PORT+k) = *(short *)a;
			break;
.
111c
{
}
.
71c
{
}
.
46c
		*(long *)(PORT+addr) = val;
		break;
.
44c
		*(ushort *)(PORT+addr) = val;
		break;
.
42c
		*(uchar *)(PORT+addr) = val;
		break;
.
40c
		val = *(long *)(PORT+addr);
		break;
.
38c
		val = *(ushort *)(PORT+addr);
		break;
.
36c
		val = *(uchar *)(PORT+addr);
		break;
.
26a
#define	Nportservice	8
static	int (*portservice[Nportservice])(void);
static	Portpage portpage;
static	Lock intrlock;

.
14c
#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
{
.
## diffname gnot/devport.c 1992/0711
## diff -e /n/bootesdump/1992/0621/sys/src/9/gnot/devport.c /n/bootesdump/1992/0711/sys/src/9/gnot/devport.c
131a
	USED(c);
.
125a
	USED(c, name, omode, perm);
.
## diffname gnot/devport.c 1992/0808
## diff -e /n/bootesdump/1992/0711/sys/src/9/gnot/devport.c /n/bootesdump/1992/0808/sys/src/9/gnot/devport.c
37c
	Portpage portpage;
.
## diffname gnot/devport.c 1992/0916
## diff -e /n/bootesdump/1992/0808/sys/src/9/gnot/devport.c /n/bootesdump/1992/0916/sys/src/9/gnot/devport.c
14,17c
#define	P_qlock(sel)	if(sel >= 0){\
				qlock(&portpage);\
				PORTSELECT = portpage.select = sel;\
			}else

#define	P_qunlock(sel)	if(sel >= 0){\
				qunlock(&portpage);\
			}else

#define	P_oper(sel, inst)		P_qlock(sel); inst; P_qunlock(sel)
.
## diffname gnot/devport.c 1993/0501 # deleted
## diff -e /n/bootesdump/1992/0916/sys/src/9/gnot/devport.c /n/fornaxdump/1993/0501/sys/src/brazil/gnot/devport.c
1,262d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.