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