Skip to content

Commit

Permalink
EDKIIUS-203:AMD/AmdPlatformPkg: Upstream Opal Revert Dxe Driver (tian…
Browse files Browse the repository at this point in the history
…ocore#259)

Co-authored-by: kenyao12 <[email protected]>
  • Loading branch information
2 people authored and Abdul Lateef Attar committed Jan 12, 2025
1 parent 42ab085 commit 58e9ac3
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
AmdPlatformPkg/Universal/S3Support/PlatformSmm/PlatformSmm.inf
AmdPlatformPkg/Universal/I2c/I2cConfigDxe/I2cConfigDxe.inf
AmdPlatformPkg/Universal/SecureBoot/SecureBootInitDxe/SecureBootInitDxe.inf
AmdPlatformPkg/Universal/OpalRevertDxe/OpalRevertDxe.inf

[PcdsDynamicDefault]
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Expand Down
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;
}
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
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

0 comments on commit 58e9ac3

Please sign in to comment.