Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Maintainers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,11 @@ F: SecurityPkg/Library/Tpm2DeviceLibDTpm/*Svsm*
R: Oliver Steffen <osteffen@redhat.com> [osteffenrh]
R: Tom Lendacky <thomas.lendacky@amd.com> [tlendacky]

SecurityPkg: ARM-FFA related modules
F: SecurityPkg/*Arm
F: SecurityPkg/*Ffa
R: Kun Qin <kun.qin@microsoft.com> [kuqin12]

ShellPkg
F: ShellPkg/
W: https://github.com/tianocore/tianocore.github.io/wiki/ShellPkg
Expand Down
6 changes: 6 additions & 0 deletions SecurityPkg/Include/Guid/PhysicalPresenceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
0xf6499b1, 0xe9ad, 0x493d, { 0xb9, 0xc2, 0x2f, 0x90, 0x81, 0x5c, 0x6c, 0xbc }\
}

#define EFI_PHYSICAL_PRESENCE_ACPI_GUID \
{ \
0x3DDDFAA6, 0x361B, 0x4eb4, { 0xA4, 0x24, 0x8D, 0x10, 0x08, 0x9D, 0x16, 0x53 }\
}

#define PHYSICAL_PRESENCE_VARIABLE L"PhysicalPresence"

typedef struct {
Expand Down Expand Up @@ -70,5 +75,6 @@ typedef struct {
#define FLAG_RESET_TRACK BIT3

extern EFI_GUID gEfiPhysicalPresenceGuid;
extern EFI_GUID gEfiPhysicalPresenceAcpiGuid;

#endif
43 changes: 43 additions & 0 deletions SecurityPkg/Include/Guid/Tpm2ServiceFfa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/** @file
Provides function interfaces to communicate with TPM 2.0 service through FF-A.

This header follows the TPM over FF-A specification:
https://developer.arm.com/documentation/den0138/latest/

Copyright (c), Microsoft Corporation.

SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef TPM2_SERVICE_FFA_H_
#define TPM2_SERVICE_FFA_H_

#define TPM2_SERVICE_FFA_GUID \
{ 0x17b862a4, 0x1806, 0x4faf, { 0x86, 0xb3, 0x08, 0x9a, 0x58, 0x35, 0x38, 0x61 } }

#define TPM2_FFA_GET_INTERFACE_VERSION 0x0f000001
#define TPM2_FFA_GET_FEATURE_INFO 0x0f000101
#define TPM2_FFA_START 0x0f000201
#define TPM2_FFA_REGISTER_FOR_NOTIFICATION 0x0f000301
#define TPM2_FFA_UNREGISTER_FROM_NOTIFICATION 0x0f000401
#define TPM2_FFA_FINISH_NOTIFIED 0x0f000501

#define TPM2_FFA_SUCCESS_OK 0x05000001
#define TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED 0x05000002

#define TPM2_FFA_ERROR_NOFUNC 0x8e000001
#define TPM2_FFA_ERROR_NOTSUP 0x8e000002
#define TPM2_FFA_ERROR_INVARG 0x8e000005
#define TPM2_FFA_ERROR_INV_CRB_CTRL_DATA 0x8e000006
#define TPM2_FFA_ERROR_ALREADY 0x8e000009
#define TPM2_FFA_ERROR_DENIED 0x8e00000a
#define TPM2_FFA_ERROR_NOMEM 0x8e00000b

#define TPM_SERVICE_FEATURE_SUPPORT_NOTIFICATION 0xfea70000

#define TPM2_FFA_START_FUNC_QUALIFIER_COMMAND 0x0
#define TPM2_FFA_START_FUNC_QUALIFIER_LOCALITY 0x1

extern EFI_GUID gTpm2ServiceFfaGuid;

#endif /* TPM2_SERVICE_FFA_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@
#

[Sources]
StandaloneMmTcg2PhysicalPresenceLib.c
MmTcg2PhysicalPresenceLibCommon.c
MmTcg2PhysicalPresenceLibCommon.h

[Sources.IA32, Sources.X64]
StandaloneMmTcg2PhysicalPresenceLib.c

[Sources.ARM, Sources.AARCH64]
StandaloneMmTcg2PhysicalPresenceLibArm.c

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
Expand All @@ -59,5 +64,8 @@
[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTcg2PhysicalPresenceFlags ## SOMETIMES_CONSUMES

[Pcd.ARM, Pcd.AARCH64]
gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer

[Depex]
gEfiSmmVariableProtocolGuid
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/** @file
Handle TPM 2.0 physical presence requests from OS.

This library will handle TPM 2.0 physical presence request from OS.

Caution: This module requires additional review when modified.
This driver will have external input - variable.
This external input must be validated carefully to avoid security issue.

Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
will receive untrusted input and do validation.

Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <PiMm.h>

#include <Library/PcdLib.h>

#include "MmTcg2PhysicalPresenceLibCommon.h"

/**
The constructor function locates SmmVariable protocol.

It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.

@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.

@retval EFI_SUCCESS The constructor successfully added string package.
@retval Other value The constructor can't add string package.
**/
EFI_STATUS
EFIAPI
Tcg2PhysicalPresenceLibStandaloneMmConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_MM_SYSTEM_TABLE *SystemTable
)
{
return Tcg2PhysicalPresenceLibCommonConstructor ();
}

/**
Check if Tcg2 PP version is lower than PP_INF_VERSION_1_3.

@retval TRUE Tcg2 PP version is lower than PP_INF_VERSION_1_3.
@retval Other Tcg2 PP version is not lower than PP_INF_VERSION_1_3.
**/
BOOLEAN
IsTcg2PPVerLowerThan_1_3 (
VOID
)
{
if (PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer) == NULL) {
return TRUE;
}

if (AsciiStrnCmp (PP_INF_VERSION_1_2, (CHAR8 *)PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer), sizeof (PP_INF_VERSION_1_2) - 1) >= 0) {
return TRUE;
}

return FALSE;
}
90 changes: 90 additions & 0 deletions SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/** @file
This library provides an implementation of Tpm2DeviceLib
using ARM64 SMC calls to request TPM service.

The implementation is only supporting the Command Response Buffer (CRB)
for sharing data with the TPM.

Copyright (c), Microsoft Corporation.

SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <Library/BaseLib.h>
#include <Library/Tpm2DeviceLib.h>
#include <IndustryStandard/Tpm20.h>

#include "Tpm2DeviceLibFfa.h"

/**
Send a command to TPM for execution and return response data.
Used during boot only.

@retval EFI_SUCCESS Command was successfully sent to the TPM
and the response was copied to the Output buffer.
@retval Other Some error occurred in communication with the TPM.
**/
EFI_STATUS
EFIAPI
Tpm2SubmitCommand (
IN UINT32 InputParameterBlockSize,
IN UINT8 *InputParameterBlock,
IN OUT UINT32 *OutputParameterBlockSize,
IN UINT8 *OutputParameterBlock
)
{
return FfaTpm2SubmitCommand (
InputParameterBlockSize,
InputParameterBlock,
OutputParameterBlockSize,
OutputParameterBlock
);
}

/**
This service requests use TPM2.
Since every communication with the TPM is blocking
you are always good to start communicating with the TPM.

@retval EFI_SUCCESS Get the control of TPM2 chip.
**/
EFI_STATUS
EFIAPI
Tpm2RequestUseTpm (
VOID
)
{
return FfaTpm2RequestUseTpm ();
}

/**
This service register TPM2 device.

@param Tpm2Device TPM2 device

@retval EFI_UNSUPPORTED System does not support register this TPM2 device.
**/
EFI_STATUS
EFIAPI
Tpm2RegisterTpm2DeviceLib (
IN TPM2_DEVICE_INTERFACE *Tpm2Device
)
{
return EFI_UNSUPPORTED;
}

/**
Check that we have an address for the CRB

@retval EFI_SUCCESS The entry point is executed successfully.
@retval EFI_NO_MAPPING The TPM base address is not set up.
@retval EFI_UNSUPPORTED The TPM interface type is not supported.
**/
EFI_STATUS
EFIAPI
Tpm2DeviceLibFfaConstructor (
VOID
)
{
return InternalTpm2DeviceLibFfaConstructor ();
}
Loading
Loading