Skip to content

Commit 989f1f4

Browse files
committed
Migrate to R-EFI 6.0
1 parent 54e5632 commit 989f1f4

11 files changed

Lines changed: 408 additions & 226 deletions

File tree

Cargo.toml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@ members = [
1515
HidIo = { path = "HidPkg/Crates/HidIo" }
1616
hidparser = { version = "1" }
1717
HiiKeyboardLayout = { path = "HidPkg/Crates/HiiKeyboardLayout" }
18-
mu_pi = { version = "6" }
19-
mu_rust_helpers = { version = "3" }
18+
memoffset = "0.9.0"
19+
mockall = {version = "0.14.0"}
20+
mu_pi = { version = "7" }
21+
mu_rust_helpers = { version = "4" }
2022
MuTelemetryHelperLib = { path = "MsWheaPkg/Crates/MuTelemetryHelperLib" }
23+
num-derive = { version = "0.4", default-features = false }
24+
num-traits = { version = "0.2", default-features = false }
25+
patina = { version = "22" }
26+
r-efi = "^6"
2127
RustAdvancedLoggerDxe = { path = "AdvLoggerPkg/Crates/RustAdvancedLoggerDxe" }
2228
RustBootServicesAllocatorDxe = { path = "MsCorePkg/Crates/RustBootServicesAllocatorDxe" }
23-
patina = { version = "21" }
24-
mockall = {version = "0.14.0"}
25-
26-
memoffset = "0.9.0"
27-
num-traits = { version = "0.2", default-features = false }
28-
num-derive = { version = "0.4", default-features = false }
29-
r-efi = "5.0.0"
3029
rustversion = "1.0.14"
31-
spin = "0.10.0"
3230
scroll = { version = "0.13", default-features = false, features = ["derive"] }
31+
spin = "0.10.0"

HidPkg/UefiHidDxe/src/driver_binding.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ pub fn initialize_driver_binding(image_handle: efi::Handle) -> Result<(), efi::S
3636
driver_binding_handle,
3737
}));
3838

39-
let status = (boot_services.install_protocol_interface)(
40-
core::ptr::addr_of_mut!(driver_binding_handle),
41-
&driver_binding::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
42-
efi::NATIVE_INTERFACE,
43-
driver_binding_ptr as *mut c_void,
44-
);
39+
// SAFETY: `boot_services` references a valid Boot Services table and the arguments below are valid
40+
// for installing the driver binding protocol.
41+
let status = unsafe {
42+
(boot_services.install_protocol_interface)(
43+
core::ptr::addr_of_mut!(driver_binding_handle),
44+
&driver_binding::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
45+
efi::NATIVE_INTERFACE,
46+
driver_binding_ptr as *mut c_void,
47+
)
48+
};
4549

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

7882
// Check to see if this controller is supported by attempting to open HidIo on it.
7983
let mut hid_io_ptr: *mut hid_io::protocol::Protocol = core::ptr::null_mut();
80-
let status = (boot_services.open_protocol)(
81-
controller,
82-
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
83-
core::ptr::addr_of_mut!(hid_io_ptr) as *mut *mut c_void,
84-
driver_binding.driver_binding_handle,
85-
controller,
86-
efi::OPEN_PROTOCOL_BY_DRIVER,
87-
);
84+
// SAFETY: `boot_services` references a valid Boot Services table and the arguments below are valid
85+
// for opening the HidIo protocol on `controller`.
86+
let status = unsafe {
87+
(boot_services.open_protocol)(
88+
controller,
89+
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
90+
core::ptr::addr_of_mut!(hid_io_ptr) as *mut *mut c_void,
91+
driver_binding.driver_binding_handle,
92+
controller,
93+
efi::OPEN_PROTOCOL_BY_DRIVER,
94+
)
95+
};
8896

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

94102
// HidIo is available, so this controller is supported. Further checking that requires actual device interaction is
95103
// done in uefi_hid_driver_binding_start. close the protocol used for the supported test and exit with success.
96-
let status = (boot_services.close_protocol)(
97-
controller,
98-
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
99-
driver_binding.driver_binding_handle,
100-
controller,
101-
);
104+
// SAFETY: `boot_services` references a valid Boot Services table and the arguments below match the
105+
// protocol opened above.
106+
let status = unsafe {
107+
(boot_services.close_protocol)(
108+
controller,
109+
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
110+
driver_binding.driver_binding_handle,
111+
controller,
112+
)
113+
};
102114
if status.is_error() {
103115
debugln!(DEBUG_ERROR, "Unexpected error from CloseProtocol: {:?}", status);
104116
//message, but no further action to handle.

HidPkg/UefiHidDxe/src/hid.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ pub fn initialize(controller: efi::Handle, driver_binding: &driver_binding::Prot
3333

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

187191
// release HidIo
188-
match (boot_services.close_protocol)(
189-
controller,
190-
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
191-
driver_binding.driver_binding_handle,
192-
controller,
193-
) {
192+
// SAFETY: `boot_services` references a valid Boot Services table and the arguments below match the
193+
// HidIo protocol opened on `controller`.
194+
match unsafe {
195+
(boot_services.close_protocol)(
196+
controller,
197+
&hid_io::protocol::GUID as *const efi::Guid as *mut efi::Guid,
198+
driver_binding.driver_binding_handle,
199+
controller,
200+
)
201+
} {
194202
efi::Status::SUCCESS => (),
195203
err => {
196204
debugln!(

HidPkg/UefiHidDxe/src/key_queue.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ impl KeyQueue {
219219
{
220220
debugln!(DEBUG_WARN, "Ctrl-Alt-Del pressed, resetting system.");
221221
if let Some(runtime_services) = unsafe { RUNTIME_SERVICES.as_mut() } {
222-
(runtime_services.reset_system)(efi::RESET_WARM, efi::Status::SUCCESS, 0, core::ptr::null_mut());
222+
// SAFETY: `runtime_services` references a valid Runtime Services table.
223+
unsafe {
224+
(runtime_services.reset_system)(efi::RESET_WARM, efi::Status::SUCCESS, 0, core::ptr::null_mut());
225+
}
223226
}
224227
panic!("Reset failed.");
225228
}

0 commit comments

Comments
 (0)