X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FSmbiosDxe%2FSmbiosDxe.c;h=809dff84ac9b42abd48b4244404c8732863bea4d;hb=5efb28784f422debfe310b210a84b6334689c4d2;hp=c15ecb54fa693407da0cf9bb4595588c8c5c0c82;hpb=f93161b4403382ac7e22203af2ac452c54083b8b;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c index c15ecb54fa..809dff84ac 100644 --- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c +++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c @@ -2,7 +2,7 @@ This code produces the Smbios protocol. It also responsible for constructing SMBIOS table into system table. -Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -22,6 +22,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // SMBIOS_INSTANCE mPrivateData; +UINTN mPreAllocatedPages = 0; +UINTN mPre64BitAllocatedPages = 0; + // // Chassis for SMBIOS entry point structure that is to be installed into EFI system config table. // @@ -47,11 +50,11 @@ SMBIOS_TABLE_ENTRY_POINT EntryPointStructureData = { // // MajorVersion // - (UINT8) (FixedPcdGet16 (PcdSmbiosVersion) >> 8), + 0, // // MinorVersion // - (UINT8) (FixedPcdGet16 (PcdSmbiosVersion) & 0x00ff), + 0, // // MaxStructureSize, TO BE FILLED // @@ -85,11 +88,11 @@ SMBIOS_TABLE_ENTRY_POINT EntryPointStructureData = { // 0, // - // StructureTableLength, TO BE FILLED + // TableLength, TO BE FILLED // 0, // - // StructureTableAddress, TO BE FILLED + // TableAddress, TO BE FILLED // 0, // @@ -99,10 +102,58 @@ SMBIOS_TABLE_ENTRY_POINT EntryPointStructureData = { // // SmbiosBcdRevision // - 0 + 0 }; - +SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios30EntryPointStructure = NULL; +SMBIOS_TABLE_3_0_ENTRY_POINT Smbios30EntryPointStructureData = { + // + // AnchorString _SM3_ + // + { + 0x5f, + 0x53, + 0x4d, + 0x33, + 0x5f, + }, + // + // EntryPointStructureChecksum,TO BE FILLED + // + 0, + // + // EntryPointLength + // + 0x18, + // + // MajorVersion + // + 0, + // + // MinorVersion + // + 0, + // + // DocRev + // + 0, + // + // EntryPointRevision + // + 0x01, + // + // Reserved + // + 0, + // + // TableMaximumSize,TO BE FILLED + // + 0, + // + // TableAddress,TO BE FILLED + // + 0 +}; /** Get the full size of SMBIOS structure including optional strings that follow the formatted structure. @@ -126,7 +177,8 @@ GetSmbiosStructureSize ( ) { UINTN FullSize; - UINT8 StrLen; + UINTN StrLen; + UINTN MaxLen; INT8* CharInStr; if (Size == NULL || NumberOfStrings == NULL) { @@ -148,26 +200,33 @@ GetSmbiosStructureSize ( } if (This->MajorVersion < 2 || (This->MajorVersion == 2 && This->MinorVersion < 7)){ - for (StrLen = 0 ; StrLen < SMBIOS_STRING_MAX_LENGTH; StrLen++) { - if (*(CharInStr+StrLen) == 0) { - break; - } - } - - if (StrLen == SMBIOS_STRING_MAX_LENGTH) { - return EFI_INVALID_PARAMETER; - } + MaxLen = SMBIOS_STRING_MAX_LENGTH; + } else if (This->MajorVersion < 3) { + // + // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the length of each individual text string. + // However, the length of the entire structure table (including all strings) must be reported + // in the Structure Table Length field of the SMBIOS Structure Table Entry Point, + // which is a WORD field limited to 65,535 bytes. + // + MaxLen = SMBIOS_TABLE_MAX_LENGTH; } else { // - // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the length of each individual text string + // SMBIOS 3.0 defines the Structure table maximum size as DWORD field limited to 0xFFFFFFFF bytes. + // Locate the end of string as long as possible. // - for (StrLen = 0 ;; StrLen++) { - if (*(CharInStr+StrLen) == 0) { - break; - } + MaxLen = SMBIOS_3_0_TABLE_MAX_LENGTH; + } + + for (StrLen = 0 ; StrLen < MaxLen; StrLen++) { + if (*(CharInStr+StrLen) == 0) { + break; } } + if (StrLen == MaxLen) { + return EFI_INVALID_PARAMETER; + } + // // forward the pointer // @@ -263,7 +322,7 @@ GetAvailableSmbiosHandle ( Private = SMBIOS_INSTANCE_FROM_THIS (This); Head = &Private->AllocatedHandleListHead; - for (AvailableHandle = 1; AvailableHandle < MaxSmbiosHandle; AvailableHandle++) { + for (AvailableHandle = 0; AvailableHandle < MaxSmbiosHandle; AvailableHandle++) { if (!CheckSmbiosHandleExistance(Head, AvailableHandle)) { *Handle = AvailableHandle; return EFI_SUCCESS; @@ -280,8 +339,8 @@ GetAvailableSmbiosHandle ( @param This The EFI_SMBIOS_PROTOCOL instance. @param ProducerHandle The handle of the controller or driver associated with the SMBIOS information. NULL means no handle. - @param SmbiosHandle On entry, if non-zero, the handle of the SMBIOS record. If zero, then a unique handle - will be assigned to the SMBIOS record. If the SMBIOS handle is already in use + @param SmbiosHandle On entry, the handle of the SMBIOS record to add. If FFFEh, then a unique handle + will be assigned to the SMBIOS record. If the SMBIOS handle is already in use, EFI_ALREADY_STARTED is returned and the SMBIOS record is not updated. @param Record The data for the fixed portion of the SMBIOS record. The format of the record is determined by EFI_SMBIOS_TABLE_HEADER.Type. The size of the formatted area is defined @@ -314,6 +373,8 @@ SmbiosAdd ( EFI_SMBIOS_HANDLE MaxSmbiosHandle; SMBIOS_HANDLE_ENTRY *HandleEntry; EFI_SMBIOS_RECORD_HEADER *InternalRecord; + BOOLEAN Smbios32BitTable; + BOOLEAN Smbios64BitTable; if (SmbiosHandle == NULL) { return EFI_INVALID_PARAMETER; @@ -324,14 +385,14 @@ SmbiosAdd ( // Check whether SmbiosHandle is already in use // Head = &Private->AllocatedHandleListHead; - if (*SmbiosHandle != 0 && CheckSmbiosHandleExistance(Head, *SmbiosHandle)) { + if (*SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED && CheckSmbiosHandleExistance(Head, *SmbiosHandle)) { return EFI_ALREADY_STARTED; } // - // when SmbiosHandle is zero, an available handle will be assigned + // when SmbiosHandle is 0xFFFE, an available handle will be assigned // - if (*SmbiosHandle == 0) { + if (*SmbiosHandle == SMBIOS_HANDLE_PI_RESERVED) { Status = GetAvailableSmbiosHandle(This, SmbiosHandle); if (EFI_ERROR(Status)) { return Status; @@ -354,6 +415,48 @@ SmbiosAdd ( return Status; } + Smbios32BitTable = FALSE; + Smbios64BitTable = FALSE; + if ((This->MajorVersion < 0x3) || + ((This->MajorVersion >= 0x3) && ((PcdGet32 (PcdSmbiosEntryPointProvideMethod) & BIT0) == BIT0))) { + // + // For SMBIOS 32-bit table, the length of the entire structure table (including all strings) must be reported + // in the Structure Table Length field of the SMBIOS Structure Table Entry Point, + // which is a WORD field limited to 65,535 bytes. So the max size of 32-bit table should not exceed 65,535 bytes. + // + if ((EntryPointStructure != NULL) && + (EntryPointStructure->TableLength + StructureSize > SMBIOS_TABLE_MAX_LENGTH)) { + DEBUG ((EFI_D_INFO, "SmbiosAdd: Total length exceeds max 32-bit table length with type = %d size = 0x%x\n", Record->Type, StructureSize)); + } else { + Smbios32BitTable = TRUE; + DEBUG ((EFI_D_INFO, "SmbiosAdd: Smbios type %d with size 0x%x is added to 32-bit table\n", Record->Type, StructureSize)); + } + } + + // + // For SMBIOS 3.0, Structure table maximum size in Entry Point structure is DWORD field limited to 0xFFFFFFFF bytes. + // + if ((This->MajorVersion >= 0x3) && ((PcdGet32 (PcdSmbiosEntryPointProvideMethod) & BIT1) == BIT1)) { + // + // For SMBIOS 64-bit table, Structure table maximum size in SMBIOS 3.0 (64-bit) Entry Point + // is a DWORD field limited to 0xFFFFFFFF bytes. So the max size of 64-bit table should not exceed 0xFFFFFFFF bytes. + // + if ((Smbios30EntryPointStructure != NULL) && + (Smbios30EntryPointStructure->TableMaximumSize + StructureSize > SMBIOS_3_0_TABLE_MAX_LENGTH)) { + DEBUG ((EFI_D_INFO, "SmbiosAdd: Total length exceeds max 64-bit table length with type = %d size = 0x%x\n", Record->Type, StructureSize)); + } else { + DEBUG ((EFI_D_INFO, "SmbiosAdd: Smbios type %d with size 0x%x is added to 64-bit table\n", Record->Type, StructureSize)); + Smbios64BitTable = TRUE; + } + } + + if ((!Smbios32BitTable) && (!Smbios64BitTable)) { + // + // If both 32-bit and 64-bit table are not updated, quit + // + return EFI_OUT_OF_RESOURCES; + } + // // Enter into critical section // @@ -403,6 +506,8 @@ SmbiosAdd ( SmbiosEntry->Signature = EFI_SMBIOS_ENTRY_SIGNATURE; SmbiosEntry->RecordHeader = InternalRecord; SmbiosEntry->RecordSize = TotalSize; + SmbiosEntry->Smbios32BitTable = Smbios32BitTable; + SmbiosEntry->Smbios64BitTable = Smbios64BitTable; InsertTailList (&Private->DataListHead, &SmbiosEntry->Link); CopyMem (Raw, Record, StructureSize); @@ -414,7 +519,7 @@ SmbiosAdd ( // configuration table, so other UEFI drivers can get SMBIOS table from // configuration table without depending on PI SMBIOS protocol. // - SmbiosTableConstruction (); + SmbiosTableConstruction (Smbios32BitTable, Smbios64BitTable); // // Leave critical section @@ -433,7 +538,7 @@ SmbiosAdd ( @retval EFI_SUCCESS SmbiosHandle had its StringNumber String updated. @retval EFI_INVALID_PARAMETER SmbiosHandle does not exist. - @retval EFI_UNSUPPORTED String was not added since it's longer than 64 significant characters. + @retval EFI_UNSUPPORTED String was not added because it is longer than the SMBIOS Table supports. @retval EFI_NOT_FOUND The StringNumber.is not valid for this SMBIOS record. **/ @@ -482,13 +587,28 @@ SmbiosUpdateString ( InputStrLen = AsciiStrLen(String); - // - // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the length of each individual text string - // if (This->MajorVersion < 2 || (This->MajorVersion == 2 && This->MinorVersion < 7)) { if (InputStrLen > SMBIOS_STRING_MAX_LENGTH) { return EFI_UNSUPPORTED; } + } else if (This->MajorVersion < 3) { + // + // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the length of each individual text string. + // However, the length of the entire structure table (including all strings) must be reported + // in the Structure Table Length field of the SMBIOS Structure Table Entry Point, + // which is a WORD field limited to 65,535 bytes. + // + if (InputStrLen > SMBIOS_TABLE_MAX_LENGTH) { + return EFI_UNSUPPORTED; + } + } else { + if (InputStrLen > SMBIOS_3_0_TABLE_MAX_LENGTH) { + // + // SMBIOS 3.0 defines the Structure table maximum size as DWORD field limited to 0xFFFFFFFF bytes. + // The input string length should not exceed 0xFFFFFFFF bytes. + // + return EFI_UNSUPPORTED; + } } Private = SMBIOS_INSTANCE_FROM_THIS (This); @@ -545,17 +665,56 @@ SmbiosUpdateString ( // TargetStrLen = AsciiStrLen(StrStart); if (InputStrLen == TargetStrLen) { - AsciiStrCpy(StrStart, String); + AsciiStrCpyS(StrStart, TargetStrLen + 1, String); // // Some UEFI drivers (such as network) need some information in SMBIOS table. // Here we create SMBIOS table and publish it in // configuration table, so other UEFI drivers can get SMBIOS table from // configuration table without depending on PI SMBIOS protocol. // - SmbiosTableConstruction (); + SmbiosTableConstruction (SmbiosEntry->Smbios32BitTable, SmbiosEntry->Smbios64BitTable); EfiReleaseLock (&Private->DataLock); return EFI_SUCCESS; } + + SmbiosEntry->Smbios32BitTable = FALSE; + SmbiosEntry->Smbios64BitTable = FALSE; + if ((This->MajorVersion < 0x3) || + ((This->MajorVersion >= 0x3) && ((PcdGet32 (PcdSmbiosEntryPointProvideMethod) & BIT0) == BIT0))) { + // + // 32-bit table is produced, check the valid length. + // + if ((EntryPointStructure != NULL) && + (EntryPointStructure->TableLength + InputStrLen - TargetStrLen > SMBIOS_TABLE_MAX_LENGTH)) { + // + // The length of the entire structure table (including all strings) must be reported + // in the Structure Table Length field of the SMBIOS Structure Table Entry Point, + // which is a WORD field limited to 65,535 bytes. + // + DEBUG ((EFI_D_INFO, "SmbiosUpdateString: Total length exceeds max 32-bit table length\n")); + } else { + DEBUG ((EFI_D_INFO, "SmbiosUpdateString: New smbios record add to 32-bit table\n")); + SmbiosEntry->Smbios32BitTable = TRUE; + } + } + + if ((This->MajorVersion >= 0x3) && ((PcdGet32 (PcdSmbiosEntryPointProvideMethod) & BIT1) == BIT1)) { + // + // 64-bit table is produced, check the valid length. + // + if ((Smbios30EntryPointStructure != NULL) && + (Smbios30EntryPointStructure->TableMaximumSize + InputStrLen - TargetStrLen > SMBIOS_3_0_TABLE_MAX_LENGTH)) { + DEBUG ((EFI_D_INFO, "SmbiosUpdateString: Total length exceeds max 64-bit table length\n")); + } else { + DEBUG ((EFI_D_INFO, "SmbiosUpdateString: New smbios record add to 64-bit table\n")); + SmbiosEntry->Smbios64BitTable = TRUE; + } + } + + if ((!SmbiosEntry->Smbios32BitTable) && (!SmbiosEntry->Smbios64BitTable)) { + EfiReleaseLock (&Private->DataLock); + return EFI_UNSUPPORTED; + } // // Original string buffer size is not exactly match input string length. @@ -596,6 +755,8 @@ SmbiosUpdateString ( ResizedSmbiosEntry->Signature = EFI_SMBIOS_ENTRY_SIGNATURE; ResizedSmbiosEntry->RecordHeader = InternalRecord; ResizedSmbiosEntry->RecordSize = NewEntrySize; + ResizedSmbiosEntry->Smbios32BitTable = SmbiosEntry->Smbios32BitTable; + ResizedSmbiosEntry->Smbios64BitTable = SmbiosEntry->Smbios64BitTable; InsertTailList (Link->ForwardLink, &ResizedSmbiosEntry->Link); // @@ -609,7 +770,7 @@ SmbiosUpdateString ( // configuration table, so other UEFI drivers can get SMBIOS table from // configuration table without depending on PI SMBIOS protocol. // - SmbiosTableConstruction (); + SmbiosTableConstruction (ResizedSmbiosEntry->Smbios32BitTable, ResizedSmbiosEntry->Smbios64BitTable); EfiReleaseLock (&Private->DataLock); return EFI_SUCCESS; } @@ -672,7 +833,6 @@ SmbiosRemove ( // Remove specified smobios record from DataList // RemoveEntryList(Link); - FreePool(SmbiosEntry); // // Remove this handle from AllocatedHandleList // @@ -691,7 +851,17 @@ SmbiosRemove ( // configuration table, so other UEFI drivers can get SMBIOS table from // configuration table without depending on PI SMBIOS protocol. // - SmbiosTableConstruction (); + if (SmbiosEntry->Smbios32BitTable) { + DEBUG ((EFI_D_INFO, "SmbiosRemove: remove from 32-bit table\n")); + } + if (SmbiosEntry->Smbios64BitTable) { + DEBUG ((EFI_D_INFO, "SmbiosRemove: remove from 64-bit table\n")); + } + // + // Update the whole SMBIOS table again based on which table the removed SMBIOS record is in. + // + SmbiosTableConstruction (SmbiosEntry->Smbios32BitTable, SmbiosEntry->Smbios64BitTable); + FreePool(SmbiosEntry); EfiReleaseLock (&Private->DataLock); return EFI_SUCCESS; } @@ -710,8 +880,8 @@ SmbiosRemove ( @param This The EFI_SMBIOS_PROTOCOL instance. @param SmbiosHandle On entry, points to the previous handle of the SMBIOS record. On exit, points to the - next SMBIOS record handle. If it is zero on entry, then the first SMBIOS record - handle will be returned. If it returns zero on exit, then there are no more SMBIOS records. + next SMBIOS record handle. If it is FFFEh on entry, then the first SMBIOS record + handle will be returned. If it returns FFFEh on exit, then there are no more SMBIOS records. @param Type On entry it means return the next SMBIOS record of type Type. If a NULL is passed in this functionally it ignored. Type is not modified by the GetNext() function. @param Record On exit, points to the SMBIOS Record consisting of the formatted area followed by @@ -752,9 +922,9 @@ SmbiosGetNext ( SmbiosTableHeader = (EFI_SMBIOS_TABLE_HEADER*)(SmbiosEntry->RecordHeader + 1); // - // If SmbiosHandle is zero, the first matched SMBIOS record handle will be returned + // If SmbiosHandle is 0xFFFE, the first matched SMBIOS record handle will be returned // - if (*SmbiosHandle == 0) { + if (*SmbiosHandle == SMBIOS_HANDLE_PI_RESERVED) { if ((Type != NULL) && (*Type != SmbiosTableHeader->Type)) { continue; } @@ -790,7 +960,7 @@ SmbiosGetNext ( } } - *SmbiosHandle = 0; + *SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; return EFI_NOT_FOUND; } @@ -859,7 +1029,6 @@ GetNextSmbiosRecord ( @param TableEntryPointStructure On exit, points to the SMBIOS entrypoint structure. @retval EFI_SUCCESS Structure created sucessfully. - @retval EFI_NOT_READY Some of The SMBIOS records was not available yet. @retval EFI_OUT_OF_RESOURCES No enough memory. **/ @@ -879,18 +1048,54 @@ SmbiosCreateTable ( EFI_SMBIOS_TABLE_HEADER *SmbiosRecord; EFI_SMBIOS_TABLE_END_STRUCTURE EndStructure; EFI_SMBIOS_ENTRY *CurrentSmbiosEntry; - UINTN PreAllocatedPages; Status = EFI_SUCCESS; BufferPointer = NULL; + if (EntryPointStructure == NULL) { + // + // Initialize the EntryPointStructure with initial values. + // It should be done only once. + // Allocate memory (below 4GB). + // + DEBUG ((EFI_D_INFO, "SmbiosCreateTable: Initialize 32-bit entry point structure\n")); + EntryPointStructureData.MajorVersion = mPrivateData.Smbios.MajorVersion; + EntryPointStructureData.MinorVersion = mPrivateData.Smbios.MinorVersion; + EntryPointStructureData.SmbiosBcdRevision = (UINT8) ((PcdGet16 (PcdSmbiosVersion) >> 4) & 0xf0) | (UINT8) (PcdGet16 (PcdSmbiosVersion) & 0x0f); + PhysicalAddress = 0xffffffff; + Status = gBS->AllocatePages ( + AllocateMaxAddress, + EfiRuntimeServicesData, + EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_ENTRY_POINT)), + &PhysicalAddress + ); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "SmbiosCreateTable () could not allocate EntryPointStructure < 4GB\n")); + Status = gBS->AllocatePages ( + AllocateAnyPages, + EfiRuntimeServicesData, + EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_ENTRY_POINT)), + &PhysicalAddress + ); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + } + + EntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *) (UINTN) PhysicalAddress; + + CopyMem ( + EntryPointStructure, + &EntryPointStructureData, + sizeof (SMBIOS_TABLE_ENTRY_POINT) + ); + } + // // Get Smbios protocol to traverse SMBIOS records. // SmbiosProtocol = &mPrivateData.Smbios; - PreAllocatedPages = EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength); - // // Make some statistics about all the structures // @@ -905,7 +1110,7 @@ SmbiosCreateTable ( do { Status = GetNextSmbiosRecord (SmbiosProtocol, &CurrentSmbiosEntry, &SmbiosRecord); - if (Status == EFI_SUCCESS) { + if ((Status == EFI_SUCCESS) && (CurrentSmbiosEntry->Smbios32BitTable)) { GetSmbiosStructureSize(SmbiosProtocol, SmbiosRecord, &RecordSize, &NumOfStr); // // Record NumberOfSmbiosStructures, TableLength and MaxStructureSize @@ -933,44 +1138,52 @@ SmbiosCreateTable ( EntryPointStructure->MaxStructureSize = (UINT16) sizeof (EndStructure); } - if ((UINTN) EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength) > PreAllocatedPages) { + if ((UINTN) EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength) > mPreAllocatedPages) { // - // If new SMBIOS talbe size exceeds the original pre-allocated page, + // If new SMBIOS table size exceeds the previous allocated page, // it is time to re-allocate memory (below 4GB). // + DEBUG ((EFI_D_INFO, "%a() re-allocate SMBIOS 32-bit table\n", + __FUNCTION__)); if (EntryPointStructure->TableAddress != 0) { // - // Free the original pre-allocated page + // Free the previous allocated page // FreePages ( (VOID*)(UINTN)EntryPointStructure->TableAddress, - PreAllocatedPages + mPreAllocatedPages ); EntryPointStructure->TableAddress = 0; + mPreAllocatedPages = 0; } PhysicalAddress = 0xffffffff; Status = gBS->AllocatePages ( AllocateMaxAddress, - EfiReservedMemoryType, + EfiRuntimeServicesData, EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength), &PhysicalAddress ); if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "SmbiosCreateTable() could not allocate SMBIOS table < 4GB\n")); + EntryPointStructure->TableAddress = 0; return EFI_OUT_OF_RESOURCES; + } else { + EntryPointStructure->TableAddress = (UINT32) PhysicalAddress; + mPreAllocatedPages = EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength); } - EntryPointStructure->TableAddress = (UINT32) PhysicalAddress; } // // Assemble the tables // + ASSERT (EntryPointStructure->TableAddress != 0); BufferPointer = (UINT8 *) (UINTN) EntryPointStructure->TableAddress; CurrentSmbiosEntry = NULL; do { Status = GetNextSmbiosRecord (SmbiosProtocol, &CurrentSmbiosEntry, &SmbiosRecord); - if (Status == EFI_SUCCESS) { + if ((Status == EFI_SUCCESS) && (CurrentSmbiosEntry->Smbios32BitTable)) { GetSmbiosStructureSize(SmbiosProtocol, SmbiosRecord, &RecordSize, &NumOfStr); CopyMem (BufferPointer, SmbiosRecord, RecordSize); BufferPointer = BufferPointer + RecordSize; @@ -985,6 +1198,9 @@ SmbiosCreateTable ( // // Fixup checksums in the Entry Point Structure // + EntryPointStructure->IntermediateChecksum = 0; + EntryPointStructure->EntryPointStructureChecksum = 0; + EntryPointStructure->IntermediateChecksum = CalculateCheckSum8 ((UINT8 *) EntryPointStructure + 0x10, EntryPointStructure->EntryPointLength - 0x10); EntryPointStructure->EntryPointStructureChecksum = @@ -999,20 +1215,202 @@ SmbiosCreateTable ( } /** - Create SMBIOS Table and install it to the System Table. + Assembles SMBIOS 64-bit table from the SMBIOS protocol. Produce Table + Entry Point and return the pointer to it. + + @param TableEntryPointStructure On exit, points to the SMBIOS entrypoint structure. + + @retval EFI_SUCCESS Structure created sucessfully. + @retval EFI_OUT_OF_RESOURCES No enough memory. + +**/ +EFI_STATUS +EFIAPI +SmbiosCreate64BitTable ( + OUT VOID **TableEntryPointStructure + ) +{ + UINT8 *BufferPointer; + UINTN RecordSize; + UINTN NumOfStr; + EFI_STATUS Status; + EFI_SMBIOS_HANDLE SmbiosHandle; + EFI_SMBIOS_PROTOCOL *SmbiosProtocol; + EFI_PHYSICAL_ADDRESS PhysicalAddress; + EFI_SMBIOS_TABLE_HEADER *SmbiosRecord; + EFI_SMBIOS_TABLE_END_STRUCTURE EndStructure; + EFI_SMBIOS_ENTRY *CurrentSmbiosEntry; + + Status = EFI_SUCCESS; + BufferPointer = NULL; + + if (Smbios30EntryPointStructure == NULL) { + // + // Initialize the Smbios30EntryPointStructure with initial values. + // It should be done only once. + // Allocate memory at any address. + // + DEBUG ((EFI_D_INFO, "SmbiosCreateTable: Initialize 64-bit entry point structure\n")); + Smbios30EntryPointStructureData.MajorVersion = mPrivateData.Smbios.MajorVersion; + Smbios30EntryPointStructureData.MinorVersion = mPrivateData.Smbios.MinorVersion; + Smbios30EntryPointStructureData.DocRev = PcdGet8 (PcdSmbiosDocRev); + Status = gBS->AllocatePages ( + AllocateAnyPages, + EfiRuntimeServicesData, + EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT)), + &PhysicalAddress + ); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "SmbiosCreate64BitTable() could not allocate Smbios30EntryPointStructure\n")); + return EFI_OUT_OF_RESOURCES; + } + + Smbios30EntryPointStructure = (SMBIOS_TABLE_3_0_ENTRY_POINT *) (UINTN) PhysicalAddress; + + CopyMem ( + Smbios30EntryPointStructure, + &Smbios30EntryPointStructureData, + sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT) + ); + } + + // + // Get Smbios protocol to traverse SMBIOS records. + // + SmbiosProtocol = &mPrivateData.Smbios; + Smbios30EntryPointStructure->TableMaximumSize = 0; + + // + // Calculate EPS Table Length + // + CurrentSmbiosEntry = NULL; + do { + Status = GetNextSmbiosRecord (SmbiosProtocol, &CurrentSmbiosEntry, &SmbiosRecord); + + if ((Status == EFI_SUCCESS) && (CurrentSmbiosEntry->Smbios64BitTable)) { + GetSmbiosStructureSize(SmbiosProtocol, SmbiosRecord, &RecordSize, &NumOfStr); + // + // Record TableMaximumSize + // + Smbios30EntryPointStructure->TableMaximumSize = (UINT32) (Smbios30EntryPointStructure->TableMaximumSize + RecordSize); + } + } while (!EFI_ERROR(Status)); + + // + // Create End-Of-Table structure + // + GetMaxSmbiosHandle(SmbiosProtocol, &SmbiosHandle); + EndStructure.Header.Type = EFI_SMBIOS_TYPE_END_OF_TABLE; + EndStructure.Header.Length = (UINT8) sizeof (EFI_SMBIOS_TABLE_HEADER); + EndStructure.Header.Handle = SmbiosHandle; + EndStructure.Tailing[0] = 0; + EndStructure.Tailing[1] = 0; + Smbios30EntryPointStructure->TableMaximumSize = (UINT32) (Smbios30EntryPointStructure->TableMaximumSize + sizeof (EndStructure)); + + if ((UINTN) EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize) > mPre64BitAllocatedPages) { + // + // If new SMBIOS table size exceeds the previous allocated page, + // it is time to re-allocate memory at anywhere. + // + DEBUG ((EFI_D_INFO, "%a() re-allocate SMBIOS 64-bit table\n", + __FUNCTION__)); + if (Smbios30EntryPointStructure->TableAddress != 0) { + // + // Free the previous allocated page + // + FreePages ( + (VOID*)(UINTN)Smbios30EntryPointStructure->TableAddress, + mPre64BitAllocatedPages + ); + Smbios30EntryPointStructure->TableAddress = 0; + mPre64BitAllocatedPages = 0; + } + + Status = gBS->AllocatePages ( + AllocateAnyPages, + EfiRuntimeServicesData, + EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize), + &PhysicalAddress + ); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "SmbiosCreateTable() could not allocate SMBIOS 64-bit table\n")); + Smbios30EntryPointStructure->TableAddress = 0; + return EFI_OUT_OF_RESOURCES; + } else { + Smbios30EntryPointStructure->TableAddress = PhysicalAddress; + mPre64BitAllocatedPages = EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize); + } + } + + // + // Assemble the tables + // + ASSERT (Smbios30EntryPointStructure->TableAddress != 0); + BufferPointer = (UINT8 *) (UINTN) Smbios30EntryPointStructure->TableAddress; + CurrentSmbiosEntry = NULL; + do { + Status = GetNextSmbiosRecord (SmbiosProtocol, &CurrentSmbiosEntry, &SmbiosRecord); + + if ((Status == EFI_SUCCESS) && (CurrentSmbiosEntry->Smbios64BitTable)) { + // + // This record can be added to 64-bit table + // + GetSmbiosStructureSize(SmbiosProtocol, SmbiosRecord, &RecordSize, &NumOfStr); + CopyMem (BufferPointer, SmbiosRecord, RecordSize); + BufferPointer = BufferPointer + RecordSize; + } + } while (!EFI_ERROR(Status)); + + // + // Assemble End-Of-Table structure + // + CopyMem (BufferPointer, &EndStructure, sizeof (EndStructure)); + + // + // Fixup checksums in the Entry Point Structure + // + Smbios30EntryPointStructure->EntryPointStructureChecksum = 0; + Smbios30EntryPointStructure->EntryPointStructureChecksum = + CalculateCheckSum8 ((UINT8 *) Smbios30EntryPointStructure, Smbios30EntryPointStructure->EntryPointLength); + + // + // Returns the pointer + // + *TableEntryPointStructure = Smbios30EntryPointStructure; + + return EFI_SUCCESS; +} + +/** + Create Smbios Table and installs the Smbios Table to the System Table. + + @param Smbios32BitTable The flag to update 32-bit table. + @param Smbios64BitTable The flag to update 64-bit table. + **/ VOID EFIAPI SmbiosTableConstruction ( - VOID + BOOLEAN Smbios32BitTable, + BOOLEAN Smbios64BitTable ) { UINT8 *Eps; + UINT8 *Eps64Bit; EFI_STATUS Status; - Status = SmbiosCreateTable ((VOID **) &Eps); - if (!EFI_ERROR (Status)) { - gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, Eps); + if (Smbios32BitTable) { + Status = SmbiosCreateTable ((VOID **) &Eps); + if (!EFI_ERROR (Status)) { + gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, Eps); + } + } + + if (Smbios64BitTable) { + Status = SmbiosCreate64BitTable ((VOID **) &Eps64Bit); + if (!EFI_ERROR (Status)) { + gBS->InstallConfigurationTable (&gEfiSmbios3TableGuid, Eps64Bit); + } } } @@ -1035,65 +1433,19 @@ SmbiosDriverEntryPoint ( ) { EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS PhysicalAddress; mPrivateData.Signature = SMBIOS_INSTANCE_SIGNATURE; mPrivateData.Smbios.Add = SmbiosAdd; mPrivateData.Smbios.UpdateString = SmbiosUpdateString; mPrivateData.Smbios.Remove = SmbiosRemove; mPrivateData.Smbios.GetNext = SmbiosGetNext; - mPrivateData.Smbios.MajorVersion = (UINT8) (FixedPcdGet16 (PcdSmbiosVersion) >> 8); - mPrivateData.Smbios.MinorVersion = (UINT8) (FixedPcdGet16 (PcdSmbiosVersion) & 0x00ff); + mPrivateData.Smbios.MajorVersion = (UINT8) (PcdGet16 (PcdSmbiosVersion) >> 8); + mPrivateData.Smbios.MinorVersion = (UINT8) (PcdGet16 (PcdSmbiosVersion) & 0x00ff); InitializeListHead (&mPrivateData.DataListHead); InitializeListHead (&mPrivateData.AllocatedHandleListHead); EfiInitializeLock (&mPrivateData.DataLock, TPL_NOTIFY); - - // - // Initialize the EntryPointStructure with initial values. - // Allocate memory (below 4GB). - // - PhysicalAddress = 0xffffffff; - Status = gBS->AllocatePages ( - AllocateMaxAddress, - EfiReservedMemoryType, - EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_ENTRY_POINT)), - &PhysicalAddress - ); - if (EFI_ERROR (Status)) { - return EFI_OUT_OF_RESOURCES; - } - - EntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *) (UINTN) PhysicalAddress; - CopyMem ( - EntryPointStructure, - &EntryPointStructureData, - sizeof (SMBIOS_TABLE_ENTRY_POINT) - ); - - // - // Pre-allocate 1 page for SMBIOS table below 4GB. - // SMBIOS table will be updated when new SMBIOS type is added or - // existing SMBIOS type is updated. If the total size of SMBIOS table exceeds 1 page, - // we will re-allocate new memory when creating whole SMBIOS table. - // - PhysicalAddress = 0xffffffff; - Status = gBS->AllocatePages ( - AllocateMaxAddress, - EfiReservedMemoryType, - 1, - &PhysicalAddress - ); - if (EFI_ERROR (Status)) { - FreePages ((VOID*) EntryPointStructure, EFI_SIZE_TO_PAGES (sizeof (SMBIOS_TABLE_ENTRY_POINT))); - EntryPointStructure = NULL; - return EFI_OUT_OF_RESOURCES; - } - - EntryPointStructure->TableAddress = (UINT32) PhysicalAddress; - EntryPointStructure->TableLength = EFI_PAGES_TO_SIZE (1); - // // Make a new handle and install the protocol //