2 It updates TPM items in ACPI table and registers SMI callback
3 functions for physical presence and ClearMemory.
5 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <IndustryStandard/Acpi.h>
19 #include <Guid/PhysicalPresenceData.h>
20 #include <Guid/MemoryOverwriteControl.h>
21 #include <Protocol/SmmSwDispatch2.h>
22 #include <Protocol/AcpiTable.h>
23 #include <Protocol/SmmVariable.h>
25 #include <Library/BaseLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/SmmServicesTableLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/DxeServicesLib.h>
41 } PHYSICAL_PRESENCE_NVS
;
50 PHYSICAL_PRESENCE_NVS PhysicalPresence
;
51 MEMORY_CLEAR_NVS MemoryClear
;
65 EFI_SMM_VARIABLE_PROTOCOL
*mSmmVariable
;
69 Software SMI callback for TPM physical presence which is called from ACPI method.
71 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
72 @param[in] Context Points to an optional handler context which was specified when the
73 handler was registered.
74 @param[in, out] CommBuffer A pointer to a collection of data in memory that will
75 be conveyed from a non-SMM environment into an SMM environment.
76 @param[in, out] CommBufferSize The size of the CommBuffer.
78 @retval EFI_SUCCESS The interrupt was handled successfully.
83 PhysicalPresenceCallback (
84 IN EFI_HANDLE DispatchHandle
,
85 IN CONST VOID
*Context
,
86 IN OUT VOID
*CommBuffer
,
87 IN OUT UINTN
*CommBufferSize
92 EFI_PHYSICAL_PRESENCE PpData
;
94 BOOLEAN RequestConfirmed
;
97 // Get the Physical Presence variable
99 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
100 Status
= mSmmVariable
->SmmGetVariable (
101 PHYSICAL_PRESENCE_VARIABLE
,
102 &gEfiPhysicalPresenceGuid
,
107 if (EFI_ERROR (Status
)) {
111 DEBUG ((EFI_D_INFO
, "[TPM] PP callback, Parameter = %x\n", mTcgNvs
->PhysicalPresence
.Parameter
));
112 if (mTcgNvs
->PhysicalPresence
.Parameter
== 5) {
114 // Return TPM Operation Response to OS Environment
116 mTcgNvs
->PhysicalPresence
.LastRequest
= PpData
.LastPPRequest
;
117 mTcgNvs
->PhysicalPresence
.Response
= PpData
.PPResponse
;
119 } else if ((mTcgNvs
->PhysicalPresence
.Parameter
== 2) || (mTcgNvs
->PhysicalPresence
.Parameter
== 7)) {
121 // Submit TPM Operation Request to Pre-OS Environment
124 if (mTcgNvs
->PhysicalPresence
.Request
== PHYSICAL_PRESENCE_SET_OPERATOR_AUTH
) {
126 // This command requires UI to prompt user for Auth data, NOT implemented.
128 mTcgNvs
->PhysicalPresence
.ReturnCode
= 1;
132 if (PpData
.PPRequest
!= mTcgNvs
->PhysicalPresence
.Request
) {
133 PpData
.PPRequest
= (UINT8
) mTcgNvs
->PhysicalPresence
.Request
;
134 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
135 Status
= mSmmVariable
->SmmSetVariable (
136 PHYSICAL_PRESENCE_VARIABLE
,
137 &gEfiPhysicalPresenceGuid
,
138 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
144 if (EFI_ERROR (Status
)) {
148 mTcgNvs
->PhysicalPresence
.ReturnCode
= 2;
151 mTcgNvs
->PhysicalPresence
.ReturnCode
= 0;
152 } else if (mTcgNvs
->PhysicalPresence
.Parameter
== 8) {
154 // Get User Confirmation Status for Operation
156 Flags
= PpData
.Flags
;
157 RequestConfirmed
= FALSE
;
159 switch (mTcgNvs
->PhysicalPresence
.Request
) {
160 case PHYSICAL_PRESENCE_ENABLE
:
161 case PHYSICAL_PRESENCE_DISABLE
:
162 case PHYSICAL_PRESENCE_ACTIVATE
:
163 case PHYSICAL_PRESENCE_DEACTIVATE
:
164 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE
:
165 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE
:
166 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE
:
167 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE
:
168 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE
:
169 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE
:
170 if ((Flags
& FLAG_NO_PPI_PROVISION
) != 0) {
171 RequestConfirmed
= TRUE
;
175 case PHYSICAL_PRESENCE_CLEAR
:
176 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR
:
177 if ((Flags
& FLAG_NO_PPI_CLEAR
) != 0) {
178 RequestConfirmed
= TRUE
;
182 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE
:
183 if ((Flags
& FLAG_NO_PPI_MAINTENANCE
) != 0) {
184 RequestConfirmed
= TRUE
;
188 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE
:
189 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE
:
190 if ((Flags
& FLAG_NO_PPI_CLEAR
) != 0 && (Flags
& FLAG_NO_PPI_PROVISION
) != 0) {
191 RequestConfirmed
= TRUE
;
195 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE
:
196 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE
:
197 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE
:
198 case PHYSICAL_PRESENCE_NO_ACTION
:
199 RequestConfirmed
= TRUE
;
202 case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH
:
204 // This command requires UI to prompt user for Auth data
205 // Here it is NOT implemented
207 mTcgNvs
->PhysicalPresence
.ReturnCode
= 0;
211 if (RequestConfirmed
) {
213 // Allowed and physically present user not required
215 mTcgNvs
->PhysicalPresence
.ReturnCode
= 4;
218 // Allowed and physically present user required
220 mTcgNvs
->PhysicalPresence
.ReturnCode
= 3;
229 Software SMI callback for MemoryClear which is called from ACPI method.
231 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
232 @param[in] Context Points to an optional handler context which was specified when the
233 handler was registered.
234 @param[in, out] CommBuffer A pointer to a collection of data in memory that will
235 be conveyed from a non-SMM environment into an SMM environment.
236 @param[in, out] CommBufferSize The size of the CommBuffer.
238 @retval EFI_SUCCESS The interrupt was handled successfully.
243 MemoryClearCallback (
244 IN EFI_HANDLE DispatchHandle
,
245 IN CONST VOID
*Context
,
246 IN OUT VOID
*CommBuffer
,
247 IN OUT UINTN
*CommBufferSize
254 if (mTcgNvs
->MemoryClear
.Parameter
== 1) {
256 // Called from ACPI _DSM method, save the MOR data to variable.
258 MorControl
= (UINT8
) mTcgNvs
->MemoryClear
.Request
;
259 } else if (mTcgNvs
->MemoryClear
.Parameter
== 2) {
261 // Called from ACPI _PTS method, setup ClearMemory flags if needed.
263 DataSize
= sizeof (UINT8
);
264 Status
= mSmmVariable
->SmmGetVariable (
265 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
266 &gEfiMemoryOverwriteControlDataGuid
,
271 if (EFI_ERROR (Status
)) {
272 ASSERT (Status
== EFI_NOT_FOUND
);
276 if (MOR_CLEAR_MEMORY_VALUE (MorControl
) == 0x0) {
279 MorControl
&= ~MOR_CLEAR_MEMORY_BIT_MASK
;
282 DataSize
= sizeof (UINT8
);
283 Status
= mSmmVariable
->SmmSetVariable (
284 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
285 &gEfiMemoryOverwriteControlDataGuid
,
286 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
290 ASSERT_EFI_ERROR (Status
);
296 Find the operation region in TCG ACPI table by given Name and Size,
297 and initialize it if the region is found.
299 @param[in, out] Table The TPM item in ACPI table.
300 @param[in] Name The name string to find in TPM table.
301 @param[in] Size The size of the region to find.
303 @return The allocated address for the found region.
308 EFI_ACPI_DESCRIPTION_HEADER
*Table
,
314 AML_OP_REGION_32_8
*OpRegion
;
315 EFI_PHYSICAL_ADDRESS MemoryAddress
;
317 MemoryAddress
= SIZE_4GB
- 1;
320 // Patch some pointers for the ASL code before loading the SSDT.
322 for (OpRegion
= (AML_OP_REGION_32_8
*) (Table
+ 1);
323 OpRegion
<= (AML_OP_REGION_32_8
*) ((UINT8
*) Table
+ Table
->Length
);
324 OpRegion
= (AML_OP_REGION_32_8
*) ((UINT8
*) OpRegion
+ 1)) {
325 if ((OpRegion
->OpRegionOp
== AML_EXT_REGION_OP
) &&
326 (OpRegion
->NameString
== Name
) &&
327 (OpRegion
->RegionLen
== Size
) &&
328 (OpRegion
->DWordPrefix
== AML_DWORD_PREFIX
) &&
329 (OpRegion
->BytePrefix
== AML_BYTE_PREFIX
)) {
331 Status
= gBS
->AllocatePages(AllocateMaxAddress
, EfiACPIMemoryNVS
, EFI_SIZE_TO_PAGES (Size
), &MemoryAddress
);
332 ASSERT_EFI_ERROR (Status
);
333 ZeroMem ((VOID
*)(UINTN
)MemoryAddress
, Size
);
334 OpRegion
->RegionOffset
= (UINT32
) (UINTN
) MemoryAddress
;
339 return (VOID
*) (UINTN
) MemoryAddress
;
343 Initialize and publish TPM items in ACPI table.
345 @retval EFI_SUCCESS The TCG ACPI table is published successfully.
346 @retval Others The TCG ACPI table is not published.
355 EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
;
357 EFI_ACPI_DESCRIPTION_HEADER
*Table
;
360 Status
= GetSectionFromFv (
367 ASSERT_EFI_ERROR (Status
);
369 ASSERT (Table
->OemTableId
== SIGNATURE_64 ('T', 'c', 'g', 'T', 'a', 'b', 'l', 'e'));
370 mTcgNvs
= AssignOpRegion (Table
, SIGNATURE_32 ('T', 'N', 'V', 'S'), (UINT16
) sizeof (TCG_NVS
));
371 ASSERT (mTcgNvs
!= NULL
);
374 // Publish the TPM ACPI table
376 Status
= gBS
->LocateProtocol (&gEfiAcpiTableProtocolGuid
, NULL
, (VOID
**) &AcpiTable
);
377 ASSERT_EFI_ERROR (Status
);
380 Status
= AcpiTable
->InstallAcpiTable (
386 ASSERT_EFI_ERROR (Status
);
392 The driver's entry point.
394 It install callbacks for TPM physical presence and MemoryClear, and locate
395 SMM variable to be used in the callback function.
397 @param[in] ImageHandle The firmware allocated handle for the EFI image.
398 @param[in] SystemTable A pointer to the EFI System Table.
400 @retval EFI_SUCCESS The entry point is executed successfully.
401 @retval Others Some error occurs when executing this entry point.
407 IN EFI_HANDLE ImageHandle
,
408 IN EFI_SYSTEM_TABLE
*SystemTable
412 EFI_SMM_SW_DISPATCH2_PROTOCOL
*SwDispatch
;
413 EFI_SMM_SW_REGISTER_CONTEXT SwContext
;
416 Status
= PublishAcpiTable ();
417 ASSERT_EFI_ERROR (Status
);
420 // Get the Sw dispatch protocol and register SMI callback functions.
422 Status
= gSmst
->SmmLocateProtocol (&gEfiSmmSwDispatch2ProtocolGuid
, NULL
, (VOID
**)&SwDispatch
);
423 ASSERT_EFI_ERROR (Status
);
424 SwContext
.SwSmiInputValue
= (UINTN
) -1;
425 Status
= SwDispatch
->Register (SwDispatch
, PhysicalPresenceCallback
, &SwContext
, &SwHandle
);
426 ASSERT_EFI_ERROR (Status
);
427 if (EFI_ERROR (Status
)) {
430 mTcgNvs
->PhysicalPresence
.SoftwareSmi
= (UINT8
) SwContext
.SwSmiInputValue
;
432 SwContext
.SwSmiInputValue
= (UINTN
) -1;
433 Status
= SwDispatch
->Register (SwDispatch
, MemoryClearCallback
, &SwContext
, &SwHandle
);
434 ASSERT_EFI_ERROR (Status
);
435 if (EFI_ERROR (Status
)) {
438 mTcgNvs
->MemoryClear
.SoftwareSmi
= (UINT8
) SwContext
.SwSmiInputValue
;
441 // Locate SmmVariableProtocol.
443 Status
= gSmst
->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**)&mSmmVariable
);
444 ASSERT_EFI_ERROR (Status
);