From 319f6345308b9fa37587d2a38fdf42dd5faed987 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 21 Feb 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-02-21 --- boot/boot.c | 12 +------- ip/ipaux.c | 18 +++++++----- ip/ipifc.c | 22 +++++++-------- pc/dat.h | 2 +- pc/devarch.c | 2 ++ pc/devpccard.c | 75 ++++++++++++++++++++++++++++++++++++++++---------- pc/devusb.c | 2 +- pc/i8253.c | 2 +- pc/usbuhci.c | 1 + port/auth.c | 7 ++--- 10 files changed, 92 insertions(+), 51 deletions(-) diff --git a/boot/boot.c b/boot/boot.c index 68bf51774a5cf75187e51aa906816c24ce04a01b..2d639147f9d5c3322b2200b0a921e0a05bd1b696 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -18,16 +18,6 @@ int bargc; static void swapproc(void); static Method *rootserver(char*); -static int -rconv(Fmt* fp) -{ - char s[ERRMAX]; - - s[0] = '\0'; - errstr(s, sizeof s); - return fmtstrcpy(fp, s); -} - void boot(int argc, char *argv[]) { @@ -41,7 +31,7 @@ boot(int argc, char *argv[]) char buf[32]; AuthInfo *ai; - fmtinstall('r', rconv); + fmtinstall('r', errfmt); open("#c/cons", OREAD); open("#c/cons", OWRITE); diff --git a/ip/ipaux.c b/ip/ipaux.c index 7f4c25693009f500f4b0b2b1e8d4349493557904..05431c86dbe111af51dc8b3121e8c063cb445817 100644 --- a/ip/ipaux.c +++ b/ip/ipaux.c @@ -135,13 +135,16 @@ eipfmt(Fmt *f) switch(f->r) { case 'E': /* Ethernet address */ p = va_arg(f->args, uchar*); - return fmtprint(f, efmt, p[0], p[1], p[2], p[3], p[4], p[5]); + snprint(buf, sizeof buf, efmt, p[0], p[1], p[2], p[3], p[4], p[5]); + return fmtstrcpy(f, buf); case 'I': /* Ip address */ p = va_arg(f->args, uchar*); common: - if(memcmp(p, v4prefix, 12) == 0) - return fmtprint(f, ifmt, p[12], p[13], p[14], p[15]); + if(memcmp(p, v4prefix, 12) == 0){ + snprint(buf, sizeof buf, ifmt, p[12], p[13], p[14], p[15]); + return fmtstrcpy(f, buf); + } /* find longest elision */ eln = eli = -1; @@ -179,7 +182,8 @@ common: case 'V': /* v4 ip address */ p = va_arg(f->args, uchar*); - return fmtprint(f, ifmt, p[0], p[1], p[2], p[3]); + snprint(buf, sizeof buf, ifmt, p[0], p[1], p[2], p[3]); + return fmtstrcpy(f, buf); case 'M': /* ip mask */ p = va_arg(f->args, uchar*); @@ -199,10 +203,10 @@ common: n = 8*16; /* got one, use /xx format */ - return fmtprint(f, "/%d", n); - + snprint(buf, sizeof buf, "/%d", n); + return fmtstrcpy(f, buf); } - return fmtprint(f, "(eipfmt)"); + return fmtstrcpy(f, "(eipfmt)"); } #define CLASS(p) ((*(uchar*)(p))>>6) diff --git a/ip/ipifc.c b/ip/ipifc.c index 1761cf3e450c44c10782870fa9b4b1c7aba1a883..618c0d7b68e574a8a76e81cbe97b60316a6cc270 100644 --- a/ip/ipifc.c +++ b/ip/ipifc.c @@ -882,31 +882,29 @@ out: } static char *stformat = "%-32.32I %2.2d %4.4s\n"; -enum -{ - Nstformat= 41, -}; long ipselftabread(Fs *f, char *cp, ulong offset, int n) { - int i, m, nifc; + int i, m, nifc, off; Ipself *p; Iplink *link; char state[8]; m = 0; + off = offset; qlock(f->self); for(i = 0; i < NHASH && m < n; i++){ for(p = f->self->hash[i]; p != nil && m < n; p = p->next){ - if(offset == 0){ - nifc = 0; - for(link = p->link; link; link = link->selflink) - nifc++; - routetype(p->type, state); - m += snprint(cp + m, n - m, stformat, p->a, nifc, state); + nifc = 0; + for(link = p->link; link; link = link->selflink) + nifc++; + routetype(p->type, state); + m += snprint(cp + m, n - m, stformat, p->a, nifc, state); + if(off > 0){ + off -= m; + m = 0; } - offset -= Nstformat; } } qunlock(f->self); diff --git a/pc/dat.h b/pc/dat.h index cefd292c7bd762e7913f7dfaae04e37edb5f9f69..1c42ab85d94dd10591fa8127d4832fa14e83c751 100644 --- a/pc/dat.h +++ b/pc/dat.h @@ -185,7 +185,7 @@ struct Mach int loopconst; int cpumhz; - int cpuhz; + vlong cpuhz; int cpuidax; int cpuiddx; char cpuidid[16]; diff --git a/pc/devarch.c b/pc/devarch.c index 668b6071eec4e57f9b7023860cfe31a7b0684107..9cc63cebd1ee9cd577a536d004db0b7e5b843ed6 100644 --- a/pc/devarch.c +++ b/pc/devarch.c @@ -546,11 +546,13 @@ static X86type x86intel[] = { 6, 6, 16, "Celeron", }, { 6, 7, 16, "PentiumIII/Xeon", }, { 6, 8, 16, "PentiumIII/Xeon", }, + { 0xF, 1, 16, "P4", }, /* P4 */ { 3, -1, 32, "386", }, /* family defaults */ { 4, -1, 22, "486", }, { 5, -1, 23, "P5", }, { 6, -1, 16, "P6", }, + { 0xF, -1, 16, "P4", }, /* P4 */ { -1, -1, 23, "unknown", }, /* total default */ }; diff --git a/pc/devpccard.c b/pc/devpccard.c index cd99c1a79ae18fdd51c6d300cb560c817c93247a..634bcfcd77cb9d035edde5076345212339e95eac 100644 --- a/pc/devpccard.c +++ b/pc/devpccard.c @@ -13,6 +13,7 @@ enum { TI_vid = 0x104c, + TI_1131_did = 0xAC15, TI_1250_did = 0xAC16, TI_1450_did = 0xAC1B, TI_1251A_did = 0xAC1D, @@ -28,6 +29,19 @@ enum { LegacyAddr = 0x3e0, NUMEVENTS = 10, + + TI1131xSC = 0x80, // system control + TI122X_SC_INTRTIE = 1 << 29, + TI12xxIM = 0x8c, // + TI1131xCC = 0x91, // card control + TI113X_CC_RIENB = 1 << 7, + TI113X_CC_ZVENABLE = 1 << 6, + TI113X_CC_PCI_IRQ_ENA = 1 << 5, + TI113X_CC_PCI_IREQ = 1 << 4, + TI113X_CC_PCI_CSC = 1 << 3, + TI113X_CC_SPKROUTEN = 1 << 1, + TI113X_CC_IFG = 1 << 0, + TI1131xDC = 0x92, // device control }; typedef struct { @@ -39,6 +53,7 @@ typedef struct { static Variant variant[] = { { Ricoh_vid, Ricoh_476_did, "Ricoh 476 PCI/Cardbus bridge", }, { Ricoh_vid, Ricoh_478_did, "Ricoh 478 PCI/Cardbus bridge", }, +{ TI_vid, TI_1131_did, "TI PCI-1131 Cardbus Controller", }, { TI_vid, TI_1250_did, "TI PCI-1250 Cardbus Controller", }, { TI_vid, TI_1450_did, "TI PCI-1450 Cardbus Controller", }, { TI_vid, TI_1251A_did, "TI PCI-1251A Cardbus Controller", }, @@ -446,7 +461,7 @@ processevents(void *) } static void -interrupt(Ureg *, void *) +cbinterrupt(Ureg *, void *) { int i; @@ -529,14 +544,18 @@ devpccardlink(void) cb->cb_pci = pci; cb->cb_variant = &variant[i]; - pcicfgw32(pci, PciCBMBR0, 0xffffffff); - pcicfgw32(pci, PciCBMLR0, 0); - pcicfgw32(pci, PciCBMBR1, 0xffffffff); - pcicfgw32(pci, PciCBMLR1, 0); - pcicfgw32(pci, PciCBIBR0, 0xffffffff); - pcicfgw32(pci, PciCBILR0, 0); - pcicfgw32(pci, PciCBIBR1, 0xffffffff); - pcicfgw32(pci, PciCBILR1, 0); + if (pci->vid != TI_vid) { + // Gross hack, needs a fix. Inherit the mappings from 9load + // for the TIs (pb) + pcicfgw32(pci, PciCBMBR0, 0xffffffff); + pcicfgw32(pci, PciCBMLR0, 0); + pcicfgw32(pci, PciCBMBR1, 0xffffffff); + pcicfgw32(pci, PciCBMLR1, 0); + pcicfgw32(pci, PciCBIBR0, 0xffffffff); + pcicfgw32(pci, PciCBILR0, 0); + pcicfgw32(pci, PciCBIBR1, 0xffffffff); + pcicfgw32(pci, PciCBILR1, 0); + } // Set up PCI bus numbers if needed. if (pcicfgr8(pci, PciSBN) == 0) { @@ -556,8 +575,36 @@ devpccardlink(void) if (pci->intl == 0xff || pci->intl == 0) print("#Y%d: No interrupt?\n", (int)(cb - cbslots)); } + + // Don't you love standards! + if (pci->vid == TI_vid) { + if (pci->did <= TI_1131_did) { + uchar cc; + + cc = pcicfgr8(pci, TI1131xCC); + cc &= ~(TI113X_CC_PCI_IRQ_ENA | + TI113X_CC_PCI_IREQ | + TI113X_CC_PCI_CSC | + TI113X_CC_ZVENABLE); + cc |= TI113X_CC_PCI_IRQ_ENA | + TI113X_CC_PCI_IREQ | + TI113X_CC_SPKROUTEN; + pcicfgw8(pci, TI1131xCC, cc); + + // PCI interrupts only + pcicfgw8(pci, TI1131xDC, + pcicfgr8(pci, TI1131xDC) & ~6); + + // CSC ints to PCI bus. + wrreg(cb, Rigc, rdreg(cb, Rigc) | 0x10); + } + else if (pci->did == TI_1250_did) { + print("No support yet for the TI_1250_did, prod pb\n"); + } + } + if (intl != -1 && intl != pci->intl) - intrenable(pci->intl, interrupt, cb, pci->tbdf, "cardbus"); + intrenable(pci->intl, cbinterrupt, cb, pci->tbdf, "cardbus"); intl = pci->intl; if ((baddr = pcicfgr32(cb->cb_pci, PciBAR0)) == 0) { @@ -1277,11 +1324,11 @@ pccardread(Chan *c, void *a, long n, vlong offset) for (i = 0; i != Nbars; i++) if (pci->mem[i].size) p = seprint(p, e, - "\tmem[%d] %.8uX (%.8uX)\n", + "\tmem[%d] %.8ulX (%.8uX)\n", i, pci->mem[i].bar, pci->mem[i].size); if (pci->rom.size) - p = seprint(p, e, "\tROM %.8uX (%.8uX)\n", i, + p = seprint(p, e, "\tROM %.8ulX (%.8uX)\n", pci->rom.bar, pci->rom.size); pci = pci->list; } @@ -1301,12 +1348,12 @@ pccardread(Chan *c, void *a, long n, vlong offset) ct = &pi->pi_ctab[n]; p = seprint(p, e, - "\tconfiguration[%d] irqs %.4X; vpp %d, %d; %s\n", + "\tconfiguration[%ld] irqs %.4uX; vpp %d, %d; %s\n", n, ct->irqs, ct->vpp1, ct->vpp2, (ct == pi->pi_defctab)? "(default);": ""); for (i = 0; i != ct->nio; i++) if (ct->io[i].len > 0) - p = seprint(p, e, "\t\tio[%d] %.8lX %d\n", + p = seprint(p, e, "\t\tio[%d] %.8ulX %uld\n", i, ct->io[i].start, ct->io[i].len); } } diff --git a/pc/devusb.c b/pc/devusb.c index 9ea30d9e41c5874b9badf443381e2429a22cada7..86f89938b94cbf393aa9ee62fc6b6bf85b0d9de5 100644 --- a/pc/devusb.c +++ b/pc/devusb.c @@ -832,7 +832,7 @@ usbwrite(Chan *c, void *a, long n, vlong offset) error(Ebadarg); } i = strtoul(cb->f[5], nil, 0); - if(i >= 1 && i <= 100000){ + if(i >= 1 && i*e->samplesz <= 12*1000*1000){ /* Hz */ e->hz = i; e->remain = 0; diff --git a/pc/i8253.c b/pc/i8253.c index 7d6f478af37a150040ccddd51901062bbb54a00b..a81ce4847f4af5b9410579da487115e014e9d19e 100644 --- a/pc/i8253.c +++ b/pc/i8253.c @@ -259,7 +259,7 @@ i8253enable(void) { i8253.when = fastticks(nil); i8253.fastperiod = (m->cpuhz + HZ/2) / HZ; - i8253.fast2freq = (vlong)m->cpuhz * FreqMul / Freq; + i8253.fast2freq = m->cpuhz * FreqMul / Freq; i8253.enabled = 1; intrenable(IrqCLOCK, clockintr0, 0, BUSUNKNOWN, "clock"); } diff --git a/pc/usbuhci.c b/pc/usbuhci.c index a6c8070316e7caa0216435e56254bd510feb0bb1..67834ac19787218aae5e17d3391bafb218d981f4 100644 --- a/pc/usbuhci.c +++ b/pc/usbuhci.c @@ -965,6 +965,7 @@ cleaniso(Endpt *e, int frnum) return; id = (e->x<<7)|(e->dev->x&0x7F); do { +//shut up! if (td->status & AnyError) iprint("usbisoerror 0x%lux\n", td->status); n = (td->status + 1) & 0x3ff; diff --git a/port/auth.c b/port/auth.c index d5e716b77519d8a6721226cd77267373a76c84bd..12aef48468e503279ce98526177ed72ea6a5a0fb 100644 --- a/port/auth.c +++ b/port/auth.c @@ -119,11 +119,10 @@ hostownerwrite(char *a, int n) if(!iseve()) error(Eperm); - if(n >= sizeof buf) - error(Ebadarg); - strncpy(buf, a, n+1); - if(buf[0] == '\0') + if(n <= 0 || n >= sizeof buf) error(Ebadarg); + memmove(buf, a, n); + buf[n] = 0; renameuser(eve, buf); kstrdup(&eve, buf);