Skip to content

Commit

Permalink
Merge branch 'release/202311' into BdsPlatformEventsCreation
Browse files Browse the repository at this point in the history
  • Loading branch information
Eathonhsu authored Apr 19, 2024
2 parents ddab201 + cd7ce3e commit 2cf4944
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 68 deletions.
10 changes: 10 additions & 0 deletions AdvLoggerPkg/AdvLoggerPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
#
gAdvancedLoggerPreDxeLogsGuid = { 0x751fc006, 0x5804, 0x440d, { 0x8b, 0x15, 0x61, 0x8c, 0xf6, 0x56, 0xae, 0x76 } }

## GUID for specifying Advanced logger interim hob, which is used to indicate whether the logger in the
# interim phase of logger buffer being initialized.
#
gAdvancedLoggerInterimHobGuid = { 0x36587034, 0xfcde, 0x45b4, { 0x9a, 0x2b, 0xd5, 0xc4, 0xc1, 0x39, 0x96, 0x5a } }

## GUID for specifying Advanced logger interim buffer hob, which is used to carry interim log entries during the
# interim phase of being initialized.
#
gAdvancedLoggerInterimBufHobGuid = { 0x4c4f8c0b, 0xbe54, 0x49b3, { 0xba, 0x54, 0x33, 0xbf, 0x14, 0x47, 0x75, 0x24 } }

[Ppis]
## Advanced Logger Ppi - Communication from PEIM to PEI_CORE library implementation
#
Expand Down
80 changes: 69 additions & 11 deletions AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/AdvancedLoggerLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
#include <Base.h>
#include <Uefi.h>

#include <Protocol/AdvancedLogger.h>
#include <AdvancedLoggerInternal.h>
#include <AdvancedLoggerInternalProtocol.h>
#include <Library/AdvancedLoggerAccessLib.h>

/**
Including the PeiMain.h from PeiCore in order to access the Platform Blob data member.
Expand Down Expand Up @@ -440,16 +443,20 @@ AdvancedLoggerGetLoggerInfo (
VOID
)
{
UINTN BufferSize;
EFI_HOB_GUID_TYPE *GuidHob;
PEI_CORE_INSTANCE *PeiCoreInstance;
ADVANCED_LOGGER_INFO *LoggerInfo;
ADVANCED_LOGGER_INFO *LoggerInfoSec;
ADVANCED_LOGGER_PTR *LogPtr;
EFI_PHYSICAL_ADDRESS NewLoggerInfo;
UINTN Pages;
CONST EFI_PEI_SERVICES **PeiServices;
EFI_STATUS Status;
UINTN BufferSize;
EFI_HOB_GUID_TYPE *GuidHob;
EFI_HOB_GUID_TYPE *GuidHobInterim;
EFI_HOB_GUID_TYPE *GuidHobInterimBuf;
PEI_CORE_INSTANCE *PeiCoreInstance;
ADVANCED_LOGGER_INFO *LoggerInfo;
ADVANCED_LOGGER_INFO *LoggerInfoSec;
ADVANCED_LOGGER_PTR *LogPtr;
EFI_PHYSICAL_ADDRESS NewLoggerInfo;
UINTN Pages;
CONST EFI_PEI_SERVICES **PeiServices;
EFI_STATUS Status;
EFI_MEMORY_TYPE Type;
ADVANCED_LOGGER_MESSAGE_ENTRY_V2 *LogEntry;

// Try to do the minimum work at the start of this function as this
// is called quite often.
Expand Down Expand Up @@ -492,6 +499,40 @@ AdvancedLoggerGetLoggerInfo (
}
}

GuidHobInterim = GetFirstGuidHob (&gAdvancedLoggerInterimHobGuid);
if (GuidHobInterim != NULL) {
// In the middle of initialization, save the log to the interim hobs
Status = PeiServicesCreateHob (
EFI_HOB_TYPE_GUID_EXTENSION,
(UINT16)(sizeof (EFI_HOB_GUID_TYPE) + sizeof (ADVANCED_LOGGER_INFO) + ADVANCED_LOGGER_MAX_MESSAGE_SIZE),
(VOID **)&GuidHobInterimBuf
);
if (EFI_ERROR (Status)) {
return NULL;
}

LoggerInfo = (ADVANCED_LOGGER_INFO *)GET_GUID_HOB_DATA (GuidHobInterimBuf);
BufferSize = sizeof (ADVANCED_LOGGER_INFO) + ADVANCED_LOGGER_MAX_MESSAGE_SIZE;
ZeroMem ((VOID *)LoggerInfo, BufferSize);
LoggerInfo->Signature = ADVANCED_LOGGER_SIGNATURE;
LoggerInfo->Version = ADVANCED_LOGGER_VERSION;
LoggerInfo->LogBuffer = PA_FROM_PTR (LoggerInfo + 1);
LoggerInfo->LogBufferSize = (UINT32)(BufferSize - sizeof (ADVANCED_LOGGER_INFO));
LoggerInfo->LogCurrent = LoggerInfo->LogBuffer;
LoggerInfo->HwPrintLevel = FixedPcdGet32 (PcdAdvancedLoggerHdwPortDebugPrintErrorLevel);
AdvancedLoggerHdwPortInitialize ();
CopyGuid (&GuidHobInterimBuf->Name, &gAdvancedLoggerInterimBufHobGuid);
LoggerInfo->HdwPortInitialized = TRUE;
return LoggerInfo;
} else {
Status = PeiServicesCreateHob (
EFI_HOB_TYPE_GUID_EXTENSION,
(UINT16)(sizeof (EFI_HOB_GUID_TYPE)),
(VOID **)&GuidHobInterim
);
CopyGuid (&GuidHobInterim->Name, &gAdvancedLoggerInterimHobGuid);
}

//
// No Logger Info - this must be the time to allocate a new LoggerInfo and save
// the pointer in the PeiCoreInstance.
Expand All @@ -516,14 +557,17 @@ AdvancedLoggerGetLoggerInfo (

if (FeaturePcdGet (PcdAdvancedLoggerPeiInRAM)) {
Pages = FixedPcdGet32 (PcdAdvancedLoggerPages);
Type = EfiReservedMemoryType;
} else {
Pages = FixedPcdGet32 (PcdAdvancedLoggerPreMemPages);
// This is to avoid the interim buffer being allocated to consume 64KB on ARM64 platforms.
Type = EfiBootServicesData;
}

BufferSize = EFI_PAGES_TO_SIZE (Pages);

Status = PeiServicesAllocatePages (
EfiReservedMemoryType,
Type,
Pages,
&NewLoggerInfo
);
Expand Down Expand Up @@ -561,6 +605,20 @@ AdvancedLoggerGetLoggerInfo (
UpdateSecLoggerInfo (LoggerInfo);
}

//
// Check to see if we have anything in the interim buffer
//
GuidHobInterimBuf = GetFirstGuidHob (&gAdvancedLoggerInterimBufHobGuid);
while (GuidHobInterimBuf != NULL) {
//
// If we have an interim buffer, copy it to the new buffer
//
LoggerInfo = (ADVANCED_LOGGER_INFO *)GET_GUID_HOB_DATA (GuidHobInterimBuf);
LogEntry = (ADVANCED_LOGGER_MESSAGE_ENTRY_V2 *)(UINTN)LoggerInfo->LogBuffer;
AdvancedLoggerMemoryLoggerWrite (LogEntry->DebugLevel, LogEntry->MessageText, LogEntry->MessageLen);
GuidHobInterimBuf = GetNextGuidHob (&gAdvancedLoggerInterimHobGuid, GuidHobInterimBuf);
}

//
// Publish the Advanced Logger Ppi
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
[Guids]
gAdvancedLoggerHobGuid
gEfiFirmwareFileSystem2Guid
gAdvancedLoggerInterimHobGuid
gAdvancedLoggerInterimBufHobGuid

[Ppis]
gAdvancedLoggerPpiGuid ## PRODUCES
Expand Down
109 changes: 64 additions & 45 deletions HidPkg/UefiHidDxeV2/src/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::{
keyboard::key_queue::OrdKeyData,
};

use rust_advanced_logger_dxe::{debugln, function, DEBUG_ERROR, DEBUG_WARN};
use rust_advanced_logger_dxe::{debugln, function, DEBUG_ERROR, DEBUG_VERBOSE, DEBUG_WARN};

// usages supported by this module
const KEYBOARD_MODIFIER_USAGE_MIN: u32 = 0x000700E0;
Expand Down Expand Up @@ -389,8 +389,8 @@ impl KeyboardHidHandler {
fn initialize_keyboard_layout(&mut self) -> Result<(), efi::Status> {
self.install_layout_change_event()?;

//signal event to pick up any existing layout
self.boot_services.signal_event(self.layout_change_event);
//fake signal event to pick up any existing layout
on_layout_update(self.layout_change_event, self.layout_context as *mut c_void);

//install a default layout if no layout is installed.
if self.key_queue.get_layout().is_none() {
Expand Down Expand Up @@ -555,7 +555,18 @@ impl HidReportReceiver for KeyboardHidHandler {

if let Some(report_data) = self.input_reports.get(&report_id).cloned() {
if report.len() != report_data.report_size {
break 'report_processing;
//Some devices report extra bytes in their reports. Warn about this, but try and process anyway.
debugln!(
DEBUG_VERBOSE,
"{:?}:{:?} unexpected report length for report_id: {:?}. expected {:?}, actual {:?}",
function!(),
line!(),
report_id,
report_data.report_size,
report.len()
);
debugln!(DEBUG_VERBOSE, "report: {:x?}", report);
//break 'report_processing;
}

//reset currently active keys to empty set.
Expand Down Expand Up @@ -828,8 +839,11 @@ mod test {
boot_services.expect_create_event().returning(|_, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_create_event_ex().returning(|_, _, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_install_protocol_interface().returning(|_, _, _, _| efi::Status::SUCCESS);
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);
boot_services.expect_signal_event().returning(|_| efi::Status::SUCCESS);
boot_services.expect_open_protocol().returning(|_, _, _, _, _, _| efi::Status::NOT_FOUND);
boot_services.expect_raise_tpl().returning(|_| efi::TPL_APPLICATION);
boot_services.expect_restore_tpl().returning(|_| ());

let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);
let mut hid_io = MockHidIo::new();
Expand All @@ -848,6 +862,7 @@ mod test {
boot_services.expect_create_event().returning(|_, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_create_event_ex().returning(|_, _, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_install_protocol_interface().returning(|_, _, _, _| efi::Status::SUCCESS);
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);
boot_services.expect_signal_event().returning(|_| efi::Status::SUCCESS);
boot_services.expect_open_protocol().returning(|_, _, _, _, _, _| efi::Status::NOT_FOUND);
boot_services.expect_raise_tpl().returning(|_| efi::TPL_APPLICATION);
Expand Down Expand Up @@ -981,6 +996,47 @@ mod test {
efi::Status::SUCCESS
}

const TEST_KEYBOARD_GUID: efi::Guid =
efi::Guid::from_fields(0xf1796c10, 0xdafb, 0x4989, 0xa0, 0x82, &[0x75, 0xe9, 0x65, 0x76, 0xbe, 0x52]);

static mut TEST_KEYBOARD_LAYOUT: HiiKeyboardLayout =
HiiKeyboardLayout { keys: Vec::new(), guid: TEST_KEYBOARD_GUID, descriptions: Vec::new() };
unsafe {
//make a test keyboard layout that is different than the default.
TEST_KEYBOARD_LAYOUT = hii_keyboard_layout::get_default_keyboard_layout();
TEST_KEYBOARD_LAYOUT.guid = TEST_KEYBOARD_GUID;
TEST_KEYBOARD_LAYOUT.keys.pop();
TEST_KEYBOARD_LAYOUT.keys.pop();
TEST_KEYBOARD_LAYOUT.keys.pop();
TEST_KEYBOARD_LAYOUT.descriptions[0].description = "Test Keyboard Layout".to_string();
TEST_KEYBOARD_LAYOUT.descriptions[0].language = "ts-TS".to_string();
}

extern "efiapi" fn get_keyboard_layout(
_this: *const protocols::hii_database::Protocol,
_key_guid: *const efi::Guid,
keyboard_layout_length: *mut u16,
keyboard_layout_ptr: *mut protocols::hii_database::KeyboardLayout,
) -> efi::Status {
let mut keyboard_layout_buffer = vec![0u8; 4096];
let buffer_size = keyboard_layout_buffer.pwrite(unsafe { &TEST_KEYBOARD_LAYOUT }, 0).unwrap();
keyboard_layout_buffer.resize(buffer_size, 0);
unsafe {
if keyboard_layout_length.read() < buffer_size as u16 {
keyboard_layout_length.write(buffer_size as u16);
return efi::Status::BUFFER_TOO_SMALL;
} else {
if keyboard_layout_ptr.is_null() {
panic!("bad keyboard pointer)");
}
keyboard_layout_length.write(buffer_size as u16);
let slice = from_raw_parts_mut(keyboard_layout_ptr as *mut u8, buffer_size);
slice.copy_from_slice(&keyboard_layout_buffer);
return efi::Status::SUCCESS;
}
}
}

extern "efiapi" fn set_keyboard_layout(
_this: *const protocols::hii_database::Protocol,
_key_guid: *mut efi::Guid,
Expand All @@ -990,47 +1046,6 @@ mod test {
boot_services.expect_restore_tpl().returning(|_| ());
boot_services.expect_signal_event().returning(|_| efi::Status::SUCCESS);

const TEST_KEYBOARD_GUID: efi::Guid =
efi::Guid::from_fields(0xf1796c10, 0xdafb, 0x4989, 0xa0, 0x82, &[0x75, 0xe9, 0x65, 0x76, 0xbe, 0x52]);

static mut TEST_KEYBOARD_LAYOUT: HiiKeyboardLayout =
HiiKeyboardLayout { keys: Vec::new(), guid: TEST_KEYBOARD_GUID, descriptions: Vec::new() };
unsafe {
//make a test keyboard layout that is different than the default.
TEST_KEYBOARD_LAYOUT = hii_keyboard_layout::get_default_keyboard_layout();
TEST_KEYBOARD_LAYOUT.guid = TEST_KEYBOARD_GUID;
TEST_KEYBOARD_LAYOUT.keys.pop();
TEST_KEYBOARD_LAYOUT.keys.pop();
TEST_KEYBOARD_LAYOUT.keys.pop();
TEST_KEYBOARD_LAYOUT.descriptions[0].description = "Test Keyboard Layout".to_string();
TEST_KEYBOARD_LAYOUT.descriptions[0].language = "ts-TS".to_string();
}

extern "efiapi" fn get_keyboard_layout(
_this: *const protocols::hii_database::Protocol,
_key_guid: *const efi::Guid,
keyboard_layout_length: *mut u16,
keyboard_layout_ptr: *mut protocols::hii_database::KeyboardLayout,
) -> efi::Status {
let mut keyboard_layout_buffer = vec![0u8; 4096];
let buffer_size = keyboard_layout_buffer.pwrite(unsafe { &TEST_KEYBOARD_LAYOUT }, 0).unwrap();
keyboard_layout_buffer.resize(buffer_size, 0);
unsafe {
if keyboard_layout_length.read() < buffer_size as u16 {
keyboard_layout_length.write(buffer_size as u16);
return efi::Status::BUFFER_TOO_SMALL;
} else {
if keyboard_layout_ptr.is_null() {
panic!("bad keyboard pointer)");
}
keyboard_layout_length.write(buffer_size as u16);
let slice = from_raw_parts_mut(keyboard_layout_ptr as *mut u8, buffer_size);
slice.copy_from_slice(&keyboard_layout_buffer);
return efi::Status::SUCCESS;
}
}
}

boot_services.expect_locate_protocol().returning(|protocol, _, interface| {
unsafe {
match *protocol {
Expand Down Expand Up @@ -1062,6 +1077,7 @@ mod test {
let mut hii_database = hii_database.assume_init();
hii_database.new_package_list = new_package_list;
hii_database.set_keyboard_layout = set_keyboard_layout;
hii_database.get_keyboard_layout = get_keyboard_layout;

interface.write(Box::into_raw(Box::new(hii_database)) as *mut c_void);
}
Expand Down Expand Up @@ -1089,6 +1105,7 @@ mod test {
boot_services.expect_create_event().returning(|_, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_create_event_ex().returning(|_, _, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_install_protocol_interface().returning(|_, _, _, _| efi::Status::SUCCESS);
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);
boot_services.expect_signal_event().returning(|_| efi::Status::SUCCESS);
boot_services.expect_open_protocol().returning(|_, _, _, _, _, _| efi::Status::NOT_FOUND);
boot_services.expect_raise_tpl().returning(|_| efi::TPL_APPLICATION);
Expand Down Expand Up @@ -1137,6 +1154,7 @@ mod test {
boot_services.expect_create_event().returning(|_, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_create_event_ex().returning(|_, _, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_install_protocol_interface().returning(|_, _, _, _| efi::Status::SUCCESS);
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);
boot_services.expect_signal_event().returning(|_| efi::Status::SUCCESS);
boot_services.expect_open_protocol().returning(|_, _, _, _, _, _| efi::Status::NOT_FOUND);
boot_services.expect_raise_tpl().returning(|_| efi::TPL_APPLICATION);
Expand Down Expand Up @@ -1200,6 +1218,7 @@ mod test {
boot_services.expect_create_event().returning(|_, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_create_event_ex().returning(|_, _, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_install_protocol_interface().returning(|_, _, _, _| efi::Status::SUCCESS);
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);
boot_services.expect_signal_event().returning(|_| efi::Status::SUCCESS);
boot_services.expect_open_protocol().returning(|_, _, _, _, _, _| efi::Status::NOT_FOUND);
boot_services.expect_raise_tpl().returning(|_| efi::TPL_APPLICATION);
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 @@ -461,6 +461,7 @@ mod test {
boot_services.expect_create_event_ex().returning(|_, _, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_signal_event().returning(|_| efi::Status::SUCCESS);
boot_services.expect_open_protocol().returning(|_, _, _, _, _, _| efi::Status::NOT_FOUND);
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);

let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);

Expand Down Expand Up @@ -586,6 +587,7 @@ mod test {

// used in install
boot_services.expect_create_event().returning(|_, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);
boot_services.expect_install_protocol_interface().returning(|_, protocol, _, interface| {
if unsafe { *protocol } == protocols::simple_text_input::PROTOCOL_GUID {
CONTEXT_PTR.store(interface, core::sync::atomic::Ordering::SeqCst);
Expand Down
5 changes: 5 additions & 0 deletions HidPkg/UefiHidDxeV2/src/keyboard/simple_text_in_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ mod test {
boot_services.expect_create_event_ex().returning(|_, _, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_signal_event().returning(|_| efi::Status::SUCCESS);
boot_services.expect_open_protocol().returning(|_, _, _, _, _, _| efi::Status::NOT_FOUND);
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);

let mut keyboard_handler = KeyboardHidHandler::new(boot_services, 1 as efi::Handle);

Expand Down Expand Up @@ -742,6 +743,7 @@ mod test {
CONTEXT_PTR.store(interface, core::sync::atomic::Ordering::SeqCst);
efi::Status::SUCCESS
});
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);

// used in set state
boot_services.expect_raise_tpl().returning(|_| efi::TPL_APPLICATION);
Expand Down Expand Up @@ -827,6 +829,7 @@ mod test {
CONTEXT_PTR.store(interface, core::sync::atomic::Ordering::SeqCst);
efi::Status::SUCCESS
});
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);

// used in read key stroke
boot_services.expect_raise_tpl().returning(|_| efi::TPL_APPLICATION);
Expand Down Expand Up @@ -967,6 +970,8 @@ mod test {
}
efi::Status::SUCCESS
});
boot_services.expect_locate_protocol().returning(|_, _, _| efi::Status::NOT_FOUND);

boot_services.expect_create_event_ex().returning(|_, _, _, _, _, _| efi::Status::SUCCESS);
boot_services.expect_raise_tpl().returning(|_| efi::TPL_APPLICATION);
boot_services.expect_restore_tpl().returning(|_| ());
Expand Down
Loading

0 comments on commit 2cf4944

Please sign in to comment.