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