]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.c
Fix the return status when physical presence variable and MemoryOverwriteRequestContr...
[mirror_edk2.git] / SecurityPkg / Tcg / MemoryOverwriteControl / TcgMor.c
CommitLineData
0c18794e 1/** @file\r
2 TCG MOR (Memory Overwrite Request) Control Driver.\r
3\r
4 This driver initilize MemoryOverwriteRequestControl variable. It \r
5 will clear MOR_CLEAR_MEMORY_BIT bit if it is set.\r
6\r
8a8c6c96 7Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
0c18794e 8This program and the accompanying materials \r
9are licensed and made available under the terms and conditions of the BSD License \r
10which accompanies this distribution. The full text of the license may be found at \r
11http://opensource.org/licenses/bsd-license.php\r
12\r
13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18#include "TcgMor.h"\r
19\r
504dfa9d 20UINT8 mMorControl;\r
21\r
22/**\r
23 Ready to Boot Event notification handler.\r
24\r
25 Sequence of OS boot events is measured in this event notification handler.\r
26\r
27 @param[in] Event Event whose notification function is being invoked\r
28 @param[in] Context Pointer to the notification function's context\r
29\r
30**/\r
31VOID\r
32EFIAPI\r
33OnReadyToBoot (\r
34 IN EFI_EVENT Event,\r
35 IN VOID *Context\r
36 )\r
37{\r
8a8c6c96 38 EFI_STATUS Status;\r
504dfa9d 39 UINTN DataSize;\r
40 \r
41 if (MOR_CLEAR_MEMORY_VALUE (mMorControl) == 0x0) {\r
42 //\r
43 // MorControl is expected, directly return to avoid unnecessary variable operation\r
44 //\r
45 return ;\r
46 }\r
47 //\r
48 // Clear MOR_CLEAR_MEMORY_BIT\r
49 //\r
50 DEBUG ((EFI_D_INFO, "TcgMor: Clear MorClearMemory bit\n"));\r
51 mMorControl &= 0xFE; \r
52\r
53 DataSize = sizeof (mMorControl);\r
8a8c6c96
DG
54 Status = gRT->SetVariable (\r
55 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
56 &gEfiMemoryOverwriteControlDataGuid, \r
57 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
58 DataSize, \r
59 &mMorControl\r
60 );\r
61 if (EFI_ERROR (Status)) {\r
62 DEBUG ((EFI_D_ERROR, "TcgMor: Clear MOR_CLEAR_MEMORY_BIT failure, Status = %r\n"));\r
63 }\r
504dfa9d 64}\r
65\r
66\r
0c18794e 67/**\r
68 Entry Point for TCG MOR Control driver.\r
69\r
70 @param[in] ImageHandle Image handle of this driver.\r
71 @param[in] SystemTable A Pointer to the EFI System Table.\r
72\r
73 @retval EFI_SUCEESS \r
74 @return Others Some error occurs.\r
75**/\r
76EFI_STATUS\r
77EFIAPI\r
78MorDriverEntryPoint (\r
79 IN EFI_HANDLE ImageHandle,\r
80 IN EFI_SYSTEM_TABLE *SystemTable\r
81 )\r
82{\r
83 EFI_STATUS Status;\r
0c18794e 84 UINTN DataSize;\r
504dfa9d 85 EFI_EVENT Event;\r
0c18794e 86\r
87 ///\r
88 /// The firmware is required to create the MemoryOverwriteRequestControl UEFI variable.\r
89 ///\r
90\r
504dfa9d 91 DataSize = sizeof (mMorControl);\r
0c18794e 92 Status = gRT->GetVariable (\r
93 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
94 &gEfiMemoryOverwriteControlDataGuid, \r
95 NULL, \r
96 &DataSize, \r
504dfa9d 97 &mMorControl\r
0c18794e 98 );\r
99 if (EFI_ERROR (Status)) {\r
100 //\r
101 // Set default value to 0\r
102 //\r
504dfa9d 103 mMorControl = 0;\r
504dfa9d 104 Status = gRT->SetVariable (\r
105 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
106 &gEfiMemoryOverwriteControlDataGuid, \r
107 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
108 DataSize, \r
109 &mMorControl\r
110 );\r
8a8c6c96 111 DEBUG ((EFI_D_INFO, "TcgMor: Create MOR variable! Status = %r\n", Status));\r
0c18794e 112 } else {\r
0c18794e 113 //\r
504dfa9d 114 // Create a Ready To Boot Event and Clear the MorControl bit in the call back function.\r
0c18794e 115 //\r
504dfa9d 116 DEBUG ((EFI_D_INFO, "TcgMor: Create ReadyToBoot Event for MorControl Bit cleanning!\n"));\r
117 Status = EfiCreateEventReadyToBootEx (\r
118 TPL_CALLBACK,\r
119 OnReadyToBoot,\r
120 NULL,\r
121 &Event\r
122 );\r
123 } \r
0c18794e 124 \r
0c18794e 125 return Status;\r
126}\r
127\r
128\r