2 System Management System Table Services MmInstallConfigurationTable service
4 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "StandaloneMmCore.h"
12 #define CONFIG_TABLE_SIZE_INCREASED 0x10
14 UINTN mMmSystemTableAllocateSize
= 0;
17 The MmInstallConfigurationTable() function is used to maintain the list
18 of configuration tables that are stored in the System Management System
19 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
20 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
22 @param SystemTable A pointer to the SMM System Table (SMST).
23 @param Guid A pointer to the GUID for the entry to add, update, or remove.
24 @param Table A pointer to the buffer of the table to add.
25 @param TableSize The size of the table to install.
27 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
28 @retval EFI_INVALID_PARAMETER Guid is not valid.
29 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
30 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
35 MmInstallConfigurationTable (
36 IN CONST EFI_MM_SYSTEM_TABLE
*SystemTable
,
37 IN CONST EFI_GUID
*Guid
,
43 EFI_CONFIGURATION_TABLE
*ConfigurationTable
;
44 EFI_CONFIGURATION_TABLE
*OldTable
;
47 // If Guid is NULL, then this operation cannot be performed
50 return EFI_INVALID_PARAMETER
;
53 ConfigurationTable
= gMmCoreMmst
.MmConfigurationTable
;
56 // Search all the table for an entry that matches Guid
58 for (Index
= 0; Index
< gMmCoreMmst
.NumberOfTableEntries
; Index
++) {
59 if (CompareGuid (Guid
, &(ConfigurationTable
[Index
].VendorGuid
))) {
64 if (Index
< gMmCoreMmst
.NumberOfTableEntries
) {
66 // A match was found, so this is either a modify or a delete operation
70 // If Table is not NULL, then this is a modify operation.
71 // Modify the table entry and return.
73 ConfigurationTable
[Index
].VendorTable
= Table
;
78 // A match was found and Table is NULL, so this is a delete operation.
80 gMmCoreMmst
.NumberOfTableEntries
--;
83 // Copy over deleted entry
86 &(ConfigurationTable
[Index
]),
87 &(ConfigurationTable
[Index
+ 1]),
88 (gMmCoreMmst
.NumberOfTableEntries
- Index
) * sizeof (EFI_CONFIGURATION_TABLE
)
93 // No matching GUIDs were found, so this is an add operation.
97 // If Table is NULL on an add operation, then return an error.
103 // Assume that Index == gMmCoreMmst.NumberOfTableEntries
105 if ((Index
* sizeof (EFI_CONFIGURATION_TABLE
)) >= mMmSystemTableAllocateSize
) {
107 // Allocate a table with one additional entry.
109 mMmSystemTableAllocateSize
+= (CONFIG_TABLE_SIZE_INCREASED
* sizeof (EFI_CONFIGURATION_TABLE
));
110 ConfigurationTable
= AllocatePool (mMmSystemTableAllocateSize
);
111 if (ConfigurationTable
== NULL
) {
113 // If a new table could not be allocated, then return an error.
115 return EFI_OUT_OF_RESOURCES
;
118 if (gMmCoreMmst
.MmConfigurationTable
!= NULL
) {
120 // Copy the old table to the new table.
124 gMmCoreMmst
.MmConfigurationTable
,
125 Index
* sizeof (EFI_CONFIGURATION_TABLE
)
129 // Record the old table pointer.
131 OldTable
= gMmCoreMmst
.MmConfigurationTable
;
134 // As the MmInstallConfigurationTable() may be re-entered by FreePool() in
135 // its calling stack, updating System table to the new table pointer must
136 // be done before calling FreePool() to free the old table.
137 // It can make sure the gMmCoreMmst.MmConfigurationTable point to the new
138 // table and avoid the errors of use-after-free to the old table by the
139 // reenter of MmInstallConfigurationTable() in FreePool()'s calling stack.
141 gMmCoreMmst
.MmConfigurationTable
= ConfigurationTable
;
144 // Free the old table after updating System Table to the new table pointer.
149 // Update System Table
151 gMmCoreMmst
.MmConfigurationTable
= ConfigurationTable
;
156 // Fill in the new entry
158 CopyGuid ((VOID
*)&ConfigurationTable
[Index
].VendorGuid
, Guid
);
159 ConfigurationTable
[Index
].VendorTable
= Table
;
162 // This is an add operation, so increment the number of table entries
164 gMmCoreMmst
.NumberOfTableEntries
++;
168 // CRC-32 field is ignorable for SMM System Table and should be set to zero