Skip to content

[REBASE & FF]Add USB and HID protocol definitions to SDK.#1498

Open
joschock wants to merge 2 commits into
OpenDevicePartnership:mainfrom
joschock:usb_hid_protocol_defs
Open

[REBASE & FF]Add USB and HID protocol definitions to SDK.#1498
joschock wants to merge 2 commits into
OpenDevicePartnership:mainfrom
joschock:usb_hid_protocol_defs

Conversation

@joschock
Copy link
Copy Markdown
Contributor

@joschock joschock commented May 5, 2026

Description

  • Add the EFI_USB_IO_PROTOCOL interface and associated USB descriptor types
    as defined in the UEFI Specification, Chapter 17.2.4 (USB I/O Protocol).

  • Add the HID_IO protocol interface as a vendor-specific protocol definition.
    This protocol is defined by Project Mu and provides the interface between
    HID transport drivers (producers) and HID class drivers (consumers).

This PR consists primarily of structural definitions of the protocols themselves, and does not include any consuming logic.

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

Tested via work in progress component development that requires these definitions.

Integration Instructions

N/A.

@patina-automation
Copy link
Copy Markdown
Contributor

patina-automation Bot commented May 5, 2026

✅ QEMU Validation Passed

All QEMU validation jobs completed successfully.

Note: Q35 is only built on Windows hosts (QEMU boot is disabled due to a QEMU vfat issue).

Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/25415455927

Boot Time to EFI Shell

Platform Elapsed
Q35 (Linux Host) 28.6s
SBSA (Linux Host) 55.9s

Dependencies

Repository Ref
patina 37d6621
patina-dxe-core-qemu af6b280
patina-fw-patcher d1d0587
patina-qemu firmware v3.0.0
patina-qemu build script 186cdcb

This comment was automatically generated by the Patina QEMU PR Validation Post workflow.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@joschock joschock force-pushed the usb_hid_protocol_defs branch from cbbf30c to 666aceb Compare May 5, 2026 00:44
@makubacki makubacki self-requested a review May 5, 2026 00:44
@joschock joschock force-pushed the usb_hid_protocol_defs branch from 666aceb to 44f35c6 Compare May 6, 2026 01:13
joschock and others added 2 commits May 5, 2026 20:35
Add the EFI_USB_IO_PROTOCOL interface and associated USB descriptor types
as defined in the UEFI Specification, Chapter 17.2.4 (USB I/O Protocol).

All protocol functions are fully defined:
- UsbControlTransfer
- UsbBulkTransfer
- UsbAsyncInterruptTransfer
- UsbSyncInterruptTransfer
- UsbIsochronousTransfer
- UsbAsyncIsochronousTransfer
- UsbGetDeviceDescriptor
- UsbGetConfigDescriptor
- UsbGetInterfaceDescriptor
- UsbGetEndpointDescriptor
- UsbGetStringDescriptor
- UsbGetSupportedLanguages
- UsbPortReset

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add the HID_IO protocol interface as a vendor-specific protocol definition.
This protocol is defined by Project Mu and provides the interface between
HID transport drivers (producers) and HID class drivers (consumers).

Reference: https://github.com/microsoft/mu_plus/blob/release/202502/HidPkg/Include/Protocol/HidIo.h

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joschock joschock force-pushed the usb_hid_protocol_defs branch from 44f35c6 to 37d6621 Compare May 6, 2026 03:39
@makubacki makubacki requested review from kuqin12 and os-d May 12, 2026 16:04
@makubacki
Copy link
Copy Markdown
Collaborator

@joschock is there a reason not to take the UEFI Specification defined content to r-efi?

/// Manages a USB device with a control transfer pipe. A control transfer is
/// typically used to perform device initialization and configuration.
pub usb_control_transfer: unsafe extern "efiapi" fn(
this: *const EfiUsbIoProtocol,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the way this is defined in the UEFI Specification, I don't think we can consider it *const here.

typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_CONTROL_TRANSFER) (
  IN EFI_USB_IO_PROTOCOL           *This,
  IN EFI_USB_DEVICE_REQUEST        *Request,
  IN EFI_USB_DATA_DIRECTION        Direction,
  IN UINT32                        Timeout,
  IN OUT VOID                      *Data OPTIONAL,
  IN UINTN                         DataLength OPTIONAL,
  OUT UINT32                       *Status
  );


/// Common header for USB descriptors.
#[derive(Debug, Clone, Copy)]
#[repr(C, packed)]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this structure (UsbDescHead) packed while the others are not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copilot added it and it was an oversight on my part not to make it consistent with the others. In this case, it should not be needed as packed will result in the same as natural alignment for this struct.

pub struct EfiUsbDeviceDescriptor {
/// Size of this descriptor in bytes.
pub length: u8,
/// Descriptor type (USB_DESC_TYPE_DEVICE).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USB_DESC_TYPE_DEVICE is not defined with the other USB descriptor types above (CONFIG and INTERFACE are currrently there). Since it's referenced here, it might be worth including for clarity. Were the other types (1, 3, 5) excluded intentionally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initially excluded because they weren't needed for the implementation; but agree they should be added to fully define the protocol

@joschock
Copy link
Copy Markdown
Contributor Author

@joschock is there a reason not to take the UEFI Specification defined content to r-efi?

Primarily for ease of prototyping this approach and getting feedback. I agree that it should be upstreamed.

@joschock
Copy link
Copy Markdown
Contributor Author

@joschock is there a reason not to take the UEFI Specification defined content to r-efi?

Primarily for ease of prototyping this approach and getting feedback. I agree that it should be upstreamed.

(definitely also needs to be more comprehensive as part of that)

Copy link
Copy Markdown
Contributor

@os-d os-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving; agree with Michael's review. Can we file an issue to track upstream to r-efi?

Copy link
Copy Markdown
Collaborator

@makubacki makubacki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with the plan to move USB IO out of this PR and take directly to r-efi (filling out all definitions).

@joschock
Copy link
Copy Markdown
Contributor Author

Approving with the plan to move USB IO out of this PR and take directly to r-efi (filling out all definitions).

Branch for r_efi here: https://github.com/joschock/r-efi/commits/add_usb_io/, but waiting on #1480 to facilitate proper testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:non-functional Does not have a functional impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants