Will a keypress on a HID USB device (like a keyboard) trigger an Event in the Event Ring thus triggering an interrupt?

Viewed 346

I've been reading for some time the xHCI specification and other ressources. I want to implement support for HID USB devices in a hobby OS I'm writing. My question is about the MSI-X mechanism and the Event Ring. As stated in the specification for the xHCI,

Interrupters 0 to MaxIntrs-1 may each trigger a unique interrupt vector. i.e. there is a 1:1 mapping of the index of an Interrupter to the index of the MSI-X vector in the MSI-X Table Structure or to the associated Pending Bit in the MSI-X PBA Structure. Refer to section 6.8.2 in the PCIspec for more information.

So there is a 1:1 mapping of index in the Interrupter Register set and MSI-X Message Table. Also it is stated that,

An xHC implementation may support Interrupter Mapping. Interrupter Mapping is the ability to target an Interrupter and its Event Ring, with the Transfer Events generated by a specific Transfer Request Block. If the Number of Interrupters (MaxIntrs) field is greater than 1, then Interrupter Mapping shall be supported. The value of the Interrupter Target field in the Transfer TRB determines which Interrupter shall receive the Transfer Events generated by the respective Device Slot or Transfer TRB. If Interrupter Mapping is not supported, the Interrupter Target field shall be ignored by the xHC and all Events targeted at Interrupter 0.

With this in mind, I thought I would implement only Interrupter 0 since I don't want to make things too complex for now. The way I see things is that I would follow the initialization steps for the keyboard. Then I would wait for an Event (an interrupt) on the Event Ring of Interrupter 0. Then I would look at the events in the Event Ring. If it is a Transfer Event, I would look at the Slot ID and Endpoint ID fields of the Event TRB to determine the Device Slot in the Device Context Base Address Array and to get which Endpoint of this Device Slot triggered the interrupt. If it is the interrupt IN endpoint of the keyboard, I would place a Normal TRB on the Transfer Ring of this Endpoint asking for 8 bytes of data. According to osdev.org I should poll the USB keyboard at a certain interval:

Driver software should request the configuration descriptor for the HID device. A HID device must support at least one configuration. Software should then scan the endpoint descriptors, searching for a descriptor that indicates an "interrupt IN" type, which is an endpoint that sends device data to the host using interrupt transfers. Software should save the 4-bit ID of the endpoint, as well as the 8-bit interval of the endpoint. The interval value encodes time in milliseconds (ms) in which timespace the software should poll for a report packet once. For example, if the interval value is 8, software should request a report from the device every 8 ms.

In the end, is there actually an Event placed on the Event Ring on keypress of a keyboard or should software poll the HID devices every interval ms?

I'm asking this question because I would have doubted that modern OSes actually poll the USB keyboard to determine if a key was pressed. As to what I understand with USB, the USB device doesn't initialize any transfer. You are thus left to poll the USB bus. Is there a possibility to have interrupts on keyboard keypress?

Do modern OSes use the PS/2 keyboard emulation of some chipset or do they all use the USB drivers instead (always on x86)?

0 Answers
Related