Skip to content

Commit 8dca0ba

Browse files
Abdul Lateef AttarAbdul Lateef Attar
Abdul Lateef Attar
authored and
Abdul Lateef Attar
committed
DynamicTablesPkg: Adds WSMT generator for X64
Adds ACPI WSMT table generator library. Updates acpi standard table enum with wsmt. Updates X64 namespace object. Updates the object parser. Updates the Readme. Cc: Sami Mujawar <Sami.Mujawar@arm.com> Cc: Pierre Gondois <pierre.gondois@arm.com> Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
1 parent baecba6 commit 8dca0ba

File tree

7 files changed

+327
-2
lines changed

7 files changed

+327
-2
lines changed

DynamicTablesPkg/DynamicTables.dsc.inc

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf
5353

5454
[Components.IA32, Components.X64]
55+
#
56+
# Generators (IA32/X64 specific)
57+
#
58+
DynamicTablesPkg/Library/Acpi/X64/AcpiWsmtLib/AcpiWsmtLib.inf
59+
5560
#
5661
# Dynamic Table Factory Dxe
5762
#
@@ -60,6 +65,7 @@
6065
# Generators
6166
# Common
6267
NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf
68+
NULL|DynamicTablesPkg/Library/Acpi/X64/AcpiWsmtLib/AcpiWsmtLib.inf
6369
}
6470

6571
[Components.ARM, Components.AARCH64]

DynamicTablesPkg/Include/AcpiTableGenerator.h

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
Copyright (c) 2017 - 2022, Arm Limited. All rights reserved.<BR>
44
Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.<BR>
5+
Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
56
67
SPDX-License-Identifier: BSD-2-Clause-Patent
78
@@ -72,6 +73,8 @@ The Dynamic Tables Framework implements the following ACPI table generators:
7273
The SSDT Pci Express generator collates the Pci Express
7374
information from the Configuration Manager and generates a
7475
SSDT table describing a Pci Express bus.
76+
- WSMT : The WSMT generator collates the WSMT protection flag information
77+
from the Configuration Manager and builds the WSMT table.
7578
*/
7679

7780
/** The ACPI_TABLE_GENERATOR_ID type describes ACPI table generator ID.
@@ -101,6 +104,7 @@ typedef enum StdAcpiTableId {
101104
EStdAcpiTableIdSsdtPciExpress, ///< SSDT Pci Express Generator
102105
EStdAcpiTableIdPcct, ///< PCCT Generator
103106
EStdAcpiTableIdTpm2, ///< TPM2 Generator
107+
EStdAcpiTableIdWsmt, ///< WSMT Generator
104108
EStdAcpiTableIdMax
105109
} ESTD_ACPI_TABLE_ID;
106110

DynamicTablesPkg/Include/X64NameSpaceObjects.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ typedef enum X64ObjectID {
3030
EX64ObjFadtXgpeBlockInfo, ///< 6 - FADT 64-bit GPE block info
3131
EX64ObjFadtSleepBlockInfo, ///< 7 - FADT Sleep block info
3232
EX64ObjFadtResetBlockInfo, ///< 8 - FADT Reset block info
33-
EX64ObjFadtMiscInfo, ///< 0 - FADT Legacy fields info
34-
EX64ObjMax ///< 10 - Maximum Object ID
33+
EX64ObjFadtMiscInfo, ///< 9 - FADT Legacy fields info
34+
EX64ObjWsmtFlagsInfo, ///< 10 - WSMT protection flags info
35+
EX64ObjMax ///< 11 - Maximum Object ID
3536
} EX64_OBJECT_ID;
3637

3738
/** A structure that describes the
@@ -167,4 +168,13 @@ typedef struct CmX64FadtFadtMiscInfo {
167168
UINT8 Century;
168169
} CM_X64_FADT_MISC_INFO;
169170

171+
/**
172+
A structure that describes the WSMT protection flags information.
173+
174+
ID: EX64ObjWsmtFlagsInfo
175+
*/
176+
typedef struct CmX64WsmtFlagsInfo {
177+
UINT32 ProtectionFlags;
178+
} CM_X64_WSMT_FLAGS_INFO;
179+
170180
#endif // X64_NAMESPACE_OBJECTS_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## @file
2+
# WSMT Table Generator
3+
#
4+
# Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
5+
#
6+
# SPDX-License-Identifier: BSD-2-Clause-Patent
7+
##
8+
9+
[Defines]
10+
INF_VERSION = 1.30
11+
BASE_NAME = AcpiWsmtLib
12+
FILE_GUID = FA6B175A-0AAF-4BFA-843A-1D885206C070
13+
VERSION_STRING = 1.0
14+
MODULE_TYPE = DXE_DRIVER
15+
LIBRARY_CLASS = NULL|DXE_DRIVER
16+
CONSTRUCTOR = AcpiWsmtLibConstructor
17+
DESTRUCTOR = AcpiWsmtLibDestructor
18+
19+
#
20+
# The following information is for reference only and not required by the build tools.
21+
#
22+
# VALID_ARCHITECTURES = IA32 X64
23+
#
24+
25+
[Sources.IA32, Sources.X64]
26+
WsmtGenerator.c
27+
28+
[Packages]
29+
DynamicTablesPkg/DynamicTablesPkg.dec
30+
MdeModulePkg/MdeModulePkg.dec
31+
MdePkg/MdePkg.dec
32+
33+
[LibraryClasses]
34+
BaseLib
35+
DebugLib
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
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+
}

DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerObjectParser.c

+7
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,12 @@ STATIC CONST CM_OBJ_PARSER CmX64ObjFadtMiscInfoParser[] = {
850850
{ "Century", 1, "0x%x", NULL }
851851
};
852852

853+
/** A parser for EX64ObjWsmtFlagsInfo.
854+
*/
855+
STATIC CONST CM_OBJ_PARSER CmX64ObjWsmtFlagsInfoParser[] = {
856+
{ "WsmtFlags", 4, "0x%x", NULL }
857+
};
858+
853859
/** A parser for X64 namespace objects.
854860
*/
855861
STATIC CONST CM_OBJ_PARSER_ARRAY X64NamespaceObjectParser[] = {
@@ -863,6 +869,7 @@ STATIC CONST CM_OBJ_PARSER_ARRAY X64NamespaceObjectParser[] = {
863869
CM_PARSER_ADD_OBJECT (EX64ObjFadtSleepBlockInfo,CmX64ObjFadtSleepBlockInfoParser),
864870
CM_PARSER_ADD_OBJECT (EX64ObjFadtResetBlockInfo,CmX64ObjFadtResetBlockInfoParser),
865871
CM_PARSER_ADD_OBJECT (EX64ObjFadtMiscInfo, CmX64ObjFadtMiscInfoParser),
872+
CM_PARSER_ADD_OBJECT (EX64ObjWsmtFlagsInfo, CmX64ObjWsmtFlagsInfoParser),
866873
CM_PARSER_ADD_OBJECT_RESERVED (EX64ObjMax)
867874
};
868875

DynamicTablesPkg/Readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,5 @@ The CM_OBJECT_ID type is used to identify the Configuration Manager
514514
| 7 | Sleep Block Info | |
515515
| 8 | Reset Block Info | |
516516
| 9 | Miscellaneous Block Info | |
517+
| 10 | Windows protection flag Info | |
517518
| `*` | All other values are reserved. | |

0 commit comments

Comments
 (0)