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