MdeModulePkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the MdeModulePkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:02 -08:00
committed by mergify[bot]
parent 7c7184e201
commit 1436aea4d5
994 changed files with 107608 additions and 101311 deletions

View File

@ -60,7 +60,7 @@ PrintStringAt (
&ScreenRows &ScreenRows
); );
if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) { if ((Column > (ScreenWidth - 1)) || (Row > (ScreenRows - 1))) {
return 0; return 0;
} }
@ -127,7 +127,7 @@ PrintCharAt (
&ScreenRows &ScreenRows
); );
if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) { if ((Column > (ScreenWidth - 1)) || (Row > (ScreenRows - 1))) {
return 0; return 0;
} }
@ -168,7 +168,8 @@ GetLineWidth (
(String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0); (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);
Index++, LineWidth = LineWidth + IncrementValue Index++, LineWidth = LineWidth + IncrementValue
) )
; {
}
// //
// We hit the null-terminator, we now have a count // We hit the null-terminator, we now have a count
@ -176,6 +177,7 @@ GetLineWidth (
if (String[Index] == 0) { if (String[Index] == 0) {
break; break;
} }
// //
// We encountered a narrow directive - strip it from the size calculation since it doesn't get printed // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed
// and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2) // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)
@ -194,6 +196,7 @@ GetLineWidth (
IncrementValue = 2; IncrementValue = 2;
} }
} while (String[Index] != 0); } while (String[Index] != 0);
FreePool (String); FreePool (String);
} }
@ -225,6 +228,7 @@ InitializeBootMenuScreen (
if (BootMenuData == NULL) { if (BootMenuData == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Get maximum string width // Get maximum string width
// //
@ -243,6 +247,7 @@ InitializeBootMenuScreen (
StrWidth = GetLineWidth (BootMenuData->HelpToken[Index]); StrWidth = GetLineWidth (BootMenuData->HelpToken[Index]);
MaxStrWidth = MaxStrWidth > StrWidth ? MaxStrWidth : StrWidth; MaxStrWidth = MaxStrWidth > StrWidth ? MaxStrWidth : StrWidth;
} }
// //
// query current row and column to calculate boot menu location // query current row and column to calculate boot menu location
// //
@ -260,6 +265,7 @@ InitializeBootMenuScreen (
} else { } else {
BootMenuData->MenuScreen.Width = MaxStrWidth + 8; BootMenuData->MenuScreen.Width = MaxStrWidth + 8;
} }
if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) { if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) {
BootMenuData->MenuScreen.Height = MaxPrintRows; BootMenuData->MenuScreen.Height = MaxPrintRows;
BootMenuData->ScrollBarControl.HasScrollBar = TRUE; BootMenuData->ScrollBarControl.HasScrollBar = TRUE;
@ -273,11 +279,13 @@ InitializeBootMenuScreen (
BootMenuData->ScrollBarControl.FirstItem = 0; BootMenuData->ScrollBarControl.FirstItem = 0;
BootMenuData->ScrollBarControl.LastItem = BootMenuData->ItemCount - 1; BootMenuData->ScrollBarControl.LastItem = BootMenuData->ItemCount - 1;
} }
BootMenuData->MenuScreen.StartCol = (Column - BootMenuData->MenuScreen.Width) / 2; BootMenuData->MenuScreen.StartCol = (Column - BootMenuData->MenuScreen.Width) / 2;
BootMenuData->MenuScreen.StartRow = (Row - BootMenuData->MenuScreen.Height) / 2; BootMenuData->MenuScreen.StartRow = (Row - BootMenuData->MenuScreen.Height) / 2;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
This function uses check boot option is wheher setup application or no This function uses check boot option is wheher setup application or no
@ -366,7 +374,7 @@ InitializeBootMenuData (
UINTN Index; UINTN Index;
UINTN StrIndex; UINTN StrIndex;
if (BootOption == NULL || BootMenuData == NULL) { if ((BootOption == NULL) || (BootMenuData == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -431,9 +439,10 @@ BootMenuSelectItem (
UINTN Index; UINTN Index;
BOOLEAN RePaintItems; BOOLEAN RePaintItems;
if (BootMenuData == NULL || WantSelectItem >= BootMenuData->ItemCount) { if ((BootMenuData == NULL) || (WantSelectItem >= BootMenuData->ItemCount)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
ASSERT (BootMenuData->ItemCount != 0); ASSERT (BootMenuData->ItemCount != 0);
SavedAttribute = gST->ConOut->Mode->Attribute; SavedAttribute = gST->ConOut->Mode->Attribute;
RePaintItems = FALSE; RePaintItems = FALSE;
@ -443,9 +452,10 @@ BootMenuSelectItem (
// print selectable items again and adjust scroll bar if need // print selectable items again and adjust scroll bar if need
// //
if (BootMenuData->ScrollBarControl.HasScrollBar && if (BootMenuData->ScrollBarControl.HasScrollBar &&
(WantSelectItem < BootMenuData->ScrollBarControl.FirstItem || ((WantSelectItem < BootMenuData->ScrollBarControl.FirstItem) ||
WantSelectItem > BootMenuData->ScrollBarControl.LastItem || (WantSelectItem > BootMenuData->ScrollBarControl.LastItem) ||
WantSelectItem == BootMenuData->SelectItem)) { (WantSelectItem == BootMenuData->SelectItem)))
{
ItemCountPerScreen = BootMenuData->ScrollBarControl.ItemCountPerScreen; ItemCountPerScreen = BootMenuData->ScrollBarControl.ItemCountPerScreen;
// //
// Set first item and last item // Set first item and last item
@ -457,6 +467,7 @@ BootMenuSelectItem (
BootMenuData->ScrollBarControl.FirstItem = WantSelectItem - ItemCountPerScreen + 1; BootMenuData->ScrollBarControl.FirstItem = WantSelectItem - ItemCountPerScreen + 1;
BootMenuData->ScrollBarControl.LastItem = WantSelectItem; BootMenuData->ScrollBarControl.LastItem = WantSelectItem;
} }
gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLUE); gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLUE);
FirstItem = BootMenuData->ScrollBarControl.FirstItem; FirstItem = BootMenuData->ScrollBarControl.FirstItem;
LastItem = BootMenuData->ScrollBarControl.LastItem; LastItem = BootMenuData->ScrollBarControl.LastItem;
@ -466,31 +477,34 @@ BootMenuSelectItem (
if ((FirstItem * ItemCountPerScreen) % BootMenuData->ItemCount != 0) { if ((FirstItem * ItemCountPerScreen) % BootMenuData->ItemCount != 0) {
TopShadeNum++; TopShadeNum++;
} }
PrintCol = StartCol + BootMenuData->MenuScreen.Width - 2; PrintCol = StartCol + BootMenuData->MenuScreen.Width - 2;
PrintRow = StartRow + TITLE_TOKEN_COUNT + 2; PrintRow = StartRow + TITLE_TOKEN_COUNT + 2;
for (Index = 0; Index < TopShadeNum; Index++, PrintRow++) { for (Index = 0; Index < TopShadeNum; Index++, PrintRow++) {
PrintCharAt (PrintCol, PrintRow, BLOCKELEMENT_LIGHT_SHADE); PrintCharAt (PrintCol, PrintRow, BLOCKELEMENT_LIGHT_SHADE);
} }
} }
LowShadeNum = 0; LowShadeNum = 0;
if (LastItem != BootMenuData->ItemCount - 1) { if (LastItem != BootMenuData->ItemCount - 1) {
LowShadeNum = ((BootMenuData->ItemCount - 1 - LastItem) * ItemCountPerScreen) / BootMenuData->ItemCount; LowShadeNum = ((BootMenuData->ItemCount - 1 - LastItem) * ItemCountPerScreen) / BootMenuData->ItemCount;
if (((BootMenuData->ItemCount - 1 - LastItem) * ItemCountPerScreen) % BootMenuData->ItemCount != 0) { if (((BootMenuData->ItemCount - 1 - LastItem) * ItemCountPerScreen) % BootMenuData->ItemCount != 0) {
LowShadeNum++; LowShadeNum++;
} }
PrintCol = StartCol + BootMenuData->MenuScreen.Width - 2; PrintCol = StartCol + BootMenuData->MenuScreen.Width - 2;
PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + ItemCountPerScreen - LowShadeNum; PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + ItemCountPerScreen - LowShadeNum;
for (Index = 0; Index < LowShadeNum; Index++, PrintRow++) { for (Index = 0; Index < LowShadeNum; Index++, PrintRow++) {
PrintCharAt (PrintCol, PrintRow, BLOCKELEMENT_LIGHT_SHADE); PrintCharAt (PrintCol, PrintRow, BLOCKELEMENT_LIGHT_SHADE);
} }
} }
PrintCol = StartCol + BootMenuData->MenuScreen.Width - 2; PrintCol = StartCol + BootMenuData->MenuScreen.Width - 2;
PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + TopShadeNum; PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + TopShadeNum;
for (Index = TopShadeNum; Index < ItemCountPerScreen - LowShadeNum; Index++, PrintRow++) { for (Index = TopShadeNum; Index < ItemCountPerScreen - LowShadeNum; Index++, PrintRow++) {
PrintCharAt (PrintCol, PrintRow, BLOCKELEMENT_FULL_BLOCK); PrintCharAt (PrintCol, PrintRow, BLOCKELEMENT_FULL_BLOCK);
} }
// //
// Clear selectable items first // Clear selectable items first
// //
@ -501,9 +515,11 @@ BootMenuSelectItem (
for (Index = 0; Index < BootMenuData->MenuScreen.Width - 3; Index++) { for (Index = 0; Index < BootMenuData->MenuScreen.Width - 3; Index++) {
String[Index] = 0x20; String[Index] = 0x20;
} }
for (Index = 0; Index < ItemCountPerScreen; Index++) { for (Index = 0; Index < ItemCountPerScreen; Index++) {
PrintStringAt (PrintCol, PrintRow + Index, String); PrintStringAt (PrintCol, PrintRow + Index, String);
} }
FreePool (String); FreePool (String);
// //
// print selectable items // print selectable items
@ -513,6 +529,7 @@ BootMenuSelectItem (
PrintStringAt (PrintCol, PrintRow, String); PrintStringAt (PrintCol, PrintRow, String);
FreePool (String); FreePool (String);
} }
RePaintItems = TRUE; RePaintItems = TRUE;
} }
@ -521,7 +538,7 @@ BootMenuSelectItem (
// items, clear select item // items, clear select item
// //
FirstItem = BootMenuData->ScrollBarControl.FirstItem; FirstItem = BootMenuData->ScrollBarControl.FirstItem;
if (WantSelectItem != BootMenuData->SelectItem && !RePaintItems) { if ((WantSelectItem != BootMenuData->SelectItem) && !RePaintItems) {
gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLUE); gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLUE);
String = HiiGetString (gStringPackHandle, BootMenuData->PtrTokens[BootMenuData->SelectItem], NULL); String = HiiGetString (gStringPackHandle, BootMenuData->PtrTokens[BootMenuData->SelectItem], NULL);
PrintCol = StartCol + 1; PrintCol = StartCol + 1;
@ -587,6 +604,7 @@ DrawBootPopupMenu (
for (Index = 1; Index < Width - 1; Index++) { for (Index = 1; Index < Width - 1; Index++) {
PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL); PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL);
} }
PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_DOWN_LEFT); PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_DOWN_LEFT);
// //
@ -610,6 +628,7 @@ DrawBootPopupMenu (
for (Index = 1; Index < Width - 1; Index++) { for (Index = 1; Index < Width - 1; Index++) {
PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL); PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL);
} }
PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL_LEFT); PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL_LEFT);
// //
@ -627,6 +646,7 @@ DrawBootPopupMenu (
for (Index = 1; Index < Width - 1; Index++) { for (Index = 1; Index < Width - 1; Index++) {
PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL); PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL);
} }
PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL_LEFT); PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL_LEFT);
// //
@ -638,6 +658,7 @@ DrawBootPopupMenu (
PrintStringAt (StartCol + 1, PrintRow, String); PrintStringAt (StartCol + 1, PrintRow, String);
PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL); PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL);
} }
FreePool (String); FreePool (String);
PrintRow++; PrintRow++;
@ -645,8 +666,8 @@ DrawBootPopupMenu (
for (Index = 1; Index < Width - 1; Index++) { for (Index = 1; Index < Width - 1; Index++) {
PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL); PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL);
} }
PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_UP_LEFT);
PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_UP_LEFT);
// //
// print title strings // print title strings
@ -839,15 +860,17 @@ BdsSetConsoleMode (
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
if ((Info->HorizontalResolution == NewHorizontalResolution) && if ((Info->HorizontalResolution == NewHorizontalResolution) &&
(Info->VerticalResolution == NewVerticalResolution)) { (Info->VerticalResolution == NewVerticalResolution))
{
if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) && if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) &&
(GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) { (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution))
{
// //
// Current resolution is same with required resolution, check if text mode need be set // Current resolution is same with required resolution, check if text mode need be set
// //
Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow); Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
if (CurrentColumn == NewColumns && CurrentRow == NewRows) { if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {
// //
// If current text mode is same with required text mode. Do nothing // If current text mode is same with required text mode. Do nothing
// //
@ -878,6 +901,7 @@ BdsSetConsoleMode (
} }
} }
} }
if (Index == MaxTextMode) { if (Index == MaxTextMode) {
// //
// If required text mode is not supported, return error. // If required text mode is not supported, return error.
@ -898,6 +922,7 @@ BdsSetConsoleMode (
} }
} }
} }
FreePool (Info); FreePool (Info);
} }
} }
@ -938,9 +963,11 @@ BdsSetConsoleMode (
for (Index = 0; Index < HandleCount; Index++) { for (Index = 0; Index < HandleCount; Index++) {
gBS->DisconnectController (HandleBuffer[Index], NULL, NULL); gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
} }
for (Index = 0; Index < HandleCount; Index++) { for (Index = 0; Index < HandleCount; Index++) {
gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE); gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
} }
if (HandleBuffer != NULL) { if (HandleBuffer != NULL) {
FreePool (HandleBuffer); FreePool (HandleBuffer);
} }
@ -1083,10 +1110,8 @@ BootManagerMenuEntry (
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
switch (Key.UnicodeChar) { switch (Key.UnicodeChar) {
case CHAR_NULL: case CHAR_NULL:
switch (Key.ScanCode) { switch (Key.ScanCode) {
case SCAN_UP: case SCAN_UP:
SelectItem = BootMenuData.SelectItem == 0 ? BootMenuData.ItemCount - 1 : BootMenuData.SelectItem - 1; SelectItem = BootMenuData.SelectItem == 0 ? BootMenuData.ItemCount - 1 : BootMenuData.SelectItem - 1;
BootMenuSelectItem (SelectItem, &BootMenuData); BootMenuSelectItem (SelectItem, &BootMenuData);
@ -1109,6 +1134,7 @@ BootManagerMenuEntry (
default: default:
break; break;
} }
break; break;
case CHAR_CARRIAGE_RETURN: case CHAR_CARRIAGE_RETURN:
@ -1130,11 +1156,11 @@ BootManagerMenuEntry (
} }
} }
} }
EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount); EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);
FreePool (BootMenuData.PtrTokens); FreePool (BootMenuData.PtrTokens);
HiiRemovePackages (gStringPackHandle); HiiRemovePackages (gStringPackHandle);
return Status; return Status;
} }

View File

@ -6,7 +6,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef _BOOT_MANAGER_MENU_H_ #ifndef _BOOT_MANAGER_MENU_H_
#define _BOOT_MANAGER_MENU_H_ #define _BOOT_MANAGER_MENU_H_
@ -51,4 +50,3 @@ typedef struct _BOOT_MENU_POPUP_DATA {
} BOOT_MENU_POPUP_DATA; } BOOT_MENU_POPUP_DATA;
#endif #endif

View File

@ -209,6 +209,7 @@ WriteFileFromBuffer (
return Status; return Status;
} }
} }
FreePool (FileInfo); FreePool (FileInfo);
// //
@ -229,4 +230,3 @@ WriteFileFromBuffer (
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -47,6 +47,7 @@ CreateBmpFmp (
Print (L"CapsuleApp: NO GOP is found.\n"); Print (L"CapsuleApp: NO GOP is found.\n");
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
Info = Gop->Mode->Info; Info = Gop->Mode->Info;
Print (L"Current GOP: Mode - %d, ", Gop->Mode->Mode); Print (L"Current GOP: Mode - %d, ", Gop->Mode->Mode);
Print (L"HorizontalResolution - %d, ", Info->HorizontalResolution); Print (L"HorizontalResolution - %d, ", Info->HorizontalResolution);
@ -63,6 +64,7 @@ CreateBmpFmp (
Print (L"CapsuleApp: NO output capsule name.\n"); Print (L"CapsuleApp: NO output capsule name.\n");
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
OutputCapsuleName = Argv[4]; OutputCapsuleName = Argv[4];
BmpBuffer = NULL; BmpBuffer = NULL;
@ -89,9 +91,11 @@ CreateBmpFmp (
Print (L"CapsuleApp: BMP image (%s) is not valid.\n", BmpName); Print (L"CapsuleApp: BMP image (%s) is not valid.\n", BmpName);
goto Done; goto Done;
} }
if (GopBlt != NULL) { if (GopBlt != NULL) {
FreePool (GopBlt); FreePool (GopBlt);
} }
Print (L"BMP image (%s), Width - %d, Height - %d\n", BmpName, Width, Height); Print (L"BMP image (%s), Width - %d, Height - %d\n", BmpName, Width, Height);
if (Height > Info->VerticalResolution) { if (Height > Info->VerticalResolution) {
@ -99,6 +103,7 @@ CreateBmpFmp (
Print (L"CapsuleApp: BMP image (%s) height is larger than current resolution.\n", BmpName); Print (L"CapsuleApp: BMP image (%s) height is larger than current resolution.\n", BmpName);
goto Done; goto Done;
} }
if (Width > Info->HorizontalResolution) { if (Width > Info->HorizontalResolution) {
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
Print (L"CapsuleApp: BMP image (%s) width is larger than current resolution.\n", BmpName); Print (L"CapsuleApp: BMP image (%s) width is larger than current resolution.\n", BmpName);
@ -140,7 +145,8 @@ CreateBmpFmp (
(UINT32)(((3 * Info->VerticalResolution) - (2 * Height)) / 4) (UINT32)(((3 * Info->VerticalResolution) - (2 * Height)) / 4)
); );
Print(L"BMP image (%s), OffsetX - %d, OffsetY - %d\n", Print (
L"BMP image (%s), OffsetX - %d, OffsetY - %d\n",
BmpName, BmpName,
DisplayCapsule->ImagePayload.OffsetX, DisplayCapsule->ImagePayload.OffsetX,
DisplayCapsule->ImagePayload.OffsetY DisplayCapsule->ImagePayload.OffsetY
@ -186,6 +192,7 @@ GetCapsuleImageTypeId (
if (FmpCapsuleHeader->PayloadItemCount == 0) { if (FmpCapsuleHeader->PayloadItemCount == 0) {
return NULL; return NULL;
} }
ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[FmpCapsuleHeader->EmbeddedDriverCount]); ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[FmpCapsuleHeader->EmbeddedDriverCount]);
return &ImageHeader->UpdateImageTypeId; return &ImageHeader->UpdateImageTypeId;
} }
@ -245,12 +252,15 @@ IsValidCapsuleHeader (
if (CapsuleSize < sizeof (EFI_CAPSULE_HEADER)) { if (CapsuleSize < sizeof (EFI_CAPSULE_HEADER)) {
return FALSE; return FALSE;
} }
if (CapsuleHeader->CapsuleImageSize != CapsuleSize) { if (CapsuleHeader->CapsuleImageSize != CapsuleSize) {
return FALSE; return FALSE;
} }
if (CapsuleHeader->HeaderSize > CapsuleHeader->CapsuleImageSize) { if (CapsuleHeader->HeaderSize > CapsuleHeader->CapsuleImageSize) {
return FALSE; return FALSE;
} }
if (CapsuleHeader->HeaderSize < sizeof (EFI_CAPSULE_HEADER)) { if (CapsuleHeader->HeaderSize < sizeof (EFI_CAPSULE_HEADER)) {
return FALSE; return FALSE;
} }
@ -311,6 +321,7 @@ CreateNestedFmp (
Print (L"CapsuleApp: NO output capsule name.\n"); Print (L"CapsuleApp: NO output capsule name.\n");
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
OutputCapsuleName = Argv[4]; OutputCapsuleName = Argv[4];
CapsuleBuffer = NULL; CapsuleBuffer = NULL;
@ -323,6 +334,7 @@ CreateNestedFmp (
Print (L"CapsuleApp: Capsule image (%s) is not found.\n", CapsuleName); Print (L"CapsuleApp: Capsule image (%s) is not found.\n", CapsuleName);
goto Done; goto Done;
} }
if (!IsValidCapsuleHeader (CapsuleBuffer, FileSize)) { if (!IsValidCapsuleHeader (CapsuleBuffer, FileSize)) {
Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName); Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
@ -341,6 +353,7 @@ CreateNestedFmp (
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done; goto Done;
} }
FwType = GetEsrtFwType (ImageTypeId); FwType = GetEsrtFwType (ImageTypeId);
if ((FwType != ESRT_FW_TYPE_SYSTEMFIRMWARE) && (FwType != ESRT_FW_TYPE_DEVICEFIRMWARE)) { if ((FwType != ESRT_FW_TYPE_SYSTEMFIRMWARE) && (FwType != ESRT_FW_TYPE_DEVICEFIRMWARE)) {
Print (L"CapsuleApp: Capsule FwType is invalid.\n"); Print (L"CapsuleApp: Capsule FwType is invalid.\n");
@ -380,7 +393,6 @@ Done:
return Status; return Status;
} }
/** /**
Clear capsule status variable. Clear capsule status variable.
@ -418,6 +430,7 @@ ClearCapsuleStatusVariable (
// //
break; break;
} }
Found = TRUE; Found = TRUE;
Print (L"Clear %s %r\n", CapsuleVarName, Status); Print (L"Clear %s %r\n", CapsuleVarName, Status);
@ -524,6 +537,7 @@ BuildGatherList (
} else { } else {
Size = SizeLeft; Size = SizeLeft;
} }
TempBlockPtr->Union.DataBlock = (UINTN)TempDataPtr; TempBlockPtr->Union.DataBlock = (UINTN)TempDataPtr;
TempBlockPtr->Length = Size; TempBlockPtr->Length = Size;
Print (L"CapsuleApp: capsule block/size 0x%X/0x%X\n", (UINTN)TempDataPtr, Size); Print (L"CapsuleApp: capsule block/size 0x%X/0x%X\n", (UINTN)TempDataPtr, Size);
@ -747,38 +761,47 @@ UefiMain (
Print (L"Please use UEFI SHELL to run this application!\n", Status); Print (L"Please use UEFI SHELL to run this application!\n", Status);
return Status; return Status;
} }
if (Argc < 2) { if (Argc < 2) {
PrintUsage (); PrintUsage ();
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
if (StrCmp (Argv[1], L"-D") == 0) { if (StrCmp (Argv[1], L"-D") == 0) {
if (Argc != 3) { if (Argc != 3) {
Print (L"CapsuleApp: Incorrect parameter count.\n"); Print (L"CapsuleApp: Incorrect parameter count.\n");
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
Status = DumpCapsule (Argv[2]); Status = DumpCapsule (Argv[2]);
return Status; return Status;
} }
if (StrCmp (Argv[1], L"-G") == 0) { if (StrCmp (Argv[1], L"-G") == 0) {
Status = CreateBmpFmp (); Status = CreateBmpFmp ();
return Status; return Status;
} }
if (StrCmp (Argv[1], L"-N") == 0) { if (StrCmp (Argv[1], L"-N") == 0) {
Status = CreateNestedFmp (); Status = CreateNestedFmp ();
return Status; return Status;
} }
if (StrCmp (Argv[1], L"-S") == 0) { if (StrCmp (Argv[1], L"-S") == 0) {
Status = DumpCapsuleStatusVariable (); Status = DumpCapsuleStatusVariable ();
return EFI_SUCCESS; return EFI_SUCCESS;
} }
if (StrCmp (Argv[1], L"-C") == 0) { if (StrCmp (Argv[1], L"-C") == 0) {
Status = ClearCapsuleStatusVariable (); Status = ClearCapsuleStatusVariable ();
return Status; return Status;
} }
if (StrCmp (Argv[1], L"-P") == 0) { if (StrCmp (Argv[1], L"-P") == 0) {
if (Argc == 2) { if (Argc == 2) {
DumpFmpData (); DumpFmpData ();
} }
if (Argc >= 3) { if (Argc >= 3) {
if (StrCmp (Argv[2], L"GET") != 0) { if (StrCmp (Argv[2], L"GET") != 0) {
Print (L"CapsuleApp: Unrecognized option(%s).\n", Argv[2]); Print (L"CapsuleApp: Unrecognized option(%s).\n", Argv[2]);
@ -797,14 +820,17 @@ UefiMain (
Print (L"Invalid ImageTypeId - %s\n", Argv[3]); Print (L"Invalid ImageTypeId - %s\n", Argv[3]);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
ImageIndex = StrDecimalToUintn (Argv[4]); ImageIndex = StrDecimalToUintn (Argv[4]);
if (StrCmp (Argv[5], L"-O") != 0) { if (StrCmp (Argv[5], L"-O") != 0) {
Print (L"CapsuleApp: NO output file name.\n"); Print (L"CapsuleApp: NO output file name.\n");
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
DumpFmpImage (&ImageTypeId, ImageIndex, Argv[6]); DumpFmpImage (&ImageTypeId, ImageIndex, Argv[6]);
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -814,11 +840,12 @@ UefiMain (
} }
if (StrCmp (Argv[1], L"-L") == 0) { if (StrCmp (Argv[1], L"-L") == 0) {
if (Argc >= 3 && StrCmp(Argv[2], L"INFO") == 0) { if ((Argc >= 3) && (StrCmp (Argv[2], L"INFO") == 0)) {
DumpProvisionedCapsule (TRUE); DumpProvisionedCapsule (TRUE);
} else { } else {
DumpProvisionedCapsule (FALSE); DumpProvisionedCapsule (FALSE);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -889,6 +916,7 @@ UefiMain (
Print (L"CapsuleApp: NO capsule image.\n"); Print (L"CapsuleApp: NO capsule image.\n");
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
if (CapsuleNum > MAX_CAPSULE_NUM) { if (CapsuleNum > MAX_CAPSULE_NUM) {
Print (L"CapsuleApp: Too many capsule images.\n"); Print (L"CapsuleApp: Too many capsule images.\n");
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
@ -905,10 +933,12 @@ UefiMain (
Print (L"CapsuleApp: capsule image (%s) is not found.\n", CapsuleName); Print (L"CapsuleApp: capsule image (%s) is not found.\n", CapsuleName);
goto Done; goto Done;
} }
if (!IsValidCapsuleHeader (CapsuleBuffer[Index], CapsuleBufferSize[Index])) { if (!IsValidCapsuleHeader (CapsuleBuffer[Index], CapsuleBufferSize[Index])) {
Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName); Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
CapsuleNames[Index] = CapsuleName; CapsuleNames[Index] = CapsuleName;
} }
@ -930,6 +960,7 @@ UefiMain (
NeedReset = TRUE; NeedReset = TRUE;
} }
} }
CapsuleHeaderArray[CapsuleNum] = NULL; CapsuleHeaderArray[CapsuleNum] = NULL;
// //
@ -975,6 +1006,7 @@ UefiMain (
Print (L"CapsuleApp: failed to update capsule - %r\n", Status); Print (L"CapsuleApp: failed to update capsule - %r\n", Status);
goto Done; goto Done;
} }
// //
// For capsule with CAPSULE_FLAGS_PERSIST_ACROSS_RESET + CAPSULE_FLAGS_INITIATE_RESET, // For capsule with CAPSULE_FLAGS_PERSIST_ACROSS_RESET + CAPSULE_FLAGS_INITIATE_RESET,
// a system reset should have been triggered by gRT->UpdateCapsule() calling above. // a system reset should have been triggered by gRT->UpdateCapsule() calling above.

View File

@ -6,7 +6,6 @@
**/ **/
#ifndef _CAPSULE_APP_H_ #ifndef _CAPSULE_APP_H_
#define _CAPSULE_APP_H_ #define _CAPSULE_APP_H_
@ -81,7 +80,6 @@ GetShellProtocol (
VOID VOID
); );
/** /**
Read a file. Read a file.
@ -118,7 +116,6 @@ WriteFileFromBuffer (
IN VOID *Buffer IN VOID *Buffer
); );
/** /**
Dump capsule information Dump capsule information
@ -193,7 +190,6 @@ DumpAllEfiSysPartition (
VOID VOID
); );
/** /**
Get SimpleFileSystem from boot option file path. Get SimpleFileSystem from boot option file path.
@ -213,7 +209,6 @@ GetEfiSysPartitionFromBootOptionFilePath (
OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **Fs OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **Fs
); );
/** /**
Process Capsule On Disk. Process Capsule On Disk.
@ -237,4 +232,3 @@ ProcessCapsuleOnDisk (
); );
#endif #endif

View File

@ -37,6 +37,7 @@ DumpUxCapsule (
) )
{ {
EFI_DISPLAY_CAPSULE *DisplayCapsule; EFI_DISPLAY_CAPSULE *DisplayCapsule;
DisplayCapsule = (EFI_DISPLAY_CAPSULE *)CapsuleHeader; DisplayCapsule = (EFI_DISPLAY_CAPSULE *)CapsuleHeader;
Print (L"[UxCapsule]\n"); Print (L"[UxCapsule]\n");
Print (L"CapsuleHeader:\n"); Print (L"CapsuleHeader:\n");
@ -53,7 +54,6 @@ DumpUxCapsule (
Print (L" OffsetY - 0x%x\n", DisplayCapsule->ImagePayload.OffsetY); Print (L" OffsetY - 0x%x\n", DisplayCapsule->ImagePayload.OffsetY);
} }
/** /**
Dump a non-nested FMP capsule. Dump a non-nested FMP capsule.
@ -155,9 +155,11 @@ IsNestedFmpCapsule (
if (NestedCapsuleSize < sizeof (EFI_CAPSULE_HEADER)) { if (NestedCapsuleSize < sizeof (EFI_CAPSULE_HEADER)) {
return FALSE; return FALSE;
} }
if (!CompareGuid (&NestedCapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) { if (!CompareGuid (&NestedCapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
@ -185,6 +187,7 @@ DumpCapsule (
Print (L"CapsuleApp: Capsule (%s) is not found.\n", CapsuleName); Print (L"CapsuleApp: Capsule (%s) is not found.\n", CapsuleName);
goto Done; goto Done;
} }
if (!IsValidCapsuleHeader (Buffer, FileSize)) { if (!IsValidCapsuleHeader (Buffer, FileSize)) {
Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName); Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
@ -201,6 +204,7 @@ DumpCapsule (
if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) { if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
DumpFmpCapsule (CapsuleHeader); DumpFmpCapsule (CapsuleHeader);
} }
if (IsNestedFmpCapsule (CapsuleHeader)) { if (IsNestedFmpCapsule (CapsuleHeader)) {
Print (L"[NestedCapsule]\n"); Print (L"[NestedCapsule]\n");
Print (L"CapsuleHeader:\n"); Print (L"CapsuleHeader:\n");
@ -215,6 +219,7 @@ Done:
if (Buffer != NULL) { if (Buffer != NULL) {
FreePool (Buffer); FreePool (Buffer);
} }
return Status; return Status;
} }
@ -254,6 +259,7 @@ DumpCapsuleStatusVariable (
Print (L"CapsuleMax - %s\n", CapsuleIndexData); Print (L"CapsuleMax - %s\n", CapsuleIndexData);
FreePool (CapsuleIndex); FreePool (CapsuleIndex);
} }
Status = GetVariable2 ( Status = GetVariable2 (
L"CapsuleLast", L"CapsuleLast",
&gEfiCapsuleReportGuid, &gEfiCapsuleReportGuid,
@ -268,7 +274,6 @@ DumpCapsuleStatusVariable (
FreePool (CapsuleIndex); FreePool (CapsuleIndex);
} }
StrCpyS (CapsuleVarName, sizeof (CapsuleVarName)/sizeof (CapsuleVarName[0]), L"Capsule"); StrCpyS (CapsuleVarName, sizeof (CapsuleVarName)/sizeof (CapsuleVarName[0]), L"Capsule");
TempVarName = CapsuleVarName + StrLen (CapsuleVarName); TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
Index = 0; Index = 0;
@ -287,6 +292,7 @@ DumpCapsuleStatusVariable (
} else if (EFI_ERROR (Status)) { } else if (EFI_ERROR (Status)) {
continue; continue;
} }
ASSERT (CapsuleResult != NULL); ASSERT (CapsuleResult != NULL);
// //
@ -451,11 +457,11 @@ DumpEsrtData (
Print (L"ESRT - %r\n", Status); Print (L"ESRT - %r\n", Status);
return; return;
} }
DumpEsrt (Esrt); DumpEsrt (Esrt);
Print (L"\n"); Print (L"\n");
} }
/** /**
Dump capsule information from CapsuleHeader Dump capsule information from CapsuleHeader
@ -477,6 +483,7 @@ DumpCapsuleFromBuffer (
if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) { if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
DumpFmpCapsule (CapsuleHeader); DumpFmpCapsule (CapsuleHeader);
} }
if (IsNestedFmpCapsule (CapsuleHeader)) { if (IsNestedFmpCapsule (CapsuleHeader)) {
Print (L"[NestedCapusule]\n"); Print (L"[NestedCapusule]\n");
Print (L"CapsuleHeader:\n"); Print (L"CapsuleHeader:\n");
@ -507,7 +514,7 @@ UpperCaseString (
CHAR16 *Cptr; CHAR16 *Cptr;
for (Cptr = Str; *Cptr != L'\0'; Cptr++) { for (Cptr = Str; *Cptr != L'\0'; Cptr++) {
if (L'a' <= *Cptr && *Cptr <= L'z') { if ((L'a' <= *Cptr) && (*Cptr <= L'z')) {
*Cptr = *Cptr - L'a' + L'A'; *Cptr = *Cptr - L'a' + L'A';
} }
} }
@ -533,6 +540,7 @@ GetSubStringBeforePeriod (
) )
{ {
UINTN Index; UINTN Index;
for (Index = 0; Str[Index] != L'.' && Str[Index] != L'\0'; Index++) { for (Index = 0; Str[Index] != L'.' && Str[Index] != L'\0'; Index++) {
SubStr[Index] = Str[Index]; SubStr[Index] = Str[Index];
} }
@ -559,7 +567,8 @@ PadStrInTail (
{ {
UINTN Index; UINTN Index;
for (Index = 0; StrBuf[Index] != L'\0'; Index++); for (Index = 0; StrBuf[Index] != L'\0'; Index++) {
}
while (PadLen != 0) { while (PadLen != 0) {
StrBuf[Index] = Character; StrBuf[Index] = Character;
@ -591,12 +600,13 @@ SplitFileNameExtension (
UINTN StringLen; UINTN StringLen;
StringLen = StrLen (FileName); StringLen = StrLen (FileName);
for (Index = StringLen; Index > 0 && FileName[Index] != L'.'; Index--); for (Index = StringLen; Index > 0 && FileName[Index] != L'.'; Index--) {
}
// //
// No period exists. No FileName Extension // No period exists. No FileName Extension
// //
if (Index == 0 && FileName[Index] != L'.') { if ((Index == 0) && (FileName[Index] != L'.')) {
FileNameExtension[0] = L'\0'; FileNameExtension[0] = L'\0';
Index = StringLen; Index = StringLen;
} else { } else {
@ -726,7 +736,7 @@ DumpCapsuleFromDisk (
// //
Status = FileHandleFindFirstFile (DirHandle, &FileInfo); Status = FileHandleFindFirstFile (DirHandle, &FileInfo);
do { do {
if (EFI_ERROR (Status) || FileInfo == NULL) { if (EFI_ERROR (Status) || (FileInfo == NULL)) {
Print (L"Get File Info Fail. Status = %r\n", Status); Print (L"Get File Info Fail. Status = %r\n", Status);
goto Done; goto Done;
} }
@ -753,6 +763,7 @@ DumpCapsuleFromDisk (
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto Done; goto Done;
} }
NoFile = FALSE; NoFile = FALSE;
// //
@ -760,7 +771,7 @@ DumpCapsuleFromDisk (
// //
Status = FileHandleFindFirstFile (DirHandle, &FileInfo); Status = FileHandleFindFirstFile (DirHandle, &FileInfo);
do { do {
if (EFI_ERROR (Status) || FileInfo == NULL) { if (EFI_ERROR (Status) || (FileInfo == NULL)) {
Print (L"Get File Info Fail. Status = %r\n", Status); Print (L"Get File Info Fail. Status = %r\n", Status);
goto Done; goto Done;
} }
@ -842,6 +853,7 @@ Done:
FreePool (FileInfoBuffer[Index]); FreePool (FileInfoBuffer[Index]);
} }
} }
FreePool (FileInfoBuffer); FreePool (FileInfoBuffer);
} }
@ -870,11 +882,13 @@ DumpBlockDescriptors (
if (DumpCapsuleInfo) { if (DumpCapsuleInfo) {
Print (L"******************************************************\n"); Print (L"******************************************************\n");
} }
Print (L"Capsule data starts at 0x%08x with size 0x%08x\n", TempBlockPtr->Union.DataBlock, TempBlockPtr->Length); Print (L"Capsule data starts at 0x%08x with size 0x%08x\n", TempBlockPtr->Union.DataBlock, TempBlockPtr->Length);
if (DumpCapsuleInfo) { if (DumpCapsuleInfo) {
Print (L"******************************************************\n"); Print (L"******************************************************\n");
DumpCapsuleFromBuffer ((EFI_CAPSULE_HEADER *)(UINTN)TempBlockPtr->Union.DataBlock); DumpCapsuleFromBuffer ((EFI_CAPSULE_HEADER *)(UINTN)TempBlockPtr->Union.DataBlock);
} }
TempBlockPtr += 1; TempBlockPtr += 1;
} else { } else {
if (TempBlockPtr->Union.ContinuationPointer == (UINTN)NULL) { if (TempBlockPtr->Union.ContinuationPointer == (UINTN)NULL) {
@ -944,10 +958,11 @@ DumpProvisionedCapsule (
(VOID **)&CapsuleDataPtr64, (VOID **)&CapsuleDataPtr64,
NULL NULL
); );
if (EFI_ERROR (Status) || CapsuleDataPtr64 == NULL) { if (EFI_ERROR (Status) || (CapsuleDataPtr64 == NULL)) {
if (Index == 0) { if (Index == 0) {
Print (L"No data.\n"); Print (L"No data.\n");
} }
break; break;
} }
@ -968,7 +983,7 @@ DumpProvisionedCapsule (
(VOID **)&BootNext, (VOID **)&BootNext,
NULL NULL
); );
if (EFI_ERROR (Status) || BootNext == NULL) { if (EFI_ERROR (Status) || (BootNext == NULL)) {
Print (L"Get BootNext Variable Fail. Status = %r\n", Status); Print (L"Get BootNext Variable Fail. Status = %r\n", Status);
} else { } else {
UnicodeSPrint (BootOptionName, sizeof (BootOptionName), L"Boot%04x", *BootNext); UnicodeSPrint (BootOptionName, sizeof (BootOptionName), L"Boot%04x", *BootNext);
@ -1057,11 +1072,13 @@ DumpFmpImageInfo (
do { do {
Print (L"%02x ", CurrentImageInfo->Dependencies->Dependencies[Index2]); Print (L"%02x ", CurrentImageInfo->Dependencies->Dependencies[Index2]);
} while (CurrentImageInfo->Dependencies->Dependencies[Index2++] != EFI_FMP_DEP_END); } while (CurrentImageInfo->Dependencies->Dependencies[Index2++] != EFI_FMP_DEP_END);
Print (L"\n"); Print (L"\n");
} }
} }
} }
} }
// //
// Use DescriptorSize to move ImageInfo Pointer to stay compatible with different ImageInfo version // Use DescriptorSize to move ImageInfo Pointer to stay compatible with different ImageInfo version
// //
@ -1206,6 +1223,7 @@ DumpFmpData (
if (PackageVersionName != NULL) { if (PackageVersionName != NULL) {
FreePool (PackageVersionName); FreePool (PackageVersionName);
} }
FreePool (FmpImageInfoBuf); FreePool (FmpImageInfoBuf);
// //
@ -1237,6 +1255,7 @@ DumpFmpData (
} }
} }
} }
Print (L"\n"); Print (L"\n");
EXIT: EXIT:
@ -1270,8 +1289,10 @@ IsThisFmpImageInfo (
if (CompareGuid (&CurrentImageInfo->ImageTypeId, ImageTypeId)) { if (CompareGuid (&CurrentImageInfo->ImageTypeId, ImageTypeId)) {
return TRUE; return TRUE;
} }
CurrentImageInfo = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)((UINT8 *)CurrentImageInfo + DescriptorSize); CurrentImageInfo = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)((UINT8 *)CurrentImageInfo + DescriptorSize);
} }
return FALSE; return FALSE;
} }
@ -1374,11 +1395,13 @@ FindFmpFromImageTypeId (
if (IsThisFmpImageInfo (FmpImageInfoBuf, FmpImageInfoCount, DescriptorSize, ImageTypeId)) { if (IsThisFmpImageInfo (FmpImageInfoBuf, FmpImageInfoCount, DescriptorSize, ImageTypeId)) {
TargetFmp = Fmp; TargetFmp = Fmp;
} }
FreePool (FmpImageInfoBuf); FreePool (FmpImageInfoBuf);
if (TargetFmp != NULL) { if (TargetFmp != NULL) {
break; break;
} }
} }
FreePool (HandleBuffer); FreePool (HandleBuffer);
return TargetFmp; return TargetFmp;
} }

View File

@ -8,7 +8,9 @@
#include "CapsuleApp.h" #include "CapsuleApp.h"
EFI_GUID mCapsuleOnDiskBootOptionGuid = { 0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } }; EFI_GUID mCapsuleOnDiskBootOptionGuid = {
0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 }
};
/** /**
Get file name from file path. Get file name from file path.
@ -83,12 +85,14 @@ IsEfiSysPartitionDevicePath (
while (!IsDevicePathEnd (TempDevicePath)) { while (!IsDevicePathEnd (TempDevicePath)) {
if ((DevicePathType (TempDevicePath) == MEDIA_DEVICE_PATH) && if ((DevicePathType (TempDevicePath) == MEDIA_DEVICE_PATH) &&
(DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP)) { (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP))
{
Hd = (HARDDRIVE_DEVICE_PATH *)TempDevicePath; Hd = (HARDDRIVE_DEVICE_PATH *)TempDevicePath;
if (Hd->MBRType == MBR_TYPE_EFI_PARTITION_TABLE_HEADER) { if (Hd->MBRType == MBR_TYPE_EFI_PARTITION_TABLE_HEADER) {
break; break;
} }
} }
TempDevicePath = NextDevicePathNode (TempDevicePath); TempDevicePath = NextDevicePathNode (TempDevicePath);
} }
@ -123,7 +127,7 @@ DumpAllEfiSysPartition (
ShellProtocol = GetShellProtocol (); ShellProtocol = GetShellProtocol ();
if (ShellProtocol == NULL) { if (ShellProtocol == NULL) {
Print (L"Get Shell Protocol Fail\n");; Print (L"Get Shell Protocol Fail\n");
return; return;
} }
@ -176,7 +180,8 @@ IsCapsuleProvisioned (
&OsIndication &OsIndication
); );
if (!EFI_ERROR (Status) && if (!EFI_ERROR (Status) &&
(OsIndication & EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED) != 0) { ((OsIndication & EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED) != 0))
{
return TRUE; return TRUE;
} }
@ -261,12 +266,14 @@ GetEfiSysPartitionFromDevPath (
TempDevicePath = DevicePath; TempDevicePath = DevicePath;
while (!IsDevicePathEnd (TempDevicePath)) { while (!IsDevicePathEnd (TempDevicePath)) {
if ((DevicePathType (TempDevicePath) == MEDIA_DEVICE_PATH) && if ((DevicePathType (TempDevicePath) == MEDIA_DEVICE_PATH) &&
(DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP)) { (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP))
{
Hd = (HARDDRIVE_DEVICE_PATH *)TempDevicePath; Hd = (HARDDRIVE_DEVICE_PATH *)TempDevicePath;
if (Hd->MBRType == MBR_TYPE_EFI_PARTITION_TABLE_HEADER) { if (Hd->MBRType == MBR_TYPE_EFI_PARTITION_TABLE_HEADER) {
break; break;
} }
} }
TempDevicePath = NextDevicePathNode (TempDevicePath); TempDevicePath = NextDevicePathNode (TempDevicePath);
} }
@ -344,6 +351,7 @@ GetEfiSysPartitionFromBootOptionFilePath (
DEBUG ((DEBUG_INFO, "Full device path %s\n", DevicePathStr)); DEBUG ((DEBUG_INFO, "Full device path %s\n", DevicePathStr));
FreePool (DevicePathStr); FreePool (DevicePathStr);
} }
DEBUG_CODE_END (); DEBUG_CODE_END ();
Status = GetEfiSysPartitionFromDevPath (CurFullPath, &FsFullPath, Fs); Status = GetEfiSysPartitionFromDevPath (CurFullPath, &FsFullPath, Fs);
@ -396,7 +404,7 @@ GetUpdateFileSystem (
ShellProtocol = GetShellProtocol (); ShellProtocol = GetShellProtocol ();
if (ShellProtocol == NULL) { if (ShellProtocol == NULL) {
Print (L"Get Shell Protocol Fail\n");; Print (L"Get Shell Protocol Fail\n");
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -404,14 +412,14 @@ GetUpdateFileSystem (
// 1. If Fs is not assigned and there are capsule provisioned before, // 1. If Fs is not assigned and there are capsule provisioned before,
// Get EFI system partition from BootNext. // Get EFI system partition from BootNext.
// //
if (IsCapsuleProvisioned () && Map == NULL) { if (IsCapsuleProvisioned () && (Map == NULL)) {
Status = GetVariable2 ( Status = GetVariable2 (
L"BootNext", L"BootNext",
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,
(VOID **)&BootNextData, (VOID **)&BootNextData,
NULL NULL
); );
if (EFI_ERROR (Status) || BootNextData == NULL) { if (EFI_ERROR (Status) || (BootNextData == NULL)) {
Print (L"Get Boot Next Data Fail. Status = %r\n", Status); Print (L"Get Boot Next Data Fail. Status = %r\n", Status);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} else { } else {
@ -449,8 +457,9 @@ GetUpdateFileSystem (
// //
BootOptionBuffer = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); BootOptionBuffer = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
if ((BootOptionBuffer == NULL) || if ((BootOptionBuffer == NULL) ||
(BootOptionCount == 0 && Map == NULL) ((BootOptionCount == 0) && (Map == NULL))
) { )
{
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -463,8 +472,9 @@ GetUpdateFileSystem (
// //
// Skip inactive or legacy boot options // Skip inactive or legacy boot options
// //
if ((BootOptionBuffer[Index].Attributes & LOAD_OPTION_ACTIVE) == 0 || if (((BootOptionBuffer[Index].Attributes & LOAD_OPTION_ACTIVE) == 0) ||
DevicePathType (DevicePath) == BBS_DEVICE_PATH) { (DevicePathType (DevicePath) == BBS_DEVICE_PATH))
{
continue; continue;
} }
@ -478,6 +488,7 @@ GetUpdateFileSystem (
} else { } else {
DEBUG ((DEBUG_INFO, "DevicePathToStr failed\n")); DEBUG ((DEBUG_INFO, "DevicePathToStr failed\n"));
} }
DEBUG_CODE_END (); DEBUG_CODE_END ();
Status = GetEfiSysPartitionFromBootOptionFilePath (DevicePath, &FullPath, Fs); Status = GetEfiSysPartitionFromBootOptionFilePath (DevicePath, &FullPath, Fs);
@ -512,6 +523,7 @@ GetUpdateFileSystem (
Print (L"Error: Cannot get EFI system partition from '%s' - %r\n", Map, Status); Print (L"Error: Cannot get EFI system partition from '%s' - %r\n", Map, Status);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
Print (L"Warning: Cannot find Boot Option on '%s'!\n", Map); Print (L"Warning: Cannot find Boot Option on '%s'!\n", Map);
} else { } else {
Status = GetEfiSysPartition (&DevicePath, Fs); Status = GetEfiSysPartition (&DevicePath, Fs);
@ -533,7 +545,8 @@ GetUpdateFileSystem (
sizeof (EFI_GUID) sizeof (EFI_GUID)
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1); { Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN)-1);
{
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
*UpdateBootNext = TRUE; *UpdateBootNext = TRUE;
*BootNext = (UINT16)NewOption.OptionNumber; *BootNext = (UINT16)NewOption.OptionNumber;
@ -604,6 +617,7 @@ WriteUpdateFile (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
} }
Status = Root->Open (Root, &DirHandle, EFI_CAPSULE_FILE_DIRECTORY, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0); Status = Root->Open (Root, &DirHandle, EFI_CAPSULE_FILE_DIRECTORY, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
Status = Root->Open (Root, &DirHandle, EFI_CAPSULE_FILE_DIRECTORY, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, EFI_FILE_DIRECTORY); Status = Root->Open (Root, &DirHandle, EFI_CAPSULE_FILE_DIRECTORY, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, EFI_FILE_DIRECTORY);
@ -699,12 +713,13 @@ SetCapsuleStatusVariable (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
OsIndication = 0; OsIndication = 0;
} }
if (SetCap) { if (SetCap) {
OsIndication |= ((UINT64)EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED); OsIndication |= ((UINT64)EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED);
} } else {
else {
OsIndication &= ~((UINT64)EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED); OsIndication &= ~((UINT64)EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED);
} }
Status = gRT->SetVariable ( Status = gRT->SetVariable (
L"OsIndications", L"OsIndications",
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,

View File

@ -14,7 +14,6 @@
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h> #include <Library/UefiLib.h>
#include <Protocol/UnicodeCollation.h> #include <Protocol/UnicodeCollation.h>
#include <Protocol/PiPcd.h> #include <Protocol/PiPcd.h>
#include <Protocol/Pcd.h> #include <Protocol/Pcd.h>
@ -23,7 +22,6 @@
#include <Protocol/ShellParameters.h> #include <Protocol/ShellParameters.h>
#include <Protocol/Shell.h> #include <Protocol/Shell.h>
// //
// String token ID of help message text. // String token ID of help message text.
// Shell supports to find help message in the resource section of an application image if // Shell supports to find help message in the resource section of an application image if
@ -50,7 +48,6 @@ static CONST CHAR8 mHex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '
static UINTN Argc; static UINTN Argc;
static CHAR16 **Argv; static CHAR16 **Argv;
/** /**
This function parse application ARG. This function parse application ARG.
@ -162,7 +159,6 @@ DumpHex (
} }
} }
/** /**
Safely append with automatic string resizing given length of Destination and Safely append with automatic string resizing given length of Destination and
desired length of copy from Source. desired length of copy from Source.
@ -222,7 +218,7 @@ InternalStrnCatGrow (
// //
// allow for un-initialized pointers, based on size being 0 // allow for un-initialized pointers, based on size being 0
// //
if (CurrentSize != NULL && *CurrentSize == 0) { if ((CurrentSize != NULL) && (*CurrentSize == 0)) {
*Destination = NULL; *Destination = NULL;
} }
@ -246,6 +242,7 @@ InternalStrnCatGrow (
while (NewSize < (DestinationStartSize + (SourceLen*sizeof (CHAR16)))) { while (NewSize < (DestinationStartSize + (SourceLen*sizeof (CHAR16)))) {
NewSize += 2 * SourceLen * sizeof (CHAR16); NewSize += 2 * SourceLen * sizeof (CHAR16);
} }
*Destination = ReallocatePool (*CurrentSize, NewSize, *Destination); *Destination = ReallocatePool (*CurrentSize, NewSize, *Destination);
*CurrentSize = NewSize; *CurrentSize = NewSize;
} }
@ -363,6 +360,7 @@ DumpPcdInfo (
} else { } else {
Uint8 = mPiPcd->Get8 (TokenSpace, TokenNumber); Uint8 = mPiPcd->Get8 (TokenSpace, TokenNumber);
} }
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint8); Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint8);
break; break;
case EFI_PCD_TYPE_16: case EFI_PCD_TYPE_16:
@ -371,6 +369,7 @@ DumpPcdInfo (
} else { } else {
Uint16 = mPiPcd->Get16 (TokenSpace, TokenNumber); Uint16 = mPiPcd->Get16 (TokenSpace, TokenNumber);
} }
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint16); Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint16);
break; break;
case EFI_PCD_TYPE_32: case EFI_PCD_TYPE_32:
@ -379,6 +378,7 @@ DumpPcdInfo (
} else { } else {
Uint32 = mPiPcd->Get32 (TokenSpace, TokenNumber); Uint32 = mPiPcd->Get32 (TokenSpace, TokenNumber);
} }
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint32); Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint32);
break; break;
case EFI_PCD_TYPE_64: case EFI_PCD_TYPE_64:
@ -387,6 +387,7 @@ DumpPcdInfo (
} else { } else {
Uint64 = mPiPcd->Get64 (TokenSpace, TokenNumber); Uint64 = mPiPcd->Get64 (TokenSpace, TokenNumber);
} }
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%lx\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint64); Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%lx\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint64);
break; break;
case EFI_PCD_TYPE_BOOL: case EFI_PCD_TYPE_BOOL:
@ -395,6 +396,7 @@ DumpPcdInfo (
} else { } else {
Boolean = mPiPcd->GetBool (TokenSpace, TokenNumber); Boolean = mPiPcd->GetBool (TokenSpace, TokenNumber);
} }
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = %a\n", TokenNumber, RetString, PcdInfo->PcdSize, Boolean ? "TRUE" : "FALSE"); Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = %a\n", TokenNumber, RetString, PcdInfo->PcdSize, Boolean ? "TRUE" : "FALSE");
break; break;
case EFI_PCD_TYPE_PTR: case EFI_PCD_TYPE_PTR:
@ -403,6 +405,7 @@ DumpPcdInfo (
} else { } else {
PcdData = mPiPcd->GetPtr (TokenSpace, TokenNumber); PcdData = mPiPcd->GetPtr (TokenSpace, TokenNumber);
} }
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize); Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize);
DumpHex (2, 0, PcdInfo->PcdSize, PcdData); DumpHex (2, 0, PcdInfo->PcdSize, PcdData);
break; break;
@ -413,6 +416,7 @@ DumpPcdInfo (
if (RetString != NULL) { if (RetString != NULL) {
FreePool (RetString); FreePool (RetString);
} }
Print (L"\n"); Print (L"\n");
} }
@ -451,7 +455,7 @@ ProcessPcd (
TokenNumber = 0; TokenNumber = 0;
do { do {
Status = mPiPcd->GetNextToken (TokenSpace, &TokenNumber); Status = mPiPcd->GetNextToken (TokenSpace, &TokenNumber);
if (!EFI_ERROR (Status) && TokenNumber != 0) { if (!EFI_ERROR (Status) && (TokenNumber != 0)) {
if (TokenSpace == NULL) { if (TokenSpace == NULL) {
// //
// PCD in default Token Space. // PCD in default Token Space.
@ -460,10 +464,12 @@ ProcessPcd (
} else { } else {
mPiPcdInfo->GetInfo (TokenSpace, TokenNumber, &PcdInfo); mPiPcdInfo->GetInfo (TokenSpace, TokenNumber, &PcdInfo);
} }
if (InputPcdName != NULL) { if (InputPcdName != NULL) {
if (PcdInfo.PcdName == NULL) { if (PcdInfo.PcdName == NULL) {
continue; continue;
} }
PcdNameSize = AsciiStrSize (PcdInfo.PcdName) * sizeof (CHAR16); PcdNameSize = AsciiStrSize (PcdInfo.PcdName) * sizeof (CHAR16);
if (mTempPcdNameBuffer == NULL) { if (mTempPcdNameBuffer == NULL) {
mTempPcdNameBufferSize = PcdNameSize; mTempPcdNameBufferSize = PcdNameSize;
@ -472,15 +478,18 @@ ProcessPcd (
mTempPcdNameBuffer = ReallocatePool (mTempPcdNameBufferSize, PcdNameSize, mTempPcdNameBuffer); mTempPcdNameBuffer = ReallocatePool (mTempPcdNameBufferSize, PcdNameSize, mTempPcdNameBuffer);
mTempPcdNameBufferSize = PcdNameSize; mTempPcdNameBufferSize = PcdNameSize;
} }
if (mTempPcdNameBuffer == NULL) { if (mTempPcdNameBuffer == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
AsciiStrToUnicodeStrS (PcdInfo.PcdName, mTempPcdNameBuffer, mTempPcdNameBufferSize / sizeof (CHAR16)); AsciiStrToUnicodeStrS (PcdInfo.PcdName, mTempPcdNameBuffer, mTempPcdNameBufferSize / sizeof (CHAR16));
// //
// Compare the input PCD name with the PCD name in PCD database. // Compare the input PCD name with the PCD name in PCD database.
// //
if ((StrStr (mTempPcdNameBuffer, InputPcdName) != NULL) || if ((StrStr (mTempPcdNameBuffer, InputPcdName) != NULL) ||
(mUnicodeCollation != NULL && mUnicodeCollation->MetaiMatch (mUnicodeCollation, mTempPcdNameBuffer, InputPcdName))) { ((mUnicodeCollation != NULL) && mUnicodeCollation->MetaiMatch (mUnicodeCollation, mTempPcdNameBuffer, InputPcdName)))
{
// //
// Found matched PCD. // Found matched PCD.
// //
@ -503,6 +512,7 @@ ProcessPcd (
Print (L"%EError. %NNo matching PCD found: %s.\n", InputPcdName); Print (L"%EError. %NNo matching PCD found: %s.\n", InputPcdName);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -607,4 +617,3 @@ DumpDynPcdMain (
return Status; return Status;
} }

View File

@ -196,7 +196,9 @@ GetShortPdbFileName (
AsciiStrnCpyS (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1, " ", 1); AsciiStrnCpyS (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1, " ", 1);
} else { } else {
StartIndex = 0; StartIndex = 0;
for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++); for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++) {
}
for (IndexPdb = 0; PdbFileName[IndexPdb] != 0; IndexPdb++) { for (IndexPdb = 0; PdbFileName[IndexPdb] != 0; IndexPdb++) {
if ((PdbFileName[IndexPdb] == '\\') || (PdbFileName[IndexPdb] == '/')) { if ((PdbFileName[IndexPdb] == '\\') || (PdbFileName[IndexPdb] == '/')) {
StartIndex = IndexPdb + 1; StartIndex = IndexPdb + 1;
@ -268,6 +270,7 @@ GetDriverNameString (
if (StrLen (NameString) > PROFILE_NAME_STRING_LENGTH) { if (StrLen (NameString) > PROFILE_NAME_STRING_LENGTH) {
NameString[PROFILE_NAME_STRING_LENGTH] = 0; NameString[PROFILE_NAME_STRING_LENGTH] = 0;
} }
UnicodeStrToAsciiStrS (NameString, mNameString, sizeof (mNameString)); UnicodeStrToAsciiStrS (NameString, mNameString, sizeof (mNameString));
FreePool (NameString); FreePool (NameString);
return mNameString; return mNameString;
@ -346,15 +349,18 @@ ProfileActionToStr (
if ((UINTN)(UINT32)Action < ActionStringCount) { if ((UINTN)(UINT32)Action < ActionStringCount) {
return ActionString[Action]; return ActionString[Action];
} }
for (Index = 0; Index < ARRAY_SIZE (mExtActionString); Index++) { for (Index = 0; Index < ARRAY_SIZE (mExtActionString); Index++) {
if (mExtActionString[Index].Action == Action) { if (mExtActionString[Index].Action == Action) {
return mExtActionString[Index].String; return mExtActionString[Index].String;
} }
} }
if ((Action & MEMORY_PROFILE_ACTION_USER_DEFINED_MASK) != 0) { if ((Action & MEMORY_PROFILE_ACTION_USER_DEFINED_MASK) != 0) {
if (UserDefinedActionString != NULL) { if (UserDefinedActionString != NULL) {
return UserDefinedActionString; return UserDefinedActionString;
} }
AsciiSPrint (mUserDefinedActionString, sizeof (mUserDefinedActionString), "UserDefined-0x%08x", Action); AsciiSPrint (mUserDefinedActionString, sizeof (mUserDefinedActionString), "UserDefined-0x%08x", Action);
return mUserDefinedActionString; return mUserDefinedActionString;
} }
@ -434,6 +440,7 @@ DumpMemoryProfileDriverInfo (
if (DriverInfo->Header.Signature != MEMORY_PROFILE_DRIVER_INFO_SIGNATURE) { if (DriverInfo->Header.Signature != MEMORY_PROFILE_DRIVER_INFO_SIGNATURE) {
return NULL; return NULL;
} }
Print (L" MEMORY_PROFILE_DRIVER_INFO (0x%x)\n", DriverIndex); Print (L" MEMORY_PROFILE_DRIVER_INFO (0x%x)\n", DriverIndex);
Print (L" Signature - 0x%08x\n", DriverInfo->Header.Signature); Print (L" Signature - 0x%08x\n", DriverInfo->Header.Signature);
Print (L" Length - 0x%04x\n", DriverInfo->Header.Length); Print (L" Length - 0x%04x\n", DriverInfo->Header.Length);
@ -443,6 +450,7 @@ DumpMemoryProfileDriverInfo (
if (DriverInfo->PdbStringOffset != 0) { if (DriverInfo->PdbStringOffset != 0) {
Print (L" Pdb - %a\n", (CHAR8 *)((UINTN)DriverInfo + DriverInfo->PdbStringOffset)); Print (L" Pdb - %a\n", (CHAR8 *)((UINTN)DriverInfo + DriverInfo->PdbStringOffset));
} }
Print (L" ImageBase - 0x%016lx\n", DriverInfo->ImageBase); Print (L" ImageBase - 0x%016lx\n", DriverInfo->ImageBase);
Print (L" ImageSize - 0x%016lx\n", DriverInfo->ImageSize); Print (L" ImageSize - 0x%016lx\n", DriverInfo->ImageSize);
Print (L" EntryPoint - 0x%016lx\n", DriverInfo->EntryPoint); Print (L" EntryPoint - 0x%016lx\n", DriverInfo->EntryPoint);
@ -452,11 +460,13 @@ DumpMemoryProfileDriverInfo (
Print (L" PeakUsage - 0x%016lx\n", DriverInfo->PeakUsage); Print (L" PeakUsage - 0x%016lx\n", DriverInfo->PeakUsage);
for (TypeIndex = 0; TypeIndex < sizeof (DriverInfo->CurrentUsageByType) / sizeof (DriverInfo->CurrentUsageByType[0]); TypeIndex++) { for (TypeIndex = 0; TypeIndex < sizeof (DriverInfo->CurrentUsageByType) / sizeof (DriverInfo->CurrentUsageByType[0]); TypeIndex++) {
if ((DriverInfo->CurrentUsageByType[TypeIndex] != 0) || if ((DriverInfo->CurrentUsageByType[TypeIndex] != 0) ||
(DriverInfo->PeakUsageByType[TypeIndex] != 0)) { (DriverInfo->PeakUsageByType[TypeIndex] != 0))
{
Print (L" CurrentUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->CurrentUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]); Print (L" CurrentUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->CurrentUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);
Print (L" PeakUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->PeakUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]); Print (L" PeakUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->PeakUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);
} }
} }
Print (L" AllocRecordCount - 0x%08x\n", DriverInfo->AllocRecordCount); Print (L" AllocRecordCount - 0x%08x\n", DriverInfo->AllocRecordCount);
AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *)((UINTN)DriverInfo + DriverInfo->Header.Length); AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *)((UINTN)DriverInfo + DriverInfo->Header.Length);
@ -466,6 +476,7 @@ DumpMemoryProfileDriverInfo (
return NULL; return NULL;
} }
} }
return (MEMORY_PROFILE_DRIVER_INFO *)AllocInfo; return (MEMORY_PROFILE_DRIVER_INFO *)AllocInfo;
} }
@ -492,6 +503,7 @@ DumpMemoryProfileContext (
if (Context->Header.Signature != MEMORY_PROFILE_CONTEXT_SIGNATURE) { if (Context->Header.Signature != MEMORY_PROFILE_CONTEXT_SIGNATURE) {
return NULL; return NULL;
} }
Print (L"MEMORY_PROFILE_CONTEXT\n"); Print (L"MEMORY_PROFILE_CONTEXT\n");
Print (L" Signature - 0x%08x\n", Context->Header.Signature); Print (L" Signature - 0x%08x\n", Context->Header.Signature);
Print (L" Length - 0x%04x\n", Context->Header.Length); Print (L" Length - 0x%04x\n", Context->Header.Length);
@ -500,11 +512,13 @@ DumpMemoryProfileContext (
Print (L" PeakTotalUsage - 0x%016lx\n", Context->PeakTotalUsage); Print (L" PeakTotalUsage - 0x%016lx\n", Context->PeakTotalUsage);
for (TypeIndex = 0; TypeIndex < sizeof (Context->CurrentTotalUsageByType) / sizeof (Context->CurrentTotalUsageByType[0]); TypeIndex++) { for (TypeIndex = 0; TypeIndex < sizeof (Context->CurrentTotalUsageByType) / sizeof (Context->CurrentTotalUsageByType[0]); TypeIndex++) {
if ((Context->CurrentTotalUsageByType[TypeIndex] != 0) || if ((Context->CurrentTotalUsageByType[TypeIndex] != 0) ||
(Context->PeakTotalUsageByType[TypeIndex] != 0)) { (Context->PeakTotalUsageByType[TypeIndex] != 0))
{
Print (L" CurrentTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->CurrentTotalUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]); Print (L" CurrentTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->CurrentTotalUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);
Print (L" PeakTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->PeakTotalUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]); Print (L" PeakTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->PeakTotalUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);
} }
} }
Print (L" TotalImageSize - 0x%016lx\n", Context->TotalImageSize); Print (L" TotalImageSize - 0x%016lx\n", Context->TotalImageSize);
Print (L" ImageCount - 0x%08x\n", Context->ImageCount); Print (L" ImageCount - 0x%08x\n", Context->ImageCount);
Print (L" SequenceCount - 0x%08x\n", Context->SequenceCount); Print (L" SequenceCount - 0x%08x\n", Context->SequenceCount);
@ -516,6 +530,7 @@ DumpMemoryProfileContext (
return NULL; return NULL;
} }
} }
return (VOID *)DriverInfo; return (VOID *)DriverInfo;
} }
@ -537,6 +552,7 @@ DumpMemoryProfileDescriptor (
if (Descriptor->Header.Signature != MEMORY_PROFILE_DESCRIPTOR_SIGNATURE) { if (Descriptor->Header.Signature != MEMORY_PROFILE_DESCRIPTOR_SIGNATURE) {
return NULL; return NULL;
} }
Print (L" MEMORY_PROFILE_DESCRIPTOR (0x%x)\n", DescriptorIndex); Print (L" MEMORY_PROFILE_DESCRIPTOR (0x%x)\n", DescriptorIndex);
Print (L" Signature - 0x%08x\n", Descriptor->Header.Signature); Print (L" Signature - 0x%08x\n", Descriptor->Header.Signature);
Print (L" Length - 0x%04x\n", Descriptor->Header.Length); Print (L" Length - 0x%04x\n", Descriptor->Header.Length);
@ -566,6 +582,7 @@ DumpMemoryProfileFreeMemory (
if (FreeMemory->Header.Signature != MEMORY_PROFILE_FREE_MEMORY_SIGNATURE) { if (FreeMemory->Header.Signature != MEMORY_PROFILE_FREE_MEMORY_SIGNATURE) {
return NULL; return NULL;
} }
Print (L"MEMORY_PROFILE_FREE_MEMORY\n"); Print (L"MEMORY_PROFILE_FREE_MEMORY\n");
Print (L" Signature - 0x%08x\n", FreeMemory->Header.Signature); Print (L" Signature - 0x%08x\n", FreeMemory->Header.Signature);
Print (L" Length - 0x%04x\n", FreeMemory->Header.Length); Print (L" Length - 0x%04x\n", FreeMemory->Header.Length);
@ -603,6 +620,7 @@ DumpMemoryProfileMemoryRange (
if (MemoryRange->Header.Signature != MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE) { if (MemoryRange->Header.Signature != MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE) {
return NULL; return NULL;
} }
Print (L"MEMORY_PROFILE_MEMORY_RANGE\n"); Print (L"MEMORY_PROFILE_MEMORY_RANGE\n");
Print (L" Signature - 0x%08x\n", MemoryRange->Header.Signature); Print (L" Signature - 0x%08x\n", MemoryRange->Header.Signature);
Print (L" Length - 0x%04x\n", MemoryRange->Header.Length); Print (L" Length - 0x%04x\n", MemoryRange->Header.Length);
@ -649,10 +667,12 @@ ScanMemoryProfileBySignature (
// //
return (VOID *)CommonHeader; return (VOID *)CommonHeader;
} }
if (CommonHeader->Length == 0) { if (CommonHeader->Length == 0) {
ASSERT (FALSE); ASSERT (FALSE);
return NULL; return NULL;
} }
CommonHeader = (MEMORY_PROFILE_COMMON_HEADER *)((UINTN)CommonHeader + CommonHeader->Length); CommonHeader = (MEMORY_PROFILE_COMMON_HEADER *)((UINTN)CommonHeader + CommonHeader->Length);
} }
@ -719,7 +739,8 @@ GetAllocSummaryInfoByCallerAddress (
for (AllocSummaryLink = AllocSummaryInfoList->ForwardLink; for (AllocSummaryLink = AllocSummaryInfoList->ForwardLink;
AllocSummaryLink != AllocSummaryInfoList; AllocSummaryLink != AllocSummaryInfoList;
AllocSummaryLink = AllocSummaryLink->ForwardLink) { AllocSummaryLink = AllocSummaryLink->ForwardLink)
{
AllocSummaryInfoData = CR ( AllocSummaryInfoData = CR (
AllocSummaryLink, AllocSummaryLink,
MEMORY_PROFILE_ALLOC_SUMMARY_INFO_DATA, MEMORY_PROFILE_ALLOC_SUMMARY_INFO_DATA,
@ -731,6 +752,7 @@ GetAllocSummaryInfoByCallerAddress (
return AllocSummaryInfoData; return AllocSummaryInfoData;
} }
} }
return NULL; return NULL;
} }
@ -776,10 +798,12 @@ CreateAllocSummaryInfo (
} else { } else {
AllocSummaryInfo->ActionString = NULL; AllocSummaryInfo->ActionString = NULL;
} }
AllocSummaryInfo->AllocateCount = 0; AllocSummaryInfo->AllocateCount = 0;
AllocSummaryInfo->TotalSize = 0; AllocSummaryInfo->TotalSize = 0;
InsertTailList (DriverSummaryInfoData->AllocSummaryInfoList, &AllocSummaryInfoData->Link); InsertTailList (DriverSummaryInfoData->AllocSummaryInfoList, &AllocSummaryInfoData->Link);
} }
AllocSummaryInfo = &AllocSummaryInfoData->AllocSummaryInfo; AllocSummaryInfo = &AllocSummaryInfoData->AllocSummaryInfo;
AllocSummaryInfo->AllocateCount++; AllocSummaryInfo->AllocateCount++;
AllocSummaryInfo->TotalSize += AllocInfo->Size; AllocSummaryInfo->TotalSize += AllocInfo->Size;
@ -815,6 +839,7 @@ CreateDriverSummaryInfo (
if (DriverSummaryInfoData == NULL) { if (DriverSummaryInfoData == NULL) {
return NULL; return NULL;
} }
DriverSummaryInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE; DriverSummaryInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
DriverSummaryInfoData->DriverInfo = DriverInfo; DriverSummaryInfoData->DriverInfo = DriverInfo;
DriverSummaryInfoData->AllocSummaryInfoList = (LIST_ENTRY *)(DriverSummaryInfoData + 1); DriverSummaryInfoData->AllocSummaryInfoList = (LIST_ENTRY *)(DriverSummaryInfoData + 1);
@ -828,6 +853,7 @@ CreateDriverSummaryInfo (
return NULL; return NULL;
} }
} }
return (MEMORY_PROFILE_DRIVER_INFO *)AllocInfo; return (MEMORY_PROFILE_DRIVER_INFO *)AllocInfo;
} }
@ -903,7 +929,8 @@ DumpContextSummaryData (
DriverSummaryInfoList = ContextSummaryData->DriverSummaryInfoList; DriverSummaryInfoList = ContextSummaryData->DriverSummaryInfoList;
for (DriverSummaryLink = DriverSummaryInfoList->ForwardLink; for (DriverSummaryLink = DriverSummaryInfoList->ForwardLink;
DriverSummaryLink != DriverSummaryInfoList; DriverSummaryLink != DriverSummaryInfoList;
DriverSummaryLink = DriverSummaryLink->ForwardLink) { DriverSummaryLink = DriverSummaryLink->ForwardLink)
{
DriverSummaryInfoData = CR ( DriverSummaryInfoData = CR (
DriverSummaryLink, DriverSummaryLink,
MEMORY_PROFILE_DRIVER_SUMMARY_INFO_DATA, MEMORY_PROFILE_DRIVER_SUMMARY_INFO_DATA,
@ -924,13 +951,15 @@ DumpContextSummaryData (
} else { } else {
Print (L"\n"); Print (L"\n");
} }
Print (L"Caller List:\n"); Print (L"Caller List:\n");
Print (L" Count Size RVA Action\n"); Print (L" Count Size RVA Action\n");
Print (L"========== ================== ================== (================================)\n"); Print (L"========== ================== ================== (================================)\n");
AllocSummaryInfoList = DriverSummaryInfoData->AllocSummaryInfoList; AllocSummaryInfoList = DriverSummaryInfoData->AllocSummaryInfoList;
for (AllocSummaryLink = AllocSummaryInfoList->ForwardLink; for (AllocSummaryLink = AllocSummaryInfoList->ForwardLink;
AllocSummaryLink != AllocSummaryInfoList; AllocSummaryLink != AllocSummaryInfoList;
AllocSummaryLink = AllocSummaryLink->ForwardLink) { AllocSummaryLink = AllocSummaryLink->ForwardLink)
{
AllocSummaryInfoData = CR ( AllocSummaryInfoData = CR (
AllocSummaryLink, AllocSummaryLink,
MEMORY_PROFILE_ALLOC_SUMMARY_INFO_DATA, MEMORY_PROFILE_ALLOC_SUMMARY_INFO_DATA,
@ -939,7 +968,8 @@ DumpContextSummaryData (
); );
AllocSummaryInfo = &AllocSummaryInfoData->AllocSummaryInfo; AllocSummaryInfo = &AllocSummaryInfoData->AllocSummaryInfo;
Print(L"0x%08x 0x%016lx <== 0x%016lx", Print (
L"0x%08x 0x%016lx <== 0x%016lx",
AllocSummaryInfo->AllocateCount, AllocSummaryInfo->AllocateCount,
AllocSummaryInfo->TotalSize, AllocSummaryInfo->TotalSize,
AllocSummaryInfo->CallerAddress - DriverInfo->ImageBase AllocSummaryInfo->CallerAddress - DriverInfo->ImageBase
@ -947,6 +977,7 @@ DumpContextSummaryData (
Print (L" (%a)\n", ProfileActionToStr (AllocSummaryInfo->Action, AllocSummaryInfo->ActionString, IsForSmm)); Print (L" (%a)\n", ProfileActionToStr (AllocSummaryInfo->Action, AllocSummaryInfo->ActionString, IsForSmm));
} }
} }
return; return;
} }
@ -975,7 +1006,8 @@ DestroyContextSummaryData (
DriverSummaryInfoList = ContextSummaryData->DriverSummaryInfoList; DriverSummaryInfoList = ContextSummaryData->DriverSummaryInfoList;
for (DriverSummaryLink = DriverSummaryInfoList->ForwardLink; for (DriverSummaryLink = DriverSummaryInfoList->ForwardLink;
DriverSummaryLink != DriverSummaryInfoList; DriverSummaryLink != DriverSummaryInfoList;
) { )
{
DriverSummaryInfoData = CR ( DriverSummaryInfoData = CR (
DriverSummaryLink, DriverSummaryLink,
MEMORY_PROFILE_DRIVER_SUMMARY_INFO_DATA, MEMORY_PROFILE_DRIVER_SUMMARY_INFO_DATA,
@ -987,7 +1019,8 @@ DestroyContextSummaryData (
AllocSummaryInfoList = DriverSummaryInfoData->AllocSummaryInfoList; AllocSummaryInfoList = DriverSummaryInfoData->AllocSummaryInfoList;
for (AllocSummaryLink = AllocSummaryInfoList->ForwardLink; for (AllocSummaryLink = AllocSummaryInfoList->ForwardLink;
AllocSummaryLink != AllocSummaryInfoList; AllocSummaryLink != AllocSummaryInfoList;
) { )
{
AllocSummaryInfoData = CR ( AllocSummaryInfoData = CR (
AllocSummaryLink, AllocSummaryLink,
MEMORY_PROFILE_ALLOC_SUMMARY_INFO_DATA, MEMORY_PROFILE_ALLOC_SUMMARY_INFO_DATA,
@ -1003,6 +1036,7 @@ DestroyContextSummaryData (
RemoveEntryList (&DriverSummaryInfoData->Link); RemoveEntryList (&DriverSummaryInfoData->Link);
FreePool (DriverSummaryInfoData); FreePool (DriverSummaryInfoData);
} }
return; return;
} }
@ -1069,7 +1103,6 @@ GetUefiMemoryProfileData (
goto Done; goto Done;
} }
Print (L"UefiMemoryProfileSize - 0x%x\n", Size); Print (L"UefiMemoryProfileSize - 0x%x\n", Size);
Print (L"======= UefiMemoryProfile begin =======\n"); Print (L"======= UefiMemoryProfile begin =======\n");
DumpMemoryProfile ((PHYSICAL_ADDRESS)(UINTN)Data, Size, FALSE); DumpMemoryProfile ((PHYSICAL_ADDRESS)(UINTN)Data, Size, FALSE);
@ -1142,15 +1175,29 @@ GetSmramProfileData (
MinimalSizeNeeded = sizeof (EFI_GUID) + MinimalSizeNeeded = sizeof (EFI_GUID) +
sizeof (UINTN) + sizeof (UINTN) +
MAX (sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO), MAX (
MAX (sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET), sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO),
sizeof (SMRAM_PROFILE_PARAMETER_RECORDING_STATE))); MAX (
MinimalSizeNeeded += MAX (sizeof (MEMORY_PROFILE_CONTEXT), sizeof (SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET),
MAX (sizeof (MEMORY_PROFILE_DRIVER_INFO), sizeof (SMRAM_PROFILE_PARAMETER_RECORDING_STATE)
MAX (sizeof (MEMORY_PROFILE_ALLOC_INFO), )
MAX (sizeof (MEMORY_PROFILE_DESCRIPTOR), );
MAX (sizeof (MEMORY_PROFILE_FREE_MEMORY), MinimalSizeNeeded += MAX (
sizeof (MEMORY_PROFILE_MEMORY_RANGE)))))); sizeof (MEMORY_PROFILE_CONTEXT),
MAX (
sizeof (MEMORY_PROFILE_DRIVER_INFO),
MAX (
sizeof (MEMORY_PROFILE_ALLOC_INFO),
MAX (
sizeof (MEMORY_PROFILE_DESCRIPTOR),
MAX (
sizeof (MEMORY_PROFILE_FREE_MEMORY),
sizeof (MEMORY_PROFILE_MEMORY_RANGE)
)
)
)
)
);
Status = EfiGetSystemConfigurationTable ( Status = EfiGetSystemConfigurationTable (
&gEdkiiPiSmmCommunicationRegionTableGuid, &gEdkiiPiSmmCommunicationRegionTableGuid,
@ -1160,6 +1207,7 @@ GetSmramProfileData (
DEBUG ((DEBUG_ERROR, "SmramProfile: Get PiSmmCommunicationRegionTable - %r\n", Status)); DEBUG ((DEBUG_ERROR, "SmramProfile: Get PiSmmCommunicationRegionTable - %r\n", Status));
return Status; return Status;
} }
ASSERT (PiSmmCommunicationRegionTable != NULL); ASSERT (PiSmmCommunicationRegionTable != NULL);
Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1); Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);
Size = 0; Size = 0;
@ -1170,8 +1218,10 @@ GetSmramProfileData (
break; break;
} }
} }
Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize); Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize);
} }
ASSERT (Index < PiSmmCommunicationRegionTable->NumberOfEntries); ASSERT (Index < PiSmmCommunicationRegionTable->NumberOfEntries);
CommBuffer = (UINT8 *)(UINTN)Entry->PhysicalStart; CommBuffer = (UINT8 *)(UINTN)Entry->PhysicalStart;
@ -1201,6 +1251,7 @@ GetSmramProfileData (
Print (L"SmramProfile: GetRecordingState - 0x%0x\n", CommRecordingState->Header.ReturnStatus); Print (L"SmramProfile: GetRecordingState - 0x%0x\n", CommRecordingState->Header.ReturnStatus);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
RecordingState = CommRecordingState->RecordingState; RecordingState = CommRecordingState->RecordingState;
if (RecordingState == MEMORY_PROFILE_RECORDING_ENABLE) { if (RecordingState == MEMORY_PROFILE_RECORDING_ENABLE) {
CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
@ -1274,6 +1325,7 @@ GetSmramProfileData (
} else { } else {
CommGetProfileData->ProfileSize = (UINT64)(ProfileSize - CommGetProfileData->ProfileOffset); CommGetProfileData->ProfileSize = (UINT64)(ProfileSize - CommGetProfileData->ProfileOffset);
} }
Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize); Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -1282,10 +1334,10 @@ GetSmramProfileData (
Print (L"GetProfileData - 0x%x\n", CommGetProfileData->Header.ReturnStatus); Print (L"GetProfileData - 0x%x\n", CommGetProfileData->Header.ReturnStatus);
goto Done; goto Done;
} }
CopyMem ((UINT8 *)ProfileBuffer + Offset, (VOID *)(UINTN)CommGetProfileData->ProfileBuffer, (UINTN)CommGetProfileData->ProfileSize); CopyMem ((UINT8 *)ProfileBuffer + Offset, (VOID *)(UINTN)CommGetProfileData->ProfileBuffer, (UINTN)CommGetProfileData->ProfileSize);
} }
Print (L"SmramProfileSize - 0x%x\n", ProfileSize); Print (L"SmramProfileSize - 0x%x\n", ProfileSize);
Print (L"======= SmramProfile begin =======\n"); Print (L"======= SmramProfile begin =======\n");
DumpMemoryProfile ((PHYSICAL_ADDRESS)(UINTN)ProfileBuffer, ProfileSize, TRUE); DumpMemoryProfile ((PHYSICAL_ADDRESS)(UINTN)ProfileBuffer, ProfileSize, TRUE);

View File

@ -41,6 +41,7 @@ InternalDumpData (
) )
{ {
UINTN Index; UINTN Index;
for (Index = 0; Index < Size; Index++) { for (Index = 0; Index < Size; Index++) {
Print (L"%02x", (UINTN)Data[Index]); Print (L"%02x", (UINTN)Data[Index]);
if ((Index + 1) != Size) { if ((Index + 1) != Size) {
@ -88,6 +89,7 @@ GetSmiHandlerProfileDatabase(
Print (L"SmiHandlerProfile: Get PiSmmCommunicationRegionTable - %r\n", Status); Print (L"SmiHandlerProfile: Get PiSmmCommunicationRegionTable - %r\n", Status);
return; return;
} }
ASSERT (PiSmmCommunicationRegionTable != NULL); ASSERT (PiSmmCommunicationRegionTable != NULL);
Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1); Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);
Size = 0; Size = 0;
@ -98,8 +100,10 @@ GetSmiHandlerProfileDatabase(
break; break;
} }
} }
Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize); Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize);
} }
ASSERT (Index < PiSmmCommunicationRegionTable->NumberOfEntries); ASSERT (Index < PiSmmCommunicationRegionTable->NumberOfEntries);
CommBuffer = (UINT8 *)(UINTN)Entry->PhysicalStart; CommBuffer = (UINT8 *)(UINTN)Entry->PhysicalStart;
@ -162,6 +166,7 @@ GetSmiHandlerProfileDatabase(
} else { } else {
CommGetData->DataSize = (UINT64)(mSmiHandlerProfileDatabaseSize - CommGetData->DataOffset); CommGetData->DataSize = (UINT64)(mSmiHandlerProfileDatabaseSize - CommGetData->DataOffset);
} }
Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize); Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -171,6 +176,7 @@ GetSmiHandlerProfileDatabase(
Print (L"SmiHandlerProfile: GetData - 0x%x\n", CommGetData->Header.ReturnStatus); Print (L"SmiHandlerProfile: GetData - 0x%x\n", CommGetData->Header.ReturnStatus);
return; return;
} }
CopyMem ((UINT8 *)mSmiHandlerProfileDatabase + Offset, (VOID *)(UINTN)CommGetData->DataBuffer, (UINTN)CommGetData->DataSize); CopyMem ((UINT8 *)mSmiHandlerProfileDatabase + Offset, (VOID *)(UINTN)CommGetData->DataBuffer, (UINTN)CommGetData->DataSize);
} }
@ -208,7 +214,9 @@ GetShortPdbFileName (
AsciiStrnCpyS (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1, " ", 1); AsciiStrnCpyS (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1, " ", 1);
} else { } else {
StartIndex = 0; StartIndex = 0;
for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++); for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++) {
}
for (IndexPdb = 0; PdbFileName[IndexPdb] != 0; IndexPdb++) { for (IndexPdb = 0; PdbFileName[IndexPdb] != 0; IndexPdb++) {
if ((PdbFileName[IndexPdb] == '\\') || (PdbFileName[IndexPdb] == '/')) { if ((PdbFileName[IndexPdb] == '\\') || (PdbFileName[IndexPdb] == '/')) {
StartIndex = IndexPdb + 1; StartIndex = IndexPdb + 1;
@ -284,6 +292,7 @@ GetDriverNameString (
if (StrLen (NameString) > PROFILE_NAME_STRING_LENGTH) { if (StrLen (NameString) > PROFILE_NAME_STRING_LENGTH) {
NameString[PROFILE_NAME_STRING_LENGTH] = 0; NameString[PROFILE_NAME_STRING_LENGTH] = 0;
} }
UnicodeStrToAsciiStrS (NameString, mNameString, sizeof (mNameString)); UnicodeStrToAsciiStrS (NameString, mNameString, sizeof (mNameString));
FreePool (NameString); FreePool (NameString);
return mNameString; return mNameString;
@ -318,6 +327,7 @@ GetImageFromRef (
return ImageStruct; return ImageStruct;
} }
} }
ImageStruct = (VOID *)((UINTN)ImageStruct + ImageStruct->Header.Length); ImageStruct = (VOID *)((UINTN)ImageStruct + ImageStruct->Header.Length);
} }
@ -345,6 +355,7 @@ DumpSmmLoadedImage(
if (ImageStruct->EntryPoint != 0) { if (ImageStruct->EntryPoint != 0) {
Print (L" EntryPoint=\"0x%lx\"", ImageStruct->EntryPoint); Print (L" EntryPoint=\"0x%lx\"", ImageStruct->EntryPoint);
} }
Print (L" FvFile=\"%g\"", &ImageStruct->FileGuid); Print (L" FvFile=\"%g\"", &ImageStruct->FileGuid);
Print (L" RefId=\"0x%x\"", ImageStruct->ImageRef); Print (L" RefId=\"0x%x\"", ImageStruct->ImageRef);
Print (L">\n"); Print (L">\n");
@ -352,6 +363,7 @@ DumpSmmLoadedImage(
PdbString = (CHAR8 *)((UINTN)ImageStruct + ImageStruct->PdbStringOffset); PdbString = (CHAR8 *)((UINTN)ImageStruct + ImageStruct->PdbStringOffset);
Print (L" <Pdb>%a</Pdb>\n", PdbString); Print (L" <Pdb>%a</Pdb>\n", PdbString);
} }
Print (L" </Image>\n"); Print (L" </Image>\n");
} }
@ -382,7 +394,7 @@ SxTypeToString (
IN EFI_SLEEP_TYPE Type IN EFI_SLEEP_TYPE Type
) )
{ {
if (Type >= 0 && Type < ARRAY_SIZE(mSxTypeString)) { if ((Type >= 0) && (Type < ARRAY_SIZE (mSxTypeString))) {
return mSxTypeString[Type]; return mSxTypeString[Type];
} else { } else {
AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Type); AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Type);
@ -407,7 +419,7 @@ SxPhaseToString (
IN EFI_SLEEP_PHASE Phase IN EFI_SLEEP_PHASE Phase
) )
{ {
if (Phase >= 0 && Phase < ARRAY_SIZE(mSxPhaseString)) { if ((Phase >= 0) && (Phase < ARRAY_SIZE (mSxPhaseString))) {
return mSxPhaseString[Phase]; return mSxPhaseString[Phase];
} else { } else {
AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Phase); AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Phase);
@ -432,7 +444,7 @@ PowerButtonPhaseToString (
IN EFI_POWER_BUTTON_PHASE Phase IN EFI_POWER_BUTTON_PHASE Phase
) )
{ {
if (Phase >= 0 && Phase < ARRAY_SIZE(mPowerButtonPhaseString)) { if ((Phase >= 0) && (Phase < ARRAY_SIZE (mPowerButtonPhaseString))) {
return mPowerButtonPhaseString[Phase]; return mPowerButtonPhaseString[Phase];
} else { } else {
AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Phase); AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Phase);
@ -457,7 +469,7 @@ StandbyButtonPhaseToString (
IN EFI_STANDBY_BUTTON_PHASE Phase IN EFI_STANDBY_BUTTON_PHASE Phase
) )
{ {
if (Phase >= 0 && Phase < ARRAY_SIZE(mStandbyButtonPhaseString)) { if ((Phase >= 0) && (Phase < ARRAY_SIZE (mStandbyButtonPhaseString))) {
return mStandbyButtonPhaseString[Phase]; return mStandbyButtonPhaseString[Phase];
} else { } else {
AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Phase); AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Phase);
@ -483,7 +495,7 @@ IoTrapTypeToString (
IN EFI_SMM_IO_TRAP_DISPATCH_TYPE Type IN EFI_SMM_IO_TRAP_DISPATCH_TYPE Type
) )
{ {
if (Type >= 0 && Type < ARRAY_SIZE(mIoTrapTypeString)) { if ((Type >= 0) && (Type < ARRAY_SIZE (mIoTrapTypeString))) {
return mIoTrapTypeString[Type]; return mIoTrapTypeString[Type];
} else { } else {
AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Type); AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Type);
@ -508,7 +520,7 @@ UsbTypeToString (
IN EFI_USB_SMI_TYPE Type IN EFI_USB_SMI_TYPE Type
) )
{ {
if (Type >= 0 && Type < ARRAY_SIZE(mUsbTypeString)) { if ((Type >= 0) && (Type < ARRAY_SIZE (mUsbTypeString))) {
return mUsbTypeString[Type]; return mUsbTypeString[Type];
} else { } else {
AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Type); AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Type);
@ -588,12 +600,14 @@ DumpSmiHandler(
if (!IsZeroGuid (&SmiStruct->HandlerType)) { if (!IsZeroGuid (&SmiStruct->HandlerType)) {
Print (L" HandlerType=\"%g\"", &SmiStruct->HandlerType); Print (L" HandlerType=\"%g\"", &SmiStruct->HandlerType);
} }
Print (L">\n"); Print (L">\n");
for (Index = 0; Index < SmiStruct->HandlerCount; Index++) { for (Index = 0; Index < SmiStruct->HandlerCount; Index++) {
Print (L" <SmiHandler"); Print (L" <SmiHandler");
if (SmiHandlerStruct->ContextBufferSize != 0) { if (SmiHandlerStruct->ContextBufferSize != 0) {
DumpSmiChildContext (&SmiStruct->HandlerType, (UINT8 *)SmiHandlerStruct + SmiHandlerStruct->ContextBufferOffset, SmiHandlerStruct->ContextBufferSize); DumpSmiChildContext (&SmiStruct->HandlerType, (UINT8 *)SmiHandlerStruct + SmiHandlerStruct->ContextBufferOffset, SmiHandlerStruct->ContextBufferSize);
} }
Print (L">\n"); Print (L">\n");
ImageStruct = GetImageFromRef ((UINTN)SmiHandlerStruct->ImageRef); ImageStruct = GetImageFromRef ((UINTN)SmiHandlerStruct->ImageRef);
NameString = GetDriverNameString (ImageStruct); NameString = GetDriverNameString (ImageStruct);
@ -601,22 +615,27 @@ DumpSmiHandler(
if ((ImageStruct != NULL) && (ImageStruct->PdbStringOffset != 0)) { if ((ImageStruct != NULL) && (ImageStruct->PdbStringOffset != 0)) {
Print (L" <Pdb>%a</Pdb>\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset); Print (L" <Pdb>%a</Pdb>\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset);
} }
Print (L" </Module>\n"); Print (L" </Module>\n");
Print (L" <Handler Address=\"0x%lx\">\n", SmiHandlerStruct->Handler); Print (L" <Handler Address=\"0x%lx\">\n", SmiHandlerStruct->Handler);
if (ImageStruct != NULL) { if (ImageStruct != NULL) {
Print (L" <RVA>0x%x</RVA>\n", (UINTN)(SmiHandlerStruct->Handler - ImageStruct->ImageBase)); Print (L" <RVA>0x%x</RVA>\n", (UINTN)(SmiHandlerStruct->Handler - ImageStruct->ImageBase));
} }
Print (L" </Handler>\n", SmiHandlerStruct->Handler); Print (L" </Handler>\n", SmiHandlerStruct->Handler);
Print (L" <Caller Address=\"0x%lx\">\n", SmiHandlerStruct->CallerAddr); Print (L" <Caller Address=\"0x%lx\">\n", SmiHandlerStruct->CallerAddr);
if (ImageStruct != NULL) { if (ImageStruct != NULL) {
Print (L" <RVA>0x%x</RVA>\n", (UINTN)(SmiHandlerStruct->CallerAddr - ImageStruct->ImageBase)); Print (L" <RVA>0x%x</RVA>\n", (UINTN)(SmiHandlerStruct->CallerAddr - ImageStruct->ImageBase));
} }
Print (L" </Caller>\n", SmiHandlerStruct->Handler); Print (L" </Caller>\n", SmiHandlerStruct->Handler);
SmiHandlerStruct = (VOID *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length); SmiHandlerStruct = (VOID *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length);
Print (L" </SmiHandler>\n"); Print (L" </SmiHandler>\n");
} }
Print (L" </SmiEntry>\n"); Print (L" </SmiEntry>\n");
} }
SmiStruct = (VOID *)((UINTN)SmiStruct + SmiStruct->Header.Length); SmiStruct = (VOID *)((UINTN)SmiStruct + SmiStruct->Header.Length);
} }

View File

@ -59,7 +59,8 @@ HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath = {
// //
// {8E6D99EE-7531-48f8-8745-7F6144468FF2} // {8E6D99EE-7531-48f8-8745-7F6144468FF2}
// //
{ 0x8e6d99ee, 0x7531, 0x48f8, { 0x87, 0x45, 0x7f, 0x61, 0x44, 0x46, 0x8f, 0xf2 } } { 0x8e6d99ee, 0x7531, 0x48f8, { 0x87, 0x45, 0x7f, 0x61, 0x44, 0x46, 0x8f, 0xf2 }
}
}, },
{ {
END_DEVICE_PATH_TYPE, END_DEVICE_PATH_TYPE,
@ -111,9 +112,10 @@ FakeExtractConfig (
OUT EFI_STRING *Results OUT EFI_STRING *Results
) )
{ {
if (Progress == NULL || Results == NULL) { if ((Progress == NULL) || (Results == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
*Progress = Request; *Progress = Request;
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -142,7 +144,7 @@ FakeRouteConfig (
OUT EFI_STRING *Progress OUT EFI_STRING *Progress
) )
{ {
if (Configuration == NULL || Progress == NULL) { if ((Configuration == NULL) || (Progress == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -253,6 +255,7 @@ InitializeFrontPage (
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
// //
// Locate Hii relative protocols // Locate Hii relative protocols
// //
@ -353,6 +356,7 @@ FreeFrontPage(
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = gBS->UninstallMultipleProtocolInterfaces ( Status = gBS->UninstallMultipleProtocolInterfaces (
gFrontPagePrivate.DriverHandle, gFrontPagePrivate.DriverHandle,
&gEfiDevicePathProtocolGuid, &gEfiDevicePathProtocolGuid,
@ -401,6 +405,7 @@ ConvertProcessorToString (
} else { } else {
FreqMhz = 0; FreqMhz = 0;
} }
DestMax = 0x20 / sizeof (CHAR16); DestMax = 0x20 / sizeof (CHAR16);
StringBuffer = AllocateZeroPool (0x20); StringBuffer = AllocateZeroPool (0x20);
ASSERT (StringBuffer != NULL); ASSERT (StringBuffer != NULL);
@ -419,7 +424,6 @@ ConvertProcessorToString (
return; return;
} }
/** /**
Convert Memory Size to a string. Convert Memory Size to a string.
@ -492,7 +496,6 @@ GetOptionalStringByIndex (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Update the banner information for the Front Page based on Smbios information. Update the banner information for the Front Page based on Smbios information.
@ -633,11 +636,17 @@ UpdateFrontPageBannerStrings (
if ( Record->Type == SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS ) { if ( Record->Type == SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS ) {
Type19Record = (SMBIOS_TABLE_TYPE19 *)Record; Type19Record = (SMBIOS_TABLE_TYPE19 *)Record;
if (Type19Record->StartingAddress != 0xFFFFFFFF ) { if (Type19Record->StartingAddress != 0xFFFFFFFF ) {
InstalledMemory += RShiftU64(Type19Record->EndingAddress - InstalledMemory += RShiftU64 (
Type19Record->StartingAddress + 1, 10); Type19Record->EndingAddress -
Type19Record->StartingAddress + 1,
10
);
} else { } else {
InstalledMemory += RShiftU64(Type19Record->ExtendedEndingAddress - InstalledMemory += RShiftU64 (
Type19Record->ExtendedStartingAddress + 1, 20); Type19Record->ExtendedEndingAddress -
Type19Record->ExtendedStartingAddress + 1,
20
);
} }
} }
@ -756,15 +765,17 @@ UiSetConsoleMode (
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
if ((Info->HorizontalResolution == NewHorizontalResolution) && if ((Info->HorizontalResolution == NewHorizontalResolution) &&
(Info->VerticalResolution == NewVerticalResolution)) { (Info->VerticalResolution == NewVerticalResolution))
{
if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) && if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) &&
(GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) { (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution))
{
// //
// Current resolution is same with required resolution, check if text mode need be set // Current resolution is same with required resolution, check if text mode need be set
// //
Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow); Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
if (CurrentColumn == NewColumns && CurrentRow == NewRows) { if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {
// //
// If current text mode is same with required text mode. Do nothing // If current text mode is same with required text mode. Do nothing
// //
@ -795,6 +806,7 @@ UiSetConsoleMode (
} }
} }
} }
if (Index == MaxTextMode) { if (Index == MaxTextMode) {
// //
// If required text mode is not supported, return error. // If required text mode is not supported, return error.
@ -815,6 +827,7 @@ UiSetConsoleMode (
} }
} }
} }
FreePool (Info); FreePool (Info);
} }
} }
@ -855,9 +868,11 @@ UiSetConsoleMode (
for (Index = 0; Index < HandleCount; Index++) { for (Index = 0; Index < HandleCount; Index++) {
gBS->DisconnectController (HandleBuffer[Index], NULL, NULL); gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
} }
for (Index = 0; Index < HandleCount; Index++) { for (Index = 0; Index < HandleCount; Index++) {
gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE); gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
} }
if (HandleBuffer != NULL) { if (HandleBuffer != NULL) {
FreePool (HandleBuffer); FreePool (HandleBuffer);
} }
@ -1034,10 +1049,6 @@ UiEntry (
// user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection. // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
// //
/** /**
Record the info that a reset is required. Record the info that a reset is required.
A module boolean variable is used to record whether a reset is required. A module boolean variable is used to record whether a reset is required.
@ -1052,10 +1063,6 @@ EnableResetRequired (
mResetRequired = TRUE; mResetRequired = TRUE;
} }
/** /**
Check if user changed any option setting which needs a system reset to be effective. Check if user changed any option setting which needs a system reset to be effective.
@ -1069,7 +1076,6 @@ IsResetRequired (
return mResetRequired; return mResetRequired;
} }
/** /**
Check whether a reset is needed, and finish the reset reminder feature. Check whether a reset is needed, and finish the reset reminder feature.
If a reset is needed, Popup a menu to notice user, and finish the feature If a reset is needed, Popup a menu to notice user, and finish the feature
@ -1090,7 +1096,6 @@ SetupResetReminder (
// check any reset required change is applied? if yes, reset system // check any reset required change is applied? if yes, reset system
// //
if (IsResetRequired ()) { if (IsResetRequired ()) {
StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)); StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
ASSERT (StringBuffer1 != NULL); ASSERT (StringBuffer1 != NULL);
StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)); StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
@ -1110,4 +1115,3 @@ SetupResetReminder (
gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL); gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
} }
} }

View File

@ -20,7 +20,6 @@ extern UINT8 FrontPageVfrBin[];
extern EFI_FORM_BROWSER2_PROTOCOL *gFormBrowser2; extern EFI_FORM_BROWSER2_PROTOCOL *gFormBrowser2;
#define SMBIOS_TYPE4_CPU_SOCKET_POPULATED BIT6 #define SMBIOS_TYPE4_CPU_SOCKET_POPULATED BIT6
// //
@ -60,7 +59,6 @@ typedef struct {
EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess; EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
} FRONT_PAGE_CALLBACK_DATA; } FRONT_PAGE_CALLBACK_DATA;
#define EFI_FP_CALLBACK_DATA_FROM_THIS(a) \ #define EFI_FP_CALLBACK_DATA_FROM_THIS(a) \
CR (a, \ CR (a, \
FRONT_PAGE_CALLBACK_DATA, \ FRONT_PAGE_CALLBACK_DATA, \
@ -210,4 +208,3 @@ ExtractDevicePathFromHiiHandle (
); );
#endif // _FRONT_PAGE_H_ #endif // _FRONT_PAGE_H_

View File

@ -132,8 +132,10 @@ UiCustomizeFrontPageBanner (
if (BannerStr != NULL) { if (BannerStr != NULL) {
FreePool (*BannerStr); FreePool (*BannerStr);
} }
*BannerStr = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_TEST_KEY_USED), NULL); *BannerStr = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_TEST_KEY_USED), NULL);
} }
} }
return; return;
} }

View File

@ -53,7 +53,6 @@ UI_HII_DRIVER_INSTANCE *gHiiDriverList;
extern EFI_HII_HANDLE gStringPackHandle; extern EFI_HII_HANDLE gStringPackHandle;
UINT8 gCurrentLanguageIndex; UINT8 gCurrentLanguageIndex;
/** /**
Get next language from language code list (with separator ';'). Get next language from language code list (with separator ';').
@ -91,6 +90,7 @@ GetNextLanguage (
if (StringPtr[Index] == ';') { if (StringPtr[Index] == ';') {
Index++; Index++;
} }
*LangCode = StringPtr + Index; *LangCode = StringPtr + Index;
} }
@ -148,6 +148,7 @@ LanguageChangeHandler (
} else { } else {
ASSERT (FALSE); ASSERT (FALSE);
} }
FreePool (Lang); FreePool (Lang);
return EFI_SUCCESS; return EFI_SUCCESS;
@ -181,9 +182,10 @@ UiSupportLibCallbackHandler (
OUT EFI_STATUS *Status OUT EFI_STATUS *Status
) )
{ {
if (QuestionId != FRONT_PAGE_KEY_CONTINUE && if ((QuestionId != FRONT_PAGE_KEY_CONTINUE) &&
QuestionId != FRONT_PAGE_KEY_RESET && (QuestionId != FRONT_PAGE_KEY_RESET) &&
QuestionId != FRONT_PAGE_KEY_LANGUAGE) { (QuestionId != FRONT_PAGE_KEY_LANGUAGE))
{
return FALSE; return FALSE;
} }
@ -194,6 +196,7 @@ UiSupportLibCallbackHandler (
} else { } else {
*Status = EFI_UNSUPPORTED; *Status = EFI_UNSUPPORTED;
} }
return TRUE; return TRUE;
} }
@ -345,10 +348,11 @@ UiCreateLanguageMenu (
Lang = AllocatePool (AsciiStrSize (gLanguageString)); Lang = AllocatePool (AsciiStrSize (gLanguageString));
ASSERT (Lang != NULL); ASSERT (Lang != NULL);
} }
while (*LangCode != 0) { while (*LangCode != 0) {
GetNextLanguage (&LangCode, Lang); GetNextLanguage (&LangCode, Lang);
if (CurrentLang != NULL && AsciiStrCmp (Lang, CurrentLang) == 0) { if ((CurrentLang != NULL) && (AsciiStrCmp (Lang, CurrentLang) == 0)) {
HiiCreateOneOfOptionOpCode ( HiiCreateOneOfOptionOpCode (
OptionsOpCodeHandle, OptionsOpCodeHandle,
gLanguageToken[OptionCount], gLanguageToken[OptionCount],
@ -373,6 +377,7 @@ UiCreateLanguageMenu (
if (CurrentLang != NULL) { if (CurrentLang != NULL) {
FreePool (CurrentLang); FreePool (CurrentLang);
} }
FreePool (Lang); FreePool (Lang);
HiiCreateOneOfOpCode ( HiiCreateOneOfOpCode (
@ -612,6 +617,7 @@ UiListThirdPartyDrivers (
DriverListPtr[Count].EmptyLineAfter = EmptyLineAfter; DriverListPtr[Count].EmptyLineAfter = EmptyLineAfter;
} }
} }
DriverListPtr[Count].PromptId = HiiSetString (HiiHandle, 0, String, NULL); DriverListPtr[Count].PromptId = HiiSetString (HiiHandle, 0, String, NULL);
FreePool (String); FreePool (String);
@ -620,6 +626,7 @@ UiListThirdPartyDrivers (
String = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); String = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);
ASSERT (String != NULL); ASSERT (String != NULL);
} }
DriverListPtr[Count].HelpId = HiiSetString (HiiHandle, 0, String, NULL); DriverListPtr[Count].HelpId = HiiSetString (HiiHandle, 0, String, NULL);
FreePool (String); FreePool (String);

View File

@ -6,7 +6,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef _BDS_MODULE_H_ #ifndef _BDS_MODULE_H_
#define _BDS_MODULE_H_ #define _BDS_MODULE_H_
@ -43,12 +42,10 @@ typedef struct {
#pragma pack() #pragma pack()
// //
// The interface functions related to the Setup Browser Reset Reminder feature // The interface functions related to the Setup Browser Reset Reminder feature
// //
/** /**
Record the info that a reset is required. Record the info that a reset is required.
A module boolean variable is used to record whether a reset is required. A module boolean variable is used to record whether a reset is required.
@ -60,8 +57,6 @@ EnableResetRequired (
VOID VOID
); );
/** /**
Check whether platform policy enables the reset reminder feature. The default is enabled. Check whether platform policy enables the reset reminder feature. The default is enabled.

View File

@ -54,10 +54,12 @@ GetVariableStatisticsData (
SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)&SmmCommunicateHeader->Data[0]; SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)&SmmCommunicateHeader->Data[0];
SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_STATISTICS; SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_STATISTICS;
Status = mMmCommunication2->Communicate (mMmCommunication2, Status = mMmCommunication2->Communicate (
mMmCommunication2,
SmmCommunicateHeader, SmmCommunicateHeader,
SmmCommunicateHeader, SmmCommunicateHeader,
SmmCommunicateSize); SmmCommunicateSize
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = SmmVariableFunctionHeader->ReturnStatus; Status = SmmVariableFunctionHeader->ReturnStatus;
@ -109,6 +111,7 @@ PrintInfoFromSmm (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
ASSERT (PiSmmCommunicationRegionTable != NULL); ASSERT (PiSmmCommunicationRegionTable != NULL);
Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1); Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);
Size = 0; Size = 0;
@ -124,8 +127,10 @@ PrintInfoFromSmm (
} }
} }
} }
Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize); Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize);
} }
ASSERT (CommBuffer != NULL); ASSERT (CommBuffer != NULL);
ZeroMem (CommBuffer, RealCommSize); ZeroMem (CommBuffer, RealCommSize);
@ -253,6 +258,7 @@ UefiMain (
VariableInfo->Name VariableInfo->Name
); );
} }
VariableInfo = VariableInfo->Next; VariableInfo = VariableInfo->Next;
} while (VariableInfo != NULL); } while (VariableInfo != NULL);
} }

View File

@ -66,7 +66,6 @@ UINT32 mMaxTransferBlockNumber[2] = {
// //
#define MAX_28BIT_ADDRESSING_CAPACITY 0xfffffff #define MAX_28BIT_ADDRESSING_CAPACITY 0xfffffff
/** /**
Read AHCI Operation register. Read AHCI Operation register.
@ -196,7 +195,6 @@ AhciWaitMmioSet (
MicroSecondDelay (100); MicroSecondDelay (100);
Delay--; Delay--;
} while (Delay > 0); } while (Delay > 0);
return EFI_TIMEOUT; return EFI_TIMEOUT;
@ -286,7 +284,6 @@ AhciWaitMemSet (
MicroSecondDelay (100); MicroSecondDelay (100);
Delay--; Delay--;
} while (InfiniteWait || (Delay > 0)); } while (InfiniteWait || (Delay > 0));
return EFI_TIMEOUT; return EFI_TIMEOUT;
@ -762,7 +759,9 @@ AhciPioTransfer (
DEBUG_ERROR, DEBUG_ERROR,
"%a: Driver only support a maximum of 0x%x PRDT entries, " "%a: Driver only support a maximum of 0x%x PRDT entries, "
"current number of data byte 0x%x is too large, maximum allowed is 0x%x.\n", "current number of data byte 0x%x is too large, maximum allowed is 0x%x.\n",
__FUNCTION__, AHCI_MAX_PRDT_NUMBER, DataCount, __FUNCTION__,
AHCI_MAX_PRDT_NUMBER,
DataCount,
AHCI_MAX_PRDT_NUMBER * AHCI_MAX_DATA_PER_PRDT AHCI_MAX_PRDT_NUMBER * AHCI_MAX_DATA_PER_PRDT
)); ));
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
@ -864,6 +863,7 @@ AhciPioTransfer (
DEBUG ((DEBUG_INFO, "%a: PioFisReceived.\n", __FUNCTION__)); DEBUG ((DEBUG_INFO, "%a: PioFisReceived.\n", __FUNCTION__));
PioFisReceived = TRUE; PioFisReceived = TRUE;
} }
// //
// According to SATA 2.6 spec section 11.7, D2h FIS means an error encountered. // According to SATA 2.6 spec section 11.7, D2h FIS means an error encountered.
// But Qemu and Marvel 9230 sata controller may just receive a D2h FIS from // But Qemu and Marvel 9230 sata controller may just receive a D2h FIS from
@ -1178,7 +1178,6 @@ AhciIdentify (
return Status; return Status;
} }
/** /**
Collect the number of bits set within a port bitmap. Collect the number of bits set within a port bitmap.
@ -1200,6 +1199,7 @@ AhciGetNumberOfPortsFromMap (
if ((PortBitMap & ((UINT32)BIT0)) != 0) { if ((PortBitMap & ((UINT32)BIT0)) != 0) {
NumberOfPorts++; NumberOfPorts++;
} }
PortBitMap = PortBitMap >> 1; PortBitMap = PortBitMap >> 1;
} }
@ -1242,6 +1242,7 @@ AhciGetPortFromMap (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
} }
PortBitMap = PortBitMap >> 1; PortBitMap = PortBitMap >> 1;
*Port = *Port + 1; *Port = *Port + 1;
} }
@ -1303,6 +1304,7 @@ AhciCreateTransferDescriptor (
if (MaxPortNumber == 0) { if (MaxPortNumber == 0) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Get the number of ports that actually needed to be initialized. // Get the number of ports that actually needed to be initialized.
// //
@ -1321,6 +1323,7 @@ AhciCreateTransferDescriptor (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)Base)); ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)Base));
AhciRegisters->AhciRFis = Base; AhciRegisters->AhciRFis = Base;
AhciRegisters->AhciRFisMap = Mapping; AhciRegisters->AhciRFisMap = Mapping;
@ -1343,6 +1346,7 @@ AhciCreateTransferDescriptor (
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit; goto ErrorExit;
} }
ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)Base)); ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)Base));
AhciRegisters->AhciCmdList = Base; AhciRegisters->AhciCmdList = Base;
AhciRegisters->AhciCmdListMap = Mapping; AhciRegisters->AhciCmdListMap = Mapping;
@ -1364,6 +1368,7 @@ AhciCreateTransferDescriptor (
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit; goto ErrorExit;
} }
ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)Base)); ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)Base));
AhciRegisters->AhciCmdTable = Base; AhciRegisters->AhciCmdTable = Base;
AhciRegisters->AhciCmdTableMap = Mapping; AhciRegisters->AhciCmdTableMap = Mapping;
@ -1472,15 +1477,21 @@ IdentifyAtaDevice (
if ((IdentifyData->config & BIT15) != 0) { if ((IdentifyData->config & BIT15) != 0) {
DEBUG (( DEBUG ((
DEBUG_ERROR, "%a: Not a hard disk device on Port 0x%x PortMultiplierPort 0x%x\n", DEBUG_ERROR,
__FUNCTION__, DeviceData->Port, DeviceData->PortMultiplier "%a: Not a hard disk device on Port 0x%x PortMultiplierPort 0x%x\n",
__FUNCTION__,
DeviceData->Port,
DeviceData->PortMultiplier
)); ));
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
DEBUG (( DEBUG ((
DEBUG_INFO, "%a: Identify Device: Port 0x%x PortMultiplierPort 0x%x\n", DEBUG_INFO,
__FUNCTION__, DeviceData->Port, DeviceData->PortMultiplier "%a: Identify Device: Port 0x%x PortMultiplierPort 0x%x\n",
__FUNCTION__,
DeviceData->Port,
DeviceData->PortMultiplier
)); ));
// //
@ -1510,6 +1521,7 @@ IdentifyAtaDevice (
DEBUG ((DEBUG_ERROR, "%a: Invalid Capacity (0) for ATA device.\n", __FUNCTION__)); DEBUG ((DEBUG_ERROR, "%a: Invalid Capacity (0) for ATA device.\n", __FUNCTION__));
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
Media->LastBlock = (EFI_PEI_LBA)(Capacity - 1); Media->LastBlock = (EFI_PEI_LBA)(Capacity - 1);
Media->BlockSize = 0x200; Media->BlockSize = 0x200;
@ -1518,8 +1530,10 @@ IdentifyAtaDevice (
// //
PhyLogicSectorSupport = IdentifyData->phy_logic_sector_support; PhyLogicSectorSupport = IdentifyData->phy_logic_sector_support;
DEBUG (( DEBUG ((
DEBUG_INFO, "%a: PhyLogicSectorSupport = 0x%x\n", DEBUG_INFO,
__FUNCTION__, PhyLogicSectorSupport "%a: PhyLogicSectorSupport = 0x%x\n",
__FUNCTION__,
PhyLogicSectorSupport
)); ));
if ((PhyLogicSectorSupport & (BIT14 | BIT15)) == BIT14) { if ((PhyLogicSectorSupport & (BIT14 | BIT15)) == BIT14) {
// //
@ -1541,8 +1555,11 @@ IdentifyAtaDevice (
} }
DEBUG (( DEBUG ((
DEBUG_INFO, "%a: BlockSize = 0x%x, LastBlock = 0x%lx\n", DEBUG_INFO,
__FUNCTION__, Media->BlockSize, Media->LastBlock "%a: BlockSize = 0x%x, LastBlock = 0x%lx\n",
__FUNCTION__,
Media->BlockSize,
Media->LastBlock
)); ));
if ((IdentifyData->trusted_computing_support & BIT0) != 0) { if ((IdentifyData->trusted_computing_support & BIT0) != 0) {
@ -1622,6 +1639,7 @@ CreateNewDevice (
Private->TrustComputingDevices++; Private->TrustComputingDevices++;
DeviceData->TrustComputingDeviceIndex = Private->TrustComputingDevices; DeviceData->TrustComputingDeviceIndex = Private->TrustComputingDevices;
} }
Private->ActiveDevices++; Private->ActiveDevices++;
InsertTailList (&Private->DeviceList, &DeviceData->Link); InsertTailList (&Private->DeviceList, &DeviceData->Link);
@ -1690,7 +1708,8 @@ AhciModeInitialization (
DEBUG (( DEBUG ((
DEBUG_ERROR, DEBUG_ERROR,
"%a: Transfer-related data allocation failed with %r.\n", "%a: Transfer-related data allocation failed with %r.\n",
__FUNCTION__, Status __FUNCTION__,
Status
)); ));
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -1809,6 +1828,7 @@ AhciModeInitialization (
if (AhciReadReg (AhciBar, Offset) != 0) { if (AhciReadReg (AhciBar, Offset) != 0) {
AhciWriteReg (AhciBar, Offset, AhciReadReg (AhciBar, Offset)); AhciWriteReg (AhciBar, Offset, AhciReadReg (AhciBar, Offset));
} }
Offset = AHCI_PORT_START + Port * AHCI_PORT_REG_WIDTH + AHCI_PORT_TFD; Offset = AHCI_PORT_START + Port * AHCI_PORT_REG_WIDTH + AHCI_PORT_TFD;
Data = AhciReadReg (AhciBar, Offset) & AHCI_PORT_TFD_MASK; Data = AhciReadReg (AhciBar, Offset) & AHCI_PORT_TFD_MASK;
@ -1824,7 +1844,9 @@ AhciModeInitialization (
DEBUG (( DEBUG ((
DEBUG_ERROR, DEBUG_ERROR,
"%a: Port %d device presence detected but phy not ready (TFD=0x%x).\n", "%a: Port %d device presence detected but phy not ready (TFD=0x%x).\n",
__FUNCTION__, Port, Data __FUNCTION__,
Port,
Data
)); ));
continue; continue;
} }
@ -1844,7 +1866,8 @@ AhciModeInitialization (
DEBUG (( DEBUG ((
DEBUG_ERROR, DEBUG_ERROR,
"%a: Error occurred when waiting for the first D2H register FIS - %r\n", "%a: Error occurred when waiting for the first D2H register FIS - %r\n",
__FUNCTION__, Status __FUNCTION__,
Status
)); ));
continue; continue;
} }
@ -1856,6 +1879,7 @@ AhciModeInitialization (
DEBUG ((DEBUG_ERROR, "%a: AhciIdentify() failed with %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: AhciIdentify() failed with %r\n", __FUNCTION__, Status));
continue; continue;
} }
DEBUG ((DEBUG_INFO, "%a: ATA hard disk found on Port %d.\n", __FUNCTION__, Port)); DEBUG ((DEBUG_INFO, "%a: ATA hard disk found on Port %d.\n", __FUNCTION__, Port));
} else { } else {
continue; continue;
@ -1919,7 +1943,8 @@ TransferAtaDevice (
ASSERT ((UINTN)DeviceData->Lba48Bit < 2); ASSERT ((UINTN)DeviceData->Lba48Bit < 2);
ASSERT ((UINTN)IsWrite < 2); ASSERT ((UINTN)IsWrite < 2);
if (((UINTN)DeviceData->Lba48Bit >= 2) || if (((UINTN)DeviceData->Lba48Bit >= 2) ||
((UINTN) IsWrite >= 2)) { ((UINTN)IsWrite >= 2))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1955,6 +1980,7 @@ TransferAtaDevice (
Packet.InDataBuffer = Buffer; Packet.InDataBuffer = Buffer;
Packet.InTransferLength = TransferLength; Packet.InTransferLength = TransferLength;
} }
Packet.Asb = NULL; Packet.Asb = NULL;
Packet.Acb = &Acb; Packet.Acb = &Acb;
Packet.Protocol = mAtaPassThruCmdProtocols[IsWrite]; Packet.Protocol = mAtaPassThruCmdProtocols[IsWrite];
@ -2072,6 +2098,7 @@ TrustTransferAtaDevice (
} else { } else {
Acb.AtaCommand = mAtaTrustCommands[IsTrustSend]; Acb.AtaCommand = mAtaTrustCommands[IsTrustSend];
} }
Acb.AtaFeatures = SecurityProtocolId; Acb.AtaFeatures = SecurityProtocolId;
Acb.AtaSectorCount = (UINT8)(TransferLength / 512); Acb.AtaSectorCount = (UINT8)(TransferLength / 512);
Acb.AtaSectorNumber = (UINT8)((TransferLength / 512) >> 8); Acb.AtaSectorNumber = (UINT8)((TransferLength / 512) >> 8);
@ -2099,7 +2126,8 @@ TrustTransferAtaDevice (
// ATA PassThru PPI. // ATA PassThru PPI.
// //
if ((AtaPassThru->Mode->IoAlign > 1) && if ((AtaPassThru->Mode->IoAlign > 1) &&
!IS_ALIGNED (Buffer, AtaPassThru->Mode->IoAlign)) { !IS_ALIGNED (Buffer, AtaPassThru->Mode->IoAlign))
{
NewBuffer = AllocateAlignedPages ( NewBuffer = AllocateAlignedPages (
EFI_SIZE_TO_PAGES (TransferLength), EFI_SIZE_TO_PAGES (TransferLength),
AtaPassThru->Mode->IoAlign AtaPassThru->Mode->IoAlign
@ -2111,6 +2139,7 @@ TrustTransferAtaDevice (
CopyMem (NewBuffer, Buffer, TransferLength); CopyMem (NewBuffer, Buffer, TransferLength);
Buffer = NewBuffer; Buffer = NewBuffer;
} }
Packet.OutDataBuffer = Buffer; Packet.OutDataBuffer = Buffer;
Packet.OutTransferLength = (UINT32)TransferLength; Packet.OutTransferLength = (UINT32)TransferLength;
Packet.Protocol = mAtaPassThruCmdProtocols[IsTrustSend]; Packet.Protocol = mAtaPassThruCmdProtocols[IsTrustSend];
@ -2119,6 +2148,7 @@ TrustTransferAtaDevice (
Packet.InTransferLength = (UINT32)TransferLength; Packet.InTransferLength = (UINT32)TransferLength;
Packet.Protocol = mAtaPassThruCmdProtocols[IsTrustSend]; Packet.Protocol = mAtaPassThruCmdProtocols[IsTrustSend];
} }
Packet.Asb = NULL; Packet.Asb = NULL;
Packet.Acb = &Acb; Packet.Acb = &Acb;
Packet.Timeout = Timeout; Packet.Timeout = Timeout;
@ -2135,5 +2165,6 @@ TrustTransferAtaDevice (
*TransferLengthOut = Packet.InTransferLength; *TransferLengthOut = Packet.InTransferLength;
} }
} }
return Status; return Status;
} }

View File

@ -40,7 +40,6 @@ EFI_PEI_NOTIFY_DESCRIPTOR mAhciEndOfPeiNotifyListTemplate = {
AhciPeimEndOfPei AhciPeimEndOfPei
}; };
/** /**
Free the DMA resources allocated by an ATA AHCI controller. Free the DMA resources allocated by an ATA AHCI controller.
@ -82,7 +81,6 @@ AhciFreeDmaResource (
AhciRegisters->AhciCmdTableMap AhciRegisters->AhciCmdTableMap
); );
} }
} }
/** /**
@ -187,8 +185,10 @@ AtaAhciPeimEntry (
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG (( DEBUG ((
DEBUG_ERROR, "%a: Fail to allocate get the device path for Controller %d.\n", DEBUG_ERROR,
__FUNCTION__, Controller "%a: Fail to allocate get the device path for Controller %d.\n",
__FUNCTION__,
Controller
)); ));
return Status; return Status;
} }
@ -199,8 +199,10 @@ AtaAhciPeimEntry (
Status = AhciIsHcDevicePathValid (DevicePath, DevicePathLength); Status = AhciIsHcDevicePathValid (DevicePath, DevicePathLength);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG (( DEBUG ((
DEBUG_ERROR, "%a: The device path is invalid for Controller %d.\n", DEBUG_ERROR,
__FUNCTION__, Controller "%a: The device path is invalid for Controller %d.\n",
__FUNCTION__,
Controller
)); ));
Controller++; Controller++;
continue; continue;
@ -231,8 +233,10 @@ AtaAhciPeimEntry (
Private = AllocateZeroPool (sizeof (PEI_AHCI_CONTROLLER_PRIVATE_DATA)); Private = AllocateZeroPool (sizeof (PEI_AHCI_CONTROLLER_PRIVATE_DATA));
if (Private == NULL) { if (Private == NULL) {
DEBUG (( DEBUG ((
DEBUG_ERROR, "%a: Fail to allocate private data for Controller %d.\n", DEBUG_ERROR,
__FUNCTION__, Controller "%a: Fail to allocate private data for Controller %d.\n",
__FUNCTION__,
Controller
)); ));
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -304,7 +308,8 @@ AtaAhciPeimEntry (
DEBUG (( DEBUG ((
DEBUG_INFO, DEBUG_INFO,
"%a: Security Security Command PPI will be produced for Controller %d.\n", "%a: Security Security Command PPI will be produced for Controller %d.\n",
__FUNCTION__, Controller __FUNCTION__,
Controller
)); ));
Private->StorageSecurityPpi.Revision = EDKII_STORAGE_SECURITY_PPI_REVISION; Private->StorageSecurityPpi.Revision = EDKII_STORAGE_SECURITY_PPI_REVISION;
Private->StorageSecurityPpi.GetNumberofDevices = AhciStorageSecurityGetDeviceNo; Private->StorageSecurityPpi.GetNumberofDevices = AhciStorageSecurityGetDeviceNo;
@ -328,8 +333,10 @@ AtaAhciPeimEntry (
PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList); PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList);
DEBUG (( DEBUG ((
DEBUG_INFO, "%a: Controller %d has been successfully initialized.\n", DEBUG_INFO,
__FUNCTION__, Controller "%a: Controller %d has been successfully initialized.\n",
__FUNCTION__,
Controller
)); ));
Controller++; Controller++;
} }

View File

@ -97,9 +97,13 @@ AccessAtaDevice (
TransferBlockNumber = NumberOfBlocks; TransferBlockNumber = NumberOfBlocks;
NumberOfBlocks = 0; NumberOfBlocks = 0;
} }
DEBUG (( DEBUG ((
DEBUG_BLKIO, "%a: Blocking AccessAtaDevice, TransferBlockNumber = %x; StartLba = %x\n", DEBUG_BLKIO,
__FUNCTION__, TransferBlockNumber, StartLba "%a: Blocking AccessAtaDevice, TransferBlockNumber = %x; StartLba = %x\n",
__FUNCTION__,
TransferBlockNumber,
StartLba
)); ));
Status = TransferAtaDevice ( Status = TransferAtaDevice (
@ -163,6 +167,7 @@ AhciRead (
if (StartLba > DeviceData->Media.LastBlock) { if (StartLba > DeviceData->Media.LastBlock) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
NumberOfBlocks = BufferSize / BlockSize; NumberOfBlocks = BufferSize / BlockSize;
if (NumberOfBlocks - 1 > DeviceData->Media.LastBlock - StartLba) { if (NumberOfBlocks - 1 > DeviceData->Media.LastBlock - StartLba) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -176,7 +181,6 @@ AhciRead (
return Status; return Status;
} }
/** /**
Gets the count of block I/O devices that one specific block driver detects. Gets the count of block I/O devices that one specific block driver detects.
@ -203,7 +207,7 @@ AhciBlockIoGetDeviceNo (
{ {
PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private; PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || NumberBlockDevices == NULL) { if ((This == NULL) || (NumberBlockDevices == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -266,7 +270,7 @@ AhciBlockIoGetMediaInfo (
PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private; PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;
PEI_AHCI_ATA_DEVICE_DATA *DeviceData; PEI_AHCI_ATA_DEVICE_DATA *DeviceData;
if (This == NULL || MediaInfo == NULL) { if ((This == NULL) || (MediaInfo == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -371,7 +375,7 @@ AhciBlockIoGetDeviceNo2 (
{ {
PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private; PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || NumberBlockDevices == NULL) { if ((This == NULL) || (NumberBlockDevices == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -434,7 +438,7 @@ AhciBlockIoGetMediaInfo2 (
PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private; PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;
PEI_AHCI_ATA_DEVICE_DATA *DeviceData; PEI_AHCI_ATA_DEVICE_DATA *DeviceData;
if (This == NULL || MediaInfo == NULL) { if ((This == NULL) || (MediaInfo == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -38,7 +38,8 @@ SearchDeviceByPort (
DeviceData = AHCI_PEI_ATA_DEVICE_INFO_FROM_THIS (Node); DeviceData = AHCI_PEI_ATA_DEVICE_INFO_FROM_THIS (Node);
if ((DeviceData->Port == Port) && if ((DeviceData->Port == Port) &&
(DeviceData->PortMultiplier == PortMultiplierPort)) { (DeviceData->PortMultiplier == PortMultiplierPort))
{
return DeviceData; return DeviceData;
} }
@ -188,7 +189,7 @@ AhciAtaPassThruPassThru (
UINT32 MaxSectorCount; UINT32 MaxSectorCount;
UINT32 BlockSize; UINT32 BlockSize;
if (This == NULL || Packet == NULL) { if ((This == NULL) || (Packet == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -218,7 +219,8 @@ AhciAtaPassThruPassThru (
// Convert the transfer length from sector count to byte. // Convert the transfer length from sector count to byte.
// //
if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) && if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) &&
(Packet->InTransferLength != 0)) { (Packet->InTransferLength != 0))
{
Packet->InTransferLength = Packet->InTransferLength * BlockSize; Packet->InTransferLength = Packet->InTransferLength * BlockSize;
} }
@ -226,7 +228,8 @@ AhciAtaPassThruPassThru (
// Convert the transfer length from sector count to byte. // Convert the transfer length from sector count to byte.
// //
if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) && if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) &&
(Packet->OutTransferLength != 0)) { (Packet->OutTransferLength != 0))
{
Packet->OutTransferLength = Packet->OutTransferLength * BlockSize; Packet->OutTransferLength = Packet->OutTransferLength * BlockSize;
} }
@ -236,7 +239,8 @@ AhciAtaPassThruPassThru (
// command, then no data is transferred and EFI_BAD_BUFFER_SIZE is returned. // command, then no data is transferred and EFI_BAD_BUFFER_SIZE is returned.
// //
if (((Packet->InTransferLength != 0) && (Packet->InTransferLength > MaxSectorCount * BlockSize)) || if (((Packet->InTransferLength != 0) && (Packet->InTransferLength > MaxSectorCount * BlockSize)) ||
((Packet->OutTransferLength != 0) && (Packet->OutTransferLength > MaxSectorCount * BlockSize))) { ((Packet->OutTransferLength != 0) && (Packet->OutTransferLength > MaxSectorCount * BlockSize)))
{
return EFI_BAD_BUFFER_SIZE; return EFI_BAD_BUFFER_SIZE;
} }
@ -292,7 +296,7 @@ AhciAtaPassThruGetNextPort (
PEI_AHCI_ATA_DEVICE_DATA *DeviceData; PEI_AHCI_ATA_DEVICE_DATA *DeviceData;
LIST_ENTRY *Node; LIST_ENTRY *Node;
if (This == NULL || Port == NULL) { if ((This == NULL) || (Port == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -402,7 +406,7 @@ AhciAtaPassThruGetNextDevice (
PEI_AHCI_ATA_DEVICE_DATA *DeviceData; PEI_AHCI_ATA_DEVICE_DATA *DeviceData;
LIST_ENTRY *Node; LIST_ENTRY *Node;
if (This == NULL || PortMultiplierPort == NULL) { if ((This == NULL) || (PortMultiplierPort == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -425,7 +429,8 @@ AhciAtaPassThruGetNextDevice (
DeviceData = AHCI_PEI_ATA_DEVICE_INFO_FROM_THIS (Node); DeviceData = AHCI_PEI_ATA_DEVICE_INFO_FROM_THIS (Node);
if ((DeviceData->Port == Port) && if ((DeviceData->Port == Port) &&
(DeviceData->PortMultiplier > *PortMultiplierPort)){ (DeviceData->PortMultiplier > *PortMultiplierPort))
{
*PortMultiplierPort = DeviceData->PortMultiplier; *PortMultiplierPort = DeviceData->PortMultiplier;
goto Exit; goto Exit;
} }
@ -497,7 +502,7 @@ AhciAtaPassThruGetDevicePath (
{ {
PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private; PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || DevicePathLength == NULL || DevicePath == NULL) { if ((This == NULL) || (DevicePathLength == NULL) || (DevicePath == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -101,25 +101,30 @@ AhciS3GetEumeratePorts (
DevicePathInst, DevicePathInst,
HcDevicePath, HcDevicePath,
HcDevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL) HcDevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL)
) == 0) { ) == 0)
{
// //
// Get the port number. // Get the port number.
// //
while (DevicePathInst->Type != END_DEVICE_PATH_TYPE) { while (DevicePathInst->Type != END_DEVICE_PATH_TYPE) {
if ((DevicePathInst->Type == MESSAGING_DEVICE_PATH) && if ((DevicePathInst->Type == MESSAGING_DEVICE_PATH) &&
(DevicePathInst->SubType == MSG_SATA_DP)) { (DevicePathInst->SubType == MSG_SATA_DP))
{
SataDeviceNode = (SATA_DEVICE_PATH *)DevicePathInst; SataDeviceNode = (SATA_DEVICE_PATH *)DevicePathInst;
// //
// For now, the driver only support upto AHCI_MAX_PORTS ports and // For now, the driver only support upto AHCI_MAX_PORTS ports and
// devices directly connected to a HBA. // devices directly connected to a HBA.
// //
if ((SataDeviceNode->HBAPortNumber >= AHCI_MAX_PORTS) || if ((SataDeviceNode->HBAPortNumber >= AHCI_MAX_PORTS) ||
(SataDeviceNode->PortMultiplierPortNumber != 0xFFFF)) { (SataDeviceNode->PortMultiplierPortNumber != 0xFFFF))
{
break; break;
} }
*PortBitMap |= (UINT32)BIT0 << SataDeviceNode->HBAPortNumber; *PortBitMap |= (UINT32)BIT0 << SataDeviceNode->HBAPortNumber;
break; break;
} }
DevicePathInst = NextDevicePathNode (DevicePathInst); DevicePathInst = NextDevicePathNode (DevicePathInst);
} }
} }

View File

@ -64,7 +64,7 @@ AhciStorageSecurityGetDeviceNo (
{ {
PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private; PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || NumberofDevices == NULL) { if ((This == NULL) || (NumberofDevices == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -112,7 +112,7 @@ AhciStorageSecurityGetDevicePath (
PEI_AHCI_ATA_DEVICE_DATA *DeviceData; PEI_AHCI_ATA_DEVICE_DATA *DeviceData;
EFI_STATUS Status; EFI_STATUS Status;
if (This == NULL || DevicePathLength == NULL || DevicePath == NULL) { if ((This == NULL) || (DevicePathLength == NULL) || (DevicePath == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -104,7 +104,7 @@ GetDevicePathInstanceSize (
{ {
EFI_DEVICE_PATH_PROTOCOL *Walker; EFI_DEVICE_PATH_PROTOCOL *Walker;
if (DevicePath == NULL || InstanceSize == NULL || EntireDevicePathEnd == NULL) { if ((DevicePath == NULL) || (InstanceSize == NULL) || (EntireDevicePathEnd == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -168,7 +168,8 @@ AhciIsHcDevicePathValid (
Start = DevicePath; Start = DevicePath;
while (!(DevicePath->Type == END_DEVICE_PATH_TYPE && while (!(DevicePath->Type == END_DEVICE_PATH_TYPE &&
DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) { DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE))
{
DevicePath = NextDevicePathNode (DevicePath); DevicePath = NextDevicePathNode (DevicePath);
// //
@ -183,7 +184,8 @@ AhciIsHcDevicePathValid (
// Prevent touching memory beyond given DevicePathLength. // Prevent touching memory beyond given DevicePathLength.
// //
if ((UINTN)DevicePath - (UINTN)Start > if ((UINTN)DevicePath - (UINTN)Start >
DevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL)) { DevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
} }
@ -227,7 +229,7 @@ AhciBuildDevicePath (
EFI_DEVICE_PATH_PROTOCOL *DevicePathWalker; EFI_DEVICE_PATH_PROTOCOL *DevicePathWalker;
SATA_DEVICE_PATH *SataDeviceNode; SATA_DEVICE_PATH *SataDeviceNode;
if (DevicePathLength == NULL || DevicePath == NULL) { if ((DevicePathLength == NULL) || (DevicePath == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -83,6 +83,7 @@ IoMmuMap (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
switch (Operation) { switch (Operation) {
case EdkiiIoMmuOperationBusMasterRead: case EdkiiIoMmuOperationBusMasterRead:
case EdkiiIoMmuOperationBusMasterRead64: case EdkiiIoMmuOperationBusMasterRead64:
@ -100,6 +101,7 @@ IoMmuMap (
ASSERT (FALSE); ASSERT (FALSE);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = IoMmu->SetAttribute ( Status = IoMmu->SetAttribute (
IoMmu, IoMmu,
*Mapping, *Mapping,
@ -113,6 +115,7 @@ IoMmuMap (
*Mapping = NULL; *Mapping = NULL;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
return Status; return Status;
} }
@ -141,6 +144,7 @@ IoMmuUnmap (
} else { } else {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
return Status; return Status;
} }
@ -204,6 +208,7 @@ IoMmuAllocateBuffer (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Status = IoMmu->SetAttribute ( Status = IoMmu->SetAttribute (
IoMmu, IoMmu,
*Mapping, *Mapping,
@ -221,10 +226,12 @@ IoMmuAllocateBuffer (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
*HostAddress = (VOID *)(UINTN)HostPhyAddress; *HostAddress = (VOID *)(UINTN)HostPhyAddress;
*DeviceAddress = HostPhyAddress; *DeviceAddress = HostPhyAddress;
*Mapping = NULL; *Mapping = NULL;
} }
return Status; return Status;
} }
@ -259,5 +266,6 @@ IoMmuFreeBuffer (
} else { } else {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
return Status; return Status;
} }

View File

@ -178,7 +178,6 @@ AhciWaitMmioSet (
MicroSecondDelay (100); MicroSecondDelay (100);
Delay--; Delay--;
} while (InfiniteWait || (Delay > 0)); } while (InfiniteWait || (Delay > 0));
return EFI_TIMEOUT; return EFI_TIMEOUT;
@ -239,7 +238,6 @@ AhciWaitMemSet (
MicroSecondDelay (100); MicroSecondDelay (100);
Delay--; Delay--;
} while (InfiniteWait || (Delay > 0)); } while (InfiniteWait || (Delay > 0));
return EFI_TIMEOUT; return EFI_TIMEOUT;
@ -275,7 +273,6 @@ AhciCheckMemSet (
return EFI_NOT_READY; return EFI_NOT_READY;
} }
/** /**
Clear the port interrupt and error status. It will also clear Clear the port interrupt and error status. It will also clear
@ -366,7 +363,6 @@ AhciDumpPortStatus (
} }
} }
/** /**
Enable the FIS running for giving port. Enable the FIS running for giving port.
@ -447,8 +443,6 @@ AhciDisableFisReceive (
); );
} }
/** /**
Build the command list, command table and prepare the fis receiver. Build the command list, command table and prepare the fis receiver.
@ -564,7 +558,6 @@ AhciBuildCommand (
AhciRegisters->AhciCmdList[CommandSlotNumber].AhciCmdCtba = Data64.Uint32.Lower32; AhciRegisters->AhciCmdList[CommandSlotNumber].AhciCmdCtba = Data64.Uint32.Lower32;
AhciRegisters->AhciCmdList[CommandSlotNumber].AhciCmdCtbau = Data64.Uint32.Upper32; AhciRegisters->AhciCmdList[CommandSlotNumber].AhciCmdCtbau = Data64.Uint32.Upper32;
AhciRegisters->AhciCmdList[CommandSlotNumber].AhciCmdPmp = PortMultiplier; AhciRegisters->AhciCmdList[CommandSlotNumber].AhciCmdPmp = PortMultiplier;
} }
/** /**
@ -637,6 +630,7 @@ AhciWaitDeviceReady (
if (AhciReadReg (PciIo, Offset) != 0) { if (AhciReadReg (PciIo, Offset) != 0) {
AhciWriteReg (PciIo, Offset, AhciReadReg (PciIo, Offset)); AhciWriteReg (PciIo, Offset, AhciReadReg (PciIo, Offset));
} }
Offset = EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_AHCI_PORT_TFD; Offset = EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_AHCI_PORT_TFD;
Data = AhciReadReg (PciIo, Offset) & EFI_AHCI_PORT_TFD_MASK; Data = AhciReadReg (PciIo, Offset) & EFI_AHCI_PORT_TFD_MASK;
@ -656,7 +650,6 @@ AhciWaitDeviceReady (
} }
} }
/** /**
Reset the SATA port. Algorithm follows AHCI spec 1.3.1 section 10.4.2 Reset the SATA port. Algorithm follows AHCI spec 1.3.1 section 10.4.2
@ -778,6 +771,7 @@ AhciCheckFisReceived (
DEBUG ((DEBUG_ERROR, "AHCI: Error interrupt reported PxIS: %X\n", PortInterrupt)); DEBUG ((DEBUG_ERROR, "AHCI: Error interrupt reported PxIS: %X\n", PortInterrupt));
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// For PIO setup FIS - According to SATA 2.6 spec section 11.7, D2h FIS means an error encountered. // For PIO setup FIS - According to SATA 2.6 spec section 11.7, D2h FIS means an error encountered.
// But Qemu and Marvel 9230 sata controller may just receive a D2h FIS from device // But Qemu and Marvel 9230 sata controller may just receive a D2h FIS from device
@ -786,8 +780,9 @@ AhciCheckFisReceived (
// By this way, we can know if there is a real error happened. // By this way, we can know if there is a real error happened.
// //
if (((FisType == SataFisD2H) && ((PortInterrupt & EFI_AHCI_PORT_IS_DHRS) != 0)) || if (((FisType == SataFisD2H) && ((PortInterrupt & EFI_AHCI_PORT_IS_DHRS) != 0)) ||
((FisType == SataFisPioSetup) && (PortInterrupt & (EFI_AHCI_PORT_IS_PSS | EFI_AHCI_PORT_IS_DHRS)) != 0) || ((FisType == SataFisPioSetup) && ((PortInterrupt & (EFI_AHCI_PORT_IS_PSS | EFI_AHCI_PORT_IS_DHRS)) != 0)) ||
((FisType == SataFisDmaSetup) && (PortInterrupt & (EFI_AHCI_PORT_IS_DSS | EFI_AHCI_PORT_IS_DHRS)) != 0)) { ((FisType == SataFisDmaSetup) && ((PortInterrupt & (EFI_AHCI_PORT_IS_DSS | EFI_AHCI_PORT_IS_DHRS)) != 0)))
{
Offset = EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_AHCI_PORT_TFD; Offset = EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_AHCI_PORT_TFD;
PortTfd = AhciReadReg (PciIo, (UINT32)Offset); PortTfd = AhciReadReg (PciIo, (UINT32)Offset);
if ((PortTfd & EFI_AHCI_PORT_TFD_ERR) != 0) { if ((PortTfd & EFI_AHCI_PORT_TFD_ERR) != 0) {
@ -836,6 +831,7 @@ AhciWaitUntilFisReceived (
if (Status != EFI_NOT_READY) { if (Status != EFI_NOT_READY) {
return Status; return Status;
} }
// //
// Stall for 100 microseconds. // Stall for 100 microseconds.
// //
@ -1163,12 +1159,13 @@ AhciDmaTransfer (
if (EFI_ERROR (Status) || (DataCount != MapLength)) { if (EFI_ERROR (Status) || (DataCount != MapLength)) {
return EFI_BAD_BUFFER_SIZE; return EFI_BAD_BUFFER_SIZE;
} }
if (Task != NULL) { if (Task != NULL) {
Task->Map = Map; Task->Map = Map;
} }
} }
if (Task == NULL || (Task != NULL && !Task->IsStart)) { if ((Task == NULL) || ((Task != NULL) && !Task->IsStart)) {
AhciBuildCommandFis (&CFis, AtaCommandBlock); AhciBuildCommandFis (&CFis, AtaCommandBlock);
ZeroMem (&CmdList, sizeof (EFI_AHCI_COMMAND_LIST)); ZeroMem (&CmdList, sizeof (EFI_AHCI_COMMAND_LIST));
@ -1191,6 +1188,7 @@ AhciDmaTransfer (
// //
MicroSecondDelay (100); MicroSecondDelay (100);
} }
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
for (Retry = 0; Retry < AHCI_COMMAND_RETRIES; Retry++) { for (Retry = 0; Retry < AHCI_COMMAND_RETRIES; Retry++) {
AhciBuildCommand ( AhciBuildCommand (
@ -1218,6 +1216,7 @@ AhciDmaTransfer (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
Status = AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2H); Status = AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2H);
if (Status == EFI_DEVICE_ERROR) { if (Status == EFI_DEVICE_ERROR) {
DEBUG ((DEBUG_ERROR, "DMA command failed at retry: %d\n", Retry)); DEBUG ((DEBUG_ERROR, "DMA command failed at retry: %d\n", Retry));
@ -1257,6 +1256,7 @@ AhciDmaTransfer (
Task->IsStart = TRUE; Task->IsStart = TRUE;
} }
} }
if (Task->IsStart) { if (Task->IsStart) {
Status = AhciCheckFisReceived (PciIo, Port, SataFisD2H); Status = AhciCheckFisReceived (PciIo, Port, SataFisD2H);
if (Status == EFI_DEVICE_ERROR) { if (Status == EFI_DEVICE_ERROR) {
@ -1275,7 +1275,7 @@ AhciDmaTransfer (
} }
if (Status == EFI_NOT_READY) { if (Status == EFI_NOT_READY) {
if (!Task->InfiniteWait && Task->RetryTimes == 0) { if (!Task->InfiniteWait && (Task->RetryTimes == 0)) {
Status = EFI_TIMEOUT; Status = EFI_TIMEOUT;
} else { } else {
Task->RetryTimes--; Task->RetryTimes--;
@ -1291,9 +1291,10 @@ AhciDmaTransfer (
// EFI_NOT_READY that means the command doesn't finished, try again.), first do the // EFI_NOT_READY that means the command doesn't finished, try again.), first do the
// context cleanup, then set the packet's Asb status. // context cleanup, then set the packet's Asb status.
// //
if (Task == NULL || if ((Task == NULL) ||
((Task != NULL) && (Status != EFI_NOT_READY)) ((Task != NULL) && (Status != EFI_NOT_READY))
) { )
{
AhciStopCommand ( AhciStopCommand (
PciIo, PciIo,
Port, Port,
@ -1588,7 +1589,6 @@ AhciStartCommand (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Do AHCI HBA reset. Do AHCI HBA reset.
@ -1775,8 +1775,12 @@ AhciAtaSmartSupport (
// //
// S.M.A.R.T is not supported by the device // S.M.A.R.T is not supported by the device
// //
DEBUG ((DEBUG_INFO, "S.M.A.R.T feature is not supported at port [%d] PortMultiplier [%d]!\n", DEBUG ((
Port, PortMultiplier)); DEBUG_INFO,
"S.M.A.R.T feature is not supported at port [%d] PortMultiplier [%d]!\n",
Port,
PortMultiplier
));
REPORT_STATUS_CODE ( REPORT_STATUS_CODE (
EFI_ERROR_CODE | EFI_ERROR_MINOR, EFI_ERROR_CODE | EFI_ERROR_MINOR,
(EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_NOTSUPPORTED) (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_NOTSUPPORTED)
@ -1786,7 +1790,6 @@ AhciAtaSmartSupport (
// Check if the feature is enabled. If not, then enable S.M.A.R.T. // Check if the feature is enabled. If not, then enable S.M.A.R.T.
// //
if ((IdentifyData->AtaData.command_set_feature_enb_85 & 0x0001) != 0x0001) { if ((IdentifyData->AtaData.command_set_feature_enb_85 & 0x0001) != 0x0001) {
REPORT_STATUS_CODE ( REPORT_STATUS_CODE (
EFI_PROGRESS_CODE, EFI_PROGRESS_CODE,
(EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_DISABLE) (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_DISABLE)
@ -1815,7 +1818,6 @@ AhciAtaSmartSupport (
NULL NULL
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
// //
// Send S.M.A.R.T AutoSave command to device // Send S.M.A.R.T AutoSave command to device
@ -1851,8 +1853,12 @@ AhciAtaSmartSupport (
AtaStatusBlock AtaStatusBlock
); );
DEBUG ((DEBUG_INFO, "Enabled S.M.A.R.T feature at port [%d] PortMultiplier [%d]!\n", DEBUG ((
Port, PortMultiplier)); DEBUG_INFO,
"Enabled S.M.A.R.T feature at port [%d] PortMultiplier [%d]!\n",
Port,
PortMultiplier
));
} }
return; return;
@ -1887,7 +1893,7 @@ AhciIdentify (
EFI_ATA_COMMAND_BLOCK AtaCommandBlock; EFI_ATA_COMMAND_BLOCK AtaCommandBlock;
EFI_ATA_STATUS_BLOCK AtaStatusBlock; EFI_ATA_STATUS_BLOCK AtaStatusBlock;
if (PciIo == NULL || AhciRegisters == NULL || Buffer == NULL) { if ((PciIo == NULL) || (AhciRegisters == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1945,7 +1951,7 @@ AhciIdentifyPacket (
EFI_ATA_COMMAND_BLOCK AtaCommandBlock; EFI_ATA_COMMAND_BLOCK AtaCommandBlock;
EFI_ATA_STATUS_BLOCK AtaStatusBlock; EFI_ATA_STATUS_BLOCK AtaStatusBlock;
if (PciIo == NULL || AhciRegisters == NULL) { if ((PciIo == NULL) || (AhciRegisters == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -2066,7 +2072,7 @@ AhciPacketCommandExecute (
EFI_ATA_STATUS_BLOCK AtaStatusBlock; EFI_ATA_STATUS_BLOCK AtaStatusBlock;
BOOLEAN Read; BOOLEAN Read;
if (Packet == NULL || Packet->Cdb == NULL) { if ((Packet == NULL) || (Packet->Cdb == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -2124,6 +2130,7 @@ AhciPacketCommandExecute (
NULL NULL
); );
} }
return Status; return Status;
} }
@ -2221,6 +2228,7 @@ AhciCreateTransferDescriptor (
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
goto Error5; goto Error5;
} }
AhciRegisters->AhciRFisPciAddr = (EFI_AHCI_RECEIVED_FIS *)(UINTN)AhciRFisPciAddr; AhciRegisters->AhciRFisPciAddr = (EFI_AHCI_RECEIVED_FIS *)(UINTN)AhciRFisPciAddr;
// //
@ -2276,6 +2284,7 @@ AhciCreateTransferDescriptor (
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
goto Error3; goto Error3;
} }
AhciRegisters->AhciCmdListPciAddr = (EFI_AHCI_COMMAND_LIST *)(UINTN)AhciCmdListPciAddr; AhciRegisters->AhciCmdListPciAddr = (EFI_AHCI_COMMAND_LIST *)(UINTN)AhciCmdListPciAddr;
// //
@ -2332,6 +2341,7 @@ AhciCreateTransferDescriptor (
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
goto Error1; goto Error1;
} }
AhciRegisters->AhciCommandTablePciAddr = (EFI_AHCI_COMMAND_TABLE *)(UINTN)AhciCommandTablePciAddr; AhciRegisters->AhciCommandTablePciAddr = (EFI_AHCI_COMMAND_TABLE *)(UINTN)AhciCommandTablePciAddr;
return EFI_SUCCESS; return EFI_SUCCESS;
@ -2403,7 +2413,7 @@ AhciReadLogExt (
EFI_ATA_COMMAND_BLOCK AtaCommandBlock; EFI_ATA_COMMAND_BLOCK AtaCommandBlock;
EFI_ATA_STATUS_BLOCK AtaStatusBlock; EFI_ATA_STATUS_BLOCK AtaStatusBlock;
if (PciIo == NULL || AhciRegisters == NULL || Buffer == NULL) { if ((PciIo == NULL) || (AhciRegisters == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -2488,19 +2498,28 @@ AhciEnableDevSlp (
DEBUG ((DEBUG_INFO, "Port CMD/DEVSLP = %08x / %08x\n", PortCmd, PortDevSlp)); DEBUG ((DEBUG_INFO, "Port CMD/DEVSLP = %08x / %08x\n", PortCmd, PortDevSlp));
if (((PortDevSlp & AHCI_PORT_DEVSLP_DSP) == 0) || if (((PortDevSlp & AHCI_PORT_DEVSLP_DSP) == 0) ||
((PortCmd & (EFI_AHCI_PORT_CMD_HPCP | EFI_AHCI_PORT_CMD_MPSP)) != 0) ((PortCmd & (EFI_AHCI_PORT_CMD_HPCP | EFI_AHCI_PORT_CMD_MPSP)) != 0)
) { )
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
// //
// Do not enable DevSlp if the device doesn't support DevSlp // Do not enable DevSlp if the device doesn't support DevSlp
// //
DEBUG ((DEBUG_INFO, "IDENTIFY DEVICE: [77] = %04x, [78] = %04x, [79] = %04x\n", DEBUG ((
DEBUG_INFO,
"IDENTIFY DEVICE: [77] = %04x, [78] = %04x, [79] = %04x\n",
IdentifyData->AtaData.reserved_77, IdentifyData->AtaData.reserved_77,
IdentifyData->AtaData.serial_ata_features_supported, IdentifyData->AtaData.serial_ata_features_enabled)); IdentifyData->AtaData.serial_ata_features_supported,
IdentifyData->AtaData.serial_ata_features_enabled
));
if ((IdentifyData->AtaData.serial_ata_features_supported & BIT8) == 0) { if ((IdentifyData->AtaData.serial_ata_features_supported & BIT8) == 0) {
DEBUG ((DEBUG_INFO, "DevSlp feature is not supported for device at port [%d] PortMultiplier [%d]!\n", DEBUG ((
Port, PortMultiplier)); DEBUG_INFO,
"DevSlp feature is not supported for device at port [%d] PortMultiplier [%d]!\n",
Port,
PortMultiplier
));
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -2509,10 +2528,21 @@ AhciEnableDevSlp (
// //
if ((IdentifyData->AtaData.serial_ata_features_enabled & BIT8) != 0) { if ((IdentifyData->AtaData.serial_ata_features_enabled & BIT8) != 0) {
Status = AhciDeviceSetFeature ( Status = AhciDeviceSetFeature (
PciIo, AhciRegisters, Port, 0, ATA_SUB_CMD_ENABLE_SATA_FEATURE, 0x09, ATA_ATAPI_TIMEOUT PciIo,
AhciRegisters,
Port,
0,
ATA_SUB_CMD_ENABLE_SATA_FEATURE,
0x09,
ATA_ATAPI_TIMEOUT
); );
DEBUG ((DEBUG_INFO, "DevSlp set feature for device at port [%d] PortMultiplier [%d] - %r\n", DEBUG ((
Port, PortMultiplier, Status)); DEBUG_INFO,
"DevSlp set feature for device at port [%d] PortMultiplier [%d] - %r\n",
Port,
PortMultiplier,
Status
));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -2541,8 +2571,13 @@ AhciEnableDevSlp (
ZeroMem (&DevSlpTiming, sizeof (DevSlpTiming)); ZeroMem (&DevSlpTiming, sizeof (DevSlpTiming));
} else { } else {
CopyMem (&DevSlpTiming, &LogData[48], sizeof (DevSlpTiming)); CopyMem (&DevSlpTiming, &LogData[48], sizeof (DevSlpTiming));
DEBUG ((DEBUG_INFO, "DevSlpTiming: Supported(%d), Deto(%d), Madt(%d)\n", DEBUG ((
DevSlpTiming.Supported, DevSlpTiming.Deto, DevSlpTiming.Madt)); DEBUG_INFO,
"DevSlpTiming: Supported(%d), Deto(%d), Madt(%d)\n",
DevSlpTiming.Supported,
DevSlpTiming.Deto,
DevSlpTiming.Madt
));
} }
// //
@ -2574,11 +2609,16 @@ AhciEnableDevSlp (
} }
} }
AhciWriteReg (PciIo, Offset + EFI_AHCI_PORT_CMD, PortCmd); AhciWriteReg (PciIo, Offset + EFI_AHCI_PORT_CMD, PortCmd);
DEBUG ((DEBUG_INFO, "Enabled DevSlp feature at port [%d] PortMultiplier [%d], Port CMD/DEVSLP = %08x / %08x\n", DEBUG ((
Port, PortMultiplier, PortCmd, PortDevSlp)); DEBUG_INFO,
"Enabled DevSlp feature at port [%d] PortMultiplier [%d], Port CMD/DEVSLP = %08x / %08x\n",
Port,
PortMultiplier,
PortCmd,
PortDevSlp
));
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -2612,11 +2652,21 @@ AhciSpinUpDisk (
// Use SET_FEATURE subcommand to spin up the device. // Use SET_FEATURE subcommand to spin up the device.
// //
Status = AhciDeviceSetFeature ( Status = AhciDeviceSetFeature (
PciIo, AhciRegisters, Port, PortMultiplier, PciIo,
ATA_SUB_CMD_PUIS_SET_DEVICE_SPINUP, 0x00, ATA_SPINUP_TIMEOUT AhciRegisters,
Port,
PortMultiplier,
ATA_SUB_CMD_PUIS_SET_DEVICE_SPINUP,
0x00,
ATA_SPINUP_TIMEOUT
); );
DEBUG ((DEBUG_INFO, "CMD_PUIS_SET_DEVICE_SPINUP for device at port [%d] PortMultiplier [%d] - %r!\n", DEBUG ((
Port, PortMultiplier, Status)); DEBUG_INFO,
"CMD_PUIS_SET_DEVICE_SPINUP for device at port [%d] PortMultiplier [%d] - %r!\n",
Port,
PortMultiplier,
Status
));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -2649,8 +2699,13 @@ AhciSpinUpDisk (
ATA_SPINUP_TIMEOUT, ATA_SPINUP_TIMEOUT,
NULL NULL
); );
DEBUG ((DEBUG_INFO, "Read LBA 0 for device at port [%d] PortMultiplier [%d] - %r!\n", DEBUG ((
Port, PortMultiplier, Status)); DEBUG_INFO,
"Read LBA 0 for device at port [%d] PortMultiplier [%d] - %r!\n",
Port,
PortMultiplier,
Status
));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -2662,14 +2717,24 @@ AhciSpinUpDisk (
ZeroMem (IdentifyData, sizeof (*IdentifyData)); ZeroMem (IdentifyData, sizeof (*IdentifyData));
Status = AhciIdentify (PciIo, AhciRegisters, Port, PortMultiplier, IdentifyData); Status = AhciIdentify (PciIo, AhciRegisters, Port, PortMultiplier, IdentifyData);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Read IDD failed for device at port [%d] PortMultiplier [%d] - %r!\n", DEBUG ((
Port, PortMultiplier, Status)); DEBUG_ERROR,
"Read IDD failed for device at port [%d] PortMultiplier [%d] - %r!\n",
Port,
PortMultiplier,
Status
));
return Status; return Status;
} }
DEBUG ((DEBUG_INFO, "IDENTIFY DEVICE: [0] = %016x, [2] = %016x, [83] = %016x, [86] = %016x\n", DEBUG ((
IdentifyData->AtaData.config, IdentifyData->AtaData.specific_config, DEBUG_INFO,
IdentifyData->AtaData.command_set_supported_83, IdentifyData->AtaData.command_set_feature_enb_86)); "IDENTIFY DEVICE: [0] = %016x, [2] = %016x, [83] = %016x, [86] = %016x\n",
IdentifyData->AtaData.config,
IdentifyData->AtaData.specific_config,
IdentifyData->AtaData.command_set_supported_83,
IdentifyData->AtaData.command_set_feature_enb_86
));
// //
// Check if IDD is incomplete // Check if IDD is incomplete
// //
@ -2705,10 +2770,17 @@ AhciPuisEnable (
} else if (mAtaAtapiPolicy->PuisEnable == 1) { } else if (mAtaAtapiPolicy->PuisEnable == 1) {
Status = AhciDeviceSetFeature (PciIo, AhciRegisters, Port, PortMultiplier, ATA_SUB_CMD_ENABLE_PUIS, 0x00, ATA_ATAPI_TIMEOUT); Status = AhciDeviceSetFeature (PciIo, AhciRegisters, Port, PortMultiplier, ATA_SUB_CMD_ENABLE_PUIS, 0x00, ATA_ATAPI_TIMEOUT);
} }
DEBUG ((DEBUG_INFO, "%a PUIS feature at port [%d] PortMultiplier [%d] - %r!\n",
DEBUG ((
DEBUG_INFO,
"%a PUIS feature at port [%d] PortMultiplier [%d] - %r!\n",
(mAtaAtapiPolicy->PuisEnable == 0) ? "Disable" : ( (mAtaAtapiPolicy->PuisEnable == 0) ? "Disable" : (
(mAtaAtapiPolicy->PuisEnable == 1) ? "Enable" : "Skip" (mAtaAtapiPolicy->PuisEnable == 1) ? "Enable" : "Skip"
), Port, PortMultiplier, Status)); ),
Port,
PortMultiplier,
Status
));
return Status; return Status;
} }
@ -2785,9 +2857,11 @@ AhciModeInitialization (
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, DEBUG ((
DEBUG_WARN,
"AhciModeInitialization: failed to enable 64-bit DMA on 64-bit capable controller (%r)\n", "AhciModeInitialization: failed to enable 64-bit DMA on 64-bit capable controller (%r)\n",
Status)); Status
));
} }
} }
@ -2934,9 +3008,12 @@ AhciModeInitialization (
} }
DEBUG (( DEBUG ((
DEBUG_INFO, "IDENTIFY DEVICE: [0] = %016x, [2] = %016x, [83] = %016x, [86] = %016x\n", DEBUG_INFO,
Buffer.AtaData.config, Buffer.AtaData.specific_config, "IDENTIFY DEVICE: [0] = %016x, [2] = %016x, [83] = %016x, [86] = %016x\n",
Buffer.AtaData.command_set_supported_83, Buffer.AtaData.command_set_feature_enb_86 Buffer.AtaData.config,
Buffer.AtaData.specific_config,
Buffer.AtaData.command_set_supported_83,
Buffer.AtaData.command_set_feature_enb_86
)); ));
if ((Buffer.AtaData.config & BIT2) != 0) { if ((Buffer.AtaData.config & BIT2) != 0) {
// //
@ -2959,8 +3036,14 @@ AhciModeInitialization (
} else { } else {
continue; continue;
} }
DEBUG ((DEBUG_INFO, "port [%d] port multitplier [%d] has a [%a]\n",
Port, 0, DeviceType == EfiIdeCdrom ? "cdrom" : "harddisk")); DEBUG ((
DEBUG_INFO,
"port [%d] port multitplier [%d] has a [%a]\n",
Port,
0,
DeviceType == EfiIdeCdrom ? "cdrom" : "harddisk"
));
// //
// If the device is a hard disk, then try to enable S.M.A.R.T feature // If the device is a hard disk, then try to enable S.M.A.R.T feature

View File

@ -5,6 +5,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef __ATA_HC_AHCI_MODE_H__ #ifndef __ATA_HC_AHCI_MODE_H__
#define __ATA_HC_AHCI_MODE_H__ #define __ATA_HC_AHCI_MODE_H__
@ -393,4 +394,3 @@ AhciStopCommand (
); );
#endif #endif

View File

@ -274,6 +274,7 @@ AtaPassThruPassThruExecute (
default: default:
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
break; break;
case EfiAtaAhciMode: case EfiAtaAhciMode:
if (PortMultiplierPort == 0xFFFF) { if (PortMultiplierPort == 0xFFFF) {
@ -284,6 +285,7 @@ AtaPassThruPassThruExecute (
// //
PortMultiplierPort = 0; PortMultiplierPort = 0;
} }
switch (Protocol) { switch (Protocol) {
case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA: case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA:
Status = AhciNonDataTransfer ( Status = AhciNonDataTransfer (
@ -370,6 +372,7 @@ AtaPassThruPassThruExecute (
default: default:
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
break; break;
default: default:
@ -555,6 +558,7 @@ AtaAtapiPassThruSupported (
// //
return Status; return Status;
} }
// //
// Close the protocol because we don't use it here // Close the protocol because we don't use it here
// //
@ -605,6 +609,7 @@ AtaAtapiPassThruSupported (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Now further check the PCI header: Base class (offset 0x0B) and // Now further check the PCI header: Base class (offset 0x0B) and
// Sub Class (offset 0x0A). This controller should be an ATA controller // Sub Class (offset 0x0A). This controller should be an ATA controller
@ -799,8 +804,10 @@ AtaAtapiPassThruStart (
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&Controller, &Controller,
&gEfiAtaPassThruProtocolGuid, &(Instance->AtaPassThru), &gEfiAtaPassThruProtocolGuid,
&gEfiExtScsiPassThruProtocolGuid, &(Instance->ExtScsiPassThru), &(Instance->AtaPassThru),
&gEfiExtScsiPassThruProtocolGuid,
&(Instance->ExtScsiPassThru),
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -828,6 +835,7 @@ ErrorExit:
DestroyDeviceInfoList (Instance); DestroyDeviceInfoList (Instance);
FreePool (Instance); FreePool (Instance);
} }
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -891,8 +899,10 @@ AtaAtapiPassThruStop (
Status = gBS->UninstallMultipleProtocolInterfaces ( Status = gBS->UninstallMultipleProtocolInterfaces (
Controller, Controller,
&gEfiAtaPassThruProtocolGuid, &(Instance->AtaPassThru), &gEfiAtaPassThruProtocolGuid,
&gEfiExtScsiPassThruProtocolGuid, &(Instance->ExtScsiPassThru), &(Instance->AtaPassThru),
&gEfiExtScsiPassThruProtocolGuid,
&(Instance->ExtScsiPassThru),
NULL NULL
); );
@ -917,6 +927,7 @@ AtaAtapiPassThruStop (
gBS->CloseEvent (Instance->TimerEvent); gBS->CloseEvent (Instance->TimerEvent);
Instance->TimerEvent = NULL; Instance->TimerEvent = NULL;
} }
DestroyAsynTaskList (Instance, FALSE); DestroyAsynTaskList (Instance, FALSE);
// //
// Free allocated resource // Free allocated resource
@ -1022,13 +1033,15 @@ SearchDeviceInfoList (
// //
if ((Instance->Mode == EfiAtaAhciMode) && if ((Instance->Mode == EfiAtaAhciMode) &&
(DeviceInfo->Type == EfiIdeCdrom) && (DeviceInfo->Type == EfiIdeCdrom) &&
(PortMultiplier == 0xFF)) { (PortMultiplier == 0xFF))
{
PortMultiplier = 0xFFFF; PortMultiplier = 0xFFFF;
} }
if ((DeviceInfo->Type == DeviceType) && if ((DeviceInfo->Type == DeviceType) &&
(Port == DeviceInfo->Port) && (Port == DeviceInfo->Port) &&
(PortMultiplier == DeviceInfo->PortMultiplier)) { (PortMultiplier == DeviceInfo->PortMultiplier))
{
return Node; return Node;
} }
@ -1114,6 +1127,7 @@ DestroyDeviceInfoList (
if (DeviceInfo->IdentifyData != NULL) { if (DeviceInfo->IdentifyData != NULL) {
FreePool (DeviceInfo->IdentifyData); FreePool (DeviceInfo->IdentifyData);
} }
FreePool (DeviceInfo); FreePool (DeviceInfo);
} }
} }
@ -1145,7 +1159,8 @@ DestroyAsynTaskList (
// //
for (Entry = (&Instance->NonBlockingTaskList)->ForwardLink; for (Entry = (&Instance->NonBlockingTaskList)->ForwardLink;
Entry != (&Instance->NonBlockingTaskList); Entry != (&Instance->NonBlockingTaskList);
) { )
{
DelEntry = Entry; DelEntry = Entry;
Entry = Entry->ForwardLink; Entry = Entry->ForwardLink;
Task = ATA_NON_BLOCK_TASK_FROM_ENTRY (DelEntry); Task = ATA_NON_BLOCK_TASK_FROM_ENTRY (DelEntry);
@ -1155,9 +1170,11 @@ DestroyAsynTaskList (
Task->Packet->Asb->AtaStatus = 0x01; Task->Packet->Asb->AtaStatus = 0x01;
gBS->SignalEvent (Task->Event); gBS->SignalEvent (Task->Event);
} }
FreePool (Task); FreePool (Task);
} }
} }
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
} }
@ -1207,6 +1224,7 @@ EnumerateAttachedDevice (
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
goto Done; goto Done;
} }
break; break;
case PCI_CLASS_MASS_STORAGE_SATADPA: case PCI_CLASS_MASS_STORAGE_SATADPA:
// //
@ -1335,7 +1353,8 @@ AtaPassThruPassThru (
// convert the transfer length from sector count to byte. // convert the transfer length from sector count to byte.
// //
if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) && if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) &&
(Packet->InTransferLength != 0)) { (Packet->InTransferLength != 0))
{
Packet->InTransferLength = Packet->InTransferLength * BlockSize; Packet->InTransferLength = Packet->InTransferLength * BlockSize;
} }
@ -1343,7 +1362,8 @@ AtaPassThruPassThru (
// convert the transfer length from sector count to byte. // convert the transfer length from sector count to byte.
// //
if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) && if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) &&
(Packet->OutTransferLength != 0)) { (Packet->OutTransferLength != 0))
{
Packet->OutTransferLength = Packet->OutTransferLength * BlockSize; Packet->OutTransferLength = Packet->OutTransferLength * BlockSize;
} }
@ -1353,7 +1373,8 @@ AtaPassThruPassThru (
// is returned. // is returned.
// //
if (((Packet->InTransferLength != 0) && (Packet->InTransferLength > MaxSectorCount * BlockSize)) || if (((Packet->InTransferLength != 0) && (Packet->InTransferLength > MaxSectorCount * BlockSize)) ||
((Packet->OutTransferLength != 0) && (Packet->OutTransferLength > MaxSectorCount * BlockSize))) { ((Packet->OutTransferLength != 0) && (Packet->OutTransferLength > MaxSectorCount * BlockSize)))
{
return EFI_BAD_BUFFER_SIZE; return EFI_BAD_BUFFER_SIZE;
} }
@ -1468,7 +1489,8 @@ AtaPassThruGetNextPort (
DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node); DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
if ((DeviceInfo->Type == EfiIdeHarddisk) && if ((DeviceInfo->Type == EfiIdeHarddisk) &&
(DeviceInfo->Port > *Port)){ (DeviceInfo->Port > *Port))
{
*Port = DeviceInfo->Port; *Port = DeviceInfo->Port;
goto Exit; goto Exit;
} }
@ -1571,7 +1593,8 @@ AtaPassThruGetNextDevice (
if ((DeviceInfo->Type == EfiIdeHarddisk) && if ((DeviceInfo->Type == EfiIdeHarddisk) &&
(DeviceInfo->Port == Port) && (DeviceInfo->Port == Port) &&
(DeviceInfo->PortMultiplier > *PortMultiplierPort)){ (DeviceInfo->PortMultiplier > *PortMultiplierPort))
{
*PortMultiplierPort = DeviceInfo->PortMultiplier; *PortMultiplierPort = DeviceInfo->PortMultiplier;
goto Exit; goto Exit;
} }
@ -1590,7 +1613,8 @@ AtaPassThruGetNextDevice (
DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node); DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
if ((DeviceInfo->Type == EfiIdeHarddisk) && if ((DeviceInfo->Type == EfiIdeHarddisk) &&
(DeviceInfo->Port == Port)){ (DeviceInfo->Port == Port))
{
*PortMultiplierPort = DeviceInfo->PortMultiplier; *PortMultiplierPort = DeviceInfo->PortMultiplier;
goto Exit; goto Exit;
} }
@ -1679,6 +1703,7 @@ AtaPassThruBuildDevicePath (
if (DevicePathNode == NULL) { if (DevicePathNode == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
DevicePathNode->Atapi.PrimarySecondary = (UINT8)Port; DevicePathNode->Atapi.PrimarySecondary = (UINT8)Port;
DevicePathNode->Atapi.SlaveMaster = (UINT8)PortMultiplierPort; DevicePathNode->Atapi.SlaveMaster = (UINT8)PortMultiplierPort;
DevicePathNode->Atapi.Lun = 0; DevicePathNode->Atapi.Lun = 0;
@ -1752,7 +1777,7 @@ AtaPassThruGetDevice (
// //
// Validate parameters passed in. // Validate parameters passed in.
// //
if (DevicePath == NULL || Port == NULL || PortMultiplierPort == NULL) { if ((DevicePath == NULL) || (Port == NULL) || (PortMultiplierPort == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1763,7 +1788,8 @@ AtaPassThruGetDevice (
((DevicePath->SubType != MSG_SATA_DP) && ((DevicePath->SubType != MSG_SATA_DP) &&
(DevicePath->SubType != MSG_ATAPI_DP)) || (DevicePath->SubType != MSG_ATAPI_DP)) ||
((DevicePathNodeLength (DevicePath) != sizeof (ATAPI_DEVICE_PATH)) && ((DevicePathNodeLength (DevicePath) != sizeof (ATAPI_DEVICE_PATH)) &&
(DevicePathNodeLength(DevicePath) != sizeof(SATA_DEVICE_PATH)))) { (DevicePathNodeLength (DevicePath) != sizeof (SATA_DEVICE_PATH))))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -2004,7 +2030,8 @@ ExtScsiPassThruPassThru (
// Don't support variable length CDB // Don't support variable length CDB
// //
if ((Packet->CdbLength != 6) && (Packet->CdbLength != 10) && if ((Packet->CdbLength != 6) && (Packet->CdbLength != 10) &&
(Packet->CdbLength != 12) && (Packet->CdbLength != 16)) { (Packet->CdbLength != 12) && (Packet->CdbLength != 16))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -2088,6 +2115,7 @@ ExtScsiPassThruPassThru (
// //
PortMultiplier = 0; PortMultiplier = 0;
} }
Status = AhciPacketCommandExecute (Instance->PciIo, &Instance->AhciRegisters, Port, PortMultiplier, Packet); Status = AhciPacketCommandExecute (Instance->PciIo, &Instance->AhciRegisters, Port, PortMultiplier, Packet);
break; break;
default: default:
@ -2125,12 +2153,15 @@ ExtScsiPassThruPassThru (
// skip the loop. // skip the loop.
// //
if ((PtrSenseData->Sense_Key == EFI_SCSI_SK_NO_SENSE) || if ((PtrSenseData->Sense_Key == EFI_SCSI_SK_NO_SENSE) ||
(SenseDataLen + sizeof (EFI_SCSI_SENSE_DATA) > Packet->SenseDataLength)) { (SenseDataLen + sizeof (EFI_SCSI_SENSE_DATA) > Packet->SenseDataLength))
{
SenseReq = FALSE; SenseReq = FALSE;
} }
} }
FreeAlignedPages (PtrSenseData, EFI_SIZE_TO_PAGES (sizeof (EFI_SCSI_SENSE_DATA))); FreeAlignedPages (PtrSenseData, EFI_SIZE_TO_PAGES (sizeof (EFI_SCSI_SENSE_DATA)));
} }
// //
// Update the SenseDataLength field to the data length received. // Update the SenseDataLength field to the data length received.
// //
@ -2180,7 +2211,7 @@ ExtScsiPassThruGetNextTargetLun (
Instance = EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This); Instance = EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
if (Target == NULL || Lun == NULL) { if ((Target == NULL) || (Lun == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -2205,7 +2236,8 @@ ExtScsiPassThruGetNextTargetLun (
// previous target id to see if it is returned by previous call. // previous target id to see if it is returned by previous call.
// //
if ((*Target16 != Instance->PreviousTargetId) || if ((*Target16 != Instance->PreviousTargetId) ||
(*Lun != Instance->PreviousLun)) { (*Lun != Instance->PreviousLun))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -2225,7 +2257,8 @@ ExtScsiPassThruGetNextTargetLun (
if ((DeviceInfo->Type == EfiIdeCdrom) && if ((DeviceInfo->Type == EfiIdeCdrom) &&
((Target8[0] < DeviceInfo->Port) || ((Target8[0] < DeviceInfo->Port) ||
((Target8[0] == DeviceInfo->Port) && ((Target8[0] == DeviceInfo->Port) &&
(Target8[1] < (UINT8)DeviceInfo->PortMultiplier)))) { (Target8[1] < (UINT8)DeviceInfo->PortMultiplier))))
{
Target8[0] = (UINT8)DeviceInfo->Port; Target8[0] = (UINT8)DeviceInfo->Port;
Target8[1] = (UINT8)DeviceInfo->PortMultiplier; Target8[1] = (UINT8)DeviceInfo->PortMultiplier;
goto Exit; goto Exit;
@ -2399,13 +2432,14 @@ ExtScsiPassThruGetTargetLun (
// //
// Validate parameters passed in. // Validate parameters passed in.
// //
if (DevicePath == NULL || Target == NULL || Lun == NULL) { if ((DevicePath == NULL) || (Target == NULL) || (Lun == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (*Target == NULL) { if (*Target == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Check whether the DevicePath belongs to SCSI_DEVICE_PATH // Check whether the DevicePath belongs to SCSI_DEVICE_PATH
// //
@ -2413,7 +2447,8 @@ ExtScsiPassThruGetTargetLun (
((DevicePath->SubType != MSG_ATAPI_DP) && ((DevicePath->SubType != MSG_ATAPI_DP) &&
(DevicePath->SubType != MSG_SATA_DP)) || (DevicePath->SubType != MSG_SATA_DP)) ||
((DevicePathNodeLength (DevicePath) != sizeof (ATAPI_DEVICE_PATH)) && ((DevicePathNodeLength (DevicePath) != sizeof (ATAPI_DEVICE_PATH)) &&
(DevicePathNodeLength(DevicePath) != sizeof(SATA_DEVICE_PATH)))) { (DevicePathNodeLength (DevicePath) != sizeof (SATA_DEVICE_PATH))))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -2506,6 +2541,7 @@ ExtScsiPassThruResetTargetLun (
if (Lun != 0) { if (Lun != 0) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// The layout of Target array: // The layout of Target array:
// ________________________________________________________________________ // ________________________________________________________________________
@ -2568,7 +2604,7 @@ ExtScsiPassThruGetNextTarget (
Instance = EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This); Instance = EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
if (Target == NULL || *Target == NULL) { if ((Target == NULL) || (*Target == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -2607,7 +2643,8 @@ ExtScsiPassThruGetNextTarget (
if ((DeviceInfo->Type == EfiIdeCdrom) && if ((DeviceInfo->Type == EfiIdeCdrom) &&
((Target8[0] < DeviceInfo->Port) || ((Target8[0] < DeviceInfo->Port) ||
((Target8[0] == DeviceInfo->Port) && ((Target8[0] == DeviceInfo->Port) &&
(Target8[1] < (UINT8)DeviceInfo->PortMultiplier)))) { (Target8[1] < (UINT8)DeviceInfo->PortMultiplier))))
{
Target8[0] = (UINT8)DeviceInfo->Port; Target8[0] = (UINT8)DeviceInfo->Port;
Target8[1] = (UINT8)DeviceInfo->PortMultiplier; Target8[1] = (UINT8)DeviceInfo->PortMultiplier;
goto Exit; goto Exit;

View File

@ -5,6 +5,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef __ATA_ATAPI_PASS_THRU_H__ #ifndef __ATA_ATAPI_PASS_THRU_H__
#define __ATA_ATAPI_PASS_THRU_H__ #define __ATA_ATAPI_PASS_THRU_H__
@ -1296,4 +1297,3 @@ AtaPioDataInOut (
); );
#endif #endif

View File

@ -103,7 +103,6 @@ AtaAtapiPassThruComponentNameGetDriverName (
); );
} }
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -187,7 +186,7 @@ AtaAtapiPassThruComponentNameGetControllerName (
VOID *Interface; VOID *Interface;
ATA_ATAPI_PASS_THRU_INSTANCE *Instance; ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
if (Language == NULL || ControllerName == NULL) { if ((Language == NULL) || (ControllerName == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -166,7 +166,6 @@ IdeWritePortWMultiple (
Count, Count,
(UINT16 *)Buffer (UINT16 *)Buffer
); );
} }
/** /**
@ -203,7 +202,6 @@ IdeReadPortWMultiple (
Count, Count,
(UINT16 *)Buffer (UINT16 *)Buffer
); );
} }
/** /**
@ -284,6 +282,7 @@ DumpAllIdeRegisters (
DEBUG ((DEBUG_ERROR, "CheckRegisterStatus()-- %02x : Error : Address Mark Not Found\n", StatusBlock.AtaError)); DEBUG ((DEBUG_ERROR, "CheckRegisterStatus()-- %02x : Error : Address Mark Not Found\n", StatusBlock.AtaError));
} }
} }
DEBUG_CODE_END (); DEBUG_CODE_END ();
} }
@ -319,6 +318,7 @@ CheckStatusRegister (
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -381,11 +381,11 @@ DRQClear (
MicroSecondDelay (100); MicroSecondDelay (100);
Delay--; Delay--;
} while (InfiniteWait || (Delay > 0)); } while (InfiniteWait || (Delay > 0));
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
/** /**
This function is used to poll for the DRQ bit clear in the Alternate This function is used to poll for the DRQ bit clear in the Alternate
Status Register. DRQ is cleared when the device is finished Status Register. DRQ is cleared when the device is finished
@ -444,7 +444,6 @@ DRQClear2 (
MicroSecondDelay (100); MicroSecondDelay (100);
Delay--; Delay--;
} while (InfiniteWait || (Delay > 0)); } while (InfiniteWait || (Delay > 0));
return EFI_TIMEOUT; return EFI_TIMEOUT;
@ -516,6 +515,7 @@ DRQReady (
if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) {
return EFI_ABORTED; return EFI_ABORTED;
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -536,6 +536,7 @@ DRQReady (
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
/** /**
This function is used to poll for the DRQ bit set in the Alternate Status Register. This function is used to poll for the DRQ bit set in the Alternate Status Register.
DRQ is set when the device is ready to transfer data. So this function is called after DRQ is set when the device is ready to transfer data. So this function is called after
@ -600,6 +601,7 @@ DRQReady2 (
if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) {
return EFI_ABORTED; return EFI_ABORTED;
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -621,9 +623,6 @@ DRQReady2 (
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
/** /**
This function is used to poll for the BSY bit clear in the Status Register. BSY This function is used to poll for the BSY bit clear in the Status Register. BSY
is clear when the device is not busy. Every command must be sent after device is not busy. is clear when the device is not busy. Every command must be sent after device is not busy.
@ -672,13 +671,11 @@ WaitForBSYClear (
MicroSecondDelay (100); MicroSecondDelay (100);
Delay--; Delay--;
} while (InfiniteWait || (Delay > 0)); } while (InfiniteWait || (Delay > 0));
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
/** /**
Get IDE i/o port registers' base addresses by mode. Get IDE i/o port registers' base addresses by mode.
@ -764,8 +761,9 @@ GetIdeRegisterIoAddr (
// //
// The BARs should be of IO type // The BARs should be of IO type
// //
if ((PciData.Device.Bar[0] & BIT0) == 0 || if (((PciData.Device.Bar[0] & BIT0) == 0) ||
(PciData.Device.Bar[1] & BIT0) == 0) { ((PciData.Device.Bar[1] & BIT0) == 0))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -794,8 +792,9 @@ GetIdeRegisterIoAddr (
// //
// The BARs should be of IO type // The BARs should be of IO type
// //
if ((PciData.Device.Bar[2] & BIT0) == 0 || if (((PciData.Device.Bar[2] & BIT0) == 0) ||
(PciData.Device.Bar[3] & BIT0) == 0) { ((PciData.Device.Bar[3] & BIT0) == 0))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -820,7 +819,6 @@ GetIdeRegisterIoAddr (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Send ATA Ext command into device with NON_DATA protocol. Send ATA Ext command into device with NON_DATA protocol.
@ -1171,6 +1169,7 @@ AtaUdmStatusWait (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
break; break;
} }
// //
// Stall for 100 microseconds. // Stall for 100 microseconds.
// //
@ -1329,6 +1328,7 @@ AtaUdmaInOut (
// //
MicroSecondDelay (1000); MicroSecondDelay (1000);
} }
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
// //
@ -1503,6 +1503,7 @@ AtaUdmaInOut (
} else { } else {
RegisterValue &= ~((UINT8)BMIC_NREAD); RegisterValue &= ~((UINT8)BMIC_NREAD);
} }
IdeWritePortB (PciIo, IoPortForBmic, RegisterValue); IdeWritePortB (PciIo, IoPortForBmic, RegisterValue);
if (Task != NULL) { if (Task != NULL) {
@ -1528,13 +1529,13 @@ AtaUdmaInOut (
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
goto Exit; goto Exit;
} }
// //
// Set START bit of BMIC register // Set START bit of BMIC register
// //
RegisterValue = IdeReadPortB (PciIo, IoPortForBmic); RegisterValue = IdeReadPortB (PciIo, IoPortForBmic);
RegisterValue |= BMIC_START; RegisterValue |= BMIC_START;
IdeWritePortB (PciIo, IoPortForBmic, RegisterValue); IdeWritePortB (PciIo, IoPortForBmic, RegisterValue);
} }
// //
@ -1552,7 +1553,7 @@ AtaUdmaInOut (
// out, or a error has been happened, it needs to clear the register and free // out, or a error has been happened, it needs to clear the register and free
// buffer. // buffer.
// //
if ((Task == NULL) || Status != EFI_NOT_READY) { if ((Task == NULL) || (Status != EFI_NOT_READY)) {
// //
// Read BMIS register and clear ERROR and INTR bit // Read BMIS register and clear ERROR and INTR bit
// //
@ -1582,14 +1583,13 @@ AtaUdmaInOut (
// Stall for 10 milliseconds. // Stall for 10 milliseconds.
// //
MicroSecondDelay (10000); MicroSecondDelay (10000);
} }
Exit: Exit:
// //
// Free all allocated resource // Free all allocated resource
// //
if ((Task == NULL) || Status != EFI_NOT_READY) { if ((Task == NULL) || (Status != EFI_NOT_READY)) {
if (Task != NULL) { if (Task != NULL) {
PciIo->Unmap (PciIo, Task->TableMap); PciIo->Unmap (PciIo, Task->TableMap);
PciIo->FreeBuffer (PciIo, Task->PageCount, Task->MapBaseAddress); PciIo->FreeBuffer (PciIo, Task->PageCount, Task->MapBaseAddress);
@ -1646,6 +1646,7 @@ AtaPacketReadPendingData (
TempWordBuffer = IdeReadPortB (PciIo, IdeRegisters->AltOrDev); TempWordBuffer = IdeReadPortB (PciIo, IdeRegisters->AltOrDev);
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1897,7 +1898,6 @@ AtaPacketCommandExecute (
return Status; return Status;
} }
/** /**
Set the calculated Best transfer mode to a detected device. Set the calculated Best transfer mode to a detected device.
@ -2126,8 +2126,12 @@ IdeAtaSmartSupport (
// //
// S.M.A.R.T is not supported by the device // S.M.A.R.T is not supported by the device
// //
DEBUG ((DEBUG_INFO, "S.M.A.R.T feature is not supported at [%a] channel [%a] device!\n", DEBUG ((
(Channel == 1) ? "secondary" : "primary", (Device == 1) ? "slave" : "master")); DEBUG_INFO,
"S.M.A.R.T feature is not supported at [%a] channel [%a] device!\n",
(Channel == 1) ? "secondary" : "primary",
(Device == 1) ? "slave" : "master"
));
REPORT_STATUS_CODE ( REPORT_STATUS_CODE (
EFI_ERROR_CODE | EFI_ERROR_MINOR, EFI_ERROR_CODE | EFI_ERROR_MINOR,
(EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_NOTSUPPORTED) (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_NOTSUPPORTED)
@ -2137,7 +2141,6 @@ IdeAtaSmartSupport (
// Check if the feature is enabled. If not, then enable S.M.A.R.T. // Check if the feature is enabled. If not, then enable S.M.A.R.T.
// //
if ((IdentifyData->AtaData.command_set_feature_enb_85 & 0x0001) != 0x0001) { if ((IdentifyData->AtaData.command_set_feature_enb_85 & 0x0001) != 0x0001) {
REPORT_STATUS_CODE ( REPORT_STATUS_CODE (
EFI_PROGRESS_CODE, EFI_PROGRESS_CODE,
(EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_DISABLE) (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_DISABLE)
@ -2195,15 +2198,17 @@ IdeAtaSmartSupport (
} }
} }
DEBUG ((DEBUG_INFO, "Enabled S.M.A.R.T feature at [%a] channel [%a] device!\n", DEBUG ((
(Channel == 1) ? "secondary" : "primary", (Device == 1) ? "slave" : "master")); DEBUG_INFO,
"Enabled S.M.A.R.T feature at [%a] channel [%a] device!\n",
(Channel == 1) ? "secondary" : "primary",
(Device == 1) ? "slave" : "master"
));
} }
return; return;
} }
/** /**
Sends out an ATA Identify Command to the specified device. Sends out an ATA Identify Command to the specified device.
@ -2327,7 +2332,6 @@ AtaIdentifyPacket (
return Status; return Status;
} }
/** /**
This function is used for detect whether the IDE device exists in the This function is used for detect whether the IDE device exists in the
specified Channel as the specified Device Number. specified Channel as the specified Device Number.
@ -2453,9 +2457,13 @@ DetectAndConfigIdeDevice (
continue; continue;
} }
DEBUG ((DEBUG_INFO, "[%a] channel [%a] [%a] device\n", DEBUG ((
(IdeChannel == 1) ? "secondary" : "primary ", (IdeDevice == 1) ? "slave " : "master", DEBUG_INFO,
DeviceType == EfiIdeCdrom ? "cdrom " : "harddisk")); "[%a] channel [%a] [%a] device\n",
(IdeChannel == 1) ? "secondary" : "primary ",
(IdeDevice == 1) ? "slave " : "master",
DeviceType == EfiIdeCdrom ? "cdrom " : "harddisk"
));
// //
// If the device is a hard disk, then try to enable S.M.A.R.T feature // If the device is a hard disk, then try to enable S.M.A.R.T feature
// //
@ -2568,10 +2576,10 @@ DetectAndConfigIdeDevice (
REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_PC_ENABLE)); REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_PC_ENABLE));
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Initialize ATA host controller at IDE mode. Initialize ATA host controller at IDE mode.

View File

@ -5,6 +5,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef __ATA_HC_IDE_MODE_H__ #ifndef __ATA_HC_IDE_MODE_H__
#define __ATA_HC_IDE_MODE_H__ #define __ATA_HC_IDE_MODE_H__
@ -195,4 +196,3 @@ AtaPacketCommandExecute (
); );
#endif #endif

View File

@ -74,7 +74,9 @@ ATA_DEVICE gAtaDeviceTemplate = {
0, // Port 0, // Port
0, // PortMultiplierPort 0, // PortMultiplierPort
{ 0, }, // Packet { 0, }, // Packet
{{ 0}, }, // Acb {
{ 0 },
}, // Acb
NULL, // Asb NULL, // Asb
FALSE, // UdmaValid FALSE, // UdmaValid
FALSE, // Lba48Bit FALSE, // Lba48Bit
@ -129,7 +131,6 @@ FreeAlignedBuffer (
} }
} }
/** /**
Release all the resources allocated for the ATA device. Release all the resources allocated for the ATA device.
@ -155,6 +156,7 @@ ReleaseAtaResources (
if (AtaDevice->DevicePath != NULL) { if (AtaDevice->DevicePath != NULL) {
FreePool (AtaDevice->DevicePath); FreePool (AtaDevice->DevicePath);
} }
OldTpl = gBS->RaiseTPL (TPL_NOTIFY); OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
if (!IsListEmpty (&AtaDevice->AtaSubTaskList)) { if (!IsListEmpty (&AtaDevice->AtaSubTaskList)) {
// //
@ -162,7 +164,8 @@ ReleaseAtaResources (
// //
for (Entry = AtaDevice->AtaSubTaskList.ForwardLink; for (Entry = AtaDevice->AtaSubTaskList.ForwardLink;
Entry != (&AtaDevice->AtaSubTaskList); Entry != (&AtaDevice->AtaSubTaskList);
) { )
{
DelEntry = Entry; DelEntry = Entry;
Entry = Entry->ForwardLink; Entry = Entry->ForwardLink;
SubTask = ATA_ASYN_SUB_TASK_FROM_ENTRY (DelEntry); SubTask = ATA_ASYN_SUB_TASK_FROM_ENTRY (DelEntry);
@ -171,13 +174,15 @@ ReleaseAtaResources (
FreeAtaSubTask (SubTask); FreeAtaSubTask (SubTask);
} }
} }
if (!IsListEmpty (&AtaDevice->AtaTaskList)) { if (!IsListEmpty (&AtaDevice->AtaTaskList)) {
// //
// Free the Subtask list. // Free the Subtask list.
// //
for (Entry = AtaDevice->AtaTaskList.ForwardLink; for (Entry = AtaDevice->AtaTaskList.ForwardLink;
Entry != (&AtaDevice->AtaTaskList); Entry != (&AtaDevice->AtaTaskList);
) { )
{
DelEntry = Entry; DelEntry = Entry;
Entry = Entry->ForwardLink; Entry = Entry->ForwardLink;
AtaTask = ATA_ASYN_TASK_FROM_ENTRY (DelEntry); AtaTask = ATA_ASYN_TASK_FROM_ENTRY (DelEntry);
@ -186,11 +191,11 @@ ReleaseAtaResources (
FreePool (AtaTask); FreePool (AtaTask);
} }
} }
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
FreePool (AtaDevice); FreePool (AtaDevice);
} }
/** /**
Registers an ATA device. Registers an ATA device.
@ -275,6 +280,7 @@ RegisterAtaDevice (
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto Done; goto Done;
} }
AtaDevice->IdentifyData = AllocateAlignedBuffer (AtaDevice, sizeof (ATA_IDENTIFY_DATA)); AtaDevice->IdentifyData = AllocateAlignedBuffer (AtaDevice, sizeof (ATA_IDENTIFY_DATA));
if (AtaDevice->IdentifyData == NULL) { if (AtaDevice->IdentifyData == NULL) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
@ -368,6 +374,7 @@ RegisterAtaDevice (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Done; goto Done;
} }
DEBUG ((DEBUG_INFO, "Successfully Install Storage Security Protocol on the ATA device\n")); DEBUG ((DEBUG_INFO, "Successfully Install Storage Security Protocol on the ATA device\n"));
} }
@ -389,10 +396,10 @@ Done:
ReleaseAtaResources (AtaDevice); ReleaseAtaResources (AtaDevice);
DEBUG ((DEBUG_ERROR | DEBUG_INIT, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port, PortMultiplierPort, Status)); DEBUG ((DEBUG_ERROR | DEBUG_INIT, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port, PortMultiplierPort, Status));
} }
return Status; return Status;
} }
/** /**
Unregisters an ATA device. Unregisters an ATA device.
@ -533,8 +540,6 @@ UnregisterAtaDevice (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Tests to see if this driver supports a given controller. If a child device is provided, Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device. it further tests to see if this driver supports creating a handle for the specified child device.
@ -670,7 +675,6 @@ AtaBusDriverBindingSupported (
return Status; return Status;
} }
/** /**
Starts a device controller or a bus controller. Starts a device controller or a bus controller.
@ -780,7 +784,6 @@ AtaBusDriverBindingStart (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto ErrorExit; goto ErrorExit;
} }
} else { } else {
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
Controller, Controller,
@ -826,9 +829,11 @@ AtaBusDriverBindingStart (
// //
break; break;
} }
RegisterAtaDevice (AtaBusDriverData, Port, PortMultiplierPort); RegisterAtaDevice (AtaBusDriverData, Port, PortMultiplierPort);
} }
} }
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} else if (!IsDevicePathEnd (RemainingDevicePath)) { } else if (!IsDevicePathEnd (RemainingDevicePath)) {
Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort); Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort);
@ -859,10 +864,8 @@ ErrorExit:
); );
return Status; return Status;
} }
/** /**
Stops a device controller or a bus controller. Stops a device controller or a bus controller.
@ -935,7 +938,6 @@ AtaBusDriverBindingStop (
AllChildrenStopped = TRUE; AllChildrenStopped = TRUE;
for (Index = 0; Index < NumberOfChildren; Index++) { for (Index = 0; Index < NumberOfChildren; Index++) {
Status = UnregisterAtaDevice (This, Controller, ChildHandleBuffer[Index]); Status = UnregisterAtaDevice (This, Controller, ChildHandleBuffer[Index]);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
AllChildrenStopped = FALSE; AllChildrenStopped = FALSE;
@ -949,7 +951,6 @@ AtaBusDriverBindingStop (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Reset the Block Device. Reset the Block Device.
@ -986,7 +987,6 @@ AtaBlockIoReset (
return Status; return Status;
} }
/** /**
Read/Write BufferSize bytes from Lba from/into Buffer. Read/Write BufferSize bytes from Lba from/into Buffer.
@ -1057,6 +1057,7 @@ BlockIoReadWrite (
Token->TransactionStatus = EFI_SUCCESS; Token->TransactionStatus = EFI_SUCCESS;
gBS->SignalEvent (Token->Event); gBS->SignalEvent (Token->Event);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1071,7 +1072,7 @@ BlockIoReadWrite (
} }
IoAlign = Media->IoAlign; IoAlign = Media->IoAlign;
if (IoAlign > 0 && (((UINTN) Buffer & (IoAlign - 1)) != 0)) { if ((IoAlign > 0) && (((UINTN)Buffer & (IoAlign - 1)) != 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1087,7 +1088,6 @@ BlockIoReadWrite (
return Status; return Status;
} }
/** /**
Read BufferSize bytes from Lba into Buffer. Read BufferSize bytes from Lba into Buffer.
@ -1120,7 +1120,6 @@ AtaBlockIoReadBlocks (
return BlockIoReadWrite ((VOID *)This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, FALSE); return BlockIoReadWrite ((VOID *)This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, FALSE);
} }
/** /**
Write BufferSize bytes from Lba into Buffer. Write BufferSize bytes from Lba into Buffer.
@ -1154,7 +1153,6 @@ AtaBlockIoWriteBlocks (
return BlockIoReadWrite ((VOID *)This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, TRUE); return BlockIoReadWrite ((VOID *)This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, TRUE);
} }
/** /**
Flush the Block Device. Flush the Block Device.
@ -1255,7 +1253,6 @@ AtaBlockIoReadBlocksEx (
return BlockIoReadWrite ((VOID *)This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, FALSE); return BlockIoReadWrite ((VOID *)This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, FALSE);
} }
/** /**
Write BufferSize bytes from Lba into Buffer. Write BufferSize bytes from Lba into Buffer.
@ -1292,7 +1289,6 @@ AtaBlockIoWriteBlocksEx (
return BlockIoReadWrite ((VOID *)This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, TRUE); return BlockIoReadWrite ((VOID *)This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, TRUE);
} }
/** /**
Flush the Block Device. Flush the Block Device.
@ -1314,12 +1310,14 @@ AtaBlockIoFlushBlocksEx (
// //
// Signal event and return directly. // Signal event and return directly.
// //
if (Token != NULL && Token->Event != NULL) { if ((Token != NULL) && (Token->Event != NULL)) {
Token->TransactionStatus = EFI_SUCCESS; Token->TransactionStatus = EFI_SUCCESS;
gBS->SignalEvent (Token->Event); gBS->SignalEvent (Token->Event);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Provides inquiry information for the controller type. Provides inquiry information for the controller type.
@ -1347,7 +1345,6 @@ AtaDiskInfoInquiry (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
Provides identify information for the controller type. Provides identify information for the controller type.
@ -1384,12 +1381,12 @@ AtaDiskInfoIdentify (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
CopyMem (IdentifyData, AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA)); CopyMem (IdentifyData, AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));
} }
*IdentifyDataSize = sizeof (ATA_IDENTIFY_DATA); *IdentifyDataSize = sizeof (ATA_IDENTIFY_DATA);
return Status; return Status;
} }
/** /**
Provides sense data information for the controller type. Provides sense data information for the controller type.
@ -1419,7 +1416,6 @@ AtaDiskInfoSenseData (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
This function is used by the IDE bus driver to get controller information. This function is used by the IDE bus driver to get controller information.
@ -1538,7 +1534,7 @@ AtaStorageSecurityReceiveData (
EFI_TPL OldTpl; EFI_TPL OldTpl;
DEBUG ((DEBUG_INFO, "EFI Storage Security Protocol - Read\n")); DEBUG ((DEBUG_INFO, "EFI Storage Security Protocol - Read\n"));
if ((PayloadBuffer == NULL || PayloadTransferSize == NULL) && PayloadBufferSize != 0) { if (((PayloadBuffer == NULL) || (PayloadTransferSize == NULL)) && (PayloadBufferSize != 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -233,7 +233,6 @@ ResetAtaDevice (
IN ATA_DEVICE *AtaDevice IN ATA_DEVICE *AtaDevice
); );
/** /**
Discovers whether it is a valid ATA device. Discovers whether it is a valid ATA device.
@ -326,6 +325,7 @@ TrustTransferAtaDevice (
// //
// Protocol interface prototypes // Protocol interface prototypes
// //
/** /**
Tests to see if this driver supports a given controller. If a child device is provided, Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device. it further tests to see if this driver supports creating a handle for the specified child device.
@ -454,7 +454,6 @@ AtaBusDriverBindingStop (
IN EFI_HANDLE *ChildHandleBuffer IN EFI_HANDLE *ChildHandleBuffer
); );
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -502,7 +501,6 @@ AtaBusComponentNameGetDriverName (
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -581,7 +579,6 @@ AtaBusComponentNameGetControllerName (
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
); );
/** /**
Reset the Block Device. Reset the Block Device.
@ -600,7 +597,6 @@ AtaBlockIoReset (
IN BOOLEAN ExtendedVerification IN BOOLEAN ExtendedVerification
); );
/** /**
Read BufferSize bytes from Lba into Buffer. Read BufferSize bytes from Lba into Buffer.
@ -630,7 +626,6 @@ AtaBlockIoReadBlocks (
OUT VOID *Buffer OUT VOID *Buffer
); );
/** /**
Write BufferSize bytes from Lba into Buffer. Write BufferSize bytes from Lba into Buffer.
@ -661,7 +656,6 @@ AtaBlockIoWriteBlocks (
IN VOID *Buffer IN VOID *Buffer
); );
/** /**
Flush the Block Device. Flush the Block Device.
@ -824,7 +818,6 @@ AtaDiskInfoInquiry (
IN OUT UINT32 *InquiryDataSize IN OUT UINT32 *InquiryDataSize
); );
/** /**
Provides identify information for the controller type. Provides identify information for the controller type.
@ -851,7 +844,6 @@ AtaDiskInfoIdentify (
IN OUT UINT32 *IdentifyDataSize IN OUT UINT32 *IdentifyDataSize
); );
/** /**
Provides sense data information for the controller type. Provides sense data information for the controller type.
@ -878,7 +870,6 @@ AtaDiskInfoSenseData (
OUT UINT8 *SenseDataNumber OUT UINT8 *SenseDataNumber
); );
/** /**
This function is used by the IDE bus driver to get controller information. This function is used by the IDE bus driver to get controller information.

View File

@ -79,7 +79,6 @@ UINT8 mAtaTrustCommands[2][2] = {
} }
}; };
// //
// Look up table (Lba48Bit) for maximum transfer block number // Look up table (Lba48Bit) for maximum transfer block number
// //
@ -88,7 +87,6 @@ UINTN mMaxTransferBlockNumber[] = {
MAX_48BIT_TRANSFER_BLOCK_NUM MAX_48BIT_TRANSFER_BLOCK_NUM
}; };
/** /**
Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.PassThru(). Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.PassThru().
@ -159,7 +157,6 @@ AtaDevicePassThru (
return Status; return Status;
} }
/** /**
Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.ResetDevice(). Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.ResetDevice().
@ -196,7 +193,6 @@ ResetAtaDevice (
); );
} }
/** /**
Prints ATA model name to ATA device structure. Prints ATA model name to ATA device structure.
@ -226,10 +222,10 @@ PrintAtaModelName (
Destination[Index] = Source[Index + 1]; Destination[Index] = Source[Index + 1];
Destination[Index + 1] = Source[Index]; Destination[Index + 1] = Source[Index];
} }
AtaDevice->ModelName[MAX_MODEL_NAME_LEN] = L'\0'; AtaDevice->ModelName[MAX_MODEL_NAME_LEN] = L'\0';
} }
/** /**
Gets ATA device Capacity according to ATA 6. Gets ATA device Capacity according to ATA 6.
@ -275,7 +271,6 @@ GetAtapi6Capacity (
return Capacity; return Capacity;
} }
/** /**
Identifies ATA device via the Identify data. Identifies ATA device via the Identify data.
@ -362,14 +357,17 @@ IdentifyAtaDevice (
BlockMedia->LogicalBlocksPerPhysicalBlock); BlockMedia->LogicalBlocksPerPhysicalBlock);
} }
} }
// //
// Check logical block size // Check logical block size
// //
if ((PhyLogicSectorSupport & BIT12) != 0) { if ((PhyLogicSectorSupport & BIT12) != 0) {
BlockMedia->BlockSize = (UINT32)(((IdentifyData->logic_sector_size_hi << 16) | IdentifyData->logic_sector_size_lo) * sizeof (UINT16)); BlockMedia->BlockSize = (UINT32)(((IdentifyData->logic_sector_size_hi << 16) | IdentifyData->logic_sector_size_lo) * sizeof (UINT16));
} }
AtaDevice->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2; AtaDevice->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2;
} }
// //
// Get ATA model name from identify data structure. // Get ATA model name from identify data structure.
// //
@ -378,7 +376,6 @@ IdentifyAtaDevice (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Discovers whether it is a valid ATA device. Discovers whether it is a valid ATA device.
@ -570,6 +567,7 @@ FreeAtaSubTask (
if (Task->Packet.Asb != NULL) { if (Task->Packet.Asb != NULL) {
FreeAlignedBuffer (Task->Packet.Asb, sizeof (EFI_ATA_STATUS_BLOCK)); FreeAlignedBuffer (Task->Packet.Asb, sizeof (EFI_ATA_STATUS_BLOCK));
} }
if (Task->Packet.Acb != NULL) { if (Task->Packet.Acb != NULL) {
FreePool (Task->Packet.Acb); FreePool (Task->Packet.Acb);
} }
@ -614,6 +612,7 @@ AtaTerminateNonBlockingTask (
Entry = RemoveEntryList (Entry); Entry = RemoveEntryList (Entry);
FreePool (AtaTask); FreePool (AtaTask);
} }
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
do { do {
@ -702,7 +701,6 @@ AtaNonBlockingCallBack (
FreePool (Task->UnsignalledEventCount); FreePool (Task->UnsignalledEventCount);
FreePool (Task->IsError); FreePool (Task->IsError);
// //
// Finish all subtasks and move to the next task in AtaTaskList. // Finish all subtasks and move to the next task in AtaTaskList.
// //
@ -723,6 +721,7 @@ AtaNonBlockingCallBack (
AtaTask->Token->TransactionStatus = Status; AtaTask->Token->TransactionStatus = Status;
gBS->SignalEvent (AtaTask->Token->Event); gBS->SignalEvent (AtaTask->Token->Event);
} }
RemoveEntryList (Entry); RemoveEntryList (Entry);
FreePool (AtaTask); FreePool (AtaTask);
} }
@ -813,6 +812,7 @@ AccessAtaDevice(
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
AtaTask->AtaDevice = AtaDevice; AtaTask->AtaDevice = AtaDevice;
AtaTask->Buffer = Buffer; AtaTask->Buffer = Buffer;
AtaTask->IsWrite = IsWrite; AtaTask->IsWrite = IsWrite;
@ -825,6 +825,7 @@ AccessAtaDevice(
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
Token->TransactionStatus = EFI_SUCCESS; Token->TransactionStatus = EFI_SUCCESS;
@ -838,6 +839,7 @@ AccessAtaDevice(
FreePool (EventCount); FreePool (EventCount);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
DEBUG ((DEBUG_BLKIO, "Allocation IsError Addr=%x\n", IsError)); DEBUG ((DEBUG_BLKIO, "Allocation IsError Addr=%x\n", IsError));
*IsError = FALSE; *IsError = FALSE;
TempCount = (NumberOfBlocks + MaxTransferBlockNumber - 1) / MaxTransferBlockNumber; TempCount = (NumberOfBlocks + MaxTransferBlockNumber - 1) / MaxTransferBlockNumber;
@ -943,6 +945,7 @@ EXIT:
if (SubEvent != NULL) { if (SubEvent != NULL) {
gBS->CloseEvent (SubEvent); gBS->CloseEvent (SubEvent);
} }
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
} }
} }
@ -1012,6 +1015,7 @@ TrustTransferAtaDevice (
} else { } else {
Acb->AtaCommand = mAtaTrustCommands[AtaDevice->UdmaValid][IsTrustSend]; Acb->AtaCommand = mAtaTrustCommands[AtaDevice->UdmaValid][IsTrustSend];
} }
Acb->AtaFeatures = SecurityProtocolId; Acb->AtaFeatures = SecurityProtocolId;
Acb->AtaSectorCount = (UINT8)(TransferLength / 512); Acb->AtaSectorCount = (UINT8)(TransferLength / 512);
Acb->AtaSectorNumber = (UINT8)((TransferLength / 512) >> 8); Acb->AtaSectorNumber = (UINT8)((TransferLength / 512) >> 8);
@ -1046,6 +1050,7 @@ TrustTransferAtaDevice (
FreePool (Buffer); FreePool (Buffer);
Buffer = NewBuffer; Buffer = NewBuffer;
} }
Packet->OutDataBuffer = Buffer; Packet->OutDataBuffer = Buffer;
Packet->OutTransferLength = (UINT32)TransferLength; Packet->OutTransferLength = (UINT32)TransferLength;
Packet->Protocol = mAtaPassThruCmdProtocols[AtaDevice->UdmaValid][IsTrustSend]; Packet->Protocol = mAtaPassThruCmdProtocols[AtaDevice->UdmaValid][IsTrustSend];
@ -1054,6 +1059,7 @@ TrustTransferAtaDevice (
Packet->InTransferLength = (UINT32)TransferLength; Packet->InTransferLength = (UINT32)TransferLength;
Packet->Protocol = mAtaPassThruCmdProtocols[AtaDevice->UdmaValid][IsTrustSend]; Packet->Protocol = mAtaPassThruCmdProtocols[AtaDevice->UdmaValid][IsTrustSend];
} }
Packet->Length = EFI_ATA_PASS_THRU_LENGTH_BYTES; Packet->Length = EFI_ATA_PASS_THRU_LENGTH_BYTES;
Packet->Timeout = Timeout; Packet->Timeout = Timeout;
@ -1063,5 +1069,6 @@ TrustTransferAtaDevice (
*TransferLengthOut = Packet->InTransferLength; *TransferLengthOut = Packet->InTransferLength;
} }
} }
return Status; return Status;
} }

View File

@ -24,7 +24,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mAtaBusControllerNameTabl
{ NULL, NULL } { NULL, NULL }
}; };
// //
// EFI Component Name Protocol // EFI Component Name Protocol
// //
@ -99,7 +98,6 @@ AtaBusComponentNameGetDriverName (
); );
} }
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -205,6 +203,7 @@ AtaBusComponentNameGetControllerName (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Get the child context // Get the child context
// //
@ -219,9 +218,11 @@ AtaBusComponentNameGetControllerName (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (BlockIo); AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (BlockIo);
ControllerNameTable = AtaDevice->ControllerNameTable; ControllerNameTable = AtaDevice->ControllerNameTable;
} }
return LookupUnicodeString2 ( return LookupUnicodeString2 (
Language, Language,
This->SupportedLanguages, This->SupportedLanguages,

View File

@ -66,7 +66,8 @@ VENDOR_DEVICE_PATH gVendorDevicePathTemplate = {
(UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8) (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
} }
}, },
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }} { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
}
}; };
// //
@ -291,7 +292,8 @@ CheckRemainingDevicePath (
// //
while (!IsDevicePathEnd (SystemDevicePath)) { while (!IsDevicePathEnd (SystemDevicePath)) {
if ((DevicePathType (SystemDevicePath) == HARDWARE_DEVICE_PATH) && if ((DevicePathType (SystemDevicePath) == HARDWARE_DEVICE_PATH) &&
(DevicePathSubType (SystemDevicePath) == HW_VENDOR_DP)) { (DevicePathSubType (SystemDevicePath) == HW_VENDOR_DP))
{
// //
// Check if vendor device path is same between system device path and remaining device path // Check if vendor device path is same between system device path and remaining device path
// //
@ -301,31 +303,37 @@ CheckRemainingDevicePath (
// //
SystemDevicePath = NextDevicePathNode (SystemDevicePath); SystemDevicePath = NextDevicePathNode (SystemDevicePath);
if ((DevicePathType (SystemDevicePath) == HARDWARE_DEVICE_PATH) && if ((DevicePathType (SystemDevicePath) == HARDWARE_DEVICE_PATH) &&
(DevicePathSubType (SystemDevicePath) == HW_CONTROLLER_DP)) { (DevicePathSubType (SystemDevicePath) == HW_CONTROLLER_DP))
{
SystemHasControllerNode = TRUE; SystemHasControllerNode = TRUE;
SystemControllerNumber = ((CONTROLLER_DEVICE_PATH *)SystemDevicePath)->ControllerNumber; SystemControllerNumber = ((CONTROLLER_DEVICE_PATH *)SystemDevicePath)->ControllerNumber;
} else { } else {
SystemHasControllerNode = FALSE; SystemHasControllerNode = FALSE;
SystemControllerNumber = 0; SystemControllerNumber = 0;
} }
if (((SystemHasControllerNode) && (!RemainingHasControllerNode) && (SystemControllerNumber == 0)) || if (((SystemHasControllerNode) && (!RemainingHasControllerNode) && (SystemControllerNumber == 0)) ||
((!SystemHasControllerNode) && (RemainingHasControllerNode) && (RemainingControllerNumber == 0)) || ((!SystemHasControllerNode) && (RemainingHasControllerNode) && (RemainingControllerNumber == 0)) ||
((SystemHasControllerNode) && (RemainingHasControllerNode) && (SystemControllerNumber == RemainingControllerNumber)) || ((SystemHasControllerNode) && (RemainingHasControllerNode) && (SystemControllerNumber == RemainingControllerNumber)) ||
((!SystemHasControllerNode) && (!RemainingHasControllerNode))) { ((!SystemHasControllerNode) && (!RemainingHasControllerNode)))
{
DEBUG ((DEBUG_ERROR, "This I2C device has been already started.\n")); DEBUG ((DEBUG_ERROR, "This I2C device has been already started.\n"));
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
break; break;
} }
} }
} }
SystemDevicePath = NextDevicePathNode (SystemDevicePath); SystemDevicePath = NextDevicePathNode (SystemDevicePath);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
} }
} }
} }
FreePool (OpenInfoBuffer); FreePool (OpenInfoBuffer);
return Status; return Status;
} }
@ -442,16 +450,19 @@ I2cBusDriverSupported (
// Check if the first node of RemainingDevicePath is a hardware vendor device path // Check if the first node of RemainingDevicePath is a hardware vendor device path
// //
if ((DevicePathType (RemainingDevicePath) != HARDWARE_DEVICE_PATH) || if ((DevicePathType (RemainingDevicePath) != HARDWARE_DEVICE_PATH) ||
(DevicePathSubType (RemainingDevicePath) != HW_VENDOR_DP)) { (DevicePathSubType (RemainingDevicePath) != HW_VENDOR_DP))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
// //
// Check if the second node of RemainingDevicePath is a controller node // Check if the second node of RemainingDevicePath is a controller node
// //
DevPathNode = NextDevicePathNode (RemainingDevicePath); DevPathNode = NextDevicePathNode (RemainingDevicePath);
if (!IsDevicePathEnd (DevPathNode)) { if (!IsDevicePathEnd (DevPathNode)) {
if ((DevicePathType (DevPathNode) != HARDWARE_DEVICE_PATH) || if ((DevicePathType (DevPathNode) != HARDWARE_DEVICE_PATH) ||
(DevicePathSubType (DevPathNode) != HW_CONTROLLER_DP)) { (DevicePathSubType (DevPathNode) != HW_CONTROLLER_DP))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} else { } else {
RemainingHasControllerNode = TRUE; RemainingHasControllerNode = TRUE;
@ -481,10 +492,10 @@ I2cBusDriverSupported (
); );
} }
if (Status == EFI_ALREADY_STARTED) { if (Status == EFI_ALREADY_STARTED) {
if ((RemainingDevicePath == NULL) || if ((RemainingDevicePath == NULL) ||
((RemainingDevicePath != NULL) && IsDevicePathEnd (RemainingDevicePath))) { ((RemainingDevicePath != NULL) && IsDevicePathEnd (RemainingDevicePath)))
{
// //
// If RemainingDevicePath is NULL or is the End of Device Path Node, return EFI_SUCCESS. // If RemainingDevicePath is NULL or is the End of Device Path Node, return EFI_SUCCESS.
// //
@ -735,7 +746,6 @@ Error:
return Status; return Status;
} }
/** /**
Stops a device controller or a bus controller. Stops a device controller or a bus controller.
@ -818,13 +828,13 @@ I2cBusDriverStop (
// //
FreePool (I2cBusContext); FreePool (I2cBusContext);
} }
return Status; return Status;
} }
AllChildrenStopped = TRUE; AllChildrenStopped = TRUE;
for (Index = 0; Index < NumberOfChildren; Index++) { for (Index = 0; Index < NumberOfChildren; Index++) {
Status = UnRegisterI2cDevice (This, Controller, ChildHandleBuffer[Index]); Status = UnRegisterI2cDevice (This, Controller, ChildHandleBuffer[Index]);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
AllChildrenStopped = FALSE; AllChildrenStopped = FALSE;
@ -834,6 +844,7 @@ I2cBusDriverStop (
if (!AllChildrenStopped) { if (!AllChildrenStopped) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -884,7 +895,8 @@ RegisterI2cDevice (
// //
DevPathNode = NextDevicePathNode (RemainingDevicePath); DevPathNode = NextDevicePathNode (RemainingDevicePath);
if ((DevicePathType (DevPathNode) == HARDWARE_DEVICE_PATH) && if ((DevicePathType (DevPathNode) == HARDWARE_DEVICE_PATH) &&
(DevicePathSubType(DevPathNode) == HW_CONTROLLER_DP)) { (DevicePathSubType (DevPathNode) == HW_CONTROLLER_DP))
{
// //
// RemainingDevicePath != NULL and RemainingDevicePath contains Controller Node, // RemainingDevicePath != NULL and RemainingDevicePath contains Controller Node,
// add Controller Node to Device Path on child handle. // add Controller Node to Device Path on child handle.
@ -908,12 +920,13 @@ RegisterI2cDevice (
// Get the next I2C device // Get the next I2C device
// //
Status = I2cBusContext->I2cEnumerate->Enumerate (I2cBusContext->I2cEnumerate, &Device); Status = I2cBusContext->I2cEnumerate->Enumerate (I2cBusContext->I2cEnumerate, &Device);
if (EFI_ERROR (Status) || Device == NULL) { if (EFI_ERROR (Status) || (Device == NULL)) {
if (RemainingDevicePath != NULL) { if (RemainingDevicePath != NULL) {
Status = EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
} else { } else {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
break; break;
} }
@ -937,14 +950,16 @@ RegisterI2cDevice (
// Get the next I2C device // Get the next I2C device
// //
Status = I2cBusContext->I2cEnumerate->Enumerate (I2cBusContext->I2cEnumerate, &TempDevice); Status = I2cBusContext->I2cEnumerate->Enumerate (I2cBusContext->I2cEnumerate, &TempDevice);
if (EFI_ERROR (Status) || TempDevice == NULL) { if (EFI_ERROR (Status) || (TempDevice == NULL)) {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
break; break;
} }
if (CompareGuid (Device->DeviceGuid, TempDevice->DeviceGuid)) { if (CompareGuid (Device->DeviceGuid, TempDevice->DeviceGuid)) {
Count++; Count++;
} }
} }
if (Count == 1) { if (Count == 1) {
// //
// RemainingDevicePath == NULL and only DeviceIndex 0 is present on the I2C bus, // RemainingDevicePath == NULL and only DeviceIndex 0 is present on the I2C bus,
@ -958,7 +973,8 @@ RegisterI2cDevice (
// Find I2C device reported in Remaining Device Path // Find I2C device reported in Remaining Device Path
// //
if ((!CompareGuid (&((VENDOR_DEVICE_PATH *)RemainingDevicePath)->Guid, Device->DeviceGuid)) || if ((!CompareGuid (&((VENDOR_DEVICE_PATH *)RemainingDevicePath)->Guid, Device->DeviceGuid)) ||
(RemainingPathDeviceIndex != Device->DeviceIndex)) { (RemainingPathDeviceIndex != Device->DeviceIndex))
{
continue; continue;
} }
} }
@ -1001,7 +1017,8 @@ RegisterI2cDevice (
&I2cDeviceContext->I2cIo, &I2cDeviceContext->I2cIo,
&gEfiDevicePathProtocolGuid, &gEfiDevicePathProtocolGuid,
I2cDeviceContext->DevicePath, I2cDeviceContext->DevicePath,
NULL ); NULL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
// //
// Free resources for this I2C device // Free resources for this I2C device
@ -1048,7 +1065,6 @@ RegisterI2cDevice (
return Status; return Status;
} }
/** /**
Queue an I2C transaction for execution on the I2C device. Queue an I2C transaction for execution on the I2C device.
@ -1373,7 +1389,6 @@ InitializeI2cBus(
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;
} }

View File

@ -31,10 +31,10 @@ InitializeI2c(
// Install driver model protocol(s). // Install driver model protocol(s).
// //
Status = InitializeI2cHost (ImageHandle, SystemTable); Status = InitializeI2cHost (ImageHandle, SystemTable);
if ( !EFI_ERROR ( Status )) if ( !EFI_ERROR (Status)) {
{
Status = InitializeI2cBus (ImageHandle, SystemTable); Status = InitializeI2cBus (ImageHandle, SystemTable);
} }
return Status; return Status;
} }
@ -65,5 +65,6 @@ I2cUnload (
if ( !EFI_ERROR (Status)) { if ( !EFI_ERROR (Status)) {
Status = I2cHostUnload (ImageHandle); Status = I2cHostUnload (ImageHandle);
} }
return Status; return Status;
} }

View File

@ -543,8 +543,8 @@ I2cHostDriverStop (
// //
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
if ( (!I2cHostContext->I2cBusConfigurationManagementPending) if ( (!I2cHostContext->I2cBusConfigurationManagementPending)
&& IsListEmpty (&I2cHostContext->RequestList)) { && IsListEmpty (&I2cHostContext->RequestList))
{
// //
// Remove the I2C host protocol // Remove the I2C host protocol
// //
@ -842,6 +842,7 @@ I2cHostRequestEnable (
// //
gBS->RestoreTPL (TplPrevious); gBS->RestoreTPL (TplPrevious);
} }
return Status; return Status;
} }

View File

@ -91,7 +91,6 @@ IsaBusComponentNameGetDriverName (
); );
} }
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.

View File

@ -63,7 +63,6 @@ IsaBusComponentNameGetDriverName (
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.

View File

@ -137,8 +137,10 @@ IsaBusCreateChild (
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
ChildHandle, ChildHandle,
&gEfiIsaHcProtocolGuid, Private->IsaHc, &gEfiIsaHcProtocolGuid,
&gEfiCallerIdGuid, Child, Private->IsaHc,
&gEfiCallerIdGuid,
Child,
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -217,8 +219,10 @@ IsaBusDestroyChild (
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Status = gBS->UninstallMultipleProtocolInterfaces ( Status = gBS->UninstallMultipleProtocolInterfaces (
ChildHandle, ChildHandle,
&gEfiIsaHcProtocolGuid, Private->IsaHc, &gEfiIsaHcProtocolGuid,
&gEfiCallerIdGuid, Child, Private->IsaHc,
&gEfiCallerIdGuid,
Child,
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -324,7 +328,8 @@ IsaBusDriverBindingStart (
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&Controller, &Controller,
&gEfiIsaHcServiceBindingProtocolGuid, &Private->ServiceBinding, &gEfiIsaHcServiceBindingProtocolGuid,
&Private->ServiceBinding,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -379,7 +384,8 @@ IsaBusDriverBindingStop (
if (NumberOfChildren == 0) { if (NumberOfChildren == 0) {
Status = gBS->UninstallMultipleProtocolInterfaces ( Status = gBS->UninstallMultipleProtocolInterfaces (
Controller, Controller,
&gEfiIsaHcServiceBindingProtocolGuid, &Private->ServiceBinding, &gEfiIsaHcServiceBindingProtocolGuid,
&Private->ServiceBinding,
NULL NULL
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {

View File

@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// EFI Component Name Functions // EFI Component Name Functions
// //
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -58,7 +59,6 @@ Ps2KeyboardComponentNameGetDriverName (
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -137,7 +137,6 @@ Ps2KeyboardComponentNameGetControllerName (
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
); );
// //
// EFI Component Name Protocol // EFI Component Name Protocol
// //
@ -156,7 +155,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPs2KeyboardComponent
"en" "en"
}; };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPs2KeyboardDriverNameTable[] = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPs2KeyboardDriverNameTable[] = {
{ {
"eng;en", "eng;en",
@ -305,6 +303,7 @@ Ps2KeyboardComponentNameGetControllerName (
EFI_STATUS Status; EFI_STATUS Status;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn; EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
KEYBOARD_CONSOLE_IN_DEV *ConsoleIn; KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;
// //
// This is a device driver, so ChildHandle must be NULL. // This is a device driver, so ChildHandle must be NULL.
// //
@ -319,6 +318,7 @@ Ps2KeyboardComponentNameGetControllerName (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Get the device context // Get the device context
// //

View File

@ -13,9 +13,7 @@ struct {
UINT16 EfiScanCode; UINT16 EfiScanCode;
CHAR16 UnicodeChar; CHAR16 UnicodeChar;
CHAR16 ShiftUnicodeChar; CHAR16 ShiftUnicodeChar;
} } ConvertKeyboardScanCodeToEfiKey[] = {
ConvertKeyboardScanCodeToEfiKey[] = {
{ {
0x01, // Escape 0x01, // Escape
SCAN_ESC, SCAN_ESC,
@ -559,8 +557,6 @@ UINTN mWaitForValueTimeOut = KEYBOARD_WAITFORVALUE_TIMEOUT;
BOOLEAN mEnableMouseInterface; BOOLEAN mEnableMouseInterface;
/** /**
Return the count of scancode in the queue. Return the count of scancode in the queue.
@ -608,6 +604,7 @@ GetScancodeBufHead (
if (GetScancodeBufCount (Queue) < Count) { if (GetScancodeBufCount (Queue) < Count) {
return EFI_NOT_READY; return EFI_NOT_READY;
} }
// //
// retrieve the values // retrieve the values
// //
@ -645,6 +642,7 @@ PopScancodeBufHead (
if (GetScancodeBufCount (Queue) < Count) { if (GetScancodeBufCount (Queue) < Count) {
return EFI_NOT_READY; return EFI_NOT_READY;
} }
// //
// Retrieve and remove the values // Retrieve and remove the values
// //
@ -806,13 +804,15 @@ KeyboardTimerHandler (
while ((KeyReadStatusRegister (ConsoleIn) & (KEYBOARD_STATUS_REGISTER_TRANSMIT_TIMEOUT|KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA)) == while ((KeyReadStatusRegister (ConsoleIn) & (KEYBOARD_STATUS_REGISTER_TRANSMIT_TIMEOUT|KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA)) ==
KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA
) { )
{
// //
// Read one byte of the scan code and store it into the memory buffer // Read one byte of the scan code and store it into the memory buffer
// //
Data = KeyReadDataRegister (ConsoleIn); Data = KeyReadDataRegister (ConsoleIn);
PushScancodeBufTail (&ConsoleIn->ScancodeQueue, Data); PushScancodeBufTail (&ConsoleIn->ScancodeQueue, Data);
} }
KeyGetchar (ConsoleIn); KeyGetchar (ConsoleIn);
// //
@ -901,6 +901,7 @@ KeyboardWrite (
if (RegEmptied == 0) { if (RegEmptied == 0) {
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
// //
// Write it // Write it
// //
@ -946,6 +947,7 @@ KeyboardCommand (
if (RegEmptied == 0) { if (RegEmptied == 0) {
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
// //
// issue the command // issue the command
// //
@ -1005,6 +1007,7 @@ KeyboardWaitForValue (
if (Data == Value) { if (Data == Value) {
Data = 1; Data = 1;
} }
// //
// Read from 8042 (multiple times if needed) // Read from 8042 (multiple times if needed)
// until the expected value appears // until the expected value appears
@ -1034,6 +1037,7 @@ KeyboardWaitForValue (
break; break;
} }
} }
// //
// Check results // Check results
// //
@ -1042,7 +1046,6 @@ KeyboardWaitForValue (
} else { } else {
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
} }
/** /**
@ -1191,6 +1194,7 @@ KeyGetchar (
return; return;
} }
} }
// //
// if we reach this position, scancodes for a key is in buffer now,pop them // if we reach this position, scancodes for a key is in buffer now,pop them
// //
@ -1207,13 +1211,13 @@ KeyGetchar (
// Check for special keys and update the driver state. // Check for special keys and update the driver state.
// //
switch (ScanCode) { switch (ScanCode) {
case SCANCODE_CTRL_MAKE: case SCANCODE_CTRL_MAKE:
if (Extend0) { if (Extend0) {
ConsoleIn->RightCtrl = TRUE; ConsoleIn->RightCtrl = TRUE;
} else { } else {
ConsoleIn->LeftCtrl = TRUE; ConsoleIn->LeftCtrl = TRUE;
} }
break; break;
case SCANCODE_CTRL_BREAK: case SCANCODE_CTRL_BREAK:
if (Extend0) { if (Extend0) {
@ -1221,6 +1225,7 @@ KeyGetchar (
} else { } else {
ConsoleIn->LeftCtrl = FALSE; ConsoleIn->LeftCtrl = FALSE;
} }
break; break;
case SCANCODE_ALT_MAKE: case SCANCODE_ALT_MAKE:
@ -1229,6 +1234,7 @@ KeyGetchar (
} else { } else {
ConsoleIn->LeftAlt = TRUE; ConsoleIn->LeftAlt = TRUE;
} }
break; break;
case SCANCODE_ALT_BREAK: case SCANCODE_ALT_BREAK:
if (Extend0) { if (Extend0) {
@ -1236,6 +1242,7 @@ KeyGetchar (
} else { } else {
ConsoleIn->LeftAlt = FALSE; ConsoleIn->LeftAlt = FALSE;
} }
break; break;
case SCANCODE_LEFT_SHIFT_MAKE: case SCANCODE_LEFT_SHIFT_MAKE:
@ -1248,12 +1255,14 @@ KeyGetchar (
ConsoleIn->LeftShift = TRUE; ConsoleIn->LeftShift = TRUE;
break; break;
} }
continue; continue;
case SCANCODE_LEFT_SHIFT_BREAK: case SCANCODE_LEFT_SHIFT_BREAK:
if (!Extend0) { if (!Extend0) {
ConsoleIn->LeftShift = FALSE; ConsoleIn->LeftShift = FALSE;
} }
break; break;
case SCANCODE_RIGHT_SHIFT_MAKE: case SCANCODE_RIGHT_SHIFT_MAKE:
@ -1288,11 +1297,13 @@ KeyGetchar (
if (Extend0) { if (Extend0) {
ConsoleIn->SysReq = TRUE; ConsoleIn->SysReq = TRUE;
} }
break; break;
case SCANCODE_SYS_REQ_BREAK: case SCANCODE_SYS_REQ_BREAK:
if (Extend0) { if (Extend0) {
ConsoleIn->SysReq = FALSE; ConsoleIn->SysReq = FALSE;
} }
break; break;
case SCANCODE_SYS_REQ_MAKE_WITH_ALT: case SCANCODE_SYS_REQ_MAKE_WITH_ALT:
@ -1315,6 +1326,7 @@ KeyGetchar (
ConsoleIn->ScrollLock = (BOOLEAN) !ConsoleIn->ScrollLock; ConsoleIn->ScrollLock = (BOOLEAN) !ConsoleIn->ScrollLock;
UpdateStatusLights (ConsoleIn); UpdateStatusLights (ConsoleIn);
} }
break; break;
} }
} }
@ -1334,8 +1346,9 @@ KeyGetchar (
// //
if ((ConsoleIn->LeftCtrl || ConsoleIn->RightCtrl) && if ((ConsoleIn->LeftCtrl || ConsoleIn->RightCtrl) &&
(ConsoleIn->LeftAlt || ConsoleIn->RightAlt) && (ConsoleIn->LeftAlt || ConsoleIn->RightAlt) &&
ScanCode == SCANCODE_DELETE_MAKE (ScanCode == SCANCODE_DELETE_MAKE)
) { )
{
gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL); gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
} }
@ -1349,28 +1362,28 @@ KeyGetchar (
// //
// Key Pad "/" shares the same scancode as that of "/" except Key Pad "/" has E0 prefix // Key Pad "/" shares the same scancode as that of "/" except Key Pad "/" has E0 prefix
// //
if (Extend0 && ScanCode == 0x35) { if (Extend0 && (ScanCode == 0x35)) {
KeyData.Key.UnicodeChar = L'/'; KeyData.Key.UnicodeChar = L'/';
KeyData.Key.ScanCode = SCAN_NULL; KeyData.Key.ScanCode = SCAN_NULL;
// //
// PAUSE shares the same scancode as that of NUM except PAUSE has E1 prefix // PAUSE shares the same scancode as that of NUM except PAUSE has E1 prefix
// //
} else if (Extend1 && ScanCode == SCANCODE_NUM_LOCK_MAKE) { } else if (Extend1 && (ScanCode == SCANCODE_NUM_LOCK_MAKE)) {
KeyData.Key.UnicodeChar = CHAR_NULL; KeyData.Key.UnicodeChar = CHAR_NULL;
KeyData.Key.ScanCode = SCAN_PAUSE; KeyData.Key.ScanCode = SCAN_PAUSE;
// //
// PAUSE shares the same scancode as that of SCROLL except PAUSE (CTRL pressed) has E0 prefix // PAUSE shares the same scancode as that of SCROLL except PAUSE (CTRL pressed) has E0 prefix
// //
} else if (Extend0 && ScanCode == SCANCODE_SCROLL_LOCK_MAKE) { } else if (Extend0 && (ScanCode == SCANCODE_SCROLL_LOCK_MAKE)) {
KeyData.Key.UnicodeChar = CHAR_NULL; KeyData.Key.UnicodeChar = CHAR_NULL;
KeyData.Key.ScanCode = SCAN_PAUSE; KeyData.Key.ScanCode = SCAN_PAUSE;
// //
// PRNT_SCRN shares the same scancode as that of Key Pad "*" except PRNT_SCRN has E0 prefix // PRNT_SCRN shares the same scancode as that of Key Pad "*" except PRNT_SCRN has E0 prefix
// //
} else if (Extend0 && ScanCode == SCANCODE_SYS_REQ_MAKE) { } else if (Extend0 && (ScanCode == SCANCODE_SYS_REQ_MAKE)) {
KeyData.Key.UnicodeChar = CHAR_NULL; KeyData.Key.UnicodeChar = CHAR_NULL;
KeyData.Key.ScanCode = SCAN_NULL; KeyData.Key.ScanCode = SCAN_NULL;
@ -1384,7 +1397,8 @@ KeyGetchar (
KeyData.Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].UnicodeChar; KeyData.Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].UnicodeChar;
if ((ConsoleIn->LeftShift || ConsoleIn->RightShift) && if ((ConsoleIn->LeftShift || ConsoleIn->RightShift) &&
(ConvertKeyboardScanCodeToEfiKey[Index].UnicodeChar != ConvertKeyboardScanCodeToEfiKey[Index].ShiftUnicodeChar)) { (ConvertKeyboardScanCodeToEfiKey[Index].UnicodeChar != ConvertKeyboardScanCodeToEfiKey[Index].ShiftUnicodeChar))
{
KeyData.Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].ShiftUnicodeChar; KeyData.Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].ShiftUnicodeChar;
// //
// Need not return associated shift state if a class of printable characters that // Need not return associated shift state if a class of printable characters that
@ -1392,16 +1406,18 @@ KeyGetchar (
// //
KeyData.KeyState.KeyShiftState &= ~(EFI_LEFT_SHIFT_PRESSED | EFI_RIGHT_SHIFT_PRESSED); KeyData.KeyState.KeyShiftState &= ~(EFI_LEFT_SHIFT_PRESSED | EFI_RIGHT_SHIFT_PRESSED);
} }
// //
// alphabetic key is affected by CapsLock State // alphabetic key is affected by CapsLock State
// //
if (ConsoleIn->CapsLock) { if (ConsoleIn->CapsLock) {
if (KeyData.Key.UnicodeChar >= L'a' && KeyData.Key.UnicodeChar <= L'z') { if ((KeyData.Key.UnicodeChar >= L'a') && (KeyData.Key.UnicodeChar <= L'z')) {
KeyData.Key.UnicodeChar = (UINT16)(KeyData.Key.UnicodeChar - L'a' + L'A'); KeyData.Key.UnicodeChar = (UINT16)(KeyData.Key.UnicodeChar - L'a' + L'A');
} 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 = (UINT16)(KeyData.Key.UnicodeChar - L'A' + L'a'); KeyData.Key.UnicodeChar = (UINT16)(KeyData.Key.UnicodeChar - L'A' + L'a');
} }
} }
break; break;
} }
} }
@ -1410,10 +1426,10 @@ KeyGetchar (
// //
// distinguish numeric key pad keys' 'up symbol' and 'down symbol' // distinguish numeric key pad keys' 'up symbol' and 'down symbol'
// //
if (ScanCode >= 0x47 && ScanCode <= 0x53) { if ((ScanCode >= 0x47) && (ScanCode <= 0x53)) {
if (ConsoleIn->NumLock && !(ConsoleIn->LeftShift || ConsoleIn->RightShift) && !Extend0) { if (ConsoleIn->NumLock && !(ConsoleIn->LeftShift || ConsoleIn->RightShift) && !Extend0) {
KeyData.Key.ScanCode = SCAN_NULL; KeyData.Key.ScanCode = SCAN_NULL;
} else if (ScanCode != 0x4a && ScanCode != 0x4e) { } else if ((ScanCode != 0x4a) && (ScanCode != 0x4e)) {
KeyData.Key.UnicodeChar = CHAR_NULL; KeyData.Key.UnicodeChar = CHAR_NULL;
} }
} }
@ -1421,7 +1437,7 @@ KeyGetchar (
// //
// If the key can not be converted then just return. // 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) { if (!ConsoleIn->IsSupportPartialKey) {
return; return;
} }
@ -1503,6 +1519,7 @@ InitKeyboard (
Status = KeyboardRead (ConsoleIn, &CommandByte); Status = KeyboardRead (ConsoleIn, &CommandByte);
TryTime++; TryTime++;
} }
// //
// Exceed the max try times. The device may be error. // Exceed the max try times. The device may be error.
// //
@ -1511,6 +1528,7 @@ InitKeyboard (
goto Done; goto Done;
} }
} }
// //
// We should disable mouse interface during the initialization process // We should disable mouse interface during the initialization process
// since mouse device output could block keyboard device output in the // since mouse device output could block keyboard device output in the
@ -1544,6 +1562,7 @@ InitKeyboard (
KeyboardError (ConsoleIn, L"\n\r"); KeyboardError (ConsoleIn, L"\n\r");
goto Done; goto Done;
} }
// //
// Test the mouse enabling bit // Test the mouse enabling bit
// //
@ -1597,16 +1616,17 @@ InitKeyboard (
goto Done; goto Done;
} }
} }
// //
// Don't enable mouse interface later // Don't enable mouse interface later
// //
mEnableMouseInterface = FALSE; mEnableMouseInterface = FALSE;
} }
if (Ps2Policy != NULL) { if (Ps2Policy != NULL) {
Ps2Policy->Ps2InitHardware (ConsoleIn->Handle); Ps2Policy->Ps2InitHardware (ConsoleIn->Handle);
} }
// //
// Write 8042 Command Byte, set System Flag // Write 8042 Command Byte, set System Flag
// While at the same time: // While at the same time:
@ -1692,6 +1712,7 @@ InitKeyboard (
); );
goto Done; goto Done;
} }
// //
// Keyboard reset with a BAT(Basic Assurance Test) // Keyboard reset with a BAT(Basic Assurance Test)
// //
@ -1706,6 +1727,7 @@ InitKeyboard (
KeyboardError (ConsoleIn, L"Some specific value not acquired from 8042 controller!\n\r"); KeyboardError (ConsoleIn, L"Some specific value not acquired from 8042 controller!\n\r");
goto Done; goto Done;
} }
// //
// wait for BAT completion code // wait for BAT completion code
// //
@ -1760,6 +1782,7 @@ InitKeyboard (
KeyboardError (ConsoleIn, L"Some specific value not acquired from 8042 controller!\n\r"); KeyboardError (ConsoleIn, L"Some specific value not acquired from 8042 controller!\n\r");
goto Done; goto Done;
} }
// //
if (Ps2Policy != NULL) { if (Ps2Policy != NULL) {
if ((Ps2Policy->KeyboardLight & EFI_KEYBOARD_CAPSLOCK) == EFI_KEYBOARD_CAPSLOCK) { if ((Ps2Policy->KeyboardLight & EFI_KEYBOARD_CAPSLOCK) == EFI_KEYBOARD_CAPSLOCK) {
@ -1774,6 +1797,7 @@ InitKeyboard (
ConsoleIn->ScrollLock = TRUE; ConsoleIn->ScrollLock = TRUE;
} }
} }
// //
// Update Keyboard Lights // Update Keyboard Lights
// //
@ -1783,6 +1807,7 @@ InitKeyboard (
goto Done; goto Done;
} }
} }
// //
// At last, we can now enable the mouse interface if appropriate // At last, we can now enable the mouse interface if appropriate
// //
@ -1804,10 +1829,8 @@ Done:
} else { } else {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
} }
/** /**
Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command
If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device
@ -1840,6 +1863,7 @@ CheckKeyboardConnect (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return FALSE; return FALSE;
} }
// //
// wait for 1s // wait for 1s
// //
@ -1860,4 +1884,3 @@ CheckKeyboardConnect (
return TRUE; return TRUE;
} }
} }

View File

@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#include "Ps2Keyboard.h" #include "Ps2Keyboard.h"
/** /**
@ -44,12 +43,14 @@ PopEfikeyBufHead (
if (IsEfikeyBufEmpty (Queue)) { if (IsEfikeyBufEmpty (Queue)) {
return EFI_NOT_READY; return EFI_NOT_READY;
} }
// //
// Retrieve and remove the values // Retrieve and remove the values
// //
if (KeyData != NULL) { if (KeyData != NULL) {
CopyMem (KeyData, &Queue->Buffer[Queue->Head], sizeof (EFI_KEY_DATA)); CopyMem (KeyData, &Queue->Buffer[Queue->Head], sizeof (EFI_KEY_DATA));
} }
Queue->Head = (Queue->Head + 1) % KEYBOARD_EFI_KEY_MAX_COUNT; Queue->Head = (Queue->Head + 1) % KEYBOARD_EFI_KEY_MAX_COUNT;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -72,6 +73,7 @@ PushEfikeyBufTail (
// //
PopEfikeyBufHead (Queue, NULL); PopEfikeyBufHead (Queue, NULL);
} }
CopyMem (&Queue->Buffer[Queue->Tail], KeyData, sizeof (EFI_KEY_DATA)); CopyMem (&Queue->Buffer[Queue->Tail], KeyData, sizeof (EFI_KEY_DATA));
Queue->Tail = (Queue->Tail + 1) % KEYBOARD_EFI_KEY_MAX_COUNT; Queue->Tail = (Queue->Tail + 1) % KEYBOARD_EFI_KEY_MAX_COUNT;
} }
@ -98,24 +100,27 @@ IsKeyRegistered (
ASSERT (RegsiteredData != NULL && InputData != NULL); ASSERT (RegsiteredData != NULL && InputData != NULL);
if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) || if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
(RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) { (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar))
{
return FALSE; return FALSE;
} }
// //
// 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 && if ((RegsiteredData->KeyState.KeyShiftState != 0) &&
RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) { (RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState))
{
return FALSE; return FALSE;
} }
if (RegsiteredData->KeyState.KeyToggleState != 0 &&
RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) { if ((RegsiteredData->KeyState.KeyToggleState != 0) &&
(RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState))
{
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
/** /**
@ -232,6 +237,7 @@ KeyboardEfiReset (
ConsoleIn->DevicePath ConsoleIn->DevicePath
); );
} }
// //
// Report the status If keyboard is locked // Report the status If keyboard is locked
// //
@ -280,20 +286,22 @@ KeyboardReadKeyStroke (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// If it is partial keystroke, skip it. // 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; continue;
} }
// //
// Translate the CTRL-Alpha characters to their corresponding control value // Translate the CTRL-Alpha characters to their corresponding control value
// (ctrl-a = 0x0001 through ctrl-Z = 0x001A) // (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') { if ((KeyData.Key.UnicodeChar >= L'a') && (KeyData.Key.UnicodeChar <= L'z')) {
KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar - L'a' + 1); 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); KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar - L'A' + 1);
} }
} }
@ -344,10 +352,11 @@ KeyboardWaitForKey (
&(ConsoleIn->EfiKeyQueue.Buffer[ConsoleIn->EfiKeyQueue.Head]), &(ConsoleIn->EfiKeyQueue.Buffer[ConsoleIn->EfiKeyQueue.Head]),
sizeof (EFI_KEY_DATA) sizeof (EFI_KEY_DATA)
); );
if (KeyData.Key.ScanCode == SCAN_NULL && KeyData.Key.UnicodeChar == CHAR_NULL) { if ((KeyData.Key.ScanCode == SCAN_NULL) && (KeyData.Key.UnicodeChar == CHAR_NULL)) {
PopEfikeyBufHead (&ConsoleIn->EfiKeyQueue, &KeyData); PopEfikeyBufHead (&ConsoleIn->EfiKeyQueue, &KeyData);
continue; continue;
} }
// //
// if there is pending value key, signal the event. // if there is pending value key, signal the event.
// //
@ -355,6 +364,7 @@ KeyboardWaitForKey (
break; break;
} }
} }
// //
// Leave critical section and return // Leave critical section and return
// //
@ -501,12 +511,15 @@ KeyboardSetState (
if ((*KeyToggleState & EFI_SCROLL_LOCK_ACTIVE) == EFI_SCROLL_LOCK_ACTIVE) { if ((*KeyToggleState & EFI_SCROLL_LOCK_ACTIVE) == EFI_SCROLL_LOCK_ACTIVE) {
ConsoleInDev->ScrollLock = TRUE; ConsoleInDev->ScrollLock = TRUE;
} }
if ((*KeyToggleState & EFI_NUM_LOCK_ACTIVE) == EFI_NUM_LOCK_ACTIVE) { if ((*KeyToggleState & EFI_NUM_LOCK_ACTIVE) == EFI_NUM_LOCK_ACTIVE) {
ConsoleInDev->NumLock = TRUE; ConsoleInDev->NumLock = TRUE;
} }
if ((*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == EFI_CAPS_LOCK_ACTIVE) { if ((*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == EFI_CAPS_LOCK_ACTIVE) {
ConsoleInDev->CapsLock = TRUE; ConsoleInDev->CapsLock = TRUE;
} }
if ((*KeyToggleState & EFI_KEY_STATE_EXPOSED) == EFI_KEY_STATE_EXPOSED) { if ((*KeyToggleState & EFI_KEY_STATE_EXPOSED) == EFI_KEY_STATE_EXPOSED) {
ConsoleInDev->IsSupportPartialKey = TRUE; ConsoleInDev->IsSupportPartialKey = TRUE;
} }
@ -523,7 +536,6 @@ Exit:
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
return Status; return Status;
} }
/** /**
@ -560,7 +572,7 @@ KeyboardRegisterKeyNotify (
KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify; KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
KEYBOARD_CONSOLE_IN_EX_NOTIFY *NewNotify; KEYBOARD_CONSOLE_IN_EX_NOTIFY *NewNotify;
if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) { if ((KeyData == NULL) || (NotifyHandle == NULL) || (KeyNotificationFunction == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -613,7 +625,6 @@ Exit:
// //
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
return Status; return Status;
} }
/** /**
@ -722,6 +733,7 @@ KeyNotifyProcessHandler (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) { for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {
CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE); CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) { if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {
@ -730,4 +742,3 @@ KeyNotifyProcessHandler (
} }
} }
} }

View File

@ -13,6 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// Function prototypes // Function prototypes
// //
/** /**
Test controller is a keyboard Controller. Test controller is a keyboard Controller.
@ -139,12 +140,13 @@ KbdControllerDriverSupported (
DevicePath = NextDevicePathNode (DevicePath); DevicePath = NextDevicePathNode (DevicePath);
} while (!IsDevicePathEnd (DevicePath)); } while (!IsDevicePathEnd (DevicePath));
if (DevicePathType (Acpi) != ACPI_DEVICE_PATH || if ((DevicePathType (Acpi) != ACPI_DEVICE_PATH) ||
(DevicePathSubType (Acpi) != ACPI_DP && DevicePathSubType (Acpi) != ACPI_EXTENDED_DP)) { ((DevicePathSubType (Acpi) != ACPI_DP) && (DevicePathSubType (Acpi) != ACPI_EXTENDED_DP)))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
if (Acpi->HID != EISA_PNP_ID (0x303) || Acpi->UID != 0) { if ((Acpi->HID != EISA_PNP_ID (0x303)) || (Acpi->UID != 0)) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -214,6 +216,7 @@ KbdControllerDriverStart (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Report that the keyboard is being enabled // Report that the keyboard is being enabled
// //
@ -237,6 +240,7 @@ KbdControllerDriverStart (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Allocate private data // Allocate private data
// //
@ -246,6 +250,7 @@ KbdControllerDriverStart (
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR; StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit; goto ErrorExit;
} }
// //
// Setup the device instance // Setup the device instance
// //
@ -304,6 +309,7 @@ KbdControllerDriverStart (
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR; StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit; goto ErrorExit;
} }
// //
// Setup the WaitForKeyEx event // Setup the WaitForKeyEx event
// //
@ -319,6 +325,7 @@ KbdControllerDriverStart (
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR; StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit; goto ErrorExit;
} }
// Setup a periodic timer, used for reading keystrokes at a fixed interval // Setup a periodic timer, used for reading keystrokes at a fixed interval
// //
Status = gBS->CreateEvent ( Status = gBS->CreateEvent (
@ -396,7 +403,6 @@ KbdControllerDriverStart (
FALSE FALSE
); );
// //
// Install protocol interfaces for the keyboard device. // Install protocol interfaces for the keyboard device.
// //
@ -434,16 +440,20 @@ ErrorExit:
if ((ConsoleIn != NULL) && (ConsoleIn->TimerEvent != NULL)) { if ((ConsoleIn != NULL) && (ConsoleIn->TimerEvent != NULL)) {
gBS->CloseEvent (ConsoleIn->TimerEvent); gBS->CloseEvent (ConsoleIn->TimerEvent);
} }
if ((ConsoleIn != NULL) && (ConsoleIn->ConInEx.WaitForKeyEx != NULL)) { if ((ConsoleIn != NULL) && (ConsoleIn->ConInEx.WaitForKeyEx != NULL)) {
gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx); gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx);
} }
if ((ConsoleIn != NULL) && (ConsoleIn->KeyNotifyProcessEvent != NULL)) { if ((ConsoleIn != NULL) && (ConsoleIn->KeyNotifyProcessEvent != NULL)) {
gBS->CloseEvent (ConsoleIn->KeyNotifyProcessEvent); gBS->CloseEvent (ConsoleIn->KeyNotifyProcessEvent);
} }
KbdFreeNotifyList (&ConsoleIn->NotifyList); KbdFreeNotifyList (&ConsoleIn->NotifyList);
if ((ConsoleIn != NULL) && (ConsoleIn->ControllerNameTable != NULL)) { if ((ConsoleIn != NULL) && (ConsoleIn->ControllerNameTable != NULL)) {
FreeUnicodeStringTable (ConsoleIn->ControllerNameTable); FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);
} }
// //
// Since there will be no timer handler for keyboard input any more, // Since there will be no timer handler for keyboard input any more,
// exhaust input data just in case there is still keyboard data left // exhaust input data just in case there is still keyboard data left
@ -451,7 +461,7 @@ ErrorExit:
if (ConsoleIn != NULL) { if (ConsoleIn != NULL) {
Status1 = EFI_SUCCESS; Status1 = EFI_SUCCESS;
while (!EFI_ERROR (Status1) && (Status != EFI_DEVICE_ERROR)) { while (!EFI_ERROR (Status1) && (Status != EFI_DEVICE_ERROR)) {
Status1 = KeyboardRead (ConsoleIn, &Data);; Status1 = KeyboardRead (ConsoleIn, &Data);
} }
} }
@ -511,6 +521,7 @@ KbdControllerDriverStop (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
Controller, Controller,
&gEfiSimpleTextInputExProtocolGuid, &gEfiSimpleTextInputExProtocolGuid,
@ -545,8 +556,9 @@ KbdControllerDriverStop (
// //
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
while (!EFI_ERROR (Status)) { while (!EFI_ERROR (Status)) {
Status = KeyboardRead (ConsoleIn, &Data);; Status = KeyboardRead (ConsoleIn, &Data);
} }
// //
// Uninstall the SimpleTextIn and SimpleTextInEx protocols // Uninstall the SimpleTextIn and SimpleTextInEx protocols
// //
@ -576,14 +588,17 @@ KbdControllerDriverStop (
gBS->CloseEvent ((ConsoleIn->ConIn).WaitForKey); gBS->CloseEvent ((ConsoleIn->ConIn).WaitForKey);
(ConsoleIn->ConIn).WaitForKey = NULL; (ConsoleIn->ConIn).WaitForKey = NULL;
} }
if (ConsoleIn->ConInEx.WaitForKeyEx != NULL) { if (ConsoleIn->ConInEx.WaitForKeyEx != NULL) {
gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx); gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx);
ConsoleIn->ConInEx.WaitForKeyEx = NULL; ConsoleIn->ConInEx.WaitForKeyEx = NULL;
} }
if (ConsoleIn->KeyNotifyProcessEvent != NULL) { if (ConsoleIn->KeyNotifyProcessEvent != NULL) {
gBS->CloseEvent (ConsoleIn->KeyNotifyProcessEvent); gBS->CloseEvent (ConsoleIn->KeyNotifyProcessEvent);
ConsoleIn->KeyNotifyProcessEvent = NULL; ConsoleIn->KeyNotifyProcessEvent = NULL;
} }
KbdFreeNotifyList (&ConsoleIn->NotifyList); KbdFreeNotifyList (&ConsoleIn->NotifyList);
FreeUnicodeStringTable (ConsoleIn->ControllerNameTable); FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);
gBS->FreePool (ConsoleIn); gBS->FreePool (ConsoleIn);
@ -609,6 +624,7 @@ KbdFreeNotifyList (
if (ListHead == NULL) { if (ListHead == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
while (!IsListEmpty (ListHead)) { while (!IsListEmpty (ListHead)) {
NotifyNode = CR ( NotifyNode = CR (
ListHead->ForwardLink, ListHead->ForwardLink,
@ -655,7 +671,5 @@ InitializePs2Keyboard(
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;
} }

View File

@ -129,6 +129,7 @@ typedef struct {
// //
// Driver entry point // Driver entry point
// //
/** /**
The user Entry Point for module Ps2Keyboard. The user code starts with this function. The user Entry Point for module Ps2Keyboard. The user code starts with this function.
@ -185,7 +186,6 @@ InstallPs2KeyboardDriver (
#define SCANCODE_MAX_MAKE 0x60 #define SCANCODE_MAX_MAKE 0x60
#define KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA BIT0 ///< 0 - Output register has no data; 1 - Output register has data #define KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA BIT0 ///< 0 - Output register has no data; 1 - Output register has data
#define KEYBOARD_STATUS_REGISTER_HAS_INPUT_DATA BIT1 ///< 0 - Input register has no data; 1 - Input register has data #define KEYBOARD_STATUS_REGISTER_HAS_INPUT_DATA BIT1 ///< 0 - Input register has no data; 1 - Input register has data
#define KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG BIT2 ///< Set to 0 after power on reset #define KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG BIT2 ///< Set to 0 after power on reset
@ -211,7 +211,6 @@ InstallPs2KeyboardDriver (
#define KEYBOARD_8048_RETURN_8042_BAT_ERROR 0xFC #define KEYBOARD_8048_RETURN_8042_BAT_ERROR 0xFC
#define KEYBOARD_8048_RETURN_8042_ACK 0xFA #define KEYBOARD_8048_RETURN_8042_ACK 0xFA
// //
// Keyboard Controller Status // Keyboard Controller Status
// //
@ -221,6 +220,7 @@ InstallPs2KeyboardDriver (
// //
// Other functions that are used among .c files // Other functions that are used among .c files
// //
/** /**
Show keyboard status lights according to Show keyboard status lights according to
indicators in ConsoleIn. indicators in ConsoleIn.
@ -294,7 +294,6 @@ InitKeyboard (
IN BOOLEAN ExtendedVerification IN BOOLEAN ExtendedVerification
); );
/** /**
Timer event handler: read a series of scancodes from 8042 Timer event handler: read a series of scancodes from 8042
and put them into memory scancode buffer. and put them into memory scancode buffer.

View File

@ -34,6 +34,7 @@ KbcSelfTest (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Read return code // Read return code
// //
@ -45,6 +46,7 @@ KbcSelfTest (
if (Data != 0x55) { if (Data != 0x55) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Set system flag // Set system flag
// //
@ -167,6 +169,7 @@ CheckKbStatus (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Check keyboard enable or not // Check keyboard enable or not
// //
@ -201,6 +204,7 @@ PS2MouseReset (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Check BAT Complete Code // Check BAT Complete Code
// //
@ -212,6 +216,7 @@ PS2MouseReset (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Check BAT Complete Code // Check BAT Complete Code
// //
@ -343,7 +348,6 @@ PS2MouseGetPacket (
// State machine to get mouse packet // State machine to get mouse packet
// //
while (1) { while (1) {
switch (State) { switch (State) {
case PS2_READ_BYTE_ONE: case PS2_READ_BYTE_ONE:
// //
@ -370,6 +374,7 @@ PS2MouseGetPacket (
KbcDisableKb (); KbcDisableKb ();
KbcEnableAux (); KbcEnableAux ();
} }
break; break;
case PS2_READ_DATA_BYTE: case PS2_READ_DATA_BYTE:
@ -398,6 +403,7 @@ PS2MouseGetPacket (
if (KeyboardEnable) { if (KeyboardEnable) {
KbcEnableKb (); KbcEnableKb ();
} }
// //
// Decode the packet // Decode the packet
// //
@ -423,11 +429,11 @@ PS2MouseGetPacket (
if ((Packet[0] & 0x10) != 0) { if ((Packet[0] & 0x10) != 0) {
RelativeMovementX = (INT16)(RelativeMovementX | 0xFF00); RelativeMovementX = (INT16)(RelativeMovementX | 0xFF00);
} }
if ((Packet[0] & 0x20) != 0) { if ((Packet[0] & 0x20) != 0) {
RelativeMovementY = (INT16)(RelativeMovementY | 0xFF00); RelativeMovementY = (INT16)(RelativeMovementY | 0xFF00);
} }
RButton = (UINT8)(Packet[0] & 0x2); RButton = (UINT8)(Packet[0] & 0x2);
LButton = (UINT8)(Packet[0] & 0x1); LButton = (UINT8)(Packet[0] & 0x1);
@ -478,17 +484,18 @@ PS2MouseRead (
} }
for (BytesRead = 0; BytesRead < *BufSize; BytesRead++) { for (BytesRead = 0; BytesRead < *BufSize; BytesRead++) {
Status = WaitOutputFull (TIMEOUT); Status = WaitOutputFull (TIMEOUT);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
Buffer[BytesRead] = IoRead8 (KBC_DATA_PORT); Buffer[BytesRead] = IoRead8 (KBC_DATA_PORT);
} }
// //
// Verify the correct number of bytes read // Verify the correct number of bytes read
// //
if (BytesRead == 0 || BytesRead != *BufSize) { if ((BytesRead == 0) || (BytesRead != *BufSize)) {
Status = EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
} }
@ -499,6 +506,7 @@ PS2MouseRead (
// //
// 8042 I/O function // 8042 I/O function
// //
/** /**
I/O work flow of outing 8042 command. I/O work flow of outing 8042 command.
@ -521,6 +529,7 @@ Out8042Command (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Send command // Send command
// //
@ -548,6 +557,7 @@ Out8042Data (
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
// //
// Wait keyboard controller input buffer empty // Wait keyboard controller input buffer empty
// //
@ -623,6 +633,7 @@ Out8042AuxCommand (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Send write to auxiliary device command // Send write to auxiliary device command
// //
@ -632,6 +643,7 @@ Out8042AuxCommand (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Send auxiliary device command // Send auxiliary device command
// //
@ -650,13 +662,11 @@ Out8042AuxCommand (
// Receive mouse acknowledge, command send success // Receive mouse acknowledge, command send success
// //
return EFI_SUCCESS; return EFI_SUCCESS;
} else if (Resend) { } else if (Resend) {
// //
// Resend fail // Resend fail
// //
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} else if (Data == PS2_RESEND) { } else if (Data == PS2_RESEND) {
// //
// Resend command // Resend command
@ -665,13 +675,11 @@ Out8042AuxCommand (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
} else { } else {
// //
// Invalid return code // Invalid return code
// //
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
@ -691,6 +699,7 @@ Out8042AuxData (
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
// //
// Wait keyboard controller input buffer empty // Wait keyboard controller input buffer empty
// //
@ -698,6 +707,7 @@ Out8042AuxData (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Send write to auxiliary device command // Send write to auxiliary device command
// //
@ -746,7 +756,6 @@ In8042AuxData (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Check keyboard controller status, if it is output buffer full and for auxiliary device. Check keyboard controller status, if it is output buffer full and for auxiliary device.

View File

@ -268,6 +268,7 @@ PS2MouseRead (
// //
// 8042 I/O function // 8042 I/O function
// //
/** /**
I/O work flow of outing 8042 command. I/O work flow of outing 8042 command.
@ -386,4 +387,3 @@ WaitOutputFull (
); );
#endif #endif

View File

@ -26,7 +26,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPs2MouseComponentNam
"en" "en"
}; };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPs2MouseDriverNameTable[] = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPs2MouseDriverNameTable[] = {
{ {
"eng;en", "eng;en",
@ -182,6 +181,7 @@ Ps2MouseComponentNameGetControllerName (
if (ChildHandle != NULL) { if (ChildHandle != NULL) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
// //
// Check Controller's handle // Check Controller's handle
// //
@ -190,6 +190,7 @@ Ps2MouseComponentNameGetControllerName (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Get the device context // Get the device context
// //

View File

@ -69,8 +69,9 @@ PS2MouseDriverSupported (
DevicePath = NextDevicePathNode (DevicePath); DevicePath = NextDevicePathNode (DevicePath);
} while (!IsDevicePathEnd (DevicePath)); } while (!IsDevicePathEnd (DevicePath));
if (DevicePathType (Acpi) != ACPI_DEVICE_PATH || if ((DevicePathType (Acpi) != ACPI_DEVICE_PATH) ||
(DevicePathSubType (Acpi) != ACPI_DP && DevicePathSubType (Acpi) != ACPI_EXTENDED_DP)) { ((DevicePathSubType (Acpi) != ACPI_DP) && (DevicePathSubType (Acpi) != ACPI_EXTENDED_DP)))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -173,6 +174,7 @@ PS2MouseDriverStart (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Report that the keyboard is being enabled // Report that the keyboard is being enabled
// //
@ -196,6 +198,7 @@ PS2MouseDriverStart (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Raise TPL to avoid keyboard operation impact // Raise TPL to avoid keyboard operation impact
// //
@ -209,6 +212,7 @@ PS2MouseDriverStart (
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit; goto ErrorExit;
} }
// //
// Setup the device instance // Setup the device instance
// //
@ -307,6 +311,7 @@ PS2MouseDriverStart (
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit; goto ErrorExit;
} }
// //
// Setup a periodic timer, used to poll mouse state // Setup a periodic timer, used to poll mouse state
// //
@ -321,6 +326,7 @@ PS2MouseDriverStart (
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit; goto ErrorExit;
} }
// //
// Start timer to poll mouse (100 samples per second) // Start timer to poll mouse (100 samples per second)
// //
@ -346,7 +352,6 @@ PS2MouseDriverStart (
FALSE FALSE
); );
// //
// Install protocol interfaces for the mouse device. // Install protocol interfaces for the mouse device.
// //
@ -625,6 +630,7 @@ MouseReset (
goto Exit; goto Exit;
} }
} }
Exit: Exit:
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
@ -732,7 +738,6 @@ MouseWaitForInput (
if (MouseDev->StateChanged) { if (MouseDev->StateChanged) {
gBS->SignalEvent (Event); gBS->SignalEvent (Event);
} }
} }
/** /**
@ -793,7 +798,5 @@ InitializePs2Mouse(
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;
} }

View File

@ -99,6 +99,7 @@ typedef struct {
// //
// Function prototypes // Function prototypes
// //
/** /**
Test to see if this driver supports ControllerHandle. Any ControllerHandle Test to see if this driver supports ControllerHandle. Any ControllerHandle
than contains a IsaIo protocol can be supported. than contains a IsaIo protocol can be supported.
@ -170,6 +171,7 @@ PS2MouseDriverStop (
// //
// EFI Component Name Functions // EFI Component Name Functions
// //
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -217,7 +219,6 @@ Ps2MouseComponentNameGetDriverName (
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.

View File

@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "Ehci.h" #include "Ehci.h"
// //
// EFI Component Name Protocol // EFI Component Name Protocol
// //
@ -28,13 +27,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEhciComponentName2 =
"en" "en"
}; };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mEhciDriverNameTable[] = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mEhciDriverNameTable[] = {
{ "eng;en", L"Usb Ehci Driver" }, { "eng;en", L"Usb Ehci Driver" },
{ NULL, NULL } { NULL, NULL }
}; };
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -179,6 +176,7 @@ EhciComponentNameGetControllerName (
if (ChildHandle != NULL) { if (ChildHandle != NULL) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
// //
// Make sure this driver is currently managing ControllerHandle // Make sure this driver is currently managing ControllerHandle
// //
@ -190,6 +188,7 @@ EhciComponentNameGetControllerName (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Get the device context // Get the device context
// //
@ -214,5 +213,4 @@ EhciComponentNameGetControllerName (
ControllerName, ControllerName,
(BOOLEAN)(This == &gEhciComponentName) (BOOLEAN)(This == &gEhciComponentName)
); );
} }

View File

@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _COMPONENT_NAME_H_ #ifndef _COMPONENT_NAME_H_
#define _COMPONENT_NAME_H_ #define _COMPONENT_NAME_H_
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -58,7 +57,6 @@ EhciComponentNameGetDriverName (
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -138,4 +136,3 @@ EhciComponentNameGetControllerName (
); );
#endif #endif

View File

@ -16,7 +16,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#include "Ehci.h" #include "Ehci.h"
// //
@ -91,7 +90,6 @@ EhcGetCapability (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Provides software reset for the USB host controller. Provides software reset for the USB host controller.
@ -186,7 +184,6 @@ ON_EXIT:
return Status; return Status;
} }
/** /**
Retrieve the current state of the USB host controller. Retrieve the current state of the USB host controller.
@ -229,7 +226,6 @@ EhcGetState (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Sets the USB host controller to a specific state. Sets the USB host controller to a specific state.
@ -304,7 +300,6 @@ EhcSetState (
return Status; return Status;
} }
/** /**
Retrieves the current status of a USB root hub port. Retrieves the current status of a USB root hub port.
@ -370,7 +365,6 @@ EhcGetRootHubPortStatus (
// //
if (EHC_BIT_IS_SET (State, PORTSC_LINESTATE_K)) { if (EHC_BIT_IS_SET (State, PORTSC_LINESTATE_K)) {
PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED; PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
} else if (EHC_BIT_IS_SET (State, PORTSC_ENABLED)) { } else if (EHC_BIT_IS_SET (State, PORTSC_ENABLED)) {
PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED; PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
} }
@ -399,7 +393,6 @@ ON_EXIT:
return Status; return Status;
} }
/** /**
Sets a feature for the specified root hub port. Sets a feature for the specified root hub port.
@ -491,6 +484,7 @@ EhcSetRootHubPortFeature (
State |= PORTSC_POWER; State |= PORTSC_POWER;
EhcWriteOpReg (Ehc, Offset, State); EhcWriteOpReg (Ehc, Offset, State);
} }
break; break;
case EfiUsbPortOwner: case EfiUsbPortOwner:
@ -509,7 +503,6 @@ ON_EXIT:
return Status; return Status;
} }
/** /**
Clears a feature for the specified root hub port. Clears a feature for the specified root hub port.
@ -624,6 +617,7 @@ EhcClearRootHubPortFeature (
State &= ~PORTSC_POWER; State &= ~PORTSC_POWER;
EhcWriteOpReg (Ehc, Offset, State); EhcWriteOpReg (Ehc, Offset, State);
} }
break; break;
case EfiUsbPortSuspendChange: case EfiUsbPortSuspendChange:
case EfiUsbPortResetChange: case EfiUsbPortResetChange:
@ -643,7 +637,6 @@ ON_EXIT:
return Status; return Status;
} }
/** /**
Submits control transfer to a target USB device. Submits control transfer to a target USB device.
@ -699,22 +692,26 @@ EhcControlTransfer (
if ((TransferDirection != EfiUsbDataIn) && if ((TransferDirection != EfiUsbDataIn) &&
(TransferDirection != EfiUsbDataOut) && (TransferDirection != EfiUsbDataOut) &&
(TransferDirection != EfiUsbNoData)) { (TransferDirection != EfiUsbNoData))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((TransferDirection == EfiUsbNoData) && if ((TransferDirection == EfiUsbNoData) &&
((Data != NULL) || (*DataLength != 0))) { ((Data != NULL) || (*DataLength != 0)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((TransferDirection != EfiUsbNoData) && if ((TransferDirection != EfiUsbNoData) &&
((Data == NULL) || (*DataLength == 0))) { ((Data == NULL) || (*DataLength == 0)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((MaximumPacketLength != 8) && (MaximumPacketLength != 16) && if ((MaximumPacketLength != 8) && (MaximumPacketLength != 16) &&
(MaximumPacketLength != 32) && (MaximumPacketLength != 64)) { (MaximumPacketLength != 32) && (MaximumPacketLength != 64))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -800,7 +797,6 @@ ON_EXIT:
return Status; return Status;
} }
/** /**
Submits bulk transfer to a bulk endpoint of a USB device. Submits bulk transfer to a bulk endpoint of a USB device.
@ -857,7 +853,8 @@ EhcBulkTransfer (
// Validate the parameters // Validate the parameters
// //
if ((DataLength == NULL) || (*DataLength == 0) || if ((DataLength == NULL) || (*DataLength == 0) ||
(Data == NULL) || (Data[0] == NULL) || (TransferResult == NULL)) { (Data == NULL) || (Data[0] == NULL) || (TransferResult == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -867,7 +864,8 @@ EhcBulkTransfer (
if ((DeviceSpeed == EFI_USB_SPEED_LOW) || if ((DeviceSpeed == EFI_USB_SPEED_LOW) ||
((DeviceSpeed == EFI_USB_SPEED_FULL) && (MaximumPacketLength > 64)) || ((DeviceSpeed == EFI_USB_SPEED_FULL) && (MaximumPacketLength > 64)) ||
((EFI_USB_SPEED_HIGH == DeviceSpeed) && (MaximumPacketLength > 512))) { ((EFI_USB_SPEED_HIGH == DeviceSpeed) && (MaximumPacketLength > 512)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -940,7 +938,6 @@ ON_EXIT:
return Status; return Status;
} }
/** /**
Submits an asynchronous interrupt transfer to an Submits an asynchronous interrupt transfer to an
interrupt endpoint of a USB device. interrupt endpoint of a USB device.
@ -1065,7 +1062,6 @@ ON_EXIT:
return Status; return Status;
} }
/** /**
Submits synchronous interrupt transfer to an interrupt endpoint Submits synchronous interrupt transfer to an interrupt endpoint
of a USB device. of a USB device.
@ -1118,7 +1114,8 @@ EhcSyncInterruptTransfer (
// Validates parameters // Validates parameters
// //
if ((DataLength == NULL) || (*DataLength == 0) || if ((DataLength == NULL) || (*DataLength == 0) ||
(Data == NULL) || (TransferResult == NULL)) { (Data == NULL) || (TransferResult == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1128,7 +1125,8 @@ EhcSyncInterruptTransfer (
if (((DeviceSpeed == EFI_USB_SPEED_LOW) && (MaximumPacketLength != 8)) || if (((DeviceSpeed == EFI_USB_SPEED_LOW) && (MaximumPacketLength != 8)) ||
((DeviceSpeed == EFI_USB_SPEED_FULL) && (MaximumPacketLength > 64)) || ((DeviceSpeed == EFI_USB_SPEED_FULL) && (MaximumPacketLength > 64)) ||
((DeviceSpeed == EFI_USB_SPEED_HIGH) && (MaximumPacketLength > 3072))) { ((DeviceSpeed == EFI_USB_SPEED_HIGH) && (MaximumPacketLength > 3072)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1195,7 +1193,6 @@ ON_EXIT:
return Status; return Status;
} }
/** /**
Submits isochronous transfer to a target USB device. Submits isochronous transfer to a target USB device.
@ -1235,7 +1232,6 @@ EhcIsochronousTransfer (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
/** /**
Submits Async isochronous transfer to a target USB device. Submits Async isochronous transfer to a target USB device.
@ -1305,7 +1301,6 @@ EhcDriverEntryPoint (
); );
} }
/** /**
Test to see if this driver supports ControllerHandle. Any Test to see if this driver supports ControllerHandle. Any
ControllerHandle that has Usb2HcProtocol installed will ControllerHandle that has Usb2HcProtocol installed will
@ -1364,8 +1359,8 @@ EhcDriverBindingSupported (
// Test whether the controller belongs to Ehci type // Test whether the controller belongs to Ehci type
// //
if ( (UsbClassCReg.BaseCode != PCI_CLASS_SERIAL) || (UsbClassCReg.SubClassCode != PCI_CLASS_SERIAL_USB) if ( (UsbClassCReg.BaseCode != PCI_CLASS_SERIAL) || (UsbClassCReg.SubClassCode != PCI_CLASS_SERIAL_USB)
|| ((UsbClassCReg.ProgInterface != PCI_IF_EHCI) && (UsbClassCReg.ProgInterface != PCI_IF_UHCI) && (UsbClassCReg.ProgInterface != PCI_IF_OHCI))) { || ((UsbClassCReg.ProgInterface != PCI_IF_EHCI) && (UsbClassCReg.ProgInterface != PCI_IF_UHCI) && (UsbClassCReg.ProgInterface != PCI_IF_OHCI)))
{
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
} }
@ -1503,7 +1498,6 @@ EhcGetUsbDebugPortInfo (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Create and initialize a USB2_HC_DEV. Create and initialize a USB2_HC_DEV.
@ -1618,7 +1612,6 @@ EhcExitBootService (
EhcResetHC (Ehc, EHC_RESET_TIMEOUT); EhcResetHC (Ehc, EHC_RESET_TIMEOUT);
} }
/** /**
Starting the Usb EHCI Driver. Starting the Usb EHCI Driver.
@ -1704,6 +1697,7 @@ EhcDriverBindingStart (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto CLOSE_PCIIO; goto CLOSE_PCIIO;
} }
PciAttributesSaved = TRUE; PciAttributesSaved = TRUE;
Status = PciIo->Attributes ( Status = PciIo->Attributes (
@ -1742,14 +1736,16 @@ EhcDriverBindingStart (
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
goto CLOSE_PCIIO; goto CLOSE_PCIIO;
} }
// //
// Determine if the device is UHCI or OHCI host controller or not. If yes, then find out the // Determine if the device is UHCI or OHCI host controller or not. If yes, then find out the
// companion usb ehci host controller and force EHCI driver get attached to it before // companion usb ehci host controller and force EHCI driver get attached to it before
// UHCI or OHCI driver attaches to UHCI or OHCI host controller. // UHCI or OHCI driver attaches to UHCI or OHCI host controller.
// //
if ((UsbClassCReg.ProgInterface == PCI_IF_UHCI || UsbClassCReg.ProgInterface == PCI_IF_OHCI) && if (((UsbClassCReg.ProgInterface == PCI_IF_UHCI) || (UsbClassCReg.ProgInterface == PCI_IF_OHCI)) &&
(UsbClassCReg.BaseCode == PCI_CLASS_SERIAL) && (UsbClassCReg.BaseCode == PCI_CLASS_SERIAL) &&
(UsbClassCReg.SubClassCode == PCI_CLASS_SERIAL_USB)) { (UsbClassCReg.SubClassCode == PCI_CLASS_SERIAL_USB))
{
Status = PciIo->GetLocation ( Status = PciIo->GetLocation (
PciIo, PciIo,
&CompanionSegmentNumber, &CompanionSegmentNumber,
@ -1798,7 +1794,8 @@ EhcDriverBindingStart (
if ((UsbClassCReg.ProgInterface == PCI_IF_EHCI) && if ((UsbClassCReg.ProgInterface == PCI_IF_EHCI) &&
(UsbClassCReg.BaseCode == PCI_CLASS_SERIAL) && (UsbClassCReg.BaseCode == PCI_CLASS_SERIAL) &&
(UsbClassCReg.SubClassCode == PCI_CLASS_SERIAL_USB)) { (UsbClassCReg.SubClassCode == PCI_CLASS_SERIAL_USB))
{
Status = Instance->GetLocation ( Status = Instance->GetLocation (
Instance, Instance,
&EhciSegmentNumber, &EhciSegmentNumber,
@ -1809,6 +1806,7 @@ EhcDriverBindingStart (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto CLOSE_PCIIO; goto CLOSE_PCIIO;
} }
// //
// Currently, the judgment on the companion usb host controller is through the // Currently, the judgment on the companion usb host controller is through the
// same bus number, which may vary on different platform. // same bus number, which may vary on different platform.
@ -1824,6 +1822,7 @@ EhcDriverBindingStart (
} }
} }
} }
Status = EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
goto CLOSE_PCIIO; goto CLOSE_PCIIO;
} }
@ -1854,9 +1853,13 @@ EhcDriverBindingStart (
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Ehc->Support64BitDma = TRUE; Ehc->Support64BitDma = TRUE;
} else { } else {
DEBUG ((DEBUG_WARN, DEBUG ((
DEBUG_WARN,
"%a: failed to enable 64-bit DMA on 64-bit capable controller @ %p (%r)\n", "%a: failed to enable 64-bit DMA on 64-bit capable controller @ %p (%r)\n",
__FUNCTION__, Controller, Status)); __FUNCTION__,
Controller,
Status
));
} }
} }
@ -1937,7 +1940,6 @@ EhcDriverBindingStart (
FALSE FALSE
); );
DEBUG ((DEBUG_INFO, "EhcDriverBindingStart: EHCI started for controller @ %p\n", Controller)); DEBUG ((DEBUG_INFO, "EhcDriverBindingStart: EHCI started for controller @ %p\n", Controller));
return EFI_SUCCESS; return EFI_SUCCESS;
@ -1976,7 +1978,6 @@ CLOSE_PCIIO:
return Status; return Status;
} }
/** /**
Stop this driver on ControllerHandle. Support stopping any child handles Stop this driver on ControllerHandle. Support stopping any child handles
created by this driver. created by this driver.

View File

@ -11,7 +11,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_EHCI_H_ #ifndef _EFI_EHCI_H_
#define _EFI_EHCI_H_ #define _EFI_EHCI_H_
#include <Uefi.h> #include <Uefi.h>
#include <Protocol/Usb2HostController.h> #include <Protocol/Usb2HostController.h>
@ -83,7 +82,6 @@ typedef struct _USB2_HC_DEV USB2_HC_DEV;
#define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field) #define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field)
#define EHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF)) #define EHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))
#define EHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF)) #define EHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
#define EHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit))) #define EHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
@ -160,7 +158,6 @@ struct _USB2_HC_DEV {
BOOLEAN Support64BitDma; // Whether 64 bit DMA may be used with this device BOOLEAN Support64BitDma; // Whether 64 bit DMA may be used with this device
}; };
extern EFI_DRIVER_BINDING_PROTOCOL gEhciDriverBinding; extern EFI_DRIVER_BINDING_PROTOCOL gEhciDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gEhciComponentName; extern EFI_COMPONENT_NAME_PROTOCOL gEhciComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gEhciComponentName2; extern EFI_COMPONENT_NAME2_PROTOCOL gEhciComponentName2;
@ -230,4 +227,3 @@ EhcDriverBindingStop (
); );
#endif #endif

View File

@ -8,7 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#include "Ehci.h" #include "Ehci.h"
/** /**
@ -57,7 +56,6 @@ EhcDumpStatus (
DEBUG ((DEBUG_VERBOSE, "\n")); DEBUG ((DEBUG_VERBOSE, "\n"));
} }
/** /**
Dump the fields of a QTD. Dump the fields of a QTD.
@ -89,13 +87,10 @@ EhcDumpQtd (
if (QtdHw->Pid == QTD_PID_SETUP) { if (QtdHw->Pid == QTD_PID_SETUP) {
DEBUG ((DEBUG_VERBOSE, "PID : Setup\n")); DEBUG ((DEBUG_VERBOSE, "PID : Setup\n"));
} else if (QtdHw->Pid == QTD_PID_INPUT) { } else if (QtdHw->Pid == QTD_PID_INPUT) {
DEBUG ((DEBUG_VERBOSE, "PID : IN\n")); DEBUG ((DEBUG_VERBOSE, "PID : IN\n"));
} else if (QtdHw->Pid == QTD_PID_OUTPUT) { } else if (QtdHw->Pid == QTD_PID_OUTPUT) {
DEBUG ((DEBUG_VERBOSE, "PID : OUT\n")); DEBUG ((DEBUG_VERBOSE, "PID : OUT\n"));
} }
DEBUG ((DEBUG_VERBOSE, "Error Count : %d\n", QtdHw->ErrCnt)); DEBUG ((DEBUG_VERBOSE, "Error Count : %d\n", QtdHw->ErrCnt));
@ -109,7 +104,6 @@ EhcDumpQtd (
} }
} }
/** /**
Dump the queue head. Dump the queue head.
@ -134,8 +128,13 @@ EhcDumpQh (
DEBUG ((DEBUG_VERBOSE, Msg)); DEBUG ((DEBUG_VERBOSE, Msg));
} }
DEBUG ((DEBUG_VERBOSE, "Queue head @ 0x%p, interval %ld, next qh %p\n", DEBUG ((
Qh, (UINT64)Qh->Interval, Qh->NextQh)); DEBUG_VERBOSE,
"Queue head @ 0x%p, interval %ld, next qh %p\n",
Qh,
(UINT64)Qh->Interval,
Qh->NextQh
));
QhHw = &Qh->QhHw; QhHw = &Qh->QhHw;
@ -166,10 +165,8 @@ EhcDumpQh (
if (QhHw->Pid == QTD_PID_SETUP) { if (QhHw->Pid == QTD_PID_SETUP) {
DEBUG ((DEBUG_VERBOSE, "PID : Setup\n")); DEBUG ((DEBUG_VERBOSE, "PID : Setup\n"));
} else if (QhHw->Pid == QTD_PID_INPUT) { } else if (QhHw->Pid == QTD_PID_INPUT) {
DEBUG ((DEBUG_VERBOSE, "PID : IN\n")); DEBUG ((DEBUG_VERBOSE, "PID : IN\n"));
} else if (QhHw->Pid == QTD_PID_OUTPUT) { } else if (QhHw->Pid == QTD_PID_OUTPUT) {
DEBUG ((DEBUG_VERBOSE, "PID : OUT\n")); DEBUG ((DEBUG_VERBOSE, "PID : OUT\n"));
} }
@ -196,7 +193,6 @@ EhcDumpQh (
} }
} }
/** /**
Dump the buffer in the form of hex. Dump the buffer in the form of hex.

View File

@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_EHCI_DEBUG_H_ #ifndef _EFI_EHCI_DEBUG_H_
#define _EFI_EHCI_DEBUG_H_ #define _EFI_EHCI_DEBUG_H_
/** /**
Dump the fields of a QTD. Dump the fields of a QTD.
@ -24,7 +23,6 @@ EhcDumpQtd (
IN CHAR8 *Msg IN CHAR8 *Msg
); );
/** /**
Dump the queue head. Dump the queue head.
@ -40,7 +38,6 @@ EhcDumpQh (
IN BOOLEAN DumpBuf IN BOOLEAN DumpBuf
); );
/** /**
Dump the buffer in the form of hex. Dump the buffer in the form of hex.
@ -54,5 +51,4 @@ EhcDumpBuf (
IN UINTN Len IN UINTN Len
); );
#endif #endif

View File

@ -7,10 +7,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#include "Ehci.h" #include "Ehci.h"
/** /**
Read EHCI capability register. Read EHCI capability register.
@ -83,7 +81,6 @@ EhcReadDbgRegister (
return Data; return Data;
} }
/** /**
Check whether the host controller has an in-use debug port. Check whether the host controller has an in-use debug port.
@ -121,7 +118,7 @@ EhcIsDebugPortInUse (
// //
// The Debug Port Number field in HCSPARAMS is one-based. // The Debug Port Number field in HCSPARAMS is one-based.
// //
if (PortNumber != NULL && *PortNumber != Ehc->DebugPortNum - 1) { if ((PortNumber != NULL) && (*PortNumber != Ehc->DebugPortNum - 1)) {
// //
// The caller specified a port, but it's not the debug port of the host // The caller specified a port, but it's not the debug port of the host
// controller. // controller.
@ -136,7 +133,6 @@ EhcIsDebugPortInUse (
return (State & USB_DEBUG_PORT_IN_USE_MASK) == USB_DEBUG_PORT_IN_USE_MASK; return (State & USB_DEBUG_PORT_IN_USE_MASK) == USB_DEBUG_PORT_IN_USE_MASK;
} }
/** /**
Read EHCI Operation register. Read EHCI Operation register.
@ -175,7 +171,6 @@ EhcReadOpReg (
return Data; return Data;
} }
/** /**
Write the data to the EHCI operation register. Write the data to the EHCI operation register.
@ -209,7 +204,6 @@ EhcWriteOpReg (
} }
} }
/** /**
Set one bit of the operational register while keeping other bits. Set one bit of the operational register while keeping other bits.
@ -232,7 +226,6 @@ EhcSetOpRegBit (
EhcWriteOpReg (Ehc, Offset, Data); EhcWriteOpReg (Ehc, Offset, Data);
} }
/** /**
Clear one bit of the operational register while keeping other bits. Clear one bit of the operational register while keeping other bits.
@ -255,7 +248,6 @@ EhcClearOpRegBit (
EhcWriteOpReg (Ehc, Offset, Data); EhcWriteOpReg (Ehc, Offset, Data);
} }
/** /**
Wait the operation register's bit as specified by Bit Wait the operation register's bit as specified by Bit
to become set (or clear). to become set (or clear).
@ -292,7 +284,6 @@ EhcWaitOpRegBit (
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
/** /**
Add support for UEFI Over Legacy (UoL) feature, stop Add support for UEFI Over Legacy (UoL) feature, stop
the legacy USB SMI support. the legacy USB SMI support.
@ -337,8 +328,6 @@ EhcClearLegacySupport (
PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ExtendCap + 0x4, 1, &Value); PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ExtendCap + 0x4, 1, &Value);
} }
/** /**
Set door bell and wait it to be ACKed by host controller. Set door bell and wait it to be ACKed by host controller.
This function is used to synchronize with the hardware. This function is used to synchronize with the hardware.
@ -376,7 +365,6 @@ EhcSetAndWaitDoorBell (
return Status; return Status;
} }
/** /**
Clear all the interrutp status bits, these bits Clear all the interrutp status bits, these bits
are Write-Clean. are Write-Clean.
@ -392,7 +380,6 @@ EhcAckAllInterrupt (
EhcWriteOpReg (Ehc, EHC_USBSTS_OFFSET, USBSTS_INTACK_MASK); EhcWriteOpReg (Ehc, EHC_USBSTS_OFFSET, USBSTS_INTACK_MASK);
} }
/** /**
Enable the periodic schedule then wait EHC to Enable the periodic schedule then wait EHC to
actually enable it. actually enable it.
@ -418,11 +405,6 @@ EhcEnablePeriodSchd (
return Status; return Status;
} }
/** /**
Enable asynchrounous schedule. Enable asynchrounous schedule.
@ -447,12 +429,6 @@ EhcEnableAsyncSchd (
return Status; return Status;
} }
/** /**
Whether Ehc is halted. Whether Ehc is halted.
@ -470,7 +446,6 @@ EhcIsHalt (
return EHC_REG_BIT_IS_SET (Ehc, EHC_USBSTS_OFFSET, USBSTS_HALT); return EHC_REG_BIT_IS_SET (Ehc, EHC_USBSTS_OFFSET, USBSTS_HALT);
} }
/** /**
Whether system error occurred. Whether system error occurred.
@ -488,7 +463,6 @@ EhcIsSysError (
return EHC_REG_BIT_IS_SET (Ehc, EHC_USBSTS_OFFSET, USBSTS_SYS_ERROR); return EHC_REG_BIT_IS_SET (Ehc, EHC_USBSTS_OFFSET, USBSTS_SYS_ERROR);
} }
/** /**
Reset the host controller. Reset the host controller.
@ -523,7 +497,6 @@ EhcResetHC (
return Status; return Status;
} }
/** /**
Halt the host controller. Halt the host controller.
@ -547,7 +520,6 @@ EhcHaltHC (
return Status; return Status;
} }
/** /**
Set the EHCI to run. Set the EHCI to run.
@ -571,7 +543,6 @@ EhcRunHC (
return Status; return Status;
} }
/** /**
Initialize the HC hardware. Initialize the HC hardware.
EHCI spec lists the five things to do to initialize the hardware: EHCI spec lists the five things to do to initialize the hardware:

View File

@ -14,7 +14,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// EHCI register offset // EHCI register offset
// //
// //
// Capability register offset // Capability register offset
// //
@ -170,7 +169,6 @@ EhcReadOpReg (
IN UINT32 Offset IN UINT32 Offset
); );
/** /**
Write the data to the EHCI operation register. Write the data to the EHCI operation register.
@ -228,8 +226,6 @@ EhcClearLegacySupport (
IN USB2_HC_DEV *Ehc IN USB2_HC_DEV *Ehc
); );
/** /**
Set door bell and wait it to be ACKed by host controller. Set door bell and wait it to be ACKed by host controller.
This function is used to synchronize with the hardware. This function is used to synchronize with the hardware.
@ -247,7 +243,6 @@ EhcSetAndWaitDoorBell (
IN UINT32 Timeout IN UINT32 Timeout
); );
/** /**
Clear all the interrutp status bits, these bits are Write-Clean. Clear all the interrutp status bits, these bits are Write-Clean.
@ -259,8 +254,6 @@ EhcAckAllInterrupt (
IN USB2_HC_DEV *Ehc IN USB2_HC_DEV *Ehc
); );
/** /**
Whether Ehc is halted. Whether Ehc is halted.
@ -275,7 +268,6 @@ EhcIsHalt (
IN USB2_HC_DEV *Ehc IN USB2_HC_DEV *Ehc
); );
/** /**
Whether system error occurred. Whether system error occurred.
@ -290,7 +282,6 @@ EhcIsSysError (
IN USB2_HC_DEV *Ehc IN USB2_HC_DEV *Ehc
); );
/** /**
Reset the host controller. Reset the host controller.
@ -307,7 +298,6 @@ EhcResetHC (
IN UINT32 Timeout IN UINT32 Timeout
); );
/** /**
Halt the host controller. Halt the host controller.
@ -324,7 +314,6 @@ EhcHaltHC (
IN UINT32 Timeout IN UINT32 Timeout
); );
/** /**
Set the EHCI to run. Set the EHCI to run.
@ -341,8 +330,6 @@ EhcRunHC (
IN UINT32 Timeout IN UINT32 Timeout
); );
/** /**
Initialize the HC hardware. Initialize the HC hardware.
EHCI spec lists the five things to do to initialize the hardware: EHCI spec lists the five things to do to initialize the hardware:

View File

@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "Ehci.h" #include "Ehci.h"
/** /**
Create helper QTD/QH for the EHCI device. Create helper QTD/QH for the EHCI device.
@ -90,7 +89,6 @@ EhcCreateHelpQ (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Initialize the schedule data structure such as frame list. Initialize the schedule data structure such as frame list.
@ -242,7 +240,6 @@ ErrorExit1:
return Status; return Status;
} }
/** /**
Free the schedule data. It may be partially initialized. Free the schedule data. It may be partially initialized.
@ -300,7 +297,6 @@ EhcFreeSched (
} }
} }
/** /**
Link the queue head to the asynchronous schedule list. Link the queue head to the asynchronous schedule list.
UEFI only supports one CTRL/BULK transfer at a time UEFI only supports one CTRL/BULK transfer at a time
@ -337,7 +333,6 @@ EhcLinkQhToAsync (
Head->QhHw.HorizonLink = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE); Head->QhHw.HorizonLink = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE);
} }
/** /**
Unlink a queue head from the asynchronous schedule list. Unlink a queue head from the asynchronous schedule list.
Need to synchronize with hardware. Need to synchronize with hardware.
@ -381,7 +376,6 @@ EhcUnlinkQhFromAsync (
} }
} }
/** /**
Link a queue head for interrupt transfer to the periodic Link a queue head for interrupt transfer to the periodic
schedule frame list. This code is very much the same as schedule frame list. This code is very much the same as
@ -484,7 +478,6 @@ EhcLinkQhToPeriod (
} }
} }
/** /**
Unlink an interrupt queue head from the periodic Unlink an interrupt queue head from the periodic
schedule frame list. schedule frame list.
@ -542,7 +535,6 @@ EhcUnlinkQhFromPeriod (
} }
} }
/** /**
Check the URB's execution result and update the URB's Check the URB's execution result and update the URB's
result accordingly. result accordingly.
@ -606,7 +598,6 @@ EhcCheckUrbResult (
Finished = TRUE; Finished = TRUE;
goto ON_EXIT; goto ON_EXIT;
} else if (EHC_BIT_IS_SET (State, QTD_STAT_ACTIVE)) { } else if (EHC_BIT_IS_SET (State, QTD_STAT_ACTIVE)) {
// //
// The QTD is still active, no need to check furthur. // The QTD is still active, no need to check furthur.
@ -615,7 +606,6 @@ EhcCheckUrbResult (
Finished = FALSE; Finished = FALSE;
goto ON_EXIT; goto ON_EXIT;
} else { } else {
// //
// This QTD is finished OK or met short packet read. Update the // This QTD is finished OK or met short packet read. Update the
@ -662,7 +652,6 @@ ON_EXIT:
return Finished; return Finished;
} }
/** /**
Execute the transfer by polling the URB. This is a synchronous operation. Execute the transfer by polling the URB. This is a synchronous operation.
@ -717,7 +706,6 @@ EhcExecTransfer (
EhcDumpQh (Urb->Qh, NULL, FALSE); EhcDumpQh (Urb->Qh, NULL, FALSE);
Status = EFI_TIMEOUT; Status = EFI_TIMEOUT;
} else if (Urb->Result != EFI_USB_NOERROR) { } else if (Urb->Result != EFI_USB_NOERROR) {
DEBUG ((DEBUG_ERROR, "EhcExecTransfer: transfer failed with %x\n", Urb->Result)); DEBUG ((DEBUG_ERROR, "EhcExecTransfer: transfer failed with %x\n", Urb->Result));
EhcDumpQh (Urb->Qh, NULL, FALSE); EhcDumpQh (Urb->Qh, NULL, FALSE);
@ -728,7 +716,6 @@ EhcExecTransfer (
return Status; return Status;
} }
/** /**
Delete a single asynchronous interrupt transfer for Delete a single asynchronous interrupt transfer for
the device and endpoint. the device and endpoint.
@ -762,7 +749,8 @@ EhciDelAsyncIntTransfer (
Urb = EFI_LIST_CONTAINER (Entry, URB, UrbList); Urb = EFI_LIST_CONTAINER (Entry, URB, UrbList);
if ((Urb->Ep.DevAddr == DevAddr) && (Urb->Ep.EpAddr == EpNum) && if ((Urb->Ep.DevAddr == DevAddr) && (Urb->Ep.EpAddr == EpNum) &&
(Urb->Ep.Direction == Direction)) { (Urb->Ep.Direction == Direction))
{
// //
// Check the URB status to retrieve the next data toggle // Check the URB status to retrieve the next data toggle
// from the associated queue head. // from the associated queue head.
@ -782,7 +770,6 @@ EhciDelAsyncIntTransfer (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
Remove all the asynchronous interrutp transfers. Remove all the asynchronous interrutp transfers.
@ -939,7 +926,6 @@ ON_ERROR:
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
/** /**
Update the queue head for next round of asynchronous transfer. Update the queue head for next round of asynchronous transfer.
@ -1023,7 +1009,6 @@ EhcUpdateAsyncRequest (
return; return;
} }
/** /**
Interrupt transfer periodic check handler. Interrupt transfer periodic check handler.

View File

@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_EHCI_SCHED_H_ #ifndef _EFI_EHCI_SCHED_H_
#define _EFI_EHCI_SCHED_H_ #define _EFI_EHCI_SCHED_H_
/** /**
Initialize the schedule data structure such as frame list. Initialize the schedule data structure such as frame list.
@ -25,7 +24,6 @@ EhcInitSched (
IN USB2_HC_DEV *Ehc IN USB2_HC_DEV *Ehc
); );
/** /**
Free the schedule data. It may be partially initialized. Free the schedule data. It may be partially initialized.
@ -37,7 +35,6 @@ EhcFreeSched (
IN USB2_HC_DEV *Ehc IN USB2_HC_DEV *Ehc
); );
/** /**
Link the queue head to the asynchronous schedule list. Link the queue head to the asynchronous schedule list.
UEFI only supports one CTRL/BULK transfer at a time UEFI only supports one CTRL/BULK transfer at a time
@ -55,7 +52,6 @@ EhcLinkQhToAsync (
IN EHC_QH *Qh IN EHC_QH *Qh
); );
/** /**
Unlink a queue head from the asynchronous schedule list. Unlink a queue head from the asynchronous schedule list.
Need to synchronize with hardware. Need to synchronize with hardware.
@ -70,7 +66,6 @@ EhcUnlinkQhFromAsync (
IN EHC_QH *Qh IN EHC_QH *Qh
); );
/** /**
Link a queue head for interrupt transfer to the periodic Link a queue head for interrupt transfer to the periodic
schedule frame list. This code is very much the same as schedule frame list. This code is very much the same as
@ -86,7 +81,6 @@ EhcLinkQhToPeriod (
IN EHC_QH *Qh IN EHC_QH *Qh
); );
/** /**
Unlink an interrupt queue head from the periodic Unlink an interrupt queue head from the periodic
schedule frame list. schedule frame list.
@ -101,8 +95,6 @@ EhcUnlinkQhFromPeriod (
IN EHC_QH *Qh IN EHC_QH *Qh
); );
/** /**
Execute the transfer by polling the URB. This is a synchronous operation. Execute the transfer by polling the URB. This is a synchronous operation.
@ -122,7 +114,6 @@ EhcExecTransfer (
IN UINTN TimeOut IN UINTN TimeOut
); );
/** /**
Delete a single asynchronous interrupt transfer for Delete a single asynchronous interrupt transfer for
the device and endpoint. the device and endpoint.
@ -144,7 +135,6 @@ EhciDelAsyncIntTransfer (
OUT UINT8 *DataToggle OUT UINT8 *DataToggle
); );
/** /**
Remove all the asynchronous interrutp transfers. Remove all the asynchronous interrutp transfers.

View File

@ -11,7 +11,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "Ehci.h" #include "Ehci.h"
/** /**
Create a single QTD to hold the data. Create a single QTD to hold the data.
@ -111,8 +110,6 @@ EhcCreateQtd (
return Qtd; return Qtd;
} }
/** /**
Initialize the queue head for interrupt transfer, Initialize the queue head for interrupt transfer,
that is, initialize the following three fields: that is, initialize the following three fields:
@ -157,8 +154,6 @@ EhcInitIntQh (
QhHw->CMask = QH_MICROFRAME_3 | QH_MICROFRAME_4 | QH_MICROFRAME_5; QhHw->CMask = QH_MICROFRAME_3 | QH_MICROFRAME_4 | QH_MICROFRAME_5;
} }
/** /**
Allocate and initialize a EHCI queue head. Allocate and initialize a EHCI queue head.
@ -221,6 +216,7 @@ EhcCreateQh (
if (Ep->DevSpeed != EFI_USB_SPEED_HIGH) { if (Ep->DevSpeed != EFI_USB_SPEED_HIGH) {
QhHw->CtrlEp = 1; QhHw->CtrlEp = 1;
} }
break; break;
case EHC_INT_TRANSFER_ASYNC: case EHC_INT_TRANSFER_ASYNC:
@ -244,7 +240,6 @@ EhcCreateQh (
return Qh; return Qh;
} }
/** /**
Convert the poll interval from application to that Convert the poll interval from application to that
be used by EHCI interface data structure. Only need be used by EHCI interface data structure. Only need
@ -282,7 +277,6 @@ EhcConvertPollRate (
return (UINTN)1 << (BitCount - 1); return (UINTN)1 << (BitCount - 1);
} }
/** /**
Free a list of QTDs. Free a list of QTDs.
@ -308,7 +302,6 @@ EhcFreeQtds (
} }
} }
/** /**
Free an allocated URB. It is possible for it to be partially inited. Free an allocated URB. It is possible for it to be partially inited.
@ -346,7 +339,6 @@ EhcFreeUrb (
gBS->FreePool (Urb); gBS->FreePool (Urb);
} }
/** /**
Create a list of QTDs for the URB. Create a list of QTDs for the URB.
@ -511,7 +503,6 @@ ON_ERROR:
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
/** /**
Create a new URB and its associated QTD. Create a new URB and its associated QTD.

View File

@ -11,7 +11,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_EHCI_URB_H_ #ifndef _EFI_EHCI_URB_H_
#define _EFI_EHCI_URB_H_ #define _EFI_EHCI_URB_H_
typedef struct _EHC_QTD EHC_QTD; typedef struct _EHC_QTD EHC_QTD;
typedef struct _EHC_QH EHC_QH; typedef struct _EHC_QH EHC_QH;
typedef struct _URB URB; typedef struct _URB URB;
@ -143,7 +142,6 @@ typedef struct {
} QH_HW; } QH_HW;
#pragma pack() #pragma pack()
// //
// Endpoint address and its capabilities // Endpoint address and its capabilities
// //
@ -230,8 +228,6 @@ struct _URB {
UINT8 DataToggle; UINT8 DataToggle;
}; };
/** /**
Create a single QTD to hold the data. Create a single QTD to hold the data.
@ -257,8 +253,6 @@ EhcCreateQtd (
IN UINTN MaxPacket IN UINTN MaxPacket
); );
/** /**
Allocate and initialize a EHCI queue head. Allocate and initialize a EHCI queue head.
@ -274,7 +268,6 @@ EhcCreateQh (
IN USB_ENDPOINT *Ep IN USB_ENDPOINT *Ep
); );
/** /**
Free an allocated URB. It is possible for it to be partially inited. Free an allocated URB. It is possible for it to be partially inited.
@ -288,7 +281,6 @@ EhcFreeUrb (
IN URB *Urb IN URB *Urb
); );
/** /**
Create a new URB and its associated QTD. Create a new URB and its associated QTD.
@ -327,4 +319,5 @@ EhcCreateUrb (
IN VOID *Context, IN VOID *Context,
IN UINTN Interval IN UINTN Interval
); );
#endif #endif

View File

@ -7,10 +7,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#include "Ehci.h" #include "Ehci.h"
/** /**
Allocate a block of memory to be used by the buffer pool. Allocate a block of memory to be used by the buffer pool.
@ -111,7 +109,6 @@ FREE_BITARRAY:
return NULL; return NULL;
} }
/** /**
Free the memory block from the memory pool. Free the memory block from the memory pool.
@ -141,7 +138,6 @@ UsbHcFreeMemBlock (
gBS->FreePool (Block); gBS->FreePool (Block);
} }
/** /**
Alloc some memory from the block. Alloc some memory from the block.
@ -185,7 +181,6 @@ UsbHcAllocMemFromBlock (
} }
NEXT_BIT (Byte, Bit); NEXT_BIT (Byte, Bit);
} else { } else {
NEXT_BIT (Byte, Bit); NEXT_BIT (Byte, Bit);
@ -263,7 +258,6 @@ UsbHcGetPciAddressForHostMem (
return PhyAddr; return PhyAddr;
} }
/** /**
Insert the memory block to the pool's list of the blocks. Insert the memory block to the pool's list of the blocks.
@ -282,7 +276,6 @@ UsbHcInsertMemBlockToPool (
Head->Next = Block; Head->Next = Block;
} }
/** /**
Is the memory block empty? Is the memory block empty?
@ -308,7 +301,6 @@ UsbHcIsMemBlockEmpty (
return TRUE; return TRUE;
} }
/** /**
Unlink the memory block from the pool's list. Unlink the memory block from the pool's list.
@ -335,7 +327,6 @@ UsbHcUnlinkMemBlock (
} }
} }
/** /**
Initialize the memory management pool for the host controller. Initialize the memory management pool for the host controller.
@ -376,7 +367,6 @@ UsbHcInitMemPool (
return Pool; return Pool;
} }
/** /**
Release the memory management pool. Release the memory management pool.
@ -410,7 +400,6 @@ UsbHcFreeMemPool (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Allocate some memory from the host controller's memory pool Allocate some memory from the host controller's memory pool
which can be used to communicate with host controller. which can be used to communicate with host controller.
@ -487,7 +476,6 @@ UsbHcAllocateMem (
return Mem; return Mem;
} }
/** /**
Free the allocated memory back to the memory pool. Free the allocated memory back to the memory pool.

View File

@ -63,8 +63,6 @@ typedef struct _USBHC_MEM_POOL {
} \ } \
} while (0) } while (0)
/** /**
Initialize the memory management pool for the host controller. Initialize the memory management pool for the host controller.
@ -84,7 +82,6 @@ UsbHcInitMemPool (
IN UINT32 Which4G IN UINT32 Which4G
); );
/** /**
Release the memory management pool. Release the memory management pool.
@ -99,7 +96,6 @@ UsbHcFreeMemPool (
IN USBHC_MEM_POOL *Pool IN USBHC_MEM_POOL *Pool
); );
/** /**
Allocate some memory from the host controller's memory pool Allocate some memory from the host controller's memory pool
which can be used to communicate with host controller. which can be used to communicate with host controller.
@ -116,7 +112,6 @@ UsbHcAllocateMem (
IN UINTN Size IN UINTN Size
); );
/** /**
Free the allocated memory back to the memory pool. Free the allocated memory back to the memory pool.

View File

@ -54,6 +54,7 @@ IoMmuMap (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
switch (Operation) { switch (Operation) {
case EdkiiIoMmuOperationBusMasterRead: case EdkiiIoMmuOperationBusMasterRead:
case EdkiiIoMmuOperationBusMasterRead64: case EdkiiIoMmuOperationBusMasterRead64:
@ -71,6 +72,7 @@ IoMmuMap (
ASSERT (FALSE); ASSERT (FALSE);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = IoMmu->SetAttribute ( Status = IoMmu->SetAttribute (
IoMmu, IoMmu,
*Mapping, *Mapping,
@ -86,6 +88,7 @@ IoMmuMap (
*Mapping = NULL; *Mapping = NULL;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
return Status; return Status;
} }
@ -170,6 +173,7 @@ IoMmuAllocateBuffer (
*HostAddress = NULL; *HostAddress = NULL;
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Status = IoMmu->SetAttribute ( Status = IoMmu->SetAttribute (
IoMmu, IoMmu,
*Mapping, *Mapping,
@ -191,10 +195,12 @@ IoMmuAllocateBuffer (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
*HostAddress = (VOID *)(UINTN)HostPhyAddress; *HostAddress = (VOID *)(UINTN)HostPhyAddress;
*DeviceAddress = HostPhyAddress; *DeviceAddress = HostPhyAddress;
*Mapping = NULL; *Mapping = NULL;
} }
return Status; return Status;
} }
@ -240,4 +246,3 @@ IoMmuInit (
(VOID **)IoMmu (VOID **)IoMmu
); );
} }

View File

@ -69,11 +69,9 @@ EhcWriteOpReg (
IN UINT32 Data IN UINT32 Data
) )
{ {
ASSERT (Ehc->CapLen != 0); ASSERT (Ehc->CapLen != 0);
MmioWrite32 (Ehc->UsbHostControllerBaseAddress + Ehc->CapLen + Offset, Data); MmioWrite32 (Ehc->UsbHostControllerBaseAddress + Ehc->CapLen + Offset, Data);
} }
/** /**
@ -454,6 +452,7 @@ EhcInitHC (
if (Ehc->PeriodFrame != NULL) { if (Ehc->PeriodFrame != NULL) {
EhcFreeSched (Ehc); EhcFreeSched (Ehc);
} }
PageNumber = sizeof (PEI_URB)/PAGESIZE +1; PageNumber = sizeof (PEI_URB)/PAGESIZE +1;
Status = PeiServicesAllocatePages ( Status = PeiServicesAllocatePages (
EfiBootServicesCode, EfiBootServicesCode,
@ -473,6 +472,7 @@ EhcInitHC (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// 1. Program the CTRLDSSEGMENT register with the high 32 bit addr // 1. Program the CTRLDSSEGMENT register with the high 32 bit addr
// //
@ -571,7 +571,8 @@ EhcBulkTransfer (
// Validate the parameters // Validate the parameters
// //
if ((DataLength == NULL) || (*DataLength == 0) || if ((DataLength == NULL) || (*DataLength == 0) ||
(Data == NULL) || (Data[0] == NULL) || (TransferResult == NULL)) { (Data == NULL) || (Data[0] == NULL) || (TransferResult == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -581,7 +582,8 @@ EhcBulkTransfer (
if ((DeviceSpeed == EFI_USB_SPEED_LOW) || if ((DeviceSpeed == EFI_USB_SPEED_LOW) ||
((DeviceSpeed == EFI_USB_SPEED_FULL) && (MaximumPacketLength > 64)) || ((DeviceSpeed == EFI_USB_SPEED_FULL) && (MaximumPacketLength > 64)) ||
((EFI_USB_SPEED_HIGH == DeviceSpeed) && (MaximumPacketLength > 512))) { ((EFI_USB_SPEED_HIGH == DeviceSpeed) && (MaximumPacketLength > 512)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -661,8 +663,8 @@ EhcGetRootHubPortNumber (
OUT UINT8 *PortNumber OUT UINT8 *PortNumber
) )
{ {
PEI_USB2_HC_DEV *EhcDev; PEI_USB2_HC_DEV *EhcDev;
EhcDev = PEI_RECOVERY_USB_EHC_DEV_FROM_EHCI_THIS (This); EhcDev = PEI_RECOVERY_USB_EHC_DEV_FROM_EHCI_THIS (This);
if (PortNumber == NULL) { if (PortNumber == NULL) {
@ -671,7 +673,6 @@ EhcGetRootHubPortNumber (
*PortNumber = (UINT8)(EhcDev->HcStructParams & HCSP_NPORTS); *PortNumber = (UINT8)(EhcDev->HcStructParams & HCSP_NPORTS);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
@ -956,7 +957,6 @@ EhcGetRootHubPortStatus (
// //
if (EHC_BIT_IS_SET (State, PORTSC_LINESTATE_K)) { if (EHC_BIT_IS_SET (State, PORTSC_LINESTATE_K)) {
PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED; PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
} else if (EHC_BIT_IS_SET (State, PORTSC_ENABLED)) { } else if (EHC_BIT_IS_SET (State, PORTSC_ENABLED)) {
PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED; PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
} }
@ -1041,29 +1041,33 @@ EhcControlTransfer (
if ((TransferDirection != EfiUsbDataIn) && if ((TransferDirection != EfiUsbDataIn) &&
(TransferDirection != EfiUsbDataOut) && (TransferDirection != EfiUsbDataOut) &&
(TransferDirection != EfiUsbNoData)) { (TransferDirection != EfiUsbNoData))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((TransferDirection == EfiUsbNoData) && if ((TransferDirection == EfiUsbNoData) &&
((Data != NULL) || (*DataLength != 0))) { ((Data != NULL) || (*DataLength != 0)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((TransferDirection != EfiUsbNoData) && if ((TransferDirection != EfiUsbNoData) &&
((Data == NULL) || (*DataLength == 0))) { ((Data == NULL) || (*DataLength == 0)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((MaximumPacketLength != 8) && (MaximumPacketLength != 16) && if ((MaximumPacketLength != 8) && (MaximumPacketLength != 16) &&
(MaximumPacketLength != 32) && (MaximumPacketLength != 64)) { (MaximumPacketLength != 32) && (MaximumPacketLength != 64))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((DeviceSpeed == EFI_USB_SPEED_LOW) || if ((DeviceSpeed == EFI_USB_SPEED_LOW) ||
((DeviceSpeed == EFI_USB_SPEED_FULL) && (MaximumPacketLength > 64)) || ((DeviceSpeed == EFI_USB_SPEED_FULL) && (MaximumPacketLength > 64)) ||
((EFI_USB_SPEED_HIGH == DeviceSpeed) && (MaximumPacketLength > 512))) { ((EFI_USB_SPEED_HIGH == DeviceSpeed) && (MaximumPacketLength > 512)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1246,7 +1250,6 @@ EhcPeimEntry (
EhcDev->UsbHostControllerBaseAddress = (UINT32)BaseAddress; EhcDev->UsbHostControllerBaseAddress = (UINT32)BaseAddress;
EhcDev->HcStructParams = EhcReadCapRegister (EhcDev, EHC_HCSPARAMS_OFFSET); EhcDev->HcStructParams = EhcReadCapRegister (EhcDev, EHC_HCSPARAMS_OFFSET);
EhcDev->HcCapParams = EhcReadCapRegister (EhcDev, EHC_HCCPARAMS_OFFSET); EhcDev->HcCapParams = EhcReadCapRegister (EhcDev, EHC_HCCPARAMS_OFFSET);
EhcDev->CapLen = EhcReadCapRegister (EhcDev, EHC_CAPLENGTH_OFFSET) & 0x0FF; EhcDev->CapLen = EhcReadCapRegister (EhcDev, EHC_CAPLENGTH_OFFSET) & 0x0FF;
@ -1301,7 +1304,6 @@ InitializeUsbHC (
{ {
EFI_STATUS Status; EFI_STATUS Status;
EhcResetHC (EhcDev, EHC_RESET_TIMEOUT); EhcResetHC (EhcDev, EHC_RESET_TIMEOUT);
Status = EhcInitHC (EhcDev); Status = EhcInitHC (EhcDev);

View File

@ -51,7 +51,6 @@ typedef struct _PEI_USB2_HC_DEV PEI_USB2_HC_DEV;
#define EHC_RESET_TIMEOUT (1 * EHC_1_SECOND) #define EHC_RESET_TIMEOUT (1 * EHC_1_SECOND)
#define EHC_GENERIC_TIMEOUT (10 * EHC_1_MILLISECOND) #define EHC_GENERIC_TIMEOUT (10 * EHC_1_MILLISECOND)
// //
// Wait for roothub port power stable, refers to Spec[EHCI1.0-2.3.9] // Wait for roothub port power stable, refers to Spec[EHCI1.0-2.3.9]
// //
@ -64,7 +63,6 @@ typedef struct _PEI_USB2_HC_DEV PEI_USB2_HC_DEV;
#define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field) #define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field)
#define EHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF)) #define EHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))
#define EHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF)) #define EHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
#define EHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit))) #define EHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))

View File

@ -10,8 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_EHCI_REG_H_ #ifndef _EFI_EHCI_REG_H_
#define _EFI_EHCI_REG_H_ #define _EFI_EHCI_REG_H_
// //
// Capability register offset // Capability register offset
// //
@ -106,7 +104,6 @@ typedef struct {
} USB_CLASSC; } USB_CLASSC;
#pragma pack() #pragma pack()
/** /**
Read EHCI capability register. Read EHCI capability register.

View File

@ -247,7 +247,7 @@ EhcLinkQhToAsync (
Qh->NextQh = Head->NextQh; Qh->NextQh = Head->NextQh;
Head->NextQh = Qh; Head->NextQh = Qh;
Qh->QhHw.HorizonLink = QH_LINK (Head, EHC_TYPE_QH, FALSE);; Qh->QhHw.HorizonLink = QH_LINK (Head, EHC_TYPE_QH, FALSE);
Head->QhHw.HorizonLink = QH_LINK (Qh, EHC_TYPE_QH, FALSE); Head->QhHw.HorizonLink = QH_LINK (Qh, EHC_TYPE_QH, FALSE);
} }
@ -352,7 +352,6 @@ EhcCheckUrbResult (
Finished = TRUE; Finished = TRUE;
goto ON_EXIT; goto ON_EXIT;
} else if (EHC_BIT_IS_SET (State, QTD_STAT_ACTIVE)) { } else if (EHC_BIT_IS_SET (State, QTD_STAT_ACTIVE)) {
// //
// The QTD is still active, no need to check furthur. // The QTD is still active, no need to check furthur.
@ -361,7 +360,6 @@ EhcCheckUrbResult (
Finished = FALSE; Finished = FALSE;
goto ON_EXIT; goto ON_EXIT;
} else { } else {
// //
// This QTD is finished OK or met short packet read. Update the // This QTD is finished OK or met short packet read. Update the
@ -381,7 +379,6 @@ EhcCheckUrbResult (
// Status Stage of the setup transfer to get the finial result // Status Stage of the setup transfer to get the finial result
// //
if (QtdHw->AltNext == QTD_LINK (Ehc->ShortReadStop, FALSE)) { if (QtdHw->AltNext == QTD_LINK (Ehc->ShortReadStop, FALSE)) {
Finished = TRUE; Finished = TRUE;
goto ON_EXIT; goto ON_EXIT;
} }
@ -460,4 +457,3 @@ EhcExecTransfer (
return Status; return Status;
} }

View File

@ -214,6 +214,7 @@ EhcCreateQh (
if (Ep->DevSpeed != EFI_USB_SPEED_HIGH) { if (Ep->DevSpeed != EFI_USB_SPEED_HIGH) {
QhHw->CtrlEp = 1; QhHw->CtrlEp = 1;
} }
break; break;
case EHC_INT_TRANSFER_ASYNC: case EHC_INT_TRANSFER_ASYNC:

View File

@ -138,7 +138,6 @@ typedef struct {
} QH_HW; } QH_HW;
#pragma pack() #pragma pack()
// //
// Endpoint address and its capabilities // Endpoint address and its capabilities
// //
@ -167,8 +166,6 @@ struct _PEI_EHC_QTD {
UINTN DataLen; // Original amount of data in this QTD UINTN DataLen; // Original amount of data in this QTD
}; };
// //
// Software QH structure. All three different transaction types // Software QH structure. All three different transaction types
// supported by UEFI USB, that is the control/bulk/interrupt // supported by UEFI USB, that is the control/bulk/interrupt
@ -321,4 +318,5 @@ EhcCreateUrb (
IN UINTN Interval IN UINTN Interval
) )
; ;
#endif #endif

View File

@ -46,6 +46,7 @@ UsbHcAllocMemBlock (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
ZeroMem ((VOID *)(UINTN)TempPtr, PageNumber*EFI_PAGE_SIZE); ZeroMem ((VOID *)(UINTN)TempPtr, PageNumber*EFI_PAGE_SIZE);
// //
@ -68,6 +69,7 @@ UsbHcAllocMemBlock (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
ZeroMem ((VOID *)(UINTN)TempPtr, PageNumber*EFI_PAGE_SIZE); ZeroMem ((VOID *)(UINTN)TempPtr, PageNumber*EFI_PAGE_SIZE);
Block->Bits = (UINT8 *)(UINTN)TempPtr; Block->Bits = (UINT8 *)(UINTN)TempPtr;
@ -82,6 +84,7 @@ UsbHcAllocMemBlock (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
ZeroMem (BufHost, Pages*EFI_PAGE_SIZE); ZeroMem (BufHost, Pages*EFI_PAGE_SIZE);
// //
@ -98,7 +101,6 @@ UsbHcAllocMemBlock (
Block->Next = NULL; Block->Next = NULL;
return Block; return Block;
} }
/** /**
@ -164,7 +166,6 @@ UsbHcAllocMemFromBlock (
} }
NEXT_BIT (Byte, Bit); NEXT_BIT (Byte, Bit);
} else { } else {
NEXT_BIT (Byte, Bit); NEXT_BIT (Byte, Bit);
@ -276,7 +277,6 @@ UsbHcIsMemBlockEmpty (
{ {
UINTN Index; UINTN Index;
for (Index = 0; Index < Block->BitsLen; Index++) { for (Index = 0; Index < Block->BitsLen; Index++) {
if (Block->Bits[Index] != 0) { if (Block->Bits[Index] != 0) {
return FALSE; return FALSE;
@ -286,7 +286,6 @@ UsbHcIsMemBlockEmpty (
return TRUE; return TRUE;
} }
/** /**
Initialize the memory management pool for the host controller. Initialize the memory management pool for the host controller.
@ -321,6 +320,7 @@ UsbHcInitMemPool (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
ZeroMem ((VOID *)(UINTN)TempPtr, PageNumber*EFI_PAGE_SIZE); ZeroMem ((VOID *)(UINTN)TempPtr, PageNumber*EFI_PAGE_SIZE);
Pool = (USBHC_MEM_POOL *)((UINTN)TempPtr); Pool = (USBHC_MEM_POOL *)((UINTN)TempPtr);
@ -425,6 +425,7 @@ UsbHcAllocateMem (
} else { } else {
Pages = USBHC_MEM_DEFAULT_PAGES; Pages = USBHC_MEM_DEFAULT_PAGES;
} }
NewBlock = UsbHcAllocMemBlock (Ehc, Pool, Pages); NewBlock = UsbHcAllocMemBlock (Ehc, Pool, Pages);
if (NewBlock == NULL) { if (NewBlock == NULL) {

View File

@ -66,7 +66,6 @@ typedef struct _USBHC_MEM_POOL {
} \ } \
} while (0) } while (0)
/** /**
Calculate the corresponding pci bus address according to the Mem parameter. Calculate the corresponding pci bus address according to the Mem parameter.

View File

@ -169,7 +169,7 @@ AtapiGetBlockDeviceMediaInfo (
AtapiBlkIoDev = NULL; AtapiBlkIoDev = NULL;
if (This == NULL || MediaInfo == NULL) { if ((This == NULL) || (MediaInfo == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -264,7 +264,6 @@ AtapiReadBlocks (
OUT VOID *Buffer OUT VOID *Buffer
) )
{ {
EFI_PEI_BLOCK_IO_MEDIA MediaInfo; EFI_PEI_BLOCK_IO_MEDIA MediaInfo;
EFI_STATUS Status; EFI_STATUS Status;
UINTN NumberOfBlocks; UINTN NumberOfBlocks;
@ -412,7 +411,7 @@ AtapiGetBlockDeviceMediaInfo2 (
AtapiBlkIoDev = NULL; AtapiBlkIoDev = NULL;
if (This == NULL || MediaInfo == NULL) { if ((This == NULL) || (MediaInfo == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -427,6 +426,7 @@ AtapiGetBlockDeviceMediaInfo2 (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Get media info from AtapiBlkIoDev // Get media info from AtapiBlkIoDev
// //
@ -503,7 +503,6 @@ AtapiReadBlocks2 (
return Status; return Status;
} }
/** /**
Enumerate Atapi devices. Enumerate Atapi devices.
@ -611,6 +610,7 @@ AtapiEnumerateDevices (
AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo2.MediaPresent = FALSE; AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo2.MediaPresent = FALSE;
AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo2.LastBlock = 0; AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo2.LastBlock = 0;
} }
DeviceCount += 1; DeviceCount += 1;
} }
} }
@ -644,11 +644,11 @@ DiscoverAtapiDevice (
if (!DetectIDEController (AtapiBlkIoDev, DevicePosition)) { if (!DetectIDEController (AtapiBlkIoDev, DevicePosition)) {
return FALSE; return FALSE;
} }
// //
// test if it is an ATAPI device (only supported device) // test if it is an ATAPI device (only supported device)
// //
if (ATAPIIdentify (AtapiBlkIoDev, DevicePosition) == EFI_SUCCESS) { if (ATAPIIdentify (AtapiBlkIoDev, DevicePosition) == EFI_SUCCESS) {
Status = Inquiry (AtapiBlkIoDev, DevicePosition, MediaInfo, MediaInfo2); Status = Inquiry (AtapiBlkIoDev, DevicePosition, MediaInfo, MediaInfo2);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
return TRUE; return TRUE;
@ -781,6 +781,7 @@ CheckPowerMode (
if (SectorCountValue != 0x55) { if (SectorCountValue != 0x55) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
// //
// Send a "ATAPI TEST UNIT READY" command ... slow but accurate // Send a "ATAPI TEST UNIT READY" command ... slow but accurate
// //
@ -821,6 +822,7 @@ DetectIDEController (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return FALSE; return FALSE;
} }
// //
// Send 'check power' command for IDE device // Send 'check power' command for IDE device
// //
@ -865,10 +867,10 @@ WaitForBSYClear (
if ((StatusValue & ATA_STSREG_BSY) == 0x00) { if ((StatusValue & ATA_STSREG_BSY) == 0x00) {
break; break;
} }
MicroSecondDelay (250); MicroSecondDelay (250);
Delay--; Delay--;
} while (Delay != 0); } while (Delay != 0);
if (Delay == 0) { if (Delay == 0) {
@ -925,7 +927,6 @@ DRDYReady (
MicroSecondDelay (250); MicroSecondDelay (250);
Delay--; Delay--;
} while (Delay != 0); } while (Delay != 0);
if (Delay == 0) { if (Delay == 0) {
@ -964,7 +965,6 @@ DRQClear (
Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1; Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
do { do {
StatusValue = IoRead8 (StatusRegister); StatusValue = IoRead8 (StatusRegister);
// //
@ -1022,7 +1022,6 @@ DRQClear2 (
Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1; Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
do { do {
AltStatusValue = IoRead8 (AltStatusRegister); AltStatusValue = IoRead8 (AltStatusRegister);
// //
@ -1095,12 +1094,12 @@ DRQReady (
} }
if ((StatusValue & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) { if ((StatusValue & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) {
ErrValue = IoRead8 (IdeIoRegisters->Reg1.Error); ErrValue = IoRead8 (IdeIoRegisters->Reg1.Error);
if ((ErrValue & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { if ((ErrValue & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) {
return EFI_ABORTED; return EFI_ABORTED;
} }
} }
MicroSecondDelay (250); MicroSecondDelay (250);
Delay--; Delay--;
@ -1143,7 +1142,6 @@ DRQReady2 (
Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1; Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
do { do {
AltStatusValue = IoRead8 (AltStatusRegister); AltStatusValue = IoRead8 (AltStatusRegister);
// //
@ -1154,12 +1152,12 @@ DRQReady2 (
} }
if ((AltStatusValue & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) { if ((AltStatusValue & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) {
ErrValue = IoRead8 (IdeIoRegisters->Reg1.Error); ErrValue = IoRead8 (IdeIoRegisters->Reg1.Error);
if ((ErrValue & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { if ((ErrValue & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) {
return EFI_ABORTED; return EFI_ABORTED;
} }
} }
MicroSecondDelay (250); MicroSecondDelay (250);
Delay--; Delay--;
@ -1193,12 +1191,10 @@ CheckErrorStatus (
StatusValue = IoRead8 (StatusReg); StatusValue = IoRead8 (StatusReg);
if ((StatusValue & (ATA_STSREG_ERR | ATA_STSREG_DWF | ATA_STSREG_CORR)) == 0) { if ((StatusValue & (ATA_STSREG_ERR | ATA_STSREG_DWF | ATA_STSREG_CORR)) == 0) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
/** /**
@ -1261,9 +1257,11 @@ ATAPIIdentify (
AtapiBlkIoDev, AtapiBlkIoDev,
&(AtapiBlkIoDev->IdeIoPortReg[Channel]), &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
ATATIMEOUT ATATIMEOUT
) != EFI_SUCCESS) { ) != EFI_SUCCESS)
{
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// select device via Head/Device register. // select device via Head/Device register.
// Before write Head/Device register, BSY and DRQ must be 0. // Before write Head/Device register, BSY and DRQ must be 0.
@ -1271,6 +1269,7 @@ ATAPIIdentify (
if (DRQClear2 (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), ATATIMEOUT) != EFI_SUCCESS) { if (DRQClear2 (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), ATATIMEOUT) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// e0:1110,0000-- bit7 and bit5 are reserved bits. // e0:1110,0000-- bit7 and bit5 are reserved bits.
// bit6 set means LBA mode // bit6 set means LBA mode
@ -1285,8 +1284,8 @@ ATAPIIdentify (
AtapiBlkIoDev, AtapiBlkIoDev,
&(AtapiBlkIoDev->IdeIoPortReg[Channel]), &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
ATATIMEOUT ATATIMEOUT
) != EFI_SUCCESS) { ) != EFI_SUCCESS)
{
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -1330,15 +1329,16 @@ ATAPIIdentify (
} }
if (CheckErrorStatus (AtapiBlkIoDev, StatusReg) != EFI_SUCCESS) { if (CheckErrorStatus (AtapiBlkIoDev, StatusReg) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Get the byte count for one series of read // Get the byte count for one series of read
// //
if ((WordCount + Increment) > ByteCount / 2) { if ((WordCount + Increment) > ByteCount / 2) {
Increment = ByteCount / 2 - WordCount; Increment = ByteCount / 2 - WordCount;
} }
// //
// perform a series of read without check DRQ ready // perform a series of read without check DRQ ready
// //
@ -1347,8 +1347,8 @@ ATAPIIdentify (
} }
WordCount += Increment; WordCount += Increment;
} }
// //
// while // while
// //
@ -1356,12 +1356,12 @@ ATAPIIdentify (
AtapiBlkIoDev, AtapiBlkIoDev,
&(AtapiBlkIoDev->IdeIoPortReg[Channel]), &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
ATATIMEOUT ATATIMEOUT
) != EFI_SUCCESS) { ) != EFI_SUCCESS)
{
return CheckErrorStatus (AtapiBlkIoDev, StatusReg); return CheckErrorStatus (AtapiBlkIoDev, StatusReg);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
@ -1471,9 +1471,11 @@ AtapiPacketCommandIn (
AtapiBlkIoDev, AtapiBlkIoDev,
&(AtapiBlkIoDev->IdeIoPortReg[Channel]), &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
ATATIMEOUT ATATIMEOUT
) != EFI_SUCCESS) { ) != EFI_SUCCESS)
{
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Select device via Device/Head Register. // Select device via Device/Head Register.
// DEFAULT_CMD: 0xa0 (1010,0000) // DEFAULT_CMD: 0xa0 (1010,0000)
@ -1508,6 +1510,7 @@ AtapiPacketCommandIn (
if (Status != EFI_SUCCESS) { if (Status != EFI_SUCCESS) {
return Status; return Status;
} }
// //
// Send out command packet // Send out command packet
// //
@ -1527,9 +1530,10 @@ AtapiPacketCommandIn (
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
if (Buffer == NULL || ByteCount == 0) { if ((Buffer == NULL) || (ByteCount == 0)) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
// //
// call PioReadWriteData() function to get // call PioReadWriteData() function to get
// requested transfer data form device. // requested transfer data form device.
@ -1551,9 +1555,11 @@ AtapiPacketCommandIn (
AtapiBlkIoDev, AtapiBlkIoDev,
&(AtapiBlkIoDev->IdeIoPortReg[Channel]), &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
TimeoutInMilliSeconds TimeoutInMilliSeconds
) != EFI_SUCCESS) { ) != EFI_SUCCESS)
{
return CheckErrorStatus (AtapiBlkIoDev, StatusReg); return CheckErrorStatus (AtapiBlkIoDev, StatusReg);
} }
// //
// read Status Register will clear interrupt // read Status Register will clear interrupt
// //
@ -1571,21 +1577,19 @@ AtapiPacketCommandIn (
// perform a series data In/Out. // perform a series data In/Out.
// //
for (Index = 0; (Index < WordCount) && (ActualWordCount < RequiredWordCount); Index++, ActualWordCount++) { for (Index = 0; (Index < WordCount) && (ActualWordCount < RequiredWordCount); Index++, ActualWordCount++) {
*PtrBuffer = IoRead16 (DataReg); *PtrBuffer = IoRead16 (DataReg);
PtrBuffer++; PtrBuffer++;
} }
if (((ATAPI_REQUEST_SENSE_CMD *) Packet)->opcode == ATA_CMD_REQUEST_SENSE && ActualWordCount >= 4) { if ((((ATAPI_REQUEST_SENSE_CMD *)Packet)->opcode == ATA_CMD_REQUEST_SENSE) && (ActualWordCount >= 4)) {
RequiredWordCount = MIN ( RequiredWordCount = MIN (
RequiredWordCount, RequiredWordCount,
(UINT32)(4 + (((ATAPI_REQUEST_SENSE_DATA *)Buffer)->addnl_sense_length / 2)) (UINT32)(4 + (((ATAPI_REQUEST_SENSE_DATA *)Buffer)->addnl_sense_length / 2))
); );
} }
} }
// //
// After data transfer is completed, normally, DRQ bit should clear. // After data transfer is completed, normally, DRQ bit should clear.
// //
@ -1593,6 +1597,7 @@ AtapiPacketCommandIn (
if (Status != EFI_SUCCESS) { if (Status != EFI_SUCCESS) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// read status register to check whether error happens. // read status register to check whether error happens.
// //
@ -1652,6 +1657,7 @@ Inquiry (
if (Status != EFI_SUCCESS) { if (Status != EFI_SUCCESS) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Identify device type via INQUIRY data. // Identify device type via INQUIRY data.
// //
@ -1718,7 +1724,6 @@ DetectMedia (
IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2 IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2
) )
{ {
UINTN Index; UINTN Index;
UINTN RetryNum; UINTN RetryNum;
UINTN MaxRetryNum; UINTN MaxRetryNum;
@ -1738,7 +1743,6 @@ DetectMedia (
// the device will produce corresponding Sense data. // the device will produce corresponding Sense data.
// //
for (Index = 0; Index < 2; Index++) { for (Index = 0; Index < 2; Index++) {
Status = TestUnitReady (AtapiBlkIoDev, DevicePosition); Status = TestUnitReady (AtapiBlkIoDev, DevicePosition);
if (Status != EFI_SUCCESS) { if (Status != EFI_SUCCESS) {
Status = ResetDevice (AtapiBlkIoDev, DevicePosition, FALSE); Status = ResetDevice (AtapiBlkIoDev, DevicePosition, FALSE);
@ -1746,7 +1750,6 @@ DetectMedia (
if (Status != EFI_SUCCESS) { if (Status != EFI_SUCCESS) {
ResetDevice (AtapiBlkIoDev, DevicePosition, TRUE); ResetDevice (AtapiBlkIoDev, DevicePosition, TRUE);
} }
} else { } else {
break; break;
} }
@ -1776,9 +1779,7 @@ DetectMedia (
} }
if (Status == EFI_SUCCESS) { if (Status == EFI_SUCCESS) {
if (IsNoMedia (SenseBuffers, SenseCounts)) { if (IsNoMedia (SenseBuffers, SenseCounts)) {
NeedReadCapacity = FALSE; NeedReadCapacity = FALSE;
MediaInfo->MediaPresent = FALSE; MediaInfo->MediaPresent = FALSE;
MediaInfo->LastBlock = 0; MediaInfo->LastBlock = 0;
@ -1801,19 +1802,16 @@ DetectMedia (
// initial retry once // initial retry once
// //
for (Index = 0; (Index < RetryNum) && (Index < MaxRetryNum); Index++) { for (Index = 0; (Index < RetryNum) && (Index < MaxRetryNum); Index++) {
Status = ReadCapacity (AtapiBlkIoDev, DevicePosition, MediaInfo, MediaInfo2); Status = ReadCapacity (AtapiBlkIoDev, DevicePosition, MediaInfo, MediaInfo2);
MicroSecondDelay (200000); MicroSecondDelay (200000);
SenseCounts = MAX_SENSE_KEY_COUNT; SenseCounts = MAX_SENSE_KEY_COUNT;
if (Status != EFI_SUCCESS) { if (Status != EFI_SUCCESS) {
Status = RequestSense (AtapiBlkIoDev, DevicePosition, SenseBuffers, &SenseCounts); Status = RequestSense (AtapiBlkIoDev, DevicePosition, SenseBuffers, &SenseCounts);
// //
// If Request Sense data failed, reset the device and retry. // If Request Sense data failed, reset the device and retry.
// //
if (Status != EFI_SUCCESS) { if (Status != EFI_SUCCESS) {
Status = ResetDevice (AtapiBlkIoDev, DevicePosition, FALSE); Status = ResetDevice (AtapiBlkIoDev, DevicePosition, FALSE);
// //
// if ATAPI soft reset fail, // if ATAPI soft reset fail,
@ -1829,11 +1827,11 @@ DetectMedia (
// //
continue; continue;
} }
// //
// No Media // No Media
// //
if (IsNoMedia (SenseBuffers, SenseCounts)) { if (IsNoMedia (SenseBuffers, SenseCounts)) {
MediaInfo->MediaPresent = FALSE; MediaInfo->MediaPresent = FALSE;
MediaInfo->LastBlock = 0; MediaInfo->LastBlock = 0;
MediaInfo2->MediaPresent = FALSE; MediaInfo2->MediaPresent = FALSE;
@ -1857,15 +1855,13 @@ DetectMedia (
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
} }
// //
// if read capacity fail not for above reasons, retry once more // if read capacity fail not for above reasons, retry once more
// //
RetryNum++; RetryNum++;
} }
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
@ -1908,7 +1904,6 @@ ResetDevice (
HeadReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Head; HeadReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Head;
if (Extensive) { if (Extensive) {
DevControl = 0; DevControl = 0;
DevControl |= ATA_CTLREG_SRST; DevControl |= ATA_CTLREG_SRST;
// //
@ -1940,7 +1935,6 @@ ResetDevice (
if (WaitForBSYClear (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), 31000) == EFI_TIMEOUT) { if (WaitForBSYClear (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), 31000) == EFI_TIMEOUT) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
} else { } else {
// //
// for ATAPI device, no need to wait DRDY ready after device selecting. // for ATAPI device, no need to wait DRDY ready after device selecting.
@ -1959,6 +1953,7 @@ ResetDevice (
if (WaitForBSYClear (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), 31000) != EFI_SUCCESS) { if (WaitForBSYClear (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), 31000) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// stall 5 seconds to make the device status stable // stall 5 seconds to make the device status stable
// //
@ -1966,7 +1961,6 @@ ResetDevice (
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
@ -2012,7 +2006,6 @@ RequestSense (
// request sense data from device continiously until no sense data exists in the device. // request sense data from device continiously until no sense data exists in the device.
// //
for (SenseReq = TRUE; SenseReq;) { for (SenseReq = TRUE; SenseReq;) {
Sense = (ATAPI_REQUEST_SENSE_DATA *)Ptr; Sense = (ATAPI_REQUEST_SENSE_DATA *)Ptr;
// //
@ -2042,6 +2035,7 @@ RequestSense (
if (*SenseCounts > MAX_SENSE_KEY_COUNT) { if (*SenseCounts > MAX_SENSE_KEY_COUNT) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
// //
// We limit MAX sense data count to 20 in order to avoid dead loop. Some // We limit MAX sense data count to 20 in order to avoid dead loop. Some
// incompatible ATAPI devices don't retrive NO_SENSE when there is no media. // incompatible ATAPI devices don't retrive NO_SENSE when there is no media.
@ -2049,7 +2043,6 @@ RequestSense (
// supposed to be large enough for any ATAPI device. // supposed to be large enough for any ATAPI device.
// //
if ((Sense->sense_key != ATA_SK_NO_SENSE) && ((*SenseCounts) < 20)) { if ((Sense->sense_key != ATA_SK_NO_SENSE) && ((*SenseCounts) < 20)) {
Ptr += sizeof (ATAPI_REQUEST_SENSE_DATA) / 2; Ptr += sizeof (ATAPI_REQUEST_SENSE_DATA) / 2;
// //
// Ptr is word based pointer // Ptr is word based pointer
@ -2100,7 +2093,6 @@ ReadCapacity (
ZeroMem (&FormatData, sizeof (FormatData)); ZeroMem (&FormatData, sizeof (FormatData));
if (MediaInfo->DeviceType == IdeCDROM) { if (MediaInfo->DeviceType == IdeCDROM) {
ZeroMem (&Packet, sizeof (ATAPI_PACKET_COMMAND)); ZeroMem (&Packet, sizeof (ATAPI_PACKET_COMMAND));
Packet.Inquiry.opcode = ATA_CMD_READ_CAPACITY; Packet.Inquiry.opcode = ATA_CMD_READ_CAPACITY;
Status = AtapiPacketCommandIn ( Status = AtapiPacketCommandIn (
@ -2111,7 +2103,6 @@ ReadCapacity (
sizeof (ATAPI_READ_CAPACITY_DATA), sizeof (ATAPI_READ_CAPACITY_DATA),
ATAPITIMEOUT ATAPITIMEOUT
); );
} else { } else {
// //
// DeviceType == IdeLS120 // DeviceType == IdeLS120
@ -2130,9 +2121,7 @@ ReadCapacity (
} }
if (Status == EFI_SUCCESS) { if (Status == EFI_SUCCESS) {
if (MediaInfo->DeviceType == IdeCDROM) { if (MediaInfo->DeviceType == IdeCDROM) {
MediaInfo->LastBlock = ((UINT32)Data.LastLba3 << 24) | (Data.LastLba2 << 16) | (Data.LastLba1 << 8) | Data.LastLba0; MediaInfo->LastBlock = ((UINT32)Data.LastLba3 << 24) | (Data.LastLba2 << 16) | (Data.LastLba1 << 8) | Data.LastLba0;
MediaInfo->MediaPresent = TRUE; MediaInfo->MediaPresent = TRUE;
// //
@ -2147,7 +2136,6 @@ ReadCapacity (
} }
if (MediaInfo->DeviceType == IdeLS120) { if (MediaInfo->DeviceType == IdeLS120) {
if (FormatData.DesCode == 3) { if (FormatData.DesCode == 3) {
MediaInfo->MediaPresent = FALSE; MediaInfo->MediaPresent = FALSE;
MediaInfo->LastBlock = 0; MediaInfo->LastBlock = 0;
@ -2167,12 +2155,10 @@ ReadCapacity (
MediaInfo2->LastBlock = MediaInfo->LastBlock; MediaInfo2->LastBlock = MediaInfo->LastBlock;
MediaInfo2->MediaPresent = MediaInfo->MediaPresent; MediaInfo2->MediaPresent = MediaInfo->MediaPresent;
MediaInfo2->BlockSize = (UINT32)MediaInfo->BlockSize; MediaInfo2->BlockSize = (UINT32)MediaInfo->BlockSize;
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} else { } else {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -2202,7 +2188,6 @@ ReadSectors (
IN UINTN BlockSize IN UINTN BlockSize
) )
{ {
ATAPI_PACKET_COMMAND Packet; ATAPI_PACKET_COMMAND Packet;
ATAPI_READ10_CMD *Read10Packet; ATAPI_READ10_CMD *Read10Packet;
EFI_STATUS Status; EFI_STATUS Status;
@ -2232,12 +2217,12 @@ ReadSectors (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
while (BlocksRemaining > 0) { while (BlocksRemaining > 0) {
if (BlocksRemaining <= MaxBlock) { if (BlocksRemaining <= MaxBlock) {
SectorCount = (UINT16)BlocksRemaining; SectorCount = (UINT16)BlocksRemaining;
} else { } else {
SectorCount = MaxBlock; SectorCount = MaxBlock;
} }
// //
// fill the Packet data sturcture // fill the Packet data sturcture
// //
@ -2306,7 +2291,6 @@ IsNoMedia (
SensePtr = SenseData; SensePtr = SenseData;
for (Index = 0; Index < SenseCounts; Index++) { for (Index = 0; Index < SenseCounts; Index++) {
if ((SensePtr->sense_key == ATA_SK_NOT_READY) && (SensePtr->addnl_sense_code == ATA_ASC_NO_MEDIA)) { if ((SensePtr->sense_key == ATA_SK_NOT_READY) && (SensePtr->addnl_sense_code == ATA_ASC_NO_MEDIA)) {
IsNoMedia = TRUE; IsNoMedia = TRUE;
} }
@ -2342,7 +2326,6 @@ IsDeviceStateUnclear (
SensePtr = SenseData; SensePtr = SenseData;
for (Index = 0; Index < SenseCounts; Index++) { for (Index = 0; Index < SenseCounts; Index++) {
if (SensePtr->sense_key == 0x06) { if (SensePtr->sense_key == 0x06) {
// //
// Sense key is 0x06 means the device is just be reset or media just // Sense key is 0x06 means the device is just be reset or media just
@ -2383,9 +2366,7 @@ IsMediaError (
SensePtr = SenseData; SensePtr = SenseData;
for (Index = 0; Index < SenseCounts; Index++) { for (Index = 0; Index < SenseCounts; Index++) {
switch (SensePtr->sense_key) { switch (SensePtr->sense_key) {
case ATA_SK_MEDIUM_ERROR: case ATA_SK_MEDIUM_ERROR:
switch (SensePtr->addnl_sense_code) { switch (SensePtr->addnl_sense_code) {
case ATA_ASC_MEDIA_ERR1: case ATA_ASC_MEDIA_ERR1:
@ -2419,6 +2400,7 @@ IsMediaError (
default: default:
break; break;
} }
break; break;
default: default:
@ -2459,9 +2441,7 @@ IsDriveReady (
SensePtr = SenseData; SensePtr = SenseData;
for (Index = 0; Index < SenseCounts; Index++) { for (Index = 0; Index < SenseCounts; Index++) {
switch (SensePtr->sense_key) { switch (SensePtr->sense_key) {
case ATA_SK_NOT_READY: case ATA_SK_NOT_READY:
switch (SensePtr->addnl_sense_code) { switch (SensePtr->addnl_sense_code) {
case ATA_ASC_NOT_READY: case ATA_ASC_NOT_READY:
@ -2476,11 +2456,13 @@ IsDriveReady (
*NeedRetry = FALSE; *NeedRetry = FALSE;
break; break;
} }
break; break;
default: default:
break; break;
} }
break; break;
default: default:

View File

@ -26,7 +26,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h> #include <Library/PcdLib.h>
#include <IndustryStandard/Atapi.h> #include <IndustryStandard/Atapi.h>
#define MAX_SENSE_KEY_COUNT 6 #define MAX_SENSE_KEY_COUNT 6
@ -81,11 +80,9 @@ typedef struct {
} IDE_BASE_REGISTERS; } IDE_BASE_REGISTERS;
typedef struct { typedef struct {
UINTN DevicePosition; UINTN DevicePosition;
EFI_PEI_BLOCK_IO_MEDIA MediaInfo; EFI_PEI_BLOCK_IO_MEDIA MediaInfo;
EFI_PEI_BLOCK_IO2_MEDIA MediaInfo2; EFI_PEI_BLOCK_IO2_MEDIA MediaInfo2;
} PEI_ATAPI_DEVICE_INFO; } PEI_ATAPI_DEVICE_INFO;
#define ATAPI_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('a', 'b', 'i', 'o') #define ATAPI_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('a', 'b', 'i', 'o')
@ -106,7 +103,6 @@ typedef struct {
#define PEI_RECOVERY_ATAPI_FROM_BLKIO_THIS(a) CR (a, ATAPI_BLK_IO_DEV, AtapiBlkIo, ATAPI_BLK_IO_DEV_SIGNATURE) #define PEI_RECOVERY_ATAPI_FROM_BLKIO_THIS(a) CR (a, ATAPI_BLK_IO_DEV, AtapiBlkIo, ATAPI_BLK_IO_DEV_SIGNATURE)
#define PEI_RECOVERY_ATAPI_FROM_BLKIO2_THIS(a) CR (a, ATAPI_BLK_IO_DEV, AtapiBlkIo2, ATAPI_BLK_IO_DEV_SIGNATURE) #define PEI_RECOVERY_ATAPI_FROM_BLKIO2_THIS(a) CR (a, ATAPI_BLK_IO_DEV, AtapiBlkIo2, ATAPI_BLK_IO_DEV_SIGNATURE)
#define STALL_1_MILLI_SECOND 1000 // stall 1 ms #define STALL_1_MILLI_SECOND 1000 // stall 1 ms
#define STALL_1_SECONDS 1000 * STALL_1_MILLI_SECOND #define STALL_1_SECONDS 1000 * STALL_1_MILLI_SECOND

View File

@ -178,7 +178,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED UINT64 mIncompatiblePciDeviceList[] = {
LIST_END_TAG LIST_END_TAG
}; };
/** /**
Entry point of the incompatible pci device support code. Setup an incompatible device list template Entry point of the incompatible pci device support code. Setup an incompatible device list template
and install EFI Incompatible PCI Device Support protocol. and install EFI Incompatible PCI Device Support protocol.
@ -260,6 +259,7 @@ PCheckDevice (
if (Configuration == NULL) { if (Configuration == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Initialize the return value to NULL // Initialize the return value to NULL
// //
@ -267,7 +267,6 @@ PCheckDevice (
ListPtr = mIncompatiblePciDeviceList; ListPtr = mIncompatiblePciDeviceList;
while (*ListPtr != LIST_END_TAG) { while (*ListPtr != LIST_END_TAG) {
Tag = *ListPtr; Tag = *ListPtr;
switch (Tag) { switch (Tag) {
@ -306,6 +305,7 @@ PCheckDevice (
continue; continue;
} }
} }
// //
// Matched an item, so construct the ACPI descriptor for the resource. // Matched an item, so construct the ACPI descriptor for the resource.
// //
@ -315,6 +315,7 @@ PCheckDevice (
for (Index = 0, TempListPtr = ListPtr; *TempListPtr == DEVICE_RES_TAG; Index++) { for (Index = 0, TempListPtr = ListPtr; *TempListPtr == DEVICE_RES_TAG; Index++) {
TempListPtr = TempListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64)); TempListPtr = TempListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));
} }
// //
// If there is at least one type of resource request, // If there is at least one type of resource request,
// allocate an acpi resource node // allocate an acpi resource node
@ -334,7 +335,6 @@ PCheckDevice (
// according to the EFI_PCI_RESOUCE_DESCRIPTOR structure // according to the EFI_PCI_RESOUCE_DESCRIPTOR structure
// //
for ( ; *ListPtr == DEVICE_RES_TAG;) { for ( ; *ListPtr == DEVICE_RES_TAG;) {
Dsc = (EFI_PCI_RESOUCE_DESCRIPTOR *)(ListPtr + 1); Dsc = (EFI_PCI_RESOUCE_DESCRIPTOR *)(ListPtr + 1);
AcpiPtr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; AcpiPtr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR;
@ -342,7 +342,7 @@ PCheckDevice (
AcpiPtr->ResType = (UINT8)Dsc->ResType; AcpiPtr->ResType = (UINT8)Dsc->ResType;
AcpiPtr->GenFlag = (UINT8)Dsc->GenFlag; AcpiPtr->GenFlag = (UINT8)Dsc->GenFlag;
AcpiPtr->SpecificFlag = (UINT8)Dsc->SpecificFlag; AcpiPtr->SpecificFlag = (UINT8)Dsc->SpecificFlag;
AcpiPtr->AddrSpaceGranularity = Dsc->AddrSpaceGranularity;; AcpiPtr->AddrSpaceGranularity = Dsc->AddrSpaceGranularity;
AcpiPtr->AddrRangeMin = Dsc->AddrRangeMin; AcpiPtr->AddrRangeMin = Dsc->AddrRangeMin;
AcpiPtr->AddrRangeMax = Dsc->AddrRangeMax; AcpiPtr->AddrRangeMax = Dsc->AddrRangeMax;
AcpiPtr->AddrTranslationOffset = Dsc->AddrTranslationOffset; AcpiPtr->AddrTranslationOffset = Dsc->AddrTranslationOffset;
@ -351,6 +351,7 @@ PCheckDevice (
ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64)); ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));
AcpiPtr++; AcpiPtr++;
} }
// //
// Put the checksum // Put the checksum
// //
@ -376,4 +377,3 @@ PCheckDevice (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }

View File

@ -73,10 +73,14 @@ NonDiscoverablePciDeviceSupported (
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc;
INTN Idx; INTN Idx;
Status = gBS->OpenProtocol (DeviceHandle, Status = gBS->OpenProtocol (
&gEdkiiNonDiscoverableDeviceProtocolGuid, (VOID **)&Device, DeviceHandle,
This->DriverBindingHandle, DeviceHandle, &gEdkiiNonDiscoverableDeviceProtocolGuid,
EFI_OPEN_PROTOCOL_BY_DRIVER); (VOID **)&Device,
This->DriverBindingHandle,
DeviceHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -98,17 +102,23 @@ NonDiscoverablePciDeviceSupported (
// that they only describe things that we can handle // that they only describe things that we can handle
// //
for (Desc = Device->Resources; Desc->Desc != ACPI_END_TAG_DESCRIPTOR; for (Desc = Device->Resources; Desc->Desc != ACPI_END_TAG_DESCRIPTOR;
Desc = (VOID *)((UINT8 *)Desc + Desc->Len + 3)) { Desc = (VOID *)((UINT8 *)Desc + Desc->Len + 3))
if (Desc->Desc != ACPI_ADDRESS_SPACE_DESCRIPTOR || {
Desc->ResType != ACPI_ADDRESS_SPACE_TYPE_MEM) { if ((Desc->Desc != ACPI_ADDRESS_SPACE_DESCRIPTOR) ||
(Desc->ResType != ACPI_ADDRESS_SPACE_TYPE_MEM))
{
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
break; break;
} }
} }
CloseProtocol: CloseProtocol:
gBS->CloseProtocol (DeviceHandle, &gEdkiiNonDiscoverableDeviceProtocolGuid, gBS->CloseProtocol (
This->DriverBindingHandle, DeviceHandle); DeviceHandle,
&gEdkiiNonDiscoverableDeviceProtocolGuid,
This->DriverBindingHandle,
DeviceHandle
);
return Status; return Status;
} }
@ -148,10 +158,14 @@ NonDiscoverablePciDeviceStart (
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Status = gBS->OpenProtocol (DeviceHandle, Status = gBS->OpenProtocol (
DeviceHandle,
&gEdkiiNonDiscoverableDeviceProtocolGuid, &gEdkiiNonDiscoverableDeviceProtocolGuid,
(VOID **)&Dev->Device, This->DriverBindingHandle, (VOID **)&Dev->Device,
DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER); This->DriverBindingHandle,
DeviceHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeDev; goto FreeDev;
} }
@ -163,8 +177,12 @@ NonDiscoverablePciDeviceStart (
// EFI_PCI_IO_PROTOCOL interface. // EFI_PCI_IO_PROTOCOL interface.
// //
Dev->Signature = NON_DISCOVERABLE_PCI_DEVICE_SIG; Dev->Signature = NON_DISCOVERABLE_PCI_DEVICE_SIG;
Status = gBS->InstallProtocolInterface (&DeviceHandle, &gEfiPciIoProtocolGuid, Status = gBS->InstallProtocolInterface (
EFI_NATIVE_INTERFACE, &Dev->PciIo); &DeviceHandle,
&gEfiPciIoProtocolGuid,
EFI_NATIVE_INTERFACE,
&Dev->PciIo
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto CloseProtocol; goto CloseProtocol;
} }
@ -174,8 +192,12 @@ NonDiscoverablePciDeviceStart (
return EFI_SUCCESS; return EFI_SUCCESS;
CloseProtocol: CloseProtocol:
gBS->CloseProtocol (DeviceHandle, &gEdkiiNonDiscoverableDeviceProtocolGuid, gBS->CloseProtocol (
This->DriverBindingHandle, DeviceHandle); DeviceHandle,
&gEdkiiNonDiscoverableDeviceProtocolGuid,
This->DriverBindingHandle,
DeviceHandle
);
FreeDev: FreeDev:
FreePool (Dev); FreePool (Dev);
@ -209,9 +231,14 @@ NonDiscoverablePciDeviceStop (
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
NON_DISCOVERABLE_PCI_DEVICE *Dev; NON_DISCOVERABLE_PCI_DEVICE *Dev;
Status = gBS->OpenProtocol (DeviceHandle, &gEfiPciIoProtocolGuid, Status = gBS->OpenProtocol (
(VOID **)&PciIo, This->DriverBindingHandle, DeviceHandle, DeviceHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL); &gEfiPciIoProtocolGuid,
(VOID **)&PciIo,
This->DriverBindingHandle,
DeviceHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -221,21 +248,27 @@ NonDiscoverablePciDeviceStop (
// //
// Handle Stop() requests for in-use driver instances gracefully. // Handle Stop() requests for in-use driver instances gracefully.
// //
Status = gBS->UninstallProtocolInterface (DeviceHandle, Status = gBS->UninstallProtocolInterface (
&gEfiPciIoProtocolGuid, &Dev->PciIo); DeviceHandle,
&gEfiPciIoProtocolGuid,
&Dev->PciIo
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
gBS->CloseProtocol (DeviceHandle, &gEdkiiNonDiscoverableDeviceProtocolGuid, gBS->CloseProtocol (
This->DriverBindingHandle, DeviceHandle); DeviceHandle,
&gEdkiiNonDiscoverableDeviceProtocolGuid,
This->DriverBindingHandle,
DeviceHandle
);
FreePool (Dev); FreePool (Dev);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
// //
// The static object that groups the Supported() (ie. probe), Start() and // The static object that groups the Supported() (ie. probe), Start() and
// Stop() functions of the driver together. Refer to UEFI Spec 2.3.1 + Errata // Stop() functions of the driver together. Refer to UEFI Spec 2.3.1 + Errata

View File

@ -52,8 +52,8 @@ GetBarResource (
for (Desc = Dev->Device->Resources; for (Desc = Dev->Device->Resources;
Desc->Desc != ACPI_END_TAG_DESCRIPTOR; Desc->Desc != ACPI_END_TAG_DESCRIPTOR;
Desc = (VOID *)((UINT8 *)Desc + Desc->Len + 3)) { Desc = (VOID *)((UINT8 *)Desc + Desc->Len + 3))
{
if (BarIndex == 0) { if (BarIndex == 0) {
*Descriptor = Desc; *Descriptor = Desc;
return EFI_SUCCESS; return EFI_SUCCESS;
@ -61,6 +61,7 @@ GetBarResource (
BarIndex -= 1; BarIndex -= 1;
} }
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -225,6 +226,7 @@ PciIoMemRW (
for ( ; Count > 0; Count--, Dst8 += DstStride, Src8 += SrcStride) { for ( ; Count > 0; Count--, Dst8 += DstStride, Src8 += SrcStride) {
*Dst8 = *Src8; *Dst8 = *Src8;
} }
break; break;
case EfiPciWidthUint16: case EfiPciWidthUint16:
Dst16 = (UINT16 *)Dst; Dst16 = (UINT16 *)Dst;
@ -232,6 +234,7 @@ PciIoMemRW (
for ( ; Count > 0; Count--, Dst16 += DstStride, Src16 += SrcStride) { for ( ; Count > 0; Count--, Dst16 += DstStride, Src16 += SrcStride) {
*Dst16 = *Src16; *Dst16 = *Src16;
} }
break; break;
case EfiPciWidthUint32: case EfiPciWidthUint32:
Dst32 = (UINT32 *)Dst; Dst32 = (UINT32 *)Dst;
@ -239,6 +242,7 @@ PciIoMemRW (
for ( ; Count > 0; Count--, Dst32 += DstStride, Src32 += SrcStride) { for ( ; Count > 0; Count--, Dst32 += DstStride, Src32 += SrcStride) {
*Dst32 = *Src32; *Dst32 = *Src32;
} }
break; break;
default: default:
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -331,6 +335,7 @@ PciIoMemRead (
default: default:
break; break;
} }
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -418,6 +423,7 @@ PciIoMemWrite (
default: default:
break; break;
} }
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -551,7 +557,7 @@ PciIoPciRead (
VOID *Address; VOID *Address;
UINTN Length; UINTN Length;
if (Width < 0 || Width >= EfiPciIoWidthMaximum || Buffer == NULL) { if ((Width < 0) || (Width >= EfiPciIoWidthMaximum) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -574,6 +580,7 @@ PciIoPciRead (
Count -= Length >> ((UINTN)Width & 0x3); Count -= Length >> ((UINTN)Width & 0x3);
} }
return PciIoMemRW (Width, Count, 1, Buffer, 1, Address); return PciIoMemRW (Width, Count, 1, Buffer, 1, Address);
} }
@ -607,7 +614,7 @@ PciIoPciWrite (
NON_DISCOVERABLE_PCI_DEVICE *Dev; NON_DISCOVERABLE_PCI_DEVICE *Dev;
VOID *Address; VOID *Address;
if (Width < 0 || Width >= EfiPciIoWidthMaximum || Buffer == NULL) { if ((Width < 0) || (Width >= EfiPciIoWidthMaximum) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -720,16 +727,18 @@ CoherentPciIoMap (
EFI_STATUS Status; EFI_STATUS Status;
NON_DISCOVERABLE_PCI_DEVICE_MAP_INFO *MapInfo; NON_DISCOVERABLE_PCI_DEVICE_MAP_INFO *MapInfo;
if (Operation != EfiPciIoOperationBusMasterRead && if ((Operation != EfiPciIoOperationBusMasterRead) &&
Operation != EfiPciIoOperationBusMasterWrite && (Operation != EfiPciIoOperationBusMasterWrite) &&
Operation != EfiPciIoOperationBusMasterCommonBuffer) { (Operation != EfiPciIoOperationBusMasterCommonBuffer))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (HostAddress == NULL || if ((HostAddress == NULL) ||
NumberOfBytes == NULL || (NumberOfBytes == NULL) ||
DeviceAddress == NULL || (DeviceAddress == NULL) ||
Mapping == NULL) { (Mapping == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -738,9 +747,9 @@ CoherentPciIoMap (
// addressing, we need to allocate a bounce buffer and copy over the data. // addressing, we need to allocate a bounce buffer and copy over the data.
// //
Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO (This); Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO (This);
if ((Dev->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) == 0 && if (((Dev->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) == 0) &&
(EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress + *NumberOfBytes > SIZE_4GB) { ((EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress + *NumberOfBytes > SIZE_4GB))
{
// //
// Bounce buffering is not possible for consistent mappings // Bounce buffering is not possible for consistent mappings
// //
@ -758,9 +767,12 @@ CoherentPciIoMap (
MapInfo->Operation = Operation; MapInfo->Operation = Operation;
MapInfo->NumberOfBytes = *NumberOfBytes; MapInfo->NumberOfBytes = *NumberOfBytes;
Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiBootServicesData,
EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes), EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes),
&MapInfo->AllocAddress); &MapInfo->AllocAddress
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
// //
// If we fail here, it is likely because the system has no memory below // If we fail here, it is likely because the system has no memory below
@ -770,16 +782,22 @@ CoherentPciIoMap (
FreePool (MapInfo); FreePool (MapInfo);
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
if (Operation == EfiPciIoOperationBusMasterRead) { if (Operation == EfiPciIoOperationBusMasterRead) {
gBS->CopyMem ((VOID *)(UINTN)MapInfo->AllocAddress, HostAddress, gBS->CopyMem (
*NumberOfBytes); (VOID *)(UINTN)MapInfo->AllocAddress,
HostAddress,
*NumberOfBytes
);
} }
*DeviceAddress = MapInfo->AllocAddress; *DeviceAddress = MapInfo->AllocAddress;
*Mapping = MapInfo; *Mapping = MapInfo;
} else { } else {
*DeviceAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress; *DeviceAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress;
*Mapping = NULL; *Mapping = NULL;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -805,13 +823,20 @@ CoherentPciIoUnmap (
MapInfo = Mapping; MapInfo = Mapping;
if (MapInfo != NULL) { if (MapInfo != NULL) {
if (MapInfo->Operation == EfiPciIoOperationBusMasterWrite) { if (MapInfo->Operation == EfiPciIoOperationBusMasterWrite) {
gBS->CopyMem (MapInfo->HostAddress, (VOID *)(UINTN)MapInfo->AllocAddress, gBS->CopyMem (
MapInfo->NumberOfBytes); MapInfo->HostAddress,
(VOID *)(UINTN)MapInfo->AllocAddress,
MapInfo->NumberOfBytes
);
} }
gBS->FreePages (MapInfo->AllocAddress,
EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes)); gBS->FreePages (
MapInfo->AllocAddress,
EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes)
);
FreePool (MapInfo); FreePool (MapInfo);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -852,7 +877,8 @@ CoherentPciIoAllocateBuffer (
EFI_STATUS Status; EFI_STATUS Status;
if ((Attributes & ~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE | if ((Attributes & ~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE |
EFI_PCI_ATTRIBUTE_MEMORY_CACHED)) != 0) { EFI_PCI_ATTRIBUTE_MEMORY_CACHED)) != 0)
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -861,7 +887,8 @@ CoherentPciIoAllocateBuffer (
} }
if ((MemoryType != EfiBootServicesData) && if ((MemoryType != EfiBootServicesData) &&
(MemoryType != EfiRuntimeServicesData)) { (MemoryType != EfiRuntimeServicesData))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -882,6 +909,7 @@ CoherentPciIoAllocateBuffer (
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
*HostAddress = (VOID *)(UINTN)AllocAddress; *HostAddress = (VOID *)(UINTN)AllocAddress;
} }
return Status; return Status;
} }
@ -945,10 +973,10 @@ NonCoherentPciIoFreeBuffer (
// //
for (Entry = Dev->UncachedAllocationList.ForwardLink; for (Entry = Dev->UncachedAllocationList.ForwardLink;
Entry != &Dev->UncachedAllocationList; Entry != &Dev->UncachedAllocationList;
Entry = Entry->ForwardLink) { Entry = Entry->ForwardLink)
{
Alloc = BASE_CR (Entry, NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION, List); Alloc = BASE_CR (Entry, NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION, List);
if (Alloc->HostAddress == HostAddress && Alloc->NumPages == Pages) { if ((Alloc->HostAddress == HostAddress) && (Alloc->NumPages == Pages)) {
// //
// We are freeing the exact allocation we were given // We are freeing the exact allocation we were given
// before by AllocateBuffer() // before by AllocateBuffer()
@ -968,7 +996,8 @@ NonCoherentPciIoFreeBuffer (
Status = gDS->SetMemorySpaceAttributes ( Status = gDS->SetMemorySpaceAttributes (
(EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress, (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress,
EFI_PAGES_TO_SIZE (Pages), EFI_PAGES_TO_SIZE (Pages),
Alloc->Attributes); Alloc->Attributes
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeAlloc; goto FreeAlloc;
} }
@ -1028,15 +1057,22 @@ NonCoherentPciIoAllocateBuffer (
Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO (This); Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO (This);
Status = CoherentPciIoAllocateBuffer (This, Type, MemoryType, Pages, Status = CoherentPciIoAllocateBuffer (
&AllocAddress, Attributes); This,
Type,
MemoryType,
Pages,
&AllocAddress,
Attributes
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
Status = gDS->GetMemorySpaceDescriptor ( Status = gDS->GetMemorySpaceDescriptor (
(EFI_PHYSICAL_ADDRESS)(UINTN)AllocAddress, (EFI_PHYSICAL_ADDRESS)(UINTN)AllocAddress,
&GcdDescriptor); &GcdDescriptor
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeBuffer; goto FreeBuffer;
} }
@ -1049,8 +1085,9 @@ NonCoherentPciIoAllocateBuffer (
// //
// Set the preferred memory attributes // Set the preferred memory attributes
// //
if ((Attributes & EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE) != 0 || if (((Attributes & EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE) != 0) ||
(GcdDescriptor.Capabilities & EFI_MEMORY_UC) == 0) { ((GcdDescriptor.Capabilities & EFI_MEMORY_UC) == 0))
{
// //
// Use write combining if it was requested, or if it is the only // Use write combining if it was requested, or if it is the only
// type supported by the region. // type supported by the region.
@ -1078,7 +1115,8 @@ NonCoherentPciIoAllocateBuffer (
Status = gDS->SetMemorySpaceAttributes ( Status = gDS->SetMemorySpaceAttributes (
(EFI_PHYSICAL_ADDRESS)(UINTN)AllocAddress, (EFI_PHYSICAL_ADDRESS)(UINTN)AllocAddress,
EFI_PAGES_TO_SIZE (Pages), EFI_PAGES_TO_SIZE (Pages),
MemType); MemType
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto RemoveList; goto RemoveList;
} }
@ -1087,7 +1125,8 @@ NonCoherentPciIoAllocateBuffer (
mCpu, mCpu,
(EFI_PHYSICAL_ADDRESS)(UINTN)AllocAddress, (EFI_PHYSICAL_ADDRESS)(UINTN)AllocAddress,
EFI_PAGES_TO_SIZE (Pages), EFI_PAGES_TO_SIZE (Pages),
EfiCpuFlushTypeInvalidate); EfiCpuFlushTypeInvalidate
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto RemoveList; goto RemoveList;
} }
@ -1144,16 +1183,18 @@ NonCoherentPciIoMap (
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
BOOLEAN Bounce; BOOLEAN Bounce;
if (HostAddress == NULL || if ((HostAddress == NULL) ||
NumberOfBytes == NULL || (NumberOfBytes == NULL) ||
DeviceAddress == NULL || (DeviceAddress == NULL) ||
Mapping == NULL) { (Mapping == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (Operation != EfiPciIoOperationBusMasterRead && if ((Operation != EfiPciIoOperationBusMasterRead) &&
Operation != EfiPciIoOperationBusMasterWrite && (Operation != EfiPciIoOperationBusMasterWrite) &&
Operation != EfiPciIoOperationBusMasterCommonBuffer) { (Operation != EfiPciIoOperationBusMasterCommonBuffer))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1187,6 +1228,7 @@ NonCoherentPciIoMap (
if ((((UINTN)HostAddress | *NumberOfBytes) & AlignMask) == 0) { if ((((UINTN)HostAddress | *NumberOfBytes) & AlignMask) == 0) {
break; break;
} }
// fall through // fall through
case EfiPciIoOperationBusMasterCommonBuffer: case EfiPciIoOperationBusMasterCommonBuffer:
@ -1195,11 +1237,14 @@ NonCoherentPciIoMap (
// //
Status = gDS->GetMemorySpaceDescriptor ( Status = gDS->GetMemorySpaceDescriptor (
(EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress, (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress,
&GcdDescriptor); &GcdDescriptor
);
if (EFI_ERROR (Status) || if (EFI_ERROR (Status) ||
(GcdDescriptor.Attributes & (EFI_MEMORY_WB|EFI_MEMORY_WT)) != 0) { ((GcdDescriptor.Attributes & (EFI_MEMORY_WB|EFI_MEMORY_WT)) != 0))
{
Bounce = TRUE; Bounce = TRUE;
} }
break; break;
default: default:
@ -1213,16 +1258,23 @@ NonCoherentPciIoMap (
goto FreeMapInfo; goto FreeMapInfo;
} }
Status = NonCoherentPciIoAllocateBuffer (This, AllocateAnyPages, Status = NonCoherentPciIoAllocateBuffer (
EfiBootServicesData, EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes), This,
&AllocAddress, EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE); AllocateAnyPages,
EfiBootServicesData,
EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes),
&AllocAddress,
EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeMapInfo; goto FreeMapInfo;
} }
MapInfo->AllocAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocAddress; MapInfo->AllocAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocAddress;
if (Operation == EfiPciIoOperationBusMasterRead) { if (Operation == EfiPciIoOperationBusMasterRead) {
gBS->CopyMem (AllocAddress, HostAddress, *NumberOfBytes); gBS->CopyMem (AllocAddress, HostAddress, *NumberOfBytes);
} }
*DeviceAddress = MapInfo->AllocAddress; *DeviceAddress = MapInfo->AllocAddress;
} else { } else {
MapInfo->AllocAddress = 0; MapInfo->AllocAddress = 0;
@ -1238,8 +1290,12 @@ NonCoherentPciIoMap (
// may be written back unexpectedly, and clobber the data written to // may be written back unexpectedly, and clobber the data written to
// main memory by the device. // main memory by the device.
// //
mCpu->FlushDataCache (mCpu, (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress, mCpu->FlushDataCache (
*NumberOfBytes, EfiCpuFlushTypeWriteBack); mCpu,
(EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress,
*NumberOfBytes,
EfiCpuFlushTypeWriteBack
);
} }
*Mapping = MapInfo; *Mapping = MapInfo;
@ -1281,12 +1337,18 @@ NonCoherentPciIoUnmap (
// and free the buffer. // and free the buffer.
// //
if (MapInfo->Operation == EfiPciIoOperationBusMasterWrite) { if (MapInfo->Operation == EfiPciIoOperationBusMasterWrite) {
gBS->CopyMem (MapInfo->HostAddress, (VOID *)(UINTN)MapInfo->AllocAddress, gBS->CopyMem (
MapInfo->NumberOfBytes); MapInfo->HostAddress,
(VOID *)(UINTN)MapInfo->AllocAddress,
MapInfo->NumberOfBytes
);
} }
NonCoherentPciIoFreeBuffer (This,
NonCoherentPciIoFreeBuffer (
This,
EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes), EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes),
(VOID *)(UINTN)MapInfo->AllocAddress); (VOID *)(UINTN)MapInfo->AllocAddress
);
} else { } else {
// //
// We are *not* using a bounce buffer: if this is a bus master write, // We are *not* using a bounce buffer: if this is a bus master write,
@ -1294,11 +1356,15 @@ NonCoherentPciIoUnmap (
// data written by the device. // data written by the device.
// //
if (MapInfo->Operation == EfiPciIoOperationBusMasterWrite) { if (MapInfo->Operation == EfiPciIoOperationBusMasterWrite) {
mCpu->FlushDataCache (mCpu, mCpu->FlushDataCache (
mCpu,
(EFI_PHYSICAL_ADDRESS)(UINTN)MapInfo->HostAddress, (EFI_PHYSICAL_ADDRESS)(UINTN)MapInfo->HostAddress,
MapInfo->NumberOfBytes, EfiCpuFlushTypeInvalidate); MapInfo->NumberOfBytes,
EfiCpuFlushTypeInvalidate
);
} }
} }
FreePool (MapInfo); FreePool (MapInfo);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1345,10 +1411,11 @@ PciIoGetLocation (
{ {
NON_DISCOVERABLE_PCI_DEVICE *Dev; NON_DISCOVERABLE_PCI_DEVICE *Dev;
if (SegmentNumber == NULL || if ((SegmentNumber == NULL) ||
BusNumber == NULL || (BusNumber == NULL) ||
DeviceNumber == NULL || (DeviceNumber == NULL) ||
FunctionNumber == NULL) { (FunctionNumber == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1406,6 +1473,7 @@ PciIoAttributes (
if (Result == NULL) { if (Result == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
*Result = Dev->Attributes; *Result = Dev->Attributes;
break; break;
@ -1413,6 +1481,7 @@ PciIoAttributes (
if (Result == NULL) { if (Result == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
*Result = DEV_SUPPORTED_ATTRIBUTES; *Result = DEV_SUPPORTED_ATTRIBUTES;
break; break;
@ -1429,16 +1498,17 @@ PciIoAttributes (
default: default:
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
}; }
// //
// If we're setting any of the EFI_PCI_DEVICE_ENABLE bits, perform // If we're setting any of the EFI_PCI_DEVICE_ENABLE bits, perform
// the device specific initialization now. // the device specific initialization now.
// //
if (Enable && !Dev->Enabled && Dev->Device->Initialize != NULL) { if (Enable && !Dev->Enabled && (Dev->Device->Initialize != NULL)) {
Dev->Device->Initialize (Dev->Device); Dev->Device->Initialize (Dev->Device);
Dev->Enabled = TRUE; Dev->Enabled = TRUE;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1480,7 +1550,7 @@ PciIoGetBarAttributes (
EFI_ACPI_END_TAG_DESCRIPTOR *End; EFI_ACPI_END_TAG_DESCRIPTOR *End;
EFI_STATUS Status; EFI_STATUS Status;
if (Supports == NULL && Resources == NULL) { if ((Supports == NULL) && (Resources == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1499,8 +1569,10 @@ PciIoGetBarAttributes (
} }
if (Resources != NULL) { if (Resources != NULL) {
Descriptor = AllocatePool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + Descriptor = AllocatePool (
sizeof (EFI_ACPI_END_TAG_DESCRIPTOR)); sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) +
sizeof (EFI_ACPI_END_TAG_DESCRIPTOR)
);
if (Descriptor == NULL) { if (Descriptor == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -1513,6 +1585,7 @@ PciIoGetBarAttributes (
*Resources = Descriptor; *Resources = Descriptor;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1550,7 +1623,7 @@ PciIoSetBarAttributes (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
if (Offset == NULL || Length == NULL) { if ((Offset == NULL) || (Length == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1626,44 +1699,65 @@ InitializePciIoProtocol (
Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_MASS_STORAGE_SATADPA; Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_MASS_STORAGE_SATADPA;
Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_MASS_STORAGE; Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_MASS_STORAGE;
Dev->BarOffset = 5; Dev->BarOffset = 5;
} else if (CompareGuid (Dev->Device->Type, } else if (CompareGuid (
&gEdkiiNonDiscoverableEhciDeviceGuid)) { Dev->Device->Type,
&gEdkiiNonDiscoverableEhciDeviceGuid
))
{
Dev->ConfigSpace.Hdr.ClassCode[0] = PCI_IF_EHCI; Dev->ConfigSpace.Hdr.ClassCode[0] = PCI_IF_EHCI;
Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_SERIAL_USB; Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_SERIAL_USB;
Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SERIAL; Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SERIAL;
Dev->BarOffset = 0; Dev->BarOffset = 0;
} else if (CompareGuid (Dev->Device->Type, } else if (CompareGuid (
&gEdkiiNonDiscoverableNvmeDeviceGuid)) { Dev->Device->Type,
&gEdkiiNonDiscoverableNvmeDeviceGuid
))
{
Dev->ConfigSpace.Hdr.ClassCode[0] = 0x2; // PCI_IF_NVMHCI Dev->ConfigSpace.Hdr.ClassCode[0] = 0x2; // PCI_IF_NVMHCI
Dev->ConfigSpace.Hdr.ClassCode[1] = 0x8; // PCI_CLASS_MASS_STORAGE_NVM Dev->ConfigSpace.Hdr.ClassCode[1] = 0x8; // PCI_CLASS_MASS_STORAGE_NVM
Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_MASS_STORAGE; Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_MASS_STORAGE;
Dev->BarOffset = 0; Dev->BarOffset = 0;
} else if (CompareGuid (Dev->Device->Type, } else if (CompareGuid (
&gEdkiiNonDiscoverableOhciDeviceGuid)) { Dev->Device->Type,
&gEdkiiNonDiscoverableOhciDeviceGuid
))
{
Dev->ConfigSpace.Hdr.ClassCode[0] = PCI_IF_OHCI; Dev->ConfigSpace.Hdr.ClassCode[0] = PCI_IF_OHCI;
Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_SERIAL_USB; Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_SERIAL_USB;
Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SERIAL; Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SERIAL;
Dev->BarOffset = 0; Dev->BarOffset = 0;
} else if (CompareGuid (Dev->Device->Type, } else if (CompareGuid (
&gEdkiiNonDiscoverableSdhciDeviceGuid)) { Dev->Device->Type,
&gEdkiiNonDiscoverableSdhciDeviceGuid
))
{
Dev->ConfigSpace.Hdr.ClassCode[0] = 0x0; // don't care Dev->ConfigSpace.Hdr.ClassCode[0] = 0x0; // don't care
Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_SUBCLASS_SD_HOST_CONTROLLER; Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_SUBCLASS_SD_HOST_CONTROLLER;
Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SYSTEM_PERIPHERAL; Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SYSTEM_PERIPHERAL;
Dev->BarOffset = 0; Dev->BarOffset = 0;
} else if (CompareGuid (Dev->Device->Type, } else if (CompareGuid (
&gEdkiiNonDiscoverableXhciDeviceGuid)) { Dev->Device->Type,
&gEdkiiNonDiscoverableXhciDeviceGuid
))
{
Dev->ConfigSpace.Hdr.ClassCode[0] = PCI_IF_XHCI; Dev->ConfigSpace.Hdr.ClassCode[0] = PCI_IF_XHCI;
Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_SERIAL_USB; Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_SERIAL_USB;
Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SERIAL; Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SERIAL;
Dev->BarOffset = 0; Dev->BarOffset = 0;
} else if (CompareGuid (Dev->Device->Type, } else if (CompareGuid (
&gEdkiiNonDiscoverableUhciDeviceGuid)) { Dev->Device->Type,
&gEdkiiNonDiscoverableUhciDeviceGuid
))
{
Dev->ConfigSpace.Hdr.ClassCode[0] = PCI_IF_UHCI; Dev->ConfigSpace.Hdr.ClassCode[0] = PCI_IF_UHCI;
Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_SERIAL_USB; Dev->ConfigSpace.Hdr.ClassCode[1] = PCI_CLASS_SERIAL_USB;
Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SERIAL; Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_SERIAL;
Dev->BarOffset = 0; Dev->BarOffset = 0;
} else if (CompareGuid (Dev->Device->Type, } else if (CompareGuid (
&gEdkiiNonDiscoverableUfsDeviceGuid)) { Dev->Device->Type,
&gEdkiiNonDiscoverableUfsDeviceGuid
))
{
Dev->ConfigSpace.Hdr.ClassCode[0] = 0x0; // don't care Dev->ConfigSpace.Hdr.ClassCode[0] = 0x0; // don't care
Dev->ConfigSpace.Hdr.ClassCode[1] = 0x9; // UFS controller subclass; Dev->ConfigSpace.Hdr.ClassCode[1] = 0x9; // UFS controller subclass;
Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_MASS_STORAGE; Dev->ConfigSpace.Hdr.ClassCode[2] = PCI_CLASS_MASS_STORAGE;
@ -1678,16 +1772,19 @@ InitializePciIoProtocol (
Idx = Dev->BarOffset; Idx = Dev->BarOffset;
for (Desc = Dev->Device->Resources, Dev->BarCount = 0; for (Desc = Dev->Device->Resources, Dev->BarCount = 0;
Desc->Desc != ACPI_END_TAG_DESCRIPTOR; Desc->Desc != ACPI_END_TAG_DESCRIPTOR;
Desc = (VOID *)((UINT8 *)Desc + Desc->Len + 3)) { Desc = (VOID *)((UINT8 *)Desc + Desc->Len + 3))
{
ASSERT (Desc->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR); ASSERT (Desc->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR);
ASSERT (Desc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM); ASSERT (Desc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM);
if (Idx >= PCI_MAX_BAR || if ((Idx >= PCI_MAX_BAR) ||
(Idx == PCI_MAX_BAR - 1 && Desc->AddrSpaceGranularity == 64)) { ((Idx == PCI_MAX_BAR - 1) && (Desc->AddrSpaceGranularity == 64)))
DEBUG ((DEBUG_ERROR, {
DEBUG ((
DEBUG_ERROR,
"%a: resource count exceeds number of emulated BARs\n", "%a: resource count exceeds number of emulated BARs\n",
__FUNCTION__)); __FUNCTION__
));
ASSERT (FALSE); ASSERT (FALSE);
break; break;
} }
@ -1698,7 +1795,9 @@ InitializePciIoProtocol (
if (Desc->AddrSpaceGranularity == 64) { if (Desc->AddrSpaceGranularity == 64) {
Dev->ConfigSpace.Device.Bar[Idx] |= 0x4; Dev->ConfigSpace.Device.Bar[Idx] |= 0x4;
Dev->ConfigSpace.Device.Bar[++Idx] = (UINT32)RShiftU64 ( Dev->ConfigSpace.Device.Bar[++Idx] = (UINT32)RShiftU64 (
Desc->AddrRangeMin, 32); Desc->AddrRangeMin,
32
);
} }
} }
} }

View File

@ -198,6 +198,7 @@ NvmExpressComponentNameGetControllerName (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Get the child context // Get the child context
// //
@ -212,6 +213,7 @@ NvmExpressComponentNameGetControllerName (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
Device = NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO (BlockIo); Device = NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO (BlockIo);
ControllerNameTable = Device->ControllerNameTable; ControllerNameTable = Device->ControllerNameTable;
} }
@ -223,5 +225,4 @@ NvmExpressComponentNameGetControllerName (
ControllerName, ControllerName,
(BOOLEAN)(This == &gNvmExpressComponentName) (BOOLEAN)(This == &gNvmExpressComponentName)
); );
} }

View File

@ -99,6 +99,7 @@ EnumerateNvmeDevNamespace (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Exit; goto Exit;
} }
// //
// Validate Namespace // Validate Namespace
// //
@ -315,9 +316,11 @@ Exit:
if (EFI_ERROR (Status) && (Device != NULL) && (Device->DevicePath != NULL)) { if (EFI_ERROR (Status) && (Device != NULL) && (Device->DevicePath != NULL)) {
FreePool (Device->DevicePath); FreePool (Device->DevicePath);
} }
if (EFI_ERROR (Status) && (Device != NULL)) { if (EFI_ERROR (Status) && (Device != NULL)) {
FreePool (Device); FreePool (Device);
} }
return Status; return Status;
} }
@ -549,7 +552,8 @@ ProcessAsyncTaskList (
// //
for (Link = GetFirstNode (&Private->UnsubmittedSubtasks); for (Link = GetFirstNode (&Private->UnsubmittedSubtasks);
!IsNull (&Private->UnsubmittedSubtasks, Link); !IsNull (&Private->UnsubmittedSubtasks, Link);
Link = NextLink) { Link = NextLink)
{
NextLink = GetNextNode (&Private->UnsubmittedSubtasks, Link); NextLink = GetNextNode (&Private->UnsubmittedSubtasks, Link);
Subtask = NVME_BLKIO2_SUBTASK_FROM_LINK (Link); Subtask = NVME_BLKIO2_SUBTASK_FROM_LINK (Link);
BlkIo2Request = Subtask->BlockIo2Request; BlkIo2Request = Subtask->BlockIo2Request;
@ -563,7 +567,8 @@ ProcessAsyncTaskList (
if (Token->TransactionStatus != EFI_SUCCESS) { if (Token->TransactionStatus != EFI_SUCCESS) {
if (IsListEmpty (&BlkIo2Request->SubtasksQueue) && if (IsListEmpty (&BlkIo2Request->SubtasksQueue) &&
BlkIo2Request->LastSubtaskSubmitted && BlkIo2Request->LastSubtaskSubmitted &&
(BlkIo2Request->UnsubmittedSubtaskNum == 0)) { (BlkIo2Request->UnsubmittedSubtaskNum == 0))
{
// //
// Remove the BlockIo2 request from the device asynchronous queue. // Remove the BlockIo2 request from the device asynchronous queue.
// //
@ -594,7 +599,8 @@ ProcessAsyncTaskList (
Token->TransactionStatus = EFI_DEVICE_ERROR; Token->TransactionStatus = EFI_DEVICE_ERROR;
if (IsListEmpty (&BlkIo2Request->SubtasksQueue) && if (IsListEmpty (&BlkIo2Request->SubtasksQueue) &&
Subtask->IsLast) { Subtask->IsLast)
{
// //
// Remove the BlockIo2 request from the device asynchronous queue. // Remove the BlockIo2 request from the device asynchronous queue.
// //
@ -625,7 +631,8 @@ ProcessAsyncTaskList (
// //
for (Link = GetFirstNode (&Private->AsyncPassThruQueue); for (Link = GetFirstNode (&Private->AsyncPassThruQueue);
!IsNull (&Private->AsyncPassThruQueue, Link); !IsNull (&Private->AsyncPassThruQueue, Link);
Link = NextLink) { Link = NextLink)
{
NextLink = GetNextNode (&Private->AsyncPassThruQueue, Link); NextLink = GetNextNode (&Private->AsyncPassThruQueue, Link);
AsyncRequest = NVME_PASS_THRU_ASYNC_REQ_FROM_THIS (Link); AsyncRequest = NVME_PASS_THRU_ASYNC_REQ_FROM_THIS (Link);
if (AsyncRequest->CommandId == Cq->Cid) { if (AsyncRequest->CommandId == Cq->Cid) {
@ -645,12 +652,15 @@ ProcessAsyncTaskList (
if (AsyncRequest->MapData != NULL) { if (AsyncRequest->MapData != NULL) {
PciIo->Unmap (PciIo, AsyncRequest->MapData); PciIo->Unmap (PciIo, AsyncRequest->MapData);
} }
if (AsyncRequest->MapMeta != NULL) { if (AsyncRequest->MapMeta != NULL) {
PciIo->Unmap (PciIo, AsyncRequest->MapMeta); PciIo->Unmap (PciIo, AsyncRequest->MapMeta);
} }
if (AsyncRequest->MapPrpList != NULL) { if (AsyncRequest->MapPrpList != NULL) {
PciIo->Unmap (PciIo, AsyncRequest->MapPrpList); PciIo->Unmap (PciIo, AsyncRequest->MapPrpList);
} }
if (AsyncRequest->PrpListHost != NULL) { if (AsyncRequest->PrpListHost != NULL) {
PciIo->FreeBuffer ( PciIo->FreeBuffer (
PciIo, PciIo,
@ -766,7 +776,8 @@ NvmExpressDriverBindingSupported (
if ((DevicePathNode.DevPath->Type != MESSAGING_DEVICE_PATH) || if ((DevicePathNode.DevPath->Type != MESSAGING_DEVICE_PATH) ||
(DevicePathNode.DevPath->SubType != MSG_NVME_NAMESPACE_DP) || (DevicePathNode.DevPath->SubType != MSG_NVME_NAMESPACE_DP) ||
(DevicePathNodeLength(DevicePathNode.DevPath) != sizeof(NVME_NAMESPACE_DEVICE_PATH))) { (DevicePathNodeLength (DevicePathNode.DevPath) != sizeof (NVME_NAMESPACE_DEVICE_PATH)))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
} }
@ -853,7 +864,6 @@ Done:
return Status; return Status;
} }
/** /**
Starts a device controller or a bus controller. Starts a device controller or a bus controller.
@ -1065,7 +1075,6 @@ NvmExpressDriverBindingStart (
Status = DiscoverAllNamespaces ( Status = DiscoverAllNamespaces (
Private Private
); );
} else if (!IsDevicePathEnd (RemainingDevicePath)) { } else if (!IsDevicePathEnd (RemainingDevicePath)) {
// //
// Enumerate the specified NVME namespace // Enumerate the specified NVME namespace
@ -1127,7 +1136,6 @@ Exit:
return Status; return Status;
} }
/** /**
Stops a device controller or a bus controller. Stops a device controller or a bus controller.
@ -1374,6 +1382,7 @@ EXIT:
if (DeviceHandleBuffer != NULL) { if (DeviceHandleBuffer != NULL) {
gBS->FreePool (DeviceHandleBuffer); gBS->FreePool (DeviceHandleBuffer);
} }
return Status; return Status;
} }

View File

@ -208,7 +208,6 @@ struct _NVME_DEVICE_PRIVATE_DATA {
NVME_ADMIN_NAMESPACE_DATA NamespaceData; NVME_ADMIN_NAMESPACE_DATA NamespaceData;
NVME_CONTROLLER_PRIVATE_DATA *Controller; NVME_CONTROLLER_PRIVATE_DATA *Controller;
}; };
// //

View File

@ -212,9 +212,17 @@ NvmeRead (
} }
} }
DEBUG ((DEBUG_BLKIO, "%a: Lba = 0x%08Lx, Original = 0x%08Lx, " DEBUG ((
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n", __FUNCTION__, Lba, DEBUG_BLKIO,
(UINT64)OrginalBlocks, (UINT64)Blocks, BlockSize, Status)); "%a: Lba = 0x%08Lx, Original = 0x%08Lx, "
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n",
__FUNCTION__,
Lba,
(UINT64)OrginalBlocks,
(UINT64)Blocks,
BlockSize,
Status
));
return Status; return Status;
} }
@ -290,9 +298,17 @@ NvmeWrite (
} }
} }
DEBUG ((DEBUG_BLKIO, "%a: Lba = 0x%08Lx, Original = 0x%08Lx, " DEBUG ((
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n", __FUNCTION__, Lba, DEBUG_BLKIO,
(UINT64)OrginalBlocks, (UINT64)Blocks, BlockSize, Status)); "%a: Lba = 0x%08Lx, Original = 0x%08Lx, "
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n",
__FUNCTION__,
Lba,
(UINT64)OrginalBlocks,
(UINT64)Blocks,
BlockSize,
Status
));
return Status; return Status;
} }
@ -745,7 +761,8 @@ NvmeAsyncRead (
if (Blocks > MaxTransferBlocks) { if (Blocks > MaxTransferBlocks) {
Status = AsyncReadSectors ( Status = AsyncReadSectors (
Device, Device,
BlkIo2Req, (UINT64)(UINTN)Buffer, BlkIo2Req,
(UINT64)(UINTN)Buffer,
Lba, Lba,
MaxTransferBlocks, MaxTransferBlocks,
FALSE FALSE
@ -796,9 +813,17 @@ NvmeAsyncRead (
} }
} }
DEBUG ((DEBUG_BLKIO, "%a: Lba = 0x%08Lx, Original = 0x%08Lx, " DEBUG ((
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n", __FUNCTION__, Lba, DEBUG_BLKIO,
(UINT64)OrginalBlocks, (UINT64)Blocks, BlockSize, Status)); "%a: Lba = 0x%08Lx, Original = 0x%08Lx, "
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n",
__FUNCTION__,
Lba,
(UINT64)OrginalBlocks,
(UINT64)Blocks,
BlockSize,
Status
));
return Status; return Status;
} }
@ -916,9 +941,17 @@ NvmeAsyncWrite (
} }
} }
DEBUG ((DEBUG_BLKIO, "%a: Lba = 0x%08Lx, Original = 0x%08Lx, " DEBUG ((
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n", __FUNCTION__, Lba, DEBUG_BLKIO,
(UINT64)OrginalBlocks, (UINT64)Blocks, BlockSize, Status)); "%a: Lba = 0x%08Lx, Original = 0x%08Lx, "
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n",
__FUNCTION__,
Lba,
(UINT64)OrginalBlocks,
(UINT64)Blocks,
BlockSize,
Status
));
return Status; return Status;
} }
@ -1039,7 +1072,7 @@ NvmeBlockIoReadBlocks (
} }
IoAlign = Media->IoAlign; IoAlign = Media->IoAlign;
if (IoAlign > 0 && (((UINTN) Buffer & (IoAlign - 1)) != 0)) { if ((IoAlign > 0) && (((UINTN)Buffer & (IoAlign - 1)) != 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1123,7 +1156,7 @@ NvmeBlockIoWriteBlocks (
} }
IoAlign = Media->IoAlign; IoAlign = Media->IoAlign;
if (IoAlign > 0 && (((UINTN) Buffer & (IoAlign - 1)) != 0)) { if ((IoAlign > 0) && (((UINTN)Buffer & (IoAlign - 1)) != 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1316,6 +1349,7 @@ NvmeBlockIoReadBlocksEx (
Token->TransactionStatus = EFI_SUCCESS; Token->TransactionStatus = EFI_SUCCESS;
gBS->SignalEvent (Token->Event); gBS->SignalEvent (Token->Event);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1330,7 +1364,7 @@ NvmeBlockIoReadBlocksEx (
} }
IoAlign = Media->IoAlign; IoAlign = Media->IoAlign;
if (IoAlign > 0 && (((UINTN) Buffer & (IoAlign - 1)) != 0)) { if ((IoAlign > 0) && (((UINTN)Buffer & (IoAlign - 1)) != 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1428,6 +1462,7 @@ NvmeBlockIoWriteBlocksEx (
Token->TransactionStatus = EFI_SUCCESS; Token->TransactionStatus = EFI_SUCCESS;
gBS->SignalEvent (Token->Event); gBS->SignalEvent (Token->Event);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1442,7 +1477,7 @@ NvmeBlockIoWriteBlocksEx (
} }
IoAlign = Media->IoAlign; IoAlign = Media->IoAlign;
if (IoAlign > 0 && (((UINTN) Buffer & (IoAlign - 1)) != 0)) { if ((IoAlign > 0) && (((UINTN)Buffer & (IoAlign - 1)) != 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1848,7 +1883,3 @@ NvmeStorageSecuritySendData (
return Status; return Status;
} }

View File

@ -33,7 +33,6 @@ InitializeDiskInfo (
CopyMem (&Device->DiskInfo, &gNvmExpressDiskInfoProtocolTemplate, sizeof (EFI_DISK_INFO_PROTOCOL)); CopyMem (&Device->DiskInfo, &gNvmExpressDiskInfoProtocolTemplate, sizeof (EFI_DISK_INFO_PROTOCOL));
} }
/** /**
Provides inquiry information for the controller type. Provides inquiry information for the controller type.
@ -61,7 +60,6 @@ NvmExpressDiskInfoInquiry (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
Provides identify information for the controller type. Provides identify information for the controller type.
@ -98,6 +96,7 @@ NvmExpressDiskInfoIdentify (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
CopyMem (IdentifyData, &Device->NamespaceData, sizeof (Device->NamespaceData)); CopyMem (IdentifyData, &Device->NamespaceData, sizeof (Device->NamespaceData));
} }
*IdentifyDataSize = sizeof (Device->NamespaceData); *IdentifyDataSize = sizeof (Device->NamespaceData);
return Status; return Status;
} }
@ -131,7 +130,6 @@ NvmExpressDiskInfoSenseData (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
This function is used to get controller information. This function is used to get controller information.
@ -153,4 +151,3 @@ NvmExpressDiskInfoWhichIde (
{ {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }

View File

@ -23,7 +23,6 @@ InitializeDiskInfo (
IN NVME_DEVICE_PRIVATE_DATA *Device IN NVME_DEVICE_PRIVATE_DATA *Device
); );
/** /**
Provides inquiry information for the controller type. Provides inquiry information for the controller type.
@ -100,7 +99,6 @@ NvmExpressDiskInfoSenseData (
OUT UINT8 *SenseDataNumber OUT UINT8 *SenseDataNumber
); );
/** /**
This function is used to get controller information. This function is used to get controller information.

View File

@ -177,8 +177,6 @@ ReadNvmeControllerStatus (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Write Nvm Express admin queue attributes register. Write Nvm Express admin queue attributes register.
@ -220,7 +218,6 @@ WriteNvmeAdminQueueAttributes (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Write Nvm Express admin submission queue base address register. Write Nvm Express admin submission queue base address register.
@ -262,8 +259,6 @@ WriteNvmeAdminSubmissionQueueBaseAddress (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Write Nvm Express admin completion queue base address register. Write Nvm Express admin completion queue base address register.
@ -731,6 +726,7 @@ NvmeControllerInit (
NVME_ACQ Acq; NVME_ACQ Acq;
UINT8 Sn[21]; UINT8 Sn[21];
UINT8 Mn[41]; UINT8 Mn[41];
// //
// Save original PCI attributes and enable this controller. // Save original PCI attributes and enable this controller.
// //
@ -1023,7 +1019,8 @@ NvmeShutdownAllControllers (
// gImageHandle equals to DriverBinding handle for this driver. // gImageHandle equals to DriverBinding handle for this driver.
// //
if (((OpenInfos[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) && if (((OpenInfos[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) &&
(OpenInfos[OpenInfoIndex].AgentHandle == gImageHandle)) { (OpenInfos[OpenInfoIndex].AgentHandle == gImageHandle))
{
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
OpenInfos[OpenInfoIndex].ControllerHandle, OpenInfos[OpenInfoIndex].ControllerHandle,
&gEfiNvmExpressPassThruProtocolGuid, &gEfiNvmExpressPassThruProtocolGuid,
@ -1035,6 +1032,7 @@ NvmeShutdownAllControllers (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
Private = NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (NvmePassThru); Private = NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (NvmePassThru);
// //
@ -1044,6 +1042,7 @@ NvmeShutdownAllControllers (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
// //
// The host should set the Shutdown Notification (CC.SHN) field to 01b // The host should set the Shutdown Notification (CC.SHN) field to 01b
// to indicate a normal shutdown operation. // to indicate a normal shutdown operation.
@ -1065,6 +1064,7 @@ NvmeShutdownAllControllers (
DEBUG ((DEBUG_INFO, "NvmeShutdownController: shutdown processing is completed after %dms.\n", Index * 10)); DEBUG ((DEBUG_INFO, "NvmeShutdownController: shutdown processing is completed after %dms.\n", Index * 10));
break; break;
} }
// //
// Stall for 10ms // Stall for 10ms
// //

View File

@ -67,4 +67,3 @@ NvmeIdentifyNamespace (
); );
#endif #endif

View File

@ -97,6 +97,7 @@ NvmeDumpStatus (
DEBUG ((DEBUG_VERBOSE, "Reservation Conflict\n")); DEBUG ((DEBUG_VERBOSE, "Reservation Conflict\n"));
break; break;
} }
break; break;
case 0x1: case 0x1:
@ -159,6 +160,7 @@ NvmeDumpStatus (
DEBUG ((DEBUG_VERBOSE, "Attempted Write to Read Only Range\n")); DEBUG ((DEBUG_VERBOSE, "Attempted Write to Read Only Range\n"));
break; break;
} }
break; break;
case 0x2: case 0x2:
@ -185,6 +187,7 @@ NvmeDumpStatus (
DEBUG ((DEBUG_VERBOSE, "Access Denied\n")); DEBUG ((DEBUG_VERBOSE, "Access Denied\n"));
break; break;
} }
break; break;
default: default:
@ -271,6 +274,7 @@ NvmeCreatePrpList (
DEBUG ((DEBUG_ERROR, "NvmeCreatePrpList: create PrpList failure!\n")); DEBUG ((DEBUG_ERROR, "NvmeCreatePrpList: create PrpList failure!\n"));
goto EXIT; goto EXIT;
} }
// //
// Fill all PRP lists except of last one. // Fill all PRP lists except of last one.
// //
@ -293,6 +297,7 @@ NvmeCreatePrpList (
} }
} }
} }
// //
// Fill last PRP list. // Fill last PRP list.
// //
@ -309,7 +314,6 @@ EXIT:
return NULL; return NULL;
} }
/** /**
Aborts the asynchronous PassThru requests. Aborts the asynchronous PassThru requests.
@ -343,7 +347,8 @@ AbortAsyncPassThruTasks (
// //
for (Link = GetFirstNode (&Private->UnsubmittedSubtasks); for (Link = GetFirstNode (&Private->UnsubmittedSubtasks);
!IsNull (&Private->UnsubmittedSubtasks, Link); !IsNull (&Private->UnsubmittedSubtasks, Link);
Link = NextLink) { Link = NextLink)
{
NextLink = GetNextNode (&Private->UnsubmittedSubtasks, Link); NextLink = GetNextNode (&Private->UnsubmittedSubtasks, Link);
Subtask = NVME_BLKIO2_SUBTASK_FROM_LINK (Link); Subtask = NVME_BLKIO2_SUBTASK_FROM_LINK (Link);
BlkIo2Request = Subtask->BlockIo2Request; BlkIo2Request = Subtask->BlockIo2Request;
@ -353,6 +358,7 @@ AbortAsyncPassThruTasks (
if (Subtask->IsLast) { if (Subtask->IsLast) {
BlkIo2Request->LastSubtaskSubmitted = TRUE; BlkIo2Request->LastSubtaskSubmitted = TRUE;
} }
Token->TransactionStatus = EFI_ABORTED; Token->TransactionStatus = EFI_ABORTED;
RemoveEntryList (Link); RemoveEntryList (Link);
@ -365,19 +371,23 @@ AbortAsyncPassThruTasks (
// //
for (Link = GetFirstNode (&Private->AsyncPassThruQueue); for (Link = GetFirstNode (&Private->AsyncPassThruQueue);
!IsNull (&Private->AsyncPassThruQueue, Link); !IsNull (&Private->AsyncPassThruQueue, Link);
Link = NextLink) { Link = NextLink)
{
NextLink = GetNextNode (&Private->AsyncPassThruQueue, Link); NextLink = GetNextNode (&Private->AsyncPassThruQueue, Link);
AsyncRequest = NVME_PASS_THRU_ASYNC_REQ_FROM_THIS (Link); AsyncRequest = NVME_PASS_THRU_ASYNC_REQ_FROM_THIS (Link);
if (AsyncRequest->MapData != NULL) { if (AsyncRequest->MapData != NULL) {
PciIo->Unmap (PciIo, AsyncRequest->MapData); PciIo->Unmap (PciIo, AsyncRequest->MapData);
} }
if (AsyncRequest->MapMeta != NULL) { if (AsyncRequest->MapMeta != NULL) {
PciIo->Unmap (PciIo, AsyncRequest->MapMeta); PciIo->Unmap (PciIo, AsyncRequest->MapMeta);
} }
if (AsyncRequest->MapPrpList != NULL) { if (AsyncRequest->MapPrpList != NULL) {
PciIo->Unmap (PciIo, AsyncRequest->MapPrpList); PciIo->Unmap (PciIo, AsyncRequest->MapPrpList);
} }
if (AsyncRequest->PrpListHost != NULL) { if (AsyncRequest->PrpListHost != NULL) {
PciIo->FreeBuffer ( PciIo->FreeBuffer (
PciIo, PciIo,
@ -392,7 +402,8 @@ AbortAsyncPassThruTasks (
} }
if (IsListEmpty (&Private->AsyncPassThruQueue) && if (IsListEmpty (&Private->AsyncPassThruQueue) &&
IsListEmpty (&Private->UnsubmittedSubtasks)) { IsListEmpty (&Private->UnsubmittedSubtasks))
{
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} else { } else {
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
@ -403,7 +414,6 @@ AbortAsyncPassThruTasks (
return Status; return Status;
} }
/** /**
Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports
both blocking I/O and non-blocking I/O. The blocking I/O functionality is required, and the non-blocking both blocking I/O and non-blocking I/O. The blocking I/O functionality is required, and the non-blocking
@ -483,7 +493,7 @@ NvmExpressPassThru (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (Packet->QueueType != NVME_ADMIN_QUEUE && Packet->QueueType != NVME_IO_QUEUE) { if ((Packet->QueueType != NVME_ADMIN_QUEUE) && (Packet->QueueType != NVME_IO_QUEUE)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -494,7 +504,8 @@ NvmExpressPassThru (
// //
Attributes = This->Mode->Attributes; Attributes = This->Mode->Attributes;
if ((Attributes & (EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL | if ((Attributes & (EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL |
EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL)) == 0) { EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL)) == 0)
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -502,11 +513,11 @@ NvmExpressPassThru (
// Buffer alignment check for TransferBuffer & MetadataBuffer. // Buffer alignment check for TransferBuffer & MetadataBuffer.
// //
IoAlign = This->Mode->IoAlign; IoAlign = This->Mode->IoAlign;
if (IoAlign > 0 && (((UINTN) Packet->TransferBuffer & (IoAlign - 1)) != 0)) { if ((IoAlign > 0) && (((UINTN)Packet->TransferBuffer & (IoAlign - 1)) != 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (IoAlign > 0 && (((UINTN) Packet->MetadataBuffer & (IoAlign - 1)) != 0)) { if ((IoAlign > 0) && (((UINTN)Packet->MetadataBuffer & (IoAlign - 1)) != 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -516,7 +527,8 @@ NvmExpressPassThru (
// Check NamespaceId is valid or not. // Check NamespaceId is valid or not.
// //
if ((NamespaceId > Private->ControllerData->Nn) && if ((NamespaceId > Private->ControllerData->Nn) &&
(NamespaceId != (UINT32) -1)) { (NamespaceId != (UINT32)-1))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -555,11 +567,13 @@ NvmExpressPassThru (
// Submission queue full check. // Submission queue full check.
// //
if ((Private->SqTdbl[QueueId].Sqt + 1) % QueueSize == if ((Private->SqTdbl[QueueId].Sqt + 1) % QueueSize ==
Private->AsyncSqHead) { Private->AsyncSqHead)
{
return EFI_NOT_READY; return EFI_NOT_READY;
} }
} }
} }
Sq = Private->SqBuffer[QueueId] + Private->SqTdbl[QueueId].Sqt; Sq = Private->SqBuffer[QueueId] + Private->SqTdbl[QueueId].Sqt;
Cq = Private->CqBuffer[QueueId] + Private->CqHdbl[QueueId].Cqh; Cq = Private->CqBuffer[QueueId] + Private->CqHdbl[QueueId].Cqh;
@ -584,7 +598,8 @@ NvmExpressPassThru (
Sq->Prp[0] = (UINT64)(UINTN)Packet->TransferBuffer; Sq->Prp[0] = (UINT64)(UINTN)Packet->TransferBuffer;
if ((Packet->QueueType == NVME_ADMIN_QUEUE) && if ((Packet->QueueType == NVME_ADMIN_QUEUE) &&
((Sq->Opc == NVME_ADMIN_CRIOCQ_CMD) || (Sq->Opc == NVME_ADMIN_CRIOSQ_CMD))) { ((Sq->Opc == NVME_ADMIN_CRIOCQ_CMD) || (Sq->Opc == NVME_ADMIN_CRIOSQ_CMD)))
{
// //
// Currently, we only use the IO Completion/Submission queues created internally // Currently, we only use the IO Completion/Submission queues created internally
// by this driver during controller initialization. Any other IO queues created // by this driver during controller initialization. Any other IO queues created
@ -601,7 +616,8 @@ NvmExpressPassThru (
// If the NVMe cmd has data in or out, then mapping the user buffer to the PCI controller specific addresses. // If the NVMe cmd has data in or out, then mapping the user buffer to the PCI controller specific addresses.
// //
if (((Packet->TransferLength != 0) && (Packet->TransferBuffer == NULL)) || if (((Packet->TransferLength != 0) && (Packet->TransferBuffer == NULL)) ||
((Packet->TransferLength == 0) && (Packet->TransferBuffer != NULL))) { ((Packet->TransferLength == 0) && (Packet->TransferBuffer != NULL)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -647,9 +663,11 @@ NvmExpressPassThru (
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Sq->Mptr = PhyAddr; Sq->Mptr = PhyAddr;
} }
} }
// //
// If the buffer size spans more than two memory pages (page size as defined in CC.Mps), // If the buffer size spans more than two memory pages (page size as defined in CC.Mps),
// then build a PRP list in the second PRP submission queue entry. // then build a PRP list in the second PRP submission queue entry.
@ -676,24 +694,31 @@ NvmExpressPassThru (
if (Packet->NvmeCmd->Flags & CDW2_VALID) { if (Packet->NvmeCmd->Flags & CDW2_VALID) {
Sq->Rsvd2 = (UINT64)Packet->NvmeCmd->Cdw2; Sq->Rsvd2 = (UINT64)Packet->NvmeCmd->Cdw2;
} }
if (Packet->NvmeCmd->Flags & CDW3_VALID) { if (Packet->NvmeCmd->Flags & CDW3_VALID) {
Sq->Rsvd2 |= LShiftU64 ((UINT64)Packet->NvmeCmd->Cdw3, 32); Sq->Rsvd2 |= LShiftU64 ((UINT64)Packet->NvmeCmd->Cdw3, 32);
} }
if (Packet->NvmeCmd->Flags & CDW10_VALID) { if (Packet->NvmeCmd->Flags & CDW10_VALID) {
Sq->Payload.Raw.Cdw10 = Packet->NvmeCmd->Cdw10; Sq->Payload.Raw.Cdw10 = Packet->NvmeCmd->Cdw10;
} }
if (Packet->NvmeCmd->Flags & CDW11_VALID) { if (Packet->NvmeCmd->Flags & CDW11_VALID) {
Sq->Payload.Raw.Cdw11 = Packet->NvmeCmd->Cdw11; Sq->Payload.Raw.Cdw11 = Packet->NvmeCmd->Cdw11;
} }
if (Packet->NvmeCmd->Flags & CDW12_VALID) { if (Packet->NvmeCmd->Flags & CDW12_VALID) {
Sq->Payload.Raw.Cdw12 = Packet->NvmeCmd->Cdw12; Sq->Payload.Raw.Cdw12 = Packet->NvmeCmd->Cdw12;
} }
if (Packet->NvmeCmd->Flags & CDW13_VALID) { if (Packet->NvmeCmd->Flags & CDW13_VALID) {
Sq->Payload.Raw.Cdw13 = Packet->NvmeCmd->Cdw13; Sq->Payload.Raw.Cdw13 = Packet->NvmeCmd->Cdw13;
} }
if (Packet->NvmeCmd->Flags & CDW14_VALID) { if (Packet->NvmeCmd->Flags & CDW14_VALID) {
Sq->Payload.Raw.Cdw14 = Packet->NvmeCmd->Cdw14; Sq->Payload.Raw.Cdw14 = Packet->NvmeCmd->Cdw14;
} }
if (Packet->NvmeCmd->Flags & CDW15_VALID) { if (Packet->NvmeCmd->Flags & CDW15_VALID) {
Sq->Payload.Raw.Cdw15 = Packet->NvmeCmd->Cdw15; Sq->Payload.Raw.Cdw15 = Packet->NvmeCmd->Cdw15;
} }
@ -707,6 +732,7 @@ NvmExpressPassThru (
} else { } else {
Private->SqTdbl[QueueId].Sqt ^= 1; Private->SqTdbl[QueueId].Sqt ^= 1;
} }
Data = ReadUnaligned32 ((UINT32 *)&Private->SqTdbl[QueueId]); Data = ReadUnaligned32 ((UINT32 *)&Private->SqTdbl[QueueId]);
Status = PciIo->Mem.Write ( Status = PciIo->Mem.Write (
PciIo, PciIo,
@ -792,6 +818,7 @@ NvmExpressPassThru (
NvmeDumpStatus (Cq); NvmeDumpStatus (Cq);
DEBUG_CODE_END (); DEBUG_CODE_END ();
} }
// //
// Copy the Respose Queue entry for this command to the callers response buffer // Copy the Respose Queue entry for this command to the callers response buffer
// //
@ -892,6 +919,7 @@ EXIT:
if (TimerEvent != NULL) { if (TimerEvent != NULL) {
gBS->CloseEvent (TimerEvent); gBS->CloseEvent (TimerEvent);
} }
return Status; return Status;
} }
@ -1060,7 +1088,8 @@ NvmExpressGetNamespace (
// Check NamespaceId in the device path node is valid or not. // Check NamespaceId in the device path node is valid or not.
// //
if ((Node->NamespaceId == 0) || if ((Node->NamespaceId == 0) ||
(Node->NamespaceId > Private->ControllerData->Nn)) { (Node->NamespaceId > Private->ControllerData->Nn))
{
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -1130,7 +1159,8 @@ NvmExpressBuildDevicePath (
// Check NamespaceId is valid or not. // Check NamespaceId is valid or not.
// //
if ((NamespaceId == 0) || if ((NamespaceId == 0) ||
(NamespaceId > Private->ControllerData->Nn)) { (NamespaceId > Private->ControllerData->Nn))
{
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }

View File

@ -103,7 +103,7 @@ GetDevicePathInstanceSize (
{ {
EFI_DEVICE_PATH_PROTOCOL *Walker; EFI_DEVICE_PATH_PROTOCOL *Walker;
if (DevicePath == NULL || InstanceSize == NULL || EntireDevicePathEnd == NULL) { if ((DevicePath == NULL) || (InstanceSize == NULL) || (EntireDevicePathEnd == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -167,7 +167,8 @@ NvmeIsHcDevicePathValid (
Start = DevicePath; Start = DevicePath;
while (!(DevicePath->Type == END_DEVICE_PATH_TYPE && while (!(DevicePath->Type == END_DEVICE_PATH_TYPE &&
DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) { DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE))
{
DevicePath = NextDevicePathNode (DevicePath); DevicePath = NextDevicePathNode (DevicePath);
// //
@ -182,7 +183,8 @@ NvmeIsHcDevicePathValid (
// Prevent touching memory beyond given DevicePathLength. // Prevent touching memory beyond given DevicePathLength.
// //
if ((UINTN)DevicePath - (UINTN)Start > if ((UINTN)DevicePath - (UINTN)Start >
DevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL)) { DevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
} }
@ -227,7 +229,7 @@ NvmeBuildDevicePath (
EFI_DEVICE_PATH_PROTOCOL *DevicePathWalker; EFI_DEVICE_PATH_PROTOCOL *DevicePathWalker;
NVME_NAMESPACE_DEVICE_PATH *NvmeDeviceNode; NVME_NAMESPACE_DEVICE_PATH *NvmeDeviceNode;
if (DevicePathLength == NULL || DevicePath == NULL) { if ((DevicePathLength == NULL) || (DevicePath == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -83,6 +83,7 @@ IoMmuMap (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
switch (Operation) { switch (Operation) {
case EdkiiIoMmuOperationBusMasterRead: case EdkiiIoMmuOperationBusMasterRead:
case EdkiiIoMmuOperationBusMasterRead64: case EdkiiIoMmuOperationBusMasterRead64:
@ -100,6 +101,7 @@ IoMmuMap (
ASSERT (FALSE); ASSERT (FALSE);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = IoMmu->SetAttribute ( Status = IoMmu->SetAttribute (
IoMmu, IoMmu,
*Mapping, *Mapping,
@ -113,6 +115,7 @@ IoMmuMap (
*Mapping = NULL; *Mapping = NULL;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
return Status; return Status;
} }
@ -141,6 +144,7 @@ IoMmuUnmap (
} else { } else {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
return Status; return Status;
} }
@ -204,6 +208,7 @@ IoMmuAllocateBuffer (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Status = IoMmu->SetAttribute ( Status = IoMmu->SetAttribute (
IoMmu, IoMmu,
*Mapping, *Mapping,
@ -221,10 +226,12 @@ IoMmuAllocateBuffer (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
*HostAddress = (VOID *)(UINTN)HostPhyAddress; *HostAddress = (VOID *)(UINTN)HostPhyAddress;
*DeviceAddress = HostPhyAddress; *DeviceAddress = HostPhyAddress;
*Mapping = NULL; *Mapping = NULL;
} }
return Status; return Status;
} }
@ -259,5 +266,6 @@ IoMmuFreeBuffer (
} else { } else {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
return Status; return Status;
} }

View File

@ -161,6 +161,7 @@ NvmeDiscoverNamespaces (
// //
EnumerateNvmeDevNamespace (Private, NamespaceId); EnumerateNvmeDevNamespace (Private, NamespaceId);
} }
if (Private->ActiveNamespaceNum == 0) { if (Private->ActiveNamespaceNum == 0) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -269,8 +270,10 @@ NvmExpressPeimEntry (
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG (( DEBUG ((
DEBUG_ERROR, "%a: Fail to allocate get the device path for Controller %d.\n", DEBUG_ERROR,
__FUNCTION__, Controller "%a: Fail to allocate get the device path for Controller %d.\n",
__FUNCTION__,
Controller
)); ));
return Status; return Status;
} }
@ -281,8 +284,10 @@ NvmExpressPeimEntry (
Status = NvmeIsHcDevicePathValid (DevicePath, DevicePathLength); Status = NvmeIsHcDevicePathValid (DevicePath, DevicePathLength);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG (( DEBUG ((
DEBUG_ERROR, "%a: The device path is invalid for Controller %d.\n", DEBUG_ERROR,
__FUNCTION__, Controller "%a: The device path is invalid for Controller %d.\n",
__FUNCTION__,
Controller
)); ));
Controller++; Controller++;
continue; continue;
@ -295,10 +300,13 @@ NvmExpressPeimEntry (
// during S3 resume. // during S3 resume.
// //
if ((BootMode == BOOT_ON_S3_RESUME) && if ((BootMode == BOOT_ON_S3_RESUME) &&
(NvmeS3SkipThisController (DevicePath, DevicePathLength))) { (NvmeS3SkipThisController (DevicePath, DevicePathLength)))
{
DEBUG (( DEBUG ((
DEBUG_ERROR, "%a: Controller %d is skipped during S3.\n", DEBUG_ERROR,
__FUNCTION__, Controller "%a: Controller %d is skipped during S3.\n",
__FUNCTION__,
Controller
)); ));
Controller++; Controller++;
continue; continue;
@ -310,8 +318,10 @@ NvmExpressPeimEntry (
Private = AllocateZeroPool (sizeof (PEI_NVME_CONTROLLER_PRIVATE_DATA)); Private = AllocateZeroPool (sizeof (PEI_NVME_CONTROLLER_PRIVATE_DATA));
if (Private == NULL) { if (Private == NULL) {
DEBUG (( DEBUG ((
DEBUG_ERROR, "%a: Fail to allocate private data for Controller %d.\n", DEBUG_ERROR,
__FUNCTION__, Controller "%a: Fail to allocate private data for Controller %d.\n",
__FUNCTION__,
Controller
)); ));
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -327,11 +337,14 @@ NvmExpressPeimEntry (
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG (( DEBUG ((
DEBUG_ERROR, "%a: Fail to allocate DMA buffers for Controller %d.\n", DEBUG_ERROR,
__FUNCTION__, Controller "%a: Fail to allocate DMA buffers for Controller %d.\n",
__FUNCTION__,
Controller
)); ));
return Status; return Status;
} }
ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)Private->Buffer)); ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)Private->Buffer));
DEBUG ((DEBUG_INFO, "%a: DMA buffer base at 0x%x\n", __FUNCTION__, Private->Buffer)); DEBUG ((DEBUG_INFO, "%a: DMA buffer base at 0x%x\n", __FUNCTION__, Private->Buffer));
@ -351,7 +364,9 @@ NvmExpressPeimEntry (
DEBUG (( DEBUG ((
DEBUG_ERROR, DEBUG_ERROR,
"%a: Controller initialization fail for Controller %d with Status - %r.\n", "%a: Controller initialization fail for Controller %d with Status - %r.\n",
__FUNCTION__, Controller, Status __FUNCTION__,
Controller,
Status
)); ));
NvmeFreeDmaResource (Private); NvmeFreeDmaResource (Private);
Controller++; Controller++;
@ -369,7 +384,9 @@ NvmExpressPeimEntry (
DEBUG (( DEBUG ((
DEBUG_ERROR, DEBUG_ERROR,
"%a: Namespaces discovery fail for Controller %d with Status - %r.\n", "%a: Namespaces discovery fail for Controller %d with Status - %r.\n",
__FUNCTION__, Controller, Status __FUNCTION__,
Controller,
Status
)); ));
NvmeFreeDmaResource (Private); NvmeFreeDmaResource (Private);
Controller++; Controller++;
@ -428,7 +445,8 @@ NvmExpressPeimEntry (
DEBUG (( DEBUG ((
DEBUG_INFO, DEBUG_INFO,
"%a: Security Security Command PPI will be produced for Controller %d.\n", "%a: Security Security Command PPI will be produced for Controller %d.\n",
__FUNCTION__, Controller __FUNCTION__,
Controller
)); ));
Private->StorageSecurityPpi.Revision = EDKII_STORAGE_SECURITY_PPI_REVISION; Private->StorageSecurityPpi.Revision = EDKII_STORAGE_SECURITY_PPI_REVISION;
Private->StorageSecurityPpi.GetNumberofDevices = NvmeStorageSecurityGetDeviceNo; Private->StorageSecurityPpi.GetNumberofDevices = NvmeStorageSecurityGetDeviceNo;
@ -452,8 +470,10 @@ NvmExpressPeimEntry (
PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList); PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList);
DEBUG (( DEBUG ((
DEBUG_INFO, "%a: Controller %d has been successfully initialized.\n", DEBUG_INFO,
__FUNCTION__, Controller "%a: Controller %d has been successfully initialized.\n",
__FUNCTION__,
Controller
)); ));
Controller++; Controller++;
} }

View File

@ -156,7 +156,6 @@ struct _PEI_NVME_CONTROLLER_PRIVATE_DATA {
#define GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) \ #define GET_NVME_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) \
CR (a, PEI_NVME_CONTROLLER_PRIVATE_DATA, EndOfPeiNotifyList, NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE) CR (a, PEI_NVME_CONTROLLER_PRIVATE_DATA, EndOfPeiNotifyList, NVME_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
// //
// Internal functions // Internal functions
// //

View File

@ -124,10 +124,11 @@ NvmeRead (
Retries++; Retries++;
MaxTransferBlocks = MaxTransferBlocks >> 1; MaxTransferBlocks = MaxTransferBlocks >> 1;
if (Retries > NVME_READ_MAX_RETRY || MaxTransferBlocks < 1) { if ((Retries > NVME_READ_MAX_RETRY) || (MaxTransferBlocks < 1)) {
DEBUG ((DEBUG_ERROR, "%a: ReadSectors fail, Status - %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: ReadSectors fail, Status - %r\n", __FUNCTION__, Status));
break; break;
} }
DEBUG (( DEBUG ((
DEBUG_BLKIO, DEBUG_BLKIO,
"%a: ReadSectors fail, retry with smaller transfer block number - 0x%x\n", "%a: ReadSectors fail, retry with smaller transfer block number - 0x%x\n",
@ -146,9 +147,17 @@ NvmeRead (
} }
} }
DEBUG ((DEBUG_BLKIO, "%a: Lba = 0x%08Lx, Original = 0x%08Lx, " DEBUG ((
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n", __FUNCTION__, Lba, DEBUG_BLKIO,
(UINT64)OrginalBlocks, (UINT64)Blocks, BlockSize, Status)); "%a: Lba = 0x%08Lx, Original = 0x%08Lx, "
"Remaining = 0x%08Lx, BlockSize = 0x%x, Status = %r\n",
__FUNCTION__,
Lba,
(UINT64)OrginalBlocks,
(UINT64)Blocks,
BlockSize,
Status
));
return Status; return Status;
} }
@ -178,7 +187,7 @@ NvmeBlockIoPeimGetDeviceNo (
{ {
PEI_NVME_CONTROLLER_PRIVATE_DATA *Private; PEI_NVME_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || NumberBlockDevices == NULL) { if ((This == NULL) || (NumberBlockDevices == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -240,7 +249,7 @@ NvmeBlockIoPeimGetMediaInfo (
{ {
PEI_NVME_CONTROLLER_PRIVATE_DATA *Private; PEI_NVME_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || MediaInfo == NULL) { if ((This == NULL) || (MediaInfo == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -313,7 +322,7 @@ NvmeBlockIoPeimReadBlocks (
// //
// Check parameters // Check parameters
// //
if (This == NULL || Buffer == NULL) { if ((This == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -337,6 +346,7 @@ NvmeBlockIoPeimReadBlocks (
if (StartLBA > NamespaceInfo->Media.LastBlock) { if (StartLBA > NamespaceInfo->Media.LastBlock) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
NumberOfBlocks = BufferSize / BlockSize; NumberOfBlocks = BufferSize / BlockSize;
if (NumberOfBlocks - 1 > NamespaceInfo->Media.LastBlock - StartLBA) { if (NumberOfBlocks - 1 > NamespaceInfo->Media.LastBlock - StartLBA) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -371,7 +381,7 @@ NvmeBlockIoPeimGetDeviceNo2 (
{ {
PEI_NVME_CONTROLLER_PRIVATE_DATA *Private; PEI_NVME_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || NumberBlockDevices == NULL) { if ((This == NULL) || (NumberBlockDevices == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -435,7 +445,7 @@ NvmeBlockIoPeimGetMediaInfo2 (
PEI_NVME_CONTROLLER_PRIVATE_DATA *Private; PEI_NVME_CONTROLLER_PRIVATE_DATA *Private;
EFI_PEI_BLOCK_IO_MEDIA Media; EFI_PEI_BLOCK_IO_MEDIA Media;
if (This == NULL || MediaInfo == NULL) { if ((This == NULL) || (MediaInfo == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -55,6 +55,7 @@ NvmeMmioRead (
Data = MmioRead8 (MmioAddr + Offset); Data = MmioRead8 (MmioAddr + Offset);
Ptr[Offset] = Data; Ptr[Offset] = Data;
} }
break; break;
} }
@ -106,6 +107,7 @@ NvmeMmioWrite (
Data = Ptr[Offset]; Data = Ptr[Offset];
MmioWrite8 (MmioAddr + Offset, Data); MmioWrite8 (MmioAddr + Offset, Data);
} }
break; break;
} }
@ -589,6 +591,7 @@ NvmeControllerInit (
ZeroMem ((VOID *)(UINTN)(&Private->SqTdbl[Index]), sizeof (NVME_SQTDBL)); ZeroMem ((VOID *)(UINTN)(&Private->SqTdbl[Index]), sizeof (NVME_SQTDBL));
ZeroMem ((VOID *)(UINTN)(&Private->CqHdbl[Index]), sizeof (NVME_CQHDBL)); ZeroMem ((VOID *)(UINTN)(&Private->CqHdbl[Index]), sizeof (NVME_CQHDBL));
} }
ZeroMem (Private->Buffer, EFI_PAGE_SIZE * NVME_MEM_MAX_PAGES); ZeroMem (Private->Buffer, EFI_PAGE_SIZE * NVME_MEM_MAX_PAGES);
// //
@ -657,11 +660,13 @@ NvmeControllerInit (
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
} }
Status = NvmeIdentifyController (Private, Private->ControllerData); Status = NvmeIdentifyController (Private, Private->ControllerData);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: NvmeIdentifyController fail, Status - %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: NvmeIdentifyController fail, Status - %r\n", __FUNCTION__, Status));
return Status; return Status;
} }
NvmeDumpControllerData (Private->ControllerData); NvmeDumpControllerData (Private->ControllerData);
// //
@ -684,6 +689,7 @@ NvmeControllerInit (
DEBUG ((DEBUG_ERROR, "%a: Create IO completion queue fail, Status - %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: Create IO completion queue fail, Status - %r\n", __FUNCTION__, Status));
return Status; return Status;
} }
Status = NvmeCreateIoSubmissionQueue (Private); Status = NvmeCreateIoSubmissionQueue (Private);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Create IO submission queue fail, Status - %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: Create IO submission queue fail, Status - %r\n", __FUNCTION__, Status));

View File

@ -51,7 +51,6 @@ enum {
#define NVME_CQ_BASE(Private, Index) (ALIGN (NVME_MEM_BASE(Private) + ((NvmeBaseMemPageOffset (BASEMEM_CQ) + ((Index)*(NVME_MAX_QUEUES-1))) * EFI_PAGE_SIZE), EFI_PAGE_SIZE)) #define NVME_CQ_BASE(Private, Index) (ALIGN (NVME_MEM_BASE(Private) + ((NvmeBaseMemPageOffset (BASEMEM_CQ) + ((Index)*(NVME_MAX_QUEUES-1))) * EFI_PAGE_SIZE), EFI_PAGE_SIZE))
#define NVME_PRP_BASE(Private) (ALIGN (NVME_MEM_BASE(Private) + ((NvmeBaseMemPageOffset (BASEMEM_PRP)) * EFI_PAGE_SIZE), EFI_PAGE_SIZE)) #define NVME_PRP_BASE(Private) (ALIGN (NVME_MEM_BASE(Private) + ((NvmeBaseMemPageOffset (BASEMEM_PRP)) * EFI_PAGE_SIZE), EFI_PAGE_SIZE))
/** /**
Transfer MMIO Data to memory. Transfer MMIO Data to memory.

View File

@ -62,6 +62,7 @@ NvmeCreatePrpList (
)); ));
return 0; return 0;
} }
PrpListHost = (VOID *)(UINTN)NVME_PRP_BASE (Private); PrpListHost = (VOID *)(UINTN)NVME_PRP_BASE (Private);
Bytes = EFI_PAGES_TO_SIZE (PrpListNo); Bytes = EFI_PAGES_TO_SIZE (PrpListNo);
@ -117,7 +118,7 @@ NvmeCheckCqStatus (
IN NVME_CQ *Cq IN NVME_CQ *Cq
) )
{ {
if (Cq->Sct == 0x0 && Cq->Sc == 0x0) { if ((Cq->Sct == 0x0) && (Cq->Sc == 0x0)) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -202,6 +203,7 @@ NvmeCheckCqStatus (
DEBUG ((DEBUG_INFO, "Reservation Conflict\n")); DEBUG ((DEBUG_INFO, "Reservation Conflict\n"));
break; break;
} }
break; break;
case 0x1: case 0x1:
@ -264,6 +266,7 @@ NvmeCheckCqStatus (
DEBUG ((DEBUG_INFO, "Attempted Write to Read Only Range\n")); DEBUG ((DEBUG_INFO, "Attempted Write to Read Only Range\n"));
break; break;
} }
break; break;
case 0x2: case 0x2:
@ -290,6 +293,7 @@ NvmeCheckCqStatus (
DEBUG ((DEBUG_INFO, "Access Denied\n")); DEBUG ((DEBUG_INFO, "Access Denied\n"));
break; break;
} }
break; break;
default: default:
@ -378,7 +382,7 @@ NvmePassThruExecute (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (Packet->QueueType != NVME_ADMIN_QUEUE && Packet->QueueType != NVME_IO_QUEUE) { if ((Packet->QueueType != NVME_ADMIN_QUEUE) && (Packet->QueueType != NVME_IO_QUEUE)) {
DEBUG (( DEBUG ((
DEBUG_ERROR, DEBUG_ERROR,
"%a, Invalid parameter: QueueId(%lx)\n", "%a, Invalid parameter: QueueId(%lx)\n",
@ -413,7 +417,7 @@ NvmePassThruExecute (
ZeroMem (Sq, sizeof (NVME_SQ)); ZeroMem (Sq, sizeof (NVME_SQ));
Sq->Opc = (UINT8)Packet->NvmeCmd->Cdw0.Opcode; Sq->Opc = (UINT8)Packet->NvmeCmd->Cdw0.Opcode;
Sq->Fuse = (UINT8)Packet->NvmeCmd->Cdw0.FusedOperation; Sq->Fuse = (UINT8)Packet->NvmeCmd->Cdw0.FusedOperation;
Sq->Cid = Private->Cid[QueueId]++;; Sq->Cid = Private->Cid[QueueId]++;
Sq->Nsid = Packet->NvmeCmd->Nsid; Sq->Nsid = Packet->NvmeCmd->Nsid;
// //
@ -436,7 +440,8 @@ NvmePassThruExecute (
// //
if ((Sq->Opc & (BIT0 | BIT1)) != 0) { if ((Sq->Opc & (BIT0 | BIT1)) != 0) {
if (((Packet->TransferLength != 0) && (Packet->TransferBuffer == NULL)) || if (((Packet->TransferLength != 0) && (Packet->TransferBuffer == NULL)) ||
((Packet->TransferLength == 0) && (Packet->TransferBuffer != NULL))) { ((Packet->TransferLength == 0) && (Packet->TransferBuffer != NULL)))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -445,9 +450,11 @@ NvmePassThruExecute (
// allocated internally by the driver. // allocated internally by the driver.
// //
if ((Packet->QueueType == NVME_ADMIN_QUEUE) && if ((Packet->QueueType == NVME_ADMIN_QUEUE) &&
((Sq->Opc == NVME_ADMIN_CRIOCQ_CMD) || (Sq->Opc == NVME_ADMIN_CRIOSQ_CMD))) { ((Sq->Opc == NVME_ADMIN_CRIOCQ_CMD) || (Sq->Opc == NVME_ADMIN_CRIOSQ_CMD)))
{
if ((Packet->TransferBuffer != Private->SqBuffer[NVME_IO_QUEUE]) && if ((Packet->TransferBuffer != Private->SqBuffer[NVME_IO_QUEUE]) &&
(Packet->TransferBuffer != Private->CqBuffer[NVME_IO_QUEUE])) { (Packet->TransferBuffer != Private->CqBuffer[NVME_IO_QUEUE]))
{
DEBUG (( DEBUG ((
DEBUG_ERROR, DEBUG_ERROR,
"%a: Does not support external IO queues creation request.\n", "%a: Does not support external IO queues creation request.\n",
@ -494,6 +501,7 @@ NvmePassThruExecute (
DEBUG ((DEBUG_ERROR, "%a: Fail to map meta data buffer.\n", __FUNCTION__)); DEBUG ((DEBUG_ERROR, "%a: Fail to map meta data buffer.\n", __FUNCTION__));
goto Exit; goto Exit;
} }
Sq->Mptr = PhyAddr; Sq->Mptr = PhyAddr;
} }
} }
@ -521,7 +529,6 @@ NvmePassThruExecute (
DEBUG ((DEBUG_ERROR, "%a: Create PRP list fail, Status - %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: Create PRP list fail, Status - %r\n", __FUNCTION__, Status));
goto Exit; goto Exit;
} }
} else if ((Offset + Bytes) > EFI_PAGE_SIZE) { } else if ((Offset + Bytes) > EFI_PAGE_SIZE) {
Sq->Prp[1] = (Sq->Prp[0] + EFI_PAGE_SIZE) & ~(EFI_PAGE_SIZE - 1); Sq->Prp[1] = (Sq->Prp[0] + EFI_PAGE_SIZE) & ~(EFI_PAGE_SIZE - 1);
} }
@ -529,18 +536,23 @@ NvmePassThruExecute (
if (Packet->NvmeCmd->Flags & CDW10_VALID) { if (Packet->NvmeCmd->Flags & CDW10_VALID) {
Sq->Payload.Raw.Cdw10 = Packet->NvmeCmd->Cdw10; Sq->Payload.Raw.Cdw10 = Packet->NvmeCmd->Cdw10;
} }
if (Packet->NvmeCmd->Flags & CDW11_VALID) { if (Packet->NvmeCmd->Flags & CDW11_VALID) {
Sq->Payload.Raw.Cdw11 = Packet->NvmeCmd->Cdw11; Sq->Payload.Raw.Cdw11 = Packet->NvmeCmd->Cdw11;
} }
if (Packet->NvmeCmd->Flags & CDW12_VALID) { if (Packet->NvmeCmd->Flags & CDW12_VALID) {
Sq->Payload.Raw.Cdw12 = Packet->NvmeCmd->Cdw12; Sq->Payload.Raw.Cdw12 = Packet->NvmeCmd->Cdw12;
} }
if (Packet->NvmeCmd->Flags & CDW13_VALID) { if (Packet->NvmeCmd->Flags & CDW13_VALID) {
Sq->Payload.Raw.Cdw13 = Packet->NvmeCmd->Cdw13; Sq->Payload.Raw.Cdw13 = Packet->NvmeCmd->Cdw13;
} }
if (Packet->NvmeCmd->Flags & CDW14_VALID) { if (Packet->NvmeCmd->Flags & CDW14_VALID) {
Sq->Payload.Raw.Cdw14 = Packet->NvmeCmd->Cdw14; Sq->Payload.Raw.Cdw14 = Packet->NvmeCmd->Cdw14;
} }
if (Packet->NvmeCmd->Flags & CDW15_VALID) { if (Packet->NvmeCmd->Flags & CDW15_VALID) {
Sq->Payload.Raw.Cdw15 = Packet->NvmeCmd->Cdw15; Sq->Payload.Raw.Cdw15 = Packet->NvmeCmd->Cdw15;
} }
@ -552,6 +564,7 @@ NvmePassThruExecute (
if (Private->SqTdbl[QueueId].Sqt == SqSize) { if (Private->SqTdbl[QueueId].Sqt == SqSize) {
Private->SqTdbl[QueueId].Sqt = 0; Private->SqTdbl[QueueId].Sqt = 0;
} }
Data32 = ReadUnaligned32 ((UINT32 *)&Private->SqTdbl[QueueId]); Data32 = ReadUnaligned32 ((UINT32 *)&Private->SqTdbl[QueueId]);
Status = NVME_SET_SQTDBL (Private, QueueId, &Data32); Status = NVME_SET_SQTDBL (Private, QueueId, &Data32);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -588,6 +601,7 @@ NvmePassThruExecute (
// //
Status = EFI_TIMEOUT; Status = EFI_TIMEOUT;
} }
goto Exit; goto Exit;
} }
@ -650,7 +664,7 @@ NvmePassThruGetDevicePath (
{ {
PEI_NVME_CONTROLLER_PRIVATE_DATA *Private; PEI_NVME_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || DevicePathLength == NULL || DevicePath == NULL) { if ((This == NULL) || (DevicePathLength == NULL) || (DevicePath == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -713,7 +727,7 @@ NvmePassThruGetNextNameSpace (
UINT32 DeviceIndex; UINT32 DeviceIndex;
EFI_STATUS Status; EFI_STATUS Status;
if (This == NULL || NamespaceId == NULL) { if ((This == NULL) || (NamespaceId == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -752,13 +766,13 @@ NvmePassThruGetNextNameSpace (
*NamespaceId = Private->NamespaceInfo[DeviceIndex + 1].NamespaceId; *NamespaceId = Private->NamespaceInfo[DeviceIndex + 1].NamespaceId;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
break; break;
} }
} }
} }
return Status; return Status;
} }
/** /**
@ -803,7 +817,7 @@ NvmePassThru (
PEI_NVME_CONTROLLER_PRIVATE_DATA *Private; PEI_NVME_CONTROLLER_PRIVATE_DATA *Private;
EFI_STATUS Status; EFI_STATUS Status;
if (This == NULL || Packet == NULL) { if ((This == NULL) || (Packet == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -812,7 +826,8 @@ NvmePassThru (
// Check NamespaceId is valid or not. // Check NamespaceId is valid or not.
// //
if ((NamespaceId > Private->ControllerData->Nn) && if ((NamespaceId > Private->ControllerData->Nn) &&
(NamespaceId != (UINT32) -1)) { (NamespaceId != (UINT32)-1))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -823,6 +838,4 @@ NvmePassThru (
); );
return Status; return Status;
} }

View File

@ -11,8 +11,6 @@
#ifndef _NVM_EXPRESS_PEI_PASSTHRU_H_ #ifndef _NVM_EXPRESS_PEI_PASSTHRU_H_
#define _NVM_EXPRESS_PEI_PASSTHRU_H_ #define _NVM_EXPRESS_PEI_PASSTHRU_H_
/** /**
Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function only Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function only
supports blocking execution of the command. supports blocking execution of the command.

View File

@ -97,7 +97,8 @@ NvmeS3SkipThisController (
DevicePathInst, DevicePathInst,
HcDevicePath, HcDevicePath,
HcDevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL) HcDevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL)
) == 0) { ) == 0)
{
Skip = FALSE; Skip = FALSE;
break; break;
} }

View File

@ -132,7 +132,7 @@ NvmeStorageSecurityGetDeviceNo (
{ {
PEI_NVME_CONTROLLER_PRIVATE_DATA *Private; PEI_NVME_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || NumberofDevices == NULL) { if ((This == NULL) || (NumberofDevices == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -178,7 +178,7 @@ NvmeStorageSecurityGetDevicePath (
{ {
PEI_NVME_CONTROLLER_PRIVATE_DATA *Private; PEI_NVME_CONTROLLER_PRIVATE_DATA *Private;
if (This == NULL || DevicePathLength == NULL || DevicePath == NULL) { if ((This == NULL) || (DevicePathLength == NULL) || (DevicePath == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -26,7 +26,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPciBusComponentName2
"en" "en"
}; };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPciBusDriverNameTable[] = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPciBusDriverNameTable[] = {
{ "eng;en", (CHAR16 *)L"PCI Bus Driver" }, { "eng;en", (CHAR16 *)L"PCI Bus Driver" },
{ NULL, NULL } { NULL, NULL }

Some files were not shown because too many files have changed in this diff Show More