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
3 changes: 1 addition & 2 deletions .azurepipelines/MuDevOpsWrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resources:
type: github
endpoint: microsoft
name: microsoft/mu_devops
ref: refs/tags/v15.0.3
ref: refs/tags/v16.0.0

parameters:
- name: do_ci_build
Expand Down Expand Up @@ -118,4 +118,3 @@ jobs:
container_build: true

- ${{ parameters.extra_jobs }}

3 changes: 0 additions & 3 deletions AdvLoggerPkg/Crates/RustAdvancedLoggerDxe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ mu_uefi_boot_services = { workspace = true }

[dev-dependencies]
mu_uefi_boot_services = { workspace = true, features = ["mockall"] }

[features]
std = []
13 changes: 7 additions & 6 deletions AdvLoggerPkg/Crates/RustAdvancedLoggerDxe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
//!
//! SPDX-License-Identifier: BSD-2-Clause-Patent
//!
#![no_std]

#[cfg(any(doc, feature = "std"))]
#![cfg_attr(not(test), no_std)]

#[cfg(doc)]
extern crate std; //allow rustdoc links to reference std (e.g. println docs below).

use core::{
Expand Down Expand Up @@ -151,14 +152,14 @@ pub fn _log(level: usize, args: fmt::Arguments) {
LOGGER.log(level, args)
}

#[cfg(not(feature = "std"))]
#[cfg(not(test))]
mod no_std_debug {
/// Prints to the AdvancedLogger log at the specified level.
///
/// This macro uses the same syntax as rust std [`std::println!`] macro, with the addition of a level argument that
/// This macro uses the same syntax as rust std `https://doc.rust-lang.org/std/macro.println.html` macro in std, with the addition of a level argument that
/// indicates what debug level the output is to be written at.
///
/// See [`std::fmt`] for details on format strings.
/// See `https://doc.rust-lang.org/std/fmt/index.html` for details on format strings.
///
/// ```no_run
/// use rust_advanced_logger_dxe::{init_debug, debug, DEBUG_INFO};
Expand All @@ -185,7 +186,7 @@ mod no_std_debug {
}
}

#[cfg(feature = "std")]
#[cfg(test)]
mod std_debug {
/// Prints to the console log.
///
Expand Down
1 change: 1 addition & 0 deletions HidPkg/UefiHidDxe/src/driver_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use r_efi::{
efi,
protocols::{device_path, driver_binding},
};

use rust_advanced_logger_dxe::{debugln, DEBUG_ERROR, DEBUG_INFO};

use crate::{hid, BOOT_SERVICES};
Expand Down
14 changes: 6 additions & 8 deletions HidPkg/UefiHidDxe/src/key_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Ord for OrdKeyData {
if !e.is_eq() {
return e;
}
return self.0.key_state.key_toggle_state.cmp(&other.0.key_state.key_toggle_state);
self.0.key_state.key_toggle_state.cmp(&other.0.key_state.key_toggle_state)
}
}

Expand Down Expand Up @@ -111,7 +111,7 @@ impl OrdKeyData {
if !(register_toggle == 0 || register_toggle == self_toggle) {
return false;
}
return true;
true
}
}

Expand Down Expand Up @@ -316,15 +316,13 @@ impl KeyQueue {
return true;
}
}
return false;
false
}

// Creates a KeyState instance initialized based on the current modifier state.
pub(crate) fn init_key_state(&self) -> KeyState {
let mut key_state: KeyState = Default::default();

key_state.key_shift_state = SHIFT_STATE_VALID;
key_state.key_toggle_state = TOGGLE_STATE_VALID | KEY_STATE_EXPOSED;
let mut key_state =
KeyState { key_shift_state: SHIFT_STATE_VALID, key_toggle_state: TOGGLE_STATE_VALID | KEY_STATE_EXPOSED };

let key_shift_state = &mut key_state.key_shift_state;
let key_toggle_state = &mut key_state.key_toggle_state;
Expand Down Expand Up @@ -396,7 +394,7 @@ impl KeyQueue {

// Returns a vector of HID usages corresponding to the active LEDs based on the active modifier state.
pub(crate) fn get_active_leds(&self) -> Vec<Usage> {
self.active_modifiers.iter().cloned().filter_map(|x| modifer_to_led_usage(x)).collect()
self.active_modifiers.iter().cloned().filter_map(modifer_to_led_usage).collect()
}

// Returns the current keyboard layout that the KeyQueue is using.
Expand Down
20 changes: 9 additions & 11 deletions HidPkg/UefiHidDxe/src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl KeyboardHandler {
ReportField::Padding(_) => (), // padding irrelevant.
}
}
if report_data.relevant_variable_fields.len() > 0 || report_data.relevant_array_fields.len() > 0 {
if !report_data.relevant_variable_fields.is_empty() || !report_data.relevant_array_fields.is_empty() {
handler.input_reports.insert(report_data.report_id, report_data);
}
}
Expand Down Expand Up @@ -209,12 +209,12 @@ impl KeyboardHandler {
ReportField::Padding(_) => (), // padding fields irrelevant.
}
}
if report_builder.relevant_variable_fields.len() > 0 {
if !report_builder.relevant_variable_fields.is_empty() {
handler.output_builders.push(report_builder);
}
}

if handler.input_reports.len() > 0 || handler.output_builders.len() > 0 {
if !handler.input_reports.is_empty() || !handler.output_builders.is_empty() {
Ok(handler)
} else {
Err(efi::Status::UNSUPPORTED)
Expand Down Expand Up @@ -411,7 +411,7 @@ impl KeyboardHandler {
if index <= range_size {
x.range().nth(index)
} else {
index = index - range_size as usize;
index -= range_size;
None
}
});
Expand All @@ -425,7 +425,7 @@ impl KeyboardHandler {

// process the given input report buffer and handle input from it.
pub fn process_input_report(&mut self, report_buffer: &[u8]) {
if report_buffer.len() == 0 {
if report_buffer.is_empty() {
return;
}

Expand All @@ -435,7 +435,7 @@ impl KeyboardHandler {
false => (None, &report_buffer[0..]),
};

if report.len() == 0 {
if report.is_empty() {
return;
}

Expand Down Expand Up @@ -602,9 +602,9 @@ pub fn attempt_to_retrieve_hid_context(
let context_ptr =
unsafe { (simple_text_in_ptr as *mut u8).sub(offset_of!(KeyboardContext, simple_text_in)) }
as *mut KeyboardContext;
return Ok(unsafe { (*context_ptr).hid_context });
Ok(unsafe { (*context_ptr).hid_context })
}
err => return Err(err),
err => Err(err),
}
}

Expand Down Expand Up @@ -790,8 +790,7 @@ extern "efiapi" fn simple_text_in_ex_read_key_stroke(
unsafe { key_data.write(key) };
efi::Status::SUCCESS
} else {
let mut key: KeyData = Default::default();
key.key_state = keyboard_context.handler.key_queue.init_key_state();
let key = KeyData { key_state: keyboard_context.handler.key_queue.init_key_state(), ..Default::default() };
unsafe { key_data.write(key) };
efi::Status::NOT_READY
}
Expand Down Expand Up @@ -1033,7 +1032,6 @@ extern "efiapi" fn on_layout_update(_event: efi::Event, context: *mut c_void) {
}
Err(_) => {
debugln!(DEBUG_WARN, "keyboard::on_layout_update: Could not parse keyboard layout buffer.");
return;
}
}
}
6 changes: 3 additions & 3 deletions HidPkg/UefiHidDxe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

extern crate alloc;

use core::panic::PanicInfo;

use driver_binding::initialize_driver_binding;
use r_efi::{efi, system};

Expand All @@ -31,6 +29,7 @@ mod pointer;
static mut BOOT_SERVICES: *mut system::BootServices = core::ptr::null_mut();
static mut RUNTIME_SERVICES: *mut system::RuntimeServices = core::ptr::null_mut();

#[allow(clippy::not_unsafe_ptr_arg_deref)]
#[no_mangle]
pub extern "efiapi" fn efi_main(image_handle: efi::Handle, system_table: *const system::SystemTable) -> efi::Status {
// Safety: This block is unsafe because it assumes that system_table and (*system_table).boot_services are correct,
Expand All @@ -56,8 +55,9 @@ pub extern "efiapi" fn efi_main(image_handle: efi::Handle, system_table: *const
#[no_mangle]
pub extern "efiapi" fn __chkstk() {}

#[cfg(target_os = "uefi")]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
fn panic(info: &core::panic::PanicInfo) -> ! {
debugln!(DEBUG_ERROR, "Panic: {:?}", info);
loop {}
}
26 changes: 13 additions & 13 deletions HidPkg/UefiHidDxe/src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ impl PointerHandler {
}
}

if report_data.relevant_fields.len() > 0 {
if !report_data.relevant_fields.is_empty() {
handler.input_reports.insert(report_data.report_id, report_data);
}
}

if handler.input_reports.len() > 0 {
if !handler.input_reports.is_empty() {
Ok(handler)
} else {
debugln!(DEBUG_INFO, "No relevant fields for handler: {:#?}", handler);
Expand Down Expand Up @@ -177,8 +177,8 @@ impl PointerHandler {
wait_for_input: core::ptr::null_mut(),
},
handler: self,
controller: controller,
hid_context: hid_context,
controller,
hid_context,
}));

let context = unsafe { context_ptr.as_mut().expect("freshly boxed context pointer is null.") };
Expand Down Expand Up @@ -241,15 +241,15 @@ impl PointerHandler {
mode.absolute_min_z = 0;
//TODO: Z-axis is interpreted as pressure data. This is for compat with reference implementation in C, but
//could consider e.g. looking for actual digitizer tip pressure usages or something.
mode.attributes = mode.attributes | 0x02;
mode.attributes |= 0x02;
} else {
debugln!(DEBUG_INFO, "No z-axis usages found in the report descriptor.");
}

let button_count = self.supported_usages.iter().filter(|x| x.page() == BUTTON_PAGE).count();

if button_count > 1 {
mode.attributes = mode.attributes | 0x01; // alternate button exists.
mode.attributes |= 0x01 // alternate button exists.
}

mode
Expand All @@ -261,7 +261,7 @@ impl PointerHandler {
if field.attributes.relative {
//for relative, just update and clamp the current state.
let new_value = current_value as i64 + field.field_value(report)?;
return Some(new_value.clamp(0, AXIS_RESOLUTION as i64) as u64);
Some(new_value.clamp(0, AXIS_RESOLUTION as i64) as u64)
} else {
//for absolute, project onto 0..AXIS_RESOLUTION
let mut new_value = field.field_value(report)?;
Expand All @@ -272,7 +272,7 @@ impl PointerHandler {
//scale to AXIS_RESOLUTION
new_value = (new_value * AXIS_RESOLUTION as i64 * 1000) / (field.field_range()? as i64 * 1000);

return Some(new_value.clamp(0, AXIS_RESOLUTION as i64) as u64);
Some(new_value.clamp(0, AXIS_RESOLUTION as i64) as u64)
}
}

Expand Down Expand Up @@ -303,7 +303,7 @@ impl PointerHandler {
// handles button inputs
fn button_handler(&mut self, field: VariableField, report: &[u8]) {
let shift: u32 = field.usage.into();
if (shift < BUTTON_MIN) || (shift > BUTTON_MAX) {
if !(BUTTON_MIN..=BUTTON_MAX).contains(&shift) {
return;
}

Expand All @@ -326,7 +326,7 @@ impl PointerHandler {

/// Processes the given input report buffer and handles input from it.
pub fn process_input_report(&mut self, report_buffer: &[u8]) {
if report_buffer.len() == 0 {
if report_buffer.is_empty() {
return;
}

Expand All @@ -336,7 +336,7 @@ impl PointerHandler {
false => (None, &report_buffer[0..]),
};

if report.len() == 0 {
if report.is_empty() {
return;
}

Expand Down Expand Up @@ -454,9 +454,9 @@ pub fn attempt_to_retrieve_hid_context(
let context_ptr =
unsafe { (absolute_pointer_ptr as *mut u8).sub(offset_of!(PointerContext, absolute_pointer)) }
as *mut PointerContext;
return Ok(unsafe { (*context_ptr).hid_context });
Ok(unsafe { (*context_ptr).hid_context })
}
err => return Err(err),
err => Err(err),
}
}

Expand Down
1 change: 0 additions & 1 deletion HidPkg/UefiHidDxeV2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ RustBootServicesAllocatorDxe = {workspace=true}

[dev-dependencies]
mockall = "0.13.0"
RustAdvancedLoggerDxe = {workspace=true, features=["std"]}
9 changes: 5 additions & 4 deletions HidPkg/UefiHidDxeV2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ mod uefi_entry {
&self,
_controller: efi::Handle,
) -> Result<Vec<Box<dyn HidReportReceiver>>, efi::Status> {
let mut receivers: Vec<Box<dyn HidReportReceiver>> = Vec::new();
receivers.push(Box::new(PointerHidHandler::new(self.boot_services, self.agent)));
receivers.push(Box::new(KeyboardHidHandler::new(self.boot_services, self.agent)));
Ok(receivers)
Ok([
Box::new(PointerHidHandler::new(self.boot_services, self.agent)) as Box<dyn HidReportReceiver>,
Box::new(KeyboardHidHandler::new(self.boot_services, self.agent)) as Box<dyn HidReportReceiver>,
]
.into())
}
}

Expand Down
30 changes: 29 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TARGET_TRIPLE = { source = "${ARCH}", mapping = { "X64" = "x86_64-unknown-uefi",
CARGO_FEATURES_FLAG = {value = "--features ${FEATURES}", condition = {env_set = ["FEATURES"], env_true = ["FEATURES"]}}
BUILD_FLAGS = "--profile ${RUSTC_PROFILE} --target ${TARGET_TRIPLE} -Zbuild-std=core,compiler_builtins,alloc -Zbuild-std-features=compiler-builtins-mem -Zunstable-options --timings=html"
TEST_FLAGS = { value = "", condition = { env_not_set = ["TEST_FLAGS"] } }
COV_FLAGS = { value = "--out html --exclude-files **/tests/*", condition = { env_not_set = ["COV_FLAGS"] } }
COV_FLAGS = { value = "--out html --out xml --exclude-files **/tests/*", condition = { env_not_set = ["COV_FLAGS"] } }

[env.development]
RUSTC_PROFILE = "dev"
Expand Down Expand Up @@ -75,6 +75,23 @@ command = "cargo"
args = ["check", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "@@split(BUILD_FLAGS, )", "--message-format=json"]
dependencies = ["individual-package-targets"]

[tasks.doc]
description = "Builds all rust documentation in the workspace. Example `cargo make doc`"
command = "cargo"
args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )"]

[tasks.doc-open]
description = "Builds all rust documentation in the workspace and opens the documentation. Example `cargo make doc-open`"
clear = true
command = "cargo"
args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--open"]

[tasks.fmt]
description = "Run cargo format."
clear = true
command = "cargo"
args = ["fmt", "--all"]

[tasks.test]
description = "Builds all rust tests in the workspace. Example `cargo make test`"
clear = true
Expand All @@ -94,3 +111,14 @@ description = "Run cargo clippy."
clear = true
command = "cargo"
args = ["clippy", "--all-targets", "--", "-D", "warnings"]

[tasks.all]
description = "Run all tasks for PR readiness."
dependencies = [
"clippy",
"fmt",
"build",
"test",
"coverage",
"doc",
]
Loading