|
| 1 | +/** @file |
| 2 | + TPM2 table parser |
| 3 | +
|
| 4 | + Copyright (c) 2024, ARM Limited. All rights reserved. |
| 5 | + SPDX-License-Identifier: BSD-2-Clause-Patent |
| 6 | +
|
| 7 | + @par Reference(s): |
| 8 | + - TCG ACPI Specification - Version 1.4, Revision 15, April 3, 2024. |
| 9 | + (https://trustedcomputinggroup.org/resource/tcg-acpi-specification/) |
| 10 | +**/ |
| 11 | + |
| 12 | +#include <IndustryStandard/Acpi.h> |
| 13 | +#include <IndustryStandard/Tpm2Acpi.h> |
| 14 | +#include <Library/UefiLib.h> |
| 15 | +#include "AcpiParser.h" |
| 16 | +#include "AcpiTableParser.h" |
| 17 | + |
| 18 | +#define TPM2_ACPI_TABLE_LOG_AREA_SIZE (sizeof(UINT32) + sizeof(UINT64)) |
| 19 | + |
| 20 | +// Log area parameter offset is different on ACPI table revision 4 and 5, due to different SMSP max size. |
| 21 | +#define TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_4 (sizeof(EFI_TPM2_ACPI_TABLE) + EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4 + TPM2_ACPI_TABLE_LOG_AREA_SIZE) |
| 22 | +#define TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_5 (sizeof(EFI_TPM2_ACPI_TABLE) + EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5 + TPM2_ACPI_TABLE_LOG_AREA_SIZE) |
| 23 | + |
| 24 | +// Local variables |
| 25 | +STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; |
| 26 | +STATIC UINT32 *StartMethod; |
| 27 | + |
| 28 | +/** |
| 29 | + An ACPI_PARSER array describing the ACPI TPM 2.0 Table. |
| 30 | +**/ |
| 31 | +STATIC CONST ACPI_PARSER Tpm2Parser[] = { |
| 32 | + PARSE_ACPI_HEADER (&AcpiHdrInfo), |
| 33 | + { L"Platform Class", 2, 36, L"0x%x", NULL, NULL, NULL, NULL }, |
| 34 | + { L"Reserved", 2, 38, L"0x%x", NULL, NULL, NULL, NULL }, |
| 35 | + { L"Address of CRB Control Area",8, 40, L"0x%lx", NULL, NULL, NULL, NULL }, |
| 36 | + { L"Start Method", 4, 48, L"0x%x", NULL, (VOID **)&StartMethod, NULL, NULL } |
| 37 | +}; |
| 38 | + |
| 39 | +/** |
| 40 | + An ACPI_PARSER array describing the ACPI TPM 2.0 Table Log Area entries. |
| 41 | +**/ |
| 42 | +STATIC CONST ACPI_PARSER Tpm2LogArea[] = { |
| 43 | + { L"Log Area Minimum Length", 4, 0, L"0x%x", NULL, NULL, NULL, NULL }, |
| 44 | + { L"Log Area Start Address", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL } |
| 45 | +}; |
| 46 | + |
| 47 | +/** |
| 48 | + An ACPI_PARSER array describing the Start Method Specific Parameters for Arm SMC Start Method table. |
| 49 | +**/ |
| 50 | +STATIC CONST ACPI_PARSER Tpm2StartMethodArmSmc[] = { |
| 51 | + { L"Interrupt", 4, 0, L"0x%x", NULL, NULL, NULL, NULL }, |
| 52 | + { L"Flags", 1, 4, L"0x%x", NULL, NULL, NULL, NULL }, |
| 53 | + { L"Operation Flags", 1, 5, L"0x%x", NULL, NULL, NULL, NULL }, |
| 54 | + { L"Attributes", 1, 6, L"0x%x", NULL, NULL, NULL, NULL }, |
| 55 | + { L"Reserved", 1, 7, L"0x%x", NULL, NULL, NULL, NULL }, |
| 56 | + { L"SMC/HVC Function ID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL }, |
| 57 | +}; |
| 58 | + |
| 59 | +/** |
| 60 | + This function parses the ACPI TPM2 table. |
| 61 | + When trace is enabled this function parses the TPM2 table and |
| 62 | + traces the ACPI table fields. |
| 63 | +
|
| 64 | + This function also performs validation of the ACPI table fields. |
| 65 | +
|
| 66 | + @param [in] Trace If TRUE, trace the ACPI fields. |
| 67 | + @param [in] Ptr Pointer to the start of the buffer. |
| 68 | + @param [in] AcpiTableLength Length of the ACPI table. |
| 69 | + @param [in] AcpiTableRevision Revision of the ACPI table. |
| 70 | +**/ |
| 71 | +VOID |
| 72 | +EFIAPI |
| 73 | +ParseAcpiTpm2 ( |
| 74 | + IN BOOLEAN Trace, |
| 75 | + IN UINT8 *Ptr, |
| 76 | + IN UINT32 AcpiTableLength, |
| 77 | + IN UINT8 AcpiTableRevision |
| 78 | + ) |
| 79 | +{ |
| 80 | + UINT32 Offset; |
| 81 | + BOOLEAN LogAreaPresent; |
| 82 | + |
| 83 | + if (!Trace) { |
| 84 | + return; |
| 85 | + } |
| 86 | + |
| 87 | + Offset = ParseAcpi ( |
| 88 | + TRUE, |
| 89 | + 0, |
| 90 | + "TPM2", |
| 91 | + Ptr, |
| 92 | + AcpiTableLength, |
| 93 | + PARSER_PARAMS (Tpm2Parser) |
| 94 | + ); |
| 95 | + |
| 96 | + // Log area parameters are optional. Presence is determined by table length. |
| 97 | + LogAreaPresent = (*AcpiHdrInfo.Revision == EFI_TPM2_ACPI_TABLE_REVISION_4 && AcpiTableLength == TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_4) || |
| 98 | + (*AcpiHdrInfo.Revision == EFI_TPM2_ACPI_TABLE_REVISION_5 && AcpiTableLength == TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_5); |
| 99 | + |
| 100 | + switch (*StartMethod) { |
| 101 | + case EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_SMC: |
| 102 | + ParseAcpi ( |
| 103 | + TRUE, |
| 104 | + 0, |
| 105 | + "Start Method Specific Parameters for Arm SMC", |
| 106 | + Ptr + Offset, |
| 107 | + AcpiTableLength - Offset, |
| 108 | + PARSER_PARAMS (Tpm2StartMethodArmSmc) |
| 109 | + ); |
| 110 | + break; |
| 111 | + |
| 112 | + default: |
| 113 | + Print ( |
| 114 | + L"WARNING: Start Method %u not supported\n", |
| 115 | + *StartMethod |
| 116 | + ); |
| 117 | + break; |
| 118 | + } |
| 119 | + |
| 120 | + if (LogAreaPresent) { |
| 121 | + Offset += (*AcpiHdrInfo.Revision == EFI_TPM2_ACPI_TABLE_REVISION_4) ? |
| 122 | + EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4 : |
| 123 | + EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5; |
| 124 | + |
| 125 | + ParseAcpi ( |
| 126 | + TRUE, |
| 127 | + 0, |
| 128 | + "TPM2 Log Area", |
| 129 | + Ptr + Offset, |
| 130 | + AcpiTableLength - Offset, |
| 131 | + PARSER_PARAMS (Tpm2LogArea) |
| 132 | + ); |
| 133 | + } |
| 134 | +} |
0 commit comments