2 System Management System Table Services SmmInstallConfigurationTable service
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "PiSmmCore.h"
17 #define CONFIG_TABLE_SIZE_INCREASED 0x10
19 UINTN mSmmSystemTableAllocateSize
= 0;
22 The SmmInstallConfigurationTable() function is used to maintain the list
23 of configuration tables that are stored in the System Management System
24 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
25 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
27 @param SystemTable A pointer to the SMM System Table (SMST).
28 @param Guid A pointer to the GUID for the entry to add, update, or remove.
29 @param Table A pointer to the buffer of the table to add.
30 @param TableSize The size of the table to install.
32 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
33 @retval EFI_INVALID_PARAMETER Guid is not valid.
34 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
35 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
40 SmmInstallConfigurationTable (
41 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
42 IN CONST EFI_GUID
*Guid
,
48 EFI_CONFIGURATION_TABLE
*ConfigurationTable
;
49 EFI_CONFIGURATION_TABLE
*OldTable
;
52 // If Guid is NULL, then this operation cannot be performed
55 return EFI_INVALID_PARAMETER
;
58 ConfigurationTable
= gSmmCoreSmst
.SmmConfigurationTable
;
61 // Search all the table for an entry that matches Guid
63 for (Index
= 0; Index
< gSmmCoreSmst
.NumberOfTableEntries
; Index
++) {
64 if (CompareGuid (Guid
, &(ConfigurationTable
[Index
].VendorGuid
))) {
69 if (Index
< gSmmCoreSmst
.NumberOfTableEntries
) {
71 // A match was found, so this is either a modify or a delete operation
75 // If Table is not NULL, then this is a modify operation.
76 // Modify the table entry and return.
78 ConfigurationTable
[Index
].VendorTable
= Table
;
83 // A match was found and Table is NULL, so this is a delete operation.
85 gSmmCoreSmst
.NumberOfTableEntries
--;
88 // Copy over deleted entry
91 &(ConfigurationTable
[Index
]),
92 &(ConfigurationTable
[Index
+ 1]),
93 (gSmmCoreSmst
.NumberOfTableEntries
- Index
) * sizeof (EFI_CONFIGURATION_TABLE
)
98 // No matching GUIDs were found, so this is an add operation.
102 // If Table is NULL on an add operation, then return an error.
104 return EFI_NOT_FOUND
;
108 // Assume that Index == gSmmCoreSmst.NumberOfTableEntries
110 if ((Index
* sizeof (EFI_CONFIGURATION_TABLE
)) >= mSmmSystemTableAllocateSize
) {
112 // Allocate a table with one additional entry.
114 mSmmSystemTableAllocateSize
+= (CONFIG_TABLE_SIZE_INCREASED
* sizeof (EFI_CONFIGURATION_TABLE
));
115 ConfigurationTable
= AllocatePool (mSmmSystemTableAllocateSize
);
116 if (ConfigurationTable
== NULL
) {
118 // If a new table could not be allocated, then return an error.
120 return EFI_OUT_OF_RESOURCES
;
123 if (gSmmCoreSmst
.SmmConfigurationTable
!= NULL
) {
125 // Copy the old table to the new table.
129 gSmmCoreSmst
.SmmConfigurationTable
,
130 Index
* sizeof (EFI_CONFIGURATION_TABLE
)
134 // Record the old table pointer.
136 OldTable
= gSmmCoreSmst
.SmmConfigurationTable
;
139 // As the SmmInstallConfigurationTable() may be re-entered by FreePool() in
140 // its calling stack, updating System table to the new table pointer must
141 // be done before calling FreePool() to free the old table.
142 // It can make sure the gSmmCoreSmst.SmmConfigurationTable point to the new
143 // table and avoid the errors of use-after-free to the old table by the
144 // reenter of SmmInstallConfigurationTable() in FreePool()'s calling stack.
146 gSmmCoreSmst
.SmmConfigurationTable
= ConfigurationTable
;
149 // Free the old table after updating System Table to the new table pointer.
154 // Update System Table
156 gSmmCoreSmst
.SmmConfigurationTable
= ConfigurationTable
;
161 // Fill in the new entry
163 CopyGuid ((VOID
*)&ConfigurationTable
[Index
].VendorGuid
, Guid
);
164 ConfigurationTable
[Index
].VendorTable
= Table
;
167 // This is an add operation, so increment the number of table entries
169 gSmmCoreSmst
.NumberOfTableEntries
++;
173 // CRC-32 field is ignorable for SMM System Table and should be set to zero