Page 1 of 1

Help me about USB EHCI !!!

Posted: Sat Apr 09, 2011 9:36 pm
by ppppllll1234
void readdesc(EHCI_DEV *ehci)
{
uint32_t cmd;
DWORD *setup_td,*td0,*td1,*td2,*status_td,*qh;
USB_SETUP_REQUEST usr;

qh=ehci->queue;
setup_td=qh+14;
td0=setup_td+8;
td1=td0+8;
td2=td1+8;
status_td=td2+8;

usr.bmRequestType=0x80;
usr.bRequest=GET_DESCRIPTOR;
usr.wValue=0x100;
usr.wIndex=0;
usr.wLength=18;

memcpy(ehci->buf,&usr,18);

setup_td[0]=GetPhysicalAddress( (DWORD)td0 );
setup_td[1]=GetPhysicalAddress( (DWORD)td0 );
setup_td[2]=(18<<16) | (1<<15) | (3<<10) | (2<<8) | 0x80;
setup_td[3]=GetPhysicalAddress( (DWORD)ehci->buf );

td0[0]=GetPhysicalAddress( (DWORD)td1 );
td0[1]=GetPhysicalAddress( (DWORD)td1 );
td0[2]=(1<<31) | (8<<16) | (1<<15) | (3<<10) | (1<<8) | 0x80;
td0[3]=GetPhysicalAddress( (DWORD)(ehci->buf+5) );

td1[0]=GetPhysicalAddress( (DWORD)td2 );
td1[1]=GetPhysicalAddress( (DWORD)td1 );
td1[2]=(8<<16) | (1<<15) | (3<<10) | (1<<8) | 0x80;
td1[3]=GetPhysicalAddress( (DWORD)(ehci->buf+5+8) );

td2[0]=GetPhysicalAddress( (DWORD)status_td );
td2[1]=GetPhysicalAddress( (DWORD)status_td );
td2[2]=(1<<31) | (6<<16) | (1<<15) | (3<<10) | (1<<8) | 0x80;
td2[3]=GetPhysicalAddress( (DWORD)(ehci->buf+5+8+8) );

status_td[0]=1;
status_td[1]=1;
status_td[2]=(1<<31) | (0<<16) | (1<<15) | (3<<10) | (0<<8) | 0x80;
status_td[3]=0;


qh[0]=GetPhysicalAddress( (DWORD)qh ) | 2;
qh[1]=(8<<16) | (1<<15) | (0<<14) | (2<<12) | (0<<8) | 0;
qh[2]=(1<<30);
qh[3]=0;
qh[4]=GetPhysicalAddress( (DWORD)setup_td );
qh[5]=0;


*ehci->CONFIGFLAG = 1;
*ehci->PERIODICLISTBASE=0;

ehci->status=0;

*ehci->ASYNCLISTADDR = GetPhysicalAddress( (DWORD)qh ) | 2;
*ehci->USBSTS = 0x0f;
cmd = *ehci->USBCMD;
cmd &= 0xfffffffe;
*ehci->USBCMD = cmd | 0x00080021;
delay(200);


// wait for complete
while(ehci->status==0);

dbgout("Already Send");
}


The problem is : It stay in "//wait for complete" , It not generate any Interrupt (if have a interrupt,I can catch it in debugger), Can your tell me what wrong !!! very thanks!!!

Re: Help me about USB EHCI !!!

Posted: Sat Apr 09, 2011 11:45 pm
by pcmattman
Is bus mastering turned on in the PCI command register?

Re: Help me about USB EHCI !!!

Posted: Sat Apr 09, 2011 11:58 pm
by ppppllll1234
If I insert a new USB device, It can generate a interrupt, I read the PORTSC status, its value is 0x0001001, So it's not enable ?
how to enable the port?

Re: Help me about USB EHCI !!!

Posted: Sun Apr 10, 2011 12:09 am
by pcmattman
The EHCI specification explains controller (and individual port) startup fairly well. It'd be a good place to start.

Re: Help me about USB EHCI !!!

Posted: Sun Apr 10, 2011 1:26 am
by madeofstaples
I haven't had much time on my hands but I have been checking back here every once in a while and I have noticed a slight, if not a fairly noticeable increase in attempts to implement USB support. This was something I had hoped would result after covering a substantial amount of USB 2.0 in the wiki--I don't know if this is really such a direct cause (and I would certainly appreciate feedback if it really is), but regardless I think it's high time I make some time to focus on:
  • Updating the wiki with USB 3.0 information (possibly combined with an effort to make USB support seem less intimidating, hah)
  • Adding hub information
  • Covering all the host controllers
  • Two tutorials that I have in mind:
    • One tutorial using more procedural code to help the developer understand in a straightforward manner which messages must be sent back and forth between a device to achieve some gaol, and
    • Another tutorial illustrating a sane organization of code for implementing a USB subsystem (prerequisite is info on hubs).
  • Not sure where is most appropriate but some things really need to be said about booting your OS from a USB drive if you insist on entering protected/long-mode before loading all necessary information via BIOS interrupts (i.e., some techniques to determine exactly which drive on the USB the bios has tried to boot (e.g., suppose you copy your OS image to two USB drives and connect them both to the computer. You use the BIOS or boot-select start-up screen to boot from one device. It enters protected/long moe, but now it maybe extremely important that it boot from the correct drive--the one you have chosen as a boot device--because they may have a different set of user accounts, and so on.
(not necessarily in order of priority).

Anway, to get back on topic, may we see your EHCI_DEV structure to make sure that is not causing issues?

Re: Help me about USB EHCI !!!

Posted: Sun Apr 10, 2011 6:27 am
by ppppllll1234
I already enable the port, but it's also don't work

Re: Help me about USB EHCI !!!

Posted: Fri Apr 15, 2011 6:53 am
by Jonatan44
Hi ppppllll1234,
first of all, let me tell you your code should really need to improve your code readability - starting from better variable names, diapering of 'magic-numbers' (qh+14 - wtf?!).

second, could you please give us the value of the Setup, IO & buffer QTDs before the controller mess with them?

third, why in this line:
memcpy(ehci->buf,&usr,18);
you copy 18 bytes of usr into the buffer? you should copy sizeof(type of usr).
18 is the length of the standard device descriptor, the size of the returned data.
Jonatan44