cfgtable.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. cfgtable.c
  5. Abstract:
  6. This module implements the install configuration table UEFI service.
  7. Author:
  8. Evan Green 25-Mar-2014
  9. Environment:
  10. Firmware
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include "ueficore.h"
  16. //
  17. // ---------------------------------------------------------------- Definitions
  18. //
  19. #define EFI_CONFIGURATION_TABLE_EXPANSION_SIZE 0x10
  20. //
  21. // ------------------------------------------------------ Data Type Definitions
  22. //
  23. //
  24. // ----------------------------------------------- Internal Function Prototypes
  25. //
  26. //
  27. // -------------------------------------------------------------------- Globals
  28. //
  29. //
  30. // Store the size of the configuration table array allocation.
  31. //
  32. UINTN EfiSystemTableAllocationSize = 0;
  33. //
  34. // ------------------------------------------------------------------ Functions
  35. //
  36. EFIAPI
  37. EFI_STATUS
  38. EfiCoreInstallConfigurationTable (
  39. EFI_GUID *Guid,
  40. VOID *Table
  41. )
  42. /*++
  43. Routine Description:
  44. This routine adds, updates, or removes a configuration table entry from the
  45. EFI System Table.
  46. Arguments:
  47. Guid - Supplies a pointer to the GUID for the entry to add, update, or
  48. remove.
  49. Table - Supplies a pointer to the configuration table for the entry to add,
  50. update, or remove. This may be NULL.
  51. Return Value:
  52. EFI_SUCCESS on success.
  53. EFI_NOT_FOUND if an attempt was made to delete a nonexistant entry.
  54. EFI_INVALID_PARAMETER if the GUID is NULL.
  55. EFI_OUT_OF_RESOURCES if an allocation failed.
  56. --*/
  57. {
  58. EFI_CONFIGURATION_TABLE *ConfigurationTable;
  59. UINTN Index;
  60. BOOLEAN Match;
  61. UINTN NewSize;
  62. UINTN RemainderSize;
  63. if (Guid == NULL) {
  64. return EFI_INVALID_PARAMETER;
  65. }
  66. ConfigurationTable = EfiSystemTable->ConfigurationTable;
  67. //
  68. // Search all the tables for an entry that matches this one.
  69. //
  70. for (Index = 0; Index < EfiSystemTable->NumberOfTableEntries; Index += 1) {
  71. Match = EfiCoreCompareGuids(
  72. Guid,
  73. &(EfiSystemTable->ConfigurationTable[Index].VendorGuid));
  74. if (Match != FALSE) {
  75. break;
  76. }
  77. }
  78. //
  79. // If a match was found, then this is either a modify or a delete operation.
  80. //
  81. if (Index < EfiSystemTable->NumberOfTableEntries) {
  82. if (Table != NULL) {
  83. EfiSystemTable->ConfigurationTable[Index].VendorTable = Table;
  84. //
  85. // Signal a configuration table change.
  86. //
  87. EfipCoreNotifySignalList(Guid);
  88. return EFI_SUCCESS;
  89. }
  90. EfiSystemTable->NumberOfTableEntries -= 1;
  91. RemainderSize = (EfiSystemTable->NumberOfTableEntries - Index) *
  92. sizeof(EFI_CONFIGURATION_TABLE);
  93. EfiCopyMem(&(ConfigurationTable[Index]),
  94. &(EfiSystemTable->ConfigurationTable[Index + 1]),
  95. RemainderSize);
  96. //
  97. // No matching GUID was found, this is an add operation.
  98. //
  99. } else {
  100. if (Table == NULL) {
  101. return EFI_NOT_FOUND;
  102. }
  103. Index = EfiSystemTable->NumberOfTableEntries;
  104. if ((Index * sizeof(EFI_CONFIGURATION_TABLE)) >=
  105. EfiSystemTableAllocationSize) {
  106. NewSize = EfiSystemTableAllocationSize +
  107. (EFI_CONFIGURATION_TABLE_EXPANSION_SIZE *
  108. sizeof(EFI_CONFIGURATION_TABLE));
  109. ConfigurationTable = EfiCoreAllocateRuntimePool(NewSize);
  110. if (ConfigurationTable == NULL) {
  111. return EFI_OUT_OF_RESOURCES;
  112. }
  113. if (EfiSystemTable->ConfigurationTable != NULL) {
  114. ASSERT(EfiSystemTableAllocationSize != 0);
  115. EfiCopyMem(ConfigurationTable,
  116. EfiSystemTable->ConfigurationTable,
  117. Index * sizeof(EFI_CONFIGURATION_TABLE));
  118. EfiFreePool(EfiSystemTable->ConfigurationTable);
  119. }
  120. EfiSystemTable->ConfigurationTable = ConfigurationTable;
  121. EfiSystemTableAllocationSize = NewSize;
  122. }
  123. //
  124. // Fill in the new entry.
  125. //
  126. EfiCopyMem(&(ConfigurationTable[Index].VendorGuid),
  127. Guid,
  128. sizeof(EFI_GUID));
  129. ConfigurationTable[Index].VendorTable = Table;
  130. EfiSystemTable->NumberOfTableEntries += 1;
  131. }
  132. EfiCoreCalculateTableCrc32(&(EfiSystemTable->Hdr));
  133. EfipCoreNotifySignalList(Guid);
  134. return EFI_SUCCESS;
  135. }
  136. //
  137. // --------------------------------------------------------- Internal Functions
  138. //