Page 1 of 2

USB EHCI memory mapped I/O how to use

Posted: Mon Oct 31, 2016 6:14 pm
by Raymond
I config Ehci on qemu ,when i read the pci config space offset 0x10 for ehci to get base address,
i get a memory mapped I/O address febd2000,how can access command register and status register .etc with this address?
And what is the detail of using memory mapped I/O address febd2000 for ehci?
below is my conifg cmdline of usb
-usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=8086
Does '-device usb-host' mean i link up to my real machine for usb?

ray

Re: USB EHCI memory mapped I/O how to use

Posted: Mon Oct 31, 2016 10:31 pm
by BenLunt
This is called a Mem-Mapped I/O address. This means that memory is mapped to this I/O. You write a value to the memory at that location and the (PCI) bus will write it to the hardware.

The EHCI is, in my opinion, the most complicated of the four types of controllers. If you have not done any USB yet, I would suggest another controller type, maybe the xHCI. If you must do EHCI, I would suggest you learn UHCI or OHCI first, since the EHCI will send all low- and full-speed devices to those controllers anyway.

I have a book that describes all four controllers, how to detect them, how to program them, and then how to retrieve the packets from the devices attached.
http://www.fysnet.net/the_universal_serial_bus.htm
It also contains source code to do all of this.

I also try to answer all emails pertaining to the book, so if you get stuck, ask here, then if that fails, send me an email.

Ben

Re: USB EHCI memory mapped I/O how to use

Posted: Tue Nov 01, 2016 2:52 am
by Raymond
Thank you,ben. I have had your usb book through the amazon.com,it is a pdf format.And i have read the book.
Now my real machine is ehci,so i wonder i could config the qemu to my host machine.

And i want pdf of 'gui' part,'network' part,there seem no pdf on amazon ,can you give me a web link to them?

Re: USB EHCI memory mapped I/O how to use

Posted: Tue Nov 01, 2016 12:05 pm
by BenLunt
If you have my book, even though in Amazon Kindle form, you should have all you need to configure the EHCI.

As for writing to the controller, instead of using

Code: Select all

  outw(someaddress, someval);
You will use

Code: Select all

  *someaddress = someval;
As for as the Kindle version of the newer books, I haven't decided if I will release them in Kindle form. Your comments make a perfect example why I probably won't. Not that you are doing it, but since you state you have it in .PDF form, that sure makes it very easy to illegally distribute. Therefore, I may not continue to release Kindle forms...

Thanks,
Ben

Re: USB EHCI memory mapped I/O how to use

Posted: Tue Nov 01, 2016 4:16 pm
by Raymond

Code: Select all

   int addr,data,temp;
	char bus,dev,func,reg;
	unsigned int timeout = EHCI_RESET_DELAY;

	reg = 0x10;
	sprintf(us,"init usb");
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 32, COL8_FFFFFF, us);
	
	addr = PCI_BUS_CONFIG(0,4,0,reg);
	//write the new value of the base address I/O field back to its offset in the configuration space
	io_out32(0xCF8,addr);
	io_out32(0xCFC,usbaddr);
	
	// Write 0x00000000 to dword 0x34 and dword 0x38 of the configuration space
	reg = 0x34;
	addr = PCI_BUS_CONFIG(0,4,0,reg);
	io_out32(0xCF8,addr);
	io_out32(0xCFC,0x00000000);
	reg = 0x38;
	addr = PCI_BUS_CONFIG(0,4,0,reg);
	io_out32(0xCF8,addr);
	io_out32(0xCFC,0x00000000);
	//set irq field
	reg = 0x3C;
	addr = PCI_BUS_CONFIG(0,4,0,reg);
	io_out32(0xCF8,addr);
	io_out8(0xCFC,0x09);
	
	//write 0x02 if you were using memory mapped I/O
	reg = 0x04;
	addr = PCI_BUS_CONFIG(0,4,0,reg);
	io_out32(0xCF8,addr);
	io_out16(0xCFC,0x0002);
	
	mdelay(1000);
	temp = (*(usbaddr+0x00));
	sprintf(us,"ehci %x",temp);
	putfonts8_asc(binfo->vram, binfo->scrnx, 0, 48, COL8_FFFFFF, us);
I used ehci because my host is ehci,and set new address for mmio to 0x10 in pci config,set 0x02 to command to enable the mmio(in the book of fysos usb is 0x06 that i think it has problems),
but even i used 0x06 that is also failed.
why i read the CAPLENGTH as a value of 0?
Is there any lack of steps to enable the mmio?I really don't know. :?:

Re: USB EHCI memory mapped I/O how to use

Posted: Tue Nov 01, 2016 10:49 pm
by BenLunt
I don't know what you have in "usbaddr", but did you make sure and clear the bottom few bits? When you read the value, there may be a few bits set in the bottom four bits. Also, I don't remember if it was the EHCI or not, but it may require a 4k boundary address too, but that is from (faded) memory.

As for setting bit 3 in the command register (writing a value of 0x06), this also sets the bus master. If the device has a bus master, it would be nice to use it. If the device does not have a bus master, this does nothing.

Have you set the power mode of the PCI device to D0? Usually this will already be done, but I would check anyway.

When you read the register, using:

Code: Select all

 temp = (*(usbaddr+0x00));
does this read a dword or a byte? I don't remember for sure but does the EHCI require dword reads and writes only? Note, I would assume you have "usbaddr" as a byte pointer since you +0x00 to it. If you change it to a dword pointer, watch yourself when adding to it. usbaddr+0x10 may not be what you think it would be depending on how you code it.

Ben

Re: USB EHCI memory mapped I/O how to use

Posted: Wed Nov 02, 2016 7:13 am
by Raymond
Thanks,Ben

Since you have said that xhci is more easier than ehci ,how can i config xhci in qemu command line?

below is ehci:
-usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=8086
Ray

Re: USB EHCI memory mapped I/O how to use

Posted: Wed Nov 02, 2016 9:15 am
by BenLunt
I haven't tried it yet, but I believe the correct command line option is

Code: Select all

-device nec-usb-xhci,id=xhci
and then you use xhci.0 instead of ehci.0.

Re: USB EHCI memory mapped I/O how to use

Posted: Wed Nov 02, 2016 9:26 am
by iansjack

Re: USB EHCI memory mapped I/O how to use

Posted: Fri Nov 04, 2016 1:40 am
by Raymond
Hi,ben.
When i read the 0x34 of the pci configuration space of xhci,i got 0x90 for offset of the capablity list start offset in pci,
then i read the offset 0x90 i received the value of 0x7011,what does it mean?And how can i compute the power management register offset?
the power management reg is in pci config space or other place?I really confused for fysos usb book on xhci.
And ben ,Can you give me a valid email ,then i can discussion some issues?

Ray

Re: USB EHCI memory mapped I/O how to use

Posted: Fri Nov 04, 2016 10:38 am
by BenLunt
This is explained on page 9-8 of my book. If you read in the word 0x7011, then you have an ID value of 0x11 and a next offset of 0x70. An ID value of 0x11 (17d) is the Extended Message Interrupt ID, not the power management one you are looking for. Therefore, take the "next offset" field to get the next ID. Unlike the xHCI extended caps list, the next offset is the actual offset. Therefore, read in the word at offset 0x70. Continue to do this until you find the Power Management ID or the end of list.

The figures and tables in chapter 9, especially page 9-8 represent the table of extended capabilities for the xHCI and is found by the offset within the HCCPARAMS1 register.

Also, with the list in the PCI config space, offset 0x34 is only valid if bit 4 is set in the status register.

The PCI Power Management Specification sheet, chapter 3, describes this in detail, as far as the PCI is concerned. The xHCI Power management, the field and linked list pointed to by the HCCPARAMS1 register, is explained in the xHCI specification.

Re: USB EHCI memory mapped I/O how to use

Posted: Fri Nov 04, 2016 8:55 pm
by Raymond
In the offset 0x70 is 0x00880005,that means id 5 offset is 0x00 ,it must be an end. there seemly is no power management register.

What should I do?Mabybe offset 0x70 is wrong

Code: Select all

0x34--0x90
0x90--0xf7011
0x70--0x880005

Re: USB EHCI memory mapped I/O how to use

Posted: Fri Nov 04, 2016 9:21 pm
by BenLunt
No, not necessarily. On the xHCI, the power management may be pointed to by the HCCPARMS1 register as I mentioned earlier. If it is, it is within the xHCI register base instead.

Re: USB EHCI memory mapped I/O how to use

Posted: Fri Nov 04, 2016 10:21 pm
by Raymond
In this case of no Power Management register,how can i set it to start the mmio base mode for xhci?

If power management reg is in HCCPARMS1 register ,before i start the mmio ,i can not read HCCPARMS1 register ,am i right?

And i should set power management for xhci to enable the mmio base read and write.

Re: USB EHCI memory mapped I/O how to use

Posted: Mon Nov 07, 2016 8:05 am
by Raymond
Where are you ben?I am seriously waiting for your reply.The power management is very important.