]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/ResetUtilityLib/ResetUtility.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Library / ResetUtilityLib / ResetUtility.c
index e3de4f117af86bc66157835c3dba12b0deb62e5a..50131a431f972a613fb9e798eb3ce88dce140e86 100644 (file)
@@ -1,16 +1,10 @@
 /** @file\r
   This contains the business logic for the module-specific Reset Helper functions.\r
 \r
-  Copyright (c) 2017 - 2018 Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2017 - 2019 Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2016 Microsoft Corporation. All rights reserved.<BR>\r
 \r
-  This program and the accompanying materials are licensed and made available under\r
-  the terms and conditions of the BSD License that accompanies this distribution.\r
-  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 #include <Uefi.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/ResetSystemLib.h>\r
 \r
+#pragma pack(1)\r
 typedef struct {\r
-  CHAR16 NullTerminator;\r
-  GUID   ResetSubtype;\r
+  CHAR16    NullTerminator;\r
+  GUID      ResetSubtype;\r
 } RESET_UTILITY_GUID_SPECIFIC_RESET_DATA;\r
+#pragma pack()\r
+\r
+STATIC_ASSERT (\r
+  sizeof (RESET_UTILITY_GUID_SPECIFIC_RESET_DATA) == 18,\r
+  "sizeof (RESET_UTILITY_GUID_SPECIFIC_RESET_DATA) is expected to be 18 bytes"\r
+  );\r
 \r
 /**\r
-  This is a shorthand helper function to reset with a subtype so that\r
-  the caller doesn't have to bother with a function that has half a dozen\r
-  parameters.\r
+  This is a shorthand helper function to reset with reset type and a subtype\r
+  so that the caller doesn't have to bother with a function that has half\r
+  a dozen parameters.\r
 \r
   This will generate a reset with status EFI_SUCCESS, a NULL string, and\r
   no custom data. The subtype will be formatted in such a way that it can be\r
@@ -37,20 +38,51 @@ typedef struct {
         are not initialized. For DXE, you can add gEfiResetArchProtocolGuid\r
         to your DEPEX.\r
 \r
+  @param[in]  ResetType     The default EFI_RESET_TYPE of the reset.\r
   @param[in]  ResetSubtype  GUID pointer for the reset subtype to be used.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
-ResetPlatformSpecificGuid (\r
-  IN CONST  GUID        *ResetSubtype\r
+ResetSystemWithSubtype (\r
+  IN EFI_RESET_TYPE  ResetType,\r
+  IN CONST  GUID     *ResetSubtype\r
   )\r
 {\r
   RESET_UTILITY_GUID_SPECIFIC_RESET_DATA  ResetData;\r
 \r
   ResetData.NullTerminator = CHAR_NULL;\r
-  CopyGuid (&ResetData.ResetSubtype, ResetSubtype);\r
-  ResetPlatformSpecific (sizeof (ResetData), &ResetData);\r
+  CopyGuid (\r
+    (GUID *)((UINT8 *)&ResetData + OFFSET_OF (RESET_UTILITY_GUID_SPECIFIC_RESET_DATA, ResetSubtype)),\r
+    ResetSubtype\r
+    );\r
+\r
+  ResetSystem (ResetType, EFI_SUCCESS, sizeof (ResetData), &ResetData);\r
+}\r
+\r
+/**\r
+  This is a shorthand helper function to reset with the reset type\r
+  'EfiResetPlatformSpecific' and a subtype so that the caller doesn't\r
+  have to bother with a function that has half a dozen parameters.\r
+\r
+  This will generate a reset with status EFI_SUCCESS, a NULL string, and\r
+  no custom data. The subtype will be formatted in such a way that it can be\r
+  picked up by notification registrations and custom handlers.\r
+\r
+  NOTE: This call will fail if the architectural ResetSystem underpinnings\r
+        are not initialized. For DXE, you can add gEfiResetArchProtocolGuid\r
+        to your DEPEX.\r
+\r
+  @param[in]  ResetSubtype  GUID pointer for the reset subtype to be used.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetPlatformSpecificGuid (\r
+  IN CONST  GUID  *ResetSubtype\r
+  )\r
+{\r
+  ResetSystemWithSubtype (EfiResetPlatformSpecific, ResetSubtype);\r
 }\r
 \r
 /**\r
@@ -78,8 +110,8 @@ GetResetPlatformSpecificGuid (
   IN CONST VOID  *ResetData\r
   )\r
 {\r
-  UINTN          ResetDataStringSize;\r
-  GUID           *ResetSubtypeGuid;\r
+  UINTN  ResetDataStringSize;\r
+  GUID   *ResetSubtypeGuid;\r
 \r
   //\r
   // Make sure parameters are valid\r
@@ -98,11 +130,12 @@ GetResetPlatformSpecificGuid (
   // Now, assuming that we have enough data for a GUID after the string, the\r
   // GUID should be immediately after the string itself.\r
   //\r
-  if ((ResetDataStringSize < DataSize) && (DataSize - ResetDataStringSize) >= sizeof (GUID)) {\r
+  if ((ResetDataStringSize < DataSize) && ((DataSize - ResetDataStringSize) >= sizeof (GUID))) {\r
     ResetSubtypeGuid = (GUID *)((UINT8 *)ResetData + ResetDataStringSize);\r
     DEBUG ((DEBUG_VERBOSE, "%a - Detected reset subtype %g...\n", __FUNCTION__, ResetSubtypeGuid));\r
     return ResetSubtypeGuid;\r
   }\r
+\r
   return NULL;\r
 }\r
 \r
@@ -142,12 +175,12 @@ GetResetPlatformSpecificGuid (
 RETURN_STATUS\r
 EFIAPI\r
 BuildResetData (\r
-  IN OUT   UINTN     *ResetDataSize,\r
-  IN OUT   VOID      *ResetData,\r
-  IN CONST GUID      *ResetSubtype  OPTIONAL,\r
-  IN CONST CHAR16    *ResetString   OPTIONAL,\r
-  IN       UINTN     ExtraDataSize  OPTIONAL,\r
-  IN CONST VOID      *ExtraData     OPTIONAL\r
+  IN OUT   UINTN   *ResetDataSize,\r
+  IN OUT   VOID    *ResetData,\r
+  IN CONST GUID    *ResetSubtype  OPTIONAL,\r
+  IN CONST CHAR16  *ResetString   OPTIONAL,\r
+  IN       UINTN   ExtraDataSize  OPTIONAL,\r
+  IN CONST VOID    *ExtraData     OPTIONAL\r
   )\r
 {\r
   UINTN  ResetStringSize;\r
@@ -160,16 +193,18 @@ BuildResetData (
   if (ResetDataSize == NULL) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
+\r
   //\r
   // If extra data is indicated, but pointer is NULL.\r
   //\r
-  if (ExtraDataSize > 0 && ExtraData == NULL) {\r
+  if ((ExtraDataSize > 0) && (ExtraData == NULL)) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
+\r
   //\r
   // If extra data is indicated, but no subtype GUID is supplied.\r
   //\r
-  if (ResetSubtype == NULL && ExtraDataSize > 0) {\r
+  if ((ResetSubtype == NULL) && (ExtraDataSize > 0)) {\r
     return RETURN_INVALID_PARAMETER;\r
   }\r
 \r
@@ -197,6 +232,7 @@ BuildResetData (
     *ResetDataSize = ResetDataBufferSize;\r
     return RETURN_BUFFER_TOO_SMALL;\r
   }\r
+\r
   *ResetDataSize = ResetDataBufferSize;\r
   if (ResetData == NULL) {\r
     return RETURN_INVALID_PARAMETER;\r
@@ -212,6 +248,7 @@ BuildResetData (
     CopyMem (Data, ResetSubtype, sizeof (GUID));\r
     Data += sizeof (GUID);\r
   }\r
+\r
   if (ExtraDataSize > 0) {\r
     CopyMem (Data, ExtraData, ExtraDataSize);\r
   }\r