forked from tianocore/edk2-platforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EDKIIUS-203:AMD/AmdPlatformPkg: Upstream Opal Revert Dxe Driver (tian…
…ocore#259) Co-authored-by: kenyao12 <[email protected]>
- Loading branch information
1 parent
42ab085
commit 58e9ac3
Showing
4 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
Platform/AMD/AmdPlatformPkg/Universal/OpalRevertDxe/OpalRevertDxe.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** @file | ||
Implements OpalRevertDxe.c | ||
Opal Revert Dxe driver. | ||
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR> | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <Base.h> | ||
#include <Library/UefiBootServicesTableLib.h> | ||
#include <Library/UefiLib.h> | ||
#include <Library/DebugLib.h> | ||
#include <Library/IoLib.h> | ||
#include <Protocol/PlatformSpecificResetHandler.h> | ||
#include "OpalRevertDxe.h" | ||
|
||
EFI_GUID mVariableGuid = SETUP_VARIABLE_GUID; | ||
|
||
/** | ||
Opal revert Platform specific reset. | ||
@param[in] ResetType Type of platform specific reset. | ||
@param[in] ResetStatus Status of platform specific reset. | ||
@param[in] DataSize Variable Data size | ||
@param[in] ResetData ResetData of platform specific reset. | ||
**/ | ||
VOID | ||
EFIAPI | ||
OpalRevertPlatformSpecificReset ( | ||
IN EFI_RESET_TYPE ResetType, | ||
IN EFI_STATUS ResetStatus, | ||
IN UINTN DataSize, | ||
IN VOID *ResetData OPTIONAL | ||
) | ||
{ | ||
EFI_STATUS Status; | ||
OPAL_REQUEST_VARIABLE *Variable; | ||
UINTN VariableSize; | ||
|
||
Status = GetVariable2 ( | ||
OPAL_REQUEST_VARIABLE_NAME, | ||
&mVariableGuid, | ||
(VOID **)&Variable, | ||
&VariableSize | ||
); | ||
if (!EFI_ERROR (Status) && (Variable != NULL)) { | ||
if (Variable->OpalRequest.Revert != 0) { | ||
// | ||
// Power cycle the system to make sure the OPAL device is in | ||
// known state for admin revert | ||
// | ||
DEBUG ((DEBUG_INFO, "OPAL admin revert requested, power cycle the system\n")); | ||
IoWrite8 (RST_CNT, POWERCYCLE); | ||
ASSERT (FALSE); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
Entry point of the OPAL Revert driver. | ||
@param[in] ImageHandle Image handle of this driver. | ||
@param[in] SystemTable Pointer to standard EFI system table. | ||
@retval EFI_SUCCESS Succeed. | ||
@retval !EFI_SUCCESS Fail to register OpalRevertPlatformSpecificReset callback. | ||
**/ | ||
EFI_STATUS | ||
EFIAPI | ||
OpalRevertEntry ( | ||
IN EFI_HANDLE ImageHandle, | ||
IN EFI_SYSTEM_TABLE *SystemTable | ||
) | ||
{ | ||
EFI_STATUS Status; | ||
EFI_RESET_NOTIFICATION_PROTOCOL *ResetNotify; | ||
|
||
ResetNotify = NULL; | ||
DEBUG ((DEBUG_INFO, "%a - ENTRY\n", __func__)); | ||
|
||
Status = gBS->LocateProtocol (&gEdkiiPlatformSpecificResetHandlerProtocolGuid, NULL, (VOID **)&ResetNotify); | ||
if (!EFI_ERROR (Status)) { | ||
DEBUG ((DEBUG_INFO, "Register OpalRevertPlatformSpecificReset by gEdkiiPlatformSpecificResetHandlerProtocolGuid.\n")); | ||
Status = ResetNotify->RegisterResetNotify (ResetNotify, OpalRevertPlatformSpecificReset); | ||
ASSERT_EFI_ERROR (Status); | ||
} else { | ||
DEBUG ((DEBUG_INFO, "Cannot locate gEdkiiPlatformSpecificResetHandlerProtocolGuid! OpalRevertPlatformSpecificReset is not registered.\n")); | ||
ASSERT_EFI_ERROR (Status); | ||
} | ||
|
||
DEBUG ((DEBUG_INFO, "%a - EXIT (Status = %r)\n", __func__, Status)); | ||
|
||
return Status; | ||
} |
43 changes: 43 additions & 0 deletions
43
Platform/AMD/AmdPlatformPkg/Universal/OpalRevertDxe/OpalRevertDxe.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** @file | ||
Implements OpalRevertDxe.h | ||
Opal Revert Dxe driver header file | ||
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR> | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#ifndef OPAL_REVERT_DXE_H_ | ||
#define OPAL_REVERT_DXE_H_ | ||
|
||
// {BBF1ACD2-28D8-44ea-A291-58A237FEDF1A} | ||
#define SETUP_VARIABLE_GUID { 0xbbf1acd2, 0x28d8, 0x44ea, { 0xa2, 0x91, 0x58, 0xa2, 0x37, 0xfe, 0xdf, 0x1a } } | ||
#define OPAL_REQUEST_VARIABLE_NAME L"OpalRequest" | ||
#define RST_CNT 0xCF9 | ||
#define POWERCYCLE 0x0E | ||
|
||
#pragma pack(1) | ||
|
||
typedef struct { | ||
UINT16 Lock : 1; | ||
UINT16 Unlock : 1; | ||
UINT16 SetAdminPwd : 1; | ||
UINT16 SetUserPwd : 1; | ||
UINT16 SecureErase : 1; | ||
UINT16 Revert : 1; | ||
UINT16 PsidRevert : 1; | ||
UINT16 DisableUser : 1; | ||
UINT16 DisableFeature : 1; | ||
UINT16 EnableFeature : 1; | ||
UINT16 Reserved : 5; | ||
UINT16 KeepUserData : 1; | ||
} OPAL_REQUEST; | ||
|
||
typedef struct { | ||
UINT32 Length; | ||
OPAL_REQUEST OpalRequest; | ||
} OPAL_REQUEST_VARIABLE; | ||
|
||
#pragma pack() | ||
|
||
#endif |
41 changes: 41 additions & 0 deletions
41
Platform/AMD/AmdPlatformPkg/Universal/OpalRevertDxe/OpalRevertDxe.inf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## @file | ||
# Opal Revert Dxe driver inf file | ||
# | ||
# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR> | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
## | ||
|
||
[Defines] | ||
INF_VERSION = 0x00010019 | ||
BASE_NAME = OpalRevertDxe | ||
FILE_GUID = 8B702C70-A9FE-45F6-BA66-951B50BA3B92 | ||
MODULE_TYPE = DXE_DRIVER | ||
VERSION_STRING = 0.1 | ||
PI_SPECIFICATION_VERSION = 0x0001000A | ||
ENTRY_POINT = OpalRevertEntry | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
MdeModulePkg/MdeModulePkg.dec | ||
AmdPlatformPkg/AmdPlatformPkg.dec | ||
|
||
[LibraryClasses] | ||
UefiDriverEntryPoint | ||
UefiBootServicesTableLib | ||
UefiRuntimeServicesTableLib | ||
UefiLib | ||
DebugLib | ||
IoLib | ||
|
||
[Sources] | ||
OpalRevertDxe.h | ||
OpalRevertDxe.c | ||
|
||
[Protocols] | ||
gEdkiiPlatformSpecificResetHandlerProtocolGuid ## CONSUMES | ||
|
||
[Depex] | ||
gEfiResetArchProtocolGuid AND | ||
gEdkiiPlatformSpecificResetHandlerProtocolGuid AND | ||
gEfiStorageSecurityCommandProtocolGuid |