|
| 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 | +} |
0 commit comments