|
| 1 | +/** @file |
| 2 | + WSMT Table Generator Implementation. |
| 3 | +
|
| 4 | + This file implements the WSMT Table Generator. |
| 5 | + The WSMT table is used to specify the security mitigations |
| 6 | + that are enabled in the Windows OS. |
| 7 | +
|
| 8 | + Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved. |
| 9 | +
|
| 10 | + SPDX-License-Identifier: BSD-2-Clause-Patent |
| 11 | +**/ |
| 12 | + |
| 13 | +#include <AcpiTableGenerator.h> |
| 14 | +#include <ConfigurationManagerHelper.h> |
| 15 | +#include <ConfigurationManagerObject.h> |
| 16 | +#include <IndustryStandard/WindowsSmmSecurityMitigationTable.h> |
| 17 | +#include <Library/BaseMemoryLib.h> |
| 18 | +#include <Library/DebugLib.h> |
| 19 | +#include <Library/TableHelperLib.h> |
| 20 | +#include <Protocol/AcpiTable.h> |
| 21 | +#include <Protocol/ConfigurationManagerProtocol.h> |
| 22 | +#include <X64NameSpaceObjects.h> |
| 23 | + |
| 24 | +/** This macro expands to a function that retrieves the |
| 25 | + WSMT protection flags information from the Configuration Manager. |
| 26 | +*/ |
| 27 | +GET_OBJECT_LIST ( |
| 28 | + EObjNameSpaceX64, |
| 29 | + EX64ObjWsmtFlagsInfo, |
| 30 | + CM_X64_WSMT_FLAGS_INFO |
| 31 | + ); |
| 32 | + |
| 33 | +/** The ACPI WSMT Table. |
| 34 | +*/ |
| 35 | +STATIC |
| 36 | +EFI_ACPI_WSMT_TABLE AcpiWsmt = { |
| 37 | + ACPI_HEADER ( |
| 38 | + EFI_ACPI_WINDOWS_SMM_SECURITY_MITIGATION_TABLE_SIGNATURE, |
| 39 | + EFI_ACPI_WSMT_TABLE, |
| 40 | + EFI_WSMT_TABLE_REVISION |
| 41 | + ), |
| 42 | + // ProtectionFlags |
| 43 | + 0 |
| 44 | +}; |
| 45 | + |
| 46 | +/** Update the protection flags information in the WSMT Table. |
| 47 | +
|
| 48 | + @param [in] CfgMgrProtocol Pointer to the Configuration Manager |
| 49 | + Protocol Interface. |
| 50 | +
|
| 51 | + @retval EFI_SUCCESS Success. |
| 52 | + @retval EFI_INVALID_PARAMETER A parameter is invalid. |
| 53 | + @retval EFI_NOT_FOUND The required object was not found. |
| 54 | + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration |
| 55 | + Manager is less than the Object size for the |
| 56 | + requested object. |
| 57 | +**/ |
| 58 | +STATIC |
| 59 | +EFI_STATUS |
| 60 | +EFIAPI |
| 61 | +WsmtAddProtectionFlagsInfo ( |
| 62 | + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol |
| 63 | + ) |
| 64 | +{ |
| 65 | + EFI_STATUS Status; |
| 66 | + CM_X64_WSMT_FLAGS_INFO *WsmtFlagInfo; |
| 67 | + |
| 68 | + ASSERT (CfgMgrProtocol != NULL); |
| 69 | + |
| 70 | + // Get the WSMT protection flag from the Platform Configuration Manager |
| 71 | + Status = GetEX64ObjWsmtFlagsInfo ( |
| 72 | + CfgMgrProtocol, |
| 73 | + CM_NULL_TOKEN, |
| 74 | + &WsmtFlagInfo, |
| 75 | + NULL |
| 76 | + ); |
| 77 | + if (EFI_ERROR (Status)) { |
| 78 | + DEBUG (( |
| 79 | + DEBUG_ERROR, |
| 80 | + "ERROR: WSMT: Failed to get WSMT protection flag information." \ |
| 81 | + " Status = %r\n", |
| 82 | + Status |
| 83 | + )); |
| 84 | + return Status; |
| 85 | + } |
| 86 | + |
| 87 | + DEBUG (( |
| 88 | + DEBUG_INFO, |
| 89 | + "WSMT: Protection flags = 0x%x\n", |
| 90 | + WsmtFlagInfo->ProtectionFlags |
| 91 | + )); |
| 92 | + |
| 93 | + AcpiWsmt.ProtectionFlags = WsmtFlagInfo->ProtectionFlags; |
| 94 | + return Status; |
| 95 | +} |
| 96 | + |
| 97 | +/** Construct the WSMT table. |
| 98 | +
|
| 99 | + This function invokes the Configuration Manager protocol interface |
| 100 | + to get the required information for generating the ACPI table. |
| 101 | +
|
| 102 | + If this function allocates any resources then they must be freed |
| 103 | + in the FreeXXXXTableResources function. |
| 104 | +
|
| 105 | + @param [in] This Pointer to the table generator. |
| 106 | + @param [in] AcpiTableInfo Pointer to the ACPI Table Info. |
| 107 | + @param [in] CfgMgrProtocol Pointer to the Configuration Manager |
| 108 | + Protocol Interface. |
| 109 | + @param [out] Table Pointer to the constructed ACPI Table. |
| 110 | +
|
| 111 | + @retval EFI_SUCCESS Table generated successfully. |
| 112 | + @retval EFI_INVALID_PARAMETER A parameter is invalid. |
| 113 | + @retval EFI_NOT_FOUND The required object was not found. |
| 114 | + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration |
| 115 | + Manager is less than the Object size for the |
| 116 | + requested object. |
| 117 | +**/ |
| 118 | +STATIC |
| 119 | +EFI_STATUS |
| 120 | +EFIAPI |
| 121 | +BuildWsmtTable ( |
| 122 | + IN CONST ACPI_TABLE_GENERATOR *CONST This, |
| 123 | + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, |
| 124 | + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, |
| 125 | + OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table |
| 126 | + ) |
| 127 | +{ |
| 128 | + EFI_STATUS Status; |
| 129 | + |
| 130 | + ASSERT (This != NULL); |
| 131 | + ASSERT (AcpiTableInfo != NULL); |
| 132 | + ASSERT (CfgMgrProtocol != NULL); |
| 133 | + ASSERT (Table != NULL); |
| 134 | + ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); |
| 135 | + ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); |
| 136 | + |
| 137 | + if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) || |
| 138 | + (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision)) |
| 139 | + { |
| 140 | + DEBUG (( |
| 141 | + DEBUG_ERROR, |
| 142 | + "ERROR: WSMT: Requested table revision = %d, is not supported." |
| 143 | + "Supported table revision: Minimum = %d, Maximum = %d\n", |
| 144 | + AcpiTableInfo->AcpiTableRevision, |
| 145 | + This->MinAcpiTableRevision, |
| 146 | + This->AcpiTableRevision |
| 147 | + )); |
| 148 | + return EFI_INVALID_PARAMETER; |
| 149 | + } |
| 150 | + |
| 151 | + *Table = NULL; |
| 152 | + |
| 153 | + Status = AddAcpiHeader ( |
| 154 | + CfgMgrProtocol, |
| 155 | + This, |
| 156 | + (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiWsmt, |
| 157 | + AcpiTableInfo, |
| 158 | + sizeof (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE) |
| 159 | + ); |
| 160 | + if (EFI_ERROR (Status)) { |
| 161 | + DEBUG (( |
| 162 | + DEBUG_ERROR, |
| 163 | + "ERROR: WSMT: Failed to add ACPI header. Status = %r\n", |
| 164 | + Status |
| 165 | + )); |
| 166 | + goto error_handler; |
| 167 | + } |
| 168 | + |
| 169 | + // Update protection flags Info |
| 170 | + Status = WsmtAddProtectionFlagsInfo (CfgMgrProtocol); |
| 171 | + if (EFI_ERROR (Status)) { |
| 172 | + goto error_handler; |
| 173 | + } |
| 174 | + |
| 175 | + *Table = (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiWsmt; |
| 176 | +error_handler: |
| 177 | + return Status; |
| 178 | +} |
| 179 | + |
| 180 | +/** This macro defines the WSMT Table Generator revision. |
| 181 | +*/ |
| 182 | +#define WSMT_GENERATOR_REVISION CREATE_REVISION (1, 0) |
| 183 | + |
| 184 | +/** The interface for the WSMT Table Generator. |
| 185 | +*/ |
| 186 | +STATIC |
| 187 | +CONST |
| 188 | +ACPI_TABLE_GENERATOR WsmtGenerator = { |
| 189 | + // Generator ID |
| 190 | + CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdWsmt), |
| 191 | + // Generator Description |
| 192 | + L"ACPI.STD.WSMT.GENERATOR", |
| 193 | + // ACPI Table Signature |
| 194 | + EFI_ACPI_WINDOWS_SMM_SECURITY_MITIGATION_TABLE_SIGNATURE, |
| 195 | + // ACPI Table Revision supported by this Generator |
| 196 | + EFI_WSMT_TABLE_REVISION, |
| 197 | + // Minimum supported ACPI Table Revision |
| 198 | + EFI_WSMT_TABLE_REVISION, |
| 199 | + // Creator ID |
| 200 | + TABLE_GENERATOR_CREATOR_ID_ARM, |
| 201 | + // Creator Revision |
| 202 | + WSMT_GENERATOR_REVISION, |
| 203 | + // Build Table function |
| 204 | + BuildWsmtTable, |
| 205 | + // No additional resources are allocated by the generator. |
| 206 | + // Hence the Free Resource function is not required. |
| 207 | + NULL, |
| 208 | + // Extended build function not needed |
| 209 | + NULL, |
| 210 | + // Extended build function not implemented by the generator. |
| 211 | + // Hence extended free resource function is not required. |
| 212 | + NULL |
| 213 | +}; |
| 214 | + |
| 215 | +/** Register the Generator with the ACPI Table Factory. |
| 216 | +
|
| 217 | + @param [in] ImageHandle The handle to the image. |
| 218 | + @param [in] SystemTable Pointer to the System Table. |
| 219 | +
|
| 220 | + @retval EFI_SUCCESS The Generator is registered. |
| 221 | + @retval EFI_INVALID_PARAMETER A parameter is invalid. |
| 222 | + @retval EFI_ALREADY_STARTED The Generator for the Table ID |
| 223 | + is already registered. |
| 224 | +**/ |
| 225 | +EFI_STATUS |
| 226 | +EFIAPI |
| 227 | +AcpiWsmtLibConstructor ( |
| 228 | + IN EFI_HANDLE ImageHandle, |
| 229 | + IN EFI_SYSTEM_TABLE *SystemTable |
| 230 | + ) |
| 231 | +{ |
| 232 | + EFI_STATUS Status; |
| 233 | + |
| 234 | + Status = RegisterAcpiTableGenerator (&WsmtGenerator); |
| 235 | + DEBUG ((DEBUG_INFO, "WSMT: Register Generator. Status = %r\n", Status)); |
| 236 | + ASSERT_EFI_ERROR (Status); |
| 237 | + return Status; |
| 238 | +} |
| 239 | + |
| 240 | +/** Deregister the Generator from the ACPI Table Factory. |
| 241 | +
|
| 242 | + @param [in] ImageHandle The handle to the image. |
| 243 | + @param [in] SystemTable Pointer to the System Table. |
| 244 | +
|
| 245 | + @retval EFI_SUCCESS The Generator is deregistered. |
| 246 | + @retval EFI_INVALID_PARAMETER A parameter is invalid. |
| 247 | + @retval EFI_NOT_FOUND The Generator is not registered. |
| 248 | +**/ |
| 249 | +EFI_STATUS |
| 250 | +EFIAPI |
| 251 | +AcpiWsmtLibDestructor ( |
| 252 | + IN EFI_HANDLE ImageHandle, |
| 253 | + IN EFI_SYSTEM_TABLE *SystemTable |
| 254 | + ) |
| 255 | +{ |
| 256 | + EFI_STATUS Status; |
| 257 | + |
| 258 | + Status = DeregisterAcpiTableGenerator (&WsmtGenerator); |
| 259 | + DEBUG ((DEBUG_INFO, "WSMT: Deregister Generator. Status = %r\n", Status)); |
| 260 | + ASSERT_EFI_ERROR (Status); |
| 261 | + return Status; |
| 262 | +} |
0 commit comments