]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Misc/InstallConfigurationTable.c
Add comments and DoxyGen format for these files.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / InstallConfigurationTable.c
CommitLineData
504214c4
LG
1/** @file \r
2\r
3 UEFI Miscellaneous boot Services InstallConfigurationTable service\r
28a00297 4\r
504214c4 5Copyright (c) 2006 - 2008, Intel Corporation \r
28a00297 6All rights reserved. This program and the accompanying materials \r
7are licensed and made available under the terms and conditions of the BSD License \r
8which accompanies this distribution. The full text of the license may be found at \r
9http://opensource.org/licenses/bsd-license.php \r
10 \r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
13\r
504214c4 14**/\r
28a00297 15\r
16#include <DxeMain.h>\r
17\r
18#define CONFIG_TABLE_SIZE_INCREASED 0x10\r
19\r
20UINTN mSystemTableAllocateSize = 0;\r
21\r
22\r
23EFI_STATUS\r
24CoreGetConfigTable (\r
25 IN EFI_GUID *Guid,\r
26 OUT VOID **Table\r
27 )\r
28/*++\r
29\r
30Routine Description:\r
31\r
32 Find a config table by name in system table's ConfigurationTable.\r
33\r
34Arguments:\r
35\r
36 Guid - The table name to look for\r
37 \r
38 Table - Pointer of the config table\r
39\r
40Returns: \r
41\r
42 EFI_NOT_FOUND - Could not find the table in system table's ConfigurationTable.\r
43 \r
44 EFI_SUCCESS - Table successfully found.\r
45\r
46--*/\r
47{\r
48 UINTN Index;\r
49\r
50 for (Index = 0; Index < gDxeCoreST->NumberOfTableEntries; Index++) {\r
51 if (CompareGuid (Guid, &(gDxeCoreST->ConfigurationTable[Index].VendorGuid))) {\r
52 *Table = gDxeCoreST->ConfigurationTable[Index].VendorTable;\r
53 return EFI_SUCCESS;\r
54 }\r
55 }\r
56\r
57 return EFI_NOT_FOUND;\r
58}\r
59\r
60\r
61\r
62EFI_STATUS\r
63EFIAPI\r
64CoreInstallConfigurationTable (\r
65 IN EFI_GUID *Guid,\r
66 IN VOID *Table\r
67 )\r
68/*++\r
69\r
70Routine Description:\r
71\r
72 Boot Service called to add, modify, or remove a system configuration table from \r
73 the EFI System Table.\r
74\r
75Arguments:\r
76\r
77 Guid - Pointer to the GUID for the entry to add, update, or remove\r
78 Table - Pointer to the configuration table for the entry to add, update, or\r
79 remove, may be NULL.\r
80\r
81Returns:\r
82 \r
83 EFI_SUCCESS Guid, Table pair added, updated, or removed.\r
84 EFI_INVALID_PARAMETER Input GUID not valid.\r
85 EFI_NOT_FOUND Attempted to delete non-existant entry\r
86 EFI_OUT_OF_RESOURCES Not enough memory available\r
87\r
88--*/\r
89{\r
90 UINTN Index;\r
91 EFI_CONFIGURATION_TABLE *EfiConfigurationTable;\r
92\r
93 //\r
94 // If Guid is NULL, then this operation cannot be performed\r
95 //\r
96 if (Guid == NULL) {\r
97 return EFI_INVALID_PARAMETER;\r
98 }\r
99\r
100 EfiConfigurationTable = gDxeCoreST->ConfigurationTable;\r
101\r
102 //\r
103 // Search all the table for an entry that matches Guid\r
104 //\r
105 for (Index = 0; Index < gDxeCoreST->NumberOfTableEntries; Index++) {\r
106 if (CompareGuid (Guid, &(gDxeCoreST->ConfigurationTable[Index].VendorGuid))) {\r
107 break;\r
108 }\r
109 }\r
110\r
111 if (Index < gDxeCoreST->NumberOfTableEntries) {\r
112 //\r
113 // A match was found, so this is either a modify or a delete operation\r
114 //\r
115 if (Table != NULL) {\r
116 //\r
117 // If Table is not NULL, then this is a modify operation.\r
118 // Modify the table enty and return.\r
119 //\r
120 gDxeCoreST->ConfigurationTable[Index].VendorTable = Table;\r
121\r
122 //\r
123 // Signal Configuration Table change\r
124 //\r
125 CoreNotifySignalList (Guid);\r
126\r
127 return EFI_SUCCESS;\r
128 }\r
129\r
130 //\r
131 // A match was found and Table is NULL, so this is a delete operation.\r
132 //\r
133 gDxeCoreST->NumberOfTableEntries--;\r
134\r
135 //\r
136 // Copy over deleted entry\r
137 //\r
138 CopyMem (\r
139 &(EfiConfigurationTable[Index]),\r
140 &(gDxeCoreST->ConfigurationTable[Index + 1]),\r
141 (gDxeCoreST->NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)\r
142 );\r
143\r
144 } else {\r
145\r
146 //\r
147 // No matching GUIDs were found, so this is an add operation.\r
148 //\r
149\r
150 if (Table == NULL) {\r
151 //\r
152 // If Table is NULL on an add operation, then return an error.\r
153 //\r
154 return EFI_NOT_FOUND;\r
155 }\r
156\r
157 //\r
158 // Assume that Index == gDxeCoreST->NumberOfTableEntries\r
159 //\r
160 if ((Index * sizeof (EFI_CONFIGURATION_TABLE)) >= mSystemTableAllocateSize) {\r
161 //\r
162 // Allocate a table with one additional entry.\r
163 //\r
164 mSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE));\r
165 EfiConfigurationTable = CoreAllocateRuntimePool (mSystemTableAllocateSize);\r
166 if (EfiConfigurationTable == NULL) {\r
167 //\r
168 // If a new table could not be allocated, then return an error.\r
169 //\r
170 return EFI_OUT_OF_RESOURCES;\r
171 }\r
172\r
173 if (gDxeCoreST->ConfigurationTable != NULL) {\r
174 //\r
175 // Copy the old table to the new table.\r
176 //\r
177 CopyMem (\r
178 EfiConfigurationTable,\r
179 gDxeCoreST->ConfigurationTable,\r
180 Index * sizeof (EFI_CONFIGURATION_TABLE)\r
181 );\r
182\r
183 //\r
184 // Free Old Table\r
185 //\r
186 CoreFreePool (gDxeCoreST->ConfigurationTable);\r
187 }\r
188\r
189 //\r
190 // Update System Table\r
191 //\r
192 gDxeCoreST->ConfigurationTable = EfiConfigurationTable;\r
193 }\r
194\r
195 //\r
196 // Fill in the new entry\r
197 //\r
198 CopyMem ((VOID *)&EfiConfigurationTable[Index].VendorGuid, Guid, sizeof (EFI_GUID));\r
199 EfiConfigurationTable[Index].VendorTable = Table;\r
200\r
201 //\r
202 // This is an add operation, so increment the number of table entries\r
203 //\r
204 gDxeCoreST->NumberOfTableEntries++;\r
205 }\r
206\r
207 //\r
208 // Fix up the CRC-32 in the EFI System Table\r
209 //\r
210 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
211\r
212 //\r
213 // Signal Configuration Table change\r
214 //\r
215 CoreNotifySignalList (Guid);\r
216\r
217 return EFI_SUCCESS;\r
218}\r