]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/PiSmmCore/InstallConfigurationTable.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / InstallConfigurationTable.c
CommitLineData
e42e9404 1/** @file\r
2 System Management System Table Services SmmInstallConfigurationTable service\r
3\r
d1102dba 4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
e42e9404 6\r
7**/\r
8\r
9#include "PiSmmCore.h"\r
10\r
1436aea4 11#define CONFIG_TABLE_SIZE_INCREASED 0x10\r
e42e9404 12\r
13UINTN mSmmSystemTableAllocateSize = 0;\r
14\r
15/**\r
16 The SmmInstallConfigurationTable() function is used to maintain the list\r
17 of configuration tables that are stored in the System Management System\r
18 Table. The list is stored as an array of (GUID, Pointer) pairs. The list\r
19 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.\r
20\r
21 @param SystemTable A pointer to the SMM System Table (SMST).\r
22 @param Guid A pointer to the GUID for the entry to add, update, or remove.\r
23 @param Table A pointer to the buffer of the table to add.\r
24 @param TableSize The size of the table to install.\r
25\r
26 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.\r
27 @retval EFI_INVALID_PARAMETER Guid is not valid.\r
28 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.\r
29 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.\r
30\r
31**/\r
32EFI_STATUS\r
33EFIAPI\r
34SmmInstallConfigurationTable (\r
35 IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,\r
36 IN CONST EFI_GUID *Guid,\r
37 IN VOID *Table,\r
38 IN UINTN TableSize\r
39 )\r
40{\r
41 UINTN Index;\r
42 EFI_CONFIGURATION_TABLE *ConfigurationTable;\r
322d827c 43 EFI_CONFIGURATION_TABLE *OldTable;\r
e42e9404 44\r
45 //\r
46 // If Guid is NULL, then this operation cannot be performed\r
47 //\r
48 if (Guid == NULL) {\r
49 return EFI_INVALID_PARAMETER;\r
50 }\r
51\r
52 ConfigurationTable = gSmmCoreSmst.SmmConfigurationTable;\r
53\r
54 //\r
55 // Search all the table for an entry that matches Guid\r
56 //\r
57 for (Index = 0; Index < gSmmCoreSmst.NumberOfTableEntries; Index++) {\r
58 if (CompareGuid (Guid, &(ConfigurationTable[Index].VendorGuid))) {\r
59 break;\r
60 }\r
61 }\r
62\r
63 if (Index < gSmmCoreSmst.NumberOfTableEntries) {\r
64 //\r
65 // A match was found, so this is either a modify or a delete operation\r
66 //\r
67 if (Table != NULL) {\r
68 //\r
69 // If Table is not NULL, then this is a modify operation.\r
322d827c 70 // Modify the table entry and return.\r
e42e9404 71 //\r
72 ConfigurationTable[Index].VendorTable = Table;\r
73 return EFI_SUCCESS;\r
74 }\r
75\r
76 //\r
77 // A match was found and Table is NULL, so this is a delete operation.\r
78 //\r
79 gSmmCoreSmst.NumberOfTableEntries--;\r
80\r
81 //\r
82 // Copy over deleted entry\r
83 //\r
84 CopyMem (\r
85 &(ConfigurationTable[Index]),\r
86 &(ConfigurationTable[Index + 1]),\r
87 (gSmmCoreSmst.NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)\r
88 );\r
e42e9404 89 } else {\r
90 //\r
91 // No matching GUIDs were found, so this is an add operation.\r
92 //\r
93 if (Table == NULL) {\r
94 //\r
95 // If Table is NULL on an add operation, then return an error.\r
96 //\r
97 return EFI_NOT_FOUND;\r
98 }\r
99\r
100 //\r
101 // Assume that Index == gSmmCoreSmst.NumberOfTableEntries\r
102 //\r
103 if ((Index * sizeof (EFI_CONFIGURATION_TABLE)) >= mSmmSystemTableAllocateSize) {\r
104 //\r
105 // Allocate a table with one additional entry.\r
106 //\r
107 mSmmSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE));\r
1436aea4 108 ConfigurationTable = AllocatePool (mSmmSystemTableAllocateSize);\r
e42e9404 109 if (ConfigurationTable == NULL) {\r
110 //\r
111 // If a new table could not be allocated, then return an error.\r
112 //\r
113 return EFI_OUT_OF_RESOURCES;\r
114 }\r
115\r
116 if (gSmmCoreSmst.SmmConfigurationTable != NULL) {\r
117 //\r
118 // Copy the old table to the new table.\r
119 //\r
120 CopyMem (\r
121 ConfigurationTable,\r
122 gSmmCoreSmst.SmmConfigurationTable,\r
123 Index * sizeof (EFI_CONFIGURATION_TABLE)\r
124 );\r
125\r
126 //\r
322d827c 127 // Record the old table pointer.\r
e42e9404 128 //\r
322d827c 129 OldTable = gSmmCoreSmst.SmmConfigurationTable;\r
e42e9404 130\r
322d827c
SS
131 //\r
132 // As the SmmInstallConfigurationTable() may be re-entered by FreePool() in\r
133 // its calling stack, updating System table to the new table pointer must\r
134 // be done before calling FreePool() to free the old table.\r
135 // It can make sure the gSmmCoreSmst.SmmConfigurationTable point to the new\r
136 // table and avoid the errors of use-after-free to the old table by the\r
137 // reenter of SmmInstallConfigurationTable() in FreePool()'s calling stack.\r
138 //\r
139 gSmmCoreSmst.SmmConfigurationTable = ConfigurationTable;\r
140\r
141 //\r
142 // Free the old table after updating System Table to the new table pointer.\r
143 //\r
144 FreePool (OldTable);\r
145 } else {\r
146 //\r
147 // Update System Table\r
148 //\r
149 gSmmCoreSmst.SmmConfigurationTable = ConfigurationTable;\r
150 }\r
e42e9404 151 }\r
152\r
153 //\r
154 // Fill in the new entry\r
155 //\r
156 CopyGuid ((VOID *)&ConfigurationTable[Index].VendorGuid, Guid);\r
157 ConfigurationTable[Index].VendorTable = Table;\r
158\r
159 //\r
160 // This is an add operation, so increment the number of table entries\r
161 //\r
162 gSmmCoreSmst.NumberOfTableEntries++;\r
163 }\r
164\r
165 //\r
166 // CRC-32 field is ignorable for SMM System Table and should be set to zero\r
167 //\r
168\r
169 return EFI_SUCCESS;\r
170}\r