]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/PlatformSmbiosDxe/PlatformSmbiosDxe.c
Add a new SMBIOS Library, and platform SMBIOS driver that does not use Framework...
[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 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 = SmbiosGetRecord (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 = SmbiosGetRecord (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 CreateSmbiosEntry ((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 UINT8 SmbiosMajorVersion;
100 UINT8 SmbiosMinorVersion;
101
102 Status = SmbiosGetVersion (&SmbiosMajorVersion, &SmbiosMinorVersion);
103 ASSERT_EFI_ERROR (Status);
104
105 // Phase 0 - Patch table to make SMBIOS 2.7 structures smaller to conform
106 // to an early version of the specification.
107
108 // Phase 1 - Initialize SMBIOS tables from template
109 Status = InitializeSmbiosTableFromTemplate (gSmbiosTemplate);
110 ASSERT_EFI_ERROR (Status);
111
112 // Phase 2 - Patch SMBIOS table entries
113
114 Smbios.Hdr = SmbiosGetRecord (EFI_SMBIOS_TYPE_BIOS_INFORMATION, 0, &SmbiosHandle);
115 if (Smbios.Type0 != NULL) {
116 // 64K * (n+1) bytes
117 Smbios.Type0->BiosSize = (UINT8)DivU64x32 (FixedPcdGet64 (PcdEmuFirmwareFdSize), 64*1024) - 1;
118
119 SmbiosUpdateUnicodeString (
120 SmbiosHandle,
121 Smbios.Type0->BiosVersion,
122 (CHAR16 *) PcdGetPtr (PcdFirmwareVersionString)
123 );
124 SmbiosUpdateUnicodeString (
125 SmbiosHandle,
126 Smbios.Type0->BiosReleaseDate,
127 (CHAR16 *) PcdGetPtr (PcdFirmwareReleaseDateString)
128 );
129 }
130
131 // Phase 3 - Create tables from scratch
132
133 // Create Type 13 record from EFI Variables
134 // Do we need this record for EFI as the info is availible from EFI varaibles
135 // Also language types don't always match between EFI and SMBIOS
136 // CreateSmbiosLanguageInformation (1, gSmbiosLangToEfiLang);
137
138 CreatePlatformSmbiosMemoryRecords ();
139
140 return EFI_SUCCESS;
141 }