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