Standarized code styles (clang-format)

This commit is contained in:
Gustave Monce 2021-12-03 17:28:30 +01:00 committed by BigfootACA
parent ebe85dc0f2
commit aee5d4edfa
40 changed files with 4756 additions and 5205 deletions

17
.clang-format Normal file
View File

@ -0,0 +1,17 @@
Language: Cpp
BreakBeforeBraces: Stroustrup
PointerAlignment: Right
IndentWidth: 2
AccessModifierOffset: 0
ColumnLimit: 80
NamespaceIndentation: All
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AlwaysBreakTemplateDeclarations: true
AlignAfterOpenBracket: AlwaysBreak
UseTab: Never
IncludeBlocks: Preserve
AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: true
SpacesInParentheses: false
SpaceBeforeParens: ControlStatements

View File

@ -16,20 +16,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/
*/
#include <Library/UefiApplicationEntryPoint.h>
#include <Library/BootSlotLib.h>
#include <Library/UefiApplicationEntryPoint.h>
EFI_STATUS
EFIAPI
SwitchSlotsAppEntryPoint(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
MemCardType Type = CheckRootDeviceType();
if (Type == UNKNOWN) {
PrintAndWaitAnyKey(SystemTable, L"Unknown device storage. Press any key to exit.\n");
PrintAndWaitAnyKey(
SystemTable, L"Unknown device storage. Press any key to exit.\n");
return EFI_UNSUPPORTED;
}
@ -46,25 +45,32 @@ SwitchSlotsAppEntryPoint (
/*Check for multislot boot support*/
BOOLEAN MultiSlotSupported = PartitionHasMultiSlot((CONST CHAR16 *)L"boot");
if (!MultiSlotSupported) {
PrintAndWaitAnyKey(SystemTable, L"A/B slots aren't supported on this device. Press any key to exit.\n");
PrintAndWaitAnyKey(
SystemTable,
L"A/B slots aren't supported on this device. Press any key to exit.\n");
return EFI_UNSUPPORTED;
}
Slot CurrentSlot = GetCurrentSlotSuffix();
if (IsSuffixEmpty(&CurrentSlot)) {
PrintAndWaitAnyKey(SystemTable, L"Current active slot not found, try to boot Android first. Press any key to exit.\n");
PrintAndWaitAnyKey(
SystemTable, L"Current active slot not found, try to boot Android "
L"first. Press any key to exit.\n");
return EFI_NOT_READY;
}
Slot *NewSlot = NULL;
Slot Slots[] = {{L"_a"}, {L"_b"}};
if (StrnCmp (CurrentSlot.Suffix, Slots[0].Suffix, StrLen (Slots[0].Suffix)) == 0) {
if (StrnCmp(CurrentSlot.Suffix, Slots[0].Suffix, StrLen(Slots[0].Suffix)) ==
0) {
NewSlot = &Slots[1];
} else {
}
else {
NewSlot = &Slots[0];
}
//Print (L"Current active slot suffix is: %s, next slot suffix is: %s\n", &CurrentSlot.Suffix, &NewSlot->Suffix);
// Print (L"Current active slot suffix is: %s, next slot suffix is: %s\n",
// &CurrentSlot.Suffix, &NewSlot->Suffix);
Status = SetActiveSlot(NewSlot, TRUE, FALSE);
@ -74,8 +80,8 @@ SwitchSlotsAppEntryPoint (
return Status;
}
//Print (L"Current active slot has been updated successfully! Press any key to reboot.\n");
//WaitAnyKey(SystemTable);
// Print (L"Current active slot has been updated successfully! Press any key
// to reboot.\n"); WaitAnyKey(SystemTable);
gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
CpuDeadLoop();
return EFI_SUCCESS;

View File

@ -16,16 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/
*/
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/BootSlotLib.h>
#include <Library/UefiLib.h>
#include <Uefi.h>
EFI_STATUS
EFIAPI
BootSlotMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
) {
BootSlotMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
MemCardType Type = CheckRootDeviceType();
if (Type == UNKNOWN) {
DEBUG((EFI_D_ERROR, "Device storage is not supported \n"));
@ -44,7 +42,9 @@ BootSlotMain(
/*Check for multislot boot support*/
BOOLEAN MultiSlotSupported = PartitionHasMultiSlot((CONST CHAR16 *)L"boot");
if (!MultiSlotSupported) {
DEBUG ((EFI_D_ERROR, "A/B slots aren't supported on this device. Press any key to exit.\n"));
DEBUG((
EFI_D_ERROR,
"A/B slots aren't supported on this device. Press any key to exit.\n"));
return EFI_SUCCESS;
}
@ -52,7 +52,8 @@ BootSlotMain(
Slot CurrentSlot = GetCurrentSlotSuffix();
if (IsSuffixEmpty(&CurrentSlot)) {
CurrentSlot = Slots[0]; // Set A as active if there is no slot available (shouldn't happen though)
CurrentSlot = Slots[0]; // Set A as active if there is no slot available
// (shouldn't happen though)
}
// Clear all unbootable bits if exists
@ -63,7 +64,8 @@ BootSlotMain(
}
}
// Set current slot as active again just refresh its attributes + mark it successful
// Set current slot as active again just refresh its attributes + mark it
// successful
Status = SetActiveSlot(&CurrentSlot, FALSE, TRUE);
if (EFI_ERROR(Status)) {

View File

@ -1,8 +1,8 @@
#include <PiDxe.h>
#include <Protocol/KeypadDevice.h>
#include <Library/DebugLib.h>
#include <Library/KeypadDeviceImplLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <PiDxe.h>
#include <Protocol/KeypadDevice.h>
typedef struct {
VENDOR_DEVICE_PATH Keypad;
@ -21,12 +21,9 @@ KEYPAD_DEVICE_PATH mInternalDevicePath = {
},
EFI_CALLER_ID_GUID,
},
{
END_DEVICE_PATH_TYPE,
{END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{ sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
}
};
{sizeof(EFI_DEVICE_PATH_PROTOCOL), 0}}};
STATIC KEYPAD_DEVICE_PROTOCOL mInternalKeypadDevice = {
KeypadDeviceImplReset,
@ -36,20 +33,13 @@ STATIC KEYPAD_DEVICE_PROTOCOL mInternalKeypadDevice = {
EFI_STATUS
EFIAPI
KeypadDeviceDxeInitialize(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
Status = gBS->InstallMultipleProtocolInterfaces(
&ImageHandle,
&gEFIDroidKeypadDeviceProtocolGuid,
&mInternalKeypadDevice,
&gEfiDevicePathProtocolGuid,
&mInternalDevicePath,
NULL
);
&ImageHandle, &gEFIDroidKeypadDeviceProtocolGuid, &mInternalKeypadDevice,
&gEfiDevicePathProtocolGuid, &mInternalDevicePath, NULL);
ASSERT_EFI_ERROR(Status);
return Status;

View File

@ -3,9 +3,9 @@
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
are licensed and made available under the terms and conditions of the BSD
License which accompanies this distribution. The full text of the license may
be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@ -59,11 +59,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
EFI_STATUS
EFIAPI
KeypadComponentNameGetDriverName(
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language,
OUT CHAR16 **DriverName);
/**
Retrieves a Unicode string that is the user readable name of the controller
@ -136,43 +133,29 @@ KeypadComponentNameGetDriverName (
EFI_STATUS
EFIAPI
KeypadComponentNameGetControllerName(
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language,
OUT CHAR16 **ControllerName);
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gKeypadComponentName = {
KeypadComponentNameGetDriverName,
KeypadComponentNameGetControllerName,
"eng"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gKeypadComponentName =
{KeypadComponentNameGetDriverName, KeypadComponentNameGetControllerName,
"eng"};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gKeypadComponentName2 = {
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL
gKeypadComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)KeypadComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) KeypadComponentNameGetControllerName,
"en"
};
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)
KeypadComponentNameGetControllerName,
"en"};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mKeypadDriverNameTable[] = {
{
"eng;en",
L"Keypad Driver"
},
{
NULL,
NULL
}
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE
mKeypadDriverNameTable[] = {{"eng;en", L"Keypad Driver"}, {NULL, NULL}};
/**
Retrieves a Unicode string that is the user readable name of the driver.
@ -216,18 +199,12 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mKeypadDriverNameTable[]
EFI_STATUS
EFIAPI
KeypadComponentNameGetDriverName(
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language,
OUT CHAR16 **DriverName)
{
return LookupUnicodeString2(
Language,
This->SupportedLanguages,
mKeypadDriverNameTable,
DriverName,
(BOOLEAN)(This == &gKeypadComponentName)
);
Language, This->SupportedLanguages, mKeypadDriverNameTable, DriverName,
(BOOLEAN)(This == &gKeypadComponentName));
}
/**
@ -301,12 +278,9 @@ KeypadComponentNameGetDriverName (
EFI_STATUS
EFIAPI
KeypadComponentNameGetControllerName(
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language,
OUT CHAR16 **ControllerName)
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
@ -321,7 +295,9 @@ KeypadComponentNameGetControllerName (
//
// Check Controller's handle
//
Status = EfiTestManagedDevice (ControllerHandle, gKeypadControllerDriver.DriverBindingHandle, &gEFIDroidKeypadDeviceProtocolGuid);
Status = EfiTestManagedDevice(
ControllerHandle, gKeypadControllerDriver.DriverBindingHandle,
&gEFIDroidKeypadDeviceProtocolGuid);
if (EFI_ERROR(Status)) {
return Status;
}
@ -329,13 +305,9 @@ KeypadComponentNameGetControllerName (
// Get the device context
//
Status = gBS->OpenProtocol(
ControllerHandle,
&gEfiSimpleTextInProtocolGuid,
(VOID **) &ConIn,
gKeypadControllerDriver.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
ControllerHandle, &gEfiSimpleTextInProtocolGuid, (VOID **)&ConIn,
gKeypadControllerDriver.DriverBindingHandle, ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR(Status)) {
return Status;
}
@ -343,10 +315,6 @@ KeypadComponentNameGetControllerName (
ConsoleIn = KEYPAD_CONSOLE_IN_DEV_FROM_THIS(ConIn);
return LookupUnicodeString2(
Language,
This->SupportedLanguages,
ConsoleIn->ControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gKeypadComponentName)
);
Language, This->SupportedLanguages, ConsoleIn->ControllerNameTable,
ControllerName, (BOOLEAN)(This == &gKeypadComponentName));
}

View File

@ -5,9 +5,9 @@
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
are licensed and made available under the terms and conditions of the BSD
License which accompanies this distribution. The full text of the license may
be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@ -33,10 +33,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
EFI_STATUS
EFIAPI
KeypadControllerDriverSupported(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath);
/**
Create KEYPAD_CONSOLE_IN_DEV instance on controller.
@ -50,10 +48,8 @@ KeypadControllerDriverSupported (
EFI_STATUS
EFIAPI
KeypadControllerDriverStart(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath);
/**
Stop this driver on ControllerHandle. Support stopping any child handles
@ -72,11 +68,8 @@ KeypadControllerDriverStart (
EFI_STATUS
EFIAPI
KeypadControllerDriverStop(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer);
/**
Free the waiting key notify list.
@ -87,9 +80,7 @@ KeypadControllerDriverStop (
@retval EFI_SUCCESS Sucess to free NotifyList
**/
EFI_STATUS
KbdFreeNotifyList (
IN OUT LIST_ENTRY *ListHead
);
KbdFreeNotifyList(IN OUT LIST_ENTRY *ListHead);
//
// DriverBinding Protocol Instance
@ -100,8 +91,7 @@ EFI_DRIVER_BINDING_PROTOCOL gKeypadControllerDriver = {
KeypadControllerDriverStop,
0xa,
NULL,
NULL
};
NULL};
/**
Test controller is a keypad Controller.
@ -116,10 +106,8 @@ EFI_DRIVER_BINDING_PROTOCOL gKeypadControllerDriver = {
EFI_STATUS
EFIAPI
KeypadControllerDriverSupported(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
{
EFI_STATUS Status;
KEYPAD_DEVICE_PROTOCOL *KeypadDevice;
@ -128,13 +116,8 @@ KeypadControllerDriverSupported (
// Open the IO Abstraction(s) needed to perform the supported test
//
Status = gBS->OpenProtocol(
Controller,
&gEFIDroidKeypadDeviceProtocolGuid,
(VOID **) &KeypadDevice,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
Controller, &gEFIDroidKeypadDeviceProtocolGuid, (VOID **)&KeypadDevice,
This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_BY_DRIVER);
if (EFI_ERROR(Status)) {
return Status;
}
@ -143,23 +126,15 @@ KeypadControllerDriverSupported (
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol(
Controller,
&gEFIDroidKeypadDeviceProtocolGuid,
This->DriverBindingHandle,
Controller
);
Controller, &gEFIDroidKeypadDeviceProtocolGuid, This->DriverBindingHandle,
Controller);
return Status;
}
STATIC
VOID
EFIAPI
KeypadReturnApiPushEfikeyBufTail (
KEYPAD_RETURN_API *This,
EFI_KEY_DATA *KeyData
)
VOID EFIAPI
KeypadReturnApiPushEfikeyBufTail(KEYPAD_RETURN_API *This, EFI_KEY_DATA *KeyData)
{
KEYPAD_CONSOLE_IN_DEV * ConsoleIn;
LIST_ENTRY * Link;
@ -170,22 +145,23 @@ KeypadReturnApiPushEfikeyBufTail (
//
// If the key can not be converted then just return.
//
if (KeyData->Key.ScanCode == SCAN_NULL && KeyData->Key.UnicodeChar == CHAR_NULL) {
if (KeyData->Key.ScanCode == SCAN_NULL &&
KeyData->Key.UnicodeChar == CHAR_NULL) {
if (!ConsoleIn->IsSupportPartialKey) {
return;
}
}
//
// Signal KeyNotify process event if this key pressed matches any key registered.
// Signal KeyNotify process event if this key pressed matches any key
// registered.
//
for (Link = GetFirstNode (&ConsoleIn->NotifyList); !IsNull (&ConsoleIn->NotifyList, Link); Link = GetNextNode (&ConsoleIn->NotifyList, Link)) {
CurrentNotify = CR (
Link,
KEYPAD_CONSOLE_IN_EX_NOTIFY,
NotifyEntry,
KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE
);
for (Link = GetFirstNode(&ConsoleIn->NotifyList);
!IsNull(&ConsoleIn->NotifyList, Link);
Link = GetNextNode(&ConsoleIn->NotifyList, Link)) {
CurrentNotify =
CR(Link, KEYPAD_CONSOLE_IN_EX_NOTIFY, NotifyEntry,
KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
if (IsKeyRegistered(&CurrentNotify->KeyData, KeyData)) {
//
// The key notification function needs to run at TPL_CALLBACK
@ -212,10 +188,8 @@ KeypadReturnApiPushEfikeyBufTail (
EFI_STATUS
EFIAPI
KeypadControllerDriverStart(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
{
EFI_STATUS Status;
KEYPAD_DEVICE_PROTOCOL *KeypadDevice;
@ -225,13 +199,8 @@ KeypadControllerDriverStart (
// Get the ISA I/O Protocol on Controller's handle
//
Status = gBS->OpenProtocol(
Controller,
&gEFIDroidKeypadDeviceProtocolGuid,
(VOID **) &KeypadDevice,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
Controller, &gEFIDroidKeypadDeviceProtocolGuid, (VOID **)&KeypadDevice,
This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_BY_DRIVER);
if (EFI_ERROR(Status)) {
return Status;
}
@ -251,7 +220,8 @@ KeypadControllerDriverStart (
(ConsoleIn->ConIn).Reset = KeypadEfiReset;
(ConsoleIn->ConIn).ReadKeyStroke = KeypadReadKeyStroke;
ConsoleIn->KeypadDevice = KeypadDevice;
ConsoleIn->KeypadReturnApi.PushEfikeyBufTail = KeypadReturnApiPushEfikeyBufTail;
ConsoleIn->KeypadReturnApi.PushEfikeyBufTail =
KeypadReturnApiPushEfikeyBufTail;
ConsoleIn->Last = (UINT64)-1;
ConsoleIn->ConInEx.Reset = KeypadEfiResetEx;
@ -263,22 +233,18 @@ KeypadControllerDriverStart (
InitializeListHead(&ConsoleIn->NotifyList);
//
// Fix for random hangs in System waiting for the Key if no KBC is present in BIOS.
// When KBC decode (IO port 0x60/0x64 decode) is not enabled,
// KeypadRead will read back as 0xFF and return status is EFI_SUCCESS.
// So instead we read status register to detect after read if KBC decode is enabled.
// Fix for random hangs in System waiting for the Key if no KBC is present in
// BIOS. When KBC decode (IO port 0x60/0x64 decode) is not enabled, KeypadRead
// will read back as 0xFF and return status is EFI_SUCCESS. So instead we read
// status register to detect after read if KBC decode is enabled.
//
//
// Setup the WaitForKey event
//
Status = gBS->CreateEvent(
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
KeypadWaitForKey,
ConsoleIn,
&((ConsoleIn->ConIn).WaitForKey)
);
EVT_NOTIFY_WAIT, TPL_NOTIFY, KeypadWaitForKey, ConsoleIn,
&((ConsoleIn->ConIn).WaitForKey));
if (EFI_ERROR(Status)) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
@ -287,12 +253,8 @@ KeypadControllerDriverStart (
// Setup the WaitForKeyEx event
//
Status = gBS->CreateEvent(
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
KeypadWaitForKeyEx,
ConsoleIn,
&(ConsoleIn->ConInEx.WaitForKeyEx)
);
EVT_NOTIFY_WAIT, TPL_NOTIFY, KeypadWaitForKeyEx, ConsoleIn,
&(ConsoleIn->ConInEx.WaitForKeyEx));
if (EFI_ERROR(Status)) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
@ -300,34 +262,23 @@ KeypadControllerDriverStart (
// Setup a periodic timer, used for reading keystrokes at a fixed interval
//
Status = gBS->CreateEvent(
EVT_TIMER | EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
KeypadTimerHandler,
ConsoleIn,
&ConsoleIn->TimerEvent
);
EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_NOTIFY, KeypadTimerHandler, ConsoleIn,
&ConsoleIn->TimerEvent);
if (EFI_ERROR(Status)) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
}
Status = gBS->SetTimer(
ConsoleIn->TimerEvent,
TimerPeriodic,
KEYPAD_TIMER_INTERVAL
);
ConsoleIn->TimerEvent, TimerPeriodic, KEYPAD_TIMER_INTERVAL);
if (EFI_ERROR(Status)) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
}
Status = gBS->CreateEvent(
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
KeyNotifyProcessHandler,
ConsoleIn,
&ConsoleIn->KeyNotifyProcessEvent
);
EVT_NOTIFY_SIGNAL, TPL_CALLBACK, KeyNotifyProcessHandler, ConsoleIn,
&ConsoleIn->KeyNotifyProcessEvent);
if (EFI_ERROR(Status)) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
@ -344,32 +295,18 @@ KeypadControllerDriverStart (
ConsoleIn->ControllerNameTable = NULL;
AddUnicodeString2(
"eng",
gKeypadComponentName.SupportedLanguages,
&ConsoleIn->ControllerNameTable,
L"Keypad Device",
TRUE
);
"eng", gKeypadComponentName.SupportedLanguages,
&ConsoleIn->ControllerNameTable, L"Keypad Device", TRUE);
AddUnicodeString2(
"en",
gKeypadComponentName2.SupportedLanguages,
&ConsoleIn->ControllerNameTable,
L"Keypad Device",
FALSE
);
"en", gKeypadComponentName2.SupportedLanguages,
&ConsoleIn->ControllerNameTable, L"Keypad Device", FALSE);
//
// Install protocol interfaces for the keypad device.
//
Status = gBS->InstallMultipleProtocolInterfaces(
&Controller,
&gEfiSimpleTextInProtocolGuid,
&ConsoleIn->ConIn,
&gEfiSimpleTextInputExProtocolGuid,
&ConsoleIn->ConInEx,
NULL
);
&Controller, &gEfiSimpleTextInProtocolGuid, &ConsoleIn->ConIn,
&gEfiSimpleTextInputExProtocolGuid, &ConsoleIn->ConInEx, NULL);
if (EFI_ERROR(Status)) {
goto ErrorExit;
}
@ -400,11 +337,8 @@ ErrorExit:
}
gBS->CloseProtocol(
Controller,
&gEFIDroidKeypadDeviceProtocolGuid,
This->DriverBindingHandle,
Controller
);
Controller, &gEFIDroidKeypadDeviceProtocolGuid, This->DriverBindingHandle,
Controller);
return Status;
}
@ -426,11 +360,8 @@ ErrorExit:
EFI_STATUS
EFIAPI
KeypadControllerDriverStop(
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
@ -440,24 +371,14 @@ KeypadControllerDriverStop (
// Disable Keypad
//
Status = gBS->OpenProtocol(
Controller,
&gEfiSimpleTextInProtocolGuid,
(VOID **) &ConIn,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
Controller, &gEfiSimpleTextInProtocolGuid, (VOID **)&ConIn,
This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR(Status)) {
return Status;
}
Status = gBS->OpenProtocol(
Controller,
&gEfiSimpleTextInputExProtocolGuid,
NULL,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
Controller, &gEfiSimpleTextInputExProtocolGuid, NULL,
This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_TEST_PROTOCOL);
if (EFI_ERROR(Status)) {
return Status;
}
@ -473,23 +394,15 @@ KeypadControllerDriverStop (
// Uninstall the SimpleTextIn and SimpleTextInEx protocols
//
Status = gBS->UninstallMultipleProtocolInterfaces(
Controller,
&gEfiSimpleTextInProtocolGuid,
&ConsoleIn->ConIn,
&gEfiSimpleTextInputExProtocolGuid,
&ConsoleIn->ConInEx,
NULL
);
Controller, &gEfiSimpleTextInProtocolGuid, &ConsoleIn->ConIn,
&gEfiSimpleTextInputExProtocolGuid, &ConsoleIn->ConInEx, NULL);
if (EFI_ERROR(Status)) {
return Status;
}
gBS->CloseProtocol(
Controller,
&gEFIDroidKeypadDeviceProtocolGuid,
This->DriverBindingHandle,
Controller
);
Controller, &gEFIDroidKeypadDeviceProtocolGuid, This->DriverBindingHandle,
Controller);
//
// Free other resources
@ -522,9 +435,7 @@ KeypadControllerDriverStop (
@retval EFI_SUCCESS Sucess to free NotifyList
**/
EFI_STATUS
KbdFreeNotifyList (
IN OUT LIST_ENTRY *ListHead
)
KbdFreeNotifyList(IN OUT LIST_ENTRY *ListHead)
{
KEYPAD_CONSOLE_IN_EX_NOTIFY *NotifyNode;
@ -532,12 +443,9 @@ KbdFreeNotifyList (
return EFI_INVALID_PARAMETER;
}
while (!IsListEmpty(ListHead)) {
NotifyNode = CR (
ListHead->ForwardLink,
KEYPAD_CONSOLE_IN_EX_NOTIFY,
NotifyEntry,
KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE
);
NotifyNode =
CR(ListHead->ForwardLink, KEYPAD_CONSOLE_IN_EX_NOTIFY, NotifyEntry,
KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
RemoveEntryList(ListHead->ForwardLink);
gBS->FreePool(NotifyNode);
}
@ -557,10 +465,7 @@ KbdFreeNotifyList (
**/
EFI_STATUS
EFIAPI
InitializeKeypad(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
InitializeKeypad(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
@ -568,16 +473,9 @@ InitializeKeypad(
// Install driver model protocol(s).
//
Status = EfiLibInstallDriverBindingComponentName2(
ImageHandle,
SystemTable,
&gKeypadControllerDriver,
ImageHandle,
&gKeypadComponentName,
&gKeypadComponentName2
);
ImageHandle, SystemTable, &gKeypadControllerDriver, ImageHandle,
&gKeypadComponentName, &gKeypadComponentName2);
ASSERT_EFI_ERROR(Status);
return Status;
}

View File

@ -3,9 +3,9 @@
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
are licensed and made available under the terms and conditions of the BSD
License which accompanies this distribution. The full text of the license may
be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@ -17,21 +17,21 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Uefi.h>
#include <Protocol/KeypadDevice.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/SimpleTextInEx.h>
#include <Protocol/KeypadDevice.h>
#include <Library/IoLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/TimerLib.h>
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/TimerLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
//
// Global Variables
@ -111,14 +111,12 @@ typedef struct {
EFI_EVENT KeyNotifyProcessEvent;
} KEYPAD_CONSOLE_IN_DEV;
#define KEYPAD_CONSOLE_IN_DEV_FROM_KEYPAD_RETURN_API(a) CR (a, KEYPAD_CONSOLE_IN_DEV, KeypadReturnApi, KEYPAD_CONSOLE_IN_DEV_SIGNATURE)
#define KEYPAD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYPAD_CONSOLE_IN_DEV, ConIn, KEYPAD_CONSOLE_IN_DEV_SIGNATURE)
#define KEYPAD_CONSOLE_IN_DEV_FROM_KEYPAD_RETURN_API(a) \
CR(a, KEYPAD_CONSOLE_IN_DEV, KeypadReturnApi, KEYPAD_CONSOLE_IN_DEV_SIGNATURE)
#define KEYPAD_CONSOLE_IN_DEV_FROM_THIS(a) \
CR(a, KEYPAD_CONSOLE_IN_DEV, ConIn, KEYPAD_CONSOLE_IN_DEV_SIGNATURE)
#define TEXT_INPUT_EX_KEYPAD_CONSOLE_IN_DEV_FROM_THIS(a) \
CR (a, \
KEYPAD_CONSOLE_IN_DEV, \
ConInEx, \
KEYPAD_CONSOLE_IN_DEV_SIGNATURE \
)
CR(a, KEYPAD_CONSOLE_IN_DEV, ConInEx, KEYPAD_CONSOLE_IN_DEV_SIGNATURE)
#define TABLE_END 0x0
@ -128,7 +126,8 @@ typedef struct {
// Driver entry point
//
/**
The user Entry Point for module KeypadDxe. The user code starts with this function.
The user Entry Point for module KeypadDxe. The user code starts with this
function.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@ -140,9 +139,7 @@ typedef struct {
EFI_STATUS
EFIAPI
InstallKeypadDriver(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable);
//
// Other functions that are used among .c files
@ -154,12 +151,7 @@ InstallKeypadDriver (
@param Event Indicates the event that invoke this function.
@param Context Indicates the calling context.
**/
VOID
EFIAPI
KeyNotifyProcessHandler (
IN EFI_EVENT Event,
IN VOID *Context
);
VOID EFIAPI KeyNotifyProcessHandler(IN EFI_EVENT Event, IN VOID *Context);
/**
Perform 8042 controller and keypad Initialization.
@ -174,9 +166,7 @@ KeyNotifyProcessHandler (
**/
EFI_STATUS
InitKeypad(
IN OUT KEYPAD_CONSOLE_IN_DEV *ConsoleIn,
IN BOOLEAN ExtendedVerification
);
IN OUT KEYPAD_CONSOLE_IN_DEV *ConsoleIn, IN BOOLEAN ExtendedVerification);
/**
Timer event handler: read a series of scancodes from 8042
@ -189,12 +179,7 @@ InitKeypad (
@param Context - A KEYPAD_CONSOLE_IN_DEV pointer
**/
VOID
EFIAPI
KeypadTimerHandler (
IN EFI_EVENT Event,
IN VOID *Context
);
VOID EFIAPI KeypadTimerHandler(IN EFI_EVENT Event, IN VOID *Context);
/**
logic reset keypad
@ -203,16 +188,14 @@ KeypadTimerHandler (
@param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL
@param ExtendedVerification Indicate that the driver may perform a more
exhaustive verification operation of the device during
reset, now this par is ignored in this driver
exhaustive verification operation of the device
during reset, now this par is ignored in this driver
**/
EFI_STATUS
EFIAPI
KeypadEfiReset(
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification);
/**
Implement SIMPLE_TEXT_IN.ReadKeyStroke().
@ -226,9 +209,7 @@ KeypadEfiReset (
EFI_STATUS
EFIAPI
KeypadReadKeyStroke(
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
);
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, OUT EFI_INPUT_KEY *Key);
/**
Event notification function for SIMPLE_TEXT_IN.WaitForKey event
@ -238,27 +219,17 @@ KeypadReadKeyStroke (
@param Context waitting context
**/
VOID
EFIAPI
KeypadWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
);
VOID EFIAPI KeypadWaitForKey(IN EFI_EVENT Event, IN VOID *Context);
/**
Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
Signal the event if there is key available
Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
event Signal the event if there is key available
@param Event event object
@param Context waiting context
**/
VOID
EFIAPI
KeypadWaitForKeyEx (
IN EFI_EVENT Event,
IN VOID *Context
);
VOID EFIAPI KeypadWaitForKeyEx(IN EFI_EVENT Event, IN VOID *Context);
//
// Simple Text Input Ex protocol function prototypes
@ -271,16 +242,15 @@ KeypadWaitForKeyEx (
@param ExtendedVerification - Driver may perform diagnostics on reset.
@retval EFI_SUCCESS - The device was reset.
@retval EFI_DEVICE_ERROR - The device is not functioning properly and could
not be reset.
@retval EFI_DEVICE_ERROR - The device is not functioning properly and
could not be reset.
**/
EFI_STATUS
EFIAPI
KeypadEfiResetEx(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
IN BOOLEAN ExtendedVerification);
/**
Reads the next keystroke from the input device. The WaitForKey Event can
@ -288,22 +258,20 @@ KeypadEfiResetEx (
@param This - Protocol instance pointer.
@param KeyData - A pointer to a buffer that is filled in with the keystroke
state data for the key that was pressed.
@param KeyData - A pointer to a buffer that is filled in with the
keystroke state data for the key that was pressed.
@retval EFI_SUCCESS - The keystroke information was returned.
@retval EFI_NOT_READY - There was no keystroke data availiable.
@retval EFI_DEVICE_ERROR - The keystroke information was not returned due to
hardware errors.
@retval EFI_DEVICE_ERROR - The keystroke information was not returned
due to hardware errors.
@retval EFI_INVALID_PARAMETER - KeyData is NULL.
**/
EFI_STATUS
EFIAPI
KeypadReadKeyStrokeEx(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
OUT EFI_KEY_DATA *KeyData
);
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, OUT EFI_KEY_DATA *KeyData);
/**
Set certain state for the input device.
@ -313,9 +281,10 @@ KeypadReadKeyStrokeEx (
state for the input device.
@retval EFI_SUCCESS - The device state was set successfully.
@retval EFI_DEVICE_ERROR - The device is not functioning correctly and could
not have the setting adjusted.
@retval EFI_UNSUPPORTED - The device does not have the ability to set its state.
@retval EFI_DEVICE_ERROR - The device is not functioning correctly and
could not have the setting adjusted.
@retval EFI_UNSUPPORTED - The device does not have the ability to set
its state.
@retval EFI_INVALID_PARAMETER - KeyToggleState is NULL.
**/
@ -323,51 +292,53 @@ EFI_STATUS
EFIAPI
KeypadSetState(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_TOGGLE_STATE *KeyToggleState
);
IN EFI_KEY_TOGGLE_STATE *KeyToggleState);
/**
Register a notification function for a particular keystroke for the input device.
Register a notification function for a particular keystroke for the input
device.
@param This - Protocol instance pointer.
@param KeyData - A pointer to a buffer that is filled in with the keystroke
information data for the key that was pressed.
@param KeyNotificationFunction - Points to the function to be called when the key
sequence is typed specified by KeyData.
@param NotifyHandle - Points to the unique handle assigned to the registered notification.
@param KeyData - A pointer to a buffer that is filled in
with the keystroke information data for the key that was pressed.
@param KeyNotificationFunction - Points to the function to be called when
the key sequence is typed specified by KeyData.
@param NotifyHandle - Points to the unique handle assigned to the
registered notification.
@retval EFI_SUCCESS - The notification function was registered successfully.
@retval EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
@retval EFI_SUCCESS - The notification function was registered
successfully.
@retval EFI_OUT_OF_RESOURCES - Unable to allocate resources for
necesssary data structures.
@retval EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
**/
EFI_STATUS
EFIAPI
KeypadRegisterKeyNotify(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_DATA *KeyData,
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_DATA *KeyData,
IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
OUT VOID **NotifyHandle
);
OUT VOID **NotifyHandle);
/**
Remove a registered notification function from a particular keystroke.
@param This - Protocol instance pointer.
@param NotificationHandle - The handle of the notification function being unregistered.
@param NotificationHandle - The handle of the notification function
being unregistered.
@retval EFI_SUCCESS - The notification function was unregistered successfully.
@retval EFI_SUCCESS - The notification function was unregistered
successfully.
@retval EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
@retval EFI_NOT_FOUND - Can not find the matching entry in database.
@retval EFI_NOT_FOUND - Can not find the matching entry in
database.
**/
EFI_STATUS
EFIAPI
KeypadUnregisterKeyNotify(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN VOID *NotificationHandle
);
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN VOID *NotificationHandle);
/**
Push one key data to the EFI key buffer.
@ -375,28 +346,21 @@ KeypadUnregisterKeyNotify (
@param Queue Pointer to instance of EFI_KEY_QUEUE.
@param KeyData The key data to push.
**/
VOID
PushEfikeyBufTail (
IN EFI_KEY_QUEUE *Queue,
IN EFI_KEY_DATA *KeyData
);
VOID PushEfikeyBufTail(IN EFI_KEY_QUEUE *Queue, IN EFI_KEY_DATA *KeyData);
/**
Judge whether is a registed key
@param RegsiteredData A pointer to a buffer that is filled in with the keystroke
state data for the key that was registered.
@param InputData A pointer to a buffer that is filled in with the keystroke
state data for the key that was pressed.
@param RegsiteredData A pointer to a buffer that is filled in with the
keystroke state data for the key that was registered.
@param InputData A pointer to a buffer that is filled in with the
keystroke state data for the key that was pressed.
@retval TRUE Key be pressed matches a registered key.
@retval FLASE Match failed.
**/
BOOLEAN
IsKeyRegistered (
IN EFI_KEY_DATA *RegsiteredData,
IN EFI_KEY_DATA *InputData
);
IsKeyRegistered(IN EFI_KEY_DATA *RegsiteredData, IN EFI_KEY_DATA *InputData);
#endif

View File

@ -3,9 +3,9 @@
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
are licensed and made available under the terms and conditions of the BSD
License which accompanies this distribution. The full text of the license may
be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@ -21,11 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@param ErrMsg Unicode string of error message
**/
VOID
KeypadError (
IN KEYPAD_CONSOLE_IN_DEV *ConsoleIn,
IN CHAR16 *ErrMsg
)
VOID KeypadError(IN KEYPAD_CONSOLE_IN_DEV *ConsoleIn, IN CHAR16 *ErrMsg)
{
ConsoleIn->KeypadErr = TRUE;
}
@ -41,12 +37,7 @@ KeypadError (
@param Context A KEYPAD_CONSOLE_IN_DEV pointer
**/
VOID
EFIAPI
KeypadTimerHandler (
IN EFI_EVENT Event,
IN VOID *Context
)
VOID EFIAPI KeypadTimerHandler(IN EFI_EVENT Event, IN VOID *Context)
{
EFI_TPL OldTpl;
@ -71,7 +62,9 @@ KeypadTimerHandler (
UINT64 DeltaCounter = CurrentCounterValue - ConsoleIn->Last;
ConsoleIn->Last = CurrentCounterValue;
ConsoleIn->KeypadDevice->GetKeys(ConsoleIn->KeypadDevice, &ConsoleIn->KeypadReturnApi, GetTimeInNanoSecond(DeltaCounter));
ConsoleIn->KeypadDevice->GetKeys(
ConsoleIn->KeypadDevice, &ConsoleIn->KeypadReturnApi,
GetTimeInNanoSecond(DeltaCounter));
//
// Leave critical section and return
@ -92,9 +85,7 @@ KeypadTimerHandler (
**/
EFI_STATUS
InitKeypad(
IN OUT KEYPAD_CONSOLE_IN_DEV *ConsoleIn,
IN BOOLEAN ExtendedVerification
)
IN OUT KEYPAD_CONSOLE_IN_DEV *ConsoleIn, IN BOOLEAN ExtendedVerification)
{
EFI_STATUS Status;
@ -131,8 +122,8 @@ InitKeypad (
if (!EFI_ERROR(Status)) {
return EFI_SUCCESS;
} else {
}
else {
return EFI_DEVICE_ERROR;
}
}

View File

@ -4,16 +4,15 @@
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
are licensed and made available under the terms and conditions of the BSD
License which accompanies this distribution. The full text of the license may
be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Keypad.h"
/**
@ -25,9 +24,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@retval FALSE The EFI key buffer isn't empty.
**/
BOOLEAN
IsEfikeyBufEmpty (
IN EFI_KEY_QUEUE *Queue
)
IsEfikeyBufEmpty(IN EFI_KEY_QUEUE *Queue)
{
return (BOOLEAN)(Queue->Head == Queue->Tail);
}
@ -42,10 +39,7 @@ IsEfikeyBufEmpty (
@retval EFI_NOT_READY There is no key data available.
**/
EFI_STATUS
PopEfikeyBufHead (
IN EFI_KEY_QUEUE *Queue,
OUT EFI_KEY_DATA *KeyData OPTIONAL
)
PopEfikeyBufHead(IN EFI_KEY_QUEUE *Queue, OUT EFI_KEY_DATA *KeyData OPTIONAL)
{
if (IsEfikeyBufEmpty(Queue)) {
return EFI_NOT_READY;
@ -66,11 +60,7 @@ PopEfikeyBufHead (
@param Queue Pointer to instance of EFI_KEY_QUEUE.
@param KeyData The key data to push.
**/
VOID
PushEfikeyBufTail (
IN EFI_KEY_QUEUE *Queue,
IN EFI_KEY_DATA *KeyData
)
VOID PushEfikeyBufTail(IN EFI_KEY_QUEUE *Queue, IN EFI_KEY_DATA *KeyData)
{
if ((Queue->Tail + 1) % KEYPAD_EFI_KEY_MAX_COUNT == Queue->Head) {
//
@ -85,20 +75,17 @@ PushEfikeyBufTail (
/**
Judge whether is a registed key
@param RegsiteredData A pointer to a buffer that is filled in with the keystroke
state data for the key that was registered.
@param InputData A pointer to a buffer that is filled in with the keystroke
state data for the key that was pressed.
@param RegsiteredData A pointer to a buffer that is filled in with the
keystroke state data for the key that was registered.
@param InputData A pointer to a buffer that is filled in with the
keystroke state data for the key that was pressed.
@retval TRUE Key be pressed matches a registered key.
@retval FLASE Match failed.
**/
BOOLEAN
IsKeyRegistered (
IN EFI_KEY_DATA *RegsiteredData,
IN EFI_KEY_DATA *InputData
)
IsKeyRegistered(IN EFI_KEY_DATA *RegsiteredData, IN EFI_KEY_DATA *InputData)
{
ASSERT(RegsiteredData != NULL && InputData != NULL);
@ -109,19 +96,21 @@ IsKeyRegistered (
}
//
// Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
// Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these
// state could be ignored.
//
if (RegsiteredData->KeyState.KeyShiftState != 0 &&
RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
RegsiteredData->KeyState.KeyShiftState !=
InputData->KeyState.KeyShiftState) {
return FALSE;
}
if (RegsiteredData->KeyState.KeyToggleState != 0 &&
RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
RegsiteredData->KeyState.KeyToggleState !=
InputData->KeyState.KeyToggleState) {
return FALSE;
}
return TRUE;
}
/**
@ -129,22 +118,20 @@ IsKeyRegistered (
be used to test for existance of a keystroke via WaitForEvent () call.
@param ConsoleInDev Keypad private structure
@param KeyData A pointer to a buffer that is filled in with the keystroke
state data for the key that was pressed.
@param KeyData A pointer to a buffer that is filled in with
the keystroke state data for the key that was pressed.
@retval EFI_SUCCESS The keystroke information was returned.
@retval EFI_NOT_READY There was no keystroke data availiable.
@retval EFI_DEVICE_ERROR The keystroke information was not returned due to
hardware errors.
@retval EFI_DEVICE_ERROR The keystroke information was not returned
due to hardware errors.
@retval EFI_INVALID_PARAMETER KeyData is NULL.
**/
EFI_STATUS
KeypadReadKeyStrokeWorker(
IN KEYPAD_CONSOLE_IN_DEV *ConsoleInDev,
OUT EFI_KEY_DATA *KeyData
)
IN KEYPAD_CONSOLE_IN_DEV *ConsoleInDev, OUT EFI_KEY_DATA *KeyData)
{
EFI_STATUS Status;
@ -163,7 +150,8 @@ KeypadReadKeyStrokeWorker (
if (ConsoleInDev->KeypadErr) {
Status = EFI_DEVICE_ERROR;
} else {
}
else {
Status = PopEfikeyBufHead(&ConsoleInDev->EfiKeyQueue, KeyData);
}
@ -172,20 +160,20 @@ KeypadReadKeyStrokeWorker (
}
/**
Perform 8042 controller and keypad initialization which implement SIMPLE_TEXT_IN.Reset()
Perform 8042 controller and keypad initialization which implement
SIMPLE_TEXT_IN.Reset()
@param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL
@param This Pointer to instance of
EFI_SIMPLE_TEXT_INPUT_PROTOCOL
@param ExtendedVerification Indicate that the driver may perform a more
exhaustive verification operation of the device during
reset, now this par is ignored in this driver
exhaustive verification operation of the device
during reset, now this par is ignored in this driver
**/
EFI_STATUS
EFIAPI
KeypadEfiReset(
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
{
EFI_STATUS Status;
KEYPAD_CONSOLE_IN_DEV *ConsoleIn;
@ -222,7 +210,8 @@ KeypadEfiReset (
}
/**
Retrieve key values for driver user which implement SIMPLE_TEXT_IN.ReadKeyStroke().
Retrieve key values for driver user which implement
SIMPLE_TEXT_IN.ReadKeyStroke().
@param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL
@param Key The output buffer for key value
@ -232,9 +221,7 @@ KeypadEfiReset (
EFI_STATUS
EFIAPI
KeypadReadKeyStroke(
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
)
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, OUT EFI_INPUT_KEY *Key)
{
EFI_STATUS Status;
KEYPAD_CONSOLE_IN_DEV *ConsoleIn;
@ -258,17 +245,21 @@ KeypadReadKeyStroke (
//
// If it is partial keystroke, skip it.
//
if (KeyData.Key.ScanCode == SCAN_NULL && KeyData.Key.UnicodeChar == CHAR_NULL) {
if (KeyData.Key.ScanCode == SCAN_NULL &&
KeyData.Key.UnicodeChar == CHAR_NULL) {
continue;
}
//
// Translate the CTRL-Alpha characters to their corresponding control value
// (ctrl-a = 0x0001 through ctrl-Z = 0x001A)
//
if ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) {
if ((KeyData.KeyState.KeyShiftState &
(EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) {
if (KeyData.Key.UnicodeChar >= L'a' && KeyData.Key.UnicodeChar <= L'z') {
KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar - L'a' + 1);
} else if (KeyData.Key.UnicodeChar >= L'A' && KeyData.Key.UnicodeChar <= L'Z') {
}
else if (
KeyData.Key.UnicodeChar >= L'A' && KeyData.Key.UnicodeChar <= L'Z') {
KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar - L'A' + 1);
}
}
@ -286,12 +277,7 @@ KeypadReadKeyStroke (
@param Context waitting context
**/
VOID
EFIAPI
KeypadWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
)
VOID EFIAPI KeypadWaitForKey(IN EFI_EVENT Event, IN VOID *Context)
{
EFI_TPL OldTpl;
KEYPAD_CONSOLE_IN_DEV *ConsoleIn;
@ -317,9 +303,9 @@ KeypadWaitForKey (
CopyMem(
&KeyData,
&(ConsoleIn->EfiKeyQueue.Buffer[ConsoleIn->EfiKeyQueue.Head]),
sizeof (EFI_KEY_DATA)
);
if (KeyData.Key.ScanCode == SCAN_NULL && KeyData.Key.UnicodeChar == CHAR_NULL) {
sizeof(EFI_KEY_DATA));
if (KeyData.Key.ScanCode == SCAN_NULL &&
KeyData.Key.UnicodeChar == CHAR_NULL) {
PopEfikeyBufHead(&ConsoleIn->EfiKeyQueue, &KeyData);
continue;
}
@ -337,19 +323,14 @@ KeypadWaitForKey (
}
/**
Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
Signal the event if there is key available
Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
event Signal the event if there is key available
@param Event event object
@param Context waiting context
**/
VOID
EFIAPI
KeypadWaitForKeyEx (
IN EFI_EVENT Event,
IN VOID *Context
)
VOID EFIAPI KeypadWaitForKeyEx(IN EFI_EVENT Event, IN VOID *Context)
{
KeypadWaitForKey(Event, Context);
@ -362,26 +343,21 @@ KeypadWaitForKeyEx (
@param ExtendedVerification Driver may perform diagnostics on reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
not be reset.
@retval EFI_DEVICE_ERROR The device is not functioning properly and
could not be reset.
**/
EFI_STATUS
EFIAPI
KeypadEfiResetEx(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
{
KEYPAD_CONSOLE_IN_DEV *ConsoleInDev;
ConsoleInDev = TEXT_INPUT_EX_KEYPAD_CONSOLE_IN_DEV_FROM_THIS(This);
return ConsoleInDev->ConIn.Reset (
&ConsoleInDev->ConIn,
ExtendedVerification
);
return ConsoleInDev->ConIn.Reset(&ConsoleInDev->ConIn, ExtendedVerification);
}
/**
@ -390,22 +366,20 @@ KeypadEfiResetEx (
@param This Protocol instance pointer.
@param KeyData A pointer to a buffer that is filled in with the keystroke
state data for the key that was pressed.
@param KeyData A pointer to a buffer that is filled in with the
keystroke state data for the key that was pressed.
@retval EFI_SUCCESS The keystroke information was returned.
@retval EFI_NOT_READY There was no keystroke data availiable.
@retval EFI_DEVICE_ERROR The keystroke information was not returned due to
hardware errors.
@retval EFI_DEVICE_ERROR The keystroke information was not returned due
to hardware errors.
@retval EFI_INVALID_PARAMETER KeyData is NULL.
**/
EFI_STATUS
EFIAPI
KeypadReadKeyStrokeEx(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
OUT EFI_KEY_DATA *KeyData
)
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, OUT EFI_KEY_DATA *KeyData)
{
KEYPAD_CONSOLE_IN_DEV *ConsoleInDev;
@ -426,9 +400,10 @@ KeypadReadKeyStrokeEx (
state for the input device.
@retval EFI_SUCCESS The device state was set successfully.
@retval EFI_DEVICE_ERROR The device is not functioning correctly and could
not have the setting adjusted.
@retval EFI_UNSUPPORTED The device does not have the ability to set its state.
@retval EFI_DEVICE_ERROR The device is not functioning correctly and
could not have the setting adjusted.
@retval EFI_UNSUPPORTED The device does not have the ability to set its
state.
@retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
**/
@ -436,8 +411,7 @@ EFI_STATUS
EFIAPI
KeypadSetState(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_TOGGLE_STATE *KeyToggleState
)
IN EFI_KEY_TOGGLE_STATE *KeyToggleState)
{
EFI_STATUS Status;
@ -493,32 +467,33 @@ Exit:
gBS->RestoreTPL(OldTpl);
return Status;
}
/**
Register a notification function for a particular keystroke for the input device.
Register a notification function for a particular keystroke for the input
device.
@param This Protocol instance pointer.
@param KeyData A pointer to a buffer that is filled in with the keystroke
information data for the key that was pressed.
@param KeyNotificationFunction Points to the function to be called when the key
sequence is typed specified by KeyData.
@param NotifyHandle Points to the unique handle assigned to the registered notification.
@param KeyData A pointer to a buffer that is filled in
with the keystroke information data for the key that was pressed.
@param KeyNotificationFunction Points to the function to be called when
the key sequence is typed specified by KeyData.
@param NotifyHandle Points to the unique handle assigned to
the registered notification.
@retval EFI_SUCCESS The notification function was registered successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
@retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
@retval EFI_SUCCESS The notification function was registered
successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate resources for
necesssary data structures.
@retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or
KeyNotificationFunction is NULL.
**/
EFI_STATUS
EFIAPI
KeypadRegisterKeyNotify(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_DATA *KeyData,
IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
OUT VOID **NotifyHandle
)
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_DATA *KeyData,
IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, OUT VOID **NotifyHandle)
{
EFI_STATUS Status;
KEYPAD_CONSOLE_IN_DEV * ConsoleInDev;
@ -527,7 +502,8 @@ KeypadRegisterKeyNotify (
KEYPAD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
KEYPAD_CONSOLE_IN_EX_NOTIFY *NewNotify;
if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {
if (KeyData == NULL || NotifyHandle == NULL ||
KeyNotificationFunction == NULL) {
return EFI_INVALID_PARAMETER;
}
@ -539,15 +515,14 @@ KeypadRegisterKeyNotify (
OldTpl = gBS->RaiseTPL(TPL_NOTIFY);
//
// Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
// Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already
// registered.
//
for (Link = ConsoleInDev->NotifyList.ForwardLink; Link != &ConsoleInDev->NotifyList; Link = Link->ForwardLink) {
CurrentNotify = CR (
Link,
KEYPAD_CONSOLE_IN_EX_NOTIFY,
NotifyEntry,
KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE
);
for (Link = ConsoleInDev->NotifyList.ForwardLink;
Link != &ConsoleInDev->NotifyList; Link = Link->ForwardLink) {
CurrentNotify =
CR(Link, KEYPAD_CONSOLE_IN_EX_NOTIFY, NotifyEntry,
KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
if (IsKeyRegistered(&CurrentNotify->KeyData, KeyData)) {
if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
*NotifyHandle = CurrentNotify;
@ -560,7 +535,8 @@ KeypadRegisterKeyNotify (
//
// Allocate resource to save the notification function
//
NewNotify = (KEYPAD_CONSOLE_IN_EX_NOTIFY *) AllocateZeroPool (sizeof (KEYPAD_CONSOLE_IN_EX_NOTIFY));
NewNotify = (KEYPAD_CONSOLE_IN_EX_NOTIFY *)AllocateZeroPool(
sizeof(KEYPAD_CONSOLE_IN_EX_NOTIFY));
if (NewNotify == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
@ -580,26 +556,25 @@ Exit:
//
gBS->RestoreTPL(OldTpl);
return Status;
}
/**
Remove a registered notification function from a particular keystroke.
@param This Protocol instance pointer.
@param NotificationHandle The handle of the notification function being unregistered.
@param NotificationHandle The handle of the notification function
being unregistered.
@retval EFI_SUCCESS The notification function was unregistered successfully.
@retval EFI_SUCCESS The notification function was unregistered
successfully.
@retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
**/
EFI_STATUS
EFIAPI
KeypadUnregisterKeyNotify(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN VOID *NotificationHandle
)
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN VOID *NotificationHandle)
{
EFI_STATUS Status;
KEYPAD_CONSOLE_IN_DEV * ConsoleInDev;
@ -618,13 +593,11 @@ KeypadUnregisterKeyNotify (
//
OldTpl = gBS->RaiseTPL(TPL_NOTIFY);
for (Link = ConsoleInDev->NotifyList.ForwardLink; Link != &ConsoleInDev->NotifyList; Link = Link->ForwardLink) {
CurrentNotify = CR (
Link,
KEYPAD_CONSOLE_IN_EX_NOTIFY,
NotifyEntry,
KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE
);
for (Link = ConsoleInDev->NotifyList.ForwardLink;
Link != &ConsoleInDev->NotifyList; Link = Link->ForwardLink) {
CurrentNotify =
CR(Link, KEYPAD_CONSOLE_IN_EX_NOTIFY, NotifyEntry,
KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
if (CurrentNotify == NotificationHandle) {
//
// Remove the notification function from NotifyList and free resources
@ -655,12 +628,7 @@ Exit:
@param Event Indicates the event that invoke this function.
@param Context Indicates the calling context.
**/
VOID
EFIAPI
KeyNotifyProcessHandler (
IN EFI_EVENT Event,
IN VOID *Context
)
VOID EFIAPI KeyNotifyProcessHandler(IN EFI_EVENT Event, IN VOID *Context)
{
EFI_STATUS Status;
KEYPAD_CONSOLE_IN_DEV * ConsoleIn;
@ -689,12 +657,14 @@ KeyNotifyProcessHandler (
if (EFI_ERROR(Status)) {
break;
}
for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {
CurrentNotify = CR (Link, KEYPAD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
for (Link = GetFirstNode(NotifyList); !IsNull(NotifyList, Link);
Link = GetNextNode(NotifyList, Link)) {
CurrentNotify =
CR(Link, KEYPAD_CONSOLE_IN_EX_NOTIFY, NotifyEntry,
KEYPAD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
if (IsKeyRegistered(&CurrentNotify->KeyData, &KeyData)) {
CurrentNotify->KeyNotificationFn(&KeyData);
}
}
}
}

View File

@ -20,9 +20,10 @@
#include "crc32.h"
#include <Library/UefiLib.h>
EFI_STATUS FixGptCRC32(EFI_BLOCK_IO_PROTOCOL *mBlockIoProtocol,
EFI_DISK_IO_PROTOCOL *mDiskIoProtocol,
EFI_SYSTEM_TABLE *mSystemTable){
EFI_STATUS FixGptCRC32(
EFI_BLOCK_IO_PROTOCOL *mBlockIoProtocol,
EFI_DISK_IO_PROTOCOL *mDiskIoProtocol, EFI_SYSTEM_TABLE *mSystemTable)
{
EFI_STATUS status;
UINT32 mMediaId;
UINT32 mBlockSize;
@ -33,28 +34,26 @@ EFI_STATUS FixGptCRC32(EFI_BLOCK_IO_PROTOCOL *mBlockIoProtocol,
unsigned char *bufGptHeader;
unsigned char *bufGptEntry;
// try to allocate pool for bufGptEntry
status = mSystemTable->BootServices->AllocatePool(EfiBootServicesCode, GPT_ENTRY_COUNT * mBlockSize, (VOID**)&bufGptEntry);
status = mSystemTable->BootServices->AllocatePool(
EfiBootServicesCode, GPT_ENTRY_COUNT * mBlockSize, (VOID **)&bufGptEntry);
if (EFI_ERROR(status)) {
return status;
}
// read gpt entry list
status = mDiskIoProtocol->ReadDisk(mDiskIoProtocol,
mMediaId,
2 * mBlockSize,
GPT_ENTRY_COUNT * mBlockSize,
status = mDiskIoProtocol->ReadDisk(
mDiskIoProtocol, mMediaId, 2 * mBlockSize, GPT_ENTRY_COUNT * mBlockSize,
bufGptEntry);
if (EFI_ERROR(status))
return status;
// get gpt entry crc32 value
get_result_array(calculate_crc32(bufGptEntry, GPT_ENTRY_COUNT * mBlockSize), crc32_entry);
get_result_array(
calculate_crc32(bufGptEntry, GPT_ENTRY_COUNT * mBlockSize), crc32_entry);
// write gpt entry crc32 value to disk
status = mDiskIoProtocol->WriteDisk(mDiskIoProtocol,
mMediaId,
mBlockSize + GPT_ENTRY_CRC32_LBA1_OFFSET,
GPT_CRC32_LEN,
crc32_entry);
status = mDiskIoProtocol->WriteDisk(
mDiskIoProtocol, mMediaId, mBlockSize + GPT_ENTRY_CRC32_LBA1_OFFSET,
GPT_CRC32_LEN, crc32_entry);
if (EFI_ERROR(status))
return status;
// try to release bufGptEntry
@ -63,27 +62,25 @@ EFI_STATUS FixGptCRC32(EFI_BLOCK_IO_PROTOCOL *mBlockIoProtocol,
return status;
}
// try to allocate pool for bufGptHeader
status = mSystemTable->BootServices->AllocatePool(EfiBootServicesCode, GPT_HEADER_SIZE, (VOID**)&bufGptHeader);
status = mSystemTable->BootServices->AllocatePool(
EfiBootServicesCode, GPT_HEADER_SIZE, (VOID **)&bufGptHeader);
// get gpt header
status = mDiskIoProtocol->ReadDisk(mDiskIoProtocol,
mMediaId,
mBlockSize,
GPT_HEADER_SIZE,
bufGptHeader);
status = mDiskIoProtocol->ReadDisk(
mDiskIoProtocol, mMediaId, mBlockSize, GPT_HEADER_SIZE, bufGptHeader);
if (EFI_ERROR(status))
return status;
// set previous crc32 value to 0x00
for (int i = GPT_HEADER_CRC32_LBA1_OFFSET; i < GPT_HEADER_CRC32_LBA1_OFFSET + GPT_CRC32_LEN; i++) {
for (int i = GPT_HEADER_CRC32_LBA1_OFFSET;
i < GPT_HEADER_CRC32_LBA1_OFFSET + GPT_CRC32_LEN; i++) {
bufGptHeader[i] = 0x00;
}
// get gpt header crc32 value
get_result_array(calculate_crc32(bufGptHeader, GPT_HEADER_SIZE), crc32_header);
get_result_array(
calculate_crc32(bufGptHeader, GPT_HEADER_SIZE), crc32_header);
// write gpt header crc32 value to disk
status = mDiskIoProtocol->WriteDisk(mDiskIoProtocol,
mMediaId,
mBlockSize + GPT_HEADER_CRC32_LBA1_OFFSET,
GPT_CRC32_LEN,
crc32_header);
status = mDiskIoProtocol->WriteDisk(
mDiskIoProtocol, mMediaId, mBlockSize + GPT_HEADER_CRC32_LBA1_OFFSET,
GPT_CRC32_LEN, crc32_header);
if (EFI_ERROR(status))
return status;
// try to release bufGptHeader
@ -154,5 +151,4 @@ void get_result_array(unsigned int reflected_regs, unsigned char * res)
res[i] = reflected_regs & 0xff;
reflected_regs >>= 8;
}
}

View File

@ -36,4 +36,5 @@ unsigned int calculate_crc32(unsigned char*, int);
void get_result_array(unsigned int, unsigned char *);
EFI_STATUS FixGptCRC32(EFI_BLOCK_IO_PROTOCOL*, EFI_DISK_IO_PROTOCOL*, EFI_SYSTEM_TABLE*);
EFI_STATUS FixGptCRC32(
EFI_BLOCK_IO_PROTOCOL *, EFI_DISK_IO_PROTOCOL *, EFI_SYSTEM_TABLE *);

View File

@ -16,17 +16,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/
*/
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Protocol/DiskIo.h>
#include <Protocol/BlockIo.h>
#include "slot.h"
#include "crc32.h"
#include <Library/UefiLib.h>
#include <Protocol/BlockIo.h>
#include <Protocol/DiskIo.h>
#include <Uefi.h>
void WaitAnyKey(EFI_SYSTEM_TABLE *mSystemTable);
EFI_STATUS EFIAPI SlotMain(IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI
SlotMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS status;
EFI_HANDLE * controllerHandles = NULL;
@ -39,10 +39,8 @@ EFI_STATUS EFIAPI SlotMain(IN EFI_HANDLE ImageHandle,
unsigned char currentSlotA[OP6T_SLOT_FLAG_SIZE];
unsigned char currentSlotB[OP6T_SLOT_FLAG_SIZE];
// list all Handles that installed DiskIoProtocol
status = SystemTable->BootServices->LocateHandleBuffer(ByProtocol,
&gEfiDiskIoProtocolGuid,
NULL,
&numHandles,
status = SystemTable->BootServices->LocateHandleBuffer(
ByProtocol, &gEfiDiskIoProtocolGuid, NULL, &numHandles,
&controllerHandles);
if (EFI_ERROR(status)) {
// WaitAnyKey(SystemTable);
@ -52,33 +50,31 @@ EFI_STATUS EFIAPI SlotMain(IN EFI_HANDLE ImageHandle,
for (handleIndex = 0; handleIndex < numHandles; handleIndex++) {
// open DiskIoProtocol on target handle
status = SystemTable->BootServices->HandleProtocol(
controllerHandles[handleIndex],
&gEfiDiskIoProtocolGuid,
controllerHandles[handleIndex], &gEfiDiskIoProtocolGuid,
(VOID **)&mDiskIoProtocol);
unsigned char slotNameBuffer[OP6T_SLOT_BOOT_BUFFER_LEN];
if (EFI_ERROR(status))
continue;
// open BlockIoProtocol on target handle
status = SystemTable->BootServices->HandleProtocol(
controllerHandles[handleIndex],
&gEfiBlockIoProtocolGuid,
controllerHandles[handleIndex], &gEfiBlockIoProtocolGuid,
(VOID **)&mBlockIoProtocol);
if (EFI_ERROR(status)) {
continue;
} else {
}
else {
// filter disk device by LogicalPartition
if (mBlockIoProtocol->Media->LogicalPartition)
continue;
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"The media is disk.\n");
SystemTable->ConOut->OutputString(
SystemTable->ConOut, L"The media is disk.\n");
mMediaId = mBlockIoProtocol->Media->MediaId;
mBlockSize = mBlockIoProtocol->Media->BlockSize;
// read buffers from disk
status = mDiskIoProtocol->ReadDisk(
mDiskIoProtocol,
mMediaId,
mDiskIoProtocol, mMediaId,
2 * mBlockSize + OP6T_SLOT_A_BOOT_BUFFER_LBA2_OFFSET,
OP6T_SLOT_BOOT_BUFFER_LEN,
slotNameBuffer);
OP6T_SLOT_BOOT_BUFFER_LEN, slotNameBuffer);
if (EFI_ERROR(status))
continue;
// filter disk device by the name of boot partition
@ -91,23 +87,20 @@ EFI_STATUS EFIAPI SlotMain(IN EFI_HANDLE ImageHandle,
}
if (i == 1)
continue;
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"The name of target partition is matched.\n");
SystemTable->ConOut->OutputString(
SystemTable->ConOut, L"The name of target partition is matched.\n");
// read flag of slot A
status = mDiskIoProtocol->ReadDisk(
mDiskIoProtocol,
mMediaId,
mDiskIoProtocol, mMediaId,
2 * mBlockSize + OP6T_SLOT_A_BOOT_FLAG_LBA2_OFFSET,
OP6T_SLOT_FLAG_SIZE,
currentSlotA);
OP6T_SLOT_FLAG_SIZE, currentSlotA);
if (EFI_ERROR(status))
return status;
// read flag of slot B
status = mDiskIoProtocol->ReadDisk(
mDiskIoProtocol,
mMediaId,
mDiskIoProtocol, mMediaId,
3 * mBlockSize + OP6T_SLOT_B_BOOT_FLAG_LBA3_OFFSET,
OP6T_SLOT_FLAG_SIZE,
currentSlotB);
OP6T_SLOT_FLAG_SIZE, currentSlotB);
if (EFI_ERROR(status))
return status;
@ -125,20 +118,18 @@ EFI_STATUS EFIAPI SlotMain(IN EFI_HANDLE ImageHandle,
else
flag_offset = 2 * mBlockSize + OP6T_SLOT_A_BOOT_FLAG_LBA2_OFFSET;
// write flag into disk
unsigned char f[1] = {OP6T_SLOT_FLAG_ACTIVE};
status = mDiskIoProtocol->WriteDisk(
mDiskIoProtocol,
mMediaId,
flag_offset,
OP6T_SLOT_FLAG_SIZE,
f);
mDiskIoProtocol, mMediaId, flag_offset, OP6T_SLOT_FLAG_SIZE, f);
if (EFI_ERROR(status)) {
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Failed to write flag into disk.\n");
SystemTable->ConOut->OutputString(
SystemTable->ConOut, L"Failed to write flag into disk.\n");
continue;
} else {
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Succeed to write flag into disk.\n");
}
else {
SystemTable->ConOut->OutputString(
SystemTable->ConOut, L"Succeed to write flag into disk.\n");
break;
}
}
@ -147,9 +138,11 @@ EFI_STATUS EFIAPI SlotMain(IN EFI_HANDLE ImageHandle,
if (mBlockIoProtocol != NULL) {
status = (FixGptCRC32(mBlockIoProtocol, mDiskIoProtocol, SystemTable));
if (EFI_ERROR(status))
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Failed to fix CRC32 value.\n");
SystemTable->ConOut->OutputString(
SystemTable->ConOut, L"Failed to fix CRC32 value.\n");
else
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Succeed to fix CRC32 value.\n");
SystemTable->ConOut->OutputString(
SystemTable->ConOut, L"Succeed to fix CRC32 value.\n");
}
// release memory
@ -159,10 +152,11 @@ EFI_STATUS EFIAPI SlotMain(IN EFI_HANDLE ImageHandle,
return EFI_SUCCESS;
}
void WaitAnyKey(EFI_SYSTEM_TABLE *mSystemTable) {
void WaitAnyKey(EFI_SYSTEM_TABLE *mSystemTable)
{
UINTN index = 0;
EFI_INPUT_KEY Key;
mSystemTable->BootServices->WaitForEvent(1, &mSystemTable->ConIn->WaitForKey, &index);
mSystemTable->BootServices->WaitForEvent(
1, &mSystemTable->ConIn->WaitForKey, &index);
mSystemTable->ConIn->ReadKeyStroke(mSystemTable->ConIn, &Key);
}

View File

@ -36,11 +36,13 @@ const unsigned char OP6T_SLOT_FLAG_BOOTABLE_6 = 0x2F;
const unsigned OP6T_SLOT_FLAG_BOOTABLE_7 = 0x37;
const unsigned OP6T_SLOT_FLAG_BOOTABLE = 0x37; /* defaultly set bootable the same as bootable_7 */
const unsigned OP6T_SLOT_FLAG_BOOTABLE =
0x37; /* defaultly set bootable the same as bootable_7 */
const unsigned OP6T_SLOT_FLAG_UNBOOTABLE = 0xBA;
// const unsigned OP6T_SLOT_FLAG_SUCCESSFUL = 0xFF; /* OP6T_SLOT_FLAG_SUCCESSFUL maybe uncorrect in this file */
// const unsigned OP6T_SLOT_FLAG_SUCCESSFUL = 0xFF; /* OP6T_SLOT_FLAG_SUCCESSFUL
// maybe uncorrect in this file */
#define OP6T_SLOT_FLAG_SIZE 1
@ -59,15 +61,16 @@ const unsigned OP6T_SLOT_FLAG_UNBOOTABLE = 0xBA;
* Find the right device by comparaing the partition name on the offset
*/
const unsigned char OP6T_SLOT_A_BOOT_BUFFER[] = {0x62, 0x00, 0x6F, 0x00, 0x6F,
0x00, 0x74, 0x00, 0x5F, 0x00, 0x61}; /* ACSII: b.o.o.t._.a */
const unsigned char OP6T_SLOT_A_BOOT_BUFFER[] = {
0x62, 0x00, 0x6F, 0x00, 0x6F, 0x00,
0x74, 0x00, 0x5F, 0x00, 0x61}; /* ACSII: b.o.o.t._.a */
const unsigned char OP6T_SLOT_B_BOOT_BUFFER[] = {0x62, 0x00, 0x6F, 0x00, 0x6F,
0x00, 0x74, 0x00, 0x5F, 0x00, 0x62}; /* ACSII: b.o.o.t._.b */
const unsigned char OP6T_SLOT_B_BOOT_BUFFER[] = {
0x62, 0x00, 0x6F, 0x00, 0x6F, 0x00,
0x74, 0x00, 0x5F, 0x00, 0x62}; /* ACSII: b.o.o.t._.b */
#define OP6T_SLOT_BOOT_BUFFER_LEN 11
#define OP6T_SLOT_A_BOOT_BUFFER_LBA2_OFFSET 0x538
#define OP6T_SLOT_B_BOOT_BUFFER_LBA3_OFFSET 0x338

View File

@ -15,21 +15,21 @@
**/
#include <Base.h>
#include <IndustryStandard/SmBios.h>
#include <Protocol/Smbios.h>
#include <Guid/SmBios.h>
#include <IndustryStandard/SmBios.h>
#include <Library/ArmLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/PrintLib.h>
#include <Library/TimeBaseLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/PrintLib.h>
#include <Protocol/Smbios.h>
/***********************************************************************
SMBIOS data definition TYPE0 BIOS Information
@ -41,14 +41,16 @@ SMBIOS_TABLE_TYPE0 mBIOSInfoType0 = {
0xE800, // BiosSegment
3, // BiosReleaseDate String
0, // BiosSize (in 64KB)
{ // BiosCharacteristics
{
// BiosCharacteristics
0, // Reserved :2; ///< Bits 0-1.
0, // Unknown :1;
0, // BiosCharacteristicsNotSupported :1;
0, // IsaIsSupported :1;
0, // McaIsSupported :1;
0, // EisaIsSupported :1;
1, // PciIsSupported :1; /// No PCIe support since we hide ECAM from the OS
1, // PciIsSupported :1; /// No PCIe support since
// we hide ECAM from the OS
0, // PcmciaIsSupported :1;
1, // PlugAndPlayIsSupported :1;
0, // ApmIsSupported :1;
@ -73,10 +75,12 @@ SMBIOS_TABLE_TYPE0 mBIOSInfoType0 = {
0, // PrinterIsSupported :1;
0, // CgaMonoIsSupported :1;
0, // NecPc98 :1;
0 // ReservedForVendor :32; ///< Bits 32-63. Bits 32-47 reserved for BIOS vendor
0 // ReservedForVendor :32; ///< Bits 32-63. Bits 32-47
// reserved for BIOS vendor
///< and bits 48-63 reserved for System Vendor.
},
{ // BIOSCharacteristicsExtensionBytes[]
{
// BIOSCharacteristicsExtensionBytes[]
0x03, // AcpiIsSupported :1;
// UsbLegacyIsSupported :1;
// AgpIsSupported :1;
@ -107,8 +111,7 @@ CHAR8 *mBIOSInfoType0Strings[] = {
mBiosVendor, // Vendor
mBiosVersion, // Version
mBiosDate, // Release Date
NULL
};
NULL};
/***********************************************************************
SMBIOS data definition TYPE1 System Information
@ -119,7 +122,10 @@ SMBIOS_TABLE_TYPE1 mSysInfoType1 = {
2, // ProductName String
3, // Version String
4, // SerialNumber String
{ 0x8A95D198, 0x7F46, 0x11E5, { 0xBF, 0x8B, 0x08, 0x00, 0x27, 0x04, 0xD4, 0x8E }},
{0x8A95D198,
0x7F46,
0x11E5,
{0xBF, 0x8B, 0x08, 0x00, 0x27, 0x04, 0xD4, 0x8E}},
SystemWakeupTypePowerSwitch,
5, // SKUNumber String
6, // Family String
@ -138,8 +144,7 @@ CHAR8 *mSysInfoType1Strings[] = {
mSysInfoSerial,
mSysInfoSKU,
"Snapdragon 845 Device",
NULL
};
NULL};
/***********************************************************************
SMBIOS data definition TYPE2 Board Information
@ -151,7 +156,8 @@ SMBIOS_TABLE_TYPE2 mBoardInfoType2 = {
3, // Version String
4, // SerialNumber String
5, // AssetTag String
{ // FeatureFlag
{
// FeatureFlag
1, // Motherboard :1;
0, // RequiresDaughterCard :1;
0, // Removable :1;
@ -175,8 +181,7 @@ CHAR8 *mBoardInfoType2Strings[] = {
mSysInfoSerial,
mChassisAssetTag,
"Portable",
NULL
};
NULL};
/***********************************************************************
SMBIOS data definition TYPE3 Enclosure Information
@ -200,12 +205,8 @@ SMBIOS_TABLE_TYPE3 mEnclosureInfoType3 = {
{{0}}, // ContainedElements[1];
};
CHAR8 *mEnclosureInfoType3Strings[] = {
mSysInfoManufName,
mSysInfoProductName,
mSysInfoSerial,
mChassisAssetTag,
NULL
};
mSysInfoManufName, mSysInfoProductName, mSysInfoSerial, mChassisAssetTag,
NULL};
/***********************************************************************
SMBIOS data definition TYPE4 Processor Information
@ -213,27 +214,32 @@ CHAR8 *mEnclosureInfoType3Strings[] = {
SMBIOS_TABLE_TYPE4 mProcessorInfoType4_a75 = {
{EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, sizeof(SMBIOS_TABLE_TYPE4), 0},
1, // Socket String
CentralProcessor, // ProcessorType; ///< The enumeration value from PROCESSOR_TYPE_DATA.
ProcessorFamilyIndicatorFamily2, // ProcessorFamily; ///< The enumeration value from PROCESSOR_FAMILY2_DATA.
CentralProcessor, // ProcessorType; ///< The enumeration value from
// PROCESSOR_TYPE_DATA.
ProcessorFamilyIndicatorFamily2, // ProcessorFamily; ///< The
// enumeration value from
// PROCESSOR_FAMILY2_DATA.
2, // ProcessorManufacture String;
{ // ProcessorId;
{0x00, 0x00, 0x00, 0x00},
{ 0x00, 0x00, 0x00, 0x00 }
},
{0x00, 0x00, 0x00, 0x00}},
3, // ProcessorVersion String;
{ // Voltage;
{
// Voltage;
0, // ProcessorVoltageCapability5V :1;
0, // ProcessorVoltageCapability3_3V :1;
0, // ProcessorVoltageCapability2_9V :1;
0, // ProcessorVoltageCapabilityReserved :1; ///< Bit 3, must be zero.
0, // ProcessorVoltageReserved :3; ///< Bits 4-6, must be zero.
0, // ProcessorVoltageReserved :3; ///< Bits 4-6, must be
// zero.
1 // ProcessorVoltageIndicateLegacy :1;
},
0, // ExternalClock;
2803, // MaxSpeed;
2803, // CurrentSpeed;
0x41, // Status;
ProcessorUpgradeOther, // ProcessorUpgrade; ///< The enumeration value from PROCESSOR_UPGRADE.
ProcessorUpgradeOther, // ProcessorUpgrade; ///< The enumeration
// value from PROCESSOR_UPGRADE.
0, // L1CacheHandle;
0, // L2CacheHandle;
0xFFFF, // L3CacheHandle;
@ -243,8 +249,8 @@ SMBIOS_TABLE_TYPE4 mProcessorInfoType4_a75 = {
4, // CoreCount;
4, // EnabledCoreCount;
0, // ThreadCount;
0xEC, // ProcessorCharacteristics; ///< The enumeration value from PROCESSOR_CHARACTERISTIC_FLAGS
// ProcessorReserved1 :1;
0xEC, // ProcessorCharacteristics; ///< The enumeration value from
// PROCESSOR_CHARACTERISTIC_FLAGS ProcessorReserved1 :1;
// ProcessorUnknown :1;
// Processor64BitCapble :1;
// ProcessorMultiCore :1;
@ -263,27 +269,32 @@ SMBIOS_TABLE_TYPE4 mProcessorInfoType4_a75 = {
SMBIOS_TABLE_TYPE4 mProcessorInfoType4_a55 = {
{EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, sizeof(SMBIOS_TABLE_TYPE4), 0},
1, // Socket String
CentralProcessor, // ProcessorType; ///< The enumeration value from PROCESSOR_TYPE_DATA.
ProcessorFamilyIndicatorFamily2, // ProcessorFamily; ///< The enumeration value from PROCESSOR_FAMILY2_DATA.
CentralProcessor, // ProcessorType; ///< The enumeration value from
// PROCESSOR_TYPE_DATA.
ProcessorFamilyIndicatorFamily2, // ProcessorFamily; ///< The
// enumeration value from
// PROCESSOR_FAMILY2_DATA.
2, // ProcessorManufacture String;
{ // ProcessorId;
{0x00, 0x00, 0x00, 0x00},
{ 0x00, 0x00, 0x00, 0x00 }
},
{0x00, 0x00, 0x00, 0x00}},
3, // ProcessorVersion String;
{ // Voltage;
{
// Voltage;
0, // ProcessorVoltageCapability5V :1;
0, // ProcessorVoltageCapability3_3V :1;
0, // ProcessorVoltageCapability2_9V :1;
0, // ProcessorVoltageCapabilityReserved :1; ///< Bit 3, must be zero.
0, // ProcessorVoltageReserved :3; ///< Bits 4-6, must be zero.
0, // ProcessorVoltageReserved :3; ///< Bits 4-6, must be
// zero.
1 // ProcessorVoltageIndicateLegacy :1;
},
0, // ExternalClock;
1766, // MaxSpeed;
1766, // CurrentSpeed;
0x41, // Status;
ProcessorUpgradeOther, // ProcessorUpgrade; ///< The enumeration value from PROCESSOR_UPGRADE.
ProcessorUpgradeOther, // ProcessorUpgrade; ///< The enumeration
// value from PROCESSOR_UPGRADE.
0, // L1CacheHandle;
0, // L2CacheHandle;
0xFFFF, // L3CacheHandle;
@ -293,8 +304,8 @@ SMBIOS_TABLE_TYPE4 mProcessorInfoType4_a55 = {
4, // CoreCount;
4, // EnabledCoreCount;
0, // ThreadCount;
0xEC, // ProcessorCharacteristics; ///< The enumeration value from PROCESSOR_CHARACTERISTIC_FLAGS
// ProcessorReserved1 :1;
0xEC, // ProcessorCharacteristics; ///< The enumeration value from
// PROCESSOR_CHARACTERISTIC_FLAGS ProcessorReserved1 :1;
// ProcessorUnknown :1;
// Processor64BitCapble :1;
// ProcessorMultiCore :1;
@ -313,11 +324,7 @@ SMBIOS_TABLE_TYPE4 mProcessorInfoType4_a55 = {
CHAR8 mCpuName[128] = "Qualcomm Snapdragon 845";
CHAR8 *mProcessorInfoType4Strings[] = {
"BGA-1156",
"Qualcomm",
"Snapdragon 845",
NULL
};
"BGA-1156", "Qualcomm", "Snapdragon 845", NULL};
/***********************************************************************
SMBIOS data definition TYPE7 Cache Information
@ -335,7 +342,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a75_L1I = {
// Reserved :6
0x0030, // Maximum Size
0x0030, // Install Size
{ // Supported SRAM Type
{
// Supported SRAM Type
0, // Other :1
1, // Unknown :1
0, // NonBurst :1
@ -345,7 +353,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a75_L1I = {
0, // Asynchronous :1
0 // Reserved :9
},
{ // Current SRAM Type
{
// Current SRAM Type
0, // Other :1
1, // Unknown :1
0, // NonBurst :1
@ -374,7 +383,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a55_L1I = {
// Reserved :6
0x0030, // Maximum Size
0x0030, // Install Size
{ // Supported SRAM Type
{
// Supported SRAM Type
0, // Other :1
1, // Unknown :1
0, // NonBurst :1
@ -384,7 +394,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a55_L1I = {
0, // Asynchronous :1
0 // Reserved :9
},
{ // Current SRAM Type
{
// Current SRAM Type
0, // Other :1
1, // Unknown :1
0, // NonBurst :1
@ -399,12 +410,7 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a55_L1I = {
CacheTypeInstruction, // System Cache Type
CacheAssociativity2Way // Associativity
};
CHAR8 *mCacheInfoType7Strings[] = {
"L1 Instruction",
"L1 Data",
"L2",
NULL
};
CHAR8 *mCacheInfoType7Strings[] = {"L1 Instruction", "L1 Data", "L2", NULL};
SMBIOS_TABLE_TYPE7 mCacheInfoType7_a75_L1D = {
{EFI_SMBIOS_TYPE_CACHE_INFORMATION, sizeof(SMBIOS_TABLE_TYPE7), 0},
@ -419,7 +425,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a75_L1D = {
// Reserved :6
0x0020, // Maximum Size
0x0020, // Install Size
{ // Supported SRAM Type
{
// Supported SRAM Type
0, // Other :1
1, // Unknown :1
0, // NonBurst :1
@ -429,7 +436,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a75_L1D = {
0, // Asynchronous :1
0 // Reserved :9
},
{ // Current SRAM Type
{
// Current SRAM Type
0, // Other :1
1, // Unknown :1
0, // NonBurst :1
@ -458,7 +466,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a55_L1D = {
// Reserved :6
0x0020, // Maximum Size
0x0020, // Install Size
{ // Supported SRAM Type
{
// Supported SRAM Type
0, // Other :1
1, // Unknown :1
0, // NonBurst :1
@ -468,7 +477,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a55_L1D = {
0, // Asynchronous :1
0 // Reserved :9
},
{ // Current SRAM Type
{
// Current SRAM Type
0, // Other :1
1, // Unknown :1
0, // NonBurst :1
@ -497,7 +507,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a75_L2 = {
// Reserved :6
0x0800, // Maximum Size
0x0800, // Install Size
{ // Supported SRAM Type
{
// Supported SRAM Type
0, // Other :1
0, // Unknown :1
1, // NonBurst :1
@ -507,7 +518,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a75_L2 = {
0, // Asynchronous :1
0 // Reserved :9
},
{ // Current SRAM Type
{
// Current SRAM Type
0, // Other :1
0, // Unknown :1
1, // NonBurst :1
@ -536,7 +548,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a55_L2 = {
// Reserved :6
0x0800, // Maximum Size
0x0800, // Install Size
{ // Supported SRAM Type
{
// Supported SRAM Type
0, // Other :1
1, // Unknown :1
0, // NonBurst :1
@ -546,7 +559,8 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a55_L2 = {
0, // Asynchronous :1
0 // Reserved :9
},
{ // Current SRAM Type
{
// Current SRAM Type
0, // Other :1
0, // Unknown :1
1, // NonBurst :1
@ -568,12 +582,17 @@ SMBIOS_TABLE_TYPE7 mCacheInfoType7_a55_L2 = {
SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_0 = {
{EFI_SMBIOS_TYPE_SYSTEM_SLOTS, sizeof(SMBIOS_TABLE_TYPE9), 0},
1, // SlotDesignation String
SlotTypePciExpressGen2X4, // SlotType; ///< The enumeration value from MISC_SLOT_TYPE.
SlotDataBusWidth1X, // SlotDataBusWidth; ///< The enumeration value from MISC_SLOT_DATA_BUS_WIDTH.
SlotUsageUnknown, // CurrentUsage; ///< The enumeration value from MISC_SLOT_USAGE.
SlotLengthShort, // SlotLength; ///< The enumeration value from MISC_SLOT_LENGTH.
SlotTypePciExpressGen2X4, // SlotType; ///< The enumeration
// value from MISC_SLOT_TYPE.
SlotDataBusWidth1X, // SlotDataBusWidth; ///< The enumeration value
// from MISC_SLOT_DATA_BUS_WIDTH.
SlotUsageUnknown, // CurrentUsage; ///< The enumeration value
// from MISC_SLOT_USAGE.
SlotLengthShort, // SlotLength; ///< The enumeration value
// from MISC_SLOT_LENGTH.
0, // SlotID;
{ // SlotCharacteristics1;
{
// SlotCharacteristics1;
1, // CharacteristicsUnknown :1;
0, // Provides50Volts :1;
0, // Provides33Volts :1;
@ -583,7 +602,8 @@ SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_0 = {
0, // ZoomVideoSupported :1;
0, // ModemRingResumeSupported:1;
},
{ // SlotCharacteristics2;
{
// SlotCharacteristics2;
1, // PmeSignalSupported :1;
0, // HotPlugDevicesSupported :1;
1, // SmbusSignalSupported :1;
@ -597,12 +617,17 @@ SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_0 = {
SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_1 = {
{EFI_SMBIOS_TYPE_SYSTEM_SLOTS, sizeof(SMBIOS_TABLE_TYPE9), 0},
2, // SlotDesignation String
SlotTypePciExpressGen2X4, // SlotType; ///< The enumeration value from MISC_SLOT_TYPE.
SlotDataBusWidth1X, // SlotDataBusWidth; ///< The enumeration value from MISC_SLOT_DATA_BUS_WIDTH.
SlotUsageUnknown, // CurrentUsage; ///< The enumeration value from MISC_SLOT_USAGE.
SlotLengthShort, // SlotLength; ///< The enumeration value from MISC_SLOT_LENGTH.
SlotTypePciExpressGen2X4, // SlotType; ///< The enumeration
// value from MISC_SLOT_TYPE.
SlotDataBusWidth1X, // SlotDataBusWidth; ///< The enumeration value
// from MISC_SLOT_DATA_BUS_WIDTH.
SlotUsageUnknown, // CurrentUsage; ///< The enumeration value
// from MISC_SLOT_USAGE.
SlotLengthShort, // SlotLength; ///< The enumeration value
// from MISC_SLOT_LENGTH.
0, // SlotID;
{ // SlotCharacteristics1;
{
// SlotCharacteristics1;
1, // CharacteristicsUnknown :1;
0, // Provides50Volts :1;
0, // Provides33Volts :1;
@ -612,7 +637,8 @@ SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_1 = {
0, // ZoomVideoSupported :1;
0, // ModemRingResumeSupported:1;
},
{ // SlotCharacteristics2;
{
// SlotCharacteristics2;
1, // PmeSignalSupported :1;
0, // HotPlugDevicesSupported :1;
1, // SmbusSignalSupported :1;
@ -626,12 +652,17 @@ SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_1 = {
SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_2 = {
{EFI_SMBIOS_TYPE_SYSTEM_SLOTS, sizeof(SMBIOS_TABLE_TYPE9), 0},
3, // SlotDesignation String
SlotTypePciExpressGen2X8, // SlotType; ///< The enumeration value from MISC_SLOT_TYPE.
SlotDataBusWidth4X, // SlotDataBusWidth; ///< The enumeration value from MISC_SLOT_DATA_BUS_WIDTH.
SlotUsageUnknown, // CurrentUsage; ///< The enumeration value from MISC_SLOT_USAGE.
SlotLengthShort, // SlotLength; ///< The enumeration value from MISC_SLOT_LENGTH.
SlotTypePciExpressGen2X8, // SlotType; ///< The enumeration
// value from MISC_SLOT_TYPE.
SlotDataBusWidth4X, // SlotDataBusWidth; ///< The enumeration value
// from MISC_SLOT_DATA_BUS_WIDTH.
SlotUsageUnknown, // CurrentUsage; ///< The enumeration value
// from MISC_SLOT_USAGE.
SlotLengthShort, // SlotLength; ///< The enumeration value
// from MISC_SLOT_LENGTH.
0, // SlotID;
{ // SlotCharacteristics1;
{
// SlotCharacteristics1;
1, // CharacteristicsUnknown :1;
0, // Provides50Volts :1;
0, // Provides33Volts :1;
@ -641,7 +672,8 @@ SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_2 = {
0, // ZoomVideoSupported :1;
0, // ModemRingResumeSupported:1;
},
{ // SlotCharacteristics2;
{
// SlotCharacteristics2;
1, // PmeSignalSupported :1;
0, // HotPlugDevicesSupported :1;
1, // SmbusSignalSupported :1;
@ -655,12 +687,17 @@ SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_2 = {
SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_3 = {
{EFI_SMBIOS_TYPE_SYSTEM_SLOTS, sizeof(SMBIOS_TABLE_TYPE9), 0},
4, // SlotDesignation String
SlotTypePciExpressGen2X16,// SlotType; ///< The enumeration value from MISC_SLOT_TYPE.
SlotDataBusWidth4X, // SlotDataBusWidth; ///< The enumeration value from MISC_SLOT_DATA_BUS_WIDTH.
SlotUsageUnknown, // CurrentUsage; ///< The enumeration value from MISC_SLOT_USAGE.
SlotLengthShort, // SlotLength; ///< The enumeration value from MISC_SLOT_LENGTH.
SlotTypePciExpressGen2X16, // SlotType; ///< The enumeration
// value from MISC_SLOT_TYPE.
SlotDataBusWidth4X, // SlotDataBusWidth; ///< The enumeration value
// from MISC_SLOT_DATA_BUS_WIDTH.
SlotUsageUnknown, // CurrentUsage; ///< The enumeration value
// from MISC_SLOT_USAGE.
SlotLengthShort, // SlotLength; ///< The enumeration value
// from MISC_SLOT_LENGTH.
0, // SlotID;
{ // SlotCharacteristics1;
{
// SlotCharacteristics1;
1, // CharacteristicsUnknown :1;
0, // Provides50Volts :1;
0, // Provides33Volts :1;
@ -670,7 +707,8 @@ SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_3 = {
0, // ZoomVideoSupported :1;
0, // ModemRingResumeSupported:1;
},
{ // SlotCharacteristics2;
{
// SlotCharacteristics2;
1, // PmeSignalSupported :1;
0, // HotPlugDevicesSupported :1;
1, // SmbusSignalSupported :1;
@ -682,13 +720,7 @@ SMBIOS_TABLE_TYPE9 mSysSlotInfoType9_3 = {
};
CHAR8 *mSysSlotInfoType9Strings[] = {
"PCIE Slot 0",
"PCIE Slot 1",
"PCIE Slot 2",
"PCIE Slot 3",
NULL
};
"PCIE Slot 0", "PCIE Slot 1", "PCIE Slot 2", "PCIE Slot 3", NULL};
/***********************************************************************
SMBIOS data definition TYPE 11 OEM Strings
@ -699,45 +731,51 @@ SMBIOS_TABLE_TYPE11 mOemStringsType11 = {
1 // StringCount
};
CHAR8 *mOemStringsType11Strings[] = {
"https://github.com/edk2-porting/edk2-sdm845",
NULL
};
"https://github.com/edk2-porting/edk2-sdm845", NULL};
/***********************************************************************
SMBIOS data definition TYPE16 Physical Memory ArrayInformation
************************************************************************/
SMBIOS_TABLE_TYPE16 mPhyMemArrayInfoType16 = {
{EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY, sizeof(SMBIOS_TABLE_TYPE16), 0},
MemoryArrayLocationSystemBoard, // Location; ///< The enumeration value from MEMORY_ARRAY_LOCATION.
MemoryArrayUseSystemMemory, // Use; ///< The enumeration value from MEMORY_ARRAY_USE.
MemoryErrorCorrectionNone, // MemoryErrorCorrection; ///< The enumeration value from MEMORY_ERROR_CORRECTION.
MemoryArrayLocationSystemBoard, // Location; ///< The
// enumeration value from
// MEMORY_ARRAY_LOCATION.
MemoryArrayUseSystemMemory, // Use; ///< The
// enumeration value from MEMORY_ARRAY_USE.
MemoryErrorCorrectionNone, // MemoryErrorCorrection; ///< The
// enumeration value from
// MEMORY_ERROR_CORRECTION.
0x800000, // MaximumCapacity;
0xFFFE, // MemoryErrorInformationHandle;
1, // NumberOfMemoryDevices;
0x00000000ULL, // ExtendedMaximumCapacity;
};
CHAR8 *mPhyMemArrayInfoType16Strings[] = {
NULL
};
CHAR8 *mPhyMemArrayInfoType16Strings[] = {NULL};
/***********************************************************************
SMBIOS data definition TYPE17 Memory Device Information
************************************************************************/
SMBIOS_TABLE_TYPE17 mMemDevInfoType17 = {
{EFI_SMBIOS_TYPE_MEMORY_DEVICE, sizeof(SMBIOS_TABLE_TYPE17), 0},
0, // MemoryArrayHandle; // Should match SMBIOS_TABLE_TYPE16.Handle, initialized at runtime, refer to PhyMemArrayInfoUpdateSmbiosType16()
0, // MemoryArrayHandle; // Should match SMBIOS_TABLE_TYPE16.Handle,
// initialized at runtime, refer to PhyMemArrayInfoUpdateSmbiosType16()
0xFFFE, // MemoryErrorInformationHandle; (not provided)
64, // TotalWidth; (unknown)
64, // DataWidth; (unknown)
0x2000, // Size; // When bit 15 is 0: Size in MB
// When bit 15 is 1: Size in KB, and continues in ExtendedSize
// initialized at runtime, refer to PhyMemArrayInfoUpdateSmbiosType16()
MemoryFormFactorRowOfChips, // FormFactor; ///< The enumeration value from MEMORY_FORM_FACTOR.
// initialized at runtime, refer to
// PhyMemArrayInfoUpdateSmbiosType16()
MemoryFormFactorRowOfChips, // FormFactor; ///< The
// enumeration value from MEMORY_FORM_FACTOR.
0, // DeviceSet;
1, // DeviceLocator String
2, // BankLocator String
MemoryTypeLpddr4, // MemoryType; ///< The enumeration value from MEMORY_DEVICE_TYPE.
{ // TypeDetail;
MemoryTypeLpddr4, // MemoryType; ///< The enumeration
// value from MEMORY_DEVICE_TYPE.
{
// TypeDetail;
0, // Reserved :1;
0, // Other :1;
0, // Unknown :1;
@ -766,8 +804,10 @@ SMBIOS_TABLE_TYPE17 mMemDevInfoType17 = {
0, // MinimumVoltage; (unknown)
0, // MaximumVoltage; (unknown)
0, // ConfiguredVoltage; (unknown)
MemoryTechnologyDram, // MemoryTechnology ///< The enumeration value from MEMORY_DEVICE_TECHNOLOGY
{{ // MemoryOperatingModeCapability
MemoryTechnologyDram, // MemoryTechnology ///< The
// enumeration value from MEMORY_DEVICE_TECHNOLOGY
{{
// MemoryOperatingModeCapability
0, // Reserved :1;
0, // Other :1;
0, // Unknown :1;
@ -782,33 +822,31 @@ SMBIOS_TABLE_TYPE17 mMemDevInfoType17 = {
0, // MemorySubsystemControllerManufacturerID (unknown)
0, // MemorySubsystemControllerProductID (unknown)
0, // NonVolatileSize
0xFFFFFFFFFFFFFFFFULL,// VolatileSize // initialized at runtime, refer to PhyMemArrayInfoUpdateSmbiosType16()
0xFFFFFFFFFFFFFFFFULL, // VolatileSize // initialized at runtime, refer to
// PhyMemArrayInfoUpdateSmbiosType16()
0, // CacheSize
0, // LogicalSize (since MemoryType is not MemoryTypeLogicalNonVolatileDevice)
0, // LogicalSize (since MemoryType is not
// MemoryTypeLogicalNonVolatileDevice)
0, // ExtendedSpeed,
0 // ExtendedConfiguredMemorySpeed
};
CHAR8 *mMemDevInfoType17Strings[] = {
"Builtin",
"BANK 0",
NULL
};
CHAR8 *mMemDevInfoType17Strings[] = {"Builtin", "BANK 0", NULL};
/***********************************************************************
SMBIOS data definition TYPE19 Memory Array Mapped Address Information
************************************************************************/
SMBIOS_TABLE_TYPE19 mMemArrMapInfoType19 = {
{ EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS, sizeof (SMBIOS_TABLE_TYPE19), 0 },
{EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS, sizeof(SMBIOS_TABLE_TYPE19),
0},
0xFFFFFFFF, // StartingAddress;
0xFFFFFFFF, // EndingAddress;
0, // MemoryArrayHandle; // Should match SMBIOS_TABLE_TYPE16.Handle, initialized at runtime, refer to PhyMemArrayInfoUpdateSmbiosType16()
0, // MemoryArrayHandle; // Should match SMBIOS_TABLE_TYPE16.Handle,
// initialized at runtime, refer to PhyMemArrayInfoUpdateSmbiosType16()
1, // PartitionWidth;
0x080000000, // ExtendedStartingAddress; // not used
0x100000000, // ExtendedEndingAddress; // not used
};
CHAR8 *mMemArrMapInfoType19Strings[] = {
NULL
};
CHAR8 *mMemArrMapInfoType19Strings[] = {NULL};
/***********************************************************************
SMBIOS data definition TYPE32 Boot Information
@ -819,9 +857,7 @@ SMBIOS_TABLE_TYPE32 mBootInfoType32 = {
BootInformationStatusNoError // BootStatus
};
CHAR8 *mBootInfoType32Strings[] = {
NULL
};
CHAR8 *mBootInfoType32Strings[] = {NULL};
/**
@ -832,8 +868,8 @@ CHAR8 *mBootInfoType32Strings[] = {
and terminated via a double NULL and add to SMBIOS table.
SMBIOS_TABLE_TYPE32 gSmbiosType12 = {
{ EFI_SMBIOS_TYPE_SYSTEM_CONFIGURATION_OPTIONS, sizeof (SMBIOS_TABLE_TYPE12), 0 },
1 // StringCount
{ EFI_SMBIOS_TYPE_SYSTEM_CONFIGURATION_OPTIONS, sizeof (SMBIOS_TABLE_TYPE12),
0 }, 1 // StringCount
};
CHAR8 *gSmbiosType12Strings[] = {
@ -858,10 +894,8 @@ CHAR8 *mBootInfoType32Strings[] = {
EFI_STATUS
EFIAPI
LogSmbiosData(
IN EFI_SMBIOS_TABLE_HEADER *Template,
IN CHAR8 **StringPack,
OUT EFI_SMBIOS_HANDLE *DataSmbiosHandle
)
IN EFI_SMBIOS_TABLE_HEADER *Template, IN CHAR8 **StringPack,
OUT EFI_SMBIOS_HANDLE *DataSmbiosHandle)
{
EFI_STATUS Status;
EFI_SMBIOS_PROTOCOL * Smbios;
@ -887,7 +921,8 @@ LogSmbiosData (
if (StringPack == NULL) {
// At least a double null is required
Size += 2;
} else {
}
else {
for (Index = 0; StringPack[Index] != NULL; Index++) {
StringSize = AsciiStrSize(StringPack[Index]);
Size += StringSize;
@ -919,12 +954,7 @@ LogSmbiosData (
*Str = 0;
SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
Status = Smbios->Add (
Smbios,
gImageHandle,
&SmbiosHandle,
Record
);
Status = Smbios->Add(Smbios, gImageHandle, &SmbiosHandle, Record);
if ((Status == EFI_SUCCESS) && (DataSmbiosHandle != NULL)) {
*DataSmbiosHandle = SmbiosHandle;
@ -938,73 +968,120 @@ LogSmbiosData (
EFI_STATUS
EFIAPI
PlatformSmbiosDriverEntryPoint(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_SMBIOS_HANDLE SmbiosHandle;
// TYPE0 BIOS Information
AsciiSPrint (mBiosVersion, sizeof (mBiosVersion), "edk2-sdm845 %s", (CHAR16 *)FixedPcdGetPtr(PcdFirmwareVersionString));
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mBIOSInfoType0, mBIOSInfoType0Strings, NULL);
AsciiSPrint(
mBiosVersion, sizeof(mBiosVersion), "edk2-sdm845 %s",
(CHAR16 *)FixedPcdGetPtr(PcdFirmwareVersionString));
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mBIOSInfoType0, mBIOSInfoType0Strings, NULL);
// TYPE1 System Information
AsciiStrCpyS (mSysInfoManufName, sizeof(mSysInfoManufName), (CHAR8*)PcdGetPtr(PcdDeviceVendor));
AsciiStrCpyS (mSysInfoProductName, sizeof(mSysInfoProductName), (CHAR8*)PcdGetPtr(PcdDeviceProduct));
AsciiStrCpyS (mSysInfoVersionName, sizeof(mSysInfoVersionName), (CHAR8*)PcdGetPtr(PcdDeviceCodeName));
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mSysInfoType1, mSysInfoType1Strings, NULL);
AsciiStrCpyS(
mSysInfoManufName, sizeof(mSysInfoManufName),
(CHAR8 *)PcdGetPtr(PcdDeviceVendor));
AsciiStrCpyS(
mSysInfoProductName, sizeof(mSysInfoProductName),
(CHAR8 *)PcdGetPtr(PcdDeviceProduct));
AsciiStrCpyS(
mSysInfoVersionName, sizeof(mSysInfoVersionName),
(CHAR8 *)PcdGetPtr(PcdDeviceCodeName));
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mSysInfoType1, mSysInfoType1Strings, NULL);
// TYPE3 Enclosure Information
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mEnclosureInfoType3, mEnclosureInfoType3Strings, &SmbiosHandle);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mEnclosureInfoType3,
mEnclosureInfoType3Strings, &SmbiosHandle);
mBoardInfoType2.ChassisHandle = (UINT16)SmbiosHandle;
// TYPE2 Board Information
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mBoardInfoType2, mBoardInfoType2Strings, NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mBoardInfoType2, mBoardInfoType2Strings,
NULL);
// TYPE7 Cache Information
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mCacheInfoType7_a75_L1I, mCacheInfoType7Strings, NULL);
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mCacheInfoType7_a55_L1I, mCacheInfoType7Strings, NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mCacheInfoType7_a75_L1I,
mCacheInfoType7Strings, NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mCacheInfoType7_a55_L1I,
mCacheInfoType7Strings, NULL);
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mCacheInfoType7_a75_L1D, mCacheInfoType7Strings, &SmbiosHandle);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mCacheInfoType7_a75_L1D,
mCacheInfoType7Strings, &SmbiosHandle);
mProcessorInfoType4_a75.L1CacheHandle = (UINT16)SmbiosHandle;
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mCacheInfoType7_a55_L1D, mCacheInfoType7Strings, &SmbiosHandle);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mCacheInfoType7_a55_L1D,
mCacheInfoType7Strings, &SmbiosHandle);
mProcessorInfoType4_a55.L1CacheHandle = (UINT16)SmbiosHandle;
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mCacheInfoType7_a75_L2, mCacheInfoType7Strings, &SmbiosHandle);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mCacheInfoType7_a75_L2,
mCacheInfoType7Strings, &SmbiosHandle);
mProcessorInfoType4_a75.L2CacheHandle = (UINT16)SmbiosHandle;
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mCacheInfoType7_a55_L2, mCacheInfoType7Strings, &SmbiosHandle);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mCacheInfoType7_a55_L2,
mCacheInfoType7Strings, &SmbiosHandle);
mProcessorInfoType4_a55.L2CacheHandle = (UINT16)SmbiosHandle;
// TYPE4 Processor Information
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mProcessorInfoType4_a75, mProcessorInfoType4Strings, NULL);
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mProcessorInfoType4_a55, mProcessorInfoType4Strings, NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mProcessorInfoType4_a75,
mProcessorInfoType4Strings, NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mProcessorInfoType4_a55,
mProcessorInfoType4Strings, NULL);
// TYPE9 System Slot Information
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mSysSlotInfoType9_0, mSysSlotInfoType9Strings, NULL);
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mSysSlotInfoType9_1, mSysSlotInfoType9Strings, NULL);
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mSysSlotInfoType9_2, mSysSlotInfoType9Strings, NULL);
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mSysSlotInfoType9_3, mSysSlotInfoType9Strings, NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mSysSlotInfoType9_0, mSysSlotInfoType9Strings,
NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mSysSlotInfoType9_1, mSysSlotInfoType9Strings,
NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mSysSlotInfoType9_2, mSysSlotInfoType9Strings,
NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mSysSlotInfoType9_3, mSysSlotInfoType9Strings,
NULL);
// TYPE11 OEM Strings
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mOemStringsType11, mOemStringsType11Strings, NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mOemStringsType11, mOemStringsType11Strings,
NULL);
// TYPE16 Physical Memory Array Information
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mPhyMemArrayInfoType16, mPhyMemArrayInfoType16Strings, &SmbiosHandle);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mPhyMemArrayInfoType16,
mPhyMemArrayInfoType16Strings, &SmbiosHandle);
mMemDevInfoType17.MemoryArrayHandle = SmbiosHandle;
mMemArrMapInfoType19.MemoryArrayHandle = SmbiosHandle;
// TYPE17 Memory Device Information
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mMemDevInfoType17, mMemDevInfoType17Strings, NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mMemDevInfoType17, mMemDevInfoType17Strings,
NULL);
// TYPE19 Memory Array Map Information
mMemArrMapInfoType19.ExtendedStartingAddress = PcdGet64(PcdSystemMemoryBase);
mMemArrMapInfoType19.ExtendedEndingAddress = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize);
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mMemArrMapInfoType19, mMemArrMapInfoType19Strings, NULL);
mMemArrMapInfoType19.ExtendedEndingAddress =
PcdGet64(PcdSystemMemoryBase) + PcdGet64(PcdSystemMemorySize);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mMemArrMapInfoType19,
mMemArrMapInfoType19Strings, NULL);
// TYPE32 Boot Information
LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mBootInfoType32, mBootInfoType32Strings, NULL);
LogSmbiosData(
(EFI_SMBIOS_TABLE_HEADER *)&mBootInfoType32, mBootInfoType32Strings,
NULL);
return EFI_SUCCESS;
}

View File

@ -1,17 +1,17 @@
/* SimpleFbDxe: Simple FrameBuffer */
#include <PiDxe.h>
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Protocol/GraphicsOutput.h>
#include <Library/BaseLib.h>
#include <Library/FrameBufferBltLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/DebugLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/FrameBufferBltLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <PiDxe.h>
#include <Protocol/GraphicsOutput.h>
#include <Uefi.h>
/// Defines
/*
@ -42,28 +42,17 @@ typedef struct {
EFI_DEVICE_PATH EndDevicePath;
} DISPLAY_DEVICE_PATH;
DISPLAY_DEVICE_PATH mDisplayDevicePath =
{
{
{
HARDWARE_DEVICE_PATH,
DISPLAY_DEVICE_PATH mDisplayDevicePath = {
{{HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8)(sizeof(VENDOR_DEVICE_PATH)),
(UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8),
}
},
EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
},
{
END_DEVICE_PATH_TYPE,
}},
EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID},
{END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{
sizeof(EFI_DEVICE_PATH_PROTOCOL),
0
}
}
};
{sizeof(EFI_DEVICE_PATH_PROTOCOL), 0}}};
/// Declares
@ -73,62 +62,39 @@ STATIC UINTN mFrameBufferBltLibConfigureSize;
STATIC
EFI_STATUS
EFIAPI
DisplayQueryMode
(
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber,
OUT UINTN *SizeOfInfo,
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
);
DisplayQueryMode(
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber,
OUT UINTN *SizeOfInfo, OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info);
STATIC
EFI_STATUS
EFIAPI
DisplaySetMode
(
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber
);
DisplaySetMode(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber);
STATIC
EFI_STATUS
EFIAPI
DisplayBlt
(
DisplayBlt(
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
IN UINTN SourceX,
IN UINTN SourceY,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height,
IN UINTN Delta OPTIONAL
);
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL * BltBuffer,
OPTIONAL IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX,
IN UINTN DestinationY, IN UINTN Width, IN UINTN Height,
IN UINTN Delta OPTIONAL);
STATIC EFI_GRAPHICS_OUTPUT_PROTOCOL mDisplay = {
DisplayQueryMode,
DisplaySetMode,
DisplayBlt,
NULL
};
DisplayQueryMode, DisplaySetMode, DisplayBlt, NULL};
STATIC
EFI_STATUS
EFIAPI
DisplayQueryMode
(
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber,
OUT UINTN *SizeOfInfo,
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
)
DisplayQueryMode(
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber,
OUT UINTN *SizeOfInfo, OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info)
{
EFI_STATUS Status;
Status = gBS->AllocatePool(
EfiBootServicesData,
sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION),
EfiBootServicesData, sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION),
(VOID **)Info);
ASSERT_EFI_ERROR(Status);
@ -146,11 +112,7 @@ DisplayQueryMode
STATIC
EFI_STATUS
EFIAPI
DisplaySetMode
(
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber
)
DisplaySetMode(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber)
{
return EFI_SUCCESS;
}
@ -158,42 +120,32 @@ DisplaySetMode
STATIC
EFI_STATUS
EFIAPI
DisplayBlt
(
DisplayBlt(
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
IN UINTN SourceX,
IN UINTN SourceY,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height,
IN UINTN Delta OPTIONAL
)
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL * BltBuffer,
OPTIONAL IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX,
IN UINTN DestinationY, IN UINTN Width, IN UINTN Height,
IN UINTN Delta OPTIONAL)
{
RETURN_STATUS Status;
EFI_TPL Tpl;
//
// We have to raise to TPL_NOTIFY, so we make an atomic write to the frame buffer.
// We would not want a timer based event (Cursor, ...) to come in while we are
// doing this operation.
// We have to raise to TPL_NOTIFY, so we make an atomic write to the frame
// buffer. We would not want a timer based event (Cursor, ...) to come in
// while we are doing this operation.
//
Tpl = gBS->RaiseTPL(TPL_NOTIFY);
Status = FrameBufferBlt(
mFrameBufferBltLibConfigure,
BltBuffer,
BltOperation,
SourceX, SourceY,
DestinationX, DestinationY, Width, Height,
Delta
);
mFrameBufferBltLibConfigure, BltBuffer, BltOperation, SourceX, SourceY,
DestinationX, DestinationY, Width, Height, Delta);
gBS->RestoreTPL(Tpl);
// zhuowei: hack: flush the cache manually since my memory maps are still broken
WriteBackInvalidateDataCacheRange((void*)mDisplay.Mode->FrameBufferBase,
mDisplay.Mode->FrameBufferSize);
// zhuowei: hack: flush the cache manually since my memory maps are still
// broken
WriteBackInvalidateDataCacheRange(
(void *)mDisplay.Mode->FrameBufferBase, mDisplay.Mode->FrameBufferSize);
// zhuowei: end hack
return RETURN_ERROR(Status) ? EFI_INVALID_PARAMETER : EFI_SUCCESS;
@ -201,54 +153,49 @@ DisplayBlt
EFI_STATUS
EFIAPI
SimpleFbDxeInitialize
(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
SimpleFbDxeInitialize(
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_HANDLE hUEFIDisplayHandle = NULL;
/* Retrieve simple frame buffer from pre-SEC bootloader */
DEBUG((EFI_D_ERROR, "SimpleFbDxe: Retrieve MIPI FrameBuffer parameters from PCD\n"));
DEBUG(
(EFI_D_ERROR,
"SimpleFbDxe: Retrieve MIPI FrameBuffer parameters from PCD\n"));
UINT32 MipiFrameBufferAddr = FixedPcdGet32(PcdMipiFrameBufferAddress);
UINT32 MipiFrameBufferWidth = FixedPcdGet32(PcdMipiFrameBufferWidth);
UINT32 MipiFrameBufferHeight = FixedPcdGet32(PcdMipiFrameBufferHeight);
/* Sanity check */
if (MipiFrameBufferAddr == 0 || MipiFrameBufferWidth == 0 || MipiFrameBufferHeight == 0)
{
if (MipiFrameBufferAddr == 0 || MipiFrameBufferWidth == 0 ||
MipiFrameBufferHeight == 0) {
DEBUG((EFI_D_ERROR, "SimpleFbDxe: Invalid FrameBuffer parameters\n"));
return EFI_DEVICE_ERROR;
}
/* Prepare struct */
if (mDisplay.Mode == NULL)
{
if (mDisplay.Mode == NULL) {
Status = gBS->AllocatePool(
EfiBootServicesData,
sizeof(EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE),
(VOID **) &mDisplay.Mode
);
EfiBootServicesData, sizeof(EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE),
(VOID **)&mDisplay.Mode);
ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status)) return Status;
if (EFI_ERROR(Status))
return Status;
ZeroMem(mDisplay.Mode, sizeof(EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE));
}
if (mDisplay.Mode->Info == NULL)
{
if (mDisplay.Mode->Info == NULL) {
Status = gBS->AllocatePool(
EfiBootServicesData,
sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION),
(VOID **) &mDisplay.Mode->Info
);
EfiBootServicesData, sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION),
(VOID **)&mDisplay.Mode->Info);
ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status)) return Status;
if (EFI_ERROR(Status))
return Status;
ZeroMem(mDisplay.Mode->Info, sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
}
@ -276,42 +223,33 @@ SimpleFbDxeInitialize
// Create the FrameBufferBltLib configuration.
//
Status = FrameBufferBltConfigure(
(VOID *) (UINTN) mDisplay.Mode->FrameBufferBase,
mDisplay.Mode->Info,
mFrameBufferBltLibConfigure,
&mFrameBufferBltLibConfigureSize
);
(VOID *)(UINTN)mDisplay.Mode->FrameBufferBase, mDisplay.Mode->Info,
mFrameBufferBltLibConfigure, &mFrameBufferBltLibConfigureSize);
if (Status == RETURN_BUFFER_TOO_SMALL) {
mFrameBufferBltLibConfigure = AllocatePool(mFrameBufferBltLibConfigureSize);
if (mFrameBufferBltLibConfigure != NULL) {
Status = FrameBufferBltConfigure(
(VOID *) (UINTN) mDisplay.Mode->FrameBufferBase,
mDisplay.Mode->Info,
mFrameBufferBltLibConfigure,
&mFrameBufferBltLibConfigureSize
);
(VOID *)(UINTN)mDisplay.Mode->FrameBufferBase, mDisplay.Mode->Info,
mFrameBufferBltLibConfigure, &mFrameBufferBltLibConfigureSize);
}
}
ASSERT_EFI_ERROR(Status);
// zhuowei: clear the screen to black
// UEFI standard requires this, since text is white - see OvmfPkg/QemuVideoDxe/Gop.c
// UEFI standard requires this, since text is white - see
// OvmfPkg/QemuVideoDxe/Gop.c
ZeroMem((void *)FrameBufferAddress, FrameBufferSize);
// hack: clear cache
WriteBackInvalidateDataCacheRange((void*)FrameBufferAddress, FrameBufferSize);
WriteBackInvalidateDataCacheRange(
(void *)FrameBufferAddress, FrameBufferSize);
// zhuowei: end
/* Register handle */
Status = gBS->InstallMultipleProtocolInterfaces(
&hUEFIDisplayHandle,
&gEfiDevicePathProtocolGuid,
&mDisplayDevicePath,
&gEfiGraphicsOutputProtocolGuid,
&mDisplay,
NULL);
&hUEFIDisplayHandle, &gEfiDevicePathProtocolGuid, &mDisplayDevicePath,
&gEfiGraphicsOutputProtocolGuid, &mDisplay, NULL);
ASSERT_EFI_ERROR(Status);
return Status;
}

View File

@ -4,9 +4,9 @@
Copyright (c) 2015, ARM Limited. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
are licensed and made available under the terms and conditions of the BSD
License which accompanies this distribution. The full text of the license may
be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@ -72,19 +72,15 @@
"PCIE_SLOT2\0" /* Slot2 */ \
"PCIE_SLOT3\0" /* Slot3 */
#define TYPE16_STRINGS \
"\0" /* nothing */
#define TYPE16_STRINGS "\0" /* nothing */
#define TYPE17_STRINGS \
"RIGHT SIDE\0" /* location */ \
"BANK 0\0" /* bank description */
#define TYPE19_STRINGS \
"\0" /* nothing */
#define TYPE32_STRINGS \
"\0" /* nothing */
#define TYPE19_STRINGS "\0" /* nothing */
#define TYPE32_STRINGS "\0" /* nothing */
//
// Type definition and contents of the default SMBIOS table.
@ -166,14 +162,16 @@ enum SMBIOS_REFRENCE_HANDLES {
SMBIOS_HANDLE_DIMM
};
#define SERIAL_LEN 10 //this must be less than the buffer len allocated in the type1 structure
#define SERIAL_LEN \
10 // this must be less than the buffer len allocated in the type1 structure
#pragma pack()
// BIOS information (section 7.1)
STATIC ARM_TYPE0 mArmDefaultType0 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE0), // UINT8 Length
SMBIOS_HANDLE_PI_RESERVED,
@ -194,7 +192,8 @@ STATIC ARM_TYPE0 mArmDefaultType0 = {
1, // Boot from CD
1, // selectable boot
}, // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
{ // BIOSCharacteristicsExtensionBytes[2]
{
// BIOSCharacteristicsExtensionBytes[2]
0x3,
0xC,
},
@ -204,13 +203,13 @@ STATIC ARM_TYPE0 mArmDefaultType0 = {
0xFF // UINT8 EmbeddedControllerFirmwareMinorRelease
},
// Text strings (unformatted area)
TYPE0_STRINGS
};
TYPE0_STRINGS};
// System information (section 7.2)
STATIC CONST ARM_TYPE1 mArmDefaultType1 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_SYSTEM_INFORMATION,
sizeof(SMBIOS_TABLE_TYPE1),
SMBIOS_HANDLE_PI_RESERVED,
@ -219,19 +218,22 @@ STATIC CONST ARM_TYPE1 mArmDefaultType1 = {
2, // Product Name
3, // Version
4, // Serial
{ 0x8a95d198, 0x7f46, 0x11e5, { 0xbf,0x8b,0x08,0x00,0x27,0x04,0xd4,0x8e }}, //UUID
{0x8a95d198,
0x7f46,
0x11e5,
{0xbf, 0x8b, 0x08, 0x00, 0x27, 0x04, 0xd4, 0x8e}}, // UUID
6, // Wakeup type
0, // SKU
0, // Family
},
// Text strings (unformatted)
TYPE1_STRINGS
};
TYPE1_STRINGS};
// Baseboard (section 7.3)
STATIC ARM_TYPE2 mArmDefaultType2 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE2), // UINT8 Length
SMBIOS_HANDLE_MOTHERBOARD,
@ -248,13 +250,13 @@ STATIC ARM_TYPE2 mArmDefaultType2 = {
1,
{SMBIOS_HANDLE_A53_CLUSTER}, //,SMBIOS_HANDLE_A53_CLUSTER,SMBIOS_HANDLE_MEMORY},
},
TYPE2_STRINGS
};
TYPE2_STRINGS};
// Enclosure
STATIC CONST ARM_TYPE3 mArmDefaultType3 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE3), // UINT8 Length
SMBIOS_HANDLE_CHASSIS,
@ -268,27 +270,36 @@ STATIC CONST ARM_TYPE3 mArmDefaultType3 = {
ChassisStateSafe, // power supply state
ChassisStateSafe, // thermal state
ChassisSecurityStatusNone, // security state
{0,0,0,0,}, //OEM defined
{
0,
0,
0,
0,
}, // OEM defined
1, // 1U height
1, // number of power cords
0, // no contained elements
},
TYPE3_STRINGS
};
TYPE3_STRINGS};
// Processor
STATIC CONST ARM_TYPE4 mArmDefaultType4_a72 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE4), // UINT8 Length
SMBIOS_HANDLE_A72_CLUSTER,
},
1, // socket type
3, // processor type CPU
ProcessorFamilyIndicatorFamily2, //processor family, acquire from field2
ProcessorFamilyIndicatorFamily2, // processor family, acquire from
// field2
2, // manufactuer
{{0,},{0.}}, //processor id
{{
0,
},
{0.}}, // processor id
5, // version
{0, 0, 0, 0, 0, 1}, // voltage
0, // external clock
@ -308,21 +319,25 @@ STATIC CONST ARM_TYPE4 mArmDefaultType4_a72 = {
0xEC, // processor characteristics
ProcessorFamilyARM, // ARM core
},
TYPE4_STRINGS
};
TYPE4_STRINGS};
STATIC CONST ARM_TYPE4 mArmDefaultType4_a57 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE4), // UINT8 Length
SMBIOS_HANDLE_A57_CLUSTER,
},
1, // socket type
3, // processor type CPU
ProcessorFamilyIndicatorFamily2, //processor family, acquire from field2
ProcessorFamilyIndicatorFamily2, // processor family, acquire from
// field2
2, // manufactuer
{{0,},{0.}}, //processor id
{{
0,
},
{0.}}, // processor id
3, // version
{0, 0, 0, 0, 0, 1}, // voltage
0, // external clock
@ -342,21 +357,25 @@ STATIC CONST ARM_TYPE4 mArmDefaultType4_a57 = {
0xEC, // processor characteristics
ProcessorFamilyARM, // ARM core
},
TYPE4_STRINGS
};
TYPE4_STRINGS};
STATIC CONST ARM_TYPE4 mArmDefaultType4_a53 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE4), // UINT8 Length
SMBIOS_HANDLE_A53_CLUSTER,
},
1, // socket type
3, // processor type CPU
ProcessorFamilyIndicatorFamily2, //processor family, acquire from field2
ProcessorFamilyIndicatorFamily2, // processor family, acquire from
// field2
2, // manufactuer
{{0,},{0.}}, //processor id
{{
0,
},
{0.}}, // processor id
4, // version
{0, 0, 0, 0, 0, 1}, // voltage
0, // external clock
@ -376,13 +395,13 @@ STATIC CONST ARM_TYPE4 mArmDefaultType4_a53 = {
0xEC, // processor characteristics
ProcessorFamilyARM, // ARM core
},
TYPE4_STRINGS
};
TYPE4_STRINGS};
// Cache
STATIC CONST ARM_TYPE7 mArmDefaultType7_a57_l1i = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_CACHE_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE7), // UINT8 Length
SMBIOS_HANDLE_A57_L1I,
@ -398,12 +417,12 @@ STATIC CONST ARM_TYPE7 mArmDefaultType7_a57_l1i = {
CacheTypeInstruction, // instruction cache
CacheAssociativityOther, // three way
},
TYPE7_STRINGS
};
TYPE7_STRINGS};
STATIC CONST ARM_TYPE7 mArmDefaultType7_a53_l1i = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_CACHE_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE7), // UINT8 Length
SMBIOS_HANDLE_A53_L1I,
@ -419,12 +438,12 @@ STATIC CONST ARM_TYPE7 mArmDefaultType7_a53_l1i = {
CacheTypeInstruction, // instruction cache
CacheAssociativity2Way, // two way
},
TYPE7_STRINGS
};
TYPE7_STRINGS};
STATIC CONST ARM_TYPE7 mArmDefaultType7_a57_l1d = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_CACHE_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE7), // UINT8 Length
SMBIOS_HANDLE_A57_L1D,
@ -440,12 +459,12 @@ STATIC CONST ARM_TYPE7 mArmDefaultType7_a57_l1d = {
CacheTypeData, // instruction cache
CacheAssociativity2Way, // two way associative
},
TYPE7_STRINGS
};
TYPE7_STRINGS};
STATIC CONST ARM_TYPE7 mArmDefaultType7_a53_l1d = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_CACHE_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE7), // UINT8 Length
SMBIOS_HANDLE_A53_L1D,
@ -461,12 +480,12 @@ STATIC CONST ARM_TYPE7 mArmDefaultType7_a53_l1d = {
CacheTypeData, // instruction cache
CacheAssociativity4Way, // four way associative
},
TYPE7_STRINGS
};
TYPE7_STRINGS};
STATIC CONST ARM_TYPE7 mArmDefaultType7_a57_l2 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_CACHE_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE7), // UINT8 Length
SMBIOS_HANDLE_A57_L2,
@ -482,12 +501,12 @@ STATIC CONST ARM_TYPE7 mArmDefaultType7_a57_l2 = {
CacheTypeUnified, // instruction cache
CacheAssociativity16Way, // 16 way associative
},
TYPE7_STRINGS
};
TYPE7_STRINGS};
STATIC CONST ARM_TYPE7 mArmDefaultType7_a53_l2 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_CACHE_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE7), // UINT8 Length
SMBIOS_HANDLE_A53_L2,
@ -503,13 +522,13 @@ STATIC CONST ARM_TYPE7 mArmDefaultType7_a53_l2 = {
CacheTypeUnified, // instruction cache
CacheAssociativity16Way, // 16 way associative
},
TYPE7_STRINGS
};
TYPE7_STRINGS};
// Slots
STATIC CONST ARM_TYPE9 mArmDefaultType9_0 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_SYSTEM_SLOTS, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE9), // UINT8 Length
SMBIOS_HANDLE_PI_RESERVED,
@ -526,12 +545,12 @@ STATIC CONST ARM_TYPE9 mArmDefaultType9_0 = {
2,
1,
},
TYPE9_STRINGS
};
TYPE9_STRINGS};
STATIC CONST ARM_TYPE9 mArmDefaultType9_1 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_SYSTEM_SLOTS, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE9), // UINT8 Length
SMBIOS_HANDLE_PI_RESERVED,
@ -548,12 +567,12 @@ STATIC CONST ARM_TYPE9 mArmDefaultType9_1 = {
2,
2,
},
TYPE9_STRINGS
};
TYPE9_STRINGS};
STATIC CONST ARM_TYPE9 mArmDefaultType9_2 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_SYSTEM_SLOTS, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE9), // UINT8 Length
SMBIOS_HANDLE_PI_RESERVED,
@ -570,12 +589,12 @@ STATIC CONST ARM_TYPE9 mArmDefaultType9_2 = {
2,
3,
},
TYPE9_STRINGS
};
TYPE9_STRINGS};
STATIC CONST ARM_TYPE9 mArmDefaultType9_3 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_SYSTEM_SLOTS, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE9), // UINT8 Length
SMBIOS_HANDLE_PI_RESERVED,
@ -592,13 +611,13 @@ STATIC CONST ARM_TYPE9 mArmDefaultType9_3 = {
2,
0xc,
},
TYPE9_STRINGS
};
TYPE9_STRINGS};
// Memory array
STATIC CONST ARM_TYPE16 mArmDefaultType16 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE16), // UINT8 Length
SMBIOS_HANDLE_MEMORY,
@ -610,13 +629,13 @@ STATIC CONST ARM_TYPE16 mArmDefaultType16 = {
0xFFFE, // No error information structure
0x1, // soldered memory
},
TYPE16_STRINGS
};
TYPE16_STRINGS};
// Memory device
STATIC CONST ARM_TYPE17 mArmDefaultType17 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_MEMORY_DEVICE, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE17), // UINT8 Length
SMBIOS_HANDLE_DIMM,
@ -639,14 +658,14 @@ STATIC CONST ARM_TYPE17 mArmDefaultType17 = {
0, // part number
0, // rank
},
TYPE17_STRINGS
};
TYPE17_STRINGS};
// Memory array mapped address, this structure
// is overridden by InstallMemoryStructure
STATIC CONST ARM_TYPE19 mArmDefaultType19 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE19), // UINT8 Length
SMBIOS_HANDLE_PI_RESERVED,
@ -658,13 +677,13 @@ STATIC CONST ARM_TYPE19 mArmDefaultType19 = {
0x080000000, // starting addr of first 2GB
0x100000000, // ending addr of first 2GB
},
TYPE19_STRINGS
};
TYPE19_STRINGS};
// System boot info
STATIC CONST ARM_TYPE32 mArmDefaultType32 = {
{
{ // SMBIOS_STRUCTURE Hdr
{
// SMBIOS_STRUCTURE Hdr
EFI_SMBIOS_TYPE_SYSTEM_BOOT_INFORMATION, // UINT8 Type
sizeof(SMBIOS_TABLE_TYPE32), // UINT8 Length
SMBIOS_HANDLE_PI_RESERVED,
@ -672,38 +691,20 @@ STATIC CONST ARM_TYPE32 mArmDefaultType32 = {
{0, 0, 0, 0, 0, 0}, // reserved
BootInformationStatusNoError,
},
TYPE32_STRINGS
};
TYPE32_STRINGS};
STATIC CONST VOID *DefaultCommonTables[]=
{
&mArmDefaultType0,
&mArmDefaultType1,
&mArmDefaultType2,
&mArmDefaultType3,
&mArmDefaultType7_a53_l1i,
&mArmDefaultType7_a53_l1d,
&mArmDefaultType7_a53_l2,
&mArmDefaultType4_a53,
&mArmDefaultType9_0,
&mArmDefaultType9_1,
&mArmDefaultType9_2,
&mArmDefaultType9_3,
&mArmDefaultType16,
&mArmDefaultType17,
STATIC CONST VOID *DefaultCommonTables[] = {
&mArmDefaultType0, &mArmDefaultType1, &mArmDefaultType2, &mArmDefaultType3,
&mArmDefaultType7_a53_l1i, &mArmDefaultType7_a53_l1d,
&mArmDefaultType7_a53_l2, &mArmDefaultType4_a53, &mArmDefaultType9_0,
&mArmDefaultType9_1, &mArmDefaultType9_2, &mArmDefaultType9_3,
&mArmDefaultType16, &mArmDefaultType17,
// &mArmDefaultType19, //memory range type 19 dynamically generated
&mArmDefaultType32,
NULL
};
&mArmDefaultType32, NULL};
STATIC CONST VOID *DefaultTablesR0R1[]=
{
&mArmDefaultType7_a57_l1i,
&mArmDefaultType7_a57_l1d,
&mArmDefaultType7_a57_l2,
&mArmDefaultType4_a57,
NULL
};
STATIC CONST VOID *DefaultTablesR0R1[] = {
&mArmDefaultType7_a57_l1i, &mArmDefaultType7_a57_l1d,
&mArmDefaultType7_a57_l2, &mArmDefaultType4_a57, NULL};
/*
@ -726,10 +727,8 @@ STATIC CONST VOID *DefaultTablesR2[]=
**/
EFI_STATUS
InstallMemoryStructure(
IN EFI_SMBIOS_PROTOCOL *Smbios,
IN UINT64 StartingAddress,
IN UINT64 RegionLength
)
IN EFI_SMBIOS_PROTOCOL *Smbios, IN UINT64 StartingAddress,
IN UINT64 RegionLength)
{
EFI_SMBIOS_HANDLE SmbiosHandle;
ARM_TYPE19 MemoryDescriptor;
@ -742,11 +741,8 @@ InstallMemoryStructure (
SmbiosHandle = MemoryDescriptor.Base.Hdr.Handle;
Status = Smbios->Add(
Smbios,
NULL,
&SmbiosHandle,
(EFI_SMBIOS_TABLE_HEADER*) &MemoryDescriptor
);
Smbios, NULL, &SmbiosHandle,
(EFI_SMBIOS_TABLE_HEADER *)&MemoryDescriptor);
return Status;
}
@ -757,30 +753,24 @@ InstallMemoryStructure (
**/
EFI_STATUS
InstallStructures(
IN EFI_SMBIOS_PROTOCOL *Smbios,
IN CONST VOID *DefaultTables[]
)
IN EFI_SMBIOS_PROTOCOL *Smbios, IN CONST VOID *DefaultTables[])
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE SmbiosHandle;
int TableEntry;
for ( TableEntry=0; DefaultTables[TableEntry] != NULL; TableEntry++)
{
SmbiosHandle = ((EFI_SMBIOS_TABLE_HEADER*)DefaultTables[TableEntry])->Handle;
for (TableEntry = 0; DefaultTables[TableEntry] != NULL; TableEntry++) {
SmbiosHandle =
((EFI_SMBIOS_TABLE_HEADER *)DefaultTables[TableEntry])->Handle;
Status = Smbios->Add(
Smbios,
NULL,
&SmbiosHandle,
(EFI_SMBIOS_TABLE_HEADER*) DefaultTables[TableEntry]
);
Smbios, NULL, &SmbiosHandle,
(EFI_SMBIOS_TABLE_HEADER *)DefaultTables[TableEntry]);
if (EFI_ERROR(Status))
break;
}
return Status;
}
/**
Install all structures from the DefaultTables structure
@ -788,9 +778,7 @@ InstallStructures (
**/
EFI_STATUS
InstallAllStructures (
IN EFI_SMBIOS_PROTOCOL *Smbios
)
InstallAllStructures(IN EFI_SMBIOS_PROTOCOL *Smbios)
{
EFI_STATUS Status = EFI_SUCCESS;
VOID * ExtraTables = DefaultTablesR0R1;
@ -805,7 +793,8 @@ InstallAllStructures (
ASSERT_EFI_ERROR(Status);
// Generate memory descriptors for the two memory ranges we know about
Status = InstallMemoryStructure ( Smbios, PcdGet64 (PcdSystemMemoryBase), PcdGet64 (PcdSystemMemorySize));
Status = InstallMemoryStructure(
Smbios, PcdGet64(PcdSystemMemoryBase), PcdGet64(PcdSystemMemorySize));
ASSERT_EFI_ERROR(Status);
return Status;
@ -824,9 +813,7 @@ InstallAllStructures (
EFI_STATUS
EFIAPI
SmbiosTablePublishEntry(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
EFI_SMBIOS_PROTOCOL *Smbios;
@ -834,11 +821,7 @@ SmbiosTablePublishEntry (
//
// Find the SMBIOS protocol
//
Status = gBS->LocateProtocol (
&gEfiSmbiosProtocolGuid,
NULL,
(VOID**)&Smbios
);
Status = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);
if (EFI_ERROR(Status)) {
return Status;
}

View File

@ -3,12 +3,13 @@
* Copyright (c) 2018, Linaro Ltd. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
* are licensed and made available under the terms and conditions of the BSD
*License which accompanies this distribution. The full text of the license may
*be found at http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
*IMPLIED.
*
**/
@ -38,15 +39,11 @@
EFI_CPU_ARCH_PROTOCOL *gCpu;
VOID
InitPeripherals (
IN VOID
)
VOID InitPeripherals(IN VOID)
{
// Lock the QcomWdogTimer in a cage on certain devices
MmioWrite32(0x17980008, 0x000000);
DEBUG((EFI_D_WARN, "\n \v The Dog has been locked in a cage :)\v"));
}
/**
@ -64,20 +61,11 @@ InitPeripherals (
@param[in] Context NULL
**/
STATIC
VOID
OnEndOfDxe (
IN EFI_EVENT Event,
IN VOID *Context
)
{
}
VOID OnEndOfDxe(IN EFI_EVENT Event, IN VOID *Context) {}
EFI_STATUS
EFIAPI
sdm845EntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
sdm845EntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
EFI_EVENT EndOfDxeEvent;
@ -95,12 +83,7 @@ sdm845EntryPoint (
// Install the INSTALL_FDT_PROTOCOL protocol.
//
Status = gBS->CreateEventEx(
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
OnEndOfDxe,
NULL,
&gEfiEndOfDxeEventGroupGuid,
&EndOfDxeEvent
);
EVT_NOTIFY_SIGNAL, TPL_CALLBACK, OnEndOfDxe, NULL,
&gEfiEndOfDxeEventGroupGuid, &EndOfDxeEvent);
return Status;
}

View File

@ -3,12 +3,13 @@
* Copyright (c) 2013-2017, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
* are licensed and made available under the terms and conditions of the BSD
*License which accompanies this distribution. The full text of the license may
*be found at http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
*IMPLIED.
*
**/
@ -27,14 +28,17 @@
// ACPI table information used to initialize tables.
//
#define EFI_ACPI_ARM_OEM_ID 'A', 'R', 'M', 'L', 'T', 'D' // OEMID 6 bytes long
#define EFI_ACPI_ARM_OEM_TABLE_ID SIGNATURE_64('A','R','M','-','J','U','N','O') // OEM table id 8 bytes long
#define EFI_ACPI_ARM_OEM_TABLE_ID \
SIGNATURE_64( \
'A', 'R', 'M', '-', 'J', 'U', 'N', 'O') // OEM table id 8 bytes long
#define EFI_ACPI_ARM_OEM_REVISION 0x20140727
#define EFI_ACPI_ARM_CREATOR_ID SIGNATURE_32('A', 'R', 'M', ' ')
#define EFI_ACPI_ARM_CREATOR_REVISION 0x00000099
// A macro to initialise the common header part of EFI ACPI tables as defined by
// EFI_ACPI_DESCRIPTION_HEADER structure.
#define ARM_ACPI_HEADER(Signature, Type, Revision) { \
#define ARM_ACPI_HEADER(Signature, Type, Revision) \
{ \
Signature, /* UINT32 Signature */ \
sizeof(Type), /* UINT32 Length */ \
Revision, /* UINT8 Revision */ \

View File

@ -39,8 +39,7 @@ static ARM_MEMORY_REGION_DESCRIPTOR_EX gDeviceMemoryDescriptorEx[] = {
/* HLOS1 */
{0x81AC0000, 0x03C40000, EFI_RESOURCE_SYSTEM_MEMORY,
SYSTEM_MEMORY_RESOURCE_ATTR_CAPABILITIES,
ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK, AddMem,
EfiBootServicesData},
ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK, AddMem, EfiBootServicesData},
/* MPSS_EFS */
{0x85D00000, 0x00200000, EFI_RESOURCE_SYSTEM_MEMORY,
SYSTEM_MEMORY_RESOURCE_ATTR_CAPABILITIES,

View File

@ -103,8 +103,7 @@ typedef struct {
EFI_STATUS
EFIAPI
GetPartitionEntry (IN EFI_HANDLE Handle,
OUT EFI_PARTITION_ENTRY **PartEntry);
GetPartitionEntry(IN EFI_HANDLE Handle, OUT EFI_PARTITION_ENTRY **PartEntry);
/**
Returns a list of BlkIo handles based on required criteria
@ -122,9 +121,8 @@ GetPartitionEntry (IN EFI_HANDLE Handle,
*/
EFI_STATUS
EFIAPI
GetBlkIOHandles (IN UINT32 SelectionAttrib,
IN PartiSelectFilter *FilterData,
OUT HandleInfo *HandleInfoPtr,
IN OUT UINT32 *MaxBlkIopCnt);
GetBlkIOHandles(
IN UINT32 SelectionAttrib, IN PartiSelectFilter *FilterData,
OUT HandleInfo *HandleInfoPtr, IN OUT UINT32 *MaxBlkIopCnt);
#endif

View File

@ -163,7 +163,8 @@ table in the respective position mentioned below.
do { \
Status = (code); \
if (Status != EFI_SUCCESS) { \
DEBUG ((EFI_D_ERROR, "Err: line:%d %a() status: %r\n", __LINE__, \
DEBUG( \
(EFI_D_ERROR, "Err: line:%d %a() status: %r\n", __LINE__, \
__FUNCTION__, Status)); \
return Status; \
} \
@ -201,7 +202,8 @@ EFI_STATUS EnumeratePartitions (VOID);
VOID UpdatePartitionEntries(VOID);
VOID UpdatePartitionAttributes(UINT32 UpdateType);
BOOLEAN IsSuffixEmpty(Slot *CheckSlot);
EFI_STATUS SetActiveSlot (Slot *NewSlot, BOOLEAN ResetSuccessBit, BOOLEAN SetSuccessBit);
EFI_STATUS
SetActiveSlot(Slot *NewSlot, BOOLEAN ResetSuccessBit, BOOLEAN SetSuccessBit);
BOOLEAN IsSlotBootable(Slot *CheckSlot);
EFI_STATUS ClearUnbootable(Slot *CheckSlot);
UINT64 GetPartitionSize(EFI_BLOCK_IO_PROTOCOL *BlockIo);

View File

@ -1,4 +1,5 @@
/* Copyright (c) 2015-2018, 2020-2021, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2018, 2020-2021, The Linux Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@ -29,13 +30,13 @@
#ifndef __BSL_BOARD_H__
#define __BSL_BOARD_H__
#include <Uefi.h>
#include <Library/PrintLib.h>
#include <Library/BootSlotLib/EFICardInfo.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/BootSlotLib/EFICardInfo.h>
#include <Uefi.h>
#define HANDLE_MAX_INFO_LIST 128
@ -45,10 +46,8 @@ typedef enum {
UNKNOWN,
} MemCardType;
VOID
GetRootDeviceType (CHAR8 *StrDeviceType, UINT32 Len);
MemCardType
CheckRootDeviceType (VOID);
VOID GetRootDeviceType(CHAR8 *StrDeviceType, UINT32 Len);
MemCardType CheckRootDeviceType(VOID);
EFI_STATUS
UfsGetSetBootLun(UINT32 *UfsBootlun, BOOLEAN IsGet);

View File

@ -32,10 +32,6 @@ void ResetFb(void);
UINTN
EFIAPI
SerialPortWriteCritical
(
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
);
SerialPortWriteCritical(IN UINT8 *Buffer, IN UINTN NumberOfBytes);
#endif

View File

@ -35,102 +35,38 @@
#define SCALE_FACTOR 2
unsigned font5x12[] = {
0x00000000, 0x00000000,
0x08421080, 0x00020084,
0x00052940, 0x00000000,
0x15f52800, 0x0000295f,
0x1c52f880, 0x00023e94,
0x08855640, 0x0004d542,
0x04528800, 0x000b2725,
0x00021080, 0x00000000,
0x04211088, 0x00821042,
0x10841082, 0x00221108,
0x09575480, 0x00000000,
0x3e420000, 0x00000084,
0x00000000, 0x00223000,
0x3e000000, 0x00000000,
0x00000000, 0x00471000,
0x08844200, 0x00008442,
0x2318a880, 0x00022a31,
0x08429880, 0x000f9084,
0x1108c5c0, 0x000f8444,
0x1c4443e0, 0x00074610,
0x14a62100, 0x000423e9,
0x26d087e0, 0x00074610,
0x1e10c5c0, 0x00074631,
0x088443e0, 0x00010844,
0x1d18c5c0, 0x00074631,
0x3d18c5c0, 0x00074610,
0x08e20000, 0x00471000,
0x08e20000, 0x00223000,
0x02222200, 0x00082082,
0x01f00000, 0x000003e0,
0x20820820, 0x00008888,
0x1108c5c0, 0x00020084,
0x2b98c5c0, 0x000f05b5,
0x2318a880, 0x0008c63f,
0x1d2949e0, 0x0007ca52,
0x0210c5c0, 0x00074421,
0x252949e0, 0x0007ca52,
0x1e1087e0, 0x000f8421,
0x1e1087e0, 0x00008421,
0x0210c5c0, 0x00074639,
0x3f18c620, 0x0008c631,
0x084211c0, 0x00071084,
0x10842380, 0x00032508,
0x0654c620, 0x0008c525,
0x02108420, 0x000f8421,
0x2b5dc620, 0x0008c631,
0x2b59ce20, 0x0008c739,
0x2318c5c0, 0x00074631,
0x1f18c5e0, 0x00008421,
0x2318c5c0, 0x01075631,
0x1f18c5e0, 0x0008c525,
0x1c10c5c0, 0x00074610,
0x084213e0, 0x00021084,
0x2318c620, 0x00074631,
0x1518c620, 0x0002114a,
0x2b18c620, 0x000556b5,
0x08a54620, 0x0008c54a,
0x08a54620, 0x00021084,
0x088443e0, 0x000f8442,
0x0421084e, 0x00e10842,
0x08210420, 0x00084108,
0x1084210e, 0x00e42108,
0x0008a880, 0x00000000,
0x00000000, 0x01f00000,
0x00000104, 0x00000000,
0x20e00000, 0x000b663e,
0x22f08420, 0x0007c631,
0x22e00000, 0x00074421,
0x23e84200, 0x000f4631,
0x22e00000, 0x0007443f,
0x1e214980, 0x00010842,
0x22e00000, 0x1d187a31,
0x26d08420, 0x0008c631,
0x08601000, 0x00071084,
0x10c02000, 0x0c94a108,
0x0a908420, 0x0008a4a3,
0x084210c0, 0x00071084,
0x2ab00000, 0x0008d6b5,
0x26d00000, 0x0008c631,
0x22e00000, 0x00074631,
0x22f00000, 0x0210be31,
0x23e00000, 0x21087a31,
0x26d00000, 0x00008421,
0x22e00000, 0x00074506,
0x04f10800, 0x00064842,
0x23100000, 0x000b6631,
0x23100000, 0x00022951,
0x23100000, 0x000556b5,
0x15100000, 0x0008a884,
0x23100000, 0x1d185b31,
0x11f00000, 0x000f8444,
0x06421098, 0x01821084,
0x08421080, 0x00021084,
0x30421083, 0x00321084,
0x0004d640, 0x00000000,
0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x08421080, 0x00020084, 0x00052940, 0x00000000,
0x15f52800, 0x0000295f, 0x1c52f880, 0x00023e94, 0x08855640, 0x0004d542,
0x04528800, 0x000b2725, 0x00021080, 0x00000000, 0x04211088, 0x00821042,
0x10841082, 0x00221108, 0x09575480, 0x00000000, 0x3e420000, 0x00000084,
0x00000000, 0x00223000, 0x3e000000, 0x00000000, 0x00000000, 0x00471000,
0x08844200, 0x00008442, 0x2318a880, 0x00022a31, 0x08429880, 0x000f9084,
0x1108c5c0, 0x000f8444, 0x1c4443e0, 0x00074610, 0x14a62100, 0x000423e9,
0x26d087e0, 0x00074610, 0x1e10c5c0, 0x00074631, 0x088443e0, 0x00010844,
0x1d18c5c0, 0x00074631, 0x3d18c5c0, 0x00074610, 0x08e20000, 0x00471000,
0x08e20000, 0x00223000, 0x02222200, 0x00082082, 0x01f00000, 0x000003e0,
0x20820820, 0x00008888, 0x1108c5c0, 0x00020084, 0x2b98c5c0, 0x000f05b5,
0x2318a880, 0x0008c63f, 0x1d2949e0, 0x0007ca52, 0x0210c5c0, 0x00074421,
0x252949e0, 0x0007ca52, 0x1e1087e0, 0x000f8421, 0x1e1087e0, 0x00008421,
0x0210c5c0, 0x00074639, 0x3f18c620, 0x0008c631, 0x084211c0, 0x00071084,
0x10842380, 0x00032508, 0x0654c620, 0x0008c525, 0x02108420, 0x000f8421,
0x2b5dc620, 0x0008c631, 0x2b59ce20, 0x0008c739, 0x2318c5c0, 0x00074631,
0x1f18c5e0, 0x00008421, 0x2318c5c0, 0x01075631, 0x1f18c5e0, 0x0008c525,
0x1c10c5c0, 0x00074610, 0x084213e0, 0x00021084, 0x2318c620, 0x00074631,
0x1518c620, 0x0002114a, 0x2b18c620, 0x000556b5, 0x08a54620, 0x0008c54a,
0x08a54620, 0x00021084, 0x088443e0, 0x000f8442, 0x0421084e, 0x00e10842,
0x08210420, 0x00084108, 0x1084210e, 0x00e42108, 0x0008a880, 0x00000000,
0x00000000, 0x01f00000, 0x00000104, 0x00000000, 0x20e00000, 0x000b663e,
0x22f08420, 0x0007c631, 0x22e00000, 0x00074421, 0x23e84200, 0x000f4631,
0x22e00000, 0x0007443f, 0x1e214980, 0x00010842, 0x22e00000, 0x1d187a31,
0x26d08420, 0x0008c631, 0x08601000, 0x00071084, 0x10c02000, 0x0c94a108,
0x0a908420, 0x0008a4a3, 0x084210c0, 0x00071084, 0x2ab00000, 0x0008d6b5,
0x26d00000, 0x0008c631, 0x22e00000, 0x00074631, 0x22f00000, 0x0210be31,
0x23e00000, 0x21087a31, 0x26d00000, 0x00008421, 0x22e00000, 0x00074506,
0x04f10800, 0x00064842, 0x23100000, 0x000b6631, 0x23100000, 0x00022951,
0x23100000, 0x000556b5, 0x15100000, 0x0008a884, 0x23100000, 0x1d185b31,
0x11f00000, 0x000f8444, 0x06421098, 0x01821084, 0x08421080, 0x00021084,
0x30421083, 0x00321084, 0x0004d640, 0x00000000, 0x00000000, 0x00000000,
};
#endif

View File

@ -9,24 +9,22 @@
*
**/
#include <Uefi.h>
#include <Chipset/AArch64.h>
#include <Library/BaseMemoryLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/ArmLib.h>
#include <Library/ArmMmuLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Uefi.h>
// We use this index definition to define an invalid block entry
#define TT_ATTR_INDX_INVALID ((UINT32)~0)
STATIC
UINT64
ArmMemoryAttributeToPageAttribute (
IN ARM_MEMORY_REGION_ATTRIBUTES Attributes
)
ArmMemoryAttributeToPageAttribute(IN ARM_MEMORY_REGION_ATTRIBUTES Attributes)
{
switch (Attributes) {
case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE:
@ -58,9 +56,7 @@ ArmMemoryAttributeToPageAttribute (
}
UINT64
PageAttributeToGcdAttribute (
IN UINT64 PageAttributes
)
PageAttributeToGcdAttribute(IN UINT64 PageAttributes)
{
UINT64 GcdAttributes;
@ -78,7 +74,10 @@ PageAttributeToGcdAttribute (
GcdAttributes = EFI_MEMORY_WB;
break;
default:
DEBUG ((EFI_D_ERROR, "PageAttributeToGcdAttribute: PageAttributes:0x%lX not supported.\n", PageAttributes));
DEBUG(
(EFI_D_ERROR,
"PageAttributeToGcdAttribute: PageAttributes:0x%lX not supported.\n",
PageAttributes));
ASSERT(0);
// The Global Coherency Domain (GCD) value is defined as a bit set.
// Returning 0 means no attribute has been set.
@ -86,7 +85,8 @@ PageAttributeToGcdAttribute (
}
// Determine protection attributes
if (((PageAttributes & TT_AP_MASK) == TT_AP_NO_RO) || ((PageAttributes & TT_AP_MASK) == TT_AP_RO_RO)) {
if (((PageAttributes & TT_AP_MASK) == TT_AP_NO_RO) ||
((PageAttributes & TT_AP_MASK) == TT_AP_RO_RO)) {
// Read only cases map to write-protect
GcdAttributes |= EFI_MEMORY_RO;
}
@ -102,12 +102,8 @@ PageAttributeToGcdAttribute (
#define MIN_T0SZ 16
#define BITS_PER_LEVEL 9
VOID
GetRootTranslationTableInfo (
IN UINTN T0SZ,
OUT UINTN *TableLevel,
OUT UINTN *TableEntryCount
)
VOID GetRootTranslationTableInfo(
IN UINTN T0SZ, OUT UINTN *TableLevel, OUT UINTN *TableEntryCount)
{
// Get the level of the root table
if (TableLevel) {
@ -115,7 +111,8 @@ GetRootTranslationTableInfo (
}
if (TableEntryCount) {
*TableEntryCount = 1UL << (BITS_PER_LEVEL - (T0SZ - MIN_T0SZ) % BITS_PER_LEVEL);
*TableEntryCount =
1UL << (BITS_PER_LEVEL - (T0SZ - MIN_T0SZ) % BITS_PER_LEVEL);
}
}
@ -137,12 +134,8 @@ ReplaceLiveEntry (
*/
STATIC
VOID
LookupAddresstoRootTable (
IN UINT64 MaxAddress,
OUT UINTN *T0SZ,
OUT UINTN *TableEntryCount
)
VOID LookupAddresstoRootTable(
IN UINT64 MaxAddress, OUT UINTN *T0SZ, OUT UINTN *TableEntryCount)
{
UINTN TopBit;
@ -167,14 +160,9 @@ LookupAddresstoRootTable (
}
STATIC
UINT64*
GetBlockEntryListFromAddress (
IN UINT64 *RootTable,
IN UINT64 RegionStart,
OUT UINTN *TableLevel,
IN OUT UINT64 *BlockEntrySize,
OUT UINT64 **LastBlockEntry
)
UINT64 *GetBlockEntryListFromAddress(
IN UINT64 *RootTable, IN UINT64 RegionStart, OUT UINTN *TableLevel,
IN OUT UINT64 *BlockEntrySize, OUT UINT64 **LastBlockEntry)
{
UINTN RootTableLevel;
UINTN RootTableEntryCount;
@ -215,11 +203,13 @@ GetBlockEntryListFromAddress (
// Get the Table info from T0SZ
GetRootTranslationTableInfo(T0SZ, &RootTableLevel, &RootTableEntryCount);
// If the start address is 0x0 then we use the size of the region to identify the alignment
// If the start address is 0x0 then we use the size of the region to identify
// the alignment
if (RegionStart == 0) {
// Identify the highest possible alignment for the Region Size
BaseAddressAlignment = LowBitSet64(*BlockEntrySize);
} else {
}
else {
// Identify the highest possible alignment for the Base Address
BaseAddressAlignment = LowBitSet64(RegionStart);
}
@ -228,32 +218,37 @@ GetBlockEntryListFromAddress (
// should be at least 1 since block translations are not supported at level 0
PageLevel = MAX(3 - ((BaseAddressAlignment - 12) / 9), 1);
// If the required size is smaller than the current block size then we need to go to the page below.
// The PageLevel was calculated on the Base Address alignment but did not take in account the alignment
// of the allocation size
// If the required size is smaller than the current block size then we need to
// go to the page below. The PageLevel was calculated on the Base Address
// alignment but did not take in account the alignment of the allocation size
while (*BlockEntrySize < TT_BLOCK_ENTRY_SIZE_AT_LEVEL(PageLevel)) {
// It does not fit so we need to go a page level above
PageLevel++;
}
//
// Get the Table Descriptor for the corresponding PageLevel. We need to decompose RegionStart to get appropriate entries
// Get the Table Descriptor for the corresponding PageLevel. We need to
// decompose RegionStart to get appropriate entries
//
TranslationTable = RootTable;
for (IndexLevel = RootTableLevel; IndexLevel <= PageLevel; IndexLevel++) {
BlockEntry = (UINT64*)TT_GET_ENTRY_FOR_ADDRESS (TranslationTable, IndexLevel, RegionStart);
BlockEntry = (UINT64 *)TT_GET_ENTRY_FOR_ADDRESS(
TranslationTable, IndexLevel, RegionStart);
if ((IndexLevel != 3) && ((*BlockEntry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY)) {
if ((IndexLevel != 3) &&
((*BlockEntry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY)) {
// Go to the next table
TranslationTable = (UINT64*)(*BlockEntry & TT_ADDRESS_MASK_DESCRIPTION_TABLE);
TranslationTable =
(UINT64 *)(*BlockEntry & TT_ADDRESS_MASK_DESCRIPTION_TABLE);
// If we are at the last level then update the last level to next level
if (IndexLevel == PageLevel) {
// Enter the next level
PageLevel++;
}
} else if ((*BlockEntry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY) {
}
else if ((*BlockEntry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY) {
// If we are not at the last level then we need to split this BlockEntry
if (IndexLevel != PageLevel) {
// Retrieve the attributes from the block entry
@ -267,14 +262,17 @@ GetBlockEntryListFromAddress (
// Get the address corresponding at this entry
BlockEntryAddress = RegionStart;
BlockEntryAddress = BlockEntryAddress >> TT_ADDRESS_OFFSET_AT_LEVEL(IndexLevel);
BlockEntryAddress =
BlockEntryAddress >> TT_ADDRESS_OFFSET_AT_LEVEL(IndexLevel);
// Shift back to right to set zero before the effective address
BlockEntryAddress = BlockEntryAddress << TT_ADDRESS_OFFSET_AT_LEVEL(IndexLevel);
BlockEntryAddress = BlockEntryAddress
<< TT_ADDRESS_OFFSET_AT_LEVEL(IndexLevel);
// Set the correct entry type for the next page level
if ((IndexLevel + 1) == 3) {
Attributes |= TT_TYPE_BLOCK_ENTRY_LEVEL3;
} else {
}
else {
Attributes |= TT_TYPE_BLOCK_ENTRY;
}
@ -287,17 +285,24 @@ GetBlockEntryListFromAddress (
// Populate the newly created lower level table
SubTableBlockEntry = TranslationTable;
for (Index = 0; Index < TT_ENTRY_COUNT; Index++) {
*SubTableBlockEntry = Attributes | (BlockEntryAddress + (Index << TT_ADDRESS_OFFSET_AT_LEVEL(IndexLevel + 1)));
*SubTableBlockEntry =
Attributes |
(BlockEntryAddress +
(Index << TT_ADDRESS_OFFSET_AT_LEVEL(IndexLevel + 1)));
SubTableBlockEntry++;
}
// Fill the BlockEntry with the new TranslationTable
*BlockEntry = ((UINTN)TranslationTable & TT_ADDRESS_MASK_DESCRIPTION_TABLE) | TableAttributes | TT_TYPE_TABLE_ENTRY;
*BlockEntry =
((UINTN)TranslationTable & TT_ADDRESS_MASK_DESCRIPTION_TABLE) |
TableAttributes | TT_TYPE_TABLE_ENTRY;
}
} else {
}
else {
if (IndexLevel != PageLevel) {
//
// Case when we have an Invalid Entry and we are at a page level above of the one targetted.
// Case when we have an Invalid Entry and we are at a page level above
// of the one targetted.
//
// Create a new translation table
@ -309,7 +314,9 @@ GetBlockEntryListFromAddress (
ZeroMem(TranslationTable, TT_ENTRY_COUNT * sizeof(UINT64));
// Fill the new BlockEntry with the TranslationTable
*BlockEntry = ((UINTN)TranslationTable & TT_ADDRESS_MASK_DESCRIPTION_TABLE) | TT_TYPE_TABLE_ENTRY;
*BlockEntry =
((UINTN)TranslationTable & TT_ADDRESS_MASK_DESCRIPTION_TABLE) |
TT_TYPE_TABLE_ENTRY;
}
}
}
@ -317,12 +324,15 @@ GetBlockEntryListFromAddress (
// Expose the found PageLevel to the caller
*TableLevel = PageLevel;
// Now, we have the Table Level we can get the Block Size associated to this table
// Now, we have the Table Level we can get the Block Size associated to this
// table
*BlockEntrySize = TT_BLOCK_ENTRY_SIZE_AT_LEVEL(PageLevel);
// The last block of the root table depends on the number of entry in this table,
// otherwise it is always the (TT_ENTRY_COUNT - 1)th entry in the table.
*LastBlockEntry = TT_LAST_BLOCK_ADDRESS(TranslationTable,
// The last block of the root table depends on the number of entry in this
// table, otherwise it is always the (TT_ENTRY_COUNT - 1)th entry in the
// table.
*LastBlockEntry = TT_LAST_BLOCK_ADDRESS(
TranslationTable,
(PageLevel == RootTableLevel) ? RootTableEntryCount : TT_ENTRY_COUNT);
return BlockEntry;
@ -331,12 +341,8 @@ GetBlockEntryListFromAddress (
STATIC
EFI_STATUS
UpdateRegionMapping(
IN UINT64 *RootTable,
IN UINT64 RegionStart,
IN UINT64 RegionLength,
IN UINT64 Attributes,
IN UINT64 BlockEntryMask
)
IN UINT64 *RootTable, IN UINT64 RegionStart, IN UINT64 RegionLength,
IN UINT64 Attributes, IN UINT64 BlockEntryMask)
{
UINT32 Type;
UINT64 *BlockEntry;
@ -351,25 +357,30 @@ UpdateRegionMapping (
}
do {
// Get the first Block Entry that matches the Virtual Address and also the information on the Table Descriptor
// such as the size of the Block Entry and the address of the last BlockEntry of the Table Descriptor
// Get the first Block Entry that matches the Virtual Address and also the
// information on the Table Descriptor such as the size of the Block Entry
// and the address of the last BlockEntry of the Table Descriptor
BlockEntrySize = RegionLength;
BlockEntry = GetBlockEntryListFromAddress (RootTable, RegionStart, &TableLevel, &BlockEntrySize, &LastBlockEntry);
BlockEntry = GetBlockEntryListFromAddress(
RootTable, RegionStart, &TableLevel, &BlockEntrySize, &LastBlockEntry);
if (BlockEntry == NULL) {
// GetBlockEntryListFromAddress() return NULL when it fails to allocate new pages from the Translation Tables
// GetBlockEntryListFromAddress() return NULL when it fails to allocate
// new pages from the Translation Tables
return EFI_OUT_OF_RESOURCES;
}
if (TableLevel != 3) {
Type = TT_TYPE_BLOCK_ENTRY;
} else {
}
else {
Type = TT_TYPE_BLOCK_ENTRY_LEVEL3;
}
do {
// Fill the Block Entry with attribute and output block address
*BlockEntry &= BlockEntryMask;
*BlockEntry |= (RegionStart & TT_ADDRESS_MASK_BLOCK_ENTRY) | Attributes | Type;
*BlockEntry |=
(RegionStart & TT_ADDRESS_MASK_BLOCK_ENTRY) | Attributes | Type;
ArmUpdateTranslationTableEntry(BlockEntry, (VOID *)RegionStart);
@ -384,7 +395,8 @@ UpdateRegionMapping (
(*BlockEntry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY) {
break;
}
} while ((RegionLength >= BlockEntrySize) && (BlockEntry <= LastBlockEntry));
} while ((RegionLength >= BlockEntrySize) &&
(BlockEntry <= LastBlockEntry));
} while (RegionLength != 0);
return EFI_SUCCESS;
@ -393,24 +405,16 @@ UpdateRegionMapping (
STATIC
EFI_STATUS
FillTranslationTable(
IN UINT64 *RootTable,
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryRegion
)
IN UINT64 *RootTable, IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryRegion)
{
return UpdateRegionMapping(
RootTable,
MemoryRegion->VirtualBase,
MemoryRegion->Length,
ArmMemoryAttributeToPageAttribute (MemoryRegion->Attributes) | TT_AF,
0
);
RootTable, MemoryRegion->VirtualBase, MemoryRegion->Length,
ArmMemoryAttributeToPageAttribute(MemoryRegion->Attributes) | TT_AF, 0);
}
STATIC
UINT64
GcdAttributeToPageAttribute (
IN UINT64 GcdAttributes
)
GcdAttributeToPageAttribute(IN UINT64 GcdAttributes)
{
UINT64 PageAttributes;
@ -436,7 +440,8 @@ GcdAttributeToPageAttribute (
(GcdAttributes & EFI_MEMORY_CACHETYPE_MASK) == EFI_MEMORY_UC) {
if (ArmReadCurrentEL() == AARCH64_EL2) {
PageAttributes |= TT_XN_MASK;
} else {
}
else {
PageAttributes |= TT_UXN_MASK | TT_PXN_MASK;
}
}
@ -450,10 +455,7 @@ GcdAttributeToPageAttribute (
EFI_STATUS
ArmSetMemoryAttributes(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
{
EFI_STATUS Status;
UINT64 * TranslationTable;
@ -469,18 +471,14 @@ ArmSetMemoryAttributes (
// permissions only.
//
PageAttributes &= TT_AP_MASK | TT_UXN_MASK | TT_PXN_MASK;
PageAttributeMask = ~(TT_ADDRESS_MASK_BLOCK_ENTRY | TT_AP_MASK |
TT_PXN_MASK | TT_XN_MASK);
PageAttributeMask =
~(TT_ADDRESS_MASK_BLOCK_ENTRY | TT_AP_MASK | TT_PXN_MASK | TT_XN_MASK);
}
TranslationTable = ArmGetTTBR0BaseAddress();
Status = UpdateRegionMapping(
TranslationTable,
BaseAddress,
Length,
PageAttributes,
PageAttributeMask);
TranslationTable, BaseAddress, Length, PageAttributes, PageAttributeMask);
if (EFI_ERROR(Status)) {
return Status;
}
@ -491,18 +489,16 @@ ArmSetMemoryAttributes (
STATIC
EFI_STATUS
SetMemoryRegionAttribute(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes,
IN UINT64 BlockEntryMask
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes,
IN UINT64 BlockEntryMask)
{
EFI_STATUS Status;
UINT64 * RootTable;
RootTable = ArmGetTTBR0BaseAddress();
Status = UpdateRegionMapping (RootTable, BaseAddress, Length, Attributes, BlockEntryMask);
Status = UpdateRegionMapping(
RootTable, BaseAddress, Length, Attributes, BlockEntryMask);
if (EFI_ERROR(Status)) {
return Status;
}
@ -511,67 +507,47 @@ SetMemoryRegionAttribute (
}
EFI_STATUS
ArmSetMemoryRegionNoExec (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
ArmSetMemoryRegionNoExec(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
{
UINT64 Val;
if (ArmReadCurrentEL() == AARCH64_EL1) {
Val = TT_PXN_MASK | TT_UXN_MASK;
} else {
}
else {
Val = TT_XN_MASK;
}
return SetMemoryRegionAttribute(
BaseAddress,
Length,
Val,
~TT_ADDRESS_MASK_BLOCK_ENTRY);
BaseAddress, Length, Val, ~TT_ADDRESS_MASK_BLOCK_ENTRY);
}
EFI_STATUS
ArmClearMemoryRegionNoExec(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
{
UINT64 Mask;
// XN maps to UXN in the EL1&0 translation regime
Mask = ~(TT_ADDRESS_MASK_BLOCK_ENTRY | TT_PXN_MASK | TT_XN_MASK);
return SetMemoryRegionAttribute (
BaseAddress,
Length,
0,
Mask);
return SetMemoryRegionAttribute(BaseAddress, Length, 0, Mask);
}
EFI_STATUS
ArmSetMemoryRegionReadOnly(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
{
return SetMemoryRegionAttribute(
BaseAddress,
Length,
TT_AP_RO_RO,
~TT_ADDRESS_MASK_BLOCK_ENTRY);
BaseAddress, Length, TT_AP_RO_RO, ~TT_ADDRESS_MASK_BLOCK_ENTRY);
}
EFI_STATUS
ArmClearMemoryRegionReadOnly(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
{
return SetMemoryRegionAttribute(
BaseAddress,
Length,
TT_AP_RW_RW,
BaseAddress, Length, TT_AP_RW_RW,
~(TT_ADDRESS_MASK_BLOCK_ENTRY | TT_AP_MASK));
}
@ -580,8 +556,7 @@ EFIAPI
ArmConfigureMmu(
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,
OUT VOID **TranslationTableBase OPTIONAL,
OUT UINTN *TranslationTableSize OPTIONAL
)
OUT UINTN *TranslationTableSize OPTIONAL)
{
VOID * TranslationTable;
UINT32 TranslationTableAttribute;
@ -603,8 +578,8 @@ ArmConfigureMmu (
// into account the architectural limitations that result from UEFI's
// use of 4 KB pages.
//
MaxAddress = MIN (LShiftU64 (1ULL, ArmGetPhysicalAddressBits ()) - 1,
MAX_ALLOC_ADDRESS);
MaxAddress =
MIN(LShiftU64(1ULL, ArmGetPhysicalAddressBits()) - 1, MAX_ALLOC_ADDRESS);
// Lookup the Table Level to get the information
LookupAddresstoRootTable(MaxAddress, &T0SZ, &RootTableEntryCount);
@ -621,44 +596,67 @@ ArmConfigureMmu (
// Set the Physical Address Size using MaxAddress
if (MaxAddress < SIZE_4GB) {
TCR |= TCR_PS_4GB;
} else if (MaxAddress < SIZE_64GB) {
}
else if (MaxAddress < SIZE_64GB) {
TCR |= TCR_PS_64GB;
} else if (MaxAddress < SIZE_1TB) {
}
else if (MaxAddress < SIZE_1TB) {
TCR |= TCR_PS_1TB;
} else if (MaxAddress < SIZE_4TB) {
}
else if (MaxAddress < SIZE_4TB) {
TCR |= TCR_PS_4TB;
} else if (MaxAddress < SIZE_16TB) {
}
else if (MaxAddress < SIZE_16TB) {
TCR |= TCR_PS_16TB;
} else if (MaxAddress < SIZE_256TB) {
}
else if (MaxAddress < SIZE_256TB) {
TCR |= TCR_PS_256TB;
} else {
DEBUG ((EFI_D_ERROR, "ArmConfigureMmu: The MaxAddress 0x%lX is not supported by this MMU configuration.\n", MaxAddress));
}
else {
DEBUG(
(EFI_D_ERROR,
"ArmConfigureMmu: The MaxAddress 0x%lX is not supported by this MMU "
"configuration.\n",
MaxAddress));
ASSERT(0); // Bigger than 48-bit memory space are not supported
return EFI_UNSUPPORTED;
}
} else if (ArmReadCurrentEL () == AARCH64_EL1) {
// Due to Cortex-A57 erratum #822227 we must set TG1[1] == 1, regardless of EPD1.
}
else if (ArmReadCurrentEL() == AARCH64_EL1) {
// Due to Cortex-A57 erratum #822227 we must set TG1[1] == 1, regardless of
// EPD1.
TCR = T0SZ | TCR_TG0_4KB | TCR_TG1_4KB | TCR_EPD1;
// Set the Physical Address Size using MaxAddress
if (MaxAddress < SIZE_4GB) {
TCR |= TCR_IPS_4GB;
} else if (MaxAddress < SIZE_64GB) {
}
else if (MaxAddress < SIZE_64GB) {
TCR |= TCR_IPS_64GB;
} else if (MaxAddress < SIZE_1TB) {
}
else if (MaxAddress < SIZE_1TB) {
TCR |= TCR_IPS_1TB;
} else if (MaxAddress < SIZE_4TB) {
}
else if (MaxAddress < SIZE_4TB) {
TCR |= TCR_IPS_4TB;
} else if (MaxAddress < SIZE_16TB) {
}
else if (MaxAddress < SIZE_16TB) {
TCR |= TCR_IPS_16TB;
} else if (MaxAddress < SIZE_256TB) {
}
else if (MaxAddress < SIZE_256TB) {
TCR |= TCR_IPS_256TB;
} else {
DEBUG ((EFI_D_ERROR, "ArmConfigureMmu: The MaxAddress 0x%lX is not supported by this MMU configuration.\n", MaxAddress));
}
else {
DEBUG(
(EFI_D_ERROR,
"ArmConfigureMmu: The MaxAddress 0x%lX is not supported by this MMU "
"configuration.\n",
MaxAddress));
ASSERT(0); // Bigger than 48-bit memory space are not supported
return EFI_UNSUPPORTED;
}
} else {
}
else {
ASSERT(0); // UEFI is only expected to run at EL2 and EL1, not EL3.
return EFI_UNSUPPORTED;
}
@ -672,8 +670,7 @@ ArmConfigureMmu (
// assert below that that matches the attributes we use for CPU accesses to
// the region.
//
TCR |= TCR_SH_INNER_SHAREABLE |
TCR_RGN_OUTER_WRITE_BACK_ALLOC |
TCR |= TCR_SH_INNER_SHAREABLE | TCR_RGN_OUTER_WRITE_BACK_ALLOC |
TCR_RGN_INNER_WRITE_BACK_ALLOC;
// Set TCR
@ -684,9 +681,10 @@ ArmConfigureMmu (
if (TranslationTable == NULL) {
return EFI_OUT_OF_RESOURCES;
}
// We set TTBR0 just after allocating the table to retrieve its location from the subsequent
// functions without needing to pass this value across the functions. The MMU is only enabled
// after the translation tables are populated.
// We set TTBR0 just after allocating the table to retrieve its location from
// the subsequent functions without needing to pass this value across the
// functions. The MMU is only enabled after the translation tables are
// populated.
ArmSetTTBR0(TranslationTable);
if (TranslationTableBase != NULL) {
@ -718,8 +716,8 @@ ArmConfigureMmu (
DEBUG_CODE_BEGIN();
// Find the memory attribute for the Translation Table
if ((UINTN)TranslationTable >= MemoryTable->PhysicalBase &&
(UINTN)TranslationTable + EFI_PAGE_SIZE <= MemoryTable->PhysicalBase +
MemoryTable->Length) {
(UINTN)TranslationTable + EFI_PAGE_SIZE <=
MemoryTable->PhysicalBase + MemoryTable->Length) {
TranslationTableAttribute = MemoryTable->Attributes;
}
DEBUG_CODE_END();
@ -732,13 +730,24 @@ ArmConfigureMmu (
idx++;
}
ASSERT (TranslationTableAttribute == ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK ||
TranslationTableAttribute == ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK);
ASSERT(
TranslationTableAttribute == ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK ||
TranslationTableAttribute ==
ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK);
ArmSetMAIR (MAIR_ATTR(TT_ATTR_INDX_DEVICE_MEMORY, MAIR_ATTR_DEVICE_MEMORY) | // mapped to EFI_MEMORY_UC
MAIR_ATTR(TT_ATTR_INDX_MEMORY_NON_CACHEABLE, MAIR_ATTR_NORMAL_MEMORY_NON_CACHEABLE) | // mapped to EFI_MEMORY_WC
MAIR_ATTR(TT_ATTR_INDX_MEMORY_WRITE_THROUGH, MAIR_ATTR_NORMAL_MEMORY_WRITE_THROUGH) | // mapped to EFI_MEMORY_WT
MAIR_ATTR(TT_ATTR_INDX_MEMORY_WRITE_BACK, MAIR_ATTR_NORMAL_MEMORY_WRITE_BACK)); // mapped to EFI_MEMORY_WB
ArmSetMAIR(
MAIR_ATTR(
TT_ATTR_INDX_DEVICE_MEMORY,
MAIR_ATTR_DEVICE_MEMORY) | // mapped to EFI_MEMORY_UC
MAIR_ATTR(
TT_ATTR_INDX_MEMORY_NON_CACHEABLE,
MAIR_ATTR_NORMAL_MEMORY_NON_CACHEABLE) | // mapped to EFI_MEMORY_WC
MAIR_ATTR(
TT_ATTR_INDX_MEMORY_WRITE_THROUGH,
MAIR_ATTR_NORMAL_MEMORY_WRITE_THROUGH) | // mapped to EFI_MEMORY_WT
MAIR_ATTR(
TT_ATTR_INDX_MEMORY_WRITE_BACK,
MAIR_ATTR_NORMAL_MEMORY_WRITE_BACK)); // mapped to EFI_MEMORY_WB
ArmDisableAlignmentCheck();
ArmEnableStackAlignmentCheck();
@ -755,9 +764,7 @@ FREE_TRANSLATION_TABLE:
RETURN_STATUS
EFIAPI
ArmMmuBaseLibConstructor (
VOID
)
ArmMmuBaseLibConstructor(VOID)
{
extern UINT32 ArmReplaceLiveTranslationEntrySize;
@ -765,8 +772,8 @@ ArmMmuBaseLibConstructor (
// The ArmReplaceLiveTranslationEntry () helper function may be invoked
// with the MMU off so we have to ensure that it gets cleaned to the PoC
//
WriteBackDataCacheRange (ArmReplaceLiveTranslationEntry,
ArmReplaceLiveTranslationEntrySize);
WriteBackDataCacheRange(
ArmReplaceLiveTranslationEntry, ArmReplaceLiveTranslationEntrySize);
return RETURN_SUCCESS;
}

View File

@ -16,9 +16,7 @@
EFI_STATUS
EFIAPI
ArmMmuPeiLibConstructor(
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
{
extern UINT32 ArmReplaceLiveTranslationEntrySize;
@ -39,16 +37,20 @@ ArmMmuPeiLibConstructor (
//
if ((UINTN)FileInfo.Buffer <= (UINTN)ArmReplaceLiveTranslationEntry &&
((UINTN)FileInfo.Buffer + FileInfo.BufferSize >=
(UINTN)ArmReplaceLiveTranslationEntry + ArmReplaceLiveTranslationEntrySize)) {
(UINTN)ArmReplaceLiveTranslationEntry +
ArmReplaceLiveTranslationEntrySize)) {
DEBUG((EFI_D_INFO, "ArmMmuLib: skipping cache maintenance on XIP PEIM\n"));
} else {
DEBUG ((EFI_D_INFO, "ArmMmuLib: performing cache maintenance on shadowed PEIM\n"));
}
else {
DEBUG(
(EFI_D_INFO,
"ArmMmuLib: performing cache maintenance on shadowed PEIM\n"));
//
// The ArmReplaceLiveTranslationEntry () helper function may be invoked
// with the MMU off so we have to ensure that it gets cleaned to the PoC
//
WriteBackDataCacheRange (ArmReplaceLiveTranslationEntry,
ArmReplaceLiveTranslationEntrySize);
WriteBackDataCacheRange(
ArmReplaceLiveTranslationEntry, ArmReplaceLiveTranslationEntrySize);
}
return RETURN_SUCCESS;

View File

@ -7,15 +7,15 @@
*
**/
#include <Uefi.h>
#include <Chipset/ArmV7.h>
#include <Library/BaseMemoryLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/ArmLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Uefi.h>
#define ID_MMFR0_SHARELVL_SHIFT 12
#define ID_MMFR0_SHARELVL_MASK 0xf
@ -33,37 +33,30 @@
#define __EFI_MEMORY_RWX 0 // no restrictions
#define CACHE_ATTRIBUTE_MASK (EFI_MEMORY_UC | \
EFI_MEMORY_WC | \
EFI_MEMORY_WT | \
EFI_MEMORY_WB | \
EFI_MEMORY_UCE | \
EFI_MEMORY_WP)
#define CACHE_ATTRIBUTE_MASK \
(EFI_MEMORY_UC | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB | \
EFI_MEMORY_UCE | EFI_MEMORY_WP)
UINTN
EFIAPI
ArmReadIdMmfr0 (
VOID
);
ArmReadIdMmfr0(VOID);
BOOLEAN
EFIAPI
ArmHasMpExtensions (
VOID
);
ArmHasMpExtensions(VOID);
UINT32
ConvertSectionAttributesToPageAttributes(
IN UINT32 SectionAttributes,
IN BOOLEAN IsLargePage
)
IN UINT32 SectionAttributes, IN BOOLEAN IsLargePage)
{
UINT32 PageAttributes;
PageAttributes = 0;
PageAttributes |= TT_DESCRIPTOR_CONVERT_TO_PAGE_CACHE_POLICY (SectionAttributes, IsLargePage);
PageAttributes |= TT_DESCRIPTOR_CONVERT_TO_PAGE_CACHE_POLICY(
SectionAttributes, IsLargePage);
PageAttributes |= TT_DESCRIPTOR_CONVERT_TO_PAGE_AP(SectionAttributes);
PageAttributes |= TT_DESCRIPTOR_CONVERT_TO_PAGE_XN (SectionAttributes, IsLargePage);
PageAttributes |=
TT_DESCRIPTOR_CONVERT_TO_PAGE_XN(SectionAttributes, IsLargePage);
PageAttributes |= TT_DESCRIPTOR_CONVERT_TO_PAGE_NG(SectionAttributes);
PageAttributes |= TT_DESCRIPTOR_CONVERT_TO_PAGE_S(SectionAttributes);
@ -72,9 +65,7 @@ ConvertSectionAttributesToPageAttributes (
STATIC
BOOLEAN
PreferNonshareableMemory (
VOID
)
PreferNonshareableMemory(VOID)
{
UINTN Mmfr;
UINTN Val;
@ -107,13 +98,9 @@ PreferNonshareableMemory (
}
STATIC
VOID
PopulateLevel2PageTable (
IN UINT32 *SectionEntry,
IN UINT32 PhysicalBase,
IN UINT32 RemainLength,
IN ARM_MEMORY_REGION_ATTRIBUTES Attributes
)
VOID PopulateLevel2PageTable(
IN UINT32 *SectionEntry, IN UINT32 PhysicalBase, IN UINT32 RemainLength,
IN ARM_MEMORY_REGION_ATTRIBUTES Attributes)
{
UINT32 *PageEntry;
UINT32 Pages;
@ -158,66 +145,84 @@ PopulateLevel2PageTable (
// Check if the Section Entry has already been populated. Otherwise attach a
// Level 2 Translation Table to it
if (*SectionEntry != 0) {
// The entry must be a page table. Otherwise it exists an overlapping in the memory map
// The entry must be a page table. Otherwise it exists an overlapping in the
// memory map
if (TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(*SectionEntry)) {
TranslationTable = *SectionEntry & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK;
} else if ((*SectionEntry & TT_DESCRIPTOR_SECTION_TYPE_MASK) == TT_DESCRIPTOR_SECTION_TYPE_SECTION) {
TranslationTable =
*SectionEntry & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK;
}
else if (
(*SectionEntry & TT_DESCRIPTOR_SECTION_TYPE_MASK) ==
TT_DESCRIPTOR_SECTION_TYPE_SECTION) {
// Case where a virtual memory map descriptor overlapped a section entry
// Allocate a Level2 Page Table for this Section
TranslationTable = (UINTN)AllocatePages(EFI_SIZE_TO_PAGES(TRANSLATION_TABLE_PAGE_SIZE + TRANSLATION_TABLE_PAGE_ALIGNMENT));
TranslationTable = ((UINTN)TranslationTable + TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK;
TranslationTable = (UINTN)AllocatePages(EFI_SIZE_TO_PAGES(
TRANSLATION_TABLE_PAGE_SIZE + TRANSLATION_TABLE_PAGE_ALIGNMENT));
TranslationTable =
((UINTN)TranslationTable + TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK) &
~TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK;
// Translate the Section Descriptor into Page Descriptor
SectionDescriptor = TT_DESCRIPTOR_PAGE_TYPE_PAGE | ConvertSectionAttributesToPageAttributes (*SectionEntry, FALSE);
SectionDescriptor =
TT_DESCRIPTOR_PAGE_TYPE_PAGE |
ConvertSectionAttributesToPageAttributes(*SectionEntry, FALSE);
BaseSectionAddress = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(*SectionEntry);
// Populate the new Level2 Page Table for the section
PageEntry = (UINT32 *)TranslationTable;
for (Index = 0; Index < TRANSLATION_TABLE_PAGE_COUNT; Index++) {
PageEntry[Index] = TT_DESCRIPTOR_PAGE_BASE_ADDRESS(BaseSectionAddress + (Index << 12)) | SectionDescriptor;
PageEntry[Index] = TT_DESCRIPTOR_PAGE_BASE_ADDRESS(
BaseSectionAddress + (Index << 12)) |
SectionDescriptor;
}
// Overwrite the section entry to point to the new Level2 Translation Table
*SectionEntry = (TranslationTable & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK) |
// Overwrite the section entry to point to the new Level2 Translation
// Table
*SectionEntry =
(TranslationTable & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK) |
(IS_ARM_MEMORY_REGION_ATTRIBUTES_SECURE(Attributes) ? (1 << 3) : 0) |
TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE;
} else {
}
else {
// We do not support the other section type (16MB Section)
ASSERT(0);
return;
}
} else {
TranslationTable = (UINTN)AllocatePages(EFI_SIZE_TO_PAGES(TRANSLATION_TABLE_PAGE_SIZE + TRANSLATION_TABLE_PAGE_ALIGNMENT));
TranslationTable = ((UINTN)TranslationTable + TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK;
}
else {
TranslationTable = (UINTN)AllocatePages(EFI_SIZE_TO_PAGES(
TRANSLATION_TABLE_PAGE_SIZE + TRANSLATION_TABLE_PAGE_ALIGNMENT));
TranslationTable =
((UINTN)TranslationTable + TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK) &
~TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK;
ZeroMem((VOID *)TranslationTable, TRANSLATION_TABLE_PAGE_SIZE);
*SectionEntry = (TranslationTable & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK) |
*SectionEntry =
(TranslationTable & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK) |
(IS_ARM_MEMORY_REGION_ATTRIBUTES_SECURE(Attributes) ? (1 << 3) : 0) |
TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE;
}
FirstPageOffset = (PhysicalBase & TT_DESCRIPTOR_PAGE_INDEX_MASK) >> TT_DESCRIPTOR_PAGE_BASE_SHIFT;
FirstPageOffset = (PhysicalBase & TT_DESCRIPTOR_PAGE_INDEX_MASK) >>
TT_DESCRIPTOR_PAGE_BASE_SHIFT;
PageEntry = (UINT32 *)TranslationTable + FirstPageOffset;
Pages = RemainLength / TT_DESCRIPTOR_PAGE_SIZE;
ASSERT(FirstPageOffset + Pages <= TRANSLATION_TABLE_PAGE_COUNT);
for (Index = 0; Index < Pages; Index++) {
*PageEntry++ = TT_DESCRIPTOR_PAGE_BASE_ADDRESS(PhysicalBase) | PageAttributes;
*PageEntry++ =
TT_DESCRIPTOR_PAGE_BASE_ADDRESS(PhysicalBase) | PageAttributes;
PhysicalBase += TT_DESCRIPTOR_PAGE_SIZE;
}
}
STATIC
VOID
FillTranslationTable (
IN UINT32 *TranslationTable,
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryRegion
)
VOID FillTranslationTable(
IN UINT32 *TranslationTable, IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryRegion)
{
UINT32 *SectionEntry;
UINT32 Attributes;
@ -277,24 +282,29 @@ FillTranslationTable (
}
// Get the first section entry for this mapping
SectionEntry = TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(TranslationTable, MemoryRegion->VirtualBase);
SectionEntry = TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(
TranslationTable, MemoryRegion->VirtualBase);
while (RemainLength != 0) {
if (PhysicalBase % TT_DESCRIPTOR_SECTION_SIZE == 0 &&
RemainLength >= TT_DESCRIPTOR_SECTION_SIZE) {
// Case: Physical address aligned on the Section Size (1MB) && the length
// is greater than the Section Size
*SectionEntry++ = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(PhysicalBase) | Attributes;
*SectionEntry++ =
TT_DESCRIPTOR_SECTION_BASE_ADDRESS(PhysicalBase) | Attributes;
PhysicalBase += TT_DESCRIPTOR_SECTION_SIZE;
RemainLength -= TT_DESCRIPTOR_SECTION_SIZE;
} else {
PageMapLength = MIN (RemainLength, TT_DESCRIPTOR_SECTION_SIZE -
}
else {
PageMapLength =
MIN(RemainLength, TT_DESCRIPTOR_SECTION_SIZE -
(PhysicalBase % TT_DESCRIPTOR_SECTION_SIZE));
// Case: Physical address aligned on the Section Size (1MB) && the length
// does not fill a section
// Case: Physical address NOT aligned on the Section Size (1MB)
PopulateLevel2PageTable (SectionEntry++, PhysicalBase, PageMapLength,
PopulateLevel2PageTable(
SectionEntry++, PhysicalBase, PageMapLength,
MemoryRegion->Attributes);
// If it is the last entry
@ -313,19 +323,21 @@ EFIAPI
ArmConfigureMmu(
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,
OUT VOID **TranslationTableBase OPTIONAL,
OUT UINTN *TranslationTableSize OPTIONAL
)
OUT UINTN *TranslationTableSize OPTIONAL)
{
VOID * TranslationTable;
ARM_MEMORY_REGION_ATTRIBUTES TranslationTableAttribute;
UINT32 TTBRAttributes;
// Allocate pages for translation table.
TranslationTable = AllocatePages (EFI_SIZE_TO_PAGES (TRANSLATION_TABLE_SECTION_SIZE + TRANSLATION_TABLE_SECTION_ALIGNMENT));
TranslationTable = AllocatePages(EFI_SIZE_TO_PAGES(
TRANSLATION_TABLE_SECTION_SIZE + TRANSLATION_TABLE_SECTION_ALIGNMENT));
if (TranslationTable == NULL) {
return RETURN_OUT_OF_RESOURCES;
}
TranslationTable = (VOID*)(((UINTN)TranslationTable + TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK);
TranslationTable =
(VOID
*)(((UINTN)TranslationTable + TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK);
if (TranslationTableBase != NULL) {
*TranslationTableBase = TranslationTable;
@ -341,7 +353,9 @@ ArmConfigureMmu (
TranslationTableAttribute = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
while (MemoryTable->Length != 0) {
// Find the memory attribute for the Translation Table
if (((UINTN)TranslationTable >= MemoryTable->PhysicalBase) && ((UINTN)TranslationTable <= MemoryTable->PhysicalBase - 1 + MemoryTable->Length)) {
if (((UINTN)TranslationTable >= MemoryTable->PhysicalBase) &&
((UINTN)TranslationTable <=
MemoryTable->PhysicalBase - 1 + MemoryTable->Length)) {
TranslationTableAttribute = MemoryTable->Attributes;
}
@ -351,9 +365,12 @@ ArmConfigureMmu (
// Translate the Memory Attributes into Translation Table Register Attributes
if ((TranslationTableAttribute == ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK) ||
(TranslationTableAttribute == ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK)) {
TTBRAttributes = ArmHasMpExtensions () ? TTBR_MP_WRITE_BACK_ALLOC : TTBR_WRITE_BACK_ALLOC;
} else {
(TranslationTableAttribute ==
ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK)) {
TTBRAttributes =
ArmHasMpExtensions() ? TTBR_MP_WRITE_BACK_ALLOC : TTBR_WRITE_BACK_ALLOC;
}
else {
// Page tables must reside in memory mapped as write-back cacheable
ASSERT(0);
return RETURN_UNSUPPORTED;
@ -362,13 +379,15 @@ ArmConfigureMmu (
if (TTBRAttributes & TTBR_SHAREABLE) {
if (PreferNonshareableMemory()) {
TTBRAttributes ^= TTBR_SHAREABLE;
} else {
}
else {
//
// Unlike the S bit in the short descriptors, which implies inner shareable
// on an implementation that supports two levels, the meaning of the S bit
// in the TTBR depends on the NOS bit, which defaults to Outer Shareable.
// However, we should only set this bit after we have confirmed that the
// implementation supports multiple levels, or else the NOS bit is UNK/SBZP
// Unlike the S bit in the short descriptors, which implies inner
// shareable on an implementation that supports two levels, the meaning of
// the S bit in the TTBR depends on the NOS bit, which defaults to Outer
// Shareable. However, we should only set this bit after we have confirmed
// that the implementation supports multiple levels, or else the NOS bit
// is UNK/SBZP
//
if (((ArmReadIdMmfr0() >> 12) & 0xf) != 0) {
TTBRAttributes |= TTBR_NOT_OUTER_SHAREABLE;
@ -388,7 +407,9 @@ ArmConfigureMmu (
ArmCleanInvalidateDataCache();
ArmInvalidateInstructionCache();
ArmSetTTBR0 ((VOID *)(UINTN)(((UINTN)TranslationTable & ~TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK) | (TTBRAttributes & 0x7F)));
ArmSetTTBR0((
VOID
*)(UINTN)(((UINTN)TranslationTable & ~TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK) | (TTBRAttributes & 0x7F)));
//
// The TTBCR register value is undefined at reset in the Non-Secure world.
@ -401,22 +422,15 @@ ArmConfigureMmu (
//
ArmSetTTBCR(0);
ArmSetDomainAccessControl (DOMAIN_ACCESS_CONTROL_NONE(15) |
DOMAIN_ACCESS_CONTROL_NONE(14) |
DOMAIN_ACCESS_CONTROL_NONE(13) |
DOMAIN_ACCESS_CONTROL_NONE(12) |
DOMAIN_ACCESS_CONTROL_NONE(11) |
DOMAIN_ACCESS_CONTROL_NONE(10) |
DOMAIN_ACCESS_CONTROL_NONE( 9) |
DOMAIN_ACCESS_CONTROL_NONE( 8) |
DOMAIN_ACCESS_CONTROL_NONE( 7) |
DOMAIN_ACCESS_CONTROL_NONE( 6) |
DOMAIN_ACCESS_CONTROL_NONE( 5) |
DOMAIN_ACCESS_CONTROL_NONE( 4) |
DOMAIN_ACCESS_CONTROL_NONE( 3) |
DOMAIN_ACCESS_CONTROL_NONE( 2) |
DOMAIN_ACCESS_CONTROL_NONE( 1) |
DOMAIN_ACCESS_CONTROL_CLIENT(0));
ArmSetDomainAccessControl(
DOMAIN_ACCESS_CONTROL_NONE(15) | DOMAIN_ACCESS_CONTROL_NONE(14) |
DOMAIN_ACCESS_CONTROL_NONE(13) | DOMAIN_ACCESS_CONTROL_NONE(12) |
DOMAIN_ACCESS_CONTROL_NONE(11) | DOMAIN_ACCESS_CONTROL_NONE(10) |
DOMAIN_ACCESS_CONTROL_NONE(9) | DOMAIN_ACCESS_CONTROL_NONE(8) |
DOMAIN_ACCESS_CONTROL_NONE(7) | DOMAIN_ACCESS_CONTROL_NONE(6) |
DOMAIN_ACCESS_CONTROL_NONE(5) | DOMAIN_ACCESS_CONTROL_NONE(4) |
DOMAIN_ACCESS_CONTROL_NONE(3) | DOMAIN_ACCESS_CONTROL_NONE(2) |
DOMAIN_ACCESS_CONTROL_NONE(1) | DOMAIN_ACCESS_CONTROL_CLIENT(0));
ArmEnableInstructionCache();
ArmEnableDataCache();
@ -426,9 +440,7 @@ ArmConfigureMmu (
STATIC
EFI_STATUS
ConvertSectionToPages (
IN EFI_PHYSICAL_ADDRESS BaseAddress
)
ConvertSectionToPages(IN EFI_PHYSICAL_ADDRESS BaseAddress)
{
UINT32 FirstLevelIdx;
UINT32 SectionDescriptor;
@ -439,20 +451,26 @@ ConvertSectionToPages (
volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable;
volatile ARM_PAGE_TABLE_ENTRY * PageTable;
DEBUG ((EFI_D_PAGE, "Converting section at 0x%x to pages\n", (UINTN)BaseAddress));
DEBUG((
EFI_D_PAGE, "Converting section at 0x%x to pages\n", (UINTN)BaseAddress));
// Obtain page table base
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress();
// Calculate index into first level translation table for start of modification
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
// Calculate index into first level translation table for start of
// modification
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress) >>
TT_DESCRIPTOR_SECTION_BASE_SHIFT;
ASSERT(FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);
// Get section attributes and convert to page attributes
SectionDescriptor = FirstLevelTable[FirstLevelIdx];
PageDescriptor = TT_DESCRIPTOR_PAGE_TYPE_PAGE | ConvertSectionAttributesToPageAttributes (SectionDescriptor, FALSE);
PageDescriptor =
TT_DESCRIPTOR_PAGE_TYPE_PAGE |
ConvertSectionAttributesToPageAttributes(SectionDescriptor, FALSE);
// Allocate a page table for the 4KB entries (we use up a full page even though we only need 1KB)
// Allocate a page table for the 4KB entries (we use up a full page even
// though we only need 1KB)
PageTable = (volatile ARM_PAGE_TABLE_ENTRY *)AllocatePages(1);
if (PageTable == NULL) {
return EFI_OUT_OF_RESOURCES;
@ -460,11 +478,15 @@ ConvertSectionToPages (
// Write the page table entries out
for (Index = 0; Index < TRANSLATION_TABLE_PAGE_COUNT; Index++) {
PageTable[Index] = TT_DESCRIPTOR_PAGE_BASE_ADDRESS(BaseAddress + (Index << 12)) | PageDescriptor;
PageTable[Index] =
TT_DESCRIPTOR_PAGE_BASE_ADDRESS(BaseAddress + (Index << 12)) |
PageDescriptor;
}
// Formulate page table entry, Domain=0, NS=0
PageTableDescriptor = (((UINTN)PageTable) & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK) | TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE;
PageTableDescriptor =
(((UINTN)PageTable) & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK) |
TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE;
// Write the page table entry out, replacing section entry
FirstLevelTable[FirstLevelIdx] = PageTableDescriptor;
@ -475,11 +497,8 @@ ConvertSectionToPages (
STATIC
EFI_STATUS
UpdatePageEntries(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes,
OUT BOOLEAN *FlushTlbs OPTIONAL
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes,
OUT BOOLEAN *FlushTlbs OPTIONAL)
{
EFI_STATUS Status;
UINT32 EntryValue;
@ -499,12 +518,13 @@ UpdatePageEntries (
Status = EFI_SUCCESS;
// EntryMask: bitmask of values to change (1 = change this value, 0 = leave alone)
// EntryValue: values at bit positions specified by EntryMask
// EntryMask: bitmask of values to change (1 = change this value, 0 = leave
// alone) EntryValue: values at bit positions specified by EntryMask
EntryMask = TT_DESCRIPTOR_PAGE_TYPE_MASK | TT_DESCRIPTOR_PAGE_AP_MASK;
if (Attributes & EFI_MEMORY_XP) {
EntryValue = TT_DESCRIPTOR_PAGE_TYPE_PAGE_XN;
} else {
}
else {
EntryValue = TT_DESCRIPTOR_PAGE_TYPE_PAGE;
}
@ -517,23 +537,35 @@ UpdatePageEntries (
// modify cacheability attributes
EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;
// map to strongly ordered
EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED; // TEX[2:0] = 0, C=0, B=0
} else if (Attributes & EFI_MEMORY_WC) {
EntryValue |=
TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED; // TEX[2:0] = 0, C=0,
// B=0
}
else if (Attributes & EFI_MEMORY_WC) {
// modify cacheability attributes
EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;
// map to normal non-cachable
EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE; // TEX [2:0]= 001 = 0x2, B=0, C=0
} else if (Attributes & EFI_MEMORY_WT) {
EntryValue |=
TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE; // TEX [2:0]= 001 = 0x2,
// B=0, C=0
}
else if (Attributes & EFI_MEMORY_WT) {
// modify cacheability attributes
EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;
// write through with no-allocate
EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC; // TEX [2:0] = 0, C=1, B=0
} else if (Attributes & EFI_MEMORY_WB) {
EntryValue |=
TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC; // TEX [2:0] =
// 0, C=1, B=0
}
else if (Attributes & EFI_MEMORY_WB) {
// modify cacheability attributes
EntryMask |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK;
// write back (with allocate)
EntryValue |= TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001, C=1, B=1
} else if (Attributes & CACHE_ATTRIBUTE_MASK) {
EntryValue |=
TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001,
// C=1, B=1
}
else if (Attributes & CACHE_ATTRIBUTE_MASK) {
// catch unsupported memory type attributes
ASSERT(FALSE);
return EFI_UNSUPPORTED;
@ -541,7 +573,8 @@ UpdatePageEntries (
if (Attributes & EFI_MEMORY_RO) {
EntryValue |= TT_DESCRIPTOR_PAGE_AP_RO_RO;
} else {
}
else {
EntryValue |= TT_DESCRIPTOR_PAGE_AP_RW_RW;
}
@ -556,7 +589,8 @@ UpdatePageEntries (
for (p = 0; p < NumPageEntries; p++) {
// Calculate index into first level translation table for page table value
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress + Offset) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress + Offset) >>
TT_DESCRIPTOR_SECTION_BASE_SHIFT;
ASSERT(FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);
// Read the descriptor from the first level page table
@ -564,7 +598,8 @@ UpdatePageEntries (
// Does this descriptor need to be converted from section entry to 4K pages?
if (!TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(Descriptor)) {
Status = ConvertSectionToPages (FirstLevelIdx << TT_DESCRIPTOR_SECTION_BASE_SHIFT);
Status = ConvertSectionToPages(
FirstLevelIdx << TT_DESCRIPTOR_SECTION_BASE_SHIFT);
if (EFI_ERROR(Status)) {
// Exit for loop
break;
@ -578,10 +613,12 @@ UpdatePageEntries (
}
// Obtain page table base address
PageTable = (ARM_PAGE_TABLE_ENTRY *)TT_DESCRIPTOR_PAGE_BASE_ADDRESS(Descriptor);
PageTable =
(ARM_PAGE_TABLE_ENTRY *)TT_DESCRIPTOR_PAGE_BASE_ADDRESS(Descriptor);
// Calculate index into the page table
PageTableIndex = ((BaseAddress + Offset) & TT_DESCRIPTOR_PAGE_INDEX_MASK) >> TT_DESCRIPTOR_PAGE_BASE_SHIFT;
PageTableIndex = ((BaseAddress + Offset) & TT_DESCRIPTOR_PAGE_INDEX_MASK) >>
TT_DESCRIPTOR_PAGE_BASE_SHIFT;
ASSERT(PageTableIndex < TRANSLATION_TABLE_PAGE_COUNT);
// Get the entry
@ -594,7 +631,9 @@ UpdatePageEntries (
PageTableEntry |= EntryValue;
if (CurrentPageTableEntry != PageTableEntry) {
Mva = (VOID *)(UINTN)((((UINTN)FirstLevelIdx) << TT_DESCRIPTOR_SECTION_BASE_SHIFT) + (PageTableIndex << TT_DESCRIPTOR_PAGE_BASE_SHIFT));
Mva =
(VOID
*)(UINTN)((((UINTN)FirstLevelIdx) << TT_DESCRIPTOR_SECTION_BASE_SHIFT) + (PageTableIndex << TT_DESCRIPTOR_PAGE_BASE_SHIFT));
// Only need to update if we are changing the entry
PageTable[PageTableIndex] = PageTableEntry;
@ -612,10 +651,7 @@ UpdatePageEntries (
STATIC
EFI_STATUS
UpdateSectionEntries(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
{
EFI_STATUS Status = EFI_SUCCESS;
UINT32 EntryMask;
@ -628,8 +664,8 @@ UpdateSectionEntries (
VOID * Mva;
volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable;
// EntryMask: bitmask of values to change (1 = change this value, 0 = leave alone)
// EntryValue: values at bit positions specified by EntryMask
// EntryMask: bitmask of values to change (1 = change this value, 0 = leave
// alone) EntryValue: values at bit positions specified by EntryMask
// Make sure we handle a section range that is unmapped
EntryMask = TT_DESCRIPTOR_SECTION_TYPE_MASK | TT_DESCRIPTOR_SECTION_XN_MASK |
@ -645,23 +681,36 @@ UpdateSectionEntries (
// modify cacheability attributes
EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;
// map to strongly ordered
EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED; // TEX[2:0] = 0, C=0, B=0
} else if (Attributes & EFI_MEMORY_WC) {
EntryValue |=
TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED; // TEX[2:0] = 0,
// C=0, B=0
}
else if (Attributes & EFI_MEMORY_WC) {
// modify cacheability attributes
EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;
// map to normal non-cachable
EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE; // TEX [2:0]= 001 = 0x2, B=0, C=0
} else if (Attributes & EFI_MEMORY_WT) {
EntryValue |=
TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE; // TEX [2:0]= 001 =
// 0x2, B=0, C=0
}
else if (Attributes & EFI_MEMORY_WT) {
// modify cacheability attributes
EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;
// write through with no-allocate
EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC; // TEX [2:0] = 0, C=1, B=0
} else if (Attributes & EFI_MEMORY_WB) {
EntryValue |=
TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC; // TEX [2:0]
// = 0, C=1,
// B=0
}
else if (Attributes & EFI_MEMORY_WB) {
// modify cacheability attributes
EntryMask |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK;
// write back (with allocate)
EntryValue |= TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001, C=1, B=1
} else if (Attributes & CACHE_ATTRIBUTE_MASK) {
EntryValue |=
TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001,
// C=1, B=1
}
else if (Attributes & CACHE_ATTRIBUTE_MASK) {
// catch unsupported memory type attributes
ASSERT(FALSE);
return EFI_UNSUPPORTED;
@ -669,7 +718,8 @@ UpdateSectionEntries (
if (Attributes & EFI_MEMORY_RO) {
EntryValue |= TT_DESCRIPTOR_SECTION_AP_RO_RO;
} else {
}
else {
EntryValue |= TT_DESCRIPTOR_SECTION_AP_RW_RW;
}
@ -680,8 +730,10 @@ UpdateSectionEntries (
// obtain page table base
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress();
// calculate index into first level translation table for start of modification
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
// calculate index into first level translation table for start of
// modification
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(BaseAddress) >>
TT_DESCRIPTOR_SECTION_BASE_SHIFT;
ASSERT(FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);
// calculate number of 1MB first level entries this applies to
@ -696,28 +748,32 @@ UpdateSectionEntries (
// forward this 1MB range to page table function instead
Status = UpdatePageEntries(
(FirstLevelIdx + i) << TT_DESCRIPTOR_SECTION_BASE_SHIFT,
TT_DESCRIPTOR_SECTION_SIZE,
Attributes,
NULL);
} else {
TT_DESCRIPTOR_SECTION_SIZE, Attributes, NULL);
}
else {
// still a section entry
if (CurrentDescriptor != 0) {
// mask off appropriate fields
Descriptor = CurrentDescriptor & ~EntryMask;
} else {
Descriptor = ((UINTN)FirstLevelIdx + i) << TT_DESCRIPTOR_SECTION_BASE_SHIFT;
}
else {
Descriptor = ((UINTN)FirstLevelIdx + i)
<< TT_DESCRIPTOR_SECTION_BASE_SHIFT;
}
// mask in new attributes and/or permissions
Descriptor |= EntryValue;
if (CurrentDescriptor != Descriptor) {
Mva = (VOID *)(UINTN)(((UINTN)FirstLevelIdx + i) << TT_DESCRIPTOR_SECTION_BASE_SHIFT);
Mva =
(VOID
*)(UINTN)(((UINTN)FirstLevelIdx + i) << TT_DESCRIPTOR_SECTION_BASE_SHIFT);
// Only need to update if we are changing the descriptor
FirstLevelTable[FirstLevelIdx + i] = Descriptor;
ArmUpdateTranslationTableEntry ((VOID *)&FirstLevelTable[FirstLevelIdx + i], Mva);
ArmUpdateTranslationTableEntry(
(VOID *)&FirstLevelTable[FirstLevelIdx + i], Mva);
}
Status = EFI_SUCCESS;
@ -729,10 +785,7 @@ UpdateSectionEntries (
EFI_STATUS
ArmSetMemoryAttributes(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
{
EFI_STATUS Status;
UINT64 ChunkLength;
@ -754,14 +807,16 @@ ArmSetMemoryAttributes (
ChunkLength = Length - Length % TT_DESCRIPTOR_SECTION_SIZE;
DEBUG ((DEBUG_PAGE,
DEBUG(
(DEBUG_PAGE,
"SetMemoryAttributes(): MMU section 0x%lx length 0x%lx to %lx\n",
BaseAddress, ChunkLength, Attributes));
Status = UpdateSectionEntries(BaseAddress, ChunkLength, Attributes);
FlushTlbs = TRUE;
} else {
}
else {
//
// Process page by page until the next section boundary, but only if
@ -773,12 +828,13 @@ ArmSetMemoryAttributes (
ChunkLength = Length;
}
DEBUG ((DEBUG_PAGE,
DEBUG(
(DEBUG_PAGE,
"SetMemoryAttributes(): MMU page 0x%lx length 0x%lx to %lx\n",
BaseAddress, ChunkLength, Attributes));
Status = UpdatePageEntries (BaseAddress, ChunkLength, Attributes,
&FlushTlbs);
Status =
UpdatePageEntries(BaseAddress, ChunkLength, Attributes, &FlushTlbs);
}
if (EFI_ERROR(Status)) {
@ -796,46 +852,32 @@ ArmSetMemoryAttributes (
}
EFI_STATUS
ArmSetMemoryRegionNoExec (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
ArmSetMemoryRegionNoExec(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
{
return ArmSetMemoryAttributes(BaseAddress, Length, EFI_MEMORY_XP);
}
EFI_STATUS
ArmClearMemoryRegionNoExec(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
{
return ArmSetMemoryAttributes(BaseAddress, Length, __EFI_MEMORY_RWX);
}
EFI_STATUS
ArmSetMemoryRegionReadOnly(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
{
return ArmSetMemoryAttributes(BaseAddress, Length, EFI_MEMORY_RO);
}
EFI_STATUS
ArmClearMemoryRegionReadOnly(
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
{
return ArmSetMemoryAttributes(BaseAddress, Length, __EFI_MEMORY_RWX);
}
RETURN_STATUS
EFIAPI
ArmMmuBaseLibConstructor (
VOID
)
{
return RETURN_SUCCESS;
}
ArmMmuBaseLibConstructor(VOID) { return RETURN_SUCCESS; }

View File

@ -42,9 +42,8 @@
BLK_IO_SEL_MATCH_ROOT_DEVICE)
/* Returns 0 if the volume label matches otherwise non zero */
STATIC UINTN
CompareVolumeLabel (IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* Fs,
IN CHAR8* ReqVolumeName)
STATIC UINTN CompareVolumeLabel(
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs, IN CHAR8 *ReqVolumeName)
{
INT32 CmpResult;
UINT32 j;
@ -67,8 +66,8 @@ CompareVolumeLabel (IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* Fs,
Status = FsVolume->GetInfo(FsVolume, &gEfiFileSystemInfoGuid, &Size, FsInfo);
if (Status == EFI_BUFFER_TOO_SMALL) {
FsInfo = AllocateZeroPool(Size);
Status = FsVolume->GetInfo (FsVolume,
&gEfiFileSystemInfoGuid, &Size, FsInfo);
Status =
FsVolume->GetInfo(FsVolume, &gEfiFileSystemInfoGuid, &Size, FsInfo);
if (Status != EFI_SUCCESS) {
FreePool(FsInfo);
return 1;
@ -83,8 +82,7 @@ CompareVolumeLabel (IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* Fs,
for (j = 0; (j < VOLUME_LABEL_SIZE - 1) && ReqVolumeName[j]; ++j) {
VolumeLabel[j] = ReqVolumeName[j];
if ((VolumeLabel[j] >= 'a') &&
(VolumeLabel[j] <= 'z')) {
if ((VolumeLabel[j] >= 'a') && (VolumeLabel[j] <= 'z')) {
VolumeLabel[j] -= ('a' - 'A');
}
}
@ -95,8 +93,7 @@ CompareVolumeLabel (IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* Fs,
/* Change any lower chars in volume name to upper
* (ideally this is not needed) */
for (j = 0; (j < VOLUME_LABEL_SIZE - 1) && FsInfo->VolumeLabel[j]; ++j) {
if ((FsInfo->VolumeLabel[j] >= 'a') &&
(FsInfo->VolumeLabel[j] <= 'z')) {
if ((FsInfo->VolumeLabel[j] >= 'a') && (FsInfo->VolumeLabel[j] <= 'z')) {
FsInfo->VolumeLabel[j] -= ('a' - 'A');
}
}
@ -111,11 +108,11 @@ CompareVolumeLabel (IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* Fs,
EFI_STATUS
EFIAPI
GetPartitionEntry (IN EFI_HANDLE Handle,
OUT EFI_PARTITION_ENTRY **PartEntry)
GetPartitionEntry(IN EFI_HANDLE Handle, OUT EFI_PARTITION_ENTRY **PartEntry)
{
EFI_PARTITION_INFO_PROTOCOL *PartInfo;
EFI_STATUS Status = gBS->HandleProtocol (Handle, &gEfiPartitionInfoProtocolGuid, (VOID **)&PartInfo);
EFI_STATUS Status = gBS->HandleProtocol(
Handle, &gEfiPartitionInfoProtocolGuid, (VOID **)&PartInfo);
if (!EFI_ERROR(Status)) {
*PartEntry = &PartInfo->Info.Gpt;
}
@ -139,10 +136,9 @@ On output, the number of handle structures returned.
*/
EFI_STATUS
EFIAPI
GetBlkIOHandles (IN UINT32 SelectionAttrib,
IN PartiSelectFilter *FilterData,
OUT HandleInfo *HandleInfoPtr,
IN OUT UINT32* MaxBlkIopCnt)
GetBlkIOHandles(
IN UINT32 SelectionAttrib, IN PartiSelectFilter *FilterData,
OUT HandleInfo *HandleInfoPtr, IN OUT UINT32 *MaxBlkIopCnt)
{
EFI_BLOCK_IO_PROTOCOL * BlkIo;
EFI_HANDLE * BlkIoHandles;
@ -176,25 +172,26 @@ GetBlkIOHandles (IN UINT32 SelectionAttrib,
* than BlkIo */
if (SelectionAttrib & (BLK_IO_SEL_SELECT_MOUNTED_FILESYSTEM |
BLK_IO_SEL_SELECT_BY_VOLUME_NAME)) {
Status =
gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleFileSystemProtocolGuid,
NULL, &BlkIoHandleCount, &BlkIoHandles);
} else {
Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid,
NULL, &BlkIoHandleCount, &BlkIoHandles);
Status = gBS->LocateHandleBuffer(
ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &BlkIoHandleCount,
&BlkIoHandles);
}
else {
Status = gBS->LocateHandleBuffer(
ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlkIoHandleCount,
&BlkIoHandles);
}
if (Status != EFI_SUCCESS) {
DEBUG (
(EFI_D_ERROR, "Unable to get Filesystem Handle buffer %r\n", Status));
DEBUG((EFI_D_ERROR, "Unable to get Filesystem Handle buffer %r\n", Status));
return Status;
}
/* Loop through to search for the ones we are interested in. */
for (i = 0; i < BlkIoHandleCount; i++) {
Status = gBS->HandleProtocol (BlkIoHandles[i], &gEfiBlockIoProtocolGuid,
(VOID **)&BlkIo);
Status = gBS->HandleProtocol(
BlkIoHandles[i], &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo);
/* Fv volumes will not support Blk I/O protocol */
if (Status == EFI_UNSUPPORTED) {
continue;
@ -209,7 +206,8 @@ GetBlkIOHandles (IN UINT32 SelectionAttrib,
if (BlkIo->Media->RemovableMedia) {
if ((SelectionAttrib & BLK_IO_SEL_MEDIA_TYPE_REMOVABLE) == 0)
continue;
} else {
}
else {
if ((SelectionAttrib & BLK_IO_SEL_MEDIA_TYPE_NON_REMOVABLE) == 0)
continue;
}
@ -247,8 +245,8 @@ GetBlkIOHandles (IN UINT32 SelectionAttrib,
(RootDevicePath->Header.Length[1] << 8)) !=
sizeof(VENDOR_DEVICE_PATH) ||
((FilterData->RootDeviceType != NULL) &&
(CompareGuid (FilterData->RootDeviceType,
&RootDevicePath->Guid) == FALSE)))
(CompareGuid(FilterData->RootDeviceType, &RootDevicePath->Guid) ==
FALSE)))
continue;
}
@ -285,20 +283,20 @@ GetBlkIOHandles (IN UINT32 SelectionAttrib,
if ((SelectionAttrib & BLK_IO_SEL_MATCH_PARTITION_TYPE_GUID) != 0) {
VOID *Interface;
if (!FilterData ||
FilterData->PartitionType == NULL) {
if (!FilterData || FilterData->PartitionType == NULL) {
return EFI_INVALID_PARAMETER;
}
Status = gBS->HandleProtocol (BlkIoHandles[i],
FilterData->PartitionType,
(VOID**)&Interface);
Status = gBS->HandleProtocol(
BlkIoHandles[i], FilterData->PartitionType, (VOID **)&Interface);
if (EFI_ERROR(Status)) {
Status = GetPartitionEntry(BlkIoHandles[i], &PartEntry);
if (EFI_ERROR(Status)) {
continue;
}
if (CompareGuid (&PartEntry->PartitionTypeGUID, FilterData->PartitionType) == FALSE) {
if (CompareGuid(
&PartEntry->PartitionTypeGUID, FilterData->PartitionType) ==
FALSE) {
continue;
}
}
@ -312,15 +310,14 @@ GetBlkIOHandles (IN UINT32 SelectionAttrib,
/* Check if the Filesystem related criteria satisfies */
if ((SelectionAttrib & BLK_IO_SEL_SELECT_MOUNTED_FILESYSTEM) != 0) {
Status = gBS->HandleProtocol (BlkIoHandles[i],
&gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs);
Status = gBS->HandleProtocol(
BlkIoHandles[i], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs);
if (EFI_ERROR(Status)) {
continue;
}
if ((SelectionAttrib & BLK_IO_SEL_SELECT_BY_VOLUME_NAME) != 0) {
if (!FilterData ||
FilterData->VolumeName == NULL) {
if (!FilterData || FilterData->VolumeName == NULL) {
return EFI_INVALID_PARAMETER;
}
if (CompareVolumeLabel(Fs, FilterData->VolumeName) != 0) {
@ -334,7 +331,8 @@ GetBlkIOHandles (IN UINT32 SelectionAttrib,
Status = GetPartitionEntry(BlkIoHandles[i], &PartEntry);
if (Status != EFI_SUCCESS)
continue;
if (StrnCmp (PartEntry->PartitionName, FilterData->PartitionLabel,
if (StrnCmp(
PartEntry->PartitionName, FilterData->PartitionLabel,
MAX(StrLen(PartEntry->PartitionName),
StrLen(FilterData->PartitionLabel))))
continue;

View File

@ -19,14 +19,17 @@
#include <Library/BootSlotLib/EFIUtils.h>
#include <Library/UefiLib.h>
void WaitAnyKey(EFI_SYSTEM_TABLE *mSystemTable) {
void WaitAnyKey(EFI_SYSTEM_TABLE *mSystemTable)
{
UINTN index = 0;
EFI_INPUT_KEY Key;
mSystemTable->BootServices->WaitForEvent(1, &mSystemTable->ConIn->WaitForKey, &index);
mSystemTable->BootServices->WaitForEvent(
1, &mSystemTable->ConIn->WaitForKey, &index);
mSystemTable->ConIn->ReadKeyStroke(mSystemTable->ConIn, &Key);
}
void PrintAndWaitAnyKey(EFI_SYSTEM_TABLE *mSystemTable, CHAR16 *Message) {
void PrintAndWaitAnyKey(EFI_SYSTEM_TABLE *mSystemTable, CHAR16 *Message)
{
Print(Message);
WaitAnyKey(mSystemTable);
}

View File

@ -28,11 +28,11 @@
*/
#include "AutoGen.h"
#include <Library/BootSlotLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h>
#include <Uefi.h>
#include <Uefi/UefiSpec.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/BootSlotLib.h>
struct StoragePartInfo Ptable[MAX_LUNS];
struct PartitionEntry PtnEntries[MAX_NUM_PARTITIONS];
@ -41,8 +41,7 @@ STATIC UINT32 PartitionCount;
STATIC struct PartitionEntry PtnEntriesBak[MAX_NUM_PARTITIONS];
STATIC struct BootPartsLinkedList *HeadNode;
STATIC EFI_STATUS
GetActiveSlot (Slot *ActiveSlot);
STATIC EFI_STATUS GetActiveSlot(Slot *ActiveSlot);
Slot GetCurrentSlotSuffix(VOID)
{
@ -57,8 +56,7 @@ Slot GetCurrentSlotSuffix (VOID)
return CurrentSlot;
}
VOID
GetPartitionCount (UINT32 *Val)
VOID GetPartitionCount(UINT32 *Val)
{
*Val = PartitionCount;
return;
@ -74,16 +72,19 @@ VOID UpdatePartitionEntries (VOID)
PartitionCount = 0;
/*Nullify the PtnEntries array before using it*/
gBS->SetMem ((VOID *)PtnEntries,
(sizeof (PtnEntries[0]) * MAX_NUM_PARTITIONS), 0);
gBS->SetMem(
(VOID *)PtnEntries, (sizeof(PtnEntries[0]) * MAX_NUM_PARTITIONS), 0);
for (i = 0; i < MaxLuns; i++) {
for (j = 0; (j < Ptable[i].MaxHandles) && (Index < MAX_NUM_PARTITIONS);
j++, Index++) {
Status = GetPartitionEntry(Ptable[i].HandleInfoList[j].Handle, &PartEntry);
Status =
GetPartitionEntry(Ptable[i].HandleInfoList[j].Handle, &PartEntry);
PartitionCount++;
if (EFI_ERROR(Status)) {
DEBUG ((EFI_D_VERBOSE, "Selected Lun : %d, handle: %d does not have "
DEBUG(
(EFI_D_VERBOSE,
"Selected Lun : %d, handle: %d does not have "
"partition record, ignore\n",
i, j));
PtnEntries[Index].lun = i;
@ -103,7 +104,8 @@ GetPartitionIndex (CHAR16 *Pname)
INT32 i;
for (i = 0; i < PartitionCount; i++) {
if (!StrnCmp (PtnEntries[i].PartEntry.PartitionName, Pname,
if (!StrnCmp(
PtnEntries[i].PartEntry.PartitionName, Pname,
ARRAY_SIZE(PtnEntries[i].PartEntry.PartitionName))) {
return i;
}
@ -130,16 +132,15 @@ GetStorageHandle (INT32 Lun, HandleInfo *BlockIoHandle, UINT32 *MaxHandles)
if (Lun == NO_LUN) {
HandleFilter.RootDeviceType = &gEfiEmmcUserPartitionGuid;
Status =
GetBlkIOHandles (Attribs, &HandleFilter, BlockIoHandle, MaxHandles);
Status = GetBlkIOHandles(Attribs, &HandleFilter, BlockIoHandle, MaxHandles);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "Error getting block IO handle for Emmc\n"));
return Status;
}
} else {
}
else {
HandleFilter.RootDeviceType = &LunGuids[Lun];
Status =
GetBlkIOHandles (Attribs, &HandleFilter, BlockIoHandle, MaxHandles);
Status = GetBlkIOHandles(Attribs, &HandleFilter, BlockIoHandle, MaxHandles);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "Error getting block IO handle for Lun:%x\n", Lun));
return Status;
@ -173,7 +174,8 @@ UINT64 GetPartitionSize (EFI_BLOCK_IO_PROTOCOL *BlockIo)
if ((MAX_UINT64 / (BlockIo->Media->LastBlock + 1)) <
(UINT64)BlockIo->Media->BlockSize) {
DEBUG ((EFI_D_ERROR,
DEBUG(
(EFI_D_ERROR,
"Integer overflow while multiplying LastBlock and BlockSize\n"));
return 0;
}
@ -222,21 +224,24 @@ VOID UpdatePartitionAttributes (UINT32 UpdateType)
if (!AsciiStrnCmp(BootDeviceType, "EMMC", AsciiStrLen("EMMC"))) {
Status = GetStorageHandle(NO_LUN, BlockIoHandle, &MaxHandles);
} else if (!AsciiStrnCmp (BootDeviceType, "UFS", AsciiStrLen ("UFS"))) {
}
else if (!AsciiStrnCmp(BootDeviceType, "UFS", AsciiStrLen("UFS"))) {
Status = GetStorageHandle(Lun, BlockIoHandle, &MaxHandles);
} else {
}
else {
DEBUG((EFI_D_ERROR, "Unsupported boot device type\n"));
return;
}
if (Status != EFI_SUCCESS) {
DEBUG ((EFI_D_ERROR,
"Failed to get BlkIo for device. MaxHandles:%d - %r\n",
DEBUG(
(EFI_D_ERROR, "Failed to get BlkIo for device. MaxHandles:%d - %r\n",
MaxHandles, Status));
return;
}
if (MaxHandles != 1) {
DEBUG ((EFI_D_VERBOSE,
DEBUG(
(EFI_D_VERBOSE,
"Failed to get the BlockIo for device. MaxHandle:%d, %r\n",
MaxHandles, Status));
continue;
@ -264,8 +269,9 @@ VOID UpdatePartitionAttributes (UINT32 UpdateType)
for (Iter = 0; Iter < 2;
Iter++, (Offset = CardSizeSec - MaxGptPartEntrySzBytes / BlkSz)) {
SkipUpdation = TRUE;
Status = BlockIo->ReadBlocks (BlockIo, BlockIo->Media->MediaId, Offset,
MaxGptPartEntrySzBytes, GptHdr);
Status = BlockIo->ReadBlocks(
BlockIo, BlockIo->Media->MediaId, Offset, MaxGptPartEntrySzBytes,
GptHdr);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "Unable to read the media \n"));
@ -276,7 +282,8 @@ VOID UpdatePartitionAttributes (UINT32 UpdateType)
/* This is the back up GPT */
Ptn_Entries = GptHdr;
GptHdr = GptHdr + ((PartEntriesblocks)*BlkSz);
} else
}
else
/* otherwise we are at the primary gpt */
Ptn_Entries = GptHdr + BlkSz;
@ -303,18 +310,18 @@ VOID UpdatePartitionAttributes (UINT32 UpdateType)
}
Attr = GET_LLWORD_FROM_BYTE(&PtnEntriesPtr[ATTRIBUTE_FLAG_OFFSET]);
if (UpdateType & PARTITION_GUID_MASK) {
if (CompareMem (&InMemPtnEnt->PartEntry.PartitionTypeGUID,
if (CompareMem(
&InMemPtnEnt->PartEntry.PartitionTypeGUID,
&PtnEntries[i].PartEntry.PartitionTypeGUID,
sizeof(EFI_GUID))) {
/* Update the partition GUID values */
gBS->CopyMem ((VOID *)PtnEntriesPtr,
(VOID *)&PtnEntries[i].PartEntry.PartitionTypeGUID,
GUID_SIZE);
gBS->CopyMem(
(VOID *)PtnEntriesPtr,
(VOID *)&PtnEntries[i].PartEntry.PartitionTypeGUID, GUID_SIZE);
/* Update the PtnEntriesBak for next comparison */
gBS->CopyMem(
(VOID *)&PtnEntriesBak[i].PartEntry.PartitionTypeGUID,
(VOID *)&PtnEntries[i].PartEntry.PartitionTypeGUID,
GUID_SIZE);
(VOID *)&PtnEntries[i].PartEntry.PartitionTypeGUID, GUID_SIZE);
SkipUpdation = FALSE;
}
}
@ -324,22 +331,24 @@ VOID UpdatePartitionAttributes (UINT32 UpdateType)
* If GUID is present, and the GUID is matched, update it
*/
if (!(InMemPtnEnt->PartEntry.PartitionTypeGUID.Data1) ||
!CompareMem (&InMemPtnEnt->PartEntry.PartitionTypeGUID,
!CompareMem(
&InMemPtnEnt->PartEntry.PartitionTypeGUID,
&PtnEntries[i].PartEntry.PartitionTypeGUID,
sizeof(EFI_GUID))) {
if (Attr != PtnEntries[i].PartEntry.Attributes) {
/* Update the partition attributes */
PUT_LONG_LONG (&PtnEntriesPtr[ATTRIBUTE_FLAG_OFFSET],
PUT_LONG_LONG(
&PtnEntriesPtr[ATTRIBUTE_FLAG_OFFSET],
PtnEntries[i].PartEntry.Attributes);
/* Update the PtnEntriesBak for next comparison */
PtnEntriesBak[i].PartEntry.Attributes =
PtnEntries[i].PartEntry.Attributes;
SkipUpdation = FALSE;
}
} else {
}
else {
if (InMemPtnEnt->PartEntry.PartitionTypeGUID.Data1) {
DEBUG ((EFI_D_ERROR,
"Error in GPT header, GUID is not match!\n"));
DEBUG((EFI_D_ERROR, "Error in GPT header, GUID is not match!\n"));
continue;
}
}
@ -356,16 +365,18 @@ VOID UpdatePartitionAttributes (UINT32 UpdateType)
PtnEntrySz = GET_LWORD_FROM_BYTE(&GptHdr[PENTRY_SIZE_OFFSET]);
if (((UINT64)(MaxPtnCount)*PtnEntrySz) > MAX_PARTITION_ENTRIES_SZ) {
DEBUG ((EFI_D_ERROR,
DEBUG(
(EFI_D_ERROR,
"Invalid GPT header fields MaxPtnCount = %x, PtnEntrySz = %x\n",
MaxPtnCount, PtnEntrySz));
goto Exit;
}
Status = gBS->CalculateCrc32 (Ptn_Entries, ((MaxPtnCount) * (PtnEntrySz)),
&CrcVal);
Status = gBS->CalculateCrc32(
Ptn_Entries, ((MaxPtnCount) * (PtnEntrySz)), &CrcVal);
if (Status != EFI_SUCCESS) {
DEBUG ((EFI_D_ERROR, "Error Calculating CRC32 on the Gpt header: %x\n",
DEBUG(
(EFI_D_ERROR, "Error Calculating CRC32 on the Gpt header: %x\n",
Status));
goto Exit;
}
@ -378,7 +389,8 @@ VOID UpdatePartitionAttributes (UINT32 UpdateType)
Status = gBS->CalculateCrc32(GptHdr, HdrSz, &CrcVal);
if (Status != EFI_SUCCESS) {
DEBUG ((EFI_D_ERROR, "Error Calculating CRC32 on the Gpt header: %x\n",
DEBUG(
(EFI_D_ERROR, "Error Calculating CRC32 on the Gpt header: %x\n",
Status));
goto Exit;
}
@ -388,13 +400,14 @@ VOID UpdatePartitionAttributes (UINT32 UpdateType)
if (Iter == 0x1)
/* Write the backup GPT header, which is at an offset of CardSizeSec -
* MaxGptPartEntrySzBytes/BlkSz in blocks*/
Status =
BlockIo->WriteBlocks (BlockIo, BlockIo->Media->MediaId, Offset,
MaxGptPartEntrySzBytes, (VOID *)Ptn_Entries);
Status = BlockIo->WriteBlocks(
BlockIo, BlockIo->Media->MediaId, Offset, MaxGptPartEntrySzBytes,
(VOID *)Ptn_Entries);
else
/* Write the primary GPT header, which is at an offset of BlkSz */
Status = BlockIo->WriteBlocks (BlockIo, BlockIo->Media->MediaId, Offset,
MaxGptPartEntrySzBytes, (VOID *)GptHdr);
Status = BlockIo->WriteBlocks(
BlockIo, BlockIo->Media->MediaId, Offset, MaxGptPartEntrySzBytes,
(VOID *)GptHdr);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "Error writing primary GPT header: %r\n", Status));
@ -412,8 +425,7 @@ Exit:
}
}
STATIC VOID
MarkPtnActive (CHAR16 *ActiveSlot)
STATIC VOID MarkPtnActive(CHAR16 *ActiveSlot)
{
UINT32 i;
for (i = 0; i < PartitionCount; i++) {
@ -428,19 +440,17 @@ MarkPtnActive (CHAR16 *ActiveSlot)
UpdatePartitionAttributes(PARTITION_ATTRIBUTES);
}
STATIC VOID
SwapPtnGuid (EFI_PARTITION_ENTRY *p1, EFI_PARTITION_ENTRY *p2)
STATIC VOID SwapPtnGuid(EFI_PARTITION_ENTRY *p1, EFI_PARTITION_ENTRY *p2)
{
EFI_GUID Temp;
if (p1 == NULL || p2 == NULL)
return;
gBS->CopyMem ((VOID *)&Temp, (VOID *)&p1->PartitionTypeGUID,
sizeof (EFI_GUID));
gBS->CopyMem ((VOID *)&p1->PartitionTypeGUID, (VOID *)&p2->PartitionTypeGUID,
sizeof (EFI_GUID));
gBS->CopyMem ((VOID *)&p2->PartitionTypeGUID, (VOID *)&Temp,
gBS->CopyMem((VOID *)&Temp, (VOID *)&p1->PartitionTypeGUID, sizeof(EFI_GUID));
gBS->CopyMem(
(VOID *)&p1->PartitionTypeGUID, (VOID *)&p2->PartitionTypeGUID,
sizeof(EFI_GUID));
gBS->CopyMem((VOID *)&p2->PartitionTypeGUID, (VOID *)&Temp, sizeof(EFI_GUID));
}
STATIC EFI_STATUS GetMultiSlotPartsList(VOID)
@ -465,19 +475,22 @@ STATIC EFI_STATUS GetMultiSlotPartsList (VOID)
/*Need to compare till "boot_"a hence skip last Char from StrLen value*/
if ((PtnLen == Len) &&
!StrnCmp (PtnEntries[j].PartEntry.PartitionName,
SearchString, Len - 1) &&
!StrnCmp(
PtnEntries[j].PartEntry.PartitionName, SearchString, Len - 1) &&
(StrStr(SearchString, (CONST CHAR16 *)L"_a") ||
StrStr(SearchString, (CONST CHAR16 *)L"_b"))) {
TempNode = AllocateZeroPool(sizeof(struct BootPartsLinkedList));
if (TempNode) {
/*Skip _a/_b from partition name*/
StrnCpyS (TempNode->PartName, sizeof (TempNode->PartName),
SearchString, Len - 2);
StrnCpyS(
TempNode->PartName, sizeof(TempNode->PartName), SearchString,
Len - 2);
TempNode->Next = HeadNode;
HeadNode = TempNode;
} else {
DEBUG ((EFI_D_ERROR,
}
else {
DEBUG(
(EFI_D_ERROR,
"Unable to Allocate Memory for MultiSlot Partition list\n"));
return EFI_OUT_OF_RESOURCES;
}
@ -488,8 +501,7 @@ STATIC EFI_STATUS GetMultiSlotPartsList (VOID)
return EFI_SUCCESS;
}
STATIC VOID
SwitchPtnSlots (CONST CHAR16 *SetActive)
STATIC VOID SwitchPtnSlots(CONST CHAR16 *SetActive)
{
UINT32 i;
struct PartitionEntry * PtnCurrent = NULL;
@ -505,12 +517,13 @@ SwitchPtnSlots (CONST CHAR16 *SetActive)
CHAR8 BootDeviceType[BOOT_DEV_NAME_SIZE_MAX];
/* Create the partition name string for active and non active slots*/
if (!StrnCmp (SetActive, (CONST CHAR16 *)L"_a",
StrLen ((CONST CHAR16 *)L"_a")))
StrnCpyS (SetInactive, MAX_SLOT_SUFFIX_SZ, (CONST CHAR16 *)L"_b",
if (!StrnCmp(SetActive, (CONST CHAR16 *)L"_a", StrLen((CONST CHAR16 *)L"_a")))
StrnCpyS(
SetInactive, MAX_SLOT_SUFFIX_SZ, (CONST CHAR16 *)L"_b",
StrLen((CONST CHAR16 *)L"_b"));
else
StrnCpyS (SetInactive, MAX_SLOT_SUFFIX_SZ, (CONST CHAR16 *)L"_a",
StrnCpyS(
SetInactive, MAX_SLOT_SUFFIX_SZ, (CONST CHAR16 *)L"_a",
StrLen((CONST CHAR16 *)L"_a"));
if (!HeadNode) {
@ -525,21 +538,26 @@ SwitchPtnSlots (CONST CHAR16 *SetActive)
gBS->SetMem(CurSlot, BOOT_PART_SIZE, 0);
gBS->SetMem(NewSlot, BOOT_PART_SIZE, 0);
StrnCpyS (CurSlot, BOOT_PART_SIZE, TempNode->PartName,
StrnCpyS(
CurSlot, BOOT_PART_SIZE, TempNode->PartName,
StrLen(TempNode->PartName));
StrnCatS(CurSlot, BOOT_PART_SIZE, SetInactive, StrLen(SetInactive));
StrnCpyS (NewSlot, BOOT_PART_SIZE, TempNode->PartName,
StrnCpyS(
NewSlot, BOOT_PART_SIZE, TempNode->PartName,
StrLen(TempNode->PartName));
StrnCatS(NewSlot, BOOT_PART_SIZE, SetActive, StrLen(SetActive));
/* Find the pointer to partition table entry for active and non-active
* slots*/
for (i = 0; i < PartitionCount; i++) {
if (!StrnCmp (PtnEntries[i].PartEntry.PartitionName, CurSlot,
if (!StrnCmp(
PtnEntries[i].PartEntry.PartitionName, CurSlot,
StrLen(CurSlot))) {
PtnCurrent = &PtnEntries[i];
} else if (!StrnCmp (PtnEntries[i].PartEntry.PartitionName, NewSlot,
}
else if (!StrnCmp(
PtnEntries[i].PartEntry.PartitionName, NewSlot,
StrLen(NewSlot))) {
PtnNew = &PtnEntries[i];
}
@ -555,13 +573,15 @@ SwitchPtnSlots (CONST CHAR16 *SetActive)
// Special case for XBL is to change the bootlun instead of swapping the
// guid
if (UfsBootLun == 0x1 &&
!StrnCmp (SetActive, (CONST CHAR16 *)L"_b",
StrLen ((CONST CHAR16 *)L"_b"))) {
!StrnCmp(
SetActive, (CONST CHAR16 *)L"_b", StrLen((CONST CHAR16 *)L"_b"))) {
DEBUG((EFI_D_INFO, "Switching the boot lun from 1 to 2\n"));
UfsBootLun = 0x2;
} else if (UfsBootLun == 0x2 &&
!StrnCmp (SetActive, (CONST CHAR16 *)L"_a",
StrLen ((CONST CHAR16 *)L"_a"))) {
}
else if (
UfsBootLun == 0x2 &&
!StrnCmp(
SetActive, (CONST CHAR16 *)L"_a", StrLen((CONST CHAR16 *)L"_a"))) {
DEBUG((EFI_D_INFO, "Switching the boot lun from 2 to 1\n"));
UfsBootLun = 0x1;
}
@ -594,8 +614,8 @@ EnumeratePartitions (VOID)
HandleFilter.VolumeName = NULL;
HandleFilter.RootDeviceType = &gEfiEmmcUserPartitionGuid;
Status =
GetBlkIOHandles (Attribs, &HandleFilter, &Ptable[0].HandleInfoList[0],
Status = GetBlkIOHandles(
Attribs, &HandleFilter, &Ptable[0].HandleInfoList[0],
&Ptable[0].MaxHandles);
if (Status == EFI_SUCCESS && Ptable[0].MaxHandles > 0) {
MaxLuns = 1;
@ -612,21 +632,23 @@ EnumeratePartitions (VOID)
HandleFilter.VolumeName = NULL;
HandleFilter.RootDeviceType = &LunGuids[i];
Status =
GetBlkIOHandles (Attribs, &HandleFilter, &Ptable[i].HandleInfoList[0],
Status = GetBlkIOHandles(
Attribs, &HandleFilter, &Ptable[i].HandleInfoList[0],
&Ptable[i].MaxHandles);
/* If we fail to get block for a lun that means the lun is not configured
* and unsed, ignore the error
* and continue with the next Lun */
if (EFI_ERROR(Status)) {
DEBUG ((EFI_D_ERROR,
DEBUG(
(EFI_D_ERROR,
"Error getting block IO handle for %d lun, Lun may be unused\n",
i));
continue;
}
}
MaxLuns = i;
} else {
}
else {
DEBUG((EFI_D_ERROR, "Error populating block IO handles\n"));
return EFI_NOT_FOUND;
}
@ -658,26 +680,34 @@ PartitionHasMultiSlot (CONST CHAR16 *Pname)
return FALSE;
}
STATIC struct PartitionEntry *
GetBootPartitionEntry (Slot *BootSlot)
STATIC struct PartitionEntry *GetBootPartitionEntry(Slot *BootSlot)
{
INT32 Index = INVALID_PTN;
if (StrnCmp ((CONST CHAR16 *)L"_a", BootSlot->Suffix,
StrLen (BootSlot->Suffix)) == 0) {
if (StrnCmp(
(CONST CHAR16 *)L"_a", BootSlot->Suffix, StrLen(BootSlot->Suffix)) ==
0) {
Index = GetPartitionIndex((CHAR16 *)L"boot_a");
} else if (StrnCmp ((CONST CHAR16 *)L"_b", BootSlot->Suffix,
StrLen (BootSlot->Suffix)) == 0) {
}
else if (
StrnCmp(
(CONST CHAR16 *)L"_b", BootSlot->Suffix, StrLen(BootSlot->Suffix)) ==
0) {
Index = GetPartitionIndex((CHAR16 *)L"boot_b");
} else {
DEBUG ((EFI_D_ERROR, "GetBootPartitionEntry: No boot partition "
}
else {
DEBUG(
(EFI_D_ERROR,
"GetBootPartitionEntry: No boot partition "
"entry for slot %s\n",
BootSlot->Suffix));
return NULL;
}
if (Index == INVALID_PTN) {
DEBUG ((EFI_D_ERROR, "GetBootPartitionEntry: No boot partition entry "
DEBUG(
(EFI_D_ERROR,
"GetBootPartitionEntry: No boot partition entry "
"for slot %s, invalid index\n",
BootSlot->Suffix));
return NULL;
@ -690,12 +720,15 @@ BOOLEAN IsSlotBootable (Slot *BootSlot)
struct PartitionEntry *BootPartition = NULL;
BootPartition = GetBootPartitionEntry(BootSlot);
if (BootPartition == NULL) {
DEBUG ((EFI_D_ERROR, "IsCurrentSlotBootable: No boot partition "
DEBUG(
(EFI_D_ERROR,
"IsCurrentSlotBootable: No boot partition "
"entry for slot %s\n",
BootSlot->Suffix));
return FALSE;
}
DEBUG ((EFI_D_VERBOSE, "Slot suffix %s Part Attr 0x%lx\n", BootSlot->Suffix,
DEBUG(
(EFI_D_VERBOSE, "Slot suffix %s Part Attr 0x%lx\n", BootSlot->Suffix,
BootPartition->PartEntry.Attributes));
if (!(BootPartition->PartEntry.Attributes & PART_ATT_UNBOOTABLE_VAL) &&
@ -713,8 +746,8 @@ EFI_STATUS ClearUnbootable (Slot *BootSlot)
struct PartitionEntry *BootEntry = NULL;
BootEntry = GetBootPartitionEntry(BootSlot);
if (BootEntry == NULL) {
DEBUG ((EFI_D_ERROR,
"ClearUnbootable: No boot partition entry for slot %s\n",
DEBUG(
(EFI_D_ERROR, "ClearUnbootable: No boot partition entry for slot %s\n",
BootSlot->Suffix));
return EFI_NOT_FOUND;
}
@ -737,8 +770,7 @@ IsSuffixEmpty (Slot *CheckSlot)
return FALSE;
}
STATIC EFI_STATUS
GetActiveSlot (Slot *ActiveSlot)
STATIC EFI_STATUS GetActiveSlot(Slot *ActiveSlot)
{
EFI_STATUS Status = EFI_SUCCESS;
Slot Slots[] = {{L"_a"}, {L"_b"}};
@ -754,7 +786,9 @@ GetActiveSlot (Slot *ActiveSlot)
GetBootPartitionEntry(&Slots[SlotIndex]);
UINT64 BootPriority = 0;
if (BootPartition == NULL) {
DEBUG ((EFI_D_ERROR, "GetActiveSlot: No boot partition "
DEBUG(
(EFI_D_ERROR,
"GetActiveSlot: No boot partition "
"entry for slot %s\n",
Slots[SlotIndex].Suffix));
return EFI_NOT_FOUND;
@ -766,14 +800,15 @@ GetActiveSlot (Slot *ActiveSlot)
if ((BootPartition->PartEntry.Attributes & PART_ATT_ACTIVE_VAL) &&
(BootPriority > Priority)) {
GUARD (StrnCpyS (ActiveSlot->Suffix, ARRAY_SIZE (ActiveSlot->Suffix),
Slots[SlotIndex].Suffix,
StrLen (Slots[SlotIndex].Suffix)));
GUARD(StrnCpyS(
ActiveSlot->Suffix, ARRAY_SIZE(ActiveSlot->Suffix),
Slots[SlotIndex].Suffix, StrLen(Slots[SlotIndex].Suffix)));
Priority = BootPriority;
}
}
DEBUG ((EFI_D_VERBOSE, "GetActiveSlot: found active slot %s, priority %d\n",
DEBUG(
(EFI_D_VERBOSE, "GetActiveSlot: found active slot %s, priority %d\n",
ActiveSlot->Suffix, Priority));
if (IsSuffixEmpty(ActiveSlot) == TRUE) {
@ -783,7 +818,9 @@ GetActiveSlot (Slot *ActiveSlot)
UINT64 RetryCount = 0;
struct PartitionEntry *SlotA = GetBootPartitionEntry(&Slots[0]);
if (SlotA == NULL) {
DEBUG ((EFI_D_ERROR, "GetActiveSlot: First Boot: No boot partition "
DEBUG(
(EFI_D_ERROR,
"GetActiveSlot: First Boot: No boot partition "
"entry for slot %s\n",
Slots[0].Suffix));
return EFI_NOT_FOUND;
@ -799,7 +836,8 @@ GetActiveSlot (Slot *ActiveSlot)
(SlotA->PartEntry.Attributes & PART_ATT_UNBOOTABLE_VAL) == 0 &&
BootPriority == 0) {
DEBUG ((EFI_D_INFO, "GetActiveSlot: First boot: set "
DEBUG(
(EFI_D_INFO, "GetActiveSlot: First boot: set "
"default slot _a\n"));
SlotA->PartEntry.Attributes &=
(~PART_ATT_SUCCESSFUL_VAL & ~PART_ATT_UNBOOTABLE_VAL);
@ -807,14 +845,17 @@ GetActiveSlot (Slot *ActiveSlot)
(PART_ATT_PRIORITY_VAL | PART_ATT_ACTIVE_VAL |
PART_ATT_MAX_RETRY_COUNT_VAL);
GUARD (StrnCpyS (ActiveSlot->Suffix, ARRAY_SIZE (ActiveSlot->Suffix),
Slots[0].Suffix, StrLen (Slots[0].Suffix)));
GUARD(StrnCpyS(
ActiveSlot->Suffix, ARRAY_SIZE(ActiveSlot->Suffix), Slots[0].Suffix,
StrLen(Slots[0].Suffix)));
UpdatePartitionAttributes(PARTITION_ATTRIBUTES);
return EFI_SUCCESS;
}
DEBUG((EFI_D_ERROR, "GetActiveSlot: No active slot found\n"));
DEBUG ((EFI_D_ERROR, "GetActiveSlot: Slot attr: Priority %ld, Retry "
DEBUG(
(EFI_D_ERROR,
"GetActiveSlot: Slot attr: Priority %ld, Retry "
"%ld, Active %ld, Success %ld, unboot %ld\n",
BootPriority, RetryCount,
(SlotA->PartEntry.Attributes & PART_ATT_ACTIVE_VAL) >>
@ -850,13 +891,15 @@ SetActiveSlot (Slot *NewSlot, BOOLEAN ResetSuccessBit, BOOLEAN SetSuccessBit)
if (StrnCmp(NewSlot->Suffix, Slots[0].Suffix, StrLen(Slots[0].Suffix)) == 0) {
AlternateSlot = &Slots[1];
} else {
}
else {
AlternateSlot = &Slots[0];
}
BootEntry = GetBootPartitionEntry(NewSlot);
if (BootEntry == NULL) {
DEBUG ((EFI_D_ERROR, "SetActiveSlot: No boot partition entry for slot %s\n",
DEBUG(
(EFI_D_ERROR, "SetActiveSlot: No boot partition entry for slot %s\n",
NewSlot->Suffix));
return EFI_NOT_FOUND;
}
@ -880,7 +923,8 @@ SetActiveSlot (Slot *NewSlot, BOOLEAN ResetSuccessBit, BOOLEAN SetSuccessBit)
/* Reduce the priority and clear the active flag for alternate slot*/
BootEntry = GetBootPartitionEntry(AlternateSlot);
if (BootEntry == NULL) {
DEBUG ((EFI_D_ERROR, "SetActiveSlot: No boot partition entry for slot %s\n",
DEBUG(
(EFI_D_ERROR, "SetActiveSlot: No boot partition entry for slot %s\n",
AlternateSlot->Suffix));
return EFI_NOT_FOUND;
}
@ -891,24 +935,28 @@ SetActiveSlot (Slot *NewSlot, BOOLEAN ResetSuccessBit, BOOLEAN SetSuccessBit)
(((UINT64)MAX_PRIORITY - 1) << PART_ATT_PRIORITY_BIT);
UpdatePartitionAttributes(PARTITION_ATTRIBUTES);
if (StrnCmp (CurrentSlot.Suffix, NewSlot->Suffix,
StrLen (CurrentSlot.Suffix)) == 0) {
DEBUG ((EFI_D_INFO, "SetActiveSlot: %s already active slot\n",
if (StrnCmp(
CurrentSlot.Suffix, NewSlot->Suffix, StrLen(CurrentSlot.Suffix)) ==
0) {
DEBUG(
(EFI_D_INFO, "SetActiveSlot: %s already active slot\n",
NewSlot->Suffix));
/* Check if BootLun is matching with Slot */
GetRootDeviceType(BootDeviceType, BOOT_DEV_NAME_SIZE_MAX);
if (!AsciiStrnCmp(BootDeviceType, "UFS", AsciiStrLen("UFS"))) {
UfsGetSetBootLun(&UfsBootLun, UfsGet);
if (UfsBootLun == 0x1 &&
!StrnCmp (CurrentSlot.Suffix, (CONST CHAR16 *)L"_b",
if (UfsBootLun == 0x1 && !StrnCmp(
CurrentSlot.Suffix, (CONST CHAR16 *)L"_b",
StrLen((CONST CHAR16 *)L"_b"))) {
DEBUG((EFI_D_INFO, "Boot lun mismatch switch from 1 to 2\n"));
DEBUG((EFI_D_INFO, "Reboot Required\n"));
UfsBootLun = 0x2;
UfsGetSetBootLun(&UfsBootLun, UfsSet);
} else if (UfsBootLun == 0x2 &&
!StrnCmp (CurrentSlot.Suffix, (CONST CHAR16 *)L"_a",
}
else if (
UfsBootLun == 0x2 && !StrnCmp(
CurrentSlot.Suffix, (CONST CHAR16 *)L"_a",
StrLen((CONST CHAR16 *)L"_a"))) {
DEBUG((EFI_D_INFO, "Boot lun mismatch switch from 2 to 1\n"));
DEBUG((EFI_D_INFO, "Reboot Required\n"));
@ -916,9 +964,11 @@ SetActiveSlot (Slot *NewSlot, BOOLEAN ResetSuccessBit, BOOLEAN SetSuccessBit)
UfsGetSetBootLun(&UfsBootLun, UfsSet);
}
}
} else {
DEBUG ((EFI_D_INFO, "Alternate slot %s, New slot %s\n",
AlternateSlot->Suffix, NewSlot->Suffix));
}
else {
DEBUG(
(EFI_D_INFO, "Alternate slot %s, New slot %s\n", AlternateSlot->Suffix,
NewSlot->Suffix));
SwitchPtnSlots(NewSlot->Suffix);
MarkPtnActive(NewSlot->Suffix);
}

View File

@ -1,4 +1,5 @@
/* Copyright (c) 2015-2018, 2020-2021, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2018, 2020-2021, The Linux Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@ -28,11 +29,13 @@
#include "AutoGen.h"
#include <Library/BootSlotLib/StorageUtils.h>
#include <Library/BootSlotLib/BlockIoUtils.h>
#include <Library/BootSlotLib/StorageUtils.h>
STATIC CONST CHAR8 *DeviceType[] = {
[EMMC] = "EMMC", [UFS] = "UFS", [UNKNOWN] = "Unknown",
[EMMC] = "EMMC",
[UFS] = "UFS",
[UNKNOWN] = "Unknown",
};
/**
@ -71,10 +74,8 @@ GetDeviceHandleInfo (VOID *HndlInfo, UINT32 MaxHandles, MemCardType Type)
return Status;
}
Status =
GetBlkIOHandles (Attribs, &HandleFilter, HandleInfoList, &MaxHandles);
if (EFI_ERROR (Status) ||
MaxHandles == 0) {
Status = GetBlkIOHandles(Attribs, &HandleFilter, HandleInfoList, &MaxHandles);
if (EFI_ERROR(Status) || MaxHandles == 0) {
DEBUG((EFI_D_ERROR, "Get BlkIohandles failed\n"));
return Status;
}
@ -85,8 +86,7 @@ GetDeviceHandleInfo (VOID *HndlInfo, UINT32 MaxHandles, MemCardType Type)
Return a device type
@retval Device type : UNKNOWN | UFS | EMMC | NAND
**/
STATIC UINT32
GetCompatibleRootDeviceType (VOID)
STATIC UINT32 GetCompatibleRootDeviceType(VOID)
{
EFI_STATUS Status = EFI_INVALID_PARAMETER;
HandleInfo HandleInfoList[HANDLE_MAX_INFO_LIST];
@ -108,8 +108,7 @@ GetCompatibleRootDeviceType (VOID)
@retval Device type : UNKNOWN | UFS | EMMC, default is UNKNOWN
**/
MemCardType
CheckRootDeviceType (VOID)
MemCardType CheckRootDeviceType(VOID)
{
EFI_STATUS Status = EFI_INVALID_PARAMETER;
STATIC MemCardType Type = UNKNOWN;
@ -117,21 +116,24 @@ CheckRootDeviceType (VOID)
EFI_MEM_CARDINFO_PROTOCOL *CardInfo;
if (Type == UNKNOWN) {
Status = gBS->LocateProtocol (&gEfiMemCardInfoProtocolGuid, NULL,
(VOID **)&CardInfo);
Status = gBS->LocateProtocol(
&gEfiMemCardInfoProtocolGuid, NULL, (VOID **)&CardInfo);
if (!EFI_ERROR(Status)) {
Status = CardInfo->GetCardInfo(CardInfo, &CardInfoData);
if (!EFI_ERROR(Status)) {
if (!AsciiStrnCmp ((CHAR8 *)CardInfoData.card_type, "UFS",
AsciiStrLen ("UFS"))) {
if (!AsciiStrnCmp(
(CHAR8 *)CardInfoData.card_type, "UFS", AsciiStrLen("UFS"))) {
Type = UFS;
} else if (!AsciiStrnCmp ((CHAR8 *)CardInfoData.card_type, "EMMC",
}
else if (!AsciiStrnCmp(
(CHAR8 *)CardInfoData.card_type, "EMMC",
AsciiStrLen("EMMC"))) {
Type = EMMC;
} else {
}
else {
Type = GetCompatibleRootDeviceType();
}
}
@ -145,8 +147,7 @@ CheckRootDeviceType (VOID)
@param[out] StrDeviceType : Pointer to array of device type string.
@param[in] Len : The size of the device type string
**/
VOID
GetRootDeviceType (CHAR8 *StrDeviceType, UINT32 Len)
VOID GetRootDeviceType(CHAR8 *StrDeviceType, UINT32 Len)
{
UINT32 Type;
@ -170,14 +171,13 @@ UfsGetSetBootLun (UINT32 *UfsBootlun, BOOLEAN IsGet)
HandleFilter.VolumeName = NULL;
HandleFilter.RootDeviceType = &gEfiUfsLU0Guid;
Status =
GetBlkIOHandles (Attribs, &HandleFilter, HandleInfoList, &MaxHandles);
Status = GetBlkIOHandles(Attribs, &HandleFilter, HandleInfoList, &MaxHandles);
if (EFI_ERROR(Status))
return EFI_NOT_FOUND;
Status =
gBS->HandleProtocol (HandleInfoList[0].Handle,
&gEfiMemCardInfoProtocolGuid, (VOID **)&CardInfo);
Status = gBS->HandleProtocol(
HandleInfoList[0].Handle, &gEfiMemCardInfoProtocolGuid,
(VOID **)&CardInfo);
if (Status != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR, "Error locating MemCardInfoProtocol:%x\n", Status));
@ -185,7 +185,8 @@ UfsGetSetBootLun (UINT32 *UfsBootlun, BOOLEAN IsGet)
}
if (CardInfo->Revision < EFI_MEM_CARD_INFO_PROTOCOL_REVISION) {
DEBUG ((EFI_D_ERROR, "This API not supported in Revision =%u\n",
DEBUG(
(EFI_D_ERROR, "This API not supported in Revision =%u\n",
CardInfo->Revision));
return EFI_NOT_FOUND;
}
@ -193,7 +194,8 @@ UfsGetSetBootLun (UINT32 *UfsBootlun, BOOLEAN IsGet)
if (IsGet == TRUE) {
if (CardInfo->GetBootLU(CardInfo, UfsBootlun) == EFI_SUCCESS)
DEBUG((EFI_D_VERBOSE, "Get BootLun =%u\n", *UfsBootlun));
} else {
}
else {
if (CardInfo->SetBootLU(CardInfo, *UfsBootlun) == EFI_SUCCESS)
DEBUG((EFI_D_VERBOSE, "SetBootLun =%u\n", *UfsBootlun));
}

View File

@ -5,8 +5,8 @@
#include <Library/HobLib.h>
#include <Library/SerialPortLib.h>
#include <Resources/font5x12.h>
#include <Resources/FbColor.h>
#include <Resources/font5x12.h>
#include "FrameBufferSerialPortLib.h"
@ -21,21 +21,11 @@ UINTN gHeight = FixedPcdGet32(PcdMipiFrameBufferHeight);
UINTN gBpp = FixedPcdGet32(PcdMipiFrameBufferPixelBpp);
// Module-used internal routine
void FbConPutCharWithFactor
(
char c,
int type,
unsigned scale_factor
);
void FbConPutCharWithFactor(char c, int type, unsigned scale_factor);
void FbConDrawglyph
(
char *pixels,
unsigned stride,
unsigned bpp,
unsigned *glyph,
unsigned scale_factor
);
void FbConDrawglyph(
char *pixels, unsigned stride, unsigned bpp, unsigned *glyph,
unsigned scale_factor);
void FbConReset(void);
void FbConScrollUp(void);
@ -43,15 +33,13 @@ void FbConFlush(void);
RETURN_STATUS
EFIAPI
SerialPortInitialize
(
VOID
)
SerialPortInitialize(VOID)
{
UINTN InterruptState = 0;
// Prevent dup initialization
if (m_Initialized) return RETURN_SUCCESS;
if (m_Initialized)
return RETURN_SUCCESS;
// Interrupt Disable
InterruptState = ArmGetInterruptState();
@ -63,7 +51,8 @@ SerialPortInitialize
// Set flag
m_Initialized = TRUE;
if (InterruptState) ArmEnableInterrupts();
if (InterruptState)
ArmEnableInterrupts();
return RETURN_SUCCESS;
}
@ -74,14 +63,11 @@ void ResetFb(void)
UINTN BgColor = FB_BGRA8888_BLACK;
// Set to black color.
for (UINTN i = 0; i < gWidth; i++)
{
for (UINTN j = 0; j < gHeight; j++)
{
for (UINTN i = 0; i < gWidth; i++) {
for (UINTN j = 0; j < gHeight; j++) {
BgColor = FB_BGRA8888_BLACK;
// Set pixel bit
for (UINTN p = 0; p < (gBpp / 8); p++)
{
for (UINTN p = 0; p < (gBpp / 8); p++) {
*Pixels = (unsigned char)BgColor;
BgColor = BgColor >> 8;
Pixels++;
@ -105,42 +91,34 @@ void FbConReset(void)
m_Color.Background = FB_BGRA8888_BLACK;
}
void FbConPutCharWithFactor
(
char c,
int type,
unsigned scale_factor
)
void FbConPutCharWithFactor(char c, int type, unsigned scale_factor)
{
char *Pixels;
if (!m_Initialized) return;
if (!m_Initialized)
return;
paint:
if ((unsigned char)c > 127) return;
if ((unsigned char)c > 127)
return;
if ((unsigned char)c < 32)
{
if (c == '\n')
{
if ((unsigned char)c < 32) {
if (c == '\n') {
goto newline;
}
else if (c == '\r')
{
else if (c == '\r') {
m_Position.x = 0;
return;
}
else
{
else {
return;
}
}
// Save some space
if (m_Position.x == 0 && (unsigned char)c == ' ' &&
type != FBCON_SUBTITLE_MSG &&
type != FBCON_TITLE_MSG)
type != FBCON_SUBTITLE_MSG && type != FBCON_TITLE_MSG)
return;
BOOLEAN intstate = ArmGetInterruptState();
@ -151,47 +129,39 @@ paint:
Pixels += m_Position.x * scale_factor * ((gBpp / 8) * (FONT_WIDTH + 1));
FbConDrawglyph(
Pixels,
gWidth,
(gBpp / 8),
font5x12 + (c - 32) * 2,
scale_factor);
Pixels, gWidth, (gBpp / 8), font5x12 + (c - 32) * 2, scale_factor);
m_Position.x++;
if (m_Position.x >= (int)(m_MaxPosition.x / scale_factor)) goto newline;
if (m_Position.x >= (int)(m_MaxPosition.x / scale_factor))
goto newline;
if (intstate) ArmEnableInterrupts();
if (intstate)
ArmEnableInterrupts();
return;
newline:
m_Position.y += scale_factor;
m_Position.x = 0;
if (m_Position.y >= m_MaxPosition.y - scale_factor)
{
if (m_Position.y >= m_MaxPosition.y - scale_factor) {
ResetFb();
FbConFlush();
m_Position.y = 0;
if (intstate) ArmEnableInterrupts();
if (intstate)
ArmEnableInterrupts();
goto paint;
}
else
{
else {
FbConFlush();
if (intstate) ArmEnableInterrupts();
if (intstate)
ArmEnableInterrupts();
}
}
}
void FbConDrawglyph
(
char *pixels,
unsigned stride,
unsigned bpp,
unsigned *glyph,
unsigned scale_factor
)
void FbConDrawglyph(
char *pixels, unsigned stride, unsigned bpp, unsigned *glyph,
unsigned scale_factor)
{
char * bg_pixels = pixels;
unsigned x, y, i, j, k;
@ -200,17 +170,12 @@ void FbConDrawglyph
unsigned int bg_color = m_Color.Background;
stride -= FONT_WIDTH * scale_factor;
for (y = 0; y < FONT_HEIGHT / 2; ++y)
{
for (i = 0; i < scale_factor; i++)
{
for (x = 0; x < FONT_WIDTH; ++x)
{
for (j = 0; j < scale_factor; j++)
{
for (y = 0; y < FONT_HEIGHT / 2; ++y) {
for (i = 0; i < scale_factor; i++) {
for (x = 0; x < FONT_WIDTH; ++x) {
for (j = 0; j < scale_factor; j++) {
bg_color = m_Color.Background;
for (k = 0; k < bpp; k++)
{
for (k = 0; k < bpp; k++) {
*bg_pixels = (unsigned char)bg_color;
bg_color = bg_color >> 8;
bg_pixels++;
@ -221,17 +186,12 @@ void FbConDrawglyph
}
}
for (y = 0; y < FONT_HEIGHT / 2; ++y)
{
for (i = 0; i < scale_factor; i++)
{
for (x = 0; x < FONT_WIDTH; ++x)
{
for (j = 0; j < scale_factor; j++)
{
for (y = 0; y < FONT_HEIGHT / 2; ++y) {
for (i = 0; i < scale_factor; i++) {
for (x = 0; x < FONT_WIDTH; ++x) {
for (j = 0; j < scale_factor; j++) {
bg_color = m_Color.Background;
for (k = 0; k < bpp; k++)
{
for (k = 0; k < bpp; k++) {
*bg_pixels = (unsigned char)bg_color;
bg_color = bg_color >> 8;
bg_pixels++;
@ -243,31 +203,23 @@ void FbConDrawglyph
}
data = glyph[0];
for (y = 0; y < FONT_HEIGHT / 2; ++y)
{
for (y = 0; y < FONT_HEIGHT / 2; ++y) {
temp = data;
for (i = 0; i < scale_factor; i++)
{
for (i = 0; i < scale_factor; i++) {
data = temp;
for (x = 0; x < FONT_WIDTH; ++x)
{
if (data & 1)
{
for (j = 0; j < scale_factor; j++)
{
for (x = 0; x < FONT_WIDTH; ++x) {
if (data & 1) {
for (j = 0; j < scale_factor; j++) {
fg_color = m_Color.Foreground;
for (k = 0; k < bpp; k++)
{
for (k = 0; k < bpp; k++) {
*pixels = (unsigned char)fg_color;
fg_color = fg_color >> 8;
pixels++;
}
}
}
else
{
for (j = 0; j < scale_factor; j++)
{
else {
for (j = 0; j < scale_factor; j++) {
pixels = pixels + bpp;
}
}
@ -278,31 +230,23 @@ void FbConDrawglyph
}
data = glyph[1];
for (y = 0; y < FONT_HEIGHT / 2; ++y)
{
for (y = 0; y < FONT_HEIGHT / 2; ++y) {
temp = data;
for (i = 0; i < scale_factor; i++)
{
for (i = 0; i < scale_factor; i++) {
data = temp;
for (x = 0; x < FONT_WIDTH; ++x)
{
if (data & 1)
{
for (j = 0; j < scale_factor; j++)
{
for (x = 0; x < FONT_WIDTH; ++x) {
if (data & 1) {
for (j = 0; j < scale_factor; j++) {
fg_color = m_Color.Foreground;
for (k = 0; k < bpp; k++)
{
for (k = 0; k < bpp; k++) {
*pixels = (unsigned char)fg_color;
fg_color = fg_color >> 8;
pixels++;
}
}
}
else
{
for (j = 0; j < scale_factor; j++)
{
else {
for (j = 0; j < scale_factor; j++) {
pixels = pixels + bpp;
}
}
@ -320,14 +264,12 @@ void FbConScrollUp(void)
unsigned short *src = dst + (gWidth * FONT_HEIGHT);
unsigned count = gWidth * (gHeight - FONT_HEIGHT);
while (count--)
{
while (count--) {
*dst++ = *src++;
}
count = gWidth * FONT_HEIGHT;
while (count--)
{
while (count--) {
*dst++ = m_Color.Background;
}
@ -345,38 +287,29 @@ void FbConFlush(void)
WriteBackInvalidateDataCacheRange(
(void *)FixedPcdGet32(PcdMipiFrameBufferAddress),
(total_x * total_y * bytes_per_bpp)
);
(total_x * total_y * bytes_per_bpp));
}
UINTN
EFIAPI
SerialPortWrite
(
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
{
UINT8 *CONST Final = &Buffer[NumberOfBytes];
UINTN InterruptState = ArmGetInterruptState();
ArmDisableInterrupts();
while (Buffer < Final)
{
while (Buffer < Final) {
FbConPutCharWithFactor(*Buffer++, FBCON_COMMON_MSG, SCALE_FACTOR);
}
if (InterruptState) ArmEnableInterrupts();
if (InterruptState)
ArmEnableInterrupts();
return NumberOfBytes;
}
UINTN
EFIAPI
SerialPortWriteCritical
(
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
SerialPortWriteCritical(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
{
UINT8 *CONST Final = &Buffer[NumberOfBytes];
UINTN CurrentForeground = m_Color.Foreground;
@ -385,80 +318,46 @@ SerialPortWriteCritical
ArmDisableInterrupts();
m_Color.Foreground = FB_BGRA8888_YELLOW;
while (Buffer < Final)
{
while (Buffer < Final) {
FbConPutCharWithFactor(*Buffer++, FBCON_COMMON_MSG, SCALE_FACTOR);
}
m_Color.Foreground = CurrentForeground;
if (InterruptState) ArmEnableInterrupts();
if (InterruptState)
ArmEnableInterrupts();
return NumberOfBytes;
}
UINTN
EFIAPI
SerialPortRead
(
OUT UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
return 0;
}
SerialPortRead(OUT UINT8 *Buffer, IN UINTN NumberOfBytes) { return 0; }
BOOLEAN
EFIAPI
SerialPortPoll
(
VOID
)
{
return FALSE;
}
SerialPortPoll(VOID) { return FALSE; }
RETURN_STATUS
EFIAPI
SerialPortSetControl
(
IN UINT32 Control
)
SerialPortSetControl(IN UINT32 Control) { return RETURN_UNSUPPORTED; }
RETURN_STATUS
EFIAPI
SerialPortGetControl(OUT UINT32 *Control) { return RETURN_UNSUPPORTED; }
RETURN_STATUS
EFIAPI
SerialPortSetAttributes(
IN OUT UINT64 *BaudRate, IN OUT UINT32 *ReceiveFifoDepth,
IN OUT UINT32 *Timeout, IN OUT EFI_PARITY_TYPE *Parity,
IN OUT UINT8 *DataBits, IN OUT EFI_STOP_BITS_TYPE *StopBits)
{
return RETURN_UNSUPPORTED;
}
RETURN_STATUS
EFIAPI
SerialPortGetControl
(
OUT UINT32 *Control
)
{
return RETURN_UNSUPPORTED;
}
UINTN SerialPortFlush(VOID) { return 0; }
RETURN_STATUS
EFIAPI
SerialPortSetAttributes
(
IN OUT UINT64 *BaudRate,
IN OUT UINT32 *ReceiveFifoDepth,
IN OUT UINT32 *Timeout,
IN OUT EFI_PARITY_TYPE *Parity,
IN OUT UINT8 *DataBits,
IN OUT EFI_STOP_BITS_TYPE *StopBits
)
{
return RETURN_UNSUPPORTED;
}
UINTN SerialPortFlush(VOID)
{
return 0;
}
VOID
EnableSynchronousSerialPortIO(VOID)
VOID EnableSynchronousSerialPortIO(VOID)
{
// Already synchronous
}

View File

@ -32,10 +32,6 @@ void ResetFb(void);
UINTN
EFIAPI
SerialPortWriteCritical
(
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
);
SerialPortWriteCritical(IN UINT8 *Buffer, IN UINTN NumberOfBytes);
#endif

View File

@ -3,26 +3,26 @@
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
are licensed and made available under the terms and conditions of the BSD
License which accompanies this distribution. The full text of the license may
be found at http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Base.h>
#include <Library/SerialPortLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/SerialPortLib.h>
/**
Initialize the serial device hardware.
If no initialization is required, then return RETURN_SUCCESS.
If the serial device was successfully initialized, then return RETURN_SUCCESS.
If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
If the serial device could not be initialized, then return
RETURN_DEVICE_ERROR.
@retval RETURN_SUCCESS The serial device was initialized.
@retval RETURN_DEVICE_ERROR The serial device could not be initialized.
@ -30,9 +30,7 @@
**/
RETURN_STATUS
EFIAPI
SerialPortInitialize (
VOID
)
SerialPortInitialize(VOID)
{
#if 0
UINT8* base = (UINT8*)0xa1a10000ull;
@ -43,7 +41,8 @@ SerialPortInitialize (
return RETURN_SUCCESS;
}
static void mem_putchar(UINT8 c) {
static void mem_putchar(UINT8 c)
{
static const UINTN size = 0x200000;
static UINTN offset = 0;
UINT8 * base = (UINT8 *)0xa1a10000ull;
@ -59,24 +58,22 @@ static void mem_putchar(UINT8 c) {
Writes NumberOfBytes data bytes from Buffer to the serial device.
The number of bytes actually written to the serial device is returned.
If the return value is less than NumberOfBytes, then the write operation failed.
If Buffer is NULL, then ASSERT().
If NumberOfBytes is zero, then return 0.
If the return value is less than NumberOfBytes, then the write operation
failed. If Buffer is NULL, then ASSERT(). If NumberOfBytes is zero, then return
0.
@param Buffer The pointer to the data buffer to be written.
@param NumberOfBytes The number of bytes to written to the serial device.
@retval 0 NumberOfBytes is 0.
@retval >0 The number of bytes written to the serial device.
If this value is less than NumberOfBytes, then the write operation failed.
If this value is less than NumberOfBytes, then the
write operation failed.
**/
UINTN
EFIAPI
SerialPortWrite (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
SerialPortWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
{
for (UINTN i = 0; i < NumberOfBytes; i++) {
mem_putchar(Buffer[i]);
@ -84,17 +81,17 @@ SerialPortWrite (
return NumberOfBytes;
}
/**
Read data from serial device and save the datas in buffer.
Reads NumberOfBytes data bytes from a serial device into the buffer
specified by Buffer. The number of bytes actually read is returned.
If the return value is less than NumberOfBytes, then the rest operation failed.
If Buffer is NULL, then ASSERT().
If NumberOfBytes is zero, then return 0.
If the return value is less than NumberOfBytes, then the rest operation
failed. If Buffer is NULL, then ASSERT(). If NumberOfBytes is zero, then return
0.
@param Buffer The pointer to the data buffer to store the data read from the serial device.
@param Buffer The pointer to the data buffer to store the data read
from the serial device.
@param NumberOfBytes The number of bytes which will be read.
@retval 0 Read data failed; No data is to be read.
@ -103,116 +100,97 @@ SerialPortWrite (
**/
UINTN
EFIAPI
SerialPortRead (
OUT UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
return 0;
}
SerialPortRead(OUT UINT8 *Buffer, IN UINTN NumberOfBytes) { return 0; }
/**
Polls a serial device to see if there is any data waiting to be read.
Polls a serial device to see if there is any data waiting to be read.
If there is data waiting to be read from the serial device, then TRUE is returned.
If there is no data waiting to be read from the serial device, then FALSE is returned.
If there is data waiting to be read from the serial device, then TRUE is
returned. If there is no data waiting to be read from the serial device, then
FALSE is returned.
@retval TRUE Data is waiting to be read from the serial device.
@retval FALSE There is no data waiting to be read from the serial device.
@retval FALSE There is no data waiting to be read from the serial
device.
**/
BOOLEAN
EFIAPI
SerialPortPoll (
VOID
)
{
return FALSE;
}
SerialPortPoll(VOID) { return FALSE; }
/**
Sets the control bits on a serial device.
@param Control Sets the bits of Control that are settable.
@retval RETURN_SUCCESS The new control bits were set on the serial device.
@retval RETURN_UNSUPPORTED The serial device does not support this operation.
@retval RETURN_SUCCESS The new control bits were set on the serial
device.
@retval RETURN_UNSUPPORTED The serial device does not support this
operation.
@retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
**/
RETURN_STATUS
EFIAPI
SerialPortSetControl (
IN UINT32 Control
)
{
return RETURN_UNSUPPORTED;
}
SerialPortSetControl(IN UINT32 Control) { return RETURN_UNSUPPORTED; }
/**
Retrieve the status of the control bits on a serial device.
@param Control A pointer to return the current control signals from the serial device.
@param Control A pointer to return the current control signals
from the serial device.
@retval RETURN_SUCCESS The control bits were read from the serial device.
@retval RETURN_UNSUPPORTED The serial device does not support this operation.
@retval RETURN_SUCCESS The control bits were read from the serial
device.
@retval RETURN_UNSUPPORTED The serial device does not support this
operation.
@retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
**/
RETURN_STATUS
EFIAPI
SerialPortGetControl (
OUT UINT32 *Control
)
{
return RETURN_UNSUPPORTED;
}
SerialPortGetControl(OUT UINT32 *Control) { return RETURN_UNSUPPORTED; }
/**
Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
data bits, and stop bits on a serial device.
@param BaudRate The requested baud rate. A BaudRate value of 0 will use the
device's default interface speed.
On output, the value actually set.
@param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
serial interface. A ReceiveFifoDepth value of 0 will use
the device's default FIFO depth.
On output, the value actually set.
@param Timeout The requested time out for a single character in microseconds.
This timeout applies to both the transmit and receive side of the
interface. A Timeout value of 0 will use the device's default time
out value.
On output, the value actually set.
@param Parity The type of parity to use on this serial device. A Parity value of
DefaultParity will use the device's default parity value.
On output, the value actually set.
@param DataBits The number of data bits to use on the serial device. A DataBits
vaule of 0 will use the device's default data bit setting.
On output, the value actually set.
@param StopBits The number of stop bits to use on this serial device. A StopBits
value of DefaultStopBits will use the device's default number of
stop bits.
On output, the value actually set.
@param BaudRate The requested baud rate. A BaudRate value of 0 will
use the device's default interface speed. On output, the value actually set.
@param ReveiveFifoDepth The requested depth of the FIFO on the receive side
of the serial interface. A ReceiveFifoDepth value of 0 will use the device's
default FIFO depth. On output, the value actually set.
@param Timeout The requested time out for a single character in
microseconds. This timeout applies to both the transmit and receive side of the
interface. A Timeout value of 0 will use the
device's default time out value. On output, the value actually set.
@param Parity The type of parity to use on this serial device. A
Parity value of DefaultParity will use the device's default parity value. On
output, the value actually set.
@param DataBits The number of data bits to use on the serial device.
A DataBits vaule of 0 will use the device's default data bit setting. On output,
the value actually set.
@param StopBits The number of stop bits to use on this serial
device. A StopBits value of DefaultStopBits will use the device's default number
of stop bits. On output, the value actually set.
@retval RETURN_SUCCESS The new attributes were set on the serial device.
@retval RETURN_UNSUPPORTED The serial device does not support this operation.
@retval RETURN_INVALID_PARAMETER One or more of the attributes has an unsupported value.
@retval RETURN_DEVICE_ERROR The serial device is not functioning correctly.
@retval RETURN_SUCCESS The new attributes were set on the serial
device.
@retval RETURN_UNSUPPORTED The serial device does not support this
operation.
@retval RETURN_INVALID_PARAMETER One or more of the attributes has an
unsupported value.
@retval RETURN_DEVICE_ERROR The serial device is not functioning
correctly.
**/
RETURN_STATUS
EFIAPI
SerialPortSetAttributes(
IN OUT UINT64 *BaudRate,
IN OUT UINT32 *ReceiveFifoDepth,
IN OUT UINT32 *Timeout,
IN OUT EFI_PARITY_TYPE *Parity,
IN OUT UINT8 *DataBits,
IN OUT EFI_STOP_BITS_TYPE *StopBits
)
IN OUT UINT64 *BaudRate, IN OUT UINT32 *ReceiveFifoDepth,
IN OUT UINT32 *Timeout, IN OUT EFI_PARITY_TYPE *Parity,
IN OUT UINT8 *DataBits, IN OUT EFI_STOP_BITS_TYPE *StopBits)
{
return RETURN_UNSUPPORTED;
}

View File

@ -10,6 +10,9 @@
**/
#include <Guid/EventGroup.h>
#include <Guid/SerialPortLibVendor.h>
#include <Guid/TtyTerm.h>
#include <IndustryStandard/Pci22.h>
#include <Library/BootLogoLib.h>
#include <Library/CapsuleLib.h>
@ -26,15 +29,13 @@
#include <Protocol/PciIo.h>
#include <Protocol/PciRootBridgeIo.h>
#include <Protocol/PlatformBootManager.h>
#include <Guid/EventGroup.h>
#include <Guid/TtyTerm.h>
#include <Guid/SerialPortLibVendor.h>
#include "PlatformBm.h"
#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) }
#define DP_NODE_LEN(Type) \
{ \
(UINT8)sizeof(Type), (UINT8)(sizeof(Type) >> 8) \
}
#pragma pack(1)
typedef struct {
@ -49,10 +50,8 @@ STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {
//
// VENDOR_DEVICE_PATH SerialDxe
//
{
{ HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },
EDKII_SERIAL_PORT_LIB_VENDOR_GUID
},
{{HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN(VENDOR_DEVICE_PATH)},
EDKII_SERIAL_PORT_LIB_VENDOR_GUID},
//
// UART_DEVICE_PATH Uart
@ -70,10 +69,8 @@ STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {
// VENDOR_DEFINED_DEVICE_PATH TermType
//
{
{
MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,
DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH)
}
{MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,
DP_NODE_LEN(VENDOR_DEFINED_DEVICE_PATH)}
//
// Guid to be filled in dynamically
//
@ -82,12 +79,8 @@ STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {
//
// EFI_DEVICE_PATH_PROTOCOL End
//
{
END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
}
};
{END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
DP_NODE_LEN(EFI_DEVICE_PATH_PROTOCOL)}};
#pragma pack(1)
typedef struct {
@ -101,10 +94,8 @@ STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {
// USB_CLASS_DEVICE_PATH Keyboard
//
{
{
MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP,
DP_NODE_LEN (USB_CLASS_DEVICE_PATH)
},
{MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP,
DP_NODE_LEN(USB_CLASS_DEVICE_PATH)},
0xFFFF, // VendorId: any
0xFFFF, // ProductId: any
3, // DeviceClass: HID
@ -115,12 +106,8 @@ STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {
//
// EFI_DEVICE_PATH_PROTOCOL End
//
{
END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
}
};
{END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
DP_NODE_LEN(EFI_DEVICE_PATH_PROTOCOL)}};
/**
Check if the handle satisfies a particular condition.
@ -133,13 +120,8 @@ STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {
@retval FALSE Otherwise. This includes the case when the condition could not
be fully evaluated due to an error.
**/
typedef
BOOLEAN
(EFIAPI *FILTER_FUNCTION) (
IN EFI_HANDLE Handle,
IN CONST CHAR16 *ReportText
);
typedef BOOLEAN(EFIAPI *FILTER_FUNCTION)(
IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText);
/**
Process a handle.
@ -148,12 +130,8 @@ BOOLEAN
@param[in] ReportText A caller-allocated string passed in for reporting
purposes. It must never be NULL.
**/
typedef
VOID
(EFIAPI *CALLBACK_FUNCTION) (
IN EFI_HANDLE Handle,
IN CONST CHAR16 *ReportText
);
typedef VOID(EFIAPI *CALLBACK_FUNCTION)(
IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText);
/**
Locate all handles that carry the specified protocol, filter them with a
@ -169,26 +147,22 @@ VOID
clears the filter.
**/
STATIC
VOID
FilterAndProcess (
IN EFI_GUID *ProtocolGuid,
IN FILTER_FUNCTION Filter OPTIONAL,
IN CALLBACK_FUNCTION Process
)
VOID FilterAndProcess(
IN EFI_GUID *ProtocolGuid, IN FILTER_FUNCTION Filter OPTIONAL,
IN CALLBACK_FUNCTION Process)
{
EFI_STATUS Status;
EFI_HANDLE *Handles;
UINTN NoHandles;
UINTN Idx;
Status = gBS->LocateHandleBuffer (ByProtocol, ProtocolGuid,
NULL /* SearchKey */, &NoHandles, &Handles);
Status = gBS->LocateHandleBuffer(
ByProtocol, ProtocolGuid, NULL /* SearchKey */, &NoHandles, &Handles);
if (EFI_ERROR(Status)) {
//
// This is not an error, just an informative condition.
//
DEBUG ((EFI_D_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid,
Status));
DEBUG((EFI_D_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid, Status));
return;
}
@ -220,24 +194,19 @@ FilterAndProcess (
gBS->FreePool(Handles);
}
/**
This FILTER_FUNCTION checks if a handle corresponds to a PCI display device.
**/
STATIC
BOOLEAN
EFIAPI
IsPciDisplay (
IN EFI_HANDLE Handle,
IN CONST CHAR16 *ReportText
)
IsPciDisplay(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
{
EFI_STATUS Status;
EFI_PCI_IO_PROTOCOL *PciIo;
PCI_TYPE00 Pci;
Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid,
(VOID**)&PciIo);
Status = gBS->HandleProtocol(Handle, &gEfiPciIoProtocolGuid, (VOID **)&PciIo);
if (EFI_ERROR(Status)) {
//
// This is not an error worth reporting.
@ -245,8 +214,9 @@ IsPciDisplay (
return FALSE;
}
Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0 /* Offset */,
sizeof Pci / sizeof (UINT32), &Pci);
Status = PciIo->Pci.Read(
PciIo, EfiPciIoWidthUint32, 0 /* Offset */, sizeof Pci / sizeof(UINT32),
&Pci);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "%a: %s: %r\n", __FUNCTION__, ReportText, Status));
return FALSE;
@ -255,18 +225,12 @@ IsPciDisplay (
return IS_PCI_DISPLAY(&Pci);
}
/**
This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking
the matching driver to produce all first-level child handles.
**/
STATIC
VOID
EFIAPI
Connect (
IN EFI_HANDLE Handle,
IN CONST CHAR16 *ReportText
)
VOID EFIAPI Connect(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
{
EFI_STATUS Status;
@ -276,58 +240,54 @@ Connect (
NULL, // RemainingDevicePath -- produce all children
FALSE // Recursive
);
DEBUG ((EFI_ERROR (Status) ? EFI_D_ERROR : EFI_D_VERBOSE, "%a: %s: %r\n",
DEBUG(
(EFI_ERROR(Status) ? EFI_D_ERROR : EFI_D_VERBOSE, "%a: %s: %r\n",
__FUNCTION__, ReportText, Status));
}
/**
This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the
handle, and adds it to ConOut and ErrOut.
**/
STATIC
VOID
EFIAPI
AddOutput (
IN EFI_HANDLE Handle,
IN CONST CHAR16 *ReportText
)
VOID EFIAPI AddOutput(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
{
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
DevicePath = DevicePathFromHandle(Handle);
if (DevicePath == NULL) {
DEBUG ((EFI_D_ERROR, "%a: %s: handle %p: device path not found\n",
DEBUG(
(EFI_D_ERROR, "%a: %s: handle %p: device path not found\n",
__FUNCTION__, ReportText, Handle));
return;
}
Status = EfiBootManagerUpdateConsoleVariable(ConOut, DevicePath, NULL);
if (EFI_ERROR(Status)) {
DEBUG ((EFI_D_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__,
DEBUG(
(EFI_D_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__,
ReportText, Status));
return;
}
Status = EfiBootManagerUpdateConsoleVariable(ErrOut, DevicePath, NULL);
if (EFI_ERROR(Status)) {
DEBUG ((EFI_D_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__,
DEBUG(
(EFI_D_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__,
ReportText, Status));
return;
}
DEBUG ((EFI_D_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__,
DEBUG(
(EFI_D_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__,
ReportText));
}
STATIC
UINT16
PlatformRegisterFvBootOption(
CONST EFI_GUID *FileGuid,
CHAR16 *Description,
UINT32 Attributes
)
CONST EFI_GUID *FileGuid, CHAR16 *Description, UINT32 Attributes)
{
EFI_STATUS Status;
INTN OptionIndex;
@ -340,41 +300,27 @@ PlatformRegisterFvBootOption (
UINT16 OptionNumber;
Status = gBS->HandleProtocol(
gImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **) &LoadedImage
);
gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&LoadedImage);
ASSERT_EFI_ERROR(Status);
EfiInitializeFwVolDevicepathNode(&FileNode, FileGuid);
DevicePath = DevicePathFromHandle(LoadedImage->DeviceHandle);
ASSERT(DevicePath != NULL);
DevicePath = AppendDevicePathNode (
DevicePath,
(EFI_DEVICE_PATH_PROTOCOL *) &FileNode
);
DevicePath =
AppendDevicePathNode(DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&FileNode);
ASSERT(DevicePath != NULL);
Status = EfiBootManagerInitializeLoadOption(
&NewOption,
LoadOptionNumberUnassigned,
LoadOptionTypeBoot,
Attributes,
Description,
DevicePath,
NULL,
0
);
&NewOption, LoadOptionNumberUnassigned, LoadOptionTypeBoot, Attributes,
Description, DevicePath, NULL, 0);
ASSERT_EFI_ERROR(Status);
FreePool(DevicePath);
BootOptions = EfiBootManagerGetLoadOptions (
&BootOptionCount, LoadOptionTypeBoot
);
BootOptions =
EfiBootManagerGetLoadOptions(&BootOptionCount, LoadOptionTypeBoot);
OptionIndex = EfiBootManagerFindLoadOption (
&NewOption, BootOptions, BootOptionCount
);
OptionIndex =
EfiBootManagerFindLoadOption(&NewOption, BootOptions, BootOptionCount);
if (OptionIndex == -1) {
Status = EfiBootManagerAddLoadOptionVariable(&NewOption, MAX_UINTN);
@ -386,12 +332,8 @@ PlatformRegisterFvBootOption (
return OptionNumber;
}
STATIC
VOID
GetPlatformOptions (
VOID
)
VOID GetPlatformOptions(VOID)
{
EFI_STATUS Status;
EFI_BOOT_MANAGER_LOAD_OPTION * CurrentBootOptions;
@ -402,16 +344,13 @@ GetPlatformOptions (
UINTN Index;
UINTN BootCount;
Status = gBS->LocateProtocol (&gPlatformBootManagerProtocolGuid, NULL,
(VOID **)&PlatformBootManager);
Status = gBS->LocateProtocol(
&gPlatformBootManagerProtocolGuid, NULL, (VOID **)&PlatformBootManager);
if (EFI_ERROR(Status)) {
return;
}
Status = PlatformBootManager->GetPlatformBootOptionsAndKeys(
&BootCount,
&BootOptions,
&BootKeys
);
&BootCount, &BootOptions, &BootKeys);
if (EFI_ERROR(Status)) {
return;
}
@ -419,10 +358,8 @@ GetPlatformOptions (
// Fetch the existent boot options. If there are none, CurrentBootCount
// will be zeroed.
//
CurrentBootOptions = EfiBootManagerGetLoadOptions (
&CurrentBootOptionCount,
LoadOptionTypeBoot
);
CurrentBootOptions =
EfiBootManagerGetLoadOptions(&CurrentBootOptionCount, LoadOptionTypeBoot);
//
// Process the platform boot options.
//
@ -438,26 +375,23 @@ GetPlatformOptions (
// == NULL) if (CurrentBootCount == 0).
//
Match = EfiBootManagerFindLoadOption(
&BootOptions[Index],
CurrentBootOptions,
CurrentBootOptionCount
);
&BootOptions[Index], CurrentBootOptions, CurrentBootOptionCount);
if (Match >= 0) {
BootOptionNumber = CurrentBootOptions[Match].OptionNumber;
} else {
}
else {
//
// Add the platform boot options as a new one, at the end of the boot
// order. Note that if the platform provided this boot option with an
// unassigned option number, then the below function call will assign a
// number.
//
Status = EfiBootManagerAddLoadOptionVariable (
&BootOptions[Index],
MAX_UINTN
);
Status =
EfiBootManagerAddLoadOptionVariable(&BootOptions[Index], MAX_UINTN);
if (EFI_ERROR(Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to register \"%s\": %r\n",
__FUNCTION__, BootOptions[Index].Description, Status));
DEBUG(
(DEBUG_ERROR, "%a: failed to register \"%s\": %r\n", __FUNCTION__,
BootOptions[Index].Description, Status));
continue;
}
BootOptionNumber = BootOptions[Index].OptionNumber;
@ -471,14 +405,10 @@ GetPlatformOptions (
}
Status = EfiBootManagerAddKeyOptionVariable(
NULL,
BootOptionNumber,
0,
&BootKeys[Index],
NULL
);
NULL, BootOptionNumber, 0, &BootKeys[Index], NULL);
if (EFI_ERROR(Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to register hotkey for \"%s\": %r\n",
DEBUG(
(DEBUG_ERROR, "%a: failed to register hotkey for \"%s\": %r\n",
__FUNCTION__, BootOptions[Index].Description, Status));
}
}
@ -487,14 +417,8 @@ GetPlatformOptions (
FreePool(BootKeys);
}
STATIC
VOID
PlatformRegisterOptionsAndKeys (
VOID
)
VOID PlatformRegisterOptionsAndKeys(VOID)
{
EFI_STATUS Status;
EFI_INPUT_KEY Enter;
@ -531,24 +455,19 @@ PlatformRegisterOptionsAndKeys (
// Register Simple Init GUI APP
//
UINT16 OptionSimpleInit = PlatformRegisterFvBootOption(
&gSimpleInitFileGuid, L"Simple Init", LOAD_OPTION_ACTIVE
);
&gSimpleInitFileGuid, L"Simple Init", LOAD_OPTION_ACTIVE);
Status = EfiBootManagerAddKeyOptionVariable(
NULL, (UINT16) OptionSimpleInit, 0, &UP, NULL
);
NULL, (UINT16)OptionSimpleInit, 0, &UP, NULL);
#else
Status = EfiBootManagerAddKeyOptionVariable(
NULL, (UINT16) BootOption.OptionNumber, 0, &UP, NULL
);
NULL, (UINT16)BootOption.OptionNumber, 0, &UP, NULL);
#endif
ASSERT(Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);
Status = EfiBootManagerAddKeyOptionVariable(
NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL
);
NULL, (UINT16)BootOption.OptionNumber, 0, &Esc, NULL);
ASSERT(Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);
}
//
// BDS Platform Functions
//
@ -563,11 +482,7 @@ PlatformRegisterOptionsAndKeys (
> Authentication action: 1. connect Auth devices;
> 2. Identify auto logon user.
**/
VOID
EFIAPI
PlatformBootManagerBeforeConsole (
VOID
)
VOID EFIAPI PlatformBootManagerBeforeConsole(VOID)
{
//
// Signal EndOfDxe PI Event
@ -602,8 +517,8 @@ PlatformBootManagerBeforeConsole (
//
// Add the hardcoded short-form USB keyboard device path to ConIn.
//
EfiBootManagerUpdateConsoleVariable (ConIn,
(EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL);
EfiBootManagerUpdateConsoleVariable(
ConIn, (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL);
EFI_HANDLE * handles;
UINTN NoHandles;
@ -611,29 +526,28 @@ PlatformBootManagerBeforeConsole (
/*CHAR16 *devicepathtxt;*/
// EfiBootManagerUpdateConsoleVariable(ConIn,
// (EFI_DEVICE_PATH_PROTOCOL*)&gQcomKeypadDeviceGuid, NULL);
gBS->LocateHandleBuffer(ByProtocol,&gEfiSimpleTextInputExProtocolGuid,NULL, &NoHandles,&handles);
gBS->LocateHandleBuffer(
ByProtocol, &gEfiSimpleTextInputExProtocolGuid, NULL, &NoHandles,
&handles);
devicehandle = DevicePathFromHandle(handles[1]);
EfiBootManagerUpdateConsoleVariable (ConIn,
devicehandle, NULL);/*
EfiBootManagerUpdateConsoleVariable(
ConIn, devicehandle, NULL); /*
devicepathtxt = ConvertDevicePathToText(devicehandle,TRUE,TRUE);
DEBUG((DEBUG_ERROR,"There are %s handles\n",devicepathtxt));
ASSERT(0);*/
//
// Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.
//
ASSERT(FixedPcdGet8(PcdDefaultTerminalType) == 4);
CopyGuid(&mSerialConsole.TermType.Guid, &gEfiTtyTermGuid);
EfiBootManagerUpdateConsoleVariable (ConIn,
(EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);
EfiBootManagerUpdateConsoleVariable (ConOut,
(EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);
EfiBootManagerUpdateConsoleVariable (ErrOut,
(EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);
EfiBootManagerUpdateConsoleVariable(
ConIn, (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);
EfiBootManagerUpdateConsoleVariable(
ConOut, (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);
EfiBootManagerUpdateConsoleVariable(
ErrOut, (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);
//
// Register platform-specific boot options and keyboard shortcuts.
@ -642,10 +556,7 @@ PlatformBootManagerBeforeConsole (
}
STATIC
VOID
HandleCapsules (
VOID
)
VOID HandleCapsules(VOID)
{
ESRT_MANAGEMENT_PROTOCOL *EsrtManagement;
EFI_PEI_HOB_POINTERS HobPointer;
@ -655,8 +566,8 @@ HandleCapsules (
DEBUG((DEBUG_INFO, "%a: processing capsules ...\n", __FUNCTION__));
Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL,
(VOID **)&EsrtManagement);
Status = gBS->LocateProtocol(
&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtManagement);
if (!EFI_ERROR(Status)) {
EsrtManagement->SyncEsrtFmp();
}
@ -666,14 +577,15 @@ HandleCapsules (
//
HobPointer.Raw = GetHobList();
NeedReset = FALSE;
while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE,
HobPointer.Raw)) != NULL) {
while ((HobPointer.Raw =
GetNextHob(EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) {
CapsuleHeader = (VOID *)(UINTN)HobPointer.Capsule->BaseAddress;
Status = ProcessCapsuleImage(CapsuleHeader);
if (EFI_ERROR(Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to process capsule %p - %r\n",
__FUNCTION__, CapsuleHeader, Status));
DEBUG(
(DEBUG_ERROR, "%a: failed to process capsule %p - %r\n", __FUNCTION__,
CapsuleHeader, Status));
return;
}
@ -682,7 +594,8 @@ HandleCapsules (
}
if (NeedReset) {
DEBUG ((DEBUG_WARN, "%a: capsule update successful, resetting ...\n",
DEBUG(
(DEBUG_WARN, "%a: capsule update successful, resetting ...\n",
__FUNCTION__));
gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
@ -690,7 +603,6 @@ HandleCapsules (
}
}
#define VERSION_STRING_PREFIX L"Tianocore/EDK2 firmware version "
/**
@ -704,11 +616,7 @@ HandleCapsules (
> Dispatch additional option roms
> Special boot: e.g.: USB boot, enter UI
**/
VOID
EFIAPI
PlatformBootManagerAfterConsole (
VOID
)
VOID EFIAPI PlatformBootManagerAfterConsole(VOID)
{
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
@ -724,24 +632,27 @@ PlatformBootManagerAfterConsole (
Status = BootLogoEnableLogo();
if (EFI_ERROR(Status)) {
if (FirmwareVerLength > 0) {
Print (VERSION_STRING_PREFIX L"%s\n",
PcdGetPtr (PcdFirmwareVersionString));
Print(VERSION_STRING_PREFIX L"%s\n", PcdGetPtr(PcdFirmwareVersionString));
}
#ifdef ENABLE_SIMPLE_INIT
Print(L"Press any side button for SimpleInitGUI");
#else
Print(L"Press any side button for Boot Options");
#endif
} else if (FirmwareVerLength > 0) {
Status = gBS->HandleProtocol (gST->ConsoleOutHandle,
&gEfiGraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
}
else if (FirmwareVerLength > 0) {
Status = gBS->HandleProtocol(
gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid,
(VOID **)&GraphicsOutput);
if (!EFI_ERROR(Status)) {
PosX = (GraphicsOutput->Mode->Info->HorizontalResolution -
(StrLen(VERSION_STRING_PREFIX) + FirmwareVerLength) *
EFI_GLYPH_WIDTH) / 2;
EFI_GLYPH_WIDTH) /
2;
PosY = 0;
PrintXY (PosX, PosY, NULL, NULL, VERSION_STRING_PREFIX L"%s",
PrintXY(
PosX, PosY, NULL, NULL, VERSION_STRING_PREFIX L"%s",
PcdGetPtr(PcdFirmwareVersionString));
}
}
@ -769,23 +680,20 @@ PlatformBootManagerAfterConsole (
// Register UEFI Shell
//
PlatformRegisterFvBootOption(
&gUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE
);
&gUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE);
//
// Register Mass Storage App
//
PlatformRegisterFvBootOption(
&gUsbfnMsdAppFileGuid, L"Mass Storage", LOAD_OPTION_ACTIVE
);
&gUsbfnMsdAppFileGuid, L"Mass Storage", LOAD_OPTION_ACTIVE);
#ifdef AB_SLOTS_SUPPORT
//
// Register Switch Slots App
//
PlatformRegisterFvBootOption(
&gSwitchSlotsAppFileGuid, L"Reboot to other slot", LOAD_OPTION_ACTIVE
);
&gSwitchSlotsAppFileGuid, L"Reboot to other slot", LOAD_OPTION_ACTIVE);
#endif
}
@ -795,11 +703,7 @@ PlatformBootManagerAfterConsole (
@param TimeoutRemain The remaining timeout.
**/
VOID
EFIAPI
PlatformBootManagerWaitCallback (
UINT16 TimeoutRemain
)
VOID EFIAPI PlatformBootManagerWaitCallback(UINT16 TimeoutRemain)
{
EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;
@ -812,17 +716,13 @@ PlatformBootManagerWaitCallback (
White.Raw = 0x00FFFFFF;
Status = BootLogoUpdateProgress(
White.Pixel,
Black.Pixel,
White.Pixel, Black.Pixel,
#ifdef ENABLE_SIMPLE_INIT
L"Press any side button for SimpleInitGUI",
#else
L"Press any side button for Boot Options",
#endif
White.Pixel,
(Timeout - TimeoutRemain) * 100 / Timeout,
0
);
White.Pixel, (Timeout - TimeoutRemain) * 100 / Timeout, 0);
if (EFI_ERROR(Status)) {
Print(L".");
}
@ -835,11 +735,4 @@ PlatformBootManagerWaitCallback (
If this function returns, BDS attempts to enter an infinite loop.
**/
VOID
EFIAPI
PlatformBootManagerUnableToBoot (
VOID
)
{
return;
}
VOID EFIAPI PlatformBootManagerUnableToBoot(VOID) { return; }

View File

@ -41,9 +41,7 @@
@retval EFI_UNSUPPORTED Logo not found
**/
EFI_STATUS
EnableQuietBoot (
IN EFI_GUID *LogoFile
);
EnableQuietBoot(IN EFI_GUID *LogoFile);
/**
Use SystemTable Conout to turn on video based Simple Text Out consoles. The
@ -53,8 +51,6 @@ EnableQuietBoot (
@retval EFI_SUCCESS UGA devices are back in text mode and synced up.
**/
EFI_STATUS
DisableQuietBoot (
VOID
);
DisableQuietBoot(VOID);
#endif // _PLATFORM_BM_H_

View File

@ -3,12 +3,13 @@
* Copyright (c) 2018, Linaro Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
* are licensed and made available under the terms and conditions of the BSD
*License which accompanies this distribution. The full text of the license may
*be found at http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
*IMPLIED.
*
**/
@ -20,13 +21,11 @@
#include <Ppi/ArmMpCoreInfo.h>
ARM_CORE_INFO mHiKey960InfoTable[] = {
{
// Cluster 0, Core 0
{// Cluster 0, Core 0
0x0, 0x0,
// MP Core MailBox Set/Get/Clear Addresses and Clear Value
(UINT64)0xFFFFFFFF
},
(UINT64)0xFFFFFFFF},
/*
{
// Cluster 0, Core 1
@ -89,33 +88,20 @@ ARM_CORE_INFO mHiKey960InfoTable[] = {
**/
EFI_BOOT_MODE
ArmPlatformGetBootMode (
VOID
)
{
return BOOT_WITH_FULL_CONFIGURATION;
}
ArmPlatformGetBootMode(VOID) { return BOOT_WITH_FULL_CONFIGURATION; }
/**
Initialize controllers that must setup in the normal world
This function is called by the ArmPlatformPkg/Pei or ArmPlatformPkg/Pei/PlatformPeim
in the PEI phase.
This function is called by the ArmPlatformPkg/Pei or
ArmPlatformPkg/Pei/PlatformPeim in the PEI phase.
**/
RETURN_STATUS
ArmPlatformInitialize (
IN UINTN MpId
)
{
return RETURN_SUCCESS;
}
ArmPlatformInitialize(IN UINTN MpId) { return RETURN_SUCCESS; }
EFI_STATUS
PrePeiCoreGetMpCoreInfo (
OUT UINTN *CoreCount,
OUT ARM_CORE_INFO **ArmCoreTable
)
PrePeiCoreGetMpCoreInfo(OUT UINTN *CoreCount, OUT ARM_CORE_INFO **ArmCoreTable)
{
// Only support one cluster
*CoreCount = sizeof(mHiKey960InfoTable) / sizeof(ARM_CORE_INFO);
@ -123,23 +109,16 @@ PrePeiCoreGetMpCoreInfo (
return EFI_SUCCESS;
}
// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore
// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is
// undefined in the contect of PrePeiCore
EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;
ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = {PrePeiCoreGetMpCoreInfo};
EFI_PEI_PPI_DESCRIPTOR gPlatformPpiTable[] = {
{
EFI_PEI_PPI_DESCRIPTOR_PPI,
&mArmMpCoreInfoPpiGuid,
&mMpCoreInfoPpi
}
};
{EFI_PEI_PPI_DESCRIPTOR_PPI, &mArmMpCoreInfoPpiGuid, &mMpCoreInfoPpi}};
VOID
ArmPlatformGetPlatformPpiList (
OUT UINTN *PpiListSize,
OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
)
VOID ArmPlatformGetPlatformPpiList(
OUT UINTN *PpiListSize, OUT EFI_PEI_PPI_DESCRIPTOR **PpiList)
{
*PpiListSize = sizeof(gPlatformPpiTable);
*PpiList = gPlatformPpiTable;

View File

@ -4,67 +4,55 @@
* Copyright (c) 2019, RUIKAI LIU and MR TUNNEL. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
* are licensed and made available under the terms and conditions of the BSD
*License which accompanies this distribution. The full text of the license may
*be found at http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
*IMPLIED.
*
**/
#include <Configuration/DeviceMemoryMap.h>
#include <Library/ArmPlatformLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Configuration/DeviceMemoryMap.h>
#include <Library/MemoryAllocationLib.h>
/**
Return the Virtual Memory Map of your platform
This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
@param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
Virtual Memory mapping. This array must be ended by a zero-filled
entry
This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
on your platform.
@param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
describing a Physical-to- Virtual Memory mapping. This array must be ended by a
zero-filled entry
**/
STATIC
VOID
AddHob
(
ARM_MEMORY_REGION_DESCRIPTOR_EX Desc
)
VOID AddHob(ARM_MEMORY_REGION_DESCRIPTOR_EX Desc)
{
BuildResourceDescriptorHob(
Desc.ResourceType,
Desc.ResourceAttribute,
Desc.Address,
Desc.Length
);
Desc.ResourceType, Desc.ResourceAttribute, Desc.Address, Desc.Length);
BuildMemoryAllocationHob(
Desc.Address,
Desc.Length,
Desc.MemoryType
);
BuildMemoryAllocationHob(Desc.Address, Desc.Length, Desc.MemoryType);
}
VOID
ArmPlatformGetVirtualMemoryMap (
IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
)
VOID ArmPlatformGetVirtualMemoryMap(
IN ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap)
{
// TO-DO:ADD MEMORY MAP HERE
ARM_MEMORY_REGION_DESCRIPTOR *MemoryDescriptor;
UINTN Index = 0;
MemoryDescriptor = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages
(EFI_SIZE_TO_PAGES (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
MemoryDescriptor =
(ARM_MEMORY_REGION_DESCRIPTOR *)AllocatePages(EFI_SIZE_TO_PAGES(
sizeof(ARM_MEMORY_REGION_DESCRIPTOR) *
MAX_ARM_MEMORY_REGION_DESCRIPTOR_COUNT));
// Run through each memory descriptor
while (gDeviceMemoryDescriptorEx[Index].Address != (EFI_PHYSICAL_ADDRESS)0xFFFFFFFF)
{
switch (gDeviceMemoryDescriptorEx[Index].HobOption)
{
while (gDeviceMemoryDescriptorEx[Index].Address !=
(EFI_PHYSICAL_ADDRESS)0xFFFFFFFF) {
switch (gDeviceMemoryDescriptorEx[Index].HobOption) {
case AddMem:
case AddDev:
AddHob(gDeviceMemoryDescriptorEx[Index]);
@ -77,10 +65,13 @@ ArmPlatformGetVirtualMemoryMap (
update:
ASSERT(Index < MAX_ARM_MEMORY_REGION_DESCRIPTOR_COUNT);
MemoryDescriptor[Index].PhysicalBase = gDeviceMemoryDescriptorEx[Index].Address;
MemoryDescriptor[Index].VirtualBase = gDeviceMemoryDescriptorEx[Index].Address;
MemoryDescriptor[Index].PhysicalBase =
gDeviceMemoryDescriptorEx[Index].Address;
MemoryDescriptor[Index].VirtualBase =
gDeviceMemoryDescriptorEx[Index].Address;
MemoryDescriptor[Index].Length = gDeviceMemoryDescriptorEx[Index].Length;
MemoryDescriptor[Index].Attributes = gDeviceMemoryDescriptorEx[Index].ArmAttributes;
MemoryDescriptor[Index].Attributes =
gDeviceMemoryDescriptorEx[Index].ArmAttributes;
Index++;
}