From 79df10c08f89f08876c5a1f4f9f1f8eff9c45db9 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 23 Feb 1993 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1993-02-23 --- pc/adaptec.c | 5 +-- pc/ether2000.c | 2 +- pc/ether503.c | 1 + pc/ether8003.c | 95 +++++++++++++++++++++++++++++++++----------------- pc/main.c | 2 -- 5 files changed, 66 insertions(+), 39 deletions(-) diff --git a/pc/adaptec.c b/pc/adaptec.c index 18705fb1fa9e08188d0b8bc382f6f04f27325243..632a1cb512ab063c2a57767423a28e2a4a717155 100644 --- a/pc/adaptec.c +++ b/pc/adaptec.c @@ -468,7 +468,6 @@ reset(Ctlr *ctlr, ulong port, ulong id) void resetscsi(void) { - uchar rs; ulong port; /* @@ -484,10 +483,8 @@ resetscsi(void) */ outb(port+Rc, Srst|Scrst); delay(500); - if((rs = inb(port+Rs)) != (Init|Idle)){ - /*print("adaptec%d: reset status #%2.2ux\n", 0, rs);/**/ + if(inb(port+Rs) != (Init|Idle)) return; - } setvec(Int0vec+Irq, interrupt); reset(&softctlr[0], port, CtlrID); diff --git a/pc/ether2000.c b/pc/ether2000.c index fe8c176e111892fde8d2e552c862f820834f7896..c286b2bc809a811659a00de4d01beaa77ed7c9e9 100644 --- a/pc/ether2000.c +++ b/pc/ether2000.c @@ -17,7 +17,7 @@ * Semiconductor Local Area Network Databook (1992) as one of the * AT evaluation cards. * - * The NE2000 is really just a DP83901 plus a data port + * The NE2000 is really just a DP8390[12] plus a data port * and a reset port. */ enum { diff --git a/pc/ether503.c b/pc/ether503.c index 2096b6ec1d7962a4097a1edfa28e710fd80c4331..600ebff906380d62f231ddc9be2bd455453d9999 100644 --- a/pc/ether503.c +++ b/pc/ether503.c @@ -119,6 +119,7 @@ static Table table[] = { { 0 }, }; + static int reset(Ctlr *ctlr) { diff --git a/pc/ether8003.c b/pc/ether8003.c index b3e91b42af8a402ef67a0585eaa2efe18161b072..1c36974b7dac3743a9dabaa0ef4f9f65b072e8d6 100644 --- a/pc/ether8003.c +++ b/pc/ether8003.c @@ -9,11 +9,16 @@ #include "ether.h" +/* + * Western Digital/Standard Microsystems Corporation cards (WD80[01]3). + * Configuration code based on that provided by SMC. + */ enum { /* 83C584 Bus Interface Controller */ Msr = 0x00, /* Memory Select Register */ Icr = 0x01, /* Interface Configuration Register */ Iar = 0x02, /* I/O Address Register */ Bio = 0x03, /* BIOS ROM Address Register */ + Ear = 0x03, /* EEROM Address Register (shared with Bio) */ Irr = 0x04, /* Interrupt Request Register */ Laar = 0x05, /* LA Address Register */ Ijr = 0x06, /* Initialisation Jumpers */ @@ -28,6 +33,17 @@ enum { /* Msr */ Menb = 0x40, /* memory enable */ }; +enum { /* Icr */ + Bit16 = 0x01, /* 16-bit bus */ + Other = 0x02, /* other register access */ + Ir2 = 0x04, /* IR2 */ + Msz = 0x08, /* SRAM size */ + Rla = 0x10, /* recall LAN address */ + Rx7 = 0x20, /* recall all but I/O and LAN address */ + Rio = 0x40, /* recall I/O address from EEROM */ + Sto = 0x80, /* non-volatile EEROM store */ +}; + enum { /* Laar */ ZeroWS16 = (1<<5), /* zero wait states for 16-bit ops */ L16en = (1<<6), /* enable 16-bit LAN operation */ @@ -43,23 +59,28 @@ static int intrmap[] = { /* * Get configuration parameters, enable memory. + * There are opportunities here for buckets of code. + * We'll try to resist. */ static int reset(Ctlr *ctlr) { int i; - uchar msr, icr, laar, irr, sum; + uchar ic[8], sum; /* * Look for the interface. We read the LAN address ROM * and validate the checksum - the sum of all 8 bytes * should be 0xFF. + * While we're at it, get the (possible) interface chip + * registers, we'll use them to check for aliasing later. */ for(ctlr->card.io = 0x200; ctlr->card.io < 0x400; ctlr->card.io += 0x20){ sum = 0; for(i = 0; i < sizeof(ctlr->ea); i++){ ctlr->ea[i] = inb(ctlr->card.io+Lar+i); sum += ctlr->ea[i]; + ic[i] = inb(ctlr->card.io+i); } sum += inb(ctlr->card.io+Id); sum += inb(ctlr->card.io+Cksum); @@ -69,17 +90,6 @@ reset(Ctlr *ctlr) if(ctlr->card.io >= 0x400) return -1; - /* - * Found it, reset it. - * Be careful to preserve the Msr address bits, - * they don't get reloaded from the EEPROM on reset. - */ - msr = inb(ctlr->card.io+Msr); - outb(ctlr->card.io+Msr, Rst|msr); - delay(1); - outb(ctlr->card.io+Msr, msr); - delay(2); - /* * Check for old, dumb 8003E, which doesn't have an interface * chip. Only the msr exists out of the 1st eight registers, reads @@ -89,32 +99,53 @@ reset(Ctlr *ctlr) * 8003EBT, 8003S, 8003SH or 8003WT, we don't care), in which * case the default irq gets used. */ - msr = inb(ctlr->card.io+Msr); - icr = inb(ctlr->card.io+Icr); - laar = inb(ctlr->card.io+Laar); - irr = inb(ctlr->card.io+Irr); - if(icr != ctlr->ea[1] || irr != ctlr->ea[4] || laar != ctlr->ea[5]) - ctlr->card.irq = intrmap[((irr>>5) & 0x3)|(icr & 0x4)]; - else { - msr = (((ulong)ctlr->card.ramstart)>>13) & 0x3F; - icr = laar = 0; + if(memcmp(&ctlr->ea[1], &ic[1], 5) == 0){ + memset(ic, 0, sizeof(ic)); + ic[Msr] = (((ulong)ctlr->card.ramstart)>>13) & 0x3F; ctlr->card.watch = 0; } + else{ + /* + * As a final sanity check for the 8013EBT, which doesn't have + * the 83C584 interface chip, but has 2 real registers, write Gp2 and if + * it reads back the same, it's not an 8013EBT. + */ + outb(ctlr->card.io+Gp2, 0xAA); + inb(ctlr->card.io+Msr); /* wiggle bus */ + if(inb(ctlr->card.io+Gp2) != 0xAA){ + memset(ic, 0, sizeof(ic)); + ic[Msr] = (((ulong)ctlr->card.ramstart)>>13) & 0x3F; + ctlr->card.watch = 0; + ctlr->card.irq = 2; /* special */ + } + else + ctlr->card.irq = intrmap[((ic[Irr]>>5) & 0x3)|(ic[Icr] & 0x4)]; + + /* + * Check if 16-bit card. + * If Bit16 is read/write, then we have an 8-bit card. + * If Bit16 is set, we're in a 16-bit slot. + */ + outb(ctlr->card.io+Icr, ic[Icr]^Bit16); + inb(ctlr->card.io+Msr); /* wiggle bus */ + if((inb(ctlr->card.io+Icr) & Bit16) == (ic[Icr] & Bit16)){ + ctlr->card.bit16 = 1; + ic[Icr] &= ~Bit16; + } + outb(ctlr->card.io+Icr, ic[Icr]); - /* - * Set up the bus-size, RAM address and RAM size - * from the info in the configuration registers. - */ - ctlr->card.bit16 = icr & 0x1; + ic[Icr] = inb(ctlr->card.io+Icr); + if(ctlr->card.bit16 && (ic[Icr] & Bit16) == 0) + ctlr->card.bit16 = 0; + } - ctlr->card.ram = 1; - ctlr->card.ramstart = KZERO|((msr & 0x3F)<<13); + ctlr->card.ramstart = KZERO|((ic[Msr] & 0x3F)<<13); if(ctlr->card.bit16) - ctlr->card.ramstart |= (laar & 0x1F)<<19; + ctlr->card.ramstart |= (ic[Laar] & 0x1F)<<19; else ctlr->card.ramstart |= 0x80000; - if(icr & (1<<3)) + if(ic[Icr] & (1<<3)) ctlr->card.ramstop = 32*1024; else ctlr->card.ramstop = 8*1024; @@ -133,9 +164,9 @@ reset(Ctlr *ctlr) /* * Enable interface RAM, set interface width. */ - outb(ctlr->card.io+Msr, Menb|msr); + outb(ctlr->card.io+Msr, ic[Msr]|Menb); if(ctlr->card.bit16) - outb(ctlr->card.io+Laar, laar|L16en|M16en|ZeroWS16); + outb(ctlr->card.io+Laar, ic[Laar]|L16en|M16en|ZeroWS16); /* * Finally, init the 8390 and set the diff --git a/pc/main.c b/pc/main.c index 164e22864c1b8df67e0fb06a2a674bd9ba228075..51422c346a517ef34a8cc37f0040bedd75aeb26d 100644 --- a/pc/main.c +++ b/pc/main.c @@ -276,8 +276,6 @@ confinit(void) pcnt = (1<