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