Skip to content

Commit

Permalink
Use Absolute Pointer Protocol from r-efi 4.3.0
Browse files Browse the repository at this point in the history
The protocol was upstreamed to r-efi 4.3.0 and bacn be picked up
from there now.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki committed Oct 18, 2023
1 parent d703e42 commit 03dd21c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 145 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Add packages that generate binaries here
members = [
"HidPkg/Crates/AbsolutePointer",
"HidPkg/Crates/HidIo",
"HidPkg/UefiHidDxe",
"MsCorePkg/HelloWorldRustDxe"
Expand All @@ -13,11 +12,10 @@ members = [
RustAdvancedLoggerDxe = {path = "AdvLoggerPkg/Crates/RustAdvancedLoggerDxe"}
RustBootServicesAllocatorDxe = {path = "MsCorePkg/Crates/RustBootServicesAllocatorDxe"}
HidIo = {path = "HidPkg/Crates/HidIo"}
AbsolutePointer = {path = "HidPkg/Crates/AbsolutePointer"}

hidparser = {git = "https://github.com/microsoft/mu_rust_hid.git", branch = "main"}

r-efi = "4.0.0"
r-efi = "4.3.0"
rustversion = "1.0.14"
spin = "0.9.8"
memoffset = "0.9.0"
13 changes: 0 additions & 13 deletions HidPkg/Crates/AbsolutePointer/Cargo.toml

This file was deleted.

114 changes: 0 additions & 114 deletions HidPkg/Crates/AbsolutePointer/src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion HidPkg/UefiHidDxe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ path = "src/main.rs"
test = false

[dependencies]
AbsolutePointer = {workspace=true}
HidIo = {workspace=true}
hidparser = {workspace=true}
memoffset = {workspace=true}
Expand Down
27 changes: 13 additions & 14 deletions HidPkg/UefiHidDxe/src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use hidparser::{
ReportDescriptor, ReportField, VariableField,
};
use memoffset::{offset_of, raw_field};
use r_efi::{efi, protocols::driver_binding, system};
use r_efi::{efi, protocols::absolute_pointer, protocols::driver_binding, system};
use rust_advanced_logger_dxe::{debugln, DEBUG_INFO, DEBUG_WARN};

use crate::{hid::HidContext, BOOT_SERVICES};
Expand Down Expand Up @@ -53,10 +53,9 @@ struct PointerReportData {
/// Context structure used to track data for this pointer device.
/// Safety: this structure is shared across FFI boundaries, and pointer arithmetic is used on its contents, so it must
/// remain #[repr(C)], and Rust aliasing and concurrency rules must be manually enforced.
#[derive(Debug)]
#[repr(C)]
pub struct PointerContext {
absolute_pointer: absolute_pointer::protocol::Protocol,
absolute_pointer: absolute_pointer::Protocol,
pub handler: PointerHandler,
controller: efi::Handle,
hid_context: *mut HidContext,
Expand All @@ -69,7 +68,7 @@ pub struct PointerHandler {
supported_usages: BTreeSet<Usage>,
report_id_present: bool,
state_changed: bool,
current_state: absolute_pointer::protocol::AbsolutePointerState,
current_state: absolute_pointer::State,
}

impl PointerHandler {
Expand Down Expand Up @@ -156,7 +155,7 @@ impl PointerHandler {
// Create pointer context. This context is shared across FFI boundary, so use Box::into_raw.
// After creation, the only way to access the context (including the handler instance) is via a raw pointer.
let context_ptr = Box::into_raw(Box::new(PointerContext {
absolute_pointer: absolute_pointer::protocol::Protocol {
absolute_pointer: absolute_pointer::Protocol {
reset: absolute_pointer_reset,
get_state: absolute_pointer_get_state,
mode: Box::into_raw(Box::new(self.initialize_mode())),
Expand Down Expand Up @@ -189,7 +188,7 @@ impl PointerHandler {
let absolute_pointer_ptr = raw_field!(context_ptr, PointerContext, absolute_pointer);
let status = (boot_services.install_protocol_interface)(
core::ptr::addr_of_mut!(controller),
&absolute_pointer::protocol::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
&absolute_pointer::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
efi::NATIVE_INTERFACE,
absolute_pointer_ptr as *mut c_void,
);
Expand All @@ -203,8 +202,8 @@ impl PointerHandler {
}

// Initializes the absolute_pointer mode structure.
fn initialize_mode(&self) -> absolute_pointer::protocol::AbsolutePointerMode {
let mut mode: absolute_pointer::protocol::AbsolutePointerMode = Default::default();
fn initialize_mode(&self) -> absolute_pointer::Mode {
let mut mode: absolute_pointer::Mode = Default::default();

if self.supported_usages.contains(&Usage::from(GENERIC_DESKTOP_X)) {
mode.absolute_max_x = AXIS_RESOLUTION;
Expand Down Expand Up @@ -358,7 +357,7 @@ impl PointerHandler {
// uninstall absolute pointer protocol
let status = (boot_services.uninstall_protocol_interface)(
unsafe { (*pointer_context).controller },
&absolute_pointer::protocol::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
&absolute_pointer::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
absolute_pointer_ptr as *mut c_void,
);
if status.is_error() {
Expand Down Expand Up @@ -421,10 +420,10 @@ pub fn attempt_to_retrieve_hid_context(
// Caller should have ensured this, so just expect on failure.
let boot_services = unsafe { BOOT_SERVICES.as_mut().expect("BOOT_SERVICES not properly initialized") };

let mut absolute_pointer_ptr: *mut absolute_pointer::protocol::Protocol = core::ptr::null_mut();
let mut absolute_pointer_ptr: *mut absolute_pointer::Protocol = core::ptr::null_mut();
let status = (boot_services.open_protocol)(
controller,
&absolute_pointer::protocol::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
&absolute_pointer::PROTOCOL_GUID as *const efi::Guid as *mut efi::Guid,
core::ptr::addr_of_mut!(absolute_pointer_ptr) as *mut *mut c_void,
driver_binding.driver_binding_handle,
controller,
Expand Down Expand Up @@ -463,7 +462,7 @@ extern "efiapi" fn wait_for_pointer(event: efi::Event, context: *mut c_void) {

// resets the pointer state - part of the absolute pointer interface.
extern "efiapi" fn absolute_pointer_reset(
this: *const absolute_pointer::protocol::Protocol,
this: *mut absolute_pointer::Protocol,
_extended_verification: bool,
) -> efi::Status {
if this.is_null() {
Expand Down Expand Up @@ -492,8 +491,8 @@ extern "efiapi" fn absolute_pointer_reset(
// returns the current pointer state in the `state` buffer provided by the caller - part of the absolute pointer
// interface.
extern "efiapi" fn absolute_pointer_get_state(
this: *const absolute_pointer::protocol::Protocol,
state: *mut absolute_pointer::protocol::AbsolutePointerState,
this: *mut absolute_pointer::Protocol,
state: *mut absolute_pointer::State,
) -> efi::Status {
if this.is_null() || state.is_null() {
return efi::Status::INVALID_PARAMETER;
Expand Down

0 comments on commit 03dd21c

Please sign in to comment.