1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579 |
- /*
- * USB Universal Host Controller Interface (UHCI) driver
- */
- #include "u.h"
- #include "../port/lib.h"
- #include "mem.h"
- #include "dat.h"
- #include "fns.h"
- #include "io.h"
- #include "../port/error.h"
- #include "usb.h"
- #define XPRINT if(debug)print
- #define XXPRINT if(0)print
- static int Chatty = 0;
- static int debug = 0;
- static char Estalled[] = "usb endpoint stalled";
- /*
- * UHCI interface registers and bits
- */
- enum
- {
- /*
- * USB packet definitions...
- */
- /* low nibbles are on-the-wire */
- Utokin = 0x69,
- Utokout = 0xE1,
- Utoksetup = 0x2D,
- /* i/o space */
- Cmd = 0,
- Status = 2,
- Usbintr = 4,
- Frnum = 6,
- Flbaseadd = 8,
- SOFMod = 0xC,
- Portsc0 = 0x10,
- Portsc1 = 0x12,
- /* port status */
- Suspend = 1<<12,
- PortReset = 1<<9,
- SlowDevice = 1<<8,
- ResumeDetect = 1<<6,
- PortChange = 1<<3, /* write 1 to clear */
- PortEnable = 1<<2,
- StatusChange = 1<<1, /* write 1 to clear */
- DevicePresent = 1<<0,
- NFRAME = 1024, /* must be 2ⁿ for xspanalloc; max 1024 */
- FRAMESIZE= NFRAME*sizeof(ulong), /* fixed by hardware; aligned to same */
- Vf = 1<<2, /* TD only */
- IsQH = 1<<1,
- Terminate = 1<<0,
- /* TD.status */
- SPD = 1<<29,
- ErrLimit0 = 0<<27,
- ErrLimit1 = 1<<27,
- ErrLimit2 = 2<<27,
- ErrLimit3 = 3<<27,
- LowSpeed = 1<<26,
- IsoSelect = 1<<25,
- IOC = 1<<24,
- Active = 1<<23,
- Stalled = 1<<22,
- DataBufferErr = 1<<21,
- Babbling = 1<<20,
- NAKed = 1<<19,
- CRCorTimeout = 1<<18,
- BitstuffErr = 1<<17,
- AnyError = (Stalled | DataBufferErr | Babbling | NAKed | CRCorTimeout |
- BitstuffErr),
- /* TD.dev */
- IsDATA1 = 1<<19,
- /* TD.flags (software) */
- CancelTD= 1<<0,
- IsoClean= 1<<2,
- };
- static struct
- {
- int bit;
- char *name;
- }
- portstatus[] =
- {
- { Suspend, "suspend", },
- { PortReset, "reset", },
- { SlowDevice, "lowspeed", },
- { ResumeDetect, "resume", },
- { PortChange, "portchange", },
- { PortEnable, "enable", },
- { StatusChange, "statuschange", },
- { DevicePresent, "present", },
- };
- typedef struct Ctlr Ctlr;
- typedef struct Endptx Endptx;
- typedef struct QH QH;
- typedef struct TD TD;
- /*
- * software structures
- */
- struct Ctlr
- {
- Lock; /* protects state shared with interrupt (eg, free list) */
- Ctlr* next;
- Pcidev* pcidev;
- int active;
- int io;
- ulong* frames; /* frame list */
- ulong* frameld; /* real time load on each frame list entry */
- QLock resetl; /* lock controller during USB reset */
- TD* tdpool;
- TD* freetd;
- QH* qhpool;
- QH* freeqh;
- QH* ctlq; /* queue for control i/o */
- QH* bwsop; /* empty bandwidth sop (to PIIX4 errata specs) */
- QH* bulkq; /* queue for bulk i/o (points back to bandwidth sop) */
- QH* recvq; /* receive queues for bulk i/o */
- Udev* ports[2];
- struct {
- Lock;
- Endpt* f;
- } activends;
- long usbints; /* debugging */
- long framenumber;
- long frameptr;
- long usbbogus;
- };
- #define IN(x) ins(ctlr->io+(x))
- #define OUT(x, v) outs(ctlr->io+(x), (v))
- static Ctlr* ctlrhead;
- static Ctlr* ctlrtail;
- struct Endptx
- {
- QH* epq; /* queue of TDs for this endpoint */
- /* ISO related: */
- void* tdalloc;
- void* bpalloc;
- uchar* bp0; /* first block in array */
- TD* td0; /* first td in array */
- TD* etd; /* pointer into circular list of TDs for isochronous ept */
- TD* xtd; /* next td to be cleaned */
- };
- /*
- * UHCI hardware structures, aligned on 16-byte boundary
- */
- struct TD
- {
- ulong link;
- ulong status; /* controller r/w */
- ulong dev;
- ulong buffer;
- /* software */
- ulong flags;
- union{
- Block* bp; /* non-iso */
- ulong offset; /* iso */
- };
- Endpt* ep;
- TD* next;
- };
- #define TFOL(p) ((TD*)KADDR((ulong)(p) & ~(0xF|PCIWINDOW)))
- struct QH
- {
- ulong head;
- ulong entries; /* address of next TD or QH to process (updated by controller) */
- /* software */
- QH* hlink;
- TD* first;
- QH* next; /* free list */
- TD* last;
- ulong _d1; /* fillers */
- ulong _d2;
- };
- #define QFOL(p) ((QH*)KADDR((ulong)(p) & ~(0xF|PCIWINDOW)))
- static TD *
- alloctd(Ctlr *ctlr)
- {
- TD *t;
- ilock(ctlr);
- t = ctlr->freetd;
- if(t == nil)
- panic("alloctd"); /* TO DO */
- ctlr->freetd = t->next;
- t->next = nil;
- iunlock(ctlr);
- t->ep = nil;
- t->bp = nil;
- t->status = 0;
- t->link = Terminate;
- t->buffer = 0;
- t->flags = 0;
- return t;
- }
- static void
- freetd(Ctlr *ctlr, TD *t)
- {
- t->ep = nil;
- if(t->bp)
- freeb(t->bp);
- t->bp = nil;
- ilock(ctlr);
- t->buffer = 0xdeadbeef;
- t->next = ctlr->freetd;
- ctlr->freetd = t;
- iunlock(ctlr);
- }
- static void
- dumpdata(Block *b, int n)
- {
- int i;
- XPRINT("\tb %#p[%d]: ", b->rp, n);
- if(n > 16)
- n = 16;
- for(i=0; i<n; i++)
- XPRINT(" %2.2ux", b->rp[i]);
- XPRINT("\n");
- }
- static void
- dumptd(TD *t, int follow)
- {
- int i, n;
- char buf[20], *s;
- TD *t0;
- t0 = t;
- while(t){
- i = t->dev & 0xFF;
- if(i == Utokout || i == Utoksetup)
- n = ((t->dev>>21) + 1) & 0x7FF;
- else if((t->status & Active) == 0)
- n = (t->status + 1) & 0x7FF;
- else
- n = 0;
- s = buf;
- if(t->status & Active)
- *s++ = 'A';
- if(t->status & Stalled)
- *s++ = 'S';
- if(t->status & DataBufferErr)
- *s++ = 'D';
- if(t->status & Babbling)
- *s++ = 'B';
- if(t->status & NAKed)
- *s++ = 'N';
- if(t->status & CRCorTimeout)
- *s++ = 'T';
- if(t->status & BitstuffErr)
- *s++ = 'b';
- if(t->status & LowSpeed)
- *s++ = 'L';
- *s = 0;
- XPRINT("td %#p: ", t);
- XPRINT("l=%#lux s=%#lux d=%#lux b=%#lux %#lux f=%#lux\n",
- t->link, t->status, t->dev, t->buffer,
- (t->bp? (ulong)t->bp->rp: 0), t->flags);
- XPRINT("\ts=%s,ep=%ld,d=%ld,D=%ld\n", buf, (t->dev>>15)&0xF,
- (t->dev>>8)&0xFF, (t->dev>>19)&1);
- if(debug && t->bp && (t->flags & CancelTD) == 0)
- dumpdata(t->bp, n);
- if(!follow || t->link & Terminate || t->link & IsQH)
- break;
- t = TFOL(t->link);
- if(t == t0)
- break; /* looped */
- }
- }
- static TD *
- alloctde(Ctlr *ctlr, Endpt *e, int pid, int n)
- {
- TD *t;
- int tog, id;
- t = alloctd(ctlr);
- id = (e->x<<7)|(e->dev->x&0x7F);
- tog = 0;
- if((pid == Utokout && e->wdata01) || (pid == Utokin && e->rdata01))
- tog = IsDATA1;
- t->ep = e;
- t->status = ErrLimit3 | Active | IOC; /* or put IOC only on last? */
- if(e->dev->speed == Lowspeed)
- t->status |= LowSpeed;
- t->dev = ((n-1)<<21) | ((id&0x7FF)<<8) | pid | tog;
- return t;
- }
- static QH *
- allocqh(Ctlr *ctlr)
- {
- QH *qh;
- ilock(ctlr);
- qh = ctlr->freeqh;
- if(qh == nil)
- panic("allocqh"); /* TO DO */
- ctlr->freeqh = qh->next;
- qh->next = nil;
- iunlock(ctlr);
- qh->head = Terminate;
- qh->entries = Terminate;
- qh->hlink = nil;
- qh->first = nil;
- qh->last = nil;
- return qh;
- }
- static void
- freeqh(Ctlr *ctlr, QH *qh)
- {
- ilock(ctlr);
- qh->next = ctlr->freeqh;
- ctlr->freeqh = qh;
- iunlock(ctlr);
- }
- static void
- dumpqh(QH *q)
- {
- int i;
- QH *q0;
- q0 = q;
- for(i = 0; q != nil && i < 10; i++){
- XPRINT("qh %#p: %#lux %#lux\n", q, q->head, q->entries);
- if((q->entries & (IsQH|Terminate)) == 0)
- dumptd(TFOL(q->entries), 1);
- if(q->head & Terminate)
- break;
- if((q->head & IsQH) == 0){
- XPRINT("head:");
- dumptd(TFOL(q->head), 1);
- break;
- }
- q = QFOL(q->head);
- if(q == q0)
- break; /* looped */
- }
- }
- static void
- queuetd(Ctlr *ctlr, QH *q, TD *t, int vf, char *why)
- {
- TD *lt;
- for(lt = t; lt->next != nil; lt = lt->next)
- lt->link = PCIWADDR(lt->next) | vf;
- lt->link = Terminate;
- ilock(ctlr);
- XPRINT("queuetd %s: t=%p lt=%p q=%p first=%p last=%p entries=%.8lux\n",
- why, t, lt, q, q->first, q->last, q->entries);
- if(q->first != nil){
- q->last->link = PCIWADDR(t) | vf;
- q->last->next = t;
- }else{
- q->first = t;
- q->entries = PCIWADDR(t);
- }
- q->last = lt;
- XPRINT(" t=%p q=%p first=%p last=%p entries=%.8lux\n",
- t, q, q->first, q->last, q->entries);
- dumpqh(q);
- iunlock(ctlr);
- }
- static void
- cleantd(Ctlr *ctlr, TD *t, int discard)
- {
- Block *b;
- int n, err;
- XPRINT("cleanTD: %#lux %#lux %#lux %#lux\n",
- t->link, t->status, t->dev, t->buffer);
- if(t->ep != nil && t->ep->debug)
- dumptd(t, 0);
- if(t->status & Active)
- panic("cleantd Active");
- err = t->status & (AnyError & ~NAKed);
- /* TO DO: on t->status&AnyError, q->entries will not have advanced */
- if (err) {
- XPRINT("cleanTD: Error %#lux %#lux %#lux %#lux\n",
- t->link, t->status, t->dev, t->buffer);
- print("cleanTD %d/%d: Error %#lux %#lux %#lux %#lux\n",
- t->ep->dev->x, t->ep->x,
- t->link, t->status, t->dev, t->buffer);
- }
- switch(t->dev&0xFF){
- case Utokin:
- if(discard || (t->flags & CancelTD) || t->ep == nil ||
- t->ep->x!=0&&err){
- if(t->ep != nil){
- if(err != 0)
- t->ep->dir[Dirin].err = err & Stalled
- ? Estalled : Eio;
- wakeup(&t->ep->dir[Dirin].rend); /* in case anyone cares */
- }
- break;
- }
- b = t->bp;
- n = (t->status + 1) & 0x7FF;
- if(n > b->lim - b->wp)
- n = 0;
- b->wp += n;
- if(Chatty)
- dumpdata(b, n);
- t->bp = nil;
- t->ep->nbytes += n;
- t->ep->nblocks++;
- qpass(t->ep->rq, b); /* TO DO: flow control */
- wakeup(&t->ep->dir[Dirin].rend); /* TO DO */
- break;
- case Utoksetup:
- XPRINT("cleanTD: Utoksetup %#p\n", &t->ep);
- /*
- * don't really need to wakeup: subsequent IN or OUT
- * gives status./
- */
- if(t->ep != nil) {
- wakeup(&t->ep->dir[Dirout].rend); /* TO DO */
- XPRINT("cleanTD: wakeup %#p\n", &t->ep->dir[Dirout].rend);
- }
- break;
- case Utokout:
- /* TO DO: mark it done somewhere */
- XPRINT("cleanTD: TokOut %#p\n", &t->ep);
- ilock(ctlr); /* e->ntd++ is ilocked */
- if(t->ep != nil){
- if(t->bp){
- n = BLEN(t->bp);
- t->ep->nbytes += n;
- t->ep->nblocks++;
- }
- if(t->ep->x && err)
- t->ep->dir[Dirout].err = err&Stalled
- ? Estalled : Eio;
- if(--t->ep->ntd < 0)
- panic("cleantd ntd");
- wakeup(&t->ep->dir[Dirout].rend); /* TO DO */
- XPRINT("cleanTD: wakeup %#p\n", &t->ep->dir[Dirout].rend);
- }
- iunlock(ctlr);
- break;
- }
- freetd(ctlr, t);
- }
- static void
- cleanq(Ctlr *ctlr, QH *q, int discard, int vf)
- {
- TD *t, *tp;
- ilock(ctlr);
- tp = nil;
- for(t = q->first; t != nil;){
- XPRINT("cleanq: %#lux %#lux %#lux %#lux %#lux %#p\n",
- t->link, t->status, t->dev, t->buffer, t->flags, t->next);
- if(t->status & Active){
- if(t->status & NAKed){
- /* ensure interrupt next frame */
- t->status = (t->status & ~NAKed) | IOC;
- tp = t;
- t = t->next;
- continue;
- }
- if(t->flags & CancelTD){
- XPRINT("cancelTD: %#p\n", t);
- /* ensure interrupt next frame */
- t->status = (t->status & ~Active) | IOC;
- tp = t;
- t = t->next;
- continue;
- }
- tp = t;
- t = t->next;
- continue;
- }
- t->status &= ~IOC;
- if (tp == nil) {
- q->first = t->next;
- if(q->first != nil)
- q->entries = PCIWADDR(q->first);
- else
- q->entries = Terminate;
- } else {
- tp->next = t->next;
- if (t->next != nil)
- tp->link = PCIWADDR(t->next) | vf;
- else
- tp->link = Terminate;
- }
- if (q->last == t)
- q->last = tp;
- iunlock(ctlr);
- cleantd(ctlr, t, discard);
- ilock(ctlr);
- if (tp)
- t = tp->next;
- else
- t = q->first;
- XPRINT("t = %#p\n", t);
- dumpqh(q);
- }
- if(q->first && q->entries != PCIWADDR(q->first)){
- ctlr->usbbogus++;
- q->entries = PCIWADDR(q->first);
- }
- iunlock(ctlr);
- }
- static void
- canceltds(Ctlr *ctlr, QH *q, Endpt *e)
- {
- TD *t;
- if(q != nil){
- ilock(ctlr);
- for(t = q->first; t != nil; t = t->next)
- if(t->ep == e)
- t->flags |= CancelTD;
- iunlock(ctlr);
- XPRINT("cancel:\n");
- dumpqh(q);
- }
- }
- static void
- eptcancel(Ctlr *ctlr, Endpt *e)
- {
- Endptx *x;
- if(e == nil)
- return;
- x = e->private;
- canceltds(ctlr, x->epq, e);
- canceltds(ctlr, ctlr->ctlq, e);
- canceltds(ctlr, ctlr->bulkq, e);
- }
- static void
- eptactivate(Ctlr *ctlr, Endpt *e)
- {
- ilock(&ctlr->activends);
- if(e->active == 0){
- XPRINT("activate 0x%p\n", e);
- e->active = 1;
- e->activef = ctlr->activends.f;
- ctlr->activends.f = e;
- }
- iunlock(&ctlr->activends);
- }
- static void
- eptdeactivate(Ctlr *ctlr, Endpt *e)
- {
- Endpt **l;
- /* could be O(1) but not worth it yet */
- ilock(&ctlr->activends);
- if(e->active){
- e->active = 0;
- XPRINT("deactivate 0x%p\n", e);
- for(l = &ctlr->activends.f; *l != e; l = &(*l)->activef)
- if(*l == nil){
- iunlock(&ctlr->activends);
- panic("usb eptdeactivate");
- }
- *l = e->activef;
- }
- iunlock(&ctlr->activends);
- }
- static void
- queueqh(Ctlr *ctlr, QH *qh)
- {
- QH *q;
- /* See if it's already queued */
- for (q = ctlr->recvq->next; q; q = q->hlink)
- if (q == qh)
- return;
- if ((qh->hlink = ctlr->recvq->next) == nil)
- qh->head = Terminate;
- else
- qh->head = PCIWADDR(ctlr->recvq->next) | IsQH;
- ctlr->recvq->next = qh;
- ctlr->recvq->entries = PCIWADDR(qh) | IsQH;
- }
- static QH*
- qxmit(Ctlr *ctlr, Endpt *e, Block *b, int pid)
- {
- TD *t;
- int n, vf;
- QH *qh;
- Endptx *x;
- x = e->private;
- if(b != nil){
- n = BLEN(b);
- t = alloctde(ctlr, e, pid, n);
- t->bp = b;
- t->buffer = PCIWADDR(b->rp);
- }else
- t = alloctde(ctlr, e, pid, 0);
- ilock(ctlr);
- e->ntd++;
- iunlock(ctlr);
- if(e->debug)
- pprint("QTD: %#p n=%ld\n", t, b? BLEN(b): 0);
- vf = 0;
- if(e->x == 0){
- qh = ctlr->ctlq;
- vf = 0;
- }else if((qh = x->epq) == nil || e->mode != OWRITE){
- qh = ctlr->bulkq;
- vf = Vf;
- }
- queuetd(ctlr, qh, t, vf, "qxmit");
- return qh;
- }
- static QH*
- qrcv(Ctlr *ctlr, Endpt *e)
- {
- TD *t;
- Block *b;
- QH *qh;
- int vf;
- Endptx *x;
- x = e->private;
- t = alloctde(ctlr, e, Utokin, e->maxpkt);
- b = allocb(e->maxpkt);
- t->bp = b;
- t->buffer = PCIWADDR(b->wp);
- vf = 0;
- if(e->x == 0){
- qh = ctlr->ctlq;
- }else if((qh = x->epq) == nil || e->mode != OREAD){
- qh = ctlr->bulkq;
- vf = Vf;
- }
- queuetd(ctlr, qh, t, vf, "qrcv");
- return qh;
- }
- static int
- usbsched(Ctlr *ctlr, int pollms, ulong load)
- {
- int i, d, q;
- ulong best, worst;
- best = 1000000;
- q = -1;
- for (d = 0; d < pollms; d++){
- worst = 0;
- for (i = d; i < NFRAME; i++)
- if (ctlr->frameld[i] + load > worst)
- worst = ctlr->frameld[i] + load;
- if (worst < best){
- best = worst;
- q = d;
- }
- }
- return q;
- }
- static int
- schedendpt(Ctlr *ctlr, Endpt *e)
- {
- TD *td;
- Endptx *x;
- uchar *bp;
- int i, id, ix, size, frnum;
- /* Only for isochronous endpoints */
- if(e->epmode != Isomode || e->sched >= 0)
- return 0;
- /* Interrupt mode should also go here */
- if (e->active)
- return -1;
- e->off = 0;
- e->sched = usbsched(ctlr, e->pollms, e->maxpkt);
- if(e->sched < 0)
- return -1;
- x = e->private;
- if (x->tdalloc || x->bpalloc)
- panic("usb: tdalloc/bpalloc");
- x->tdalloc = mallocz(0x10 + NFRAME*sizeof(TD), 1);
- x->bpalloc = mallocz(0x10 + e->maxpkt*NFRAME/e->pollms, 1);
- x->td0 = (TD*)(((ulong)x->tdalloc + 0xf) & ~0xf);
- x->bp0 = (uchar *)(((ulong)x->bpalloc + 0xf) & ~0xf);
- frnum = (IN(Frnum) + 1) & 0x3ff;
- frnum = (frnum & ~(e->pollms - 1)) + e->sched;
- x->xtd = &x->td0[(frnum+8)&0x3ff]; /* Next td to finish */
- x->etd = nil;
- e->remain = 0;
- e->nbytes = 0;
- td = x->td0;
- for(i = e->sched; i < NFRAME; i += e->pollms){
- bp = x->bp0 + e->maxpkt*i/e->pollms;
- td->buffer = PCIWADDR(bp);
- td->ep = e;
- td->next = &td[1];
- ctlr->frameld[i] += e->maxpkt;
- td++;
- }
- td[-1].next = x->td0;
- for(i = e->sched; i < NFRAME; i += e->pollms){
- ix = (frnum+i) & 0x3ff;
- td = &x->td0[ix];
- id = (e->x<<7)|(e->dev->x&0x7F);
- if (e->mode == OREAD)
- /* enable receive on this entry */
- td->dev = (e->maxpkt-1)<<21 | (id&0x7FF)<<8 | Utokin;
- else{
- size = (e->hz + e->remain)*e->pollms/1000;
- e->remain = (e->hz + e->remain)*e->pollms%1000;
- size *= e->samplesz;
- td->dev = (size-1)<<21 | (id&0x7FF)<<8 | Utokout;
- }
- td->status = ErrLimit1 | Active | IsoSelect | IOC;
- td->link = ctlr->frames[ix];
- td->flags |= IsoClean;
- ctlr->frames[ix] = PCIWADDR(td);
- }
- return 0;
- }
- static void
- unschedendpt(Ctlr *ctlr, Endpt *e)
- {
- int q;
- TD *td;
- Endptx *x;
- ulong *addr;
- if(e->epmode != Isomode || e->sched < 0)
- return;
- x = e->private;
- if (x->tdalloc == nil)
- panic("tdalloc");
- for (q = e->sched; q < NFRAME; q += e->pollms){
- td = x->td0++;
- addr = &ctlr->frames[q];
- while(*addr != PADDR(td)) {
- if(*addr & IsQH)
- panic("usb: TD expected");
- addr = &TFOL(*addr)->link;
- }
- *addr = td->link;
- ctlr->frameld[q] -= e->maxpkt;
- }
- free(x->tdalloc);
- free(x->bpalloc);
- x->tdalloc = nil;
- x->bpalloc = nil;
- x->etd = nil;
- x->td0 = nil;
- e->sched = -1;
- }
- static void
- epalloc(Usbhost *uh, Endpt *e)
- {
- Endptx *x;
- x = malloc(sizeof(Endptx));
- e->private = x;
- x->epq = allocqh(uh->ctlr);
- if(x->epq == nil)
- panic("devendptx");
- }
- static void
- epfree(Usbhost *uh, Endpt *e)
- {
- Ctlr *ctlr;
- Endptx *x;
- ctlr = uh->ctlr;
- x = e->private;
- if(x->epq != nil)
- freeqh(ctlr, x->epq);
- }
- static void
- epopen(Usbhost *uh, Endpt *e)
- {
- Ctlr *ctlr;
- ctlr = uh->ctlr;
- if(e->epmode == Isomode && e->active)
- error("already open");
- if(schedendpt(ctlr, e) < 0){
- if(e->active)
- error("cannot schedule USB endpoint, active");
- else
- error("cannot schedule USB endpoint");
- }
- eptactivate(ctlr, e);
- }
- static void
- epclose(Usbhost *uh, Endpt *e)
- {
- Ctlr *ctlr;
- ctlr = uh->ctlr;
- eptdeactivate(ctlr, e);
- unschedendpt(ctlr, e);
- }
- static void
- epmode(Usbhost *uh, Endpt *e)
- {
- Ctlr *ctlr;
- Endptx *x;
- if(e->epnewmode == e->epmode)
- return;
- ctlr = uh->ctlr;
- x = e->private;
- if(e->epnewmode == Isomode){
- if(x->epq != nil){
- freeqh(ctlr, x->epq);
- x->epq = nil;
- }
- }else{
- /* Each bulk device gets a queue head hanging off the
- * bulk queue head
- */
- if(x->epq == nil){
- x->epq = allocqh(ctlr);
- if(x->epq == nil)
- panic("epbulk: allocqh");
- }
- queueqh(ctlr, x->epq);
- }
- e->epmode = e->epnewmode;
- }
- static int ioport[] = {-1, Portsc0, Portsc1};
- static void
- portreset(Usbhost *uh, int port)
- {
- int i, p;
- Ctlr *ctlr;
- ctlr = uh->ctlr;
- if(port != 1 && port != 2)
- error(Ebadarg);
- /* should check that device not being configured on other port? */
- p = ioport[port];
- qlock(&ctlr->resetl);
- if(waserror()){
- qunlock(&ctlr->resetl);
- nexterror();
- }
- XPRINT("r: %x\n", IN(p));
- ilock(ctlr);
- OUT(p, PortReset);
- delay(12); /* BUG */
- XPRINT("r2: %x\n", IN(p));
- OUT(p, IN(p) & ~PortReset);
- XPRINT("r3: %x\n", IN(p));
- OUT(p, IN(p) | PortEnable);
- microdelay(64);
- for(i=0; i<1000 && (IN(p) & PortEnable) == 0; i++)
- ;
- XPRINT("r': %x %d\n", IN(p), i);
- OUT(p, (IN(p) & ~PortReset)|PortEnable);
- iunlock(ctlr);
- poperror();
- qunlock(&ctlr->resetl);
- }
- static void
- portenable(Usbhost *uh, int port, int on)
- {
- int w, p;
- Ctlr *ctlr;
- ctlr = uh->ctlr;
- if(port != 1 && port != 2)
- error(Ebadarg);
- /* should check that device not being configured on other port? */
- p = ioport[port];
- qlock(&ctlr->resetl);
- if(waserror()){
- qunlock(&ctlr->resetl);
- nexterror();
- }
- ilock(ctlr);
- w = IN(p);
- if(on)
- w |= PortEnable;
- else
- w &= ~PortEnable;
- OUT(p, w);
- microdelay(64);
- iunlock(ctlr);
- XPRINT("e: %x\n", IN(p));
- poperror();
- qunlock(&ctlr->resetl);
- }
- static void
- portinfo(Usbhost *uh, char *s, char *se)
- {
- int x, i, j;
- Ctlr *ctlr;
- ctlr = uh->ctlr;
- for(i = 1; i <= 2; i++) {
- ilock(ctlr);
- x = IN(ioport[i]);
- if((x & (PortChange|StatusChange)) != 0)
- /* TODO: could notify usbd equivalent here */
- OUT(ioport[i], x);
- iunlock(ctlr);
- s = seprint(s, se, "%d %ux", i, x);
- for(j = 0; j < nelem(portstatus); j++) {
- if((x & portstatus[j].bit) != 0)
- s = seprint(s, se, " %s", portstatus[j].name);
- }
- s = seprint(s, se, "\n");
- }
- }
- static void
- cleaniso(Endpt *e, int frnum)
- {
- TD *td;
- int id, n, i;
- Endptx *x;
- uchar *bp;
- x = e->private;
- td = x->xtd;
- if (td->status & Active)
- return;
- id = e->x<<7 | (e->dev->x&0x7F);
- do {
- if (td->status & AnyError)
- XPRINT("usbisoerror 0x%lux\n", td->status);
- n = (td->status + 1) & 0x3ff;
- e->nbytes += n;
- if ((td->flags & IsoClean) == 0)
- e->nblocks++;
- if (e->mode == OREAD){
- e->buffered += n;
- e->poffset += (td->status + 1) & 0x3ff;
- td->offset = e->poffset;
- td->dev = (e->maxpkt-1)<<21 | (id&0x7FF)<<8 | Utokin;
- e->toffset = td->offset;
- }else{
- if ((td->flags & IsoClean) == 0){
- e->buffered -= n;
- if (e->buffered < 0){
- // print("e->buffered %d?\n", e->buffered);
- e->buffered = 0;
- }
- }
- e->toffset = td->offset;
- n = (e->hz + e->remain)*e->pollms/1000;
- e->remain = (e->hz + e->remain)*e->pollms%1000;
- n *= e->samplesz;
- td->dev = (n-1)<<21 | (id&0x7FF)<<8 | Utokout;
- td->offset = e->poffset;
- e->poffset += n;
- }
- td = td->next;
- if (x->xtd == td){
- XPRINT("@");
- break;
- }
- } while ((td->status & Active) == 0);
- e->time = todget(nil);
- x->xtd = td;
- for (n = 2; n < 4; n++){
- i = (frnum + n) & 0x3ff;
- td = x->td0 + i;
- bp = x->bp0 + e->maxpkt*i/e->pollms;
- if (td->status & Active)
- continue;
- if (e->mode == OWRITE){
- if (td == x->etd) {
- XPRINT("*");
- memset(bp+e->off, 0, e->maxpkt-e->off);
- if (e->off == 0)
- td->flags |= IsoClean;
- else
- e->buffered += (((td->dev>>21) +1) &
- 0x3ff) - e->off;
- x->etd = nil;
- }else if ((td->flags & IsoClean) == 0){
- XPRINT("-");
- memset(bp, 0, e->maxpkt);
- td->flags |= IsoClean;
- }
- } else
- /* Unread bytes are now lost */
- e->buffered -= (td->status + 1) & 0x3ff;
- td->status = ErrLimit1 | Active | IsoSelect | IOC;
- }
- wakeup(&e->dir[Dirout].rend);
- }
- static void
- interrupt(Ureg*, void *a)
- {
- QH *q;
- Ctlr *ctlr;
- Endpt *e;
- Endptx *x;
- int s, frnum;
- Usbhost *uh;
- uh = a;
- ctlr = uh->ctlr;
- s = IN(Status);
- ctlr->frameptr = inl(ctlr->io+Flbaseadd);
- ctlr->framenumber = IN(Frnum) & 0x3ff;
- OUT(Status, s);
- if ((s & 0x1f) == 0)
- return;
- ctlr->usbints++;
- frnum = IN(Frnum) & 0x3ff;
- if (s & 0x1a) {
- XPRINT("cmd #%x sofmod #%x\n", IN(Cmd), inb(ctlr->io+SOFMod));
- XPRINT("sc0 #%x sc1 #%x\n", IN(Portsc0), IN(Portsc1));
- }
- ilock(&ctlr->activends);
- for(e = ctlr->activends.f; e != nil; e = e->activef){
- x = e->private;
- if(e->epmode == Isomode){
- XXPRINT("cleaniso(e)\n");
- cleaniso(e, frnum);
- }else if(x->epq != nil){
- XXPRINT("cleanq(ctlr, x->epq, 0, 0)\n");
- cleanq(ctlr, x->epq, 0, 0);
- }
- }
- iunlock(&ctlr->activends);
- XXPRINT("cleanq(ctlr, ctlr->ctlq, 0, 0)\n");
- cleanq(ctlr, ctlr->ctlq, 0, 0);
- XXPRINT("cleanq(ctlr, ctlr->bulkq, 0, Vf)\n");
- cleanq(ctlr, ctlr->bulkq, 0, Vf);
- XXPRINT("clean recvq\n");
- for (q = ctlr->recvq->next; q; q = q->hlink) {
- XXPRINT("cleanq(ctlr, q, 0, Vf)\n");
- cleanq(ctlr, q, 0, Vf);
- }
- }
- static int
- eptinput(void *arg)
- {
- Endpt *e;
- e = arg;
- return e->eof || e->dir[Dirin].err || qcanread(e->rq);
- }
- static int
- isoready(void *a)
- {
- Endptx *x;
- TD *etd;
- x = a;
- return (etd = x->etd) == nil ||
- (etd != x->xtd && (etd->status & Active) == 0);
- }
- static long
- isoio(Ctlr *ctlr, Endpt *e, void *a, long n, ulong offset, int w)
- {
- TD *td;
- Endptx *x;
- int i, frnum;
- uchar *p, *q, *bp;
- volatile int isolock;
- x = e->private;
- qlock(&e->rlock);
- isolock = 0;
- if(waserror()){
- if (isolock){
- isolock = 0;
- iunlock(&ctlr->activends);
- }
- qunlock(&e->rlock);
- eptcancel(ctlr, e);
- nexterror();
- }
- p = a;
- if (offset != 0 && offset != e->foffset){
- iprint("offset %lud, foffset %llud\n", offset, e->foffset);
- /* Seek to a specific position */
- frnum = (IN(Frnum) + 8) & 0x3ff;
- td = x->td0 + frnum;
- if (offset < td->offset)
- error("ancient history");
- while (offset > e->toffset)
- tsleep(&e->dir[Dirout].rend, return0, 0, 500);
- /* TODO: how should this be parenthesised? */
- while (offset >= td->offset +
- (((w? (td->dev>>21): td->status) + 1) & 0x7ff)){
- td = td->next;
- if (td == x->xtd)
- iprint("trouble\n");
- }
- ilock(&ctlr->activends);
- isolock = 1;
- e->off = td->offset - offset;
- if (e->off >= e->maxpkt){
- iprint("I can't program: %d\n", e->off);
- e->off = 0;
- }
- x->etd = td;
- e->foffset = offset;
- }
- do {
- if (isolock == 0){
- ilock(&ctlr->activends);
- isolock = 1;
- }
- td = x->etd;
- if (td == nil || e->off == 0){
- if (td == nil){
- XPRINT("0");
- if (w){
- frnum = (IN(Frnum) + 1) & 0x3ff;
- td = x->td0 + frnum;
- while(td->status & Active)
- td = td->next;
- }else{
- frnum = (IN(Frnum) - 4) & 0x3ff;
- td = x->td0 + frnum;
- while(td->next != x->xtd)
- td = td->next;
- }
- x->etd = td;
- e->off = 0;
- }else{
- /* New td, make sure it's ready */
- while (isoready(x) == 0){
- isolock = 0;
- iunlock(&ctlr->activends);
- sleep(&e->dir[Dirout].rend, isoready, x);
- ilock(&ctlr->activends);
- isolock = 1;
- }
- if (x->etd == nil){
- XPRINT("!");
- continue;
- }
- }
- if (w)
- e->psize = ((td->dev >> 21) + 1) & 0x7ff;
- else
- e->psize = (x->etd->status + 1) & 0x7ff;
- if(e->psize > e->maxpkt)
- panic("packet size > maximum");
- }
- if((i = n) >= e->psize)
- i = e->psize;
- if (w)
- e->buffered += i;
- else{
- e->buffered -= i;
- if (e->buffered < 0)
- e->buffered = 0;
- }
- isolock = 0;
- iunlock(&ctlr->activends);
- td->flags &= ~IsoClean;
- bp = x->bp0 + (td - x->td0) * e->maxpkt / e->pollms;
- q = bp + e->off;
- if (w)
- memmove(q, p, i);
- else
- memmove(p, q, i);
- p += i;
- n -= i;
- e->off += i;
- e->psize -= i;
- if (e->psize){
- if (n != 0)
- panic("usb iso: can't happen");
- break;
- }
- if(w)
- td->offset = offset + (p-(uchar*)a) -
- (((td->dev >> 21) + 1) & 0x7ff);
- td->status = ErrLimit3 | Active | IsoSelect | IOC;
- x->etd = td->next;
- e->off = 0;
- } while(n > 0);
- n = p-(uchar*)a;
- e->foffset += n;
- poperror();
- if (isolock)
- iunlock(&ctlr->activends);
- qunlock(&e->rlock);
- return n;
- }
- static long
- read(Usbhost *uh, Endpt *e, void *a, long n, vlong offset)
- {
- long l, i;
- Block *b;
- Ctlr *ctlr;
- uchar *p;
- ctlr = uh->ctlr;
- if(e->epmode == Isomode)
- return isoio(ctlr, e, a, n, (ulong)offset, 0);
- XPRINT("qlock(%p)\n", &e->rlock);
- qlock(&e->rlock);
- XPRINT("got qlock(%p)\n", &e->rlock);
- if(waserror()){
- e->dir[Dirin].err = nil;
- qunlock(&e->rlock);
- eptcancel(ctlr, e);
- nexterror();
- }
- p = a;
- do {
- if(e->eof) {
- XPRINT("e->eof\n");
- break;
- }
- if(e->dir[Dirin].err)
- error(e->dir[Dirin].err);
- qrcv(ctlr, e);
- e->rdata01 ^= 1;
- sleep(&e->dir[Dirin].rend, eptinput, e);
- if(e->dir[Dirin].err)
- error(e->dir[Dirin].err);
- b = qget(e->rq); /* TO DO */
- if(b == nil) {
- XPRINT("b == nil\n");
- break;
- }
- if(waserror()){
- freeb(b);
- nexterror();
- }
- l = BLEN(b);
- if((i = l) > n)
- i = n;
- if(i > 0){
- memmove(p, b->rp, i);
- p += i;
- }
- poperror();
- freeb(b);
- n -= i;
- if (l != e->maxpkt)
- break;
- } while (n > 0);
- poperror();
- qunlock(&e->rlock);
- return p - (uchar*)a;
- }
- static int
- qisempty(void *arg)
- {
- return ((QH*)arg)->entries & Terminate;
- }
- static long
- write(Usbhost *uh, Endpt *e, void *a, long n, vlong offset, int tok)
- {
- int i, j;
- QH *qh;
- Block *b;
- Ctlr *ctlr;
- uchar *p;
- ctlr = uh->ctlr;
- if(e->epmode == Isomode)
- return isoio(ctlr, e, a, n, (ulong)offset, 1);
- p = a;
- qlock(&e->wlock);
- if(waserror()){
- e->dir[Dirout].err = nil;
- qunlock(&e->wlock);
- eptcancel(ctlr, e);
- nexterror();
- }
- do {
- if(e->dir[Dirout].err)
- error(e->dir[Dirout].err);
- if((i = n) >= e->maxpkt)
- i = e->maxpkt;
- b = allocb(i);
- if(waserror()){
- freeb(b);
- nexterror();
- }
- XPRINT("out [%d]", i);
- for (j = 0; j < i; j++)
- XPRINT(" %.2x", p[j]);
- XPRINT("\n");
- memmove(b->wp, p, i);
- b->wp += i;
- p += i;
- n -= i;
- poperror();
- qh = qxmit(ctlr, e, b, tok);
- tok = Utokout;
- e->wdata01 ^= 1;
- if(e->ntd >= e->nbuf) {
- XPRINT("qh %s: q=%p first=%p last=%p entries=%.8lux\n",
- "writeusb sleep", qh, qh->first, qh->last,
- qh->entries);
- XPRINT("write: sleep %#p\n", &e->dir[Dirout].rend);
- sleep(&e->dir[Dirout].rend, qisempty, qh);
- XPRINT("write: awake\n");
- }
- } while(n > 0);
- poperror();
- qunlock(&e->wlock);
- return p - (uchar*)a;
- }
- static void
- init(Usbhost* uh)
- {
- Ctlr *ctlr;
- ctlr = uh->ctlr;
- ilock(ctlr);
- outl(ctlr->io+Flbaseadd, PCIWADDR(ctlr->frames));
- OUT(Frnum, 0);
- OUT(Usbintr, 0xF); /* enable all interrupts */
- XPRINT("cmd %#x sofmod %#x\n", IN(Cmd), inb(ctlr->io+SOFMod));
- XPRINT("sc0 %#x sc1 %#x\n", IN(Portsc0), IN(Portsc1));
- if((IN(Cmd)&1)==0)
- OUT(Cmd, 1); /* run */
- // pprint("at: c=%#x s=%#x c0=%x\n", IN(Cmd), IN(Status), IN(Portsc0));
- iunlock(ctlr);
- }
- static void
- scanpci(void)
- {
- int io;
- Ctlr *ctlr;
- Pcidev *p;
- static int already = 0;
- if(already)
- return;
- already = 1;
- p = nil;
- while(p = pcimatch(p, 0, 0)) {
- /*
- * Find UHCI controllers (Programming Interface = 0).
- */
- if(p->ccrb != Pcibcserial || p->ccru != Pciscusb)
- continue;
- switch(p->ccrp){
- case 0:
- io = p->mem[4].bar & ~0x0F;
- break;
- default:
- continue;
- }
- if(io == 0) {
- print("usbuhci: %x/%x failed to map registers\n",
- p->vid, p->did);
- continue;
- }
- if(ioalloc(io, p->mem[4].size, 0, "usbuhci") < 0){
- print("usbuhci: port %#ux in use\n", io);
- continue;
- }
- if(p->intl == 0xFF || p->intl == 0) {
- print("usbuhci: no irq assigned for port %#ux\n", io);
- continue;
- }
- XPRINT("usbuhci: %x/%x port 0x%ux size 0x%x irq %d\n",
- p->vid, p->did, io, p->mem[4].size, p->intl);
- ctlr = malloc(sizeof(Ctlr));
- ctlr->pcidev = p;
- ctlr->io = io;
- if(ctlrhead != nil)
- ctlrtail->next = ctlr;
- else
- ctlrhead = ctlr;
- ctlrtail = ctlr;
- }
- }
- static int
- reset(Usbhost *uh)
- {
- int i;
- TD *t;
- ulong io;
- Ctlr *ctlr;
- Pcidev *p;
- scanpci();
- /*
- * Any adapter matches if no uh->port is supplied,
- * otherwise the ports must match.
- */
- for(ctlr = ctlrhead; ctlr != nil; ctlr = ctlr->next){
- if(ctlr->active)
- continue;
- if(uh->port == 0 || uh->port == ctlr->io){
- ctlr->active = 1;
- break;
- }
- }
- if(ctlr == nil)
- return -1;
- io = ctlr->io;
- p = ctlr->pcidev;
- uh->ctlr = ctlr;
- uh->port = io;
- uh->irq = p->intl;
- uh->tbdf = p->tbdf;
- XPRINT("usbcmd\t0x%.4x\nusbsts\t0x%.4x\nusbintr\t0x%.4x\nfrnum\t0x%.2x\n",
- IN(Cmd), IN(Status), IN(Usbintr), inb(io+Frnum));
- XPRINT("frbaseadd\t0x%.4x\nsofmod\t0x%x\nportsc1\t0x%.4x\nportsc2\t0x%.4x\n",
- IN(Flbaseadd), inb(io+SOFMod), IN(Portsc0), IN(Portsc1));
- OUT(Cmd, 0); /* stop */
- while((IN(Status) & (1<<5)) == 0) /* wait for halt */
- ;
- OUT(Status, 0xFF); /* clear pending interrupts */
- /* legacy support register: turn off lunacy mode */
- pcicfgw16(p, 0xc0, 0x2000);
- if(0){
- i = inb(io+SOFMod);
- OUT(Cmd, 4); /* global reset */
- delay(15);
- OUT(Cmd, 0); /* end reset */
- delay(4);
- outb(io+SOFMod, i);
- }
- ctlr->tdpool = xspanalloc(128*sizeof(TD), 16, 0);
- for(i=128; --i>=0;){
- ctlr->tdpool[i].next = ctlr->freetd;
- ctlr->freetd = &ctlr->tdpool[i];
- }
- ctlr->qhpool = xspanalloc(64*sizeof(QH), 16, 0);
- for(i=64; --i>=0;){
- ctlr->qhpool[i].next = ctlr->freeqh;
- ctlr->freeqh = &ctlr->qhpool[i];
- }
- /*
- * the last entries of the periodic (interrupt & isochronous)
- * scheduling TD entries points to the control queue and the
- * bandwidth sop for bulk traffic. this is looped following the
- * instructions in PIIX4 errata 29773804.pdf: a QH links to a
- * looped but inactive TD as its sole entry, with its head entry
- * leading on to the bulk traffic, the last QH of which links
- * back to the empty QH.
- */
- ctlr->ctlq = allocqh(ctlr);
- ctlr->bwsop = allocqh(ctlr);
- ctlr->bulkq = allocqh(ctlr);
- ctlr->recvq = allocqh(ctlr);
- t = alloctd(ctlr); /* inactive TD, looped */
- t->link = PCIWADDR(t);
- ctlr->bwsop->entries = PCIWADDR(t);
- ctlr->ctlq->head = PCIWADDR(ctlr->bulkq) | IsQH;
- ctlr->bulkq->head = PCIWADDR(ctlr->recvq) | IsQH;
- ctlr->recvq->head = PCIWADDR(ctlr->bwsop) | IsQH;
- if (1) /* don't use loop back */
- ctlr->bwsop->head = Terminate;
- else /* set up loop back */
- ctlr->bwsop->head = PCIWADDR(ctlr->bwsop) | IsQH;
- ctlr->frames = xspanalloc(FRAMESIZE, FRAMESIZE, 0);
- ctlr->frameld = xallocz(FRAMESIZE, 1);
- if (ctlr->frames == nil || ctlr->frameld == nil)
- panic("uhci reset: no memory");
- for (i = 0; i < NFRAME; i++)
- ctlr->frames[i] = PCIWADDR(ctlr->ctlq) | IsQH;
- /*
- * Linkage to the generic USB driver.
- */
- uh->init = init;
- uh->interrupt = interrupt;
- uh->portinfo = portinfo;
- uh->portreset = portreset;
- uh->portenable = portenable;
- uh->epalloc = epalloc;
- uh->epfree = epfree;
- uh->epopen = epopen;
- uh->epclose = epclose;
- uh->epmode = epmode;
- uh->read = read;
- uh->write = write;
- uh->tokin = Utokin;
- uh->tokout = Utokout;
- uh->toksetup = Utoksetup;
- return 0;
- }
- void
- usbuhcilink(void)
- {
- addusbtype("uhci", reset);
- }
|