nullplan wrote:Getting the interface right is basically all you need. I looked at seabios, and worked out the following interface:
- The abstract "usb_pipe" is a data type containing a connection to an endpoint.
- The host controller driver knows how to initialize the host controller, and further more knows how to send requests to pipes.
- The hub drivers know how many ports a given hub has, how to reset a port and detect a device on a port, and also how to de-power a port.
Now you only need to implement those for XHCI (I suggest you start with XHCI, it probably being the simplest interface and the most relevant these days), the XHCI root hub, USB hubs 1,2,3, and you are basically done.
Ah, seabios, that's one I hadn't looked at. It is somewhat gratifying that seabios implements an API for hubs in basically the same manner as I currently do. Ie. The root hub is accessed via an virtual function table rather than as a virtual hub via USB requests, as the NetBSD root hubs do. The benefit of the NetBSD approach is that the root hubs act just like a real hub.
Yes, I was converging on an endpoint being the unit of addressing for requests. I've implemented a UHCI driver, on which I'm currently building some generic USB infrastructure, and I can currently enumerate the devices connected to the root hub, and get the configuration/interface/endpoint descriptors, but that's as far as I've got so far.
I have no actual machines with xHCI, so I might give that a swerve for now.
rdos wrote:
I built my own in x86 assembly.
...
At this point, I think I have something that works, but it was a lot of work to get it up again. I support all USB standards (UHCI, OHCI, EHCI, and XHCI), and USB 2 hubs (on EHCI and XHCI). I have a working HID class (that actually partially is in C), several USB serial drivers, two USB printer drivers, and a USB disc driver.
I may disagree with how you handle bad sectors, but I've got to admire your effort in implementing a USB stack in predominantly assembly. The thought just gives me the willies!
klange wrote:
It has been on my TODO list for a decade now.
Haha, I don't feel so bad now, that something as accomplished as PonyOS^WToaruos can come so far without USB support.
I wanted USB support mainly for the USB storage support it affords me. I want to run on real hardware, which will most likely be old netbooks and laptops, using USB storage as the primary storage medium.
bloodline wrote:
I’ll try and get started this weekend...
About this time last year, I went on holiday armed with Ben Lunt's USB book, and vowed to have USB well on the way to being started. In that week, I implemented the start of my UHCI driver, and was able to do some basic port enumeration, but I was no where near anything usable.
A year passes, and I'm again on holiday in the same place, armed with the same book, and some more experience and USB knowledge (I discovered Ben Eater's youtube channel a couple of weeks ago, from which I learned quite a lot in the couple of videos I've looked at.) So far this week, I've found what I think is an optimisation bug in GCC which has been distracting me for weeks, and done some work reading and parsing the configuration descriptor that I can then use to select a driver based on the interface information contained therein, so over the next week, I hope to have at least keyboard/mouse support using boot protocol at least, and perhaps BBB storage support, but at least be in a position to start writing higher level drivers at the USB interface/endpoint level.
It was this latter bit, parsing in the nuts and bolts of descriptors, that made me question how cut down a cut down USB stack can be, but I think I may be on the right (or at least, a reasonable) track.