Skip to content

Commit 5dcde4c

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

File tree

3 files changed

+220
-0
lines changed

3 files changed

+220
-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: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
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+
newtype_enum! {
12+
pub enum Speed: u8 => {
13+
FULL = 0,
14+
LOW = 1,
15+
HIGH = 2,
16+
SUPER = 3,
17+
}
18+
}
19+
20+
bitflags! {
21+
#[repr(transparent)]
22+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
23+
pub struct ResetAttributes: u16 {
24+
/// Send a global reset signal to the USB bus.
25+
const RESET_GLOBAL = 0x0001;
26+
/// Reset the USB host controller hardware.
27+
///
28+
/// No reset signal will be sent to the USB bus.
29+
const RESET_HOST = 0x0002;
30+
/// Send a global reset signal to the USB bus.
31+
///
32+
/// Even if a debug port has been enabled, this still resets the host controller.
33+
const RESET_GLOBAL_WITH_DEBUG = 0x0004;
34+
/// Reset the USB host controller hardware.
35+
///
36+
/// Even if a debug port has been enabled, this still resets the host controller.
37+
const RESET_HOST_WITH_DEBUG = 0x0008;
38+
}
39+
}
40+
41+
newtype_enum! {
42+
pub enum HostControllerState: i32 => {
43+
HALT = 0,
44+
OPERATIONAL = 1,
45+
SUSPEND = 2,
46+
}
47+
}
48+
49+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
50+
#[repr(C)]
51+
pub struct TransactionTranslator {
52+
pub hub_address: u8,
53+
pub port_number: u8,
54+
}
55+
56+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
57+
#[repr(C)]
58+
pub struct UsbPortStatus {
59+
pub port_status: PortStatus,
60+
pub port_change_status: PortChangeStatus,
61+
}
62+
63+
bitflags! {
64+
#[repr(transparent)]
65+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
66+
pub struct PortStatus: u16 {
67+
const CONNECTION = 0x0001;
68+
const ENABLE = 0x0002;
69+
const SUSPEND = 0x0004;
70+
const OVER_CURRENT = 0x0008;
71+
const RESET = 0x0010;
72+
const POWER = 0x0100;
73+
const LOW_SPEED = 0x0200;
74+
const HIGH_SPEED = 0x0400;
75+
const SUPER_SPEED = 0x0800;
76+
const OWNER = 0x2000;
77+
}
78+
}
79+
80+
bitflags! {
81+
#[repr(transparent)]
82+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
83+
pub struct PortChangeStatus: u16 {
84+
const CONNECTION = 0x0001;
85+
const ENABLE = 0x0002;
86+
const SUSPEND = 0x0004;
87+
const OVER_CURRENT = 0x0008;
88+
const RESET = 0x0010;
89+
}
90+
}
91+
92+
newtype_enum! {
93+
pub enum PortFeature: i32 => {
94+
ENABLE = 1,
95+
SUSPEND = 2,
96+
RESET = 4,
97+
POWER = 8,
98+
OWNER = 13,
99+
CONNECT_CHANGE = 16,
100+
ENABLE_CHANGE = 17,
101+
SUSPEND_CHANGE = 18,
102+
OVER_CURRENT_CHARGE = 19,
103+
RESET_CHANGE = 20,
104+
}
105+
}
106+
107+
#[derive(Debug)]
108+
#[repr(C)]
109+
pub struct Usb2HostControllerProtocol {
110+
pub get_capability: unsafe extern "efiapi" fn(
111+
this: *const Self,
112+
max_speed: *mut Speed,
113+
port_number: *mut u8,
114+
is_64_bit_capable: *mut u8,
115+
) -> Status,
116+
pub reset: unsafe extern "efiapi" fn(this: *mut Self, attributes: ResetAttributes) -> Status,
117+
pub get_state:
118+
unsafe extern "efiapi" fn(this: *mut Self, state: *mut HostControllerState) -> Status,
119+
pub set_state: unsafe extern "efiapi" fn(this: *mut Self, state: HostControllerState) -> Status,
120+
pub control_transfer: unsafe extern "efiapi" fn(
121+
this: *mut Self,
122+
device_address: u8,
123+
device_speed: Speed,
124+
maximum_packet_length: usize,
125+
request: *const DeviceRequest,
126+
transfer_direction: DataDirection,
127+
data: *mut ffi::c_void,
128+
data_length: *mut usize,
129+
timeout: usize,
130+
translator: *const TransactionTranslator,
131+
transfer_result: *mut UsbTransferStatus,
132+
) -> Status,
133+
pub bulk_transfer: unsafe extern "efiapi" fn(
134+
this: *mut Self,
135+
device_address: u8,
136+
endpoint_address: u8,
137+
device_speed: Speed,
138+
maximum_packet_length: usize,
139+
data_buffers_number: u8,
140+
data: *const *const ffi::c_void,
141+
data_length: *mut usize,
142+
data_toggle: *mut u8,
143+
timeout: usize,
144+
translator: *const TransactionTranslator,
145+
transfer_result: *mut UsbTransferStatus,
146+
) -> Status,
147+
pub async_interrupt_transfer: unsafe extern "efiapi" fn(
148+
this: *mut Self,
149+
device_address: u8,
150+
endpoint_address: u8,
151+
device_speed: Speed,
152+
maximum_packet_length: usize,
153+
is_new_transfer: Boolean,
154+
data_toggle: *mut u8,
155+
polling_interval: usize,
156+
data_length: usize,
157+
translator: *const TransactionTranslator,
158+
callback_function: AsyncUsbTransferCallback,
159+
context: *mut ffi::c_void,
160+
) -> Status,
161+
pub sync_interrupt_transfer: unsafe extern "efiapi" fn(
162+
this: *mut Self,
163+
device_address: u8,
164+
endpoint_address: u8,
165+
device_speed: Speed,
166+
maximum_packet_length: usize,
167+
data: *mut ffi::c_void,
168+
data_length: *mut usize,
169+
data_toggle: *mut u8,
170+
timeout: usize,
171+
translator: *const TransactionTranslator,
172+
transfer_result: *mut UsbTransferStatus,
173+
) -> Status,
174+
pub isochronous_transfer: unsafe extern "efiapi" fn(
175+
this: *mut Self,
176+
device_address: u8,
177+
endpoint_address: u8,
178+
device_speed: Speed,
179+
maximum_packet_length: usize,
180+
data_buffers_number: u8,
181+
data: *const *const ffi::c_void,
182+
data_length: usize,
183+
translator: *const TransactionTranslator,
184+
transfer_result: *mut UsbTransferStatus,
185+
) -> Status,
186+
pub async_isochronous_transfer: unsafe extern "efiapi" fn(
187+
this: *mut Self,
188+
device_address: u8,
189+
endpoint_address: u8,
190+
device_speed: Speed,
191+
maximum_packet_length: usize,
192+
data_buffers_number: u8,
193+
data: *const *const ffi::c_void,
194+
data_length: usize,
195+
translator: *const TransactionTranslator,
196+
isochronous_callback: AsyncUsbTransferCallback,
197+
context: *mut ffi::c_void,
198+
) -> Status,
199+
pub get_root_hub_port_status: unsafe extern "efiapi" fn(
200+
this: *mut Self,
201+
port_number: u8,
202+
port_status: *mut UsbPortStatus,
203+
) -> Status,
204+
pub set_root_hub_port_feature: unsafe extern "efiapi" fn(
205+
this: *mut Self,
206+
port_number: u8,
207+
port_feature: PortFeature,
208+
) -> Status,
209+
pub clear_root_hub_port_feature:
210+
unsafe extern "efiapi" fn(this: *mut Self, port_number: u8, feature: PortFeature) -> Status,
211+
212+
pub major_revision: u16,
213+
pub minor_revision: u16,
214+
}
215+
216+
impl Usb2HostControllerProtocol {
217+
pub const GUID: Guid = guid!("3e745226-9818-45b6-a2ac-d7cd0e8ba2bc");
218+
}

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)