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