1 /** @file
2 Library to add SMBIOS data records from HOB to SMBIOS table.
3
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials are licensed and made available under
7 the terms and conditions of the BSD License which accompanies this distribution.
8 The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 @par Specification Reference:
15 System Management BIOS (SMBIOS) Reference Specification v3.0.0
16 dated 2015-Feb-12 (DSP0134)
17 http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.0.0.pdf
18
19 **/
20 #include <IndustryStandard/SmBios.h>
21 #include <Library/UefiLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/MemoryAllocationLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/HobLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Protocol/Smbios.h>
29
30
31 /**
32 Adds SMBIOS records to tables
33
34 @param[in] ImageHandle Image handle of this driver.
35 @param[in] SystemTable Global system service table.
36
37 @retval EFI_UNSUPPORTED - Could not locate SMBIOS protocol
38 @retval EFI_OUT_OF_RESOURCES - Failed to allocate memory for SMBIOS HOB type.
39 @retval EFI_SUCCESS - Successfully added SMBIOS records based on HOB.
40 **/
41 EFI_STATUS
42 EFIAPI
DxeSmbiosDataHobLibConstructor(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)43 DxeSmbiosDataHobLibConstructor (
44 IN EFI_HANDLE ImageHandle,
45 IN EFI_SYSTEM_TABLE *SystemTable
46 )
47 {
48 EFI_PEI_HOB_POINTERS Hob;
49 EFI_SMBIOS_HANDLE SmbiosHandle;
50 EFI_SMBIOS_PROTOCOL *Smbios;
51 EFI_STATUS Status;
52 UINT8 *RecordPtr;
53 UINT16 RecordCount;
54
55 RecordCount = 0;
56
57 DEBUG ((DEBUG_INFO, "Adding SMBIOS records from HOB..\n"));
58
59 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);
60 if (Smbios == NULL) {
61 DEBUG ((DEBUG_WARN, "Can't locate SMBIOS protocol\n"));
62 return EFI_UNSUPPORTED;
63 }
64
65 ///
66 /// Get SMBIOS HOB data (each hob contains one SMBIOS record)
67 ///
68 for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
69 if ((GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_GUID_EXTENSION) && (CompareGuid (&Hob.Guid->Name, &gIntelSmbiosDataHobGuid))) {
70 RecordPtr = GET_GUID_HOB_DATA (Hob.Raw);
71
72 ///
73 /// Add generic SMBIOS HOB to SMBIOS table
74 ///
75 DEBUG ((DEBUG_VERBOSE, "Add SMBIOS record type: %x\n", ((EFI_SMBIOS_TABLE_HEADER *) RecordPtr)->Type));
76 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
77 Status = Smbios->Add (Smbios, NULL, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *) RecordPtr);
78 if (!EFI_ERROR (Status)) {
79 RecordCount++;
80 }
81 }
82 }
83 DEBUG ((DEBUG_INFO, "Found %d Records and added to SMBIOS table.\n", RecordCount));
84
85 return EFI_SUCCESS;
86 }
87
88