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 / mod.rs

137 lines · 3053 bytes Raw Blame History
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3use core::ffi;
4
5use bitflags::bitflags;
6
7use crate::{Status, newtype_enum};
8
9pub mod host_controller;
10pub mod io;
11
12newtype_enum! {
13 pub enum DataDirection: i32 => {
14 DATA_IN = 0,
15 DATA_OUT = 1,
16 NO_DATA = 2,
17 }
18}
19
20#[derive(Clone, Copy, Debug, PartialEq, Eq)]
21#[repr(C, packed)]
22pub struct DeviceRequest {
23 pub request_type: u8,
24 pub request: u8,
25 pub value: u16,
26 pub index: u16,
27 pub length: u16,
28}
29
30// Compile-time ABI check.
31const _: () = {
32 assert!(size_of::<DeviceRequest>() == 8);
33};
34
35bitflags! {
36 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
37 #[repr(transparent)]
38 pub struct UsbTransferStatus: u32 {
39 const NOT_EXECUTE = 0x0001;
40 const STALL = 0x0002;
41 const BUFFER = 0x0004;
42 const BABBLE = 0x0008;
43 const NAK = 0x0010;
44 const CRC = 0x0020;
45 const TIMEOUT = 0x0040;
46 const BIT_STUFF = 0x0080;
47 const SYSTEM = 0x0100;
48 }
49}
50
51impl UsbTransferStatus {
52 pub const SUCCESS: Self = Self::empty();
53}
54
55pub type AsyncUsbTransferCallback = unsafe extern "efiapi" fn(
56 data: *const ffi::c_void,
57 data_length: usize,
58 context: *const ffi::c_void,
59 status: UsbTransferStatus,
60) -> Status;
61
62#[derive(Clone, Copy, Debug, PartialEq, Eq)]
63#[repr(C, packed)]
64pub struct DeviceDescriptor {
65 pub length: u8,
66 pub descriptor_type: u8,
67 pub bcd_usb: u16,
68 pub device_class: u8,
69 pub device_subclass: u8,
70 pub device_protocol: u8,
71 pub max_packet_size: u8,
72 pub id_vendor: u16,
73 pub id_product: u16,
74 pub bcd_device: u16,
75 pub str_manufacturer: u8,
76 pub str_product: u8,
77 pub str_serial_number: u8,
78 pub num_configurations: u8,
79}
80
81// Compile-time ABI check.
82const _: () = {
83 assert!(size_of::<DeviceDescriptor>() == 18);
84};
85
86#[derive(Clone, Copy, Debug, PartialEq, Eq)]
87#[repr(C, packed)]
88pub struct ConfigDescriptor {
89 pub length: u8,
90 pub descriptor_type: u8,
91 pub total_length: u16,
92 pub num_interfaces: u8,
93 pub configuration_value: u8,
94 pub configuration: u8,
95 pub attributes: u8,
96 pub max_power: u8,
97}
98
99// Compile-time ABI check.
100const _: () = {
101 assert!(size_of::<ConfigDescriptor>() == 9);
102};
103
104#[derive(Clone, Copy, Debug, PartialEq, Eq)]
105#[repr(C, packed)]
106pub struct InterfaceDescriptor {
107 pub length: u8,
108 pub descriptor_type: u8,
109 pub interface_number: u8,
110 pub alternate_setting: u8,
111 pub num_endpoints: u8,
112 pub interface_class: u8,
113 pub interface_subclass: u8,
114 pub interface_protocol: u8,
115 pub interface: u8,
116}
117
118// Compile-time ABI check.
119const _: () = {
120 assert!(size_of::<InterfaceDescriptor>() == 9);
121};
122
123#[derive(Clone, Copy, Debug, PartialEq, Eq)]
124#[repr(C, packed)]
125pub struct EndpointDescriptor {
126 pub length: u8,
127 pub descriptor_type: u8,
128 pub endpoint_address: u8,
129 pub attributes: u8,
130 pub max_packet_size: u16,
131 pub interval: u8,
132}
133
134// Compile-time ABI check.
135const _: () = {
136 assert!(size_of::<EndpointDescriptor>() == 7);
137};