Skip to content

Commit debe2c9

Browse files
authored
Merge pull request #1623 from JarlEvanson/usb-io-raw
uefi-raw: Add EFI_USB_IO_PROTOCOL bindings
2 parents 5440cc2 + 06b737c commit debe2c9

File tree

4 files changed

+183
-0
lines changed

4 files changed

+183
-0
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Added `NvmExpressPassThruProtocol`.
1313
- Added `AtaPassThruProtocol`.
1414
- Added `DevicePathUtilitiesProtocol`.
15+
- Added `UsbIoProtocol`.
1516

1617

1718
# uefi-raw - 0.10.0 (2025-02-07)

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ pub mod scsi;
2626
pub mod shell_params;
2727
pub mod string;
2828
pub mod tcg;
29+
pub mod usb;

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

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use core::ffi;
4+
5+
use crate::{guid, Boolean, Char16, Guid, Status};
6+
7+
newtype_enum! {
8+
pub enum DataDirection: i32 => {
9+
DATA_IN = 0,
10+
DATA_OUT = 1,
11+
NO_DATA = 2,
12+
}
13+
}
14+
15+
#[derive(Debug)]
16+
#[repr(C)]
17+
pub struct DeviceRequest {
18+
pub request_type: u8,
19+
pub request: u8,
20+
pub value: u16,
21+
pub index: u16,
22+
pub length: u16,
23+
}
24+
25+
#[derive(Default, Debug)]
26+
#[repr(transparent)]
27+
pub struct UsbTransferStatus(pub u32);
28+
29+
pub type AsyncUsbTransferCallback = unsafe extern "efiapi" fn(
30+
data: *mut ffi::c_void,
31+
data_length: usize,
32+
context: *mut ffi::c_void,
33+
status: UsbTransferStatus,
34+
) -> Status;
35+
36+
#[derive(Debug)]
37+
#[repr(C)]
38+
pub struct DeviceDescriptor {
39+
pub length: u8,
40+
pub descriptor_type: u8,
41+
pub bcd_usb: u16,
42+
pub device_class: u8,
43+
pub device_subclass: u8,
44+
pub device_protocol: u8,
45+
pub max_packet_size: u8,
46+
pub id_vendor: u16,
47+
pub id_product: u16,
48+
pub bcd_device: u16,
49+
pub str_manufacturer: u8,
50+
pub str_product: u8,
51+
pub str_serial_number: u8,
52+
pub num_configurations: u8,
53+
}
54+
55+
#[derive(Debug)]
56+
#[repr(C)]
57+
pub struct ConfigDescriptor {
58+
pub length: u8,
59+
pub descriptor_type: u8,
60+
pub total_length: u16,
61+
pub num_interfaces: u8,
62+
pub configuration_value: u8,
63+
pub configuration: u8,
64+
pub attributes: u8,
65+
pub max_power: u8,
66+
}
67+
68+
#[derive(Debug)]
69+
#[repr(C)]
70+
pub struct InterfaceDescriptor {
71+
pub length: u8,
72+
pub descriptor_type: u8,
73+
pub interface_number: u8,
74+
pub alternate_setting: u8,
75+
pub num_endpoints: u8,
76+
pub interface_class: u8,
77+
pub interface_subclass: u8,
78+
pub interface_protocol: u8,
79+
pub interface: u8,
80+
}
81+
82+
#[derive(Debug)]
83+
#[repr(C)]
84+
pub struct EndpointDescriptor {
85+
pub length: u8,
86+
pub descriptor_type: u8,
87+
pub endpoint_address: u8,
88+
pub attributes: u8,
89+
pub max_packet_size: u16,
90+
pub interval: u8,
91+
}
92+
93+
#[derive(Debug)]
94+
#[repr(C)]
95+
pub struct UsbIoProtocol {
96+
pub control_transfer: unsafe extern "efiapi" fn(
97+
this: *mut Self,
98+
request: *mut DeviceRequest,
99+
direction: DataDirection,
100+
timeout: u32,
101+
data: *mut ffi::c_void,
102+
data_length: usize,
103+
status: *mut UsbTransferStatus,
104+
) -> Status,
105+
pub bulk_transfer: unsafe extern "efiapi" fn(
106+
this: *mut Self,
107+
device_endpoint: u8,
108+
data: *mut ffi::c_void,
109+
data_length: usize,
110+
timeout: u32,
111+
status: *mut UsbTransferStatus,
112+
) -> Status,
113+
pub async_interrupt_transfer: unsafe extern "efiapi" fn(
114+
this: *mut Self,
115+
device_endpoint: u8,
116+
is_new_transfer: Boolean,
117+
polling_interval: usize,
118+
data_length: usize,
119+
interrupt_callback: AsyncUsbTransferCallback,
120+
context: *mut ffi::c_void,
121+
) -> Status,
122+
pub sync_interrupt_transfer: unsafe extern "efiapi" fn(
123+
this: *mut Self,
124+
device_endpoint: u8,
125+
data: *mut ffi::c_void,
126+
data_length: *mut usize,
127+
timeout: usize,
128+
status: *mut UsbTransferStatus,
129+
) -> Status,
130+
pub isochronous_transfer: unsafe extern "efiapi" fn(
131+
this: *mut Self,
132+
device_endpoint: u8,
133+
data: *mut ffi::c_void,
134+
data_length: usize,
135+
status: *mut UsbTransferStatus,
136+
) -> Status,
137+
pub async_isochronous_transfer: unsafe extern "efiapi" fn(
138+
this: *mut Self,
139+
device_endpoint: u8,
140+
data: *mut ffi::c_void,
141+
data_length: usize,
142+
isochronous_callback: AsyncUsbTransferCallback,
143+
context: *mut ffi::c_void,
144+
) -> Status,
145+
pub get_device_descriptor: unsafe extern "efiapi" fn(
146+
this: *mut Self,
147+
device_descriptor: *mut DeviceDescriptor,
148+
) -> Status,
149+
pub get_config_descriptor: unsafe extern "efiapi" fn(
150+
this: *mut Self,
151+
config_descriptor: *mut ConfigDescriptor,
152+
) -> Status,
153+
pub get_interface_descriptor: unsafe extern "efiapi" fn(
154+
this: *mut Self,
155+
interface_descriptor: *mut InterfaceDescriptor,
156+
) -> Status,
157+
pub get_endpoint_descriptor: unsafe extern "efiapi" fn(
158+
this: *mut Self,
159+
endpoint_index: u8,
160+
endpoint_descriptor: *mut EndpointDescriptor,
161+
) -> Status,
162+
pub get_string_descriptor: unsafe extern "efiapi" fn(
163+
this: *mut Self,
164+
lang_id: u16,
165+
string_id: u8,
166+
string: *mut *mut Char16,
167+
) -> Status,
168+
pub get_supported_languages: unsafe extern "efiapi" fn(
169+
this: *mut Self,
170+
lang_id_table: *mut *mut u16,
171+
table_size: *mut u16,
172+
) -> Status,
173+
pub port_reset: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
174+
}
175+
176+
impl UsbIoProtocol {
177+
pub const GUID: Guid = guid!("2b2f68d6-0cd2-44cf-8e8b-bba20b1b5b75");
178+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
pub mod io;

0 commit comments

Comments
 (0)