update pc kernel devices shared with the pcpae kernel to handle 64-bit bars. Reference: /n/atom/patch/applied/pcdevs64bit2 Date: Sat Jan 11 20:54:24 CET 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/9/pc/archacpi.c Sat Jan 11 20:54:04 2014 +++ /sys/src/9/pc/archacpi.c Sat Jan 11 20:54:04 2014 @@ -564,7 +564,7 @@ } PCArch archacpi = { -.id= "ACPI", +.id= "ACPI", .ident= identify, .reset= mpshutdown, .intrinit= acpiinit, --- /sys/src/9/pc/screen.c Sat Jan 11 20:54:04 2014 +++ /sys/src/9/pc/screen.c Sat Jan 11 20:54:04 2014 @@ -518,7 +518,7 @@ best = i; } if(best >= 0){ - paddr = p->mem[best].bar & ~0x0F; + paddr = p->mem[best].bar & (uintmem)0xf; size = p->mem[best].size; vgalinearaddr(scr, paddr, size); return; --- /sys/src/9/pc/usbehcipc.c Sat Jan 11 20:54:04 2014 +++ /sys/src/9/pc/usbehcipc.c Sat Jan 11 20:54:04 2014 @@ -113,7 +113,7 @@ ctlr->nframes = 256; break; default: - panic("ehci: unknown fls %ld", opio->cmd & Cflsmask); + panic("ehci: unknown fls %d", opio->cmd & Cflsmask); } dprint("ehci: %d frames\n", ctlr->nframes); iunlock(ctlr); @@ -184,7 +184,7 @@ /* * Find EHCI controllers (Programming Interface = 0x20). */ - if(p->ccrb != Pcibcserial || p->ccru != Pciscusb || p->ccrp != 0x20) + if(p->ccrb != 0xc || p->ccru != 3 || p->ccrp != 0x20) continue; if(i == Nhcis){ print("ehci: bug: more than %d controllers\n", Nhcis); @@ -194,7 +194,7 @@ print("usbehci: ignore %.4ux/%.4ux\n", p->vid, p->did); continue; } - io = p->mem[0].bar & ~0x0f; + io = p->mem[0].bar & ~(uintmem)0xf; if(io == 0){ print("usbehci: %x %x: failed to map registers\n", p->vid, p->did); --- /sys/src/9/pc/usbohci.c Sat Jan 11 20:54:04 2014 +++ /sys/src/9/pc/usbohci.c Sat Jan 11 20:54:05 2014 @@ -2,6 +2,7 @@ * USB Open Host Controller Interface (Ohci) driver * * BUGS: + * - not really 64-bit safe (Tds aren't necessarly in low memory) * - Missing isochronous input streams. * - Too many delays and ilocks. * - bandwidth admission control must be done per-frame. @@ -174,10 +175,10 @@ * Endpoint descriptor. (first 4 words used by hardware) */ struct Ed { - ulong ctrl; - ulong tail; /* transfer descriptor */ - ulong head; - ulong nexted; + u32int ctrl; + u32int tail; /* transfer descriptor */ + u32int head; + u32int nexted; Ed* next; /* sw; in free list or next in list */ Td* tds; /* in use by current xfer; all for iso */ @@ -217,8 +218,8 @@ int nframes; /* number of frames for a full second */ Td* atds; /* Tds avail for further I/O */ int navail; /* number of avail Tds */ - ulong frno; /* next frame number avail for I/O */ - ulong left; /* remainder after rounding Hz to samples/ms */ + u32int frno; /* next frame number avail for I/O */ + u32int left; /* remainder after rounding Hz to samples/ms */ int nerrs; /* consecutive errors on iso I/O */ }; @@ -228,11 +229,11 @@ */ struct Td { - ulong ctrl; - ulong cbp; /* current buffer pointer */ - ulong nexttd; - ulong be; - ushort offsets[8]; /* used by Iso Tds only */ + u32int ctrl; + u32int cbp; /* current buffer pointer */ + u32int nexttd; + u32int be; + u16int offsets[8]; /* used by Iso Tds only */ Td* next; /* in free or Ed tds list */ Td* anext; /* in avail td list (iso) */ @@ -240,8 +241,8 @@ Qio* io; /* using this Td for I/O */ Block* bp; /* data for this Td */ ulong nbytes; /* bytes in this Td */ - ulong cbp0; /* initial value for cbp */ - ulong last; /* true for last Td in Qio */ + u32int cbp0; /* initial value for cbp */ + int last; /* true for last Td in Qio */ }; /* @@ -249,10 +250,10 @@ */ struct Hcca { - ulong intrtable[32]; - ushort framenumber; - ushort pad1; - ulong donehead; + u32int intrtable[32]; + u16int framenumber; + u16int pad1; + u32int donehead; uchar reserved[116]; }; @@ -262,44 +263,44 @@ struct Ohci { /* control and status group */ - ulong revision; /*00*/ - ulong control; /*04*/ - ulong cmdsts; /*08*/ - ulong intrsts; /*0c*/ - ulong intrenable; /*10*/ - ulong intrdisable; /*14*/ + u32int revision; /*00*/ + u32int control; /*04*/ + u32int cmdsts; /*08*/ + u32int intrsts; /*0c*/ + u32int intrenable; /*10*/ + u32int intrdisable; /*14*/ /* memory pointer group */ - ulong hcca; /*18*/ - ulong periodcurred; /*1c*/ - ulong ctlheaded; /*20*/ - ulong ctlcurred; /*24*/ - ulong bulkheaded; /*28*/ - ulong bulkcurred; /*2c*/ - ulong donehead; /*30*/ + u32int hcca; /*18*/ + u32int periodcurred; /*1c*/ + u32int ctlheaded; /*20*/ + u32int ctlcurred; /*24*/ + u32int bulkheaded; /*28*/ + u32int bulkcurred; /*2c*/ + u32int donehead; /*30*/ /* frame counter group */ - ulong fminterval; /*34*/ - ulong fmremaining; /*38*/ - ulong fmnumber; /*3c*/ - ulong periodicstart; /*40*/ - ulong lsthreshold; /*44*/ + u32int fminterval; /*34*/ + u32int fmremaining; /*38*/ + u32int fmnumber; /*3c*/ + u32int periodicstart; /*40*/ + u32int lsthreshold; /*44*/ /* root hub group */ - ulong rhdesca; /*48*/ - ulong rhdescb; /*4c*/ - ulong rhsts; /*50*/ - ulong rhportsts[15]; /*54*/ - ulong pad25[20]; /*90*/ + u32int rhdesca; /*48*/ + u32int rhdescb; /*4c*/ + u32int rhsts; /*50*/ + u32int rhportsts[15]; /*54*/ + u32int pad25[20]; /*90*/ /* unknown */ - ulong hostueaddr; /*e0*/ - ulong hostuests; /*e4*/ - ulong hosttimeoutctrl; /*e8*/ - ulong pad59; /*ec*/ - ulong pad60; /*f0*/ - ulong hostrevision; /*f4*/ - ulong pad62[2]; + u32int hostueaddr; /*e0*/ + u32int hostuests; /*e4*/ + u32int hosttimeoutctrl; /*e8*/ + u32int pad59; /*ec*/ + u32int pad60; /*f0*/ + u32int hostrevision; /*f4*/ + u32int pad62[2]; /*100*/ }; @@ -390,21 +391,26 @@ }; static void* -pa2ptr(ulong pa) +pa2ptr(uintmem pa) { if(pa == 0) return nil; - else - return KADDR(pa); + else if(sizeof(pa) > 4 && pa > 0xffffffff) + panic("usb: ohci: highmem pa %#P", pa); + return KADDR(pa); } -static ulong +static uintmem ptr2pa(void *p) { + uintmem pa; + if(p == nil) return 0; - else - return PADDR(p); + pa = PADDR(p); + if(sizeof(pa) > 4 && pa > 0xffffffff) + panic("usb: ohci: highmemptr %#p", p); + return pa; } static void @@ -572,7 +578,7 @@ static int tdtok(Td *td) { - return (td->ctrl & Tdtokmask); + return td->ctrl & Tdtokmask; } static void* @@ -622,7 +628,7 @@ static void tdfree(Td *td) { - if(td == 0) + if(td == nil) return; freeb(td->bp); td->bp = nil; @@ -834,8 +840,8 @@ if(td == nil) return seprint(s, e, "\n"); - s = seprint(s, e, "%#p ep %#p ctrl %#p", td, td->ep, td->ctrl); - s = seprint(s, e, " cc=%#ulx", (td->ctrl >> Tdccshift) & Tdccmask); + s = seprint(s, e, "%#p ep %#p ctrl %#.8ux", td, td->ep, td->ctrl); + s = seprint(s, e, " cc=%#ux", (td->ctrl >> Tdccshift) & Tdccmask); if(iso == 0){ if((td->ctrl & Tdround) != 0) s = seprint(s, e, " rnd"); @@ -844,12 +850,12 @@ s = seprint(s, e, " d%d", (td->ctrl & Tddata1) ? 1 : 0); else s = seprint(s, e, " d-"); - s = seprint(s, e, " ec=%uld", (td->ctrl >> Tderrshift) & Tderrmask); + s = seprint(s, e, " ec=%ud", (td->ctrl >> Tderrshift) & Tderrmask); }else{ - s = seprint(s, e, " fc=%uld", (td->ctrl >> Tdfcshift) & Tdfcmask); - s = seprint(s, e, " sf=%uld", td->ctrl & Tdsfmask); + s = seprint(s, e, " fc=%ud", (td->ctrl >> Tdfcshift) & Tdfcmask); + s = seprint(s, e, " sf=%ud", td->ctrl & Tdsfmask); } - s = seprint(s, e, " cbp0 %#p cbp %#p next %#p be %#p %s", + s = seprint(s, e, " cbp0 %#.8ux cbp %#.8ux next %#.8ux be %#.8ux %s", td->cbp0, td->cbp, td->nexttd, td->be, td->last ? "last" : ""); s = seprint(s, e, "\n\t\t%ld bytes", td->nbytes); if((bp = td->bp) != nil){ @@ -911,7 +917,7 @@ if(buf == nil) return; e = buf+512; - s = seprint(buf, e, "\ted %#p: ctrl %#p", ed, ed->ctrl); + s = seprint(buf, e, "\ted %#p: ctrl %#.8ux", ed, ed->ctrl); if((ed->ctrl & Edskip) != 0) s = seprint(s, e, " skip"); if((ed->ctrl & Ediso) != 0) @@ -925,9 +931,9 @@ s = seprint(s, e, " out"); if(edhalted(ed)) s = seprint(s, e, " hlt"); - s = seprint(s, e, " ep%uld.%uld", (ed->ctrl>>7)&Epmax, ed->ctrl&0x7f); - s = seprint(s, e, " maxpkt %uld", (ed->ctrl>>Edmpsshift)&Edmpsmask); - seprint(s, e, " tail %#p head %#p next %#p\n",ed->tail,ed->head,ed->nexted); + s = seprint(s, e, " ep%ud.%ud", (ed->ctrl>>7)&Epmax, ed->ctrl&0x7f); + s = seprint(s, e, " maxpkt %ud", (ed->ctrl>>Edmpsshift)&Edmpsmask); + seprint(s, e, " tail %#.8ux head %#.8ux next %#.8ux\n", ed->tail, ed->head, ed->nexted); print("%s", buf); free(buf); if(ed->tds != nil && (ed->ctrl & Ediso) == 0) @@ -973,7 +979,7 @@ case Tiso: iso = ep->aux; s = seprintio(s, e, iso, "w"); - s = seprint(s, e, "\tntds %d avail %d frno %uld left %uld next avail %#p\n", + s = seprint(s, e, "\tntds %d avail %d frno %ud left %ud next avail %#p\n", iso->nframes, iso->navail, iso->frno, iso->left, iso->atds); break; } @@ -1016,10 +1022,10 @@ ctlr = hp->aux; ilock(ctlr); seprintctl(cs, cs+sizeof(cs), ctlr->ohci->control); - print("ohci ctlr %#p: frno %#ux ctl %#lux %s sts %#lux intr %#lux\n", + print("ohci ctlr %#p: frno %#ux ctl %#ux %s sts %#ux intr %#ux\n", ctlr, ctlr->hcca->framenumber, ctlr->ohci->control, cs, ctlr->ohci->cmdsts, ctlr->ohci->intrsts); - print("ctlhd %#ulx cur %#ulx bulkhd %#ulx cur %#ulx done %#ulx\n", + print("ctlhd %#ux cur %#ux bulkhd %#ux cur %#ux done %#ux\n", ctlr->ohci->ctlheaded, ctlr->ohci->ctlcurred, ctlr->ohci->bulkheaded, ctlr->ohci->bulkcurred, ctlr->ohci->donehead); @@ -1241,7 +1247,7 @@ bp->wp = bp->rp; io->err = errmsg(err); if(debug || ep->debug){ - print("ohci: isointerrupt: ep%d.%d: err %d (%s) frnum 0x%lux\n", + print("ohci: isointerrupt: ep%d.%d: err %d (%s) frnum %#ux\n", ep->dev->nb, ep->nb, err, errmsg(err), ctlr->ohci->fmnumber); dumptd(td, "failed", ed->ctrl & Ediso); @@ -1271,7 +1277,7 @@ Td *td, *ntd, *td0; Hci *hp; Ctlr *ctlr; - ulong status, curred; + u32int status, curred; int i, frno; hp = arg; @@ -1318,7 +1324,7 @@ } if((status & Ue) != 0){ curred = ctlr->ohci->periodcurred; - print("ohci: unrecoverable error frame 0x%.8lux ed 0x%.8lux, " + print("ohci: unrecoverable error frame %#.8ux ed %#.8ux, " "ints %d %d %d %d\n", ctlr->ohci->fmnumber, curred, ohciinterrupts[Tctl], ohciinterrupts[Tintr], @@ -1328,7 +1334,7 @@ status &= ~Ue; } if(status != 0) - print("ohci interrupt: unhandled sts 0x%.8lux\n", status); + print("ohci interrupt: unhandled sts %#.8ux\n", status); iunlock(ctlr); } @@ -1350,7 +1356,7 @@ panic("ohci: transfer > two pages"); /* maximum of one physical page crossing allowed */ bp = allocb(count+BY2PG); - bp->rp = (uchar*)PGROUND((uintptr)bp->rp); + bp->rp = (uchar*)ROUNDUP((uintptr)bp->rp, BY2PG); bp->wp = bp->rp; } dtd = *dtdp; @@ -2021,7 +2027,7 @@ Ctlr *ctlr; Qio *io; Ctlio *cio; - ulong usbid; + u32int usbid; ctlr = ep->hp->aux; deprint("ohci: epopen ep%d.%d\n", ep->dev->nb, ep->nb); @@ -2241,7 +2247,7 @@ { int v; Ctlr *ub; - ulong ohcistatus; + u32int ohcistatus; /* * We must return status bits as a @@ -2272,7 +2278,7 @@ if(ohcistatus & Lsda) v |= HPslow; if(v & (HPstatuschg|HPchange)) - ddprint("ohci port %d sts %#ulx hub sts %#x\n", port, ohcistatus, v); + ddprint("ohci port %d sts %#ux hub sts %#x\n", port, ohcistatus, v); return v; } @@ -2280,13 +2286,13 @@ dumpohci(Ctlr *ctlr) { int i; - ulong *ohci; + u32int *ohci; ohci = &ctlr->ohci->revision; print("ohci registers: \n"); - for(i = 0; i < sizeof(Ohci)/sizeof(ulong); i++) + for(i = 0; i < sizeof(Ohci)/sizeof *ohci; i++) if(i < 3 || ohci[i] != 0) - print("\t[%#2.2x]\t%#8.8ulx\n", i * 4, ohci[i]); + print("\t[%#2.2x]\t%#8.8ux\n", i * 4, ohci[i]); print("\n"); } @@ -2296,7 +2302,7 @@ Ctlr *ctlr; Ohci *ohci; int i; - ulong ival, ctrl, fmi; + u32int ival, ctrl, fmi; ctlr = hp->aux; dprint("ohci %#p init\n", ctlr->ohci); @@ -2374,10 +2380,9 @@ /* * Find Ohci controllers (Programming Interface = 0x10). */ - if(p->ccrb != Pcibcserial || p->ccru != Pciscusb || - p->ccrp != 0x10) + if(p->ccrb != 0xc || p->ccru != 3 || p->ccrp != 0x10) continue; - pa = p->mem[0].bar & ~0x0F; + pa = p->mem[0].bar & ~(uintmem)0xf; if(p->intl == 0xFF || p->intl == 0) { print("usb: ohci: no irq assigned for port %#P\n", pa); continue; @@ -2476,7 +2481,6 @@ hcca = lomallocalign(sizeof(Hcca), 256); if(hcca == nil) panic("usbhreset: no memory for Hcca"); - memset(hcca, 0, sizeof(*hcca)); ctlr->hcca = hcca; mkqhtree(ctlr); --- /sys/src/9/pc/usbuhci.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/usbuhci.c Sat Jan 11 20:54:05 2014 @@ -148,7 +148,7 @@ Qh* qhs; /* list of Qhs for this controller */ Qh* qh[Tmax]; /* Dummy Qhs to insert Qhs after */ Isoio* iso; /* list of active iso I/O */ - ulong* frames; /* frame list (used by hw) */ + u32int* frames; /* frame list (used by hw) */ ulong load; /* max load for a single frame */ ulong isoload; /* max iso load for a single frame */ int nintr; /* number of interrupts attended */ @@ -235,10 +235,10 @@ */ struct Qh { - ulong link; /* link to next horiz. item (eg. Qh) */ - ulong elink; /* link to element (eg. Td; updated by hw) */ + u32int link; /* link to next horiz. item (eg. Qh) */ + u32int elink; /* link to element (eg. Td; updated by hw) */ - ulong state; /* Qidle -> Qinstall -> Qrun -> Qdone | Qclose */ + u32int state; /* Qidle -> Qinstall -> Qrun -> Qdone | Qclose */ Qio* io; /* for this queue */ Qh* next; /* in active or free list */ @@ -259,13 +259,13 @@ */ struct Td { - ulong link; /* Link to next Td or Qh */ - ulong csw; /* control and status word (updated by hw) */ - ulong token; /* endpt, device, pid */ - ulong buffer; /* buffer pointer */ + u32int link; /* Link to next Td or Qh */ + u32int csw; /* control and status word (updated by hw) */ + u32int token; /* endpt, device, pid */ + u32int buffer; /* buffer pointer */ Td* next; /* in qh or Isoio or free list */ - ulong ndata; /* bytes available/used at data */ + u32int ndata; /* bytes available/used at data */ uchar* data; /* pointer to actual data */ void* buff; /* allocated data, for large transfers */ @@ -347,14 +347,14 @@ static char* seprinttd(char *s, char *se, Td *td) { - s = seprint(s, se, "%#p link %#ulx", td, td->link); + s = seprint(s, se, "%#p link %#ux", td, td->link); if((td->link & Tdvf) != 0) s = seprint(s, se, "V"); if((td->link & Tdterm) != 0) s = seprint(s, se, "T"); if((td->link & Tdlinkqh) != 0) s = seprint(s, se, "Q"); - s = seprint(s, se, " csw %#ulx ", td->csw); + s = seprint(s, se, " csw %#ux ", td->csw); if(td->csw & Tdactive) s = seprint(s, se, "a"); if(td->csw & Tdiso) @@ -366,7 +366,7 @@ if((td->csw & (Tderr1|Tderr2)) == 0) s = seprint(s, se, "z"); if(td->csw & Tderrors) - s = seprint(s, se, " err %#ulx", td->csw & Tderrors); + s = seprint(s, se, " err %#ux", td->csw & Tderrors); if(td->csw & Tdstalled) s = seprint(s, se, "s"); if(td->csw & Tddberr) @@ -381,7 +381,7 @@ s = seprint(s, se, "B"); s = seprint(s, se, " stslen %d", tdlen(td)); - s = seprint(s, se, " token %#ulx", td->token); + s = seprint(s, se, " token %#ux", td->token); if(td->token == 0) /* the BWS loopback Td, ignore rest */ return s; s = seprint(s, se, " maxlen %d", maxtdlen(td)); @@ -389,8 +389,8 @@ s = seprint(s, se, " d1"); else s = seprint(s, se, " d0"); - s = seprint(s, se, " id %#ulx:", (td->token>>15) & Epmax); - s = seprint(s, se, "%#ulx", (td->token>>8) & Devmax); + s = seprint(s, se, " id %#ux:", (td->token>>15) & Epmax); + s = seprint(s, se, "%#ux", (td->token>>8) & Devmax); switch(tdtok(td)){ case Tdtokin: s = seprint(s, se, " in"); @@ -404,8 +404,8 @@ default: s = seprint(s, se, " BADPID"); } - s = seprint(s, se, "\n\t buffer %#ulx data %#p", td->buffer, td->data); - s = seprint(s, se, " ndata %uld sbuff %#p buff %#p", + s = seprint(s, se, "\n\t buffer %#ux data %#p", td->buffer, td->data); + s = seprint(s, se, " ndata %ud sbuff %#p buff %#p", td->ndata, td->sbuff, td->buff); if(td->ndata > 0) s = seprintdata(s, se, td->data, td->ndata); @@ -466,7 +466,7 @@ for(; td != nil; td = td->next){ s = seprinttd(buf, se, td); if(!sameptr(td->next, td->link)) - seprint(s, se, " next %#p != link %#ulx %#p", + seprint(s, se, " next %#p != link %#ux %#p", td->next, td->link, TPTR(td->link)); print("%std %s\n", pref, buf); if(i++ > 20){ @@ -487,19 +487,19 @@ s = buf; se = buf+sizeof(buf); - s = seprint(s, se, "%sqh %s %#p state %s link %#ulx", pref, + s = seprint(s, se, "%sqh %s %#p state %s link %#ux", pref, qh->tag, qh, qhsname[qh->state], qh->link); if(!sameptr(qh->tds, qh->elink)) - s = seprint(s, se, " [tds %#p != elink %#ulx %#p]", + s = seprint(s, se, " [tds %#p != elink %#ux %#p]", qh->tds, qh->elink, TPTR(qh->elink)); if(!sameptr(qh->next, qh->link)) - s = seprint(s, se, " [next %#p != link %#ulx %#p]", + s = seprint(s, se, " [next %#p != link %#ux %#p]", qh->next, qh->link, QPTR(qh->link)); if((qh->link & Tdterm) != 0) s = seprint(s, se, "T"); if((qh->link & Tdlinkqh) != 0) s = seprint(s, se, "Q"); - s = seprint(s, se, " elink %#ulx", qh->elink); + s = seprint(s, se, " elink %#ux", qh->elink); if((qh->elink & Tdterm) != 0) s = seprint(s, se, "T"); if((qh->elink & Tdlinkqh) != 0) @@ -548,7 +548,7 @@ print("uhci port %#x frames %#p nintr %d ntdintr %d", ctlr->port, ctlr->frames, ctlr->nintr, ctlr->ntdintr); print(" nqhintr %d nisointr %d\n", ctlr->nqhintr, ctlr->nisointr); - print("cmd %#ux sts %#ux fl %#ulx ps1 %#ux ps2 %#ux frames[0] %#ulx\n", + print("cmd %#ux sts %#ux fl %#ux ps1 %#ux ps2 %#ux frames[0] %#ux\n", INS(Cmd), INS(Status), INL(Flbaseadd), INS(PORT(0)), INS(PORT(1)), ctlr->frames[0]); @@ -1212,7 +1212,7 @@ int timedout; qh = io->qh; - ddqprint("uhci io %#p sleep on qh %#p state %uld\n", io, qh, qh->state); + ddqprint("uhci io %#p sleep on qh %#p state %ud\n", io, qh, qh->state); timedout = 0; if(waserror()){ dqprint("uhci io %#p qh %#p timed out\n", io, qh); @@ -1811,7 +1811,7 @@ cancelisoio(Ctlr *ctlr, Isoio *iso, int pollival, ulong load) { Isoio **il; - ulong *lp; + u32int *lp; int i; int frno; Td *td; @@ -2072,11 +2072,10 @@ static void scanpci(void) { - static int already = 0; - int io; - int i; + int i, io; Ctlr *ctlr; Pcidev *p; + static int already = 0; if(already) return; @@ -2086,11 +2085,11 @@ /* * Find UHCI controllers (Programming Interface = 0). */ - if(p->ccrb != Pcibcserial || p->ccru != Pciscusb) + if(p->ccrb != 0xc || p->ccru != 3) continue; switch(p->ccrp){ case 0: - io = p->mem[4].bar & ~0x0F; + io = p->mem[4].bar & ~(uintmem)0xf; break; default: continue; @@ -2151,7 +2150,7 @@ qh->link = PCIWADDR(ctlr->qhs); frsize = Nframes*sizeof(ulong); - ctlr->frames = xspanalloc(frsize, frsize, 0); + ctlr->frames = mallocalign(frsize, frsize, 0, 0); if(ctlr->frames == nil) panic("uhci reset: no memory"); @@ -2160,7 +2159,7 @@ ctlr->frames[i] = PCIWADDR(ctlr->qhs)|QHlinkqh; OUTL(Flbaseadd, PCIWADDR(ctlr->frames)); OUTS(Frnum, 0); - dprint("uhci %#ux flb %#ulx frno %#ux\n", ctlr->port, + dprint("uhci %#ux flb %#ux frno %#ux\n", ctlr->port, INL(Flbaseadd), INS(Frnum)); } @@ -2179,7 +2178,7 @@ uhcirun(ctlr, 1); dprint("uhci: init: cmd %#ux sts %#ux sof %#ux", INS(Cmd), INS(Status), INS(SOFmod)); - dprint(" flb %#ulx frno %#ux psc0 %#ux psc1 %#ux", + dprint(" flb %#ux frno %#ux psc0 %#ux psc1 %#ux", INL(Flbaseadd), INS(Frnum), INS(PORT(0)), INS(PORT(1))); /* guess other ports */ for(i = 2; i < 6; i++){ --- /sys/src/9/pc/sdodin.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/sdodin.c Sat Jan 11 20:54:05 2014 @@ -2491,7 +2491,7 @@ { uintptr io; - io = p->mem[bar].bar & ~0xf; + io = p->mem[bar].bar & ~(uintmem)0xf; return (uint*)vmap(io, p->mem[bar].size); } --- /sys/src/9/pc/sdmv50xx.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/sdmv50xx.c Sat Jan 11 20:54:05 2014 @@ -1130,7 +1130,8 @@ { int i, nunit; uchar *base; - ulong io, n, *mem; + ulong n, *mem; + uintmem io; Ctlr *ctlr; Drive *d; Pcidev *p; @@ -1173,7 +1174,7 @@ free(sdev); continue; } - io = p->mem[0].bar & ~0x0F; + io = p->mem[0].bar & ~(uintmem)0xf; mem = (ulong*)vmap(io, p->mem[0].size); if(mem == 0){ print("sdmv50xx: address 0x%luX in use\n", io); --- /sys/src/9/pc/vgai81x.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/vgai81x.c Sat Jan 11 20:54:05 2014 @@ -89,10 +89,10 @@ p = i81xpcimatch(); if(p == nil) return; - scr->mmio = vmap(p->mem[1].bar & ~0x0F, p->mem[1].size); + scr->mmio = vmap(p->mem[1].bar & ~(uintmem)0xf, p->mem[1].size); if(scr->mmio == 0) return; - addvgaseg("i81xmmio", p->mem[1].bar&~0x0F, p->mem[1].size); + addvgaseg("i81xmmio", p->mem[1].bar & ~(uintmem)0xf, p->mem[1].size); /* allocate page table (used by device, not system's MMU) */ pgtbl = xspanalloc(64*1024, BY2PG, 0); --- /sys/src/9/pc/audiohda.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/audiohda.c Sat Jan 11 20:54:05 2014 @@ -1624,7 +1624,7 @@ ctlr->no = adev->ctlrno; ctlr->size = p->mem[0].size; ctlr->q = qopen(256, 0, 0, 0); - ctlr->mem = vmap(p->mem[0].bar & ~0x0F, ctlr->size); + ctlr->mem = vmap(p->mem[0].bar & ~(uintmem)0xf, ctlr->size); if(ctlr->mem == nil){ print("#A%d: hda: can't map %.8ux\n", ctlr->no, (uint)p->mem[0].bar); return -1; --- /sys/src/9/pc/ether82563.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/ether82563.c Sat Jan 11 20:54:05 2014 @@ -1093,6 +1093,7 @@ } if(i != 0){ ctlr->rdt = rdt; + sfence(); csr32w(ctlr, Rdt, rdt); } return 0; @@ -1344,7 +1345,7 @@ if(c->phyerrata == 0){ c->phyerrata++; phywrite(c, phyno, Phyprst, Prst); /* try a port reset */ - print("%s: phy port reset\n", cname(c)); + print("ether%d: %s: phy port reset\n", e->ctlrno, cname(c)); } else c->phyerrata = 0; @@ -1748,8 +1749,9 @@ static int fload(Ctlr *c) { - uint data, io, r, adr; + uint data, r, adr; u16int sum; + uintmem io; Flash f; io = c->pcidev->mem[1].bar & ~(uintmem)0xf; --- /sys/src/9/pc/etherbcm.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/etherbcm.c Sat Jan 11 20:54:05 2014 @@ -19,7 +19,7 @@ #include "ethermii.h" #define dprint(...) do{ if(debug)print(__VA_ARGS__); }while(0) -#define Rbsz ROUNDUP(sizeof(Etherpkt)+4, 4) +#define Rbsz ROUNDUP(1514+4, 4) typedef struct Ctlr Ctlr; struct Ctlr { @@ -30,7 +30,7 @@ u32int *nic, *status; u32int *recvret, *recvprod, *sendr; - ulong port; + uintmem port; uint recvreti, recvprodi, sendri, sendcleani; Block **sends; Block **rxs; @@ -186,11 +186,11 @@ PhyAuxControl = 0x18, PhyIntStatus = 0x1A, PhyIntMask = 0x1B, - + Updated = 1<<0, LinkStateChange = 1<<1, Error = 1<<2, - + PacketEnd = 1<<2, FrameError = 1<<10, }; @@ -239,7 +239,7 @@ } static long -bcmifstat(Ether *edev, void *a, long n, ulong offset) +bcmifstat(Ether *edev, void *a, long n, usize offset) { char *s, *p, *e; Ctlr *c; @@ -391,7 +391,7 @@ uint incr; u32int *next; Block *bp; - + incr = (ctlr->recvprodi + 1) & (RxProdRingLen - 1); if(incr == (ctlr->status[2] >> 16)) return -1; @@ -421,7 +421,7 @@ u32int *pkt; Ctlr *ctlr; Block *bp; - + ctlr = edev->ctlr; for(; pkt = currentrecvret(ctlr); replenish(ctlr), consumerecvret(ctlr)) { bp = ctlr->rxs[pkt[7]]; @@ -446,7 +446,7 @@ bcmtransclean(Ether *edev) { Ctlr *ctlr; - + ctlr = edev->ctlr; ilock(&ctlr->txlock); while(ctlr->sendcleani != (ctlr->status[4] >> 16)) { @@ -464,7 +464,7 @@ u32int *next; Ctlr *ctlr; Block *bp; - + ctlr = edev->ctlr; ilock(&ctlr->txlock); for(;;){ @@ -493,7 +493,7 @@ bcmerror(Ether *edev) { Ctlr *ctlr; - + ctlr = edev->ctlr; if(csr32(ctlr, FlowAttention)) { if(csr32(ctlr, FlowAttention) & 0xf8ff8080) @@ -520,7 +520,7 @@ u32int status, tag, dummy; Ether *edev; Ctlr *ctlr; - + edev = arg; ctlr = edev->ctlr; ilock(&ctlr->imlock); @@ -581,7 +581,7 @@ uint i; u32int j; Ctlr *ctlr; - + ctlr = edev->ctlr; dprint("bcm: reset\n"); /* initialization procedure according to the datasheet */ @@ -756,7 +756,7 @@ { if(p->vid != 0x14e4) return -1; - + switch(p->did){ default: return -1; @@ -811,19 +811,19 @@ if(ctlr == nil) continue; ctlr->type = type; - ctlr->port = p->mem[0].bar & ~0x0F; + ctlr->port = p->mem[0].bar & ~(uintmem)0xf; mem = vmap(ctlr->port, p->mem[0].size); if(mem == nil) { - print("bcm: can't map %#p\n", ctlr->port); + print("bcm: can't map %#P\n", ctlr->port); free(ctlr); continue; } ctlr->pdev = p; ctlr->nic = mem; - ctlr->status = xspanalloc(20, 16, 0); - ctlr->recvprod = xspanalloc(32 * RxProdRingLen, 16, 0); - ctlr->recvret = xspanalloc(32 * RxRetRingLen, 16, 0); - ctlr->sendr = xspanalloc(16 * TxRingLen, 16, 0); + ctlr->status = mallocalign(20, 16, 0, 0); + ctlr->recvprod = mallocalign(32 * RxProdRingLen, 16, 0, 0); + ctlr->recvret = mallocalign(32 * RxRetRingLen, 16, 0, 0); + ctlr->sendr = mallocalign(16 * TxRingLen, 16, 0, 0); ctlr->sends = malloc(sizeof *ctlr->sends * TxRingLen); ctlr->rxs = malloc(sizeof *ctlr->sends * TxRingLen); *xx = ctlr; @@ -835,7 +835,7 @@ bcmpromiscuous(void* arg, int on) { Ctlr *ctlr; - + ctlr = ((Ether*)arg)->ctlr; if(on) csr32(ctlr, RxMACMode) |= 1<<8; @@ -858,14 +858,14 @@ bcmpci(); done = 1; } - + redux: for(ctlr = bcmhead; ; ctlr = ctlr->next) { if(ctlr == nil) return -1; if(ctlr->active) continue; - if(ethercfgmatch(edev, ctlr->pdev, ctlr->port) == 0) { + if(ethercfgmatch(edev, ctlr->pdev, ctlr->port) == 0){ ctlr->active = 1; break; } --- /sys/src/9/pc/etherelnk3.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/etherelnk3.c Sat Jan 11 20:54:05 2014 @@ -426,8 +426,8 @@ int ts; /* threshold shift */ int upenabled; int dnenabled; - ulong cbfnpa; /* CardBus functions */ - ulong* cbfn; + uintmem cbfnpa; /* CardBus functions */ + u32int* cbfn; } Ctlr; static Ctlr* ctlrhead; @@ -1485,13 +1485,13 @@ break; case 0x5157: ctlr->eepromcmd = EepromRead8bRegister; - ctlr->cbfnpa = p->mem[2].bar&~0x0F; - ctlr->cbfn = vmap(p->mem[2].bar&~0x0F, p->mem[2].size); + ctlr->cbfnpa = p->mem[2].bar & ~(uintmem)0xf; + ctlr->cbfn = vmap(ctlr->cbfnpa, p->mem[2].size); break; case 0x6056: ctlr->eepromcmd = EepromReadOffRegister; - ctlr->cbfnpa = p->mem[2].bar&~0x0F; - ctlr->cbfn = vmap(p->mem[2].bar&~0x0F, p->mem[2].size); + ctlr->cbfnpa = p->mem[2].bar & ~(uintmem)0xf; + ctlr->cbfn = vmap(ctlr->cbfnpa, p->mem[2].size); break; } pcisetbme(p); --- /sys/src/9/pc/etherigbe.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/etherigbe.c Sat Jan 11 20:54:05 2014 @@ -359,12 +359,12 @@ }; typedef struct Rd { /* Receive Descriptor */ - uint addr[2]; - ushort length; - ushort checksum; + u32int addr[2]; + u16int length; + u16int checksum; uchar status; uchar errors; - ushort special; + u16int special; } Rd; enum { /* Rd status */ @@ -389,7 +389,7 @@ typedef struct Td Td; struct Td { /* Transmit Descriptor */ - u32int addr[2]; /* Data */ + u32int addr[2]; /* Data */ u32int control; u32int status; }; @@ -439,7 +439,7 @@ typedef struct Ctlr Ctlr; typedef struct Ctlr { - int port; + uintmem port; Pcidev* pcidev; Ctlr* next; Ether* edev; @@ -447,14 +447,14 @@ int started; int id; int cls; - ushort eeprom[0x40]; + u16int eeprom[0x40]; QLock alock; /* attach */ void* alloc; /* receive/transmit descriptors */ int nrd; int ntd; - int* nic; + u32int* nic; Lock imlock; int im; /* interrupt mask */ @@ -501,7 +501,7 @@ int txcw; int fcrtl; int fcrth; - uint pba; // packet buffer allocation register + uint pba; /* packet buffer allocation register */ } Ctlr; #define csr32r(c, r) (*((c)->nic+((r)/4))) @@ -581,7 +581,7 @@ }; static long -igbeifstat(Ether* edev, void* a, long n, ulong offset) +igbeifstat(Ether* edev, void* a, long n, usize offset) { Ctlr *ctlr; char *p0, *p, *e, *s; @@ -630,17 +630,9 @@ p = seprint(p, e, "tintr: %ud %ud\n", ctlr->tintr, ctlr->txdw); p = seprint(p, e, "ixcs: %ud %ud %ud\n", ctlr->ixsm, ctlr->ipcs, ctlr->tcpcs); p = seprint(p, e, "rdtr: %ud\n", ctlr->rdtr); - p = seprint(p, e, "Ctrlext: %08x\n", csr32r(ctlr, Ctrlext)); + p = seprint(p, e, "ctrlext: %.8ux\n", csr32r(ctlr, Ctrlext)); p = seprint(p, e, "pba: %#ux\n", ctlr->pba); -// p = seprint(p, e, "eeprom:"); -// for(i = 0; i < 0x40; i++){ -// if(i && ((i & 0x07) == 0)) -// p = seprint(p, e, "\n "); -// p = seprint(p, e, " %4.4uX", ctlr->eeprom[i]); -// } -// p = seprint(p, e, "\n"); - if(ctlr->mii != nil && ctlr->mii->curphy != nil){ p = seprint(p, e, "phy: "); for(i = 0; i < NMiiPhyr; i++){ @@ -704,7 +696,7 @@ static void igbepromiscuous(void* arg, int on) { - int rctl; + u32int rctl; Ctlr *ctlr; Ether *edev; @@ -724,7 +716,7 @@ static void igbemulticast(void* arg, uchar* addr, int add) { - int bit, x; + u32int bit, x; Ctlr *ctlr; Ether *edev; @@ -766,7 +758,7 @@ static void igberbfree(Block* b) { - b->rp = b->wp = (uchar*)PGROUND((uintptr)b->base); + b->rp = b->wp = (uchar*)ROUNDUP((uintptr)b->base, BY2PG); b->flag &= ~(Bipck | Budpck | Btcpck | Bpktck); ilock(&igberblock); b->next = igberbpool; @@ -795,7 +787,7 @@ Ctlr *ctlr; Ether *edev; MiiPhy *phy; - int ctrl, r; + u32int ctrl, r; edev = arg; ctlr = edev->ctlr; @@ -911,8 +903,8 @@ csr32w(ctlr, Ait, 0); csr32w(ctlr, Txdmac, 0); - csr32w(ctlr, Tdbal, PCIWADDR(ctlr->tdba)); - csr32w(ctlr, Tdbah, 0); + csr32w(ctlr, Tdbal, Pciwaddrl(ctlr->tdba)); + csr32w(ctlr, Tdbah, Pciwaddrh(ctlr->tdba)); csr32w(ctlr, Tdlen, ctlr->ntd*sizeof(Td)); ctlr->tdh = PREV(0, ctlr->ntd); csr32w(ctlr, Tdh, 0); @@ -1003,7 +995,8 @@ if((b = qget(edev->oq)) == nil) break; td = &c->tdba[tdt]; - td->addr[0] = PCIWADDR(b->rp); + td->addr[0] = Pciwaddrl(b->rp); + td->addr[1] = Pciwaddrh(b->rp); td->control = Ifcs|Teop|DtypeDD|Rs|BLEN(b); c->tb[tdt] = b; c->sent++; @@ -1043,8 +1036,8 @@ break; } ctlr->rb[rdt] = bp; - rd->addr[0] = PCIWADDR(bp->rp); -// rd->addr[1] = 0; + rd->addr[0] = Pciwaddrl(bp->rp); + rd->addr[1] = Pciwaddrh(bp->rp); } rd->status = 0; rdt = Next(rdt, m); @@ -1063,8 +1056,8 @@ csr32w(ctlr, Rctl, Dpf|Rbsize|Bam|RdtmsHALF); - csr32w(ctlr, Rdbal, PCIWADDR(ctlr->rdba)); - csr32w(ctlr, Rdbah, 0); + csr32w(ctlr, Rdbal, Pciwaddrl(ctlr->rdba)); + csr32w(ctlr, Rdbah, Pciwaddrh(ctlr->rdba)); csr32w(ctlr, Rdlen, ctlr->nrd*sizeof(Rd)); ctlr->rdh = 0; csr32w(ctlr, Rdh, 0); @@ -1115,16 +1108,14 @@ Rd *rd; Block *bp; Ctlr *ctlr; - int r, rdh; + int rdh; Ether *edev; edev = arg; ctlr = edev->ctlr; igberxinit(ctlr); - r = csr32r(ctlr, Rctl); - r |= Ren; - csr32w(ctlr, Rctl, r); + csr32w(ctlr, Rctl, csr32r(ctlr, Rctl) | Ren); for(;;){ ctlr->rim = 0; @@ -1225,15 +1216,14 @@ Ctlr *ctlr; ctlr = edev->ctlr; - ctlr->edev = edev; /* point back to Ether* */ qlock(&ctlr->alock); if(ctlr->alloc != nil){ qunlock(&ctlr->alock); return; } - ctlr->nrd = ROUND(Nrd, 8); - ctlr->ntd = ROUND(Ntd, 8); + ctlr->nrd = ROUNDUP(Nrd, 8); + ctlr->ntd = ROUNDUP(Ntd, 8); ctlr->alloc = malloc(ctlr->nrd*sizeof(Rd)+ctlr->ntd*sizeof(Td) + 127); if(ctlr->alloc == nil){ print("igbe: can't allocate ctlr->alloc\n"); @@ -1289,7 +1279,7 @@ { Ctlr *ctlr; Ether *edev; - int icr, im; + u32int icr, im; edev = arg; ctlr = edev->ctlr; @@ -1326,7 +1316,8 @@ static int i82543mdior(Ctlr* ctlr, int n) { - int ctrl, data, i, r; + int i; + u32int ctrl, r, data; /* * Read n bits from the Management Data I/O Interface. @@ -1348,7 +1339,8 @@ static int i82543mdiow(Ctlr* ctlr, int bits, int n) { - int ctrl, i, r; + int i; + u32int ctrl,r; /* * Write n bits to the Management Data I/O Interface. @@ -1371,7 +1363,7 @@ static int i82543miimir(Mii* mii, int pa, int ra) { - int data; + u32int data; Ctlr *ctlr; ctlr = mii->ctlr; @@ -1419,7 +1411,7 @@ igbemiimir(Mii* mii, int pa, int ra) { Ctlr *ctlr; - int mdic, timo; + u32int mdic, timo; ctlr = mii->ctlr; @@ -1441,7 +1433,7 @@ igbemiimiw(Mii* mii, int pa, int ra, int data) { Ctlr *ctlr; - int mdic, timo; + u32int mdic, timo; ctlr = mii->ctlr; @@ -1462,8 +1454,8 @@ static int igbemii(Ctlr* ctlr) { + u32int ctrl, p, r; MiiPhy *phy; - int ctrl, p, r; r = csr32r(ctlr, Status); if(r & Tbimode) @@ -1583,7 +1575,8 @@ at93c46io(Ctlr* ctlr, char* op, int data) { char *lp, *p; - int i, loop, eecd, r; + int loop; + u32int eecd, i, r; eecd = csr32r(ctlr, Eecd); @@ -1657,9 +1650,10 @@ static int at93c46r(Ctlr* ctlr) { - ushort sum; + u16int sum; char rop[20]; - int addr, areq, bits, data, eecd, i; + int addr, areq, bits, data, i; + u32int eecd; eecd = csr32r(ctlr, Eecd); if(eecd & Spi){ @@ -1731,7 +1725,8 @@ static int igbedetach(Ctlr* ctlr) { - int r, timeo; + int timeo; + u32int r; /* rebalance rx/tx packet buffers for >8k jumbos. */ switch(ctlr->id){ @@ -1817,7 +1812,8 @@ static int igbereset(Ctlr* ctlr) { - int ctrl, i, pause, r, swdpio, txcw; + int i; + u32int ctrl, r, pause, swdpio, txcw; if(igbedetach(ctlr)) return -1; @@ -1827,7 +1823,7 @@ * then get the device back to a power-on state. */ if((r = at93c46r(ctlr)) != 0xBABA){ - print("igbe: bad EEPROM checksum - 0x%4.4uX\n", r); + print("igbe: bad EEPROM checksum - %#.4ux\n", r); return -1; } @@ -1974,9 +1970,9 @@ break; } - mem = vmap(p->mem[0].bar & ~0x0F, p->mem[0].size); + mem = vmap(p->mem[0].bar & ~(uintmem)0xf, p->mem[0].size); if(mem == nil){ - print("igbe: can't map %8.8luX\n", p->mem[0].bar); + print("igbe: can't map %#P\n", p->mem[0].bar); continue; } cls = pcicfgr8(p, PciCLS); @@ -1998,7 +1994,7 @@ vunmap(mem, p->mem[0].size); continue; } - ctlr->port = p->mem[0].bar & ~0x0F; + ctlr->port = p->mem[0].bar & ~(uintmem)0xf; ctlr->pcidev = p; ctlr->id = (p->did<<16)|p->vid; ctlr->cls = cls*4; @@ -2042,6 +2038,7 @@ if(ctlr == nil) return -1; + ctlr->edev = edev; /* point back to Ether* */ edev->ctlr = ctlr; edev->port = ctlr->port; edev->irq = ctlr->pcidev->intl; --- /sys/src/9/pc/etherm10g.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/etherm10g.c Sat Jan 11 20:54:05 2014 @@ -824,7 +824,7 @@ if(c->ramsz > p->mem[0].size) return -1; - raddr = p->mem[0].bar & ~0x0F; + raddr = p->mem[0].bar & ~(uintmem)0xf; mem = vmappat(raddr, p->mem[0].size, PATWC); if(mem == nil){ print("m10g: can't map %P\n", (uintmem)p->mem[0].bar); --- /sys/src/9/pc/etheryuk.c Sat Jan 11 20:54:05 2014 +++ /sys/src/9/pc/etheryuk.c Sat Jan 11 20:54:05 2014 @@ -675,7 +675,7 @@ uchar rev; uchar nports; uchar portno; - uintptr io; + uintmem io; uchar *reg8; ushort *reg16; uint *reg; @@ -2195,7 +2195,7 @@ Pcidev *p; p = c->p; - c->io = p->mem[0].bar&~0xf; + c->io = p->mem[0].bar & ~(uintmem)0xf; mem = vmap(c->io, p->mem[0].size); if(mem == nil){ print("yuk: cant map %#p\n", c->io);