Page 1 of 1

How to read data from USB with in/out in pmode?

Posted: Fri May 24, 2013 7:57 pm
by windows8
How to read data from USB with in/out in pmode?
I searched Google,but I got few information about that.Then I tried to search osdev forum,there is no results,too!
I found USB class code and subclass in PCI wiki(http://wiki.osdev.org/PCI),so I guess I can get io ports in PCI.If I'm right,how to use the ports?
Can you help me write an example?Thank you very much!

Re: How to read data from USB with in/out in pmode?

Posted: Fri May 24, 2013 8:07 pm
by thepowersgang
It's a lot harder than you think. USB is essentially a network protocol (except not really, but it's about as complex, and it helps to think of it this way).

If you're really interested, I'd look at the USB page on the wiki, as well as the OHCI/UHCI/EHCI datasheets. I'd guess from the way your post is framed that you're only just starting out, and want to handle USB mass storage and input devices. I would (and did) leave USB support until after my OS was stable with full multithreading and a partial network stack, just so the groundwork is covered.

Re: How to read data from USB with in/out in pmode?

Posted: Fri May 24, 2013 8:32 pm
by sounds
windows8 wrote:How to read data from USB with in/out in pmode?
I searched Google,but I got few information about that.Then I tried to search osdev forum,there is no results,too!
I found USB class code and subclass in PCI wiki(http://wiki.osdev.org/PCI),so I guess I can get io ports in PCI.If I'm right,how to use the ports?
Can you help me write an example?Thank you very much!
If you are asking about the x86 instructions "in" and "out," the answer is that you can't.

Although "in" and "out" can be used to configure the USB device's PCI configuration space... what goes there is a physical memory address.

Reads and writes to the USB device are then done using memory access, not "in" and "out."

Re: How to read data from USB with in/out in pmode?

Posted: Fri May 24, 2013 8:37 pm
by ~
thepowersgang wrote:It's a lot harder than you think. USB is essentially a network protocol (except not really, but it's about as complex, and it helps to think of it this way).

If you're really interested, I'd look at the USB page on the wiki, as well as the OHCI/UHCI/EHCI datasheets. I'd guess from the way your post is framed that you're only just starting out, and want to handle USB mass storage and input devices. I would (and did) leave USB support until after my OS was stable with full multithreading and a partial network stack, just so the groundwork is covered.
I would also like to know: Why is the reason for the apparently strong insistence about even having multithreading and network stack to implement USB?

I see that the BIOS can handle USB input devices as well as mass storage devices, and it is a 16-bit program with no multithreading and presumably not a network stack, or at least not even required for USB support.

Then I would attempt to implement USB just like the BIOS (first an easy, monotasking version, and then iterate it to naturally adapt it to a multitasking environment over a period of time).

Re: How to read data from USB with in/out in pmode?

Posted: Fri May 24, 2013 10:18 pm
by thepowersgang
I suggested waiting mostly because of the extra experience it gives you (network particularly, as it's a similar idea), but you're right - USB doesn't require full threading (just some basic timing) but it helps immensely with interrupt handling.