Skip to content

Commit f2df283

Browse files
committed
uefi-raw: Add EFI_USB2_HC_PROTOCOL bindings
1 parent 6583ae5 commit f2df283

File tree

3 files changed

+182
-0
lines changed

3 files changed

+182
-0
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Added `AtaPassThruProtocol`.
1414
- Added `DevicePathUtilitiesProtocol`.
1515
- Added `UsbIoProtocol`.
16+
- Added `Usb2HostControllerProtocol`.
1617

1718

1819
# uefi-raw - 0.10.0 (2025-02-07)
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use core::ffi;
4+
5+
use bitflags::bitflags;
6+
7+
use crate::{guid, Boolean, Guid, Status};
8+
9+
use super::{AsyncUsbTransferCallback, DataDirection, DeviceRequest, UsbTransferStatus};
10+
11+
bitflags! {
12+
#[repr(transparent)]
13+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14+
pub struct ResetAttributes: u16 {
15+
/// Send a global reset signal to the USB bus.
16+
const RESET_GLOBAL = 0x0001;
17+
/// Reset the USB host controller hardware.
18+
///
19+
/// No reset signal will be sent to the USB bus.
20+
const RESET_HOST = 0x0002;
21+
/// Send a global reset signal to the USB bus.
22+
///
23+
/// Even if a debug port has been enabled, this still resets the host controller.
24+
const RESET_GLOBAL_WITH_DEBUG = 0x0004;
25+
/// Reset the USB host controller hardware.
26+
///
27+
/// Even if a debug port has been enabled, this still resets the host controller.
28+
const RESET_HOST_WITH_DEBUG = 0x0008;
29+
}
30+
}
31+
32+
newtype_enum! {
33+
pub enum HostControllerState: i32 => {
34+
HALT = 0,
35+
OPERATIONAL = 1,
36+
SUSPEND = 2,
37+
}
38+
}
39+
40+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41+
#[repr(C)]
42+
pub struct TransactionTranslator {
43+
pub hub_address: u8,
44+
pub port_number: u8,
45+
}
46+
47+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
48+
#[repr(C)]
49+
pub struct PortStatus {
50+
pub port_status: u16,
51+
pub port_change_status: u16,
52+
}
53+
54+
newtype_enum! {
55+
pub enum PortFeature: i32 => {
56+
ENABLE = 1,
57+
SUSPEND = 2,
58+
RESET = 4,
59+
POWER = 8,
60+
OWNER = 13,
61+
CONNECT_CHANGE = 16,
62+
ENABLE_CHANGE = 17,
63+
SUSPEND_CHANGE = 18,
64+
OVER_CURRENT_CHARGE = 19,
65+
RESET_CHANGE = 20,
66+
}
67+
}
68+
69+
#[derive(Debug)]
70+
#[repr(C)]
71+
pub struct Usb2HostControllerProtocol {
72+
pub get_capability: unsafe extern "efiapi" fn(
73+
this: *const Self,
74+
max_speed: *mut u8,
75+
port_number: *mut u8,
76+
is_64_bit_capable: *mut u8,
77+
) -> Status,
78+
pub reset: unsafe extern "efiapi" fn(this: *mut Self, attributes: ResetAttributes) -> Status,
79+
pub get_state:
80+
unsafe extern "efiapi" fn(this: *mut Self, state: *mut HostControllerState) -> Status,
81+
pub set_state: unsafe extern "efiapi" fn(this: *mut Self, state: HostControllerState) -> Status,
82+
pub control_transfer: unsafe extern "efiapi" fn(
83+
this: *mut Self,
84+
device_address: u8,
85+
device_speed: u8,
86+
maximum_packet_length: usize,
87+
request: *const DeviceRequest,
88+
transfer_direction: DataDirection,
89+
data: *mut ffi::c_void,
90+
data_length: *mut usize,
91+
timeout: usize,
92+
translator: *const TransactionTranslator,
93+
transfer_result: *mut UsbTransferStatus,
94+
) -> Status,
95+
pub bulk_transfer: unsafe extern "efiapi" fn(
96+
this: *mut Self,
97+
device_address: u8,
98+
endpoint_address: u8,
99+
device_speed: u8,
100+
maximum_packet_length: usize,
101+
data_buffers_number: u8,
102+
data: *const *const ffi::c_void,
103+
data_length: *mut usize,
104+
data_toggle: *mut u8,
105+
timeout: usize,
106+
translator: *const TransactionTranslator,
107+
transfer_result: *mut UsbTransferStatus,
108+
) -> Status,
109+
pub async_interrupt_transfer: unsafe extern "efiapi" fn(
110+
this: *mut Self,
111+
device_address: u8,
112+
endpoint_address: u8,
113+
device_speed: u8,
114+
maximum_packet_length: usize,
115+
is_new_transfer: Boolean,
116+
data_toggle: *mut u8,
117+
polling_interval: usize,
118+
data_length: usize,
119+
translator: *const TransactionTranslator,
120+
callback_function: AsyncUsbTransferCallback,
121+
context: *mut ffi::c_void,
122+
) -> Status,
123+
pub sync_interrupt_transfer: unsafe extern "efiapi" fn(
124+
this: *mut Self,
125+
device_address: u8,
126+
endpoint_address: u8,
127+
device_speed: u8,
128+
maximum_packet_length: usize,
129+
data: *mut ffi::c_void,
130+
data_length: *mut usize,
131+
data_toggle: *mut u8,
132+
timeout: usize,
133+
translator: *const TransactionTranslator,
134+
transfer_result: *mut UsbTransferStatus,
135+
) -> Status,
136+
pub isochronous_transfer: unsafe extern "efiapi" fn(
137+
this: *mut Self,
138+
device_address: u8,
139+
endpoint_address: u8,
140+
device_speed: u8,
141+
maximum_packet_length: usize,
142+
data_buffers_number: u8,
143+
data: *const *const ffi::c_void,
144+
data_length: usize,
145+
translator: *const TransactionTranslator,
146+
transfer_result: *mut UsbTransferStatus,
147+
) -> Status,
148+
pub async_isochronous_transfer: unsafe extern "efiapi" fn(
149+
this: *mut Self,
150+
device_address: u8,
151+
endpoint_address: u8,
152+
device_speed: u8,
153+
maximum_packet_length: usize,
154+
data_buffers_number: u8,
155+
data: *const *const ffi::c_void,
156+
data_length: usize,
157+
translator: *const TransactionTranslator,
158+
isochronous_callback: AsyncUsbTransferCallback,
159+
context: *mut ffi::c_void,
160+
) -> Status,
161+
pub get_root_hub_port_status: unsafe extern "efiapi" fn(
162+
this: *mut Self,
163+
port_number: u8,
164+
port_status: *mut PortStatus,
165+
) -> Status,
166+
pub set_root_hub_port_feature: unsafe extern "efiapi" fn(
167+
this: *mut Self,
168+
port_number: u8,
169+
port_feature: PortFeature,
170+
) -> Status,
171+
pub clear_root_hub_port_feature:
172+
unsafe extern "efiapi" fn(this: *mut Self, port_number: u8, feature: PortFeature) -> Status,
173+
174+
pub major_revision: u16,
175+
pub minor_revision: u16,
176+
}
177+
178+
impl Usb2HostControllerProtocol {
179+
pub const GUID: Guid = guid!("3e745226-9818-45b6-a2ac-d7cd0e8ba2bc");
180+
}

uefi-raw/src/protocol/usb/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::ffi;
44

55
use crate::Status;
66

7+
pub mod host_controller;
78
pub mod io;
89

910
newtype_enum! {

0 commit comments

Comments
 (0)