Add Tper Reset Logic by using MOR bit.
[mirror_edk2.git] / SecurityPkg / Tcg / MemoryOverwriteControl / TcgMor.c
1 /** @file
2 TCG MOR (Memory Overwrite Request) Control Driver.
3
4 This driver initilize MemoryOverwriteRequestControl variable. It
5 will clear MOR_CLEAR_MEMORY_BIT bit if it is set.
6
7 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include "TcgMor.h"
19
20 /**
21 Entry Point for TCG MOR Control driver.
22
23 @param[in] ImageHandle Image handle of this driver.
24 @param[in] SystemTable A Pointer to the EFI System Table.
25
26 @retval EFI_SUCEESS
27 @return Others Some error occurs.
28 **/
29 EFI_STATUS
30 EFIAPI
31 MorDriverEntryPoint (
32 IN EFI_HANDLE ImageHandle,
33 IN EFI_SYSTEM_TABLE *SystemTable
34 )
35 {
36 EFI_STATUS Status;
37 UINT8 MorControl;
38 UINTN DataSize;
39
40 ///
41 /// The firmware is required to create the MemoryOverwriteRequestControl UEFI variable.
42 ///
43
44 DataSize = sizeof (MorControl);
45 Status = gRT->GetVariable (
46 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
47 &gEfiMemoryOverwriteControlDataGuid,
48 NULL,
49 &DataSize,
50 &MorControl
51 );
52 if (EFI_ERROR (Status)) {
53 //
54 // Set default value to 0
55 //
56 MorControl = 0;
57 } else {
58 if (MOR_CLEAR_MEMORY_VALUE (MorControl) == 0x0) {
59 //
60 // MorControl is expected, directly return to avoid unnecessary variable operation
61 //
62 return EFI_SUCCESS;
63 }
64 //
65 // Clear MOR_CLEAR_MEMORY_BIT
66 //
67 DEBUG ((EFI_D_INFO, "TcgMor: Clear MorClearMemory bit\n"));
68 MorControl &= 0xFE;
69 }
70
71 Status = gRT->SetVariable (
72 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
73 &gEfiMemoryOverwriteControlDataGuid,
74 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
75 DataSize,
76 &MorControl
77 );
78 ASSERT_EFI_ERROR (Status);
79 return Status;
80 }
81
82