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