]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.c
Add Tper Reset Logic by using MOR bit.
[mirror_edk2.git] / SecurityPkg / Tcg / MemoryOverwriteControl / TcgMor.c
... / ...
CommitLineData
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
7Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
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
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
38 UINTN DataSize;\r
39 \r
40 if (MOR_CLEAR_MEMORY_VALUE (mMorControl) == 0x0) {\r
41 //\r
42 // MorControl is expected, directly return to avoid unnecessary variable operation\r
43 //\r
44 return ;\r
45 }\r
46 //\r
47 // Clear MOR_CLEAR_MEMORY_BIT\r
48 //\r
49 DEBUG ((EFI_D_INFO, "TcgMor: Clear MorClearMemory bit\n"));\r
50 mMorControl &= 0xFE; \r
51\r
52 DataSize = sizeof (mMorControl);\r
53 gRT->SetVariable (\r
54 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
55 &gEfiMemoryOverwriteControlDataGuid, \r
56 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
57 DataSize, \r
58 &mMorControl\r
59 );\r
60\r
61}\r
62\r
63\r
64/**\r
65 Entry Point for TCG MOR Control driver.\r
66\r
67 @param[in] ImageHandle Image handle of this driver.\r
68 @param[in] SystemTable A Pointer to the EFI System Table.\r
69\r
70 @retval EFI_SUCEESS \r
71 @return Others Some error occurs.\r
72**/\r
73EFI_STATUS\r
74EFIAPI\r
75MorDriverEntryPoint (\r
76 IN EFI_HANDLE ImageHandle,\r
77 IN EFI_SYSTEM_TABLE *SystemTable\r
78 )\r
79{\r
80 EFI_STATUS Status;\r
81 UINTN DataSize;\r
82 EFI_EVENT Event;\r
83\r
84 ///\r
85 /// The firmware is required to create the MemoryOverwriteRequestControl UEFI variable.\r
86 ///\r
87\r
88 DataSize = sizeof (mMorControl);\r
89 Status = gRT->GetVariable (\r
90 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
91 &gEfiMemoryOverwriteControlDataGuid, \r
92 NULL, \r
93 &DataSize, \r
94 &mMorControl\r
95 );\r
96 if (EFI_ERROR (Status)) {\r
97 //\r
98 // Set default value to 0\r
99 //\r
100 mMorControl = 0;\r
101 DEBUG ((EFI_D_INFO, "TcgMor: Create gEfiMemoryOverwriteControlDataGuid!\n"));\r
102 Status = gRT->SetVariable (\r
103 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, \r
104 &gEfiMemoryOverwriteControlDataGuid, \r
105 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
106 DataSize, \r
107 &mMorControl\r
108 );\r
109 ASSERT_EFI_ERROR (Status);\r
110 \r
111 } else {\r
112 //\r
113 // Create a Ready To Boot Event and Clear the MorControl bit in the call back function.\r
114 //\r
115 DEBUG ((EFI_D_INFO, "TcgMor: Create ReadyToBoot Event for MorControl Bit cleanning!\n"));\r
116 Status = EfiCreateEventReadyToBootEx (\r
117 TPL_CALLBACK,\r
118 OnReadyToBoot,\r
119 NULL,\r
120 &Event\r
121 );\r
122 } \r
123 \r
124 return Status;\r
125}\r
126\r
127\r