EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

MdeModulePkg/Core/PiSmmCore/InstallConfigurationTable.c

Go to the documentation of this file.
00001 
00015 #include "PiSmmCore.h"
00016 
00017 #define CONFIG_TABLE_SIZE_INCREASED 0x10
00018 
00019 UINTN  mSmmSystemTableAllocateSize = 0;
00020 
00038 EFI_STATUS
00039 EFIAPI
00040 SmmInstallConfigurationTable (
00041   IN  CONST EFI_SMM_SYSTEM_TABLE2  *SystemTable,
00042   IN  CONST EFI_GUID               *Guid,
00043   IN  VOID                         *Table,
00044   IN  UINTN                        TableSize
00045   )
00046 {
00047   UINTN                    Index;
00048   EFI_CONFIGURATION_TABLE  *ConfigurationTable;
00049 
00050   //
00051   // If Guid is NULL, then this operation cannot be performed
00052   //
00053   if (Guid == NULL) {
00054     return EFI_INVALID_PARAMETER;
00055   }
00056 
00057   ConfigurationTable = gSmmCoreSmst.SmmConfigurationTable;
00058 
00059   //
00060   // Search all the table for an entry that matches Guid
00061   //
00062   for (Index = 0; Index < gSmmCoreSmst.NumberOfTableEntries; Index++) {
00063     if (CompareGuid (Guid, &(ConfigurationTable[Index].VendorGuid))) {
00064       break;
00065     }
00066   }
00067 
00068   if (Index < gSmmCoreSmst.NumberOfTableEntries) {
00069     //
00070     // A match was found, so this is either a modify or a delete operation
00071     //
00072     if (Table != NULL) {
00073       //
00074       // If Table is not NULL, then this is a modify operation.
00075       // Modify the table enty and return.
00076       //
00077       ConfigurationTable[Index].VendorTable = Table;
00078       return EFI_SUCCESS;
00079     }
00080 
00081     //
00082     // A match was found and Table is NULL, so this is a delete operation.
00083     //
00084     gSmmCoreSmst.NumberOfTableEntries--;
00085 
00086     //
00087     // Copy over deleted entry
00088     //
00089     CopyMem (
00090       &(ConfigurationTable[Index]),
00091       &(ConfigurationTable[Index + 1]),
00092       (gSmmCoreSmst.NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)
00093       );
00094 
00095   } else {
00096     //
00097     // No matching GUIDs were found, so this is an add operation.
00098     //
00099     if (Table == NULL) {
00100       //
00101       // If Table is NULL on an add operation, then return an error.
00102       //
00103       return EFI_NOT_FOUND;
00104     }
00105 
00106     //
00107     // Assume that Index == gSmmCoreSmst.NumberOfTableEntries
00108     //
00109     if ((Index * sizeof (EFI_CONFIGURATION_TABLE)) >= mSmmSystemTableAllocateSize) {
00110       //
00111       // Allocate a table with one additional entry.
00112       //
00113       mSmmSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE));
00114       ConfigurationTable = AllocatePool (mSmmSystemTableAllocateSize);
00115       if (ConfigurationTable == NULL) {
00116         //
00117         // If a new table could not be allocated, then return an error.
00118         //
00119         return EFI_OUT_OF_RESOURCES;
00120       }
00121 
00122       if (gSmmCoreSmst.SmmConfigurationTable != NULL) {
00123         //
00124         // Copy the old table to the new table.
00125         //
00126         CopyMem (
00127           ConfigurationTable,
00128           gSmmCoreSmst.SmmConfigurationTable,
00129           Index * sizeof (EFI_CONFIGURATION_TABLE)
00130           );
00131 
00132         //
00133         // Free Old Table
00134         //
00135         FreePool (gSmmCoreSmst.SmmConfigurationTable);
00136       }
00137 
00138       //
00139       // Update System Table
00140       //
00141       gSmmCoreSmst.SmmConfigurationTable = ConfigurationTable;
00142     }
00143 
00144     //
00145     // Fill in the new entry
00146     //
00147     CopyGuid ((VOID *)&ConfigurationTable[Index].VendorGuid, Guid);
00148     ConfigurationTable[Index].VendorTable = Table;
00149 
00150     //
00151     // This is an add operation, so increment the number of table entries
00152     //
00153     gSmmCoreSmst.NumberOfTableEntries++;
00154   }
00155 
00156   //
00157   // CRC-32 field is ignorable for SMM System Table and should be set to zero
00158   //
00159 
00160   return EFI_SUCCESS;
00161 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines