SmbiosPlatformDxe.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /** @file
  2. This driver installs SMBIOS information for QSP
  3. Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>
  4. Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "SmbiosPlatformDxe.h"
  8. /**
  9. Get the system memory size below 4GB
  10. @return The size of system memory below 4GB
  11. **/
  12. UINT32
  13. GetSystemMemorySizeBelow4gb(
  14. VOID
  15. )
  16. {
  17. UINT32 Size;
  18. //
  19. // CMOS 0x34/0x35 specifies the system memory above 16 MB.
  20. // * The size is specified in 64kb chunks
  21. // * Since this is memory above 16MB, the 16MB must be added
  22. // into the calculation to get the total memory size.
  23. //
  24. Size = (UINT32) ((CmosRead16 (CMOS_SYSTEM_MEM_ABOVE_16MB_LOW_BYTE) << 16)
  25. + SIZE_16MB);
  26. return Size;
  27. }
  28. /**
  29. Get the system memory size above 4GB
  30. @return The size of system memory above 4GB
  31. **/
  32. STATIC
  33. UINT64
  34. GetSystemMemorySizeAbove4gb(
  35. VOID
  36. )
  37. {
  38. UINT32 Size;
  39. //
  40. // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.
  41. // * The size is specified in 64kb chunks
  42. //
  43. Size = (CmosRead16 (CMOS_SYSTEM_MEM_ABOVE_4GB_MIDDLE_BYTE) << 8)
  44. + CmosRead8 (CMOS_SYSTEM_MEM_ABOVE_4GB_LOW_BYTE);
  45. return LShiftU64 (Size, 16);
  46. }
  47. /**
  48. Installs SMBIOS information for SIMICS QSP
  49. @param ImageHandle Module's image handle
  50. @param SystemTable Pointer of EFI_SYSTEM_TABLE
  51. @retval EFI_SUCCESS Smbios data successfully installed
  52. @retval Other Smbios data was not installed
  53. **/
  54. EFI_STATUS
  55. EFIAPI
  56. SmbiosTablePublishEntry (
  57. IN EFI_HANDLE ImageHandle,
  58. IN EFI_SYSTEM_TABLE *SystemTable
  59. )
  60. {
  61. EFI_STATUS Status;
  62. EFI_SMBIOS_PROTOCOL *Smbios;
  63. SMBIOS_TABLE_TYPE19 *Type19Record;
  64. EFI_SMBIOS_HANDLE MemArrayMappedAddrSmbiosHandle;
  65. UINT8 NumSlots;
  66. UINT64 TotalMemorySize;
  67. //
  68. // Find the SMBIOS protocol
  69. //
  70. Status = gBS->LocateProtocol (
  71. &gEfiSmbiosProtocolGuid,
  72. NULL,
  73. (VOID**)&Smbios
  74. );
  75. if (EFI_ERROR (Status)) {
  76. return Status;
  77. }
  78. //
  79. // Generate Memory Array Mapped Address info
  80. //
  81. NumSlots = 2;
  82. TotalMemorySize = 0;
  83. TotalMemorySize = GetSystemMemorySizeBelow4gb();
  84. Type19Record = AllocatePool(sizeof(SMBIOS_TABLE_TYPE19));
  85. ZeroMem(Type19Record, sizeof(SMBIOS_TABLE_TYPE19));
  86. Type19Record->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS;
  87. Type19Record->Hdr.Length = sizeof(SMBIOS_TABLE_TYPE19);
  88. Type19Record->Hdr.Handle = 0;
  89. Type19Record->StartingAddress = 0;
  90. Type19Record->EndingAddress = (UINT32)RShiftU64(TotalMemorySize, 10) - 1;
  91. Type19Record->MemoryArrayHandle = SMBIOS_HANDLE_PI_RESERVED;
  92. Type19Record->PartitionWidth = (UINT8)(NumSlots);
  93. MemArrayMappedAddrSmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  94. Status = Smbios->Add(Smbios, NULL, &MemArrayMappedAddrSmbiosHandle, (EFI_SMBIOS_TABLE_HEADER*)Type19Record);
  95. ASSERT_EFI_ERROR(Status);
  96. TotalMemorySize = GetSystemMemorySizeAbove4gb();
  97. Type19Record->StartingAddress = 0xFFFFFFFF;
  98. Type19Record->ExtendedStartingAddress = 0xFFFFFFFF;
  99. Type19Record->ExtendedEndingAddress = TotalMemorySize + 0xFFFFFFFF - 1;
  100. MemArrayMappedAddrSmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  101. Status = Smbios->Add(Smbios, NULL, &MemArrayMappedAddrSmbiosHandle, (EFI_SMBIOS_TABLE_HEADER*)Type19Record);
  102. FreePool(Type19Record);
  103. ASSERT_EFI_ERROR(Status);
  104. return Status;
  105. }