From previous lab 20 we got /dev/usb connected in our system, but what to do with it? Different systems handling usb in different ways, but Inferno and Plan9 has /dev/usb just as communication filesystem which should managed not by kernel but user-space process usbd which by communication with the file server manages the connectivity and start appropriate drivers for connected usb devices.
My first attempt was to have a look at original Inferno OS used to see possibilities to just reuse it. But looks like Plan9 own used was migrated so far from what Inferno has (if they had initial common file server names conventions). Because I took devusb.c from Plan9/bcm I also need used similar to Plan9. But I need limbo program!
I took challenge to port the usbd from Plan9 to Inferno, at least to the point where it has to start device. At the point when everything is ready to start device, Inferno has a preference (and it is implemented in Inferno’s usbd) that it can dynamically load/unload appropriate usb dis-drivers, while in Plan9 you need to spin a extra process to manage this.
The porting process itself wasn’t so complicated and was completed after applying some efforts. But during the testing I caught some mystery that bytes in replays are often shifted which leads to problems of identifying usb responses. The investigation of the problem pointed that usbdwg writes chunks aligned for 32 bytes while memory block created in port/allocb.c are aligned for 8 bytes (BY2V). I made allocb() similar to Plan9 version to use define BLOCKALIGN (32).
To embed used into kernel, add the
/dis/lib/daytime.dis # usb support + /dis/usb/usbd.dis /os/rpi/usb/usbd.dis /dis/lib/usb/usb.dis /dis/lib/usb/usbmass.dis
So, boot the Inferno and try final version of usbd:
$ usb/usbd usbd: base: /dev/usb/ usbd: starting: /dev/usb/ep1.0 usbd: start dev: class:9, 1060.38162.512 usbd: start dev: class:255, 1060.60416.512 $ ls /dev/usb /dev/usb/ctl /dev/usb/ep1.0 /dev/usb/ep2.0 /dev/usb/ep3.0 $ usbd: start dev: class:3, 3727.34.528 $ ls /dev/usb /dev/usb/ctl /dev/usb/ep1.0 /dev/usb/ep2.0 /dev/usb/ep3.0 /dev/usb/ep4.0 $
What we see here is ep1.0 which is default root hub existing from beginning, then ep2.0 hub, then ep3.0 which is probably Ethernet card. Later I connected usb keyboard and you see device appeared ep4.0.
In next Lab we will try to implement/load and get to work USB keyboard driver.