2 It updates TPM items in ACPI table and registers SMI callback
3 functions for physical presence and ClearMemory.
5 Copyright (c) 2011 - 2012, 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 EFI_SMM_VARIABLE_PROTOCOL
*mSmmVariable
;
22 Software SMI callback for TPM physical presence which is called from ACPI method.
24 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
25 @param[in] Context Points to an optional handler context which was specified when the
26 handler was registered.
27 @param[in, out] CommBuffer A pointer to a collection of data in memory that will
28 be conveyed from a non-SMM environment into an SMM environment.
29 @param[in, out] CommBufferSize The size of the CommBuffer.
31 @retval EFI_SUCCESS The interrupt was handled successfully.
36 PhysicalPresenceCallback (
37 IN EFI_HANDLE DispatchHandle
,
38 IN CONST VOID
*Context
,
39 IN OUT VOID
*CommBuffer
,
40 IN OUT UINTN
*CommBufferSize
45 EFI_PHYSICAL_PRESENCE PpData
;
47 BOOLEAN RequestConfirmed
;
50 // Get the Physical Presence variable
52 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
53 Status
= mSmmVariable
->SmmGetVariable (
54 PHYSICAL_PRESENCE_VARIABLE
,
55 &gEfiPhysicalPresenceGuid
,
60 if (EFI_ERROR (Status
)) {
64 DEBUG ((EFI_D_INFO
, "[TPM] PP callback, Parameter = %x\n", mTcgNvs
->PhysicalPresence
.Parameter
));
65 if (mTcgNvs
->PhysicalPresence
.Parameter
== ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS
) {
66 mTcgNvs
->PhysicalPresence
.LastRequest
= PpData
.LastPPRequest
;
67 mTcgNvs
->PhysicalPresence
.Response
= PpData
.PPResponse
;
68 } else if ((mTcgNvs
->PhysicalPresence
.Parameter
== ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS
)
69 || (mTcgNvs
->PhysicalPresence
.Parameter
== ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2
)) {
70 if (mTcgNvs
->PhysicalPresence
.Request
== PHYSICAL_PRESENCE_SET_OPERATOR_AUTH
) {
72 // This command requires UI to prompt user for Auth data.
74 mTcgNvs
->PhysicalPresence
.ReturnCode
= PP_SUBMIT_REQUEST_NOT_IMPLEMENTED
;
78 if (PpData
.PPRequest
!= mTcgNvs
->PhysicalPresence
.Request
) {
79 PpData
.PPRequest
= (UINT8
) mTcgNvs
->PhysicalPresence
.Request
;
80 DataSize
= sizeof (EFI_PHYSICAL_PRESENCE
);
81 Status
= mSmmVariable
->SmmSetVariable (
82 PHYSICAL_PRESENCE_VARIABLE
,
83 &gEfiPhysicalPresenceGuid
,
84 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
90 if (EFI_ERROR (Status
)) {
91 mTcgNvs
->PhysicalPresence
.ReturnCode
= PP_SUBMIT_REQUEST_GENERAL_FAILURE
;
94 mTcgNvs
->PhysicalPresence
.ReturnCode
= PP_SUBMIT_REQUEST_SUCCESS
;
95 } else if (mTcgNvs
->PhysicalPresence
.Parameter
== ACPI_FUNCTION_GET_USER_CONFIRMATION_STATUS_FOR_REQUEST
) {
97 RequestConfirmed
= FALSE
;
99 switch (mTcgNvs
->PhysicalPresence
.Request
) {
100 case PHYSICAL_PRESENCE_ENABLE
:
101 case PHYSICAL_PRESENCE_DISABLE
:
102 case PHYSICAL_PRESENCE_ACTIVATE
:
103 case PHYSICAL_PRESENCE_DEACTIVATE
:
104 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE
:
105 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE
:
106 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE
:
107 case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE
:
108 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE
:
109 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE
:
110 if ((Flags
& FLAG_NO_PPI_PROVISION
) != 0) {
111 RequestConfirmed
= TRUE
;
115 case PHYSICAL_PRESENCE_CLEAR
:
116 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR
:
117 if ((Flags
& FLAG_NO_PPI_CLEAR
) != 0) {
118 RequestConfirmed
= TRUE
;
122 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE
:
123 if ((Flags
& FLAG_NO_PPI_MAINTENANCE
) != 0) {
124 RequestConfirmed
= TRUE
;
128 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE
:
129 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE
:
130 if ((Flags
& FLAG_NO_PPI_CLEAR
) != 0 && (Flags
& FLAG_NO_PPI_PROVISION
) != 0) {
131 RequestConfirmed
= TRUE
;
135 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE
:
136 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE
:
137 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE
:
138 case PHYSICAL_PRESENCE_NO_ACTION
:
139 RequestConfirmed
= TRUE
;
142 case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH
:
144 // This command requires UI to prompt user for Auth data
146 mTcgNvs
->PhysicalPresence
.ReturnCode
= PP_REQUEST_NOT_IMPLEMENTED
;
150 if (RequestConfirmed
) {
151 mTcgNvs
->PhysicalPresence
.ReturnCode
= PP_REQUEST_ALLOWED_AND_PPUSER_NOT_REQUIRED
;
153 mTcgNvs
->PhysicalPresence
.ReturnCode
= PP_REQUEST_ALLOWED_AND_PPUSER_REQUIRED
;
162 Software SMI callback for MemoryClear which is called from ACPI method.
164 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
165 @param[in] Context Points to an optional handler context which was specified when the
166 handler was registered.
167 @param[in, out] CommBuffer A pointer to a collection of data in memory that will
168 be conveyed from a non-SMM environment into an SMM environment.
169 @param[in, out] CommBufferSize The size of the CommBuffer.
171 @retval EFI_SUCCESS The interrupt was handled successfully.
176 MemoryClearCallback (
177 IN EFI_HANDLE DispatchHandle
,
178 IN CONST VOID
*Context
,
179 IN OUT VOID
*CommBuffer
,
180 IN OUT UINTN
*CommBufferSize
187 mTcgNvs
->MemoryClear
.ReturnCode
= MOR_REQUEST_SUCCESS
;
188 if (mTcgNvs
->MemoryClear
.Parameter
== ACPI_FUNCTION_DSM_MEMORY_CLEAR_INTERFACE
) {
189 MorControl
= (UINT8
) mTcgNvs
->MemoryClear
.Request
;
190 } else if (mTcgNvs
->MemoryClear
.Parameter
== ACPI_FUNCTION_PTS_CLEAR_MOR_BIT
) {
191 DataSize
= sizeof (UINT8
);
192 Status
= mSmmVariable
->SmmGetVariable (
193 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
194 &gEfiMemoryOverwriteControlDataGuid
,
199 if (EFI_ERROR (Status
)) {
203 if (MOR_CLEAR_MEMORY_VALUE (MorControl
) == 0x0) {
206 MorControl
&= ~MOR_CLEAR_MEMORY_BIT_MASK
;
209 DataSize
= sizeof (UINT8
);
210 Status
= mSmmVariable
->SmmSetVariable (
211 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
,
212 &gEfiMemoryOverwriteControlDataGuid
,
213 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
217 if (EFI_ERROR (Status
)) {
218 mTcgNvs
->MemoryClear
.ReturnCode
= MOR_REQUEST_GENERAL_FAILURE
;
225 Find the operation region in TCG ACPI table by given Name and Size,
226 and initialize it if the region is found.
228 @param[in, out] Table The TPM item in ACPI table.
229 @param[in] Name The name string to find in TPM table.
230 @param[in] Size The size of the region to find.
232 @return The allocated address for the found region.
237 EFI_ACPI_DESCRIPTION_HEADER
*Table
,
243 AML_OP_REGION_32_8
*OpRegion
;
244 EFI_PHYSICAL_ADDRESS MemoryAddress
;
246 MemoryAddress
= SIZE_4GB
- 1;
249 // Patch some pointers for the ASL code before loading the SSDT.
251 for (OpRegion
= (AML_OP_REGION_32_8
*) (Table
+ 1);
252 OpRegion
<= (AML_OP_REGION_32_8
*) ((UINT8
*) Table
+ Table
->Length
);
253 OpRegion
= (AML_OP_REGION_32_8
*) ((UINT8
*) OpRegion
+ 1)) {
254 if ((OpRegion
->OpRegionOp
== AML_EXT_REGION_OP
) &&
255 (OpRegion
->NameString
== Name
) &&
256 (OpRegion
->DWordPrefix
== AML_DWORD_PREFIX
) &&
257 (OpRegion
->BytePrefix
== AML_BYTE_PREFIX
)) {
259 Status
= gBS
->AllocatePages(AllocateMaxAddress
, EfiACPIMemoryNVS
, EFI_SIZE_TO_PAGES (Size
), &MemoryAddress
);
260 ASSERT_EFI_ERROR (Status
);
261 ZeroMem ((VOID
*)(UINTN
)MemoryAddress
, Size
);
262 OpRegion
->RegionOffset
= (UINT32
) (UINTN
) MemoryAddress
;
263 OpRegion
->RegionLen
= (UINT8
) Size
;
268 return (VOID
*) (UINTN
) MemoryAddress
;
272 Initialize and publish TPM items in ACPI table.
274 @retval EFI_SUCCESS The TCG ACPI table is published successfully.
275 @retval Others The TCG ACPI table is not published.
284 EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
;
286 EFI_ACPI_DESCRIPTION_HEADER
*Table
;
289 Status
= GetSectionFromFv (
296 ASSERT_EFI_ERROR (Status
);
298 ASSERT (Table
->OemTableId
== SIGNATURE_64 ('T', 'c', 'g', 'T', 'a', 'b', 'l', 'e'));
299 mTcgNvs
= AssignOpRegion (Table
, SIGNATURE_32 ('T', 'N', 'V', 'S'), (UINT16
) sizeof (TCG_NVS
));
300 ASSERT (mTcgNvs
!= NULL
);
303 // Publish the TPM ACPI table
305 Status
= gBS
->LocateProtocol (&gEfiAcpiTableProtocolGuid
, NULL
, (VOID
**) &AcpiTable
);
306 ASSERT_EFI_ERROR (Status
);
309 Status
= AcpiTable
->InstallAcpiTable (
315 ASSERT_EFI_ERROR (Status
);
321 The driver's entry point.
323 It install callbacks for TPM physical presence and MemoryClear, and locate
324 SMM variable to be used in the callback function.
326 @param[in] ImageHandle The firmware allocated handle for the EFI image.
327 @param[in] SystemTable A pointer to the EFI System Table.
329 @retval EFI_SUCCESS The entry point is executed successfully.
330 @retval Others Some error occurs when executing this entry point.
336 IN EFI_HANDLE ImageHandle
,
337 IN EFI_SYSTEM_TABLE
*SystemTable
341 EFI_SMM_SW_DISPATCH2_PROTOCOL
*SwDispatch
;
342 EFI_SMM_SW_REGISTER_CONTEXT SwContext
;
345 Status
= PublishAcpiTable ();
346 ASSERT_EFI_ERROR (Status
);
349 // Get the Sw dispatch protocol and register SMI callback functions.
351 Status
= gSmst
->SmmLocateProtocol (&gEfiSmmSwDispatch2ProtocolGuid
, NULL
, (VOID
**)&SwDispatch
);
352 ASSERT_EFI_ERROR (Status
);
353 SwContext
.SwSmiInputValue
= (UINTN
) -1;
354 Status
= SwDispatch
->Register (SwDispatch
, PhysicalPresenceCallback
, &SwContext
, &SwHandle
);
355 ASSERT_EFI_ERROR (Status
);
356 if (EFI_ERROR (Status
)) {
359 mTcgNvs
->PhysicalPresence
.SoftwareSmi
= (UINT8
) SwContext
.SwSmiInputValue
;
361 SwContext
.SwSmiInputValue
= (UINTN
) -1;
362 Status
= SwDispatch
->Register (SwDispatch
, MemoryClearCallback
, &SwContext
, &SwHandle
);
363 ASSERT_EFI_ERROR (Status
);
364 if (EFI_ERROR (Status
)) {
367 mTcgNvs
->MemoryClear
.SoftwareSmi
= (UINT8
) SwContext
.SwSmiInputValue
;
370 // Locate SmmVariableProtocol.
372 Status
= gSmst
->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**)&mSmmVariable
);
373 ASSERT_EFI_ERROR (Status
);