2 System Management System Table Services SmmInstallConfigurationTable service
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #define CONFIG_TABLE_SIZE_INCREASED 0x10
13 UINTN mSmmSystemTableAllocateSize
= 0;
16 The SmmInstallConfigurationTable() function is used to maintain the list
17 of configuration tables that are stored in the System Management System
18 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
19 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
21 @param SystemTable A pointer to the SMM System Table (SMST).
22 @param Guid A pointer to the GUID for the entry to add, update, or remove.
23 @param Table A pointer to the buffer of the table to add.
24 @param TableSize The size of the table to install.
26 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
27 @retval EFI_INVALID_PARAMETER Guid is not valid.
28 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
29 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
34 SmmInstallConfigurationTable (
35 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
36 IN CONST EFI_GUID
*Guid
,
42 EFI_CONFIGURATION_TABLE
*ConfigurationTable
;
43 EFI_CONFIGURATION_TABLE
*OldTable
;
46 // If Guid is NULL, then this operation cannot be performed
49 return EFI_INVALID_PARAMETER
;
52 ConfigurationTable
= gSmmCoreSmst
.SmmConfigurationTable
;
55 // Search all the table for an entry that matches Guid
57 for (Index
= 0; Index
< gSmmCoreSmst
.NumberOfTableEntries
; Index
++) {
58 if (CompareGuid (Guid
, &(ConfigurationTable
[Index
].VendorGuid
))) {
63 if (Index
< gSmmCoreSmst
.NumberOfTableEntries
) {
65 // A match was found, so this is either a modify or a delete operation
69 // If Table is not NULL, then this is a modify operation.
70 // Modify the table entry and return.
72 ConfigurationTable
[Index
].VendorTable
= Table
;
77 // A match was found and Table is NULL, so this is a delete operation.
79 gSmmCoreSmst
.NumberOfTableEntries
--;
82 // Copy over deleted entry
85 &(ConfigurationTable
[Index
]),
86 &(ConfigurationTable
[Index
+ 1]),
87 (gSmmCoreSmst
.NumberOfTableEntries
- Index
) * sizeof (EFI_CONFIGURATION_TABLE
)
92 // No matching GUIDs were found, so this is an add operation.
96 // If Table is NULL on an add operation, then return an error.
102 // Assume that Index == gSmmCoreSmst.NumberOfTableEntries
104 if ((Index
* sizeof (EFI_CONFIGURATION_TABLE
)) >= mSmmSystemTableAllocateSize
) {
106 // Allocate a table with one additional entry.
108 mSmmSystemTableAllocateSize
+= (CONFIG_TABLE_SIZE_INCREASED
* sizeof (EFI_CONFIGURATION_TABLE
));
109 ConfigurationTable
= AllocatePool (mSmmSystemTableAllocateSize
);
110 if (ConfigurationTable
== NULL
) {
112 // If a new table could not be allocated, then return an error.
114 return EFI_OUT_OF_RESOURCES
;
117 if (gSmmCoreSmst
.SmmConfigurationTable
!= NULL
) {
119 // Copy the old table to the new table.
123 gSmmCoreSmst
.SmmConfigurationTable
,
124 Index
* sizeof (EFI_CONFIGURATION_TABLE
)
128 // Record the old table pointer.
130 OldTable
= gSmmCoreSmst
.SmmConfigurationTable
;
133 // As the SmmInstallConfigurationTable() may be re-entered by FreePool() in
134 // its calling stack, updating System table to the new table pointer must
135 // be done before calling FreePool() to free the old table.
136 // It can make sure the gSmmCoreSmst.SmmConfigurationTable point to the new
137 // table and avoid the errors of use-after-free to the old table by the
138 // reenter of SmmInstallConfigurationTable() in FreePool()'s calling stack.
140 gSmmCoreSmst
.SmmConfigurationTable
= ConfigurationTable
;
143 // Free the old table after updating System Table to the new table pointer.
148 // Update System Table
150 gSmmCoreSmst
.SmmConfigurationTable
= ConfigurationTable
;
155 // Fill in the new entry
157 CopyGuid ((VOID
*)&ConfigurationTable
[Index
].VendorGuid
, Guid
);
158 ConfigurationTable
[Index
].VendorTable
= Table
;
161 // This is an add operation, so increment the number of table entries
163 gSmmCoreSmst
.NumberOfTableEntries
++;
167 // CRC-32 field is ignorable for SMM System Table and should be set to zero