Skip to content

uefi-raw: Redefine UsbPortStatus and UsbTransferStatus #1638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions uefi-raw/src/protocol/usb/host_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,38 @@ pub struct TransactionTranslator {

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct PortStatus {
pub port_status: u16,
pub port_change_status: u16,
pub struct UsbPortStatus {
pub port_status: PortStatus,
pub port_change_status: PortChangeStatus,
}

bitflags! {
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PortStatus: u16 {
const CONNECTION = 0x0001;
const ENABLE = 0x0002;
const SUSPEND = 0x0004;
const OVER_CURRENT = 0x0008;
const RESET = 0x0010;
const POWER = 0x0100;
const LOW_SPEED = 0x0200;
const HIGH_SPEED = 0x0400;
const SUPER_SPEED = 0x0800;
const OWNER = 0x2000;
}
}

bitflags! {
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PortChangeStatus: u16 {
const CONNECTION = 0x0001;
const ENABLE = 0x0002;
const SUSPEND = 0x0004;
const OVER_CURRENT = 0x0008;
const RESET = 0x0010;
}
}

newtype_enum! {
Expand Down Expand Up @@ -170,7 +199,7 @@ pub struct Usb2HostControllerProtocol {
pub get_root_hub_port_status: unsafe extern "efiapi" fn(
this: *mut Self,
port_number: u8,
port_status: *mut PortStatus,
port_status: *mut UsbPortStatus,
) -> Status,
pub set_root_hub_port_feature: unsafe extern "efiapi" fn(
this: *mut Self,
Expand Down
24 changes: 21 additions & 3 deletions uefi-raw/src/protocol/usb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use core::ffi;

use bitflags::bitflags;

use crate::Status;

pub mod host_controller;
Expand All @@ -25,9 +27,25 @@ pub struct DeviceRequest {
pub length: u16,
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(transparent)]
pub struct UsbTransferStatus(pub u32);
bitflags! {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(transparent)]
pub struct UsbTransferStatus: u32 {
const NOT_EXECUTE = 0x0001;
const STALL = 0x0002;
const BUFFER = 0x0004;
const BABBLE = 0x0008;
const NAK = 0x0010;
const CRC = 0x0020;
const TIMEOUT = 0x0040;
const BIT_STUFF = 0x0080;
const SYSTEM = 0x0100;
}
}

impl UsbTransferStatus {
pub const SUCCESS: Self = Self::empty();
}

pub type AsyncUsbTransferCallback = unsafe extern "efiapi" fn(
data: *mut ffi::c_void,
Expand Down