interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / uefi-raw / src / protocol / usb / host_controller.rs

223 lines · 6876 bytes Raw Blame History
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3use core::ffi;
4
5use bitflags::bitflags;
6
7use crate::{Boolean, Guid, Status, guid, newtype_enum};
8
9use super::{AsyncUsbTransferCallback, DataDirection, DeviceRequest, UsbTransferStatus};
10
11newtype_enum! {
12 pub enum Speed: u8 => {
13 FULL = 0,
14 LOW = 1,
15 HIGH = 2,
16 SUPER = 3,
17 }
18}
19
20bitflags! {
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
41newtype_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)]
51pub struct TransactionTranslator {
52 pub hub_address: u8,
53 pub port_number: u8,
54}
55
56#[derive(Clone, Copy, Debug, PartialEq, Eq)]
57#[repr(C)]
58pub struct UsbPortStatus {
59 pub port_status: PortStatus,
60 pub port_change_status: PortChangeStatus,
61}
62
63bitflags! {
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
80bitflags! {
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
92newtype_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)]
109pub 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 // [`Boolean::TRUE`] if the controller supports 64-bit memory
115 // addressing, [`Boolean::false`] otherwise.
116 //
117 // Effectively this is treated like a [`Boolean`] but the spec types it
118 // as `u8`.
119 is_64_bit_capable: *mut u8,
120 ) -> Status,
121 pub reset: unsafe extern "efiapi" fn(this: *mut Self, attributes: ResetAttributes) -> Status,
122 pub get_state:
123 unsafe extern "efiapi" fn(this: *mut Self, state: *mut HostControllerState) -> Status,
124 pub set_state: unsafe extern "efiapi" fn(this: *mut Self, state: HostControllerState) -> Status,
125 pub control_transfer: unsafe extern "efiapi" fn(
126 this: *mut Self,
127 device_address: u8,
128 device_speed: Speed,
129 maximum_packet_length: usize,
130 request: *const DeviceRequest,
131 transfer_direction: DataDirection,
132 data: *mut ffi::c_void,
133 data_length: *mut usize,
134 timeout: usize,
135 translator: *const TransactionTranslator,
136 transfer_result: *mut UsbTransferStatus,
137 ) -> Status,
138 pub bulk_transfer: unsafe extern "efiapi" fn(
139 this: *mut Self,
140 device_address: u8,
141 endpoint_address: u8,
142 device_speed: Speed,
143 maximum_packet_length: usize,
144 data_buffers_number: u8,
145 data: *const *mut ffi::c_void,
146 data_length: *mut usize,
147 data_toggle: *mut u8,
148 timeout: usize,
149 translator: *const TransactionTranslator,
150 transfer_result: *mut UsbTransferStatus,
151 ) -> Status,
152 pub async_interrupt_transfer: unsafe extern "efiapi" fn(
153 this: *mut Self,
154 device_address: u8,
155 endpoint_address: u8,
156 device_speed: Speed,
157 maximum_packet_length: usize,
158 is_new_transfer: Boolean,
159 data_toggle: *mut u8,
160 polling_interval: usize,
161 data_length: usize,
162 translator: *const TransactionTranslator,
163 callback_function: Option<AsyncUsbTransferCallback>,
164 context: *const ffi::c_void,
165 ) -> Status,
166 pub sync_interrupt_transfer: unsafe extern "efiapi" fn(
167 this: *mut Self,
168 device_address: u8,
169 endpoint_address: u8,
170 device_speed: Speed,
171 maximum_packet_length: usize,
172 data: *mut ffi::c_void,
173 data_length: *mut usize,
174 data_toggle: *mut u8,
175 timeout: usize,
176 translator: *const TransactionTranslator,
177 transfer_result: *mut UsbTransferStatus,
178 ) -> Status,
179 pub isochronous_transfer: unsafe extern "efiapi" fn(
180 this: *mut Self,
181 device_address: u8,
182 endpoint_address: u8,
183 device_speed: Speed,
184 maximum_packet_length: usize,
185 data_buffers_number: u8,
186 data: *const *mut ffi::c_void,
187 data_length: usize,
188 translator: *const TransactionTranslator,
189 transfer_result: *mut UsbTransferStatus,
190 ) -> Status,
191 pub async_isochronous_transfer: unsafe extern "efiapi" fn(
192 this: *mut Self,
193 device_address: u8,
194 endpoint_address: u8,
195 device_speed: Speed,
196 maximum_packet_length: usize,
197 data_buffers_number: u8,
198 data: *const *mut ffi::c_void,
199 data_length: usize,
200 translator: *const TransactionTranslator,
201 isochronous_callback: AsyncUsbTransferCallback,
202 context: *const ffi::c_void,
203 ) -> Status,
204 pub get_root_hub_port_status: unsafe extern "efiapi" fn(
205 this: *mut Self,
206 port_number: u8,
207 port_status: *mut UsbPortStatus,
208 ) -> Status,
209 pub set_root_hub_port_feature: unsafe extern "efiapi" fn(
210 this: *mut Self,
211 port_number: u8,
212 port_feature: PortFeature,
213 ) -> Status,
214 pub clear_root_hub_port_feature:
215 unsafe extern "efiapi" fn(this: *mut Self, port_number: u8, feature: PortFeature) -> Status,
216
217 pub major_revision: u16,
218 pub minor_revision: u16,
219}
220
221impl Usb2HostControllerProtocol {
222 pub const GUID: Guid = guid!("3e745226-9818-45b6-a2ac-d7cd0e8ba2bc");
223}