1 /** @file 2 Static SMBIOS Table for platform 3 4 5 Copyright (c) 2012, Apple Inc. All rights reserved.<BR> 6 This program and the accompanying materials 7 are licensed and made available under the terms and conditions of the BSD License 8 which accompanies this distribution. 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 **/ 15 16 #include <PiDxe.h> 17 #include <IndustryStandard/SmBios.h> 18 #include <Protocol/Smbios.h> 19 20 #include <Library/BaseLib.h> 21 #include <Library/BaseMemoryLib.h> 22 #include <Library/DebugLib.h> 23 #include <Library/SmbiosLib.h> 24 #include <Library/HobLib.h> 25 26 extern SMBIOS_TEMPLATE_ENTRY gSmbiosTemplate[]; 27 28 29 30 SMBIOS_TABLE_TYPE19 gSmbiosType19Template = { 31 { EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS, sizeof (SMBIOS_TABLE_TYPE19), 0 }, 32 0xffffffff, // StartingAddress; 33 0xffffffff, // EndingAddress; 34 0, // MemoryArrayHandle; 35 1, // PartitionWidth; 36 0, // ExtendedStartingAddress; 37 0, // ExtendedEndingAddress; 38 }; 39 40 VOID 41 CreatePlatformSmbiosMemoryRecords ( 42 VOID 43 ) 44 { 45 EFI_PEI_HOB_POINTERS HobPtr; 46 SMBIOS_STRUCTURE_POINTER Smbios16; 47 SMBIOS_STRUCTURE_POINTER Smbios17; 48 EFI_SMBIOS_HANDLE PhyscialMemoryArrayHandle; 49 EFI_SMBIOS_HANDLE SmbiosHandle; 50 51 Smbios16.Hdr = SmbiosLibGetRecord (EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY, 0, &PhyscialMemoryArrayHandle); 52 if (Smbios16.Hdr == NULL) { 53 // Only make a Type19 entry if a Type16 entry exists. 54 return; 55 } 56 57 Smbios17.Hdr = SmbiosLibGetRecord (EFI_SMBIOS_TYPE_MEMORY_DEVICE, 0, &SmbiosHandle); 58 if (Smbios17.Hdr == NULL) { 59 // if type17 exits update with type16 Smbios handle 60 Smbios17.Type17->MemoryArrayHandle = PhyscialMemoryArrayHandle; 61 } 62 63 // Generate Type16 records 64 gSmbiosType19Template.MemoryArrayHandle = PhyscialMemoryArrayHandle; 65 HobPtr.Raw = GetHobList (); 66 while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, HobPtr.Raw)) != NULL) { 67 if (HobPtr.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) { 68 gSmbiosType19Template.ExtendedStartingAddress = HobPtr.ResourceDescriptor->PhysicalStart; 69 gSmbiosType19Template.ExtendedEndingAddress = 70 HobPtr.ResourceDescriptor->PhysicalStart + 71 HobPtr.ResourceDescriptor->ResourceLength - 1; 72 73 SmbiosLibCreateEntry ((SMBIOS_STRUCTURE *)&gSmbiosType19Template, NULL); 74 } 75 HobPtr.Raw = GET_NEXT_HOB (HobPtr); 76 } 77 } 78 79 80 /** 81 Main entry for this driver. 82 83 @param ImageHandle Image handle this driver. 84 @param SystemTable Pointer to SystemTable. 85 86 @retval EFI_SUCESS This function always complete successfully. 87 88 **/ 89 EFI_STATUS 90 EFIAPI 91 PlatfomrSmbiosDriverEntryPoint ( 92 IN EFI_HANDLE ImageHandle, 93 IN EFI_SYSTEM_TABLE *SystemTable 94 ) 95 { 96 EFI_STATUS Status; 97 EFI_SMBIOS_HANDLE SmbiosHandle; 98 SMBIOS_STRUCTURE_POINTER Smbios; 99 100 // Phase 0 - Patch table to make SMBIOS 2.7 structures smaller to conform 101 // to an early version of the specification. 102 103 // Phase 1 - Initialize SMBIOS tables from template 104 Status = SmbiosLibInitializeFromTemplate (gSmbiosTemplate); 105 ASSERT_EFI_ERROR (Status); 106 107 // Phase 2 - Patch SMBIOS table entries 108 109 Smbios.Hdr = SmbiosLibGetRecord (EFI_SMBIOS_TYPE_BIOS_INFORMATION, 0, &SmbiosHandle); 110 if (Smbios.Type0 != NULL) { 111 // 64K * (n+1) bytes 112 Smbios.Type0->BiosSize = (UINT8)DivU64x32 (FixedPcdGet64 (PcdEmuFirmwareFdSize), 64*1024) - 1; 113 114 SmbiosLibUpdateUnicodeString ( 115 SmbiosHandle, 116 Smbios.Type0->BiosVersion, 117 (CHAR16 *) PcdGetPtr (PcdFirmwareVersionString) 118 ); 119 SmbiosLibUpdateUnicodeString ( 120 SmbiosHandle, 121 Smbios.Type0->BiosReleaseDate, 122 (CHAR16 *) PcdGetPtr (PcdFirmwareReleaseDateString) 123 ); 124 } 125 126 // Phase 3 - Create tables from scratch 127 128 // Create Type 13 record from EFI Variables 129 // Do we need this record for EFI as the info is availible from EFI varaibles 130 // Also language types don't always match between EFI and SMBIOS 131 // CreateSmbiosLanguageInformation (1, gSmbiosLangToEfiLang); 132 133 CreatePlatformSmbiosMemoryRecords (); 134 135 return EFI_SUCCESS; 136 }