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