usbohci: ensure Ed and Td alignment, fix for amd64

This commit is contained in:
cinap_lenrek 2015-03-22 17:41:35 +01:00
parent c86561f625
commit 8e61a0036d
2 changed files with 22 additions and 20 deletions

View file

@ -37,8 +37,8 @@ enum
{ {
Incr = 64, /* for Td and Ed pools */ Incr = 64, /* for Td and Ed pools */
Align = 0x20, /* OHCI only requires 0x10 */ Edalign = 0x10,
/* use always a power of 2 */ Tdalign = 0x20,
Abortdelay = 1, /* delay after cancelling Tds (ms) */ Abortdelay = 1, /* delay after cancelling Tds (ms) */
Tdatomic = 8, /* max nb. of Tds per bulk I/O op. */ Tdatomic = 8, /* max nb. of Tds per bulk I/O op. */
@ -581,19 +581,20 @@ tdtok(Td *td)
static Td* static Td*
tdalloc(void) tdalloc(void)
{ {
uchar *pool;
Td *td; Td *td;
Td *pool;
int i; int i;
lock(&tdpool); lock(&tdpool);
if(tdpool.free == nil){ if(tdpool.free == nil){
ddprint("ohci: tdalloc %d Tds\n", Incr); ddprint("ohci: tdalloc %d Tds\n", Incr);
pool = xspanalloc(Incr*sizeof(Td), Align, 0); pool = xspanalloc(Incr*ROUND(sizeof(Td), Tdalign), Tdalign, 0);
if(pool == nil) if(pool == nil)
panic("ohci: tdalloc"); panic("ohci: tdalloc");
for(i=Incr; --i>=0;){ for(i=Incr; --i>=0;){
pool[i].next = tdpool.free; td = (Td*)(pool + i*ROUND(sizeof(Td), Tdalign));
tdpool.free = &pool[i]; td->next = tdpool.free;
tdpool.free = td;
} }
tdpool.nalloc += Incr; tdpool.nalloc += Incr;
tdpool.nfree += Incr; tdpool.nfree += Incr;
@ -602,10 +603,9 @@ tdalloc(void)
tdpool.nfree--; tdpool.nfree--;
td = tdpool.free; td = tdpool.free;
tdpool.free = td->next; tdpool.free = td->next;
memset(td, 0, sizeof(Td));
unlock(&tdpool); unlock(&tdpool);
assert(((uintptr)td & 0x1F) == 0);
assert(((uintptr)td & 0xF) == 0); memset(td, 0, sizeof(Td));
return td; return td;
} }
@ -630,18 +630,20 @@ tdfree(Td *td)
static Ed* static Ed*
edalloc(void) edalloc(void)
{ {
Ed *ed, *pool; uchar *pool;
Ed *ed;
int i; int i;
lock(&edpool); lock(&edpool);
if(edpool.free == nil){ if(edpool.free == nil){
ddprint("ohci: edalloc %d Eds\n", Incr); ddprint("ohci: edalloc %d Eds\n", Incr);
pool = xspanalloc(Incr*sizeof(Ed), Align, 0); pool = xspanalloc(Incr*ROUND(sizeof(Ed), Edalign), Edalign, 0);
if(pool == nil) if(pool == nil)
panic("ohci: edalloc"); panic("ohci: edalloc");
for(i=Incr; --i>=0;){ for(i=Incr; --i>=0;){
pool[i].next = edpool.free; ed = (Ed*)(pool + i*ROUND(sizeof(Ed), Edalign));
edpool.free = &pool[i]; ed->next = edpool.free;
edpool.free = ed;
} }
edpool.nalloc += Incr; edpool.nalloc += Incr;
edpool.nfree += Incr; edpool.nfree += Incr;
@ -650,9 +652,9 @@ edalloc(void)
edpool.nfree--; edpool.nfree--;
ed = edpool.free; ed = edpool.free;
edpool.free = ed->next; edpool.free = ed->next;
memset(ed, 0, sizeof(Ed));
unlock(&edpool); unlock(&edpool);
assert(((uintptr)ed & 0xF) == 0);
memset(ed, 0, sizeof(Ed));
return ed; return ed;
} }
@ -821,7 +823,7 @@ seprinttd(char *s, char *e, Td *td, int iso)
if(td == nil) if(td == nil)
return seprint(s, e, "<nil td>\n"); return seprint(s, e, "<nil td>\n");
s = seprint(s, e, "%#p ep %#p ctrl %#p", td, td->ep, td->ctrl); s = seprint(s, e, "%#p ep %#p ctrl %#lux", td, td->ep, td->ctrl);
s = seprint(s, e, " cc=%#ulx", (td->ctrl >> Tdccshift) & Tdccmask); s = seprint(s, e, " cc=%#ulx", (td->ctrl >> Tdccshift) & Tdccmask);
if(iso == 0){ if(iso == 0){
if((td->ctrl & Tdround) != 0) if((td->ctrl & Tdround) != 0)
@ -836,7 +838,7 @@ seprinttd(char *s, char *e, Td *td, int iso)
s = seprint(s, e, " fc=%uld", (td->ctrl >> Tdfcshift) & Tdfcmask); s = seprint(s, e, " fc=%uld", (td->ctrl >> Tdfcshift) & Tdfcmask);
s = seprint(s, e, " sf=%uld", td->ctrl & Tdsfmask); s = seprint(s, e, " sf=%uld", td->ctrl & Tdsfmask);
} }
s = seprint(s, e, " cbp0 %#p cbp %#p next %#p be %#p %s", s = seprint(s, e, " cbp0 %#lux cbp %#lux next %#lux be %#lux %s",
td->cbp0, td->cbp, td->nexttd, td->be, td->last ? "last" : ""); td->cbp0, td->cbp, td->nexttd, td->be, td->last ? "last" : "");
s = seprint(s, e, "\n\t\t%ld bytes", td->nbytes); s = seprint(s, e, "\n\t\t%ld bytes", td->nbytes);
if((bp = td->bp) != nil){ if((bp = td->bp) != nil){
@ -898,7 +900,7 @@ dumped(Ed *ed)
if(buf == nil) if(buf == nil)
return; return;
e = buf+512; e = buf+512;
s = seprint(buf, e, "\ted %#p: ctrl %#p", ed, ed->ctrl); s = seprint(buf, e, "\ted %#p: ctrl %#lux", ed, ed->ctrl);
if((ed->ctrl & Edskip) != 0) if((ed->ctrl & Edskip) != 0)
s = seprint(s, e, " skip"); s = seprint(s, e, " skip");
if((ed->ctrl & Ediso) != 0) if((ed->ctrl & Ediso) != 0)
@ -914,7 +916,7 @@ dumped(Ed *ed)
s = seprint(s, e, " hlt"); s = seprint(s, e, " hlt");
s = seprint(s, e, " ep%uld.%uld", (ed->ctrl>>7)&Epmax, ed->ctrl&0x7f); s = seprint(s, e, " ep%uld.%uld", (ed->ctrl>>7)&Epmax, ed->ctrl&0x7f);
s = seprint(s, e, " maxpkt %uld", (ed->ctrl>>Edmpsshift)&Edmpsmask); 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); seprint(s, e, " tail %#lux head %#lux next %#lux\n",ed->tail,ed->head,ed->nexted);
print("%s", buf); print("%s", buf);
free(buf); free(buf);
if(ed->tds != nil && (ed->ctrl & Ediso) == 0) if(ed->tds != nil && (ed->ctrl & Ediso) == 0)

View file

@ -75,7 +75,7 @@ link
netdevmedium netdevmedium
loopbackmedium loopbackmedium
usbuhci usbuhci
# usbohci usbohci
usbehci usbehcipc usbehci usbehcipc
# audiosb16 dma # audiosb16 dma