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