Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ members = [
HidIo = { path = "HidPkg/Crates/HidIo" }
hidparser = { version = "1" }
HiiKeyboardLayout = { path = "HidPkg/Crates/HiiKeyboardLayout" }
mu_pi = { version = "6" }
mu_rust_helpers = { version = "3" }
memoffset = "0.9.0"
mockall = {version = "0.14.0"}
mu_pi = { version = "7" }
mu_rust_helpers = { version = "4" }
MuTelemetryHelperLib = { path = "MsWheaPkg/Crates/MuTelemetryHelperLib" }
num-derive = { version = "0.4", default-features = false }
num-traits = { version = "0.2", default-features = false }
patina = { version = "22" }
r-efi = "^6"
RustAdvancedLoggerDxe = { path = "AdvLoggerPkg/Crates/RustAdvancedLoggerDxe" }
RustBootServicesAllocatorDxe = { path = "MsCorePkg/Crates/RustBootServicesAllocatorDxe" }
patina = { version = "21" }
mockall = {version = "0.14.0"}

memoffset = "0.9.0"
num-traits = { version = "0.2", default-features = false }
num-derive = { version = "0.4", default-features = false }
r-efi = "5.0.0"
rustversion = "1.0.14"
spin = "0.10.0"
scroll = { version = "0.13", default-features = false, features = ["derive"] }
spin = "0.10.0"
52 changes: 32 additions & 20 deletions HidPkg/UefiHidDxe/src/driver_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ pub fn initialize_driver_binding(image_handle: efi::Handle) -> Result<(), efi::S
driver_binding_handle,
}));

let status = (boot_services.install_protocol_interface)(
core::ptr::addr_of_mut!(driver_binding_handle),
&driver_binding::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
efi::NATIVE_INTERFACE,
driver_binding_ptr as *mut c_void,
);
// SAFETY: `boot_services` references a valid Boot Services table and the arguments below are valid
// for installing the driver binding protocol.
let status = unsafe {
(boot_services.install_protocol_interface)(
core::ptr::addr_of_mut!(driver_binding_handle),
&driver_binding::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
efi::NATIVE_INTERFACE,
driver_binding_ptr as *mut c_void,
)
};

if status.is_error() {
drop(unsafe { Box::from_raw(driver_binding_ptr) });
Expand Down Expand Up @@ -77,14 +81,18 @@ extern "efiapi" fn uefi_hid_driver_binding_supported(

// Check to see if this controller is supported by attempting to open HidIo on it.
let mut hid_io_ptr: *mut hid_io::protocol::Protocol = core::ptr::null_mut();
let status = (boot_services.open_protocol)(
controller,
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
core::ptr::addr_of_mut!(hid_io_ptr) as *mut *mut c_void,
driver_binding.driver_binding_handle,
controller,
efi::OPEN_PROTOCOL_BY_DRIVER,
);
// SAFETY: `boot_services` references a valid Boot Services table and the arguments below are valid
// for opening the HidIo protocol on `controller`.
let status = unsafe {
(boot_services.open_protocol)(
controller,
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
core::ptr::addr_of_mut!(hid_io_ptr) as *mut *mut c_void,
driver_binding.driver_binding_handle,
controller,
efi::OPEN_PROTOCOL_BY_DRIVER,
)
};

// if HidIo could not be opened then it is either in use or not present.
if status.is_error() {
Expand All @@ -93,12 +101,16 @@ extern "efiapi" fn uefi_hid_driver_binding_supported(

// HidIo is available, so this controller is supported. Further checking that requires actual device interaction is
// done in uefi_hid_driver_binding_start. close the protocol used for the supported test and exit with success.
let status = (boot_services.close_protocol)(
controller,
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
driver_binding.driver_binding_handle,
controller,
);
// SAFETY: `boot_services` references a valid Boot Services table and the arguments below match the
// protocol opened above.
let status = unsafe {
(boot_services.close_protocol)(
controller,
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
driver_binding.driver_binding_handle,
controller,
)
};
if status.is_error() {
debugln!(DEBUG_ERROR, "Unexpected error from CloseProtocol: {:?}", status);
//message, but no further action to handle.
Expand Down
36 changes: 22 additions & 14 deletions HidPkg/UefiHidDxe/src/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ pub fn initialize(controller: efi::Handle, driver_binding: &driver_binding::Prot

// retrieve the HidIo instance for the given controller.
let mut hid_io_ptr: *mut hid_io::protocol::Protocol = core::ptr::null_mut();
let status = (boot_services.open_protocol)(
controller,
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
core::ptr::addr_of_mut!(hid_io_ptr) as *mut *mut c_void,
driver_binding.driver_binding_handle,
controller,
system::OPEN_PROTOCOL_BY_DRIVER,
);
// SAFETY: `boot_services` references a valid Boot Services table and the arguments below are valid
// for opening the HidIo protocol on `controller`.
let status = unsafe {
(boot_services.open_protocol)(
controller,
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
core::ptr::addr_of_mut!(hid_io_ptr) as *mut *mut c_void,
driver_binding.driver_binding_handle,
controller,
system::OPEN_PROTOCOL_BY_DRIVER,
)
};
if status.is_error() {
debugln!(DEBUG_ERROR, "[hid::initialize] Unexpected error opening HidIo protocol: {:#?}", status);
return Err(status);
Expand Down Expand Up @@ -185,12 +189,16 @@ fn release_hid_io(controller: efi::Handle, driver_binding: &driver_binding::Prot
let boot_services = unsafe { BOOT_SERVICES.as_mut().expect("BOOT_SERVICES not properly initialized") };

// release HidIo
match (boot_services.close_protocol)(
controller,
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
driver_binding.driver_binding_handle,
controller,
) {
// SAFETY: `boot_services` references a valid Boot Services table and the arguments below match the
// HidIo protocol opened on `controller`.
match unsafe {
(boot_services.close_protocol)(
controller,
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
driver_binding.driver_binding_handle,
controller,
)
} {
efi::Status::SUCCESS => (),
err => {
debugln!(
Expand Down
5 changes: 4 additions & 1 deletion HidPkg/UefiHidDxe/src/key_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ impl KeyQueue {
{
debugln!(DEBUG_WARN, "Ctrl-Alt-Del pressed, resetting system.");
if let Some(runtime_services) = unsafe { RUNTIME_SERVICES.as_mut() } {
(runtime_services.reset_system)(efi::RESET_WARM, efi::Status::SUCCESS, 0, core::ptr::null_mut());
// SAFETY: `runtime_services` references a valid Runtime Services table.
unsafe {
(runtime_services.reset_system)(efi::RESET_WARM, efi::Status::SUCCESS, 0, core::ptr::null_mut());
}
}
panic!("Reset failed.");
}
Expand Down
Loading
Loading