Skip to content

Commit

Permalink
[CHERRY-PICK] Reset the keyboard to default state during initialization
Browse files Browse the repository at this point in the history
Fixes #633

Reset the keyboard to default state during initialization in order to
make sure the LED status on keyboard is determined.

- [x] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [ ] Includes documentation?
- [x] Backport to release branch?

Tested on Surface Laptop and Surface Pro, all keyboard LEDs are turned
off when booting to the UEFI front page.
No regressions observed.

N/A

(cherry picked from commit f55d046)
  • Loading branch information
wenbhou authored and makubacki committed Feb 18, 2025
1 parent b79fc10 commit b2be3f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions HidPkg/UefiHidDxeV2/src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ impl HidReportReceiver for KeyboardHidHandler {
fn initialize(&mut self, controller: efi::Handle, hid_io: &dyn HidIo) -> Result<(), efi::Status> {
let descriptor = hid_io.get_report_descriptor()?;
self.process_descriptor(descriptor)?;
// Set the key toggle state here so that the subsequent reset() can send the LED state to the device.
self.set_key_toggle_state(protocols::simple_text_input_ex::CAPS_LOCK_ACTIVE);
self.reset(hid_io, true)?;
self.install_protocol_interfaces(controller)?;
self.initialize_keyboard_layout()?;
Ok(())
Expand Down Expand Up @@ -818,6 +821,7 @@ mod test {
let boot_services = create_fake_static_boot_service();
let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);
let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&MOUSE_REPORT_DESCRIPTOR).unwrap()));
Expand All @@ -839,6 +843,7 @@ mod test {

let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);
let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand All @@ -862,6 +867,7 @@ mod test {

let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);
let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down Expand Up @@ -1086,6 +1092,7 @@ mod test {
unsafe { HANDLER = &mut keyboard_handler as *mut KeyboardHidHandler };

let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down Expand Up @@ -1156,6 +1163,7 @@ mod test {

let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);
let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down Expand Up @@ -1220,6 +1228,7 @@ mod test {

let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);
let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down
2 changes: 2 additions & 0 deletions HidPkg/UefiHidDxeV2/src/keyboard/simple_text_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ mod test {
let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);

let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down Expand Up @@ -607,6 +608,7 @@ mod test {
let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);

let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down
4 changes: 4 additions & 0 deletions HidPkg/UefiHidDxeV2/src/keyboard/simple_text_in_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ mod test {
let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);

let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down Expand Up @@ -775,6 +776,7 @@ mod test {
let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);

let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down Expand Up @@ -840,6 +842,7 @@ mod test {
let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);

let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down Expand Up @@ -978,6 +981,7 @@ mod test {
let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);

let mut hid_io = MockHidIo::new();
hid_io.expect_set_output_report().returning(|_, _| Ok(()));
hid_io
.expect_get_report_descriptor()
.returning(|| Ok(hidparser::parse_report_descriptor(&BOOT_KEYBOARD_REPORT_DESCRIPTOR).unwrap()));
Expand Down

0 comments on commit b2be3f7

Please sign in to comment.