]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | InstallConfigurationTable.c\r | |
15 | \r | |
16 | \r | |
17 | Abstract:\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 | |
27 | UINTN mSystemTableAllocateSize = 0;\r | |
28 | \r | |
29 | \r | |
30 | EFI_STATUS\r | |
31 | CoreGetConfigTable (\r | |
32 | IN EFI_GUID *Guid,\r | |
33 | OUT VOID **Table\r | |
34 | )\r | |
35 | /*++\r | |
36 | \r | |
37 | Routine Description:\r | |
38 | \r | |
39 | Find a config table by name in system table's ConfigurationTable.\r | |
40 | \r | |
41 | Arguments:\r | |
42 | \r | |
43 | Guid - The table name to look for\r | |
44 | \r | |
45 | Table - Pointer of the config table\r | |
46 | \r | |
47 | Returns: \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 | |
57 | for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r | |
58 | if (CompareGuid (Guid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r | |
59 | *Table = gST->ConfigurationTable[Index].VendorTable;\r | |
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 | |
69 | EFI_STATUS\r | |
70 | EFIAPI\r | |
71 | CoreInstallConfigurationTable (\r | |
72 | IN EFI_GUID *Guid,\r | |
73 | IN VOID *Table\r | |
74 | )\r | |
75 | /*++\r | |
76 | \r | |
77 | Routine 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 | |
82 | Arguments:\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 | |
88 | Returns:\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 | |
107 | EfiConfigurationTable = gST->ConfigurationTable;\r | |
108 | \r | |
109 | //\r | |
110 | // Search all the table for an entry that matches Guid\r | |
111 | //\r | |
112 | for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r | |
113 | if (CompareGuid (Guid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r | |
114 | break;\r | |
115 | }\r | |
116 | }\r | |
117 | \r | |
118 | if (Index < gST->NumberOfTableEntries) {\r | |
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 | |
127 | gST->ConfigurationTable[Index].VendorTable = Table;\r | |
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 | |
134 | gST->NumberOfTableEntries--;\r | |
135 | \r | |
136 | //\r | |
137 | // Copy over deleted entry\r | |
138 | //\r | |
139 | CopyMem (\r | |
140 | &(EfiConfigurationTable[Index]),\r | |
141 | &(gST->ConfigurationTable[Index + 1]),\r | |
142 | (gST->NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)\r | |
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 | |
159 | // Assume that Index == gST->NumberOfTableEntries\r | |
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 | |
174 | if (gST->ConfigurationTable != NULL) {\r | |
175 | //\r | |
176 | // Copy the old table to the new table.\r | |
177 | //\r | |
178 | CopyMem (\r | |
179 | EfiConfigurationTable,\r | |
180 | gST->ConfigurationTable,\r | |
181 | Index * sizeof (EFI_CONFIGURATION_TABLE)\r | |
182 | );\r | |
183 | \r | |
184 | //\r | |
185 | // Free Old Table\r | |
186 | //\r | |
187 | CoreFreePool (gST->ConfigurationTable);\r | |
188 | }\r | |
189 | \r | |
190 | //\r | |
191 | // Update System Table\r | |
192 | //\r | |
193 | gST->ConfigurationTable = EfiConfigurationTable;\r | |
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 | |
205 | gST->NumberOfTableEntries++;\r | |
206 | }\r | |
207 | \r | |
208 | //\r | |
209 | // Fix up the CRC-32 in the EFI System Table\r | |
210 | //\r | |
211 | CalculateEfiHdrCrc (&gST->Hdr);\r | |
212 | \r | |
213 | return EFI_SUCCESS;\r | |
214 | }\r |