PlatformSmbiosDxe.c 4.0 KB

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