e42e9404 |
1 | /** @file\r |
2 | System Management System Table Services SmmInstallConfigurationTable service\r |
3 | \r |
cd5ebaa0 |
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r |
e42e9404 |
5 | This program and the accompanying materials are licensed and made available \r |
6 | under the terms and conditions of the BSD License which accompanies this \r |
7 | distribution. The full text of the license may be found at \r |
8 | http://opensource.org/licenses/bsd-license.php \r |
9 | \r |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r |
12 | \r |
13 | **/\r |
14 | \r |
15 | #include "PiSmmCore.h"\r |
16 | \r |
17 | #define CONFIG_TABLE_SIZE_INCREASED 0x10\r |
18 | \r |
19 | UINTN mSmmSystemTableAllocateSize = 0;\r |
20 | \r |
21 | /**\r |
22 | The SmmInstallConfigurationTable() function is used to maintain the list\r |
23 | of configuration tables that are stored in the System Management System\r |
24 | Table. The list is stored as an array of (GUID, Pointer) pairs. The list\r |
25 | must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.\r |
26 | \r |
27 | @param SystemTable A pointer to the SMM System Table (SMST).\r |
28 | @param Guid A pointer to the GUID for the entry to add, update, or remove.\r |
29 | @param Table A pointer to the buffer of the table to add.\r |
30 | @param TableSize The size of the table to install.\r |
31 | \r |
32 | @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.\r |
33 | @retval EFI_INVALID_PARAMETER Guid is not valid.\r |
34 | @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.\r |
35 | @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.\r |
36 | \r |
37 | **/\r |
38 | EFI_STATUS\r |
39 | EFIAPI\r |
40 | SmmInstallConfigurationTable (\r |
41 | IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,\r |
42 | IN CONST EFI_GUID *Guid,\r |
43 | IN VOID *Table,\r |
44 | IN UINTN TableSize\r |
45 | )\r |
46 | {\r |
47 | UINTN Index;\r |
48 | EFI_CONFIGURATION_TABLE *ConfigurationTable;\r |
49 | \r |
50 | //\r |
51 | // If Guid is NULL, then this operation cannot be performed\r |
52 | //\r |
53 | if (Guid == NULL) {\r |
54 | return EFI_INVALID_PARAMETER;\r |
55 | }\r |
56 | \r |
57 | ConfigurationTable = gSmmCoreSmst.SmmConfigurationTable;\r |
58 | \r |
59 | //\r |
60 | // Search all the table for an entry that matches Guid\r |
61 | //\r |
62 | for (Index = 0; Index < gSmmCoreSmst.NumberOfTableEntries; Index++) {\r |
63 | if (CompareGuid (Guid, &(ConfigurationTable[Index].VendorGuid))) {\r |
64 | break;\r |
65 | }\r |
66 | }\r |
67 | \r |
68 | if (Index < gSmmCoreSmst.NumberOfTableEntries) {\r |
69 | //\r |
70 | // A match was found, so this is either a modify or a delete operation\r |
71 | //\r |
72 | if (Table != NULL) {\r |
73 | //\r |
74 | // If Table is not NULL, then this is a modify operation.\r |
75 | // Modify the table enty and return.\r |
76 | //\r |
77 | ConfigurationTable[Index].VendorTable = Table;\r |
78 | return EFI_SUCCESS;\r |
79 | }\r |
80 | \r |
81 | //\r |
82 | // A match was found and Table is NULL, so this is a delete operation.\r |
83 | //\r |
84 | gSmmCoreSmst.NumberOfTableEntries--;\r |
85 | \r |
86 | //\r |
87 | // Copy over deleted entry\r |
88 | //\r |
89 | CopyMem (\r |
90 | &(ConfigurationTable[Index]),\r |
91 | &(ConfigurationTable[Index + 1]),\r |
92 | (gSmmCoreSmst.NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)\r |
93 | );\r |
94 | \r |
95 | } else {\r |
96 | //\r |
97 | // No matching GUIDs were found, so this is an add operation.\r |
98 | //\r |
99 | if (Table == NULL) {\r |
100 | //\r |
101 | // If Table is NULL on an add operation, then return an error.\r |
102 | //\r |
103 | return EFI_NOT_FOUND;\r |
104 | }\r |
105 | \r |
106 | //\r |
107 | // Assume that Index == gSmmCoreSmst.NumberOfTableEntries\r |
108 | //\r |
109 | if ((Index * sizeof (EFI_CONFIGURATION_TABLE)) >= mSmmSystemTableAllocateSize) {\r |
110 | //\r |
111 | // Allocate a table with one additional entry.\r |
112 | //\r |
113 | mSmmSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE));\r |
114 | ConfigurationTable = AllocatePool (mSmmSystemTableAllocateSize);\r |
115 | if (ConfigurationTable == NULL) {\r |
116 | //\r |
117 | // If a new table could not be allocated, then return an error.\r |
118 | //\r |
119 | return EFI_OUT_OF_RESOURCES;\r |
120 | }\r |
121 | \r |
122 | if (gSmmCoreSmst.SmmConfigurationTable != NULL) {\r |
123 | //\r |
124 | // Copy the old table to the new table.\r |
125 | //\r |
126 | CopyMem (\r |
127 | ConfigurationTable,\r |
128 | gSmmCoreSmst.SmmConfigurationTable,\r |
129 | Index * sizeof (EFI_CONFIGURATION_TABLE)\r |
130 | );\r |
131 | \r |
132 | //\r |
133 | // Free Old Table\r |
134 | //\r |
135 | FreePool (gSmmCoreSmst.SmmConfigurationTable);\r |
136 | }\r |
137 | \r |
138 | //\r |
139 | // Update System Table\r |
140 | //\r |
141 | gSmmCoreSmst.SmmConfigurationTable = ConfigurationTable;\r |
142 | }\r |
143 | \r |
144 | //\r |
145 | // Fill in the new entry\r |
146 | //\r |
147 | CopyGuid ((VOID *)&ConfigurationTable[Index].VendorGuid, Guid);\r |
148 | ConfigurationTable[Index].VendorTable = Table;\r |
149 | \r |
150 | //\r |
151 | // This is an add operation, so increment the number of table entries\r |
152 | //\r |
153 | gSmmCoreSmst.NumberOfTableEntries++;\r |
154 | }\r |
155 | \r |
156 | //\r |
157 | // CRC-32 field is ignorable for SMM System Table and should be set to zero\r |
158 | //\r |
159 | \r |
160 | return EFI_SUCCESS;\r |
161 | }\r |