Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/pc/headland.c

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


## diffname pc/headland.c 1991/0719
## diff -e /dev/null /n/bootesdump/1991/0719/sys/src/9/safari/headland.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"

/*
 *  headland hip set for the safari.
 *  
 *  serious magic!!!
 */

enum
{
	Head=		0x92,		/* control port */
	 Reset=		(1<<0),		/* reset the 386 */
	 A20ena=	(1<<1),		/* enable address line 20 */
};

/*
 *  enable address bit 20
 */
void
a20enable(void)
{
	outb(Head, A20ena);
}

/*
 *  reset the chip
 */
void
exit(void)
{
	int i;

	u = 0;
	print("exiting\n");
	delay(5000);
	outb(Head, Reset);
}
.
## diffname pc/headland.c 1991/0720
## diff -e /n/bootesdump/1991/0719/sys/src/9/safari/headland.c /n/bootesdump/1991/0720/sys/src/9/safari/headland.c
39d
## diffname pc/headland.c 1991/0727
## diff -e /n/bootesdump/1991/0720/sys/src/9/safari/headland.c /n/bootesdump/1991/0727/sys/src/9/safari/headland.c
39a
}

/*
 *  setup a dma transfer.  return count actually set up.  we DMA up
 *  to a page.
 */
long
dmasetup(int d, int chan, Page *pg, long len, int isread)
{
	DMA *dp;
	ulong addr;

	dp = &dma[d];
	addr = (ulong)a;
	addr &= ~KZERO;

	outb(dp->cbp, isread ? 0x46 : 0x4a);
	outb(dp->mode, isread ? 0x46 : 0x4a);
	outb(dp->addr, addr);
	outb(dp->addr, addr>>8);
	outb(dp->page, addr>>16);
	outb(dp->count, len-1);
	outb(dp->count, (len-1)>>8);
	outb(dp->sbm, 2);
.
20a
 *  ports used by the DMA controllers
 */
typedef struct DMA	DMA;
struct DMA {
	uchar	addr[4];	/* current address (4 channels) */
	uchar	count[4];	/* current count (4 channels) */
	uchar	page[4];	/* page registers (4 channels) */
	uchar	cmd;		/* command status register */
	uchar	req;		/* request registers */
	uchar	sbm;		/* single bit mask register */
	uchar	mode;		/* mode register */
	uchar	cbp;		/* clear byte pointer */
	uchar	mc;		/* master clear */
	uchar	cmask;		/* clear mask register */
	uchar	wam;		/* write all mask register bit */
};

DMA dma[2] = {
	{ 0x00, 0x02, 0x04, 0x06,
	  0x01, 0x03, 0x05, 0x07,
	  0x87, 0x83, 0x81, 0x82,
	  0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
	{ 0xc0, 0xc6, 0xca, 0xce,
	  0xc4, 0xc8, 0xcc, 0xcf,
	  0x80, 0x8b, 0x89, 0x8a,
	  0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc, 0xde },
};

/*
.
## diffname pc/headland.c 1991/0728
## diff -e /n/bootesdump/1991/0727/sys/src/9/safari/headland.c /n/bootesdump/1991/0728/sys/src/9/safari/headland.c
92c
	outb(dp->sbm, chan);		/* enable the channel */
	unlock(dp);

	return n;
}

/*
 *  this must be called after a dma has been completed.
 *
 *  if a page has been allocated for the dma,
 *  copy the data into the actual destination
 *  and free the page.
 */
void
dmaend(int chan)
{
	DMA *dp;
	DMAxfer *xp;
	ulong addr;
	uchar mode;

	dp = &dma[(chan>>2)&1];
	chan &= 3;
	outb(dp->sbm, 4|chan);		/* disable the channel */
	xp = &dp->x[chan];
	if(xp->pg == 0)
		return;

	memmove(a, KZERO|xp->pg->pa, xp->len);
	putpage(xp->pg);
	xp->pg = 0;
.
85,90c
	/*
	 *  if this isn't kernel memory, we can't count on it being
	 *  there during the DMA.  Allocate a page for the DMA.
	 */
	if(isphys(va)){
		pa = va & ~KZERO;
	} else {
		xp->pg = newpage(1, 0, 0);
		if(len > BY2PG)
			len = BY2PG;
		if(!isread)
			memmove(KZERO|xp->pg->pa, a, len);
		xp->va = va;
		xp->len = len;
		xp->isread = isread;
		pa = xp->pg->pa;
	}

	/*
	 * this setup must be atomic
	 */
	lock(dp);
	outb(dp->cbp, 0);		/* set count & address to their first byte */
	mode = (isread ? 0x44 : 0x48) | chan;
	outb(dp->mode, mode);		/* single mode dma (give CPU a chance at mem) */
	outb(dp->addr, pa);		/* set address */
	outb(dp->addr, pa>>8);
	outb(dp->page, pa>>16);
	outb(dp->count, len-1);		/* set count */
.
81,83c
	dp = &dma[(chan>>2)&1];
	chan &= 3;
	xp = &dp->x[chan];
.
79c
	DMAxfer *xp;
	ulong pa;
	uchar mode;
.
76c
dmasetup(int chan, void *va, long len, int isread)
.
72,73c
 *  setup a dma transfer.  if the destination is not in kernel
 *  memory, allocate a page for the transfer.
 *
 *  we assume BIOS has set up the command register before we
 *  are booted.
.
37a
typdef struct DMA	DMA;
struct DMA
{
	DMAport;
	Lock;
	DMAxfer	x[4];
};

.
35a

	Lock;
.
23,24c
typedef struct DMAxfer	DMAxfer;
struct DMAxfer
{
	Page	pg;		/* page used by dma */
	void	*va;		/* virtual address destination/src */
	long	len;		/* bytes to be transferred */
	int	isread;
};

/*
 *  the dma controllers.  the first half of this structure specifies
 *  the I/O ports used by the DMA controllers.
 */
typedef struct DMAport	DMAport;
struct DMAport
{
.
21c
 *  state of a dma transfer
.
8,10c
 *  headland chip set for the safari.
.
## diffname pc/headland.c 1991/0731
## diff -e /n/bootesdump/1991/0728/sys/src/9/safari/headland.c /n/bootesdump/1991/0731/sys/src/9/safari/headland.c
98a
 *
 *  return the updated transfer length (we can't transfer across 64k
 *  boundaries)
.
15a

	/*
	 *  the byte registers for DMA0 are all one byte apart
	 */
	Dma0=		0x00,
	Dma0status=	Dma0+0x8,	/* status port */
	Dma0reset=	Dma0+0xD,	/* reset port */

	/*
	 *  the byte registers for DMA1 are all two bytes apart (why?)
	 */
	Dma1=		0xC0,
	Dma1status=	Dma1+2*0x8,	/* status port */
	Dma1reset=	Dma1+2*0xD,	/* reset port */
.
## diffname pc/headland.c 1991/0802
## diff -e /n/bootesdump/1991/0731/sys/src/9/safari/headland.c /n/bootesdump/1991/0802/sys/src/9/safari/headland.c
187c
	/*
	 *  copy out of temporary page
	 */
	memmove(xp->va, (void*)(KZERO|xp->pg->pa), xp->len);
.
181,182c
	chan = chan & 3;

	/*
	 *  disable the channel
	 */
	lock(dp);
	outb(dp->sbm, 4|chan);
	unlock(dp);

.
162c
	return len;
.
154,158c
	outb(dp->addr[chan], pa);		/* set address */
	outb(dp->addr[chan], pa>>8);
	outb(dp->page[chan], pa>>16);
	outb(dp->count[chan], len-1);		/* set count */
	outb(dp->count[chan], (len-1)>>8);
.
140c
			memmove((void*)(KZERO|xp->pg->pa), va, len);
.
133,135c
	pa = ((ulong)va) & ~KZERO;
	if(!isphys(va) || (pa&0xFFFF0000)!=((pa+len)&0xFFFF0000)){
.
130,131c
	 *  if this isn't kernel memory (or crossing 64k boundary),
	 *  allocate a page for the DMA.
.
126c
	chan = chan & 3;
.
66d
48d
38c
	Page	*pg;		/* page used by dma */
.
35d
12a
	/*
	 *  system control port
	 */
.
9a
typedef struct DMAport	DMAport;
typedef struct DMA	DMA;
typedef struct DMAxfer	DMAxfer;
.
## diffname pc/headland.c 1991/1210
## diff -e /n/bootesdump/1991/0802/sys/src/9/safari/headland.c /n/bootesdump/1991/1210/sys/src/9/safari/headland.c
108,201d
103,106d
101c
headreset(void)
.
98c
 *  reset machine
.
92c
heada20(void)
.
39,88d
22,35d
10,13d
8c
 *  headland system controller (ht21)
.
5a
#include	"io.h"
.
## diffname pc/headland.c 1992/0321
## diff -e /n/bootesdump/1991/1210/sys/src/9/safari/headland.c /n/bootesdump/1992/0321/sys/src/9/safari/headland.c
2c
#include	"../port/lib.h"
.
## diffname pc/headland.c 1992/0923 # deleted
## diff -e /n/bootesdump/1992/0808/sys/src/9/safari/headland.c /n/bootesdump/1992/0923/sys/src/9/pc/headland.c
1,37d

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.